功能:完善门店能力与用户安全配置
This commit is contained in:
@@ -445,6 +445,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* UsersView page script.
|
||||
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
|
||||
*/
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
@@ -476,6 +480,7 @@ import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
const { hasPermission, hasAnyPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
/** currentUserInfo is a local helper used by this page script. */
|
||||
const currentUserInfo = (() => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
@@ -486,17 +491,25 @@ const currentUserInfo = (() => {
|
||||
}
|
||||
})()
|
||||
|
||||
/** normalizeUserType is a local helper used by this page script. */
|
||||
const normalizeUserType = (value: unknown) => {
|
||||
const type = Number(value)
|
||||
return Number.isFinite(type) ? type : -1
|
||||
}
|
||||
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** shopLoading is a reactive state variable used by the template and event handlers. */
|
||||
const shopLoading = ref(false)
|
||||
/** modalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const modalVisible = ref(false)
|
||||
/** modalLoading is a reactive state variable used by the template and event handlers. */
|
||||
const modalLoading = ref(false)
|
||||
/** viewModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const viewModalVisible = ref(false)
|
||||
/** isEdit is a reactive state variable used by the template and event handlers. */
|
||||
const isEdit = ref(false)
|
||||
/** searchText is a reactive state variable used by the template and event handlers. */
|
||||
const searchText = ref('')
|
||||
const formRef = ref<FormInstance>()
|
||||
const userList = ref<UserVO[]>([])
|
||||
@@ -505,8 +518,11 @@ const currentUser = ref<UserVO | null>(null)
|
||||
const viewRecord = ref<UserVO | null>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
/** assetModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const assetModalVisible = ref(false)
|
||||
/** assetLoading is a reactive state variable used by the template and event handlers. */
|
||||
const assetLoading = ref(false)
|
||||
/** assetSaving is a reactive state variable used by the template and event handlers. */
|
||||
const assetSaving = ref(false)
|
||||
const assetTargetUser = ref<UserVO | null>(null)
|
||||
const assetData = ref<UserAssetVO | null>(null)
|
||||
@@ -514,10 +530,13 @@ const balanceHistory = ref<UserBalanceHistoryItem[]>([])
|
||||
const balanceDraftSavedAt = ref<number | null>(null)
|
||||
const vipDraftSavedAt = ref<number | null>(null)
|
||||
|
||||
/** canOpenAssetPanel is a reactive state variable used by the template and event handlers. */
|
||||
const canOpenAssetPanel = computed(() =>
|
||||
hasAnyPermission(['user:balance:view', 'user:balance:manage', 'user:vip:manage'])
|
||||
)
|
||||
/** currentUserType is a reactive state variable used by the template and event handlers. */
|
||||
const currentUserType = computed(() => normalizeUserType(currentUserInfo?.type))
|
||||
/** availableUserTypeOptions is a reactive state variable used by the template and event handlers. */
|
||||
const availableUserTypeOptions = computed(() => {
|
||||
if (currentUserType.value === 4) {
|
||||
return [
|
||||
@@ -540,12 +559,15 @@ const availableUserTypeOptions = computed(() => {
|
||||
}
|
||||
return []
|
||||
})
|
||||
/** canCreateUser is a reactive state variable used by the template and event handlers. */
|
||||
const canCreateUser = computed(() =>
|
||||
hasPermission('user:create') || currentUserType.value === 2 || currentUserType.value === 4
|
||||
)
|
||||
/** canDeleteUser is a reactive state variable used by the template and event handlers. */
|
||||
const canDeleteUser = computed(() =>
|
||||
currentUserType.value === 4 && hasPermission('user:delete')
|
||||
)
|
||||
/** canUnbindUser is a reactive state variable used by the template and event handlers. */
|
||||
const canUnbindUser = computed(() =>
|
||||
hasPermission('user:unbind')
|
||||
)
|
||||
@@ -569,6 +591,7 @@ const formState = reactive({
|
||||
shopIds: [] as string[]
|
||||
})
|
||||
|
||||
/** handleAccountInput is a local helper used by this page script. */
|
||||
const handleAccountInput = () => {
|
||||
const normalized = sanitizeAccountInput(formState.account)
|
||||
if (normalized !== formState.account) {
|
||||
@@ -576,6 +599,7 @@ const handleAccountInput = () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handlePhoneInput is a local helper used by this page script. */
|
||||
const handlePhoneInput = () => {
|
||||
const normalized = formState.phone.replace(/\D/g, '').slice(0, 11)
|
||||
if (normalized !== formState.phone) {
|
||||
@@ -583,6 +607,7 @@ const handlePhoneInput = () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** validatePhoneUniqueness is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const validatePhoneUniqueness = async (value: string) => {
|
||||
const normalized = value?.trim()
|
||||
if (!normalized) {
|
||||
@@ -620,9 +645,12 @@ const vipForm = reactive<AdminUserVipOverrideRequest>({
|
||||
remark: ''
|
||||
})
|
||||
|
||||
/** getBalanceDraftKey is a local helper used by this page script. */
|
||||
const getBalanceDraftKey = () => buildDraftStorageKey('admin-user-assets', 'balance', assetTargetUser.value?.id ?? 'unknown')
|
||||
/** getVipDraftKey is a local helper used by this page script. */
|
||||
const getVipDraftKey = () => buildDraftStorageKey('admin-user-assets', 'vip', assetTargetUser.value?.id ?? 'unknown')
|
||||
|
||||
/** restoreBalanceDraft is a local helper used by this page script. */
|
||||
const restoreBalanceDraft = () => {
|
||||
const draft = loadDraftRecord<{
|
||||
changeScene: string
|
||||
@@ -640,6 +668,7 @@ const restoreBalanceDraft = () => {
|
||||
message.success('已恢复余额变动暂存')
|
||||
}
|
||||
|
||||
/** handleSaveBalanceDraft is a local helper used by this page script. */
|
||||
const handleSaveBalanceDraft = () => {
|
||||
const draft = saveDraftRecord(getBalanceDraftKey(), {
|
||||
changeScene: balanceForm.changeScene,
|
||||
@@ -652,6 +681,7 @@ const handleSaveBalanceDraft = () => {
|
||||
message.success('余额变动已暂存到本地')
|
||||
}
|
||||
|
||||
/** handleClearBalanceDraft is a local helper used by this page script. */
|
||||
const handleClearBalanceDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getBalanceDraftKey())
|
||||
balanceDraftSavedAt.value = null
|
||||
@@ -660,6 +690,7 @@ const handleClearBalanceDraft = (showMessage = true) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** restoreVipDraft is a local helper used by this page script. */
|
||||
const restoreVipDraft = () => {
|
||||
const draft = loadDraftRecord<{
|
||||
vipLevel: string
|
||||
@@ -674,6 +705,7 @@ const restoreVipDraft = () => {
|
||||
message.success('已恢复 VIP 暂存')
|
||||
}
|
||||
|
||||
/** handleSaveVipDraft is a local helper used by this page script. */
|
||||
const handleSaveVipDraft = () => {
|
||||
const draft = saveDraftRecord(getVipDraftKey(), {
|
||||
vipLevel: vipForm.vipLevel,
|
||||
@@ -683,6 +715,7 @@ const handleSaveVipDraft = () => {
|
||||
message.success('VIP 设置已暂存到本地')
|
||||
}
|
||||
|
||||
/** handleClearVipDraft is a local helper used by this page script. */
|
||||
const handleClearVipDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getVipDraftKey())
|
||||
vipDraftSavedAt.value = null
|
||||
@@ -742,6 +775,7 @@ const historyColumns = [
|
||||
{ title: '时间', key: 'changeTime', width: 180 }
|
||||
]
|
||||
|
||||
/** getUserTypeText is a local helper used by this page script. */
|
||||
const getUserTypeText = (type: number) => {
|
||||
const map: Record<number, string> = {
|
||||
0: '用户',
|
||||
@@ -752,6 +786,7 @@ const getUserTypeText = (type: number) => {
|
||||
return map[type] || '未知'
|
||||
}
|
||||
|
||||
/** getUserTypeColor is a local helper used by this page script. */
|
||||
const getUserTypeColor = (type: number) => {
|
||||
const map: Record<number, string> = {
|
||||
0: 'default',
|
||||
@@ -762,6 +797,7 @@ const getUserTypeColor = (type: number) => {
|
||||
return map[type] || 'default'
|
||||
}
|
||||
|
||||
/** canShowDelete is a local helper used by this page script. */
|
||||
const canShowDelete = (record: Partial<UserVO> | Record<string, any>) => {
|
||||
if (!canDeleteUser.value) {
|
||||
return false
|
||||
@@ -772,6 +808,7 @@ const canShowDelete = (record: Partial<UserVO> | Record<string, any>) => {
|
||||
return String(record.id) !== String(currentUserInfo?.id ?? '')
|
||||
}
|
||||
|
||||
/** canShowUnbind is a local helper used by this page script. */
|
||||
const canShowUnbind = (record: Partial<UserVO> | Record<string, any>) => {
|
||||
if (!canUnbindUser.value) {
|
||||
return false
|
||||
@@ -779,6 +816,7 @@ const canShowUnbind = (record: Partial<UserVO> | Record<string, any>) => {
|
||||
return record.type !== 4
|
||||
}
|
||||
|
||||
/** getUnbindConfirmText is a local helper used by this page script. */
|
||||
const getUnbindConfirmText = (record: Partial<UserVO> | Record<string, any>) => {
|
||||
if (currentUserType.value === 2 && record.type === 3) {
|
||||
return '确定要解绑该美甲师与当前店铺的关系吗?解绑后该账号会同步降级为普通用户。'
|
||||
@@ -786,6 +824,7 @@ const getUnbindConfirmText = (record: Partial<UserVO> | Record<string, any>) =>
|
||||
return '确定要解绑该用户与当前店铺的关系吗?'
|
||||
}
|
||||
|
||||
/** getSceneText is a local helper used by this page script. */
|
||||
const getSceneText = (scene?: string) => {
|
||||
const map: Record<string, string> = {
|
||||
RECHARGE: '充值',
|
||||
@@ -797,6 +836,7 @@ const getSceneText = (scene?: string) => {
|
||||
return scene ? map[scene] || scene : '-'
|
||||
}
|
||||
|
||||
/** formatMoney is a local helper used by this page script. */
|
||||
const formatMoney = (value?: number | string | null) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return '0.00'
|
||||
@@ -804,6 +844,7 @@ const formatMoney = (value?: number | string | null) => {
|
||||
return Number(value).toFixed(2)
|
||||
}
|
||||
|
||||
/** formatDate is a local helper used by this page script. */
|
||||
const formatDate = (value?: string) => {
|
||||
if (!value) {
|
||||
return '-'
|
||||
@@ -811,6 +852,7 @@ const formatDate = (value?: string) => {
|
||||
return value.replace('T', ' ').slice(0, 19)
|
||||
}
|
||||
|
||||
/** filterVisibleUsers is a local helper used by this page script. */
|
||||
const filterVisibleUsers = (list: UserVO[]) => {
|
||||
if (!currentUserInfo || currentUserType.value === 4) {
|
||||
return list
|
||||
@@ -824,6 +866,7 @@ const filterVisibleUsers = (list: UserVO[]) => {
|
||||
return list
|
||||
}
|
||||
|
||||
/** normalizeShopId is a local helper used by this page script. */
|
||||
const normalizeShopId = (value: unknown) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return undefined
|
||||
@@ -831,8 +874,10 @@ const normalizeShopId = (value: unknown) => {
|
||||
return String(value)
|
||||
}
|
||||
|
||||
/** getShopOptionValue is a local helper used by this page script. */
|
||||
const getShopOptionValue = (shop: Shop) => normalizeShopId((shop as any).id) || ''
|
||||
|
||||
/** getShopNameById is a local helper used by this page script. */
|
||||
const getShopNameById = (shopId?: string | number | null) => {
|
||||
const targetShopId = normalizeShopId(shopId)
|
||||
if (!targetShopId) {
|
||||
@@ -842,6 +887,7 @@ const getShopNameById = (shopId?: string | number | null) => {
|
||||
return matchedShop?.shopName || ''
|
||||
}
|
||||
|
||||
/** getShopDisplay is a local helper used by this page script. */
|
||||
const getShopDisplay = (user?: Partial<UserVO> | Record<string, any> | null) => {
|
||||
if (!user) {
|
||||
return ''
|
||||
@@ -861,6 +907,7 @@ const getShopDisplay = (user?: Partial<UserVO> | Record<string, any> | null) =>
|
||||
return getShopNameById(user.shopId) || ''
|
||||
}
|
||||
|
||||
/** resolveEditableShopIds is a local helper used by this page script. */
|
||||
const resolveEditableShopIds = (user?: UserVO | null) => {
|
||||
const sourceIds = user?.shopIds?.length
|
||||
? user.shopIds
|
||||
@@ -879,6 +926,7 @@ const resolveEditableShopIds = (user?: UserVO | null) => {
|
||||
: []
|
||||
}
|
||||
|
||||
/** fetchShopList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchShopList = async () => {
|
||||
shopLoading.value = true
|
||||
try {
|
||||
@@ -894,6 +942,7 @@ const fetchShopList = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchUserList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchUserList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -919,6 +968,7 @@ const fetchUserList = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** resetFormState is a local helper used by this page script. */
|
||||
const resetFormState = () => {
|
||||
Object.assign(formState, {
|
||||
account: '',
|
||||
@@ -932,8 +982,10 @@ const resetFormState = () => {
|
||||
})
|
||||
}
|
||||
|
||||
/** getDraftKey is a local helper used by this page script. */
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-users', isEdit.value ? 'edit' : 'create', currentUser.value?.id ?? 'new')
|
||||
|
||||
/** buildDraftPayload is a local helper used by this page script. */
|
||||
const buildDraftPayload = () => ({
|
||||
account: formState.account,
|
||||
nickname: formState.nickname,
|
||||
@@ -943,6 +995,7 @@ const buildDraftPayload = () => ({
|
||||
shopIds: [...formState.shopIds]
|
||||
})
|
||||
|
||||
/** restoreDraft is a local helper used by this page script. */
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey(), 'session')
|
||||
if (!draft) {
|
||||
@@ -955,12 +1008,14 @@ const restoreDraft = () => {
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/** handleSaveDraft is a local helper used by this page script. */
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload(), 'session')
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到当前会话')
|
||||
}
|
||||
|
||||
/** handleClearDraft is a local helper used by this page script. */
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey(), 'session')
|
||||
draftSavedAt.value = null
|
||||
@@ -969,17 +1024,20 @@ const handleClearDraft = (showMessage = true) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleSearch is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleSearch = async () => {
|
||||
pagination.current = 1
|
||||
await runWithGlobalLoading(() => fetchUserList())
|
||||
}
|
||||
|
||||
/** handleTableChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleTableChange = async (pag: any) => {
|
||||
pagination.current = pag.current || 1
|
||||
pagination.pageSize = pag.pageSize || pagination.pageSize
|
||||
await runWithGlobalLoading(() => fetchUserList())
|
||||
}
|
||||
|
||||
/** showAddModal is a local helper used by this page script. */
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
currentUser.value = null
|
||||
@@ -988,6 +1046,7 @@ const showAddModal = () => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showEditModal is a local helper used by this page script. */
|
||||
const showEditModal = (record: any) => {
|
||||
isEdit.value = true
|
||||
currentUser.value = record
|
||||
@@ -1003,11 +1062,13 @@ const showEditModal = (record: any) => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showViewModal is a local helper used by this page script. */
|
||||
const showViewModal = (record: any) => {
|
||||
viewRecord.value = record
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
/** loadUserAssetData is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadUserAssetData = async (userId: IdType) => {
|
||||
const [asset, history] = await Promise.all([
|
||||
adminUserApi.getUserAsset(userId),
|
||||
@@ -1018,6 +1079,7 @@ const loadUserAssetData = async (userId: IdType) => {
|
||||
vipForm.vipLevel = asset.vipLevel || '普通'
|
||||
}
|
||||
|
||||
/** resetAssetForms is a local helper used by this page script. */
|
||||
const resetAssetForms = () => {
|
||||
Object.assign(balanceForm, {
|
||||
changeScene: 'RECHARGE',
|
||||
@@ -1032,6 +1094,7 @@ const resetAssetForms = () => {
|
||||
})
|
||||
}
|
||||
|
||||
/** showAssetModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const showAssetModal = async (record: any) => {
|
||||
assetTargetUser.value = record
|
||||
assetModalVisible.value = true
|
||||
@@ -1052,6 +1115,7 @@ const showAssetModal = async (record: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleAssetModalCancel is a local helper used by this page script. */
|
||||
const handleAssetModalCancel = () => {
|
||||
assetModalVisible.value = false
|
||||
assetTargetUser.value = null
|
||||
@@ -1060,6 +1124,7 @@ const handleAssetModalCancel = () => {
|
||||
resetAssetForms()
|
||||
}
|
||||
|
||||
/** handleModalOk is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
@@ -1101,12 +1166,14 @@ const handleModalOk = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleModalCancel is a local helper used by this page script. */
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
resetFormState()
|
||||
}
|
||||
|
||||
/** handleStatusChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleStatusChange = async (record: any, checked: boolean) => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
@@ -1125,6 +1192,7 @@ const handleStatusChange = async (record: any, checked: boolean) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleResetPassword is a local helper used by this page script. */
|
||||
const handleResetPassword = (record: any) => {
|
||||
Modal.confirm({
|
||||
title: '确认重置密码',
|
||||
@@ -1143,6 +1211,7 @@ const handleResetPassword = (record: any) => {
|
||||
})
|
||||
}
|
||||
|
||||
/** handleDelete is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleDelete = async (record: any) => {
|
||||
try {
|
||||
if (record.type === 4) {
|
||||
@@ -1167,6 +1236,7 @@ const handleDelete = async (record: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleUnbind is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleUnbind = async (record: any) => {
|
||||
try {
|
||||
if (record.type === 4) {
|
||||
@@ -1195,6 +1265,7 @@ const handleUnbind = async (record: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** refreshAssetPanel is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const refreshAssetPanel = async () => {
|
||||
if (!assetTargetUser.value) {
|
||||
return
|
||||
@@ -1212,6 +1283,7 @@ const refreshAssetPanel = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleBalanceChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleBalanceChange = async () => {
|
||||
if (!assetTargetUser.value) {
|
||||
return
|
||||
@@ -1258,6 +1330,7 @@ const handleBalanceChange = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleVipOverride is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleVipOverride = async () => {
|
||||
if (!assetTargetUser.value) {
|
||||
return
|
||||
@@ -1283,6 +1356,7 @@ const handleVipOverride = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleVipRecalculate is a local helper used by this page script. */
|
||||
const handleVipRecalculate = () => {
|
||||
if (!assetTargetUser.value) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user