重构项目文件夹目录
This commit is contained in:
@@ -0,0 +1,835 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<!-- 头部区域 -->
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>账号设置</h1>
|
||||
<div class="empty"></div>
|
||||
</header>
|
||||
|
||||
<!-- 账号设置内容 -->
|
||||
<div class="account-settings">
|
||||
<!-- 账号设置选项 -->
|
||||
<a-card :bordered="false" class="settings-card">
|
||||
<a-list :data-source="accountSettings" :split="false">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item class="setting-item" @click="handleSettingClick(item.key)">
|
||||
<template #actions>
|
||||
<RightOutlined />
|
||||
</template>
|
||||
<a-list-item-meta>
|
||||
<template #avatar>
|
||||
<div class="setting-icon" :style="{ backgroundColor: item.bgColor }">
|
||||
<component :is="item.icon" />
|
||||
</div>
|
||||
</template>
|
||||
<template #title>
|
||||
<span>{{ item.title }}</span>
|
||||
</template>
|
||||
<template #description v-if="item.desc">
|
||||
<span>{{ item.desc }}</span>
|
||||
</template>
|
||||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<!-- 绑定手机号弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="bindPhoneModalVisible"
|
||||
title="绑定手机号"
|
||||
@ok="handleBindPhoneSubmit"
|
||||
@cancel="handleBindPhoneCancel"
|
||||
:confirmLoading="bindPhoneLoading"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="bindPhoneDraftSavedAt"
|
||||
@save="handleSaveBindPhoneDraft"
|
||||
@clear="handleClearBindPhoneDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="手机号" name="phone">
|
||||
<a-input
|
||||
v-model:value="bindPhoneForm.phone"
|
||||
placeholder="请输入手机号"
|
||||
:disabled="!!userInfo.phone"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="验证码" name="verificationCode">
|
||||
<a-input
|
||||
v-model:value="bindPhoneForm.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !bindPhoneForm.phone"
|
||||
@click="handleSendVerificationCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 修改手机号弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="changePhoneModalVisible"
|
||||
title="修改手机号"
|
||||
@ok="handleChangePhoneSubmit"
|
||||
@cancel="handleChangePhoneCancel"
|
||||
:confirmLoading="changePhoneLoading"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="changePhoneDraftSavedAt"
|
||||
@save="handleSaveChangePhoneDraft"
|
||||
@clear="handleClearChangePhoneDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="旧手机号">
|
||||
<a-input :value="userInfo.phone" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="新手机号" name="newPhone">
|
||||
<a-input
|
||||
v-model:value="changePhoneForm.newPhone"
|
||||
placeholder="请输入新手机号"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="验证码" name="verificationCode">
|
||||
<a-input
|
||||
v-model:value="changePhoneForm.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !changePhoneForm.newPhone"
|
||||
@click="handleSendChangePhoneVerificationCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 修改密码弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="changePasswordModalVisible"
|
||||
title="修改密码"
|
||||
@ok="handleChangePasswordSubmit"
|
||||
@cancel="handleChangePasswordCancel"
|
||||
:confirmLoading="changePasswordLoading"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="changePasswordDraftSavedAt"
|
||||
@save="handleSaveChangePasswordDraft"
|
||||
@clear="handleClearChangePasswordDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="手机号">
|
||||
<a-input :value="userInfo.phone" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="验证码" name="verificationCode">
|
||||
<a-input
|
||||
v-model:value="changePasswordForm.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0"
|
||||
@click="handleSendChangePasswordVerificationCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
<a-form-item label="新密码" name="password">
|
||||
<a-input-password
|
||||
v-model:value="changePasswordForm.password"
|
||||
placeholder="请输入新密码"
|
||||
/>
|
||||
<div class="password-tip">
|
||||
密码长度至少8位,包含字母和数字
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="确认密码" name="confirmPassword">
|
||||
<a-input-password
|
||||
v-model:value="changePasswordForm.confirmPassword"
|
||||
placeholder="请再次输入新密码"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* AccountSettingsView 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 { useRouter } from 'vue-router'
|
||||
import { LeftOutlined, RightOutlined, LockOutlined, PhoneOutlined } from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { userApi } from '@/api/user'
|
||||
import type { UserVO } from '@/api/user'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
/**
|
||||
* Purpose: router supports AccountSettingsView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const router = useRouter()
|
||||
|
||||
// 用户信息
|
||||
const userInfo = ref<UserVO>({
|
||||
id: 0,
|
||||
nickname: '',
|
||||
account: '',
|
||||
avatar: '',
|
||||
type: 0,
|
||||
status: 0,
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
|
||||
// 状态标识
|
||||
/** hasPassword is a reactive state variable used by the template and event handlers. */
|
||||
const hasPassword = ref(false)
|
||||
/** hasPhone is a reactive state variable used by the template and event handlers. */
|
||||
const hasPhone = ref(false)
|
||||
|
||||
// 绑定手机号表单
|
||||
/** bindPhoneModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const bindPhoneModalVisible = ref(false)
|
||||
/** bindPhoneLoading is a reactive state variable used by the template and event handlers. */
|
||||
const bindPhoneLoading = ref(false)
|
||||
/**
|
||||
* Purpose: bindPhoneDraftSavedAt supports AccountSettingsView.vue by holding or executing the bind phone draft saved at page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const bindPhoneDraftSavedAt = ref<number | null>(null)
|
||||
/**
|
||||
* Purpose: bindPhoneForm supports AccountSettingsView.vue by holding or executing the bind phone form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const bindPhoneForm = reactive({
|
||||
phone: '',
|
||||
verificationCode: ''
|
||||
})
|
||||
|
||||
// 修改手机号表单
|
||||
/** changePhoneModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const changePhoneModalVisible = ref(false)
|
||||
/** changePhoneLoading is a reactive state variable used by the template and event handlers. */
|
||||
const changePhoneLoading = ref(false)
|
||||
/**
|
||||
* Purpose: changePhoneDraftSavedAt supports AccountSettingsView.vue by holding or executing the change phone draft saved at page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const changePhoneDraftSavedAt = ref<number | null>(null)
|
||||
/**
|
||||
* Purpose: changePhoneForm supports AccountSettingsView.vue by holding or executing the change phone form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const changePhoneForm = reactive({
|
||||
newPhone: '',
|
||||
verificationCode: ''
|
||||
})
|
||||
|
||||
// 修改密码表单
|
||||
/** changePasswordModalVisible is a reactive state variable used by the template and event handlers. */
|
||||
const changePasswordModalVisible = ref(false)
|
||||
/** changePasswordLoading is a reactive state variable used by the template and event handlers. */
|
||||
const changePasswordLoading = ref(false)
|
||||
/**
|
||||
* Purpose: changePasswordDraftSavedAt supports AccountSettingsView.vue by holding or executing the change password draft saved at page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const changePasswordDraftSavedAt = ref<number | null>(null)
|
||||
/**
|
||||
* Purpose: changePasswordForm supports AccountSettingsView.vue by holding or executing the change password form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const changePasswordForm = reactive({
|
||||
verificationCode: '',
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: restoreSessionDraft supports AccountSettingsView.vue by holding or executing the restore session draft page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const restoreSessionDraft = <T extends Record<string, any>>(key: string, target: T, savedAtRef: typeof bindPhoneDraftSavedAt) => {
|
||||
const draft = loadDraftRecord<T>(key, 'session')
|
||||
if (!draft) {
|
||||
savedAtRef.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(target, draft.payload)
|
||||
savedAtRef.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: saveSessionDraft supports AccountSettingsView.vue by holding or executing the save session draft page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const saveSessionDraft = <T>(key: string, payload: T, savedAtRef: typeof bindPhoneDraftSavedAt, successMessage = '已暂存到当前会话') => {
|
||||
const draft = saveDraftRecord(key, payload, 'session')
|
||||
savedAtRef.value = draft.savedAt
|
||||
message.success(successMessage)
|
||||
}
|
||||
|
||||
/** clearSessionDraft is a local helper used by this page script. */
|
||||
const clearSessionDraft = (key: string, savedAtRef: typeof bindPhoneDraftSavedAt, showMessage = true) => {
|
||||
clearDraftRecord(key, 'session')
|
||||
savedAtRef.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: bindPhoneDraftKey supports AccountSettingsView.vue by holding or executing the bind phone draft key page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const bindPhoneDraftKey = buildDraftStorageKey('account-settings', 'bind-phone')
|
||||
/**
|
||||
* Purpose: changePhoneDraftKey supports AccountSettingsView.vue by holding or executing the change phone draft key page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const changePhoneDraftKey = buildDraftStorageKey('account-settings', 'change-phone')
|
||||
/**
|
||||
* Purpose: changePasswordDraftKey supports AccountSettingsView.vue by holding or executing the change password draft key page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const changePasswordDraftKey = buildDraftStorageKey('account-settings', 'change-password')
|
||||
|
||||
/** handleSaveBindPhoneDraft is a local helper used by this page script. */
|
||||
const handleSaveBindPhoneDraft = () => {
|
||||
saveSessionDraft(bindPhoneDraftKey, { ...bindPhoneForm }, bindPhoneDraftSavedAt)
|
||||
}
|
||||
|
||||
/** handleClearBindPhoneDraft is a local helper used by this page script. */
|
||||
const handleClearBindPhoneDraft = (showMessage = true) => {
|
||||
clearSessionDraft(bindPhoneDraftKey, bindPhoneDraftSavedAt, showMessage)
|
||||
}
|
||||
|
||||
/** handleSaveChangePhoneDraft is a local helper used by this page script. */
|
||||
const handleSaveChangePhoneDraft = () => {
|
||||
saveSessionDraft(changePhoneDraftKey, { ...changePhoneForm }, changePhoneDraftSavedAt)
|
||||
}
|
||||
|
||||
/** handleClearChangePhoneDraft is a local helper used by this page script. */
|
||||
const handleClearChangePhoneDraft = (showMessage = true) => {
|
||||
clearSessionDraft(changePhoneDraftKey, changePhoneDraftSavedAt, showMessage)
|
||||
}
|
||||
|
||||
/** handleSaveChangePasswordDraft is a local helper used by this page script. */
|
||||
const handleSaveChangePasswordDraft = () => {
|
||||
saveSessionDraft(changePasswordDraftKey, { ...changePasswordForm }, changePasswordDraftSavedAt)
|
||||
}
|
||||
|
||||
/** handleClearChangePasswordDraft is a local helper used by this page script. */
|
||||
const handleClearChangePasswordDraft = (showMessage = true) => {
|
||||
clearSessionDraft(changePasswordDraftKey, changePasswordDraftSavedAt, showMessage)
|
||||
}
|
||||
|
||||
// 倒计时
|
||||
/** countdown is a reactive state variable used by the template and event handlers. */
|
||||
const countdown = ref(0)
|
||||
|
||||
// 账号设置选项
|
||||
/** accountSettings is a reactive state variable used by the template and event handlers. */
|
||||
const accountSettings = ref([
|
||||
{
|
||||
key: 'changePhone',
|
||||
title: '修改手机号',
|
||||
icon: PhoneOutlined,
|
||||
bgColor: '#e6f7ff'
|
||||
},
|
||||
{
|
||||
key: 'changePassword',
|
||||
title: '修改密码',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#f6ffed'
|
||||
},
|
||||
{
|
||||
key: 'deactivateAccount',
|
||||
title: '注销账号',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#fff1f0'
|
||||
}
|
||||
])
|
||||
|
||||
// 根据用户状态动态更新账号设置选项
|
||||
/** updateAccountSettings is a local helper used by this page script. */
|
||||
const updateAccountSettings = () => {
|
||||
const settings = []
|
||||
|
||||
// 手机号相关
|
||||
if (!hasPhone.value) {
|
||||
settings.push({
|
||||
key: 'bindPhone',
|
||||
title: '绑定手机号',
|
||||
icon: PhoneOutlined,
|
||||
bgColor: '#e6f7ff'
|
||||
})
|
||||
} else {
|
||||
settings.push({
|
||||
key: 'changePhone',
|
||||
title: '修改手机号',
|
||||
icon: PhoneOutlined,
|
||||
bgColor: '#e6f7ff'
|
||||
})
|
||||
}
|
||||
|
||||
// 密码相关
|
||||
if (!hasPassword.value) {
|
||||
settings.push({
|
||||
key: 'setPassword',
|
||||
title: '设置密码',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#fff7e6'
|
||||
})
|
||||
} else {
|
||||
settings.push({
|
||||
key: 'changePassword',
|
||||
title: '修改密码',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#f6ffed'
|
||||
})
|
||||
}
|
||||
|
||||
// 注销账号
|
||||
settings.push({
|
||||
key: 'deactivateAccount',
|
||||
title: '注销账号',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#fff1f0'
|
||||
})
|
||||
|
||||
accountSettings.value = settings
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
/** fetchUserInfo is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const response = await userApi.getUserInfo() as any
|
||||
userInfo.value = response
|
||||
// 检查是否绑定手机号
|
||||
hasPhone.value = !!userInfo.value.phone
|
||||
// 检查是否设置密码(通过localStorage中的标识)
|
||||
hasPassword.value = localStorage.getItem('needSetPassword') !== 'true'
|
||||
// 更新账号设置选项
|
||||
updateAccountSettings()
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
message.error('获取用户信息失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 处理返回
|
||||
/** handleBackClick is a local helper used by this page script. */
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
// 处理设置项点击
|
||||
/** handleSettingClick is a local helper used by this page script. */
|
||||
const handleSettingClick = (key: string) => {
|
||||
switch (key) {
|
||||
case 'bindPhone':
|
||||
restoreSessionDraft(bindPhoneDraftKey, bindPhoneForm, bindPhoneDraftSavedAt)
|
||||
bindPhoneModalVisible.value = true
|
||||
break
|
||||
case 'changePhone':
|
||||
restoreSessionDraft(changePhoneDraftKey, changePhoneForm, changePhoneDraftSavedAt)
|
||||
changePhoneModalVisible.value = true
|
||||
break
|
||||
case 'setPassword':
|
||||
handleSetPassword()
|
||||
break
|
||||
case 'changePassword':
|
||||
restoreSessionDraft(changePasswordDraftKey, changePasswordForm, changePasswordDraftSavedAt)
|
||||
changePasswordModalVisible.value = true
|
||||
break
|
||||
case 'deactivateAccount':
|
||||
handleDeactivateAccount()
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 处理设置密码
|
||||
/** handleSetPassword is a local helper used by this page script. */
|
||||
const handleSetPassword = () => {
|
||||
router.push('/settings/password')
|
||||
}
|
||||
|
||||
// 发送绑定手机号验证码
|
||||
/** handleSendVerificationCode is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleSendVerificationCode = async () => {
|
||||
if (!bindPhoneForm.phone) {
|
||||
message.error('请输入手机号')
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(bindPhoneForm.phone)) {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithGlobalLoading(() => userApi.sendVerificationCode({
|
||||
phone: bindPhoneForm.phone,
|
||||
sceneCode: 'USER_BIND_PHONE_SMS_CODE'
|
||||
}))
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error('发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 发送修改手机号验证码
|
||||
/** handleSendChangePhoneVerificationCode is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleSendChangePhoneVerificationCode = async () => {
|
||||
if (!changePhoneForm.newPhone) {
|
||||
message.error('请输入新手机号')
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(changePhoneForm.newPhone)) {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithGlobalLoading(() => userApi.sendVerificationCode({
|
||||
phone: changePhoneForm.newPhone,
|
||||
sceneCode: 'USER_CHANGE_PHONE_SMS_CODE'
|
||||
}))
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error('发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 发送修改密码验证码
|
||||
/** handleSendChangePasswordVerificationCode is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleSendChangePasswordVerificationCode = async () => {
|
||||
if (!userInfo.value.phone) {
|
||||
message.error('请先绑定手机号')
|
||||
return
|
||||
}
|
||||
|
||||
const phone = userInfo.value.phone
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(phone)) {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithGlobalLoading(() => userApi.sendVerificationCode({
|
||||
phone,
|
||||
sceneCode: 'USER_CHANGE_PASSWORD_SMS_CODE'
|
||||
}))
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error('发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 开始倒计时
|
||||
/** startCountdown is a local helper used by this page script. */
|
||||
const startCountdown = () => {
|
||||
countdown.value = 60
|
||||
const timer = setInterval(() => {
|
||||
countdown.value--
|
||||
if (countdown.value <= 0) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
// 处理绑定手机号提交
|
||||
/** handleBindPhoneSubmit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleBindPhoneSubmit = async () => {
|
||||
if (!bindPhoneForm.phone || !bindPhoneForm.verificationCode) {
|
||||
message.error('请填写完整信息')
|
||||
return
|
||||
}
|
||||
|
||||
bindPhoneLoading.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await userApi.bindPhone({
|
||||
phone: bindPhoneForm.phone,
|
||||
verificationCode: bindPhoneForm.verificationCode
|
||||
})
|
||||
await fetchUserInfo()
|
||||
})
|
||||
message.success('手机号绑定成功')
|
||||
handleClearBindPhoneDraft(false)
|
||||
bindPhoneModalVisible.value = false
|
||||
} catch (error: any) {
|
||||
console.error('绑定手机号失败:', error)
|
||||
message.error(error.message || '绑定手机号失败')
|
||||
} finally {
|
||||
bindPhoneLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理绑定手机号取消
|
||||
/** handleBindPhoneCancel is a local helper used by this page script. */
|
||||
const handleBindPhoneCancel = () => {
|
||||
bindPhoneModalVisible.value = false
|
||||
bindPhoneForm.phone = ''
|
||||
bindPhoneForm.verificationCode = ''
|
||||
}
|
||||
|
||||
// 处理修改手机号提交
|
||||
/** handleChangePhoneSubmit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleChangePhoneSubmit = async () => {
|
||||
if (!changePhoneForm.newPhone || !changePhoneForm.verificationCode) {
|
||||
message.error('请填写完整信息')
|
||||
return
|
||||
}
|
||||
|
||||
changePhoneLoading.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await userApi.updatePhone({
|
||||
oldPhone: userInfo.value.phone!,
|
||||
newPhone: changePhoneForm.newPhone,
|
||||
verificationCode: changePhoneForm.verificationCode
|
||||
})
|
||||
await fetchUserInfo()
|
||||
})
|
||||
message.success('手机号修改成功')
|
||||
handleClearChangePhoneDraft(false)
|
||||
changePhoneModalVisible.value = false
|
||||
} catch (error: any) {
|
||||
console.error('修改手机号失败:', error)
|
||||
message.error(error.message || '修改手机号失败')
|
||||
} finally {
|
||||
changePhoneLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理修改手机号取消
|
||||
/** handleChangePhoneCancel is a local helper used by this page script. */
|
||||
const handleChangePhoneCancel = () => {
|
||||
changePhoneModalVisible.value = false
|
||||
changePhoneForm.newPhone = ''
|
||||
changePhoneForm.verificationCode = ''
|
||||
}
|
||||
|
||||
// 处理修改密码提交
|
||||
/** handleChangePasswordSubmit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleChangePasswordSubmit = async () => {
|
||||
if (!changePasswordForm.verificationCode || !changePasswordForm.password || !changePasswordForm.confirmPassword) {
|
||||
message.error('请填写完整信息')
|
||||
return
|
||||
}
|
||||
|
||||
if (changePasswordForm.password !== changePasswordForm.confirmPassword) {
|
||||
message.error('两次输入的密码不一致')
|
||||
return
|
||||
}
|
||||
|
||||
changePasswordLoading.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(() => userApi.updatePassword({
|
||||
password: changePasswordForm.password,
|
||||
verificationCode: changePasswordForm.verificationCode
|
||||
}))
|
||||
message.success('密码修改成功')
|
||||
handleClearChangePasswordDraft(false)
|
||||
changePasswordModalVisible.value = false
|
||||
// 清除需要设置密码的标识
|
||||
localStorage.removeItem('needSetPassword')
|
||||
hasPassword.value = true
|
||||
updateAccountSettings()
|
||||
} catch (error: any) {
|
||||
console.error('修改密码失败:', error)
|
||||
message.error(error.message || '修改密码失败')
|
||||
} finally {
|
||||
changePasswordLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理修改密码取消
|
||||
/** handleChangePasswordCancel is a local helper used by this page script. */
|
||||
const handleChangePasswordCancel = () => {
|
||||
changePasswordModalVisible.value = false
|
||||
changePasswordForm.verificationCode = ''
|
||||
changePasswordForm.password = ''
|
||||
changePasswordForm.confirmPassword = ''
|
||||
}
|
||||
|
||||
// 处理注销账号
|
||||
/** handleDeactivateAccount is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleDeactivateAccount = async () => {
|
||||
Modal.confirm({
|
||||
title: '确认注销账号',
|
||||
content: '注销账号后,您的所有数据将被删除且无法恢复。确定要注销账号吗?',
|
||||
okText: '确认注销',
|
||||
okType: 'danger',
|
||||
cancelText: '取消',
|
||||
onOk: async () => {
|
||||
await runWithGlobalLoading(async () => {
|
||||
try {
|
||||
await userApi.deactivateAccount()
|
||||
message.success('账号注销成功')
|
||||
} catch (error) {
|
||||
console.error('注销账号失败:', error)
|
||||
message.error('注销账号失败')
|
||||
} finally {
|
||||
// 无论成功或失败,都清除本地存储的用户信息
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('needSetPassword')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
// 跳转到登录页
|
||||
router.push('/')
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
background: var(--theme-page-bg);
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
background: var(--theme-card-bg);
|
||||
border-bottom: 1px solid var(--theme-border);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.back-btn,
|
||||
.empty {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.account-settings {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.status-tips {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
background: var(--theme-card-bg);
|
||||
}
|
||||
|
||||
.settings-card :deep(.ant-card-body) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
padding: 16px;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s;
|
||||
border-bottom: 1px solid var(--theme-border);
|
||||
}
|
||||
|
||||
.setting-item:hover {
|
||||
background: var(--theme-primary-soft);
|
||||
}
|
||||
|
||||
.setting-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-action) {
|
||||
margin-left: 8px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.setting-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 18px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-meta-title) {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-meta-description) {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.password-tip {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
margin-top: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,141 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { afterSaleApi, orderApi } from '../api/order'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const order = ref<any | null>(null)
|
||||
|
||||
const orderId = computed(() => String(route.query.orderId || ''))
|
||||
const items = computed(() => Array.isArray(order.value?.items) ? order.value.items : [])
|
||||
const form = reactive({
|
||||
orderItemId: undefined as IdType | undefined,
|
||||
type: 'REFUND',
|
||||
reason: '',
|
||||
refundAmount: undefined as number | undefined
|
||||
})
|
||||
|
||||
const formatMoney = (value?: number | string) => {
|
||||
const amount = Number(value)
|
||||
return Number.isFinite(amount) ? `¥${amount.toFixed(2)}` : '¥0.00'
|
||||
}
|
||||
|
||||
const loadOrder = async () => {
|
||||
if (!orderId.value) return
|
||||
loading.value = true
|
||||
try {
|
||||
order.value = await orderApi.getOrderDetail(orderId.value)
|
||||
const preferredItemId = String(route.query.orderItemId || '')
|
||||
const firstItem = items.value.find((item: any) => String(item.id) === preferredItemId) || items.value[0]
|
||||
form.orderItemId = firstItem?.id
|
||||
form.refundAmount = Number(order.value?.actualAmount || order.value?.totalAmount || 0)
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '订单信息加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const submit = async () => {
|
||||
if (!orderId.value) {
|
||||
message.warning('缺少订单信息')
|
||||
return
|
||||
}
|
||||
if (!form.reason.trim()) {
|
||||
message.warning('请填写售后原因')
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(() => afterSaleApi.apply({
|
||||
orderId: orderId.value,
|
||||
orderItemId: form.orderItemId,
|
||||
type: form.type,
|
||||
reason: form.reason.trim(),
|
||||
refundAmount: form.refundAmount
|
||||
}))
|
||||
message.success('售后申请已提交')
|
||||
router.replace({ path: '/after-sales', query: { orderId: orderId.value } })
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '售后申请提交失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadOrder)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="apply-page">
|
||||
<header class="header">
|
||||
<a-button type="text" @click="router.back()">
|
||||
<LeftOutlined />
|
||||
</a-button>
|
||||
<h1>申请售后</h1>
|
||||
<a-button type="link" @click="router.push('/after-sales')">记录</a-button>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<section class="hero-card">
|
||||
<span>售后申请</span>
|
||||
<h2>{{ order?.orderNo || (orderId ? `订单 ${orderId}` : '选择订单') }}</h2>
|
||||
<p>{{ order ? `可申请金额 ${formatMoney(order.actualAmount || order.totalAmount)}` : '从订单详情或订单中心进入可自动带入订单信息' }}</p>
|
||||
</section>
|
||||
|
||||
<a-spin :spinning="loading">
|
||||
<a-empty v-if="!orderId" description="缺少订单参数">
|
||||
<a-button type="primary" @click="router.push('/orders')">选择订单</a-button>
|
||||
</a-empty>
|
||||
|
||||
<section v-else class="form-card">
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="订单项目">
|
||||
<a-select v-model:value="form.orderItemId" allow-clear placeholder="默认整单">
|
||||
<a-select-option v-for="item in items" :key="item.id" :value="item.id">
|
||||
{{ item.productTitle || `项目 ${item.id}` }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="售后类型" required>
|
||||
<a-select v-model:value="form.type">
|
||||
<a-select-option value="REFUND">退款</a-select-option>
|
||||
<a-select-option value="AFTER_SALE">售后服务</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="退款金额">
|
||||
<a-input-number v-model:value="form.refundAmount" :min="0" :step="0.01" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="原因说明" required>
|
||||
<a-textarea v-model:value="form.reason" :rows="5" :maxlength="300" placeholder="请说明退款或售后原因" />
|
||||
</a-form-item>
|
||||
<a-button type="primary" block :loading="submitting" @click="submit">提交申请</a-button>
|
||||
</a-form>
|
||||
</section>
|
||||
</a-spin>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.apply-page { min-height: 100vh; padding-top: 60px; background: var(--theme-page-bg); color: var(--text-primary); }
|
||||
.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; height: 60px; padding: 9px 14px; background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent); border-bottom: 1px solid var(--theme-border); backdrop-filter: blur(14px); }
|
||||
.header h1 { margin: 0; font-size: 18px; }
|
||||
.content { padding: 16px 14px 32px; }
|
||||
.hero-card, .form-card { border: 1px solid var(--theme-border); border-radius: 20px; background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent); box-shadow: 0 18px 44px rgba(74, 68, 63, 0.08); }
|
||||
.hero-card { padding: 22px; margin-bottom: 14px; background: var(--theme-gradient-soft); }
|
||||
.hero-card span { color: var(--theme-primary); font-size: 12px; font-weight: 700; letter-spacing: .05em; }
|
||||
.hero-card h2 { margin: 10px 0 6px; font-size: 21px; }
|
||||
.hero-card p { margin: 0; color: var(--text-secondary); line-height: 1.6; }
|
||||
.form-card { padding: 16px; }
|
||||
:deep(.ant-btn-primary) { background: var(--theme-primary); border-color: var(--theme-primary); }
|
||||
:deep(.ant-btn-link) { color: var(--theme-primary); }
|
||||
:deep(.ant-input:focus), :deep(.ant-input-focused), :deep(.ant-select-focused .ant-select-selector) { border-color: var(--theme-primary) !important; box-shadow: var(--theme-focus-shadow) !important; }
|
||||
</style>
|
||||
@@ -0,0 +1,122 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { afterSaleApi, type AfterSaleVO } from '../api/order'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const loading = ref(false)
|
||||
const records = ref<AfterSaleVO[]>([])
|
||||
|
||||
const focusOrderId = computed(() => String(route.query.orderId || ''))
|
||||
const focusedRecords = computed(() => {
|
||||
if (!focusOrderId.value) return records.value
|
||||
return records.value.filter(item => String(item.orderId) === focusOrderId.value)
|
||||
})
|
||||
|
||||
const statusText = (status?: string) => {
|
||||
if (status === 'PENDING') return '审核中'
|
||||
if (status === 'APPROVED') return '已通过'
|
||||
if (status === 'REJECTED') return '已拒绝'
|
||||
return status || '处理中'
|
||||
}
|
||||
|
||||
const typeText = (type?: string) => type === 'REFUND' ? '退款' : (type || '售后')
|
||||
const formatMoney = (value?: number) => value === undefined || value === null ? '--' : `¥${Number(value).toFixed(2)}`
|
||||
const formatTime = (value?: string) => value ? String(value).replace('T', ' ').slice(0, 16) : '--'
|
||||
|
||||
const loadRecords = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const page = await afterSaleApi.listMy({ page: 1, size: 50 })
|
||||
records.value = page?.list || []
|
||||
} catch (error: any) {
|
||||
records.value = []
|
||||
message.error(error?.message || '售后记录加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadRecords)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="after-sales-page">
|
||||
<header class="header">
|
||||
<a-button type="text" @click="router.back()">
|
||||
<LeftOutlined />
|
||||
</a-button>
|
||||
<h1>售后记录</h1>
|
||||
<a-button type="link" @click="loadRecords">刷新</a-button>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<section class="hero-card">
|
||||
<span>售后服务</span>
|
||||
<h2>{{ focusedRecords.length }} 条记录</h2>
|
||||
<p>{{ focusOrderId ? `订单 ${focusOrderId} 的售后进度` : '查看退款、售后审核与处理说明' }}</p>
|
||||
</section>
|
||||
|
||||
<a-spin :spinning="loading">
|
||||
<a-empty v-if="!focusedRecords.length" description="暂无售后记录">
|
||||
<a-button type="primary" @click="router.push('/orders')">查看订单</a-button>
|
||||
</a-empty>
|
||||
|
||||
<article v-for="item in focusedRecords" :key="item.id" class="record-card">
|
||||
<div class="record-head">
|
||||
<div>
|
||||
<span class="record-label">{{ typeText(item.type) }}</span>
|
||||
<h3>{{ item.afterSaleNo || `售后 ${item.id}` }}</h3>
|
||||
</div>
|
||||
<strong>{{ statusText(item.status) }}</strong>
|
||||
</div>
|
||||
<dl>
|
||||
<div>
|
||||
<dt>订单</dt>
|
||||
<dd>{{ item.orderId }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>金额</dt>
|
||||
<dd>{{ formatMoney(item.refundAmount) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>提交时间</dt>
|
||||
<dd>{{ formatTime(item.createTime) }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<p v-if="item.reason">原因:{{ item.reason }}</p>
|
||||
<p v-if="item.auditReason">处理说明:{{ item.auditReason }}</p>
|
||||
<div class="actions">
|
||||
<a-button size="small" @click="router.push(`/orders/${item.orderId}`)">订单详情</a-button>
|
||||
<a-button size="small" @click="router.push({ path: '/service-progress', query: { orderId: String(item.orderId) } })">服务进度</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</a-spin>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.after-sales-page { min-height: 100vh; padding-top: 60px; background: var(--theme-page-bg); color: var(--text-primary); }
|
||||
.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; height: 60px; padding: 9px 14px; background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent); border-bottom: 1px solid var(--theme-border); backdrop-filter: blur(14px); }
|
||||
.header h1 { margin: 0; font-size: 18px; }
|
||||
.content { padding: 16px 14px 32px; }
|
||||
.hero-card, .record-card { border: 1px solid var(--theme-border); border-radius: 20px; background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent); box-shadow: 0 18px 44px rgba(74, 68, 63, 0.08); }
|
||||
.hero-card { padding: 22px; margin-bottom: 14px; background: var(--theme-gradient-soft); }
|
||||
.hero-card span, .record-label { color: var(--theme-primary); font-size: 12px; font-weight: 700; letter-spacing: .05em; }
|
||||
.hero-card h2 { margin: 10px 0 6px; font-size: 21px; }
|
||||
.hero-card p, .record-card p { margin: 0; color: var(--text-secondary); line-height: 1.6; }
|
||||
.record-card { padding: 16px; margin-top: 14px; }
|
||||
.record-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
|
||||
.record-head h3 { margin: 6px 0 0; font-size: 17px; }
|
||||
.record-head strong { flex: 0 0 auto; padding: 6px 12px; border-radius: 999px; background: var(--theme-primary-soft); color: var(--theme-primary); font-size: 12px; }
|
||||
dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 14px 0; }
|
||||
dt { color: var(--text-secondary); font-size: 12px; }
|
||||
dd { margin: 4px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
|
||||
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
|
||||
:deep(.ant-btn-primary) { background: var(--theme-primary); border-color: var(--theme-primary); }
|
||||
:deep(.ant-btn-link) { color: var(--theme-primary); }
|
||||
</style>
|
||||
@@ -0,0 +1,288 @@
|
||||
<template>
|
||||
<div class="artist-calendar-page">
|
||||
<header class="calendar-header">
|
||||
<a-button type="text" class="back-btn" @click="router.back()">
|
||||
<LeftOutlined />
|
||||
</a-button>
|
||||
<div class="header-copy">
|
||||
<span>预约日历</span>
|
||||
<h1>未来 7 天</h1>
|
||||
</div>
|
||||
<a-button type="link" @click="openArtistOrders">订单</a-button>
|
||||
</header>
|
||||
|
||||
<main class="calendar-content">
|
||||
<section class="summary-strip">
|
||||
<div>
|
||||
<span>今日预约</span>
|
||||
<strong>{{ todayCount }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>下一单</span>
|
||||
<strong>{{ nextAppointmentText }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>7 天合计</span>
|
||||
<strong>{{ appointments.length }}</strong>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="toolbar">
|
||||
<a-button type="primary" :loading="loading" @click="loadAppointments">刷新</a-button>
|
||||
<a-button @click="openArtistOrders">查看我的相关订单</a-button>
|
||||
</section>
|
||||
|
||||
<a-spin :spinning="loading">
|
||||
<section v-if="groupedDays.length" class="timeline">
|
||||
<article v-for="day in groupedDays" :key="day.dateKey" class="day-row">
|
||||
<aside class="day-label">
|
||||
<strong>{{ day.dayText }}</strong>
|
||||
<span>{{ day.weekText }}</span>
|
||||
<em>{{ day.items.length }} 单</em>
|
||||
</aside>
|
||||
<div class="day-line">
|
||||
<button
|
||||
v-for="item in day.items"
|
||||
:key="String(item.orderItemId)"
|
||||
type="button"
|
||||
class="appointment-block"
|
||||
:class="statusClass(item.orderStatus)"
|
||||
@click="openDetail(item)"
|
||||
>
|
||||
<span class="time">{{ timeRange(item) }}</span>
|
||||
<strong>{{ item.customerNickname || '用户' }} · {{ item.productTitle }}</strong>
|
||||
<small>{{ item.orderStatusText }} · {{ item.shopName || '门店' }}</small>
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
<a-empty v-else description="未来 7 天暂无预约" />
|
||||
</a-spin>
|
||||
</main>
|
||||
|
||||
<a-drawer v-model:open="detailOpen" title="预约详情" placement="right" :width="420">
|
||||
<div v-if="selected" class="detail-body">
|
||||
<div class="detail-title">
|
||||
<strong>{{ selected.productTitle }}</strong>
|
||||
<a-tag :color="selected.orderStatus === 2 ? 'green' : 'orange'">{{ selected.orderStatusText }}</a-tag>
|
||||
</div>
|
||||
<dl>
|
||||
<dt>预约时间</dt>
|
||||
<dd>{{ formatDateTime(selected.appointmentStartTime) }} - {{ formatClock(selected.appointmentEndTime) }}</dd>
|
||||
<dt>客户</dt>
|
||||
<dd>{{ selected.customerNickname || '用户' }} {{ selected.customerPhoneMasked || '' }}</dd>
|
||||
<dt>订单号</dt>
|
||||
<dd>{{ selected.orderNo }}</dd>
|
||||
<dt>订单金额</dt>
|
||||
<dd>{{ formatMoney(selected.totalAmount) }} / 实付 {{ formatMoney(selected.actualAmount) }}</dd>
|
||||
<dt>门店</dt>
|
||||
<dd>{{ selected.shopName || '--' }}</dd>
|
||||
<dt>数量 / 时长</dt>
|
||||
<dd>{{ selected.quantity }} 件 · {{ selected.durationMinutes }} 分钟</dd>
|
||||
</dl>
|
||||
<a-space direction="vertical" style="width: 100%">
|
||||
<a-button block @click="openSelectedProduct">查看客户选择的作品</a-button>
|
||||
<a-button block @click="openSelectedOrder">查看对应订单</a-button>
|
||||
<a-button
|
||||
v-if="selected.orderStatus === 1"
|
||||
type="primary"
|
||||
block
|
||||
:loading="completing"
|
||||
@click="completeSelectedOrder"
|
||||
>
|
||||
完成服务
|
||||
</a-button>
|
||||
<a-button block @click="openArtistOrders">打开我的相关订单</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
</a-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* ArtistCalendarView 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 { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
/**
|
||||
* Purpose: ArtistCalendarAppointment supports ArtistCalendarView.vue by holding or executing the artist calendar appointment page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { orderApi, type ArtistCalendarAppointment } from '@/api/order'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
/**
|
||||
* Purpose: router supports ArtistCalendarView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const router = useRouter()
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** completing is a reactive state variable used by the template and event handlers. */
|
||||
const completing = ref(false)
|
||||
/**
|
||||
* Purpose: appointments supports ArtistCalendarView.vue by holding or executing the appointments page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const appointments = ref<ArtistCalendarAppointment[]>([])
|
||||
/**
|
||||
* Purpose: selected supports ArtistCalendarView.vue by holding or executing the selected page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const selected = ref<ArtistCalendarAppointment | null>(null)
|
||||
/** detailOpen is a reactive state variable used by the template and event handlers. */
|
||||
const detailOpen = ref(false)
|
||||
|
||||
/**
|
||||
* Purpose: todayKey supports ArtistCalendarView.vue by holding or executing the today key page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const todayKey = localDateKey(new Date())
|
||||
/** todayCount is a reactive state variable used by the template and event handlers. */
|
||||
const todayCount = computed(() => appointments.value.filter(item => dateKey(item.appointmentStartTime) === todayKey).length)
|
||||
/** nextAppointmentText is a reactive state variable used by the template and event handlers. */
|
||||
const nextAppointmentText = computed(() => {
|
||||
const now = Date.now()
|
||||
const next = appointments.value.find(item => new Date(item.appointmentStartTime).getTime() >= now)
|
||||
return next ? formatClock(next.appointmentStartTime) : '--'
|
||||
})
|
||||
/** groupedDays is a reactive state variable used by the template and event handlers. */
|
||||
const groupedDays = computed(() => {
|
||||
const map = new Map<string, ArtistCalendarAppointment[]>()
|
||||
appointments.value.forEach(item => {
|
||||
const key = dateKey(item.appointmentStartTime)
|
||||
map.set(key, [...(map.get(key) || []), item])
|
||||
})
|
||||
return Array.from(map.entries()).map(([key, items]) => ({
|
||||
dateKey: key,
|
||||
dayText: key.slice(5),
|
||||
weekText: weekText(key),
|
||||
items: items.sort((a, b) => a.appointmentStartTime.localeCompare(b.appointmentStartTime))
|
||||
}))
|
||||
})
|
||||
|
||||
/** loadAppointments is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadAppointments = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
appointments.value = await orderApi.getArtistCalendarRecent(7)
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取预约日历失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** openDetail is a local helper used by this page script. */
|
||||
const openDetail = (item: ArtistCalendarAppointment) => {
|
||||
selected.value = item
|
||||
detailOpen.value = true
|
||||
}
|
||||
|
||||
/** completeSelectedOrder is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const completeSelectedOrder = async () => {
|
||||
if (!selected.value) return
|
||||
completing.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(() => orderApi.completeArtistOrder(selected.value!.orderId))
|
||||
message.success('服务已完成')
|
||||
detailOpen.value = false
|
||||
await loadAppointments()
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '完成服务失败')
|
||||
} finally {
|
||||
completing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** openSelectedProduct is a local helper used by this page script. */
|
||||
const openSelectedProduct = () => {
|
||||
if (!selected.value?.productId) return
|
||||
const productId = selected.value.productId
|
||||
detailOpen.value = false
|
||||
router.push(`/product/${productId}`)
|
||||
}
|
||||
|
||||
/** openArtistOrders is a local helper used by this page script. */
|
||||
const openArtistOrders = () => {
|
||||
detailOpen.value = false
|
||||
router.push({ path: '/artist-orders' })
|
||||
}
|
||||
|
||||
/** openSelectedOrder is a local helper used by this page script. */
|
||||
const openSelectedOrder = () => {
|
||||
if (!selected.value?.orderId) return
|
||||
const orderId = selected.value.orderId
|
||||
detailOpen.value = false
|
||||
router.push({ path: '/artist-orders', query: { orderId: String(orderId) } })
|
||||
}
|
||||
|
||||
/** dateKey is a local helper used by this page script. */
|
||||
const dateKey = (value: string) => value ? value.slice(0, 10) : ''
|
||||
/**
|
||||
* Purpose: localDateKey supports ArtistCalendarView.vue by holding or executing the local date key page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function localDateKey(value: Date) {
|
||||
const month = String(value.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(value.getDate()).padStart(2, '0')
|
||||
return `${value.getFullYear()}-${month}-${day}`
|
||||
}
|
||||
/** formatDateTime is a local helper used by this page script. */
|
||||
const formatDateTime = (value: string) => value ? value.replace('T', ' ').slice(0, 16) : '--'
|
||||
/** formatClock is a local helper used by this page script. */
|
||||
const formatClock = (value: string) => value ? value.replace('T', ' ').slice(11, 16) : '--'
|
||||
/** formatMoney is a local helper used by this page script. */
|
||||
const formatMoney = (value?: number) => value === undefined || value === null ? '--' : `¥${Number(value).toFixed(2)}`
|
||||
/** timeRange is a local helper used by this page script. */
|
||||
const timeRange = (item: ArtistCalendarAppointment) => `${formatClock(item.appointmentStartTime)} - ${formatClock(item.appointmentEndTime)}`
|
||||
/** weekText is a local helper used by this page script. */
|
||||
const weekText = (key: string) => ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][new Date(`${key}T00:00:00`).getDay()] || ''
|
||||
/** statusClass is a local helper used by this page script. */
|
||||
const statusClass = (status: number) => status === 2 ? 'is-completed' : 'is-pending'
|
||||
|
||||
onMounted(loadAppointments)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.artist-calendar-page { min-height: 100vh; background: var(--theme-page-bg); color: var(--text-primary); }
|
||||
.calendar-header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: color-mix(in srgb, var(--theme-card-bg) 94%, transparent); border-bottom: 1px solid var(--theme-border); backdrop-filter: blur(12px); }
|
||||
.back-btn { width: 40px; height: 40px; }
|
||||
.header-copy { flex: 1; min-width: 0; }
|
||||
.header-copy span { display: block; font-size: 12px; color: var(--text-secondary); }
|
||||
.header-copy h1 { margin: 2px 0 0; font-size: 20px; }
|
||||
.calendar-content { max-width: 1040px; margin: 0 auto; padding: 18px 16px 96px; }
|
||||
.summary-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; overflow: hidden; border-radius: 8px; background: var(--theme-border); }
|
||||
.summary-strip div { padding: 16px; background: var(--theme-card-bg); }
|
||||
.summary-strip span { display: block; color: var(--text-secondary); font-size: 12px; }
|
||||
.summary-strip strong { display: block; margin-top: 8px; font-size: 22px; }
|
||||
.toolbar { display: flex; justify-content: space-between; gap: 12px; margin: 16px 0; }
|
||||
.timeline { display: grid; gap: 14px; }
|
||||
.day-row { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 14px; }
|
||||
.day-label { display: grid; align-content: start; gap: 4px; padding-top: 4px; }
|
||||
.day-label strong { font-size: 20px; }
|
||||
.day-label span, .day-label em { color: var(--text-secondary); font-style: normal; font-size: 12px; }
|
||||
.day-line { position: relative; display: grid; gap: 10px; padding-left: 18px; border-left: 2px solid var(--theme-border); }
|
||||
.appointment-block { width: 100%; display: grid; gap: 5px; padding: 14px 16px; border: 1px solid var(--theme-border); border-radius: 8px; background: var(--theme-card-bg); text-align: left; color: var(--text-primary); box-shadow: 0 10px 22px color-mix(in srgb, var(--theme-primary) 8%, transparent); cursor: pointer; transition: transform .18s ease, border-color .18s ease; }
|
||||
.appointment-block:hover { transform: translateY(-2px); border-color: var(--theme-primary); }
|
||||
.appointment-block.is-completed { background: #f5fff7; border-color: #c8ead1; }
|
||||
.appointment-block .time { color: var(--theme-primary); font-weight: 700; }
|
||||
.appointment-block small { color: var(--text-secondary); }
|
||||
.detail-body { display: grid; gap: 18px; }
|
||||
.detail-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
||||
.detail-title strong { font-size: 20px; }
|
||||
dl { display: grid; gap: 10px; margin: 0; }
|
||||
dt { color: var(--text-secondary); font-size: 12px; }
|
||||
dd { margin: -6px 0 4px; color: var(--text-primary); font-weight: 600; }
|
||||
@media (max-width: 720px) {
|
||||
.summary-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||
.summary-strip div { min-width: 0; padding: 12px 10px; }
|
||||
.summary-strip strong { font-size: 18px; }
|
||||
.day-row { grid-template-columns: 1fr; gap: 8px; }
|
||||
.day-label { grid-template-columns: auto auto 1fr; align-items: baseline; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,340 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, shallowRef, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
CalendarOutlined,
|
||||
LeftOutlined,
|
||||
RightOutlined,
|
||||
StarFilled,
|
||||
UserOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { nailArtistApi, type NailArtistListItemVO } from '@/api/nail-artist'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const artists = ref<NailArtistListItemVO[]>([])
|
||||
const loading = shallowRef(false)
|
||||
const loadError = shallowRef('')
|
||||
|
||||
const shopId = computed(() => String(route.params.shopId || ''))
|
||||
const pageTitle = computed(() => String(route.query.shopName || '美甲师'))
|
||||
|
||||
const formatRating = (value?: number | string) => {
|
||||
const rating = Number(value || 0)
|
||||
return rating > 0 ? rating.toFixed(1) : '暂无'
|
||||
}
|
||||
|
||||
const parseSkillTags = (skills?: string) => {
|
||||
return String(skills || '')
|
||||
.split(/[,;,;、\s]+/)
|
||||
.map(tag => tag.trim())
|
||||
.filter(Boolean)
|
||||
.slice(0, 4)
|
||||
}
|
||||
|
||||
const formatWorkTime = (artist: NailArtistListItemVO) => {
|
||||
const start = String(artist.workStartTime || '').slice(0, 5)
|
||||
const end = String(artist.workEndTime || '').slice(0, 5)
|
||||
return start && end ? `${start}-${end}` : '到店确认'
|
||||
}
|
||||
|
||||
const displayName = (artist: NailArtistListItemVO) => artist.nickname || artist.identity || '美甲师'
|
||||
|
||||
const openArtist = (artist: NailArtistListItemVO) => {
|
||||
const artistId = artist.userId
|
||||
if (!artistId) {
|
||||
message.info('美甲师信息暂未完善')
|
||||
return
|
||||
}
|
||||
router.push(`/artist/${artistId}`)
|
||||
}
|
||||
|
||||
const loadArtists = async () => {
|
||||
if (!shopId.value) {
|
||||
loadError.value = '缺少店铺信息'
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
artists.value = await nailArtistApi.listByShopId(shopId.value)
|
||||
} catch (error) {
|
||||
loadError.value = error instanceof Error ? error.message : '美甲师列表加载失败'
|
||||
message.error(loadError.value)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(shopId, loadArtists, { immediate: true })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="artist-list-page">
|
||||
<header class="artist-list-topbar">
|
||||
<a-button class="nav-button" type="text" aria-label="返回" @click="router.back()">
|
||||
<LeftOutlined />
|
||||
</a-button>
|
||||
<h1>{{ pageTitle }}</h1>
|
||||
<span class="topbar-count">{{ artists.length }} 位</span>
|
||||
</header>
|
||||
|
||||
<main class="artist-list-body">
|
||||
<a-spin :spinning="loading">
|
||||
<a-result v-if="loadError" status="warning" title="暂时无法查看美甲师" :sub-title="loadError">
|
||||
<template #extra>
|
||||
<a-button type="primary" @click="loadArtists">重试</a-button>
|
||||
</template>
|
||||
</a-result>
|
||||
|
||||
<template v-else>
|
||||
<section class="list-summary">
|
||||
<span>Artists</span>
|
||||
<h2>本店美甲师</h2>
|
||||
<p>选择熟悉的美甲师进入主页,查看作品、评价和近期可预约时间。</p>
|
||||
</section>
|
||||
|
||||
<div v-if="artists.length" class="artist-cards">
|
||||
<button
|
||||
v-for="artist in artists"
|
||||
:key="artist.userId || artist.id"
|
||||
class="artist-card"
|
||||
type="button"
|
||||
@click="openArtist(artist)"
|
||||
>
|
||||
<a-avatar :size="56" class="artist-avatar">
|
||||
<UserOutlined />
|
||||
</a-avatar>
|
||||
<div class="artist-copy">
|
||||
<div class="artist-heading">
|
||||
<strong>{{ displayName(artist) }}</strong>
|
||||
<span :class="['status-chip', artist.status === 1 ? 'status-chip--active' : '']">
|
||||
{{ artist.status === 1 ? '可预约' : '休息中' }}
|
||||
</span>
|
||||
</div>
|
||||
<p>{{ artist.signature || artist.identity || '专注细节与稳定出品' }}</p>
|
||||
<div class="artist-meta">
|
||||
<span><StarFilled /> {{ formatRating(artist.rating) }}</span>
|
||||
<span><CalendarOutlined /> {{ formatWorkTime(artist) }}</span>
|
||||
</div>
|
||||
<div v-if="parseSkillTags(artist.skills).length" class="tag-row">
|
||||
<span v-for="tag in parseSkillTags(artist.skills)" :key="tag">{{ tag }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<RightOutlined class="card-arrow" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<a-empty v-else class="empty-state" description="本店暂未配置可展示的美甲师" />
|
||||
</template>
|
||||
</a-spin>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.artist-list-page {
|
||||
min-height: 100vh;
|
||||
background:
|
||||
radial-gradient(circle at 18% 0%, rgba(232, 180, 184, 0.28), transparent 34%),
|
||||
var(--theme-page-bg);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.artist-list-topbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 20;
|
||||
display: grid;
|
||||
grid-template-columns: 44px minmax(0, 1fr) 52px;
|
||||
align-items: center;
|
||||
height: 58px;
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
padding: 0 14px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent);
|
||||
border-bottom: 1px solid var(--theme-border);
|
||||
backdrop-filter: blur(14px);
|
||||
}
|
||||
|
||||
.nav-button {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.artist-list-topbar h1 {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.topbar-count {
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.artist-list-body {
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
padding: 18px 14px 36px;
|
||||
}
|
||||
|
||||
.list-summary {
|
||||
padding: 20px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent);
|
||||
border: 1px solid color-mix(in srgb, var(--theme-border) 78%, transparent);
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 16px 40px rgba(124, 83, 87, 0.08);
|
||||
backdrop-filter: blur(18px);
|
||||
}
|
||||
|
||||
.list-summary span {
|
||||
color: var(--theme-primary);
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.05em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.list-summary h2 {
|
||||
margin: 8px 0;
|
||||
font-size: 22px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.list-summary p {
|
||||
margin: 0;
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.artist-cards {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.artist-card {
|
||||
display: grid;
|
||||
grid-template-columns: 56px minmax(0, 1fr) 18px;
|
||||
gap: 14px;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
padding: 16px;
|
||||
color: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent);
|
||||
border: 1px solid color-mix(in srgb, var(--theme-border) 82%, transparent);
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 12px 28px rgba(124, 83, 87, 0.06);
|
||||
}
|
||||
|
||||
.artist-avatar {
|
||||
color: var(--theme-primary);
|
||||
background: var(--theme-primary-soft);
|
||||
border: 2px solid #fff;
|
||||
}
|
||||
|
||||
.artist-copy {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.artist-heading {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.artist-heading strong {
|
||||
overflow: hidden;
|
||||
font-size: 17px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.status-chip {
|
||||
flex: 0 0 auto;
|
||||
padding: 4px 8px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 70%, var(--theme-primary-soft));
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.status-chip--active {
|
||||
color: var(--theme-primary);
|
||||
background: var(--theme-primary-soft);
|
||||
}
|
||||
|
||||
.artist-copy p {
|
||||
display: -webkit-box;
|
||||
margin: 6px 0 10px;
|
||||
overflow: hidden;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
}
|
||||
|
||||
.artist-meta,
|
||||
.tag-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.artist-meta span {
|
||||
display: inline-flex;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.artist-meta svg {
|
||||
color: var(--theme-primary);
|
||||
}
|
||||
|
||||
.tag-row {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.tag-row span {
|
||||
padding: 4px 8px;
|
||||
color: var(--theme-primary);
|
||||
font-size: 12px;
|
||||
background: var(--theme-primary-soft);
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.card-arrow {
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
margin-top: 48px;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.artist-list-body {
|
||||
padding: 14px 12px 30px;
|
||||
}
|
||||
|
||||
.artist-card {
|
||||
grid-template-columns: 52px minmax(0, 1fr) 16px;
|
||||
gap: 12px;
|
||||
padding: 14px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,748 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<header class="header">
|
||||
<a-button type="text" @click="router.back()">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>美甲师订单</h1>
|
||||
<a-button v-if="showCalendarEntry" type="link" @click="router.push('/artist-calendar')">日历</a-button>
|
||||
<div v-else class="placeholder" />
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<section v-if="orders.length" class="filter-panel">
|
||||
<a-input v-model:value="filters.keyword" allow-clear placeholder="搜索订单号、客户、作品" />
|
||||
<div class="filter-row">
|
||||
<a-select v-model:value="filters.source" class="filter-select" placeholder="订单来源">
|
||||
<a-select-option value="all">全部来源</a-select-option>
|
||||
<a-select-option value="SERVICE">客户预约我的订单</a-select-option>
|
||||
<a-select-option value="SHOP">本店美甲师订单</a-select-option>
|
||||
<a-select-option value="SELF">我下的订单</a-select-option>
|
||||
<a-select-option value="BOTH">两者都有</a-select-option>
|
||||
</a-select>
|
||||
<a-select v-model:value="filters.status" class="filter-select" placeholder="订单状态">
|
||||
<a-select-option value="all">全部状态</a-select-option>
|
||||
<a-select-option :value="0">确认价格中</a-select-option>
|
||||
<a-select-option :value="1">待使用</a-select-option>
|
||||
<a-select-option :value="2">已完成</a-select-option>
|
||||
<a-select-option :value="3">已取消</a-select-option>
|
||||
</a-select>
|
||||
</div>
|
||||
<div class="filter-row">
|
||||
<a-date-picker v-model:value="filters.date" class="filter-date" popup-class-name="yumi-date-picker-panel" placeholder="预约日期" />
|
||||
<a-input-number v-model:value="filters.minAmount" class="filter-number" :min="0" placeholder="最低金额" />
|
||||
<a-input-number v-model:value="filters.maxAmount" class="filter-number" :min="0" placeholder="最高金额" />
|
||||
</div>
|
||||
<div class="filter-actions">
|
||||
<span>共 {{ filteredOrders.length }} / {{ orders.length }} 个订单</span>
|
||||
<a-button @click="resetFilters">重置</a-button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-empty v-if="!orders.length" description="暂无订单">
|
||||
<a-button type="primary" @click="handleRefreshClick">刷新</a-button>
|
||||
</a-empty>
|
||||
<a-empty v-else-if="!filteredOrders.length" description="没有符合条件的订单">
|
||||
<a-button @click="resetFilters">清空筛选</a-button>
|
||||
</a-empty>
|
||||
|
||||
<a-card
|
||||
v-for="order in filteredOrders"
|
||||
:key="order.id"
|
||||
:ref="(el: any) => setOrderRef(order.id, el)"
|
||||
class="order-card"
|
||||
:class="{ 'is-target': isTargetOrder(order.id) }"
|
||||
>
|
||||
<div class="order-head">
|
||||
<div class="order-title">
|
||||
<span>订单号:{{ order.orderNo }}</span>
|
||||
<span v-if="order.artistOrderSourceText" class="source-tag" :class="sourceClass(order.artistOrderSource)">
|
||||
{{ order.artistOrderSourceText }}
|
||||
</span>
|
||||
<span v-if="isQuoteOrder(order)" class="quote-tag">询价预约</span>
|
||||
</div>
|
||||
<span class="status" :class="statusClass(order.status)">{{ orderStatusText(order) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="customer-meta">
|
||||
<span>预约用户:{{ order.customerNickname || '用户' }}</span>
|
||||
<span v-if="order.customerPhoneMasked">联系电话:{{ order.customerPhoneMasked }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="isQuoteOrder(order)" class="quote-summary">
|
||||
<div class="quote-summary__head">
|
||||
<strong>{{ quoteStatusText(order) }}</strong>
|
||||
<span v-if="order.quoteExpireTime">过期时间:{{ order.quoteExpireTime }}</span>
|
||||
</div>
|
||||
<p v-if="order.customerRemark">客户备注:{{ order.customerRemark }}</p>
|
||||
<div class="quote-summary__flags">
|
||||
<span>客户{{ confirmationText(order.quoteUserConfirmed) }}</span>
|
||||
<span>门店{{ confirmationText(order.quoteShopConfirmed) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-for="item in order.items" :key="item.id" class="item">
|
||||
<div class="thumb">
|
||||
<img v-if="item.productImage" :src="item.productImage" :alt="item.productTitle" loading="lazy" decoding="async" />
|
||||
<span v-else>{{ item.productTitle[0] }}</span>
|
||||
</div>
|
||||
<div class="main">
|
||||
<div class="title">{{ item.productTitle }}</div>
|
||||
<div class="line">{{ formatMoney(item.price) }} x {{ item.quantity }}</div>
|
||||
<div v-if="hasItemQuoteInfo(item)" class="line quote-line">
|
||||
参考 {{ formatMoney(item.referencePrice ?? item.price) }} · 报价 {{ formatMoney(item.quotedPrice) }} · 最终 {{ formatMoney(item.confirmedPrice) }}
|
||||
</div>
|
||||
<div v-if="item.appointmentTime" class="line appointment">预约时间:{{ item.appointmentTime }}</div>
|
||||
<div v-if="pendingArtistChangeForItem(order, item)" class="change-status">
|
||||
改派申请处理中:{{ pendingArtistChangeForItem(order, item)?.requestedArtistName || '新美甲师' }}
|
||||
</div>
|
||||
<div v-else-if="canRequestArtistChange(order, item)" class="change-action">
|
||||
<span>需要更换服务美甲师</span>
|
||||
<a-button size="small" @click="openArtistChangeModal(order, item)">申请改派</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<span>当前项目合计:{{ formatMoney(order.actualAmount) }}</span>
|
||||
<div class="footer-actions">
|
||||
<a-button v-if="canQuoteOrder(order)" size="small" type="primary" @click="openQuoteModal(order)">
|
||||
报价/确认价格
|
||||
</a-button>
|
||||
<a-button v-if="canComplete(order)" size="small" type="primary" @click="completeOrder(order.id)">
|
||||
完成服务
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</main>
|
||||
|
||||
<a-modal
|
||||
v-model:open="artistChangeModalOpen"
|
||||
title="申请改派"
|
||||
:confirm-loading="artistChangeSubmitting"
|
||||
@ok="submitArtistChangeRequest"
|
||||
@cancel="closeArtistChangeModal"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="当前美甲师">
|
||||
<span>{{ artistChangeOptions?.currentArtistName || activeArtistChangeItem?.artistName || '未分配' }}</span>
|
||||
</a-form-item>
|
||||
<a-form-item label="新美甲师" required>
|
||||
<a-select
|
||||
v-model:value="artistChangeForm.requestedArtistId"
|
||||
:loading="artistChangeOptionsLoading"
|
||||
placeholder="请选择新的美甲师"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="artist in selectableArtistOptions"
|
||||
:key="String(artist.artistId)"
|
||||
:value="artist.artistId"
|
||||
>
|
||||
{{ artist.artistName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="改派原因" required>
|
||||
<a-textarea v-model:value="artistChangeForm.reason" :rows="4" :maxlength="300" placeholder="请说明申请改派的原因" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<a-modal
|
||||
v-model:open="quoteModalOpen"
|
||||
title="门店报价"
|
||||
:footer="null"
|
||||
@cancel="closeQuoteModal"
|
||||
>
|
||||
<a-form layout="vertical" class="quote-form">
|
||||
<div class="quote-form__items">
|
||||
<div v-for="item in activeQuoteOrder?.items || []" :key="item.id" class="quote-form__item">
|
||||
<div class="quote-form__meta">
|
||||
<strong>{{ item.productTitle || `订单项 ${item.id}` }}</strong>
|
||||
<span>参考价 {{ formatMoney(item.referencePrice ?? item.price) }}</span>
|
||||
</div>
|
||||
<a-input-number
|
||||
:value="quoteInputValue(item)"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
placeholder="报价"
|
||||
class="quote-form__input"
|
||||
@change="value => setQuoteInputValue(item, value)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<a-form-item label="报价备注">
|
||||
<a-textarea v-model:value="quoteForm.remark" :rows="3" :maxlength="300" placeholder="填写给客户的报价说明" />
|
||||
</a-form-item>
|
||||
<div class="quote-form__actions">
|
||||
<a-button type="primary" :loading="quoteSubmitting" @click="submitQuote">提交报价</a-button>
|
||||
<a-button :loading="quoteConfirming" @click="confirmQuote">确认当前价格</a-button>
|
||||
</div>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* ArtistOrderView 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, nextTick, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { userApi } from '@/api/user'
|
||||
import { orderApi } from '../api/order'
|
||||
import type { OrderArtistChangeOptionsVO, OrderArtistChangeRequestVO } from '../api/order'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { extractLegacyFileId, getCachedSignedImageUrl, getCachedSignedImageUrlSync } from '@/utils/signed-image-cache'
|
||||
|
||||
/**
|
||||
* Purpose: router supports ArtistOrderView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const router = useRouter()
|
||||
/**
|
||||
* Purpose: route supports ArtistOrderView.vue by holding or executing the route page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const route = useRoute()
|
||||
/**
|
||||
* Purpose: orders supports ArtistOrderView.vue by holding or executing the orders page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const orders = ref<any[]>([])
|
||||
/**
|
||||
* Purpose: orderRefs supports ArtistOrderView.vue by holding or executing the order refs page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const orderRefs = ref<Record<string, any>>({})
|
||||
/**
|
||||
* Purpose: showCalendarEntry supports ArtistOrderView.vue by holding or executing the show calendar entry page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const showCalendarEntry = ref(false)
|
||||
/**
|
||||
* Purpose: currentUserId supports ArtistOrderView.vue by holding or executing the current user id page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const currentUserId = ref<IdType>()
|
||||
const currentUserType = ref<number>()
|
||||
/**
|
||||
* Purpose: artistChangeModalOpen supports ArtistOrderView.vue by holding or executing the artist change modal open page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const artistChangeModalOpen = ref(false)
|
||||
const quoteModalOpen = ref(false)
|
||||
const quoteSubmitting = ref(false)
|
||||
const quoteConfirming = ref(false)
|
||||
/**
|
||||
* Purpose: artistChangeSubmitting supports ArtistOrderView.vue by holding or executing the artist change submitting page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const artistChangeSubmitting = ref(false)
|
||||
/**
|
||||
* Purpose: artistChangeOptionsLoading supports ArtistOrderView.vue by holding or executing the artist change options loading page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const artistChangeOptionsLoading = ref(false)
|
||||
/**
|
||||
* Purpose: artistChangeOptions supports ArtistOrderView.vue by holding or executing the artist change options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const artistChangeOptions = ref<OrderArtistChangeOptionsVO | null>(null)
|
||||
/**
|
||||
* Purpose: activeArtistChangeOrder supports ArtistOrderView.vue by holding or executing the active artist change order page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const activeArtistChangeOrder = ref<any | null>(null)
|
||||
/**
|
||||
* Purpose: activeArtistChangeItem supports ArtistOrderView.vue by holding or executing the active artist change item page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const activeArtistChangeItem = ref<any | null>(null)
|
||||
const activeQuoteOrder = ref<any | null>(null)
|
||||
/**
|
||||
* Purpose: filters supports ArtistOrderView.vue by holding or executing the filters page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const filters = reactive({
|
||||
keyword: '',
|
||||
source: 'all',
|
||||
status: 'all' as 'all' | number,
|
||||
date: null as any,
|
||||
minAmount: undefined as number | undefined,
|
||||
maxAmount: undefined as number | undefined
|
||||
})
|
||||
/**
|
||||
* Purpose: artistChangeForm supports ArtistOrderView.vue by holding or executing the artist change form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const artistChangeForm = reactive({
|
||||
requestedArtistId: undefined as IdType | undefined,
|
||||
reason: ''
|
||||
})
|
||||
const quoteForm = reactive({
|
||||
remark: '',
|
||||
items: {} as Record<string, number | undefined>
|
||||
})
|
||||
|
||||
/** filteredOrders is a reactive state variable used by the template and event handlers. */
|
||||
const filteredOrders = computed(() => {
|
||||
const keyword = filters.keyword.trim().toLowerCase()
|
||||
const targetDate = filters.date?.format?.('YYYY-MM-DD')
|
||||
return orders.value.filter(order => {
|
||||
if (filters.source !== 'all' && order.artistOrderSource !== filters.source) return false
|
||||
if (filters.status !== 'all' && order.status !== filters.status) return false
|
||||
const amount = Number(order.actualAmount || 0)
|
||||
if (filters.minAmount !== undefined && amount < filters.minAmount) return false
|
||||
if (filters.maxAmount !== undefined && amount > filters.maxAmount) return false
|
||||
const items = order.items || []
|
||||
if (targetDate && !items.some((item: any) => String(item.appointmentTime || '').slice(0, 10) === targetDate)) {
|
||||
return false
|
||||
}
|
||||
if (keyword) {
|
||||
const haystack = [
|
||||
order.orderNo,
|
||||
order.statusText,
|
||||
order.quoteStatusText,
|
||||
order.customerRemark,
|
||||
order.artistOrderSourceText,
|
||||
order.customerNickname,
|
||||
order.customerPhoneMasked,
|
||||
...items.flatMap((item: any) => [item.productTitle, item.appointmentTime])
|
||||
].filter(Boolean).join(' ').toLowerCase()
|
||||
if (!haystack.includes(keyword)) return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
})
|
||||
|
||||
/** targetOrderId is a local helper used by this page script. */
|
||||
const targetOrderId = () => String(route.query.orderId || '')
|
||||
/** isTargetOrder is a local helper used by this page script. */
|
||||
const isTargetOrder = (orderId: IdType) => targetOrderId() === String(orderId)
|
||||
|
||||
/** setOrderRef is a local helper used by this page script. */
|
||||
const setOrderRef = (orderId: IdType, el: any) => {
|
||||
if (!el) return
|
||||
orderRefs.value[String(orderId)] = el
|
||||
}
|
||||
|
||||
/** scrollToTargetOrder is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const scrollToTargetOrder = async () => {
|
||||
const id = targetOrderId()
|
||||
if (!id) return
|
||||
await nextTick()
|
||||
const target = orderRefs.value[id]?.$el || orderRefs.value[id]
|
||||
target?.scrollIntoView?.({ behavior: 'smooth', block: 'center' })
|
||||
}
|
||||
|
||||
const isQuoteOrder = (order: any) => Number(order?.status) === 0
|
||||
|
||||
const orderStatusText = (order: any) => order?.statusText || (isQuoteOrder(order) ? '确认价格中' : '--')
|
||||
|
||||
const quoteStatusText = (order: any) => order?.quoteStatusText || (isQuoteOrder(order) ? '确认价格中' : '--')
|
||||
|
||||
const confirmationText = (confirmed?: boolean) => confirmed ? '已确认' : '待确认'
|
||||
|
||||
const formatMoney = (value?: unknown) => {
|
||||
if (value === undefined || value === null || value === '') return '--'
|
||||
const amount = Number(value)
|
||||
return Number.isFinite(amount) ? `¥${amount.toFixed(2)}` : '--'
|
||||
}
|
||||
|
||||
const hasItemQuoteInfo = (item: any) => {
|
||||
return item?.referencePrice !== undefined || item?.quotedPrice !== undefined || item?.confirmedPrice !== undefined
|
||||
}
|
||||
|
||||
/** statusClass is a local helper used by this page script. */
|
||||
const statusClass = (status: number) => {
|
||||
const normalized = Number(status)
|
||||
if (normalized === 0) return 'quoting'
|
||||
if (normalized === 1) return 'pending'
|
||||
if (normalized === 2) return 'completed'
|
||||
return 'cancelled'
|
||||
}
|
||||
|
||||
/** sourceClass is a local helper used by this page script. */
|
||||
const sourceClass = (source?: string) => {
|
||||
if (source === 'SELF') return 'source-self'
|
||||
if (source === 'BOTH') return 'source-both'
|
||||
if (source === 'SHOP') return 'source-shop'
|
||||
return 'source-service'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: sameId supports ArtistOrderView.vue by holding or executing the same id page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const sameId = (left: unknown, right: unknown) => {
|
||||
return left !== undefined && left !== null && right !== undefined && right !== null && String(left) === String(right)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: pendingArtistChangeForItem supports ArtistOrderView.vue by holding or executing the pending artist change for item page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const pendingArtistChangeForItem = (order: any, item: any): OrderArtistChangeRequestVO | undefined => {
|
||||
const itemValue = item?.pendingArtistChangeRequest as OrderArtistChangeRequestVO | undefined
|
||||
if (itemValue) return itemValue
|
||||
const orderValue = order?.pendingArtistChangeRequest as OrderArtistChangeRequestVO | undefined
|
||||
if (!orderValue) return undefined
|
||||
return sameId(orderValue.orderItemId, item.id) || (order.items || []).length === 1 ? orderValue : undefined
|
||||
}
|
||||
|
||||
/** canComplete is a local helper used by this page script. */
|
||||
const canComplete = (order: any) => {
|
||||
return !isQuoteOrder(order) && Number(order.status) === 1 && order.artistOrderSource !== 'SELF' && order.artistOrderSource !== 'SHOP'
|
||||
}
|
||||
|
||||
const canQuoteOrder = (order: any) => {
|
||||
return currentUserType.value === 2 && isQuoteOrder(order) && order.artistOrderSource === 'SHOP'
|
||||
}
|
||||
|
||||
const resetQuoteForm = (order: any) => {
|
||||
quoteForm.remark = ''
|
||||
Object.keys(quoteForm.items).forEach(key => {
|
||||
delete quoteForm.items[key]
|
||||
})
|
||||
for (const item of order?.items || []) {
|
||||
if (item?.id === undefined || item?.id === null) continue
|
||||
quoteForm.items[String(item.id)] = Number(item.quotedPrice ?? item.confirmedPrice ?? item.referencePrice ?? item.price ?? 0)
|
||||
}
|
||||
}
|
||||
|
||||
const openQuoteModal = (order: any) => {
|
||||
if (!canQuoteOrder(order)) return
|
||||
activeQuoteOrder.value = order
|
||||
resetQuoteForm(order)
|
||||
quoteModalOpen.value = true
|
||||
}
|
||||
|
||||
const closeQuoteModal = () => {
|
||||
quoteModalOpen.value = false
|
||||
activeQuoteOrder.value = null
|
||||
resetQuoteForm(null)
|
||||
}
|
||||
|
||||
const quoteInputValue = (item: any) => {
|
||||
if (item?.id === undefined || item?.id === null) return undefined
|
||||
return quoteForm.items[String(item.id)]
|
||||
}
|
||||
|
||||
const setQuoteInputValue = (item: any, value: unknown) => {
|
||||
if (item?.id === undefined || item?.id === null) return
|
||||
const key = String(item.id)
|
||||
if (value === undefined || value === null || value === '') {
|
||||
quoteForm.items[key] = undefined
|
||||
return
|
||||
}
|
||||
quoteForm.items[key] = Number(value)
|
||||
}
|
||||
|
||||
const collectQuoteItems = (order: any) => {
|
||||
const orderItems = order?.items || []
|
||||
if (!orderItems.length) return null
|
||||
const items: Array<{ orderItemId: IdType; quotedPrice: number }> = []
|
||||
for (const item of orderItems) {
|
||||
if (item?.id === undefined || item?.id === null) return null
|
||||
const price = Number(quoteForm.items[String(item.id)])
|
||||
if (!Number.isFinite(price) || price <= 0) return null
|
||||
items.push({ orderItemId: item.id, quotedPrice: price })
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
const syncActiveQuoteOrder = (orderId: IdType, fallback?: any) => {
|
||||
if (!sameId(activeQuoteOrder.value?.id, orderId)) return
|
||||
activeQuoteOrder.value = orders.value.find(order => sameId(order.id, orderId)) || fallback || activeQuoteOrder.value
|
||||
resetQuoteForm(activeQuoteOrder.value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: canRequestArtistChange supports ArtistOrderView.vue by holding or executing the can request artist change page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const canRequestArtistChange = (order: any, item: any) => {
|
||||
const assignedToCurrentUser = !currentUserId.value || !item.artistId || sameId(item.artistId, currentUserId.value)
|
||||
return !isQuoteOrder(order) && Number(order.status) === 1 && item.id && assignedToCurrentUser && !pendingArtistChangeForItem(order, item)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: selectableArtistOptions supports ArtistOrderView.vue by holding or executing the selectable artist options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const selectableArtistOptions = computed(() => {
|
||||
const options = artistChangeOptions.value?.artists || []
|
||||
return options.filter(artist => !sameId(artist.artistId, artistChangeOptions.value?.currentArtistId))
|
||||
})
|
||||
|
||||
/** resetFilters is a local helper used by this page script. */
|
||||
const resetFilters = () => {
|
||||
filters.keyword = ''
|
||||
filters.source = 'all'
|
||||
filters.status = 'all'
|
||||
filters.date = null
|
||||
filters.minAmount = undefined
|
||||
filters.maxAmount = undefined
|
||||
}
|
||||
|
||||
/** loadOrders is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadOrders = async () => {
|
||||
try {
|
||||
orders.value = (await orderApi.getArtistOrders() as unknown as any[]) || []
|
||||
for (const order of orders.value) {
|
||||
for (const item of order.items || []) {
|
||||
const imageId = extractLegacyFileId(item.productImage)
|
||||
if (!imageId) continue
|
||||
const cachedUrl = getCachedSignedImageUrlSync(imageId)
|
||||
if (cachedUrl) item.productImage = cachedUrl
|
||||
item.productImage = await getCachedSignedImageUrl(imageId)
|
||||
}
|
||||
}
|
||||
await scrollToTargetOrder()
|
||||
} catch {
|
||||
message.error('获取订单列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
/** loadCalendarAccess is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadCalendarAccess = async () => {
|
||||
showCalendarEntry.value = false
|
||||
try {
|
||||
const currentUser = await userApi.getUserInfo()
|
||||
currentUserId.value = currentUser.id
|
||||
currentUserType.value = currentUser.type
|
||||
if (currentUser.type === 3) {
|
||||
showCalendarEntry.value = true
|
||||
return
|
||||
}
|
||||
if (currentUser.type === 2) {
|
||||
const artistInfo = await userApi.getNailArtistInfo(currentUser.id).catch(() => null)
|
||||
showCalendarEntry.value = Number(artistInfo?.participateProduction) === 1
|
||||
}
|
||||
} catch {
|
||||
currentUserId.value = undefined
|
||||
currentUserType.value = undefined
|
||||
showCalendarEntry.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** handleRefreshClick is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleRefreshClick = async () => {
|
||||
await runWithGlobalLoading(() => loadOrders())
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: openArtistChangeModal supports ArtistOrderView.vue by holding or executing the open artist change modal page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const openArtistChangeModal = async (order: any, item: any) => {
|
||||
if (!canRequestArtistChange(order, item)) return
|
||||
activeArtistChangeOrder.value = order
|
||||
activeArtistChangeItem.value = item
|
||||
artistChangeOptions.value = null
|
||||
artistChangeForm.requestedArtistId = undefined
|
||||
artistChangeForm.reason = ''
|
||||
artistChangeModalOpen.value = true
|
||||
artistChangeOptionsLoading.value = true
|
||||
try {
|
||||
artistChangeOptions.value = await orderApi.getArtistChangeOptions(order.id, item.id)
|
||||
if (!selectableArtistOptions.value.length) {
|
||||
message.warning('暂无可改派的美甲师')
|
||||
}
|
||||
} catch {
|
||||
message.error('获取可改派美甲师失败')
|
||||
closeArtistChangeModal()
|
||||
} finally {
|
||||
artistChangeOptionsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: closeArtistChangeModal supports ArtistOrderView.vue by holding or executing the close artist change modal page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const closeArtistChangeModal = () => {
|
||||
artistChangeModalOpen.value = false
|
||||
activeArtistChangeOrder.value = null
|
||||
activeArtistChangeItem.value = null
|
||||
artistChangeOptions.value = null
|
||||
artistChangeForm.requestedArtistId = undefined
|
||||
artistChangeForm.reason = ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: submitArtistChangeRequest supports ArtistOrderView.vue by holding or executing the submit artist change request page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const submitArtistChangeRequest = async () => {
|
||||
if (!activeArtistChangeOrder.value || !activeArtistChangeItem.value) return
|
||||
if (!artistChangeForm.requestedArtistId) {
|
||||
message.warning('请选择新的美甲师')
|
||||
return
|
||||
}
|
||||
const reason = artistChangeForm.reason.trim()
|
||||
if (!reason) {
|
||||
message.warning('请填写改派原因')
|
||||
return
|
||||
}
|
||||
if (sameId(artistChangeForm.requestedArtistId, artistChangeOptions.value?.currentArtistId)) {
|
||||
message.warning('新美甲师不能与当前美甲师相同')
|
||||
return
|
||||
}
|
||||
artistChangeSubmitting.value = true
|
||||
try {
|
||||
await orderApi.requestArtistChange({
|
||||
orderId: activeArtistChangeOrder.value.id,
|
||||
orderItemId: activeArtistChangeItem.value.id,
|
||||
requestedArtistId: artistChangeForm.requestedArtistId,
|
||||
reason
|
||||
})
|
||||
message.success('改派申请已提交')
|
||||
closeArtistChangeModal()
|
||||
await loadOrders()
|
||||
} catch {
|
||||
message.error('提交改派申请失败')
|
||||
} finally {
|
||||
artistChangeSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const submitQuote = async () => {
|
||||
const order = activeQuoteOrder.value
|
||||
if (!order || !canQuoteOrder(order)) return
|
||||
const items = collectQuoteItems(order)
|
||||
if (!items) {
|
||||
message.warning('请填写每个项目的有效报价')
|
||||
return
|
||||
}
|
||||
quoteSubmitting.value = true
|
||||
try {
|
||||
let updatedOrder: any
|
||||
await runWithGlobalLoading(async () => {
|
||||
updatedOrder = await orderApi.submitShopQuote(order.id, {
|
||||
remark: quoteForm.remark.trim() || undefined,
|
||||
items
|
||||
})
|
||||
await loadOrders()
|
||||
})
|
||||
syncActiveQuoteOrder(order.id, updatedOrder)
|
||||
message.success('报价已提交')
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '提交报价失败')
|
||||
} finally {
|
||||
quoteSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const confirmQuote = async () => {
|
||||
const order = activeQuoteOrder.value
|
||||
if (!order || !canQuoteOrder(order)) return
|
||||
quoteConfirming.value = true
|
||||
try {
|
||||
let updatedOrder: any
|
||||
await runWithGlobalLoading(async () => {
|
||||
updatedOrder = await orderApi.confirmShopQuote(order.id)
|
||||
await loadOrders()
|
||||
})
|
||||
syncActiveQuoteOrder(order.id, updatedOrder)
|
||||
message.success('当前价格已确认')
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '确认当前价格失败')
|
||||
} finally {
|
||||
quoteConfirming.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** completeOrder is a local helper used by this page script. */
|
||||
const completeOrder = (orderId: IdType) => {
|
||||
Modal.confirm({
|
||||
title: '确认完成服务',
|
||||
content: '确定要完成这个订单吗?',
|
||||
onOk: async () => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await orderApi.completeArtistOrder(orderId)
|
||||
await loadOrders()
|
||||
})
|
||||
message.success('订单已完成')
|
||||
} catch (error: any) {
|
||||
message.error('完成订单失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await Promise.all([loadCalendarAccess(), loadOrders()])
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { min-height: 100vh; padding-top: 60px; background: linear-gradient(rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.92)), var(--theme-background-image), var(--theme-page-bg); background-size: cover, cover, auto; background-position: center top; color: var(--text-primary); }
|
||||
.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; height: 60px; padding: 10px 15px; background: rgba(255, 255, 255, 0.92); border-bottom: 1px solid var(--theme-border); backdrop-filter: blur(14px); }
|
||||
.header h1 { margin: 0; font-size: 18px; color: var(--text-primary); }
|
||||
.placeholder { width: 40px; height: 40px; }
|
||||
.content { padding: 15px; }
|
||||
.filter-panel { display: grid; gap: 10px; margin-bottom: 12px; padding: 12px; border-radius: 14px; background: var(--theme-card-bg); border: 1px solid var(--theme-border); box-shadow: 0 14px 34px rgba(122, 67, 88, 0.08); }
|
||||
.filter-row { display: flex; gap: 8px; align-items: center; }
|
||||
.filter-select, .filter-date, .filter-number { flex: 1; min-width: 0; }
|
||||
.filter-actions { display: flex; align-items: center; justify-content: space-between; color: var(--text-secondary); font-size: 12px; }
|
||||
.order-card { margin-bottom: 12px; border-radius: 14px; border: 1px solid var(--theme-border); background: var(--theme-card-bg); box-shadow: 0 14px 34px rgba(122, 67, 88, 0.08); }
|
||||
.order-card.is-target { border-color: var(--theme-primary); box-shadow: 0 0 0 2px rgba(198, 89, 125, .16); }
|
||||
.order-head, .footer { display: flex; align-items: center; justify-content: space-between; }
|
||||
.footer { gap: 10px; }
|
||||
.footer-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
|
||||
.order-head { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--theme-border); }
|
||||
.order-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
||||
.source-tag { padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
|
||||
.source-service { background: var(--theme-primary-soft); color: var(--theme-primary); }
|
||||
.source-shop { background: var(--theme-primary-soft); color: var(--theme-primary); }
|
||||
.source-self { background: var(--theme-primary-soft); color: var(--theme-accent); }
|
||||
.source-both { background: var(--theme-primary-soft); color: var(--theme-primary); }
|
||||
.quote-tag { padding: 3px 8px; border-radius: 999px; background: rgba(22, 119, 255, .1); color: #1677ff; font-size: 12px; font-weight: 600; }
|
||||
.customer-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 12px; color: var(--text-secondary); font-size: 13px; }
|
||||
.quote-summary { display: grid; gap: 8px; margin-bottom: 12px; padding: 10px; border-radius: 8px; background: rgba(22, 119, 255, .08); color: var(--text-secondary); font-size: 13px; }
|
||||
.quote-summary__head, .quote-summary__flags { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
|
||||
.quote-summary__head strong { color: #1677ff; }
|
||||
.quote-summary p { margin: 0; }
|
||||
.status { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
|
||||
.quoting { background: rgba(22, 119, 255, .1); color: #1677ff; }
|
||||
.pending { background: var(--theme-primary-soft); color: var(--theme-primary); }
|
||||
.completed { background: var(--theme-primary-soft); color: var(--theme-primary); }
|
||||
.cancelled { background: var(--theme-primary-soft); color: var(--theme-accent); }
|
||||
.item { display: flex; gap: 12px; margin-bottom: 12px; }
|
||||
.thumb { width: 60px; height: 60px; border-radius: 10px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: var(--theme-primary-soft); color: var(--theme-primary); }
|
||||
.thumb img { width: 100%; height: 100%; object-fit: cover; }
|
||||
.main { flex: 1; }
|
||||
.title { font-weight: 600; color: var(--text-primary); }
|
||||
.line { margin-top: 4px; color: var(--text-secondary); font-size: 13px; }
|
||||
.quote-line { color: #1677ff; }
|
||||
.appointment { color: var(--theme-primary); }
|
||||
.change-status { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--theme-primary-soft); color: var(--theme-primary); font-size: 13px; }
|
||||
.change-action { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--theme-primary-soft); color: var(--theme-primary); font-size: 13px; }
|
||||
.quote-form { display: grid; gap: 12px; }
|
||||
.quote-form__items { display: grid; gap: 10px; }
|
||||
.quote-form__item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px; border: 1px solid var(--theme-border); border-radius: 8px; background: var(--theme-primary-soft); }
|
||||
.quote-form__meta { display: grid; gap: 3px; min-width: 0; }
|
||||
.quote-form__meta strong { color: var(--text-primary); }
|
||||
.quote-form__meta span { color: var(--text-secondary); font-size: 12px; }
|
||||
.quote-form__input { width: 140px; flex: 0 0 auto; }
|
||||
.quote-form__actions { display: flex; justify-content: flex-end; gap: 8px; }
|
||||
|
||||
:deep(.ant-btn-primary) { background: var(--theme-primary); border-color: var(--theme-primary); }
|
||||
:deep(.ant-btn-link) { color: var(--theme-primary); }
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.content {
|
||||
max-width: 980px;
|
||||
margin: 0 auto;
|
||||
padding: 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,881 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, shallowRef } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
CalendarOutlined,
|
||||
HeartOutlined,
|
||||
LeftOutlined,
|
||||
MessageOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
ShareAltOutlined,
|
||||
ShopOutlined,
|
||||
StarFilled,
|
||||
UserOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
||||
import {
|
||||
nailArtistApi,
|
||||
type NailArtistAvailabilityVO,
|
||||
type NailArtistProfileVO,
|
||||
type NailArtistReviewVO,
|
||||
type NailArtistWorkVO
|
||||
} from '@/api/nail-artist'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const profile = shallowRef<NailArtistProfileVO | null>(null)
|
||||
const reviews = ref<NailArtistReviewVO[]>([])
|
||||
const availability = ref<NailArtistAvailabilityVO[]>([])
|
||||
const loading = shallowRef(false)
|
||||
const loadError = shallowRef('')
|
||||
const selectedDate = shallowRef('')
|
||||
const workFilter = shallowRef('全部')
|
||||
|
||||
const artistId = computed(() => String(route.params.id || ''))
|
||||
const artistName = computed(() => profile.value?.artistName || '美甲师')
|
||||
const ratingValue = computed(() => Number(profile.value?.rating || 0))
|
||||
const ratingText = computed(() => ratingValue.value > 0 ? ratingValue.value.toFixed(1) : '暂无')
|
||||
const serviceCountText = computed(() => formatCompactNumber(Number(profile.value?.serviceCount || 0)))
|
||||
const goodRateText = computed(() => ratingValue.value > 0 ? `${Math.min(99, Math.round((ratingValue.value / 5) * 100))}%` : '暂无')
|
||||
const works = computed<NailArtistWorkVO[]>(() => profile.value?.works || [])
|
||||
const styleTags = computed(() => profile.value?.styleTags?.filter(Boolean) || [])
|
||||
const firstWorkImage = computed(() => works.value.find(work => work.coverImageUrl)?.coverImageUrl || DEFAULT_PRODUCT_IMAGE)
|
||||
const workTimeText = computed(() => {
|
||||
const start = profile.value?.workStartTime?.slice(0, 5)
|
||||
const end = profile.value?.workEndTime?.slice(0, 5)
|
||||
return start && end ? `${start}-${end}` : '到店确认'
|
||||
})
|
||||
|
||||
const availabilityGroups = computed(() => {
|
||||
const groupMap = new Map<string, NailArtistAvailabilityVO[]>()
|
||||
availability.value
|
||||
.filter(slot => slot.available !== false)
|
||||
.forEach(slot => {
|
||||
const date = slot.dateText || String(slot.startTime || '').slice(0, 10)
|
||||
if (!date) return
|
||||
const slots = groupMap.get(date) || []
|
||||
slots.push(slot)
|
||||
groupMap.set(date, slots)
|
||||
})
|
||||
|
||||
return Array.from(groupMap.entries()).map(([date, slots]) => ({
|
||||
date,
|
||||
label: formatDateLabel(date),
|
||||
week: formatWeekLabel(date),
|
||||
slots
|
||||
}))
|
||||
})
|
||||
|
||||
const selectedDateSlots = computed(() => {
|
||||
return availabilityGroups.value.find(group => group.date === selectedDate.value)?.slots || []
|
||||
})
|
||||
|
||||
const workFilterOptions = computed(() => {
|
||||
const tags = new Set<string>()
|
||||
works.value.forEach(work => work.tags?.filter(Boolean).forEach(tag => tags.add(tag)))
|
||||
return ['全部', ...Array.from(tags).slice(0, 5)]
|
||||
})
|
||||
|
||||
const filteredWorks = computed(() => {
|
||||
if (workFilter.value === '全部') {
|
||||
return works.value
|
||||
}
|
||||
return works.value.filter(work => work.tags?.includes(workFilter.value))
|
||||
})
|
||||
|
||||
const certificationText = computed(() => {
|
||||
const identity = profile.value?.identity || '认证美甲师'
|
||||
const experience = Number(profile.value?.experience || 0)
|
||||
return experience > 0 ? `${identity} · ${experience} 年经验` : identity
|
||||
})
|
||||
|
||||
function formatCompactNumber(value: number) {
|
||||
if (value >= 1000) {
|
||||
return `${(value / 1000).toFixed(1)}k+`
|
||||
}
|
||||
return String(value || 0)
|
||||
}
|
||||
|
||||
function formatDateLabel(dateText: string) {
|
||||
const date = new Date(`${dateText}T00:00:00`)
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return dateText
|
||||
}
|
||||
return `${date.getMonth() + 1}.${date.getDate()}`
|
||||
}
|
||||
|
||||
function formatWeekLabel(dateText: string) {
|
||||
const date = new Date(`${dateText}T00:00:00`)
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return '可约'
|
||||
}
|
||||
const today = new Date()
|
||||
today.setHours(0, 0, 0, 0)
|
||||
const diffDays = Math.round((date.getTime() - today.getTime()) / 86400000)
|
||||
if (diffDays === 0) return '今天'
|
||||
if (diffDays === 1) return '明天'
|
||||
return ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][date.getDay()]
|
||||
}
|
||||
|
||||
const formatDateTime = (value?: string) => {
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
return value.replace('T', ' ').slice(0, 16)
|
||||
}
|
||||
|
||||
const roundedRating = (value?: number | string) => Math.round(Number(value || 0))
|
||||
|
||||
const openProduct = (work: NailArtistWorkVO) => {
|
||||
if (!work.id) {
|
||||
return
|
||||
}
|
||||
router.push(`/product/${work.id}`)
|
||||
}
|
||||
|
||||
const openShop = () => {
|
||||
if (!profile.value?.shopId) {
|
||||
message.info('门店信息暂未完善')
|
||||
return
|
||||
}
|
||||
router.push(`/shop/${profile.value.shopId}`)
|
||||
}
|
||||
|
||||
const handleBookNow = () => {
|
||||
const firstWork = works.value[0]
|
||||
if (firstWork?.id) {
|
||||
openProduct(firstWork)
|
||||
return
|
||||
}
|
||||
openShop()
|
||||
}
|
||||
|
||||
const handleConsult = () => {
|
||||
if (profile.value?.shopId) {
|
||||
router.push(`/shop/${profile.value.shopId}`)
|
||||
return
|
||||
}
|
||||
message.info('请先选择作品后联系门店')
|
||||
}
|
||||
|
||||
const handleShare = async () => {
|
||||
const shareTitle = `${artistName.value}的美甲师主页`
|
||||
const shareUrl = window.location.href
|
||||
try {
|
||||
if (navigator.share) {
|
||||
await navigator.share({ title: shareTitle, url: shareUrl })
|
||||
return
|
||||
}
|
||||
await navigator.clipboard.writeText(shareUrl)
|
||||
message.success('主页链接已复制')
|
||||
} catch {
|
||||
message.info('分享已取消')
|
||||
}
|
||||
}
|
||||
|
||||
const loadProfile = async () => {
|
||||
if (!artistId.value) {
|
||||
loadError.value = '缺少美甲师信息'
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
const [profileData, availabilityData, reviewData] = await Promise.all([
|
||||
nailArtistApi.getPublicProfile(artistId.value),
|
||||
nailArtistApi.getAvailability(artistId.value),
|
||||
nailArtistApi.listReviews(artistId.value)
|
||||
])
|
||||
profile.value = profileData
|
||||
availability.value = availabilityData || profileData.availability || []
|
||||
reviews.value = reviewData || profileData.reviews || []
|
||||
selectedDate.value = availability.value[0]?.dateText || String(availability.value[0]?.startTime || '').slice(0, 10)
|
||||
} catch (error) {
|
||||
loadError.value = error instanceof Error ? error.message : '美甲师个人页加载失败'
|
||||
message.error(loadError.value)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadProfile)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="artist-profile">
|
||||
<header class="artist-topbar">
|
||||
<a-button type="text" class="icon-btn" aria-label="返回" @click="router.back()">
|
||||
<LeftOutlined />
|
||||
</a-button>
|
||||
<h1>美甲师</h1>
|
||||
<a-button type="text" class="icon-btn" aria-label="分享" @click="handleShare">
|
||||
<ShareAltOutlined />
|
||||
</a-button>
|
||||
</header>
|
||||
|
||||
<main class="artist-body">
|
||||
<a-spin :spinning="loading">
|
||||
<a-result v-if="loadError" status="warning" title="暂时无法查看个人页" :sub-title="loadError">
|
||||
<template #extra>
|
||||
<a-button type="primary" @click="loadProfile">重试</a-button>
|
||||
</template>
|
||||
</a-result>
|
||||
|
||||
<template v-else-if="profile">
|
||||
<section class="profile-card">
|
||||
<img class="profile-glow-image" :src="firstWorkImage" alt="" aria-hidden="true" />
|
||||
<div class="avatar-wrap">
|
||||
<a-avatar :size="112" :src="profile.avatar">
|
||||
<UserOutlined />
|
||||
</a-avatar>
|
||||
<span class="top-badge">TOP 1%</span>
|
||||
</div>
|
||||
<h2>{{ artistName }}</h2>
|
||||
<div class="rating-line">
|
||||
<span class="star-row">
|
||||
<StarFilled v-for="star in 5" :key="star" :class="{ active: star <= roundedRating(profile.rating) }" />
|
||||
</span>
|
||||
<strong>{{ ratingText }}</strong>
|
||||
<span>{{ reviews.length }} 条评价</span>
|
||||
</div>
|
||||
<p>{{ profile.signature || profile.identity || '专注细节与稳定出品,让每一次指尖细节都更贴合你的风格。' }}</p>
|
||||
<button type="button" class="shop-link" @click="openShop">
|
||||
<ShopOutlined />
|
||||
<span>{{ profile.shopName || '门店待确认' }}</span>
|
||||
</button>
|
||||
<div class="style-tags">
|
||||
<span v-for="tag in styleTags" :key="tag">{{ tag }}</span>
|
||||
<span v-if="!styleTags.length">风格待补充</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="stats-section">
|
||||
<div class="stat-card">
|
||||
<strong>{{ serviceCountText }}</strong>
|
||||
<span>累计服务</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<strong>{{ goodRateText }}</strong>
|
||||
<span>好评率</span>
|
||||
</div>
|
||||
<div class="cert-card">
|
||||
<SafetyCertificateOutlined />
|
||||
<div>
|
||||
<span>认证资质</span>
|
||||
<strong>{{ certificationText }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="content-section">
|
||||
<div class="section-head">
|
||||
<div>
|
||||
<span>Schedule</span>
|
||||
<h3>可预约时间</h3>
|
||||
</div>
|
||||
<small>{{ workTimeText }}</small>
|
||||
</div>
|
||||
<div v-if="availabilityGroups.length" class="date-strip">
|
||||
<button
|
||||
v-for="group in availabilityGroups"
|
||||
:key="group.date"
|
||||
type="button"
|
||||
:class="['date-card', { active: selectedDate === group.date }]"
|
||||
@click="selectedDate = group.date"
|
||||
>
|
||||
<span>{{ group.week }}</span>
|
||||
<strong>{{ group.label }}</strong>
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="selectedDateSlots.length" class="time-grid">
|
||||
<button v-for="slot in selectedDateSlots" :key="slot.startTime" type="button" class="time-chip">
|
||||
{{ slot.timeText }}
|
||||
</button>
|
||||
</div>
|
||||
<a-empty v-else description="近期暂未放出可预约时间" />
|
||||
</section>
|
||||
|
||||
<section class="content-section">
|
||||
<div class="section-head">
|
||||
<div>
|
||||
<span>Portfolio</span>
|
||||
<h3>作品集</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="workFilterOptions.length > 1" class="filter-row">
|
||||
<button
|
||||
v-for="option in workFilterOptions"
|
||||
:key="option"
|
||||
type="button"
|
||||
:class="['filter-chip', { active: workFilter === option }]"
|
||||
@click="workFilter = option"
|
||||
>
|
||||
{{ option }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="filteredWorks.length" class="work-grid">
|
||||
<button v-for="work in filteredWorks" :key="work.id" type="button" class="work-card" @click="openProduct(work)">
|
||||
<img :src="work.coverImageUrl || DEFAULT_PRODUCT_IMAGE" :alt="work.title || '作品'" loading="lazy" decoding="async" />
|
||||
<span>{{ work.title || '美甲作品' }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<a-empty v-else description="作品正在整理中" />
|
||||
</section>
|
||||
|
||||
<section class="content-section review-section">
|
||||
<div class="section-head">
|
||||
<div>
|
||||
<span>Reviews</span>
|
||||
<h3>用户评价</h3>
|
||||
</div>
|
||||
<small>{{ reviews.length }} 条</small>
|
||||
</div>
|
||||
<div v-if="reviews.length" class="review-list">
|
||||
<article v-for="review in reviews" :key="review.id" class="review-item">
|
||||
<div class="review-top">
|
||||
<a-avatar :size="44" :src="review.customerAvatar">
|
||||
<UserOutlined />
|
||||
</a-avatar>
|
||||
<div class="review-author">
|
||||
<strong>{{ review.customerName || '匿名用户' }}</strong>
|
||||
<span class="star-row">
|
||||
<StarFilled v-for="star in 5" :key="star" :class="{ active: star <= roundedRating(review.rating) }" />
|
||||
</span>
|
||||
</div>
|
||||
<time>{{ formatDateTime(review.submittedAt) }}</time>
|
||||
</div>
|
||||
<p>{{ review.content || '这位用户没有填写文字评价' }}</p>
|
||||
<div v-if="review.imageUrls?.length" class="review-images">
|
||||
<img v-for="url in review.imageUrls" :key="url" :src="url" alt="评价图片" loading="lazy" decoding="async" />
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<a-empty v-else description="还没有公开评价" />
|
||||
</section>
|
||||
</template>
|
||||
</a-spin>
|
||||
</main>
|
||||
|
||||
<footer v-if="profile" class="booking-bar">
|
||||
<button type="button" class="bar-icon-btn" @click="handleConsult">
|
||||
<MessageOutlined />
|
||||
<span>咨询</span>
|
||||
</button>
|
||||
<button type="button" class="bar-icon-btn" @click="message.info('收藏功能即将开放')">
|
||||
<HeartOutlined />
|
||||
<span>收藏</span>
|
||||
</button>
|
||||
<button type="button" class="book-btn" @click="handleBookNow">
|
||||
<CalendarOutlined />
|
||||
<span>立即预约</span>
|
||||
</button>
|
||||
</footer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.artist-profile {
|
||||
min-height: 100vh;
|
||||
background:
|
||||
linear-gradient(180deg, rgba(232, 180, 184, 0.24), rgba(255, 248, 244, 0) 260px),
|
||||
var(--theme-page-bg);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.artist-topbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 30;
|
||||
display: grid;
|
||||
grid-template-columns: 44px minmax(0, 1fr) 44px;
|
||||
align-items: center;
|
||||
height: 62px;
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
padding: 0 14px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 86%, transparent);
|
||||
border-bottom: 1px solid color-mix(in srgb, var(--theme-border) 72%, transparent);
|
||||
backdrop-filter: blur(18px);
|
||||
}
|
||||
|
||||
.artist-topbar h1 {
|
||||
margin: 0;
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.icon-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.artist-body {
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
padding: 22px 14px 116px;
|
||||
}
|
||||
|
||||
.profile-card,
|
||||
.content-section,
|
||||
.stat-card,
|
||||
.cert-card,
|
||||
.review-item {
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent);
|
||||
border: 1px solid color-mix(in srgb, var(--theme-border) 72%, transparent);
|
||||
box-shadow: 0 18px 48px rgba(124, 83, 87, 0.08);
|
||||
backdrop-filter: blur(18px);
|
||||
}
|
||||
|
||||
.profile-card {
|
||||
position: relative;
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
padding: 34px 20px 24px;
|
||||
overflow: hidden;
|
||||
text-align: center;
|
||||
border-radius: 24px;
|
||||
}
|
||||
|
||||
.profile-glow-image {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 170px;
|
||||
object-fit: cover;
|
||||
opacity: 0.18;
|
||||
filter: blur(14px);
|
||||
transform: scale(1.08);
|
||||
}
|
||||
|
||||
.avatar-wrap {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.avatar-wrap :deep(.ant-avatar) {
|
||||
color: var(--theme-primary);
|
||||
background: var(--theme-primary-soft);
|
||||
border: 4px solid #fff;
|
||||
box-shadow: 0 16px 36px rgba(124, 83, 87, 0.18);
|
||||
}
|
||||
|
||||
.top-badge {
|
||||
position: absolute;
|
||||
right: -8px;
|
||||
bottom: 8px;
|
||||
padding: 5px 8px;
|
||||
color: #fff;
|
||||
font-size: 11px;
|
||||
font-weight: 800;
|
||||
background: var(--theme-primary);
|
||||
border: 2px solid #fff;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.profile-card h2 {
|
||||
position: relative;
|
||||
margin: 18px 0 8px;
|
||||
font-size: 26px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.rating-line {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.rating-line strong {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.star-row {
|
||||
display: inline-flex;
|
||||
gap: 2px;
|
||||
color: color-mix(in srgb, var(--theme-border) 70%, #fff);
|
||||
}
|
||||
|
||||
.star-row .active {
|
||||
color: #b88935;
|
||||
}
|
||||
|
||||
.profile-card p {
|
||||
position: relative;
|
||||
max-width: 640px;
|
||||
margin: 14px 0;
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.75;
|
||||
}
|
||||
|
||||
.shop-link {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
max-width: 100%;
|
||||
padding: 8px 12px;
|
||||
color: var(--theme-primary);
|
||||
cursor: pointer;
|
||||
background: var(--theme-primary-soft);
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.shop-link span {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.style-tags {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
justify-content: center;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.style-tags span,
|
||||
.filter-chip {
|
||||
padding: 7px 11px;
|
||||
color: var(--theme-primary);
|
||||
font-size: 12px;
|
||||
background: color-mix(in srgb, var(--theme-primary-soft) 86%, #fff);
|
||||
border: 1px solid color-mix(in srgb, var(--theme-primary) 18%, transparent);
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.stats-section {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
min-height: 96px;
|
||||
padding: 18px;
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.stat-card strong {
|
||||
color: var(--theme-primary);
|
||||
font-size: 24px;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
.stat-card span,
|
||||
.cert-card span {
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.cert-card {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
padding: 16px;
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.cert-card svg {
|
||||
color: #b88935;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.cert-card div {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.cert-card strong {
|
||||
overflow: hidden;
|
||||
font-size: 15px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.content-section {
|
||||
margin-top: 22px;
|
||||
padding: 18px;
|
||||
border-radius: 22px;
|
||||
}
|
||||
|
||||
.section-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.section-head span {
|
||||
color: var(--theme-primary);
|
||||
font-size: 12px;
|
||||
font-weight: 800;
|
||||
letter-spacing: 0.05em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.section-head h3 {
|
||||
margin: 4px 0 0;
|
||||
font-size: 19px;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.section-head small {
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.date-strip {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
overflow-x: auto;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
|
||||
.date-card {
|
||||
display: grid;
|
||||
flex: 0 0 80px;
|
||||
gap: 8px;
|
||||
place-items: center;
|
||||
min-height: 92px;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 72%, var(--theme-primary-soft));
|
||||
border: 1px solid color-mix(in srgb, var(--theme-border) 72%, transparent);
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.date-card strong {
|
||||
color: var(--text-primary);
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.date-card.active {
|
||||
color: #fff;
|
||||
background: var(--theme-primary);
|
||||
border-color: var(--theme-primary);
|
||||
}
|
||||
|
||||
.date-card.active strong {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.time-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.time-chip {
|
||||
min-height: 44px;
|
||||
color: var(--theme-primary);
|
||||
font-weight: 700;
|
||||
cursor: default;
|
||||
background: var(--theme-primary-soft);
|
||||
border: 1px solid color-mix(in srgb, var(--theme-primary) 18%, transparent);
|
||||
border-radius: 14px;
|
||||
}
|
||||
|
||||
.filter-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
overflow-x: auto;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.filter-chip {
|
||||
flex: 0 0 auto;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.filter-chip.active {
|
||||
color: #fff;
|
||||
background: var(--theme-primary);
|
||||
}
|
||||
|
||||
.work-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.work-card {
|
||||
position: relative;
|
||||
min-height: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
background: var(--theme-primary-soft);
|
||||
border: 0;
|
||||
border-radius: 22px;
|
||||
aspect-ratio: 3 / 4;
|
||||
}
|
||||
|
||||
.work-card img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.work-card::after {
|
||||
position: absolute;
|
||||
inset: auto 0 0;
|
||||
height: 46%;
|
||||
content: "";
|
||||
background: linear-gradient(180deg, transparent, rgba(31, 27, 23, 0.62));
|
||||
}
|
||||
|
||||
.work-card span {
|
||||
position: absolute;
|
||||
right: 12px;
|
||||
bottom: 12px;
|
||||
left: 12px;
|
||||
z-index: 1;
|
||||
overflow: hidden;
|
||||
color: #fff;
|
||||
font-weight: 700;
|
||||
text-align: left;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.review-list {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.review-item {
|
||||
padding: 14px;
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.review-top {
|
||||
display: grid;
|
||||
grid-template-columns: 44px minmax(0, 1fr) auto;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.review-author {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.review-author strong {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.review-top time {
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.review-item p {
|
||||
margin: 12px 0 0;
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.7;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.review-images {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.review-images img {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
object-fit: cover;
|
||||
border-radius: 14px;
|
||||
}
|
||||
|
||||
.booking-bar {
|
||||
position: fixed;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 40;
|
||||
display: grid;
|
||||
grid-template-columns: 64px 64px minmax(0, 1fr);
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
padding: 12px 14px max(12px, env(safe-area-inset-bottom));
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent);
|
||||
border-top: 1px solid var(--theme-border);
|
||||
box-shadow: 0 -16px 40px rgba(124, 83, 87, 0.1);
|
||||
backdrop-filter: blur(18px);
|
||||
}
|
||||
|
||||
.bar-icon-btn,
|
||||
.book-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 48px;
|
||||
cursor: pointer;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.bar-icon-btn {
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
color: var(--theme-primary);
|
||||
font-size: 11px;
|
||||
background: var(--theme-primary-soft);
|
||||
}
|
||||
|
||||
.book-btn {
|
||||
gap: 8px;
|
||||
color: #fff;
|
||||
font-size: 15px;
|
||||
font-weight: 800;
|
||||
background: var(--theme-primary);
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.artist-body {
|
||||
padding: 18px 12px 112px;
|
||||
}
|
||||
|
||||
.profile-card {
|
||||
padding: 30px 16px 22px;
|
||||
}
|
||||
|
||||
.profile-card h2 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.content-section {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.time-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,446 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<header class="header">
|
||||
<a-button type="text" class="back-btn" @click="router.back()">
|
||||
<LeftOutlined />
|
||||
</a-button>
|
||||
<h1>我的优惠券</h1>
|
||||
<div class="placeholder"></div>
|
||||
</header>
|
||||
|
||||
<div class="coupon-section">
|
||||
<a-card :bordered="false" class="filter-card">
|
||||
<a-segmented
|
||||
v-model:value="activeFilter"
|
||||
:options="filterOptions"
|
||||
class="filter-segmented"
|
||||
/>
|
||||
</a-card>
|
||||
|
||||
<a-card v-if="loading" :bordered="false" class="content-card">
|
||||
<a-skeleton :paragraph="{ rows: 3 }" />
|
||||
</a-card>
|
||||
|
||||
<a-card v-else-if="coupons.length === 0" :bordered="false" class="content-card">
|
||||
<a-empty description="暂无优惠券">
|
||||
<a-button type="primary">去领取</a-button>
|
||||
</a-empty>
|
||||
</a-card>
|
||||
|
||||
<div v-else class="coupon-list">
|
||||
<a-card
|
||||
v-for="coupon in filteredCoupons"
|
||||
:key="coupon.id"
|
||||
class="coupon-card"
|
||||
:class="{ 'expired': coupon.status === 3 }"
|
||||
>
|
||||
<div class="coupon-content">
|
||||
<div class="coupon-value">
|
||||
{{ coupon.couponType === 1 ? `${coupon.discountValue}折` : `¥${coupon.reduceAmount}` }}
|
||||
</div>
|
||||
<div class="coupon-info">
|
||||
<div class="coupon-name">{{ coupon.couponName }}</div>
|
||||
<div class="coupon-condition" v-if="coupon.couponType === 2">
|
||||
满{{ coupon.minAmount }}元可用
|
||||
</div>
|
||||
<div class="coupon-time">
|
||||
{{ formatDate(coupon.startTime) }} 至 {{ formatDate(coupon.endTime) }}
|
||||
</div>
|
||||
<div :class="['coupon-status', getStatusClass(coupon.status)]">
|
||||
{{ coupon.statusName }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* CouponView 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, computed, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { couponApi } from '@/api/coupon'
|
||||
|
||||
/**
|
||||
* Purpose: router supports CouponView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const router = useRouter()
|
||||
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/**
|
||||
* Purpose: coupons supports CouponView.vue by holding or executing the coupons page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const coupons = ref<any[]>([])
|
||||
/** activeFilter is a reactive state variable used by the template and event handlers. */
|
||||
const activeFilter = ref('all')
|
||||
|
||||
/**
|
||||
* Purpose: filterOptions supports CouponView.vue by holding or executing the filter options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const filterOptions = [
|
||||
{ label: '全部', value: 'all' },
|
||||
{ label: '未使用', value: 'available' },
|
||||
{ label: '已使用', value: 'used' },
|
||||
{ label: '已过期', value: 'expired' }
|
||||
]
|
||||
|
||||
/** filteredCoupons is a reactive state variable used by the template and event handlers. */
|
||||
const filteredCoupons = computed(() => {
|
||||
if (activeFilter.value === 'all') {
|
||||
return coupons.value
|
||||
} else if (activeFilter.value === 'available') {
|
||||
return coupons.value.filter(coupon => coupon.status === 1)
|
||||
} else if (activeFilter.value === 'used') {
|
||||
return coupons.value.filter(coupon => coupon.status === 2)
|
||||
} else if (activeFilter.value === 'expired') {
|
||||
return coupons.value.filter(coupon => coupon.status === 3)
|
||||
}
|
||||
return coupons.value
|
||||
})
|
||||
|
||||
/** loadCoupons is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadCoupons = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const response = await couponApi.listUserCoupons() as any
|
||||
coupons.value = response || []
|
||||
} catch (error) {
|
||||
console.error('获取优惠券列表失败:', error)
|
||||
message.error('获取优惠券列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** getStatusClass is a local helper used by this page script. */
|
||||
const getStatusClass = (status: number) => {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return 'available'
|
||||
case 2:
|
||||
return 'used'
|
||||
case 3:
|
||||
return 'expired'
|
||||
default:
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
/** formatDate is a local helper used by this page script. */
|
||||
const formatDate = (dateString: string) => {
|
||||
if (!dateString) return ''
|
||||
const date = new Date(dateString)
|
||||
return date.toLocaleDateString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit'
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadCoupons()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
padding-top: 60px;
|
||||
min-height: 100vh;
|
||||
background:
|
||||
linear-gradient(rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.92)),
|
||||
var(--theme-background-image),
|
||||
var(--theme-page-bg);
|
||||
background-size: cover, cover, auto;
|
||||
background-position: center top;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
height: 60px;
|
||||
padding: 10px 15px;
|
||||
background: rgba(255, 255, 255, 0.92);
|
||||
border-bottom: 1px solid var(--theme-border);
|
||||
backdrop-filter: blur(14px);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.coupon-section {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.filter-card {
|
||||
border-radius: 14px;
|
||||
margin-bottom: 15px;
|
||||
background: var(--theme-card-bg);
|
||||
border: 1px solid var(--theme-border);
|
||||
box-shadow: 0 14px 34px rgba(122, 67, 88, 0.08);
|
||||
}
|
||||
|
||||
.filter-segmented {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.content-card {
|
||||
border-radius: 14px;
|
||||
background: var(--theme-card-bg);
|
||||
border: 1px solid var(--theme-border);
|
||||
box-shadow: 0 14px 34px rgba(122, 67, 88, 0.08);
|
||||
padding: 40px 20px;
|
||||
}
|
||||
|
||||
.coupon-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.coupon-card {
|
||||
border-radius: 14px;
|
||||
overflow: hidden;
|
||||
background: var(--theme-gradient-soft);
|
||||
border: 1px solid var(--theme-border);
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 14px 34px rgba(122, 67, 88, 0.08);
|
||||
}
|
||||
|
||||
.coupon-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 18px 44px rgba(122, 67, 88, 0.12);
|
||||
}
|
||||
|
||||
.coupon-card.expired {
|
||||
opacity: 0.66;
|
||||
background: var(--theme-card-bg);
|
||||
}
|
||||
|
||||
.coupon-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.coupon-value {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: var(--theme-primary);
|
||||
padding: 20px;
|
||||
background: var(--theme-primary-soft);
|
||||
border-radius: 8px;
|
||||
min-width: 100px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.coupon-card.expired .coupon-value {
|
||||
color: var(--text-secondary);
|
||||
background: var(--theme-primary-soft);
|
||||
}
|
||||
|
||||
.coupon-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.coupon-name {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.coupon-condition {
|
||||
font-size: 12px;
|
||||
color: var(--theme-primary);
|
||||
}
|
||||
|
||||
.coupon-time {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.coupon-status {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
padding: 2px 8px;
|
||||
border-radius: 8px;
|
||||
align-self: flex-start;
|
||||
}
|
||||
|
||||
.coupon-status.available {
|
||||
background: var(--theme-primary-soft);
|
||||
color: var(--theme-primary);
|
||||
}
|
||||
|
||||
.coupon-status.used {
|
||||
background: var(--theme-primary-soft);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.coupon-status.expired {
|
||||
background: var(--theme-primary-soft);
|
||||
color: var(--theme-accent);
|
||||
}
|
||||
|
||||
:deep(.ant-segmented) {
|
||||
background: var(--theme-primary-soft);
|
||||
}
|
||||
|
||||
:deep(.ant-segmented-item-selected) {
|
||||
background: var(--theme-primary);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
:deep(.ant-btn-primary) {
|
||||
background: var(--theme-primary);
|
||||
border-color: var(--theme-primary);
|
||||
}
|
||||
|
||||
.mobile-container {
|
||||
padding-top: 68px;
|
||||
background:
|
||||
radial-gradient(circle at 84% 0%, color-mix(in srgb, var(--theme-primary) 26%, transparent), transparent 32%),
|
||||
linear-gradient(180deg, color-mix(in srgb, var(--theme-card-bg) 78%, transparent), var(--theme-page-bg));
|
||||
}
|
||||
|
||||
.header {
|
||||
height: 64px;
|
||||
padding: 12px 18px 10px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 17px;
|
||||
font-weight: 820;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 74%, transparent);
|
||||
}
|
||||
|
||||
.coupon-section {
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
.filter-card,
|
||||
.content-card {
|
||||
border-radius: 22px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 90%, transparent);
|
||||
box-shadow: 0 18px 40px color-mix(in srgb, var(--theme-neutral) 8%, transparent);
|
||||
}
|
||||
|
||||
.coupon-list {
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.coupon-card {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
border-radius: 24px;
|
||||
background:
|
||||
linear-gradient(135deg, color-mix(in srgb, var(--theme-card-bg) 88%, transparent), color-mix(in srgb, var(--theme-primary) 20%, var(--theme-card-bg)));
|
||||
box-shadow: 0 20px 42px color-mix(in srgb, var(--theme-neutral) 9%, transparent);
|
||||
}
|
||||
|
||||
.coupon-card::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 112px;
|
||||
width: 1px;
|
||||
background: linear-gradient(var(--theme-border) 52%, transparent 0);
|
||||
background-size: 1px 12px;
|
||||
}
|
||||
|
||||
.coupon-content {
|
||||
gap: 18px;
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
.coupon-value {
|
||||
min-width: 78px;
|
||||
padding: 16px 8px;
|
||||
border-radius: 18px;
|
||||
color: var(--theme-primary-action);
|
||||
background: color-mix(in srgb, var(--theme-primary) 24%, var(--theme-card-bg));
|
||||
font-family: Georgia, 'Times New Roman', serif;
|
||||
}
|
||||
|
||||
.coupon-name {
|
||||
font-weight: 820;
|
||||
}
|
||||
|
||||
.coupon-condition,
|
||||
.coupon-status.available {
|
||||
color: var(--theme-primary-action);
|
||||
}
|
||||
|
||||
:deep(.ant-segmented) {
|
||||
width: 100%;
|
||||
padding: 4px;
|
||||
border-radius: 16px;
|
||||
background: color-mix(in srgb, var(--theme-primary) 16%, var(--theme-card-bg));
|
||||
}
|
||||
|
||||
:deep(.ant-segmented-item) {
|
||||
border-radius: 13px;
|
||||
}
|
||||
|
||||
:deep(.ant-segmented-item-selected) {
|
||||
background: var(--theme-card-bg);
|
||||
color: var(--theme-primary-action);
|
||||
box-shadow: 0 10px 20px color-mix(in srgb, var(--theme-neutral) 8%, transparent);
|
||||
}
|
||||
|
||||
:deep(.ant-btn-primary) {
|
||||
border-color: transparent;
|
||||
background: linear-gradient(135deg, var(--theme-primary-action), var(--theme-secondary));
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.coupon-section {
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
padding: 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,95 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { userApi, type ContactInfoVO } from '@/api/user'
|
||||
|
||||
const router = useRouter()
|
||||
const loading = ref(false)
|
||||
const contact = ref<ContactInfoVO | null>(null)
|
||||
|
||||
const loadContact = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
contact.value = await userApi.getPlatformContact()
|
||||
} catch (error: any) {
|
||||
contact.value = null
|
||||
message.warning(error?.message || '暂时无法加载客服信息')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadContact)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="help-page">
|
||||
<header class="header">
|
||||
<a-button type="text" @click="router.back()">
|
||||
<LeftOutlined />
|
||||
</a-button>
|
||||
<h1>帮助与客服</h1>
|
||||
<a-button type="link" @click="loadContact">刷新</a-button>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<section class="hero-card">
|
||||
<span>指尖设计师客服</span>
|
||||
<h2>帮助与客服</h2>
|
||||
<p>订单、预约、售后和账号问题都可以从这里继续处理。</p>
|
||||
</section>
|
||||
|
||||
<a-spin :spinning="loading">
|
||||
<section class="section-card">
|
||||
<h3>平台联系信息</h3>
|
||||
<p v-if="contact?.contactName">{{ contact.contactName }} {{ contact.roleLabel || '' }}</p>
|
||||
<p v-if="contact?.phoneAvailable && contact.phone">电话:{{ contact.phone }}</p>
|
||||
<p v-if="contact?.wechatAvailable && contact.wechatId">微信:{{ contact.wechatId }}</p>
|
||||
<p v-if="contact?.platformContactText">{{ contact.platformContactText }}</p>
|
||||
<p v-if="!contact">暂无可展示的客服信息,请稍后重试或通过订单详情联系服务人员。</p>
|
||||
</section>
|
||||
|
||||
<section class="quick-grid">
|
||||
<button type="button" @click="router.push('/orders')">
|
||||
<strong>订单中心</strong>
|
||||
<span>查看预约、支付、评价</span>
|
||||
</button>
|
||||
<button type="button" @click="router.push('/after-sales')">
|
||||
<strong>售后记录</strong>
|
||||
<span>查看退款和处理进度</span>
|
||||
</button>
|
||||
<button type="button" @click="router.push('/notifications')">
|
||||
<strong>消息中心</strong>
|
||||
<span>查看系统通知</span>
|
||||
</button>
|
||||
<button type="button" @click="router.push('/settings')">
|
||||
<strong>账号设置</strong>
|
||||
<span>修改资料、手机号和密码</span>
|
||||
</button>
|
||||
</section>
|
||||
</a-spin>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.help-page { min-height: 100vh; padding-top: 66px; background: linear-gradient(180deg, color-mix(in srgb, var(--theme-card-bg) 76%, transparent), var(--theme-page-bg)); color: var(--text-primary); }
|
||||
.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; height: 64px; padding: 11px 18px; background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent); border-bottom: 1px solid var(--theme-border); backdrop-filter: blur(14px); }
|
||||
.header h1 { margin: 0; font-size: 17px; font-weight: 820; }
|
||||
.content { padding: 18px 18px 34px; }
|
||||
.hero-card, .section-card, .quick-grid button { border: 1px solid var(--theme-border); border-radius: 24px; background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent); box-shadow: 0 18px 44px color-mix(in srgb, var(--theme-neutral) 8%, transparent); }
|
||||
.hero-card { padding: 24px; margin-bottom: 14px; background: linear-gradient(135deg, color-mix(in srgb, var(--theme-primary) 24%, var(--theme-card-bg)), color-mix(in srgb, var(--theme-secondary) 18%, var(--theme-card-bg))); }
|
||||
.hero-card span { color: var(--theme-primary-action); font-family: Georgia, 'Times New Roman', serif; font-size: 12px; font-weight: 800; }
|
||||
.hero-card h2 { margin: 10px 0 6px; font-size: 21px; font-weight: 850; }
|
||||
.hero-card p, .section-card p, .quick-grid span { margin: 0; color: var(--text-secondary); line-height: 1.6; }
|
||||
.section-card { padding: 16px; }
|
||||
.section-card h3 { margin: 0 0 12px; font-size: 17px; }
|
||||
.section-card p + p { margin-top: 8px; }
|
||||
.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
|
||||
.quick-grid button { display: grid; gap: 6px; min-height: 112px; padding: 16px; border-color: var(--theme-border); text-align: left; color: var(--text-primary); cursor: pointer; }
|
||||
.quick-grid strong { font-size: 16px; }
|
||||
.quick-grid span { font-size: 13px; }
|
||||
:deep(.ant-btn-link) { color: var(--theme-primary-action); }
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,223 @@
|
||||
<template>
|
||||
<div class="not-found-container">
|
||||
<header class="not-found-topbar">
|
||||
<button class="not-found-back" type="button" aria-label="返回" @click="handleBackClick">
|
||||
<LeftOutlined />
|
||||
</button>
|
||||
<strong>指尖设计师</strong>
|
||||
<span class="not-found-topbar-spacer" aria-hidden="true"></span>
|
||||
</header>
|
||||
|
||||
<div class="not-found-content">
|
||||
<span class="not-found-kicker">指尖设计师</span>
|
||||
<div class="error-code">404</div>
|
||||
<h1>这页去做护理了</h1>
|
||||
<p>您访问的页面不存在或已被删除,我们带您回到首页继续浏览作品。</p>
|
||||
<p class="redirect-message">
|
||||
将在 <span class="countdown">{{ countdown }}</span> 秒后自动跳转到首页...
|
||||
</p>
|
||||
<a-button type="primary" @click="redirectToHome">立即前往首页</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* NotFoundView 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, onMounted, onUnmounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
|
||||
/**
|
||||
* Purpose: router supports NotFoundView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const router = useRouter()
|
||||
/** countdown is a reactive state variable used by the template and event handlers. */
|
||||
const countdown = ref(5)
|
||||
let timer: number | null = null
|
||||
|
||||
const clearRedirectTimer = () => {
|
||||
if (timer) {
|
||||
clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
}
|
||||
|
||||
const handleBackClick = () => {
|
||||
clearRedirectTimer()
|
||||
if (window.history.length > 1) {
|
||||
router.back()
|
||||
return
|
||||
}
|
||||
router.push('/home')
|
||||
}
|
||||
|
||||
/** redirectToHome is a local helper used by this page script. */
|
||||
const redirectToHome = () => {
|
||||
clearRedirectTimer()
|
||||
router.push('/home')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
timer = window.setInterval(() => {
|
||||
if (countdown.value > 0) {
|
||||
countdown.value--
|
||||
} else {
|
||||
if (timer) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
redirectToHome()
|
||||
}
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
clearRedirectTimer()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.not-found-container {
|
||||
position: relative;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background:
|
||||
radial-gradient(circle at 82% 12%, color-mix(in srgb, var(--theme-primary) 30%, transparent), transparent 34%),
|
||||
linear-gradient(180deg, var(--theme-tertiary), color-mix(in srgb, var(--theme-secondary) 14%, var(--theme-tertiary)));
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.not-found-topbar {
|
||||
position: fixed;
|
||||
top: 12px;
|
||||
left: 50%;
|
||||
z-index: 20;
|
||||
display: grid;
|
||||
grid-template-columns: 40px minmax(0, 1fr) 40px;
|
||||
align-items: center;
|
||||
width: min(calc(100% - 32px), var(--app-mobile-max-width, 480px));
|
||||
height: 44px;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.not-found-back {
|
||||
display: inline-grid;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
place-items: center;
|
||||
border: 1px solid color-mix(in srgb, var(--theme-border) 78%, transparent);
|
||||
border-radius: 999px;
|
||||
color: var(--theme-primary-action);
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent);
|
||||
box-shadow: 0 10px 24px color-mix(in srgb, var(--theme-neutral) 8%, transparent);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.not-found-topbar strong {
|
||||
overflow: hidden;
|
||||
color: var(--text-primary);
|
||||
font-size: 16px;
|
||||
font-weight: 800;
|
||||
text-align: center;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.not-found-topbar-spacer {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
}
|
||||
|
||||
.not-found-content {
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent);
|
||||
border: 1px solid var(--theme-border);
|
||||
border-radius: 28px;
|
||||
padding: 48px 28px;
|
||||
text-align: center;
|
||||
box-shadow: 0 24px 54px color-mix(in srgb, var(--theme-neutral) 12%, transparent);
|
||||
max-width: 500px;
|
||||
width: 100%;
|
||||
backdrop-filter: blur(16px);
|
||||
}
|
||||
|
||||
.not-found-kicker {
|
||||
color: var(--theme-secondary);
|
||||
font-family: Georgia, 'Times New Roman', serif;
|
||||
font-size: 13px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.error-code {
|
||||
font-size: 104px;
|
||||
font-weight: 900;
|
||||
color: var(--theme-primary-action);
|
||||
margin: 10px 0 14px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.not-found-content h1 {
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
color: var(--text-primary);
|
||||
margin: 0 0 16px 0;
|
||||
}
|
||||
|
||||
.not-found-content p {
|
||||
font-size: 16px;
|
||||
color: var(--text-secondary);
|
||||
margin: 0 0 24px 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.redirect-message {
|
||||
margin: 20px 0 30px 0;
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.countdown {
|
||||
color: var(--theme-primary-action);
|
||||
font-weight: bold;
|
||||
font-size: 18px;
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
:deep(.ant-btn-primary) {
|
||||
background: linear-gradient(135deg, var(--theme-primary-action), var(--theme-secondary));
|
||||
border: none;
|
||||
padding: 12px 32px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
border-radius: 25px;
|
||||
box-shadow: var(--theme-button-shadow);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
:deep(.ant-btn-primary:hover) {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: var(--theme-button-shadow);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.not-found-content {
|
||||
padding: 40px 20px;
|
||||
}
|
||||
|
||||
.error-code {
|
||||
font-size: 80px;
|
||||
}
|
||||
|
||||
.not-found-content h1 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.not-found-content p {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,331 @@
|
||||
<template>
|
||||
<div class="notifications-page">
|
||||
<header class="page-header">
|
||||
<button class="back-btn" type="button" @click="router.back()">‹</button>
|
||||
<div>
|
||||
<h1>消息通知</h1>
|
||||
<p>{{ unreadCount }} 条未读消息</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="message-list">
|
||||
<button
|
||||
v-for="item in messages"
|
||||
:key="item.id"
|
||||
class="message-item"
|
||||
:class="{ unread: item.readStatus !== 1 }"
|
||||
type="button"
|
||||
@click="openMessage(item)"
|
||||
>
|
||||
<span class="dot"></span>
|
||||
<span class="message-main">
|
||||
<strong>{{ item.title }}</strong>
|
||||
<small>{{ item.publisherName || '系统消息' }} · {{ item.publishTime || item.createTime }}</small>
|
||||
<em v-if="item.imageUrl">含图片</em>
|
||||
</span>
|
||||
</button>
|
||||
<a-empty v-if="!loading && messages.length === 0" description="暂无消息" />
|
||||
</main>
|
||||
|
||||
<a-modal v-model:open="detailVisible" title="消息详情" @ok="detailVisible = false">
|
||||
<h3>{{ currentMessage?.title }}</h3>
|
||||
<p class="message-meta">{{ currentMessage?.publisherName || '系统消息' }} · {{ currentMessage?.publishTime }}</p>
|
||||
<div v-if="currentMessageContentHtml" class="message-content" v-html="currentMessageContentHtml"></div>
|
||||
<img v-if="currentMessage?.imageUrl" class="message-image" :src="currentMessage.imageUrl" alt="消息图片" />
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* NotificationsView 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 } from 'ant-design-vue'
|
||||
/**
|
||||
* Purpose: SystemMessageVO supports NotificationsView.vue by holding or executing the system message vo page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { userApi, type SystemMessageVO } from '@/api/user'
|
||||
import { buildSystemMessageActionPath } from '@/utils/system-message-action'
|
||||
import { renderRichContent } from '@/utils/rich-content'
|
||||
|
||||
/**
|
||||
* Purpose: router supports NotificationsView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const router = useRouter()
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/**
|
||||
* Purpose: messages supports NotificationsView.vue by holding or executing the messages page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const messages = ref<SystemMessageVO[]>([])
|
||||
/** detailVisible is a reactive state variable used by the template and event handlers. */
|
||||
const detailVisible = ref(false)
|
||||
/**
|
||||
* Purpose: currentMessage supports NotificationsView.vue by holding or executing the current message page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const currentMessage = ref<SystemMessageVO | null>(null)
|
||||
/** unreadCount is a reactive state variable used by the template and event handlers. */
|
||||
const unreadCount = computed(() => messages.value.filter(item => item.readStatus !== 1).length)
|
||||
const currentMessageContentHtml = computed(() => renderRichContent(currentMessage.value?.content || ''))
|
||||
|
||||
/**
|
||||
* Purpose: resolveSystemMessageActionPath supports NotificationsView.vue by holding or executing the resolve system message action path page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const resolveSystemMessageActionPath = (item: SystemMessageVO) => buildSystemMessageActionPath(item)
|
||||
|
||||
/**
|
||||
* Purpose: markMessageReadIfNeeded supports NotificationsView.vue by holding or executing the mark message read if needed page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const markMessageReadIfNeeded = async (item: SystemMessageVO) => {
|
||||
if (item.readStatus === 1) {
|
||||
return
|
||||
}
|
||||
await userApi.markMessageRead(item.id)
|
||||
item.readStatus = 1
|
||||
}
|
||||
|
||||
/** loadMessages is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadMessages = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
messages.value = await userApi.listMyMessages()
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '消息加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** openMessage is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const openMessage = async (item: SystemMessageVO) => {
|
||||
try {
|
||||
await markMessageReadIfNeeded(item)
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '标记已读失败')
|
||||
return
|
||||
}
|
||||
|
||||
const actionPath = resolveSystemMessageActionPath(item)
|
||||
if (actionPath) {
|
||||
await router.push(actionPath)
|
||||
return
|
||||
}
|
||||
|
||||
currentMessage.value = item
|
||||
detailVisible.value = true
|
||||
}
|
||||
|
||||
onMounted(loadMessages)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.notifications-page {
|
||||
min-height: 100vh;
|
||||
background: var(--theme-page-bg);
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
align-items: center;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.page-header h1 {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.page-header p {
|
||||
margin: 4px 0 0;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 0;
|
||||
border-radius: 20px;
|
||||
background: var(--theme-card-bg);
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.message-list {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.message-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
width: 100%;
|
||||
padding: 16px;
|
||||
border: 0;
|
||||
border-radius: 8px;
|
||||
background: var(--theme-card-bg);
|
||||
border: 1px solid var(--theme-border);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.message-item .dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--theme-border);
|
||||
}
|
||||
|
||||
.message-item.unread .dot {
|
||||
background: var(--theme-primary);
|
||||
}
|
||||
|
||||
.message-main {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.message-main em {
|
||||
width: fit-content;
|
||||
padding: 2px 8px;
|
||||
border-radius: 999px;
|
||||
background: var(--theme-primary-soft);
|
||||
color: var(--theme-primary);
|
||||
font-size: 12px;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.message-main small,
|
||||
.message-meta {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.message-content {
|
||||
line-height: 1.8;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
.message-content :deep(*) {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.message-content :deep(p),
|
||||
.message-content :deep(ul),
|
||||
.message-content :deep(ol),
|
||||
.message-content :deep(blockquote),
|
||||
.message-content :deep(pre),
|
||||
.message-content :deep(table) {
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
|
||||
.message-content :deep(p:last-child),
|
||||
.message-content :deep(ul:last-child),
|
||||
.message-content :deep(ol:last-child),
|
||||
.message-content :deep(blockquote:last-child),
|
||||
.message-content :deep(pre:last-child),
|
||||
.message-content :deep(table:last-child) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.message-content :deep(ul),
|
||||
.message-content :deep(ol) {
|
||||
padding-left: 1.25em;
|
||||
}
|
||||
|
||||
.message-content :deep(a) {
|
||||
color: var(--theme-primary);
|
||||
}
|
||||
|
||||
.message-content :deep(img) {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.message-content :deep(pre) {
|
||||
overflow-x: auto;
|
||||
padding: 10px 12px;
|
||||
border-radius: 8px;
|
||||
background: var(--theme-primary-soft);
|
||||
}
|
||||
|
||||
.message-image {
|
||||
display: block;
|
||||
width: 100%;
|
||||
max-height: 420px;
|
||||
margin-top: 14px;
|
||||
object-fit: contain;
|
||||
border-radius: 8px;
|
||||
background: var(--theme-primary-soft);
|
||||
}
|
||||
|
||||
.notifications-page {
|
||||
padding: 18px 18px 34px;
|
||||
background:
|
||||
radial-gradient(circle at 84% 0%, color-mix(in srgb, var(--theme-primary) 28%, transparent), transparent 30%),
|
||||
linear-gradient(180deg, color-mix(in srgb, var(--theme-card-bg) 74%, transparent), var(--theme-page-bg));
|
||||
}
|
||||
|
||||
.page-header {
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.page-header h1 {
|
||||
font-size: 21px;
|
||||
font-weight: 860;
|
||||
}
|
||||
|
||||
.page-header p {
|
||||
color: var(--theme-secondary);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
color: var(--theme-primary-action);
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 82%, transparent);
|
||||
box-shadow: 0 12px 24px color-mix(in srgb, var(--theme-neutral) 8%, transparent);
|
||||
}
|
||||
|
||||
.message-list {
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.message-item {
|
||||
align-items: flex-start;
|
||||
padding: 17px;
|
||||
border-radius: 22px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 90%, transparent);
|
||||
box-shadow: 0 18px 38px color-mix(in srgb, var(--theme-neutral) 7%, transparent);
|
||||
}
|
||||
|
||||
.message-item.unread {
|
||||
border-color: color-mix(in srgb, var(--theme-primary) 36%, var(--theme-border));
|
||||
}
|
||||
|
||||
.message-item.unread .dot {
|
||||
background: var(--theme-primary-action);
|
||||
}
|
||||
|
||||
.message-main strong {
|
||||
color: var(--text-primary);
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.message-main em {
|
||||
color: var(--theme-primary-action);
|
||||
background: color-mix(in srgb, var(--theme-primary) 18%, var(--theme-card-bg));
|
||||
}
|
||||
|
||||
.message-content :deep(a) {
|
||||
color: var(--theme-primary-action);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,429 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { afterSaleApi, orderApi, paymentApi } from '../api/order'
|
||||
import type { AfterSaleVO, OrderArtistChangeRequestVO, OrderArtistReviewVO } from '../api/order'
|
||||
import { userApi, type ContactInfoVO } from '@/api/user'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { extractLegacyFileId, getCachedSignedImageUrl, getCachedSignedImageUrlSync } from '@/utils/signed-image-cache'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const loading = ref(false)
|
||||
const order = ref<any | null>(null)
|
||||
const reviews = ref<OrderArtistReviewVO[]>([])
|
||||
const changeRequests = ref<OrderArtistChangeRequestVO[]>([])
|
||||
const afterSales = ref<AfterSaleVO[]>([])
|
||||
const contact = ref<ContactInfoVO | null>(null)
|
||||
const quoteReply = ref('')
|
||||
const quoteSubmitting = ref(false)
|
||||
const quoteConfirming = ref(false)
|
||||
|
||||
const orderId = computed(() => String(route.params.id || route.query.orderId || ''))
|
||||
const items = computed(() => Array.isArray(order.value?.items) ? order.value.items : [])
|
||||
|
||||
const formatMoney = (value?: number | string) => {
|
||||
const amount = Number(value)
|
||||
return Number.isFinite(amount) ? `¥${amount.toFixed(2)}` : '¥0.00'
|
||||
}
|
||||
|
||||
const formatDateTime = (value?: string) => value ? String(value).replace('T', ' ').slice(0, 16) : '--'
|
||||
const isQuoteStatus = (status?: unknown) => Number(status) === 0
|
||||
const isQuoteConfirming = computed(() => isQuoteStatus(order.value?.status))
|
||||
const statusClass = (status?: number) => isQuoteStatus(status) ? 'quote' : status === 2 ? 'done' : status === 3 ? 'cancelled' : 'pending'
|
||||
const isOrderPaid = (target: any) => String(target?.paymentStatus || '').toUpperCase() === 'PAID'
|
||||
const canPreparePayment = computed(() => !isQuoteConfirming.value && Number(order.value?.status) === 1 && !isOrderPaid(order.value))
|
||||
const canMockPay = computed(() => !isQuoteConfirming.value && Number(order.value?.status) === 1 && String(order.value?.paymentStatus || '').toUpperCase() === 'PAYING')
|
||||
const canApplyAfterSale = computed(() => !isQuoteConfirming.value && (Number(order.value?.status) === 2 || isOrderPaid(order.value)))
|
||||
|
||||
const timeline = computed(() => {
|
||||
const current = order.value || {}
|
||||
const firstAppointment = items.value.map((item: any) => item.appointmentTime).find(Boolean)
|
||||
const status = Number(current.status)
|
||||
if (status === 0) {
|
||||
return [
|
||||
{ key: 'created', title: '已创建', text: formatDateTime(current.createTime), done: true, active: false },
|
||||
{ key: 'quote', title: '确认价格', text: current.quoteStatusText || '等待双方确认', done: Boolean(current.quoteUserConfirmed && current.quoteShopConfirmed), active: true },
|
||||
{ key: 'appointment', title: '预约时间', text: firstAppointment ? formatDateTime(firstAppointment) : '价格确认后安排', done: Boolean(firstAppointment), active: false },
|
||||
{ key: 'service', title: '服务完成', text: '待服务', done: false, active: false },
|
||||
{ key: 'review', title: '评价', text: '完成后可评价', done: false, active: false }
|
||||
]
|
||||
}
|
||||
return [
|
||||
{ key: 'created', title: '已创建', text: formatDateTime(current.createTime), done: true, active: false },
|
||||
{ key: 'appointment', title: '预约时间', text: formatDateTime(firstAppointment), done: Boolean(firstAppointment), active: status === 1 },
|
||||
{ key: 'service', title: status === 3 ? '已取消' : '服务完成', text: formatDateTime(current.completeTime || current.cancelTime || current.updateTime), done: status === 2 || status === 3, active: status === 2 || status === 3 },
|
||||
{ key: 'review', title: '评价', text: reviews.value.length ? `${reviews.value.length} 条记录` : '完成后可评价', done: reviews.value.some(item => Number(item.status) === 1 || item.rating), active: reviews.value.some(item => Number(item.status) !== 1 && !item.rating) },
|
||||
{ key: 'after-sale', title: '售后', text: afterSales.value.length ? `${afterSales.value.length} 条记录` : '暂无售后', done: afterSales.value.length > 0, active: afterSales.value.some(item => item.status === 'PENDING') }
|
||||
]
|
||||
})
|
||||
|
||||
const hasAmount = (value: unknown) => value !== undefined && value !== null && value !== '' && Number.isFinite(Number(value))
|
||||
|
||||
const formatQuoteAmount = (value: unknown, fallback = '--') => hasAmount(value) ? formatMoney(value as number | string) : fallback
|
||||
|
||||
const quoteReferencePrice = (item: any) => item?.referencePrice ?? item?.price
|
||||
|
||||
const quoteMessages = computed(() => Array.isArray(order.value?.quoteMessages) ? order.value.quoteMessages : [])
|
||||
|
||||
const quoteStatusText = computed(() => order.value?.quoteStatusText || order.value?.statusText || '确认价格中')
|
||||
|
||||
const quoteExpireText = computed(() => {
|
||||
const expireTime = formatDateTime(order.value?.quoteExpireTime)
|
||||
return expireTime !== '--' ? `有效期至 ${expireTime}` : '等待门店报价'
|
||||
})
|
||||
|
||||
const quoteMessageItems = (quoteMessage: any) => Array.isArray(quoteMessage?.items) ? quoteMessage.items : []
|
||||
|
||||
const quoteActorText = (quoteMessage: any) => {
|
||||
if (quoteMessage?.actorTypeText) return quoteMessage.actorTypeText
|
||||
if (String(quoteMessage?.actorType || '').toUpperCase() === 'USER') return '用户'
|
||||
if (String(quoteMessage?.actorType || '').toUpperCase() === 'SHOP') return '门店'
|
||||
return '系统'
|
||||
}
|
||||
|
||||
const quoteActionText = (quoteMessage: any) => quoteMessage?.actionText || quoteMessage?.action || '报价更新'
|
||||
|
||||
const quoteMessageKey = (quoteMessage: any, index: string | number) => {
|
||||
return String(quoteMessage?.id ?? `${quoteMessage?.createTime || 'quote'}-${quoteMessage?.action || index}`)
|
||||
}
|
||||
|
||||
const quoteMessageItemKey = (quoteItem: any) => {
|
||||
return String(quoteItem?.orderItemId ?? quoteItem?.productId ?? quoteItem?.id ?? JSON.stringify(quoteItem))
|
||||
}
|
||||
|
||||
const quoteMessageItemText = (quoteItem: any) => {
|
||||
const sourceItem = items.value.find((item: any) => String(item.id) === String(quoteItem?.orderItemId) || String(item.productId) === String(quoteItem?.productId))
|
||||
const title = quoteItem?.productTitle || sourceItem?.productTitle || '预约项目'
|
||||
const amount = quoteItem?.confirmedPrice ?? quoteItem?.quotedPrice ?? quoteItem?.price
|
||||
return hasAmount(amount) ? `${title}:${formatMoney(amount)}` : title
|
||||
}
|
||||
|
||||
const orderHasCurrentQuote = computed(() => {
|
||||
return items.value.some((item: any) => hasAmount(item?.quotedPrice ?? item?.confirmedPrice))
|
||||
})
|
||||
|
||||
const resolveOrderImages = async () => {
|
||||
for (const item of items.value) {
|
||||
const imageId = extractLegacyFileId(item.productImage)
|
||||
if (!imageId) continue
|
||||
const cachedUrl = getCachedSignedImageUrlSync(imageId)
|
||||
if (cachedUrl) item.productImage = cachedUrl
|
||||
item.productImage = await getCachedSignedImageUrl(imageId)
|
||||
}
|
||||
}
|
||||
|
||||
const loadRelated = async () => {
|
||||
if (!orderId.value) return
|
||||
const [reviewList, changeList, afterSalePage, contactInfo] = await Promise.all([
|
||||
orderApi.getOrderReviews(orderId.value).catch(() => []),
|
||||
orderApi.getOrderArtistChangeRequests(orderId.value).catch(() => []),
|
||||
afterSaleApi.listMy({ page: 1, size: 50 }).catch(() => ({ list: [] })),
|
||||
userApi.getOrderArtistContact(orderId.value).catch(() => null)
|
||||
])
|
||||
reviews.value = reviewList || []
|
||||
changeRequests.value = changeList || []
|
||||
afterSales.value = ((afterSalePage as any)?.list || []).filter((item: AfterSaleVO) => String(item.orderId) === orderId.value)
|
||||
contact.value = contactInfo
|
||||
}
|
||||
|
||||
const loadOrder = async () => {
|
||||
if (!orderId.value) {
|
||||
order.value = null
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
order.value = await orderApi.getOrderDetail(orderId.value)
|
||||
await resolveOrderImages()
|
||||
await loadRelated()
|
||||
} catch (error: any) {
|
||||
order.value = null
|
||||
message.error(error?.message || '订单详情加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const submitQuoteReply = async () => {
|
||||
if (!order.value?.id) return
|
||||
const remark = quoteReply.value.trim()
|
||||
if (!remark) {
|
||||
message.warning('请先填写回复内容')
|
||||
return
|
||||
}
|
||||
quoteSubmitting.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await orderApi.replyQuote(order.value.id, { remark })
|
||||
await loadOrder()
|
||||
})
|
||||
quoteReply.value = ''
|
||||
message.success('报价回复已发送')
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '发送报价回复失败')
|
||||
} finally {
|
||||
quoteSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const confirmQuote = () => {
|
||||
if (!order.value?.id) return
|
||||
if (!orderHasCurrentQuote.value) {
|
||||
message.warning('当前暂无可确认报价')
|
||||
return
|
||||
}
|
||||
Modal.confirm({
|
||||
title: '确认当前报价',
|
||||
content: '确认后门店会继续处理预约,请确认当前报价无误。',
|
||||
onOk: async () => {
|
||||
quoteConfirming.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await orderApi.confirmUserQuote(order.value.id)
|
||||
await loadOrder()
|
||||
})
|
||||
message.success('已确认当前报价')
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '确认报价失败')
|
||||
} finally {
|
||||
quoteConfirming.value = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const preparePayment = async () => {
|
||||
if (!order.value?.id) return
|
||||
await runWithGlobalLoading(async () => {
|
||||
await paymentApi.prepareOrderPayment(order.value.id)
|
||||
await loadOrder()
|
||||
})
|
||||
message.success('支付单已准备')
|
||||
}
|
||||
|
||||
const mockPay = async () => {
|
||||
if (!order.value?.id) return
|
||||
await runWithGlobalLoading(async () => {
|
||||
await paymentApi.mockSuccess(order.value.id)
|
||||
await loadOrder()
|
||||
})
|
||||
message.success('模拟支付成功')
|
||||
}
|
||||
|
||||
const cancelOrder = () => {
|
||||
if (!order.value?.id) return
|
||||
Modal.confirm({
|
||||
title: '取消订单',
|
||||
content: '确认取消这笔订单吗?',
|
||||
onOk: async () => {
|
||||
await runWithGlobalLoading(() => orderApi.cancelOrder(order.value.id as IdType))
|
||||
message.success('订单已取消')
|
||||
await loadOrder()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(loadOrder)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="detail-page">
|
||||
<header class="header">
|
||||
<a-button type="text" @click="router.back()">
|
||||
<LeftOutlined />
|
||||
</a-button>
|
||||
<h1>订单详情</h1>
|
||||
<a-button type="link" @click="router.push('/orders')">列表</a-button>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<a-spin :spinning="loading">
|
||||
<a-empty v-if="!order" description="未找到订单">
|
||||
<a-button type="primary" @click="router.push('/orders')">查看订单中心</a-button>
|
||||
</a-empty>
|
||||
|
||||
<template v-else>
|
||||
<section class="hero-card">
|
||||
<span class="eyebrow">{{ isQuoteConfirming ? '询价预约' : '预约订单' }}</span>
|
||||
<h2>{{ order.orderNo || `订单 ${order.id}` }}</h2>
|
||||
<p>{{ order.shopName || '当前门店' }}</p>
|
||||
<div class="hero-meta">
|
||||
<strong>{{ formatMoney(order.actualAmount || order.totalAmount) }}</strong>
|
||||
<span :class="['status-pill', statusClass(order.status)]">{{ isQuoteConfirming ? quoteStatusText : (order.statusText || '处理中') }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="timeline-card">
|
||||
<article v-for="node in timeline" :key="node.key" :class="{ done: node.done, active: node.active }">
|
||||
<strong>{{ node.title }}</strong>
|
||||
<span>{{ node.text }}</span>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section v-if="isQuoteConfirming" class="section-card quote-detail-panel">
|
||||
<div class="section-head">
|
||||
<div>
|
||||
<h3>报价确认</h3>
|
||||
<p>{{ quoteStatusText }} · {{ quoteExpireText }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<p>客户备注:{{ order.customerRemark || '暂无备注' }}</p>
|
||||
<div class="quote-flags">
|
||||
<span :class="{ active: order.quoteUserConfirmed }">用户{{ order.quoteUserConfirmed ? '已确认' : '待确认' }}</span>
|
||||
<span :class="{ active: order.quoteShopConfirmed }">门店{{ order.quoteShopConfirmed ? '已确认' : '待确认' }}</span>
|
||||
</div>
|
||||
<div class="quote-items">
|
||||
<article v-for="item in items" :key="item.id || item.productId" class="quote-item">
|
||||
<strong>{{ item.productTitle || '预约项目' }}</strong>
|
||||
<span>参考价 {{ formatQuoteAmount(quoteReferencePrice(item), '待确认') }}</span>
|
||||
<span>当前报价 {{ formatQuoteAmount(item.quotedPrice, '待报价') }}</span>
|
||||
<span>最终价 {{ formatQuoteAmount(item.confirmedPrice, '待确认') }}</span>
|
||||
</article>
|
||||
</div>
|
||||
<div class="quote-history">
|
||||
<strong>报价历史</strong>
|
||||
<div v-if="quoteMessages.length" class="quote-history__list">
|
||||
<article v-for="(quoteMessage, index) in quoteMessages" :key="quoteMessageKey(quoteMessage, index)" class="quote-history__item">
|
||||
<div>
|
||||
<span>{{ quoteActorText(quoteMessage) }}</span>
|
||||
<em>{{ quoteActionText(quoteMessage) }}</em>
|
||||
<small>{{ formatDateTime(quoteMessage.createTime) }}</small>
|
||||
</div>
|
||||
<p v-if="quoteMessage.remark">{{ quoteMessage.remark }}</p>
|
||||
<div v-if="quoteMessageItems(quoteMessage).length" class="quote-history__prices">
|
||||
<span v-for="quoteItem in quoteMessageItems(quoteMessage)" :key="quoteMessageItemKey(quoteItem)">
|
||||
{{ quoteMessageItemText(quoteItem) }}
|
||||
</span>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<p v-else>暂无报价历史</p>
|
||||
</div>
|
||||
<div class="quote-reply">
|
||||
<a-textarea v-model:value="quoteReply" :rows="3" :maxlength="300" placeholder="给门店补充说明或回复当前报价" />
|
||||
<div class="quote-reply__actions">
|
||||
<a-button :loading="quoteSubmitting" @click="submitQuoteReply">发送回复</a-button>
|
||||
<a-button
|
||||
v-if="!order.quoteUserConfirmed"
|
||||
type="primary"
|
||||
:loading="quoteConfirming"
|
||||
:disabled="!orderHasCurrentQuote"
|
||||
@click="confirmQuote"
|
||||
>
|
||||
确认当前报价
|
||||
</a-button>
|
||||
<span v-else class="quote-confirmed">你已确认当前报价</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="section-card">
|
||||
<div class="section-head">
|
||||
<h3>预约项目</h3>
|
||||
<a-button type="link" @click="router.push({ path: '/service-progress', query: { orderId } })">服务进度</a-button>
|
||||
</div>
|
||||
<article v-for="item in items" :key="item.id" class="item-row">
|
||||
<div class="thumb">
|
||||
<img v-if="item.productImage" :src="item.productImage" :alt="item.productTitle" loading="lazy" decoding="async" />
|
||||
<span v-else>{{ String(item.productTitle || '项').slice(0, 1) }}</span>
|
||||
</div>
|
||||
<div class="item-main">
|
||||
<strong>{{ item.productTitle || '预约项目' }}</strong>
|
||||
<span>{{ isQuoteConfirming ? '参考价 ' : '' }}{{ formatMoney(item.price) }} x {{ item.quantity || 1 }}</span>
|
||||
<span v-if="item.artistName">美甲师:{{ item.artistName }}</span>
|
||||
<span v-if="item.appointmentTime">预约:{{ formatDateTime(item.appointmentTime) }}</span>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section v-if="contact" class="section-card">
|
||||
<h3>联系信息</h3>
|
||||
<p>{{ contact.contactName || contact.roleLabel || '服务联系人' }}</p>
|
||||
<p v-if="contact.phoneAvailable && contact.phone">电话:{{ contact.phone }}</p>
|
||||
<p v-if="contact.wechatAvailable && contact.wechatId">微信:{{ contact.wechatId }}</p>
|
||||
<p v-if="contact.platformContactText">{{ contact.platformContactText }}</p>
|
||||
</section>
|
||||
|
||||
<section v-if="afterSales.length || changeRequests.length || reviews.length" class="section-card">
|
||||
<h3>关联记录</h3>
|
||||
<p v-for="item in afterSales" :key="`as-${item.id}`">售后 {{ item.afterSaleNo || item.id }}:{{ item.status || '-' }}</p>
|
||||
<p v-for="item in changeRequests" :key="`change-${item.id}`">改派:{{ item.statusText || item.status || '-' }}</p>
|
||||
<p v-for="item in reviews" :key="`review-${item.id}`">评价:{{ item.statusText || item.rating || '待评价' }}</p>
|
||||
</section>
|
||||
|
||||
<section class="action-bar">
|
||||
<a-button v-if="canPreparePayment" @click="preparePayment">准备支付</a-button>
|
||||
<a-button v-if="canMockPay" type="primary" @click="mockPay">模拟支付</a-button>
|
||||
<a-button v-if="canApplyAfterSale" @click="router.push({ path: '/after-sale/apply', query: { orderId } })">申请售后</a-button>
|
||||
<a-button v-if="order.status === 1" danger @click="cancelOrder">取消订单</a-button>
|
||||
</section>
|
||||
</template>
|
||||
</a-spin>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.detail-page { min-height: 100vh; padding-top: 60px; background: var(--theme-page-bg); color: var(--text-primary); }
|
||||
.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; height: 60px; padding: 9px 14px; background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent); border-bottom: 1px solid var(--theme-border); backdrop-filter: blur(14px); }
|
||||
.header h1 { margin: 0; font-size: 18px; }
|
||||
.content { padding: 16px 14px 28px; }
|
||||
.hero-card, .section-card, .timeline-card { border: 1px solid var(--theme-border); border-radius: 20px; background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent); box-shadow: 0 18px 44px rgba(74, 68, 63, 0.08); }
|
||||
.hero-card { padding: 22px; background: var(--theme-gradient-soft); }
|
||||
.eyebrow { display: block; color: var(--theme-primary); font-size: 12px; font-weight: 700; letter-spacing: .05em; }
|
||||
.hero-card h2 { margin: 10px 0 6px; font-size: 21px; }
|
||||
.hero-card p { margin: 0; color: var(--text-secondary); }
|
||||
.hero-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; }
|
||||
.hero-meta strong { font-size: 20px; }
|
||||
.status-pill { padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--theme-primary-soft); color: var(--theme-primary); }
|
||||
.status-pill.quote { color: #6b4600; background: #fff2cc; }
|
||||
.status-pill.cancelled { color: var(--theme-accent); }
|
||||
.timeline-card { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px; overflow: hidden; margin-top: 14px; background: var(--theme-border); }
|
||||
.timeline-card article { min-width: 0; padding: 12px 8px; background: var(--theme-card-bg); color: var(--text-secondary); }
|
||||
.timeline-card article.active { color: var(--theme-primary); }
|
||||
.timeline-card article.done strong { color: var(--theme-primary); }
|
||||
.timeline-card strong, .timeline-card span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.timeline-card strong { font-size: 12px; }
|
||||
.timeline-card span { margin-top: 4px; font-size: 11px; }
|
||||
.section-card { margin-top: 14px; padding: 16px; }
|
||||
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
||||
.section-card h3 { margin: 0 0 12px; font-size: 17px; }
|
||||
.section-card p { margin: 8px 0 0; color: var(--text-secondary); line-height: 1.6; }
|
||||
.section-head p { margin: 4px 0 0; font-size: 13px; }
|
||||
.quote-detail-panel { display: grid; gap: 12px; }
|
||||
.quote-flags { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.quote-flags span { padding: 4px 9px; border-radius: 999px; color: var(--text-secondary); background: var(--theme-primary-soft); font-size: 12px; }
|
||||
.quote-flags span.active { color: var(--theme-primary); font-weight: 700; }
|
||||
.quote-items, .quote-history, .quote-history__list, .quote-reply { display: grid; gap: 8px; }
|
||||
.quote-item { display: grid; grid-template-columns: minmax(0, 1.35fr) repeat(3, minmax(82px, auto)); gap: 8px; align-items: center; min-width: 0; padding: 10px; border-radius: 12px; background: color-mix(in srgb, var(--theme-primary-soft) 48%, var(--theme-card-bg)); }
|
||||
.quote-item strong { min-width: 0; overflow-wrap: anywhere; color: var(--text-primary); font-size: 13px; }
|
||||
.quote-item span, .quote-history__item small, .quote-confirmed { color: var(--text-secondary); font-size: 12px; }
|
||||
.quote-history > strong { color: var(--text-primary); font-size: 13px; }
|
||||
.quote-history__item { display: grid; gap: 6px; padding: 10px; border-radius: 12px; background: color-mix(in srgb, var(--theme-primary-soft) 42%, var(--theme-card-bg)); }
|
||||
.quote-history__item div { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
|
||||
.quote-history__item span, .quote-history__item em { color: var(--theme-primary); font-size: 12px; font-style: normal; font-weight: 700; }
|
||||
.quote-history__item p { margin: 0; overflow-wrap: anywhere; font-size: 13px; }
|
||||
.quote-history__prices { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.quote-history__prices span { padding: 3px 7px; border-radius: 8px; color: var(--text-secondary); background: var(--theme-card-bg); font-size: 12px; }
|
||||
.quote-reply__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
|
||||
.quote-confirmed { display: inline-flex; align-items: center; min-height: 32px; color: var(--theme-primary); font-weight: 700; }
|
||||
.item-row { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--theme-border); }
|
||||
.item-row:first-of-type { border-top: 0; padding-top: 0; }
|
||||
.thumb { width: 64px; height: 64px; flex: 0 0 auto; border-radius: 14px; overflow: hidden; display: grid; place-items: center; background: var(--theme-primary-soft); color: var(--theme-primary); font-weight: 700; }
|
||||
.thumb img { width: 100%; height: 100%; object-fit: cover; }
|
||||
.item-main { display: grid; gap: 5px; min-width: 0; color: var(--text-secondary); font-size: 13px; }
|
||||
.item-main strong { color: var(--text-primary); font-size: 15px; }
|
||||
.action-bar { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 16px; }
|
||||
:deep(.ant-btn-primary) { background: var(--theme-primary); border-color: var(--theme-primary); }
|
||||
:deep(.ant-btn-link) { color: var(--theme-primary); }
|
||||
@media (max-width: 640px) {
|
||||
.quote-item { grid-template-columns: 1fr; }
|
||||
.quote-reply__actions { justify-content: stretch; }
|
||||
.quote-reply__actions :deep(.ant-btn) { flex: 1 1 140px; }
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,343 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>设置密码</h1>
|
||||
<div class="empty"></div>
|
||||
</header>
|
||||
|
||||
<div class="password-form">
|
||||
<a-card :bordered="false" class="form-card">
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
layout="vertical"
|
||||
@finish="handleSubmit"
|
||||
>
|
||||
<a-form-item label="手机号">
|
||||
<a-input :value="userPhone || '未绑定手机号'" disabled size="large" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="验证码" name="verificationCode">
|
||||
<a-input
|
||||
v-model:value="formState.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
size="large"
|
||||
>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !userPhone"
|
||||
@click="handleSendVerificationCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="新密码" name="password">
|
||||
<a-input-password
|
||||
v-model:value="formState.password"
|
||||
placeholder="请输入新密码"
|
||||
size="large"
|
||||
@pressEnter="handleSubmit"
|
||||
>
|
||||
<template #prefix>
|
||||
<LockOutlined style="color: var(--text-secondary)" />
|
||||
</template>
|
||||
</a-input-password>
|
||||
<div class="password-tip">
|
||||
密码长度至少 8 位,且需包含字母和数字
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="确认密码" name="confirmPassword">
|
||||
<a-input-password
|
||||
v-model:value="formState.confirmPassword"
|
||||
placeholder="请再次输入新密码"
|
||||
size="large"
|
||||
@pressEnter="handleSubmit"
|
||||
>
|
||||
<template #prefix>
|
||||
<LockOutlined style="color: var(--text-secondary)" />
|
||||
</template>
|
||||
</a-input-password>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
block
|
||||
:loading="loading"
|
||||
>
|
||||
确认设置
|
||||
</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* PasswordSettingsView 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, onUnmounted, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import type { Rule } from 'ant-design-vue/es/form'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { userApi } from '@/api/user'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
/**
|
||||
* Purpose: router supports PasswordSettingsView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const router = useRouter()
|
||||
/**
|
||||
* Purpose: formRef supports PasswordSettingsView.vue by holding or executing the form ref page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formRef = ref<FormInstance>()
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** countdown is a reactive state variable used by the template and event handlers. */
|
||||
const countdown = ref(0)
|
||||
/**
|
||||
* Purpose: userInfo supports PasswordSettingsView.vue by holding or executing the user info page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const userInfo = ref<{ phone?: string } | null>(null)
|
||||
/**
|
||||
* Purpose: draftSavedAt supports PasswordSettingsView.vue by holding or executing the draft saved at page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
let countdownTimer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
/**
|
||||
* Purpose: formState supports PasswordSettingsView.vue by holding or executing the form state page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formState = reactive({
|
||||
verificationCode: '',
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: draftKey supports PasswordSettingsView.vue by holding or executing the draft key page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const draftKey = buildDraftStorageKey('password-settings', 'set-password')
|
||||
|
||||
/** restoreDraft is a local helper used by this page script. */
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<typeof formState>(draftKey, 'session')
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(formState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/** handleSaveDraft is a local helper used by this page script. */
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(draftKey, { ...formState }, 'session')
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到当前会话')
|
||||
}
|
||||
|
||||
/** handleClearDraft is a local helper used by this page script. */
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(draftKey, 'session')
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
/** userPhone is a reactive state variable used by the template and event handlers. */
|
||||
const userPhone = computed(() => userInfo.value?.phone || '')
|
||||
|
||||
/** validateConfirmPassword is a local helper used by this page script. */
|
||||
const validateConfirmPassword = (_rule: any, value: string) => {
|
||||
if (value !== formState.password) {
|
||||
return Promise.reject(new Error('两次输入的密码不一致'))
|
||||
}
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const formRules: Record<string, Rule[]> = {
|
||||
verificationCode: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||
{ pattern: /^\d{6}$/, message: '验证码必须是6位数字', trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||||
{ min: 8, message: '密码长度至少8位', trigger: 'blur' },
|
||||
{ pattern: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/, message: '密码必须包含字母和数字', trigger: 'blur' }
|
||||
],
|
||||
confirmPassword: [
|
||||
{ required: true, message: '请确认新密码', trigger: 'blur' },
|
||||
{ validator: validateConfirmPassword, trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
/** startCountdown is a local helper used by this page script. */
|
||||
const startCountdown = () => {
|
||||
countdown.value = 60
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer)
|
||||
}
|
||||
countdownTimer = setInterval(() => {
|
||||
countdown.value -= 1
|
||||
if (countdown.value <= 0 && countdownTimer) {
|
||||
clearInterval(countdownTimer)
|
||||
countdownTimer = null
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
/** fetchUserInfo is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const res = await userApi.getUserInfo()
|
||||
userInfo.value = res as unknown as { phone?: string }
|
||||
} catch (error: any) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
message.error(error.message || '获取用户信息失败')
|
||||
}
|
||||
}
|
||||
|
||||
/** handleSendVerificationCode is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleSendVerificationCode = async () => {
|
||||
if (!userPhone.value) {
|
||||
message.error('请先绑定手机号')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithGlobalLoading(() => userApi.sendVerificationCode({
|
||||
phone: userPhone.value,
|
||||
sceneCode: 'USER_CHANGE_PASSWORD_SMS_CODE'
|
||||
}))
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error: any) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error(error.message || '发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
/** handleSubmit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
if (!userPhone.value) {
|
||||
message.error('请先绑定手机号')
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
await runWithGlobalLoading(() => userApi.updatePassword({
|
||||
password: formState.password,
|
||||
verificationCode: formState.verificationCode
|
||||
}))
|
||||
|
||||
message.success('密码设置成功')
|
||||
handleClearDraft(false)
|
||||
localStorage.removeItem('needSetPassword')
|
||||
router.push('/profile')
|
||||
} catch (error: any) {
|
||||
console.error('设置密码失败:', error)
|
||||
message.error(error.message || '设置密码失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** handleBackClick is a local helper used by this page script. */
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
restoreDraft()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
background: var(--theme-page-bg);
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
background: var(--theme-card-bg);
|
||||
border-bottom: 1px solid var(--theme-border);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.back-btn,
|
||||
.empty {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.password-form {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.form-card {
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
background: var(--theme-card-bg);
|
||||
}
|
||||
|
||||
.password-tip {
|
||||
margin-top: 8px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,147 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { afterSaleApi, orderApi } from '../api/order'
|
||||
import type { AfterSaleVO, OrderArtistChangeRequestVO, OrderArtistReviewVO } from '../api/order'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const loading = ref(false)
|
||||
const order = ref<any | null>(null)
|
||||
const reviews = ref<OrderArtistReviewVO[]>([])
|
||||
const changes = ref<OrderArtistChangeRequestVO[]>([])
|
||||
const afterSales = ref<AfterSaleVO[]>([])
|
||||
|
||||
const orderId = computed(() => String(route.query.orderId || route.params.id || ''))
|
||||
const items = computed(() => Array.isArray(order.value?.items) ? order.value.items : [])
|
||||
const firstAppointment = computed(() => items.value.map((item: any) => item.appointmentTime).find(Boolean))
|
||||
|
||||
const formatTime = (value?: string) => value ? String(value).replace('T', ' ').slice(0, 16) : '--'
|
||||
const latestChangeText = computed(() => {
|
||||
const latest = changes.value.slice().sort((left: any, right: any) => String(right.updateTime || right.createTime || '').localeCompare(String(left.updateTime || left.createTime || '')))[0] as any
|
||||
return latest ? (latest.statusText || latest.status || '改派记录') : '暂无改派'
|
||||
})
|
||||
|
||||
const nodes = computed(() => {
|
||||
const current = order.value || {}
|
||||
const status = Number(current.status)
|
||||
return [
|
||||
{ key: 'created', title: '订单创建', desc: formatTime(current.createTime), done: true, active: false },
|
||||
{ key: 'appointment', title: '预约确认', desc: formatTime(firstAppointment.value), done: Boolean(firstAppointment.value), active: status === 1 },
|
||||
{ key: 'artist', title: '服务安排', desc: latestChangeText.value, done: changes.value.length > 0 || items.value.some((item: any) => item.artistName), active: changes.value.some(item => item.status === 'PENDING') },
|
||||
{ key: 'service', title: status === 3 ? '订单取消' : '服务完成', desc: formatTime(current.completeTime || current.cancelTime || current.updateTime), done: status === 2 || status === 3, active: status === 2 || status === 3 },
|
||||
{ key: 'after-sale', title: '售后/评价', desc: afterSales.value.length ? `${afterSales.value.length} 条售后` : (reviews.value.length ? `${reviews.value.length} 条评价` : '暂无记录'), done: afterSales.value.length > 0 || reviews.value.length > 0, active: afterSales.value.some(item => item.status === 'PENDING') || reviews.value.some(item => !item.rating) }
|
||||
]
|
||||
})
|
||||
|
||||
const loadProgress = async () => {
|
||||
if (!orderId.value) return
|
||||
loading.value = true
|
||||
try {
|
||||
const [detail, reviewList, changeList, afterSalePage] = await Promise.all([
|
||||
orderApi.getOrderDetail(orderId.value),
|
||||
orderApi.getOrderReviews(orderId.value).catch(() => []),
|
||||
orderApi.getOrderArtistChangeRequests(orderId.value).catch(() => []),
|
||||
afterSaleApi.listMy({ page: 1, size: 50 }).catch(() => ({ list: [] }))
|
||||
])
|
||||
order.value = detail
|
||||
reviews.value = reviewList || []
|
||||
changes.value = changeList || []
|
||||
afterSales.value = ((afterSalePage as any)?.list || []).filter((item: AfterSaleVO) => String(item.orderId) === orderId.value)
|
||||
} catch (error: any) {
|
||||
order.value = null
|
||||
message.error(error?.message || '服务进度加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadProgress)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="progress-page">
|
||||
<header class="header">
|
||||
<a-button type="text" @click="router.back()">
|
||||
<LeftOutlined />
|
||||
</a-button>
|
||||
<h1>服务进度</h1>
|
||||
<a-button type="link" @click="loadProgress">刷新</a-button>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<section class="hero-card">
|
||||
<span>进度追踪</span>
|
||||
<h2>{{ order?.orderNo || (orderId ? `订单 ${orderId}` : '选择订单') }}</h2>
|
||||
<p>{{ order?.shopName || '查看预约、服务、评价与售后节点' }}</p>
|
||||
</section>
|
||||
|
||||
<a-spin :spinning="loading">
|
||||
<a-empty v-if="!orderId" description="缺少订单参数">
|
||||
<a-button type="primary" @click="router.push('/orders')">选择订单</a-button>
|
||||
</a-empty>
|
||||
|
||||
<template v-else>
|
||||
<section class="progress-list">
|
||||
<article v-for="node in nodes" :key="node.key" :class="{ done: node.done, active: node.active }">
|
||||
<i />
|
||||
<div>
|
||||
<strong>{{ node.title }}</strong>
|
||||
<span>{{ node.desc }}</span>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section v-if="items.length" class="section-card">
|
||||
<h3>项目进度</h3>
|
||||
<p v-for="item in items" :key="item.id">
|
||||
{{ item.productTitle || '预约项目' }}:{{ item.artistName || '待安排美甲师' }},{{ formatTime(item.appointmentTime) }}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section v-if="changes.length" class="section-card">
|
||||
<h3>改派记录</h3>
|
||||
<p v-for="item in changes" :key="item.id">{{ item.statusText || item.status }}:{{ item.reason || item.timeImpactText || '已记录' }}</p>
|
||||
</section>
|
||||
|
||||
<section v-if="afterSales.length" class="section-card">
|
||||
<h3>售后记录</h3>
|
||||
<p v-for="item in afterSales" :key="item.id">{{ item.afterSaleNo || item.id }}:{{ item.status || '-' }}</p>
|
||||
</section>
|
||||
|
||||
<div class="actions">
|
||||
<a-button @click="router.push(`/orders/${orderId}`)">订单详情</a-button>
|
||||
<a-button type="primary" @click="router.push({ path: '/after-sale/apply', query: { orderId } })">申请售后</a-button>
|
||||
</div>
|
||||
</template>
|
||||
</a-spin>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.progress-page { min-height: 100vh; padding-top: 60px; background: var(--theme-page-bg); color: var(--text-primary); }
|
||||
.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; height: 60px; padding: 9px 14px; background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent); border-bottom: 1px solid var(--theme-border); backdrop-filter: blur(14px); }
|
||||
.header h1 { margin: 0; font-size: 18px; }
|
||||
.content { padding: 16px 14px 32px; }
|
||||
.hero-card, .section-card, .progress-list { border: 1px solid var(--theme-border); border-radius: 20px; background: color-mix(in srgb, var(--theme-card-bg) 88%, transparent); box-shadow: 0 18px 44px rgba(74, 68, 63, 0.08); }
|
||||
.hero-card { padding: 22px; margin-bottom: 14px; background: var(--theme-gradient-soft); }
|
||||
.hero-card span { color: var(--theme-primary); font-size: 12px; font-weight: 700; letter-spacing: .05em; }
|
||||
.hero-card h2 { margin: 10px 0 6px; font-size: 21px; }
|
||||
.hero-card p { margin: 0; color: var(--text-secondary); line-height: 1.6; }
|
||||
.progress-list { display: grid; gap: 0; overflow: hidden; }
|
||||
.progress-list article { display: flex; gap: 12px; padding: 16px; border-top: 1px solid var(--theme-border); }
|
||||
.progress-list article:first-child { border-top: 0; }
|
||||
.progress-list i { width: 14px; height: 14px; margin-top: 3px; border-radius: 999px; background: var(--theme-border); box-shadow: 0 0 0 5px var(--theme-primary-soft); }
|
||||
.progress-list article.done i, .progress-list article.active i { background: var(--theme-primary); }
|
||||
.progress-list strong, .progress-list span { display: block; }
|
||||
.progress-list span, .section-card p { margin-top: 6px; color: var(--text-secondary); line-height: 1.6; }
|
||||
.section-card { margin-top: 14px; padding: 16px; }
|
||||
.section-card h3 { margin: 0 0 10px; font-size: 17px; }
|
||||
.section-card p { margin: 8px 0 0; }
|
||||
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
|
||||
:deep(.ant-btn-primary) { background: var(--theme-primary); border-color: var(--theme-primary); }
|
||||
:deep(.ant-btn-link) { color: var(--theme-primary); }
|
||||
</style>
|
||||
@@ -0,0 +1,258 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>设置中心</h1>
|
||||
<div class="empty"></div>
|
||||
</header>
|
||||
|
||||
<div class="settings-menu">
|
||||
<a-card :bordered="false" class="settings-card">
|
||||
<a-list :data-source="settingsSections" :split="false">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item v-if="item.type === 'title'" class="section-title">
|
||||
<span>{{ item.title }}</span>
|
||||
</a-list-item>
|
||||
|
||||
<a-list-item v-else class="setting-item" @click="handleSettingClick(item.key)">
|
||||
<template #actions>
|
||||
<RightOutlined />
|
||||
</template>
|
||||
<a-list-item-meta>
|
||||
<template #avatar>
|
||||
<div class="setting-icon" :style="{ backgroundColor: item.bgColor }">
|
||||
<component :is="item.icon" />
|
||||
</div>
|
||||
</template>
|
||||
<template #title>
|
||||
<span>{{ item.title }}</span>
|
||||
</template>
|
||||
<template #description>
|
||||
<span>{{ item.desc }}</span>
|
||||
</template>
|
||||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<div class="version-info">
|
||||
<a-typography-text type="secondary">版本 1.0.0</a-typography-text>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* SettingsView 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 } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
LeftOutlined,
|
||||
LockOutlined,
|
||||
RightOutlined,
|
||||
} from '@ant-design/icons-vue'
|
||||
|
||||
/**
|
||||
* Purpose: router supports SettingsView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const router = useRouter()
|
||||
|
||||
/** settingsSections is a reactive state variable used by the template and event handlers. */
|
||||
const settingsSections = ref([
|
||||
{
|
||||
type: 'title',
|
||||
title: '账号与安全'
|
||||
},
|
||||
{
|
||||
key: 'account',
|
||||
title: '账号设置',
|
||||
desc: '管理手机号、登录密码和账号安全',
|
||||
icon: LockOutlined,
|
||||
bgColor: 'var(--theme-primary-soft)'
|
||||
}
|
||||
])
|
||||
|
||||
/** handleBackClick is a local helper used by this page script. */
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
/** handleSettingClick is a local helper used by this page script. */
|
||||
const handleSettingClick = (key: string) => {
|
||||
if (key === 'account') {
|
||||
router.push('/settings/account')
|
||||
return
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
padding-top: 60px;
|
||||
background:
|
||||
linear-gradient(rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.92)),
|
||||
var(--theme-background-image),
|
||||
var(--theme-page-bg);
|
||||
background-size: cover, cover, auto;
|
||||
background-position: center top;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
height: 60px;
|
||||
padding: 10px 15px;
|
||||
background: rgba(255, 255, 255, 0.92);
|
||||
border-bottom: 1px solid var(--theme-border);
|
||||
backdrop-filter: blur(14px);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.back-btn,
|
||||
.empty {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.settings-menu {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
background: var(--theme-card-bg);
|
||||
border: 1px solid var(--theme-border);
|
||||
box-shadow: 0 14px 34px rgba(122, 67, 88, 0.08);
|
||||
}
|
||||
|
||||
.settings-card :deep(.ant-card-body) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
padding: 12px 16px;
|
||||
font-size: 13px;
|
||||
color: var(--theme-accent);
|
||||
background: var(--theme-primary-soft);
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
padding: 16px;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s;
|
||||
border-bottom: 1px solid var(--theme-border);
|
||||
}
|
||||
|
||||
.setting-item:hover {
|
||||
background: var(--theme-primary-soft);
|
||||
}
|
||||
|
||||
.setting-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-action) {
|
||||
margin-left: 8px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.setting-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 18px;
|
||||
color: var(--theme-primary);
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-meta-title) {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-meta-description) {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.version-info {
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.mobile-container {
|
||||
padding-top: 68px;
|
||||
background:
|
||||
radial-gradient(circle at 85% 0%, color-mix(in srgb, var(--theme-primary) 28%, transparent), transparent 32%),
|
||||
linear-gradient(180deg, color-mix(in srgb, var(--theme-card-bg) 78%, transparent), var(--theme-page-bg));
|
||||
}
|
||||
|
||||
.header {
|
||||
height: 64px;
|
||||
padding: 12px 18px 10px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 17px;
|
||||
font-weight: 820;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 74%, transparent);
|
||||
}
|
||||
|
||||
.settings-menu {
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border-radius: 24px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 90%, transparent);
|
||||
box-shadow: 0 20px 42px color-mix(in srgb, var(--theme-neutral) 9%, transparent);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
color: var(--theme-primary-action);
|
||||
background: color-mix(in srgb, var(--theme-primary) 18%, var(--theme-card-bg));
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
padding: 18px 16px;
|
||||
}
|
||||
|
||||
.setting-icon {
|
||||
border-radius: 14px;
|
||||
color: var(--theme-primary-action);
|
||||
background: color-mix(in srgb, var(--theme-primary) 22%, var(--theme-card-bg)) !important;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,957 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, shallowRef } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
CreditCardOutlined,
|
||||
CrownOutlined,
|
||||
GiftOutlined,
|
||||
HistoryOutlined,
|
||||
LeftOutlined,
|
||||
PayCircleOutlined,
|
||||
PercentageOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
ScissorOutlined,
|
||||
ShoppingOutlined,
|
||||
StarFilled,
|
||||
TrophyOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { userApi, type BalanceHistoryItem, type UserAssetVO, type VipRechargePlanVO } from '@/api/user'
|
||||
|
||||
const router = useRouter()
|
||||
const loading = shallowRef(false)
|
||||
const rechargeOpen = shallowRef(false)
|
||||
const visibleHistoryCount = shallowRef(3)
|
||||
const asset = ref<UserAssetVO | null>(null)
|
||||
const history = ref<BalanceHistoryItem[]>([])
|
||||
const plans = ref<VipRechargePlanVO[]>([])
|
||||
const selectedPlan = ref<VipRechargePlanVO | null>(null)
|
||||
const rechargeSectionRef = ref<HTMLElement | null>(null)
|
||||
|
||||
interface LevelStep {
|
||||
name: string
|
||||
amount: number
|
||||
}
|
||||
|
||||
const levelSteps: [LevelStep, ...LevelStep[]] = [
|
||||
{ name: '普通会员', amount: 0 },
|
||||
{ name: '玫瑰金会员', amount: 1000 },
|
||||
{ name: '钻石会员', amount: 5000 }
|
||||
]
|
||||
|
||||
const money = (value?: number | string) => {
|
||||
const amount = Number(value || 0)
|
||||
return Number.isFinite(amount)
|
||||
? amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||||
: '0.00'
|
||||
}
|
||||
|
||||
const formatTime = (value?: string) => value ? value.replace('T', ' ').slice(0, 16) : '--'
|
||||
|
||||
const sceneText = (scene?: string) => {
|
||||
const map: Record<string, string> = {
|
||||
MANUAL_RECHARGE: '手工充值',
|
||||
MANUAL_DEDUCT: '手工扣减',
|
||||
ORDER_PAY: '订单消费',
|
||||
ORDER_REFUND: '订单退款',
|
||||
RECHARGE: '会员充值',
|
||||
CONSUME: '余额消费'
|
||||
}
|
||||
return map[scene || ''] || scene || '余额变动'
|
||||
}
|
||||
|
||||
const sceneIcon = (item: BalanceHistoryItem) => {
|
||||
const scene = item.changeScene || item.type || ''
|
||||
if (Number(item.amount) > 0 || scene.includes('RECHARGE') || scene.includes('REFUND')) {
|
||||
return PayCircleOutlined
|
||||
}
|
||||
if (scene.includes('ORDER') || scene.includes('CONSUME')) {
|
||||
return ScissorOutlined
|
||||
}
|
||||
return HistoryOutlined
|
||||
}
|
||||
|
||||
const memberLevel = computed(() => asset.value?.vipLevel || '普通会员')
|
||||
const totalRecharge = computed(() => Number(asset.value?.totalRechargeAmount || 0))
|
||||
const balanceAmount = computed(() => Number(asset.value?.balance || 0))
|
||||
const sortedPlans = computed(() => [...plans.value].sort((left, right) => {
|
||||
const sortDelta = Number(left.sortOrder || 0) - Number(right.sortOrder || 0)
|
||||
return sortDelta || Number(left.rechargeAmount || 0) - Number(right.rechargeAmount || 0)
|
||||
}))
|
||||
const visibleHistory = computed(() => history.value.slice(0, visibleHistoryCount.value))
|
||||
const canLoadMoreHistory = computed(() => visibleHistoryCount.value < history.value.length)
|
||||
const currentStep = computed(() => {
|
||||
return [...levelSteps].reverse().find(step => totalRecharge.value >= step.amount) || levelSteps[0]
|
||||
})
|
||||
const nextStep = computed(() => levelSteps.find(step => step.amount > totalRecharge.value))
|
||||
const levelProgress = computed(() => {
|
||||
const next = nextStep.value
|
||||
if (!next) return 100
|
||||
const current = currentStep.value
|
||||
const range = Math.max(next.amount - current.amount, 1)
|
||||
return Math.min(100, Math.max(8, ((totalRecharge.value - current.amount) / range) * 100))
|
||||
})
|
||||
const nextLevelText = computed(() => nextStep.value ? `下一等级:${nextStep.value.name}` : '已达最高等级')
|
||||
const remainingAmountText = computed(() => {
|
||||
const next = nextStep.value
|
||||
if (!next) return '继续保持你的专属礼遇'
|
||||
return `再充值 ¥${money(Math.max(next.amount - totalRecharge.value, 0))} 可升级`
|
||||
})
|
||||
const validityText = computed(() => {
|
||||
const start = formatTime(asset.value?.vipStartTime)
|
||||
const expire = formatTime(asset.value?.vipExpireTime)
|
||||
if (start === '--' && expire === '--') return '长期有效'
|
||||
if (expire === '--') return `${start} 起生效`
|
||||
return `${start} - ${expire}`
|
||||
})
|
||||
const benefitCards = computed(() => [
|
||||
{
|
||||
icon: GiftOutlined,
|
||||
title: '生日礼遇',
|
||||
desc: '生日月专属美甲套装',
|
||||
tone: 'rose'
|
||||
},
|
||||
{
|
||||
icon: SafetyCertificateOutlined,
|
||||
title: '优先预约',
|
||||
desc: '热门时段优先锁定档期',
|
||||
tone: 'gold'
|
||||
},
|
||||
{
|
||||
icon: PercentageOutlined,
|
||||
title: '专属优惠',
|
||||
desc: asset.value?.benefitInfo || '会员专属折扣权益',
|
||||
tone: 'slate'
|
||||
},
|
||||
{
|
||||
icon: CrownOutlined,
|
||||
title: '护理礼遇',
|
||||
desc: '精选护理权益持续更新',
|
||||
tone: 'cream'
|
||||
}
|
||||
])
|
||||
|
||||
const planTag = (index: number) => {
|
||||
if (index === 0) return '超值'
|
||||
if (index === 1) return '最佳选择'
|
||||
return '尊享'
|
||||
}
|
||||
|
||||
const openPlan = (plan: VipRechargePlanVO) => {
|
||||
selectedPlan.value = plan
|
||||
rechargeOpen.value = true
|
||||
}
|
||||
|
||||
const scrollToRecharge = () => {
|
||||
rechargeSectionRef.value?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
}
|
||||
|
||||
const loadMoreHistory = () => {
|
||||
visibleHistoryCount.value += 3
|
||||
}
|
||||
|
||||
const loadData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const [assetRes, historyRes] = await Promise.all([
|
||||
userApi.getMyAsset(),
|
||||
userApi.getMyBalanceHistory()
|
||||
])
|
||||
asset.value = assetRes
|
||||
history.value = historyRes || []
|
||||
plans.value = await userApi.listMyVipRechargePlans().catch(() => [])
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取 VIP 信息失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadData)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="vip-center">
|
||||
<header class="vip-topbar">
|
||||
<button class="topbar-button" type="button" aria-label="返回" @click="router.back()">
|
||||
<LeftOutlined />
|
||||
</button>
|
||||
<h1>VIP中心</h1>
|
||||
<button class="topbar-button" type="button" aria-label="购物车" @click="router.push('/cart')">
|
||||
<ShoppingOutlined />
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<a-spin :spinning="loading">
|
||||
<main class="vip-main">
|
||||
<section class="vip-hero-card">
|
||||
<div class="hero-glow hero-glow--top"></div>
|
||||
<div class="hero-glow hero-glow--bottom"></div>
|
||||
<div class="hero-content">
|
||||
<div class="hero-head">
|
||||
<div>
|
||||
<span class="vip-kicker">当前会员等级</span>
|
||||
<h2>{{ memberLevel }} <StarFilled /></h2>
|
||||
</div>
|
||||
<div class="fingerprint-badge">
|
||||
<CrownOutlined />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hero-stats">
|
||||
<div>
|
||||
<span>可用余额</span>
|
||||
<strong><small>¥</small>{{ money(balanceAmount) }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>累计充值</span>
|
||||
<strong><small>¥</small>{{ money(totalRecharge) }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="level-progress">
|
||||
<div>
|
||||
<span>等级进度</span>
|
||||
<span>{{ nextLevelText }}</span>
|
||||
</div>
|
||||
<div class="progress-track">
|
||||
<i :style="{ width: `${levelProgress}%` }"></i>
|
||||
</div>
|
||||
<p>{{ remainingAmountText }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<TrophyOutlined class="hero-watermark" />
|
||||
</section>
|
||||
|
||||
<section class="vip-section">
|
||||
<div class="section-head">
|
||||
<h3>会员特权</h3>
|
||||
<button type="button" @click="scrollToRecharge">查看全部</button>
|
||||
</div>
|
||||
<div class="benefit-grid">
|
||||
<article
|
||||
v-for="item in benefitCards"
|
||||
:key="item.title"
|
||||
class="benefit-card"
|
||||
:class="`benefit-card--${item.tone}`"
|
||||
>
|
||||
<span class="benefit-icon">
|
||||
<component :is="item.icon" />
|
||||
</span>
|
||||
<strong>{{ item.title }}</strong>
|
||||
<p>{{ item.desc }}</p>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="vip-section member-info-section">
|
||||
<div class="section-head">
|
||||
<h3>会员信息</h3>
|
||||
</div>
|
||||
<div class="info-grid">
|
||||
<article>
|
||||
<span>生效周期</span>
|
||||
<strong>{{ validityText }}</strong>
|
||||
</article>
|
||||
<article>
|
||||
<span>最近充值</span>
|
||||
<strong>{{ formatTime(asset?.lastRechargeTime) }}</strong>
|
||||
</article>
|
||||
<article>
|
||||
<span>等级来源</span>
|
||||
<strong>{{ asset?.manualOverride ? '后台指定' : '自动计算' }}</strong>
|
||||
</article>
|
||||
<article>
|
||||
<span>当前权益</span>
|
||||
<strong>{{ asset?.benefitInfo || '暂无额外权益说明' }}</strong>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section ref="rechargeSectionRef" class="vip-section recharge-section">
|
||||
<div class="section-head">
|
||||
<h3>快速充值</h3>
|
||||
</div>
|
||||
<div v-if="sortedPlans.length" class="plan-grid">
|
||||
<article
|
||||
v-for="(plan, index) in sortedPlans"
|
||||
:key="String(plan.id)"
|
||||
class="plan-card"
|
||||
:class="{ 'plan-card--featured': index === 1 }"
|
||||
>
|
||||
<div class="plan-tag" :class="{ 'plan-tag--featured': index === 1 }">
|
||||
{{ planTag(index) }}
|
||||
</div>
|
||||
<span class="plan-title">{{ plan.title || plan.vipLevel }}</span>
|
||||
<div class="plan-price">
|
||||
<small>¥</small>
|
||||
<strong>{{ money(plan.rechargeAmount).replace('.00', '') }}</strong>
|
||||
</div>
|
||||
<p>赠送 <b>¥{{ money(plan.giftAmount) }}</b> 奖励金</p>
|
||||
<button type="button" @click="openPlan(plan)">立即充值</button>
|
||||
</article>
|
||||
</div>
|
||||
<a-empty v-else description="暂无可展示充值档位" />
|
||||
</section>
|
||||
|
||||
<section class="vip-section history-section">
|
||||
<div class="section-head">
|
||||
<h3>最近动态</h3>
|
||||
</div>
|
||||
<div v-if="visibleHistory.length" class="history-card">
|
||||
<article
|
||||
v-for="item in visibleHistory"
|
||||
:key="String(item.id)"
|
||||
class="history-row"
|
||||
>
|
||||
<span class="history-icon" :class="{ 'history-icon--income': Number(item.amount) > 0 }">
|
||||
<component :is="sceneIcon(item)" />
|
||||
</span>
|
||||
<div class="history-copy">
|
||||
<strong>{{ sceneText(item.changeScene || item.type) }}</strong>
|
||||
<span>{{ formatTime(item.changeTime) }}</span>
|
||||
<em v-if="item.remark">{{ item.remark }}</em>
|
||||
</div>
|
||||
<div class="history-amount">
|
||||
<strong :class="{ income: Number(item.amount) > 0 }">
|
||||
{{ Number(item.amount) > 0 ? '+' : '' }}¥{{ money(item.amount) }}
|
||||
</strong>
|
||||
<span v-if="item.afterBalance !== undefined">余额: ¥{{ money(item.afterBalance) }}</span>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<a-empty v-else description="暂无余额变动" />
|
||||
<button v-if="canLoadMoreHistory" class="load-more-button" type="button" @click="loadMoreHistory">
|
||||
加载更多交易记录
|
||||
</button>
|
||||
</section>
|
||||
</main>
|
||||
</a-spin>
|
||||
|
||||
<a-modal v-model:open="rechargeOpen" title="充值档位说明" :footer="null">
|
||||
<div class="plan-modal" v-if="selectedPlan">
|
||||
<span class="modal-icon"><CreditCardOutlined /></span>
|
||||
<h3>{{ selectedPlan.title || selectedPlan.vipLevel }}</h3>
|
||||
<p>充值 ¥{{ money(selectedPlan.rechargeAmount) }},赠送 ¥{{ money(selectedPlan.giftAmount) }} 奖励金。</p>
|
||||
<p>{{ selectedPlan.description || '该档位仅展示,暂不发起支付。' }}</p>
|
||||
</div>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.vip-center {
|
||||
--vip-bg: #fff8f4;
|
||||
--vip-surface: rgba(255, 255, 255, 0.82);
|
||||
--vip-surface-strong: rgba(255, 255, 255, 0.94);
|
||||
--vip-surface-low: #fcf2ea;
|
||||
--vip-surface-mid: #f6ece5;
|
||||
--vip-surface-high: #f1e6df;
|
||||
--vip-text: #1f1b17;
|
||||
--vip-muted: #504444;
|
||||
--vip-outline: #d4c2c3;
|
||||
--vip-outline-soft: rgba(212, 194, 195, 0.54);
|
||||
--vip-primary: #7c5357;
|
||||
--vip-blush: #e8b4b8;
|
||||
--vip-blush-soft: #ffdadc;
|
||||
--vip-blush-dim: #eeb9bd;
|
||||
--vip-gold: #775a19;
|
||||
--vip-gold-soft: #fed488;
|
||||
--vip-neutral: #5e5e5d;
|
||||
--vip-neutral-soft: #c2c1bf;
|
||||
--vip-hero-text: #fff8f4;
|
||||
--vip-shadow: rgba(74, 68, 63, 0.1);
|
||||
min-height: 100vh;
|
||||
color: var(--vip-text);
|
||||
background:
|
||||
radial-gradient(circle at 84% 0%, rgba(232, 180, 184, 0.38), transparent 34%),
|
||||
radial-gradient(circle at 4% 18%, rgba(254, 212, 136, 0.34), transparent 30%),
|
||||
linear-gradient(180deg, var(--vip-bg) 0%, var(--vip-surface-low) 46%, var(--vip-bg) 100%);
|
||||
}
|
||||
|
||||
.vip-topbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 30;
|
||||
display: grid;
|
||||
grid-template-columns: 42px minmax(0, 1fr) 42px;
|
||||
align-items: center;
|
||||
width: min(100%, var(--app-mobile-max-width, 480px));
|
||||
min-height: 64px;
|
||||
margin: 0 auto;
|
||||
padding: 8px 20px;
|
||||
background: rgba(255, 248, 244, 0.86);
|
||||
box-shadow: 0 8px 28px rgba(74, 68, 63, 0.06);
|
||||
backdrop-filter: blur(18px);
|
||||
}
|
||||
|
||||
.vip-topbar h1 {
|
||||
margin: 0;
|
||||
color: var(--vip-primary);
|
||||
font-family: Georgia, 'Times New Roman', serif;
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
line-height: 1.15;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.topbar-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
color: var(--vip-primary);
|
||||
background: var(--vip-surface-strong);
|
||||
box-shadow: 0 12px 24px rgba(74, 68, 63, 0.08);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.topbar-button :deep(.anticon) {
|
||||
font-size: 21px;
|
||||
}
|
||||
|
||||
.vip-main {
|
||||
display: grid;
|
||||
gap: 32px;
|
||||
width: min(100%, var(--app-mobile-max-width, 480px));
|
||||
margin: 0 auto;
|
||||
padding: 22px 20px 42px;
|
||||
}
|
||||
|
||||
.vip-hero-card {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
padding: 28px;
|
||||
border-radius: 32px;
|
||||
color: var(--vip-hero-text);
|
||||
background:
|
||||
linear-gradient(135deg, var(--vip-primary) 0%, var(--vip-blush) 55%, var(--vip-gold-soft) 100%);
|
||||
box-shadow: 0 26px 54px rgba(124, 83, 87, 0.22);
|
||||
}
|
||||
|
||||
.hero-glow {
|
||||
position: absolute;
|
||||
width: 210px;
|
||||
height: 210px;
|
||||
border-radius: 999px;
|
||||
background: rgba(255, 255, 255, 0.13);
|
||||
filter: blur(18px);
|
||||
}
|
||||
|
||||
.hero-glow--top {
|
||||
top: -74px;
|
||||
right: -78px;
|
||||
}
|
||||
|
||||
.hero-glow--bottom {
|
||||
bottom: -118px;
|
||||
left: -86px;
|
||||
background: rgba(254, 212, 136, 0.24);
|
||||
}
|
||||
|
||||
.hero-content {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: grid;
|
||||
gap: 22px;
|
||||
}
|
||||
|
||||
.hero-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.vip-kicker,
|
||||
.section-head button,
|
||||
.plan-title {
|
||||
font-size: 12px;
|
||||
font-weight: 800;
|
||||
line-height: 1.2;
|
||||
letter-spacing: 0;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.vip-kicker {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
opacity: 0.78;
|
||||
}
|
||||
|
||||
.hero-head h2 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
font-family: Georgia, 'Times New Roman', serif;
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
line-height: 1.15;
|
||||
}
|
||||
|
||||
.hero-head h2 :deep(.anticon) {
|
||||
color: var(--vip-gold-soft);
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.fingerprint-badge {
|
||||
display: grid;
|
||||
flex: 0 0 auto;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
place-items: center;
|
||||
border: 1px solid rgba(255, 255, 255, 0.28);
|
||||
border-radius: 18px;
|
||||
background: rgba(255, 255, 255, 0.18);
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.fingerprint-badge :deep(.anticon) {
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.hero-stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.hero-stats > div {
|
||||
min-width: 0;
|
||||
padding: 14px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
border-radius: 16px;
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.hero-stats span,
|
||||
.level-progress span,
|
||||
.level-progress p {
|
||||
color: rgba(255, 255, 255, 0.74);
|
||||
font-size: 12px;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.hero-stats strong {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 3px;
|
||||
min-width: 0;
|
||||
margin-top: 6px;
|
||||
overflow-wrap: anywhere;
|
||||
color: var(--vip-hero-text);
|
||||
font-family: Georgia, 'Times New Roman', serif;
|
||||
font-size: 22px;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
.hero-stats small,
|
||||
.plan-price small {
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.level-progress {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.level-progress > div:first-child {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.progress-track {
|
||||
height: 6px;
|
||||
overflow: hidden;
|
||||
border-radius: 999px;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.progress-track i {
|
||||
display: block;
|
||||
height: 100%;
|
||||
border-radius: inherit;
|
||||
background: var(--vip-hero-text);
|
||||
box-shadow: 0 0 14px rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
.level-progress p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.hero-watermark {
|
||||
position: absolute;
|
||||
right: 20px;
|
||||
bottom: -26px;
|
||||
color: rgba(255, 255, 255, 0.1);
|
||||
font-size: 118px;
|
||||
}
|
||||
|
||||
.vip-section {
|
||||
display: grid;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.section-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.section-head h3 {
|
||||
margin: 0;
|
||||
color: var(--vip-text);
|
||||
font-family: Georgia, 'Times New Roman', serif;
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.section-head button {
|
||||
border: 0;
|
||||
color: var(--vip-primary);
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.benefit-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.benefit-card,
|
||||
.member-info-section,
|
||||
.plan-card,
|
||||
.history-card {
|
||||
border: 1px solid rgba(212, 194, 195, 0.5);
|
||||
background: var(--vip-surface);
|
||||
box-shadow: 0 20px 40px var(--vip-shadow);
|
||||
backdrop-filter: blur(16px);
|
||||
}
|
||||
|
||||
.benefit-card {
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
gap: 10px;
|
||||
min-height: 164px;
|
||||
padding: 20px 14px;
|
||||
border-radius: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.benefit-icon {
|
||||
display: grid;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
place-items: center;
|
||||
border-radius: 999px;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.benefit-card--rose .benefit-icon {
|
||||
color: var(--vip-primary);
|
||||
background: var(--vip-blush-soft);
|
||||
}
|
||||
|
||||
.benefit-card--gold .benefit-icon {
|
||||
color: var(--vip-gold);
|
||||
background: rgba(254, 212, 136, 0.72);
|
||||
}
|
||||
|
||||
.benefit-card--slate .benefit-icon {
|
||||
color: var(--vip-neutral);
|
||||
background: rgba(194, 193, 191, 0.48);
|
||||
}
|
||||
|
||||
.benefit-card--cream .benefit-icon {
|
||||
color: var(--vip-primary);
|
||||
background: var(--vip-surface-high);
|
||||
}
|
||||
|
||||
.benefit-card strong {
|
||||
color: var(--vip-text);
|
||||
font-size: 14px;
|
||||
font-weight: 850;
|
||||
}
|
||||
|
||||
.benefit-card p {
|
||||
display: -webkit-box;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
color: var(--vip-muted);
|
||||
font-size: 12px;
|
||||
line-height: 1.45;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
}
|
||||
|
||||
.member-info-section {
|
||||
padding: 18px;
|
||||
border-radius: 24px;
|
||||
}
|
||||
|
||||
.info-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.info-grid article {
|
||||
min-width: 0;
|
||||
padding: 13px;
|
||||
border: 1px solid var(--vip-outline-soft);
|
||||
border-radius: 16px;
|
||||
background: rgba(252, 242, 234, 0.78);
|
||||
}
|
||||
|
||||
.info-grid span,
|
||||
.history-copy span,
|
||||
.history-copy em,
|
||||
.history-amount span {
|
||||
display: block;
|
||||
color: var(--vip-muted);
|
||||
font-size: 12px;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.info-grid strong {
|
||||
display: block;
|
||||
margin-top: 6px;
|
||||
overflow-wrap: anywhere;
|
||||
color: var(--vip-text);
|
||||
font-size: 13px;
|
||||
font-weight: 800;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.plan-grid {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.plan-card {
|
||||
position: relative;
|
||||
display: grid;
|
||||
gap: 13px;
|
||||
padding: 24px;
|
||||
border-radius: 24px;
|
||||
}
|
||||
|
||||
.plan-card--featured {
|
||||
border-color: rgba(119, 90, 25, 0.24);
|
||||
background: linear-gradient(135deg, rgba(255, 250, 240, 0.92), rgba(254, 212, 136, 0.28));
|
||||
}
|
||||
|
||||
.plan-tag {
|
||||
justify-self: start;
|
||||
padding: 5px 11px;
|
||||
border-radius: 999px;
|
||||
color: var(--vip-primary);
|
||||
background: var(--vip-blush-soft);
|
||||
font-size: 10px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.plan-tag--featured {
|
||||
position: absolute;
|
||||
top: -11px;
|
||||
right: 22px;
|
||||
color: var(--vip-hero-text);
|
||||
background: var(--vip-gold);
|
||||
}
|
||||
|
||||
.plan-title {
|
||||
color: var(--vip-muted);
|
||||
}
|
||||
|
||||
.plan-price {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 5px;
|
||||
color: var(--vip-primary);
|
||||
}
|
||||
|
||||
.plan-price strong {
|
||||
font-family: Georgia, 'Times New Roman', serif;
|
||||
font-size: 40px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.plan-card p {
|
||||
margin: 0;
|
||||
color: var(--vip-muted);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.plan-card p b {
|
||||
color: var(--vip-primary);
|
||||
}
|
||||
|
||||
.plan-card button {
|
||||
width: 100%;
|
||||
min-height: 46px;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
color: var(--vip-hero-text);
|
||||
background: var(--vip-primary);
|
||||
font-size: 14px;
|
||||
font-weight: 850;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 14px 28px rgba(124, 83, 87, 0.2);
|
||||
}
|
||||
|
||||
.plan-card--featured button {
|
||||
background: var(--vip-gold);
|
||||
}
|
||||
|
||||
.history-card {
|
||||
overflow: hidden;
|
||||
border-radius: 24px;
|
||||
}
|
||||
|
||||
.history-row {
|
||||
display: grid;
|
||||
grid-template-columns: 42px minmax(0, 1fr) auto;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
padding: 16px;
|
||||
border-bottom: 1px solid var(--vip-outline-soft);
|
||||
}
|
||||
|
||||
.history-row:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.history-icon {
|
||||
display: grid;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
place-items: center;
|
||||
border-radius: 999px;
|
||||
color: var(--vip-muted);
|
||||
background: var(--vip-surface-high);
|
||||
}
|
||||
|
||||
.history-icon--income {
|
||||
color: var(--vip-primary);
|
||||
background: var(--vip-blush-soft);
|
||||
}
|
||||
|
||||
.history-copy {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.history-copy strong {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
color: var(--vip-text);
|
||||
font-size: 14px;
|
||||
font-weight: 850;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.history-copy em {
|
||||
margin-top: 3px;
|
||||
overflow: hidden;
|
||||
font-style: normal;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.history-amount {
|
||||
min-width: 88px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.history-amount strong {
|
||||
display: block;
|
||||
color: var(--vip-text);
|
||||
font-size: 13px;
|
||||
font-weight: 900;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.history-amount strong.income {
|
||||
color: var(--vip-gold);
|
||||
}
|
||||
|
||||
.load-more-button {
|
||||
width: 100%;
|
||||
min-height: 44px;
|
||||
border: 0;
|
||||
border-radius: 16px;
|
||||
color: var(--vip-primary);
|
||||
background: rgba(232, 180, 184, 0.22);
|
||||
font-weight: 850;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.plan-modal {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.modal-icon {
|
||||
display: grid;
|
||||
width: 54px;
|
||||
height: 54px;
|
||||
margin: 0 auto;
|
||||
place-items: center;
|
||||
border-radius: 999px;
|
||||
color: var(--vip-primary);
|
||||
background: var(--vip-blush-soft);
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
.plan-modal h3 {
|
||||
margin: 4px 0 0;
|
||||
font-size: 18px;
|
||||
font-weight: 850;
|
||||
}
|
||||
|
||||
.plan-modal p {
|
||||
margin: 0;
|
||||
color: var(--vip-muted);
|
||||
line-height: 1.65;
|
||||
}
|
||||
|
||||
@media (max-width: 370px) {
|
||||
.vip-main {
|
||||
padding-right: 14px;
|
||||
padding-left: 14px;
|
||||
}
|
||||
|
||||
.vip-hero-card {
|
||||
padding: 22px;
|
||||
}
|
||||
|
||||
.hero-stats,
|
||||
.benefit-grid,
|
||||
.info-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.vip-topbar {
|
||||
border-top-left-radius: 32px;
|
||||
border-top-right-radius: 32px;
|
||||
}
|
||||
|
||||
.plan-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,523 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<header class="header">
|
||||
<div class="back-btn" @click="handleBackClick">
|
||||
<el-icon><ArrowLeft /></el-icon>
|
||||
</div>
|
||||
<h1>我的收藏</h1>
|
||||
<div class="empty"></div>
|
||||
</header>
|
||||
|
||||
<div v-if="groups.length" class="group-tabs">
|
||||
<button
|
||||
class="group-tab"
|
||||
:class="{ 'group-tab--active': activeGroupId === null }"
|
||||
type="button"
|
||||
@click="activeGroupId = null"
|
||||
>
|
||||
All
|
||||
</button>
|
||||
<button
|
||||
v-for="group in groups"
|
||||
:key="String(group.id)"
|
||||
class="group-tab"
|
||||
:class="{ 'group-tab--active': sameId(activeGroupId, group.id) }"
|
||||
type="button"
|
||||
@click="activeGroupId = group.id"
|
||||
>
|
||||
{{ group.name }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="wishlist-items">
|
||||
<div v-for="item in visibleWishlistItems" :key="item.id" class="wishlist-item">
|
||||
<div class="item-image" @click="handleProductClick(item.product.id)">
|
||||
<img
|
||||
v-if="getProductImages(item.product).length > 0"
|
||||
:src="getProductImages(item.product)[0]"
|
||||
:alt="item.product.title"
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
/>
|
||||
<div v-else class="image-placeholder" :style="{ backgroundColor: getRandomColor() }">
|
||||
<span>{{ item.product.title ? item.product.title[0] : '作' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="item-details">
|
||||
<h3 class="item-name" @click="handleProductClick(item.product.id)">{{ item.product.title }}</h3>
|
||||
<div class="item-group">{{ item.groupName || '最近想做' }}</div>
|
||||
<p v-if="item.note" class="item-note">{{ item.note }}</p>
|
||||
<p class="item-price">¥{{ Number(item.product.price || 0).toFixed(2) }}</p>
|
||||
<div class="item-actions">
|
||||
<el-button
|
||||
size="small"
|
||||
:type="isProductInCart(item.product.id) ? 'info' : 'primary'"
|
||||
@click="handleAddToCart(item.product.id)"
|
||||
>
|
||||
{{ isProductInCart(item.product.id) ? '购物车已有' : '加入购物车' }}
|
||||
</el-button>
|
||||
<el-icon class="delete-icon" @click="handleRemoveItem(item.product.id)"><Delete /></el-icon>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="wishlistItems.length === 0" class="empty-wishlist">
|
||||
<el-icon :size="60" :style="{ color: 'var(--theme-primary)' }"><StarFilled /></el-icon>
|
||||
<p>收藏列表为空</p>
|
||||
<el-button type="primary" @click="handleBrowseProducts">
|
||||
浏览作品
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* WishlistView 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, onMounted, inject } from 'vue'
|
||||
import { ArrowLeft, Delete, StarFilled } from '@element-plus/icons-vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import 'element-plus/es/components/message/style/css'
|
||||
/**
|
||||
* Purpose: WishlistItem supports WishlistView.vue by holding or executing the wishlist item page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { wishlistApi, type WishlistGroup, type WishlistItem } from '@/api/wishlist'
|
||||
import { cartApi } from '@/api/cart'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { sameId } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { fetchCartProductIdSet, hasCartProduct, withAddedCartProduct } from '@/utils/cart-state'
|
||||
import { getCachedSignedImageUrls, getCachedSignedImageUrlsSync, parseImageFileIds } from '@/utils/signed-image-cache'
|
||||
|
||||
/**
|
||||
* Purpose: router supports WishlistView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const router = useRouter()
|
||||
/**
|
||||
* Purpose: updateCartCount supports WishlistView.vue by holding or executing the update cart count page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
||||
|
||||
/**
|
||||
* Purpose: wishlistItems supports WishlistView.vue by holding or executing the wishlist items page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const wishlistItems = ref<WishlistItem[]>([])
|
||||
const groups = ref<WishlistGroup[]>([])
|
||||
const activeGroupId = ref<IdType | null>(null)
|
||||
/**
|
||||
* Purpose: imageUrls supports WishlistView.vue by holding or executing the image urls page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const imageUrls = ref<Record<string, string[]>>({})
|
||||
/** cartProductIdSet is a reactive state variable used by the template and event handlers. */
|
||||
const cartProductIdSet = ref(new Set<string>())
|
||||
/**
|
||||
* Purpose: DEFAULT_PRODUCT_IMAGE supports WishlistView.vue by holding or executing the default product image page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const DEFAULT_PRODUCT_IMAGE = 'data:image/svg+xml;base64,PHN2ZyB3aW0dPSJodHRwOi8vd3d3Lm9yZy8yMDAwL3N2ZyI+Pjwvc3ZnPg=='
|
||||
|
||||
const visibleWishlistItems = computed(() => {
|
||||
if (activeGroupId.value === null) {
|
||||
return wishlistItems.value
|
||||
}
|
||||
return wishlistItems.value.filter(item => sameId(item.groupId, activeGroupId.value))
|
||||
})
|
||||
|
||||
/** handleBackClick is a local helper used by this page script. */
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
/** fetchWishlist is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const fetchWishlist = async () => {
|
||||
try {
|
||||
const [response, nextGroups, nextCartProductIdSet] = await Promise.all([
|
||||
wishlistApi.getWishlist(),
|
||||
wishlistApi.getGroups(),
|
||||
fetchCartProductIdSet()
|
||||
])
|
||||
cartProductIdSet.value = nextCartProductIdSet
|
||||
groups.value = nextGroups
|
||||
wishlistItems.value = response as unknown as WishlistItem[]
|
||||
await loadImageUrls(response as unknown as WishlistItem[])
|
||||
} catch (error: any) {
|
||||
console.error('获取收藏列表失败:', error)
|
||||
ElMessage.error(error?.message || '获取收藏列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
/** loadImageUrls is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadImageUrls = async (items: WishlistItem[]) => {
|
||||
for (const item of items) {
|
||||
if (item.product.imageFileIds) {
|
||||
const ids = parseImageFileIds(item.product.imageFileIds)
|
||||
const cachedUrls = getCachedSignedImageUrlsSync(ids)
|
||||
if (cachedUrls.length) {
|
||||
imageUrls.value[String(item.product.id)] = cachedUrls
|
||||
}
|
||||
|
||||
const urls = await getCachedSignedImageUrls(ids, DEFAULT_PRODUCT_IMAGE)
|
||||
imageUrls.value[String(item.product.id)] = urls.length ? urls : [DEFAULT_PRODUCT_IMAGE]
|
||||
} else {
|
||||
imageUrls.value[String(item.product.id)] = [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
}
|
||||
}
|
||||
/** getProductImages is a local helper used by this page script. */
|
||||
const getProductImages = (product: any): string[] => {
|
||||
return imageUrls.value[String(product.id)] || [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
|
||||
/** isProductInCart is a local helper used by this page script. */
|
||||
const isProductInCart = (productId: IdType) => hasCartProduct(cartProductIdSet.value, productId)
|
||||
|
||||
/** handleAddToCart is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleAddToCart = async (productId: IdType) => {
|
||||
if (isProductInCart(productId)) {
|
||||
ElMessage.info('购物车已有')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithGlobalLoading(() => cartApi.addToCart({ productId, quantity: 1 }))
|
||||
cartProductIdSet.value = withAddedCartProduct(cartProductIdSet.value, productId)
|
||||
await updateCartCount()
|
||||
ElMessage.success('已添加到购物车')
|
||||
} catch (error: any) {
|
||||
console.error('添加到购物车失败:', error)
|
||||
ElMessage.error(error?.message || '添加到购物车失败')
|
||||
}
|
||||
}
|
||||
|
||||
/** handleRemoveItem is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleRemoveItem = async (productId: IdType) => {
|
||||
try {
|
||||
await runWithGlobalLoading(() => wishlistApi.removeFromWishlist(productId))
|
||||
wishlistItems.value = wishlistItems.value.filter(item => !sameId(item.productId, productId))
|
||||
ElMessage.success('已从收藏中移除')
|
||||
} catch (error: any) {
|
||||
console.error('移除收藏失败:', error)
|
||||
ElMessage.error(error?.message || '移除收藏失败')
|
||||
}
|
||||
}
|
||||
|
||||
/** handleBrowseProducts is a local helper used by this page script. */
|
||||
const handleBrowseProducts = () => {
|
||||
router.push('/products')
|
||||
}
|
||||
|
||||
/** handleProductClick is a local helper used by this page script. */
|
||||
const handleProductClick = (productId: IdType) => {
|
||||
router.push(`/product/${productId}`)
|
||||
}
|
||||
|
||||
/** getRandomColor is a local helper used by this page script. */
|
||||
const getRandomColor = () => {
|
||||
return 'var(--theme-primary-soft)'
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchWishlist()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
padding-top: 60px;
|
||||
background:
|
||||
linear-gradient(rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.92)),
|
||||
var(--theme-background-image),
|
||||
var(--theme-page-bg);
|
||||
background-size: cover, cover, auto;
|
||||
background-position: center top;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
height: 60px;
|
||||
padding: 10px 15px;
|
||||
background: rgba(255, 255, 255, 0.92);
|
||||
border-bottom: 1px solid var(--theme-border);
|
||||
backdrop-filter: blur(14px);
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.empty {
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.group-tabs {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
overflow-x: auto;
|
||||
padding: 14px 16px 0;
|
||||
}
|
||||
|
||||
.group-tab {
|
||||
flex: 0 0 auto;
|
||||
height: 32px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid var(--theme-border);
|
||||
border-radius: 8px;
|
||||
background: var(--theme-card-bg);
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 30px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.group-tab--active {
|
||||
border-color: var(--theme-primary);
|
||||
background: var(--theme-primary-soft);
|
||||
color: var(--theme-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.wishlist-items {
|
||||
padding: 16px;
|
||||
padding-bottom: 28px;
|
||||
}
|
||||
|
||||
.wishlist-item {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
padding: 15px;
|
||||
background: var(--theme-card-bg);
|
||||
border: 1px solid var(--theme-border);
|
||||
border-radius: 16px;
|
||||
margin-bottom: 15px;
|
||||
box-shadow: 0 14px 34px rgba(122, 67, 88, 0.08);
|
||||
}
|
||||
|
||||
.item-image {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.item-image img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.image-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 30px;
|
||||
font-weight: bold;
|
||||
color: rgba(0, 0, 0, 0.1);
|
||||
border: 1px solid var(--theme-border);
|
||||
}
|
||||
|
||||
.item-details {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.item-name {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
margin: 0 0 5px 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.item-group {
|
||||
width: fit-content;
|
||||
max-width: 100%;
|
||||
margin-bottom: 6px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 8px;
|
||||
background: var(--theme-primary-soft);
|
||||
color: var(--theme-accent);
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
.item-note {
|
||||
margin: 0 0 8px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 18px;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.item-price {
|
||||
color: var(--theme-primary);
|
||||
font-weight: bold;
|
||||
margin: 0 0 10px 0;
|
||||
}
|
||||
|
||||
.item-actions {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.delete-icon {
|
||||
color: var(--theme-accent);
|
||||
cursor: pointer;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.empty-wishlist {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 16px;
|
||||
padding: 64px 20px;
|
||||
color: var(--text-secondary);
|
||||
background: var(--theme-card-bg);
|
||||
border: 1px solid var(--theme-border);
|
||||
border-radius: 18px;
|
||||
box-shadow: 0 14px 34px rgba(122, 67, 88, 0.08);
|
||||
}
|
||||
|
||||
.empty-wishlist p {
|
||||
margin: 20px 0;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
:deep(.el-button--primary) {
|
||||
--el-button-bg-color: var(--theme-primary);
|
||||
--el-button-border-color: var(--theme-primary);
|
||||
--el-button-hover-bg-color: var(--theme-accent);
|
||||
--el-button-hover-border-color: var(--theme-accent);
|
||||
}
|
||||
|
||||
:deep(.el-button--info) {
|
||||
--el-button-bg-color: var(--theme-primary-soft);
|
||||
--el-button-border-color: var(--theme-border);
|
||||
--el-button-text-color: var(--theme-accent);
|
||||
--el-button-hover-bg-color: var(--theme-primary-soft);
|
||||
--el-button-hover-border-color: var(--theme-border);
|
||||
--el-button-hover-text-color: var(--theme-accent);
|
||||
}
|
||||
|
||||
.mobile-container {
|
||||
padding-top: 68px;
|
||||
background:
|
||||
radial-gradient(circle at 84% 0%, color-mix(in srgb, var(--theme-primary) 26%, transparent), transparent 32%),
|
||||
linear-gradient(180deg, color-mix(in srgb, var(--theme-card-bg) 76%, transparent), var(--theme-page-bg));
|
||||
}
|
||||
|
||||
.header {
|
||||
height: 64px;
|
||||
padding: 12px 18px 10px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 92%, transparent);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 17px;
|
||||
font-weight: 820;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 74%, transparent);
|
||||
}
|
||||
|
||||
.group-tabs {
|
||||
padding: 16px 18px 0;
|
||||
}
|
||||
|
||||
.group-tab {
|
||||
height: 34px;
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 84%, transparent);
|
||||
}
|
||||
|
||||
.group-tab--active {
|
||||
border-color: color-mix(in srgb, var(--theme-primary) 40%, var(--theme-border));
|
||||
background: color-mix(in srgb, var(--theme-primary) 20%, var(--theme-card-bg));
|
||||
color: var(--theme-primary-action);
|
||||
}
|
||||
|
||||
.wishlist-items {
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
.wishlist-item {
|
||||
border-radius: 24px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 90%, transparent);
|
||||
box-shadow: 0 18px 42px color-mix(in srgb, var(--theme-neutral) 8%, transparent);
|
||||
}
|
||||
|
||||
.item-image {
|
||||
width: 92px;
|
||||
height: 92px;
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.item-name {
|
||||
font-weight: 820;
|
||||
}
|
||||
|
||||
.item-group {
|
||||
border-radius: 999px;
|
||||
color: var(--theme-primary-action);
|
||||
background: color-mix(in srgb, var(--theme-primary) 18%, var(--theme-card-bg));
|
||||
}
|
||||
|
||||
.item-price {
|
||||
color: var(--theme-primary-action);
|
||||
}
|
||||
|
||||
.empty-wishlist {
|
||||
border-radius: 24px;
|
||||
background: color-mix(in srgb, var(--theme-card-bg) 90%, transparent);
|
||||
box-shadow: 0 18px 42px color-mix(in srgb, var(--theme-neutral) 8%, transparent);
|
||||
}
|
||||
|
||||
:deep(.el-button--primary) {
|
||||
--el-button-bg-color: var(--theme-primary-action);
|
||||
--el-button-border-color: var(--theme-primary-action);
|
||||
--el-button-hover-bg-color: var(--theme-secondary);
|
||||
--el-button-hover-border-color: var(--theme-secondary);
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,514 @@
|
||||
<template>
|
||||
<div class="admin-login">
|
||||
<div class="login-container">
|
||||
<div class="login-header">
|
||||
<h1>后台管理系统</h1>
|
||||
<p>欢迎回来,请登录您的账户</p>
|
||||
</div>
|
||||
|
||||
<a-card class="login-card">
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
layout="vertical"
|
||||
@finish="handleLogin"
|
||||
>
|
||||
<a-alert
|
||||
v-if="loginShopMessage"
|
||||
:type="allowShoplessLogin || hasAvailableShops ? 'info' : 'warning'"
|
||||
show-icon
|
||||
:message="loginShopMessage"
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
|
||||
<a-form-item label="用户名" name="account">
|
||||
<a-input
|
||||
v-model:value="formState.account"
|
||||
size="large"
|
||||
placeholder="请输入用户名"
|
||||
:prefix-icon="UserOutlined"
|
||||
@input="handleAccountInput"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="密码" name="password">
|
||||
<a-input-password
|
||||
v-model:value="formState.password"
|
||||
size="large"
|
||||
placeholder="请输入密码"
|
||||
:prefix-icon="LockOutlined"
|
||||
@pressEnter="handleLogin"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="hasAvailableShops || !allowShoplessLogin" label="登录店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
size="large"
|
||||
:placeholder="shopPlaceholder"
|
||||
:loading="shopLoading"
|
||||
:options="shopOptions"
|
||||
:disabled="shopLoading || (!hasAvailableShops && !allowShoplessLogin)"
|
||||
show-search
|
||||
:filter-option="filterShopOption"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
size="large"
|
||||
html-type="submit"
|
||||
:loading="loading"
|
||||
block
|
||||
>
|
||||
登录
|
||||
</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
|
||||
<div class="login-footer">
|
||||
<a @click="goToFrontend">返回前台</a>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</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'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||
/**
|
||||
* Purpose: LoginShopSelectionResponse supports AdminLoginView.vue by holding or executing the login shop selection response page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { adminAuthApi, type LoginShopSelectionResponse } from '@/api/admin'
|
||||
import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { resolveAdminLandingPath } from '@/utils/admin-auth-bootstrap'
|
||||
|
||||
/**
|
||||
* Purpose: router supports AdminLoginView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const router = useRouter()
|
||||
/**
|
||||
* Purpose: formRef supports AdminLoginView.vue by holding or executing the form ref page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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)
|
||||
/**
|
||||
* Purpose: shops supports AdminLoginView.vue by holding or executing the shops page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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()
|
||||
|
||||
/**
|
||||
* Purpose: formState supports AdminLoginView.vue by holding or executing the form state page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formState = reactive({
|
||||
account: '',
|
||||
password: '',
|
||||
shopId: undefined as string | undefined
|
||||
})
|
||||
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) {
|
||||
formState.account = normalized
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 (shopLoading.value) {
|
||||
return '正在加载可登录店铺'
|
||||
}
|
||||
if (hasAvailableShops.value) {
|
||||
return allowShoplessLogin.value ? '可选择本次登录店铺,留空进入平台总览' : '请选择登录店铺'
|
||||
}
|
||||
if (allowShoplessLogin.value) {
|
||||
return '当前无需选择店铺'
|
||||
}
|
||||
return '请先输入账号'
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: formRules supports AdminLoginView.vue by holding or executing the form rules page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formRules = {
|
||||
account: [
|
||||
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||||
{ pattern: ACCOUNT_REGEX, message: ACCOUNT_RULE_MESSAGE, trigger: 'blur' }
|
||||
],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
shopId: [{
|
||||
validator: async () => {
|
||||
if (!shouldRequireShop.value || formState.shopId) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
return Promise.reject(new Error('请选择登录店铺'))
|
||||
},
|
||||
trigger: 'change'
|
||||
}]
|
||||
} 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)
|
||||
loginShopTimer = undefined
|
||||
}
|
||||
}
|
||||
|
||||
/** restoreLoginShop is a local helper used by this page script. */
|
||||
const restoreLoginShop = () => {
|
||||
const cached = localStorage.getItem('adminUserInfo')
|
||||
if (!cached) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(cached)
|
||||
if (parsed?.type === 4) {
|
||||
return
|
||||
}
|
||||
if (parsed?.shopId) {
|
||||
formState.shopId = String(parsed.shopId)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('恢复后台登录店铺失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/** applyLoginShopSelection is a local helper used by this page script. */
|
||||
const applyLoginShopSelection = (selection?: LoginShopSelectionResponse | null) => {
|
||||
shops.value = selection?.shops || []
|
||||
allowShoplessLogin.value = Boolean(selection?.allowShoplessLogin)
|
||||
loginShopMessage.value = selection?.message || ''
|
||||
|
||||
if (!shops.value.length) {
|
||||
formState.shopId = undefined
|
||||
return
|
||||
}
|
||||
|
||||
const matchedShop = shops.value.find(shop => getShopIdValue(shop) === formState.shopId)
|
||||
if (matchedShop) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!allowShoplessLogin.value && shops.value.length === 1) {
|
||||
formState.shopId = getShopIdValue(shops.value[0]!)
|
||||
return
|
||||
}
|
||||
|
||||
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) {
|
||||
applyLoginShopSelection(null)
|
||||
return
|
||||
}
|
||||
|
||||
shopLoading.value = true
|
||||
try {
|
||||
const selection = await adminAuthApi.getLoginShops(trimmedAccount) as unknown as LoginShopSelectionResponse
|
||||
if (formState.account.trim() === trimmedAccount) {
|
||||
applyLoginShopSelection(selection)
|
||||
}
|
||||
} catch (error) {
|
||||
if (formState.account.trim() === trimmedAccount) {
|
||||
if (isLoginShopPrefetchUnsupported(error)) {
|
||||
applyLoginShopSelection({
|
||||
allowShoplessLogin: true,
|
||||
message: '可直接登录;如账号绑定多家门店,登录后可在个人中心切换当前门店。',
|
||||
shops: []
|
||||
})
|
||||
} else {
|
||||
applyLoginShopSelection(null)
|
||||
loginShopMessage.value = '登录店铺加载失败,请稍后重试'
|
||||
}
|
||||
}
|
||||
if (!isLoginShopPrefetchUnsupported(error)) {
|
||||
console.error('获取登录店铺列表失败:', error)
|
||||
}
|
||||
} finally {
|
||||
shopLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 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()
|
||||
loading.value = true
|
||||
|
||||
const res = await runWithGlobalLoading(() => adminAuthApi.login({
|
||||
account: formState.account,
|
||||
password: formState.password,
|
||||
shopId: formState.shopId
|
||||
}))
|
||||
|
||||
|
||||
const { accessToken, refreshToken, userInfo } = res as any
|
||||
|
||||
localStorage.setItem('adminAccessToken', accessToken)
|
||||
localStorage.setItem('adminRefreshToken', refreshToken)
|
||||
localStorage.setItem('adminUserInfo', JSON.stringify(userInfo))
|
||||
sessionStorage.setItem('adminAccessToken', accessToken)
|
||||
sessionStorage.setItem('adminRefreshToken', refreshToken)
|
||||
|
||||
|
||||
message.success('登录成功')
|
||||
|
||||
await runWithGlobalLoading(() => loadUserPermissions())
|
||||
|
||||
const landingPath = resolveAdminLandingPath()
|
||||
router.push(landingPath).catch(err => {
|
||||
console.error('跳转到后台默认页面失败:', err)
|
||||
window.location.href = landingPath
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error('登录失败:', error)
|
||||
message.error(error.message || '登录失败,请检查用户名和密码')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
restoreLoginShop()
|
||||
})
|
||||
|
||||
watch(
|
||||
() => formState.account,
|
||||
value => {
|
||||
resetLoginShopTimer()
|
||||
const trimmedAccount = value.trim()
|
||||
if (!trimmedAccount) {
|
||||
applyLoginShopSelection(null)
|
||||
return
|
||||
}
|
||||
loginShopTimer = window.setTimeout(() => {
|
||||
loginShopTimer = undefined
|
||||
void loadLoginShops(trimmedAccount)
|
||||
}, 400)
|
||||
}
|
||||
)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
resetLoginShopTimer()
|
||||
})
|
||||
|
||||
/** goToFrontend is a local helper used by this page script. */
|
||||
const goToFrontend = () => {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
sessionStorage.removeItem('adminRefreshToken')
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = '/'
|
||||
}, 100)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-login {
|
||||
min-height: 100dvh;
|
||||
background:
|
||||
linear-gradient(color-mix(in srgb, var(--theme-page-bg) 74%, transparent), color-mix(in srgb, var(--theme-page-bg) 90%, transparent)),
|
||||
var(--theme-background-image),
|
||||
linear-gradient(
|
||||
160deg,
|
||||
var(--theme-primary) 0%,
|
||||
var(--theme-accent) 58%,
|
||||
color-mix(in srgb, var(--theme-accent) 78%, var(--text-primary)) 100%
|
||||
);
|
||||
background-size: cover, cover, auto;
|
||||
background-position: center top;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.login-container {
|
||||
width: 100%;
|
||||
max-width: 440px;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: center;
|
||||
margin-bottom: 28px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: clamp(23px, 3.2vw, 28px);
|
||||
font-weight: 700;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.login-header p {
|
||||
font-size: 14px;
|
||||
line-height: 1.7;
|
||||
opacity: 0.82;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
border-radius: 24px;
|
||||
border: 1px solid var(--theme-border);
|
||||
box-shadow: var(--theme-button-shadow);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.login-footer {
|
||||
text-align: center;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.login-footer a {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 36px;
|
||||
padding: 0 14px;
|
||||
border-radius: 999px;
|
||||
color: var(--theme-primary);
|
||||
background: var(--theme-primary-soft);
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
box-shadow: 0 8px 20px color-mix(in srgb, var(--theme-primary) 18%, transparent);
|
||||
}
|
||||
|
||||
.login-footer a:hover {
|
||||
color: var(--theme-accent);
|
||||
background: var(--theme-card-bg);
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-card-body) {
|
||||
background: var(--theme-card-bg);
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-btn-primary) {
|
||||
border-color: transparent;
|
||||
background: var(--theme-gradient);
|
||||
box-shadow: var(--theme-button-shadow);
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-btn-primary:hover),
|
||||
.login-card :deep(.ant-btn-primary:focus) {
|
||||
border-color: transparent;
|
||||
background: linear-gradient(135deg, var(--theme-accent) 0%, var(--theme-secondary) 100%);
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-input:hover),
|
||||
.login-card :deep(.ant-input-affix-wrapper:hover),
|
||||
.login-card :deep(.ant-select:not(.ant-select-disabled):hover .ant-select-selector) {
|
||||
border-color: var(--theme-primary);
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-input:focus),
|
||||
.login-card :deep(.ant-input-affix-wrapper-focused),
|
||||
.login-card :deep(.ant-select-focused .ant-select-selector) {
|
||||
border-color: var(--theme-primary);
|
||||
box-shadow: var(--theme-focus-shadow);
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.admin-login {
|
||||
align-items: flex-start;
|
||||
justify-content: stretch;
|
||||
padding: calc(22px + env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.login-container {
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: left;
|
||||
margin-bottom: 18px;
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
max-width: 8em;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
border-radius: 26px;
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-card-body) {
|
||||
padding: 20px 18px 18px;
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-form-item) {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-btn-lg),
|
||||
.login-card :deep(.ant-input-affix-wrapper-lg),
|
||||
.login-card :deep(.ant-input-lg),
|
||||
.login-card :deep(.ant-select-single.ant-select-lg .ant-select-selector) {
|
||||
min-height: 48px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,295 @@
|
||||
<template>
|
||||
<div class="after-sales">
|
||||
<a-page-header v-if="!isMobile" title="售后处理" sub-title="处理客户退款与售后申请" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">售后</span>
|
||||
<h1 class="admin-page-intro__title">售后处理</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">申请 {{ pagination.total }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">售后列表</template>
|
||||
|
||||
<AdminFilterPanel :active-count="activeFilterCount">
|
||||
<a-select
|
||||
v-model:value="statusFilter"
|
||||
:options="statusOptions"
|
||||
style="width: 160px"
|
||||
@change="reload"
|
||||
/>
|
||||
<a-button @click="resetFilters">重置筛选</a-button>
|
||||
</AdminFilterPanel>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="visibleAfterSales"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
row-key="id"
|
||||
:scroll="{ x: 'max-content' }"
|
||||
@change="handleTableChange"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'status'">
|
||||
<a-tag :color="statusColor(record.status)">{{ statusText(record.status) }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'amount'">¥{{ money(record.refundAmount) }}</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="currentAfterSale = record as AfterSaleVO">查看</a-button>
|
||||
<a-button v-if="record.status === 'PENDING'" type="primary" size="small" @click="openAudit(record as AfterSaleVO, 'approve')">通过</a-button>
|
||||
<a-button v-if="record.status === 'PENDING'" danger size="small" @click="openAudit(record as AfterSaleVO, 'reject')">驳回</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="visibleAfterSales" empty-description="暂无售后申请">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.afterSaleNo || `售后 ${item.id}` }}</div>
|
||||
<div class="admin-mobile-card__subtitle">订单 {{ item.orderId }} · {{ item.createTime || '-' }}</div>
|
||||
</div>
|
||||
<a-tag :color="statusColor(item.status)">{{ statusText(item.status) }}</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>类型</span>
|
||||
<strong>{{ typeText(item.type) }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>退款金额</span>
|
||||
<strong>¥{{ money(item.refundAmount) }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>原因</span>
|
||||
<strong>{{ item.reason || '-' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button size="small" @click="currentAfterSale = item">查看</a-button>
|
||||
<a-button v-if="item.status === 'PENDING'" type="primary" size="small" @click="openAudit(item, 'approve')">通过</a-button>
|
||||
<a-button v-if="item.status === 'PENDING'" danger size="small" @click="openAudit(item, 'reject')">驳回</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="detailOpen"
|
||||
title="售后详情"
|
||||
:desktop-width="760"
|
||||
:footer="null"
|
||||
@cancel="currentAfterSale = null"
|
||||
>
|
||||
<a-descriptions v-if="currentAfterSale" bordered :column="1" size="small">
|
||||
<a-descriptions-item label="售后单号">{{ currentAfterSale.afterSaleNo || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="订单ID">{{ currentAfterSale.orderId }}</a-descriptions-item>
|
||||
<a-descriptions-item label="订单项ID">{{ currentAfterSale.orderItemId || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="用户ID">{{ currentAfterSale.userId || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="类型">{{ typeText(currentAfterSale.type) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="退款金额">¥{{ money(currentAfterSale.refundAmount) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="状态">{{ statusText(currentAfterSale.status) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="申请原因">{{ currentAfterSale.reason || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="审核原因">{{ currentAfterSale.auditReason || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="申请时间">{{ currentAfterSale.createTime || '-' }}</a-descriptions-item>
|
||||
</a-descriptions>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="auditOpen"
|
||||
:title="auditAction === 'approve' ? '通过售后' : '驳回售后'"
|
||||
:desktop-width="620"
|
||||
:confirm-loading="auditing"
|
||||
@ok="submitAudit"
|
||||
@cancel="closeAudit"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
<a-alert
|
||||
v-if="auditTarget"
|
||||
class="audit-alert"
|
||||
type="info"
|
||||
show-icon
|
||||
:message="`${auditTarget.afterSaleNo || auditTarget.id} · 退款 ¥${money(auditTarget.refundAmount)}`"
|
||||
:description="auditTarget.reason || '暂无申请原因'"
|
||||
/>
|
||||
<a-form-item label="处理备注">
|
||||
<a-textarea v-model:value="auditReason" :rows="4" :maxlength="300" placeholder="填写给客户和门店留痕的处理说明" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { adminAfterSaleApi, type AfterSaleVO } from '@/api/admin'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminFilterPanel from '@/components/admin/AdminFilterPanel.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { isMobile } = useAdminViewport()
|
||||
const route = useRoute()
|
||||
const loading = ref(false)
|
||||
const auditing = ref(false)
|
||||
const statusFilter = ref('all')
|
||||
const afterSales = ref<AfterSaleVO[]>([])
|
||||
const currentAfterSale = ref<AfterSaleVO | null>(null)
|
||||
const auditOpen = ref(false)
|
||||
const auditTarget = ref<AfterSaleVO | null>(null)
|
||||
const auditAction = ref<'approve' | 'reject'>('approve')
|
||||
const auditReason = ref('')
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const detailOpen = computed({
|
||||
get: () => !!currentAfterSale.value,
|
||||
set: value => { if (!value) currentAfterSale.value = null }
|
||||
})
|
||||
|
||||
const activeFilterCount = computed(() => statusFilter.value === 'all' ? 0 : 1)
|
||||
|
||||
const visibleAfterSales = computed(() => {
|
||||
const orderId = route.query.orderId
|
||||
if (!orderId) {
|
||||
return afterSales.value
|
||||
}
|
||||
return afterSales.value.filter(item => String(item.orderId) === String(orderId))
|
||||
})
|
||||
|
||||
const statusOptions = [
|
||||
{ label: '全部状态', value: 'all' },
|
||||
{ label: '待处理', value: 'PENDING' },
|
||||
{ label: '已通过', value: 'APPROVED' },
|
||||
{ label: '已驳回', value: 'REJECTED' }
|
||||
]
|
||||
|
||||
const columns = [
|
||||
{ title: '售后单号', dataIndex: 'afterSaleNo', key: 'afterSaleNo' },
|
||||
{ title: '订单ID', dataIndex: 'orderId', key: 'orderId', width: 110 },
|
||||
{ title: '用户ID', dataIndex: 'userId', key: 'userId', width: 110 },
|
||||
{ title: '类型', dataIndex: 'type', key: 'type', width: 110 },
|
||||
{ title: '退款金额', key: 'amount', width: 120 },
|
||||
{ title: '状态', key: 'status', width: 110 },
|
||||
{ title: '申请时间', dataIndex: 'createTime', key: 'createTime', width: 180 },
|
||||
{ title: '操作', key: 'actions', width: 190 }
|
||||
]
|
||||
|
||||
const money = (value?: number) => Number(value || 0).toFixed(2)
|
||||
const typeText = (type?: string) => {
|
||||
if (type === 'REFUND') return '退款'
|
||||
if (type === 'AFTER_SALE') return '售后'
|
||||
return type || '-'
|
||||
}
|
||||
const statusText = (status?: string) => {
|
||||
if (status === 'PENDING') return '待处理'
|
||||
if (status === 'APPROVED') return '已通过'
|
||||
if (status === 'REJECTED') return '已驳回'
|
||||
return status || '-'
|
||||
}
|
||||
const statusColor = (status?: string) => {
|
||||
if (status === 'PENDING') return 'orange'
|
||||
if (status === 'APPROVED') return 'green'
|
||||
if (status === 'REJECTED') return 'red'
|
||||
return 'default'
|
||||
}
|
||||
|
||||
const loadAfterSales = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await adminAfterSaleApi.listAfterSales({
|
||||
status: statusFilter.value === 'all' ? undefined : statusFilter.value,
|
||||
page: pagination.current,
|
||||
size: pagination.pageSize
|
||||
})
|
||||
afterSales.value = result.list || []
|
||||
pagination.total = result.total || 0
|
||||
} catch (error) {
|
||||
console.error('加载售后失败:', error)
|
||||
message.error('加载售后失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const reload = () => {
|
||||
pagination.current = 1
|
||||
void loadAfterSales()
|
||||
}
|
||||
|
||||
const resetFilters = () => {
|
||||
statusFilter.value = 'all'
|
||||
reload()
|
||||
}
|
||||
|
||||
const handleTableChange = (pag: any) => {
|
||||
pagination.current = pag.current || 1
|
||||
pagination.pageSize = pag.pageSize || pagination.pageSize
|
||||
void loadAfterSales()
|
||||
}
|
||||
|
||||
const openAudit = (record: AfterSaleVO, action: 'approve' | 'reject') => {
|
||||
auditTarget.value = record
|
||||
auditAction.value = action
|
||||
auditReason.value = ''
|
||||
auditOpen.value = true
|
||||
}
|
||||
|
||||
const closeAudit = () => {
|
||||
auditOpen.value = false
|
||||
auditTarget.value = null
|
||||
auditReason.value = ''
|
||||
}
|
||||
|
||||
const submitAudit = async () => {
|
||||
if (!auditTarget.value) return
|
||||
auditing.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
const payload = { auditReason: auditReason.value.trim() || undefined }
|
||||
if (auditAction.value === 'approve') {
|
||||
await adminAfterSaleApi.approveAfterSale(auditTarget.value!.id, payload)
|
||||
} else {
|
||||
await adminAfterSaleApi.rejectAfterSale(auditTarget.value!.id, payload)
|
||||
}
|
||||
await loadAfterSales()
|
||||
})
|
||||
message.success('售后已处理')
|
||||
closeAudit()
|
||||
} catch (error: any) {
|
||||
console.error('处理售后失败:', error)
|
||||
message.error(error?.message || '处理售后失败')
|
||||
} finally {
|
||||
auditing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadAfterSales)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.after-sales {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.audit-alert {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,216 @@
|
||||
<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
|
||||
class="announcement-table"
|
||||
:columns="columns"
|
||||
:data-source="announcements"
|
||||
:loading="loading"
|
||||
row-key="id"
|
||||
:scroll="{ x: 'max-content' }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'content'">
|
||||
<span class="ellipsis">{{ extractRichText(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="发布公告" :mask-closable="false" @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" placeholder="支持 HTML / Markdown,也可以直接输入纯文本" />
|
||||
</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, h, onMounted, reactive, ref } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
/**
|
||||
* Purpose: AnnouncementVO supports AnnouncementsView.vue by holding or executing the announcement vo page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { adminAnnouncementApi, type AnnouncementVO, type MessageTargetOptionsVO } from '@/api/admin'
|
||||
import { extractRichText, renderRichContent } from '@/utils/rich-content'
|
||||
|
||||
/** 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)
|
||||
/**
|
||||
* Purpose: announcements supports AnnouncementsView.vue by holding or executing the announcements page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const announcements = ref<AnnouncementVO[]>([])
|
||||
/**
|
||||
* Purpose: options supports AnnouncementsView.vue by holding or executing the options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const options = ref<MessageTargetOptionsVO>({ shops: [], users: [] })
|
||||
/**
|
||||
* Purpose: form supports AnnouncementsView.vue by holding or executing the form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const form = reactive<any>({ title: '', content: '', targetType: 'PLATFORM_ALL', shopIds: [], userIds: [], sortOrder: 0 })
|
||||
|
||||
/**
|
||||
* Purpose: columns supports AnnouncementsView.vue by holding or executing the columns page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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 }
|
||||
]
|
||||
|
||||
/**
|
||||
* Purpose: targetOptions supports AnnouncementsView.vue by holding or executing the target options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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,
|
||||
width: 560,
|
||||
content: h('div', {
|
||||
class: 'announcement-preview-content',
|
||||
innerHTML: renderRichContent(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: var(--text-secondary); }
|
||||
.ellipsis { display: inline-block; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
|
||||
.announcement-table :deep(.ant-table) { min-width: 880px; }
|
||||
.announcement-table :deep(.ant-table-cell) { white-space: nowrap; word-break: keep-all; overflow-wrap: normal; }
|
||||
.announcement-table :deep(.ant-table-content) { overflow-x: auto; }
|
||||
:global(.announcement-preview-content) { line-height: 1.8; overflow-wrap: break-word; }
|
||||
:global(.announcement-preview-content *) { max-width: 100%; }
|
||||
:global(.announcement-preview-content p),
|
||||
:global(.announcement-preview-content ul),
|
||||
:global(.announcement-preview-content ol),
|
||||
:global(.announcement-preview-content blockquote),
|
||||
:global(.announcement-preview-content pre),
|
||||
:global(.announcement-preview-content table) { margin: 0 0 12px; }
|
||||
:global(.announcement-preview-content p:last-child),
|
||||
:global(.announcement-preview-content ul:last-child),
|
||||
:global(.announcement-preview-content ol:last-child),
|
||||
:global(.announcement-preview-content blockquote:last-child),
|
||||
:global(.announcement-preview-content pre:last-child),
|
||||
:global(.announcement-preview-content table:last-child) { margin-bottom: 0; }
|
||||
:global(.announcement-preview-content ul),
|
||||
:global(.announcement-preview-content ol) { padding-left: 1.25em; }
|
||||
:global(.announcement-preview-content img) { display: block; max-width: 100%; border-radius: 8px; }
|
||||
:global(.announcement-preview-content pre) { overflow-x: auto; padding: 10px 12px; border-radius: 8px; background: var(--theme-primary-soft); }
|
||||
</style>
|
||||
@@ -0,0 +1,312 @@
|
||||
<template>
|
||||
<div class="campaigns">
|
||||
<a-page-header v-if="!isMobile" title="活动管理" sub-title="维护营销活动、推荐位和关联资源" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">活动</span>
|
||||
<h1 class="admin-page-intro__title">活动管理</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">活动 {{ pagination.total }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">活动列表</template>
|
||||
<template #extra>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-button type="primary" @click="openCreateModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增活动
|
||||
</a-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<AdminFilterPanel :active-count="activeFilterCount">
|
||||
<a-select
|
||||
v-model:value="statusFilter"
|
||||
:options="statusOptions"
|
||||
style="width: 160px"
|
||||
@change="reload"
|
||||
/>
|
||||
<a-button @click="resetFilters">重置筛选</a-button>
|
||||
</AdminFilterPanel>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="campaigns"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
row-key="id"
|
||||
:scroll="{ x: 'max-content' }"
|
||||
@change="handleTableChange"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 0 ? 'red' : 'green'">{{ campaignStatusText(record.status) }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'time'">
|
||||
{{ record.startTime || '-' }} 至 {{ record.endTime || '-' }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-button type="link" size="small" @click="openEditModal(record as CampaignVO)">编辑</a-button>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="campaigns" empty-description="暂无活动数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.title }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.scene || 'GENERAL' }} · 排序 {{ item.sortOrder ?? 0 }}</div>
|
||||
</div>
|
||||
<a-tag :color="item.status === 0 ? 'red' : 'green'">{{ campaignStatusText(item.status) }}</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>时间</span>
|
||||
<strong>{{ item.startTime || '-' }} 至 {{ item.endTime || '-' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>作品ID</span>
|
||||
<strong>{{ item.productIds || '-' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>优惠券ID</span>
|
||||
<strong>{{ item.couponIds || '-' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button size="small" @click="openEditModal(item)">编辑</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="modalOpen"
|
||||
:title="editingCampaign ? '编辑活动' : '新增活动'"
|
||||
:desktop-width="760"
|
||||
:confirm-loading="saving"
|
||||
@ok="saveCampaign"
|
||||
@cancel="closeModal"
|
||||
>
|
||||
<a-form ref="formRef" :model="formState" :rules="rules" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
|
||||
<a-form-item label="活动标题" name="title">
|
||||
<a-input v-model:value="formState.title" placeholder="请输入活动标题" />
|
||||
</a-form-item>
|
||||
<a-form-item label="活动场景">
|
||||
<a-input v-model:value="formState.scene" placeholder="HOME / DETAIL / POPUP" />
|
||||
</a-form-item>
|
||||
<a-form-item label="活动说明">
|
||||
<a-textarea v-model:value="formState.description" :rows="3" :maxlength="500" />
|
||||
</a-form-item>
|
||||
<a-form-item label="关联作品ID">
|
||||
<a-input v-model:value="formState.productIds" placeholder="多个 ID 用英文逗号分隔" />
|
||||
</a-form-item>
|
||||
<a-form-item label="关联券ID">
|
||||
<a-input v-model:value="formState.couponIds" placeholder="多个 ID 用英文逗号分隔" />
|
||||
</a-form-item>
|
||||
<a-form-item label="开始时间">
|
||||
<a-date-picker
|
||||
v-model:value="formState.startTime"
|
||||
show-time
|
||||
value-format="YYYY-MM-DDTHH:mm:ss"
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="结束时间">
|
||||
<a-date-picker
|
||||
v-model:value="formState.endTime"
|
||||
show-time
|
||||
value-format="YYYY-MM-DDTHH:mm:ss"
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="排序">
|
||||
<a-input-number v-model:value="formState.sortOrder" :min="0" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="状态">
|
||||
<a-select v-model:value="formState.status">
|
||||
<a-select-option :value="1">启用</a-select-option>
|
||||
<a-select-option :value="0">停用</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { adminCampaignApi, type CampaignRequest, type CampaignVO } from '@/api/admin'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminFilterPanel from '@/components/admin/AdminFilterPanel.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { isMobile } = useAdminViewport()
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const statusFilter = ref<'all' | number>('all')
|
||||
const campaigns = ref<CampaignVO[]>([])
|
||||
const modalOpen = ref(false)
|
||||
const editingCampaign = ref<CampaignVO | null>(null)
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const formState = reactive<CampaignRequest>({
|
||||
title: '',
|
||||
description: '',
|
||||
scene: 'HOME',
|
||||
productIds: '',
|
||||
couponIds: '',
|
||||
status: 1,
|
||||
startTime: undefined,
|
||||
endTime: undefined,
|
||||
sortOrder: 0
|
||||
})
|
||||
|
||||
const rules = {
|
||||
title: [{ required: true, message: '请输入活动标题', trigger: 'blur' }]
|
||||
} as any
|
||||
|
||||
const statusOptions = [
|
||||
{ label: '全部状态', value: 'all' },
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '停用', value: 0 }
|
||||
]
|
||||
|
||||
const activeFilterCount = computed(() => statusFilter.value === 'all' ? 0 : 1)
|
||||
|
||||
const columns = [
|
||||
{ title: '标题', dataIndex: 'title', key: 'title' },
|
||||
{ title: '场景', dataIndex: 'scene', key: 'scene', width: 120 },
|
||||
{ title: '活动时间', key: 'time', width: 280 },
|
||||
{ title: '排序', dataIndex: 'sortOrder', key: 'sortOrder', width: 90 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '操作', key: 'actions', width: 90 }
|
||||
]
|
||||
|
||||
const campaignStatusText = (status?: number) => status === 0 ? '停用' : '启用'
|
||||
|
||||
const resetForm = () => {
|
||||
Object.assign(formState, {
|
||||
title: '',
|
||||
description: '',
|
||||
scene: 'HOME',
|
||||
productIds: '',
|
||||
couponIds: '',
|
||||
status: 1,
|
||||
startTime: undefined,
|
||||
endTime: undefined,
|
||||
sortOrder: 0
|
||||
})
|
||||
}
|
||||
|
||||
const loadCampaigns = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await adminCampaignApi.listCampaigns({
|
||||
status: statusFilter.value === 'all' ? undefined : Number(statusFilter.value),
|
||||
page: pagination.current,
|
||||
size: pagination.pageSize
|
||||
})
|
||||
campaigns.value = result.list || []
|
||||
pagination.total = result.total || 0
|
||||
} catch (error) {
|
||||
console.error('加载活动失败:', error)
|
||||
message.error('加载活动失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const reload = () => {
|
||||
pagination.current = 1
|
||||
void loadCampaigns()
|
||||
}
|
||||
|
||||
const resetFilters = () => {
|
||||
statusFilter.value = 'all'
|
||||
reload()
|
||||
}
|
||||
|
||||
const handleTableChange = (pag: any) => {
|
||||
pagination.current = pag.current || 1
|
||||
pagination.pageSize = pag.pageSize || pagination.pageSize
|
||||
void loadCampaigns()
|
||||
}
|
||||
|
||||
const openCreateModal = () => {
|
||||
editingCampaign.value = null
|
||||
resetForm()
|
||||
modalOpen.value = true
|
||||
}
|
||||
|
||||
const openEditModal = (record: CampaignVO) => {
|
||||
editingCampaign.value = record
|
||||
Object.assign(formState, {
|
||||
title: record.title || '',
|
||||
description: record.description || '',
|
||||
scene: record.scene || 'HOME',
|
||||
productIds: record.productIds || '',
|
||||
couponIds: record.couponIds || '',
|
||||
status: record.status ?? 1,
|
||||
startTime: record.startTime,
|
||||
endTime: record.endTime,
|
||||
sortOrder: record.sortOrder ?? 0
|
||||
})
|
||||
modalOpen.value = true
|
||||
}
|
||||
|
||||
const closeModal = () => {
|
||||
modalOpen.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const saveCampaign = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
saving.value = true
|
||||
await runWithGlobalLoading(async () => {
|
||||
await adminCampaignApi.saveCampaign({ ...formState })
|
||||
await loadCampaigns()
|
||||
})
|
||||
message.success('活动已保存')
|
||||
closeModal()
|
||||
} catch (error: any) {
|
||||
if (error?.errorFields) return
|
||||
console.error('保存活动失败:', error)
|
||||
message.error(error?.message || '保存活动失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadCampaigns)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.campaigns {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,245 @@
|
||||
<template>
|
||||
<div class="comments-page">
|
||||
<header class="page-head">
|
||||
<div>
|
||||
<h2>评论管理</h2>
|
||||
<p>查看作品评论与回复,删除不合规内容。</p>
|
||||
</div>
|
||||
<a-input-search v-model:value="keyword" class="search" allow-clear placeholder="搜索评论内容" @search="loadComments" />
|
||||
</header>
|
||||
|
||||
<AdminFilterPanel :active-count="activeFilterCount">
|
||||
<a-input v-model:value="shopKeyword" allow-clear placeholder="店铺" style="width: 160px" @pressEnter="loadComments" />
|
||||
<a-input v-model:value="productKeyword" allow-clear placeholder="作品" style="width: 160px" @pressEnter="loadComments" />
|
||||
<a-input v-model:value="userKeyword" allow-clear placeholder="用户" style="width: 160px" @pressEnter="loadComments" />
|
||||
<a-range-picker v-model:value="createdRange" value-format="YYYY-MM-DD HH:mm:ss" show-time />
|
||||
<a-button @click="resetFilters">重置筛选</a-button>
|
||||
</AdminFilterPanel>
|
||||
|
||||
<a-table
|
||||
:columns="columns"
|
||||
:data-source="filteredComments"
|
||||
:loading="loading"
|
||||
:pagination="{ pageSize: 10 }"
|
||||
row-key="id"
|
||||
:scroll="{ x: 'max-content' }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'commentContent'">
|
||||
<div class="comment-cell">
|
||||
<strong>{{ record.commentContent }}</strong>
|
||||
<span v-if="record.parentCommentContent">回复:{{ record.parentCommentContent }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'action'">
|
||||
<a-popconfirm title="确认删除这条评论?" ok-text="删除" cancel-text="取消" @confirm="deleteComment(record.id)">
|
||||
<a-button danger type="link">删除</a-button>
|
||||
</a-popconfirm>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
/**
|
||||
* Purpose: AdminCommentVO supports CommentsView.vue by holding or executing the admin comment vo page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { adminCommentApi, type AdminCommentVO } from '@/api/admin'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import AdminFilterPanel from '@/components/admin/AdminFilterPanel.vue'
|
||||
|
||||
/**
|
||||
* Purpose: loading supports CommentsView.vue by holding or executing the loading page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const loading = ref(false)
|
||||
/**
|
||||
* Purpose: keyword supports CommentsView.vue by holding or executing the keyword page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const keyword = ref('')
|
||||
/**
|
||||
* Purpose: shopKeyword supports CommentsView.vue by holding or executing the shop keyword page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const shopKeyword = ref('')
|
||||
/**
|
||||
* Purpose: productKeyword supports CommentsView.vue by holding or executing the product keyword page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const productKeyword = ref('')
|
||||
/**
|
||||
* Purpose: userKeyword supports CommentsView.vue by holding or executing the user keyword page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const userKeyword = ref('')
|
||||
/**
|
||||
* Purpose: createdRange supports CommentsView.vue by holding or executing the created range page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const createdRange = ref<[string, string] | undefined>()
|
||||
/**
|
||||
* Purpose: comments supports CommentsView.vue by holding or executing the comments page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const comments = ref<AdminCommentVO[]>([])
|
||||
const activeFilterCount = computed(() => [
|
||||
keyword.value,
|
||||
shopKeyword.value,
|
||||
productKeyword.value,
|
||||
userKeyword.value,
|
||||
createdRange.value?.length ? 'date' : ''
|
||||
].filter(Boolean).length)
|
||||
|
||||
/**
|
||||
* Purpose: columns supports CommentsView.vue by holding or executing the columns page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const columns = [
|
||||
{ title: '评论内容', dataIndex: 'commentContent', key: 'commentContent' },
|
||||
{ title: '用户', dataIndex: 'userNickname', key: 'userNickname', width: 140 },
|
||||
{ title: '作品', dataIndex: 'productTitle', key: 'productTitle', width: 180 },
|
||||
{ title: '店铺', dataIndex: 'shopName', key: 'shopName', width: 160 },
|
||||
{ title: '时间', dataIndex: 'createTime', key: 'createTime', width: 180 },
|
||||
{ title: '操作', key: 'action', width: 100 }
|
||||
]
|
||||
|
||||
/**
|
||||
* Purpose: filteredComments supports CommentsView.vue by holding or executing the filtered comments page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const filteredComments = computed(() => comments.value.filter(comment => {
|
||||
if (!matchText(shopKeyword.value, [comment.shopName, comment.shopId])) return false
|
||||
if (!matchText(productKeyword.value, [comment.productTitle, comment.productId])) return false
|
||||
if (!matchText(userKeyword.value, [comment.userNickname, comment.userId])) return false
|
||||
return matchRange(comment.createTime, createdRange.value)
|
||||
}))
|
||||
|
||||
/**
|
||||
* Purpose: matchText supports CommentsView.vue by holding or executing the match text page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const matchText = (needle: string, values: any[]) => {
|
||||
const normalized = needle.trim().toLowerCase()
|
||||
if (!normalized) return true
|
||||
return values.some(value => String(value ?? '').toLowerCase().includes(normalized))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: matchRange supports CommentsView.vue by holding or executing the match range page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const matchRange = (value?: string, range?: [string, string]) => {
|
||||
if (!range?.length) return true
|
||||
if (!value) return false
|
||||
const time = new Date(value).getTime()
|
||||
return time >= new Date(range[0]).getTime() && time <= new Date(range[1]).getTime()
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: loadComments supports CommentsView.vue by holding or executing the load comments page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const loadComments = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
comments.value = await adminCommentApi.listComments({ keyword: keyword.value || undefined })
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '评论加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: deleteComment supports CommentsView.vue by holding or executing the delete comment page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const deleteComment = async (id: IdType) => {
|
||||
await adminCommentApi.deleteComment(id)
|
||||
message.success('评论已删除')
|
||||
await loadComments()
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: resetFilters supports CommentsView.vue by holding or executing the reset filters page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const resetFilters = () => {
|
||||
keyword.value = ''
|
||||
shopKeyword.value = ''
|
||||
productKeyword.value = ''
|
||||
userKeyword.value = ''
|
||||
createdRange.value = undefined
|
||||
loadComments()
|
||||
}
|
||||
|
||||
onMounted(loadComments)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.comments-page {
|
||||
display: grid;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.page-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.page-head h2 {
|
||||
margin: 0;
|
||||
font-size: 22px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.page-head p {
|
||||
margin: 6px 0 0;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.search {
|
||||
width: min(360px, 100%);
|
||||
}
|
||||
|
||||
.comment-cell {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.comment-cell strong {
|
||||
color: var(--text-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.comment-cell span {
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.comments-page {
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.page-head {
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.page-head > div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.search {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,987 @@
|
||||
<template>
|
||||
<div class="coupons">
|
||||
<a-page-header v-if="!isMobile" title="优惠券管理" sub-title="管理系统优惠券" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">经营</span>
|
||||
<h1 class="admin-page-intro__title">优惠券管理</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">优惠券 {{ couponList.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">
|
||||
优惠券列表
|
||||
</template>
|
||||
<template #extra>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索优惠券名称"
|
||||
:style="isMobile ? { width: '100%' } : { width: '260px' }"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button v-if="!isMobile && hasPermission('coupon:create')" type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增优惠券
|
||||
</a-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="couponList"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
row-key="id"
|
||||
:scroll="{ x: 'max-content' }"
|
||||
@change="handleTableChange"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'shop'">
|
||||
{{ record.shopName || '未指定店铺' }}
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'couponType'">
|
||||
<a-tag :color="record.couponType === 1 ? 'blue' : 'green'">
|
||||
{{ record.couponTypeName || (record.couponType === 1 ? '折扣券' : '满减券') }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'couponScene'">
|
||||
<a-tag :color="record.couponScene === 'VIP_AUTO' ? 'gold' : 'default'">
|
||||
{{ getCouponSceneText(record.couponScene) }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'requiredVipLevel'">
|
||||
{{ record.requiredVipLevel || '-' }}
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'value'">
|
||||
<template v-if="record.couponType === 1">
|
||||
{{ record.discountValue }} 折
|
||||
</template>
|
||||
<template v-else>
|
||||
满 {{ record.minAmount }} 减 {{ record.reduceAmount }}
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="getStatusColor(record.status || 1)">
|
||||
{{ record.statusName || '未知' }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space wrap>
|
||||
<a-button v-if="hasPermission('coupon:view')" type="link" size="small" @click="showViewModal(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('coupon:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="hasPermission('coupon:assign') && !isVipAutoCoupon(record) && record.status === 1"
|
||||
type="link"
|
||||
size="small"
|
||||
@click="showDistributeModal(record)"
|
||||
>
|
||||
发放
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="hasPermission('coupon:delete') && record.status !== 2"
|
||||
type="link"
|
||||
size="small"
|
||||
danger
|
||||
@click="handleDelete(record)"
|
||||
>
|
||||
删除
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="couponList" empty-description="暂无优惠券数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.couponName }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.shopName || '未指定店铺' }}</div>
|
||||
</div>
|
||||
<a-tag :color="getStatusColor(item.status || 1)">
|
||||
{{ item.statusName || '未知' }}
|
||||
</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>类型</span>
|
||||
<strong>{{ item.couponType === 1 ? '折扣券' : '满减券' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>场景</span>
|
||||
<strong>{{ getCouponSceneText(item.couponScene) }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>优惠值</span>
|
||||
<strong>{{ getCouponValueText(item) }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>剩余数量</span>
|
||||
<strong>{{ item.remainingCount ?? '-' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button v-if="hasPermission('coupon:view')" size="small" @click="showViewModal(item)">查看</a-button>
|
||||
<a-button v-if="hasPermission('coupon:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
|
||||
<a-button
|
||||
v-if="hasPermission('coupon:assign') && !isVipAutoCoupon(item) && item.status === 1"
|
||||
size="small"
|
||||
@click="showDistributeModal(item)"
|
||||
>
|
||||
发放
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="hasPermission('coupon:delete') && item.status !== 2"
|
||||
size="small"
|
||||
danger
|
||||
@click="handleDelete(item)"
|
||||
>
|
||||
删除
|
||||
</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="modalVisible"
|
||||
:title="isEdit ? '编辑优惠券' : '新增优惠券'"
|
||||
:desktop-width="820"
|
||||
:confirm-loading="modalLoading"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="优惠券名称" name="couponName">
|
||||
<a-input v-model:value="formState.couponName" placeholder="请输入优惠券名称" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="所属店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
placeholder="请选择所属店铺"
|
||||
:loading="loadingShops"
|
||||
:disabled="currentUserInfo?.type === 2"
|
||||
>
|
||||
<a-select-option v-for="shop in shops" :key="shop.id" :value="shop.id">
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="优惠券类型" name="couponType">
|
||||
<a-select v-model:value="formState.couponType" placeholder="请选择优惠券类型">
|
||||
<a-select-option :value="1">折扣券</a-select-option>
|
||||
<a-select-option :value="2">满减券</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="优惠场景" name="couponScene">
|
||||
<a-select v-model:value="formState.couponScene" placeholder="请选择优惠场景">
|
||||
<a-select-option value="GENERAL">普通券</a-select-option>
|
||||
<a-select-option value="VIP_AUTO">VIP 自动券</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="自动匹配">
|
||||
<a-switch :checked="formState.autoMatch === 1" @change="(checked: any) => handleAutoMatchChange(checked === true)" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="isVipAutoForm" label="所需 VIP 等级" name="requiredVipLevel">
|
||||
<a-select v-model:value="formState.requiredVipLevel" placeholder="请选择 VIP 等级">
|
||||
<a-select-option v-for="level in vipLevelOptions" :key="level" :value="level">{{ level }}</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="formState.couponType === 1" label="折扣值" name="discountValue">
|
||||
<a-input-number v-model:value="formState.discountValue" :min="0.1" :max="9.9" :step="0.1" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="formState.couponType === 2" label="最低消费" name="minAmount">
|
||||
<a-input-number v-model:value="formState.minAmount" :min="0" :step="0.01" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="formState.couponType === 2" label="减免金额" name="reduceAmount">
|
||||
<a-input-number v-model:value="formState.reduceAmount" :min="0" :step="0.01" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="总数量" name="totalCount">
|
||||
<a-input-number v-model:value="formState.totalCount" :min="1" style="width: 100%" />
|
||||
</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" 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" popup-class-name="yumi-date-picker-panel yumi-date-time-panel" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="可用标签" name="availableTagIds">
|
||||
<a-select v-model:value="formState.availableTagIds" mode="multiple" placeholder="请选择可用标签">
|
||||
<a-select-option v-for="tag in tagList" :key="tag.id" :value="tag.id" :disabled="formState.unavailableTagIds.includes(Number(tag.id))">
|
||||
{{ tag.tagName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="不可用标签" name="unavailableTagIds">
|
||||
<a-select v-model:value="formState.unavailableTagIds" mode="multiple" placeholder="请选择不可用标签">
|
||||
<a-select-option v-for="tag in tagList" :key="tag.id" :value="tag.id" :disabled="formState.availableTagIds.includes(Number(tag.id))">
|
||||
{{ tag.tagName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看优惠券详情"
|
||||
:footer="null"
|
||||
:desktop-width="760"
|
||||
@cancel="viewModalVisible = false"
|
||||
>
|
||||
<a-descriptions bordered :column="1" size="small">
|
||||
<a-descriptions-item label="优惠券名称">{{ currentCoupon?.couponName || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="所属店铺">{{ currentCoupon?.shopName || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="优惠券类型">{{ currentCoupon?.couponType === 1 ? '折扣券' : '满减券' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="优惠场景">{{ getCouponSceneText(currentCoupon?.couponScene) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="所需 VIP 等级">{{ currentCoupon?.requiredVipLevel || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="自动匹配">{{ currentCoupon?.autoMatch === 1 ? '是' : '否' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="优惠信息">{{ getCouponValueText(currentCoupon) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="总数量">{{ currentCoupon?.totalCount ?? '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="已使用">{{ currentCoupon?.usedCount ?? '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="开始时间">{{ currentCoupon?.startTime || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="结束时间">{{ currentCoupon?.endTime || '-' }}</a-descriptions-item>
|
||||
</a-descriptions>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="distributeModalVisible"
|
||||
title="发放优惠券"
|
||||
:desktop-width="760"
|
||||
:confirm-loading="distributeLoading"
|
||||
@ok="handleDistributeOk"
|
||||
@cancel="handleDistributeCancel"
|
||||
>
|
||||
<a-form
|
||||
ref="distributeFormRef"
|
||||
:model="distributeFormState"
|
||||
:rules="distributeFormRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="优惠券">
|
||||
<a-input v-model:value="distributeFormState.couponName" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="选择用户" name="userIds">
|
||||
<a-select
|
||||
v-model:value="distributeFormState.userIds"
|
||||
mode="multiple"
|
||||
placeholder="请选择要发放的用户"
|
||||
>
|
||||
<a-select-option v-for="user in userList" :key="user.id" :value="user.id">
|
||||
{{ user.nickname }}({{ user.account }})
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="发放数量" name="quantity">
|
||||
<a-input-number v-model:value="distributeFormState.quantity" :min="1" style="width: 100%" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminMobileFab
|
||||
:visible="isMobile && hasPermission('coupon:create') && !modalVisible && !viewModalVisible && !distributeModalVisible"
|
||||
label="新增优惠券"
|
||||
@click="showAddModal"
|
||||
/>
|
||||
</div>
|
||||
</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'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
/**
|
||||
* Purpose: Dayjs supports CouponsView.vue by holding or executing the dayjs page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import dayjs, { type Dayjs } from 'dayjs'
|
||||
import {
|
||||
adminCouponApi,
|
||||
adminVipRechargePlanApi,
|
||||
adminShopApi,
|
||||
adminTagApi,
|
||||
adminUserApi,
|
||||
type Coupon,
|
||||
type Shop,
|
||||
type Tag,
|
||||
type UserVO
|
||||
} from '@/api/admin'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminMobileFab from '@/components/admin/AdminMobileFab.vue'
|
||||
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')
|
||||
return userInfoStr ? JSON.parse(userInfoStr) : null
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
return null
|
||||
}
|
||||
})()
|
||||
|
||||
/**
|
||||
* Purpose: CouponFormState supports CouponsView.vue by holding or executing the coupon form state page or API role.
|
||||
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
interface CouponFormState {
|
||||
couponCode: string
|
||||
couponName: string
|
||||
couponType: number
|
||||
discountValue?: number
|
||||
minAmount?: number
|
||||
reduceAmount?: number
|
||||
totalCount: number
|
||||
startTime?: Dayjs
|
||||
endTime?: Dayjs
|
||||
availableTagIds: number[]
|
||||
unavailableTagIds: number[]
|
||||
shopId?: number
|
||||
couponScene: string
|
||||
requiredVipLevel?: string
|
||||
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('')
|
||||
/**
|
||||
* Purpose: formRef supports CouponsView.vue by holding or executing the form ref page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formRef = ref<FormInstance>()
|
||||
/**
|
||||
* Purpose: distributeFormRef supports CouponsView.vue by holding or executing the distribute form ref page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const distributeFormRef = ref<FormInstance>()
|
||||
/**
|
||||
* Purpose: currentCoupon supports CouponsView.vue by holding or executing the current coupon page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const currentCoupon = ref<Coupon | null>(null)
|
||||
/**
|
||||
* Purpose: draftSavedAt supports CouponsView.vue by holding or executing the draft saved at page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
/**
|
||||
* Purpose: couponList supports CouponsView.vue by holding or executing the coupon list page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const couponList = ref<Coupon[]>([])
|
||||
/**
|
||||
* Purpose: tagList supports CouponsView.vue by holding or executing the tag list page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const tagList = ref<Tag[]>([])
|
||||
/**
|
||||
* Purpose: userList supports CouponsView.vue by holding or executing the user list page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const userList = ref<UserVO[]>([])
|
||||
/**
|
||||
* Purpose: shops supports CouponsView.vue by holding or executing the shops page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const shops = ref<Shop[]>([])
|
||||
/**
|
||||
* Purpose: vipLevelOptions supports CouponsView.vue by holding or executing the vip level options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const vipLevelOptions = ref<string[]>(['普通', '青铜', '白银', '黄金'])
|
||||
|
||||
/** 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)
|
||||
/**
|
||||
* Purpose: currentDistributeCoupon supports CouponsView.vue by holding or executing the current distribute coupon page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const currentDistributeCoupon = ref<Coupon | null>(null)
|
||||
|
||||
/**
|
||||
* Purpose: pagination supports CouponsView.vue by holding or executing the pagination page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: formState supports CouponsView.vue by holding or executing the form state page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formState = reactive<CouponFormState>({
|
||||
couponCode: '',
|
||||
couponName: '',
|
||||
couponType: 1,
|
||||
discountValue: 9.5,
|
||||
minAmount: 100,
|
||||
reduceAmount: 20,
|
||||
totalCount: 100,
|
||||
startTime: dayjs(),
|
||||
endTime: dayjs().add(30, 'day'),
|
||||
availableTagIds: [],
|
||||
unavailableTagIds: [],
|
||||
shopId: undefined,
|
||||
couponScene: 'GENERAL',
|
||||
requiredVipLevel: undefined,
|
||||
autoMatch: 0
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: distributeFormState supports CouponsView.vue by holding or executing the distribute form state page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const distributeFormState = reactive({
|
||||
couponName: '',
|
||||
userIds: [] as number[],
|
||||
quantity: 1
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: formRules supports CouponsView.vue by holding or executing the form rules page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formRules = {
|
||||
couponName: [{ required: true, message: '请输入优惠券名称', trigger: 'blur' }],
|
||||
couponType: [{ required: true, message: '请选择优惠券类型', trigger: 'change' }],
|
||||
couponScene: [{ required: true, message: '请选择优惠场景', trigger: 'change' }],
|
||||
requiredVipLevel: [{ required: true, message: '请选择所需 VIP 等级', trigger: 'change' }],
|
||||
totalCount: [{ required: true, message: '请输入优惠券总数量', trigger: 'blur' }],
|
||||
startTime: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
|
||||
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }],
|
||||
shopId: [{ required: true, message: '请选择所属店铺', trigger: 'change' }]
|
||||
} as any
|
||||
|
||||
/**
|
||||
* Purpose: distributeFormRules supports CouponsView.vue by holding or executing the distribute form rules page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const distributeFormRules = {
|
||||
userIds: [{ required: true, message: '请选择要发放的用户', trigger: 'change' }],
|
||||
quantity: [{ required: true, message: '请输入发放数量', trigger: 'blur' }]
|
||||
} as any
|
||||
|
||||
/**
|
||||
* Purpose: columns supports CouponsView.vue by holding or executing the columns page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const columns = [
|
||||
{ title: '优惠券名称', dataIndex: 'couponName', key: 'couponName' },
|
||||
{ title: '所属店铺', key: 'shop', width: 140 },
|
||||
{ title: '类型', key: 'couponType', width: 100 },
|
||||
{ title: '场景', key: 'couponScene', width: 120 },
|
||||
{ title: '所需 VIP', key: 'requiredVipLevel', width: 110 },
|
||||
{ title: '优惠信息', key: 'value', width: 170 },
|
||||
{ title: '总数量', dataIndex: 'totalCount', key: 'totalCount', width: 90 },
|
||||
{ title: '已使用', dataIndex: 'usedCount', key: 'usedCount', width: 90 },
|
||||
{ title: '剩余', dataIndex: 'remainingCount', key: 'remainingCount', width: 90 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ 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:
|
||||
return 'green'
|
||||
case 2:
|
||||
return 'red'
|
||||
case 3:
|
||||
return 'orange'
|
||||
default:
|
||||
return 'default'
|
||||
}
|
||||
}
|
||||
|
||||
/** getCouponSceneText is a local helper used by this page script. */
|
||||
const getCouponSceneText = (scene?: string) => {
|
||||
if (scene === 'VIP_AUTO') {
|
||||
return 'VIP 自动券'
|
||||
}
|
||||
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 '-'
|
||||
}
|
||||
return coupon.couponType === 1
|
||||
? `${coupon.discountValue} 折`
|
||||
: `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
|
||||
}
|
||||
|
||||
/** resetFormState is a local helper used by this page script. */
|
||||
const resetFormState = () => {
|
||||
Object.assign(formState, {
|
||||
couponCode: '',
|
||||
couponName: '',
|
||||
couponType: 1,
|
||||
discountValue: 9.5,
|
||||
minAmount: 100,
|
||||
reduceAmount: 20,
|
||||
totalCount: 100,
|
||||
startTime: dayjs(),
|
||||
endTime: dayjs().add(30, 'day'),
|
||||
availableTagIds: [],
|
||||
unavailableTagIds: [],
|
||||
shopId: currentUserInfo?.shopId || undefined,
|
||||
couponScene: 'GENERAL',
|
||||
requiredVipLevel: undefined,
|
||||
autoMatch: 0
|
||||
})
|
||||
}
|
||||
|
||||
/** 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,
|
||||
couponType: formState.couponType,
|
||||
discountValue: formState.discountValue,
|
||||
minAmount: formState.minAmount,
|
||||
reduceAmount: formState.reduceAmount,
|
||||
totalCount: formState.totalCount,
|
||||
startTime: formState.startTime?.format('YYYY-MM-DDTHH:mm:ss'),
|
||||
endTime: formState.endTime?.format('YYYY-MM-DDTHH:mm:ss'),
|
||||
availableTagIds: [...formState.availableTagIds],
|
||||
unavailableTagIds: [...formState.unavailableTagIds],
|
||||
shopId: formState.shopId,
|
||||
couponScene: formState.couponScene,
|
||||
requiredVipLevel: formState.requiredVipLevel,
|
||||
autoMatch: formState.autoMatch
|
||||
})
|
||||
|
||||
/** restoreDraft is a local helper used by this page script. */
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
|
||||
Object.assign(formState, {
|
||||
...draft.payload,
|
||||
startTime: draft.payload.startTime ? dayjs(draft.payload.startTime) : undefined,
|
||||
endTime: draft.payload.endTime ? dayjs(draft.payload.endTime) : undefined
|
||||
})
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/** 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
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isSameTagSelection supports CouponsView.vue by holding or executing the is same tag selection page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const isSameTagSelection = (left: number[], right: number[]) =>
|
||||
left.length === right.length && left.every((id, index) => Number(id) === Number(right[index]))
|
||||
|
||||
/**
|
||||
* Purpose: removeSelectedTags supports CouponsView.vue by holding or executing the remove selected tags page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const removeSelectedTags = (target: number[], selected: number[]) => {
|
||||
const selectedIds = new Set(selected.map(Number))
|
||||
return target.filter(id => !selectedIds.has(Number(id)))
|
||||
}
|
||||
|
||||
watch(
|
||||
() => formState.couponScene,
|
||||
value => {
|
||||
if (value === 'VIP_AUTO') {
|
||||
formState.autoMatch = 1
|
||||
if (!formState.requiredVipLevel) {
|
||||
formState.requiredVipLevel = vipLevelOptions.value.find(level => level !== '普通') || vipLevelOptions.value[0]
|
||||
}
|
||||
} else {
|
||||
formState.autoMatch = 0
|
||||
formState.requiredVipLevel = undefined
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
watch(
|
||||
() => formState.availableTagIds.slice(),
|
||||
value => {
|
||||
const nextUnavailableTagIds = removeSelectedTags(formState.unavailableTagIds, value)
|
||||
if (!isSameTagSelection(formState.unavailableTagIds, nextUnavailableTagIds)) {
|
||||
formState.unavailableTagIds = nextUnavailableTagIds
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
watch(
|
||||
() => formState.unavailableTagIds.slice(),
|
||||
value => {
|
||||
const nextAvailableTagIds = removeSelectedTags(formState.availableTagIds, value)
|
||||
if (!isSameTagSelection(formState.availableTagIds, nextAvailableTagIds)) {
|
||||
formState.availableTagIds = nextAvailableTagIds
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/** 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 {
|
||||
const shopId = currentUserInfo?.shopId || undefined
|
||||
const coupons = await adminCouponApi.listAllCoupons(shopId) as unknown as Coupon[]
|
||||
const list = Array.isArray(coupons) ? coupons : []
|
||||
const keyword = searchText.value.trim()
|
||||
couponList.value = keyword
|
||||
? list.filter(item => (item.couponName || '').includes(keyword))
|
||||
: list
|
||||
pagination.total = couponList.value.length
|
||||
} catch (error) {
|
||||
console.error('获取优惠券列表失败:', error)
|
||||
message.error('获取优惠券列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 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[]
|
||||
tagList.value = tags || []
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 {
|
||||
const shopList = await adminShopApi.listAllShops() as unknown as Shop[]
|
||||
shops.value = shopList || []
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 }
|
||||
if (currentUserInfo?.shopId) {
|
||||
params.shopId = currentUserInfo.shopId
|
||||
}
|
||||
const result = await adminUserApi.listUsers(params as any)
|
||||
userList.value = result.list || []
|
||||
} catch (error) {
|
||||
console.error('获取用户列表失败:', error)
|
||||
userList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
/** 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
|
||||
resetFormState()
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showEditModal is a local helper used by this page script. */
|
||||
const showEditModal = (record: any) => {
|
||||
isEdit.value = true
|
||||
currentCoupon.value = record
|
||||
Object.assign(formState, {
|
||||
couponCode: record.couponCode || '',
|
||||
couponName: record.couponName || '',
|
||||
couponType: record.couponType || 1,
|
||||
discountValue: record.discountValue ? Number(record.discountValue) : 9.5,
|
||||
minAmount: record.minAmount ? Number(record.minAmount) : 100,
|
||||
reduceAmount: record.reduceAmount ? Number(record.reduceAmount) : 20,
|
||||
totalCount: record.totalCount || 100,
|
||||
startTime: record.startTime ? dayjs(record.startTime) : undefined,
|
||||
endTime: record.endTime ? dayjs(record.endTime) : undefined,
|
||||
availableTagIds: record.availableTags?.map((tag: Tag) => tag.id) || [],
|
||||
unavailableTagIds: record.unavailableTags?.map((tag: Tag) => tag.id) || [],
|
||||
shopId: record.shopId,
|
||||
couponScene: record.couponScene || 'GENERAL',
|
||||
requiredVipLevel: record.requiredVipLevel || undefined,
|
||||
autoMatch: record.autoMatch || 0
|
||||
})
|
||||
restoreDraft()
|
||||
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,
|
||||
couponType: formState.couponType,
|
||||
discountValue: formState.couponType === 1 ? formState.discountValue : undefined,
|
||||
minAmount: formState.couponType === 2 ? formState.minAmount : undefined,
|
||||
reduceAmount: formState.couponType === 2 ? formState.reduceAmount : undefined,
|
||||
totalCount: formState.totalCount,
|
||||
startTime: formState.startTime?.format('YYYY-MM-DDTHH:mm:ss'),
|
||||
endTime: formState.endTime?.format('YYYY-MM-DDTHH:mm:ss'),
|
||||
availableTagIds: formState.availableTagIds,
|
||||
unavailableTagIds: formState.unavailableTagIds,
|
||||
shopId: formState.shopId,
|
||||
couponScene: formState.couponScene,
|
||||
requiredVipLevel: isVipAutoForm.value ? formState.requiredVipLevel : undefined,
|
||||
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()
|
||||
modalLoading.value = true
|
||||
|
||||
await runWithGlobalLoading(async () => {
|
||||
const payload = buildCouponPayload()
|
||||
if (isEdit.value && currentCoupon.value) {
|
||||
await adminCouponApi.updateCoupon(currentCoupon.value.id, payload)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await adminCouponApi.createCoupon(payload)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
await fetchCoupons()
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error('保存优惠券失败:', error)
|
||||
message.error(error.message || '操作失败')
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 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: '确认删除',
|
||||
content: `确定要删除优惠券 ${record.couponName} 吗?`,
|
||||
async onOk() {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await adminCouponApi.deleteCoupon(record.id)
|
||||
message.success('删除成功')
|
||||
await fetchCoupons()
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('删除优惠券失败:', error)
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/** 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
|
||||
distributeFormState.userIds = []
|
||||
distributeFormState.quantity = 1
|
||||
await runWithGlobalLoading(() => fetchUsers())
|
||||
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
|
||||
}
|
||||
const couponId = currentDistributeCoupon.value.id
|
||||
if (isVipAutoCoupon(currentDistributeCoupon.value)) {
|
||||
message.warning('VIP 自动券为系统模板券,不能手动发放')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await distributeFormRef.value?.validate()
|
||||
distributeLoading.value = true
|
||||
await runWithGlobalLoading(async () => {
|
||||
await adminCouponApi.distributeCoupon({
|
||||
couponId,
|
||||
userIds: distributeFormState.userIds,
|
||||
quantity: distributeFormState.quantity
|
||||
})
|
||||
message.success('发放成功')
|
||||
distributeModalVisible.value = false
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error('发放优惠券失败:', error)
|
||||
message.error(error.message || '发放失败')
|
||||
} finally {
|
||||
distributeLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** handleDistributeCancel is a local helper used by this page script. */
|
||||
const handleDistributeCancel = () => {
|
||||
distributeModalVisible.value = false
|
||||
distributeFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: fetchVipLevelOptions supports CouponsView.vue by holding or executing the fetch vip level options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const fetchVipLevelOptions = async () => {
|
||||
try {
|
||||
const levels = await adminVipRechargePlanApi.listVipLevelOptions(currentUserInfo?.shopId)
|
||||
if (Array.isArray(levels) && levels.length) {
|
||||
vipLevelOptions.value = ['普通', ...levels.filter(level => level !== '普通')]
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('VIP 等级选项加载失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
await Promise.all([fetchTags(), fetchShops(), fetchCoupons(), fetchVipLevelOptions()])
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.coupons {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,583 @@
|
||||
<template>
|
||||
<div class="home">
|
||||
<template v-if="!isMobile">
|
||||
<a-page-header title="欢迎使用后台管理系统" :sub-title="welcomeMessage" />
|
||||
|
||||
<a-alert
|
||||
v-if="isBootstrapAdmin"
|
||||
class="bootstrap-alert"
|
||||
type="info"
|
||||
show-icon
|
||||
message="当前处于平台总览模式"
|
||||
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>
|
||||
|
||||
<a-card class="info-card">
|
||||
<a-descriptions bordered>
|
||||
<a-descriptions-item label="用户信息">
|
||||
<div class="user-info">
|
||||
<a-avatar :size="64" :src="userInfo?.avatar || DEFAULT_AVATAR" />
|
||||
<div class="user-details">
|
||||
<h3>{{ userInfo?.nickname || '管理员' }}</h3>
|
||||
<p>{{ getUserTypeText(userInfo?.type) }}</p>
|
||||
<p v-if="userInfo?.shopName">所属店铺:{{ userInfo?.shopName }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</a-descriptions-item>
|
||||
</a-descriptions>
|
||||
</a-card>
|
||||
|
||||
<a-card class="permissions-card">
|
||||
<template #title>
|
||||
<div class="card-title">
|
||||
<SafetyCertificateOutlined class="title-icon" />
|
||||
<span>我的权限</span>
|
||||
</div>
|
||||
</template>
|
||||
<div class="permissions-content" v-if="userPermissions.length > 0">
|
||||
<div v-for="(group, groupName) in groupedPermissions" :key="groupName" class="permission-group">
|
||||
<div class="group-title">{{ groupName }}</div>
|
||||
<div class="permission-tags">
|
||||
<a-tag v-for="permission in group" :key="permission.id" color="blue" class="permission-tag">
|
||||
{{ permission.permissionName }}
|
||||
</a-tag>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="no-permissions" v-else>
|
||||
暂无权限信息
|
||||
</div>
|
||||
</a-card>
|
||||
|
||||
<a-card class="quick-actions">
|
||||
<template #title>
|
||||
快捷操作
|
||||
</template>
|
||||
<a-row :gutter="[16, 16]">
|
||||
<a-col v-for="item in quickActions" :key="item.key" :span="8">
|
||||
<a-card hoverable @click="navigateTo(item.path, item.permissionCode)">
|
||||
<template #cover>
|
||||
<div class="action-icon">
|
||||
<component :is="item.icon" />
|
||||
</div>
|
||||
</template>
|
||||
<template #title>
|
||||
{{ item.title }}
|
||||
</template>
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-card>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<section class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">{{ userInfo?.nickname || userInfo?.account || '后台账号' }}</span>
|
||||
<h1 class="admin-page-intro__title">{{ userInfo?.shopName || (isBootstrapAdmin ? '平台总览模式' : '游客模式') }}</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">{{ currentTime }}</span>
|
||||
<span class="admin-page-chip">{{ getUserTypeText(userInfo?.type) }}</span>
|
||||
<span v-if="isBootstrapAdmin" class="admin-page-chip">平台总览</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="isBootstrapAdmin" class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">平台总览模式</div>
|
||||
<a-button type="primary" size="large" block @click="navigateTo('/admin/shops', 'shop:view')">进入店铺管理</a-button>
|
||||
</section>
|
||||
|
||||
<div class="admin-mobile-grid admin-mobile-grid--two">
|
||||
<section class="admin-mobile-stat">
|
||||
<div class="admin-mobile-stat__label">权限数量</div>
|
||||
<div class="admin-mobile-stat__value">{{ userPermissions.length }}</div>
|
||||
</section>
|
||||
<section class="admin-mobile-stat">
|
||||
<div class="admin-mobile-stat__label">快捷入口</div>
|
||||
<div class="admin-mobile-stat__value">{{ quickActions.length }}</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">快捷入口</div>
|
||||
<div class="mobile-actions">
|
||||
<button
|
||||
v-for="item in quickActions"
|
||||
:key="item.key"
|
||||
class="mobile-action"
|
||||
type="button"
|
||||
@click="navigateTo(item.path, item.permissionCode)"
|
||||
>
|
||||
<div class="mobile-action__icon">
|
||||
<component :is="item.icon" />
|
||||
</div>
|
||||
<div class="mobile-action__body">
|
||||
<div class="mobile-action__title">{{ item.title }}</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">权限分组</div>
|
||||
<div v-if="userPermissions.length > 0" class="mobile-permission-groups">
|
||||
<div v-for="(group, groupName) in groupedPermissions" :key="groupName" class="mobile-permission-group">
|
||||
<div class="mobile-permission-group__title">{{ groupName }}</div>
|
||||
<div class="permission-tags">
|
||||
<a-tag v-for="permission in group" :key="permission.id" color="blue" class="permission-tag">
|
||||
{{ permission.permissionName }}
|
||||
</a-tag>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<a-empty v-else description="暂无权限信息" />
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
</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,
|
||||
FileProtectOutlined,
|
||||
GiftOutlined,
|
||||
HomeOutlined,
|
||||
MessageOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
SettingOutlined,
|
||||
ShopOutlined,
|
||||
ShoppingOutlined,
|
||||
TagOutlined,
|
||||
TeamOutlined,
|
||||
UserOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
/**
|
||||
* Purpose: UserVO supports HomeView.vue by holding or executing the user vo page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { userApi, type UserVO } from '@/api/admin'
|
||||
/**
|
||||
* Purpose: PermissionVO supports HomeView.vue by holding or executing the permission vo page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { permissionApi, type PermissionVO } from '@/api/permission'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import { isBootstrapAdminUser } from './admin-helpers'
|
||||
import { isAllowedForShoplessPlatformAdmin } from '@/utils/platform-admin-permissions'
|
||||
|
||||
/**
|
||||
* Purpose: router supports HomeView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const router = useRouter()
|
||||
const { isMobile } = useAdminViewport()
|
||||
/** currentTime is a reactive state variable used by the template and event handlers. */
|
||||
const currentTime = ref('')
|
||||
/**
|
||||
* Purpose: userInfo supports HomeView.vue by holding or executing the user info page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const userInfo = ref<UserVO | null>(null)
|
||||
/**
|
||||
* Purpose: userPermissions supports HomeView.vue by holding or executing the user permissions page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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) {
|
||||
return '早上好!'
|
||||
} else if (hour < 18) {
|
||||
return '下午好!'
|
||||
} else {
|
||||
return '晚上好!'
|
||||
}
|
||||
})
|
||||
|
||||
/** 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 => {
|
||||
const groupName = permission.permissionGroup
|
||||
if (!groups[groupName]) {
|
||||
groups[groupName] = []
|
||||
}
|
||||
groups[groupName]!.push(permission)
|
||||
})
|
||||
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',
|
||||
title: '仪表盘',
|
||||
path: '/admin/dashboard',
|
||||
icon: DashboardOutlined,
|
||||
permissionCode: 'dashboard:view'
|
||||
},
|
||||
{
|
||||
key: 'users',
|
||||
title: '用户管理',
|
||||
path: '/admin/users',
|
||||
icon: UserOutlined,
|
||||
permissionCode: 'user:view'
|
||||
},
|
||||
{
|
||||
key: 'products',
|
||||
title: '作品管理',
|
||||
path: '/admin/products',
|
||||
icon: ShopOutlined,
|
||||
permissionCode: 'product:view'
|
||||
},
|
||||
{
|
||||
key: 'coupons',
|
||||
title: '优惠券',
|
||||
path: '/admin/coupons',
|
||||
icon: GiftOutlined,
|
||||
permissionCode: 'coupon:view'
|
||||
},
|
||||
{
|
||||
key: 'orders',
|
||||
title: '订单管理',
|
||||
path: '/admin/orders',
|
||||
icon: ShoppingOutlined,
|
||||
permissionCode: 'order:view'
|
||||
},
|
||||
{
|
||||
key: 'tags',
|
||||
title: '标签管理',
|
||||
path: '/admin/tags',
|
||||
icon: TagOutlined,
|
||||
permissionCode: 'tag:view'
|
||||
},
|
||||
{
|
||||
key: 'artists',
|
||||
title: '美甲师管理',
|
||||
path: '/admin/nail-artists',
|
||||
icon: TeamOutlined,
|
||||
permissionCode: 'nail_artist:view'
|
||||
},
|
||||
{
|
||||
key: 'shops',
|
||||
title: '店铺管理',
|
||||
path: '/admin/shops',
|
||||
icon: HomeOutlined,
|
||||
permissionCode: 'shop:view'
|
||||
},
|
||||
{
|
||||
key: 'permissions',
|
||||
title: '权限管理',
|
||||
path: '/admin/permissions',
|
||||
icon: SafetyCertificateOutlined,
|
||||
permissionCode: 'permission:view'
|
||||
},
|
||||
{
|
||||
key: 'messages',
|
||||
title: '消息发布',
|
||||
path: '/admin/messages',
|
||||
icon: MessageOutlined,
|
||||
permissionCode: 'message:view'
|
||||
},
|
||||
{
|
||||
key: 'announcements',
|
||||
title: '公告管理',
|
||||
path: '/admin/announcements',
|
||||
icon: MessageOutlined,
|
||||
permissionCode: 'announcement:view'
|
||||
},
|
||||
{
|
||||
key: 'vip-plans',
|
||||
title: 'VIP充值配置',
|
||||
path: '/admin/vip-recharge-plans',
|
||||
icon: GiftOutlined,
|
||||
permissionCode: 'user:vip:manage'
|
||||
},
|
||||
{
|
||||
key: 'parameters',
|
||||
title: '参数管理',
|
||||
path: '/admin/messagehub-push-configs',
|
||||
icon: SettingOutlined,
|
||||
permissionCode: 'messagehub:config:manage'
|
||||
},
|
||||
{
|
||||
key: 'agreements',
|
||||
title: '协议管理',
|
||||
path: '/admin/legal-agreements',
|
||||
icon: FileProtectOutlined,
|
||||
permissionCode: 'legal_agreement:manage'
|
||||
}
|
||||
]
|
||||
|
||||
const grantedPermissions = new Set(userPermissions.value.map(permission => permission.permissionCode))
|
||||
if (isBootstrapAdmin.value) {
|
||||
return actions.filter(item => isAllowedForShoplessPlatformAdmin(item.permissionCode))
|
||||
}
|
||||
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:
|
||||
return '平台管理员'
|
||||
case 2:
|
||||
return '店长'
|
||||
case 3:
|
||||
return '美甲师'
|
||||
default:
|
||||
return '后台账号'
|
||||
}
|
||||
}
|
||||
|
||||
/** updateCurrentTime is a local helper used by this page script. */
|
||||
const updateCurrentTime = () => {
|
||||
const now = new Date()
|
||||
currentTime.value = now.toLocaleString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit'
|
||||
})
|
||||
}
|
||||
|
||||
/** 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')
|
||||
if (adminUserInfoStr) {
|
||||
userInfo.value = JSON.parse(adminUserInfoStr)
|
||||
} else {
|
||||
const res = await userApi.getUserInfo()
|
||||
userInfo.value = res as unknown as UserVO
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/** 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()
|
||||
userPermissions.value = res as unknown as PermissionVO[]
|
||||
} catch (error) {
|
||||
console.error('获取用户权限失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/** navigateTo is a local helper used by this page script. */
|
||||
const navigateTo = (path: string, permissionCode?: string) => {
|
||||
if (permissionCode) {
|
||||
if (isBootstrapAdmin.value && isAllowedForShoplessPlatformAdmin(permissionCode)) {
|
||||
router.push(path)
|
||||
return
|
||||
}
|
||||
const hasPermission = userPermissions.value.some(p => p.permissionCode === permissionCode)
|
||||
if (!hasPermission) {
|
||||
message.warning('您没有该操作的权限')
|
||||
return
|
||||
}
|
||||
}
|
||||
router.push(path)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
updateCurrentTime()
|
||||
timer = window.setInterval(updateCurrentTime, 1000)
|
||||
void fetchUserInfo()
|
||||
void fetchUserPermissions()
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (timer !== null) {
|
||||
window.clearInterval(timer)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.home {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.time-card,
|
||||
.bootstrap-alert,
|
||||
.info-card,
|
||||
.permissions-card {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.user-details {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.user-details h3 {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.user-details p {
|
||||
margin: 4px 0;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.card-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.title-icon {
|
||||
font-size: 20px;
|
||||
color: var(--admin-mobile-accent);
|
||||
}
|
||||
|
||||
.permissions-content,
|
||||
.mobile-permission-groups {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.permission-group,
|
||||
.mobile-permission-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.group-title,
|
||||
.mobile-permission-group__title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--theme-primary);
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.permission-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.permission-tag {
|
||||
font-size: 13px;
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.no-permissions {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.quick-actions {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 80px;
|
||||
font-size: 32px;
|
||||
color: var(--theme-primary);
|
||||
background: var(--admin-mobile-accent-soft);
|
||||
}
|
||||
|
||||
.mobile-actions {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.mobile-action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
padding: 14px 0;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--admin-mobile-border);
|
||||
background: transparent;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.mobile-action:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.mobile-action__icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
border-radius: 14px;
|
||||
background: var(--admin-mobile-accent-soft);
|
||||
color: var(--theme-primary);
|
||||
}
|
||||
|
||||
.mobile-action__body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.mobile-action__title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.mobile-action__meta {
|
||||
margin-top: 4px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,344 @@
|
||||
<template>
|
||||
<div class="inventory">
|
||||
<a-page-header v-if="!isMobile" title="库存管理" sub-title="维护门店耗材库存和预警阈值" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">库存</span>
|
||||
<h1 class="admin-page-intro__title">库存管理</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">物料 {{ pagination.total }}</span>
|
||||
<span class="admin-page-chip">预警 {{ warningCount }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">库存列表</template>
|
||||
<template #extra>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-input-search
|
||||
v-model:value="keyword"
|
||||
placeholder="搜索物料或分类"
|
||||
:style="isMobile ? { width: '100%' } : { width: '220px' }"
|
||||
/>
|
||||
<a-button type="primary" @click="openCreateModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增物料
|
||||
</a-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-alert
|
||||
v-if="warningCount"
|
||||
class="inventory-alert"
|
||||
type="warning"
|
||||
show-icon
|
||||
:message="`当前有 ${warningCount} 个物料低于预警阈值`"
|
||||
/>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="filteredItems"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
row-key="id"
|
||||
:scroll="{ x: 'max-content' }"
|
||||
@change="handleTableChange"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'stock'">
|
||||
<a-tag :color="record.warning ? 'red' : 'green'">{{ numberText(record.stockQuantity) }} {{ record.unit || '' }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'warning'">{{ numberText(record.warningThreshold) }} {{ record.unit || '' }}</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 0 ? 'red' : 'green'">{{ record.status === 0 ? '停用' : '启用' }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="openAdjustModal(record as InventoryItemVO, 'IN')">入库</a-button>
|
||||
<a-button type="link" size="small" @click="openAdjustModal(record as InventoryItemVO, 'OUT')">出库</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="filteredItems" empty-description="暂无库存物料">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.itemName }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.category || '未分类' }}</div>
|
||||
</div>
|
||||
<a-tag :color="item.warning ? 'red' : 'green'">{{ item.warning ? '预警' : '正常' }}</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>库存</span>
|
||||
<strong>{{ numberText(item.stockQuantity) }} {{ item.unit || '' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>预警阈值</span>
|
||||
<strong>{{ numberText(item.warningThreshold) }} {{ item.unit || '' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button size="small" @click="openAdjustModal(item, 'IN')">入库</a-button>
|
||||
<a-button size="small" @click="openAdjustModal(item, 'OUT')">出库</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="itemModalOpen"
|
||||
title="新增物料"
|
||||
:desktop-width="680"
|
||||
:confirm-loading="savingItem"
|
||||
@ok="saveItem"
|
||||
@cancel="closeItemModal"
|
||||
>
|
||||
<a-form ref="itemFormRef" :model="itemForm" :rules="itemRules" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
|
||||
<a-form-item label="物料名称" name="itemName">
|
||||
<a-input v-model:value="itemForm.itemName" placeholder="例如:底胶" />
|
||||
</a-form-item>
|
||||
<a-form-item label="分类">
|
||||
<a-input v-model:value="itemForm.category" placeholder="例如:胶类/工具/耗材" />
|
||||
</a-form-item>
|
||||
<a-form-item label="单位">
|
||||
<a-input v-model:value="itemForm.unit" placeholder="瓶、盒、个" />
|
||||
</a-form-item>
|
||||
<a-form-item label="初始库存">
|
||||
<a-input-number v-model:value="itemForm.stockQuantity" :min="0" :step="1" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="预警阈值">
|
||||
<a-input-number v-model:value="itemForm.warningThreshold" :min="0" :step="1" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="状态">
|
||||
<a-select v-model:value="itemForm.status">
|
||||
<a-select-option :value="1">启用</a-select-option>
|
||||
<a-select-option :value="0">停用</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="adjustModalOpen"
|
||||
:title="adjustForm.changeType === 'OUT' ? '出库调整' : '入库调整'"
|
||||
:desktop-width="600"
|
||||
:confirm-loading="adjusting"
|
||||
@ok="submitAdjust"
|
||||
@cancel="closeAdjustModal"
|
||||
>
|
||||
<a-form ref="adjustFormRef" :model="adjustForm" :rules="adjustRules" layout="vertical">
|
||||
<a-alert
|
||||
v-if="adjustTarget"
|
||||
class="inventory-alert"
|
||||
type="info"
|
||||
show-icon
|
||||
:message="adjustTarget.itemName"
|
||||
:description="`当前库存:${numberText(adjustTarget.stockQuantity)} ${adjustTarget.unit || ''}`"
|
||||
/>
|
||||
<a-form-item label="调整数量" name="changeQuantity">
|
||||
<a-input-number v-model:value="adjustForm.changeQuantity" :step="1" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="备注">
|
||||
<a-textarea v-model:value="adjustForm.remark" :rows="3" :maxlength="200" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { adminInventoryApi, type InventoryItemVO } from '@/api/admin'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { isMobile } = useAdminViewport()
|
||||
const loading = ref(false)
|
||||
const savingItem = ref(false)
|
||||
const adjusting = ref(false)
|
||||
const keyword = ref('')
|
||||
const items = ref<InventoryItemVO[]>([])
|
||||
const itemModalOpen = ref(false)
|
||||
const adjustModalOpen = ref(false)
|
||||
const adjustTarget = ref<InventoryItemVO | null>(null)
|
||||
const itemFormRef = ref<FormInstance>()
|
||||
const adjustFormRef = ref<FormInstance>()
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const itemForm = reactive({
|
||||
itemName: '',
|
||||
category: '',
|
||||
unit: '',
|
||||
stockQuantity: 0,
|
||||
warningThreshold: 0,
|
||||
status: 1
|
||||
})
|
||||
|
||||
const adjustForm = reactive({
|
||||
changeType: 'IN' as 'IN' | 'OUT',
|
||||
changeQuantity: 1,
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const itemRules = {
|
||||
itemName: [{ required: true, message: '请输入物料名称', trigger: 'blur' }]
|
||||
} as any
|
||||
|
||||
const adjustRules = {
|
||||
changeQuantity: [{ required: true, message: '请输入调整数量', trigger: 'blur' }]
|
||||
} as any
|
||||
|
||||
const columns = [
|
||||
{ title: '物料名称', dataIndex: 'itemName', key: 'itemName' },
|
||||
{ title: '分类', dataIndex: 'category', key: 'category', width: 140 },
|
||||
{ title: '库存', key: 'stock', width: 140 },
|
||||
{ title: '预警阈值', key: 'warning', width: 140 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '操作', key: 'actions', width: 130 }
|
||||
]
|
||||
|
||||
const warningCount = computed(() => items.value.filter(item => item.warning).length)
|
||||
const filteredItems = computed(() => {
|
||||
const value = keyword.value.trim().toLowerCase()
|
||||
if (!value) return items.value
|
||||
return items.value.filter(item => [item.itemName, item.category, item.unit].join(' ').toLowerCase().includes(value))
|
||||
})
|
||||
|
||||
const numberText = (value?: number) => Number(value || 0).toFixed(2).replace(/\.00$/, '')
|
||||
|
||||
const resetItemForm = () => {
|
||||
Object.assign(itemForm, {
|
||||
itemName: '',
|
||||
category: '',
|
||||
unit: '',
|
||||
stockQuantity: 0,
|
||||
warningThreshold: 0,
|
||||
status: 1
|
||||
})
|
||||
}
|
||||
|
||||
const loadItems = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await adminInventoryApi.listItems({
|
||||
page: pagination.current,
|
||||
size: pagination.pageSize
|
||||
})
|
||||
items.value = result.list || []
|
||||
pagination.total = result.total || 0
|
||||
} catch (error) {
|
||||
console.error('加载库存失败:', error)
|
||||
message.error('加载库存失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleTableChange = (pag: any) => {
|
||||
pagination.current = pag.current || 1
|
||||
pagination.pageSize = pag.pageSize || pagination.pageSize
|
||||
void loadItems()
|
||||
}
|
||||
|
||||
const openCreateModal = () => {
|
||||
resetItemForm()
|
||||
itemModalOpen.value = true
|
||||
}
|
||||
|
||||
const closeItemModal = () => {
|
||||
itemModalOpen.value = false
|
||||
itemFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const saveItem = async () => {
|
||||
try {
|
||||
await itemFormRef.value?.validate()
|
||||
savingItem.value = true
|
||||
await runWithGlobalLoading(async () => {
|
||||
await adminInventoryApi.saveItem({ ...itemForm })
|
||||
await loadItems()
|
||||
})
|
||||
message.success('物料已保存')
|
||||
closeItemModal()
|
||||
} catch (error: any) {
|
||||
if (error?.errorFields) return
|
||||
console.error('保存物料失败:', error)
|
||||
message.error(error?.message || '保存物料失败')
|
||||
} finally {
|
||||
savingItem.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const openAdjustModal = (record: InventoryItemVO, changeType: 'IN' | 'OUT') => {
|
||||
adjustTarget.value = record
|
||||
adjustForm.changeType = changeType
|
||||
adjustForm.changeQuantity = changeType === 'OUT' ? -1 : 1
|
||||
adjustForm.remark = ''
|
||||
adjustModalOpen.value = true
|
||||
}
|
||||
|
||||
const closeAdjustModal = () => {
|
||||
adjustModalOpen.value = false
|
||||
adjustTarget.value = null
|
||||
adjustFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const submitAdjust = async () => {
|
||||
if (!adjustTarget.value) return
|
||||
const quantity = Number(adjustForm.changeQuantity || 0)
|
||||
if (quantity === 0) {
|
||||
message.warning('调整数量不能为 0')
|
||||
return
|
||||
}
|
||||
adjusting.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await adminInventoryApi.adjustStock(adjustTarget.value!.id, {
|
||||
changeType: adjustForm.changeType,
|
||||
changeQuantity: quantity,
|
||||
remark: adjustForm.remark.trim() || undefined
|
||||
})
|
||||
await loadItems()
|
||||
})
|
||||
message.success('库存已调整')
|
||||
closeAdjustModal()
|
||||
} catch (error: any) {
|
||||
console.error('库存调整失败:', error)
|
||||
message.error(error?.message || '库存调整失败')
|
||||
} finally {
|
||||
adjusting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadItems)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.inventory {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.inventory-alert {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,214 @@
|
||||
<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" :scroll="{ x: 'max-content' }" 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"
|
||||
:mask-closable="false"
|
||||
: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="例如:Fingertip Designer 用户协议" />
|
||||
</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="请输入协议正文,支持 HTML / Markdown" />
|
||||
</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'
|
||||
/**
|
||||
* Purpose: LegalAgreementAdminVO supports LegalAgreementsView.vue by holding or executing the legal agreement admin vo page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { adminLegalAgreementApi, type LegalAgreementAdminVO } from '@/api/admin'
|
||||
import type { IdType } from '@/utils/id'
|
||||
|
||||
/**
|
||||
* Purpose: loading supports LegalAgreementsView.vue by holding or executing the loading page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const loading = ref(false)
|
||||
/**
|
||||
* Purpose: saving supports LegalAgreementsView.vue by holding or executing the saving page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const saving = ref(false)
|
||||
/**
|
||||
* Purpose: modalOpen supports LegalAgreementsView.vue by holding or executing the modal open page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const modalOpen = ref(false)
|
||||
/**
|
||||
* Purpose: editingId supports LegalAgreementsView.vue by holding or executing the editing id page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const editingId = ref<IdType | null>(null)
|
||||
/**
|
||||
* Purpose: agreements supports LegalAgreementsView.vue by holding or executing the agreements page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const agreements = ref<LegalAgreementAdminVO[]>([])
|
||||
/**
|
||||
* Purpose: form supports LegalAgreementsView.vue by holding or executing the form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const form = reactive({
|
||||
agreementType: 'USER_TERMS' as 'USER_TERMS' | 'PRIVACY_POLICY',
|
||||
title: '',
|
||||
version: '',
|
||||
content: ''
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: columns supports LegalAgreementsView.vue by holding or executing the columns page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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 }
|
||||
]
|
||||
|
||||
/**
|
||||
* Purpose: loadAgreements supports LegalAgreementsView.vue by holding or executing the load agreements page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const loadAgreements = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
agreements.value = await adminLegalAgreementApi.list() as unknown as LegalAgreementAdminVO[]
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: resetForm supports LegalAgreementsView.vue by holding or executing the reset form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const resetForm = () => {
|
||||
editingId.value = null
|
||||
form.agreementType = 'USER_TERMS'
|
||||
form.title = ''
|
||||
form.version = ''
|
||||
form.content = ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: openCreate supports LegalAgreementsView.vue by holding or executing the open create page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const openCreate = () => {
|
||||
resetForm()
|
||||
modalOpen.value = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: openEdit supports LegalAgreementsView.vue by holding or executing the open edit page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: saveAgreement supports LegalAgreementsView.vue by holding or executing the save agreement page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: publishAgreement supports LegalAgreementsView.vue by holding or executing the publish agreement page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const publishAgreement = async (id: IdType) => {
|
||||
await adminLegalAgreementApi.publish(id)
|
||||
message.success('发布成功')
|
||||
await loadAgreements()
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: disableAgreement supports LegalAgreementsView.vue by holding or executing the disable agreement page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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: var(--text-secondary); }
|
||||
</style>
|
||||
@@ -0,0 +1,405 @@
|
||||
<template>
|
||||
<div class="admin-manage">
|
||||
<section class="admin-page-intro admin-manage__intro">
|
||||
<span class="admin-page-intro__eyebrow">经营</span>
|
||||
<h1 class="admin-page-intro__title">{{ currentShopName }}</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">{{ roleLabel }}</span>
|
||||
<span class="admin-page-chip">可见模块 {{ visibleModules.length }}</span>
|
||||
<span v-if="isBootstrapAdmin" class="admin-page-chip">平台总览</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="module-grid">
|
||||
<button
|
||||
v-for="module in visibleModules"
|
||||
:key="module.key"
|
||||
class="module-card"
|
||||
:class="{ 'is-disabled': !module.allowed }"
|
||||
type="button"
|
||||
@click="openModule(module)"
|
||||
>
|
||||
<div class="module-card__icon">
|
||||
<component :is="module.icon" />
|
||||
</div>
|
||||
<div class="module-card__body">
|
||||
<div class="module-card__head">
|
||||
<div class="module-card__title">{{ module.title }}</div>
|
||||
<span class="module-card__badge">
|
||||
{{ module.readonly ? '仅查看' : (module.allowed ? '进入' : '受限') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="module-card__subtitle">{{ module.description }}</div>
|
||||
<div v-if="!module.allowed && module.disabledReason" class="module-card__hint">
|
||||
{{ module.disabledReason }}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</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 {
|
||||
DashboardOutlined,
|
||||
FileProtectOutlined,
|
||||
GiftOutlined,
|
||||
HomeOutlined,
|
||||
MessageOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
ShopOutlined,
|
||||
SettingOutlined,
|
||||
TagOutlined,
|
||||
TeamOutlined,
|
||||
UserOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import {
|
||||
getAdminCurrentShopName,
|
||||
getAdminRoleLabel,
|
||||
isBootstrapAdminUser,
|
||||
loadCachedAdminUserInfo
|
||||
} from './admin-helpers'
|
||||
|
||||
/**
|
||||
* Purpose: router supports ManageView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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 = [
|
||||
{
|
||||
key: 'dashboard',
|
||||
title: '仪表盘',
|
||||
description: '查看经营概览、近期动态和重点提醒。',
|
||||
path: '/admin/dashboard',
|
||||
icon: DashboardOutlined,
|
||||
permissionCode: 'dashboard:view'
|
||||
},
|
||||
{
|
||||
key: 'users',
|
||||
title: '用户管理',
|
||||
description: '处理账号、资产、VIP 和店铺关系。',
|
||||
path: '/admin/users',
|
||||
icon: UserOutlined,
|
||||
permissionCode: 'user:view',
|
||||
requireShopContext: true,
|
||||
allowPlatformOverviewManage: true
|
||||
},
|
||||
{
|
||||
key: 'products',
|
||||
title: '作品管理',
|
||||
description: '维护作品、标签、可预约美甲师和优惠券。',
|
||||
path: '/admin/products',
|
||||
icon: ShopOutlined,
|
||||
permissionCode: 'product:view',
|
||||
requireShopContext: true
|
||||
},
|
||||
{
|
||||
key: 'coupons',
|
||||
title: '优惠券',
|
||||
description: '管理券模板、场景和批量发放入口。',
|
||||
path: '/admin/coupons',
|
||||
icon: GiftOutlined,
|
||||
permissionCode: 'coupon:view',
|
||||
requireShopContext: true
|
||||
},
|
||||
{
|
||||
key: 'tags',
|
||||
title: '标签管理',
|
||||
description: '维护作品标签及颜色风格。',
|
||||
path: '/admin/tags',
|
||||
icon: TagOutlined,
|
||||
permissionCode: 'tag:view',
|
||||
requireShopContext: true
|
||||
},
|
||||
{
|
||||
key: 'artists',
|
||||
title: '美甲师',
|
||||
description: '查看状态、技能与作品挂载关系。',
|
||||
path: '/admin/nail-artists',
|
||||
icon: TeamOutlined,
|
||||
permissionCode: 'nail_artist:view',
|
||||
requireShopContext: true
|
||||
},
|
||||
{
|
||||
key: 'shops',
|
||||
title: '店铺管理',
|
||||
description: '创建门店、调整营业信息与图片素材。',
|
||||
path: '/admin/shops',
|
||||
icon: HomeOutlined,
|
||||
permissionCode: 'shop:view'
|
||||
},
|
||||
{
|
||||
key: 'permissions',
|
||||
title: '权限管理',
|
||||
description: '查看权限列表并给后台账号分配权限。',
|
||||
path: '/admin/permissions',
|
||||
icon: SafetyCertificateOutlined,
|
||||
permissionCode: 'permission:view'
|
||||
},
|
||||
{
|
||||
key: 'messages',
|
||||
title: '消息发布',
|
||||
description: '发布站内消息,可面向全平台或指定范围。',
|
||||
path: '/admin/messages',
|
||||
icon: MessageOutlined,
|
||||
permissionCode: 'message:view'
|
||||
},
|
||||
{
|
||||
key: 'announcements',
|
||||
title: '公告管理',
|
||||
description: '维护首页滚动公告,支持平台和门店范围。',
|
||||
path: '/admin/announcements',
|
||||
icon: MessageOutlined,
|
||||
permissionCode: 'announcement:view'
|
||||
},
|
||||
{
|
||||
key: 'vip-plans',
|
||||
title: 'VIP充值配置',
|
||||
description: '维护充值档位和 VIP 等级来源。',
|
||||
path: '/admin/vip-recharge-plans',
|
||||
icon: GiftOutlined,
|
||||
permissionCode: 'user:vip:manage',
|
||||
requireShopContext: true
|
||||
},
|
||||
{
|
||||
key: 'parameters',
|
||||
title: '参数管理',
|
||||
description: '维护地图 Key、短信 MessageHub 等系统参数。',
|
||||
path: '/admin/messagehub-push-configs',
|
||||
icon: SettingOutlined,
|
||||
permissionCode: 'messagehub:config:manage'
|
||||
},
|
||||
{
|
||||
key: 'agreements',
|
||||
title: '协议管理',
|
||||
description: '维护用户协议和隐私政策版本。',
|
||||
path: '/admin/legal-agreements',
|
||||
icon: FileProtectOutlined,
|
||||
permissionCode: 'legal_agreement:manage'
|
||||
}
|
||||
]
|
||||
|
||||
return definitions
|
||||
.filter(module => !module.permissionCode || hasPermission(module.permissionCode))
|
||||
.map(module => {
|
||||
if (module.requireShopContext && isBootstrapAdmin.value && !module.allowPlatformOverviewManage) {
|
||||
return {
|
||||
...module,
|
||||
allowed: true,
|
||||
readonly: true,
|
||||
disabledReason: '平台总览模式下该模块仅可查看,编辑操作已关闭。'
|
||||
}
|
||||
}
|
||||
return {
|
||||
...module,
|
||||
allowed: true,
|
||||
readonly: false,
|
||||
disabledReason: ''
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
/** openModule is a local helper used by this page script. */
|
||||
const openModule = (module: any) => {
|
||||
if (!module.allowed) {
|
||||
message.warning(module.disabledReason || '当前无法进入该模块')
|
||||
return
|
||||
}
|
||||
router.push(module.path)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadUserPermissions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-manage {
|
||||
display: grid;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.module-grid {
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.module-card {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 14px;
|
||||
padding: 18px;
|
||||
border: 1px solid var(--admin-mobile-border);
|
||||
border-radius: 24px;
|
||||
background: var(--admin-mobile-card);
|
||||
text-align: left;
|
||||
box-shadow: 0 12px 30px rgba(144, 103, 84, 0.08);
|
||||
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.module-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 18px 36px rgba(144, 103, 84, 0.12);
|
||||
}
|
||||
|
||||
.module-card.is-disabled {
|
||||
opacity: 0.78;
|
||||
}
|
||||
|
||||
.module-card__icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border-radius: 18px;
|
||||
background: var(--admin-mobile-accent-soft);
|
||||
color: var(--theme-primary);
|
||||
flex-shrink: 0;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.module-card__body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.module-card__head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.module-card__title {
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.module-card__badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 28px;
|
||||
padding: 0 10px;
|
||||
border-radius: 999px;
|
||||
background: var(--theme-primary-soft);
|
||||
color: var(--theme-primary);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.module-card__subtitle {
|
||||
margin-top: 8px;
|
||||
line-height: 1.6;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.module-card__hint {
|
||||
margin-top: 10px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 14px;
|
||||
background: var(--theme-primary-soft);
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.admin-manage {
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.admin-manage__intro {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.module-grid {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.module-card {
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
border-radius: 18px;
|
||||
box-shadow: 0 8px 20px rgba(144, 103, 84, 0.07);
|
||||
}
|
||||
|
||||
.module-card:hover {
|
||||
transform: none;
|
||||
box-shadow: 0 8px 20px rgba(144, 103, 84, 0.07);
|
||||
}
|
||||
|
||||
.module-card__icon {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: 14px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.module-card__head {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.module-card__title {
|
||||
font-size: 16px;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.module-card__badge {
|
||||
min-height: 24px;
|
||||
padding: 0 8px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.module-card__subtitle {
|
||||
margin-top: 5px;
|
||||
font-size: 13px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.module-card__hint {
|
||||
margin-top: 8px;
|
||||
padding: 8px 10px;
|
||||
border-radius: 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 420px) {
|
||||
.module-card {
|
||||
padding: 12px 14px;
|
||||
}
|
||||
|
||||
.module-card__icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.module-card__head {
|
||||
gap: 8px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,480 @@
|
||||
<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="当前地图渠道">
|
||||
<a-radio-group v-model:value="mapProvider">
|
||||
<a-radio-button value="TENCENT">腾讯地图</a-radio-button>
|
||||
<a-radio-button value="AMAP">高德地图</a-radio-button>
|
||||
</a-radio-group>
|
||||
</a-form-item>
|
||||
<a-form-item label="腾讯 Web Key">
|
||||
<a-input-password v-model:value="mapForms.tencentWeb.configValue" placeholder="用于后台腾讯地图选点和 Web 展示" />
|
||||
</a-form-item>
|
||||
<a-form-item label="高德 Web Key">
|
||||
<a-input-password v-model:value="mapForms.amapWeb.configValue" placeholder="用于后台高德地图选点和 Web 展示" />
|
||||
</a-form-item>
|
||||
<a-form-item label="高德小程序 Key">
|
||||
<a-input-password v-model:value="mapForms.amapMini.configValue" placeholder="用于后续小程序端高德 SDK / API 调用" />
|
||||
</a-form-item>
|
||||
<a-form-item label="备注">
|
||||
<a-textarea v-model:value="mapRemark" :rows="2" placeholder="例如:默认使用腾讯地图,高德小程序 Key 单独申请填写" />
|
||||
</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-card title="用户默认密码" :bordered="false">
|
||||
<a-form layout="vertical">
|
||||
<a-alert
|
||||
type="info"
|
||||
show-icon
|
||||
message="后台新增用户时,密码留空会自动使用这里配置的默认密码。"
|
||||
class="inline-alert"
|
||||
/>
|
||||
<a-form-item label="后台新增用户默认密码">
|
||||
<a-input-password
|
||||
v-model:value="defaultPasswordForm.configValue"
|
||||
placeholder="请输入 8-32 位强密码"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="备注">
|
||||
<a-textarea v-model:value="defaultPasswordForm.remark" :rows="2" />
|
||||
</a-form-item>
|
||||
<a-form-item>
|
||||
<a-space>
|
||||
<a-switch v-model:checked="defaultPasswordEnabled" checked-children="启用" un-checked-children="停用" />
|
||||
<a-button type="primary" :loading="savingDefaultPassword" @click="saveDefaultPasswordConfig">
|
||||
保存默认密码
|
||||
</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" :scroll="{ x: 'max-content' }">
|
||||
<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: any) => 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 ? '编辑配置' : '新增配置'" :mask-closable="false" @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="测试投递" :mask-closable="false" @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'
|
||||
/**
|
||||
* Purpose: MessageHubPushConfigVO supports MessageHubPushConfigsView.vue by holding or executing the message hub push config vo page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import {
|
||||
adminMessageHubPushConfigApi,
|
||||
adminSystemParameterConfigApi,
|
||||
type MessageHubPushConfigVO,
|
||||
type SystemParameterConfigVO
|
||||
} 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)
|
||||
/**
|
||||
* Purpose: editingId supports MessageHubPushConfigsView.vue by holding or executing the editing id page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const editingId = ref<any>()
|
||||
/**
|
||||
* Purpose: testingId supports MessageHubPushConfigsView.vue by holding or executing the testing id page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const testingId = ref<any>()
|
||||
/** testPhone is a reactive state variable used by the template and event handlers. */
|
||||
const testPhone = ref('')
|
||||
/**
|
||||
* Purpose: configs supports MessageHubPushConfigsView.vue by holding or executing the configs page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const configs = ref<MessageHubPushConfigVO[]>([])
|
||||
/**
|
||||
* Purpose: savingMap supports MessageHubPushConfigsView.vue by holding or executing the saving map page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const savingMap = ref(false)
|
||||
const savingDefaultPassword = ref(false)
|
||||
/**
|
||||
* Purpose: mapEnabled supports MessageHubPushConfigsView.vue by holding or executing the map enabled page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const mapEnabled = ref(true)
|
||||
const defaultPasswordEnabled = ref(true)
|
||||
/**
|
||||
* Purpose: mapProvider supports MessageHubPushConfigsView.vue by holding or executing the map provider page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const mapProvider = ref<'TENCENT' | 'AMAP'>('TENCENT')
|
||||
/**
|
||||
* Purpose: mapRemark supports MessageHubPushConfigsView.vue by holding or executing the map remark page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const mapRemark = ref('地图渠道由平台管理员选择;高德 Web Key 与高德小程序 Key 分开填写。')
|
||||
/**
|
||||
* Purpose: createMapForm supports MessageHubPushConfigsView.vue by holding or executing the create map form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const createMapForm = (configKey: string, configName: string, remark: string) => ({
|
||||
configGroup: 'MAP',
|
||||
configKey,
|
||||
configName,
|
||||
configValue: '',
|
||||
enabled: 1,
|
||||
remark
|
||||
})
|
||||
/**
|
||||
* Purpose: mapForms supports MessageHubPushConfigsView.vue by holding or executing the map forms page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const mapForms = reactive({
|
||||
provider: createMapForm('MAP_PROVIDER', '当前地图渠道', 'TENCENT 或 AMAP;决定后台店铺选点默认使用哪个地图渠道'),
|
||||
tencentWeb: createMapForm('TENCENT_MAP_KEY', '腾讯 Web Key', '用于后台腾讯地图选点和 Web 展示'),
|
||||
amapWeb: createMapForm('AMAP_WEB_KEY', '高德 Web Key', '用于后台高德地图选点和 Web 展示'),
|
||||
amapMini: createMapForm('AMAP_MINI_KEY', '高德小程序 Key', '用于后续小程序端高德 SDK / API 调用')
|
||||
})
|
||||
const defaultPasswordForm = reactive<SystemParameterConfigVO>({
|
||||
configGroup: 'USER',
|
||||
configKey: 'DEFAULT_PASSWORD',
|
||||
configName: '后台新增用户默认密码',
|
||||
configValue: 'Fingertip@123',
|
||||
enabled: 1,
|
||||
remark: '后台新增用户不填写密码时使用;需满足 8-32 位且至少包含数字、小写字母、大写字母、特殊符号中的 3 类'
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: sceneOptions supports MessageHubPushConfigsView.vue by holding or executing the scene options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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' }
|
||||
]
|
||||
|
||||
/**
|
||||
* Purpose: sendMethodOptions supports MessageHubPushConfigsView.vue by holding or executing the send method options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const sendMethodOptions = [
|
||||
{ label: 'SPUG', value: 'SPUG' },
|
||||
{ label: 'OTHER', value: 'OTHER' }
|
||||
]
|
||||
|
||||
/**
|
||||
* Purpose: form supports MessageHubPushConfigsView.vue by holding or executing the form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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: ''
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: columns supports MessageHubPushConfigsView.vue by holding or executing the columns page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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, userConfigs] = await Promise.all([
|
||||
adminMessageHubPushConfigApi.listConfigs(),
|
||||
adminSystemParameterConfigApi.listConfigs('MAP'),
|
||||
adminSystemParameterConfigApi.listConfigs('USER')
|
||||
])
|
||||
configs.value = messageConfigs
|
||||
const providerConfig = mapConfigs.find(item => item.configKey === 'MAP_PROVIDER')
|
||||
const tencentMapConfig = mapConfigs.find(item => item.configKey === 'TENCENT_MAP_KEY')
|
||||
const amapWebConfig = mapConfigs.find(item => item.configKey === 'AMAP_WEB_KEY')
|
||||
const amapMiniConfig = mapConfigs.find(item => item.configKey === 'AMAP_MINI_KEY')
|
||||
if (providerConfig?.configValue) {
|
||||
mapProvider.value = providerConfig.configValue === 'AMAP' ? 'AMAP' : 'TENCENT'
|
||||
mapEnabled.value = providerConfig.enabled === 1
|
||||
Object.assign(mapForms.provider, providerConfig)
|
||||
}
|
||||
if (tencentMapConfig) Object.assign(mapForms.tencentWeb, tencentMapConfig)
|
||||
if (amapWebConfig) Object.assign(mapForms.amapWeb, amapWebConfig)
|
||||
if (amapMiniConfig) Object.assign(mapForms.amapMini, amapMiniConfig)
|
||||
const defaultPasswordConfig = userConfigs.find(item => item.configKey === 'DEFAULT_PASSWORD')
|
||||
if (defaultPasswordConfig) {
|
||||
Object.assign(defaultPasswordForm, defaultPasswordConfig)
|
||||
defaultPasswordEnabled.value = defaultPasswordConfig.enabled === 1
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: saveMapConfig supports MessageHubPushConfigsView.vue by holding or executing the save map config page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const saveMapConfig = async () => {
|
||||
savingMap.value = true
|
||||
try {
|
||||
await adminSystemParameterConfigApi.saveConfig({
|
||||
...mapForms.provider,
|
||||
configValue: mapProvider.value,
|
||||
enabled: mapEnabled.value ? 1 : 0
|
||||
})
|
||||
await adminSystemParameterConfigApi.saveConfig({
|
||||
...mapForms.tencentWeb,
|
||||
enabled: mapEnabled.value ? 1 : 0
|
||||
})
|
||||
await adminSystemParameterConfigApi.saveConfig({
|
||||
...mapForms.amapWeb,
|
||||
enabled: mapEnabled.value ? 1 : 0
|
||||
})
|
||||
await adminSystemParameterConfigApi.saveConfig({
|
||||
...mapForms.amapMini,
|
||||
enabled: mapEnabled.value ? 1 : 0
|
||||
})
|
||||
message.success('地图配置已保存')
|
||||
await load()
|
||||
} finally {
|
||||
savingMap.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const validateDefaultPasswordInput = () => {
|
||||
const password = defaultPasswordForm.configValue.trim()
|
||||
if (password.length < 8 || password.length > 32) {
|
||||
message.warning('默认密码长度需为 8-32 位')
|
||||
return false
|
||||
}
|
||||
const categoryCount = [
|
||||
/\d/.test(password),
|
||||
/[a-z]/.test(password),
|
||||
/[A-Z]/.test(password),
|
||||
/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password)
|
||||
].filter(Boolean).length
|
||||
if (categoryCount < 3) {
|
||||
message.warning('默认密码需至少包含数字、小写字母、大写字母、特殊符号中的 3 类')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
const saveDefaultPasswordConfig = async () => {
|
||||
if (!validateDefaultPasswordInput()) {
|
||||
return
|
||||
}
|
||||
savingDefaultPassword.value = true
|
||||
try {
|
||||
await adminSystemParameterConfigApi.saveConfig({
|
||||
...defaultPasswordForm,
|
||||
configValue: defaultPasswordForm.configValue.trim(),
|
||||
enabled: defaultPasswordEnabled.value ? 1 : 0
|
||||
})
|
||||
message.success('默认密码已保存')
|
||||
await load()
|
||||
} finally {
|
||||
savingDefaultPassword.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: var(--text-secondary); }
|
||||
.inline-alert { margin-bottom: 16px; }
|
||||
</style>
|
||||
@@ -0,0 +1,708 @@
|
||||
<template>
|
||||
<div class="nail-artists">
|
||||
<a-page-header v-if="!isMobile" title="美甲师管理" sub-title="管理美甲师详细信息" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">经营</span>
|
||||
<h1 class="admin-page-intro__title">美甲师管理</h1>
|
||||
<p class="admin-page-intro__subtitle">
|
||||
把状态、技能和作品挂载关系收成单列卡片,手机端可以直接查看和编辑。
|
||||
</p>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">美甲师 {{ nailArtistList.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">
|
||||
美甲师列表
|
||||
</template>
|
||||
<template #extra>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索美甲师姓名"
|
||||
:style="isMobile ? { width: '100%' } : { width: '250px' }"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="nailArtistList"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
@change="handleTableChange"
|
||||
row-key="userId"
|
||||
:scroll="{ x: 'max-content' }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'status'">
|
||||
<a-tag :color="getStatusColor(record.status)">
|
||||
{{ 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)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('nail_artist:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="nailArtistList" item-key="userId" empty-description="暂无美甲师数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.nickname }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.shopName || '未绑定店铺' }}</div>
|
||||
</div>
|
||||
<a-tag :color="getStatusColor(item.status)">{{ getStatusText(item.status) }}</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>身份</span>
|
||||
<strong>{{ item.identity || '--' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>从业年限</span>
|
||||
<strong>{{ item.experience ?? '--' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>评分</span>
|
||||
<strong>{{ item.rating || '--' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button v-if="hasPermission('nail_artist:view')" size="small" @click="showViewModal(item)">查看</a-button>
|
||||
<a-button v-if="hasPermission('nail_artist:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<!-- 编辑美甲师信息模态框 -->
|
||||
<AdminResponsiveModal
|
||||
v-model:open="modalVisible"
|
||||
title="编辑美甲师信息"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
:confirmLoading="modalLoading"
|
||||
:desktop-width="800"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="美甲师姓名" name="nickname">
|
||||
<a-input v-model:value="formState.nickname" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="身份" name="identity">
|
||||
<a-input
|
||||
v-model:value="formState.identity"
|
||||
placeholder="请输入身份"
|
||||
:disabled="!isShopOwner"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="从业年限" name="experience">
|
||||
<a-input-number
|
||||
v-model:value="formState.experience"
|
||||
:min="0"
|
||||
placeholder="请输入从业年限"
|
||||
:disabled="!isShopOwner"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="技能标签" name="skills">
|
||||
<a-select
|
||||
v-model:value="formState.skills"
|
||||
mode="multiple"
|
||||
placeholder="请选择技能标签"
|
||||
:loading="tagLoading"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="tag in tagList"
|
||||
:key="tag.id"
|
||||
:value="tag.id.toString()"
|
||||
>
|
||||
{{ tag.tagName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="状态" name="status">
|
||||
<a-select
|
||||
v-model:value="formState.status"
|
||||
placeholder="请选择状态"
|
||||
:disabled="!isShopOwner"
|
||||
>
|
||||
<a-select-option :value="1">营业中</a-select-option>
|
||||
<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"
|
||||
mode="multiple"
|
||||
placeholder="请选择作品作品"
|
||||
:loading="productLoading"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="product in productList"
|
||||
:key="product.id"
|
||||
:value="product.id.toString()"
|
||||
>
|
||||
{{ product.title }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="评分">
|
||||
<a-input v-model:value="formState.rating" :disabled="true" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<!-- 查看美甲师详情模态框 -->
|
||||
<AdminResponsiveModal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看美甲师详情"
|
||||
:footer="null"
|
||||
@cancel="handleViewModalCancel"
|
||||
:desktop-width="600"
|
||||
>
|
||||
<a-form
|
||||
:model="viewFormState"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="美甲师姓名">
|
||||
<a-input v-model:value="viewFormState.nickname" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺">
|
||||
<a-input v-model:value="viewFormState.shopName" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="身份">
|
||||
<a-input v-model:value="viewFormState.identity" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="从业年限">
|
||||
<a-input v-model:value="viewFormState.experience" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="技能标签">
|
||||
<a-input v-model:value="viewFormState.skillsText" :disabled="true" />
|
||||
</a-form-item>
|
||||
<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>
|
||||
<a-form-item label="作品">
|
||||
<a-input v-model:value="viewFormState.portfolioText" :disabled="true" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
</div>
|
||||
</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'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
/**
|
||||
* Purpose: NailArtistInfoVO supports NailArtistsView.vue by holding or executing the nail artist info vo page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { adminNailArtistApi, type NailArtistInfoVO } from '@/api/admin'
|
||||
/**
|
||||
* Purpose: Tag supports NailArtistsView.vue by holding or executing the tag page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { adminTagApi, type Tag } from '@/api/admin'
|
||||
/**
|
||||
* Purpose: Product supports NailArtistsView.vue by holding or executing the product page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { adminProductApi, type Product } from '@/api/admin'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
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')
|
||||
if (userInfoStr) {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
isAdmin.value = userInfo.type === 4
|
||||
isShopOwner.value = userInfo.type === 2
|
||||
return userInfo
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
}
|
||||
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('')
|
||||
/**
|
||||
* Purpose: nailArtistList supports NailArtistsView.vue by holding or executing the nail artist list page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const nailArtistList = ref<NailArtistInfoVO[]>([])
|
||||
/**
|
||||
* Purpose: tagList supports NailArtistsView.vue by holding or executing the tag list page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const tagList = ref<Tag[]>([])
|
||||
/**
|
||||
* Purpose: productList supports NailArtistsView.vue by holding or executing the product list page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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)
|
||||
/**
|
||||
* Purpose: formRef supports NailArtistsView.vue by holding or executing the form ref page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formRef = ref<FormInstance>()
|
||||
/**
|
||||
* Purpose: currentNailArtist supports NailArtistsView.vue by holding or executing the current nail artist page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const currentNailArtist = ref<NailArtistInfoVO | null>(null)
|
||||
/**
|
||||
* Purpose: currentUserInfo supports NailArtistsView.vue by holding or executing the current user info page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const currentUserInfo = getCurrentUserInfo()
|
||||
/**
|
||||
* Purpose: draftSavedAt supports NailArtistsView.vue by holding or executing the draft saved at page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
/**
|
||||
* Purpose: viewFormState supports NailArtistsView.vue by holding or executing the view form state page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const viewFormState = reactive({
|
||||
nickname: '',
|
||||
shopName: '',
|
||||
identity: '',
|
||||
experience: '',
|
||||
skillsText: '',
|
||||
statusText: '',
|
||||
userTypeName: '',
|
||||
workTime: '',
|
||||
rating: '',
|
||||
portfolioText: ''
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: pagination supports NailArtistsView.vue by holding or executing the pagination page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: formState supports NailArtistsView.vue by holding or executing the form state page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formState = reactive({
|
||||
userId: 0,
|
||||
identity: '',
|
||||
experience: 0,
|
||||
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) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(formState, {
|
||||
identity: draft.payload.identity ?? formState.identity,
|
||||
experience: typeof draft.payload.experience === 'number' ? draft.payload.experience : formState.experience,
|
||||
skills: Array.isArray(draft.payload.skills) ? draft.payload.skills : formState.skills,
|
||||
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
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: formRules supports NailArtistsView.vue by holding or executing the form rules page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formRules = {
|
||||
identity: [{ required: true, message: '请输入身份', trigger: 'blur' }],
|
||||
experience: [{ required: true, message: '请输入从业年限', trigger: 'blur' }],
|
||||
skills: [{ required: true, message: '请选择技能标签', trigger: 'change' }],
|
||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
||||
portfolio: [{ required: true, message: '请选择作品作品', trigger: 'change' }]
|
||||
} as any
|
||||
|
||||
/**
|
||||
* Purpose: columns supports NailArtistsView.vue by holding or executing the columns page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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' },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ 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 {
|
||||
const res = await adminTagApi.listAllTags() as unknown as Tag[]
|
||||
tagList.value = res || []
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败:', error)
|
||||
} finally {
|
||||
tagLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 {
|
||||
const params: any = {
|
||||
page: 1,
|
||||
size: 1000
|
||||
}
|
||||
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
|
||||
params.shopId = currentUserInfo.shopId
|
||||
}
|
||||
const res = await adminProductApi.listProducts(params) as unknown as { list: Product[] }
|
||||
productList.value = res.list || []
|
||||
} catch (error) {
|
||||
console.error('获取作品列表失败:', error)
|
||||
} finally {
|
||||
productLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 {
|
||||
const res = await adminNailArtistApi.listNailArtists() as unknown as NailArtistInfoVO[]
|
||||
let filteredList = res || []
|
||||
|
||||
// 按搜索词过滤
|
||||
if (searchText.value) {
|
||||
filteredList = filteredList.filter((item: NailArtistInfoVO) =>
|
||||
item.nickname?.includes(searchText.value)
|
||||
)
|
||||
}
|
||||
|
||||
nailArtistList.value = filteredList
|
||||
pagination.total = filteredList.length || 0
|
||||
} catch (error) {
|
||||
message.error('获取美甲师列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 = {
|
||||
userId: record.userId,
|
||||
rating: record.rating || 0,
|
||||
nickname: record.nickname || ''
|
||||
}
|
||||
Object.assign(formState, {
|
||||
identity: record.identity || '',
|
||||
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
|
||||
})
|
||||
restoreDraft()
|
||||
Object.assign(formState, lockedFields)
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showViewModal is a local helper used by this page script. */
|
||||
const showViewModal = (record: Record<string, any>) => {
|
||||
const nailArtist = record as NailArtistInfoVO
|
||||
// 构建技能标签文本
|
||||
const skillsArray = nailArtist.skills ? nailArtist.skills.split(',').filter(Boolean) : []
|
||||
const skillsText = skillsArray.map(skillId => {
|
||||
const tag = tagList.value.find(t => t.id.toString() === skillId)
|
||||
return tag ? tag.tagName : skillId
|
||||
}).join(', ')
|
||||
|
||||
// 构建作品文本
|
||||
const portfolioArray = nailArtist.portfolio ? nailArtist.portfolio.split(',').filter(Boolean) : []
|
||||
const portfolioText = portfolioArray.map(productId => {
|
||||
const product = productList.value.find(p => p.id.toString() === productId)
|
||||
return product ? product.title : productId
|
||||
}).join(', ')
|
||||
|
||||
Object.assign(viewFormState, {
|
||||
nickname: nailArtist.nickname || '',
|
||||
shopName: nailArtist.shopName || '',
|
||||
identity: nailArtist.identity || '',
|
||||
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()
|
||||
|
||||
const targetUserId = currentNailArtist.value?.userId ?? formState.userId
|
||||
if (!targetUserId) {
|
||||
message.error('未获取到当前美甲师信息,请关闭弹窗后重试')
|
||||
return
|
||||
}
|
||||
|
||||
modalLoading.value = true
|
||||
|
||||
await runWithGlobalLoading(async () => {
|
||||
// 准备提交数据
|
||||
const submitData = {
|
||||
userId: targetUserId,
|
||||
identity: formState.identity,
|
||||
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(',')
|
||||
}
|
||||
|
||||
await adminNailArtistApi.saveNailArtistInfo(submitData)
|
||||
message.success('保存成功')
|
||||
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
await fetchNailArtistList()
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
const errorMessage = (error as Error)?.message
|
||||
if (errorMessage) {
|
||||
message.error(errorMessage)
|
||||
return
|
||||
}
|
||||
message.error('操作失败')
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** handleModalCancel is a local helper used by this page script. */
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
currentNailArtist.value = null
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
fetchTagList()
|
||||
fetchProductList()
|
||||
fetchNailArtistList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.nail-artists {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,835 @@
|
||||
<template>
|
||||
<div class="permissions">
|
||||
<a-page-header v-if="!isMobile" title="权限管理" sub-title="管理系统权限和用户权限分配" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">经营</span>
|
||||
<h1 class="admin-page-intro__title">权限管理</h1>
|
||||
<p class="admin-page-intro__subtitle">
|
||||
手机端拆成“权限列表”和“用户权限”两段流程,先选人再分配,避免保留桌面双栏布局。
|
||||
</p>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">权限 {{ permissionList.length }}</span>
|
||||
<span class="admin-page-chip">用户 {{ filteredUserList.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<a-tabs v-model:activeKey="activeTab">
|
||||
<a-tab-pane key="permissions" tab="权限列表">
|
||||
<div style="margin-bottom: 16px;" :style="isMobile ? {} : { textAlign: 'right' }">
|
||||
<a-button v-if="!isMobile && hasPermission('permission:create')" type="primary" @click="showAddPermissionModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增权限
|
||||
</a-button>
|
||||
</div>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="permissionColumns"
|
||||
:data-source="permissionList"
|
||||
:loading="loading"
|
||||
:pagination="permissionPagination"
|
||||
:scroll="{ x: 'max-content' }"
|
||||
@change="handlePermissionTableChange"
|
||||
row-key="id"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'permissionGroup'">
|
||||
<a-tag color="purple">{{ record.permissionGroup }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'permissionCode'">
|
||||
<div style="max-width: 220px;">
|
||||
<TableEllipsisText :text="record.permissionCode" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'permissionName'">
|
||||
<div style="max-width: 180px;">
|
||||
<TableEllipsisText :text="record.permissionName" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'description'">
|
||||
<div style="max-width: 320px;">
|
||||
<TableEllipsisText :text="record.description" :lines="2" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('permission:edit')" type="link" size="small" @click="showEditPermissionModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
v-if="hasPermission('permission:delete')"
|
||||
title="确定要删除这个权限吗?"
|
||||
@confirm="handleDeletePermission(record)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="permissionList" empty-description="暂无权限数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.permissionName }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.permissionCode }}</div>
|
||||
</div>
|
||||
<a-tag color="purple">{{ item.permissionGroup }}</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__description">{{ item.description }}</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>创建时间</span>
|
||||
<strong>{{ item.createTime }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button v-if="hasPermission('permission:edit')" size="small" @click="showEditPermissionModal(item)">编辑</a-button>
|
||||
<a-button v-if="hasPermission('permission:delete')" size="small" danger @click="handleDeletePermission(item)">删除</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-tab-pane>
|
||||
|
||||
<a-tab-pane v-if="hasPermission('permission:assign')" key="user-permissions" tab="用户权限分配">
|
||||
<template v-if="!isMobile">
|
||||
<a-row :gutter="16">
|
||||
<a-col :span="8">
|
||||
<a-card title="选择用户" :bordered="false">
|
||||
<a-input-search
|
||||
v-model:value="userSearchText"
|
||||
placeholder="搜索用户"
|
||||
style="margin-bottom: 16px"
|
||||
@search="handleUserSearch"
|
||||
/>
|
||||
<a-list
|
||||
:data-source="filteredUserList"
|
||||
:loading="userLoading"
|
||||
item-layout="horizontal"
|
||||
size="small"
|
||||
>
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item
|
||||
:class="{ selected: sameId(selectedUser?.id, item.id) }"
|
||||
style="cursor: pointer;"
|
||||
@click="selectUser(item)"
|
||||
>
|
||||
<a-list-item-meta>
|
||||
<template #avatar>
|
||||
<a-avatar :src="item.avatar || DEFAULT_AVATAR" />
|
||||
</template>
|
||||
<template #title>{{ item.nickname }}</template>
|
||||
<template #description>{{ item.account }} - {{ getUserTypeText(item.type) }}</template>
|
||||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :span="16">
|
||||
<a-card
|
||||
title="分配权限"
|
||||
:bordered="false"
|
||||
>
|
||||
<template #extra>
|
||||
<a-button v-if="selectedUser && hasPermission('permission:assign')" type="primary" @click="handleSaveUserPermissions">
|
||||
保存权限
|
||||
</a-button>
|
||||
</template>
|
||||
<template v-if="selectedUser">
|
||||
<a-alert
|
||||
:message="`当前用户: ${selectedUser.nickname}`"
|
||||
:description="`用户类型: ${getUserTypeText(selectedUser.type)}`"
|
||||
type="info"
|
||||
show-icon
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
<a-alert
|
||||
v-if="disabledPermissionCount > 0"
|
||||
:message="`有 ${disabledPermissionCount} 项权限不在该角色可分配范围内,已禁止选择`"
|
||||
type="warning"
|
||||
show-icon
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
|
||||
<a-spin :spinning="assignLoading">
|
||||
<a-checkbox-group v-model:value="selectedPermissions">
|
||||
<a-collapse v-model:activeKey="activeCollapseKeys">
|
||||
<a-collapse-panel
|
||||
v-for="(permissions, group) in groupedPermissions"
|
||||
:key="group"
|
||||
:header="group"
|
||||
>
|
||||
<a-space direction="vertical" style="width: 100%">
|
||||
<a-checkbox
|
||||
v-for="permission in permissions"
|
||||
:key="permission.id"
|
||||
:value="permission.id"
|
||||
:disabled="isPermissionDisabled(permission)"
|
||||
>
|
||||
{{ permission.permissionName }}
|
||||
<span style="color: var(--text-secondary); font-size: 12px; margin-left: 8px;">
|
||||
({{ permission.permissionCode }})
|
||||
</span>
|
||||
<span
|
||||
v-if="isPermissionDisabled(permission)"
|
||||
style="color: #ff4d4f; font-size: 12px; margin-left: 8px;"
|
||||
>
|
||||
不可分配
|
||||
</span>
|
||||
</a-checkbox>
|
||||
</a-space>
|
||||
</a-collapse-panel>
|
||||
</a-collapse>
|
||||
</a-checkbox-group>
|
||||
</a-spin>
|
||||
</template>
|
||||
<a-empty v-else description="请先选择一个用户" />
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="mobile-permission-flow">
|
||||
<template v-if="mobilePermissionStep === 'users' || !selectedUser">
|
||||
<a-input-search
|
||||
v-model:value="userSearchText"
|
||||
placeholder="搜索用户"
|
||||
style="margin-bottom: 16px"
|
||||
@search="handleUserSearch"
|
||||
/>
|
||||
<AdminMobileCardList :items="filteredUserList" empty-description="暂无可分配权限的用户">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card" @click="selectUser(item)">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="mobile-user-pick">
|
||||
<a-avatar :src="item.avatar || DEFAULT_AVATAR" />
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.nickname }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.account }} · {{ getUserTypeText(item.type) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<span class="admin-mobile-card__badge">选择</span>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="mobile-assign-actions">
|
||||
<a-button @click="mobilePermissionStep = 'users'">返回选用户</a-button>
|
||||
<a-button type="primary" @click="handleSaveUserPermissions">保存权限</a-button>
|
||||
</div>
|
||||
|
||||
<a-alert
|
||||
:message="`当前用户: ${selectedUser.nickname}`"
|
||||
:description="`用户类型: ${getUserTypeText(selectedUser.type)}`"
|
||||
type="info"
|
||||
show-icon
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
<a-alert
|
||||
v-if="disabledPermissionCount > 0"
|
||||
:message="`有 ${disabledPermissionCount} 项权限不在该角色可分配范围内,已禁用`"
|
||||
type="warning"
|
||||
show-icon
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
|
||||
<a-spin :spinning="assignLoading">
|
||||
<a-checkbox-group v-model:value="selectedPermissions" style="width: 100%">
|
||||
<a-collapse v-model:activeKey="activeCollapseKeys">
|
||||
<a-collapse-panel
|
||||
v-for="(permissions, group) in groupedPermissions"
|
||||
:key="group"
|
||||
:header="group"
|
||||
>
|
||||
<a-space direction="vertical" style="width: 100%">
|
||||
<a-checkbox
|
||||
v-for="permission in permissions"
|
||||
:key="permission.id"
|
||||
:value="permission.id"
|
||||
:disabled="isPermissionDisabled(permission)"
|
||||
>
|
||||
{{ permission.permissionName }}
|
||||
<span style="color: var(--text-secondary); font-size: 12px; margin-left: 8px;">
|
||||
({{ permission.permissionCode }})
|
||||
</span>
|
||||
</a-checkbox>
|
||||
</a-space>
|
||||
</a-collapse-panel>
|
||||
</a-collapse>
|
||||
</a-checkbox-group>
|
||||
</a-spin>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</a-tab-pane>
|
||||
</a-tabs>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="permissionModalVisible"
|
||||
:title="isEditPermission ? '编辑权限' : '新增权限'"
|
||||
@ok="handlePermissionModalOk"
|
||||
@cancel="handlePermissionModalCancel"
|
||||
:confirmLoading="permissionModalLoading"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="permissionFormRef"
|
||||
:model="permissionFormState"
|
||||
:rules="permissionFormRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="权限编码" name="permissionCode">
|
||||
<a-input v-model:value="permissionFormState.permissionCode" placeholder="例如:product:add" />
|
||||
</a-form-item>
|
||||
<a-form-item label="权限名称" name="permissionName">
|
||||
<a-input v-model:value="permissionFormState.permissionName" placeholder="例如:添加作品" />
|
||||
</a-form-item>
|
||||
<a-form-item label="权限分组" name="permissionGroup">
|
||||
<a-select v-model:value="permissionFormState.permissionGroup" placeholder="请选择权限分组">
|
||||
<a-select-option value="作品管理">作品管理</a-select-option>
|
||||
<a-select-option value="店铺管理">店铺管理</a-select-option>
|
||||
<a-select-option value="用户管理">用户管理</a-select-option>
|
||||
<a-select-option value="权限管理">权限管理</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="权限描述" name="description">
|
||||
<a-textarea
|
||||
v-model:value="permissionFormState.description"
|
||||
placeholder="请输入权限描述"
|
||||
:rows="3"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminMobileFab
|
||||
:visible="isMobile && activeTab === 'permissions' && hasPermission('permission:create') && !permissionModalVisible"
|
||||
label="新增权限"
|
||||
@click="showAddPermissionModal"
|
||||
/>
|
||||
</div>
|
||||
</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'
|
||||
import type { Rule } from 'ant-design-vue/es/form'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import TableEllipsisText from '@/components/TableEllipsisText.vue'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
/**
|
||||
* Purpose: UserVO supports PermissionsView.vue by holding or executing the user vo page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { userApi, type UserVO } from '@/api/admin'
|
||||
/**
|
||||
* Purpose: PermissionVO supports PermissionsView.vue by holding or executing the permission vo page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { permissionApi, type PermissionVO } from '@/api/permission'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { sameId } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminMobileFab from '@/components/admin/AdminMobileFab.vue'
|
||||
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)
|
||||
/**
|
||||
* Purpose: permissionList supports PermissionsView.vue by holding or executing the permission list page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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)
|
||||
/**
|
||||
* Purpose: permissionFormRef supports PermissionsView.vue by holding or executing the permission form ref page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const permissionFormRef = ref<FormInstance>()
|
||||
/**
|
||||
* Purpose: currentPermission supports PermissionsView.vue by holding or executing the current permission page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const currentPermission = ref<PermissionVO | null>(null)
|
||||
/**
|
||||
* Purpose: draftSavedAt supports PermissionsView.vue by holding or executing the draft saved at page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
/**
|
||||
* Purpose: permissionPagination supports PermissionsView.vue by holding or executing the permission pagination page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const permissionPagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 20,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: permissionFormState supports PermissionsView.vue by holding or executing the permission form state page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const permissionFormState = reactive({
|
||||
permissionCode: '',
|
||||
permissionName: '',
|
||||
permissionGroup: '',
|
||||
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,
|
||||
permissionGroup: permissionFormState.permissionGroup,
|
||||
description: permissionFormState.description
|
||||
})
|
||||
|
||||
/** restoreDraft is a local helper used by this page script. */
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(permissionFormState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/** 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
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const permissionFormRules: Record<string, Rule[]> = {
|
||||
permissionCode: [{ required: true, message: '请输入权限编码', trigger: 'blur' }],
|
||||
permissionName: [{ required: true, message: '请输入权限名称', trigger: 'blur' }],
|
||||
permissionGroup: [{ required: true, message: '请选择权限分组', trigger: 'change' }],
|
||||
description: [{ required: true, message: '请输入权限描述', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: permissionColumns supports PermissionsView.vue by holding or executing the permission columns page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const permissionColumns = [
|
||||
{ title: '权限编码', dataIndex: 'permissionCode', key: 'permissionCode' },
|
||||
{ title: '权限名称', dataIndex: 'permissionName', key: 'permissionName' },
|
||||
{ title: '权限分组', key: 'permissionGroup', width: 120 },
|
||||
{ title: '权限描述', dataIndex: 'description', key: 'description' },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ 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('')
|
||||
/**
|
||||
* Purpose: userList supports PermissionsView.vue by holding or executing the user list page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const userList = ref<UserVO[]>([])
|
||||
/**
|
||||
* Purpose: selectedUser supports PermissionsView.vue by holding or executing the selected user page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const selectedUser = ref<UserVO | null>(null)
|
||||
/** assignLoading is a reactive state variable used by the template and event handlers. */
|
||||
const assignLoading = ref(false)
|
||||
/**
|
||||
* Purpose: selectedPermissions supports PermissionsView.vue by holding or executing the selected permissions page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const selectedPermissions = ref<IdType[]>([])
|
||||
/**
|
||||
* Purpose: assignablePermissionIds supports PermissionsView.vue by holding or executing the assignable permission ids page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const assignablePermissionIds = ref<IdType[]>([])
|
||||
/**
|
||||
* Purpose: activeCollapseKeys supports PermissionsView.vue by holding or executing the active collapse keys page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const activeCollapseKeys = ref<string[]>(['作品管理', '店铺管理', '用户管理', '权限管理'])
|
||||
/**
|
||||
* Purpose: currentLoginUser supports PermissionsView.vue by holding or executing the current login user page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const currentLoginUser = ref<UserVO | null>(null)
|
||||
/**
|
||||
* Purpose: mobilePermissionStep supports PermissionsView.vue by holding or executing the mobile permission step page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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 => {
|
||||
const groupName = p.permissionGroup
|
||||
if (!groups[groupName]) {
|
||||
groups[groupName] = []
|
||||
}
|
||||
groups[groupName]!.push(p)
|
||||
})
|
||||
return groups
|
||||
})
|
||||
|
||||
/** getUserTypeText is a local helper used by this page script. */
|
||||
const getUserTypeText = (type: number) => {
|
||||
const map: Record<number, string> = {
|
||||
0: '用户',
|
||||
2: '店长',
|
||||
3: '美甲师',
|
||||
4: '管理员'
|
||||
}
|
||||
return map[type] || '未知'
|
||||
}
|
||||
|
||||
/** filteredUserList is a reactive state variable used by the template and event handlers. */
|
||||
const filteredUserList = computed(() => {
|
||||
if (!currentLoginUser.value) return []
|
||||
|
||||
const currentUserId = currentLoginUser.value.id
|
||||
|
||||
// 管理员可以看到所有用户(除了普通用户和自己)
|
||||
if (currentLoginUser.value.type === 4) {
|
||||
return userList.value.filter(user => user.type !== 0 && !sameId(user.id, currentUserId))
|
||||
}
|
||||
|
||||
// 店长只能看到美甲师(除了自己)
|
||||
if (currentLoginUser.value.type === 2) {
|
||||
return userList.value.filter(user => user.type === 3 && !sameId(user.id, currentUserId))
|
||||
}
|
||||
|
||||
// 其他用户类型(如美甲师)不能管理权限
|
||||
return []
|
||||
})
|
||||
|
||||
/** isPermissionDisabled is a local helper used by this page script. */
|
||||
const isPermissionDisabled = (permission: PermissionVO) => {
|
||||
if (!selectedUser.value) {
|
||||
return true
|
||||
}
|
||||
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获取用户信息
|
||||
try {
|
||||
const res = await userApi.getUserInfo()
|
||||
currentLoginUser.value = res as unknown as UserVO
|
||||
} catch (apiError) {
|
||||
// 如果API调用失败,尝试从本地存储获取
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
try {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
currentLoginUser.value = userInfo as UserVO
|
||||
} catch (parseError) {
|
||||
console.error('解析本地存储的用户信息失败:', parseError)
|
||||
}
|
||||
} else {
|
||||
console.error('获取当前用户信息失败,本地存储也没有用户信息')
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 {
|
||||
const res = await permissionApi.listAllPermissions() as unknown as PermissionVO[]
|
||||
permissionList.value = res || []
|
||||
permissionPagination.total = res?.length || 0
|
||||
} catch (error) {
|
||||
message.error('获取权限列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 {
|
||||
const params: any = {
|
||||
page: 1,
|
||||
size: 100,
|
||||
keyword: userSearchText.value
|
||||
}
|
||||
|
||||
// 如果当前用户不是管理员,只获取当前店铺的用户
|
||||
if (currentLoginUser.value && currentLoginUser.value.type !== 4 && currentLoginUser.value.shopId) {
|
||||
params.shopId = currentLoginUser.value.shopId
|
||||
}
|
||||
|
||||
const res = await userApi.listUsers(params) as unknown as { list: UserVO[] }
|
||||
userList.value = res.list || []
|
||||
} catch (error) {
|
||||
message.error('获取用户列表失败')
|
||||
} finally {
|
||||
userLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 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
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
// 已分配权限和“当前角色允许分配的权限”需要分开拿,前端只保留交集,避免保存时越权。
|
||||
const [assignedPermissions, allowedIds] = await Promise.all([
|
||||
permissionApi.getUserPermissions(user.id) as unknown as Promise<PermissionVO[]>,
|
||||
permissionApi.getAssignablePermissionIds(user.id) as unknown as Promise<IdType[]>
|
||||
])
|
||||
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
|
||||
if (trimmedCount > 0) {
|
||||
message.warning(`已自动排除 ${trimmedCount} 项超出当前角色允许范围的权限`)
|
||||
}
|
||||
})
|
||||
} catch (error: any) {
|
||||
message.error(resolveRequestErrorMessage(error, '获取用户权限失败'))
|
||||
assignablePermissionIds.value = []
|
||||
selectedPermissions.value = []
|
||||
} finally {
|
||||
assignLoading.value = false
|
||||
if (isMobile.value) {
|
||||
mobilePermissionStep.value = 'assign'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 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
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await permissionApi.assignUserPermissions(userId, selectedPermissions.value)
|
||||
message.success('权限保存成功')
|
||||
// 重新加载当前用户的权限
|
||||
await loadUserPermissions()
|
||||
})
|
||||
} catch (error: any) {
|
||||
message.error(resolveRequestErrorMessage(error, '权限保存失败'))
|
||||
}
|
||||
}
|
||||
|
||||
/** showAddPermissionModal is a local helper used by this page script. */
|
||||
const showAddPermissionModal = () => {
|
||||
isEditPermission.value = false
|
||||
currentPermission.value = null
|
||||
Object.assign(permissionFormState, {
|
||||
permissionCode: '',
|
||||
permissionName: '',
|
||||
permissionGroup: '',
|
||||
description: ''
|
||||
})
|
||||
restoreDraft()
|
||||
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
|
||||
Object.assign(permissionFormState, {
|
||||
permissionCode: record.permissionCode,
|
||||
permissionName: record.permissionName,
|
||||
permissionGroup: record.permissionGroup,
|
||||
description: record.description
|
||||
})
|
||||
restoreDraft()
|
||||
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()
|
||||
permissionModalLoading.value = true
|
||||
|
||||
await runWithGlobalLoading(async () => {
|
||||
if (isEditPermission.value && currentPermission.value) {
|
||||
await permissionApi.updatePermission(currentPermission.value.id, permissionFormState)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await permissionApi.createPermission(permissionFormState)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
handleClearDraft(false)
|
||||
permissionModalVisible.value = false
|
||||
await fetchPermissionList()
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
permissionModalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 () => {
|
||||
await permissionApi.deletePermission((record as PermissionVO).id)
|
||||
message.success('删除成功')
|
||||
await fetchPermissionList()
|
||||
})
|
||||
} catch (error) {
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchCurrentUser()
|
||||
await loadUserPermissions()
|
||||
fetchPermissionList()
|
||||
// 确保在获取当前用户信息后再获取用户列表
|
||||
setTimeout(() => {
|
||||
fetchUserList()
|
||||
}, 100)
|
||||
})
|
||||
|
||||
watch(
|
||||
() => activeTab.value,
|
||||
value => {
|
||||
if (value !== 'user-permissions') {
|
||||
mobilePermissionStep.value = 'users'
|
||||
}
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.permissions {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.selected {
|
||||
background: var(--theme-primary-soft) !important;
|
||||
border-left: 3px solid var(--theme-primary);
|
||||
}
|
||||
|
||||
.mobile-permission-flow {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.mobile-user-pick {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.mobile-assign-actions {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,260 @@
|
||||
<template>
|
||||
<div class="admin-profile">
|
||||
<section class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">{{ userInfo?.account || '后台账号' }}</span>
|
||||
<h1 class="admin-page-intro__title">{{ userInfo?.nickname || '未设置昵称' }}</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">权限 {{ permissionCount }}</span>
|
||||
<span class="admin-page-chip">门店 {{ shopOptions.length || 0 }}</span>
|
||||
<span class="admin-page-chip">{{ roleLabel }}</span>
|
||||
<span v-if="isPlatformOverview" class="admin-page-chip">平台总览</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="admin-mobile-grid admin-mobile-grid--two">
|
||||
<section class="admin-mobile-stat">
|
||||
<div class="admin-mobile-stat__label">当前门店</div>
|
||||
<div class="admin-mobile-stat__value">{{ currentShopName }}</div>
|
||||
</section>
|
||||
<section class="admin-mobile-stat">
|
||||
<div class="admin-mobile-stat__label">角色</div>
|
||||
<div class="admin-mobile-stat__value">{{ roleLabel }}</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">账号信息</div>
|
||||
<div class="profile-meta-list">
|
||||
<div class="profile-meta-list__row">
|
||||
<span>账号</span>
|
||||
<strong>{{ userInfo?.account || '--' }}</strong>
|
||||
</div>
|
||||
<div class="profile-meta-list__row">
|
||||
<span>昵称</span>
|
||||
<strong>{{ userInfo?.nickname || '--' }}</strong>
|
||||
</div>
|
||||
<div class="profile-meta-list__row">
|
||||
<span>权限数量</span>
|
||||
<strong>{{ permissionCount }}</strong>
|
||||
</div>
|
||||
<div class="profile-meta-list__row">
|
||||
<span>可登录门店</span>
|
||||
<strong>{{ shopScopeText }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">{{ isPlatformOverview ? '管理范围' : '门店切换' }}</div>
|
||||
<div v-if="isPlatformOverview" class="profile-static-shop">
|
||||
平台总览模式,店铺业务仅可查看
|
||||
</div>
|
||||
<a-select
|
||||
v-else-if="shopOptions.length > 1"
|
||||
v-model:value="selectedShopId"
|
||||
class="profile-shop-select"
|
||||
:options="shopSelectOptions"
|
||||
:loading="shopSwitchLoading"
|
||||
@change="handleShopChange"
|
||||
/>
|
||||
<div v-else class="profile-static-shop">
|
||||
{{ currentShopName }}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">常用入口</div>
|
||||
<div class="profile-actions">
|
||||
<a-button type="default" size="large" block @click="router.push('/admin/orders')">查看订单</a-button>
|
||||
<a-button type="default" size="large" block @click="router.push('/admin/manage')">进入经营模块</a-button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="admin-mobile-section-card">
|
||||
<div class="admin-mobile-section-card__title">退出登录</div>
|
||||
<a-button danger size="large" block @click="handleLogout">退出当前账号</a-button>
|
||||
</section>
|
||||
</div>
|
||||
</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'
|
||||
import { adminAuthApi } from '@/api/admin'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { notifyShopThemeChanged } from '@/utils/shop-theme'
|
||||
import {
|
||||
getAdminCurrentShopName,
|
||||
getAdminRoleLabel,
|
||||
getAdminShopOptions,
|
||||
isBootstrapAdminUser,
|
||||
loadCachedAdminUserInfo
|
||||
} from './admin-helpers'
|
||||
|
||||
/**
|
||||
* Purpose: router supports ProfileView.vue by holding or executing the router page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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))
|
||||
/**
|
||||
* Purpose: isPlatformOverview supports ProfileView.vue by holding or executing the is platform overview page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const isPlatformOverview = computed(() => isBootstrapAdminUser(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(() => {
|
||||
const options = shopOptions.value.map(shop => ({ label: shop.name, value: shop.id }))
|
||||
return options
|
||||
})
|
||||
/** 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 isPlatformOverview.value ? '平台总览模式' : '游客模式'
|
||||
}
|
||||
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)
|
||||
localStorage.setItem('adminUserInfo', JSON.stringify(payload.userInfo))
|
||||
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
|
||||
}
|
||||
const normalizedShopId = String(shopId)
|
||||
if (!normalizedShopId || normalizedShopId === String(userInfo.value?.shopId || '')) {
|
||||
return
|
||||
}
|
||||
shopSwitchLoading.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
const response = await adminAuthApi.switchShop(normalizedShopId)
|
||||
persistAdminSession(response as any)
|
||||
refreshLocalUserInfo()
|
||||
await loadUserPermissions()
|
||||
notifyShopThemeChanged()
|
||||
})
|
||||
message.success('门店切换成功')
|
||||
window.location.reload()
|
||||
} catch (error: any) {
|
||||
selectedShopId.value = userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined
|
||||
message.error(error?.message || '切换门店失败')
|
||||
} finally {
|
||||
shopSwitchLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** handleLogout is a local helper used by this page script. */
|
||||
const handleLogout = () => {
|
||||
Modal.confirm({
|
||||
title: '确认退出登录',
|
||||
content: '退出后需要重新登录后台。',
|
||||
okText: '确认',
|
||||
cancelText: '取消',
|
||||
onOk: async () => {
|
||||
await runWithGlobalLoading(async () => {
|
||||
try {
|
||||
await adminAuthApi.logout()
|
||||
} catch (error) {
|
||||
console.error('退出失败:', error)
|
||||
} finally {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
clearPermissions()
|
||||
message.success('已退出登录')
|
||||
window.location.href = '/admin/login'
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
refreshLocalUserInfo()
|
||||
await loadUserPermissions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-profile {
|
||||
display: grid;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.profile-meta-list {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.profile-meta-list__row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.profile-meta-list__row strong {
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.profile-shop-select {
|
||||
width: 100%;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.profile-static-shop {
|
||||
margin-top: 14px;
|
||||
min-height: 46px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 14px;
|
||||
border-radius: 16px;
|
||||
background: var(--admin-mobile-accent-soft);
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.profile-actions {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,309 @@
|
||||
<template>
|
||||
<div class="schedules">
|
||||
<a-page-header v-if="!isMobile" title="排班管理" sub-title="维护美甲师班次、容量和可约状态" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">排班</span>
|
||||
<h1 class="admin-page-intro__title">排班管理</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">班次 {{ schedules.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">班次列表</template>
|
||||
<template #extra>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-button type="primary" @click="openCreateModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增排班
|
||||
</a-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<AdminFilterPanel :active-count="activeFilterCount">
|
||||
<a-select
|
||||
v-model:value="filters.artistId"
|
||||
allow-clear
|
||||
placeholder="选择美甲师"
|
||||
:options="artistOptions"
|
||||
style="width: 180px"
|
||||
@change="loadSchedules"
|
||||
/>
|
||||
<a-range-picker
|
||||
v-model:value="filters.dateRange"
|
||||
value-format="YYYY-MM-DD"
|
||||
style="width: 240px"
|
||||
@change="loadSchedules"
|
||||
/>
|
||||
<a-button @click="resetFilters">重置筛选</a-button>
|
||||
</AdminFilterPanel>
|
||||
|
||||
<a-table v-if="!isMobile" :columns="columns" :data-source="schedules" :loading="loading" row-key="id" :scroll="{ x: 'max-content' }">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'artist'">{{ artistName(record.artistId) }}</template>
|
||||
<template v-else-if="column.key === 'time'">{{ record.startTime }} - {{ record.endTime }}</template>
|
||||
<template v-else-if="column.key === 'capacity'">{{ record.capacity ?? '-' }} / {{ record.slotMinutes ?? '-' }} 分钟</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 0 ? 'red' : 'green'">{{ scheduleStatusText(record.status) }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-button type="link" size="small" @click="openEditModal(record as ArtistScheduleVO)">编辑</a-button>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="schedules" empty-description="暂无排班数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ artistName(item.artistId) }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.workDate }} {{ item.startTime }} - {{ item.endTime }}</div>
|
||||
</div>
|
||||
<a-tag :color="item.status === 0 ? 'red' : 'green'">{{ scheduleStatusText(item.status) }}</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>容量</span>
|
||||
<strong>{{ item.capacity ?? '-' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>间隔</span>
|
||||
<strong>{{ item.slotMinutes ?? '-' }} 分钟</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>备注</span>
|
||||
<strong>{{ item.remark || '-' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button size="small" @click="openEditModal(item)">编辑</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="modalOpen"
|
||||
:title="editingSchedule ? '编辑排班' : '新增排班'"
|
||||
:desktop-width="720"
|
||||
:confirm-loading="saving"
|
||||
@ok="saveSchedule"
|
||||
@cancel="closeModal"
|
||||
>
|
||||
<a-form ref="formRef" :model="formState" :rules="rules" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
|
||||
<a-form-item label="美甲师" name="artistId">
|
||||
<a-select v-model:value="formState.artistId" placeholder="选择美甲师" :options="artistOptions" />
|
||||
</a-form-item>
|
||||
<a-form-item label="工作日期" name="workDate">
|
||||
<a-date-picker v-model:value="formState.workDate" value-format="YYYY-MM-DD" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="开始时间" name="startTime">
|
||||
<a-input v-model:value="formState.startTime" placeholder="09:00:00" />
|
||||
</a-form-item>
|
||||
<a-form-item label="结束时间" name="endTime">
|
||||
<a-input v-model:value="formState.endTime" placeholder="18:00:00" />
|
||||
</a-form-item>
|
||||
<a-form-item label="预约间隔">
|
||||
<a-input-number v-model:value="formState.slotMinutes" :min="5" :step="5" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="容量">
|
||||
<a-input-number v-model:value="formState.capacity" :min="1" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="状态">
|
||||
<a-select v-model:value="formState.status">
|
||||
<a-select-option :value="1">可预约</a-select-option>
|
||||
<a-select-option :value="0">停用</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="备注">
|
||||
<a-textarea v-model:value="formState.remark" :rows="3" :maxlength="200" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import {
|
||||
adminArtistScheduleApi,
|
||||
adminNailArtistApi,
|
||||
type ArtistScheduleRequest,
|
||||
type ArtistScheduleVO,
|
||||
type NailArtistInfoVO
|
||||
} from '@/api/admin'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminFilterPanel from '@/components/admin/AdminFilterPanel.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { isMobile } = useAdminViewport()
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const modalOpen = ref(false)
|
||||
const schedules = ref<ArtistScheduleVO[]>([])
|
||||
const artists = ref<NailArtistInfoVO[]>([])
|
||||
const editingSchedule = ref<ArtistScheduleVO | null>(null)
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const filters = reactive({
|
||||
artistId: undefined as string | undefined,
|
||||
dateRange: undefined as [string, string] | undefined
|
||||
})
|
||||
|
||||
const formState = reactive<ArtistScheduleRequest>({
|
||||
artistId: undefined,
|
||||
workDate: '',
|
||||
startTime: '09:00:00',
|
||||
endTime: '18:00:00',
|
||||
slotMinutes: 30,
|
||||
capacity: 1,
|
||||
status: 1,
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const rules = {
|
||||
artistId: [{ required: true, message: '请选择美甲师', trigger: 'change' }],
|
||||
workDate: [{ required: true, message: '请选择工作日期', trigger: 'change' }],
|
||||
startTime: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
|
||||
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }]
|
||||
} as any
|
||||
|
||||
const columns = [
|
||||
{ title: '美甲师', key: 'artist', width: 160 },
|
||||
{ title: '工作日期', dataIndex: 'workDate', key: 'workDate', width: 140 },
|
||||
{ title: '工作时段', key: 'time', width: 180 },
|
||||
{ title: '容量 / 间隔', key: 'capacity', width: 140 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '备注', dataIndex: 'remark', key: 'remark' },
|
||||
{ title: '操作', key: 'actions', width: 90 }
|
||||
]
|
||||
|
||||
const artistOptions = computed(() => artists.value.map(artist => ({
|
||||
label: artist.nickname || artist.identity || `美甲师 ${artist.userId}`,
|
||||
value: String(artist.userId || artist.id)
|
||||
})))
|
||||
|
||||
const activeFilterCount = computed(() => [
|
||||
filters.artistId,
|
||||
filters.dateRange?.length ? 'date' : ''
|
||||
].filter(Boolean).length)
|
||||
|
||||
const artistName = (artistId?: unknown) => {
|
||||
const artist = artists.value.find(item => String(item.userId || item.id) === String(artistId))
|
||||
return artist?.nickname || artist?.identity || (artistId ? `美甲师 ${artistId}` : '-')
|
||||
}
|
||||
|
||||
const scheduleStatusText = (status?: number) => status === 0 ? '停用' : '可预约'
|
||||
|
||||
const resetForm = () => {
|
||||
Object.assign(formState, {
|
||||
artistId: undefined,
|
||||
workDate: '',
|
||||
startTime: '09:00:00',
|
||||
endTime: '18:00:00',
|
||||
slotMinutes: 30,
|
||||
capacity: 1,
|
||||
status: 1,
|
||||
remark: ''
|
||||
})
|
||||
}
|
||||
|
||||
const loadArtists = async () => {
|
||||
try {
|
||||
artists.value = await adminNailArtistApi.listNailArtists() as unknown as NailArtistInfoVO[]
|
||||
} catch (error) {
|
||||
console.error('加载美甲师失败:', error)
|
||||
artists.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const loadSchedules = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
schedules.value = await adminArtistScheduleApi.listSchedules({
|
||||
artistId: filters.artistId,
|
||||
startDate: filters.dateRange?.[0],
|
||||
endDate: filters.dateRange?.[1]
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('加载排班失败:', error)
|
||||
message.error('加载排班失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resetFilters = () => {
|
||||
filters.artistId = undefined
|
||||
filters.dateRange = undefined
|
||||
void loadSchedules()
|
||||
}
|
||||
|
||||
const openCreateModal = () => {
|
||||
editingSchedule.value = null
|
||||
resetForm()
|
||||
modalOpen.value = true
|
||||
}
|
||||
|
||||
const openEditModal = (record: ArtistScheduleVO) => {
|
||||
editingSchedule.value = record
|
||||
Object.assign(formState, {
|
||||
artistId: String(record.artistId),
|
||||
workDate: record.workDate,
|
||||
startTime: record.startTime,
|
||||
endTime: record.endTime,
|
||||
slotMinutes: record.slotMinutes ?? 30,
|
||||
capacity: record.capacity ?? 1,
|
||||
status: record.status ?? 1,
|
||||
remark: record.remark || ''
|
||||
})
|
||||
modalOpen.value = true
|
||||
}
|
||||
|
||||
const closeModal = () => {
|
||||
modalOpen.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const saveSchedule = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
saving.value = true
|
||||
await runWithGlobalLoading(async () => {
|
||||
await adminArtistScheduleApi.saveSchedule({ ...formState })
|
||||
await loadSchedules()
|
||||
})
|
||||
message.success('排班已保存')
|
||||
closeModal()
|
||||
} catch (error: any) {
|
||||
if (error?.errorFields) {
|
||||
return
|
||||
}
|
||||
console.error('保存排班失败:', error)
|
||||
message.error(error?.message || '保存排班失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadArtists()
|
||||
await loadSchedules()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.schedules {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,727 @@
|
||||
<template>
|
||||
<div class="system-messages admin-page">
|
||||
<section class="message-page-head">
|
||||
<a-page-header title="消息发布" sub-title="发布站内消息,支持文本和单张图片" />
|
||||
</section>
|
||||
|
||||
<section class="message-composer-shell">
|
||||
<div class="message-composer-grid">
|
||||
<article class="message-editor-panel">
|
||||
<div class="panel-heading">
|
||||
<div class="panel-heading__icon">
|
||||
<SendOutlined />
|
||||
</div>
|
||||
<div>
|
||||
<p class="panel-eyebrow">站内消息</p>
|
||||
<h2>发布消息</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a-form layout="vertical" :model="form" class="message-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="6" :maxlength="2000" placeholder="支持 HTML / Markdown,可配合图片展示" />
|
||||
</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">
|
||||
<PictureOutlined />
|
||||
<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>
|
||||
|
||||
<div class="scope-panel">
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<div class="publish-footer">
|
||||
<a-checkbox v-model:checked="popupEnabled" class="popup-checkbox">弹窗显示一次</a-checkbox>
|
||||
<a-space>
|
||||
<a-button @click="resetForm">清空</a-button>
|
||||
<a-button type="primary" :loading="saving" @click="handlePublish">
|
||||
<template #icon>
|
||||
<SendOutlined />
|
||||
</template>
|
||||
发布
|
||||
</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
</a-form>
|
||||
</article>
|
||||
|
||||
<aside class="message-preview-panel">
|
||||
<SystemMessageCard
|
||||
:title="previewTitle"
|
||||
:content="previewContent"
|
||||
:image-url="imagePreviewUrl"
|
||||
:meta="previewMeta"
|
||||
surface="preview"
|
||||
footer-align="end"
|
||||
>
|
||||
<template #footer>
|
||||
<button class="preview-read-button" type="button" tabindex="-1">
|
||||
<CheckOutlined />
|
||||
我知道了
|
||||
</button>
|
||||
</template>
|
||||
</SystemMessageCard>
|
||||
</aside>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<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 }" :scroll="{ x: 'max-content' }">
|
||||
<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" :footer="null" width="560px" wrap-class-name="message-detail-modal-wrap" :mask-closable="false">
|
||||
<SystemMessageCard
|
||||
:title="currentMessage?.title || '消息详情'"
|
||||
:content="currentMessage?.content || ''"
|
||||
:image-url="currentMessage?.imageUrl || ''"
|
||||
:meta="currentMessageMeta"
|
||||
surface="modal"
|
||||
footer-align="end"
|
||||
>
|
||||
<template #footer>
|
||||
<a-button type="primary" class="message-detail-close-button" @click="previewVisible = false">
|
||||
<template #icon>
|
||||
<CheckOutlined />
|
||||
</template>
|
||||
我知道了
|
||||
</a-button>
|
||||
</template>
|
||||
</SystemMessageCard>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import {
|
||||
CheckOutlined,
|
||||
PictureOutlined,
|
||||
SendOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import SystemMessageCard from '@/components/SystemMessageCard.vue'
|
||||
/**
|
||||
* Purpose: SystemMessageCreateRequest supports SystemMessagesView.vue by holding or executing the system message create request page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { adminFileApi, adminSystemMessageApi, type SystemMessageCreateRequest, type SystemMessageVO } from '@/api/admin'
|
||||
import type { IdType } from '@/utils/id'
|
||||
|
||||
/**
|
||||
* Purpose: loading supports SystemMessagesView.vue by holding or executing the loading page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const loading = ref(false)
|
||||
/**
|
||||
* Purpose: saving supports SystemMessagesView.vue by holding or executing the saving page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const saving = ref(false)
|
||||
/**
|
||||
* Purpose: imageUploading supports SystemMessagesView.vue by holding or executing the image uploading page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const imageUploading = ref(false)
|
||||
/**
|
||||
* Purpose: messages supports SystemMessagesView.vue by holding or executing the messages page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const messages = ref<SystemMessageVO[]>([])
|
||||
/**
|
||||
* Purpose: targetOptions supports SystemMessagesView.vue by holding or executing the target options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const targetOptions = ref({ shops: [] as any[], users: [] as any[] })
|
||||
/**
|
||||
* Purpose: popupEnabled supports SystemMessagesView.vue by holding or executing the popup enabled page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const popupEnabled = ref(true)
|
||||
/**
|
||||
* Purpose: previewVisible supports SystemMessagesView.vue by holding or executing the preview visible page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const previewVisible = ref(false)
|
||||
/**
|
||||
* Purpose: currentMessage supports SystemMessagesView.vue by holding or executing the current message page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const currentMessage = ref<SystemMessageVO | null>(null)
|
||||
/**
|
||||
* Purpose: imagePreviewUrl supports SystemMessagesView.vue by holding or executing the image preview url page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const imagePreviewUrl = ref('')
|
||||
|
||||
/**
|
||||
* Purpose: form supports SystemMessagesView.vue by holding or executing the form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const form = reactive<SystemMessageCreateRequest>({
|
||||
title: '',
|
||||
content: '',
|
||||
imageFileId: undefined,
|
||||
targetType: 'CURRENT_SHOP_ALL',
|
||||
shopIds: [],
|
||||
userIds: [],
|
||||
popupEnabled: 1
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: currentAdminUser supports SystemMessagesView.vue by holding or executing the current admin user page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const currentAdminUser = computed(() => {
|
||||
try {
|
||||
const cache = localStorage.getItem('adminUserInfo') || sessionStorage.getItem('adminUserInfo')
|
||||
return cache ? JSON.parse(cache) : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
})
|
||||
/**
|
||||
* Purpose: isPlatformAdmin supports SystemMessagesView.vue by holding or executing the is platform admin page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const isPlatformAdmin = computed(() => Number(currentAdminUser.value?.type) === 4)
|
||||
/**
|
||||
* Purpose: targetTypes supports SystemMessagesView.vue by holding or executing the target types page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const targetTypes = computed(() => [
|
||||
...(isPlatformAdmin.value ? [{ label: '全平台', value: 'PLATFORM_ALL' }] : []),
|
||||
{ label: isPlatformAdmin.value ? '指定店铺全员' : '本店全员', value: isPlatformAdmin.value ? 'SELECTED_SHOPS' : 'CURRENT_SHOP_ALL' },
|
||||
{ label: '指定用户', value: 'SELECTED_USERS' }
|
||||
])
|
||||
/**
|
||||
* Purpose: needsShopSelection supports SystemMessagesView.vue by holding or executing the needs shop selection page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const needsShopSelection = computed(() => form.targetType === 'SELECTED_SHOPS' || form.targetType === 'SHOP_ALL')
|
||||
/**
|
||||
* Purpose: shopOptions supports SystemMessagesView.vue by holding or executing the shop options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const shopOptions = computed(() => targetOptions.value.shops.map(shop => ({ label: shop.shopName, value: shop.id })))
|
||||
/**
|
||||
* Purpose: userOptions supports SystemMessagesView.vue by holding or executing the user options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const userOptions = computed(() => targetOptions.value.users.map(user => ({
|
||||
label: `${user.nickname || user.account} ${user.shopName ? `(${user.shopName})` : ''}`,
|
||||
value: user.id
|
||||
})))
|
||||
/**
|
||||
* Purpose: previewTitle supports SystemMessagesView.vue by holding or executing the preview title page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const previewTitle = computed(() => form.title.trim() || '消息标题预览')
|
||||
/**
|
||||
* Purpose: previewContent supports SystemMessagesView.vue by holding or executing the preview content page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const previewContent = computed(() => form.content.trim() || (imagePreviewUrl.value ? '' : '这里会显示消息正文。支持纯文本,也可以配合一张图片展示给用户。'))
|
||||
/**
|
||||
* Purpose: previewMeta supports SystemMessagesView.vue by holding or executing the preview meta page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const previewMeta = computed(() => `系统消息 · ${popupEnabled.value ? '弹窗预览' : '列表预览'}`)
|
||||
/**
|
||||
* Purpose: currentMessageMeta supports SystemMessagesView.vue by holding or executing the current message meta page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const currentMessageMeta = computed(() => {
|
||||
if (!currentMessage.value) return ''
|
||||
return [
|
||||
currentMessage.value.publisherName || '系统消息',
|
||||
currentMessage.value.publishTime || currentMessage.value.createTime
|
||||
].filter(Boolean).join(' · ')
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: columns supports SystemMessagesView.vue by holding or executing the columns page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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 }
|
||||
]
|
||||
|
||||
/**
|
||||
* Purpose: syncDefaultTargetType supports SystemMessagesView.vue by holding or executing the sync default target type page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const syncDefaultTargetType = () => {
|
||||
if (isPlatformAdmin.value && form.targetType === 'CURRENT_SHOP_ALL') {
|
||||
form.targetType = 'PLATFORM_ALL'
|
||||
}
|
||||
if (!isPlatformAdmin.value && form.targetType === 'PLATFORM_ALL') {
|
||||
form.targetType = 'CURRENT_SHOP_ALL'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: loadData supports SystemMessagesView.vue by holding or executing the load data page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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: [] }
|
||||
syncDefaultTargetType()
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '消息数据加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: handleTargetTypeChange supports SystemMessagesView.vue by holding or executing the handle target type change page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const handleTargetTypeChange = () => {
|
||||
form.shopIds = []
|
||||
form.userIds = []
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: removeImage supports SystemMessagesView.vue by holding or executing the remove image page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const removeImage = () => {
|
||||
form.imageFileId = undefined
|
||||
imagePreviewUrl.value = ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: resetForm supports SystemMessagesView.vue by holding or executing the reset form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const resetForm = () => {
|
||||
form.title = ''
|
||||
form.content = ''
|
||||
form.imageFileId = undefined
|
||||
form.targetType = isPlatformAdmin.value ? 'PLATFORM_ALL' : 'CURRENT_SHOP_ALL'
|
||||
form.shopIds = []
|
||||
form.userIds = []
|
||||
popupEnabled.value = true
|
||||
imagePreviewUrl.value = ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: handleImageUpload supports SystemMessagesView.vue by holding or executing the handle image upload page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: handlePublish supports SystemMessagesView.vue by holding or executing the handle publish page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: handleRevoke supports SystemMessagesView.vue by holding or executing the handle revoke page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const handleRevoke = async (id: IdType) => {
|
||||
await adminSystemMessageApi.revokeMessage(id)
|
||||
message.success('消息已撤回')
|
||||
await loadData()
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: previewMessage supports SystemMessagesView.vue by holding or executing the preview message page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const previewMessage = (record: SystemMessageVO) => {
|
||||
currentMessage.value = record
|
||||
previewVisible.value = true
|
||||
}
|
||||
|
||||
onMounted(loadData)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.system-messages {
|
||||
padding: 18px;
|
||||
max-width: 1180px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.message-page-head {
|
||||
max-width: 1120px;
|
||||
margin: 0 auto 12px;
|
||||
}
|
||||
|
||||
.message-page-head :deep(.ant-page-header) {
|
||||
padding: 0 0 12px;
|
||||
}
|
||||
|
||||
.message-page-head :deep(.ant-page-header-heading-title) {
|
||||
color: var(--text-primary);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.message-composer-shell {
|
||||
max-width: 1120px;
|
||||
margin: 0 auto 24px;
|
||||
}
|
||||
|
||||
.message-composer-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(330px, 420px);
|
||||
gap: 22px;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.message-editor-panel,
|
||||
.message-preview-panel {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.message-editor-panel {
|
||||
padding: 24px;
|
||||
border: 1px solid var(--theme-border);
|
||||
border-radius: 22px;
|
||||
background: var(--theme-card-bg);
|
||||
box-shadow: 0 18px 48px color-mix(in srgb, var(--theme-primary) 12%, transparent);
|
||||
}
|
||||
|
||||
.panel-heading {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
align-items: center;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.panel-heading__icon {
|
||||
display: grid;
|
||||
width: 46px;
|
||||
height: 46px;
|
||||
flex: 0 0 auto;
|
||||
place-items: center;
|
||||
border-radius: 14px;
|
||||
color: #ffffff;
|
||||
font-size: 20px;
|
||||
background: var(--theme-gradient);
|
||||
box-shadow: var(--theme-button-shadow);
|
||||
}
|
||||
|
||||
.panel-eyebrow {
|
||||
margin: 0 0 4px;
|
||||
color: var(--theme-primary);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.panel-heading h2 {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
font-size: 22px;
|
||||
font-weight: 750;
|
||||
}
|
||||
|
||||
.message-form :deep(.ant-form-item-label > label) {
|
||||
color: var(--text-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.message-form :deep(.ant-input),
|
||||
.message-form :deep(.ant-input-number),
|
||||
.message-form :deep(.ant-select-selector),
|
||||
.message-form :deep(.ant-input-affix-wrapper) {
|
||||
border-color: var(--theme-border);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.message-form :deep(.ant-input:focus),
|
||||
.message-form :deep(.ant-input-focused),
|
||||
.message-form :deep(.ant-select-focused .ant-select-selector),
|
||||
.message-form :deep(.ant-input-affix-wrapper-focused) {
|
||||
border-color: var(--theme-primary);
|
||||
box-shadow: var(--theme-focus-shadow);
|
||||
}
|
||||
|
||||
.scope-panel {
|
||||
padding: 16px 16px 0;
|
||||
margin-bottom: 18px;
|
||||
border: 1px solid var(--theme-border);
|
||||
border-radius: 16px;
|
||||
background: var(--theme-gradient-soft);
|
||||
}
|
||||
|
||||
.publish-footer {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding-top: 18px;
|
||||
border-top: 1px solid var(--theme-border);
|
||||
}
|
||||
|
||||
.popup-checkbox {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.message-preview-panel {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.message-preview-panel :deep(.system-message-card) {
|
||||
max-width: 420px;
|
||||
}
|
||||
|
||||
.preview-read-button {
|
||||
display: inline-flex;
|
||||
min-height: 40px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
padding: 0 18px;
|
||||
border: 0;
|
||||
border-radius: 12px;
|
||||
color: #ffffff;
|
||||
font-weight: 700;
|
||||
background: var(--theme-gradient);
|
||||
box-shadow: var(--theme-button-shadow);
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.admin-section-card {
|
||||
max-width: 1120px;
|
||||
margin-bottom: 16px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
border: 1px solid var(--theme-border);
|
||||
border-radius: 18px;
|
||||
box-shadow: 0 18px 42px color-mix(in srgb, var(--theme-primary) 10%, transparent);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.admin-section-card :deep(.ant-card-head) {
|
||||
color: var(--theme-primary);
|
||||
background: var(--theme-gradient-soft);
|
||||
}
|
||||
|
||||
.image-upload-row {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.upload-placeholder {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
place-items: center;
|
||||
color: var(--text-secondary);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.message-image-preview {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.image-upload-copy {
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.image-upload-copy small,
|
||||
.muted {
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.table-image {
|
||||
object-fit: cover;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
:global(.message-detail-modal-wrap .ant-modal-content) {
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
:global(.message-detail-modal-wrap .ant-modal-body) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
:global(.message-detail-modal-wrap .ant-modal-close) {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
:global(.message-detail-modal-wrap .message-detail-close-button) {
|
||||
border: 0;
|
||||
border-radius: 12px;
|
||||
color: #ffffff;
|
||||
font-weight: 700;
|
||||
background: var(--theme-gradient);
|
||||
box-shadow: var(--theme-button-shadow);
|
||||
}
|
||||
|
||||
:global(.message-detail-modal-wrap .message-detail-close-button:hover),
|
||||
:global(.message-detail-modal-wrap .message-detail-close-button:focus) {
|
||||
color: #ffffff;
|
||||
background: var(--theme-gradient);
|
||||
filter: brightness(0.98);
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.message-composer-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.message-preview-panel :deep(.system-message-card) {
|
||||
max-width: 640px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.system-messages {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.message-editor-panel {
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.image-upload-row,
|
||||
.publish-footer {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.publish-footer :deep(.ant-space) {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.preview-read-button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,662 @@
|
||||
<template>
|
||||
<div class="tags">
|
||||
<a-page-header v-if="!isMobile" title="标签管理" sub-title="管理系统标签" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">经营</span>
|
||||
<h1 class="admin-page-intro__title">标签管理</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">标签 {{ tagList.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">
|
||||
标签列表
|
||||
</template>
|
||||
<template #extra>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索标签名称"
|
||||
:style="isMobile ? { width: '100%' } : { width: '250px' }"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button v-if="!isMobile && hasPermission('tag:create')" type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增标签
|
||||
</a-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="tagList"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
@change="handleTableChange"
|
||||
row-key="id"
|
||||
:scroll="{ x: 'max-content' }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'color'">
|
||||
<span
|
||||
class="tag-preview"
|
||||
:style="{
|
||||
backgroundColor: record.bgColor,
|
||||
color: record.textColor,
|
||||
borderColor: record.borderColor
|
||||
}"
|
||||
>
|
||||
{{ record.tagName }}
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'shop'">
|
||||
<span>{{ record.shopName || getShopName(record.shopId) }}</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('tag:view')" type="link" size="small" @click="showViewModal(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('tag:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('tag:delete')" type="link" size="small" danger @click="handleDelete(record)">
|
||||
删除
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="tagList" empty-description="暂无标签数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__head">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.tagName }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.shopName || getShopName(item.shopId) || '未关联店铺' }}</div>
|
||||
</div>
|
||||
<span
|
||||
class="tag-preview"
|
||||
:style="{ backgroundColor: item.bgColor, color: item.textColor, borderColor: item.borderColor }"
|
||||
>
|
||||
{{ item.tagName }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>创建时间</span>
|
||||
<strong>{{ item.createTime || '--' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button v-if="hasPermission('tag:view')" size="small" @click="showViewModal(item)">查看</a-button>
|
||||
<a-button v-if="hasPermission('tag:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
|
||||
<a-button v-if="hasPermission('tag:delete')" size="small" danger @click="handleDelete(item)">删除</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="modalVisible"
|
||||
:title="isEdit ? '编辑标签' : '新增标签'"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
:confirmLoading="modalLoading"
|
||||
:desktop-width="600"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="标签名称" name="tagName">
|
||||
<a-input v-model:value="formState.tagName" placeholder="请输入标签名称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
placeholder="请选择所属店铺"
|
||||
style="width: 100%"
|
||||
:loading="loadingShops"
|
||||
:disabled="getCurrentUserInfo()?.type === 2"
|
||||
>
|
||||
<a-select-option
|
||||
v-if="shops.length === 0"
|
||||
disabled
|
||||
value=""
|
||||
>
|
||||
暂无店铺数据
|
||||
</a-select-option>
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="文字颜色" name="textColor">
|
||||
<el-color-picker v-model="formState.textColor" />
|
||||
</a-form-item>
|
||||
<a-form-item label="背景颜色" name="bgColor">
|
||||
<el-color-picker v-model="formState.bgColor" />
|
||||
</a-form-item>
|
||||
<a-form-item label="边框颜色" name="borderColor">
|
||||
<el-color-picker v-model="formState.borderColor" />
|
||||
</a-form-item>
|
||||
<a-form-item label="场景分组" name="sceneGroup">
|
||||
<a-input v-model:value="formState.sceneGroup" placeholder="如:风格、场合、季节" />
|
||||
</a-form-item>
|
||||
<a-form-item label="前台名称" name="displayName">
|
||||
<a-input v-model:value="formState.displayName" placeholder="留空则使用标签名称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="前台排序" name="sortOrder">
|
||||
<a-input-number v-model:value="formState.sortOrder" :min="0" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="前台展示" name="frontVisible">
|
||||
<a-switch v-model:checked="formState.frontVisible" :checked-value="1" :un-checked-value="0" />
|
||||
</a-form-item>
|
||||
<a-form-item label="预览">
|
||||
<span
|
||||
class="tag-preview"
|
||||
:style="{
|
||||
backgroundColor: formState.bgColor,
|
||||
color: formState.textColor,
|
||||
borderColor: formState.borderColor
|
||||
}"
|
||||
>
|
||||
{{ formState.tagName }}
|
||||
</span>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<!-- 查看标签详情模态框 -->
|
||||
<AdminResponsiveModal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看标签详情"
|
||||
:footer="null"
|
||||
@cancel="handleViewModalCancel"
|
||||
:desktop-width="600"
|
||||
>
|
||||
<a-form
|
||||
:model="viewFormState"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="标签名称">
|
||||
<a-input v-model:value="viewFormState.tagName" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺">
|
||||
<a-select v-model:value="viewFormState.shopId" :disabled="true">
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="文字颜色">
|
||||
<el-color-picker v-model="viewFormState.textColor" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="背景颜色">
|
||||
<el-color-picker v-model="viewFormState.bgColor" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="边框颜色">
|
||||
<el-color-picker v-model="viewFormState.borderColor" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="场景分组">
|
||||
<a-input v-model:value="viewFormState.sceneGroup" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="前台名称">
|
||||
<a-input v-model:value="viewFormState.displayName" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="前台排序">
|
||||
<a-input-number v-model:value="viewFormState.sortOrder" :disabled="true" style="width: 100%" />
|
||||
</a-form-item>
|
||||
<a-form-item label="前台展示">
|
||||
<a-switch v-model:checked="viewFormState.frontVisible" :checked-value="1" :un-checked-value="0" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="预览">
|
||||
<span
|
||||
class="tag-preview"
|
||||
:style="{
|
||||
backgroundColor: viewFormState.bgColor,
|
||||
color: viewFormState.textColor,
|
||||
borderColor: viewFormState.borderColor
|
||||
}"
|
||||
>
|
||||
{{ viewFormState.tagName }}
|
||||
</span>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminMobileFab
|
||||
:visible="isMobile && hasPermission('tag:create') && !modalVisible && !viewModalVisible"
|
||||
label="新增标签"
|
||||
@click="showAddModal"
|
||||
/>
|
||||
</div>
|
||||
</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'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
/**
|
||||
* Purpose: Shop supports TagsView.vue by holding or executing the shop page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { adminTagApi, adminShopApi, type Shop } from '@/api/admin'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminMobileFab from '@/components/admin/AdminMobileFab.vue'
|
||||
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')
|
||||
if (userInfoStr) {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
return userInfo
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
}
|
||||
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('')
|
||||
/**
|
||||
* Purpose: formRef supports TagsView.vue by holding or executing the form ref page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formRef = ref<FormInstance>()
|
||||
/**
|
||||
* Purpose: currentTag supports TagsView.vue by holding or executing the current tag page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const currentTag = ref<any>(null)
|
||||
/**
|
||||
* Purpose: draftSavedAt supports TagsView.vue by holding or executing the draft saved at page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
// 查看标签相关状态
|
||||
const viewFormState = reactive({
|
||||
tagName: '',
|
||||
shopId: undefined as number | undefined,
|
||||
textColor: '#333333',
|
||||
bgColor: '#FFFFFF',
|
||||
borderColor: '#E5E5E5',
|
||||
sceneGroup: '',
|
||||
displayName: '',
|
||||
sortOrder: 100,
|
||||
frontVisible: 1
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: tagList supports TagsView.vue by holding or executing the tag list page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const tagList = ref<any[]>([])
|
||||
/**
|
||||
* Purpose: shops supports TagsView.vue by holding or executing the shops page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const shops = ref<Shop[]>([])
|
||||
/** loadingShops is a reactive state variable used by the template and event handlers. */
|
||||
const loadingShops = ref(false)
|
||||
|
||||
/**
|
||||
* Purpose: pagination supports TagsView.vue by holding or executing the pagination page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
/**
|
||||
* Purpose: formState supports TagsView.vue by holding or executing the form state page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formState = reactive({
|
||||
tagName: '',
|
||||
shopId: undefined as number | undefined,
|
||||
textColor: '#333333',
|
||||
bgColor: '#FFFFFF',
|
||||
borderColor: '#E5E5E5',
|
||||
sceneGroup: '',
|
||||
displayName: '',
|
||||
sortOrder: 100,
|
||||
frontVisible: 1
|
||||
})
|
||||
|
||||
/** 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,
|
||||
textColor: formState.textColor,
|
||||
bgColor: formState.bgColor,
|
||||
borderColor: formState.borderColor,
|
||||
sceneGroup: formState.sceneGroup,
|
||||
displayName: formState.displayName,
|
||||
sortOrder: formState.sortOrder,
|
||||
frontVisible: formState.frontVisible
|
||||
})
|
||||
|
||||
/** restoreDraft is a local helper used by this page script. */
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(formState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
/** 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
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: formRules supports TagsView.vue by holding or executing the form rules page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const formRules = {
|
||||
tagName: [{ required: true, message: '请输入标签名称', trigger: 'blur' }],
|
||||
shopId: [{ required: true, message: '请选择所属店铺', trigger: 'change' }]
|
||||
} as any
|
||||
|
||||
/**
|
||||
* Purpose: columns supports TagsView.vue by holding or executing the columns page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const columns = [
|
||||
{ title: '标签名称', dataIndex: 'tagName', key: 'tagName' },
|
||||
{ title: '所属店铺', key: 'shop', width: 150 },
|
||||
{ title: '预览', key: 'color', width: 150 },
|
||||
{ title: '文字颜色', dataIndex: 'textColor', key: 'textColor', width: 120 },
|
||||
{ title: '背景颜色', dataIndex: 'bgColor', key: 'bgColor', width: 120 },
|
||||
{ title: '边框颜色', dataIndex: 'borderColor', key: 'borderColor', width: 120 },
|
||||
{ title: '场景分组', dataIndex: 'sceneGroup', key: 'sceneGroup', width: 120 },
|
||||
{ title: '前台名称', dataIndex: 'displayName', key: 'displayName', width: 120 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ 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 {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||
let tags
|
||||
if (shopId) {
|
||||
tags = await adminTagApi.listTagsByShopId(shopId) as unknown as any[]
|
||||
} else {
|
||||
tags = await adminTagApi.listAllTags() as unknown as any[]
|
||||
}
|
||||
tagList.value = tags || []
|
||||
pagination.total = tagList.value.length
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败:', error)
|
||||
message.error('获取标签列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 {
|
||||
const res = await adminShopApi.listAllShops() as unknown as any[]
|
||||
shops.value = res || []
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** normalizeShopIdValue is a local helper used by this page script. */
|
||||
const normalizeShopIdValue = (value: string | number | undefined | null) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return ''
|
||||
}
|
||||
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
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const shopId = (currentUser && currentUser.shopId) ? currentUser.shopId : undefined
|
||||
Object.assign(formState, {
|
||||
tagName: '',
|
||||
shopId: shopId,
|
||||
textColor: '#333333',
|
||||
bgColor: '#FFFFFF',
|
||||
borderColor: '#E5E5E5',
|
||||
sceneGroup: '',
|
||||
displayName: '',
|
||||
sortOrder: 100,
|
||||
frontVisible: 1
|
||||
})
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showEditModal is a local helper used by this page script. */
|
||||
const showEditModal = (record: any) => {
|
||||
isEdit.value = true
|
||||
currentTag.value = record
|
||||
Object.assign(formState, {
|
||||
tagName: record.tagName,
|
||||
shopId: record.shopId,
|
||||
textColor: record.textColor,
|
||||
bgColor: record.bgColor,
|
||||
borderColor: record.borderColor,
|
||||
sceneGroup: record.sceneGroup || '',
|
||||
displayName: record.displayName || '',
|
||||
sortOrder: record.sortOrder ?? 100,
|
||||
frontVisible: record.frontVisible ?? 1
|
||||
})
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
/** showViewModal is a local helper used by this page script. */
|
||||
const showViewModal = (record: any) => {
|
||||
Object.assign(viewFormState, {
|
||||
tagName: record.tagName,
|
||||
shopId: record.shopId,
|
||||
textColor: record.textColor,
|
||||
bgColor: record.bgColor,
|
||||
borderColor: record.borderColor,
|
||||
sceneGroup: record.sceneGroup || '',
|
||||
displayName: record.displayName || '',
|
||||
sortOrder: record.sortOrder ?? 100,
|
||||
frontVisible: record.frontVisible ?? 1
|
||||
})
|
||||
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()
|
||||
modalLoading.value = true
|
||||
|
||||
await runWithGlobalLoading(async () => {
|
||||
const requestData = {
|
||||
tagName: formState.tagName,
|
||||
shopId: formState.shopId,
|
||||
textColor: formState.textColor,
|
||||
bgColor: formState.bgColor,
|
||||
borderColor: formState.borderColor,
|
||||
sceneGroup: formState.sceneGroup,
|
||||
displayName: formState.displayName,
|
||||
sortOrder: formState.sortOrder,
|
||||
frontVisible: formState.frontVisible
|
||||
}
|
||||
|
||||
if (isEdit.value && currentTag.value) {
|
||||
await adminTagApi.updateTag(currentTag.value.id, requestData)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await adminTagApi.createTag(requestData)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
handleClearDraft(false)
|
||||
modalVisible.value = false
|
||||
await fetchTags()
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error('Error:', error)
|
||||
message.error(error?.message || (isEdit.value ? '更新失败' : '创建失败'))
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 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: '确认删除',
|
||||
content: `确定要删除标签 ${record.tagName} 吗?`,
|
||||
onOk: async () => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await adminTagApi.deleteTag(record.id)
|
||||
message.success('删除成功')
|
||||
await fetchTags()
|
||||
})
|
||||
} catch (error) {
|
||||
message.error('删除失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
await fetchShops()
|
||||
await fetchTags()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.tags {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.tag-preview {
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,189 @@
|
||||
<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" :scroll="{ x: 'max-content' }">
|
||||
<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: any) => 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 ? '编辑档位' : '新增档位'" :mask-closable="false" @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="如 青铜 / 白银 / 黄金,也可以输入自定义等级" />
|
||||
<div class="level-shortcuts">
|
||||
<a-tag v-for="level in vipLevelOptions" :key="level" @click="form.vipLevel = level">{{ level }}</a-tag>
|
||||
</div>
|
||||
</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'
|
||||
/**
|
||||
* Purpose: Shop supports VipRechargePlansView.vue by holding or executing the shop page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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)
|
||||
/**
|
||||
* Purpose: editingId supports VipRechargePlansView.vue by holding or executing the editing id page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const editingId = ref<any>()
|
||||
/**
|
||||
* Purpose: plans supports VipRechargePlansView.vue by holding or executing the plans page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const plans = ref<VipRechargePlanVO[]>([])
|
||||
/**
|
||||
* Purpose: shops supports VipRechargePlansView.vue by holding or executing the shops page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const shops = ref<Shop[]>([])
|
||||
/**
|
||||
* Purpose: vipLevelOptions supports VipRechargePlansView.vue by holding or executing the vip level options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const vipLevelOptions = ref<string[]>(['普通', '青铜', '白银', '黄金'])
|
||||
/**
|
||||
* Purpose: form supports VipRechargePlansView.vue by holding or executing the form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const form = reactive<any>({ shopId: undefined, title: '', rechargeAmount: 0, giftAmount: 0, vipLevel: '', description: '', sortOrder: 0, status: 1 })
|
||||
|
||||
/**
|
||||
* Purpose: columns supports VipRechargePlansView.vue by holding or executing the columns page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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 }
|
||||
]
|
||||
|
||||
/**
|
||||
* Purpose: shopOptions supports VipRechargePlansView.vue by holding or executing the shop options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
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 || []
|
||||
const configuredLevels = Array.from(new Set(plans.value.map(item => item.vipLevel).filter(Boolean)))
|
||||
vipLevelOptions.value = Array.from(new Set(['普通', '青铜', '白银', '黄金', ...configuredLevels]))
|
||||
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: var(--text-secondary); }
|
||||
.level-shortcuts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
|
||||
.level-shortcuts :deep(.ant-tag) { cursor: pointer; }
|
||||
</style>
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Purpose: AdminCachedUserInfo supports admin-helpers.ts by holding or executing the admin cached user info page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { loadCachedAdminUserInfo, isBootstrapAdminUser, type AdminCachedUserInfo } from '@/utils/admin-session'
|
||||
|
||||
export { loadCachedAdminUserInfo, isBootstrapAdminUser }
|
||||
export type { AdminCachedUserInfo }
|
||||
|
||||
/**
|
||||
* Purpose: getAdminRoleLabel supports admin-helpers.ts by holding or executing the get admin role label page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
export const getAdminRoleLabel = (type?: number) => {
|
||||
switch (type) {
|
||||
case 4:
|
||||
return '平台管理员'
|
||||
case 2:
|
||||
return '店长'
|
||||
case 3:
|
||||
return '美甲师'
|
||||
default:
|
||||
return '后台账号'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getAdminShopOptions supports admin-helpers.ts by holding or executing the get admin shop options page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
export const getAdminShopOptions = (userInfo?: AdminCachedUserInfo | null) => {
|
||||
const ids = userInfo?.shopIds || []
|
||||
const names = userInfo?.shopNames || []
|
||||
return ids.map((id, index) => ({
|
||||
id: String(id),
|
||||
name: names[index] || `门店 ${id}`
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getAdminCurrentShopName supports admin-helpers.ts by holding or executing the get admin current shop name page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
export const getAdminCurrentShopName = (userInfo?: AdminCachedUserInfo | null) =>
|
||||
userInfo?.shopName || (isBootstrapAdminUser(userInfo) ? '平台总览模式' : '游客模式')
|
||||
@@ -0,0 +1,70 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { readFileSync, readdirSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const sourceRoot = join(process.cwd(), 'src')
|
||||
const adminViewsPath = join(sourceRoot, 'views', 'admin')
|
||||
|
||||
function readSource(relativePath: string) {
|
||||
return readFileSync(join(sourceRoot, relativePath), 'utf-8')
|
||||
}
|
||||
|
||||
function findModalTags(source: string) {
|
||||
return Array.from(source.matchAll(/<a-modal\b[\s\S]*?>/g), match => match[0])
|
||||
}
|
||||
|
||||
function findUserFormModal(source: string) {
|
||||
const match = source.match(/<AdminResponsiveModal\b[\s\S]*?@cancel="handleModalCancel"[\s\S]*?<\/AdminResponsiveModal>/)
|
||||
return match?.[0] ?? ''
|
||||
}
|
||||
|
||||
function findFormItem(source: string, name: string) {
|
||||
const match = source.match(new RegExp(`<a-form-item\\b[\\s\\S]*?name="${name}"[\\s\\S]*?</a-form-item>`))
|
||||
return match?.[0] ?? ''
|
||||
}
|
||||
|
||||
describe('admin modal and user form behavior', () => {
|
||||
it('keeps every backend modal open when users click the blank mask area', () => {
|
||||
const responsiveModal = readSource('components/admin/AdminResponsiveModal.vue')
|
||||
expect(responsiveModal).toMatch(/<a-modal\b[\s\S]*:mask-closable="false"/)
|
||||
|
||||
const missingMaskLock = readdirSync(adminViewsPath)
|
||||
.filter(fileName => fileName.endsWith('.vue'))
|
||||
.flatMap(fileName => {
|
||||
const source = readFileSync(join(adminViewsPath, fileName), 'utf-8')
|
||||
return findModalTags(source)
|
||||
.map((tag, index) => ({ fileName, index: index + 1, tag }))
|
||||
.filter(({ tag }) => !/:mask-closable\s*=\s*"false"/.test(tag))
|
||||
.map(({ fileName, index }) => `${fileName} modal #${index}`)
|
||||
})
|
||||
|
||||
expect(missingMaskLock).toEqual([])
|
||||
})
|
||||
|
||||
it('shows only one editable phone field in the user create and edit form', () => {
|
||||
const usersView = readSource('views/admin/UsersView.vue')
|
||||
const userFormModal = findUserFormModal(usersView)
|
||||
|
||||
expect(userFormModal).toContain('name="phone"')
|
||||
expect(userFormModal).not.toContain('name="contactPhone"')
|
||||
expect(userFormModal).not.toContain('formState.contactPhone')
|
||||
expect(usersView).toContain('const primaryPhone = formState.phone.trim()')
|
||||
expect(usersView).toContain('phone: primaryPhone')
|
||||
expect(usersView).toContain('contactPhone: primaryPhone')
|
||||
})
|
||||
|
||||
it('uses a polished date picker and visible required markers for conditional user fields', () => {
|
||||
const usersView = readSource('views/admin/UsersView.vue')
|
||||
const userFormModal = findUserFormModal(usersView)
|
||||
const wechatIdField = findFormItem(userFormModal, 'wechatId')
|
||||
const shopIdsField = findFormItem(userFormModal, 'shopIds')
|
||||
|
||||
expect(userFormModal).not.toContain('type="date"')
|
||||
expect(userFormModal).toContain('<a-date-picker')
|
||||
expect(userFormModal).toContain('value-format="YYYY-MM-DD"')
|
||||
expect(userFormModal).toContain('class="user-date-picker"')
|
||||
expect(usersView).toContain('.user-date-picker')
|
||||
expect(wechatIdField).toContain(':required="[2, 3].includes(Number(formState.type))"')
|
||||
expect(shopIdsField).toContain(':required="Number(formState.type) !== 4"')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,47 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { readFileSync, readdirSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const sourceRoot = join(process.cwd(), 'src')
|
||||
const adminViewsPath = join(sourceRoot, 'views', 'admin')
|
||||
|
||||
function readSource(relativePath: string) {
|
||||
return readFileSync(join(sourceRoot, relativePath), 'utf-8')
|
||||
}
|
||||
|
||||
function findTableTags(source: string) {
|
||||
return Array.from(source.matchAll(/<a-table\b[\s\S]*?>/g), match => match[0])
|
||||
}
|
||||
|
||||
describe('admin table layout', () => {
|
||||
it('keeps every admin table wide enough to scroll horizontally', () => {
|
||||
const missingScrollX = readdirSync(adminViewsPath)
|
||||
.filter(fileName => fileName.endsWith('.vue'))
|
||||
.flatMap(fileName => {
|
||||
const source = readFileSync(join(adminViewsPath, fileName), 'utf-8')
|
||||
return findTableTags(source)
|
||||
.map((tag, index) => ({ fileName, index: index + 1, tag }))
|
||||
.filter(({ tag }) => !/:scroll\s*=\s*"\{[\s\S]*x:\s*'max-content'/.test(tag))
|
||||
.map(({ fileName, index }) => `${fileName} table #${index}`)
|
||||
})
|
||||
|
||||
expect(missingScrollX).toEqual([])
|
||||
})
|
||||
|
||||
it('prevents backend table cells from breaking text into vertical columns', () => {
|
||||
const adminLayout = readSource('views/admin/AdminLayout.vue')
|
||||
|
||||
expect(adminLayout).not.toMatch(/\.mobile-content\s+:deep\(\.ant-table-cell\)\s*\{[\s\S]*overflow-wrap:\s*anywhere/)
|
||||
expect(adminLayout).toContain('table-layout: auto;')
|
||||
expect(adminLayout).toContain('width: max-content;')
|
||||
expect(adminLayout).toContain('word-break: keep-all;')
|
||||
})
|
||||
|
||||
it('keeps table ellipsis text content-sized without arbitrary character breaking', () => {
|
||||
const ellipsisText = readSource('components/TableEllipsisText.vue')
|
||||
|
||||
expect(ellipsisText).toContain('display: inline-block;')
|
||||
expect(ellipsisText).not.toMatch(/^\s*width:\s*100%;$/m)
|
||||
expect(ellipsisText).not.toContain('word-break: break-all;')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,76 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const sourceRoot = join(process.cwd(), 'src')
|
||||
const coreRoot = join(process.cwd(), '..', 'YumiNail-Core', 'src', 'main', 'java')
|
||||
|
||||
function readSource(relativePath: string) {
|
||||
return readFileSync(join(sourceRoot, relativePath), 'utf-8')
|
||||
}
|
||||
|
||||
describe('web theme governance', () => {
|
||||
it('keeps login pages on the shared shop theme variables', () => {
|
||||
const authView = readSource('views/AuthView.vue')
|
||||
const adminLoginView = readSource('views/admin/AdminLoginView.vue')
|
||||
|
||||
expect(authView).not.toMatch(/#667eea|#764ba2/)
|
||||
expect(authView).toContain('var(--theme-gradient)')
|
||||
expect(authView).toContain('var(--theme-card-bg)')
|
||||
expect(adminLoginView).not.toMatch(/--admin-mobile-accent|#d4866c|#c26e52/)
|
||||
expect(adminLoginView).toContain('var(--theme-gradient)')
|
||||
expect(adminLoginView).toContain('var(--theme-card-bg)')
|
||||
})
|
||||
|
||||
it('does not reset admin routes back to an unrelated theme', () => {
|
||||
const app = readSource('App.vue')
|
||||
|
||||
expect(app).not.toMatch(/if\s*\(\s*isAdminPage\s*\)\s*\{\s*resetShopTheme\(\)/)
|
||||
expect(app).not.toMatch(/route\.matched\.some\(r => r\.meta\.isAdmin\)\)\s*\{\s*resetShopTheme\(\)/)
|
||||
expect(app).toContain("mode: 'admin'")
|
||||
})
|
||||
|
||||
it('derives backend mobile colors from the active shop theme', () => {
|
||||
const adminMobile = readSource('styles/admin-mobile.css')
|
||||
|
||||
expect(adminMobile).toContain('--admin-mobile-ink: var(--text-primary);')
|
||||
expect(adminMobile).toContain('--admin-mobile-card: var(--theme-card-bg);')
|
||||
expect(adminMobile).toContain('--admin-mobile-accent: var(--theme-primary);')
|
||||
expect(adminMobile).not.toMatch(/--admin-mobile-(?:ink|surface|card|accent|accent-strong|shell-start|shell-mid|shell-end):\s*#[0-9a-fA-F]{3,8}/)
|
||||
expect(adminMobile).toContain('.admin-mobile-card__row strong')
|
||||
expect(adminMobile).toContain('overflow-wrap: break-word;')
|
||||
})
|
||||
|
||||
it('does not let feature pages redefine global theme variables', () => {
|
||||
const systemMessages = readSource('views/admin/SystemMessagesView.vue')
|
||||
|
||||
expect(systemMessages).not.toMatch(/--theme-primary:\s*#[0-9a-fA-F]{3,8}/)
|
||||
expect(systemMessages).not.toMatch(/--theme-gradient:\s*linear-gradient\([^;]*#[0-9a-fA-F]{3,8}/)
|
||||
})
|
||||
|
||||
it('keeps the web customer surface in a centered phone shell on desktop', () => {
|
||||
const app = readSource('App.vue')
|
||||
const globalStyle = readSource('style.css')
|
||||
|
||||
expect(app).toContain('yumi-phone-frame')
|
||||
expect(app).toContain('yumi-phone-frame--hidden-nav')
|
||||
expect(globalStyle).toMatch(/--frontend-page-max-width:\s*430px/)
|
||||
expect(globalStyle).toContain('--theme-neutral: #4A443F;')
|
||||
expect(globalStyle).toContain('--theme-tertiary: #FDFBF9;')
|
||||
expect(globalStyle).toContain('.yumi-phone-frame')
|
||||
expect(globalStyle).toContain('.yumi-page')
|
||||
expect(globalStyle).toContain('.yumi-glass-card')
|
||||
expect(globalStyle).toContain('.yumi-status-chip')
|
||||
expect(globalStyle).toContain('.yumi-bottom-action')
|
||||
expect(globalStyle).toContain('max-width: var(--frontend-page-max-width);')
|
||||
expect(globalStyle).not.toMatch(/--theme-primary:\s*#7C5357/)
|
||||
})
|
||||
|
||||
it('keeps frontend and backend platform overview permission allowlists aligned', () => {
|
||||
const frontend = readSource('utils/platform-admin-permissions.ts')
|
||||
const backend = readFileSync(join(coreRoot, 'com', 'xiaowang', 'yuminailcore', 'support', 'PermissionCatalog.java'), 'utf-8')
|
||||
|
||||
expect(backend).toContain('"security:audit:view"')
|
||||
expect(frontend).toContain("'security:audit:view'")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user