功能:为编辑表单增加前端暂存
This commit is contained in:
Vendored
+1
@@ -73,6 +73,7 @@ declare module 'vue' {
|
||||
ATypographyText: typeof import('ant-design-vue/es')['TypographyText']
|
||||
AUpload: typeof import('ant-design-vue/es')['Upload']
|
||||
BottomNav: typeof import('./components/BottomNav.vue')['default']
|
||||
DraftActions: typeof import('./components/DraftActions.vue')['default']
|
||||
ElButton: typeof import('element-plus/es')['ElButton']
|
||||
ElColorPicker: typeof import('element-plus/es')['ElColorPicker']
|
||||
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<template>
|
||||
<div class="draft-actions">
|
||||
<a-space wrap>
|
||||
<a-button size="small" @click="$emit('save')" :disabled="disabled">
|
||||
暂存
|
||||
</a-button>
|
||||
<a-button v-if="showClear" size="small" type="link" @click="$emit('clear')" :disabled="disabled">
|
||||
清除暂存
|
||||
</a-button>
|
||||
<span v-if="savedAt" class="draft-saved-at">
|
||||
上次暂存:{{ formattedSavedAt }}
|
||||
</span>
|
||||
<span v-else class="draft-saved-at">
|
||||
暂存仅保存在当前浏览器中
|
||||
</span>
|
||||
</a-space>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
savedAt?: number | null
|
||||
disabled?: boolean
|
||||
showClear?: boolean
|
||||
}>(), {
|
||||
savedAt: null,
|
||||
disabled: false,
|
||||
showClear: true
|
||||
})
|
||||
|
||||
defineEmits<{
|
||||
(event: 'save'): void
|
||||
(event: 'clear'): void
|
||||
}>()
|
||||
|
||||
const formattedSavedAt = computed(() => {
|
||||
if (!props.savedAt) {
|
||||
return ''
|
||||
}
|
||||
const date = new Date(props.savedAt)
|
||||
const year = date.getFullYear()
|
||||
const month = `${date.getMonth() + 1}`.padStart(2, '0')
|
||||
const day = `${date.getDate()}`.padStart(2, '0')
|
||||
const hour = `${date.getHours()}`.padStart(2, '0')
|
||||
const minute = `${date.getMinutes()}`.padStart(2, '0')
|
||||
return `${year}-${month}-${day} ${hour}:${minute}`
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.draft-actions {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.draft-saved-at {
|
||||
color: #8c8c8c;
|
||||
font-size: 12px;
|
||||
line-height: 24px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,42 @@
|
||||
export type DraftStorageMode = 'local' | 'session'
|
||||
|
||||
export interface DraftRecord<T> {
|
||||
savedAt: number
|
||||
payload: T
|
||||
}
|
||||
|
||||
const getStorage = (mode: DraftStorageMode) => (mode === 'session' ? window.sessionStorage : window.localStorage)
|
||||
|
||||
export const buildDraftStorageKey = (...parts: Array<string | number | undefined | null>) => {
|
||||
const normalizedParts = parts
|
||||
.filter((part): part is string | number => part !== undefined && part !== null && String(part).trim().length > 0)
|
||||
.map(part => String(part).trim())
|
||||
return `yuminail:draft:${normalizedParts.join(':')}`
|
||||
}
|
||||
|
||||
export const saveDraftRecord = <T>(key: string, payload: T, mode: DraftStorageMode = 'local') => {
|
||||
const record: DraftRecord<T> = {
|
||||
savedAt: Date.now(),
|
||||
payload
|
||||
}
|
||||
getStorage(mode).setItem(key, JSON.stringify(record))
|
||||
return record
|
||||
}
|
||||
|
||||
export const loadDraftRecord = <T>(key: string, mode: DraftStorageMode = 'local') => {
|
||||
const rawValue = getStorage(mode).getItem(key)
|
||||
if (!rawValue) {
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(rawValue) as DraftRecord<T>
|
||||
} catch {
|
||||
getStorage(mode).removeItem(key)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export const clearDraftRecord = (key: string, mode: DraftStorageMode = 'local') => {
|
||||
getStorage(mode).removeItem(key)
|
||||
}
|
||||
@@ -46,6 +46,11 @@
|
||||
@cancel="handleBindPhoneCancel"
|
||||
:confirmLoading="bindPhoneLoading"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="bindPhoneDraftSavedAt"
|
||||
@save="handleSaveBindPhoneDraft"
|
||||
@clear="handleClearBindPhoneDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="手机号" name="phone">
|
||||
<a-input
|
||||
@@ -81,6 +86,11 @@
|
||||
@cancel="handleChangePhoneCancel"
|
||||
:confirmLoading="changePhoneLoading"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="changePhoneDraftSavedAt"
|
||||
@save="handleSaveChangePhoneDraft"
|
||||
@clear="handleClearChangePhoneDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="旧手机号">
|
||||
<a-input :value="userInfo.phone" disabled />
|
||||
@@ -118,6 +128,11 @@
|
||||
@cancel="handleChangePasswordCancel"
|
||||
:confirmLoading="changePasswordLoading"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="changePasswordDraftSavedAt"
|
||||
@save="handleSaveChangePasswordDraft"
|
||||
@clear="handleClearChangePasswordDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="手机号">
|
||||
<a-input :value="userInfo.phone" disabled />
|
||||
@@ -163,8 +178,10 @@ import { ref, reactive, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined, RightOutlined, LockOutlined, PhoneOutlined } from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { userApi } from '@/api/user'
|
||||
import type { UserVO } from '@/api/user'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
@@ -187,6 +204,7 @@ const hasPhone = ref(false)
|
||||
// 绑定手机号表单
|
||||
const bindPhoneModalVisible = ref(false)
|
||||
const bindPhoneLoading = ref(false)
|
||||
const bindPhoneDraftSavedAt = ref<number | null>(null)
|
||||
const bindPhoneForm = reactive({
|
||||
phone: '',
|
||||
verificationCode: ''
|
||||
@@ -195,6 +213,7 @@ const bindPhoneForm = reactive({
|
||||
// 修改手机号表单
|
||||
const changePhoneModalVisible = ref(false)
|
||||
const changePhoneLoading = ref(false)
|
||||
const changePhoneDraftSavedAt = ref<number | null>(null)
|
||||
const changePhoneForm = reactive({
|
||||
newPhone: '',
|
||||
verificationCode: ''
|
||||
@@ -203,12 +222,66 @@ const changePhoneForm = reactive({
|
||||
// 修改密码表单
|
||||
const changePasswordModalVisible = ref(false)
|
||||
const changePasswordLoading = ref(false)
|
||||
const changePasswordDraftSavedAt = ref<number | null>(null)
|
||||
const changePasswordForm = reactive({
|
||||
verificationCode: '',
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
const restoreSessionDraft = <T extends Record<string, any>>(key: string, target: T, savedAtRef: typeof bindPhoneDraftSavedAt) => {
|
||||
const draft = loadDraftRecord<T>(key, 'session')
|
||||
if (!draft) {
|
||||
savedAtRef.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(target, draft.payload)
|
||||
savedAtRef.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const saveSessionDraft = <T>(key: string, payload: T, savedAtRef: typeof bindPhoneDraftSavedAt, successMessage = '已暂存到当前会话') => {
|
||||
const draft = saveDraftRecord(key, payload, 'session')
|
||||
savedAtRef.value = draft.savedAt
|
||||
message.success(successMessage)
|
||||
}
|
||||
|
||||
const clearSessionDraft = (key: string, savedAtRef: typeof bindPhoneDraftSavedAt, showMessage = true) => {
|
||||
clearDraftRecord(key, 'session')
|
||||
savedAtRef.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const bindPhoneDraftKey = buildDraftStorageKey('account-settings', 'bind-phone')
|
||||
const changePhoneDraftKey = buildDraftStorageKey('account-settings', 'change-phone')
|
||||
const changePasswordDraftKey = buildDraftStorageKey('account-settings', 'change-password')
|
||||
|
||||
const handleSaveBindPhoneDraft = () => {
|
||||
saveSessionDraft(bindPhoneDraftKey, { ...bindPhoneForm }, bindPhoneDraftSavedAt)
|
||||
}
|
||||
|
||||
const handleClearBindPhoneDraft = (showMessage = true) => {
|
||||
clearSessionDraft(bindPhoneDraftKey, bindPhoneDraftSavedAt, showMessage)
|
||||
}
|
||||
|
||||
const handleSaveChangePhoneDraft = () => {
|
||||
saveSessionDraft(changePhoneDraftKey, { ...changePhoneForm }, changePhoneDraftSavedAt)
|
||||
}
|
||||
|
||||
const handleClearChangePhoneDraft = (showMessage = true) => {
|
||||
clearSessionDraft(changePhoneDraftKey, changePhoneDraftSavedAt, showMessage)
|
||||
}
|
||||
|
||||
const handleSaveChangePasswordDraft = () => {
|
||||
saveSessionDraft(changePasswordDraftKey, { ...changePasswordForm }, changePasswordDraftSavedAt)
|
||||
}
|
||||
|
||||
const handleClearChangePasswordDraft = (showMessage = true) => {
|
||||
clearSessionDraft(changePasswordDraftKey, changePasswordDraftSavedAt, showMessage)
|
||||
}
|
||||
|
||||
// 倒计时
|
||||
const countdown = ref(0)
|
||||
|
||||
@@ -309,15 +382,18 @@ const handleBackClick = () => {
|
||||
const handleSettingClick = (key: string) => {
|
||||
switch (key) {
|
||||
case 'bindPhone':
|
||||
restoreSessionDraft(bindPhoneDraftKey, bindPhoneForm, bindPhoneDraftSavedAt)
|
||||
bindPhoneModalVisible.value = true
|
||||
break
|
||||
case 'changePhone':
|
||||
restoreSessionDraft(changePhoneDraftKey, changePhoneForm, changePhoneDraftSavedAt)
|
||||
changePhoneModalVisible.value = true
|
||||
break
|
||||
case 'setPassword':
|
||||
handleSetPassword()
|
||||
break
|
||||
case 'changePassword':
|
||||
restoreSessionDraft(changePasswordDraftKey, changePasswordForm, changePasswordDraftSavedAt)
|
||||
changePasswordModalVisible.value = true
|
||||
break
|
||||
case 'deactivateAccount':
|
||||
@@ -427,6 +503,7 @@ const handleBindPhoneSubmit = async () => {
|
||||
verificationCode: bindPhoneForm.verificationCode
|
||||
})
|
||||
message.success('手机号绑定成功')
|
||||
handleClearBindPhoneDraft(false)
|
||||
bindPhoneModalVisible.value = false
|
||||
await fetchUserInfo()
|
||||
} catch (error: any) {
|
||||
@@ -459,6 +536,7 @@ const handleChangePhoneSubmit = async () => {
|
||||
verificationCode: changePhoneForm.verificationCode
|
||||
})
|
||||
message.success('手机号修改成功')
|
||||
handleClearChangePhoneDraft(false)
|
||||
changePhoneModalVisible.value = false
|
||||
await fetchUserInfo()
|
||||
} catch (error: any) {
|
||||
@@ -495,6 +573,7 @@ const handleChangePasswordSubmit = async () => {
|
||||
verificationCode: changePasswordForm.verificationCode
|
||||
})
|
||||
message.success('密码修改成功')
|
||||
handleClearChangePasswordDraft(false)
|
||||
changePasswordModalVisible.value = false
|
||||
// 清除需要设置密码的标识
|
||||
localStorage.removeItem('needSetPassword')
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
|
||||
<div class="password-form">
|
||||
<a-card :bordered="false" class="form-card">
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
@@ -92,13 +97,16 @@ import { LeftOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import type { Rule } from 'ant-design-vue/es/form'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { userApi } from '@/api/user'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
const countdown = ref(0)
|
||||
const userInfo = ref<{ phone?: string } | null>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
let countdownTimer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
const formState = reactive({
|
||||
@@ -107,6 +115,33 @@ const formState = reactive({
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
const draftKey = buildDraftStorageKey('password-settings', 'set-password')
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<typeof formState>(draftKey, 'session')
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(formState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(draftKey, { ...formState }, 'session')
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到当前会话')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(draftKey, 'session')
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const userPhone = computed(() => userInfo.value?.phone || '')
|
||||
|
||||
const validateConfirmPassword = (_rule: any, value: string) => {
|
||||
@@ -189,6 +224,7 @@ const handleSubmit = async () => {
|
||||
})
|
||||
|
||||
message.success('密码设置成功')
|
||||
handleClearDraft(false)
|
||||
localStorage.removeItem('needSetPassword')
|
||||
router.push('/profile')
|
||||
} catch (error: any) {
|
||||
@@ -205,6 +241,7 @@ const handleBackClick = () => {
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
restoreDraft()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
|
||||
@@ -127,6 +127,12 @@
|
||||
:confirmLoading="saving"
|
||||
:ok-button-props="{ disabled: avatarUploadPending }"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
:disabled="avatarUploadPending"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="头像">
|
||||
<div class="avatar-upload-section">
|
||||
@@ -198,12 +204,14 @@ import {
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { UploadProps } from 'ant-design-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { couponApi } from '@/api/coupon'
|
||||
import { fileApi } from '@/api/file'
|
||||
import { orderApi } from '@/api/order'
|
||||
import { userApi, type UserVO } from '@/api/user'
|
||||
import { createChunkUploadTask, type ChunkUploadTask } from '@/utils/chunk-upload'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { wishlistApi } from '@/api/wishlist'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
|
||||
@@ -233,6 +241,7 @@ const selectedShopId = ref<string>()
|
||||
const avatarUploadProgress = ref(0)
|
||||
const avatarUploadPending = ref(false)
|
||||
let avatarUploadTask: ChunkUploadTask<string> | null = null
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
const editForm = reactive({
|
||||
nickname: '',
|
||||
@@ -240,6 +249,43 @@ const editForm = reactive({
|
||||
signature: ''
|
||||
})
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('profile-edit')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
nickname: editForm.nickname,
|
||||
avatar: editForm.avatar,
|
||||
signature: editForm.signature
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(editForm, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
if (avatarUploadPending.value) {
|
||||
message.warning('头像上传完成后才能暂存')
|
||||
return
|
||||
}
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const shopOptions = computed(() => {
|
||||
const ids = userInfo.value.shopIds || []
|
||||
const names = userInfo.value.shopNames || []
|
||||
@@ -345,6 +391,7 @@ const handleEditProfile = () => {
|
||||
editForm.nickname = userInfo.value.nickname || ''
|
||||
editForm.avatar = userInfo.value.avatar || ''
|
||||
editForm.signature = userInfo.value.signature || ''
|
||||
restoreDraft()
|
||||
editModalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -445,6 +492,7 @@ const handleSaveProfile = async () => {
|
||||
signature: editForm.signature
|
||||
})
|
||||
message.success('资料更新成功')
|
||||
handleClearDraft(false)
|
||||
editModalVisible.value = false
|
||||
await fetchUserInfo()
|
||||
} catch (error) {
|
||||
|
||||
@@ -103,6 +103,11 @@
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
@@ -264,6 +269,7 @@ import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import dayjs, { type Dayjs } from 'dayjs'
|
||||
import {
|
||||
adminCouponApi,
|
||||
@@ -275,6 +281,7 @@ import {
|
||||
type Tag,
|
||||
type UserVO
|
||||
} from '@/api/admin'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
@@ -317,6 +324,7 @@ const searchText = ref('')
|
||||
const formRef = ref<FormInstance>()
|
||||
const distributeFormRef = ref<FormInstance>()
|
||||
const currentCoupon = ref<Coupon | null>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
const couponList = ref<Coupon[]>([])
|
||||
const tagList = ref<Tag[]>([])
|
||||
const userList = ref<UserVO[]>([])
|
||||
@@ -444,6 +452,56 @@ const resetFormState = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-coupons', isEdit.value ? 'edit' : 'create', currentCoupon.value?.id ?? 'new')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
couponCode: formState.couponCode,
|
||||
couponName: formState.couponName,
|
||||
couponType: formState.couponType,
|
||||
discountValue: formState.discountValue,
|
||||
minAmount: formState.minAmount,
|
||||
reduceAmount: formState.reduceAmount,
|
||||
totalCount: formState.totalCount,
|
||||
startTime: formState.startTime?.format('YYYY-MM-DD HH:mm:ss'),
|
||||
endTime: formState.endTime?.format('YYYY-MM-DD HH:mm:ss'),
|
||||
availableTagIds: [...formState.availableTagIds],
|
||||
unavailableTagIds: [...formState.unavailableTagIds],
|
||||
shopId: formState.shopId,
|
||||
couponScene: formState.couponScene,
|
||||
requiredVipLevel: formState.requiredVipLevel,
|
||||
autoMatch: formState.autoMatch
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
|
||||
Object.assign(formState, {
|
||||
...draft.payload,
|
||||
startTime: draft.payload.startTime ? dayjs(draft.payload.startTime) : undefined,
|
||||
endTime: draft.payload.endTime ? dayjs(draft.payload.endTime) : undefined
|
||||
})
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => formState.couponScene,
|
||||
value => {
|
||||
@@ -533,6 +591,7 @@ const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
currentCoupon.value = null
|
||||
resetFormState()
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -556,6 +615,7 @@ const showEditModal = (record: any) => {
|
||||
requiredVipLevel: record.requiredVipLevel || undefined,
|
||||
autoMatch: record.autoMatch || 0
|
||||
})
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -596,6 +656,7 @@ const handleModalOk = async () => {
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
await fetchCoupons()
|
||||
|
||||
@@ -51,6 +51,11 @@
|
||||
:confirmLoading="modalLoading"
|
||||
width="800px"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
@@ -169,9 +174,11 @@
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { adminNailArtistApi, type NailArtistInfoVO } from '@/api/admin'
|
||||
import { adminTagApi, type Tag } from '@/api/admin'
|
||||
import { adminProductApi, type Product } from '@/api/admin'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
@@ -206,6 +213,7 @@ const isShopOwner = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentNailArtist = ref<NailArtistInfoVO | null>(null)
|
||||
const currentUserInfo = getCurrentUserInfo()
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
const viewFormState = reactive({
|
||||
nickname: '',
|
||||
@@ -238,6 +246,44 @@ const formState = reactive({
|
||||
nickname: ''
|
||||
})
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-nail-artists', 'edit', currentNailArtist.value?.userId ?? formState.userId ?? 'unknown')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
userId: formState.userId,
|
||||
identity: formState.identity,
|
||||
experience: formState.experience,
|
||||
skills: [...formState.skills],
|
||||
rating: formState.rating,
|
||||
status: formState.status,
|
||||
portfolio: [...formState.portfolio],
|
||||
nickname: formState.nickname
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(formState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const formRules = {
|
||||
identity: [{ required: true, message: '请输入身份', trigger: 'blur' }],
|
||||
experience: [{ required: true, message: '请输入从业年限', trigger: 'blur' }],
|
||||
@@ -340,6 +386,7 @@ const showEditModal = (record: Record<string, any>) => {
|
||||
portfolio: record.portfolio ? record.portfolio.split(',').filter(Boolean) : [],
|
||||
nickname: record.nickname || ''
|
||||
})
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -392,6 +439,7 @@ const handleModalOk = async () => {
|
||||
await adminNailArtistApi.saveNailArtistInfo(submitData)
|
||||
message.success('保存成功')
|
||||
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
fetchNailArtistList()
|
||||
} catch (error) {
|
||||
@@ -419,4 +467,4 @@ onMounted(async () => {
|
||||
.nail-artists {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -139,6 +139,11 @@
|
||||
@cancel="handlePermissionModalCancel"
|
||||
:confirmLoading="permissionModalLoading"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="permissionFormRef"
|
||||
:model="permissionFormState"
|
||||
@@ -178,9 +183,11 @@ import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import type { Rule } from 'ant-design-vue/es/form'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { userApi, type UserVO } from '@/api/admin'
|
||||
import { permissionApi, type PermissionVO } from '@/api/permission'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
@@ -193,6 +200,7 @@ const permissionModalLoading = ref(false)
|
||||
const isEditPermission = ref(false)
|
||||
const permissionFormRef = ref<FormInstance>()
|
||||
const currentPermission = ref<PermissionVO | null>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
const permissionPagination = reactive({
|
||||
current: 1,
|
||||
@@ -210,6 +218,40 @@ const permissionFormState = reactive({
|
||||
description: ''
|
||||
})
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-permissions', isEditPermission.value ? 'edit' : 'create', currentPermission.value?.id ?? 'new')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
permissionCode: permissionFormState.permissionCode,
|
||||
permissionName: permissionFormState.permissionName,
|
||||
permissionGroup: permissionFormState.permissionGroup,
|
||||
description: permissionFormState.description
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(permissionFormState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const permissionFormRules: Record<string, Rule[]> = {
|
||||
permissionCode: [{ required: true, message: '请输入权限编码', trigger: 'blur' }],
|
||||
permissionName: [{ required: true, message: '请输入权限名称', trigger: 'blur' }],
|
||||
@@ -375,12 +417,14 @@ const handleSaveUserPermissions = async () => {
|
||||
|
||||
const showAddPermissionModal = () => {
|
||||
isEditPermission.value = false
|
||||
currentPermission.value = null
|
||||
Object.assign(permissionFormState, {
|
||||
permissionCode: '',
|
||||
permissionName: '',
|
||||
permissionGroup: '',
|
||||
description: ''
|
||||
})
|
||||
restoreDraft()
|
||||
permissionModalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -393,6 +437,7 @@ const showEditPermissionModal = (record: Record<string, any>) => {
|
||||
permissionGroup: record.permissionGroup,
|
||||
description: record.description
|
||||
})
|
||||
restoreDraft()
|
||||
permissionModalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -409,6 +454,7 @@ const handlePermissionModalOk = async () => {
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
handleClearDraft(false)
|
||||
permissionModalVisible.value = false
|
||||
fetchPermissionList()
|
||||
} catch (error) {
|
||||
|
||||
@@ -91,6 +91,12 @@
|
||||
:confirmLoading="modalLoading"
|
||||
:ok-button-props="{ disabled: isUploadPending }"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
:disabled="isUploadPending"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
@@ -367,9 +373,11 @@
|
||||
import { computed, ref, reactive, onMounted, watch } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
||||
import { adminProductApi, type Product, adminShopApi, type Shop, adminFileApi, adminTagApi, adminArtistApi, adminCouponApi } from '@/api/admin'
|
||||
import { createChunkUploadTask, type ChunkUploadTask } from '@/utils/chunk-upload'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { MAX_IMAGE_UPLOAD_SIZE, compressImageIfNeeded, formatFileSize } from '@/utils/image-upload'
|
||||
|
||||
@@ -403,6 +411,7 @@ const MAX_PRODUCT_IMAGE_COUNT = 5
|
||||
const uploadTaskMap = new Map<string, ChunkUploadTask<any>>()
|
||||
const activeUploadCount = ref(0)
|
||||
const isUploadPending = computed(() => activeUploadCount.value > 0)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
const viewFormState = reactive({
|
||||
shopId: undefined,
|
||||
@@ -639,8 +648,9 @@ const handleTableChange = (pag: any) => {
|
||||
fetchProductList()
|
||||
}
|
||||
|
||||
const showAddModal = () => {
|
||||
const showAddModal = async () => {
|
||||
isEdit.value = false
|
||||
currentProduct.value = null
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.type !== 4 && currentUser.shopId) ? currentUser.shopId : undefined
|
||||
Object.assign(formState, {
|
||||
@@ -660,6 +670,7 @@ const showAddModal = () => {
|
||||
if (shopId) {
|
||||
fetchArtists(shopId)
|
||||
}
|
||||
await restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -701,35 +712,7 @@ const showEditModal = async (record: Product | Record<string, any>) => {
|
||||
if (recordImageFileIds) {
|
||||
const ids = recordImageFileIds.split(',').filter((id: string) => id)
|
||||
syncUploadedFileIds(ids)
|
||||
|
||||
// 加载所有图片签名链接
|
||||
const fileList = []
|
||||
for (const [index, id] of ids.entries()) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const response = await adminFileApi.getSignedUrl(Number(id)) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
fileList.push({
|
||||
uid: id,
|
||||
fileId: id,
|
||||
name: `图片${index + 1}`,
|
||||
status: 'done',
|
||||
url: imageIdCache.value[id]
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
fileList.push({
|
||||
uid: id,
|
||||
fileId: id,
|
||||
name: `图片${index + 1}`,
|
||||
status: 'done',
|
||||
url: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
imageFileList.value = fileList
|
||||
imageFileList.value = await buildImageFileListByIds(ids)
|
||||
} else {
|
||||
imageFileList.value = []
|
||||
syncUploadedFileIds([])
|
||||
@@ -739,6 +722,7 @@ const showEditModal = async (record: Product | Record<string, any>) => {
|
||||
if (recordShopId) {
|
||||
await fetchArtists(recordShopId)
|
||||
}
|
||||
await restoreDraft()
|
||||
|
||||
modalVisible.value = true
|
||||
}
|
||||
@@ -815,6 +799,84 @@ const cancelAllPendingUploads = () => {
|
||||
uploadTaskMap.forEach(task => task.cancel())
|
||||
}
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-products', isEdit.value ? 'edit' : 'create', currentProduct.value?.id ?? 'new')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
formState: {
|
||||
shopId: formState.shopId,
|
||||
title: formState.title,
|
||||
description: formState.description,
|
||||
imageFileIds: formState.imageFileIds,
|
||||
price: formState.price,
|
||||
tags: [...formState.tags],
|
||||
approximateDuration: formState.approximateDuration,
|
||||
bookableArtists: [...formState.bookableArtists],
|
||||
availableCoupons: [...formState.availableCoupons]
|
||||
},
|
||||
uploadedFileIds: [...uploadedFileIds.value]
|
||||
})
|
||||
|
||||
const buildImageFileListByIds = async (ids: string[]) => {
|
||||
const fileList = []
|
||||
for (const [index, id] of ids.entries()) {
|
||||
try {
|
||||
if (!imageIdCache.value[id]) {
|
||||
const response = await adminFileApi.getSignedUrl(Number(id)) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
fileList.push({
|
||||
uid: id,
|
||||
fileId: id,
|
||||
name: `图片${index + 1}`,
|
||||
status: 'done',
|
||||
url: imageIdCache.value[id]
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
fileList.push({
|
||||
uid: id,
|
||||
fileId: id,
|
||||
name: `图片${index + 1}`,
|
||||
status: 'done',
|
||||
url: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
return fileList
|
||||
}
|
||||
|
||||
const restoreDraft = async () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
|
||||
Object.assign(formState, draft.payload.formState)
|
||||
syncUploadedFileIds(draft.payload.uploadedFileIds || [])
|
||||
imageFileList.value = await buildImageFileListByIds(uploadedFileIds.value)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
if (isUploadPending.value) {
|
||||
message.warning('图片上传完成后才能暂存')
|
||||
return
|
||||
}
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const syncUploadedFileIds = (fileIds: string[]) => {
|
||||
uploadedFileIds.value = Array.from(new Set(fileIds.filter(id => Boolean(id))))
|
||||
formState.imageFileIds = uploadedFileIds.value.join(',')
|
||||
@@ -1003,7 +1065,8 @@ const handleModalOk = async () => {
|
||||
await adminProductApi.createProduct(requestData)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
fetchProductList()
|
||||
} catch (error: any) {
|
||||
|
||||
@@ -105,6 +105,12 @@
|
||||
:confirmLoading="modalLoading"
|
||||
:ok-button-props="{ disabled: isUploadPending }"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
:disabled="isUploadPending"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
@@ -268,9 +274,11 @@ import { computed, ref, reactive, onMounted } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { DEFAULT_SHOP_IMAGE } from '@/constants'
|
||||
import { adminShopApi, adminFileApi, type Shop } from '@/api/admin'
|
||||
import { createChunkUploadTask, type ChunkUploadTask } from '@/utils/chunk-upload'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
@@ -307,6 +315,7 @@ const businessEndTime = ref('')
|
||||
const uploadTaskMap = new Map<string, ChunkUploadTask<any>>()
|
||||
const activeUploadCount = ref(0)
|
||||
const isUploadPending = computed(() => activeUploadCount.value > 0)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
// 查看店铺相关状态
|
||||
const viewFormState = reactive({
|
||||
@@ -692,8 +701,9 @@ const handleBusinessHoursChange = async () => {
|
||||
await formRef.value?.validateFields?.(['businessHours']).catch(() => undefined)
|
||||
}
|
||||
|
||||
const showAddModal = () => {
|
||||
const showAddModal = async () => {
|
||||
isEdit.value = false
|
||||
currentShop.value = null
|
||||
Object.assign(formState, {
|
||||
shopName: '',
|
||||
description: '',
|
||||
@@ -708,6 +718,7 @@ const showAddModal = () => {
|
||||
syncUploadedBannerIds([])
|
||||
imageFileList.value = []
|
||||
syncUploadedFileIds([])
|
||||
await restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -730,35 +741,7 @@ const showEditModal = async (record: Shop | Record<string, any>) => {
|
||||
if (coverImageFileId) {
|
||||
const ids = coverImageFileId.split(',').filter((id: string) => id)
|
||||
syncUploadedBannerIds(ids)
|
||||
|
||||
// 加载所有图片签名链接
|
||||
const fileList = []
|
||||
for (const [index, id] of ids.entries()) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const response = await adminFileApi.getSignedUrl(Number(id || '0')) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
fileList.push({
|
||||
uid: id,
|
||||
fileId: id,
|
||||
name: `Banner${index + 1}`,
|
||||
status: 'done',
|
||||
url: imageIdCache.value[id]
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
fileList.push({
|
||||
uid: id,
|
||||
fileId: id,
|
||||
name: `Banner${index + 1}`,
|
||||
status: 'done',
|
||||
url: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
bannerFileList.value = fileList
|
||||
bannerFileList.value = await buildShopUploadFileList(ids, 'Banner')
|
||||
} else {
|
||||
bannerFileList.value = []
|
||||
syncUploadedBannerIds([])
|
||||
@@ -769,40 +752,13 @@ const showEditModal = async (record: Shop | Record<string, any>) => {
|
||||
if (imageFileIds) {
|
||||
const ids = imageFileIds.split(',').filter((id: string) => id)
|
||||
syncUploadedFileIds(ids)
|
||||
|
||||
// 加载所有图片签名链接
|
||||
const fileList = []
|
||||
for (const [index, id] of ids.entries()) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const response = await adminFileApi.getSignedUrl(Number(id || '0')) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
fileList.push({
|
||||
uid: id,
|
||||
fileId: id,
|
||||
name: `图片${index + 1}`,
|
||||
status: 'done',
|
||||
url: imageIdCache.value[id]
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
fileList.push({
|
||||
uid: id,
|
||||
fileId: id,
|
||||
name: `图片${index + 1}`,
|
||||
status: 'done',
|
||||
url: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
imageFileList.value = fileList
|
||||
imageFileList.value = await buildShopUploadFileList(ids, '图片')
|
||||
} else {
|
||||
imageFileList.value = []
|
||||
syncUploadedFileIds([])
|
||||
}
|
||||
|
||||
await restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -878,6 +834,89 @@ const cancelAllPendingUploads = () => {
|
||||
uploadTaskMap.forEach(task => task.cancel())
|
||||
}
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-shops', isEdit.value ? 'edit' : 'create', currentShop.value?.id ?? 'new')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
formState: {
|
||||
shopName: formState.shopName,
|
||||
description: formState.description,
|
||||
address: formState.address,
|
||||
businessHours: formState.businessHours,
|
||||
status: formState.status,
|
||||
coverImageFileId: formState.coverImageFileId,
|
||||
imageFileIds: formState.imageFileIds
|
||||
},
|
||||
businessStartTime: businessStartTime.value,
|
||||
businessEndTime: businessEndTime.value,
|
||||
uploadedBannerIds: [...uploadedBannerIds.value],
|
||||
uploadedFileIds: [...uploadedFileIds.value]
|
||||
})
|
||||
|
||||
const buildShopUploadFileList = async (ids: string[], fileNamePrefix: string) => {
|
||||
const fileList = []
|
||||
for (const [index, id] of ids.entries()) {
|
||||
try {
|
||||
if (!imageIdCache.value[id]) {
|
||||
const response = await adminFileApi.getSignedUrl(Number(id || '0')) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
fileList.push({
|
||||
uid: id,
|
||||
fileId: id,
|
||||
name: `${fileNamePrefix}${index + 1}`,
|
||||
status: 'done',
|
||||
url: imageIdCache.value[id]
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
fileList.push({
|
||||
uid: id,
|
||||
fileId: id,
|
||||
name: `${fileNamePrefix}${index + 1}`,
|
||||
status: 'done',
|
||||
url: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
return fileList
|
||||
}
|
||||
|
||||
const restoreDraft = async () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
|
||||
Object.assign(formState, draft.payload.formState)
|
||||
businessStartTime.value = draft.payload.businessStartTime || ''
|
||||
businessEndTime.value = draft.payload.businessEndTime || ''
|
||||
syncUploadedBannerIds(draft.payload.uploadedBannerIds || [])
|
||||
syncUploadedFileIds(draft.payload.uploadedFileIds || [])
|
||||
bannerFileList.value = await buildShopUploadFileList(uploadedBannerIds.value, 'Banner')
|
||||
imageFileList.value = await buildShopUploadFileList(uploadedFileIds.value, '图片')
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
if (isUploadPending.value) {
|
||||
message.warning('图片上传完成后才能暂存')
|
||||
return
|
||||
}
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const syncUploadedBannerIds = (fileIds: string[]) => {
|
||||
uploadedBannerIds.value = Array.from(new Set(fileIds.filter(id => Boolean(id))))
|
||||
formState.coverImageFileId = uploadedBannerIds.value.join(',')
|
||||
@@ -947,6 +986,7 @@ const handleModalOk = async () => {
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
fetchShopList()
|
||||
} catch (error) {
|
||||
|
||||
@@ -69,6 +69,11 @@
|
||||
:confirmLoading="modalLoading"
|
||||
width="600px"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
@@ -184,7 +189,9 @@ import { ref, reactive, onMounted } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { adminTagApi, adminShopApi, type Shop } from '@/api/admin'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
@@ -210,6 +217,7 @@ const isEdit = ref(false)
|
||||
const searchText = ref('')
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentTag = ref<any>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
// 查看标签相关状态
|
||||
const viewFormState = reactive({
|
||||
@@ -241,6 +249,41 @@ const formState = reactive({
|
||||
borderColor: '#E5E5E5'
|
||||
})
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-tags', isEdit.value ? 'edit' : 'create', currentTag.value?.id ?? 'new')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
tagName: formState.tagName,
|
||||
shopId: formState.shopId,
|
||||
textColor: formState.textColor,
|
||||
bgColor: formState.bgColor,
|
||||
borderColor: formState.borderColor
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(formState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const formRules = {
|
||||
tagName: [{ required: true, message: '请输入标签名称', trigger: 'blur' }],
|
||||
shopId: [{ required: true, message: '请选择所属店铺', trigger: 'change' }]
|
||||
@@ -308,6 +351,7 @@ const handleTableChange = (pag: any) => {
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
currentTag.value = null
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||
Object.assign(formState, {
|
||||
@@ -317,6 +361,7 @@ const showAddModal = () => {
|
||||
bgColor: '#FFFFFF',
|
||||
borderColor: '#E5E5E5'
|
||||
})
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -330,6 +375,7 @@ const showEditModal = (record: any) => {
|
||||
bgColor: record.bgColor,
|
||||
borderColor: record.borderColor
|
||||
})
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -370,6 +416,7 @@ const handleModalOk = async () => {
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
fetchTags()
|
||||
} catch (error) {
|
||||
@@ -419,4 +466,4 @@ onMounted(async () => {
|
||||
border: 1px solid;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -103,6 +103,11 @@
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
@@ -225,6 +230,11 @@
|
||||
<a-row :gutter="16" class="asset-actions">
|
||||
<a-col :span="12">
|
||||
<a-card size="small" title="余额变动">
|
||||
<DraftActions
|
||||
:saved-at="balanceDraftSavedAt"
|
||||
@save="handleSaveBalanceDraft"
|
||||
@clear="handleClearBalanceDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="变动场景">
|
||||
<a-select v-model:value="balanceForm.changeScene">
|
||||
@@ -281,6 +291,11 @@
|
||||
|
||||
<a-col :span="12">
|
||||
<a-card size="small" title="VIP 管理">
|
||||
<DraftActions
|
||||
:saved-at="vipDraftSavedAt"
|
||||
@save="handleSaveVipDraft"
|
||||
@clear="handleClearVipDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="目标等级">
|
||||
<a-select v-model:value="vipForm.vipLevel">
|
||||
@@ -363,8 +378,10 @@ import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import {
|
||||
adminShopApi,
|
||||
adminUserApi,
|
||||
@@ -401,6 +418,7 @@ const userList = ref<UserVO[]>([])
|
||||
const shopList = ref<Shop[]>([])
|
||||
const currentUser = ref<UserVO | null>(null)
|
||||
const viewRecord = ref<UserVO | null>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
const assetModalVisible = ref(false)
|
||||
const assetLoading = ref(false)
|
||||
@@ -408,6 +426,8 @@ const assetSaving = ref(false)
|
||||
const assetTargetUser = ref<UserVO | null>(null)
|
||||
const assetData = ref<UserAssetVO | null>(null)
|
||||
const balanceHistory = ref<UserBalanceHistoryItem[]>([])
|
||||
const balanceDraftSavedAt = ref<number | null>(null)
|
||||
const vipDraftSavedAt = ref<number | null>(null)
|
||||
|
||||
const canOpenAssetPanel = computed(() =>
|
||||
hasAnyPermission(['user:balance:view', 'user:balance:manage', 'user:vip:manage'])
|
||||
@@ -452,6 +472,77 @@ const vipForm = reactive<AdminUserVipOverrideRequest>({
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const getBalanceDraftKey = () => buildDraftStorageKey('admin-user-assets', 'balance', assetTargetUser.value?.id ?? 'unknown')
|
||||
const getVipDraftKey = () => buildDraftStorageKey('admin-user-assets', 'vip', assetTargetUser.value?.id ?? 'unknown')
|
||||
|
||||
const restoreBalanceDraft = () => {
|
||||
const draft = loadDraftRecord<{
|
||||
changeScene: string
|
||||
amount?: number
|
||||
relatedOrderId?: number
|
||||
externalOrderNo: string
|
||||
remark: string
|
||||
}>(getBalanceDraftKey())
|
||||
if (!draft) {
|
||||
balanceDraftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(balanceForm, draft.payload)
|
||||
balanceDraftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复余额变动暂存')
|
||||
}
|
||||
|
||||
const handleSaveBalanceDraft = () => {
|
||||
const draft = saveDraftRecord(getBalanceDraftKey(), {
|
||||
changeScene: balanceForm.changeScene,
|
||||
amount: balanceForm.amount,
|
||||
relatedOrderId: balanceForm.relatedOrderId,
|
||||
externalOrderNo: balanceForm.externalOrderNo,
|
||||
remark: balanceForm.remark
|
||||
})
|
||||
balanceDraftSavedAt.value = draft.savedAt
|
||||
message.success('余额变动已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearBalanceDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getBalanceDraftKey())
|
||||
balanceDraftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除余额变动暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const restoreVipDraft = () => {
|
||||
const draft = loadDraftRecord<{
|
||||
vipLevel: string
|
||||
remark: string
|
||||
}>(getVipDraftKey())
|
||||
if (!draft) {
|
||||
vipDraftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(vipForm, draft.payload)
|
||||
vipDraftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复 VIP 暂存')
|
||||
}
|
||||
|
||||
const handleSaveVipDraft = () => {
|
||||
const draft = saveDraftRecord(getVipDraftKey(), {
|
||||
vipLevel: vipForm.vipLevel,
|
||||
remark: vipForm.remark || ''
|
||||
})
|
||||
vipDraftSavedAt.value = draft.savedAt
|
||||
message.success('VIP 设置已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearVipDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getVipDraftKey())
|
||||
vipDraftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除 VIP 暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const formRules = {
|
||||
account: [
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||
@@ -675,6 +766,43 @@ const resetFormState = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-users', isEdit.value ? 'edit' : 'create', currentUser.value?.id ?? 'new')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
account: formState.account,
|
||||
nickname: formState.nickname,
|
||||
phone: formState.phone,
|
||||
password: formState.password,
|
||||
type: formState.type,
|
||||
shopIds: [...formState.shopIds]
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey(), 'session')
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
|
||||
Object.assign(formState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload(), 'session')
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到当前会话')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey(), 'session')
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
pagination.current = 1
|
||||
void fetchUserList()
|
||||
@@ -690,6 +818,7 @@ const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
currentUser.value = null
|
||||
resetFormState()
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -704,6 +833,7 @@ const showEditModal = (record: any) => {
|
||||
type: record.type,
|
||||
shopIds: resolveEditableShopIds(record)
|
||||
})
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -746,6 +876,8 @@ const showAssetModal = async (record: any) => {
|
||||
try {
|
||||
await loadUserAssetData(record.id)
|
||||
resetAssetForms()
|
||||
restoreBalanceDraft()
|
||||
restoreVipDraft()
|
||||
} catch (error) {
|
||||
console.error('获取用户资产失败:', error)
|
||||
message.error('获取用户资产失败')
|
||||
@@ -789,6 +921,7 @@ const handleModalOk = async () => {
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
await fetchUserList()
|
||||
@@ -892,6 +1025,7 @@ const handleBalanceChange = async () => {
|
||||
remark: balanceForm.remark?.trim() || undefined
|
||||
})
|
||||
message.success('余额变动已保存')
|
||||
handleClearBalanceDraft(false)
|
||||
Object.assign(balanceForm, {
|
||||
amount: undefined,
|
||||
relatedOrderId: undefined,
|
||||
@@ -918,6 +1052,7 @@ const handleVipOverride = async () => {
|
||||
remark: vipForm.remark?.trim() || undefined
|
||||
})
|
||||
message.success('VIP 已更新')
|
||||
handleClearVipDraft(false)
|
||||
vipForm.remark = ''
|
||||
await refreshAssetPanel()
|
||||
} catch (error: any) {
|
||||
@@ -940,6 +1075,7 @@ const handleVipRecalculate = () => {
|
||||
try {
|
||||
await adminUserApi.recalculateUserVip(assetTargetUser.value!.id)
|
||||
message.success('已恢复自动判级')
|
||||
handleClearVipDraft(false)
|
||||
vipForm.remark = ''
|
||||
await refreshAssetPanel()
|
||||
} catch (error: any) {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
# 2026-03-26 编辑表单前端暂存功能
|
||||
|
||||
## 本次调整
|
||||
|
||||
- 为前端主要编辑表单统一增加“暂存”能力。
|
||||
- 暂存仅保存在当前浏览器端,不写入后端数据库。
|
||||
- 表单提交成功后会自动清除对应暂存。
|
||||
- 重新打开同一编辑表单时,会自动恢复上次暂存内容。
|
||||
|
||||
## 草稿能力设计
|
||||
|
||||
- 新增公共草稿工具:
|
||||
- [form-draft.ts](/E:/code/xiaowang/Frontend/src/utils/form-draft.ts)
|
||||
- 统一处理草稿 key、保存、读取、清除。
|
||||
|
||||
- 新增统一按钮条组件:
|
||||
- [DraftActions.vue](/E:/code/xiaowang/Frontend/src/components/DraftActions.vue)
|
||||
- 提供:
|
||||
- `暂存`
|
||||
- `清除暂存`
|
||||
- 上次暂存时间显示
|
||||
|
||||
- 敏感表单处理策略:
|
||||
- 普通资料类表单使用 `localStorage`
|
||||
- 含密码、验证码等敏感字段的表单使用 `sessionStorage`
|
||||
- 这样既满足前端暂存,又避免把敏感信息长期落在本地持久存储里。
|
||||
|
||||
## 已接入的编辑表单
|
||||
|
||||
- 后台:
|
||||
- [UsersView.vue](/E:/code/xiaowang/Frontend/src/views/admin/UsersView.vue)
|
||||
- 用户新增/编辑
|
||||
- 余额变动
|
||||
- VIP 手工设置
|
||||
- [TagsView.vue](/E:/code/xiaowang/Frontend/src/views/admin/TagsView.vue)
|
||||
- [ShopsView.vue](/E:/code/xiaowang/Frontend/src/views/admin/ShopsView.vue)
|
||||
- [ProductsView.vue](/E:/code/xiaowang/Frontend/src/views/admin/ProductsView.vue)
|
||||
- [CouponsView.vue](/E:/code/xiaowang/Frontend/src/views/admin/CouponsView.vue)
|
||||
- [NailArtistsView.vue](/E:/code/xiaowang/Frontend/src/views/admin/NailArtistsView.vue)
|
||||
- [PermissionsView.vue](/E:/code/xiaowang/Frontend/src/views/admin/PermissionsView.vue)
|
||||
|
||||
- 前台:
|
||||
- [ProfileView.vue](/E:/code/xiaowang/Frontend/src/views/ProfileView.vue)
|
||||
- [AccountSettingsView.vue](/E:/code/xiaowang/Frontend/src/views/AccountSettingsView.vue)
|
||||
- 绑定手机号
|
||||
- 修改手机号
|
||||
- 修改密码
|
||||
- [PasswordSettingsView.vue](/E:/code/xiaowang/Frontend/src/views/PasswordSettingsView.vue)
|
||||
|
||||
## 交互说明
|
||||
|
||||
- 点击“暂存”后会在当前浏览器保存草稿。
|
||||
- 重新打开同一表单时,如果存在草稿,会自动恢复并提示。
|
||||
- 点击“清除暂存”只清除本地草稿,不会直接改动当前后端数据。
|
||||
- 表单提交成功后,会自动删除对应暂存,避免下次误恢复旧内容。
|
||||
- 对带图片上传的表单,上传未完成前不允许暂存,避免把半上传状态写入草稿。
|
||||
|
||||
## 构建验证
|
||||
|
||||
- 已执行前端构建:`npm run build`
|
||||
- 构建通过。
|
||||
|
||||
## 数据库
|
||||
|
||||
- 本轮无 SQL 变更。
|
||||
Reference in New Issue
Block a user