功能:完善门店能力与用户安全配置
This commit is contained in:
@@ -200,6 +200,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* AdminLayout 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, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
@@ -245,11 +249,14 @@ const router = useRouter()
|
||||
const route = useRoute()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
/** collapsed is a reactive state variable used by the template and event handlers. */
|
||||
const collapsed = ref(false)
|
||||
/** mobileDrawerOpen is a reactive state variable used by the template and event handlers. */
|
||||
const mobileDrawerOpen = ref(false)
|
||||
const userInfo = ref<UserVO | null>(null)
|
||||
const selectedKeys = ref<string[]>([route.path])
|
||||
const selectedShopId = ref<string>()
|
||||
/** shopSwitchLoading is a reactive state variable used by the template and event handlers. */
|
||||
const shopSwitchLoading = ref(false)
|
||||
const { loadUserPermissions, hasPermission, clearPermissions, userPermissions } = usePermission()
|
||||
|
||||
@@ -265,6 +272,12 @@ const menuItems: AdminMenuItem[] = [
|
||||
{ key: '/admin/tags', icon: TagOutlined, label: '标签管理', permissionCode: 'tag:view' },
|
||||
{ key: '/admin/orders', icon: ShoppingOutlined, label: '订单管理', permissionCode: 'order:view' },
|
||||
{ key: '/admin/nail-artists', icon: TeamOutlined, label: '美甲师管理', permissionCode: 'nail_artist:view' }
|
||||
,
|
||||
{ key: '/admin/messages', icon: MessageOutlined, label: '消息发布', permissionCode: 'message:view' },
|
||||
{ key: '/admin/announcements', icon: MessageOutlined, label: '公告管理', permissionCode: 'announcement:view' },
|
||||
{ key: '/admin/vip-recharge-plans', icon: GiftOutlined, label: 'VIP充值配置', permissionCode: 'user:vip:manage' },
|
||||
{ key: '/admin/messagehub-push-configs', icon: MessageOutlined, label: '参数管理', permissionCode: 'messagehub:config:manage' },
|
||||
{ key: '/admin/legal-agreements', icon: SafetyCertificateOutlined, label: '协议管理', permissionCode: 'legal_agreement:manage' }
|
||||
]
|
||||
|
||||
const mobileTabs = [
|
||||
@@ -274,11 +287,19 @@ const mobileTabs = [
|
||||
{ key: 'profile', label: '我的', path: '/admin/profile', icon: UserOutlined }
|
||||
]
|
||||
|
||||
/** isBootstrapAdmin is a reactive state variable used by the template and event handlers. */
|
||||
const isBootstrapAdmin = computed(() => isBootstrapAdminUser(userInfo.value))
|
||||
/** isShopAuthorizationExpired is a reactive state variable used by the template and event handlers. */
|
||||
const isShopAuthorizationExpired = computed(() => Boolean(userInfo.value?.shopAuthorizationExpired))
|
||||
/** shopOptions is a reactive state variable used by the template and event handlers. */
|
||||
const shopOptions = computed(() => getAdminShopOptions(userInfo.value))
|
||||
/** shopSelectOptions is a reactive state variable used by the template and event handlers. */
|
||||
const shopSelectOptions = computed(() => shopOptions.value.map(shop => ({ label: shop.name, value: shop.id })))
|
||||
/** currentShopName is a reactive state variable used by the template and event handlers. */
|
||||
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
|
||||
/** roleLabel is a reactive state variable used by the template and event handlers. */
|
||||
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
|
||||
/** shopScopeText is a reactive state variable used by the template and event handlers. */
|
||||
const shopScopeText = computed(() => {
|
||||
if (!shopOptions.value.length) {
|
||||
return '游客模式'
|
||||
@@ -286,6 +307,7 @@ const shopScopeText = computed(() => {
|
||||
return `可登录门店:${shopOptions.value.map(shop => shop.name).join(' / ')}`
|
||||
})
|
||||
|
||||
/** filteredMenuItems is a reactive state variable used by the template and event handlers. */
|
||||
const filteredMenuItems = computed(() => {
|
||||
userPermissions.value
|
||||
let visibleItems = menuItems.filter(item => {
|
||||
@@ -300,9 +322,13 @@ const filteredMenuItems = computed(() => {
|
||||
if (isBootstrapAdmin.value) {
|
||||
visibleItems = visibleItems.filter(item => item.key === '/admin' || item.key === '/admin/shops')
|
||||
}
|
||||
if (isShopAuthorizationExpired.value && userInfo.value?.type !== 4) {
|
||||
visibleItems = visibleItems.filter(item => item.key === '/admin')
|
||||
}
|
||||
return visibleItems
|
||||
})
|
||||
|
||||
/** activeMobileTab is a reactive state variable used by the template and event handlers. */
|
||||
const activeMobileTab = computed(() => {
|
||||
if (route.path === '/admin' || route.path === '/admin/dashboard') {
|
||||
return 'workbench'
|
||||
@@ -329,6 +355,7 @@ const activeMobileTab = computed(() => {
|
||||
return 'workbench'
|
||||
})
|
||||
|
||||
/** currentMobileSectionLabel is a reactive state variable used by the template and event handlers. */
|
||||
const currentMobileSectionLabel = computed(() => {
|
||||
switch (activeMobileTab.value) {
|
||||
case 'orders':
|
||||
@@ -342,6 +369,7 @@ const currentMobileSectionLabel = computed(() => {
|
||||
}
|
||||
})
|
||||
|
||||
/** currentMobileTitle is a reactive state variable used by the template and event handlers. */
|
||||
const currentMobileTitle = computed(() => {
|
||||
const currentMenu = menuItems.find(item => item.key === route.path)
|
||||
if (currentMenu) {
|
||||
@@ -356,6 +384,7 @@ const currentMobileTitle = computed(() => {
|
||||
return '后台管理'
|
||||
})
|
||||
|
||||
/** persistAdminSession is a local helper used by this page script. */
|
||||
const persistAdminSession = (payload: any) => {
|
||||
localStorage.setItem('adminAccessToken', payload.accessToken)
|
||||
localStorage.setItem('adminRefreshToken', payload.refreshToken)
|
||||
@@ -363,29 +392,47 @@ const persistAdminSession = (payload: any) => {
|
||||
sessionStorage.setItem('adminAccessToken', payload.accessToken)
|
||||
}
|
||||
|
||||
/** toggleCollapsed is a local helper used by this page script. */
|
||||
const toggleCollapsed = () => {
|
||||
collapsed.value = !collapsed.value
|
||||
}
|
||||
|
||||
/** handleMenuClick is a local helper used by this page script. */
|
||||
const handleMenuClick = (info: any) => {
|
||||
if (isShopAuthorizationExpired.value && userInfo.value?.type !== 4 && info.key !== '/admin') {
|
||||
message.warning('授权已到期,请联系管理员')
|
||||
return
|
||||
}
|
||||
router.push(info.key)
|
||||
}
|
||||
|
||||
/** openPathFromDrawer is a local helper used by this page script. */
|
||||
const openPathFromDrawer = (path: string) => {
|
||||
if (isShopAuthorizationExpired.value && userInfo.value?.type !== 4 && path !== '/admin' && path !== '/admin/profile') {
|
||||
message.warning('授权已到期,请联系管理员')
|
||||
return
|
||||
}
|
||||
mobileDrawerOpen.value = false
|
||||
router.push(path)
|
||||
}
|
||||
|
||||
/** openProfileFromDrawer is a local helper used by this page script. */
|
||||
const openProfileFromDrawer = () => {
|
||||
openPathFromDrawer('/admin/profile')
|
||||
}
|
||||
|
||||
/** handleMobileTabClick is a local helper used by this page script. */
|
||||
const handleMobileTabClick = (path: string) => {
|
||||
if (isShopAuthorizationExpired.value && userInfo.value?.type !== 4 && path !== '/admin' && path !== '/admin/profile') {
|
||||
message.warning('授权已到期,请联系管理员')
|
||||
return
|
||||
}
|
||||
if (route.path !== path) {
|
||||
router.push(path)
|
||||
}
|
||||
}
|
||||
|
||||
/** handleLogout is a local helper used by this page script. */
|
||||
const handleLogout = () => {
|
||||
Modal.confirm({
|
||||
title: '确认退出登录',
|
||||
@@ -416,6 +463,7 @@ const handleLogout = () => {
|
||||
})
|
||||
}
|
||||
|
||||
/** fetchUserInfo is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const cache = localStorage.getItem('adminUserInfo')
|
||||
@@ -431,6 +479,7 @@ const fetchUserInfo = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleShopChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleShopChange = async (shopId: unknown) => {
|
||||
if (typeof shopId !== 'string' && typeof shopId !== 'number') {
|
||||
return
|
||||
|
||||
@@ -77,6 +77,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* AdminLoginView 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, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { message } from 'ant-design-vue'
|
||||
@@ -90,10 +94,14 @@ import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
/** 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)
|
||||
const shops = ref<Array<{ id: IdType; shopName: string }>>([])
|
||||
/** allowShoplessLogin is a reactive state variable used by the template and event handlers. */
|
||||
const allowShoplessLogin = ref(false)
|
||||
/** loginShopMessage is a reactive state variable used by the template and event handlers. */
|
||||
const loginShopMessage = ref('')
|
||||
const { loadUserPermissions } = usePermission()
|
||||
|
||||
@@ -104,6 +112,7 @@ const formState = reactive({
|
||||
})
|
||||
let loginShopTimer: number | undefined
|
||||
|
||||
/** handleAccountInput is a local helper used by this page script. */
|
||||
const handleAccountInput = () => {
|
||||
const normalized = sanitizeAccountInput(formState.account)
|
||||
if (normalized !== formState.account) {
|
||||
@@ -111,17 +120,23 @@ const handleAccountInput = () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** getShopIdValue is a local helper used by this page script. */
|
||||
const getShopIdValue = (shop: { id: IdType; shopName: string }) => String(shop.id ?? '')
|
||||
/** getShopLabel is a local helper used by this page script. */
|
||||
const getShopLabel = (shop: { id: IdType; shopName: string }) => String(shop.shopName || `店铺 ${shop.id}`)
|
||||
|
||||
/** shopOptions is a reactive state variable used by the template and event handlers. */
|
||||
const shopOptions = computed(() =>
|
||||
shops.value.map(shop => ({
|
||||
label: getShopLabel(shop),
|
||||
value: getShopIdValue(shop)
|
||||
}))
|
||||
)
|
||||
/** hasAvailableShops is a reactive state variable used by the template and event handlers. */
|
||||
const hasAvailableShops = computed(() => shopOptions.value.length > 0)
|
||||
/** shouldRequireShop is a reactive state variable used by the template and event handlers. */
|
||||
const shouldRequireShop = computed(() => hasAvailableShops.value && !allowShoplessLogin.value)
|
||||
/** shopPlaceholder is a reactive state variable used by the template and event handlers. */
|
||||
const shopPlaceholder = computed(() => {
|
||||
if (allowShoplessLogin.value) {
|
||||
return '当前无需选择店铺'
|
||||
@@ -152,14 +167,17 @@ const formRules = {
|
||||
}]
|
||||
} as any
|
||||
|
||||
/** filterShopOption is a local helper used by this page script. */
|
||||
const filterShopOption = (input: string, option: { label?: string | number } | undefined) =>
|
||||
String(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
|
||||
|
||||
/** isLoginShopPrefetchUnsupported is a local helper used by this page script. */
|
||||
const isLoginShopPrefetchUnsupported = (error: unknown) => {
|
||||
const status = (error as any)?.response?.status
|
||||
return status === 404
|
||||
}
|
||||
|
||||
/** resetLoginShopTimer is a local helper used by this page script. */
|
||||
const resetLoginShopTimer = () => {
|
||||
if (loginShopTimer !== undefined) {
|
||||
window.clearTimeout(loginShopTimer)
|
||||
@@ -167,6 +185,7 @@ const resetLoginShopTimer = () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** restoreLoginShop is a local helper used by this page script. */
|
||||
const restoreLoginShop = () => {
|
||||
const cached = localStorage.getItem('adminUserInfo')
|
||||
if (!cached) {
|
||||
@@ -182,6 +201,7 @@ const restoreLoginShop = () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** applyLoginShopSelection is a local helper used by this page script. */
|
||||
const applyLoginShopSelection = (selection?: LoginShopSelectionResponse | null) => {
|
||||
shops.value = selection?.shops || []
|
||||
allowShoplessLogin.value = Boolean(selection?.allowShoplessLogin)
|
||||
@@ -210,6 +230,7 @@ const applyLoginShopSelection = (selection?: LoginShopSelectionResponse | null)
|
||||
formState.shopId = undefined
|
||||
}
|
||||
|
||||
/** loadLoginShops is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadLoginShops = async (account = formState.account) => {
|
||||
const trimmedAccount = account.trim()
|
||||
if (!trimmedAccount) {
|
||||
@@ -244,6 +265,7 @@ const loadLoginShops = async (account = formState.account) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleLogin is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleLogin = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
@@ -304,6 +326,7 @@ onBeforeUnmount(() => {
|
||||
resetLoginShopTimer()
|
||||
})
|
||||
|
||||
/** goToFrontend is a local helper used by this page script. */
|
||||
const goToFrontend = () => {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
<template>
|
||||
<div class="admin-page">
|
||||
<div class="page-head">
|
||||
<div>
|
||||
<h2>公告管理</h2>
|
||||
<p>发布后会在用户首页顶部持续滚动展示。</p>
|
||||
</div>
|
||||
<a-button type="primary" @click="openCreate">发布公告</a-button>
|
||||
</div>
|
||||
|
||||
<a-table :columns="columns" :data-source="announcements" :loading="loading" row-key="id">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'content'">
|
||||
<span class="ellipsis">{{ record.content }}</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 1 ? 'green' : 'default'">{{ record.status === 1 ? '已发布' : '已撤回' }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'action'">
|
||||
<a-space>
|
||||
<a-button size="small" @click="preview(record as AnnouncementVO)">查看</a-button>
|
||||
<a-button v-if="record.status === 1" size="small" danger @click="revoke(record.id)">撤回</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<a-modal v-model:open="formOpen" title="发布公告" @ok="submit" :confirm-loading="saving">
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="标题">
|
||||
<a-input v-model:value="form.title" :maxlength="100" />
|
||||
</a-form-item>
|
||||
<a-form-item label="内容">
|
||||
<a-textarea v-model:value="form.content" :rows="4" :maxlength="1000" />
|
||||
</a-form-item>
|
||||
<a-form-item label="接收范围">
|
||||
<a-select v-model:value="form.targetType" :options="targetOptions" />
|
||||
</a-form-item>
|
||||
<a-form-item v-if="needsShop" label="指定店铺">
|
||||
<a-select v-model:value="form.shopIds" mode="multiple" :options="shopOptions" />
|
||||
</a-form-item>
|
||||
<a-form-item v-if="needsUser" label="指定用户">
|
||||
<a-select v-model:value="form.userIds" mode="multiple" show-search option-filter-prop="label" :options="userOptions" />
|
||||
</a-form-item>
|
||||
<a-form-item label="排序">
|
||||
<a-input-number v-model:value="form.sortOrder" style="width: 100%" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* AnnouncementsView 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 { adminAnnouncementApi, type AnnouncementVO, type MessageTargetOptionsVO } from '@/api/admin'
|
||||
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** saving is a reactive state variable used by the template and event handlers. */
|
||||
const saving = ref(false)
|
||||
/** formOpen is a reactive state variable used by the template and event handlers. */
|
||||
const formOpen = ref(false)
|
||||
const announcements = ref<AnnouncementVO[]>([])
|
||||
const options = ref<MessageTargetOptionsVO>({ shops: [], users: [] })
|
||||
const form = reactive<any>({ title: '', content: '', targetType: 'PLATFORM_ALL', shopIds: [], userIds: [], sortOrder: 0 })
|
||||
|
||||
const columns = [
|
||||
{ title: '标题', dataIndex: 'title', key: 'title' },
|
||||
{ title: '内容', dataIndex: 'content', key: 'content' },
|
||||
{ title: '发布人', dataIndex: 'publisherName', key: 'publisherName' },
|
||||
{ title: '范围', dataIndex: 'targetTypeName', key: 'targetTypeName' },
|
||||
{ title: '状态', dataIndex: 'status', key: 'status' },
|
||||
{ title: '发布时间', dataIndex: 'publishTime', key: 'publishTime' },
|
||||
{ title: '操作', key: 'action', width: 150 }
|
||||
]
|
||||
|
||||
const targetOptions = [
|
||||
{ label: '全平台', value: 'PLATFORM_ALL' },
|
||||
{ label: '当前门店全部用户', value: 'CURRENT_SHOP_ALL' },
|
||||
{ label: '指定门店全部用户', value: 'SELECTED_SHOPS' },
|
||||
{ label: '指定用户', value: 'SELECTED_USERS' }
|
||||
]
|
||||
/** shopOptions is a reactive state variable used by the template and event handlers. */
|
||||
const shopOptions = computed(() => options.value.shops.map(item => ({ label: item.shopName, value: item.id })))
|
||||
/** userOptions is a reactive state variable used by the template and event handlers. */
|
||||
const userOptions = computed(() => options.value.users.map(item => ({ label: `${item.nickname || item.account} ${item.shopName ? `(${item.shopName})` : ''}`, value: item.id })))
|
||||
/** needsShop is a reactive state variable used by the template and event handlers. */
|
||||
const needsShop = computed(() => ['SHOP_ALL', 'SELECTED_SHOPS'].includes(form.targetType))
|
||||
/** needsUser is a reactive state variable used by the template and event handlers. */
|
||||
const needsUser = computed(() => form.targetType === 'SELECTED_USERS')
|
||||
|
||||
/** load is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const load = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const [list, target] = await Promise.all([
|
||||
adminAnnouncementApi.listAnnouncements(),
|
||||
adminAnnouncementApi.getTargetOptions().catch(() => ({ shops: [], users: [] }))
|
||||
])
|
||||
announcements.value = list || []
|
||||
options.value = target
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** openCreate is a local helper used by this page script. */
|
||||
const openCreate = () => {
|
||||
Object.assign(form, { title: '', content: '', targetType: 'PLATFORM_ALL', shopIds: [], userIds: [], sortOrder: 0 })
|
||||
formOpen.value = true
|
||||
}
|
||||
|
||||
/** submit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const submit = async () => {
|
||||
if (!form.title || !form.content) {
|
||||
message.warning('请填写标题和内容')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
await adminAnnouncementApi.createAnnouncement(form)
|
||||
message.success('公告已发布')
|
||||
formOpen.value = false
|
||||
await load()
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** preview is a local helper used by this page script. */
|
||||
const preview = (record: AnnouncementVO) => {
|
||||
Modal.info({ title: record.title, content: record.content })
|
||||
}
|
||||
|
||||
/** revoke is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const revoke = async (id: any) => {
|
||||
await adminAnnouncementApi.revokeAnnouncement(id)
|
||||
message.success('公告已撤回')
|
||||
await load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-page { display: grid; gap: 18px; }
|
||||
.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
|
||||
.page-head h2 { margin: 0 0 4px; }
|
||||
.page-head p { margin: 0; color: #7a6f68; }
|
||||
.ellipsis { display: inline-block; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
|
||||
</style>
|
||||
@@ -33,12 +33,18 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* CommentsView 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 { onMounted, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { adminCommentApi, type AdminCommentVO } from '@/api/admin'
|
||||
import type { IdType } from '@/utils/id'
|
||||
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** keyword is a reactive state variable used by the template and event handlers. */
|
||||
const keyword = ref('')
|
||||
const comments = ref<AdminCommentVO[]>([])
|
||||
|
||||
@@ -51,6 +57,7 @@ const columns = [
|
||||
{ title: '操作', key: 'action', width: 100 }
|
||||
]
|
||||
|
||||
/** loadComments is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadComments = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -62,6 +69,7 @@ const loadComments = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** deleteComment is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const deleteComment = async (id: IdType) => {
|
||||
await adminCommentApi.deleteComment(id)
|
||||
message.success('评论已删除')
|
||||
|
||||
@@ -240,11 +240,11 @@
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="开始时间" name="startTime">
|
||||
<a-date-picker v-model:value="formState.startTime" show-time format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
|
||||
<a-date-picker v-model:value="formState.startTime" show-time format="YYYY-MM-DD HH:mm:ss" popup-class-name="yumi-date-picker-panel yumi-date-time-panel" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="结束时间" name="endTime">
|
||||
<a-date-picker v-model:value="formState.endTime" show-time format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
|
||||
<a-date-picker v-model:value="formState.endTime" show-time format="YYYY-MM-DD HH:mm:ss" popup-class-name="yumi-date-picker-panel yumi-date-time-panel" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="可用标签" name="availableTagIds">
|
||||
@@ -331,6 +331,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* CouponsView 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, watch } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
@@ -358,6 +362,7 @@ import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
/** currentUserInfo is a local helper used by this page script. */
|
||||
const currentUserInfo = (() => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
@@ -386,12 +391,19 @@ interface CouponFormState {
|
||||
autoMatch: number
|
||||
}
|
||||
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** loadingShops is a reactive state variable used by the template and event handlers. */
|
||||
const loadingShops = ref(false)
|
||||
/** modalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const modalVisible = ref(false)
|
||||
/** viewModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const viewModalVisible = ref(false)
|
||||
/** modalLoading is a reactive state variable used by the template and event handlers. */
|
||||
const modalLoading = 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 distributeFormRef = ref<FormInstance>()
|
||||
@@ -402,7 +414,9 @@ const tagList = ref<Tag[]>([])
|
||||
const userList = ref<UserVO[]>([])
|
||||
const shops = ref<Shop[]>([])
|
||||
|
||||
/** distributeModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const distributeModalVisible = ref(false)
|
||||
/** distributeLoading is a reactive state variable used by the template and event handlers. */
|
||||
const distributeLoading = ref(false)
|
||||
const currentDistributeCoupon = ref<Coupon | null>(null)
|
||||
|
||||
@@ -469,8 +483,10 @@ const columns = [
|
||||
{ title: '操作', key: 'actions', width: 180, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
/** isVipAutoForm is a reactive state variable used by the template and event handlers. */
|
||||
const isVipAutoForm = computed(() => formState.couponScene === 'VIP_AUTO' || formState.autoMatch === 1)
|
||||
|
||||
/** getStatusColor is a local helper used by this page script. */
|
||||
const getStatusColor = (status: number) => {
|
||||
switch (status) {
|
||||
case 1:
|
||||
@@ -484,6 +500,7 @@ const getStatusColor = (status: number) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** getCouponSceneText is a local helper used by this page script. */
|
||||
const getCouponSceneText = (scene?: string) => {
|
||||
if (scene === 'VIP_AUTO') {
|
||||
return 'VIP 自动券'
|
||||
@@ -491,8 +508,10 @@ const getCouponSceneText = (scene?: string) => {
|
||||
return '普通券'
|
||||
}
|
||||
|
||||
/** isVipAutoCoupon is a local helper used by this page script. */
|
||||
const isVipAutoCoupon = (coupon: any) => coupon?.couponScene === 'VIP_AUTO' || coupon?.autoMatch === 1
|
||||
|
||||
/** getCouponValueText is a local helper used by this page script. */
|
||||
const getCouponValueText = (coupon: Coupon | null) => {
|
||||
if (!coupon) {
|
||||
return '-'
|
||||
@@ -502,6 +521,7 @@ const getCouponValueText = (coupon: Coupon | null) => {
|
||||
: `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
|
||||
}
|
||||
|
||||
/** resetFormState is a local helper used by this page script. */
|
||||
const resetFormState = () => {
|
||||
Object.assign(formState, {
|
||||
couponCode: '',
|
||||
@@ -522,8 +542,10 @@ const resetFormState = () => {
|
||||
})
|
||||
}
|
||||
|
||||
/** getDraftKey is a local helper used by this page script. */
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-coupons', isEdit.value ? 'edit' : 'create', currentCoupon.value?.id ?? 'new')
|
||||
|
||||
/** buildDraftPayload is a local helper used by this page script. */
|
||||
const buildDraftPayload = () => ({
|
||||
couponCode: formState.couponCode,
|
||||
couponName: formState.couponName,
|
||||
@@ -542,6 +564,7 @@ const buildDraftPayload = () => ({
|
||||
autoMatch: formState.autoMatch
|
||||
})
|
||||
|
||||
/** restoreDraft is a local helper used by this page script. */
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
@@ -558,12 +581,14 @@ const restoreDraft = () => {
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/** handleSaveDraft is a local helper used by this page script. */
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
/** handleClearDraft is a local helper used by this page script. */
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
@@ -587,11 +612,13 @@ watch(
|
||||
}
|
||||
)
|
||||
|
||||
/** handleAutoMatchChange is a local helper used by this page script. */
|
||||
const handleAutoMatchChange = (checked: boolean) => {
|
||||
formState.autoMatch = checked ? 1 : 0
|
||||
formState.couponScene = checked ? 'VIP_AUTO' : 'GENERAL'
|
||||
}
|
||||
|
||||
/** fetchCoupons is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchCoupons = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -611,6 +638,7 @@ const fetchCoupons = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchTags is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchTags = async () => {
|
||||
try {
|
||||
const tags = await adminTagApi.listAllTags() as unknown as Tag[]
|
||||
@@ -620,6 +648,7 @@ const fetchTags = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchShops is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
@@ -632,6 +661,7 @@ const fetchShops = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchUsers is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchUsers = async () => {
|
||||
try {
|
||||
const params: Record<string, unknown> = { page: 1, size: 200 }
|
||||
@@ -646,16 +676,19 @@ const fetchUsers = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** 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(() => fetchCoupons())
|
||||
}
|
||||
|
||||
/** handleTableChange is a local helper used by this page script. */
|
||||
const handleTableChange = (pag: any) => {
|
||||
pagination.current = pag.current || 1
|
||||
pagination.pageSize = pag.pageSize || pagination.pageSize
|
||||
}
|
||||
|
||||
/** showAddModal is a local helper used by this page script. */
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
currentCoupon.value = null
|
||||
@@ -664,6 +697,7 @@ const showAddModal = () => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showEditModal is a local helper used by this page script. */
|
||||
const showEditModal = (record: any) => {
|
||||
isEdit.value = true
|
||||
currentCoupon.value = record
|
||||
@@ -688,11 +722,13 @@ const showEditModal = (record: any) => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showViewModal is a local helper used by this page script. */
|
||||
const showViewModal = (record: any) => {
|
||||
currentCoupon.value = record
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
/** buildCouponPayload is a local helper used by this page script. */
|
||||
const buildCouponPayload = () => ({
|
||||
couponCode: formState.couponCode,
|
||||
couponName: formState.couponName,
|
||||
@@ -711,6 +747,7 @@ const buildCouponPayload = () => ({
|
||||
autoMatch: isVipAutoForm.value ? 1 : 0
|
||||
})
|
||||
|
||||
/** 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()
|
||||
@@ -739,12 +776,14 @@ const handleModalOk = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleModalCancel is a local helper used by this page script. */
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
resetFormState()
|
||||
}
|
||||
|
||||
/** handleDelete is a local helper used by this page script. */
|
||||
const handleDelete = (record: any) => {
|
||||
Modal.confirm({
|
||||
title: '确认删除',
|
||||
@@ -764,6 +803,7 @@ const handleDelete = (record: any) => {
|
||||
})
|
||||
}
|
||||
|
||||
/** showDistributeModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const showDistributeModal = async (record: any) => {
|
||||
currentDistributeCoupon.value = record
|
||||
distributeFormState.couponName = record.couponName
|
||||
@@ -773,6 +813,7 @@ const showDistributeModal = async (record: any) => {
|
||||
distributeModalVisible.value = true
|
||||
}
|
||||
|
||||
/** handleDistributeOk is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleDistributeOk = async () => {
|
||||
if (!currentDistributeCoupon.value) {
|
||||
return
|
||||
@@ -803,6 +844,7 @@ const handleDistributeOk = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleDistributeCancel is a local helper used by this page script. */
|
||||
const handleDistributeCancel = () => {
|
||||
distributeModalVisible.value = false
|
||||
distributeFormRef.value?.resetFields()
|
||||
|
||||
@@ -106,6 +106,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* DashboardView 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 } from 'ant-design-vue'
|
||||
import { HomeOutlined, ShopOutlined, ShoppingOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
@@ -113,6 +117,7 @@ import { adminDashboardApi, type DashboardStats } from '@/api/admin'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
|
||||
const { isMobile } = useAdminViewport()
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
const stats = reactive<DashboardStats>({
|
||||
totalUsers: 0,
|
||||
@@ -123,6 +128,7 @@ const stats = reactive<DashboardStats>({
|
||||
recentActivities: []
|
||||
})
|
||||
|
||||
/** getCurrentUserInfo is a local helper used by this page script. */
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const cache = localStorage.getItem('adminUserInfo')
|
||||
@@ -133,8 +139,11 @@ const getCurrentUserInfo = () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** currentUser is a reactive state variable used by the template and event handlers. */
|
||||
const currentUser = computed(() => getCurrentUserInfo())
|
||||
/** isAdmin is a reactive state variable used by the template and event handlers. */
|
||||
const isAdmin = computed(() => currentUser.value?.type === 4)
|
||||
/** pageSubtitle is a reactive state variable used by the template and event handlers. */
|
||||
const pageSubtitle = computed(() => {
|
||||
if (isAdmin.value) {
|
||||
return stats.totalShops > 0 ? '查看整体经营情况与各门店动态' : '当前还没有门店,先去店铺管理创建第一家门店'
|
||||
@@ -142,6 +151,7 @@ const pageSubtitle = computed(() => {
|
||||
return currentUser.value?.shopName ? `当前门店:${currentUser.value.shopName}` : '当前还没有选中门店'
|
||||
})
|
||||
|
||||
/** insightItems is a reactive state variable used by the template and event handlers. */
|
||||
const insightItems = computed(() => {
|
||||
const items = []
|
||||
if (isAdmin.value && stats.totalShops === 0) {
|
||||
@@ -181,6 +191,7 @@ const insightItems = computed(() => {
|
||||
return items
|
||||
})
|
||||
|
||||
/** formatTime is a local helper used by this page script. */
|
||||
const formatTime = (timeStr: string) => {
|
||||
if (!timeStr) return ''
|
||||
const time = new Date(timeStr)
|
||||
@@ -198,6 +209,7 @@ const formatTime = (timeStr: string) => {
|
||||
return time.toLocaleDateString('zh-CN')
|
||||
}
|
||||
|
||||
/** fetchStats is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchStats = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
|
||||
@@ -12,6 +12,15 @@
|
||||
description="系统里还没有可用店铺。当前账号已允许登录后台先创建第一家店铺,其他后台模块会保持不可用,创建完成后请重新登录并选择店铺。"
|
||||
/>
|
||||
|
||||
<a-alert
|
||||
v-if="isShopAuthorizationExpired"
|
||||
class="bootstrap-alert"
|
||||
type="error"
|
||||
show-icon
|
||||
message="授权已到期,请联系管理员"
|
||||
description="当前店铺已超过授权有效期,后台业务功能已暂时禁用。"
|
||||
/>
|
||||
|
||||
<a-card class="time-card">
|
||||
<a-statistic title="当前时间" :value="currentTime" />
|
||||
</a-card>
|
||||
@@ -140,6 +149,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* HomeView 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, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { DashboardOutlined, HomeOutlined, SafetyCertificateOutlined, ShopOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
@@ -152,11 +165,13 @@ import { isBootstrapAdminUser } from './admin-helpers'
|
||||
|
||||
const router = useRouter()
|
||||
const { isMobile } = useAdminViewport()
|
||||
/** currentTime is a reactive state variable used by the template and event handlers. */
|
||||
const currentTime = ref('')
|
||||
const userInfo = ref<UserVO | null>(null)
|
||||
const userPermissions = ref<PermissionVO[]>([])
|
||||
let timer: number | null = null
|
||||
|
||||
/** welcomeMessage is a reactive state variable used by the template and event handlers. */
|
||||
const welcomeMessage = computed(() => {
|
||||
const hour = new Date().getHours()
|
||||
if (hour < 12) {
|
||||
@@ -168,8 +183,12 @@ const welcomeMessage = computed(() => {
|
||||
}
|
||||
})
|
||||
|
||||
/** isBootstrapAdmin is a reactive state variable used by the template and event handlers. */
|
||||
const isBootstrapAdmin = computed(() => isBootstrapAdminUser(userInfo.value))
|
||||
/** isShopAuthorizationExpired is a reactive state variable used by the template and event handlers. */
|
||||
const isShopAuthorizationExpired = computed(() => Boolean(userInfo.value?.shopAuthorizationExpired) && userInfo.value?.type !== 4)
|
||||
|
||||
/** groupedPermissions is a reactive state variable used by the template and event handlers. */
|
||||
const groupedPermissions = computed(() => {
|
||||
const groups: Record<string, PermissionVO[]> = {}
|
||||
userPermissions.value.forEach(permission => {
|
||||
@@ -182,7 +201,11 @@ const groupedPermissions = computed(() => {
|
||||
return groups
|
||||
})
|
||||
|
||||
/** quickActions is a reactive state variable used by the template and event handlers. */
|
||||
const quickActions = computed(() => {
|
||||
if (isShopAuthorizationExpired.value) {
|
||||
return []
|
||||
}
|
||||
const actions = [
|
||||
{
|
||||
key: 'dashboard',
|
||||
@@ -225,6 +248,7 @@ const quickActions = computed(() => {
|
||||
return actions.filter(item => grantedPermissions.has(item.permissionCode))
|
||||
})
|
||||
|
||||
/** getUserTypeText is a local helper used by this page script. */
|
||||
const getUserTypeText = (type: number | undefined) => {
|
||||
switch (type) {
|
||||
case 4:
|
||||
@@ -238,6 +262,7 @@ const getUserTypeText = (type: number | undefined) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** updateCurrentTime is a local helper used by this page script. */
|
||||
const updateCurrentTime = () => {
|
||||
const now = new Date()
|
||||
currentTime.value = now.toLocaleString('zh-CN', {
|
||||
@@ -250,6 +275,7 @@ const updateCurrentTime = () => {
|
||||
})
|
||||
}
|
||||
|
||||
/** fetchUserInfo is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const adminUserInfoStr = localStorage.getItem('adminUserInfo')
|
||||
@@ -264,6 +290,7 @@ const fetchUserInfo = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchUserPermissions is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchUserPermissions = async () => {
|
||||
try {
|
||||
const res = await permissionApi.getUserPermissions()
|
||||
@@ -273,6 +300,7 @@ const fetchUserPermissions = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** navigateTo is a local helper used by this page script. */
|
||||
const navigateTo = (path: string, permissionCode?: string) => {
|
||||
if (permissionCode) {
|
||||
const hasPermission = userPermissions.value.some(p => p.permissionCode === permissionCode)
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
<template>
|
||||
<div class="admin-page">
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h2>协议管理</h2>
|
||||
<p>维护用户登录/注册前需要阅读并同意的用户协议和隐私政策。</p>
|
||||
</div>
|
||||
<a-button type="primary" @click="openCreate">新增协议</a-button>
|
||||
</div>
|
||||
|
||||
<a-table :columns="columns" :data-source="agreements" :loading="loading" row-key="id" bordered>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 1 ? 'green' : 'default'">{{ record.statusText || (record.status === 1 ? '已发布' : '草稿/停用') }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'action'">
|
||||
<a-space>
|
||||
<a-button size="small" @click="openEdit(record)">编辑</a-button>
|
||||
<a-button size="small" type="primary" :disabled="record.status === 1" @click="publishAgreement(record.id)">发布</a-button>
|
||||
<a-button size="small" danger :disabled="record.status !== 1" @click="disableAgreement(record.id)">停用</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<a-modal
|
||||
v-model:open="modalOpen"
|
||||
:title="editingId ? '编辑协议' : '新增协议'"
|
||||
width="760px"
|
||||
:confirm-loading="saving"
|
||||
@ok="saveAgreement"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="协议类型">
|
||||
<a-select v-model:value="form.agreementType">
|
||||
<a-select-option value="USER_TERMS">用户协议</a-select-option>
|
||||
<a-select-option value="PRIVACY_POLICY">隐私政策</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="标题">
|
||||
<a-input v-model:value="form.title" placeholder="例如:YumiNail 用户协议" />
|
||||
</a-form-item>
|
||||
<a-form-item label="版本">
|
||||
<a-input v-model:value="form.version" placeholder="例如:2026-05-18" />
|
||||
</a-form-item>
|
||||
<a-form-item label="内容">
|
||||
<a-textarea v-model:value="form.content" :rows="12" placeholder="请输入协议正文" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { adminLegalAgreementApi, type LegalAgreementAdminVO } from '@/api/admin'
|
||||
import type { IdType } from '@/utils/id'
|
||||
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const modalOpen = ref(false)
|
||||
const editingId = ref<IdType | null>(null)
|
||||
const agreements = ref<LegalAgreementAdminVO[]>([])
|
||||
const form = reactive({
|
||||
agreementType: 'USER_TERMS' as 'USER_TERMS' | 'PRIVACY_POLICY',
|
||||
title: '',
|
||||
version: '',
|
||||
content: ''
|
||||
})
|
||||
|
||||
const columns = [
|
||||
{ title: '类型', dataIndex: 'agreementTypeName', key: 'agreementTypeName' },
|
||||
{ title: '标题', dataIndex: 'title', key: 'title' },
|
||||
{ title: '版本', dataIndex: 'version', key: 'version' },
|
||||
{ title: '状态', dataIndex: 'status', key: 'status' },
|
||||
{ title: '生效时间', dataIndex: 'effectiveTime', key: 'effectiveTime' },
|
||||
{ title: '操作', key: 'action', width: 220 }
|
||||
]
|
||||
|
||||
const loadAgreements = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
agreements.value = await adminLegalAgreementApi.list() as unknown as LegalAgreementAdminVO[]
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resetForm = () => {
|
||||
editingId.value = null
|
||||
form.agreementType = 'USER_TERMS'
|
||||
form.title = ''
|
||||
form.version = ''
|
||||
form.content = ''
|
||||
}
|
||||
|
||||
const openCreate = () => {
|
||||
resetForm()
|
||||
modalOpen.value = true
|
||||
}
|
||||
|
||||
const openEdit = (record: Record<string, any>) => {
|
||||
const agreement = record as LegalAgreementAdminVO
|
||||
editingId.value = agreement.id
|
||||
form.agreementType = agreement.agreementType
|
||||
form.title = agreement.title
|
||||
form.version = agreement.version
|
||||
form.content = agreement.content
|
||||
modalOpen.value = true
|
||||
}
|
||||
|
||||
const saveAgreement = async () => {
|
||||
if (!form.title || !form.version || !form.content) {
|
||||
message.warning('请填写完整协议信息')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
if (editingId.value) {
|
||||
await adminLegalAgreementApi.update(editingId.value, { ...form })
|
||||
} else {
|
||||
await adminLegalAgreementApi.create({ ...form })
|
||||
}
|
||||
message.success('保存成功')
|
||||
modalOpen.value = false
|
||||
await loadAgreements()
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const publishAgreement = async (id: IdType) => {
|
||||
await adminLegalAgreementApi.publish(id)
|
||||
message.success('发布成功')
|
||||
await loadAgreements()
|
||||
}
|
||||
|
||||
const disableAgreement = async (id: IdType) => {
|
||||
await adminLegalAgreementApi.disable(id)
|
||||
message.success('已停用')
|
||||
await loadAgreements()
|
||||
}
|
||||
|
||||
onMounted(loadAgreements)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-page { padding: 16px; }
|
||||
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
|
||||
.page-header h2 { margin: 0 0 6px; }
|
||||
.page-header p { margin: 0; color: #8c8c8c; }
|
||||
</style>
|
||||
@@ -40,6 +40,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* ManageView 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 } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
@@ -64,11 +68,16 @@ import {
|
||||
const router = useRouter()
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
/** userInfo is a reactive state variable used by the template and event handlers. */
|
||||
const userInfo = computed(() => loadCachedAdminUserInfo())
|
||||
/** currentShopName is a reactive state variable used by the template and event handlers. */
|
||||
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
|
||||
/** roleLabel is a reactive state variable used by the template and event handlers. */
|
||||
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
|
||||
/** isBootstrapAdmin is a reactive state variable used by the template and event handlers. */
|
||||
const isBootstrapAdmin = computed(() => isBootstrapAdminUser(userInfo.value))
|
||||
|
||||
/** visibleModules is a reactive state variable used by the template and event handlers. */
|
||||
const visibleModules = computed(() => {
|
||||
const definitions = [
|
||||
{
|
||||
@@ -160,6 +169,7 @@ const visibleModules = computed(() => {
|
||||
})
|
||||
})
|
||||
|
||||
/** openModule is a local helper used by this page script. */
|
||||
const openModule = (module: any) => {
|
||||
if (!module.allowed) {
|
||||
message.warning(module.disabledReason || '当前无法进入该模块')
|
||||
|
||||
@@ -0,0 +1,292 @@
|
||||
<template>
|
||||
<div class="admin-page">
|
||||
<div class="page-head">
|
||||
<div>
|
||||
<h2>参数管理</h2>
|
||||
<p>统一维护地图 Key、短信 MessageHub 对接参数等平台级配置,仅平台管理员可修改。</p>
|
||||
</div>
|
||||
<a-button type="primary" @click="openCreate">新增配置</a-button>
|
||||
</div>
|
||||
|
||||
<a-card title="地图服务配置" :bordered="false">
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="腾讯位置服务 Key">
|
||||
<a-input-password v-model:value="mapForm.configValue" placeholder="请输入腾讯位置服务 Key" />
|
||||
</a-form-item>
|
||||
<a-form-item label="备注">
|
||||
<a-textarea v-model:value="mapForm.remark" :rows="2" placeholder="例如:用于后台店铺选点和腾讯地图展示" />
|
||||
</a-form-item>
|
||||
<a-form-item>
|
||||
<a-space>
|
||||
<a-switch v-model:checked="mapEnabled" checked-children="启用" un-checked-children="停用" />
|
||||
<a-button type="primary" :loading="savingMap" @click="saveMapConfig">保存地图配置</a-button>
|
||||
</a-space>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-card>
|
||||
|
||||
<a-alert
|
||||
type="info"
|
||||
show-icon
|
||||
message="这里不配置 Spug、阿里云等供应商密钥;真实短信通道仍在 MessageHub 中独立管理。"
|
||||
/>
|
||||
|
||||
<a-table :columns="columns" :data-source="configs" :loading="loading" row-key="id">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'scene'">
|
||||
<strong>{{ record.sceneName }}</strong>
|
||||
<div class="muted">{{ record.sceneCode }}</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'messagehub'">
|
||||
<div>队列:{{ record.queueName }}</div>
|
||||
<div class="muted">来源:{{ record.sourceSystem }}</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'template'">
|
||||
<div>{{ record.templateCode }}</div>
|
||||
<div class="muted">通道ID:{{ record.channelId || '由 MessageHub 自动选择' }}</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'enabled'">
|
||||
<a-switch :checked="record.enabled === 1" @change="checked => toggleStatus(record as MessageHubPushConfigVO, Boolean(checked))" />
|
||||
</template>
|
||||
<template v-else-if="column.key === 'action'">
|
||||
<a-space>
|
||||
<a-button size="small" @click="openEdit(record as MessageHubPushConfigVO)">编辑</a-button>
|
||||
<a-button size="small" @click="openTest(record as MessageHubPushConfigVO)">测试</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<a-modal v-model:open="formOpen" :title="editingId ? '编辑配置' : '新增配置'" @ok="submit" :confirm-loading="saving">
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="业务场景">
|
||||
<a-select v-model:value="form.sceneCode" :options="sceneOptions" show-search @change="handleSceneChange" />
|
||||
</a-form-item>
|
||||
<a-form-item label="场景名称">
|
||||
<a-input v-model:value="form.sceneName" />
|
||||
</a-form-item>
|
||||
<a-form-item label="MessageHub 队列">
|
||||
<a-input v-model:value="form.queueName" placeholder="smsQueue" />
|
||||
</a-form-item>
|
||||
<a-form-item label="来源系统">
|
||||
<a-input v-model:value="form.sourceSystem" placeholder="yuminail" />
|
||||
</a-form-item>
|
||||
<a-form-item label="模板编码">
|
||||
<a-input v-model:value="form.templateCode" placeholder="MessageHub 中维护的模板编码" />
|
||||
</a-form-item>
|
||||
<a-form-item label="指定通道 ID">
|
||||
<a-input-number v-model:value="form.channelId" :min="1" style="width: 100%" placeholder="不填则由 MessageHub 选择" />
|
||||
</a-form-item>
|
||||
<a-form-item label="发送方式">
|
||||
<a-select v-model:value="form.sendMethod" allow-clear :options="sendMethodOptions" />
|
||||
</a-form-item>
|
||||
<a-form-item label="备注">
|
||||
<a-textarea v-model:value="form.remark" :rows="3" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<a-modal v-model:open="testOpen" title="测试投递" @ok="submitTest" :confirm-loading="testing">
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="测试手机号">
|
||||
<a-input v-model:value="testPhone" :maxlength="11" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* MessageHubPushConfigsView 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 { onMounted, reactive, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { adminMessageHubPushConfigApi, adminSystemParameterConfigApi, type MessageHubPushConfigVO } from '@/api/admin'
|
||||
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** saving is a reactive state variable used by the template and event handlers. */
|
||||
const saving = ref(false)
|
||||
/** testing is a reactive state variable used by the template and event handlers. */
|
||||
const testing = ref(false)
|
||||
/** formOpen is a reactive state variable used by the template and event handlers. */
|
||||
const formOpen = ref(false)
|
||||
/** testOpen is a reactive state variable used by the template and event handlers. */
|
||||
const testOpen = ref(false)
|
||||
const editingId = ref<any>()
|
||||
const testingId = ref<any>()
|
||||
/** testPhone is a reactive state variable used by the template and event handlers. */
|
||||
const testPhone = ref('')
|
||||
const configs = ref<MessageHubPushConfigVO[]>([])
|
||||
const savingMap = ref(false)
|
||||
const mapEnabled = ref(true)
|
||||
const mapForm = reactive({
|
||||
configGroup: 'MAP',
|
||||
configKey: 'TENCENT_MAP_KEY',
|
||||
configName: '腾讯位置服务 Key',
|
||||
configValue: '',
|
||||
enabled: 1,
|
||||
remark: '用于后台店铺选点和腾讯地图展示'
|
||||
})
|
||||
|
||||
const sceneOptions = [
|
||||
{ label: '用户注册验证码', value: 'USER_REGISTER_SMS_CODE' },
|
||||
{ label: '手机号登录验证码', value: 'USER_LOGIN_SMS_CODE' },
|
||||
{ label: '找回密码验证码', value: 'USER_RESET_PASSWORD_SMS_CODE' },
|
||||
{ label: '绑定手机号验证码', value: 'USER_BIND_PHONE_SMS_CODE' },
|
||||
{ label: '修改手机号验证码', value: 'USER_CHANGE_PHONE_SMS_CODE' },
|
||||
{ label: '修改密码验证码', value: 'USER_CHANGE_PASSWORD_SMS_CODE' }
|
||||
]
|
||||
|
||||
const sendMethodOptions = [
|
||||
{ label: 'SPUG', value: 'SPUG' },
|
||||
{ label: 'OTHER', value: 'OTHER' }
|
||||
]
|
||||
|
||||
const form = reactive<any>({
|
||||
sceneCode: 'USER_LOGIN_SMS_CODE',
|
||||
sceneName: '手机号登录验证码',
|
||||
platform: 'SMS',
|
||||
msgType: 'VERIFICATION',
|
||||
queueName: 'smsQueue',
|
||||
sourceSystem: 'yuminail',
|
||||
templateCode: 'SPUG0001',
|
||||
channelId: undefined,
|
||||
sendMethod: 'SPUG',
|
||||
enabled: 1,
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const columns = [
|
||||
{ title: '业务场景', key: 'scene' },
|
||||
{ title: 'MessageHub', key: 'messagehub' },
|
||||
{ title: '模板/通道', key: 'template' },
|
||||
{ title: '消息类型', dataIndex: 'msgType', key: 'msgType', width: 110 },
|
||||
{ title: '启用', key: 'enabled', width: 90 },
|
||||
{ title: '操作', key: 'action', width: 150 }
|
||||
]
|
||||
|
||||
/** load is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const load = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const [messageConfigs, mapConfigs] = await Promise.all([
|
||||
adminMessageHubPushConfigApi.listConfigs(),
|
||||
adminSystemParameterConfigApi.listConfigs('MAP')
|
||||
])
|
||||
configs.value = messageConfigs
|
||||
const tencentMapConfig = mapConfigs.find(item => item.configKey === 'TENCENT_MAP_KEY')
|
||||
if (tencentMapConfig) {
|
||||
Object.assign(mapForm, tencentMapConfig)
|
||||
mapEnabled.value = tencentMapConfig.enabled === 1
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const saveMapConfig = async () => {
|
||||
savingMap.value = true
|
||||
try {
|
||||
await adminSystemParameterConfigApi.saveConfig({
|
||||
...mapForm,
|
||||
enabled: mapEnabled.value ? 1 : 0
|
||||
})
|
||||
message.success('地图配置已保存')
|
||||
await load()
|
||||
} finally {
|
||||
savingMap.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** resetForm is a local helper used by this page script. */
|
||||
const resetForm = () => Object.assign(form, {
|
||||
sceneCode: 'USER_LOGIN_SMS_CODE',
|
||||
sceneName: '手机号登录验证码',
|
||||
platform: 'SMS',
|
||||
msgType: 'VERIFICATION',
|
||||
queueName: 'smsQueue',
|
||||
sourceSystem: 'yuminail',
|
||||
templateCode: 'SPUG0001',
|
||||
channelId: undefined,
|
||||
sendMethod: 'SPUG',
|
||||
enabled: 1,
|
||||
remark: ''
|
||||
})
|
||||
|
||||
/** handleSceneChange is a local helper used by this page script. */
|
||||
const handleSceneChange = (value: any) => {
|
||||
const option = sceneOptions.find(item => item.value === String(value || ''))
|
||||
if (option) form.sceneName = option.label
|
||||
}
|
||||
|
||||
/** openCreate is a local helper used by this page script. */
|
||||
const openCreate = () => { editingId.value = undefined; resetForm(); formOpen.value = true }
|
||||
/** openEdit is a local helper used by this page script. */
|
||||
const openEdit = (record: MessageHubPushConfigVO) => {
|
||||
editingId.value = record.id
|
||||
Object.assign(form, record)
|
||||
formOpen.value = true
|
||||
}
|
||||
|
||||
/** submit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const submit = async () => {
|
||||
if (!form.sceneCode || !form.sceneName || !form.queueName || !form.sourceSystem || !form.templateCode) {
|
||||
message.warning('请填写场景、队列、来源系统和模板编码')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
if (editingId.value) {
|
||||
await adminMessageHubPushConfigApi.updateConfig(editingId.value, form)
|
||||
} else {
|
||||
await adminMessageHubPushConfigApi.createConfig(form)
|
||||
}
|
||||
message.success('配置已保存')
|
||||
formOpen.value = false
|
||||
await load()
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** toggleStatus is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const toggleStatus = async (record: MessageHubPushConfigVO, checked: boolean) => {
|
||||
await adminMessageHubPushConfigApi.updateStatus(record.id, checked ? 1 : 0)
|
||||
record.enabled = checked ? 1 : 0
|
||||
}
|
||||
|
||||
/** openTest is a local helper used by this page script. */
|
||||
const openTest = (record: MessageHubPushConfigVO) => {
|
||||
testingId.value = record.id
|
||||
testPhone.value = ''
|
||||
testOpen.value = true
|
||||
}
|
||||
|
||||
/** submitTest is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const submitTest = async () => {
|
||||
if (!/^1[3-9]\d{9}$/.test(testPhone.value)) {
|
||||
message.warning('请输入正确的测试手机号')
|
||||
return
|
||||
}
|
||||
testing.value = true
|
||||
try {
|
||||
await adminMessageHubPushConfigApi.testConfig(testingId.value, testPhone.value)
|
||||
message.success('测试消息已投递到 MessageHub')
|
||||
testOpen.value = false
|
||||
} finally {
|
||||
testing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-page { display: grid; gap: 18px; }
|
||||
.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
|
||||
.page-head h2 { margin: 0 0 4px; }
|
||||
.page-head p, .muted { margin: 0; color: #7a6f68; }
|
||||
</style>
|
||||
@@ -43,6 +43,19 @@
|
||||
{{ getStatusText(record.status) }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'userTypeName'">
|
||||
<a-tag :color="record.userType === 2 ? 'gold' : 'blue'">
|
||||
{{ record.userTypeName || (record.userType === 2 ? '店长' : '美甲师') }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'participateProduction'">
|
||||
<a-tag :color="record.participateProduction === 1 ? 'green' : 'default'">
|
||||
{{ record.participateProduction === 1 ? '参与制作' : '不参与' }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'workTime'">
|
||||
{{ formatWorkTime(record) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('nail_artist:view')" type="link" size="small" @click="showViewModal(record)">
|
||||
@@ -154,6 +167,19 @@
|
||||
<a-select-option :value="0">休息中</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="参与制作" name="participateProduction">
|
||||
<a-switch
|
||||
v-model:checked="formState.participateProduction"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
:disabled="!isShopOwner"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="工作时间">
|
||||
<a-input v-model:value="formState.workStartTime" type="time" placeholder="开始" />
|
||||
<span class="time-separator">至</span>
|
||||
<a-input v-model:value="formState.workEndTime" type="time" placeholder="结束" />
|
||||
</a-form-item>
|
||||
<a-form-item label="作品" name="portfolio">
|
||||
<a-select
|
||||
v-model:value="formState.portfolio"
|
||||
@@ -207,6 +233,12 @@
|
||||
<a-form-item label="状态">
|
||||
<a-input v-model:value="viewFormState.statusText" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="人员类型">
|
||||
<a-input v-model:value="viewFormState.userTypeName" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="工作时间">
|
||||
<a-input v-model:value="viewFormState.workTime" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="评分">
|
||||
<a-input v-model:value="viewFormState.rating" :disabled="true" />
|
||||
</a-form-item>
|
||||
@@ -219,6 +251,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* NailArtistsView 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 { ref, reactive, onMounted } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
@@ -236,6 +272,7 @@ import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
/** getCurrentUserInfo is a local helper used by this page script. */
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
@@ -251,17 +288,26 @@ const getCurrentUserInfo = () => {
|
||||
return null
|
||||
}
|
||||
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** tagLoading is a reactive state variable used by the template and event handlers. */
|
||||
const tagLoading = ref(false)
|
||||
/** productLoading is a reactive state variable used by the template and event handlers. */
|
||||
const productLoading = ref(false)
|
||||
/** searchText is a reactive state variable used by the template and event handlers. */
|
||||
const searchText = ref('')
|
||||
const nailArtistList = ref<NailArtistInfoVO[]>([])
|
||||
const tagList = ref<Tag[]>([])
|
||||
const productList = ref<Product[]>([])
|
||||
/** 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)
|
||||
/** isAdmin is a reactive state variable used by the template and event handlers. */
|
||||
const isAdmin = ref(false)
|
||||
/** isShopOwner is a reactive state variable used by the template and event handlers. */
|
||||
const isShopOwner = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentNailArtist = ref<NailArtistInfoVO | null>(null)
|
||||
@@ -275,6 +321,8 @@ const viewFormState = reactive({
|
||||
experience: '',
|
||||
skillsText: '',
|
||||
statusText: '',
|
||||
userTypeName: '',
|
||||
workTime: '',
|
||||
rating: '',
|
||||
portfolioText: ''
|
||||
})
|
||||
@@ -295,20 +343,29 @@ const formState = reactive({
|
||||
skills: [] as string[],
|
||||
rating: 0,
|
||||
status: 1,
|
||||
participateProduction: 1,
|
||||
workStartTime: '',
|
||||
workEndTime: '',
|
||||
portfolio: [] as string[],
|
||||
nickname: ''
|
||||
})
|
||||
|
||||
/** getDraftKey is a local helper used by this page script. */
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-nail-artists', 'edit', currentNailArtist.value?.userId ?? formState.userId ?? 'unknown')
|
||||
|
||||
/** buildDraftPayload is a local helper used by this page script. */
|
||||
const buildDraftPayload = () => ({
|
||||
identity: formState.identity,
|
||||
experience: formState.experience,
|
||||
skills: [...formState.skills],
|
||||
status: formState.status,
|
||||
participateProduction: formState.participateProduction,
|
||||
workStartTime: formState.workStartTime,
|
||||
workEndTime: formState.workEndTime,
|
||||
portfolio: [...formState.portfolio]
|
||||
})
|
||||
|
||||
/** restoreDraft is a local helper used by this page script. */
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
@@ -322,18 +379,25 @@ const restoreDraft = () => {
|
||||
status: typeof draft.payload.status === 'number'
|
||||
? (draft.payload.status === 0 ? 0 : 1)
|
||||
: formState.status,
|
||||
participateProduction: typeof draft.payload.participateProduction === 'number'
|
||||
? (draft.payload.participateProduction === 1 ? 1 : 0)
|
||||
: formState.participateProduction,
|
||||
workStartTime: draft.payload.workStartTime ?? formState.workStartTime,
|
||||
workEndTime: draft.payload.workEndTime ?? formState.workEndTime,
|
||||
portfolio: Array.isArray(draft.payload.portfolio) ? draft.payload.portfolio : formState.portfolio
|
||||
})
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/** handleSaveDraft is a local helper used by this page script. */
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
/** handleClearDraft is a local helper used by this page script. */
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
@@ -353,6 +417,9 @@ const formRules = {
|
||||
const columns = [
|
||||
{ title: '美甲师姓名', dataIndex: 'nickname', key: 'nickname' },
|
||||
{ title: '所属店铺', dataIndex: 'shopName', key: 'shopName' },
|
||||
{ title: '人员类型', key: 'userTypeName', width: 110 },
|
||||
{ title: '参与制作', key: 'participateProduction', width: 120 },
|
||||
{ title: '工作时间', key: 'workTime', width: 150 },
|
||||
{ title: '身份', dataIndex: 'identity', key: 'identity' },
|
||||
{ title: '从业年限', dataIndex: 'experience', key: 'experience' },
|
||||
{ title: '评分', dataIndex: 'rating', key: 'rating' },
|
||||
@@ -360,14 +427,27 @@ const columns = [
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
/** getStatusText is a local helper used by this page script. */
|
||||
const getStatusText = (status: number) => {
|
||||
return status === 1 ? '营业中' : '休息中'
|
||||
}
|
||||
|
||||
/** getStatusColor is a local helper used by this page script. */
|
||||
const getStatusColor = (status: number) => {
|
||||
return status === 1 ? 'green' : 'default'
|
||||
}
|
||||
|
||||
/** formatWorkTime is a local helper used by this page script. */
|
||||
const formatWorkTime = (record: Partial<NailArtistInfoVO>) => {
|
||||
const start = record.workStartTime ? String(record.workStartTime).slice(0, 5) : ''
|
||||
const end = record.workEndTime ? String(record.workEndTime).slice(0, 5) : ''
|
||||
return start && end ? `${start} - ${end}` : '--'
|
||||
}
|
||||
|
||||
/** normalizeTime is a local helper used by this page script. */
|
||||
const normalizeTime = (value?: string) => value ? (String(value).length === 5 ? `${value}:00` : String(value)) : undefined
|
||||
|
||||
/** fetchTagList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchTagList = async () => {
|
||||
tagLoading.value = true
|
||||
try {
|
||||
@@ -380,6 +460,7 @@ const fetchTagList = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchProductList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchProductList = async () => {
|
||||
productLoading.value = true
|
||||
try {
|
||||
@@ -399,6 +480,7 @@ const fetchProductList = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchNailArtistList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchNailArtistList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -421,17 +503,20 @@ const fetchNailArtistList = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** 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(() => fetchNailArtistList())
|
||||
}
|
||||
|
||||
/** 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
|
||||
pagination.pageSize = pag.pageSize
|
||||
await runWithGlobalLoading(() => fetchNailArtistList())
|
||||
}
|
||||
|
||||
/** showEditModal is a local helper used by this page script. */
|
||||
const showEditModal = (record: Record<string, any>) => {
|
||||
currentNailArtist.value = record as NailArtistInfoVO
|
||||
const lockedFields = {
|
||||
@@ -444,6 +529,9 @@ const showEditModal = (record: Record<string, any>) => {
|
||||
experience: record.experience || 0,
|
||||
skills: record.skills ? record.skills.split(',').filter(Boolean) : [],
|
||||
status: record.status || 1,
|
||||
participateProduction: record.participateProduction ?? (record.userType === 3 ? 1 : 0),
|
||||
workStartTime: record.workStartTime || '',
|
||||
workEndTime: record.workEndTime || '',
|
||||
portfolio: record.portfolio ? record.portfolio.split(',').filter(Boolean) : [],
|
||||
...lockedFields
|
||||
})
|
||||
@@ -452,6 +540,7 @@ const showEditModal = (record: Record<string, any>) => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showViewModal is a local helper used by this page script. */
|
||||
const showViewModal = (record: Record<string, any>) => {
|
||||
const nailArtist = record as NailArtistInfoVO
|
||||
// 构建技能标签文本
|
||||
@@ -475,16 +564,20 @@ const showViewModal = (record: Record<string, any>) => {
|
||||
experience: (nailArtist.experience || 0).toString(),
|
||||
skillsText: skillsText,
|
||||
statusText: getStatusText(nailArtist.status || 1),
|
||||
userTypeName: nailArtist.userTypeName || (nailArtist.userType === 2 ? '店长' : '美甲师'),
|
||||
workTime: formatWorkTime(nailArtist),
|
||||
rating: (nailArtist.rating || 0).toString(),
|
||||
portfolioText: portfolioText
|
||||
})
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
/** handleViewModalCancel is a local helper used by this page script. */
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
}
|
||||
|
||||
/** 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()
|
||||
@@ -505,6 +598,9 @@ const handleModalOk = async () => {
|
||||
experience: formState.experience,
|
||||
rating: formState.rating,
|
||||
status: formState.status,
|
||||
participateProduction: formState.participateProduction,
|
||||
workStartTime: normalizeTime(formState.workStartTime),
|
||||
workEndTime: normalizeTime(formState.workEndTime),
|
||||
skills: formState.skills.join(','),
|
||||
portfolio: formState.portfolio.join(',')
|
||||
}
|
||||
@@ -529,6 +625,7 @@ const handleModalOk = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleModalCancel is a local helper used by this page script. */
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
currentNailArtist.value = null
|
||||
|
||||
@@ -185,6 +185,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* OrdersView 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, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { orderApi } from '../../api/order'
|
||||
@@ -198,18 +202,23 @@ import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { isMobile } = useAdminViewport()
|
||||
const orders = ref<any[]>([])
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
const currentOrder = ref<any | null>(null)
|
||||
const currentUserType = ref<number | null>(null)
|
||||
/** keyword is a reactive state variable used by the template and event handlers. */
|
||||
const keyword = ref('')
|
||||
const statusFilter = ref<'all' | string>('all')
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
/** detailVisible is a reactive state variable used by the template and event handlers. */
|
||||
const detailVisible = computed({
|
||||
get: () => !!currentOrder.value,
|
||||
set: value => { if (!value) currentOrder.value = null }
|
||||
})
|
||||
/** canProcessOrders is a reactive state variable used by the template and event handlers. */
|
||||
const canProcessOrders = computed(() => hasPermission('order:process'))
|
||||
/** isArtist is a reactive state variable used by the template and event handlers. */
|
||||
const isArtist = computed(() => currentUserType.value === 3)
|
||||
const statusOptions = [
|
||||
{ label: '全部状态', value: 'all' },
|
||||
@@ -218,6 +227,7 @@ const statusOptions = [
|
||||
{ label: '已取消', value: '3' }
|
||||
]
|
||||
|
||||
/** filteredOrders is a reactive state variable used by the template and event handlers. */
|
||||
const filteredOrders = computed(() => {
|
||||
const keywordValue = keyword.value.trim().toLowerCase()
|
||||
return orders.value.filter(order => {
|
||||
@@ -259,6 +269,7 @@ const itemColumns = [
|
||||
{ title: '总价', key: 'totalPrice', width: 100 }
|
||||
]
|
||||
|
||||
/** statusColor is a local helper used by this page script. */
|
||||
const statusColor = (status: number) => {
|
||||
if (status === 1) return 'orange'
|
||||
if (status === 2) return 'green'
|
||||
@@ -266,6 +277,7 @@ const statusColor = (status: number) => {
|
||||
return 'default'
|
||||
}
|
||||
|
||||
/** resolveCurrentUserType is a local helper used by this page script. */
|
||||
const resolveCurrentUserType = () => {
|
||||
const cached = localStorage.getItem('adminUserInfo') || sessionStorage.getItem('adminUserInfo')
|
||||
if (!cached) {
|
||||
@@ -279,6 +291,7 @@ const resolveCurrentUserType = () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** loadOrders is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -290,6 +303,7 @@ const loadOrders = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** process is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const process = async (orderId: IdType, status: number) => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
@@ -305,6 +319,7 @@ const process = async (orderId: IdType, status: number) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** noop is a local helper used by this page script. */
|
||||
const noop = () => {}
|
||||
|
||||
onMounted(async () => {
|
||||
|
||||
@@ -331,6 +331,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* PermissionsView 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 { ref, reactive, computed, onMounted, watch } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
@@ -354,11 +358,16 @@ import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
/** activeTab is a reactive state variable used by the template and event handlers. */
|
||||
const activeTab = ref('permissions')
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
const permissionList = ref<PermissionVO[]>([])
|
||||
/** permissionModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const permissionModalVisible = ref(false)
|
||||
/** permissionModalLoading is a reactive state variable used by the template and event handlers. */
|
||||
const permissionModalLoading = ref(false)
|
||||
/** isEditPermission is a reactive state variable used by the template and event handlers. */
|
||||
const isEditPermission = ref(false)
|
||||
const permissionFormRef = ref<FormInstance>()
|
||||
const currentPermission = ref<PermissionVO | null>(null)
|
||||
@@ -380,8 +389,10 @@ const permissionFormState = reactive({
|
||||
description: ''
|
||||
})
|
||||
|
||||
/** getDraftKey is a local helper used by this page script. */
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-permissions', isEditPermission.value ? 'edit' : 'create', currentPermission.value?.id ?? 'new')
|
||||
|
||||
/** buildDraftPayload is a local helper used by this page script. */
|
||||
const buildDraftPayload = () => ({
|
||||
permissionCode: permissionFormState.permissionCode,
|
||||
permissionName: permissionFormState.permissionName,
|
||||
@@ -389,6 +400,7 @@ const buildDraftPayload = () => ({
|
||||
description: permissionFormState.description
|
||||
})
|
||||
|
||||
/** restoreDraft is a local helper used by this page script. */
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
@@ -400,12 +412,14 @@ const restoreDraft = () => {
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/** handleSaveDraft is a local helper used by this page script. */
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
/** handleClearDraft is a local helper used by this page script. */
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
@@ -430,10 +444,13 @@ const permissionColumns = [
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
/** userLoading is a reactive state variable used by the template and event handlers. */
|
||||
const userLoading = ref(false)
|
||||
/** userSearchText is a reactive state variable used by the template and event handlers. */
|
||||
const userSearchText = ref('')
|
||||
const userList = ref<UserVO[]>([])
|
||||
const selectedUser = ref<UserVO | null>(null)
|
||||
/** assignLoading is a reactive state variable used by the template and event handlers. */
|
||||
const assignLoading = ref(false)
|
||||
const selectedPermissions = ref<IdType[]>([])
|
||||
const assignablePermissionIds = ref<IdType[]>([])
|
||||
@@ -442,11 +459,14 @@ const currentLoginUser = ref<UserVO | null>(null)
|
||||
const mobilePermissionStep = ref<'users' | 'assign'>('users')
|
||||
|
||||
// 权限 ID 同样可能以字符串形式返回,所以这里统一转成字符串集合做包含判断。
|
||||
/** assignablePermissionIdSet is a reactive state variable used by the template and event handlers. */
|
||||
const assignablePermissionIdSet = computed(() => new Set(assignablePermissionIds.value.map(id => String(id))))
|
||||
/** disabledPermissionCount is a reactive state variable used by the template and event handlers. */
|
||||
const disabledPermissionCount = computed(() =>
|
||||
permissionList.value.filter(permission => !assignablePermissionIdSet.value.has(String(permission.id))).length
|
||||
)
|
||||
|
||||
/** groupedPermissions is a reactive state variable used by the template and event handlers. */
|
||||
const groupedPermissions = computed(() => {
|
||||
const groups: Record<string, PermissionVO[]> = {}
|
||||
permissionList.value.forEach(p => {
|
||||
@@ -459,6 +479,7 @@ const groupedPermissions = computed(() => {
|
||||
return groups
|
||||
})
|
||||
|
||||
/** getUserTypeText is a local helper used by this page script. */
|
||||
const getUserTypeText = (type: number) => {
|
||||
const map: Record<number, string> = {
|
||||
0: '用户',
|
||||
@@ -469,6 +490,7 @@ const getUserTypeText = (type: number) => {
|
||||
return map[type] || '未知'
|
||||
}
|
||||
|
||||
/** filteredUserList is a reactive state variable used by the template and event handlers. */
|
||||
const filteredUserList = computed(() => {
|
||||
if (!currentLoginUser.value) return []
|
||||
|
||||
@@ -488,6 +510,7 @@ const filteredUserList = computed(() => {
|
||||
return []
|
||||
})
|
||||
|
||||
/** isPermissionDisabled is a local helper used by this page script. */
|
||||
const isPermissionDisabled = (permission: PermissionVO) => {
|
||||
if (!selectedUser.value) {
|
||||
return true
|
||||
@@ -495,10 +518,12 @@ const isPermissionDisabled = (permission: PermissionVO) => {
|
||||
return !assignablePermissionIdSet.value.has(String(permission.id))
|
||||
}
|
||||
|
||||
/** resolveRequestErrorMessage is a local helper used by this page script. */
|
||||
const resolveRequestErrorMessage = (error: any, fallback: string) => {
|
||||
return error?.response?.data?.message || error?.message || fallback
|
||||
}
|
||||
|
||||
/** fetchCurrentUser is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchCurrentUser = async () => {
|
||||
try {
|
||||
// 尝试从API获取用户信息
|
||||
@@ -524,6 +549,7 @@ const fetchCurrentUser = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchPermissionList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchPermissionList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -537,6 +563,7 @@ const fetchPermissionList = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchUserList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchUserList = async () => {
|
||||
userLoading.value = true
|
||||
try {
|
||||
@@ -560,16 +587,19 @@ const fetchUserList = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handlePermissionTableChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handlePermissionTableChange = async (pag: any) => {
|
||||
permissionPagination.current = pag.current
|
||||
permissionPagination.pageSize = pag.pageSize
|
||||
await runWithGlobalLoading(() => fetchPermissionList())
|
||||
}
|
||||
|
||||
/** handleUserSearch is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleUserSearch = async () => {
|
||||
await runWithGlobalLoading(() => fetchUserList())
|
||||
}
|
||||
|
||||
/** selectUser is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const selectUser = async (user: UserVO) => {
|
||||
selectedUser.value = user
|
||||
assignLoading.value = true
|
||||
@@ -582,6 +612,7 @@ const selectUser = async (user: UserVO) => {
|
||||
])
|
||||
assignablePermissionIds.value = allowedIds || []
|
||||
const allowedIdSet = new Set(assignablePermissionIds.value.map(id => String(id)))
|
||||
/** assignedIds is a local helper used by this page script. */
|
||||
const assignedIds = (assignedPermissions || []).map((p: PermissionVO) => p.id)
|
||||
selectedPermissions.value = assignedIds.filter(id => allowedIdSet.has(String(id)))
|
||||
const trimmedCount = assignedIds.length - selectedPermissions.value.length
|
||||
@@ -601,6 +632,7 @@ const selectUser = async (user: UserVO) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleSaveUserPermissions is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleSaveUserPermissions = async () => {
|
||||
if (!selectedUser.value) return
|
||||
const userId = selectedUser.value.id
|
||||
@@ -616,6 +648,7 @@ const handleSaveUserPermissions = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** showAddPermissionModal is a local helper used by this page script. */
|
||||
const showAddPermissionModal = () => {
|
||||
isEditPermission.value = false
|
||||
currentPermission.value = null
|
||||
@@ -629,6 +662,7 @@ const showAddPermissionModal = () => {
|
||||
permissionModalVisible.value = true
|
||||
}
|
||||
|
||||
/** showEditPermissionModal is a local helper used by this page script. */
|
||||
const showEditPermissionModal = (record: Record<string, any>) => {
|
||||
isEditPermission.value = true
|
||||
currentPermission.value = record as PermissionVO
|
||||
@@ -642,6 +676,7 @@ const showEditPermissionModal = (record: Record<string, any>) => {
|
||||
permissionModalVisible.value = true
|
||||
}
|
||||
|
||||
/** handlePermissionModalOk is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handlePermissionModalOk = async () => {
|
||||
try {
|
||||
await permissionFormRef.value?.validate()
|
||||
@@ -667,11 +702,13 @@ const handlePermissionModalOk = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handlePermissionModalCancel is a local helper used by this page script. */
|
||||
const handlePermissionModalCancel = () => {
|
||||
permissionModalVisible.value = false
|
||||
permissionFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
/** handleDeletePermission is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleDeletePermission = async (record: Record<string, any>) => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
|
||||
@@ -300,7 +300,7 @@
|
||||
:key="artist.id"
|
||||
:value="artist.id.toString()"
|
||||
>
|
||||
{{ artist.nickname }}
|
||||
{{ artist.nickname }}{{ artist.type === 2 ? '(店长 · 参与制作)' : '' }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
@@ -453,7 +453,7 @@
|
||||
:key="artist?.id"
|
||||
:value="artist?.id?.toString()"
|
||||
>
|
||||
{{ artist?.nickname || '' }}
|
||||
{{ artist?.nickname || '' }}{{ artist?.type === 2 ? '(店长 · 参与制作)' : '' }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
@@ -485,6 +485,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* ProductsView 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, ref, reactive, onMounted, watch } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
@@ -506,33 +510,48 @@ import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** searchText is a reactive state variable used by the template and event handlers. */
|
||||
const searchText = ref('')
|
||||
const productList = ref<Product[]>([])
|
||||
/** modalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const modalVisible = ref(false)
|
||||
/** viewModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const viewModalVisible = ref(false)
|
||||
/** modalLoading is a reactive state variable used by the template and event handlers. */
|
||||
const modalLoading = ref(false)
|
||||
/** isEdit is a reactive state variable used by the template and event handlers. */
|
||||
const isEdit = ref(false)
|
||||
const currentProduct = ref<Product | null>(null)
|
||||
const shops = ref<Shop[]>([])
|
||||
/** loadingShops is a reactive state variable used by the template and event handlers. */
|
||||
const loadingShops = ref(false)
|
||||
const tags = ref<any[]>([])
|
||||
/** loadingTags is a reactive state variable used by the template and event handlers. */
|
||||
const loadingTags = ref(false)
|
||||
const artists = ref<any[]>([])
|
||||
/** loadingArtists is a reactive state variable used by the template and event handlers. */
|
||||
const loadingArtists = ref(false)
|
||||
const coupons = ref<any[]>([])
|
||||
/** loadingCoupons is a reactive state variable used by the template and event handlers. */
|
||||
const loadingCoupons = ref(false)
|
||||
/** previewVisible is a reactive state variable used by the template and event handlers. */
|
||||
const previewVisible = ref(false)
|
||||
/** previewImage is a reactive state variable used by the template and event handlers. */
|
||||
const previewImage = ref('')
|
||||
const imageFileList = ref<any[]>([])
|
||||
const uploadedFileIds = ref<string[]>([])
|
||||
const imageUrls = ref<Record<string, string[]>>({})
|
||||
const viewImageUrls = ref<string[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
/** isAdmin is a reactive state variable used by the template and event handlers. */
|
||||
const isAdmin = ref(false)
|
||||
const formRef = ref<any>(null)
|
||||
const uploadTaskMap = new Map<string, ChunkUploadTask<any>>()
|
||||
/** activeUploadCount is a reactive state variable used by the template and event handlers. */
|
||||
const activeUploadCount = ref(0)
|
||||
/** isUploadPending is a reactive state variable used by the template and event handlers. */
|
||||
const isUploadPending = computed(() => activeUploadCount.value > 0)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
const requestTokens = reactive({
|
||||
@@ -543,13 +562,16 @@ const requestTokens = reactive({
|
||||
products: 0
|
||||
})
|
||||
|
||||
/** nextRequestToken is a local helper used by this page script. */
|
||||
const nextRequestToken = (key: keyof typeof requestTokens) => {
|
||||
requestTokens[key] += 1
|
||||
return requestTokens[key]
|
||||
}
|
||||
|
||||
/** isLatestRequestToken is a local helper used by this page script. */
|
||||
const isLatestRequestToken = (key: keyof typeof requestTokens, token: number) => requestTokens[key] === token
|
||||
|
||||
/** formatDuration is a local helper used by this page script. */
|
||||
const formatDuration = (value?: string | number | null) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return '--'
|
||||
@@ -595,6 +617,7 @@ const formState = reactive({
|
||||
availableCoupons: [] as string[]
|
||||
})
|
||||
|
||||
/** validateInteractionCount is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const validateInteractionCount = async (_rule: any, value: number | undefined) => {
|
||||
if (value === undefined || value === null) {
|
||||
return Promise.resolve()
|
||||
@@ -629,12 +652,14 @@ const columns = [
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
/** getShopName is a local helper used by this page script. */
|
||||
const getShopName = (shopId: IdType): string => {
|
||||
const normalizedShopId = normalizeShopIdValue(shopId)
|
||||
const shop = shops.value.find(s => normalizeShopIdValue(s.id) === normalizedShopId)
|
||||
return shop ? shop.shopName : '未知店铺'
|
||||
}
|
||||
|
||||
/** normalizeShopIdValue is a local helper used by this page script. */
|
||||
const normalizeShopIdValue = (value: string | number | undefined | null) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return ''
|
||||
@@ -642,6 +667,7 @@ const normalizeShopIdValue = (value: string | number | undefined | null) => {
|
||||
return String(value)
|
||||
}
|
||||
|
||||
/** normalizeInteractionCount is a local helper used by this page script. */
|
||||
const normalizeInteractionCount = (value: unknown) => {
|
||||
const numericValue = Number(value)
|
||||
if (!Number.isFinite(numericValue) || numericValue < 0) {
|
||||
@@ -650,6 +676,7 @@ const normalizeInteractionCount = (value: unknown) => {
|
||||
return Math.floor(numericValue)
|
||||
}
|
||||
|
||||
/** getCurrentUserInfo is a local helper used by this page script. */
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
@@ -665,13 +692,16 @@ const getCurrentUserInfo = () => {
|
||||
return null
|
||||
}
|
||||
|
||||
/** canManageAvailableCoupons is a local helper used by this page script. */
|
||||
const canManageAvailableCoupons = () => {
|
||||
const userInfo = getCurrentUserInfo()
|
||||
return Boolean(userInfo && (userInfo.type === 2 || userInfo.type === 4))
|
||||
}
|
||||
|
||||
/** isCouponSelectionDisabled is a reactive state variable used by the template and event handlers. */
|
||||
const isCouponSelectionDisabled = computed(() => !canManageAvailableCoupons())
|
||||
|
||||
/** fetchShops is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchShops = async () => {
|
||||
const requestToken = nextRequestToken('shops')
|
||||
loadingShops.value = true
|
||||
@@ -712,6 +742,7 @@ const fetchShops = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchTags is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchTags = async (shopId?: IdType) => {
|
||||
const requestToken = nextRequestToken('tags')
|
||||
loadingTags.value = true
|
||||
@@ -736,6 +767,7 @@ const fetchTags = async (shopId?: IdType) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchArtists is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchArtists = async (shopId?: IdType) => {
|
||||
const requestToken = nextRequestToken('artists')
|
||||
loadingArtists.value = true
|
||||
@@ -755,6 +787,7 @@ const fetchArtists = async (shopId?: IdType) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** syncAvailableCouponSelection is a local helper used by this page script. */
|
||||
const syncAvailableCouponSelection = () => {
|
||||
const availableCouponIdSet = new Set(
|
||||
coupons.value
|
||||
@@ -765,6 +798,7 @@ const syncAvailableCouponSelection = () => {
|
||||
formState.availableCoupons = formState.availableCoupons.filter(couponId => availableCouponIdSet.has(String(couponId)))
|
||||
}
|
||||
|
||||
/** fetchCoupons is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchCoupons = async (shopId?: IdType) => {
|
||||
if (!shopId) {
|
||||
nextRequestToken('coupons')
|
||||
@@ -793,6 +827,7 @@ const fetchCoupons = async (shopId?: IdType) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchProductList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchProductList = async () => {
|
||||
const requestToken = nextRequestToken('products')
|
||||
loading.value = true
|
||||
@@ -829,6 +864,7 @@ const fetchProductList = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** loadImageUrls is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadImageUrls = async (products: Product[], requestToken?: number) => {
|
||||
const nextImageUrls: Record<string, string[]> = {}
|
||||
for (const product of products) {
|
||||
@@ -870,6 +906,7 @@ const loadImageUrls = async (products: Product[], requestToken?: number) => {
|
||||
return nextImageUrls
|
||||
}
|
||||
|
||||
/** getProductImages is a local helper used by this page script. */
|
||||
const getProductImages = (product: Product | Record<string, any>): string[] => {
|
||||
const productId = 'id' in product ? product.id : (product as any).id
|
||||
if (productId !== undefined) {
|
||||
@@ -878,17 +915,20 @@ const getProductImages = (product: Product | Record<string, any>): string[] => {
|
||||
return [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
|
||||
/** 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(() => fetchProductList())
|
||||
}
|
||||
|
||||
/** 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
|
||||
pagination.pageSize = pag.pageSize
|
||||
await runWithGlobalLoading(() => fetchProductList())
|
||||
}
|
||||
|
||||
/** showAddModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const showAddModal = async () => {
|
||||
isEdit.value = false
|
||||
currentProduct.value = null
|
||||
@@ -918,6 +958,7 @@ const showAddModal = async () => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showEditModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const showEditModal = async (record: Product | Record<string, any>) => {
|
||||
isEdit.value = true
|
||||
currentProduct.value = record as Product
|
||||
@@ -976,6 +1017,7 @@ const showEditModal = async (record: Product | Record<string, any>) => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showViewModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const showViewModal = async (record: Product | Record<string, any>) => {
|
||||
const recordShopId = 'shopId' in record ? record.shopId : (record as any).shopId
|
||||
const recordTitle = 'title' in record ? record.title : (record as any).title
|
||||
@@ -1044,17 +1086,21 @@ const showViewModal = async (record: Product | Record<string, any>) => {
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
/** handleViewModalCancel is a local helper used by this page script. */
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
viewImageUrls.value = []
|
||||
}
|
||||
|
||||
/** cancelAllPendingUploads is a local helper used by this page script. */
|
||||
const cancelAllPendingUploads = () => {
|
||||
uploadTaskMap.forEach(task => task.cancel())
|
||||
}
|
||||
|
||||
/** getDraftKey is a local helper used by this page script. */
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-products', isEdit.value ? 'edit' : 'create', currentProduct.value?.id ?? 'new')
|
||||
|
||||
/** buildDraftPayload is a local helper used by this page script. */
|
||||
const buildDraftPayload = () => ({
|
||||
formState: {
|
||||
shopId: formState.shopId,
|
||||
@@ -1072,6 +1118,7 @@ const buildDraftPayload = () => ({
|
||||
uploadedFileIds: [...uploadedFileIds.value]
|
||||
})
|
||||
|
||||
/** buildImageFileListByIds is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const buildImageFileListByIds = async (ids: string[]) => {
|
||||
const fileList = []
|
||||
for (const [index, id] of ids.entries()) {
|
||||
@@ -1101,6 +1148,7 @@ const buildImageFileListByIds = async (ids: string[]) => {
|
||||
return fileList
|
||||
}
|
||||
|
||||
/** restoreDraft is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const restoreDraft = async () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
@@ -1117,6 +1165,7 @@ const restoreDraft = async () => {
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/** handleSaveDraft is a local helper used by this page script. */
|
||||
const handleSaveDraft = () => {
|
||||
if (isUploadPending.value) {
|
||||
message.warning('图片上传完成后才能暂存')
|
||||
@@ -1127,6 +1176,7 @@ const handleSaveDraft = () => {
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
/** handleClearDraft is a local helper used by this page script. */
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
@@ -1135,11 +1185,13 @@ const handleClearDraft = (showMessage = true) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** syncUploadedFileIds is a local helper used by this page script. */
|
||||
const syncUploadedFileIds = (fileIds: string[]) => {
|
||||
uploadedFileIds.value = Array.from(new Set(fileIds.filter(id => Boolean(id))))
|
||||
formState.imageFileIds = uploadedFileIds.value.join(',')
|
||||
}
|
||||
|
||||
/** getUploadResponse is a local helper used by this page script. */
|
||||
const getUploadResponse = (file: any) => {
|
||||
if (!file || typeof file !== 'object') {
|
||||
return null
|
||||
@@ -1147,6 +1199,7 @@ const getUploadResponse = (file: any) => {
|
||||
return file.response || null
|
||||
}
|
||||
|
||||
/** resolveUploadedFileId is a local helper used by this page script. */
|
||||
const resolveUploadedFileId = (file: any) => {
|
||||
const response = getUploadResponse(file)
|
||||
const responseId = response?.id ?? response?.data?.id ?? file?.fileId
|
||||
@@ -1167,6 +1220,7 @@ const resolveUploadedFileId = (file: any) => {
|
||||
return ''
|
||||
}
|
||||
|
||||
/** getPreviewUrlFromFile is a local helper used by this page script. */
|
||||
const getPreviewUrlFromFile = (file: any) => {
|
||||
const fileUrl = typeof file?.url === 'string' ? file.url : ''
|
||||
if (fileUrl && !/^\d+$/.test(fileUrl)) {
|
||||
@@ -1181,6 +1235,7 @@ const getPreviewUrlFromFile = (file: any) => {
|
||||
return ''
|
||||
}
|
||||
|
||||
/** beforeUpload is a local helper used by this page script. */
|
||||
const beforeUpload = (file: File) => {
|
||||
const isImage = file.type.startsWith('image/')
|
||||
if (!isImage) {
|
||||
@@ -1190,6 +1245,7 @@ const beforeUpload = (file: File) => {
|
||||
}
|
||||
|
||||
// 作品图片走分片上传,并在上传前做压缩兜底,保证大图也能稳定进入对象存储。
|
||||
/** handleUploadImage is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleUploadImage = async (options: any) => {
|
||||
const { file, onSuccess, onError, onProgress } = options
|
||||
let successMessage = '图片上传成功'
|
||||
@@ -1247,6 +1303,7 @@ const handleUploadImage = async (options: any) => {
|
||||
}
|
||||
|
||||
// Ant Upload 的文件对象来源很多,预览时优先复用已有 URL,缺失时再回源签名地址。
|
||||
/** handlePreview is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handlePreview = async (file: any) => {
|
||||
try {
|
||||
const cachedPreviewUrl = getPreviewUrlFromFile(file)
|
||||
@@ -1274,6 +1331,7 @@ const handlePreview = async (file: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleRemove is a local helper used by this page script. */
|
||||
const handleRemove = (file: any) => {
|
||||
const uploadTask = uploadTaskMap.get(String(file.uid))
|
||||
if (uploadTask) {
|
||||
@@ -1289,6 +1347,7 @@ const handleRemove = (file: any) => {
|
||||
return true
|
||||
}
|
||||
|
||||
/** handleModalOk is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
if (isUploadPending.value) {
|
||||
@@ -1341,12 +1400,14 @@ const handleModalOk = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleModalCancel is a local helper used by this page script. */
|
||||
const handleModalCancel = () => {
|
||||
cancelAllPendingUploads()
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
/** handleDelete is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleDelete = async (record: Product | Record<string, any>) => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
@@ -1363,6 +1424,7 @@ const handleDelete = async (record: Product | Record<string, any>) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleSelectAllCoupons is a local helper used by this page script. */
|
||||
const handleSelectAllCoupons = () => {
|
||||
if (isCouponSelectionDisabled.value) {
|
||||
return
|
||||
@@ -1373,6 +1435,7 @@ const handleSelectAllCoupons = () => {
|
||||
.map(id => String(id))
|
||||
}
|
||||
|
||||
/** handleClearAvailableCoupons is a local helper used by this page script. */
|
||||
const handleClearAvailableCoupons = () => {
|
||||
formState.availableCoupons = []
|
||||
}
|
||||
|
||||
@@ -75,6 +75,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* ProfileView 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, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
@@ -91,15 +95,24 @@ import {
|
||||
const router = useRouter()
|
||||
const { userPermissions, loadUserPermissions, clearPermissions } = usePermission()
|
||||
|
||||
/** userInfo is a reactive state variable used by the template and event handlers. */
|
||||
const userInfo = ref(loadCachedAdminUserInfo())
|
||||
/** selectedShopId is a reactive state variable used by the template and event handlers. */
|
||||
const selectedShopId = ref(userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined)
|
||||
/** shopSwitchLoading is a reactive state variable used by the template and event handlers. */
|
||||
const shopSwitchLoading = ref(false)
|
||||
|
||||
/** currentShopName is a reactive state variable used by the template and event handlers. */
|
||||
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
|
||||
/** roleLabel is a reactive state variable used by the template and event handlers. */
|
||||
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
|
||||
/** shopOptions is a reactive state variable used by the template and event handlers. */
|
||||
const shopOptions = computed(() => getAdminShopOptions(userInfo.value))
|
||||
/** shopSelectOptions is a reactive state variable used by the template and event handlers. */
|
||||
const shopSelectOptions = computed(() => shopOptions.value.map(shop => ({ label: shop.name, value: shop.id })))
|
||||
/** permissionCount is a reactive state variable used by the template and event handlers. */
|
||||
const permissionCount = computed(() => userPermissions.value.length)
|
||||
/** shopScopeText is a reactive state variable used by the template and event handlers. */
|
||||
const shopScopeText = computed(() => {
|
||||
if (!shopOptions.value.length) {
|
||||
return '游客模式'
|
||||
@@ -107,6 +120,7 @@ const shopScopeText = computed(() => {
|
||||
return shopOptions.value.map(item => item.name).join(' / ')
|
||||
})
|
||||
|
||||
/** persistAdminSession is a local helper used by this page script. */
|
||||
const persistAdminSession = (payload: any) => {
|
||||
localStorage.setItem('adminAccessToken', payload.accessToken)
|
||||
localStorage.setItem('adminRefreshToken', payload.refreshToken)
|
||||
@@ -114,11 +128,13 @@ const persistAdminSession = (payload: any) => {
|
||||
sessionStorage.setItem('adminAccessToken', payload.accessToken)
|
||||
}
|
||||
|
||||
/** refreshLocalUserInfo is a local helper used by this page script. */
|
||||
const refreshLocalUserInfo = () => {
|
||||
userInfo.value = loadCachedAdminUserInfo()
|
||||
selectedShopId.value = userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined
|
||||
}
|
||||
|
||||
/** handleShopChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleShopChange = async (shopId: unknown) => {
|
||||
if (typeof shopId !== 'string' && typeof shopId !== 'number') {
|
||||
return
|
||||
@@ -145,6 +161,7 @@ const handleShopChange = async (shopId: unknown) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleLogout is a local helper used by this page script. */
|
||||
const handleLogout = () => {
|
||||
Modal.confirm({
|
||||
title: '确认退出登录',
|
||||
|
||||
@@ -89,6 +89,14 @@
|
||||
@change="(checked: any) => handleStatusChange(record, checked === true)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'authorization'">
|
||||
<a-space direction="vertical" size="small">
|
||||
<a-tag :color="record.authorizationExpired ? 'red' : 'green'">
|
||||
{{ record.authorizationStatusText || (record.authorizationExpired ? '已到期' : '有效') }}
|
||||
</a-tag>
|
||||
<span>{{ formatAuthorizationExpireTime(record.authorizationExpireTime) }}</span>
|
||||
</a-space>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'shopName'">
|
||||
<div style="max-width: 180px;">
|
||||
<TableEllipsisText :text="record.shopName" />
|
||||
@@ -200,11 +208,20 @@
|
||||
<a-form-item label="店铺地址" name="address">
|
||||
<a-input v-model:value="formState.address" placeholder="请输入店铺地址" />
|
||||
</a-form-item>
|
||||
<a-form-item label="地图位置">
|
||||
<div class="map-picker-row">
|
||||
<a-input v-model:value="formState.longitude" placeholder="经度" />
|
||||
<a-input v-model:value="formState.latitude" placeholder="纬度" />
|
||||
<a-button @click="openTencentLocationPicker">腾讯地图选点</a-button>
|
||||
</div>
|
||||
<div class="map-picker-tip">选点和展示使用腾讯地图;保存经纬度后,用户端可跳转腾讯地图或高德地图导航。</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="营业时间" name="businessHours">
|
||||
<div class="business-hours-picker">
|
||||
<a-date-picker
|
||||
v-model:value="businessStartTime"
|
||||
picker="time"
|
||||
popup-class-name="yumi-date-picker-panel yumi-time-panel"
|
||||
value-format="HH:mm"
|
||||
format="HH:mm"
|
||||
placeholder="开始时间"
|
||||
@@ -216,6 +233,7 @@
|
||||
<a-date-picker
|
||||
v-model:value="businessEndTime"
|
||||
picker="time"
|
||||
popup-class-name="yumi-date-picker-panel yumi-time-panel"
|
||||
value-format="HH:mm"
|
||||
format="HH:mm"
|
||||
placeholder="结束时间"
|
||||
@@ -225,6 +243,17 @@
|
||||
/>
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="授权有效期" name="authorizationExpireTime">
|
||||
<a-date-picker
|
||||
v-model:value="formState.authorizationExpireTime"
|
||||
show-time
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
format="YYYY-MM-DD HH:mm"
|
||||
placeholder="为空表示长期有效"
|
||||
:disabled="!isAdmin"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="Banner图片">
|
||||
<div class="upload-tip">首页轮播图,建议尺寸 750x300 像素</div>
|
||||
<a-upload
|
||||
@@ -295,9 +324,18 @@
|
||||
<a-form-item label="店铺地址">
|
||||
<a-input v-model:value="viewFormState.address" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="地图位置">
|
||||
<a-input :value="formatLocation(viewFormState.longitude, viewFormState.latitude)" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="营业时间">
|
||||
<a-input v-model:value="viewFormState.businessHours" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="授权状态">
|
||||
<a-input :value="viewFormState.authorizationStatusText || '有效'" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="授权有效期">
|
||||
<a-input :value="formatAuthorizationExpireTime(viewFormState.authorizationExpireTime)" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="Banner图片">
|
||||
<div class="shop-images">
|
||||
<a-image
|
||||
@@ -345,6 +383,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* ShopsView 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, ref, reactive, onMounted } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
@@ -352,7 +394,7 @@ import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import TableEllipsisText from '@/components/TableEllipsisText.vue'
|
||||
import { DEFAULT_SHOP_IMAGE } from '@/constants'
|
||||
import { adminShopApi, adminFileApi, type Shop } from '@/api/admin'
|
||||
import { adminShopApi, adminFileApi, adminSystemParameterConfigApi, 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'
|
||||
@@ -365,21 +407,30 @@ import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** searchText is a reactive state variable used by the template and event handlers. */
|
||||
const searchText = ref('')
|
||||
const shopList = ref<Shop[]>([])
|
||||
/** modalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const modalVisible = ref(false)
|
||||
/** viewModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const viewModalVisible = ref(false)
|
||||
/** modalLoading is a reactive state variable used by the template and event handlers. */
|
||||
const modalLoading = ref(false)
|
||||
/** isEdit is a reactive state variable used by the template and event handlers. */
|
||||
const isEdit = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentShop = ref<Shop | null>(null)
|
||||
/** isAdmin is a reactive state variable used by the template and event handlers. */
|
||||
const isAdmin = ref(false)
|
||||
|
||||
// Banner图片相关
|
||||
const bannerFileList = ref<any[]>([])
|
||||
const uploadedBannerIds = ref<string[]>([])
|
||||
/** bannerPreviewVisible is a reactive state variable used by the template and event handlers. */
|
||||
const bannerPreviewVisible = ref(false)
|
||||
/** bannerPreviewImage is a reactive state variable used by the template and event handlers. */
|
||||
const bannerPreviewImage = ref('')
|
||||
|
||||
// 店铺图片相关
|
||||
@@ -390,12 +441,18 @@ const shopImageUrls = ref<Record<string, string[]>>({})
|
||||
const shopBannerUrls = ref<Record<string, string[]>>({})
|
||||
const viewImageUrls = ref<string[]>([])
|
||||
const viewBannerUrls = ref<string[]>([])
|
||||
/** previewVisible is a reactive state variable used by the template and event handlers. */
|
||||
const previewVisible = ref(false)
|
||||
/** previewImage is a reactive state variable used by the template and event handlers. */
|
||||
const previewImage = ref('')
|
||||
/** businessStartTime is a reactive state variable used by the template and event handlers. */
|
||||
const businessStartTime = ref('')
|
||||
/** businessEndTime is a reactive state variable used by the template and event handlers. */
|
||||
const businessEndTime = ref('')
|
||||
const uploadTaskMap = new Map<string, ChunkUploadTask<any>>()
|
||||
/** activeUploadCount is a reactive state variable used by the template and event handlers. */
|
||||
const activeUploadCount = ref(0)
|
||||
/** isUploadPending is a reactive state variable used by the template and event handlers. */
|
||||
const isUploadPending = computed(() => activeUploadCount.value > 0)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
@@ -404,8 +461,13 @@ const viewFormState = reactive({
|
||||
shopName: '',
|
||||
description: '',
|
||||
address: '',
|
||||
mapProvider: 'TENCENT',
|
||||
longitude: '',
|
||||
latitude: '',
|
||||
businessHours: '',
|
||||
status: 1,
|
||||
authorizationExpireTime: '',
|
||||
authorizationStatusText: '',
|
||||
coverImageFileId: '',
|
||||
imageFileIds: ''
|
||||
})
|
||||
@@ -423,8 +485,12 @@ const formState = reactive({
|
||||
shopName: '',
|
||||
description: '',
|
||||
address: '',
|
||||
mapProvider: 'TENCENT',
|
||||
longitude: '',
|
||||
latitude: '',
|
||||
businessHours: '',
|
||||
status: 1,
|
||||
authorizationExpireTime: '',
|
||||
coverImageFileId: '',
|
||||
imageFileIds: ''
|
||||
})
|
||||
@@ -455,10 +521,12 @@ const columns = [
|
||||
{ title: '店铺地址', dataIndex: 'address', key: 'address' },
|
||||
{ title: '营业时间', dataIndex: 'businessHours', key: 'businessHours' },
|
||||
{ title: '状态', key: 'status', width: 120 },
|
||||
{ title: '授权', key: 'authorization', width: 180 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
/** getCurrentUserInfo is a local helper used by this page script. */
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
@@ -474,6 +542,7 @@ const getCurrentUserInfo = () => {
|
||||
return null
|
||||
}
|
||||
|
||||
/** loadImageUrls is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadImageUrls = async (shops: Shop[]) => {
|
||||
for (const shop of shops) {
|
||||
// 加载店铺图片
|
||||
@@ -538,6 +607,7 @@ const loadImageUrls = async (shops: Shop[]) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** getShopImages is a local helper used by this page script. */
|
||||
const getShopImages = (shop: Shop | Record<string, any>): string[] => {
|
||||
const shopId = 'id' in shop ? shop.id : (shop as any).id
|
||||
if (shopId !== undefined) {
|
||||
@@ -546,6 +616,7 @@ const getShopImages = (shop: Shop | Record<string, any>): string[] => {
|
||||
return []
|
||||
}
|
||||
|
||||
/** getShopBannerImages is a local helper used by this page script. */
|
||||
const getShopBannerImages = (shop: Shop | Record<string, any>): string[] => {
|
||||
const shopId = 'id' in shop ? shop.id : (shop as any).id
|
||||
if (shopId !== undefined) {
|
||||
@@ -554,6 +625,52 @@ const getShopBannerImages = (shop: Shop | Record<string, any>): string[] => {
|
||||
return []
|
||||
}
|
||||
|
||||
/** formatAuthorizationExpireTime is a local helper used by this page script. */
|
||||
const formatAuthorizationExpireTime = (value?: string) => {
|
||||
if (!value) {
|
||||
return '长期有效'
|
||||
}
|
||||
return value.replace('T', ' ').slice(0, 16)
|
||||
}
|
||||
|
||||
const formatLocation = (longitude?: string | number, latitude?: string | number) => {
|
||||
return longitude && latitude ? `${longitude}, ${latitude}` : '未设置地图坐标'
|
||||
}
|
||||
|
||||
const openTencentLocationPicker = async () => {
|
||||
const response = await adminSystemParameterConfigApi.getTencentMapKey()
|
||||
const key = response?.key || ''
|
||||
if (!key) {
|
||||
message.warning('请先在参数管理中配置腾讯位置服务 Key')
|
||||
return
|
||||
}
|
||||
|
||||
const keyword = encodeURIComponent(formState.address || formState.shopName || '')
|
||||
const url = `https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=${key}&referer=yuminail&keyword=${keyword}`
|
||||
const picker = window.open(url, 'yuminailTencentLocationPicker', 'width=900,height=680')
|
||||
const handleMessage = (event: MessageEvent) => {
|
||||
const data = event.data || {}
|
||||
const location = data.loclatlng || data.latlng || data.location
|
||||
if (!location) {
|
||||
return
|
||||
}
|
||||
formState.latitude = String(location.lat || location.latitude || '')
|
||||
formState.longitude = String(location.lng || location.longitude || '')
|
||||
formState.mapProvider = 'TENCENT'
|
||||
if (data.poiaddress || data.addr || data.address) {
|
||||
formState.address = data.poiaddress || data.addr || data.address
|
||||
}
|
||||
if (data.poiname && !formState.shopName) {
|
||||
formState.shopName = data.poiname
|
||||
}
|
||||
message.success('已选择腾讯地图位置')
|
||||
window.removeEventListener('message', handleMessage)
|
||||
picker?.close()
|
||||
}
|
||||
window.addEventListener('message', handleMessage)
|
||||
}
|
||||
|
||||
/** fetchShopList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchShopList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -582,17 +699,20 @@ const fetchShopList = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** 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(() => fetchShopList())
|
||||
}
|
||||
|
||||
/** 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
|
||||
pagination.pageSize = pag.pageSize
|
||||
await runWithGlobalLoading(() => fetchShopList())
|
||||
}
|
||||
|
||||
/** beforeUpload is a local helper used by this page script. */
|
||||
const beforeUpload = (file: File) => {
|
||||
const isImage = file.type.startsWith('image/')
|
||||
if (!isImage) {
|
||||
@@ -606,6 +726,7 @@ const beforeUpload = (file: File) => {
|
||||
}
|
||||
|
||||
// Banner 与门店环境图分开维护上传任务,便于表单回显和删除时分别同步 fileId 列表。
|
||||
/** handleUploadBanner is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleUploadBanner = async (options: any) => {
|
||||
const { file, onSuccess, onError, onProgress } = options
|
||||
const taskKey = `banner:${String(file.uid)}`
|
||||
@@ -645,6 +766,7 @@ const handleUploadBanner = async (options: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleBannerPreview is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleBannerPreview = async (file: any) => {
|
||||
try {
|
||||
const cachedPreviewUrl = getPreviewUrlFromFile(file)
|
||||
@@ -671,6 +793,7 @@ const handleBannerPreview = async (file: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleBannerRemove is a local helper used by this page script. */
|
||||
const handleBannerRemove = (file: any) => {
|
||||
const task = uploadTaskMap.get(`banner:${String(file.uid)}`)
|
||||
if (task) {
|
||||
@@ -686,6 +809,7 @@ const handleBannerRemove = (file: any) => {
|
||||
}
|
||||
|
||||
// 店铺环境图与 Banner 走同一套分片上传协议,但写入不同业务字段。
|
||||
/** handleUploadImage is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleUploadImage = async (options: any) => {
|
||||
const { file, onSuccess, onError, onProgress } = options
|
||||
const taskKey = `image:${String(file.uid)}`
|
||||
@@ -726,6 +850,7 @@ const handleUploadImage = async (options: any) => {
|
||||
}
|
||||
|
||||
// 编辑态下 Upload 里的文件可能只剩 fileId,所以预览时需要兼容本地 URL 与远端签名地址两种来源。
|
||||
/** handlePreview is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handlePreview = async (file: any) => {
|
||||
try {
|
||||
const cachedPreviewUrl = getPreviewUrlFromFile(file)
|
||||
@@ -752,6 +877,7 @@ const handlePreview = async (file: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleRemove is a local helper used by this page script. */
|
||||
const handleRemove = (file: any) => {
|
||||
const task = uploadTaskMap.get(`image:${String(file.uid)}`)
|
||||
if (task) {
|
||||
@@ -766,12 +892,14 @@ const handleRemove = (file: any) => {
|
||||
return true
|
||||
}
|
||||
|
||||
/** syncBusinessHoursValue is a local helper used by this page script. */
|
||||
const syncBusinessHoursValue = () => {
|
||||
formState.businessHours = businessStartTime.value && businessEndTime.value
|
||||
? `${businessStartTime.value}-${businessEndTime.value}`
|
||||
: ''
|
||||
}
|
||||
|
||||
/** setBusinessHoursValue is a local helper used by this page script. */
|
||||
const setBusinessHoursValue = (value?: string) => {
|
||||
const matched = (value || '').match(/(\d{2}:\d{2})\s*-\s*(\d{2}:\d{2})/)
|
||||
businessStartTime.value = matched?.[1] || ''
|
||||
@@ -779,11 +907,13 @@ const setBusinessHoursValue = (value?: string) => {
|
||||
syncBusinessHoursValue()
|
||||
}
|
||||
|
||||
/** handleBusinessHoursChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleBusinessHoursChange = async () => {
|
||||
syncBusinessHoursValue()
|
||||
await formRef.value?.validateFields?.(['businessHours']).catch(() => undefined)
|
||||
}
|
||||
|
||||
/** showAddModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const showAddModal = async () => {
|
||||
isEdit.value = false
|
||||
currentShop.value = null
|
||||
@@ -791,8 +921,12 @@ const showAddModal = async () => {
|
||||
shopName: '',
|
||||
description: '',
|
||||
address: '',
|
||||
mapProvider: 'TENCENT',
|
||||
longitude: '',
|
||||
latitude: '',
|
||||
businessHours: '',
|
||||
status: 1,
|
||||
authorizationExpireTime: '',
|
||||
coverImageFileId: '',
|
||||
imageFileIds: ''
|
||||
})
|
||||
@@ -805,6 +939,7 @@ const showAddModal = async () => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showEditModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const showEditModal = async (record: Shop | Record<string, any>) => {
|
||||
isEdit.value = true
|
||||
currentShop.value = record as Shop
|
||||
@@ -812,8 +947,12 @@ const showEditModal = async (record: Shop | Record<string, any>) => {
|
||||
shopName: 'shopName' in record ? record.shopName : (record as any).shopName,
|
||||
description: 'description' in record ? record.description : (record as any).description,
|
||||
address: 'address' in record ? record.address : (record as any).address,
|
||||
mapProvider: 'TENCENT',
|
||||
longitude: 'longitude' in record ? record.longitude : (record as any).longitude,
|
||||
latitude: 'latitude' in record ? record.latitude : (record as any).latitude,
|
||||
businessHours: 'businessHours' in record ? record.businessHours : (record as any).businessHours,
|
||||
status: 'status' in record ? (record.status ?? 1) : ((record as any).status ?? 1),
|
||||
authorizationExpireTime: 'authorizationExpireTime' in record ? record.authorizationExpireTime : (record as any).authorizationExpireTime,
|
||||
coverImageFileId: 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId,
|
||||
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
})
|
||||
@@ -845,13 +984,19 @@ const showEditModal = async (record: Shop | Record<string, any>) => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showViewModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const showViewModal = async (record: Shop | Record<string, any>) => {
|
||||
Object.assign(viewFormState, {
|
||||
shopName: 'shopName' in record ? record.shopName : (record as any).shopName,
|
||||
description: 'description' in record ? record.description : (record as any).description,
|
||||
address: 'address' in record ? record.address : (record as any).address,
|
||||
mapProvider: 'TENCENT',
|
||||
longitude: 'longitude' in record ? record.longitude : (record as any).longitude,
|
||||
latitude: 'latitude' in record ? record.latitude : (record as any).latitude,
|
||||
businessHours: 'businessHours' in record ? record.businessHours : (record as any).businessHours,
|
||||
status: 'status' in record ? (record.status ?? 1) : ((record as any).status ?? 1),
|
||||
authorizationExpireTime: 'authorizationExpireTime' in record ? record.authorizationExpireTime : (record as any).authorizationExpireTime,
|
||||
authorizationStatusText: 'authorizationStatusText' in record ? record.authorizationStatusText : (record as any).authorizationStatusText,
|
||||
coverImageFileId: 'coverImageFileId' in record ? record.coverImageFileId : (record as any).coverImageFileId,
|
||||
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
})
|
||||
@@ -907,25 +1052,33 @@ const showViewModal = async (record: Shop | Record<string, any>) => {
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
/** handleViewModalCancel is a local helper used by this page script. */
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
viewImageUrls.value = []
|
||||
viewBannerUrls.value = []
|
||||
}
|
||||
|
||||
/** cancelAllPendingUploads is a local helper used by this page script. */
|
||||
const cancelAllPendingUploads = () => {
|
||||
uploadTaskMap.forEach(task => task.cancel())
|
||||
}
|
||||
|
||||
/** getDraftKey is a local helper used by this page script. */
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-shops', isEdit.value ? 'edit' : 'create', currentShop.value?.id ?? 'new')
|
||||
|
||||
/** buildDraftPayload is a local helper used by this page script. */
|
||||
const buildDraftPayload = () => ({
|
||||
formState: {
|
||||
shopName: formState.shopName,
|
||||
description: formState.description,
|
||||
address: formState.address,
|
||||
mapProvider: 'TENCENT',
|
||||
longitude: formState.longitude,
|
||||
latitude: formState.latitude,
|
||||
businessHours: formState.businessHours,
|
||||
status: formState.status,
|
||||
authorizationExpireTime: formState.authorizationExpireTime,
|
||||
coverImageFileId: formState.coverImageFileId,
|
||||
imageFileIds: formState.imageFileIds
|
||||
},
|
||||
@@ -935,6 +1088,7 @@ const buildDraftPayload = () => ({
|
||||
uploadedFileIds: [...uploadedFileIds.value]
|
||||
})
|
||||
|
||||
/** buildShopUploadFileList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const buildShopUploadFileList = async (ids: string[], fileNamePrefix: string) => {
|
||||
const fileList = []
|
||||
for (const [index, id] of ids.entries()) {
|
||||
@@ -964,6 +1118,7 @@ const buildShopUploadFileList = async (ids: string[], fileNamePrefix: string) =>
|
||||
return fileList
|
||||
}
|
||||
|
||||
/** restoreDraft is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const restoreDraft = async () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
@@ -982,6 +1137,7 @@ const restoreDraft = async () => {
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/** handleSaveDraft is a local helper used by this page script. */
|
||||
const handleSaveDraft = () => {
|
||||
if (isUploadPending.value) {
|
||||
message.warning('图片上传完成后才能暂存')
|
||||
@@ -992,6 +1148,7 @@ const handleSaveDraft = () => {
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
/** handleClearDraft is a local helper used by this page script. */
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
@@ -1000,16 +1157,19 @@ const handleClearDraft = (showMessage = true) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** syncUploadedBannerIds is a local helper used by this page script. */
|
||||
const syncUploadedBannerIds = (fileIds: string[]) => {
|
||||
uploadedBannerIds.value = Array.from(new Set(fileIds.filter(id => Boolean(id))))
|
||||
formState.coverImageFileId = uploadedBannerIds.value.join(',')
|
||||
}
|
||||
|
||||
/** syncUploadedFileIds is a local helper used by this page script. */
|
||||
const syncUploadedFileIds = (fileIds: string[]) => {
|
||||
uploadedFileIds.value = Array.from(new Set(fileIds.filter(id => Boolean(id))))
|
||||
formState.imageFileIds = uploadedFileIds.value.join(',')
|
||||
}
|
||||
|
||||
/** getUploadResponse is a local helper used by this page script. */
|
||||
const getUploadResponse = (file: any) => {
|
||||
if (!file || typeof file !== 'object') {
|
||||
return null
|
||||
@@ -1017,6 +1177,7 @@ const getUploadResponse = (file: any) => {
|
||||
return file.response || null
|
||||
}
|
||||
|
||||
/** resolveUploadedFileId is a local helper used by this page script. */
|
||||
const resolveUploadedFileId = (file: any) => {
|
||||
const response = getUploadResponse(file)
|
||||
const responseId = response?.id ?? response?.data?.id ?? file?.fileId
|
||||
@@ -1037,6 +1198,7 @@ const resolveUploadedFileId = (file: any) => {
|
||||
return ''
|
||||
}
|
||||
|
||||
/** getPreviewUrlFromFile is a local helper used by this page script. */
|
||||
const getPreviewUrlFromFile = (file: any) => {
|
||||
const fileUrl = typeof file?.url === 'string' ? file.url : ''
|
||||
if (fileUrl && !/^\d+$/.test(fileUrl)) {
|
||||
@@ -1051,6 +1213,7 @@ const getPreviewUrlFromFile = (file: any) => {
|
||||
return ''
|
||||
}
|
||||
|
||||
/** handleModalOk is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
if (isUploadPending.value) {
|
||||
@@ -1081,6 +1244,7 @@ const handleModalOk = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleModalCancel is a local helper used by this page script. */
|
||||
const handleModalCancel = () => {
|
||||
cancelAllPendingUploads()
|
||||
modalVisible.value = false
|
||||
@@ -1092,6 +1256,7 @@ const handleModalCancel = () => {
|
||||
syncUploadedFileIds([])
|
||||
}
|
||||
|
||||
/** handleDelete is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleDelete = async (record: Shop | Record<string, any>) => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
@@ -1105,6 +1270,7 @@ const handleDelete = async (record: Shop | Record<string, any>) => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleStatusChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleStatusChange = async (record: Shop | Record<string, any>, enabled: boolean) => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
@@ -1136,6 +1302,19 @@ onMounted(async () => {
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.map-picker-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.map-picker-tip {
|
||||
margin-top: 8px;
|
||||
color: #8c8c8c;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.shop-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -0,0 +1,350 @@
|
||||
<template>
|
||||
<div class="system-messages admin-page">
|
||||
<a-page-header title="消息发布" sub-title="发布站内消息,支持文本和单张图片" />
|
||||
|
||||
<a-card :bordered="false" class="admin-section-card">
|
||||
<template #title>发布消息</template>
|
||||
<a-form layout="vertical" :model="form">
|
||||
<a-form-item label="标题" required>
|
||||
<a-input v-model:value="form.title" :maxlength="100" placeholder="请输入消息标题" />
|
||||
</a-form-item>
|
||||
<a-form-item label="内容">
|
||||
<a-textarea v-model:value="form.content" :rows="5" :maxlength="2000" placeholder="请输入消息内容,可配合图片展示" />
|
||||
</a-form-item>
|
||||
<a-form-item label="消息图片">
|
||||
<div class="image-upload-row">
|
||||
<a-upload
|
||||
accept="image/*"
|
||||
list-type="picture-card"
|
||||
:show-upload-list="false"
|
||||
:custom-request="handleImageUpload"
|
||||
>
|
||||
<div v-if="!imagePreviewUrl" class="upload-placeholder">
|
||||
<span class="upload-plus">+</span>
|
||||
<span>上传图片</span>
|
||||
</div>
|
||||
<img v-else class="message-image-preview" :src="imagePreviewUrl" alt="消息图片预览" />
|
||||
</a-upload>
|
||||
<div class="image-upload-copy">
|
||||
<div>每条消息最多上传一张图片。</div>
|
||||
<small>建议使用 JPG/PNG/WebP,图片会在弹窗和通知详情中展示。</small>
|
||||
<a-button v-if="form.imageFileId" type="link" danger size="small" @click="removeImage">移除图片</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-row :gutter="16">
|
||||
<a-col :xs="24" :md="10">
|
||||
<a-form-item label="接收范围" required>
|
||||
<a-select v-model:value="form.targetType" @change="handleTargetTypeChange">
|
||||
<a-select-option v-for="item in targetTypes" :key="item.value" :value="item.value">
|
||||
{{ item.label }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col v-if="needsShopSelection" :xs="24" :md="14">
|
||||
<a-form-item label="接收店铺" required>
|
||||
<a-select v-model:value="form.shopIds" mode="multiple" :options="shopOptions" placeholder="请选择店铺" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col v-if="form.targetType === 'SELECTED_USERS'" :xs="24" :md="14">
|
||||
<a-form-item label="接收用户" required>
|
||||
<a-select
|
||||
v-model:value="form.userIds"
|
||||
mode="multiple"
|
||||
show-search
|
||||
option-filter-prop="label"
|
||||
:options="userOptions"
|
||||
placeholder="请选择用户"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-form-item>
|
||||
<a-checkbox v-model:checked="popupEnabled">弹窗显示一次</a-checkbox>
|
||||
</a-form-item>
|
||||
<a-space>
|
||||
<a-button type="primary" :loading="saving" @click="handlePublish">发布</a-button>
|
||||
<a-button @click="resetForm">清空</a-button>
|
||||
</a-space>
|
||||
</a-form>
|
||||
</a-card>
|
||||
|
||||
<a-card :bordered="false" class="admin-section-card">
|
||||
<template #title>发布记录</template>
|
||||
<a-table :columns="columns" :data-source="messages" :loading="loading" row-key="id" :pagination="{ pageSize: 8 }">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'image'">
|
||||
<a-image v-if="record.imageUrl" :src="record.imageUrl" :width="54" :height="54" class="table-image" />
|
||||
<span v-else class="muted">无</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 1 ? 'green' : 'default'">{{ record.status === 1 ? '已发布' : '已撤回' }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'popupEnabled'">
|
||||
<a-tag :color="record.popupEnabled === 1 ? 'blue' : 'default'">{{ record.popupEnabled === 1 ? '弹窗' : '不弹窗' }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'action'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="previewMessage(record as SystemMessageVO)">查看</a-button>
|
||||
<a-popconfirm v-if="record.status === 1" title="确定撤回这条消息吗?" @confirm="handleRevoke(record.id)">
|
||||
<a-button type="link" size="small" danger>撤回</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-card>
|
||||
|
||||
<a-modal v-model:open="previewVisible" title="消息详情" :footer="null" width="620px">
|
||||
<h3>{{ currentMessage?.title }}</h3>
|
||||
<p class="message-meta">{{ currentMessage?.publisherName }} · {{ currentMessage?.targetTypeName }} · {{ currentMessage?.publishTime }}</p>
|
||||
<div v-if="currentMessage?.content" class="message-content">{{ currentMessage?.content }}</div>
|
||||
<img v-if="currentMessage?.imageUrl" class="detail-image" :src="currentMessage.imageUrl" alt="消息图片" />
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* SystemMessagesView 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 } from 'ant-design-vue'
|
||||
import { adminFileApi, adminSystemMessageApi, type SystemMessageVO, type SystemMessageCreateRequest } from '@/api/admin'
|
||||
import type { IdType } from '@/utils/id'
|
||||
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** saving is a reactive state variable used by the template and event handlers. */
|
||||
const saving = ref(false)
|
||||
/** imageUploading is a reactive state variable used by the template and event handlers. */
|
||||
const imageUploading = ref(false)
|
||||
const messages = ref<SystemMessageVO[]>([])
|
||||
/** targetOptions is a reactive state variable used by the template and event handlers. */
|
||||
const targetOptions = ref({ shops: [] as any[], users: [] as any[] })
|
||||
/** popupEnabled is a reactive state variable used by the template and event handlers. */
|
||||
const popupEnabled = ref(true)
|
||||
/** previewVisible is a reactive state variable used by the template and event handlers. */
|
||||
const previewVisible = ref(false)
|
||||
const currentMessage = ref<SystemMessageVO | null>(null)
|
||||
/** imagePreviewUrl is a reactive state variable used by the template and event handlers. */
|
||||
const imagePreviewUrl = ref('')
|
||||
|
||||
const form = reactive<SystemMessageCreateRequest>({
|
||||
title: '',
|
||||
content: '',
|
||||
imageFileId: undefined,
|
||||
targetType: 'CURRENT_SHOP_ALL',
|
||||
shopIds: [],
|
||||
userIds: [],
|
||||
popupEnabled: 1
|
||||
})
|
||||
|
||||
/** targetTypes is a reactive state variable used by the template and event handlers. */
|
||||
const targetTypes = computed(() => {
|
||||
const shopCount = targetOptions.value.shops.length
|
||||
const hasPlatformScope = shopCount > 1
|
||||
return [
|
||||
...(hasPlatformScope ? [{ label: '全平台', value: 'PLATFORM_ALL' }] : []),
|
||||
{ label: hasPlatformScope ? '指定店铺全员' : '本店全员', value: hasPlatformScope ? 'SELECTED_SHOPS' : 'CURRENT_SHOP_ALL' },
|
||||
{ label: '指定用户', value: 'SELECTED_USERS' }
|
||||
]
|
||||
})
|
||||
|
||||
/** needsShopSelection is a reactive state variable used by the template and event handlers. */
|
||||
const needsShopSelection = computed(() => form.targetType === 'SELECTED_SHOPS' || form.targetType === 'SHOP_ALL')
|
||||
/** shopOptions is a reactive state variable used by the template and event handlers. */
|
||||
const shopOptions = computed(() => targetOptions.value.shops.map(shop => ({ label: shop.shopName, value: shop.id })))
|
||||
/** userOptions is a reactive state variable used by the template and event handlers. */
|
||||
const userOptions = computed(() => targetOptions.value.users.map(user => ({
|
||||
label: `${user.nickname || user.account} ${user.shopName ? `(${user.shopName})` : ''}`,
|
||||
value: user.id
|
||||
})))
|
||||
|
||||
const columns = [
|
||||
{ title: '标题', dataIndex: 'title', key: 'title' },
|
||||
{ title: '图片', key: 'image', width: 84 },
|
||||
{ title: '范围', dataIndex: 'targetTypeName', key: 'targetTypeName', width: 140 },
|
||||
{ title: '发布人', dataIndex: 'publisherName', key: 'publisherName', width: 140 },
|
||||
{ title: '弹窗', key: 'popupEnabled', width: 90 },
|
||||
{ title: '状态', key: 'status', width: 90 },
|
||||
{ title: '发布时间', dataIndex: 'publishTime', key: 'publishTime', width: 180 },
|
||||
{ title: '操作', key: 'action', width: 120 }
|
||||
]
|
||||
|
||||
/** loadData is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const [messageList, options] = await Promise.all([
|
||||
adminSystemMessageApi.listMessages(),
|
||||
adminSystemMessageApi.getTargetOptions()
|
||||
])
|
||||
messages.value = messageList || []
|
||||
targetOptions.value = options || { shops: [], users: [] }
|
||||
if (targetOptions.value.shops.length > 1 && form.targetType === 'CURRENT_SHOP_ALL') {
|
||||
form.targetType = 'PLATFORM_ALL'
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '消息数据加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** handleTargetTypeChange is a local helper used by this page script. */
|
||||
const handleTargetTypeChange = () => {
|
||||
form.shopIds = []
|
||||
form.userIds = []
|
||||
}
|
||||
|
||||
/** removeImage is a local helper used by this page script. */
|
||||
const removeImage = () => {
|
||||
form.imageFileId = undefined
|
||||
imagePreviewUrl.value = ''
|
||||
}
|
||||
|
||||
/** resetForm is a local helper used by this page script. */
|
||||
const resetForm = () => {
|
||||
form.title = ''
|
||||
form.content = ''
|
||||
form.imageFileId = undefined
|
||||
form.targetType = targetOptions.value.shops.length > 1 ? 'PLATFORM_ALL' : 'CURRENT_SHOP_ALL'
|
||||
form.shopIds = []
|
||||
form.userIds = []
|
||||
popupEnabled.value = true
|
||||
imagePreviewUrl.value = ''
|
||||
}
|
||||
|
||||
/** handleImageUpload is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleImageUpload = async (options: any) => {
|
||||
const file = options.file as File
|
||||
if (!file?.type?.startsWith('image/')) {
|
||||
message.warning('请上传图片文件')
|
||||
options.onError?.(new Error('invalid image'))
|
||||
return
|
||||
}
|
||||
if (file.size > 5 * 1024 * 1024) {
|
||||
message.warning('图片不能超过 5MB')
|
||||
options.onError?.(new Error('image too large'))
|
||||
return
|
||||
}
|
||||
imageUploading.value = true
|
||||
try {
|
||||
const uploaded = await adminFileApi.uploadFile(file)
|
||||
form.imageFileId = uploaded.id
|
||||
imagePreviewUrl.value = await adminFileApi.getSignedUrl(uploaded.id)
|
||||
options.onSuccess?.(uploaded)
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '图片上传失败')
|
||||
options.onError?.(error)
|
||||
} finally {
|
||||
imageUploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** handlePublish is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handlePublish = async () => {
|
||||
if (!form.title.trim()) return message.warning('请填写消息标题')
|
||||
if (!form.content.trim() && !form.imageFileId) return message.warning('请填写消息内容或上传消息图片')
|
||||
if (imageUploading.value) return message.warning('图片还在上传中,请稍后发布')
|
||||
if (needsShopSelection.value && !form.shopIds?.length) return message.warning('请选择接收店铺')
|
||||
if (form.targetType === 'SELECTED_USERS' && !form.userIds?.length) return message.warning('请选择接收用户')
|
||||
saving.value = true
|
||||
try {
|
||||
await adminSystemMessageApi.createMessage({ ...form, popupEnabled: popupEnabled.value ? 1 : 0 })
|
||||
message.success('消息已发布')
|
||||
resetForm()
|
||||
await loadData()
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '消息发布失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** handleRevoke is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleRevoke = async (id: IdType) => {
|
||||
await adminSystemMessageApi.revokeMessage(id)
|
||||
message.success('消息已撤回')
|
||||
await loadData()
|
||||
}
|
||||
|
||||
/** previewMessage is a local helper used by this page script. */
|
||||
const previewMessage = (record: SystemMessageVO) => {
|
||||
currentMessage.value = record
|
||||
previewVisible.value = true
|
||||
}
|
||||
|
||||
onMounted(loadData)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.system-messages {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.admin-section-card {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.image-upload-row {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.upload-placeholder {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
color: #8a7b83;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.upload-plus {
|
||||
font-size: 24px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.message-image-preview {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.image-upload-copy {
|
||||
color: #5f5660;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.image-upload-copy small,
|
||||
.message-meta,
|
||||
.muted {
|
||||
color: #7f7781;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
white-space: pre-wrap;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.detail-image {
|
||||
display: block;
|
||||
width: 100%;
|
||||
max-height: 420px;
|
||||
margin-top: 14px;
|
||||
object-fit: contain;
|
||||
border-radius: 8px;
|
||||
background: #f7f2f4;
|
||||
}
|
||||
|
||||
.table-image {
|
||||
overflow: hidden;
|
||||
border-radius: 6px;
|
||||
object-fit: cover;
|
||||
}
|
||||
</style>
|
||||
@@ -234,6 +234,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* TagsView 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 { ref, reactive, onMounted } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
@@ -252,6 +256,7 @@ import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
/** getCurrentUserInfo is a local helper used by this page script. */
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
@@ -265,11 +270,17 @@ const getCurrentUserInfo = () => {
|
||||
return null
|
||||
}
|
||||
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** modalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const modalVisible = ref(false)
|
||||
/** viewModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const viewModalVisible = ref(false)
|
||||
/** modalLoading is a reactive state variable used by the template and event handlers. */
|
||||
const modalLoading = 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 currentTag = ref<any>(null)
|
||||
@@ -286,6 +297,7 @@ const viewFormState = reactive({
|
||||
|
||||
const tagList = ref<any[]>([])
|
||||
const shops = ref<Shop[]>([])
|
||||
/** loadingShops is a reactive state variable used by the template and event handlers. */
|
||||
const loadingShops = ref(false)
|
||||
|
||||
const pagination = reactive({
|
||||
@@ -305,8 +317,10 @@ const formState = reactive({
|
||||
borderColor: '#E5E5E5'
|
||||
})
|
||||
|
||||
/** getDraftKey is a local helper used by this page script. */
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-tags', isEdit.value ? 'edit' : 'create', currentTag.value?.id ?? 'new')
|
||||
|
||||
/** buildDraftPayload is a local helper used by this page script. */
|
||||
const buildDraftPayload = () => ({
|
||||
tagName: formState.tagName,
|
||||
shopId: formState.shopId,
|
||||
@@ -315,6 +329,7 @@ const buildDraftPayload = () => ({
|
||||
borderColor: formState.borderColor
|
||||
})
|
||||
|
||||
/** restoreDraft is a local helper used by this page script. */
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
@@ -326,12 +341,14 @@ const restoreDraft = () => {
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/** handleSaveDraft is a local helper used by this page script. */
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
/** handleClearDraft is a local helper used by this page script. */
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
@@ -356,6 +373,7 @@ const columns = [
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
/** fetchTags is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchTags = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -377,6 +395,7 @@ const fetchTags = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** fetchShops is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
@@ -389,6 +408,7 @@ const fetchShops = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** normalizeShopIdValue is a local helper used by this page script. */
|
||||
const normalizeShopIdValue = (value: string | number | undefined | null) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return ''
|
||||
@@ -396,23 +416,27 @@ const normalizeShopIdValue = (value: string | number | undefined | null) => {
|
||||
return String(value)
|
||||
}
|
||||
|
||||
/** getShopName is a local helper used by this page script. */
|
||||
const getShopName = (shopId: IdType | undefined) => {
|
||||
const normalizedShopId = normalizeShopIdValue(shopId)
|
||||
const shop = shops.value.find(s => normalizeShopIdValue(s.id) === normalizedShopId)
|
||||
return shop ? shop.shopName : '未知店铺'
|
||||
}
|
||||
|
||||
/** 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(() => fetchTags())
|
||||
}
|
||||
|
||||
/** 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
|
||||
pagination.pageSize = pag.pageSize
|
||||
await runWithGlobalLoading(() => fetchTags())
|
||||
}
|
||||
|
||||
/** showAddModal is a local helper used by this page script. */
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
currentTag.value = null
|
||||
@@ -429,6 +453,7 @@ const showAddModal = () => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showEditModal is a local helper used by this page script. */
|
||||
const showEditModal = (record: any) => {
|
||||
isEdit.value = true
|
||||
currentTag.value = record
|
||||
@@ -443,6 +468,7 @@ const showEditModal = (record: any) => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showViewModal is a local helper used by this page script. */
|
||||
const showViewModal = (record: any) => {
|
||||
Object.assign(viewFormState, {
|
||||
tagName: record.tagName,
|
||||
@@ -454,10 +480,12 @@ const showViewModal = (record: any) => {
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
/** handleViewModalCancel is a local helper used by this page script. */
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
}
|
||||
|
||||
/** 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()
|
||||
@@ -492,11 +520,13 @@ const handleModalOk = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** handleModalCancel is a local helper used by this page script. */
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
/** handleDelete is a local helper used by this page script. */
|
||||
const handleDelete = (record: any) => {
|
||||
Modal.confirm({
|
||||
title: '确认删除',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
<template>
|
||||
<div class="admin-page">
|
||||
<div class="page-head">
|
||||
<div>
|
||||
<h2>VIP 充值配置</h2>
|
||||
<p>这里只配置展示档位,不会创建支付订单或修改余额。</p>
|
||||
</div>
|
||||
<a-button type="primary" @click="openCreate">新增档位</a-button>
|
||||
</div>
|
||||
|
||||
<a-table :columns="columns" :data-source="plans" :loading="loading" row-key="id">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'amount'">
|
||||
充 {{ money(record.rechargeAmount) }} 送 {{ money(record.giftAmount) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-switch :checked="record.status === 1" @change="checked => toggleStatus(record as VipRechargePlanVO, Boolean(checked))" />
|
||||
</template>
|
||||
<template v-else-if="column.key === 'action'">
|
||||
<a-button size="small" @click="openEdit(record as VipRechargePlanVO)">编辑</a-button>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<a-modal v-model:open="formOpen" :title="editingId ? '编辑档位' : '新增档位'" @ok="submit" :confirm-loading="saving">
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="所属店铺">
|
||||
<a-select v-model:value="form.shopId" :options="shopOptions" allow-clear placeholder="店长默认当前店铺" />
|
||||
</a-form-item>
|
||||
<a-form-item label="标题">
|
||||
<a-input v-model:value="form.title" />
|
||||
</a-form-item>
|
||||
<a-form-item label="充值金额">
|
||||
<a-input-number v-model:value="form.rechargeAmount" :min="0" :precision="2" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="赠送金额">
|
||||
<a-input-number v-model:value="form.giftAmount" :min="0" :precision="2" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="对应 VIP 等级">
|
||||
<a-input v-model:value="form.vipLevel" placeholder="如 青铜VIP / 白银VIP / 黄金VIP" />
|
||||
</a-form-item>
|
||||
<a-form-item label="展示说明">
|
||||
<a-textarea v-model:value="form.description" :rows="3" />
|
||||
</a-form-item>
|
||||
<a-form-item label="排序">
|
||||
<a-input-number v-model:value="form.sortOrder" style="width: 100%" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* VipRechargePlansView 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 { onMounted, reactive, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { adminShopApi, adminVipRechargePlanApi, type Shop, type VipRechargePlanVO } from '@/api/admin'
|
||||
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** saving is a reactive state variable used by the template and event handlers. */
|
||||
const saving = ref(false)
|
||||
/** formOpen is a reactive state variable used by the template and event handlers. */
|
||||
const formOpen = ref(false)
|
||||
const editingId = ref<any>()
|
||||
const plans = ref<VipRechargePlanVO[]>([])
|
||||
const shops = ref<Shop[]>([])
|
||||
const form = reactive<any>({ shopId: undefined, title: '', rechargeAmount: 0, giftAmount: 0, vipLevel: '', description: '', sortOrder: 0, status: 1 })
|
||||
|
||||
const columns = [
|
||||
{ title: '标题', dataIndex: 'title', key: 'title' },
|
||||
{ title: '店铺', dataIndex: 'shopName', key: 'shopName' },
|
||||
{ title: '金额', key: 'amount' },
|
||||
{ title: 'VIP 等级', dataIndex: 'vipLevel', key: 'vipLevel' },
|
||||
{ title: '说明', dataIndex: 'description', key: 'description' },
|
||||
{ title: '启用', key: 'status', width: 100 },
|
||||
{ title: '操作', key: 'action', width: 100 }
|
||||
]
|
||||
|
||||
const shopOptions = ref<Array<{ label: string; value: any }>>([])
|
||||
/** money is a local helper used by this page script. */
|
||||
const money = (value: number | string) => Number(value || 0).toFixed(2)
|
||||
|
||||
/** load is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const load = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const [planList, shopList] = await Promise.all([
|
||||
adminVipRechargePlanApi.listPlans(),
|
||||
adminShopApi.listAllShops().catch(() => [])
|
||||
])
|
||||
plans.value = planList || []
|
||||
shops.value = shopList || []
|
||||
shopOptions.value = shops.value.map(item => ({ label: item.shopName, value: item.id }))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** resetForm is a local helper used by this page script. */
|
||||
const resetForm = () => Object.assign(form, { shopId: undefined, title: '', rechargeAmount: 0, giftAmount: 0, vipLevel: '', description: '', sortOrder: 0, status: 1 })
|
||||
/** openCreate is a local helper used by this page script. */
|
||||
const openCreate = () => { editingId.value = undefined; resetForm(); formOpen.value = true }
|
||||
/** openEdit is a local helper used by this page script. */
|
||||
const openEdit = (record: VipRechargePlanVO) => {
|
||||
editingId.value = record.id
|
||||
Object.assign(form, record)
|
||||
formOpen.value = true
|
||||
}
|
||||
|
||||
/** submit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const submit = async () => {
|
||||
if (!form.title || !form.vipLevel || Number(form.rechargeAmount) <= 0) {
|
||||
message.warning('请填写标题、充值金额和 VIP 等级')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
if (editingId.value) {
|
||||
await adminVipRechargePlanApi.updatePlan(editingId.value, form)
|
||||
} else {
|
||||
await adminVipRechargePlanApi.createPlan(form)
|
||||
}
|
||||
message.success('档位已保存')
|
||||
formOpen.value = false
|
||||
await load()
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** toggleStatus is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const toggleStatus = async (record: VipRechargePlanVO, checked: boolean) => {
|
||||
await adminVipRechargePlanApi.updateStatus(record.id, checked ? 1 : 0)
|
||||
record.status = checked ? 1 : 0
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-page { display: grid; gap: 18px; }
|
||||
.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
|
||||
.page-head h2 { margin: 0 0 4px; }
|
||||
.page-head p { margin: 0; color: #7a6f68; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user