功能:更新消息中心和 YumiNail 模块
This commit is contained in:
@@ -0,0 +1,741 @@
|
||||
<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">
|
||||
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'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
// 用户信息
|
||||
const userInfo = ref<UserVO>({
|
||||
id: 0,
|
||||
nickname: '',
|
||||
account: '',
|
||||
avatar: '',
|
||||
type: 0,
|
||||
status: 0,
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
|
||||
// 状态标识
|
||||
const hasPassword = ref(false)
|
||||
const hasPhone = ref(false)
|
||||
|
||||
// 绑定手机号表单
|
||||
const bindPhoneModalVisible = ref(false)
|
||||
const bindPhoneLoading = ref(false)
|
||||
const bindPhoneDraftSavedAt = ref<number | null>(null)
|
||||
const bindPhoneForm = reactive({
|
||||
phone: '',
|
||||
verificationCode: ''
|
||||
})
|
||||
|
||||
// 修改手机号表单
|
||||
const changePhoneModalVisible = ref(false)
|
||||
const changePhoneLoading = ref(false)
|
||||
const changePhoneDraftSavedAt = ref<number | null>(null)
|
||||
const changePhoneForm = reactive({
|
||||
newPhone: '',
|
||||
verificationCode: ''
|
||||
})
|
||||
|
||||
// 修改密码表单
|
||||
const changePasswordModalVisible = ref(false)
|
||||
const changePasswordLoading = ref(false)
|
||||
const changePasswordDraftSavedAt = ref<number | null>(null)
|
||||
const changePasswordForm = reactive({
|
||||
verificationCode: '',
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
const restoreSessionDraft = <T extends Record<string, any>>(key: string, target: T, savedAtRef: typeof bindPhoneDraftSavedAt) => {
|
||||
const draft = loadDraftRecord<T>(key, 'session')
|
||||
if (!draft) {
|
||||
savedAtRef.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(target, draft.payload)
|
||||
savedAtRef.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const saveSessionDraft = <T>(key: string, payload: T, savedAtRef: typeof bindPhoneDraftSavedAt, successMessage = '已暂存到当前会话') => {
|
||||
const draft = saveDraftRecord(key, payload, 'session')
|
||||
savedAtRef.value = draft.savedAt
|
||||
message.success(successMessage)
|
||||
}
|
||||
|
||||
const clearSessionDraft = (key: string, savedAtRef: typeof bindPhoneDraftSavedAt, showMessage = true) => {
|
||||
clearDraftRecord(key, 'session')
|
||||
savedAtRef.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const bindPhoneDraftKey = buildDraftStorageKey('account-settings', 'bind-phone')
|
||||
const changePhoneDraftKey = buildDraftStorageKey('account-settings', 'change-phone')
|
||||
const changePasswordDraftKey = buildDraftStorageKey('account-settings', 'change-password')
|
||||
|
||||
const handleSaveBindPhoneDraft = () => {
|
||||
saveSessionDraft(bindPhoneDraftKey, { ...bindPhoneForm }, bindPhoneDraftSavedAt)
|
||||
}
|
||||
|
||||
const handleClearBindPhoneDraft = (showMessage = true) => {
|
||||
clearSessionDraft(bindPhoneDraftKey, bindPhoneDraftSavedAt, showMessage)
|
||||
}
|
||||
|
||||
const handleSaveChangePhoneDraft = () => {
|
||||
saveSessionDraft(changePhoneDraftKey, { ...changePhoneForm }, changePhoneDraftSavedAt)
|
||||
}
|
||||
|
||||
const handleClearChangePhoneDraft = (showMessage = true) => {
|
||||
clearSessionDraft(changePhoneDraftKey, changePhoneDraftSavedAt, showMessage)
|
||||
}
|
||||
|
||||
const handleSaveChangePasswordDraft = () => {
|
||||
saveSessionDraft(changePasswordDraftKey, { ...changePasswordForm }, changePasswordDraftSavedAt)
|
||||
}
|
||||
|
||||
const handleClearChangePasswordDraft = (showMessage = true) => {
|
||||
clearSessionDraft(changePasswordDraftKey, changePasswordDraftSavedAt, showMessage)
|
||||
}
|
||||
|
||||
// 倒计时
|
||||
const countdown = ref(0)
|
||||
|
||||
// 账号设置选项
|
||||
const accountSettings = ref([
|
||||
{
|
||||
key: 'changePhone',
|
||||
title: '修改手机号',
|
||||
icon: PhoneOutlined,
|
||||
bgColor: '#e6f7ff'
|
||||
},
|
||||
{
|
||||
key: 'changePassword',
|
||||
title: '修改密码',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#f6ffed'
|
||||
},
|
||||
{
|
||||
key: 'deactivateAccount',
|
||||
title: '注销账号',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#fff1f0'
|
||||
}
|
||||
])
|
||||
|
||||
// 根据用户状态动态更新账号设置选项
|
||||
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
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
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('获取用户信息失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 处理返回
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
// 处理设置项点击
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// 处理设置密码
|
||||
const handleSetPassword = () => {
|
||||
router.push('/settings/password')
|
||||
}
|
||||
|
||||
// 发送绑定手机号验证码
|
||||
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 }))
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error('发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 发送修改手机号验证码
|
||||
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 }))
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error('发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 发送修改密码验证码
|
||||
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 }))
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error('发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 开始倒计时
|
||||
const startCountdown = () => {
|
||||
countdown.value = 60
|
||||
const timer = setInterval(() => {
|
||||
countdown.value--
|
||||
if (countdown.value <= 0) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
// 处理绑定手机号提交
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// 处理绑定手机号取消
|
||||
const handleBindPhoneCancel = () => {
|
||||
bindPhoneModalVisible.value = false
|
||||
bindPhoneForm.phone = ''
|
||||
bindPhoneForm.verificationCode = ''
|
||||
}
|
||||
|
||||
// 处理修改手机号提交
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// 处理修改手机号取消
|
||||
const handleChangePhoneCancel = () => {
|
||||
changePhoneModalVisible.value = false
|
||||
changePhoneForm.newPhone = ''
|
||||
changePhoneForm.verificationCode = ''
|
||||
}
|
||||
|
||||
// 处理修改密码提交
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// 处理修改密码取消
|
||||
const handleChangePasswordCancel = () => {
|
||||
changePasswordModalVisible.value = false
|
||||
changePasswordForm.verificationCode = ''
|
||||
changePasswordForm.password = ''
|
||||
changePasswordForm.confirmPassword = ''
|
||||
}
|
||||
|
||||
// 处理注销账号
|
||||
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: #f5f5f5;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
background: white;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.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: white;
|
||||
}
|
||||
|
||||
.settings-card :deep(.ant-card-body) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
padding: 16px;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.setting-item:hover {
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.setting-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-action) {
|
||||
margin-left: 8px;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.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: #333;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-meta-description) {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.password-tip {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin-top: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,145 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<header class="header">
|
||||
<a-button type="text" @click="router.back()">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>美甲师订单</h1>
|
||||
<div class="placeholder" />
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<a-empty v-if="!orders.length" description="暂无订单">
|
||||
<a-button type="primary" @click="handleRefreshClick">刷新</a-button>
|
||||
</a-empty>
|
||||
|
||||
<a-card v-for="order in orders" :key="order.id" class="order-card">
|
||||
<div class="order-head">
|
||||
<span>订单号:{{ order.orderNo }}</span>
|
||||
<span class="status" :class="statusClass(order.status)">{{ order.statusText }}</span>
|
||||
</div>
|
||||
|
||||
<div class="customer-meta">
|
||||
<span>预约用户:{{ order.customerNickname || '用户' }}</span>
|
||||
<span v-if="order.customerPhoneMasked">联系电话:{{ order.customerPhoneMasked }}</span>
|
||||
</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" />
|
||||
<span v-else>{{ item.productTitle[0] }}</span>
|
||||
</div>
|
||||
<div class="main">
|
||||
<div class="title">{{ item.productTitle }}</div>
|
||||
<div class="line">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
|
||||
<div v-if="item.appointmentTime" class="line appointment">预约时间:{{ item.appointmentTime }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<span>当前项目合计:¥{{ order.actualAmount.toFixed(2) }}</span>
|
||||
<a-button v-if="order.status === 1" size="small" type="primary" @click="completeOrder(order.id)">
|
||||
完成服务
|
||||
</a-button>
|
||||
</div>
|
||||
</a-card>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { fileApi } from '../api/index'
|
||||
import { orderApi } from '../api/order'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
const router = useRouter()
|
||||
const orders = ref<any[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
|
||||
const statusClass = (status: number) => {
|
||||
if (status === 1) return 'pending'
|
||||
if (status === 2) return 'completed'
|
||||
return 'cancelled'
|
||||
}
|
||||
|
||||
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 match = item.productImage?.replace(/<[^>]*>/g, '').match(/\/api\/file\/get\/(\d+)/)
|
||||
if (!match?.[1]) continue
|
||||
const imageId = match[1]
|
||||
try {
|
||||
if (!imageIdCache.value[imageId]) imageIdCache.value[imageId] = await fileApi.getSignedUrl(imageId) as any
|
||||
item.productImage = imageIdCache.value[imageId]
|
||||
} catch {
|
||||
item.productImage = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
message.error('获取订单列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleRefreshClick = async () => {
|
||||
await runWithGlobalLoading(() => loadOrders())
|
||||
}
|
||||
|
||||
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(loadOrders)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { min-height: 100vh; padding-top: 60px; background: #f5f5f5; }
|
||||
.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 10px 15px; background: #fff; border-bottom: 1px solid #f0f0f0; }
|
||||
.header h1 { margin: 0; font-size: 18px; }
|
||||
.placeholder { width: 40px; height: 40px; }
|
||||
.content { padding: 15px; }
|
||||
.order-card { margin-bottom: 12px; border-radius: 12px; }
|
||||
.order-head, .footer { display: flex; align-items: center; justify-content: space-between; }
|
||||
.order-head { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid #f0f0f0; }
|
||||
.customer-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 12px; color: #666; font-size: 13px; }
|
||||
.status { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
|
||||
.pending { background: #fff7e6; color: #fa8c16; }
|
||||
.completed { background: #f6ffed; color: #52c41a; }
|
||||
.cancelled { background: #fff1f0; color: #ff4d4f; }
|
||||
.item { display: flex; gap: 12px; margin-bottom: 12px; }
|
||||
.thumb { width: 60px; height: 60px; border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #eef3ff; }
|
||||
.thumb img { width: 100%; height: 100%; object-fit: cover; }
|
||||
.main { flex: 1; }
|
||||
.title { font-weight: 600; }
|
||||
.line { margin-top: 4px; color: #666; font-size: 13px; }
|
||||
.appointment { color: #1890ff; }
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.content {
|
||||
max-width: 980px;
|
||||
margin: 0 auto;
|
||||
padding: 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -485,9 +485,9 @@ const changeQuantity = async (item: CartItem, delta: number) => {
|
||||
await loadAvailableCoupons()
|
||||
})
|
||||
await updateCartCount()
|
||||
} catch {
|
||||
} catch (error: any) {
|
||||
item.quantity -= delta
|
||||
message.error('更新数量失败')
|
||||
message.error(error?.message || '更新数量失败')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,8 +500,8 @@ const removeItem = async (item: CartItem) => {
|
||||
})
|
||||
await updateCartCount()
|
||||
message.success('作品已删除')
|
||||
} catch {
|
||||
message.error('删除作品失败')
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '删除作品失败')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -520,7 +520,7 @@ const removeSelectedItems = async () => {
|
||||
message.success('已删除选中的作品')
|
||||
} catch (error) {
|
||||
console.error('批量删除失败:', error)
|
||||
message.error('批量删除失败,请稍后重试')
|
||||
message.error((error as any)?.message || '批量删除失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,8 +687,8 @@ const checkout = async () => {
|
||||
onMounted(async () => {
|
||||
try {
|
||||
await loadCartItems()
|
||||
} catch {
|
||||
message.error('获取购物车数据失败')
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '获取购物车数据失败')
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,294 @@
|
||||
<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">
|
||||
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'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const loading = ref(false)
|
||||
const coupons = ref<any[]>([])
|
||||
const activeFilter = ref('all')
|
||||
|
||||
const filterOptions = [
|
||||
{ label: '全部', value: 'all' },
|
||||
{ label: '未使用', value: 'available' },
|
||||
{ label: '已使用', value: 'used' },
|
||||
{ label: '已过期', value: 'expired' }
|
||||
]
|
||||
|
||||
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
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
const getStatusClass = (status: number) => {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return 'available'
|
||||
case 2:
|
||||
return 'used'
|
||||
case 3:
|
||||
return 'expired'
|
||||
default:
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
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: #f5f5f5;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
background: white;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.coupon-section {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.filter-card {
|
||||
border-radius: 12px;
|
||||
margin-bottom: 15px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.filter-segmented {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.content-card {
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
|
||||
padding: 40px 20px;
|
||||
}
|
||||
|
||||
.coupon-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.coupon-card {
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
background: linear-gradient(135deg, #f5f7ff 0%, #e8ecff 100%);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.coupon-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.15);
|
||||
}
|
||||
|
||||
.coupon-card.expired {
|
||||
opacity: 0.6;
|
||||
background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
|
||||
}
|
||||
|
||||
.coupon-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.coupon-value {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: #667eea;
|
||||
padding: 20px;
|
||||
background: rgba(102, 126, 234, 0.1);
|
||||
border-radius: 8px;
|
||||
min-width: 100px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.coupon-card.expired .coupon-value {
|
||||
color: #8b8b9a;
|
||||
background: rgba(139, 139, 154, 0.1);
|
||||
}
|
||||
|
||||
.coupon-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.coupon-name {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.coupon-condition {
|
||||
font-size: 12px;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.coupon-time {
|
||||
font-size: 12px;
|
||||
color: #8b8b9a;
|
||||
}
|
||||
|
||||
.coupon-status {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
padding: 2px 8px;
|
||||
border-radius: 8px;
|
||||
align-self: flex-start;
|
||||
}
|
||||
|
||||
.coupon-status.available {
|
||||
background: #f6ffed;
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.coupon-status.used {
|
||||
background: #f5f5f5;
|
||||
color: #8b8b9a;
|
||||
}
|
||||
|
||||
.coupon-status.expired {
|
||||
background: #fff1f0;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.coupon-section {
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
padding: 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,707 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<header class="header">
|
||||
<div class="user-info" @click="handleUserClick">
|
||||
<a-avatar
|
||||
:size="44"
|
||||
:src="userInfo?.avatar || DEFAULT_AVATAR"
|
||||
/>
|
||||
<div class="welcome">
|
||||
<p class="greeting">{{ greeting }}</p>
|
||||
<p class="username">{{ displayName }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<a-button class="header-action" type="primary" ghost @click="handleUserClick">
|
||||
{{ isLoggedIn ? '个人中心' : '去登录' }}
|
||||
</a-button>
|
||||
</header>
|
||||
|
||||
<div class="search-section">
|
||||
<a-input-search
|
||||
v-model:value="searchQuery"
|
||||
size="large"
|
||||
placeholder="搜索作品、风格或门店"
|
||||
enter-button="搜索"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<a-alert
|
||||
v-if="!isLoggedIn"
|
||||
class="guest-alert"
|
||||
type="info"
|
||||
show-icon
|
||||
message="当前为游客模式"
|
||||
description="先逛作品和门店,收藏、加购、下单时再登录即可。"
|
||||
/>
|
||||
|
||||
<section class="section">
|
||||
<div class="banner-container">
|
||||
<div class="banner-carousel">
|
||||
<a-carousel v-if="bannerImages.length" autoplay :autoplay-speed="3200" effect="fade">
|
||||
<div
|
||||
v-for="banner in bannerImages"
|
||||
:key="banner.id"
|
||||
class="banner-slide"
|
||||
@click="openShopById(banner.shopId)"
|
||||
>
|
||||
<img :src="banner.url" :alt="banner.shopName" class="banner-img" />
|
||||
<div class="banner-copy">
|
||||
<a-tag color="blue">门店推荐</a-tag>
|
||||
<h3>{{ banner.shopName }}</h3>
|
||||
<p>{{ banner.businessHours || '欢迎到店体验' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</a-carousel>
|
||||
<div v-else class="banner-empty">
|
||||
<h3>发现适合你的美甲风格</h3>
|
||||
<p>先看看门店 Banner 和精选作品,再决定今天预约谁。</p>
|
||||
<a-button type="primary" @click="router.push('/products')">浏览作品</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="section">
|
||||
<div class="section-header">
|
||||
<h3>精选作品</h3>
|
||||
<a class="see-all" @click="handleSeeAll('featured')">查看全部</a>
|
||||
</div>
|
||||
<div class="horizontal-scroll">
|
||||
<a-card
|
||||
v-for="item in featuredItems"
|
||||
:key="item.id"
|
||||
class="product-card"
|
||||
:body-style="{ padding: '12px' }"
|
||||
hoverable
|
||||
@click="handleProductClick(item)"
|
||||
>
|
||||
<div class="product-img" :style="{ backgroundColor: item.bgColor }">
|
||||
<img v-if="item.coverUrl" :src="item.coverUrl" :alt="item.name" class="product-cover" />
|
||||
<span v-else>{{ item.name[0] }}</span>
|
||||
</div>
|
||||
<div class="product-info">
|
||||
<p class="name">{{ item.name }}</p>
|
||||
<p class="meta">{{ item.meta }}</p>
|
||||
<p class="price">¥{{ item.price }}</p>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="section popular-section">
|
||||
<div class="section-header">
|
||||
<h3>热门作品</h3>
|
||||
<a class="see-all" @click="handleSeeAll('popular')">查看全部</a>
|
||||
</div>
|
||||
<div class="product-grid">
|
||||
<a-card
|
||||
v-for="item in popularItems"
|
||||
:key="item.id"
|
||||
class="product-card grid-item"
|
||||
:body-style="{ padding: '12px' }"
|
||||
hoverable
|
||||
@click="handleProductClick(item)"
|
||||
>
|
||||
<div class="product-img" :style="{ backgroundColor: item.bgColor }">
|
||||
<img v-if="item.coverUrl" :src="item.coverUrl" :alt="item.name" class="product-cover" />
|
||||
<span v-else>{{ item.name[0] }}</span>
|
||||
</div>
|
||||
<div class="product-info">
|
||||
<p class="name">{{ item.name }}</p>
|
||||
<p class="meta">{{ item.meta }}</p>
|
||||
<p class="price">¥{{ item.price }}</p>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="loading-more">
|
||||
<a-spin size="small" />
|
||||
<span>加载中...</span>
|
||||
</div>
|
||||
<div v-else-if="!hasMore && popularItems.length > 0" class="no-more">
|
||||
没有更多热门推荐了
|
||||
</div>
|
||||
<div v-else-if="popularItems.length === 0 && !loading" class="no-products">
|
||||
暂无热门作品
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { userApi, type UserVO } from '../api/user'
|
||||
import { productApi, type ProductVO } from '../api/product'
|
||||
import { shopApi, type ShopVO } from '../api/shop'
|
||||
import { fileApi } from '../api/file'
|
||||
import { DEFAULT_AVATAR, DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
||||
import type { IdType } from '@/utils/id'
|
||||
|
||||
interface BannerImage {
|
||||
id: string
|
||||
shopId: IdType
|
||||
shopName: string
|
||||
businessHours?: string
|
||||
url: string
|
||||
}
|
||||
|
||||
interface ProductCardItem {
|
||||
id: IdType
|
||||
name: string
|
||||
price: string
|
||||
meta: string
|
||||
coverUrl: string
|
||||
bgColor: string
|
||||
}
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const userInfo = ref<UserVO | null>(null)
|
||||
const publicShops = ref<ShopVO[]>([])
|
||||
const bannerImages = ref<BannerImage[]>([])
|
||||
const featuredItems = ref<ProductCardItem[]>([])
|
||||
const popularSource = ref<ProductCardItem[]>([])
|
||||
const popularItems = ref<ProductCardItem[]>([])
|
||||
const productImageCache = ref<Record<string, string>>({})
|
||||
const searchQuery = ref('')
|
||||
const loading = ref(false)
|
||||
const hasMore = ref(true)
|
||||
const page = ref(1)
|
||||
const pageSize = 8
|
||||
|
||||
const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')))
|
||||
const greeting = computed(() => (isLoggedIn.value ? '欢迎回来' : '游客模式'))
|
||||
const displayName = computed(() => userInfo.value?.nickname || (isLoggedIn.value ? '用户' : '先看看门店和作品'))
|
||||
|
||||
const getRandomColor = (): string => {
|
||||
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||
return colors[Math.floor(Math.random() * colors.length)] ?? '#ffe4d6'
|
||||
}
|
||||
|
||||
const getProductCoverUrl = async (product: ProductVO): Promise<string> => {
|
||||
const firstImageId = product.imageFileIds?.split(',').map(id => id.trim()).find(Boolean)
|
||||
if (!firstImageId) {
|
||||
return DEFAULT_PRODUCT_IMAGE
|
||||
}
|
||||
if (!productImageCache.value[firstImageId]) {
|
||||
try {
|
||||
productImageCache.value[firstImageId] = await fileApi.getSignedUrl(firstImageId) as unknown as string
|
||||
} catch (error) {
|
||||
console.error('获取首页作品封面失败:', error)
|
||||
productImageCache.value[firstImageId] = DEFAULT_PRODUCT_IMAGE
|
||||
}
|
||||
}
|
||||
return productImageCache.value[firstImageId] || DEFAULT_PRODUCT_IMAGE
|
||||
}
|
||||
|
||||
const formatProductCards = async (products: ProductVO[]): Promise<ProductCardItem[]> =>
|
||||
Promise.all(products.map(async item => ({
|
||||
id: item.id,
|
||||
name: item.title || item.name || '未命名作品',
|
||||
price: Number(item.price || 0).toFixed(2),
|
||||
meta: item.approximateDuration || item.shopName || '支持预约',
|
||||
coverUrl: await getProductCoverUrl(item),
|
||||
bgColor: getRandomColor()
|
||||
})))
|
||||
|
||||
const appendPopularItems = (loadMore = false) => {
|
||||
const nextItems = popularSource.value.slice(0, page.value * pageSize)
|
||||
popularItems.value = nextItems
|
||||
hasMore.value = nextItems.length < popularSource.value.length
|
||||
if (!loadMore && nextItems.length === 0) {
|
||||
hasMore.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const loadUserInfo = async () => {
|
||||
if (!isLoggedIn.value) {
|
||||
userInfo.value = null
|
||||
return
|
||||
}
|
||||
try {
|
||||
const response = await userApi.getUserInfo()
|
||||
userInfo.value = response || null
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
userInfo.value = null
|
||||
}
|
||||
}
|
||||
|
||||
const loadPublicShops = async () => {
|
||||
try {
|
||||
const shops = await shopApi.getPublicShops()
|
||||
publicShops.value = Array.isArray(shops) ? shops : []
|
||||
await loadBannerImages()
|
||||
} catch (error) {
|
||||
console.error('获取门店列表失败:', error)
|
||||
publicShops.value = []
|
||||
bannerImages.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const loadBannerImages = async () => {
|
||||
const banners: BannerImage[] = []
|
||||
for (const shop of publicShops.value) {
|
||||
const coverIds = (shop.coverImageFileId || shop.imageFileIds || '')
|
||||
.split(',')
|
||||
.map(id => id.trim())
|
||||
.filter(Boolean)
|
||||
for (const id of coverIds) {
|
||||
try {
|
||||
const url = await fileApi.getSignedUrl(id) as unknown as string
|
||||
if (url) {
|
||||
banners.push({
|
||||
id: `${shop.id}-${id}`,
|
||||
shopId: shop.id,
|
||||
shopName: shop.shopName,
|
||||
businessHours: shop.businessHours,
|
||||
url
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取门店轮播图失败:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
bannerImages.value = banners.slice(0, 8)
|
||||
}
|
||||
|
||||
const loadFeaturedProducts = async () => {
|
||||
try {
|
||||
let products = await productApi.getProductsByTag('精选')
|
||||
if (!Array.isArray(products) || products.length === 0) {
|
||||
products = await productApi.getAllProducts()
|
||||
}
|
||||
featuredItems.value = await formatProductCards((products || []).slice(0, 6))
|
||||
} catch (error) {
|
||||
console.error('获取精选作品失败:', error)
|
||||
featuredItems.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const loadPopularProducts = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
let products = await productApi.getProductsByTag('热门')
|
||||
if (!Array.isArray(products) || products.length === 0) {
|
||||
products = await productApi.getAllProducts()
|
||||
}
|
||||
popularSource.value = await formatProductCards(products || [])
|
||||
page.value = 1
|
||||
appendPopularItems()
|
||||
} catch (error) {
|
||||
console.error('获取热门作品失败:', error)
|
||||
popularSource.value = []
|
||||
popularItems.value = []
|
||||
hasMore.value = false
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleScroll = () => {
|
||||
if (loading.value || !hasMore.value) {
|
||||
return
|
||||
}
|
||||
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
|
||||
const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight
|
||||
const clientHeight = document.documentElement.clientHeight
|
||||
if (scrollTop + clientHeight >= scrollHeight - 120) {
|
||||
page.value += 1
|
||||
appendPopularItems(true)
|
||||
}
|
||||
}
|
||||
|
||||
const handleUserClick = () => {
|
||||
if (isLoggedIn.value) {
|
||||
router.push('/profile')
|
||||
return
|
||||
}
|
||||
message.info('登录后可查看个人中心、收藏和订单')
|
||||
router.push('/')
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
const keyword = searchQuery.value.trim()
|
||||
router.push(keyword ? { path: '/products', query: { keyword } } : '/products')
|
||||
}
|
||||
|
||||
const handleSeeAll = (type: 'featured' | 'popular') => {
|
||||
router.push({
|
||||
path: '/products',
|
||||
query: type === 'featured' ? { tag: '精选' } : { tag: '热门' }
|
||||
})
|
||||
}
|
||||
|
||||
const handleProductClick = (item: ProductCardItem) => {
|
||||
router.push(`/product/${item.id}`)
|
||||
}
|
||||
|
||||
const openShopById = (shopId: IdType) => {
|
||||
router.push(`/shop/${shopId}`)
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await Promise.all([
|
||||
loadUserInfo(),
|
||||
loadPublicShops(),
|
||||
loadFeaturedProducts(),
|
||||
loadPopularProducts()
|
||||
])
|
||||
window.addEventListener('scroll', handleScroll)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('scroll', handleScroll)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 16px 20px 8px;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.greeting {
|
||||
font-size: 12px;
|
||||
color: #8b8b9a;
|
||||
margin: 0 0 2px;
|
||||
}
|
||||
|
||||
.username {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
margin: 0;
|
||||
color: #1f1f1f;
|
||||
}
|
||||
|
||||
.header-action {
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.search-section {
|
||||
padding: 8px 20px 0;
|
||||
}
|
||||
|
||||
.guest-alert {
|
||||
margin: 16px 20px 0;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.banner-container {
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
.banner-carousel {
|
||||
width: 100%;
|
||||
border-radius: 18px;
|
||||
overflow: hidden;
|
||||
min-height: 220px;
|
||||
box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
|
||||
background: linear-gradient(135deg, #f4f7ff 0%, #eef4ff 100%);
|
||||
}
|
||||
|
||||
.banner-slide {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
aspect-ratio: 16 / 9;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.banner-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.banner-copy {
|
||||
position: absolute;
|
||||
left: 24px;
|
||||
bottom: 24px;
|
||||
padding: 16px 18px;
|
||||
border-radius: 16px;
|
||||
background: rgba(255, 255, 255, 0.92);
|
||||
backdrop-filter: blur(6px);
|
||||
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.banner-copy h3 {
|
||||
margin: 10px 0 4px;
|
||||
font-size: 22px;
|
||||
color: #1f1f1f;
|
||||
}
|
||||
|
||||
.banner-copy p {
|
||||
margin: 0;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.banner-empty {
|
||||
min-height: 220px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
padding: 28px;
|
||||
}
|
||||
|
||||
.banner-empty h3 {
|
||||
margin: 0;
|
||||
font-size: 26px;
|
||||
color: #1f1f1f;
|
||||
}
|
||||
|
||||
.banner-empty p {
|
||||
margin: 0;
|
||||
max-width: 360px;
|
||||
color: #666;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.section {
|
||||
padding: 24px 0 0;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0 20px 14px;
|
||||
}
|
||||
|
||||
.section-header h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.see-all {
|
||||
color: #1677ff;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.horizontal-scroll {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
overflow-x: auto;
|
||||
padding: 0 20px;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
.horizontal-scroll::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.product-card {
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.horizontal-scroll .product-card {
|
||||
flex: 0 0 calc((100% - 14px) / 2);
|
||||
width: calc((100% - 14px) / 2);
|
||||
max-width: calc((100% - 14px) / 2);
|
||||
}
|
||||
|
||||
.product-card :deep(.ant-card-body) {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.product-img {
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
border-radius: 14px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 10px;
|
||||
font-size: 40px;
|
||||
font-weight: 700;
|
||||
color: rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.product-cover {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.name {
|
||||
margin: 0 0 4px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #1f1f1f;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.meta {
|
||||
margin: 0 0 6px;
|
||||
font-size: 12px;
|
||||
color: #8b8b9a;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.price {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.product-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 14px;
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
.grid-item {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.loading-more,
|
||||
.no-more,
|
||||
.no-products {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 24px 0 36px;
|
||||
color: #8b8b9a;
|
||||
}
|
||||
|
||||
@media (max-width: 420px) {
|
||||
.header {
|
||||
gap: 12px;
|
||||
padding: 14px 16px 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
min-width: 0;
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
.welcome {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.greeting,
|
||||
.username {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.header-action {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.search-section {
|
||||
padding: 8px 16px 0;
|
||||
}
|
||||
|
||||
.guest-alert {
|
||||
margin: 14px 16px 0;
|
||||
}
|
||||
|
||||
.banner-container,
|
||||
.horizontal-scroll,
|
||||
.product-grid {
|
||||
padding-left: 16px;
|
||||
padding-right: 16px;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
padding: 0 16px 12px;
|
||||
}
|
||||
|
||||
.banner-empty {
|
||||
padding: 22px 18px;
|
||||
}
|
||||
|
||||
.banner-empty h3 {
|
||||
font-size: 22px;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.banner-empty p {
|
||||
max-width: none;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.banner-copy {
|
||||
left: 16px;
|
||||
right: 16px;
|
||||
bottom: 16px;
|
||||
padding: 12px 14px;
|
||||
}
|
||||
|
||||
.banner-copy h3 {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.banner-copy p {
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.header,
|
||||
.search-section,
|
||||
.section,
|
||||
.guest-alert {
|
||||
max-width: var(--frontend-content-max-width);
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.banner-container {
|
||||
padding: 0 24px;
|
||||
}
|
||||
|
||||
.banner-carousel {
|
||||
max-width: var(--frontend-content-max-width);
|
||||
}
|
||||
|
||||
.horizontal-scroll {
|
||||
overflow: visible;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.horizontal-scroll .product-card {
|
||||
flex: 0 0 calc(25% - 12px);
|
||||
width: calc(25% - 12px);
|
||||
max-width: calc(25% - 12px);
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
.product-grid {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.product-grid .product-card {
|
||||
width: 100%;
|
||||
max-width: none;
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,138 @@
|
||||
<template>
|
||||
<div class="not-found-container">
|
||||
<div class="not-found-content">
|
||||
<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">
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const router = useRouter()
|
||||
const countdown = ref(5)
|
||||
let timer: number | null = null
|
||||
|
||||
const redirectToHome = () => {
|
||||
if (timer) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
router.push('/home')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
timer = window.setInterval(() => {
|
||||
if (countdown.value > 0) {
|
||||
countdown.value--
|
||||
} else {
|
||||
if (timer) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
redirectToHome()
|
||||
}
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (timer) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.not-found-container {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.not-found-content {
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
padding: 60px 40px;
|
||||
text-align: center;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
||||
max-width: 500px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.error-code {
|
||||
font-size: 120px;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
margin: 0 0 20px 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.not-found-content h1 {
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
margin: 0 0 16px 0;
|
||||
}
|
||||
|
||||
.not-found-content p {
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
margin: 0 0 24px 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.redirect-message {
|
||||
margin: 20px 0 30px 0;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.countdown {
|
||||
color: #667eea;
|
||||
font-weight: bold;
|
||||
font-size: 18px;
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
:deep(.ant-btn-primary) {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border: none;
|
||||
padding: 12px 32px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
border-radius: 25px;
|
||||
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
:deep(.ant-btn-primary:hover) {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
@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,132 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<header class="header">
|
||||
<a-button type="text" @click="router.back()">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>我的订单</h1>
|
||||
<div class="placeholder" />
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<a-empty v-if="!orders.length" description="暂无订单">
|
||||
<a-button type="primary" @click="router.push('/products')">去逛逛</a-button>
|
||||
</a-empty>
|
||||
|
||||
<a-card v-for="order in orders" :key="order.id" class="order-card">
|
||||
<div class="order-head">
|
||||
<span>订单号:{{ order.orderNo }}</span>
|
||||
<span class="status" :class="statusClass(order.status)">{{ order.statusText }}</span>
|
||||
</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" />
|
||||
<span v-else>{{ item.productTitle[0] }}</span>
|
||||
</div>
|
||||
<div class="main">
|
||||
<div class="title">{{ item.productTitle }}</div>
|
||||
<div class="line">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
|
||||
<div v-if="item.artistName" class="line">美甲师:{{ item.artistName }}</div>
|
||||
<div v-if="item.appointmentTime" class="line appointment">预约时间:{{ item.appointmentTime }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<span>总计:¥{{ order.actualAmount.toFixed(2) }}</span>
|
||||
<a-button v-if="order.status === 1" size="small" danger @click="cancelOrder(order.id)">取消订单</a-button>
|
||||
</div>
|
||||
</a-card>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { fileApi } from '../api/index'
|
||||
import { orderApi } from '../api/order'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
const router = useRouter()
|
||||
const orders = ref<any[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
|
||||
const statusClass = (status: number) => {
|
||||
if (status === 1) return 'pending'
|
||||
if (status === 2) return 'completed'
|
||||
return 'cancelled'
|
||||
}
|
||||
|
||||
const loadOrders = async () => {
|
||||
try {
|
||||
orders.value = (await orderApi.getOrderList() as unknown as any[]) || []
|
||||
for (const order of orders.value) {
|
||||
for (const item of order.items || []) {
|
||||
const match = item.productImage?.replace(/<[^>]*>/g, '').match(/\/api\/file\/get\/(\d+)/)
|
||||
if (!match?.[1]) continue
|
||||
const imageId = match[1]
|
||||
try {
|
||||
if (!imageIdCache.value[imageId]) imageIdCache.value[imageId] = await fileApi.getSignedUrl(imageId) as any
|
||||
item.productImage = imageIdCache.value[imageId]
|
||||
} catch {
|
||||
item.productImage = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
message.error('获取订单列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
const cancelOrder = (orderId: IdType) => {
|
||||
Modal.confirm({
|
||||
title: '确认取消订单',
|
||||
content: '确定要取消这个订单吗?',
|
||||
onOk: async () => {
|
||||
try {
|
||||
await runWithGlobalLoading(() => orderApi.cancelOrder(orderId))
|
||||
message.success('订单已取消')
|
||||
await loadOrders()
|
||||
} catch {
|
||||
message.error('取消订单失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(loadOrders)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { min-height: 100vh; padding-top: 60px; background: #f5f5f5; }
|
||||
.header { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 10px 15px; background: #fff; border-bottom: 1px solid #f0f0f0; }
|
||||
.header h1 { margin: 0; font-size: 18px; }
|
||||
.placeholder { width: 40px; height: 40px; }
|
||||
.content { padding: 15px; }
|
||||
.order-card { margin-bottom: 12px; border-radius: 12px; }
|
||||
.order-head, .footer { display: flex; align-items: center; justify-content: space-between; }
|
||||
.order-head { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid #f0f0f0; }
|
||||
.status { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
|
||||
.pending { background: #fff7e6; color: #fa8c16; }
|
||||
.completed { background: #f6ffed; color: #52c41a; }
|
||||
.cancelled { background: #fff1f0; color: #ff4d4f; }
|
||||
.item { display: flex; gap: 12px; margin-bottom: 12px; }
|
||||
.thumb { width: 60px; height: 60px; border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #eef3ff; }
|
||||
.thumb img { width: 100%; height: 100%; object-fit: cover; }
|
||||
.main { flex: 1; }
|
||||
.title { font-weight: 600; }
|
||||
.line { margin-top: 4px; color: #666; font-size: 13px; }
|
||||
.appointment { color: #1890ff; }
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.content {
|
||||
max-width: 980px;
|
||||
margin: 0 auto;
|
||||
padding: 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,300 @@
|
||||
<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: #999" />
|
||||
</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: #999" />
|
||||
</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">
|
||||
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'
|
||||
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
const countdown = ref(0)
|
||||
const userInfo = ref<{ phone?: string } | null>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
let countdownTimer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
const formState = reactive({
|
||||
verificationCode: '',
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
const draftKey = buildDraftStorageKey('password-settings', 'set-password')
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<typeof formState>(draftKey, 'session')
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(formState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(draftKey, { ...formState }, 'session')
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到当前会话')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(draftKey, 'session')
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const userPhone = computed(() => userInfo.value?.phone || '')
|
||||
|
||||
const validateConfirmPassword = (_rule: any, value: string) => {
|
||||
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' }
|
||||
]
|
||||
}
|
||||
|
||||
const startCountdown = () => {
|
||||
countdown.value = 60
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer)
|
||||
}
|
||||
countdownTimer = setInterval(() => {
|
||||
countdown.value -= 1
|
||||
if (countdown.value <= 0 && countdownTimer) {
|
||||
clearInterval(countdownTimer)
|
||||
countdownTimer = null
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
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 || '获取用户信息失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleSendVerificationCode = async () => {
|
||||
if (!userPhone.value) {
|
||||
message.error('请先绑定手机号')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithGlobalLoading(() => userApi.sendVerificationCode({ phone: userPhone.value }))
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error: any) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error(error.message || '发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
restoreDraft()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
background: white;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.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: white;
|
||||
}
|
||||
|
||||
.password-tip {
|
||||
margin-top: 8px;
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,687 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<header class="header">
|
||||
<a-button type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>{{ product.title || product.name || '作品详情' }}</h1>
|
||||
<a-button type="text" @click="handleFavoriteClick">
|
||||
<component :is="isFavorite ? StarFilled : StarOutlined" :class="['header-star', { active: isFavorite }]" />
|
||||
</a-button>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<a-result
|
||||
v-if="loadError"
|
||||
status="warning"
|
||||
title="暂时无法查看作品详情"
|
||||
:sub-title="loadError"
|
||||
>
|
||||
<template #extra>
|
||||
<a-button type="primary" @click="handleBackClick">返回上一页</a-button>
|
||||
</template>
|
||||
</a-result>
|
||||
|
||||
<template v-else>
|
||||
<section class="hero-card">
|
||||
<a-carousel v-if="productImages.length > 1" autoplay dots>
|
||||
<div v-for="(image, index) in productImages" :key="index" class="carousel-slide">
|
||||
<img :src="image" :alt="product.title || product.name" class="product-image" />
|
||||
</div>
|
||||
</a-carousel>
|
||||
<div v-else class="single-image">
|
||||
<img :src="productImages[0] || DEFAULT_PRODUCT_IMAGE" :alt="product.title || product.name" class="product-image" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="info-card">
|
||||
<div class="info-header">
|
||||
<div>
|
||||
<h2 class="product-name">{{ product.title || product.name }}</h2>
|
||||
<p class="product-price">¥{{ Number(product.price || 0).toFixed(2) }}</p>
|
||||
</div>
|
||||
<a-tag color="blue">{{ product.approximateDuration || '时长待确认' }}</a-tag>
|
||||
</div>
|
||||
|
||||
<div class="metric-row">
|
||||
<button class="metric-card" type="button" @click="openShopDetail" :disabled="!shopInfo?.id">
|
||||
<ShopOutlined />
|
||||
<div>
|
||||
<span class="metric-label">所属门店</span>
|
||||
<strong>{{ shopInfo?.shopName || '暂未绑定门店' }}</strong>
|
||||
</div>
|
||||
</button>
|
||||
<div class="metric-card">
|
||||
<TeamOutlined />
|
||||
<div>
|
||||
<span class="metric-label">可约美甲师</span>
|
||||
<strong>{{ artistCountText }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="metric-card">
|
||||
<CalendarOutlined />
|
||||
<div>
|
||||
<span class="metric-label">最早可约</span>
|
||||
<strong>{{ earliestBookableText }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="shopInfo" class="shop-summary" @click="openShopDetail">
|
||||
<div class="shop-summary-title">{{ shopInfo.shopName }}</div>
|
||||
<div class="shop-summary-text">{{ shopInfo.address || '门店地址待完善' }}</div>
|
||||
<div class="shop-summary-text">{{ shopInfo.businessHours || '营业时间待完善' }}</div>
|
||||
</div>
|
||||
|
||||
<div class="stats-row">
|
||||
<button type="button" class="stat-btn" @click="handleLikeClick">
|
||||
<component :is="isLiked ? HeartFilled : HeartOutlined" :class="{ active: isLiked }" />
|
||||
<span>{{ product.likeCount || 0 }} 点赞</span>
|
||||
</button>
|
||||
<button type="button" class="stat-btn" @click="handleFavoriteClick">
|
||||
<component :is="isFavorite ? StarFilled : StarOutlined" :class="{ active: isFavorite }" />
|
||||
<span>{{ product.collectCount || 0 }} 收藏</span>
|
||||
</button>
|
||||
<div class="stat-btn static">
|
||||
<ClockCircleOutlined />
|
||||
<span>{{ product.approximateDuration || '时长待定' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tags">
|
||||
<a-tag
|
||||
v-for="tag in product.tagInfos || []"
|
||||
:key="tag.id"
|
||||
:style="{
|
||||
color: tag.textColor || '#333',
|
||||
backgroundColor: tag.bgColor || '#f0f0f0',
|
||||
borderColor: tag.borderColor || '#f0f0f0'
|
||||
}"
|
||||
>
|
||||
{{ tag.tagName }}
|
||||
</a-tag>
|
||||
<a-tag v-if="!product.tagInfos?.length" color="default">暂无标签</a-tag>
|
||||
</div>
|
||||
|
||||
<div class="description-block">
|
||||
<h3>作品介绍</h3>
|
||||
<p>{{ product.description || '店家还没补充作品说明。' }}</p>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
</main>
|
||||
|
||||
<footer v-if="!loadError" class="action-buttons">
|
||||
<a-button class="add-cart-btn" size="large" @click="handleAddToCart">
|
||||
<ShoppingCartOutlined />
|
||||
加入购物车
|
||||
</a-button>
|
||||
<a-button class="buy-now-btn" type="primary" size="large" @click="handleBuyNow">
|
||||
<ThunderboltOutlined />
|
||||
立即预约
|
||||
</a-button>
|
||||
</footer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
CalendarOutlined,
|
||||
ClockCircleOutlined,
|
||||
HeartFilled,
|
||||
HeartOutlined,
|
||||
LeftOutlined,
|
||||
ShoppingCartOutlined,
|
||||
ShopOutlined,
|
||||
StarFilled,
|
||||
StarOutlined,
|
||||
TeamOutlined,
|
||||
ThunderboltOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { cartApi } from '@/api/cart'
|
||||
import { fileApi } from '@/api/file'
|
||||
import { productApi, type ProductVO } from '@/api/product'
|
||||
import { productLikeApi } from '@/api/productLike'
|
||||
import { shopApi, type ShopVO } from '@/api/shop'
|
||||
import { wishlistApi } from '@/api/wishlist'
|
||||
import { DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { toOptionalIdString } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
||||
|
||||
const product = ref<ProductVO>({} as ProductVO)
|
||||
const shopInfo = ref<ShopVO | null>(null)
|
||||
const productImages = ref<string[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const isFavorite = ref(false)
|
||||
const isLiked = ref(false)
|
||||
const loadError = ref('')
|
||||
|
||||
const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')))
|
||||
const artistCount = computed(() => {
|
||||
if (typeof product.value.availableBookableArtistCount === 'number') {
|
||||
return product.value.availableBookableArtistCount
|
||||
}
|
||||
const rawValue = product.value.bookableArtists || ''
|
||||
return rawValue
|
||||
.split(',')
|
||||
.map(id => id.trim())
|
||||
.filter(Boolean).length
|
||||
})
|
||||
const artistCountText = computed(() => {
|
||||
if (artistCount.value > 0) {
|
||||
return `${artistCount.value} 位`
|
||||
}
|
||||
return product.value.bookableArtistRestricted ? '暂无' : '门店安排'
|
||||
})
|
||||
const earliestBookableText = computed(() => estimateEarliestBookable(shopInfo.value?.businessHours))
|
||||
|
||||
const parseTimeRange = (businessHours?: string): { start: string; end: string } | null => {
|
||||
if (!businessHours) {
|
||||
return null
|
||||
}
|
||||
const normalized = businessHours.replace(/\s+/g, '')
|
||||
const matched = normalized.match(/(\d{1,2}:\d{2}).*?(\d{1,2}:\d{2})/)
|
||||
if (!matched) {
|
||||
return null
|
||||
}
|
||||
const [, start, end] = matched
|
||||
if (!start || !end) {
|
||||
return null
|
||||
}
|
||||
return { start, end }
|
||||
}
|
||||
|
||||
const formatDateTime = (date: Date) => {
|
||||
const month = `${date.getMonth() + 1}`.padStart(2, '0')
|
||||
const day = `${date.getDate()}`.padStart(2, '0')
|
||||
const hour = `${date.getHours()}`.padStart(2, '0')
|
||||
const minute = `${date.getMinutes()}`.padStart(2, '0')
|
||||
return `${month}-${day} ${hour}:${minute}`
|
||||
}
|
||||
|
||||
const estimateEarliestBookable = (businessHours?: string) => {
|
||||
const timeRange = parseTimeRange(businessHours)
|
||||
if (!timeRange) {
|
||||
return businessHours || '以门店安排为准'
|
||||
}
|
||||
|
||||
const startParts = timeRange.start.split(':').map(Number)
|
||||
const endParts = timeRange.end.split(':').map(Number)
|
||||
const startHour = startParts[0]
|
||||
const startMinute = startParts[1]
|
||||
const endHour = endParts[0]
|
||||
const endMinute = endParts[1]
|
||||
if ([startHour, startMinute, endHour, endMinute].some(value => value === undefined || Number.isNaN(value))) {
|
||||
return businessHours || '以门店安排为准'
|
||||
}
|
||||
const safeStartHour = startHour ?? 0
|
||||
const safeStartMinute = startMinute ?? 0
|
||||
const safeEndHour = endHour ?? 0
|
||||
const safeEndMinute = endMinute ?? 0
|
||||
const candidate = new Date(Date.now() + 30 * 60 * 1000)
|
||||
|
||||
const openTime = new Date(candidate)
|
||||
openTime.setHours(safeStartHour, safeStartMinute, 0, 0)
|
||||
|
||||
const closeTime = new Date(candidate)
|
||||
closeTime.setHours(safeEndHour, safeEndMinute, 0, 0)
|
||||
|
||||
if (candidate <= openTime) {
|
||||
return `今天 ${timeRange.start}`
|
||||
}
|
||||
|
||||
if (candidate >= closeTime) {
|
||||
const nextOpen = new Date(openTime)
|
||||
nextOpen.setDate(nextOpen.getDate() + 1)
|
||||
return `明天 ${timeRange.start}`
|
||||
}
|
||||
|
||||
return formatDateTime(candidate)
|
||||
}
|
||||
|
||||
const requireLogin = (actionText: string) => {
|
||||
if (isLoggedIn.value) {
|
||||
return true
|
||||
}
|
||||
message.info(`${actionText}前请先登录`)
|
||||
router.push('/')
|
||||
return false
|
||||
}
|
||||
|
||||
const loadProductImages = async () => {
|
||||
const fileIds = product.value.imageFileIds?.split(',').map(id => id.trim()).filter(Boolean) || []
|
||||
if (!fileIds.length) {
|
||||
productImages.value = [DEFAULT_PRODUCT_IMAGE]
|
||||
return
|
||||
}
|
||||
|
||||
const urls: string[] = []
|
||||
for (const id of fileIds) {
|
||||
try {
|
||||
if (!imageIdCache.value[id]) {
|
||||
imageIdCache.value[id] = await fileApi.getSignedUrl(id) as unknown as string
|
||||
}
|
||||
if (imageIdCache.value[id]) {
|
||||
urls.push(imageIdCache.value[id])
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取作品图片失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
productImages.value = urls.length ? urls : [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
|
||||
const loadShopInfo = async (shopId?: IdType | null) => {
|
||||
if (!shopId) {
|
||||
shopInfo.value = null
|
||||
return
|
||||
}
|
||||
try {
|
||||
const response = await shopApi.getShopById(shopId)
|
||||
shopInfo.value = response || null
|
||||
} catch (error) {
|
||||
console.error('获取门店信息失败:', error)
|
||||
shopInfo.value = null
|
||||
}
|
||||
}
|
||||
|
||||
const checkWishlistStatus = async () => {
|
||||
if (!isLoggedIn.value || !product.value.id) {
|
||||
isFavorite.value = false
|
||||
return
|
||||
}
|
||||
try {
|
||||
const status = await wishlistApi.checkWishlist(product.value.id)
|
||||
isFavorite.value = Boolean(status)
|
||||
} catch (error) {
|
||||
console.error('获取收藏状态失败:', error)
|
||||
isFavorite.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const checkLikeStatus = async () => {
|
||||
if (!isLoggedIn.value || !product.value.id) {
|
||||
isLiked.value = false
|
||||
return
|
||||
}
|
||||
try {
|
||||
const status = await productLikeApi.checkLikeStatus(product.value.id)
|
||||
isLiked.value = Boolean(status)
|
||||
} catch (error) {
|
||||
console.error('获取点赞状态失败:', error)
|
||||
isLiked.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resolveLoadError = (error: any) => {
|
||||
const status = error?.response?.status
|
||||
if (status === 404) {
|
||||
return '这件作品可能已下架或不存在。'
|
||||
}
|
||||
if (status === 401) {
|
||||
return '作品详情暂时无法加载,请稍后重试。'
|
||||
}
|
||||
return error?.message || '网络有点忙,请稍后再试。'
|
||||
}
|
||||
|
||||
const fetchProductDetail = async () => {
|
||||
loadError.value = ''
|
||||
try {
|
||||
const productId = toOptionalIdString(route.params.id)
|
||||
if (!productId) {
|
||||
throw new Error('作品ID不存在')
|
||||
}
|
||||
const response = await productApi.getProductById(productId)
|
||||
if (!response?.id) {
|
||||
throw new Error('未找到对应作品')
|
||||
}
|
||||
product.value = response
|
||||
await Promise.all([
|
||||
loadProductImages(),
|
||||
loadShopInfo(response.shopId),
|
||||
checkWishlistStatus(),
|
||||
checkLikeStatus()
|
||||
])
|
||||
} catch (error) {
|
||||
console.error('获取作品详情失败:', error)
|
||||
loadError.value = resolveLoadError(error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
const openShopDetail = () => {
|
||||
if (!shopInfo.value?.id) {
|
||||
return
|
||||
}
|
||||
router.push(`/shop/${shopInfo.value.id}`)
|
||||
}
|
||||
|
||||
const handleFavoriteClick = async () => {
|
||||
if (!product.value.id || !requireLogin('收藏作品')) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
if (isFavorite.value) {
|
||||
await wishlistApi.removeFromWishlist(product.value.id)
|
||||
product.value.collectCount = Math.max(0, Number(product.value.collectCount || 0) - 1)
|
||||
message.success('已取消收藏')
|
||||
} else {
|
||||
await wishlistApi.addToWishlist(product.value.id)
|
||||
product.value.collectCount = Number(product.value.collectCount || 0) + 1
|
||||
message.success('已加入收藏')
|
||||
}
|
||||
})
|
||||
isFavorite.value = !isFavorite.value
|
||||
} catch (error) {
|
||||
console.error('收藏操作失败:', error)
|
||||
message.error('收藏操作失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
const handleLikeClick = async () => {
|
||||
if (!product.value.id || !requireLogin('点赞作品')) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
if (isLiked.value) {
|
||||
await productLikeApi.unlikeProduct(product.value.id)
|
||||
product.value.likeCount = Math.max(0, Number(product.value.likeCount || 0) - 1)
|
||||
message.success('已取消点赞')
|
||||
} else {
|
||||
await productLikeApi.likeProduct(product.value.id)
|
||||
product.value.likeCount = Number(product.value.likeCount || 0) + 1
|
||||
message.success('已点赞')
|
||||
}
|
||||
})
|
||||
isLiked.value = !isLiked.value
|
||||
} catch (error) {
|
||||
console.error('点赞操作失败:', error)
|
||||
message.error('点赞操作失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
const handleAddToCart = async () => {
|
||||
if (!product.value.id || !requireLogin('加入购物车')) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await runWithGlobalLoading(() => cartApi.addToCart({ productId: product.value.id, quantity: 1 }))
|
||||
await updateCartCount()
|
||||
message.success(`已将 ${product.value.title || product.value.name || '作品'} 加入购物车`)
|
||||
} catch (error) {
|
||||
console.error('加入购物车失败:', error)
|
||||
message.error('加入购物车失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
const handleBuyNow = async () => {
|
||||
if (!product.value.id || !requireLogin('预约下单')) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await runWithGlobalLoading(() => cartApi.addToCart({ productId: product.value.id, quantity: 1 }))
|
||||
await updateCartCount()
|
||||
router.push('/cart')
|
||||
} catch (error) {
|
||||
console.error('立即预约失败:', error)
|
||||
message.error('操作失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void fetchProductDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 10px 16px;
|
||||
background: rgba(255, 255, 255, 0.96);
|
||||
backdrop-filter: blur(10px);
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
flex: 1;
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header-star {
|
||||
font-size: 20px;
|
||||
color: #8b8b9a;
|
||||
}
|
||||
|
||||
.header-star.active {
|
||||
color: #f7b500;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 16px 16px 108px;
|
||||
}
|
||||
|
||||
.hero-card,
|
||||
.info-card {
|
||||
max-width: 1040px;
|
||||
margin: 0 auto 16px;
|
||||
border-radius: 20px;
|
||||
overflow: hidden;
|
||||
background: white;
|
||||
box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
|
||||
}
|
||||
|
||||
.carousel-slide,
|
||||
.single-image {
|
||||
aspect-ratio: 16 / 11;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.product-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.info-card {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.info-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.product-name {
|
||||
margin: 0 0 8px;
|
||||
font-size: 26px;
|
||||
font-weight: 700;
|
||||
color: #1f1f1f;
|
||||
}
|
||||
|
||||
.product-price {
|
||||
margin: 0;
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.metric-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.metric-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
border: 1px solid #edf0f5;
|
||||
border-radius: 16px;
|
||||
background: #fafcff;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.metric-card:disabled {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.metric-card :deep(svg) {
|
||||
font-size: 18px;
|
||||
color: #1677ff;
|
||||
}
|
||||
|
||||
.metric-label {
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
color: #8b8b9a;
|
||||
}
|
||||
|
||||
.metric-card strong {
|
||||
font-size: 14px;
|
||||
color: #1f1f1f;
|
||||
}
|
||||
|
||||
.shop-summary {
|
||||
margin-top: 18px;
|
||||
padding: 16px 18px;
|
||||
border-radius: 18px;
|
||||
background: linear-gradient(135deg, #f8fbff 0%, #eef4ff 100%);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.shop-summary-title {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: #1f1f1f;
|
||||
}
|
||||
|
||||
.shop-summary-text {
|
||||
margin-top: 6px;
|
||||
color: #666;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.stats-row {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.stat-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 14px;
|
||||
border: 1px solid #edf0f5;
|
||||
border-radius: 999px;
|
||||
background: white;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.stat-btn :deep(svg) {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.stat-btn :deep(.active),
|
||||
.stat-btn :deep(svg.active) {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.stat-btn .active {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.stat-btn.static {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.description-block {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.description-block h3 {
|
||||
margin: 0 0 12px;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.description-block p {
|
||||
margin: 0;
|
||||
color: #666;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 120;
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
padding: 16px;
|
||||
background: rgba(255, 255, 255, 0.96);
|
||||
backdrop-filter: blur(10px);
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.action-buttons :deep(.ant-btn) {
|
||||
flex: 1;
|
||||
height: 48px;
|
||||
border-radius: 999px;
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.metric-row {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.stats-row {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,574 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1 v-if="!showSearch">作品列表</h1>
|
||||
<div v-else class="search-input-container">
|
||||
<a-input-search
|
||||
v-model:value="searchKeyword"
|
||||
placeholder="搜索标题、标签或描述"
|
||||
class="search-input"
|
||||
enter-button
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</div>
|
||||
<a-button class="search-btn" type="text" @click="toggleSearch">
|
||||
<SearchOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
</header>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="category-sidebar">
|
||||
<div
|
||||
v-for="category in categories"
|
||||
:key="category"
|
||||
class="category-item"
|
||||
:class="{ active: selectedCategory === category }"
|
||||
@click="handleCategoryClick(category)"
|
||||
>
|
||||
{{ category }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="product-section">
|
||||
<a-alert
|
||||
v-if="activeBannerText"
|
||||
class="page-banner"
|
||||
type="info"
|
||||
show-icon
|
||||
:message="activeBannerText"
|
||||
/>
|
||||
|
||||
<div class="product-grid">
|
||||
<a-card
|
||||
v-for="item in products"
|
||||
:key="item.id"
|
||||
class="product-card"
|
||||
:body-style="{ padding: '12px' }"
|
||||
hoverable
|
||||
@click="handleProductClick(item)"
|
||||
>
|
||||
<div class="product-img">
|
||||
<img
|
||||
v-if="getProductImages(item).length > 0"
|
||||
:src="getProductImages(item)[0]"
|
||||
:alt="item.title || item.name"
|
||||
class="product-image"
|
||||
/>
|
||||
<div v-else class="product-img-placeholder">
|
||||
<span>{{ (item.title || item.name)?.[0] || '作' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="product-info">
|
||||
<p class="name">{{ item.title || item.name }}</p>
|
||||
<div class="product-meta">
|
||||
<span class="duration">{{ item.approximateDuration || '时长待定' }}</span>
|
||||
<div class="stats">
|
||||
<span>{{ item.likeCount || 0 }} 点赞</span>
|
||||
<span>{{ item.collectCount || 0 }} 收藏</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="product-tags">
|
||||
<template v-if="item.tagInfos?.length">
|
||||
<a-tag
|
||||
v-for="tag in item.tagInfos"
|
||||
:key="tag.id"
|
||||
size="small"
|
||||
:style="{
|
||||
marginRight: '4px',
|
||||
marginBottom: '4px',
|
||||
color: tag.textColor || '#333',
|
||||
backgroundColor: tag.bgColor || '#f0f0f0',
|
||||
borderColor: tag.borderColor || '#f0f0f0'
|
||||
}"
|
||||
>
|
||||
{{ tag.tagName }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<a-tag v-else size="small" color="default">暂无标签</a-tag>
|
||||
</div>
|
||||
|
||||
<div class="price-row">
|
||||
<p class="price">¥{{ Number(item.price || 0).toFixed(2) }}</p>
|
||||
<div class="cart-action">
|
||||
<span v-if="item.inCart" class="cart-note">购物车已有</span>
|
||||
<a-button
|
||||
:type="item.inCart ? 'default' : 'primary'"
|
||||
size="small"
|
||||
shape="circle"
|
||||
class="cart-btn"
|
||||
:class="{ 'cart-btn-in-cart': item.inCart }"
|
||||
@click.stop="handleAddToCart(item)"
|
||||
>
|
||||
<CheckOutlined v-if="item.inCart" />
|
||||
<ShoppingCartOutlined v-else />
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<div v-if="products.length === 0 && !loading" class="empty-state">
|
||||
<a-empty description="暂时没有匹配的作品">
|
||||
<a-button type="primary" @click="resetFilters">查看全部作品</a-button>
|
||||
</a-empty>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="loading-state">
|
||||
<a-spin />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, watch, inject, computed } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { CheckOutlined, LeftOutlined, SearchOutlined, ShoppingCartOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { productApi, type ProductVO } from '@/api/product'
|
||||
import { tagApi, type TagVO } from '@/api/tag'
|
||||
import { cartApi } from '@/api/cart'
|
||||
import { fileApi } from '@/api/file'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { fetchCartProductIdSet, hasCartProduct, withAddedCartProduct } from '@/utils/cart-state'
|
||||
|
||||
type ProductListItem = ProductVO & {
|
||||
inCart?: boolean
|
||||
}
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
||||
|
||||
const allTags = ref<TagVO[]>([])
|
||||
const categories = ref<string[]>(['全部'])
|
||||
const selectedCategory = ref('全部')
|
||||
const products = ref<ProductListItem[]>([])
|
||||
const loading = ref(false)
|
||||
const showSearch = ref(false)
|
||||
const searchKeyword = ref('')
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const imageUrls = ref<Record<string, string[]>>({})
|
||||
const cartProductIdSet = ref(new Set<string>())
|
||||
let useGlobalLoadingForNextRouteSync = false
|
||||
|
||||
const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')))
|
||||
const activeBannerText = computed(() => {
|
||||
if (searchKeyword.value.trim()) {
|
||||
return `当前显示“${searchKeyword.value.trim()}”的匹配结果`
|
||||
}
|
||||
if (selectedCategory.value !== '全部') {
|
||||
return `当前按标签“${selectedCategory.value}”筛选`
|
||||
}
|
||||
return ''
|
||||
})
|
||||
|
||||
const DEFAULT_PRODUCT_IMAGE = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCBmaWxsPSIjZjVmNWY1IiB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIvPjx0ZXh0IHg9IjUwJSIgeT0iNTAlIiBmaWxsPSIjYmZiZmJmIiBmb250LXNpemU9IjI0IiB0ZXh0LWFuY2hvcj0ibWlkZGxlIiBkeT0iLjNlbSI+YWFhPC90ZXh0Pjwvc3ZnPg=='
|
||||
|
||||
const ensureLoginForAction = (actionText: string) => {
|
||||
if (isLoggedIn.value) {
|
||||
return true
|
||||
}
|
||||
message.info(`${actionText}前请先登录账号`)
|
||||
router.push('/')
|
||||
return false
|
||||
}
|
||||
|
||||
const loadImageUrls = async (productList: ProductVO[]) => {
|
||||
for (const product of productList) {
|
||||
if (!product.imageFileIds) {
|
||||
imageUrls.value[String(product.id)] = [DEFAULT_PRODUCT_IMAGE]
|
||||
continue
|
||||
}
|
||||
|
||||
const ids = product.imageFileIds.split(',').map(id => id.trim()).filter(Boolean)
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
try {
|
||||
if (!imageIdCache.value[id]) {
|
||||
imageIdCache.value[id] = await fileApi.getSignedUrl(id) as unknown as string
|
||||
}
|
||||
if (imageIdCache.value[id]) {
|
||||
urls.push(imageIdCache.value[id])
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取作品图片失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
imageUrls.value[String(product.id)] = urls.length ? urls : [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
}
|
||||
|
||||
const getProductImages = (product: ProductVO): string[] => imageUrls.value[String(product.id)] || [DEFAULT_PRODUCT_IMAGE]
|
||||
|
||||
const markProductsInCart = (productList: ProductVO[]) => {
|
||||
return (Array.isArray(productList) ? productList : []).map(item => ({
|
||||
...item,
|
||||
inCart: hasCartProduct(cartProductIdSet.value, item.id)
|
||||
}))
|
||||
}
|
||||
|
||||
const syncCartProductState = async () => {
|
||||
if (!isLoggedIn.value) {
|
||||
cartProductIdSet.value = new Set()
|
||||
return
|
||||
}
|
||||
cartProductIdSet.value = await fetchCartProductIdSet()
|
||||
}
|
||||
|
||||
const fetchTags = async () => {
|
||||
try {
|
||||
const response = await tagApi.getAllTags() as unknown as TagVO[]
|
||||
allTags.value = Array.isArray(response) ? response : []
|
||||
categories.value = ['全部', ...allTags.value.map(tag => tag.tagName)]
|
||||
} catch (error: any) {
|
||||
console.error('获取标签失败:', error)
|
||||
categories.value = ['全部']
|
||||
}
|
||||
}
|
||||
|
||||
const fetchProducts = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
let response: ProductVO[] = []
|
||||
const keyword = searchKeyword.value.trim()
|
||||
|
||||
if (keyword) {
|
||||
response = await productApi.searchProducts(keyword)
|
||||
} else if (selectedCategory.value === '全部') {
|
||||
response = await productApi.getAllProducts()
|
||||
} else {
|
||||
response = await productApi.getProductsByTag(selectedCategory.value)
|
||||
}
|
||||
|
||||
products.value = markProductsInCart(Array.isArray(response) ? response : [])
|
||||
await loadImageUrls(products.value)
|
||||
} catch (error: any) {
|
||||
console.error('获取作品列表失败:', error)
|
||||
message.error(error?.message || '加载作品列表失败,请稍后重试')
|
||||
products.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const syncRouteFilters = async () => {
|
||||
await syncCartProductState()
|
||||
const keyword = typeof route.query.keyword === 'string' ? route.query.keyword.trim() : ''
|
||||
const tag = typeof route.query.tag === 'string' ? route.query.tag.trim() : ''
|
||||
|
||||
searchKeyword.value = keyword
|
||||
showSearch.value = Boolean(keyword)
|
||||
selectedCategory.value = tag && categories.value.includes(tag) ? tag : '全部'
|
||||
if (useGlobalLoadingForNextRouteSync) {
|
||||
useGlobalLoadingForNextRouteSync = false
|
||||
await runWithGlobalLoading(() => fetchProducts())
|
||||
return
|
||||
}
|
||||
await fetchProducts()
|
||||
}
|
||||
|
||||
const handleBackClick = () => {
|
||||
router.push('/home')
|
||||
}
|
||||
|
||||
const handleCategoryClick = (category: string) => {
|
||||
selectedCategory.value = category
|
||||
searchKeyword.value = ''
|
||||
showSearch.value = false
|
||||
useGlobalLoadingForNextRouteSync = true
|
||||
router.replace({
|
||||
path: '/products',
|
||||
query: category === '全部' ? {} : { tag: category }
|
||||
})
|
||||
}
|
||||
|
||||
const handleProductClick = (item: ProductVO) => {
|
||||
router.push(`/product/${item.id}`)
|
||||
}
|
||||
|
||||
const handleAddToCart = async (item: ProductListItem) => {
|
||||
if (!ensureLoginForAction('加入购物车')) {
|
||||
return
|
||||
}
|
||||
if (hasCartProduct(cartProductIdSet.value, item.id)) {
|
||||
message.info('购物车已有')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await runWithGlobalLoading(() => cartApi.addToCart({ productId: item.id, quantity: 1 }))
|
||||
cartProductIdSet.value = withAddedCartProduct(cartProductIdSet.value, item.id)
|
||||
products.value = markProductsInCart(products.value)
|
||||
await updateCartCount()
|
||||
message.success(`已将 ${item.title || item.name || '作品'} 加入购物车`)
|
||||
} catch (error: any) {
|
||||
console.error('加入购物车失败:', error)
|
||||
message.error(error?.message || '加入购物车失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
const keyword = searchKeyword.value.trim()
|
||||
useGlobalLoadingForNextRouteSync = true
|
||||
router.replace({
|
||||
path: '/products',
|
||||
query: keyword ? { keyword } : {}
|
||||
})
|
||||
}
|
||||
|
||||
const toggleSearch = () => {
|
||||
showSearch.value = !showSearch.value
|
||||
if (!showSearch.value) {
|
||||
searchKeyword.value = ''
|
||||
useGlobalLoadingForNextRouteSync = true
|
||||
router.replace({ path: '/products', query: selectedCategory.value === '全部' ? {} : { tag: selectedCategory.value } })
|
||||
}
|
||||
}
|
||||
|
||||
const resetFilters = () => {
|
||||
selectedCategory.value = '全部'
|
||||
searchKeyword.value = ''
|
||||
showSearch.value = false
|
||||
useGlobalLoadingForNextRouteSync = true
|
||||
router.replace('/products')
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.query,
|
||||
async () => {
|
||||
await syncRouteFilters()
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchTags()
|
||||
await syncRouteFilters()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
padding-top: 60px;
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
background: white;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.back-btn,
|
||||
.search-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.search-input-container {
|
||||
flex: 1;
|
||||
margin: 0 10px;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
display: flex;
|
||||
min-height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.category-sidebar {
|
||||
width: 92px;
|
||||
background: #fafafa;
|
||||
border-right: 1px solid #ececec;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
padding: 16px 12px;
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
border-left: 3px solid transparent;
|
||||
}
|
||||
|
||||
.category-item.active {
|
||||
color: #1677ff;
|
||||
background: white;
|
||||
border-left-color: #1677ff;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.product-section {
|
||||
flex: 1;
|
||||
padding: 16px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.page-banner {
|
||||
margin-bottom: 16px;
|
||||
border-radius: 14px;
|
||||
}
|
||||
|
||||
.product-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.product-card {
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.product-img {
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
overflow: hidden;
|
||||
border-radius: 14px;
|
||||
background: #eef3ff;
|
||||
}
|
||||
|
||||
.product-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.product-img-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 40px;
|
||||
font-weight: 700;
|
||||
color: rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.name {
|
||||
margin: 12px 0 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
color: #1f1f1f;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.product-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
color: #8b8b9a;
|
||||
}
|
||||
|
||||
.duration {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px 8px;
|
||||
border-radius: 999px;
|
||||
background: #f4f6fb;
|
||||
}
|
||||
|
||||
.stats {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.product-tags {
|
||||
margin: 10px 0;
|
||||
min-height: 26px;
|
||||
}
|
||||
|
||||
.price-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.price {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.cart-action {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.cart-note {
|
||||
font-size: 12px;
|
||||
color: #8c8c8c;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.cart-btn {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.cart-btn-in-cart {
|
||||
color: #52c41a;
|
||||
border-color: #b7eb8f;
|
||||
background: #f6ffed;
|
||||
}
|
||||
|
||||
.empty-state,
|
||||
.loading-state {
|
||||
padding: 56px 0;
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.main-content {
|
||||
max-width: var(--frontend-content-max-width);
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.category-sidebar {
|
||||
width: 128px;
|
||||
border-radius: 20px 0 0 20px;
|
||||
}
|
||||
|
||||
.product-section {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.product-grid {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,914 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<div class="header-bg"></div>
|
||||
|
||||
<header class="header">
|
||||
<h1>个人中心</h1>
|
||||
<a-button class="settings-btn" type="text" @click="handleSettingsClick">
|
||||
<SettingOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
</header>
|
||||
|
||||
<div class="profile-info">
|
||||
<a-card :bordered="false" class="profile-card">
|
||||
<div class="avatar-section">
|
||||
<a-badge :dot="hasNotification" :offset="[-5, 5]">
|
||||
<a-avatar :size="90" :src="userInfo.avatar || DEFAULT_AVATAR" class="user-avatar" />
|
||||
</a-badge>
|
||||
<div class="user-details">
|
||||
<h2 class="username">{{ userInfo.nickname || '用户' }}</h2>
|
||||
<p class="account">{{ userInfo.account }}</p>
|
||||
<p class="signature" v-if="userInfo.signature">{{ userInfo.signature }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="shop-card" @click="handleShopCardClick">
|
||||
<div class="shop-icon-wrapper">
|
||||
<ShopOutlined class="shop-icon" />
|
||||
</div>
|
||||
<div class="shop-content">
|
||||
<p class="shop-label">当前登录门店</p>
|
||||
<h3 class="shop-name">{{ currentShopName }}</h3>
|
||||
<p class="shop-tip">{{ shopSwitchTip }}</p>
|
||||
</div>
|
||||
<div class="shop-arrow">
|
||||
<RightOutlined />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="needSetPassword" class="password-tip">
|
||||
<a-alert
|
||||
type="warning"
|
||||
message="建议尽快设置密码"
|
||||
description="当前账号还未设置登录密码。"
|
||||
show-icon
|
||||
>
|
||||
<template #action>
|
||||
<a-button size="small" type="primary" @click="handleSetPassword">去设置</a-button>
|
||||
</template>
|
||||
</a-alert>
|
||||
</div>
|
||||
|
||||
<a-button type="primary" block @click="handleEditProfile" class="edit-btn">
|
||||
编辑资料
|
||||
</a-button>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<div class="stats-section">
|
||||
<a-card :bordered="false" class="stats-card">
|
||||
<a-row :gutter="16">
|
||||
<a-col :span="8">
|
||||
<div class="stat-item" @click="router.push('/orders')">
|
||||
<div class="stat-icon orders">
|
||||
<ShoppingOutlined />
|
||||
</div>
|
||||
<a-statistic title="订单" :value="orderCount" />
|
||||
</div>
|
||||
</a-col>
|
||||
<a-col :span="8">
|
||||
<div class="stat-item" @click="router.push('/wishlist')">
|
||||
<div class="stat-icon wishlist">
|
||||
<HeartOutlined />
|
||||
</div>
|
||||
<a-statistic title="收藏" :value="wishlistCount" />
|
||||
</div>
|
||||
</a-col>
|
||||
<a-col :span="8">
|
||||
<div class="stat-item" @click="router.push('/coupons')">
|
||||
<div class="stat-icon coupons">
|
||||
<CreditCardOutlined />
|
||||
</div>
|
||||
<a-statistic title="优惠券" :value="couponCount" />
|
||||
</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<div class="menu-section">
|
||||
<a-card :bordered="false" class="menu-card">
|
||||
<a-list :data-source="coreMenuItems" :split="false">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item class="menu-item" @click="handleMenuClick(item.key)">
|
||||
<template #actions>
|
||||
<RightOutlined />
|
||||
</template>
|
||||
<a-list-item-meta>
|
||||
<template #avatar>
|
||||
<div class="menu-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>
|
||||
|
||||
<div class="logout-section">
|
||||
<a-button danger block @click="handleLogout">
|
||||
退出登录
|
||||
</a-button>
|
||||
</div>
|
||||
|
||||
<a-modal
|
||||
v-model:open="editModalVisible"
|
||||
title="编辑资料"
|
||||
@ok="handleSaveProfile"
|
||||
@cancel="handleCancelEdit"
|
||||
:confirmLoading="saving"
|
||||
:ok-button-props="{ disabled: avatarUploadPending }"
|
||||
>
|
||||
<DraftActions
|
||||
:saved-at="draftSavedAt"
|
||||
:disabled="avatarUploadPending"
|
||||
@save="handleSaveDraft"
|
||||
@clear="handleClearDraft"
|
||||
/>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="头像">
|
||||
<div class="avatar-upload-section">
|
||||
<a-upload
|
||||
name="file"
|
||||
:show-upload-list="false"
|
||||
:before-upload="beforeUploadAvatar"
|
||||
:custom-request="handleAvatarUpload"
|
||||
accept="image/*"
|
||||
>
|
||||
<a-avatar :size="80" :src="editForm.avatar || DEFAULT_AVATAR" />
|
||||
<div class="upload-hint">点击更换头像</div>
|
||||
</a-upload>
|
||||
<a-progress
|
||||
v-if="avatarUploadPending"
|
||||
:percent="Math.round(avatarUploadProgress)"
|
||||
size="small"
|
||||
status="active"
|
||||
class="avatar-upload-progress"
|
||||
/>
|
||||
<div v-if="avatarUploadPending" class="avatar-upload-status">头像上传中,上传完成前不可保存。</div>
|
||||
<a-button v-if="editForm.avatar" type="text" danger size="small" @click="handleDeleteAvatar">
|
||||
删除头像
|
||||
</a-button>
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="昵称">
|
||||
<a-input v-model:value="editForm.nickname" placeholder="请输入昵称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="个性签名">
|
||||
<a-textarea v-model:value="editForm.signature" placeholder="请输入个性签名" :rows="3" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<a-modal
|
||||
v-model:open="shopSwitchVisible"
|
||||
title="切换登录门店"
|
||||
:confirm-loading="shopSwitchLoading"
|
||||
@ok="handleConfirmSwitchShop"
|
||||
>
|
||||
<a-radio-group v-model:value="selectedShopId" class="shop-option-group">
|
||||
<a-radio
|
||||
v-for="shop in shopOptions"
|
||||
:key="String(shop.id)"
|
||||
:value="String(shop.id)"
|
||||
class="shop-option"
|
||||
>
|
||||
<div class="shop-option-name">{{ shop.shopName }}</div>
|
||||
</a-radio>
|
||||
</a-radio-group>
|
||||
<a-empty v-if="!shopOptions.length" description="当前账号没有可切换的门店" />
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
BellOutlined,
|
||||
CreditCardOutlined,
|
||||
HeartOutlined,
|
||||
QuestionCircleOutlined,
|
||||
RightOutlined,
|
||||
SettingOutlined,
|
||||
ShopOutlined,
|
||||
ShoppingOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { UploadProps } from 'ant-design-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { couponApi } from '@/api/coupon'
|
||||
import { fileApi } from '@/api/file'
|
||||
import { orderApi } from '@/api/order'
|
||||
import { userApi, type UserVO } from '@/api/user'
|
||||
import { createChunkUploadTask, type ChunkUploadTask } from '@/utils/chunk-upload'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { wishlistApi } from '@/api/wishlist'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const userInfo = ref<UserVO>({
|
||||
id: 0,
|
||||
nickname: '',
|
||||
account: '',
|
||||
avatar: '',
|
||||
type: 0,
|
||||
status: 0,
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
|
||||
const editModalVisible = ref(false)
|
||||
const saving = ref(false)
|
||||
const needSetPassword = ref(false)
|
||||
const hasNotification = ref(false)
|
||||
const orderCount = ref(0)
|
||||
const couponCount = ref(0)
|
||||
const wishlistCount = ref(0)
|
||||
const shopSwitchVisible = ref(false)
|
||||
const shopSwitchLoading = ref(false)
|
||||
const selectedShopId = ref<string>()
|
||||
const avatarUploadProgress = ref(0)
|
||||
const avatarUploadPending = ref(false)
|
||||
let avatarUploadTask: ChunkUploadTask<string> | null = null
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
const editForm = reactive({
|
||||
nickname: '',
|
||||
avatar: '',
|
||||
signature: ''
|
||||
})
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('profile-edit')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
nickname: editForm.nickname,
|
||||
avatar: editForm.avatar,
|
||||
signature: editForm.signature
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(editForm, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
if (avatarUploadPending.value) {
|
||||
message.warning('头像上传完成后才能暂存')
|
||||
return
|
||||
}
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const shopOptions = computed(() => {
|
||||
const ids = userInfo.value.shopIds || []
|
||||
const names = userInfo.value.shopNames || []
|
||||
return ids.map((id, index) => ({
|
||||
id,
|
||||
shopName: names[index] || `门店 ${id}`
|
||||
}))
|
||||
})
|
||||
|
||||
const currentShopName = computed(() => userInfo.value.shopName || '当前暂无可用门店')
|
||||
const shopSwitchTip = computed(() => {
|
||||
if (shopOptions.value.length > 1) {
|
||||
return `可切换 ${shopOptions.value.length} 家门店`
|
||||
}
|
||||
if (shopOptions.value.length === 1) {
|
||||
return '点击查看当前门店详情'
|
||||
}
|
||||
return '当前暂无可用门店'
|
||||
})
|
||||
|
||||
const menuItems = [
|
||||
{
|
||||
key: 'orders',
|
||||
title: '我的订单',
|
||||
desc: '查看预约状态、取消订单',
|
||||
icon: ShoppingOutlined,
|
||||
bgColor: '#e6f7ff'
|
||||
},
|
||||
{
|
||||
key: 'wishlist',
|
||||
title: '我的收藏',
|
||||
desc: '快速回到喜欢的作品',
|
||||
icon: HeartOutlined,
|
||||
bgColor: '#fff1f0'
|
||||
},
|
||||
{
|
||||
key: 'coupons',
|
||||
title: '我的优惠券',
|
||||
desc: '查看可用优惠和 VIP 折扣',
|
||||
icon: CreditCardOutlined,
|
||||
bgColor: '#fff7e6'
|
||||
},
|
||||
{
|
||||
key: 'notifications',
|
||||
title: '消息通知',
|
||||
desc: '消息中心功能开发中',
|
||||
icon: BellOutlined,
|
||||
bgColor: '#f9f0ff'
|
||||
},
|
||||
{
|
||||
key: 'help',
|
||||
title: '帮助与支持',
|
||||
desc: '常见问题功能开发中',
|
||||
icon: QuestionCircleOutlined,
|
||||
bgColor: '#eef9ff'
|
||||
}
|
||||
]
|
||||
|
||||
void menuItems
|
||||
|
||||
const coreMenuItems = [
|
||||
{
|
||||
key: 'orders',
|
||||
title: '我的订单',
|
||||
desc: '查看预约状态、取消订单',
|
||||
icon: ShoppingOutlined,
|
||||
bgColor: '#e6f7ff'
|
||||
},
|
||||
{
|
||||
key: 'wishlist',
|
||||
title: '我的收藏',
|
||||
desc: '快速回到喜欢的作品',
|
||||
icon: HeartOutlined,
|
||||
bgColor: '#fff1f0'
|
||||
},
|
||||
{
|
||||
key: 'coupons',
|
||||
title: '我的优惠券',
|
||||
desc: '查看可用优惠和 VIP 折扣',
|
||||
icon: CreditCardOutlined,
|
||||
bgColor: '#fff7e6'
|
||||
},
|
||||
{
|
||||
key: 'settings',
|
||||
title: '设置中心',
|
||||
desc: '统一管理账号安全和更多入口',
|
||||
icon: SettingOutlined,
|
||||
bgColor: '#f9f0ff'
|
||||
}
|
||||
]
|
||||
|
||||
const persistUserSession = (payload: any) => {
|
||||
localStorage.setItem('accessToken', payload.accessToken)
|
||||
localStorage.setItem('refreshToken', payload.refreshToken)
|
||||
localStorage.setItem('userInfo', JSON.stringify(payload.userInfo))
|
||||
sessionStorage.setItem('accessToken', payload.accessToken)
|
||||
if (payload.needSetPassword) {
|
||||
localStorage.setItem('needSetPassword', 'true')
|
||||
} else {
|
||||
localStorage.removeItem('needSetPassword')
|
||||
}
|
||||
}
|
||||
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const response = await userApi.getUserInfo()
|
||||
userInfo.value = response
|
||||
needSetPassword.value = localStorage.getItem('needSetPassword') === 'true'
|
||||
selectedShopId.value = response.shopId ? String(response.shopId) : undefined
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
message.error('获取用户信息失败')
|
||||
}
|
||||
}
|
||||
|
||||
const loadCounts = async () => {
|
||||
try {
|
||||
const [orders, coupons, wishlist] = await Promise.all([
|
||||
orderApi.getOrderList(),
|
||||
couponApi.listUserCoupons(),
|
||||
wishlistApi.getWishlist()
|
||||
])
|
||||
orderCount.value = Array.isArray(orders) ? orders.length : 0
|
||||
couponCount.value = Array.isArray(coupons) ? coupons.length : 0
|
||||
wishlistCount.value = Array.isArray(wishlist) ? wishlist.length : 0
|
||||
} catch (error) {
|
||||
console.error('加载个人中心统计失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleEditProfile = () => {
|
||||
avatarUploadTask?.cancel()
|
||||
avatarUploadTask = null
|
||||
avatarUploadPending.value = false
|
||||
avatarUploadProgress.value = 0
|
||||
editForm.nickname = userInfo.value.nickname || ''
|
||||
editForm.avatar = userInfo.value.avatar || ''
|
||||
editForm.signature = userInfo.value.signature || ''
|
||||
restoreDraft()
|
||||
editModalVisible.value = true
|
||||
}
|
||||
|
||||
const beforeUploadAvatar: UploadProps['beforeUpload'] = file => {
|
||||
const isImage = file.type.startsWith('image/')
|
||||
const isLt20M = file.size / 1024 / 1024 < 20
|
||||
|
||||
if (!isImage) {
|
||||
message.error('只能上传图片文件')
|
||||
}
|
||||
if (!isLt20M) {
|
||||
message.error('图片大小不能超过 20MB')
|
||||
}
|
||||
return isImage && isLt20M
|
||||
}
|
||||
|
||||
const handleAvatarUpload = async (options: any) => {
|
||||
const { file, onProgress, onSuccess, onError } = options
|
||||
|
||||
avatarUploadTask?.cancel()
|
||||
avatarUploadProgress.value = 0
|
||||
avatarUploadPending.value = true
|
||||
|
||||
const task = createChunkUploadTask({
|
||||
file: file as File,
|
||||
scene: 'profile-avatar',
|
||||
api: {
|
||||
initUpload: fileApi.initAvatarChunkUpload,
|
||||
uploadChunk: fileApi.uploadAvatarChunk,
|
||||
completeUpload: fileApi.completeAvatarChunkUpload,
|
||||
cancelUpload: fileApi.cancelAvatarChunkUpload
|
||||
},
|
||||
onProgress: (percent) => {
|
||||
avatarUploadProgress.value = percent
|
||||
onProgress?.({ percent })
|
||||
}
|
||||
})
|
||||
|
||||
avatarUploadTask = task
|
||||
|
||||
try {
|
||||
const { response } = await task.promise
|
||||
editForm.avatar = response as unknown as string
|
||||
avatarUploadProgress.value = 100
|
||||
onSuccess?.({ url: response })
|
||||
message.success('头像上传成功')
|
||||
} catch (error) {
|
||||
const errorMessage = (error as Error)?.message || '头像上传失败'
|
||||
if (errorMessage !== '上传已取消' && errorMessage !== 'canceled') {
|
||||
console.error('头像上传失败:', error)
|
||||
message.error(errorMessage)
|
||||
onError?.(error)
|
||||
}
|
||||
} finally {
|
||||
if (avatarUploadTask === task) {
|
||||
avatarUploadTask = null
|
||||
avatarUploadPending.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleDeleteAvatar = () => {
|
||||
Modal.confirm({
|
||||
title: '确认删除头像',
|
||||
content: '删除后会恢复为默认头像。',
|
||||
okText: '确认',
|
||||
cancelText: '取消',
|
||||
onOk: async () => {
|
||||
editForm.avatar = ''
|
||||
try {
|
||||
await runWithGlobalLoading(() => userApi.updateUserInfo({ avatar: '' }))
|
||||
userInfo.value.avatar = ''
|
||||
message.success('头像删除成功')
|
||||
} catch (error) {
|
||||
console.error('删除头像失败:', error)
|
||||
message.error('删除头像失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const handleSaveProfile = async () => {
|
||||
if (!editForm.nickname.trim()) {
|
||||
message.error('请输入昵称')
|
||||
return
|
||||
}
|
||||
|
||||
if (avatarUploadPending.value) {
|
||||
message.warning('头像上传完成前不可保存')
|
||||
return
|
||||
}
|
||||
|
||||
saving.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await userApi.updateUserInfo({
|
||||
nickname: editForm.nickname,
|
||||
avatar: editForm.avatar,
|
||||
signature: editForm.signature
|
||||
})
|
||||
await fetchUserInfo()
|
||||
})
|
||||
message.success('资料更新成功')
|
||||
handleClearDraft(false)
|
||||
editModalVisible.value = false
|
||||
} catch (error) {
|
||||
console.error('保存资料失败:', error)
|
||||
message.error('保存资料失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleCancelEdit = () => {
|
||||
avatarUploadTask?.cancel()
|
||||
avatarUploadTask = null
|
||||
avatarUploadPending.value = false
|
||||
avatarUploadProgress.value = 0
|
||||
editModalVisible.value = false
|
||||
}
|
||||
|
||||
const handleShopCardClick = () => {
|
||||
if (shopOptions.value.length > 1) {
|
||||
shopSwitchVisible.value = true
|
||||
return
|
||||
}
|
||||
if (userInfo.value.shopId) {
|
||||
router.push(`/shop/${userInfo.value.shopId}`)
|
||||
return
|
||||
}
|
||||
message.info('当前暂无可用门店')
|
||||
}
|
||||
|
||||
const handleConfirmSwitchShop = async () => {
|
||||
if (!selectedShopId.value) {
|
||||
message.warning('请选择要切换的门店')
|
||||
return
|
||||
}
|
||||
if (String(userInfo.value.shopId || '') === selectedShopId.value) {
|
||||
shopSwitchVisible.value = false
|
||||
return
|
||||
}
|
||||
|
||||
shopSwitchLoading.value = true
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
const response = await authApi.switchShop({ shopId: selectedShopId.value })
|
||||
persistUserSession(response as any)
|
||||
await Promise.all([fetchUserInfo(), loadCounts()])
|
||||
})
|
||||
message.success('门店已切换')
|
||||
shopSwitchVisible.value = false
|
||||
} catch (error: any) {
|
||||
console.error('切换门店失败:', error)
|
||||
message.error(error?.message || '切换门店失败')
|
||||
} finally {
|
||||
shopSwitchLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleMenuClick = (key: string) => {
|
||||
if (key === 'orders') {
|
||||
router.push('/orders')
|
||||
} else if (key === 'wishlist') {
|
||||
router.push('/wishlist')
|
||||
} else if (key === 'coupons') {
|
||||
router.push('/coupons')
|
||||
} else if (key === 'settings') {
|
||||
router.push('/settings')
|
||||
} else if (key === 'notifications') {
|
||||
message.info('消息通知功能开发中')
|
||||
} else if (key === 'help') {
|
||||
message.info('帮助中心功能开发中')
|
||||
}
|
||||
}
|
||||
|
||||
const handleLogout = () => {
|
||||
Modal.confirm({
|
||||
title: '确认退出登录',
|
||||
content: '退出后需要重新登录才能继续下单和查看订单。',
|
||||
okText: '确认',
|
||||
cancelText: '取消',
|
||||
onOk: async () => {
|
||||
await runWithGlobalLoading(async () => {
|
||||
try {
|
||||
await authApi.logout()
|
||||
} catch (error) {
|
||||
console.error('退出登录接口调用失败:', error)
|
||||
} finally {
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
localStorage.removeItem('needSetPassword')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
message.success('已退出登录')
|
||||
router.push('/')
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const handleSettingsClick = () => {
|
||||
router.push('/settings')
|
||||
}
|
||||
|
||||
const handleSetPassword = () => {
|
||||
router.push('/settings/password')
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await Promise.all([fetchUserInfo(), loadCounts()])
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
padding-top: 60px;
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.header-bg {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 200px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 45%, #f093fb 100%);
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.settings-btn {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.profile-info,
|
||||
.stats-section,
|
||||
.menu-section,
|
||||
.logout-section {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
padding: 0 15px 15px;
|
||||
}
|
||||
|
||||
.profile-info {
|
||||
padding-top: 15px;
|
||||
}
|
||||
|
||||
.profile-card,
|
||||
.stats-card,
|
||||
.menu-card {
|
||||
border-radius: 22px;
|
||||
box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
|
||||
}
|
||||
|
||||
.profile-card :deep(.ant-card-body) {
|
||||
padding: 28px 24px 24px;
|
||||
}
|
||||
|
||||
.avatar-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.user-avatar {
|
||||
border: 4px solid white;
|
||||
}
|
||||
|
||||
.username {
|
||||
margin: 0 0 6px;
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.account,
|
||||
.signature {
|
||||
margin: 0;
|
||||
color: #7c7c8a;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.shop-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
margin-top: 24px;
|
||||
padding: 18px;
|
||||
border-radius: 18px;
|
||||
background: linear-gradient(135deg, #f5f7ff 0%, #e8ecff 100%);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.shop-icon-wrapper {
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
}
|
||||
|
||||
.shop-icon {
|
||||
font-size: 24px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.shop-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.shop-label {
|
||||
margin: 0 0 4px;
|
||||
font-size: 12px;
|
||||
color: #8b8b9a;
|
||||
}
|
||||
|
||||
.shop-name {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.shop-tip {
|
||||
margin: 6px 0 0;
|
||||
color: #6b6b7a;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.shop-arrow {
|
||||
color: #c4c4d0;
|
||||
}
|
||||
|
||||
.password-tip {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.edit-btn {
|
||||
margin-top: 20px;
|
||||
height: 48px;
|
||||
border-radius: 14px;
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.stats-card :deep(.ant-card-body) {
|
||||
padding: 20px 16px;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 24px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.stat-icon.orders {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
}
|
||||
|
||||
.stat-icon.wishlist {
|
||||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||||
}
|
||||
|
||||
.stat-icon.coupons {
|
||||
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
|
||||
}
|
||||
|
||||
.menu-card :deep(.ant-card-body) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
padding: 18px 16px;
|
||||
cursor: pointer;
|
||||
border-bottom: 1px solid #f5f5f7;
|
||||
}
|
||||
|
||||
.menu-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 20px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.logout-section :deep(.ant-btn-dangerous) {
|
||||
height: 50px;
|
||||
border-radius: 25px;
|
||||
font-weight: 700;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.avatar-upload-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.upload-hint {
|
||||
font-size: 12px;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.avatar-upload-progress {
|
||||
width: 220px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.avatar-upload-status {
|
||||
font-size: 12px;
|
||||
color: #fa8c16;
|
||||
}
|
||||
|
||||
.shop-option-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.shop-option {
|
||||
margin: 0;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #e8ecff;
|
||||
border-radius: 14px;
|
||||
}
|
||||
|
||||
.shop-option-name {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.profile-info,
|
||||
.stats-section,
|
||||
.menu-section,
|
||||
.logout-section {
|
||||
max-width: var(--frontend-content-max-width);
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,243 @@
|
||||
<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">
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
BellOutlined,
|
||||
ClearOutlined,
|
||||
InfoCircleOutlined,
|
||||
LeftOutlined,
|
||||
LockOutlined,
|
||||
MessageOutlined,
|
||||
QuestionCircleOutlined,
|
||||
RightOutlined,
|
||||
SafetyOutlined,
|
||||
SoundOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const comingSoonDesc = '暂未开放,敬请期待'
|
||||
|
||||
const settingsSections = ref([
|
||||
{
|
||||
type: 'title',
|
||||
title: '账号与安全'
|
||||
},
|
||||
{
|
||||
key: 'account',
|
||||
title: '账号设置',
|
||||
desc: '修改密码、绑定手机号、管理账号安全项',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#e6f7ff'
|
||||
},
|
||||
{
|
||||
type: 'title',
|
||||
title: '更多功能'
|
||||
},
|
||||
{
|
||||
key: 'notifications',
|
||||
title: '消息通知',
|
||||
desc: comingSoonDesc,
|
||||
icon: BellOutlined,
|
||||
bgColor: '#f6ffed'
|
||||
},
|
||||
{
|
||||
key: 'message-push',
|
||||
title: '消息推送',
|
||||
desc: comingSoonDesc,
|
||||
icon: MessageOutlined,
|
||||
bgColor: '#fffbe6'
|
||||
},
|
||||
{
|
||||
key: 'theme',
|
||||
title: '主题设置',
|
||||
desc: comingSoonDesc,
|
||||
icon: SoundOutlined,
|
||||
bgColor: '#f9f0ff'
|
||||
},
|
||||
{
|
||||
key: 'clear-cache',
|
||||
title: '缓存清理',
|
||||
desc: comingSoonDesc,
|
||||
icon: ClearOutlined,
|
||||
bgColor: '#fff2e8'
|
||||
},
|
||||
{
|
||||
key: 'privacy',
|
||||
title: '隐私政策',
|
||||
desc: comingSoonDesc,
|
||||
icon: SafetyOutlined,
|
||||
bgColor: '#e6f7ff'
|
||||
},
|
||||
{
|
||||
key: 'about',
|
||||
title: '关于我们',
|
||||
desc: comingSoonDesc,
|
||||
icon: InfoCircleOutlined,
|
||||
bgColor: '#f6ffed'
|
||||
},
|
||||
{
|
||||
key: 'help',
|
||||
title: '帮助中心',
|
||||
desc: comingSoonDesc,
|
||||
icon: QuestionCircleOutlined,
|
||||
bgColor: '#eef9ff'
|
||||
}
|
||||
])
|
||||
|
||||
const showComingSoon = () => {
|
||||
message.info('该功能暂未开放,敬请期待')
|
||||
}
|
||||
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
const handleSettingClick = (key: string) => {
|
||||
if (key === 'account') {
|
||||
router.push('/settings/account')
|
||||
return
|
||||
}
|
||||
|
||||
showComingSoon()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.settings-menu {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.settings-card :deep(.ant-card-body) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
padding: 12px 16px;
|
||||
font-size: 13px;
|
||||
color: #999;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
padding: 16px;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.setting-item:hover {
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.setting-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-action) {
|
||||
margin-left: 8px;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.setting-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-meta-title) {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-meta-description) {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.version-info {
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,398 @@
|
||||
<template>
|
||||
<div class="shop-detail">
|
||||
<div class="header-bg"></div>
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>店铺详情</h1>
|
||||
<div class="header-placeholder"></div>
|
||||
</header>
|
||||
<div class="shop-content">
|
||||
<a-card :bordered="false" class="shop-card">
|
||||
<div class="shop-info">
|
||||
<div class="shop-header">
|
||||
<div class="shop-icon-wrapper">
|
||||
<ShopOutlined class="shop-icon" />
|
||||
</div>
|
||||
<div class="shop-header-content">
|
||||
<h2 class="shop-name" @click="copyToClipboard(shopInfo.shopName, '店名')" style="cursor: pointer;">
|
||||
{{ shopInfo.shopName }}
|
||||
<span class="copy-icon">📋</span>
|
||||
</h2>
|
||||
<p class="shop-address" @click="copyToClipboard(shopInfo.address, '地址')" style="cursor: pointer;">
|
||||
{{ shopInfo.address }}
|
||||
<span class="copy-icon">📋</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="shop-details">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">营业时间</div>
|
||||
<div class="detail-value">{{ shopInfo.businessHours }}</div>
|
||||
</div>
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">店铺描述</div>
|
||||
<div class="detail-value">{{ shopInfo.description }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 店铺环境图轮播 -->
|
||||
<div class="shop-images" v-if="shopImages.length > 0">
|
||||
<h3 class="section-title">店铺环境图</h3>
|
||||
<div class="image-carousel">
|
||||
<a-carousel autoplay :autoplay-speed="3000" dots>
|
||||
<div v-for="(url, index) in shopImages" :key="index" class="carousel-item" @click="showImageModal(url)">
|
||||
<img :src="url" :alt="`店铺环境图 ${index + 1}`" class="carousel-image" />
|
||||
</div>
|
||||
</a-carousel>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 图片查看模态框 -->
|
||||
<a-modal
|
||||
v-model:open="imageModalVisible"
|
||||
title="店铺环境图"
|
||||
:width="800"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<img :src="selectedImage" alt="店铺环境图" class="modal-image" />
|
||||
</a-modal>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { LeftOutlined, ShopOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { shopApi, type ShopVO } from '@/api/shop'
|
||||
import { fileApi } from '@/api/file'
|
||||
import { toOptionalIdString } from '@/utils/id'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const shopInfo = ref<ShopVO>({
|
||||
id: '',
|
||||
shopName: '',
|
||||
description: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
imageFileIds: '',
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
|
||||
const shopImages = ref<string[]>([])
|
||||
|
||||
// 图片模态框
|
||||
const imageModalVisible = ref(false)
|
||||
const selectedImage = ref('')
|
||||
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
// 显示图片模态框
|
||||
const showImageModal = (imageUrl: string) => {
|
||||
selectedImage.value = imageUrl
|
||||
imageModalVisible.value = true
|
||||
}
|
||||
|
||||
// 关闭图片模态框
|
||||
const handleCancel = () => {
|
||||
imageModalVisible.value = false
|
||||
selectedImage.value = ''
|
||||
}
|
||||
|
||||
// 复制到剪贴板
|
||||
const copyToClipboard = async (text: string, type: string) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text)
|
||||
message.success(`${type}已复制到剪贴板`)
|
||||
} catch (err) {
|
||||
console.error('复制失败:', err)
|
||||
message.error('复制失败,请手动复制')
|
||||
}
|
||||
}
|
||||
|
||||
const loadShopImages = async () => {
|
||||
try {
|
||||
const imageFileIds = shopInfo.value.imageFileIds
|
||||
if (imageFileIds) {
|
||||
const fileIds = imageFileIds.split(',').filter(id => id.trim())
|
||||
const fileIdPromises = fileIds.map(idStr => {
|
||||
const fileId = idStr.trim()
|
||||
if (!fileId) {
|
||||
return null
|
||||
}
|
||||
return fileApi.getSignedUrl(fileId).catch(() => {
|
||||
return null
|
||||
})
|
||||
})
|
||||
|
||||
const results = await Promise.all(fileIdPromises)
|
||||
const filteredResults = results
|
||||
.filter((url): url is any => url !== null)
|
||||
.map(url => {
|
||||
const urlStr = typeof url === 'string' ? url : String(url)
|
||||
return urlStr.replace(/[`]/g, '').trim()
|
||||
})
|
||||
shopImages.value = filteredResults
|
||||
}
|
||||
} catch (error) {
|
||||
}
|
||||
}
|
||||
|
||||
const fetchShopDetail = async () => {
|
||||
try {
|
||||
// 从路由参数或本地存储获取店铺ID
|
||||
const shopId = toOptionalIdString(route.params.id || localStorage.getItem('userShopId'))
|
||||
if (!shopId) {
|
||||
message.error('店铺ID不存在')
|
||||
router.back()
|
||||
return
|
||||
}
|
||||
|
||||
const response = await shopApi.getShopById(shopId) as any
|
||||
shopInfo.value = response || {}
|
||||
|
||||
// 加载店铺图片
|
||||
await loadShopImages()
|
||||
} catch (error) {
|
||||
message.error('获取店铺详情失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchShopDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.shop-detail {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.header-bg {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 120px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
background: transparent;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.header-placeholder {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.shop-content {
|
||||
padding: 100px 15px 20px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.shop-card {
|
||||
border-radius: 20px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.shop-card :deep(.ant-card-body) {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.shop-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.shop-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.shop-icon-wrapper {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.shop-icon {
|
||||
font-size: 36px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.shop-header-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.shop-name {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
margin: 0 0 8px 0;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.shop-address {
|
||||
font-size: 14px;
|
||||
color: #8b8b9a;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.copy-icon {
|
||||
font-size: 12px;
|
||||
margin-left: 6px;
|
||||
opacity: 0.6;
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.shop-name:hover .copy-icon,
|
||||
.shop-address:hover .copy-icon {
|
||||
opacity: 1;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.shop-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.detail-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.detail-label {
|
||||
font-size: 13px;
|
||||
color: #8b8b9a;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.detail-value {
|
||||
font-size: 16px;
|
||||
color: #1a1a2e;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #1a1a2e;
|
||||
margin: 0 0 12px 0;
|
||||
}
|
||||
|
||||
.image-carousel {
|
||||
margin: 12px 0;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
.carousel-item {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.carousel-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.carousel-item:hover .carousel-image {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
/* 轮播指示器样式 */
|
||||
.image-carousel :deep(.slick-dots) {
|
||||
bottom: 10px;
|
||||
}
|
||||
|
||||
.image-carousel :deep(.slick-dots li) {
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
.image-carousel :deep(.slick-dots li button) {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.image-carousel :deep(.slick-dots li.slick-active button) {
|
||||
width: 20px;
|
||||
border-radius: 4px;
|
||||
background: #667eea;
|
||||
}
|
||||
|
||||
.modal-image {
|
||||
width: 100%;
|
||||
max-height: 600px;
|
||||
object-fit: contain;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.shop-content {
|
||||
max-width: 1040px;
|
||||
margin: 0 auto;
|
||||
padding: 100px 24px 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,292 @@
|
||||
<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 class="wishlist-items">
|
||||
<div v-for="item in wishlistItems" :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"
|
||||
/>
|
||||
<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>
|
||||
<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: '#fadb14' }"><StarFilled /></el-icon>
|
||||
<p>收藏列表为空</p>
|
||||
<el-button type="primary" @click="handleBrowseProducts">
|
||||
浏览作品
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { 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 { wishlistApi, type WishlistItem } from '@/api/wishlist'
|
||||
import { cartApi } from '@/api/cart'
|
||||
import { fileApi } from '@/api/file'
|
||||
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'
|
||||
|
||||
const router = useRouter()
|
||||
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
||||
|
||||
const wishlistItems = ref<WishlistItem[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const imageUrls = ref<Record<string, string[]>>({})
|
||||
const cartProductIdSet = ref(new Set<string>())
|
||||
const DEFAULT_PRODUCT_IMAGE = 'data:image/svg+xml;base64,PHN2ZyB3aW0dPSJodHRwOi8vd3d3Lm9yZy8yMDAwL3N2ZyI+Pjwvc3ZnPg=='
|
||||
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
const fetchWishlist = async () => {
|
||||
try {
|
||||
const [response, nextCartProductIdSet] = await Promise.all([
|
||||
wishlistApi.getWishlist(),
|
||||
fetchCartProductIdSet()
|
||||
])
|
||||
cartProductIdSet.value = nextCartProductIdSet
|
||||
wishlistItems.value = response as unknown as WishlistItem[]
|
||||
await loadImageUrls(response as unknown as WishlistItem[])
|
||||
} catch (error: any) {
|
||||
console.error('获取收藏列表失败:', error)
|
||||
ElMessage.error(error?.message || '获取收藏列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
const loadImageUrls = async (items: WishlistItem[]) => {
|
||||
for (const item of items) {
|
||||
if (item.product.imageFileIds) {
|
||||
const ids = item.product.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
if (id) {
|
||||
try {
|
||||
if (!imageIdCache.value[id]) {
|
||||
const response = await fileApi.getSignedUrl(id.trim()) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
if (imageIdCache.value[id]) {
|
||||
urls.push(imageIdCache.value[id] as string)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
urls.push(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]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getProductImages = (product: any): string[] => {
|
||||
return imageUrls.value[String(product.id)] || [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
|
||||
const isProductInCart = (productId: IdType) => hasCartProduct(cartProductIdSet.value, productId)
|
||||
|
||||
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 || '添加到购物车失败')
|
||||
}
|
||||
}
|
||||
|
||||
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 || '移除收藏失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleBrowseProducts = () => {
|
||||
router.push('/products')
|
||||
}
|
||||
|
||||
const handleProductClick = (productId: IdType) => {
|
||||
router.push(`/product/${productId}`)
|
||||
}
|
||||
|
||||
const getRandomColor = () => {
|
||||
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||
return colors[Math.floor(Math.random() * colors.length)]
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchWishlist()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 15px 20px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.empty {
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.wishlist-items {
|
||||
padding: 20px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.wishlist-item {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
padding: 15px;
|
||||
background: #f9f9f9;
|
||||
border-radius: 15px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.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);
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.item-price {
|
||||
color: var(--primary-color);
|
||||
font-weight: bold;
|
||||
margin: 0 0 10px 0;
|
||||
}
|
||||
|
||||
.item-actions {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.delete-icon {
|
||||
color: #ff4757;
|
||||
cursor: pointer;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.empty-wishlist {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 60px 20px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty-wishlist p {
|
||||
margin: 20px 0;
|
||||
font-size: 16px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,907 @@
|
||||
<template>
|
||||
<div class="admin-layout" :class="{ 'admin-layout--mobile': isMobile }">
|
||||
<template v-if="!isMobile">
|
||||
<a-layout>
|
||||
<a-layout-sider
|
||||
v-model:collapsed="collapsed"
|
||||
:trigger="null"
|
||||
collapsible
|
||||
class="sider"
|
||||
width="240"
|
||||
>
|
||||
<div class="logo">
|
||||
<h1 v-if="!collapsed">后台管理</h1>
|
||||
<h1 v-else>后台</h1>
|
||||
</div>
|
||||
<a-menu
|
||||
:selectedKeys="selectedKeys"
|
||||
mode="inline"
|
||||
theme="dark"
|
||||
@click="handleMenuClick"
|
||||
>
|
||||
<a-menu-item
|
||||
v-for="item in filteredMenuItems"
|
||||
:key="item.key"
|
||||
>
|
||||
<template #icon>
|
||||
<component :is="item.icon" />
|
||||
</template>
|
||||
<span>{{ item.label }}</span>
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</a-layout-sider>
|
||||
|
||||
<a-layout>
|
||||
<a-layout-header class="header">
|
||||
<div class="header-shell">
|
||||
<div class="header-left">
|
||||
<MenuUnfoldOutlined v-if="collapsed" class="trigger" @click="toggleCollapsed" />
|
||||
<MenuFoldOutlined v-else class="trigger" @click="toggleCollapsed" />
|
||||
|
||||
<div v-if="isBootstrapAdmin" class="shop-hint">
|
||||
<span>当前暂无可用门店,请先前往店铺管理创建</span>
|
||||
<a-button type="link" @click="router.push('/admin/shops')">去创建</a-button>
|
||||
</div>
|
||||
|
||||
<div v-else-if="shopOptions.length > 1" class="shop-switcher">
|
||||
<span class="shop-switcher-label">当前门店</span>
|
||||
<a-select
|
||||
v-model:value="selectedShopId"
|
||||
class="shop-select"
|
||||
:options="shopSelectOptions"
|
||||
:loading="shopSwitchLoading"
|
||||
@change="handleShopChange"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-else class="shop-pill">
|
||||
<ShopOutlined />
|
||||
<span>{{ currentShopName }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="header-right">
|
||||
<a-dropdown>
|
||||
<a class="user-dropdown" @click.prevent>
|
||||
<a-avatar :size="32" :src="userInfo?.avatar || DEFAULT_AVATAR" />
|
||||
<span class="username">{{ userInfo?.nickname || '管理员' }}</span>
|
||||
<DownOutlined />
|
||||
</a>
|
||||
<template #overlay>
|
||||
<a-menu>
|
||||
<a-menu-item key="home" @click="router.push('/admin')">
|
||||
<template #icon>
|
||||
<UserOutlined />
|
||||
</template>
|
||||
工作台
|
||||
</a-menu-item>
|
||||
<a-menu-item key="profile" @click="router.push('/admin/profile')">
|
||||
<template #icon>
|
||||
<IdcardOutlined />
|
||||
</template>
|
||||
我的
|
||||
</a-menu-item>
|
||||
<a-menu-divider />
|
||||
<a-menu-item key="logout" @click="handleLogout">
|
||||
<template #icon>
|
||||
<LogoutOutlined />
|
||||
</template>
|
||||
退出登录
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</template>
|
||||
</a-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</a-layout-header>
|
||||
|
||||
<a-layout-content class="content">
|
||||
<div class="content-shell">
|
||||
<router-view />
|
||||
</div>
|
||||
</a-layout-content>
|
||||
</a-layout>
|
||||
</a-layout>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="mobile-shell">
|
||||
<header class="mobile-topbar">
|
||||
<button class="mobile-icon-btn" type="button" @click="mobileDrawerOpen = true">
|
||||
<MenuOutlined />
|
||||
</button>
|
||||
<div class="mobile-title-block">
|
||||
<span class="mobile-eyebrow">{{ currentMobileSectionLabel }}</span>
|
||||
<strong class="mobile-title">{{ currentMobileTitle }}</strong>
|
||||
</div>
|
||||
<button class="mobile-avatar-btn" type="button" @click="router.push('/admin/profile')">
|
||||
<a-avatar :size="34" :src="userInfo?.avatar || DEFAULT_AVATAR" />
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<section class="mobile-context">
|
||||
<div class="mobile-context__primary">{{ currentShopName }}</div>
|
||||
<div class="mobile-context__secondary">{{ roleLabel }}</div>
|
||||
</section>
|
||||
|
||||
<main class="mobile-content">
|
||||
<router-view />
|
||||
</main>
|
||||
|
||||
<nav class="mobile-tabbar">
|
||||
<button
|
||||
v-for="tab in mobileTabs"
|
||||
:key="tab.key"
|
||||
class="mobile-tabbar__item"
|
||||
:class="{ 'is-active': activeMobileTab === tab.key }"
|
||||
type="button"
|
||||
@click="handleMobileTabClick(tab.path)"
|
||||
>
|
||||
<component :is="tab.icon" />
|
||||
<span>{{ tab.label }}</span>
|
||||
</button>
|
||||
</nav>
|
||||
|
||||
<a-drawer
|
||||
v-model:open="mobileDrawerOpen"
|
||||
placement="left"
|
||||
:width="320"
|
||||
class="mobile-drawer"
|
||||
:closable="false"
|
||||
root-class-name="admin-mobile-drawer"
|
||||
>
|
||||
<div class="drawer-account">
|
||||
<a-avatar :size="46" :src="userInfo?.avatar || DEFAULT_AVATAR" />
|
||||
<div class="drawer-account__body">
|
||||
<div class="drawer-account__title">{{ userInfo?.nickname || userInfo?.account || '后台账号' }}</div>
|
||||
<div class="drawer-account__meta">{{ roleLabel }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="drawer-shop-card">
|
||||
<span class="drawer-shop-card__label">当前门店</span>
|
||||
<strong class="drawer-shop-card__value">{{ currentShopName }}</strong>
|
||||
<p class="drawer-shop-card__desc">{{ shopScopeText }}</p>
|
||||
<a-button type="default" block @click="openProfileFromDrawer">
|
||||
{{ shopOptions.length > 1 ? '切换门店' : '查看账号信息' }}
|
||||
</a-button>
|
||||
</div>
|
||||
|
||||
<div class="drawer-section">
|
||||
<div class="drawer-section__title">二级模块</div>
|
||||
<button
|
||||
v-for="item in filteredMenuItems"
|
||||
:key="item.key"
|
||||
class="drawer-link"
|
||||
type="button"
|
||||
@click="openPathFromDrawer(item.key)"
|
||||
>
|
||||
<div class="drawer-link__icon">
|
||||
<component :is="item.icon" />
|
||||
</div>
|
||||
<div class="drawer-link__body">
|
||||
<div class="drawer-link__title">{{ item.label }}</div>
|
||||
</div>
|
||||
<RightOutlined class="drawer-link__arrow" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="drawer-section">
|
||||
<div class="drawer-section__title">会话操作</div>
|
||||
<a-space direction="vertical" style="width: 100%">
|
||||
<a-button block @click="openPathFromDrawer('/admin/profile')">打开我的</a-button>
|
||||
<a-button block danger @click="handleLogout">退出当前账号</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
</a-drawer>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
DashboardOutlined,
|
||||
DownOutlined,
|
||||
GiftOutlined,
|
||||
HomeOutlined,
|
||||
IdcardOutlined,
|
||||
LogoutOutlined,
|
||||
MenuFoldOutlined,
|
||||
MenuOutlined,
|
||||
MenuUnfoldOutlined,
|
||||
RightOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
ShopOutlined,
|
||||
ShoppingOutlined,
|
||||
TagOutlined,
|
||||
TeamOutlined,
|
||||
UserOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { adminAuthApi, type UserVO } from '@/api/admin'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import {
|
||||
getAdminCurrentShopName,
|
||||
getAdminRoleLabel,
|
||||
getAdminShopOptions,
|
||||
isBootstrapAdminUser
|
||||
} from './admin-helpers'
|
||||
|
||||
type AdminMenuItem = {
|
||||
key: string
|
||||
icon: any
|
||||
label: string
|
||||
permissionCode: string
|
||||
}
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const { isMobile } = useAdminViewport()
|
||||
|
||||
const collapsed = ref(false)
|
||||
const mobileDrawerOpen = ref(false)
|
||||
const userInfo = ref<UserVO | null>(null)
|
||||
const selectedKeys = ref<string[]>([route.path])
|
||||
const selectedShopId = ref<string>()
|
||||
const shopSwitchLoading = ref(false)
|
||||
const { loadUserPermissions, hasPermission, clearPermissions, userPermissions } = usePermission()
|
||||
|
||||
const menuItems: AdminMenuItem[] = [
|
||||
{ key: '/admin', icon: HomeOutlined, label: '首页', permissionCode: '' },
|
||||
{ key: '/admin/dashboard', icon: DashboardOutlined, label: '仪表盘', permissionCode: 'dashboard:view' },
|
||||
{ key: '/admin/users', icon: UserOutlined, label: '用户管理', permissionCode: 'user:view' },
|
||||
{ key: '/admin/products', icon: ShopOutlined, label: '作品管理', permissionCode: 'product:view' },
|
||||
{ key: '/admin/coupons', icon: GiftOutlined, label: '优惠券管理', permissionCode: 'coupon:view' },
|
||||
{ key: '/admin/shops', icon: HomeOutlined, label: '店铺管理', permissionCode: 'shop:view' },
|
||||
{ key: '/admin/permissions', icon: SafetyCertificateOutlined, label: '权限管理', permissionCode: 'permission:view' },
|
||||
{ key: '/admin/tags', icon: TagOutlined, label: '标签管理', permissionCode: 'tag:view' },
|
||||
{ key: '/admin/orders', icon: ShoppingOutlined, label: '订单管理', permissionCode: 'order:view' },
|
||||
{ key: '/admin/nail-artists', icon: TeamOutlined, label: '美甲师管理', permissionCode: 'nail_artist:view' }
|
||||
]
|
||||
|
||||
const mobileTabs = [
|
||||
{ key: 'workbench', label: '工作台', path: '/admin', icon: HomeOutlined },
|
||||
{ key: 'orders', label: '订单', path: '/admin/orders', icon: ShoppingOutlined },
|
||||
{ key: 'manage', label: '经营', path: '/admin/manage', icon: DashboardOutlined },
|
||||
{ key: 'profile', label: '我的', path: '/admin/profile', icon: UserOutlined }
|
||||
]
|
||||
|
||||
const isBootstrapAdmin = computed(() => isBootstrapAdminUser(userInfo.value))
|
||||
const shopOptions = computed(() => getAdminShopOptions(userInfo.value))
|
||||
const shopSelectOptions = computed(() => shopOptions.value.map(shop => ({ label: shop.name, value: shop.id })))
|
||||
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
|
||||
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
|
||||
const shopScopeText = computed(() => {
|
||||
if (!shopOptions.value.length) {
|
||||
return '游客模式'
|
||||
}
|
||||
return `可登录门店:${shopOptions.value.map(shop => shop.name).join(' / ')}`
|
||||
})
|
||||
|
||||
const filteredMenuItems = computed(() => {
|
||||
userPermissions.value
|
||||
let visibleItems = menuItems.filter(item => {
|
||||
if (!item.permissionCode) {
|
||||
return true
|
||||
}
|
||||
if (isBootstrapAdmin.value && item.key === '/admin/shops') {
|
||||
return true
|
||||
}
|
||||
return hasPermission(item.permissionCode)
|
||||
})
|
||||
if (isBootstrapAdmin.value) {
|
||||
visibleItems = visibleItems.filter(item => item.key === '/admin' || item.key === '/admin/shops')
|
||||
}
|
||||
return visibleItems
|
||||
})
|
||||
|
||||
const activeMobileTab = computed(() => {
|
||||
if (route.path === '/admin' || route.path === '/admin/dashboard') {
|
||||
return 'workbench'
|
||||
}
|
||||
if (route.path.startsWith('/admin/orders')) {
|
||||
return 'orders'
|
||||
}
|
||||
if (
|
||||
route.path === '/admin/manage' ||
|
||||
route.path.startsWith('/admin/users') ||
|
||||
route.path.startsWith('/admin/products') ||
|
||||
route.path.startsWith('/admin/coupons') ||
|
||||
route.path.startsWith('/admin/shops') ||
|
||||
route.path.startsWith('/admin/permissions') ||
|
||||
route.path.startsWith('/admin/tags') ||
|
||||
route.path.startsWith('/admin/nail-artists')
|
||||
) {
|
||||
return 'manage'
|
||||
}
|
||||
if (route.path.startsWith('/admin/profile')) {
|
||||
return 'profile'
|
||||
}
|
||||
return 'workbench'
|
||||
})
|
||||
|
||||
const currentMobileSectionLabel = computed(() => {
|
||||
switch (activeMobileTab.value) {
|
||||
case 'orders':
|
||||
return '订单'
|
||||
case 'manage':
|
||||
return '经营'
|
||||
case 'profile':
|
||||
return '我的'
|
||||
default:
|
||||
return '工作台'
|
||||
}
|
||||
})
|
||||
|
||||
const currentMobileTitle = computed(() => {
|
||||
const currentMenu = menuItems.find(item => item.key === route.path)
|
||||
if (currentMenu) {
|
||||
return currentMenu.label
|
||||
}
|
||||
if (route.path === '/admin/manage') {
|
||||
return '经营模块'
|
||||
}
|
||||
if (route.path === '/admin/profile') {
|
||||
return '账号与门店'
|
||||
}
|
||||
return '后台管理'
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
const toggleCollapsed = () => {
|
||||
collapsed.value = !collapsed.value
|
||||
}
|
||||
|
||||
const handleMenuClick = (info: any) => {
|
||||
router.push(info.key)
|
||||
}
|
||||
|
||||
const openPathFromDrawer = (path: string) => {
|
||||
mobileDrawerOpen.value = false
|
||||
router.push(path)
|
||||
}
|
||||
|
||||
const openProfileFromDrawer = () => {
|
||||
openPathFromDrawer('/admin/profile')
|
||||
}
|
||||
|
||||
const handleMobileTabClick = (path: string) => {
|
||||
if (route.path !== path) {
|
||||
router.push(path)
|
||||
}
|
||||
}
|
||||
|
||||
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('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
clearPermissions()
|
||||
message.success('已退出登录')
|
||||
window.location.href = '/admin/login'
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const cache = localStorage.getItem('adminUserInfo')
|
||||
if (cache) {
|
||||
userInfo.value = JSON.parse(cache)
|
||||
}
|
||||
if (!userInfo.value) {
|
||||
return
|
||||
}
|
||||
selectedShopId.value = userInfo.value.shopId ? String(userInfo.value.shopId) : undefined
|
||||
} catch (error) {
|
||||
console.error('获取后台用户信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
await fetchUserInfo()
|
||||
await loadUserPermissions()
|
||||
})
|
||||
message.success('门店上下文已切换')
|
||||
window.location.reload()
|
||||
} catch (error: any) {
|
||||
console.error('切换门店失败:', error)
|
||||
selectedShopId.value = userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined
|
||||
message.error(error?.message || '切换门店失败')
|
||||
} finally {
|
||||
shopSwitchLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.path,
|
||||
newPath => {
|
||||
selectedKeys.value = menuItems.some(item => item.key === newPath) ? [newPath] : []
|
||||
mobileDrawerOpen.value = false
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchUserInfo()
|
||||
if (isBootstrapAdmin.value) {
|
||||
clearPermissions()
|
||||
return
|
||||
}
|
||||
await loadUserPermissions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-layout {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.sider {
|
||||
background:
|
||||
linear-gradient(
|
||||
180deg,
|
||||
var(--admin-mobile-shell-start) 0%,
|
||||
var(--admin-mobile-shell-mid) 48%,
|
||||
var(--admin-mobile-shell-end) 100%
|
||||
);
|
||||
overflow: auto;
|
||||
height: 100vh;
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 64px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 248, 240, 0.14);
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
margin: 0;
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
padding: 0 24px;
|
||||
background: rgba(255, 249, 242, 0.96);
|
||||
box-shadow: 0 10px 24px rgba(145, 102, 82, 0.08);
|
||||
backdrop-filter: blur(14px);
|
||||
}
|
||||
|
||||
.header-shell {
|
||||
width: 100%;
|
||||
max-width: var(--admin-content-max-width);
|
||||
margin: 0 auto;
|
||||
min-height: 64px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.trigger {
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.shop-hint,
|
||||
.shop-switcher,
|
||||
.shop-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-height: 40px;
|
||||
padding: 0 14px;
|
||||
border-radius: 999px;
|
||||
background: var(--admin-mobile-surface-alt);
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.shop-hint {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.shop-switcher-label {
|
||||
font-size: 13px;
|
||||
color: var(--admin-mobile-muted);
|
||||
}
|
||||
|
||||
.shop-select {
|
||||
min-width: 220px;
|
||||
}
|
||||
|
||||
.shop-pill {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.user-dropdown {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 10px;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
|
||||
.user-dropdown:hover {
|
||||
background: rgba(204, 123, 95, 0.1);
|
||||
}
|
||||
|
||||
.username {
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.content {
|
||||
margin-left: 240px;
|
||||
min-height: calc(100vh - 64px);
|
||||
padding: 24px;
|
||||
background:
|
||||
linear-gradient(180deg, #fbf6f0 0%, #f4e8dc 100%);
|
||||
transition: margin-left 0.2s;
|
||||
}
|
||||
|
||||
.content-shell {
|
||||
width: 100%;
|
||||
max-width: var(--admin-content-max-width);
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.admin-layout :deep(.ant-layout-sider-collapsed) + .ant-layout .content {
|
||||
margin-left: 80px;
|
||||
}
|
||||
|
||||
.mobile-shell {
|
||||
min-height: 100vh;
|
||||
background:
|
||||
linear-gradient(180deg, var(--admin-mobile-shell-mid) 0 132px, var(--admin-mobile-surface) 132px 100%);
|
||||
}
|
||||
|
||||
.mobile-topbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 120;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
|
||||
background: var(--admin-mobile-shell-glass);
|
||||
backdrop-filter: blur(16px);
|
||||
}
|
||||
|
||||
.mobile-icon-btn,
|
||||
.mobile-avatar-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 14px;
|
||||
background: var(--admin-mobile-shell-soft);
|
||||
color: #fff8f1;
|
||||
}
|
||||
|
||||
.mobile-title-block {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.mobile-eyebrow {
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.14em;
|
||||
text-transform: uppercase;
|
||||
color: rgba(247, 242, 235, 0.68);
|
||||
}
|
||||
|
||||
.mobile-title {
|
||||
color: #f7f2eb;
|
||||
font-size: 18px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.mobile-context {
|
||||
padding: 0 16px 16px;
|
||||
color: #fff8f1;
|
||||
}
|
||||
|
||||
.mobile-context__primary {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.mobile-context__secondary {
|
||||
margin-top: 4px;
|
||||
color: rgba(255, 248, 241, 0.74);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.mobile-content {
|
||||
padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.mobile-tabbar {
|
||||
position: fixed;
|
||||
left: 12px;
|
||||
right: 12px;
|
||||
bottom: 12px;
|
||||
z-index: 130;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
padding: 10px;
|
||||
background: rgba(150, 103, 82, 0.92);
|
||||
border: 1px solid rgba(255, 248, 241, 0.16);
|
||||
border-radius: 24px;
|
||||
box-shadow: 0 16px 40px rgba(146, 103, 82, 0.24);
|
||||
backdrop-filter: blur(18px);
|
||||
}
|
||||
|
||||
.mobile-tabbar__item {
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
gap: 6px;
|
||||
padding: 10px 4px;
|
||||
border: 0;
|
||||
border-radius: 18px;
|
||||
background: transparent;
|
||||
color: rgba(255, 248, 241, 0.68);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.mobile-tabbar__item.is-active {
|
||||
background: rgba(255, 248, 241, 0.16);
|
||||
color: #fff7ef;
|
||||
}
|
||||
|
||||
.mobile-tabbar__item :deep(.anticon) {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.drawer-account {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
padding: 18px;
|
||||
border-radius: 24px;
|
||||
color: #fff8f1;
|
||||
background:
|
||||
radial-gradient(circle at top right, rgba(255, 244, 232, 0.2), transparent 42%),
|
||||
radial-gradient(circle at left top, rgba(232, 195, 169, 0.22), transparent 44%),
|
||||
linear-gradient(
|
||||
160deg,
|
||||
var(--admin-mobile-shell-start) 0%,
|
||||
var(--admin-mobile-shell-mid) 58%,
|
||||
var(--admin-mobile-shell-end) 100%
|
||||
);
|
||||
}
|
||||
|
||||
.drawer-account__body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.drawer-account__title {
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.drawer-account__meta {
|
||||
margin-top: 4px;
|
||||
font-size: 13px;
|
||||
color: rgba(255, 248, 241, 0.8);
|
||||
}
|
||||
|
||||
.drawer-shop-card {
|
||||
margin-top: 18px;
|
||||
padding: 18px;
|
||||
border-radius: 22px;
|
||||
background: var(--admin-mobile-card);
|
||||
border: 1px solid var(--admin-mobile-border);
|
||||
box-shadow: 0 12px 24px rgba(144, 103, 84, 0.08);
|
||||
}
|
||||
|
||||
.drawer-shop-card__label {
|
||||
font-size: 12px;
|
||||
color: var(--admin-mobile-muted);
|
||||
}
|
||||
|
||||
.drawer-shop-card__value {
|
||||
display: block;
|
||||
margin-top: 6px;
|
||||
color: var(--admin-mobile-ink);
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.drawer-shop-card__desc {
|
||||
margin: 8px 0 14px;
|
||||
color: var(--admin-mobile-muted);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.drawer-section {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.drawer-section__title {
|
||||
margin-bottom: 12px;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
color: #6f594e;
|
||||
}
|
||||
|
||||
.drawer-link {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 0;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--admin-mobile-border);
|
||||
background: transparent;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.drawer-link:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.drawer-link__icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
border-radius: 14px;
|
||||
background: var(--admin-mobile-accent-soft);
|
||||
color: #9e5a44;
|
||||
}
|
||||
|
||||
.drawer-link__body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.drawer-link__title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: var(--admin-mobile-ink);
|
||||
}
|
||||
|
||||
.drawer-link__meta {
|
||||
margin-top: 4px;
|
||||
color: var(--admin-mobile-muted);
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.drawer-link__arrow {
|
||||
color: #b39384;
|
||||
}
|
||||
|
||||
.mobile-drawer :deep(.ant-drawer-body) {
|
||||
padding: calc(18px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom));
|
||||
background: var(--admin-mobile-surface);
|
||||
}
|
||||
|
||||
.sider :deep(.ant-menu),
|
||||
.sider :deep(.ant-menu-dark) {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.sider :deep(.ant-menu-item) {
|
||||
width: calc(100% - 24px);
|
||||
margin: 6px 12px;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.sider :deep(.ant-menu-dark .ant-menu-item),
|
||||
.sider :deep(.ant-menu-dark .ant-menu-submenu-title) {
|
||||
color: rgba(255, 248, 241, 0.8);
|
||||
}
|
||||
|
||||
.sider :deep(.ant-menu-dark .ant-menu-item:hover),
|
||||
.sider :deep(.ant-menu-dark .ant-menu-submenu-title:hover) {
|
||||
color: #fff8f1;
|
||||
background: rgba(255, 248, 241, 0.12);
|
||||
}
|
||||
|
||||
.sider :deep(.ant-menu-dark .ant-menu-item-selected) {
|
||||
color: #fff8f1;
|
||||
background: rgba(255, 248, 241, 0.18);
|
||||
}
|
||||
|
||||
.admin-layout :deep(.ant-btn-primary) {
|
||||
border-color: transparent;
|
||||
background: linear-gradient(135deg, var(--admin-mobile-accent) 0%, var(--admin-mobile-accent-strong) 100%);
|
||||
box-shadow: 0 10px 20px rgba(185, 100, 73, 0.18);
|
||||
}
|
||||
|
||||
.admin-layout :deep(.ant-btn-primary:hover),
|
||||
.admin-layout :deep(.ant-btn-primary:focus) {
|
||||
border-color: transparent;
|
||||
background: linear-gradient(135deg, #d4866c 0%, #c26e52 100%);
|
||||
}
|
||||
|
||||
.admin-layout :deep(.ant-select:not(.ant-select-disabled):hover .ant-select-selector),
|
||||
.admin-layout :deep(.ant-input:hover),
|
||||
.admin-layout :deep(.ant-input-affix-wrapper:hover) {
|
||||
border-color: rgba(204, 123, 95, 0.45);
|
||||
}
|
||||
|
||||
.admin-layout :deep(.ant-select-focused .ant-select-selector),
|
||||
.admin-layout :deep(.ant-input:focus),
|
||||
.admin-layout :deep(.ant-input-affix-wrapper-focused) {
|
||||
border-color: rgba(204, 123, 95, 0.6);
|
||||
box-shadow: 0 0 0 2px rgba(204, 123, 95, 0.12);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,458 @@
|
||||
<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 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">
|
||||
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'
|
||||
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'
|
||||
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
const shopLoading = ref(false)
|
||||
const shops = ref<Array<{ id: IdType; shopName: string }>>([])
|
||||
const allowShoplessLogin = ref(false)
|
||||
const loginShopMessage = ref('')
|
||||
const { loadUserPermissions } = usePermission()
|
||||
|
||||
const formState = reactive({
|
||||
account: '',
|
||||
password: '',
|
||||
shopId: undefined as string | undefined
|
||||
})
|
||||
let loginShopTimer: number | undefined
|
||||
|
||||
const handleAccountInput = () => {
|
||||
const normalized = sanitizeAccountInput(formState.account)
|
||||
if (normalized !== formState.account) {
|
||||
formState.account = normalized
|
||||
}
|
||||
}
|
||||
|
||||
const getShopIdValue = (shop: { id: IdType; shopName: string }) => String(shop.id ?? '')
|
||||
const getShopLabel = (shop: { id: IdType; shopName: string }) => String(shop.shopName || `店铺 ${shop.id}`)
|
||||
|
||||
const shopOptions = computed(() =>
|
||||
shops.value.map(shop => ({
|
||||
label: getShopLabel(shop),
|
||||
value: getShopIdValue(shop)
|
||||
}))
|
||||
)
|
||||
const hasAvailableShops = computed(() => shopOptions.value.length > 0)
|
||||
const shouldRequireShop = computed(() => hasAvailableShops.value && !allowShoplessLogin.value)
|
||||
const shopPlaceholder = computed(() => {
|
||||
if (allowShoplessLogin.value) {
|
||||
return '当前无需选择店铺'
|
||||
}
|
||||
if (shopLoading.value) {
|
||||
return '正在加载可登录店铺'
|
||||
}
|
||||
if (hasAvailableShops.value) {
|
||||
return '请选择登录店铺'
|
||||
}
|
||||
return '请先输入账号'
|
||||
})
|
||||
|
||||
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
|
||||
|
||||
const filterShopOption = (input: string, option: { label?: string | number } | undefined) =>
|
||||
String(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
|
||||
|
||||
const isLoginShopPrefetchUnsupported = (error: unknown) => {
|
||||
const status = (error as any)?.response?.status
|
||||
return status === 404
|
||||
}
|
||||
|
||||
const resetLoginShopTimer = () => {
|
||||
if (loginShopTimer !== undefined) {
|
||||
window.clearTimeout(loginShopTimer)
|
||||
loginShopTimer = undefined
|
||||
}
|
||||
}
|
||||
|
||||
const restoreLoginShop = () => {
|
||||
const cached = localStorage.getItem('adminUserInfo')
|
||||
if (!cached) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(cached)
|
||||
if (parsed?.shopId) {
|
||||
formState.shopId = String(parsed.shopId)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('恢复后台登录店铺失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const applyLoginShopSelection = (selection?: LoginShopSelectionResponse | null) => {
|
||||
shops.value = selection?.shops || []
|
||||
allowShoplessLogin.value = Boolean(selection?.allowShoplessLogin)
|
||||
loginShopMessage.value = selection?.message || ''
|
||||
|
||||
if (allowShoplessLogin.value) {
|
||||
formState.shopId = undefined
|
||||
return
|
||||
}
|
||||
|
||||
if (!shops.value.length) {
|
||||
formState.shopId = undefined
|
||||
return
|
||||
}
|
||||
|
||||
const matchedShop = shops.value.find(shop => getShopIdValue(shop) === formState.shopId)
|
||||
if (matchedShop) {
|
||||
return
|
||||
}
|
||||
|
||||
if (shops.value.length === 1) {
|
||||
formState.shopId = getShopIdValue(shops.value[0]!)
|
||||
return
|
||||
}
|
||||
|
||||
formState.shopId = undefined
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
|
||||
message.success('登录成功')
|
||||
|
||||
await runWithGlobalLoading(() => loadUserPermissions())
|
||||
|
||||
router.push('/admin').catch(err => {
|
||||
console.error('跳转到首页失败:', err)
|
||||
window.location.href = '/admin'
|
||||
})
|
||||
} 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()
|
||||
})
|
||||
|
||||
const goToFrontend = () => {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = '/'
|
||||
}, 100)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-login {
|
||||
min-height: 100dvh;
|
||||
background:
|
||||
radial-gradient(circle at top right, rgba(255, 244, 232, 0.2), transparent 30%),
|
||||
radial-gradient(circle at left top, rgba(233, 193, 167, 0.18), transparent 38%),
|
||||
linear-gradient(
|
||||
160deg,
|
||||
var(--admin-mobile-shell-start) 0%,
|
||||
var(--admin-mobile-shell-mid) 56%,
|
||||
var(--admin-mobile-shell-end) 100%
|
||||
);
|
||||
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: #f7f2eb;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: clamp(28px, 4vw, 38px);
|
||||
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(--admin-mobile-border);
|
||||
box-shadow: 0 24px 50px rgba(146, 103, 82, 0.18);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.login-footer {
|
||||
text-align: center;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.login-footer a {
|
||||
color: #fff3ea;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.login-footer a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-card-body) {
|
||||
background: rgba(255, 250, 244, 0.98);
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-btn-primary) {
|
||||
border-color: transparent;
|
||||
background: linear-gradient(135deg, var(--admin-mobile-accent) 0%, var(--admin-mobile-accent-strong) 100%);
|
||||
box-shadow: 0 10px 22px rgba(185, 100, 73, 0.18);
|
||||
}
|
||||
|
||||
.login-card :deep(.ant-btn-primary:hover),
|
||||
.login-card :deep(.ant-btn-primary:focus) {
|
||||
border-color: transparent;
|
||||
background: linear-gradient(135deg, #d4866c 0%, #c26e52 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: rgba(204, 123, 95, 0.46);
|
||||
}
|
||||
|
||||
.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: rgba(204, 123, 95, 0.62);
|
||||
box-shadow: 0 0 0 2px rgba(204, 123, 95, 0.12);
|
||||
}
|
||||
|
||||
@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,821 @@
|
||||
<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"
|
||||
@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 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 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" style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="结束时间" name="endTime">
|
||||
<a-date-picker v-model:value="formState.endTime" show-time format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
|
||||
</a-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">
|
||||
{{ 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">
|
||||
{{ 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">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import dayjs, { type Dayjs } from 'dayjs'
|
||||
import {
|
||||
adminCouponApi,
|
||||
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()
|
||||
|
||||
const currentUserInfo = (() => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
return userInfoStr ? JSON.parse(userInfoStr) : null
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
return null
|
||||
}
|
||||
})()
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const loadingShops = ref(false)
|
||||
const modalVisible = ref(false)
|
||||
const viewModalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const searchText = ref('')
|
||||
const formRef = ref<FormInstance>()
|
||||
const distributeFormRef = ref<FormInstance>()
|
||||
const currentCoupon = ref<Coupon | null>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
const couponList = ref<Coupon[]>([])
|
||||
const tagList = ref<Tag[]>([])
|
||||
const userList = ref<UserVO[]>([])
|
||||
const shops = ref<Shop[]>([])
|
||||
|
||||
const distributeModalVisible = ref(false)
|
||||
const distributeLoading = ref(false)
|
||||
const currentDistributeCoupon = ref<Coupon | null>(null)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
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
|
||||
})
|
||||
|
||||
const distributeFormState = reactive({
|
||||
couponName: '',
|
||||
userIds: [] as number[],
|
||||
quantity: 1
|
||||
})
|
||||
|
||||
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
|
||||
|
||||
const distributeFormRules = {
|
||||
userIds: [{ required: true, message: '请选择要发放的用户', trigger: 'change' }],
|
||||
quantity: [{ required: true, message: '请输入发放数量', trigger: 'blur' }]
|
||||
} as any
|
||||
|
||||
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 }
|
||||
]
|
||||
|
||||
const isVipAutoForm = computed(() => formState.couponScene === 'VIP_AUTO' || formState.autoMatch === 1)
|
||||
|
||||
const getStatusColor = (status: number) => {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return 'green'
|
||||
case 2:
|
||||
return 'red'
|
||||
case 3:
|
||||
return 'orange'
|
||||
default:
|
||||
return 'default'
|
||||
}
|
||||
}
|
||||
|
||||
const getCouponSceneText = (scene?: string) => {
|
||||
if (scene === 'VIP_AUTO') {
|
||||
return 'VIP 自动券'
|
||||
}
|
||||
return '普通券'
|
||||
}
|
||||
|
||||
const isVipAutoCoupon = (coupon: any) => coupon?.couponScene === 'VIP_AUTO' || coupon?.autoMatch === 1
|
||||
|
||||
const getCouponValueText = (coupon: Coupon | null) => {
|
||||
if (!coupon) {
|
||||
return '-'
|
||||
}
|
||||
return coupon.couponType === 1
|
||||
? `${coupon.discountValue} 折`
|
||||
: `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
|
||||
}
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-coupons', isEdit.value ? 'edit' : 'create', currentCoupon.value?.id ?? 'new')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
couponCode: formState.couponCode,
|
||||
couponName: formState.couponName,
|
||||
couponType: formState.couponType,
|
||||
discountValue: formState.discountValue,
|
||||
minAmount: formState.minAmount,
|
||||
reduceAmount: formState.reduceAmount,
|
||||
totalCount: formState.totalCount,
|
||||
startTime: formState.startTime?.format('YYYY-MM-DD HH:mm:ss'),
|
||||
endTime: formState.endTime?.format('YYYY-MM-DD HH:mm:ss'),
|
||||
availableTagIds: [...formState.availableTagIds],
|
||||
unavailableTagIds: [...formState.unavailableTagIds],
|
||||
shopId: formState.shopId,
|
||||
couponScene: formState.couponScene,
|
||||
requiredVipLevel: formState.requiredVipLevel,
|
||||
autoMatch: formState.autoMatch
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
|
||||
Object.assign(formState, {
|
||||
...draft.payload,
|
||||
startTime: draft.payload.startTime ? dayjs(draft.payload.startTime) : undefined,
|
||||
endTime: draft.payload.endTime ? dayjs(draft.payload.endTime) : undefined
|
||||
})
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => formState.couponScene,
|
||||
value => {
|
||||
if (value === 'VIP_AUTO') {
|
||||
formState.autoMatch = 1
|
||||
if (!formState.requiredVipLevel) {
|
||||
formState.requiredVipLevel = '青铜'
|
||||
}
|
||||
} else {
|
||||
formState.autoMatch = 0
|
||||
formState.requiredVipLevel = undefined
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const handleAutoMatchChange = (checked: boolean) => {
|
||||
formState.autoMatch = checked ? 1 : 0
|
||||
formState.couponScene = checked ? 'VIP_AUTO' : 'GENERAL'
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
const fetchTags = async () => {
|
||||
try {
|
||||
const tags = await adminTagApi.listAllTags() as unknown as Tag[]
|
||||
tagList.value = tags || []
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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 = []
|
||||
}
|
||||
}
|
||||
|
||||
const handleSearch = async () => {
|
||||
pagination.current = 1
|
||||
await runWithGlobalLoading(() => fetchCoupons())
|
||||
}
|
||||
|
||||
const handleTableChange = (pag: any) => {
|
||||
pagination.current = pag.current || 1
|
||||
pagination.pageSize = pag.pageSize || pagination.pageSize
|
||||
}
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
currentCoupon.value = null
|
||||
resetFormState()
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
const showViewModal = (record: any) => {
|
||||
currentCoupon.value = record
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
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-DD HH:mm:ss'),
|
||||
endTime: formState.endTime?.format('YYYY-MM-DD HH:mm:ss'),
|
||||
availableTagIds: formState.availableTagIds,
|
||||
unavailableTagIds: formState.unavailableTagIds,
|
||||
shopId: formState.shopId,
|
||||
couponScene: formState.couponScene,
|
||||
requiredVipLevel: isVipAutoForm.value ? formState.requiredVipLevel : undefined,
|
||||
autoMatch: isVipAutoForm.value ? 1 : 0
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
resetFormState()
|
||||
}
|
||||
|
||||
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('删除失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const showDistributeModal = async (record: any) => {
|
||||
currentDistributeCoupon.value = record
|
||||
distributeFormState.couponName = record.couponName
|
||||
distributeFormState.userIds = []
|
||||
distributeFormState.quantity = 1
|
||||
await runWithGlobalLoading(() => fetchUsers())
|
||||
distributeModalVisible.value = true
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
const handleDistributeCancel = () => {
|
||||
distributeModalVisible.value = false
|
||||
distributeFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
await Promise.all([fetchTags(), fetchShops(), fetchCoupons()])
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.coupons {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,313 @@
|
||||
<template>
|
||||
<div class="dashboard">
|
||||
<a-page-header
|
||||
v-if="!isMobile"
|
||||
title="仪表盘"
|
||||
:sub-title="pageSubtitle"
|
||||
/>
|
||||
|
||||
<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">{{ pageSubtitle }}</p>
|
||||
</section>
|
||||
|
||||
<a-row :gutter="[16, 16]" class="stat-cards">
|
||||
<a-col :xs="24" :sm="12" :xl="6">
|
||||
<a-card>
|
||||
<a-statistic title="用户数" :value="stats.totalUsers" :loading="loading">
|
||||
<template #prefix>
|
||||
<UserOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
|
||||
<a-col :xs="24" :sm="12" :xl="6">
|
||||
<a-card>
|
||||
<a-statistic title="作品数" :value="stats.totalProducts" :loading="loading">
|
||||
<template #prefix>
|
||||
<ShopOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
|
||||
<a-col v-if="isAdmin" :xs="24" :sm="12" :xl="6">
|
||||
<a-card>
|
||||
<a-statistic title="门店数" :value="stats.totalShops" :loading="loading">
|
||||
<template #prefix>
|
||||
<HomeOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
|
||||
<a-col :xs="24" :sm="12" :xl="6">
|
||||
<a-card>
|
||||
<a-statistic title="今日订单" :value="stats.todayOrders" :loading="loading">
|
||||
<template #prefix>
|
||||
<ShoppingOutlined />
|
||||
</template>
|
||||
</a-statistic>
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<a-row :gutter="[16, 16]">
|
||||
<a-col :xs="24" :xl="14">
|
||||
<a-card title="经营提醒" class="insight-card">
|
||||
<a-spin :spinning="loading">
|
||||
<div class="insight-list">
|
||||
<div v-for="item in insightItems" :key="item.title" class="insight-item">
|
||||
<div class="insight-title">{{ item.title }}</div>
|
||||
<div class="insight-description">{{ item.description }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-spin>
|
||||
</a-card>
|
||||
</a-col>
|
||||
|
||||
<a-col :xs="24" :xl="10">
|
||||
<a-card title="热门作品" class="side-card">
|
||||
<a-spin :spinning="loading">
|
||||
<a-empty v-if="!stats.hotProducts.length" description="暂时还没有热门作品数据" />
|
||||
<div v-else class="hot-list">
|
||||
<div v-for="item in stats.hotProducts" :key="item.id" class="hot-item">
|
||||
<div>
|
||||
<div class="hot-name">{{ item.title }}</div>
|
||||
<div class="hot-meta">点赞 {{ item.likeCount || 0 }} · 收藏 {{ item.collectCount || 0 }}</div>
|
||||
</div>
|
||||
<div class="hot-price">¥{{ Number(item.price || 0).toFixed(2) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-spin>
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<a-card title="最近动态" class="activity-card">
|
||||
<a-spin :spinning="loading">
|
||||
<a-empty v-if="!stats.recentActivities.length" description="暂时没有最近动态" />
|
||||
<a-timeline v-else>
|
||||
<a-timeline-item
|
||||
v-for="activity in stats.recentActivities"
|
||||
:key="activity.id"
|
||||
:color="activity.color || 'blue'"
|
||||
>
|
||||
<p class="activity-title">{{ activity.title || '系统动态' }}</p>
|
||||
<p class="activity-description">{{ activity.description }}</p>
|
||||
<p class="activity-time">{{ formatTime(activity.time) }}</p>
|
||||
</a-timeline-item>
|
||||
</a-timeline>
|
||||
</a-spin>
|
||||
</a-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { HomeOutlined, ShopOutlined, ShoppingOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
import { adminDashboardApi, type DashboardStats } from '@/api/admin'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
|
||||
const { isMobile } = useAdminViewport()
|
||||
const loading = ref(false)
|
||||
const stats = reactive<DashboardStats>({
|
||||
totalUsers: 0,
|
||||
totalProducts: 0,
|
||||
totalShops: 0,
|
||||
todayOrders: 0,
|
||||
hotProducts: [],
|
||||
recentActivities: []
|
||||
})
|
||||
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const cache = localStorage.getItem('adminUserInfo')
|
||||
return cache ? JSON.parse(cache) : null
|
||||
} catch (error) {
|
||||
console.error('读取后台用户信息失败:', error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const currentUser = computed(() => getCurrentUserInfo())
|
||||
const isAdmin = computed(() => currentUser.value?.type === 4)
|
||||
const pageSubtitle = computed(() => {
|
||||
if (isAdmin.value) {
|
||||
return stats.totalShops > 0 ? '查看整体经营情况与各门店动态' : '当前还没有门店,先去店铺管理创建第一家门店'
|
||||
}
|
||||
return currentUser.value?.shopName ? `当前门店:${currentUser.value.shopName}` : '当前还没有选中门店'
|
||||
})
|
||||
|
||||
const insightItems = computed(() => {
|
||||
const items = []
|
||||
if (isAdmin.value && stats.totalShops === 0) {
|
||||
items.push({
|
||||
title: '先创建门店',
|
||||
description: '系统目前还没有门店,建议先在店铺管理里创建第一家门店,再继续配置作品、优惠券和员工。'
|
||||
})
|
||||
}
|
||||
if (stats.totalProducts === 0) {
|
||||
items.push({
|
||||
title: '还没有可售作品',
|
||||
description: '可以先补充几款基础作品,首页和前台作品页会更完整,也更方便测试完整下单流程。'
|
||||
})
|
||||
} else {
|
||||
items.push({
|
||||
title: '作品库已准备好',
|
||||
description: `当前共有 ${stats.totalProducts} 个作品,建议继续关注热门作品的收藏和点赞表现。`
|
||||
})
|
||||
}
|
||||
if (stats.todayOrders === 0) {
|
||||
items.push({
|
||||
title: '今日订单较安静',
|
||||
description: '可以检查首页推荐、优惠券配置或门店营业时间是否完整,减少用户下单前的犹豫。'
|
||||
})
|
||||
} else {
|
||||
items.push({
|
||||
title: '今日已有订单流入',
|
||||
description: `今天已产生 ${stats.todayOrders} 笔订单,建议优先关注订单状态推进和美甲师排期。`
|
||||
})
|
||||
}
|
||||
if (stats.totalUsers > 0) {
|
||||
items.push({
|
||||
title: '用户池正在积累',
|
||||
description: `当前共有 ${stats.totalUsers} 个用户,可继续结合收藏、优惠券和 VIP 规则提升复购。`
|
||||
})
|
||||
}
|
||||
return items
|
||||
})
|
||||
|
||||
const formatTime = (timeStr: string) => {
|
||||
if (!timeStr) return ''
|
||||
const time = new Date(timeStr)
|
||||
const now = new Date()
|
||||
const diff = now.getTime() - time.getTime()
|
||||
|
||||
const minutes = Math.floor(diff / 60000)
|
||||
const hours = Math.floor(diff / 3600000)
|
||||
const days = Math.floor(diff / 86400000)
|
||||
|
||||
if (minutes < 1) return '刚刚'
|
||||
if (minutes < 60) return `${minutes} 分钟前`
|
||||
if (hours < 24) return `${hours} 小时前`
|
||||
if (days < 7) return `${days} 天前`
|
||||
return time.toLocaleDateString('zh-CN')
|
||||
}
|
||||
|
||||
const fetchStats = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await adminDashboardApi.getStats()
|
||||
Object.assign(stats, data)
|
||||
} catch (error) {
|
||||
console.error('获取统计数据失败:', error)
|
||||
message.error('获取统计数据失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void fetchStats()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dashboard {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.stat-cards {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.insight-card,
|
||||
.side-card,
|
||||
.activity-card {
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.insight-list {
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.insight-item {
|
||||
padding: 16px 18px;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(135deg, #fff8f1 0%, #f8ede1 100%);
|
||||
border: 1px solid #edd9ca;
|
||||
}
|
||||
|
||||
.insight-title {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.insight-description {
|
||||
margin-top: 6px;
|
||||
line-height: 1.7;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.hot-list {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.hot-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 14px 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.hot-item:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.hot-name {
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.hot-meta,
|
||||
.activity-description,
|
||||
.activity-time {
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.hot-meta,
|
||||
.activity-time {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.hot-price {
|
||||
white-space: nowrap;
|
||||
font-weight: 700;
|
||||
color: #c4684b;
|
||||
}
|
||||
|
||||
.activity-card {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.activity-title {
|
||||
margin: 0 0 4px;
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.activity-description,
|
||||
.activity-time {
|
||||
margin: 0;
|
||||
line-height: 1.7;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,451 @@
|
||||
<template>
|
||||
<div class="home">
|
||||
<template v-if="!isMobile">
|
||||
<a-page-header title="欢迎使用后台管理系统" :sub-title="welcomeMessage" />
|
||||
|
||||
<a-alert
|
||||
v-if="isBootstrapAdmin"
|
||||
class="bootstrap-alert"
|
||||
type="warning"
|
||||
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-grid :columns="3" :colGap="16" :rowGap="16">
|
||||
<a-grid-item v-for="item in quickActions" :key="item.key">
|
||||
<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-grid-item>
|
||||
</a-grid>
|
||||
</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">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { DashboardOutlined, HomeOutlined, SafetyCertificateOutlined, ShopOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
import { userApi, type UserVO } from '@/api/admin'
|
||||
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'
|
||||
|
||||
const router = useRouter()
|
||||
const { isMobile } = useAdminViewport()
|
||||
const currentTime = ref('')
|
||||
const userInfo = ref<UserVO | null>(null)
|
||||
const userPermissions = ref<PermissionVO[]>([])
|
||||
let timer: number | null = null
|
||||
|
||||
const welcomeMessage = computed(() => {
|
||||
const hour = new Date().getHours()
|
||||
if (hour < 12) {
|
||||
return '早上好!'
|
||||
} else if (hour < 18) {
|
||||
return '下午好!'
|
||||
} else {
|
||||
return '晚上好!'
|
||||
}
|
||||
})
|
||||
|
||||
const isBootstrapAdmin = computed(() => isBootstrapAdminUser(userInfo.value))
|
||||
|
||||
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
|
||||
})
|
||||
|
||||
const quickActions = computed(() => {
|
||||
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: 'shops',
|
||||
title: '店铺管理',
|
||||
path: '/admin/shops',
|
||||
icon: HomeOutlined,
|
||||
permissionCode: 'shop:view'
|
||||
},
|
||||
{
|
||||
key: 'permissions',
|
||||
title: '权限管理',
|
||||
path: '/admin/permissions',
|
||||
icon: SafetyCertificateOutlined,
|
||||
permissionCode: 'permission:view'
|
||||
}
|
||||
]
|
||||
|
||||
const grantedPermissions = new Set(userPermissions.value.map(permission => permission.permissionCode))
|
||||
return actions.filter(item => grantedPermissions.has(item.permissionCode))
|
||||
})
|
||||
|
||||
const getUserTypeText = (type: number | undefined) => {
|
||||
switch (type) {
|
||||
case 4:
|
||||
return '平台管理员'
|
||||
case 2:
|
||||
return '店长'
|
||||
case 3:
|
||||
return '美甲师'
|
||||
default:
|
||||
return '后台账号'
|
||||
}
|
||||
}
|
||||
|
||||
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'
|
||||
})
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchUserPermissions = async () => {
|
||||
try {
|
||||
const res = await permissionApi.getUserPermissions()
|
||||
userPermissions.value = res as unknown as PermissionVO[]
|
||||
} catch (error) {
|
||||
console.error('获取用户权限失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const navigateTo = (path: string, permissionCode?: string) => {
|
||||
if (permissionCode) {
|
||||
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: #666;
|
||||
}
|
||||
|
||||
.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: #a45d44;
|
||||
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: #999;
|
||||
}
|
||||
|
||||
.quick-actions {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 80px;
|
||||
font-size: 32px;
|
||||
color: #b96449;
|
||||
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: #9e5a44;
|
||||
}
|
||||
|
||||
.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: #67727a;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,273 @@
|
||||
<template>
|
||||
<div class="admin-manage">
|
||||
<section class="admin-page-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.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">
|
||||
import { computed, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
DashboardOutlined,
|
||||
GiftOutlined,
|
||||
HomeOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
ShopOutlined,
|
||||
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'
|
||||
|
||||
const router = useRouter()
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
const userInfo = computed(() => loadCachedAdminUserInfo())
|
||||
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
|
||||
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
|
||||
const isBootstrapAdmin = computed(() => isBootstrapAdminUser(userInfo.value))
|
||||
|
||||
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
|
||||
},
|
||||
{
|
||||
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'
|
||||
}
|
||||
]
|
||||
|
||||
return definitions
|
||||
.filter(module => !module.permissionCode || hasPermission(module.permissionCode))
|
||||
.map(module => {
|
||||
if (module.requireShopContext && isBootstrapAdmin.value) {
|
||||
return {
|
||||
...module,
|
||||
allowed: false,
|
||||
disabledReason: '当前没有门店上下文,先进入店铺管理完成初始化或切换门店。'
|
||||
}
|
||||
}
|
||||
return {
|
||||
...module,
|
||||
allowed: true,
|
||||
disabledReason: ''
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
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: #9e5a44;
|
||||
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: rgba(215, 108, 84, 0.12);
|
||||
color: #9a412d;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.module-card__subtitle {
|
||||
margin-top: 8px;
|
||||
line-height: 1.6;
|
||||
color: #66727a;
|
||||
}
|
||||
|
||||
.module-card__hint {
|
||||
margin-top: 10px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 14px;
|
||||
background: rgba(204, 123, 95, 0.08);
|
||||
color: #725d51;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.module-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,550 @@
|
||||
<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"
|
||||
>
|
||||
<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 === '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="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.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">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { adminNailArtistApi, type NailArtistInfoVO } from '@/api/admin'
|
||||
import { adminTagApi, type Tag } from '@/api/admin'
|
||||
import { adminProductApi, type Product } from '@/api/admin'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
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()
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const tagLoading = ref(false)
|
||||
const productLoading = ref(false)
|
||||
const searchText = ref('')
|
||||
const nailArtistList = ref<NailArtistInfoVO[]>([])
|
||||
const tagList = ref<Tag[]>([])
|
||||
const productList = ref<Product[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const viewModalVisible = ref(false)
|
||||
const isAdmin = ref(false)
|
||||
const isShopOwner = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentNailArtist = ref<NailArtistInfoVO | null>(null)
|
||||
const currentUserInfo = getCurrentUserInfo()
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
const viewFormState = reactive({
|
||||
nickname: '',
|
||||
shopName: '',
|
||||
identity: '',
|
||||
experience: '',
|
||||
skillsText: '',
|
||||
statusText: '',
|
||||
rating: '',
|
||||
portfolioText: ''
|
||||
})
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const formState = reactive({
|
||||
userId: 0,
|
||||
identity: '',
|
||||
experience: 0,
|
||||
skills: [] as string[],
|
||||
rating: 0,
|
||||
status: 1,
|
||||
portfolio: [] as string[],
|
||||
nickname: ''
|
||||
})
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-nail-artists', 'edit', currentNailArtist.value?.userId ?? formState.userId ?? 'unknown')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
identity: formState.identity,
|
||||
experience: formState.experience,
|
||||
skills: [...formState.skills],
|
||||
status: formState.status,
|
||||
portfolio: [...formState.portfolio]
|
||||
})
|
||||
|
||||
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,
|
||||
portfolio: Array.isArray(draft.payload.portfolio) ? draft.payload.portfolio : formState.portfolio
|
||||
})
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const formRules = {
|
||||
identity: [{ required: true, message: '请输入身份', trigger: 'blur' }],
|
||||
experience: [{ required: true, message: '请输入从业年限', trigger: 'blur' }],
|
||||
skills: [{ required: true, message: '请选择技能标签', trigger: 'change' }],
|
||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
||||
portfolio: [{ required: true, message: '请选择作品作品', trigger: 'change' }]
|
||||
} as any
|
||||
|
||||
const columns = [
|
||||
{ title: '美甲师姓名', dataIndex: 'nickname', key: 'nickname' },
|
||||
{ title: '所属店铺', dataIndex: 'shopName', key: 'shopName' },
|
||||
{ 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 }
|
||||
]
|
||||
|
||||
const getStatusText = (status: number) => {
|
||||
return status === 1 ? '营业中' : '休息中'
|
||||
}
|
||||
|
||||
const getStatusColor = (status: number) => {
|
||||
return status === 1 ? 'green' : 'default'
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
const handleSearch = async () => {
|
||||
pagination.current = 1
|
||||
await runWithGlobalLoading(() => fetchNailArtistList())
|
||||
}
|
||||
|
||||
const handleTableChange = async (pag: any) => {
|
||||
pagination.current = pag.current
|
||||
pagination.pageSize = pag.pageSize
|
||||
await runWithGlobalLoading(() => fetchNailArtistList())
|
||||
}
|
||||
|
||||
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,
|
||||
portfolio: record.portfolio ? record.portfolio.split(',').filter(Boolean) : [],
|
||||
...lockedFields
|
||||
})
|
||||
restoreDraft()
|
||||
Object.assign(formState, lockedFields)
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
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),
|
||||
rating: (nailArtist.rating || 0).toString(),
|
||||
portfolioText: portfolioText
|
||||
})
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
}
|
||||
|
||||
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,
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
@@ -0,0 +1,326 @@
|
||||
<template>
|
||||
<div class="orders">
|
||||
<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">订单 {{ filteredOrders.length }}</span>
|
||||
<span class="admin-page-chip">{{ canProcessOrders ? '可处理订单' : '查看模式' }}</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"
|
||||
class="admin-toolbar__grow"
|
||||
placeholder="搜索订单号、用户 ID 或优惠券"
|
||||
@search="noop"
|
||||
/>
|
||||
<a-select
|
||||
v-model:value="statusFilter"
|
||||
:options="statusOptions"
|
||||
:style="isMobile ? { width: '100%' } : { width: '160px' }"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-table v-if="!isMobile" :columns="columns" :data-source="filteredOrders" :loading="loading" row-key="id">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'status'">
|
||||
<a-tag :color="statusColor(record.status)">{{ record.statusText }}</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'totalAmount'">
|
||||
¥{{ record.totalAmount.toFixed(2) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actualAmount'">
|
||||
¥{{ record.actualAmount.toFixed(2) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="currentOrder = record">查看</a-button>
|
||||
<a-button
|
||||
v-if="record.status === 1 && canProcessOrders"
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="process(record.id, 2)"
|
||||
>
|
||||
确认完成
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="record.status === 1 && canProcessOrders && !isArtist"
|
||||
danger
|
||||
size="small"
|
||||
@click="process(record.id, 3)"
|
||||
>
|
||||
取消订单
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="filteredOrders" 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.orderNo }}</div>
|
||||
<div class="admin-mobile-card__subtitle">
|
||||
用户 {{ item.userId }} · {{ item.createTime }}
|
||||
</div>
|
||||
</div>
|
||||
<a-tag :color="statusColor(item.status)">{{ item.statusText }}</a-tag>
|
||||
</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>总金额</span>
|
||||
<strong>¥{{ item.totalAmount.toFixed(2) }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>实付金额</span>
|
||||
<strong>¥{{ item.actualAmount.toFixed(2) }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>优惠券</span>
|
||||
<strong>{{ item.couponName || '无' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>预约项目</span>
|
||||
<strong>{{ item.items?.length || 0 }} 个</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button size="small" @click="currentOrder = item">查看详情</a-button>
|
||||
<a-button
|
||||
v-if="item.status === 1 && canProcessOrders"
|
||||
size="small"
|
||||
type="primary"
|
||||
@click="process(item.id, 2)"
|
||||
>
|
||||
完成
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="item.status === 1 && canProcessOrders && !isArtist"
|
||||
size="small"
|
||||
danger
|
||||
@click="process(item.id, 3)"
|
||||
>
|
||||
取消
|
||||
</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<AdminResponsiveModal
|
||||
v-model:open="detailVisible"
|
||||
title="订单详情"
|
||||
:desktop-width="860"
|
||||
@cancel="currentOrder = null"
|
||||
>
|
||||
<template v-if="currentOrder">
|
||||
<a-descriptions :column="isMobile ? 1 : 2" bordered size="small">
|
||||
<a-descriptions-item label="订单编号">{{ currentOrder.orderNo }}</a-descriptions-item>
|
||||
<a-descriptions-item label="用户ID">{{ currentOrder.userId }}</a-descriptions-item>
|
||||
<a-descriptions-item label="订单总额">¥{{ currentOrder.totalAmount.toFixed(2) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="实付金额">¥{{ currentOrder.actualAmount.toFixed(2) }}</a-descriptions-item>
|
||||
<a-descriptions-item label="优惠券">{{ currentOrder.couponName || '无' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="订单状态">{{ currentOrder.statusText }}</a-descriptions-item>
|
||||
<a-descriptions-item label="创建时间" :span="isMobile ? 1 : 2">{{ currentOrder.createTime }}</a-descriptions-item>
|
||||
</a-descriptions>
|
||||
|
||||
<a-divider>订单项目</a-divider>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="itemColumns"
|
||||
:data-source="currentOrder.items"
|
||||
row-key="id"
|
||||
:pagination="false"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'price'">¥{{ record.price.toFixed(2) }}</template>
|
||||
<template v-else-if="column.key === 'totalPrice'">¥{{ (record.price * record.quantity).toFixed(2) }}</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<div v-else class="detail-items">
|
||||
<article v-for="item in currentOrder.items" :key="item.id" class="admin-mobile-card">
|
||||
<div class="admin-mobile-card__title">{{ item.productTitle }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.artistName || '未指定美甲师' }}</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>预约时间</span>
|
||||
<strong>{{ item.appointmentTime || '--' }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>单价</span>
|
||||
<strong>¥{{ item.price.toFixed(2) }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>数量</span>
|
||||
<strong>{{ item.quantity }}</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>小计</span>
|
||||
<strong>¥{{ (item.price * item.quantity).toFixed(2) }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</template>
|
||||
</AdminResponsiveModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { orderApi } from '../../api/order'
|
||||
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 AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { isMobile } = useAdminViewport()
|
||||
const orders = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const currentOrder = ref<any | null>(null)
|
||||
const currentUserType = ref<number | null>(null)
|
||||
const keyword = ref('')
|
||||
const statusFilter = ref<'all' | string>('all')
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
const detailVisible = computed({
|
||||
get: () => !!currentOrder.value,
|
||||
set: value => { if (!value) currentOrder.value = null }
|
||||
})
|
||||
const canProcessOrders = computed(() => hasPermission('order:process'))
|
||||
const isArtist = computed(() => currentUserType.value === 3)
|
||||
const statusOptions = [
|
||||
{ label: '全部状态', value: 'all' },
|
||||
{ label: '待处理', value: '1' },
|
||||
{ label: '已完成', value: '2' },
|
||||
{ label: '已取消', value: '3' }
|
||||
]
|
||||
|
||||
const filteredOrders = computed(() => {
|
||||
const keywordValue = keyword.value.trim().toLowerCase()
|
||||
return orders.value.filter(order => {
|
||||
const matchStatus = statusFilter.value === 'all' || String(order.status) === String(statusFilter.value)
|
||||
if (!matchStatus) {
|
||||
return false
|
||||
}
|
||||
if (!keywordValue) {
|
||||
return true
|
||||
}
|
||||
const haystack = [
|
||||
order.orderNo,
|
||||
order.userId,
|
||||
order.couponName,
|
||||
...(order.items || []).map((item: any) => `${item.productTitle || ''} ${item.artistName || ''}`)
|
||||
].join(' ').toLowerCase()
|
||||
return haystack.includes(keywordValue)
|
||||
})
|
||||
})
|
||||
|
||||
const columns = [
|
||||
{ title: '订单编号', dataIndex: 'orderNo', key: 'orderNo' },
|
||||
{ title: '用户ID', dataIndex: 'userId', key: 'userId', width: 100 },
|
||||
{ title: '订单总额', key: 'totalAmount', width: 120 },
|
||||
{ title: '实付金额', key: 'actualAmount', width: 120 },
|
||||
{ title: '优惠券', dataIndex: 'couponName', key: 'couponName', width: 140 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime', width: 180 },
|
||||
{ title: '操作', key: 'actions', width: 180 }
|
||||
]
|
||||
|
||||
const itemColumns = [
|
||||
{ title: '商品ID', dataIndex: 'productId', key: 'productId', width: 100 },
|
||||
{ title: '商品名称', dataIndex: 'productTitle', key: 'productTitle' },
|
||||
{ title: '美甲师', dataIndex: 'artistName', key: 'artistName', width: 120 },
|
||||
{ title: '预约时间', dataIndex: 'appointmentTime', key: 'appointmentTime', width: 180 },
|
||||
{ title: '单价', key: 'price', width: 100 },
|
||||
{ title: '数量', dataIndex: 'quantity', key: 'quantity', width: 80 },
|
||||
{ title: '总价', key: 'totalPrice', width: 100 }
|
||||
]
|
||||
|
||||
const statusColor = (status: number) => {
|
||||
if (status === 1) return 'orange'
|
||||
if (status === 2) return 'green'
|
||||
if (status === 3) return 'red'
|
||||
return 'default'
|
||||
}
|
||||
|
||||
const resolveCurrentUserType = () => {
|
||||
const cached = localStorage.getItem('adminUserInfo') || sessionStorage.getItem('adminUserInfo')
|
||||
if (!cached) {
|
||||
currentUserType.value = null
|
||||
return
|
||||
}
|
||||
try {
|
||||
currentUserType.value = JSON.parse(cached)?.type ?? null
|
||||
} catch {
|
||||
currentUserType.value = null
|
||||
}
|
||||
}
|
||||
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
orders.value = await orderApi.getAllOrders() as unknown as any[]
|
||||
} catch {
|
||||
message.error('获取订单列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const process = async (orderId: IdType, status: number) => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await orderApi.processOrder(orderId, status)
|
||||
await loadOrders()
|
||||
})
|
||||
message.success('操作成功')
|
||||
if (sameId(currentOrder.value?.id, orderId)) {
|
||||
currentOrder.value = orders.value.find(order => sameId(order.id, orderId)) || null
|
||||
}
|
||||
} catch {
|
||||
message.error('操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
const noop = () => {}
|
||||
|
||||
onMounted(async () => {
|
||||
resolveCurrentUserType()
|
||||
await loadUserPermissions()
|
||||
await loadOrders()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.orders {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.detail-items {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,734 @@
|
||||
<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: 1080 }"
|
||||
@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: #999; 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: #999; 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">
|
||||
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'
|
||||
import { userApi, type UserVO } from '@/api/admin'
|
||||
import { permissionApi, type PermissionVO } from '@/api/permission'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
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()
|
||||
|
||||
const activeTab = ref('permissions')
|
||||
const loading = ref(false)
|
||||
const permissionList = ref<PermissionVO[]>([])
|
||||
const permissionModalVisible = ref(false)
|
||||
const permissionModalLoading = ref(false)
|
||||
const isEditPermission = ref(false)
|
||||
const permissionFormRef = ref<FormInstance>()
|
||||
const currentPermission = ref<PermissionVO | null>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
const permissionPagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 20,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const permissionFormState = reactive({
|
||||
permissionCode: '',
|
||||
permissionName: '',
|
||||
permissionGroup: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-permissions', isEditPermission.value ? 'edit' : 'create', currentPermission.value?.id ?? 'new')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
permissionCode: permissionFormState.permissionCode,
|
||||
permissionName: permissionFormState.permissionName,
|
||||
permissionGroup: permissionFormState.permissionGroup,
|
||||
description: permissionFormState.description
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(permissionFormState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const permissionFormRules: Record<string, Rule[]> = {
|
||||
permissionCode: [{ required: true, message: '请输入权限编码', trigger: 'blur' }],
|
||||
permissionName: [{ required: true, message: '请输入权限名称', trigger: 'blur' }],
|
||||
permissionGroup: [{ required: true, message: '请选择权限分组', trigger: 'change' }],
|
||||
description: [{ required: true, message: '请输入权限描述', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
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 }
|
||||
]
|
||||
|
||||
const userLoading = ref(false)
|
||||
const userSearchText = ref('')
|
||||
const userList = ref<UserVO[]>([])
|
||||
const selectedUser = ref<UserVO | null>(null)
|
||||
const assignLoading = ref(false)
|
||||
const selectedPermissions = ref<IdType[]>([])
|
||||
const assignablePermissionIds = ref<IdType[]>([])
|
||||
const activeCollapseKeys = ref<string[]>(['作品管理', '店铺管理', '用户管理', '权限管理'])
|
||||
const currentLoginUser = ref<UserVO | null>(null)
|
||||
const mobilePermissionStep = ref<'users' | 'assign'>('users')
|
||||
|
||||
// 权限 ID 同样可能以字符串形式返回,所以这里统一转成字符串集合做包含判断。
|
||||
const assignablePermissionIdSet = computed(() => new Set(assignablePermissionIds.value.map(id => String(id))))
|
||||
const disabledPermissionCount = computed(() =>
|
||||
permissionList.value.filter(permission => !assignablePermissionIdSet.value.has(String(permission.id))).length
|
||||
)
|
||||
|
||||
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
|
||||
})
|
||||
|
||||
const getUserTypeText = (type: number) => {
|
||||
const map: Record<number, string> = {
|
||||
0: '用户',
|
||||
2: '店长',
|
||||
3: '美甲师',
|
||||
4: '管理员'
|
||||
}
|
||||
return map[type] || '未知'
|
||||
}
|
||||
|
||||
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 []
|
||||
})
|
||||
|
||||
const isPermissionDisabled = (permission: PermissionVO) => {
|
||||
if (!selectedUser.value) {
|
||||
return true
|
||||
}
|
||||
return !assignablePermissionIdSet.value.has(String(permission.id))
|
||||
}
|
||||
|
||||
const resolveRequestErrorMessage = (error: any, fallback: string) => {
|
||||
return error?.response?.data?.message || error?.message || fallback
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
const handlePermissionTableChange = async (pag: any) => {
|
||||
permissionPagination.current = pag.current
|
||||
permissionPagination.pageSize = pag.pageSize
|
||||
await runWithGlobalLoading(() => fetchPermissionList())
|
||||
}
|
||||
|
||||
const handleUserSearch = async () => {
|
||||
await runWithGlobalLoading(() => fetchUserList())
|
||||
}
|
||||
|
||||
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)))
|
||||
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'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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, '权限保存失败'))
|
||||
}
|
||||
}
|
||||
|
||||
const showAddPermissionModal = () => {
|
||||
isEditPermission.value = false
|
||||
currentPermission.value = null
|
||||
Object.assign(permissionFormState, {
|
||||
permissionCode: '',
|
||||
permissionName: '',
|
||||
permissionGroup: '',
|
||||
description: ''
|
||||
})
|
||||
restoreDraft()
|
||||
permissionModalVisible.value = true
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
const handlePermissionModalCancel = () => {
|
||||
permissionModalVisible.value = false
|
||||
permissionFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
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: rgba(204, 123, 95, 0.12) !important;
|
||||
border-left: 3px solid #cc7b5f;
|
||||
}
|
||||
|
||||
.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>
|
||||
@@ -1,26 +1,38 @@
|
||||
<template>
|
||||
<div class="products">
|
||||
<a-page-header title="作品管理" sub-title="管理美甲作品" />
|
||||
<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">作品 {{ productList.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">
|
||||
作品列表
|
||||
</template>
|
||||
<template #extra>
|
||||
<a-space>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索作品名称"
|
||||
style="width: 250px"
|
||||
:style="isMobile ? { width: '100%' } : { width: '250px' }"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button v-if="hasPermission('product:create')" type="primary" @click="showAddModal">
|
||||
<a-button v-if="!isMobile && hasPermission('product:create')" type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增作品
|
||||
</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="productList"
|
||||
:loading="loading"
|
||||
@@ -91,12 +103,47 @@
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="productList" empty-description="暂无作品数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<a-image
|
||||
class="admin-mobile-card__cover admin-mobile-card__cover--wide"
|
||||
:src="getProductImages(item)[0] || DEFAULT_PRODUCT_IMAGE"
|
||||
:preview="false"
|
||||
/>
|
||||
<div class="admin-mobile-card__head" style="margin-top: 14px">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.title }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.shopName || getShopName(item.shopId) }}</div>
|
||||
</div>
|
||||
<span class="admin-mobile-card__badge">¥{{ item.price }}</span>
|
||||
</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.approximateDuration || '--' }} 分钟</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>互动数据</span>
|
||||
<strong>赞 {{ item.likeCount || 0 }} / 藏 {{ item.collectCount || 0 }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button size="small" @click="showViewModal(item)">查看</a-button>
|
||||
<a-button v-if="hasPermission('product:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
|
||||
<a-button v-if="hasPermission('product:delete')" size="small" danger @click="handleDelete(item)">删除</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<a-modal
|
||||
<AdminResponsiveModal
|
||||
v-model:open="modalVisible"
|
||||
:title="isEdit ? '编辑作品' : '新增作品'"
|
||||
width="700px"
|
||||
:desktop-width="700"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
:confirmLoading="modalLoading"
|
||||
@@ -302,13 +349,13 @@
|
||||
</a-form-item>
|
||||
</template>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<!-- 查看作品详情模态框 -->
|
||||
<a-modal
|
||||
<AdminResponsiveModal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看作品详情"
|
||||
width="700px"
|
||||
:desktop-width="700"
|
||||
@cancel="handleViewModalCancel"
|
||||
>
|
||||
<a-form
|
||||
@@ -427,7 +474,13 @@
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminMobileFab
|
||||
:visible="isMobile && hasPermission('product:create') && !modalVisible && !viewModalVisible"
|
||||
label="新增作品"
|
||||
@click="showAddModal"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -446,8 +499,13 @@ import { MAX_IMAGE_UPLOAD_SIZE, compressImageIfNeeded, formatFileSize } from '@/
|
||||
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()
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const productList = ref<Product[]>([])
|
||||
@@ -477,6 +535,20 @@ const uploadTaskMap = new Map<string, ChunkUploadTask<any>>()
|
||||
const activeUploadCount = ref(0)
|
||||
const isUploadPending = computed(() => activeUploadCount.value > 0)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
const requestTokens = reactive({
|
||||
shops: 0,
|
||||
tags: 0,
|
||||
artists: 0,
|
||||
coupons: 0,
|
||||
products: 0
|
||||
})
|
||||
|
||||
const nextRequestToken = (key: keyof typeof requestTokens) => {
|
||||
requestTokens[key] += 1
|
||||
return requestTokens[key]
|
||||
}
|
||||
|
||||
const isLatestRequestToken = (key: keyof typeof requestTokens, token: number) => requestTokens[key] === token
|
||||
|
||||
const viewFormState = reactive({
|
||||
shopId: undefined,
|
||||
@@ -593,6 +665,7 @@ const canManageAvailableCoupons = () => {
|
||||
const isCouponSelectionDisabled = computed(() => !canManageAvailableCoupons())
|
||||
|
||||
const fetchShops = async () => {
|
||||
const requestToken = nextRequestToken('shops')
|
||||
loadingShops.value = true
|
||||
try {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
@@ -600,11 +673,16 @@ const fetchShops = async () => {
|
||||
// 检查用户类型和权限
|
||||
if (currentUser && currentUser.type === 3 && currentUser.shopId) {
|
||||
// 美甲师直接使用自己的店铺ID,不需要获取店铺列表
|
||||
shops.value = []
|
||||
formState.shopId = currentUser.shopId
|
||||
if (isLatestRequestToken('shops', requestToken)) {
|
||||
shops.value = []
|
||||
formState.shopId = currentUser.shopId
|
||||
}
|
||||
} else {
|
||||
const response = await adminShopApi.listAllShops() as any
|
||||
const res = response || []
|
||||
if (!isLatestRequestToken('shops', requestToken)) {
|
||||
return
|
||||
}
|
||||
// 根据用户权限控制店铺列表的显示
|
||||
if (currentUser && currentUser.type !== 4 && currentUser.shopId) {
|
||||
// 如果是店长,只显示用户所属的店铺
|
||||
@@ -620,11 +698,14 @@ const fetchShops = async () => {
|
||||
// 权限不足时不显示错误提示
|
||||
console.error('获取店铺列表失败:', error)
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
if (isLatestRequestToken('shops', requestToken)) {
|
||||
loadingShops.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fetchTags = async (shopId?: IdType) => {
|
||||
const requestToken = nextRequestToken('tags')
|
||||
loadingTags.value = true
|
||||
try {
|
||||
let response
|
||||
@@ -633,25 +714,36 @@ const fetchTags = async (shopId?: IdType) => {
|
||||
} else {
|
||||
response = await adminTagApi.listAllTags() as any
|
||||
}
|
||||
if (!isLatestRequestToken('tags', requestToken)) {
|
||||
return
|
||||
}
|
||||
tags.value = response || []
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败', error)
|
||||
message.error('获取标签列表失败')
|
||||
} finally {
|
||||
loadingTags.value = false
|
||||
if (isLatestRequestToken('tags', requestToken)) {
|
||||
loadingTags.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fetchArtists = async (shopId?: IdType) => {
|
||||
const requestToken = nextRequestToken('artists')
|
||||
loadingArtists.value = true
|
||||
try {
|
||||
const response = await adminArtistApi.listArtists(shopId) as any
|
||||
if (!isLatestRequestToken('artists', requestToken)) {
|
||||
return
|
||||
}
|
||||
artists.value = response || []
|
||||
} catch (error) {
|
||||
console.error('获取美甲师列表失败', error)
|
||||
message.error('获取美甲师列表失败')
|
||||
} finally {
|
||||
loadingArtists.value = false
|
||||
if (isLatestRequestToken('artists', requestToken)) {
|
||||
loadingArtists.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -667,26 +759,34 @@ const syncAvailableCouponSelection = () => {
|
||||
|
||||
const fetchCoupons = async (shopId?: IdType) => {
|
||||
if (!shopId) {
|
||||
nextRequestToken('coupons')
|
||||
coupons.value = []
|
||||
formState.availableCoupons = []
|
||||
return
|
||||
}
|
||||
|
||||
const requestToken = nextRequestToken('coupons')
|
||||
loadingCoupons.value = true
|
||||
try {
|
||||
const response = await adminCouponApi.listAllCoupons(shopId)
|
||||
const res = typeof response === 'object' && 'data' in response ? response.data : response
|
||||
if (!isLatestRequestToken('coupons', requestToken)) {
|
||||
return
|
||||
}
|
||||
coupons.value = (res as any[]) || []
|
||||
syncAvailableCouponSelection()
|
||||
} catch (error) {
|
||||
console.error('获取优惠券列表失败', error)
|
||||
message.error('获取优惠券列表失败')
|
||||
} finally {
|
||||
loadingCoupons.value = false
|
||||
if (isLatestRequestToken('coupons', requestToken)) {
|
||||
loadingCoupons.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fetchProductList = async () => {
|
||||
const requestToken = nextRequestToken('products')
|
||||
loading.value = true
|
||||
try {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
@@ -701,24 +801,40 @@ const fetchProductList = async () => {
|
||||
}
|
||||
|
||||
const response = await adminProductApi.listProducts(params) as any
|
||||
productList.value = response?.list || []
|
||||
if (!isLatestRequestToken('products', requestToken)) {
|
||||
return
|
||||
}
|
||||
const nextProducts = response?.list || []
|
||||
productList.value = nextProducts
|
||||
pagination.total = response?.total || 0
|
||||
|
||||
await loadImageUrls(response?.list || [])
|
||||
|
||||
const nextImageUrls = await loadImageUrls(nextProducts, requestToken)
|
||||
if (nextImageUrls && isLatestRequestToken('products', requestToken)) {
|
||||
imageUrls.value = nextImageUrls
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取作品列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (isLatestRequestToken('products', requestToken)) {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const loadImageUrls = async (products: Product[]) => {
|
||||
const loadImageUrls = async (products: Product[], requestToken?: number) => {
|
||||
const nextImageUrls: Record<string, string[]> = {}
|
||||
for (const product of products) {
|
||||
if (requestToken && !isLatestRequestToken('products', requestToken)) {
|
||||
return null
|
||||
}
|
||||
if (product.imageFileIds) {
|
||||
const ids = product.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
if (requestToken && !isLatestRequestToken('products', requestToken)) {
|
||||
return null
|
||||
}
|
||||
if (id) {
|
||||
try {
|
||||
// 检查缓存
|
||||
@@ -735,14 +851,15 @@ const loadImageUrls = async (products: Product[]) => {
|
||||
}
|
||||
|
||||
if (product.id) {
|
||||
imageUrls.value[String(product.id)] = urls
|
||||
nextImageUrls[String(product.id)] = urls
|
||||
}
|
||||
} else {
|
||||
if (product.id) {
|
||||
imageUrls.value[String(product.id)] = [DEFAULT_PRODUCT_IMAGE]
|
||||
nextImageUrls[String(product.id)] = [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
}
|
||||
}
|
||||
return nextImageUrls
|
||||
}
|
||||
|
||||
const getProductImages = (product: Product | Record<string, any>): string[] => {
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
<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="currentShopName === '游客模式'" 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">门店切换</div>
|
||||
<a-select
|
||||
v-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">
|
||||
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 {
|
||||
getAdminCurrentShopName,
|
||||
getAdminRoleLabel,
|
||||
getAdminShopOptions,
|
||||
loadCachedAdminUserInfo
|
||||
} from './admin-helpers'
|
||||
|
||||
const router = useRouter()
|
||||
const { userPermissions, loadUserPermissions, clearPermissions } = usePermission()
|
||||
|
||||
const userInfo = ref(loadCachedAdminUserInfo())
|
||||
const selectedShopId = ref(userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined)
|
||||
const shopSwitchLoading = ref(false)
|
||||
|
||||
const currentShopName = computed(() => getAdminCurrentShopName(userInfo.value))
|
||||
const roleLabel = computed(() => getAdminRoleLabel(userInfo.value?.type))
|
||||
const shopOptions = computed(() => getAdminShopOptions(userInfo.value))
|
||||
const shopSelectOptions = computed(() => shopOptions.value.map(shop => ({ label: shop.name, value: shop.id })))
|
||||
const permissionCount = computed(() => userPermissions.value.length)
|
||||
const shopScopeText = computed(() => {
|
||||
if (!shopOptions.value.length) {
|
||||
return '游客模式'
|
||||
}
|
||||
return shopOptions.value.map(item => item.name).join(' / ')
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
const refreshLocalUserInfo = () => {
|
||||
userInfo.value = loadCachedAdminUserInfo()
|
||||
selectedShopId.value = userInfo.value?.shopId ? String(userInfo.value.shopId) : undefined
|
||||
}
|
||||
|
||||
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()
|
||||
})
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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: #64707a;
|
||||
}
|
||||
|
||||
.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>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,537 @@
|
||||
<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"
|
||||
>
|
||||
<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="预览">
|
||||
<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="预览">
|
||||
<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">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import { adminTagApi, adminShopApi, type Shop } from '@/api/admin'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import 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()
|
||||
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
return userInfo
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const modalVisible = ref(false)
|
||||
const viewModalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const searchText = ref('')
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentTag = ref<any>(null)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
|
||||
// 查看标签相关状态
|
||||
const viewFormState = reactive({
|
||||
tagName: '',
|
||||
shopId: undefined as number | undefined,
|
||||
textColor: '#333333',
|
||||
bgColor: '#FFFFFF',
|
||||
borderColor: '#E5E5E5'
|
||||
})
|
||||
|
||||
const tagList = ref<any[]>([])
|
||||
const shops = ref<Shop[]>([])
|
||||
const loadingShops = ref(false)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
|
||||
const formState = reactive({
|
||||
tagName: '',
|
||||
shopId: undefined as number | undefined,
|
||||
textColor: '#333333',
|
||||
bgColor: '#FFFFFF',
|
||||
borderColor: '#E5E5E5'
|
||||
})
|
||||
|
||||
const getDraftKey = () => buildDraftStorageKey('admin-tags', isEdit.value ? 'edit' : 'create', currentTag.value?.id ?? 'new')
|
||||
|
||||
const buildDraftPayload = () => ({
|
||||
tagName: formState.tagName,
|
||||
shopId: formState.shopId,
|
||||
textColor: formState.textColor,
|
||||
bgColor: formState.bgColor,
|
||||
borderColor: formState.borderColor
|
||||
})
|
||||
|
||||
const restoreDraft = () => {
|
||||
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
|
||||
if (!draft) {
|
||||
draftSavedAt.value = null
|
||||
return
|
||||
}
|
||||
Object.assign(formState, draft.payload)
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
|
||||
const handleSaveDraft = () => {
|
||||
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已暂存到本地')
|
||||
}
|
||||
|
||||
const handleClearDraft = (showMessage = true) => {
|
||||
clearDraftRecord(getDraftKey())
|
||||
draftSavedAt.value = null
|
||||
if (showMessage) {
|
||||
message.success('已清除暂存')
|
||||
}
|
||||
}
|
||||
|
||||
const formRules = {
|
||||
tagName: [{ required: true, message: '请输入标签名称', trigger: 'blur' }],
|
||||
shopId: [{ required: true, message: '请选择所属店铺', trigger: 'change' }]
|
||||
} as any
|
||||
|
||||
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: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
const normalizeShopIdValue = (value: string | number | undefined | null) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return ''
|
||||
}
|
||||
return String(value)
|
||||
}
|
||||
|
||||
const getShopName = (shopId: IdType | undefined) => {
|
||||
const normalizedShopId = normalizeShopIdValue(shopId)
|
||||
const shop = shops.value.find(s => normalizeShopIdValue(s.id) === normalizedShopId)
|
||||
return shop ? shop.shopName : '未知店铺'
|
||||
}
|
||||
|
||||
const handleSearch = async () => {
|
||||
pagination.current = 1
|
||||
await runWithGlobalLoading(() => fetchTags())
|
||||
}
|
||||
|
||||
const handleTableChange = async (pag: any) => {
|
||||
pagination.current = pag.current
|
||||
pagination.pageSize = pag.pageSize
|
||||
await runWithGlobalLoading(() => fetchTags())
|
||||
}
|
||||
|
||||
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'
|
||||
})
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
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
|
||||
})
|
||||
restoreDraft()
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showViewModal = (record: any) => {
|
||||
Object.assign(viewFormState, {
|
||||
tagName: record.tagName,
|
||||
shopId: record.shopId,
|
||||
textColor: record.textColor,
|
||||
bgColor: record.bgColor,
|
||||
borderColor: record.borderColor
|
||||
})
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
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,29 @@
|
||||
import { loadCachedAdminUserInfo, isBootstrapAdminUser, type AdminCachedUserInfo } from '@/utils/admin-session'
|
||||
|
||||
export { loadCachedAdminUserInfo, isBootstrapAdminUser }
|
||||
export type { AdminCachedUserInfo }
|
||||
|
||||
export const getAdminRoleLabel = (type?: number) => {
|
||||
switch (type) {
|
||||
case 4:
|
||||
return '平台管理员'
|
||||
case 2:
|
||||
return '店长'
|
||||
case 3:
|
||||
return '美甲师'
|
||||
default:
|
||||
return '后台账号'
|
||||
}
|
||||
}
|
||||
|
||||
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}`
|
||||
}))
|
||||
}
|
||||
|
||||
export const getAdminCurrentShopName = (userInfo?: AdminCachedUserInfo | null) =>
|
||||
userInfo?.shopName || '游客模式'
|
||||
Reference in New Issue
Block a user