463 lines
15 KiB
Vue
463 lines
15 KiB
Vue
<template>
|
|
<el-config-provider>
|
|
<ConfigProvider :locale="antdLocale" :theme="antdTheme">
|
|
<div
|
|
class="app-container"
|
|
:class="{
|
|
'app-container--phone-shell': !isAdminShell,
|
|
'app-container--admin': isAdminShell
|
|
}"
|
|
>
|
|
<div v-if="isAdminShell" class="admin-shell">
|
|
<div class="page-content no-nav-padding">
|
|
<router-view v-slot="{ Component }">
|
|
<component :is="Component" :key="route.path" />
|
|
</router-view>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-else class="fingertip-designer-phone-frame" :class="{ 'fingertip-designer-phone-frame--hidden-nav': isHiddenNav }">
|
|
<BottomNav v-if="!isHiddenNav" />
|
|
<div class="page-content" :class="{ 'no-nav-padding': isHiddenNav }">
|
|
<router-view v-slot="{ Component }">
|
|
<component :is="Component" :key="route.path" />
|
|
</router-view>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</ConfigProvider>
|
|
</el-config-provider>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
/**
|
|
* App page script.
|
|
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
|
|
*/
|
|
import { computed, h, onMounted, onUnmounted, provide, ref, watch } from 'vue'
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
import { ConfigProvider, Modal } from 'ant-design-vue'
|
|
import type { ButtonProps } from 'ant-design-vue/es/button/buttonTypes'
|
|
import type { ThemeConfig } from 'ant-design-vue/es/config-provider/context'
|
|
import { CheckOutlined } from '@ant-design/icons-vue'
|
|
import BottomNav from './components/BottomNav.vue'
|
|
import SystemMessageCard from './components/SystemMessageCard.vue'
|
|
import { cartApi } from './api/cart'
|
|
/**
|
|
* Purpose: SystemMessageVO supports App.vue by holding or executing the system message vo page or API role.
|
|
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
import { userApi, type SystemMessageVO } from './api/user'
|
|
import antdLocale from './config/antdv-locale'
|
|
import { useGlobalConfirmEnter } from './composables/useConfirmEnter'
|
|
import { useShopTheme } from './composables/useShopTheme'
|
|
import { buildSystemMessageActionPath } from './utils/system-message-action'
|
|
|
|
/**
|
|
* Purpose: route supports App.vue by holding or executing the route page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const route = useRoute()
|
|
/**
|
|
* Purpose: router supports App.vue by holding or executing the router page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const router = useRouter()
|
|
const { currentTheme, refreshShopTheme, setupShopThemeSync } = useShopTheme()
|
|
useGlobalConfirmEnter()
|
|
/**
|
|
* Purpose: ButtonPropsWithClass supports App.vue by holding or executing the button props with class page or API role.
|
|
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
type ButtonPropsWithClass = ButtonProps & { class?: string }
|
|
const popupMessageOkButtonProps: ButtonPropsWithClass = { class: 'popup-message-ok-button' }
|
|
/** routerReady is a reactive state variable used by the template and event handlers. */
|
|
const routerReady = ref(false)
|
|
let stopThemeSync: (() => void) | undefined
|
|
const adminThemeRefreshOptions = { mode: 'admin' as const }
|
|
const customerThemeRefreshOptions = { mode: 'customer' as const }
|
|
|
|
const isAdminShell = computed(() => route.path.startsWith('/admin') || route.matched.some(r => r.meta.isAdmin))
|
|
const bottomNavRouteNames = new Set(['home', 'products', 'cart', 'profile'])
|
|
|
|
/** isHiddenNav is a reactive state variable used by the template and event handlers. */
|
|
const isHiddenNav = computed(() => {
|
|
if (!routerReady.value) {
|
|
return true
|
|
}
|
|
|
|
if (isAdminShell.value) {
|
|
return true
|
|
}
|
|
|
|
return !bottomNavRouteNames.has(String(route.name || ''))
|
|
})
|
|
|
|
/**
|
|
* Purpose: antdTheme supports App.vue by holding or executing the antd theme page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const antdTheme = computed<ThemeConfig>(() => ({
|
|
token: {
|
|
colorPrimary: currentTheme.value.primaryColor,
|
|
colorLink: currentTheme.value.primaryColor,
|
|
borderRadius: 8
|
|
},
|
|
components: {
|
|
Button: {
|
|
colorPrimary: currentTheme.value.primaryColor,
|
|
colorPrimaryHover: currentTheme.value.accentColor,
|
|
colorPrimaryActive: currentTheme.value.accentColor
|
|
},
|
|
Radio: {
|
|
colorPrimary: currentTheme.value.primaryColor
|
|
},
|
|
Input: {
|
|
activeBorderColor: currentTheme.value.primaryColor,
|
|
hoverBorderColor: currentTheme.value.primaryColor
|
|
}
|
|
}
|
|
}))
|
|
|
|
// 全局购物车数量状态
|
|
/** cartCount is a reactive state variable used by the template and event handlers. */
|
|
const cartCount = ref(0)
|
|
/** checkingPopupMessages is a reactive state variable used by the template and event handlers. */
|
|
const checkingPopupMessages = ref(false)
|
|
|
|
// 加载购物车数量
|
|
/** loadCartCount is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
|
const loadCartCount = async () => {
|
|
try {
|
|
// 检查用户是否已登录
|
|
const token = localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')
|
|
if (!token) {
|
|
cartCount.value = 0
|
|
return
|
|
}
|
|
|
|
const response = await cartApi.getCartList() as any
|
|
const data = response || []
|
|
const cartList = Array.isArray(data) ? data : []
|
|
const totalQuantity = cartList.reduce((sum: number, item: any) => sum + (item.quantity || 0), 0)
|
|
cartCount.value = totalQuantity
|
|
} catch (error) {
|
|
cartCount.value = 0
|
|
}
|
|
}
|
|
|
|
// 提供更新购物车数量的方法
|
|
/** updateCartCount is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
|
const updateCartCount = async () => {
|
|
await loadCartCount()
|
|
}
|
|
|
|
/**
|
|
* Purpose: resolveSystemMessageActionPath supports App.vue by holding or executing the resolve system message action path page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const resolveSystemMessageActionPath = (item: SystemMessageVO) => {
|
|
return buildSystemMessageActionPath(item)
|
|
}
|
|
|
|
/**
|
|
* Purpose: openSystemMessageAction supports App.vue by holding or executing the open system message action page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const openSystemMessageAction = async (item: SystemMessageVO) => {
|
|
const actionPath = resolveSystemMessageActionPath(item)
|
|
if (!actionPath) {
|
|
return
|
|
}
|
|
await router.push(actionPath)
|
|
}
|
|
|
|
/** showPopupMessage is a local helper used by this page script. */
|
|
const showPopupMessage = (item: SystemMessageVO) => {
|
|
return new Promise<void>((resolve) => {
|
|
let settled = false
|
|
/** markShownAndResolve is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
|
const markShownAndResolve = async () => {
|
|
if (settled) {
|
|
return
|
|
}
|
|
settled = true
|
|
await userApi.markMessagePopupShown(item.id)
|
|
resolve()
|
|
}
|
|
const metaText = `${item.publisherName || '系统消息'} · ${item.publishTime || item.createTime || '刚刚'}`
|
|
Modal.info({
|
|
icon: null,
|
|
centered: true,
|
|
width: 560,
|
|
class: 'fingertip-designer-system-message-dialog',
|
|
wrapClassName: 'fingertip-designer-system-message-wrap',
|
|
content: h(SystemMessageCard, {
|
|
title: item.title || '系统消息',
|
|
content: item.content || '',
|
|
imageUrl: item.imageUrl || '',
|
|
meta: metaText,
|
|
surface: 'modal'
|
|
}),
|
|
okText: h('span', { class: 'popup-message-ok-text' }, [
|
|
h(CheckOutlined),
|
|
h('span', '我知道了')
|
|
]),
|
|
okButtonProps: popupMessageOkButtonProps,
|
|
async onOk() {
|
|
await markShownAndResolve()
|
|
await openSystemMessageAction(item)
|
|
},
|
|
async afterClose() {
|
|
await markShownAndResolve()
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
/** checkPopupMessages is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
|
const checkPopupMessages = async () => {
|
|
const token = localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')
|
|
const isAdminPage = route.matched.some(r => r.meta.isAdmin)
|
|
if (!token || isAdminPage || checkingPopupMessages.value) {
|
|
return
|
|
}
|
|
checkingPopupMessages.value = true
|
|
try {
|
|
const messages = await userApi.listMyPopupMessages()
|
|
for (const item of messages || []) {
|
|
await showPopupMessage(item)
|
|
}
|
|
} catch (error) {
|
|
console.error('加载待弹窗消息失败:', error)
|
|
} finally {
|
|
checkingPopupMessages.value = false
|
|
}
|
|
}
|
|
|
|
provide('updateCartCount', updateCartCount)
|
|
provide('cartCount', cartCount)
|
|
|
|
// 监听路由变化,更新购物车数量
|
|
watch(() => route.path, async () => {
|
|
// 检查当前是否是后台页面,如果是则不加载购物车数据
|
|
const isAdminPage = route.matched.some(r => r.meta.isAdmin)
|
|
await refreshShopTheme(isAdminPage ? adminThemeRefreshOptions : customerThemeRefreshOptions)
|
|
if (!isAdminPage) {
|
|
await loadCartCount()
|
|
await checkPopupMessages()
|
|
}
|
|
})
|
|
|
|
// 页面加载时获取购物车数量
|
|
loadCartCount()
|
|
|
|
onMounted(async () => {
|
|
stopThemeSync = setupShopThemeSync()
|
|
await router.isReady()
|
|
routerReady.value = true
|
|
await refreshShopTheme(route.matched.some(r => r.meta.isAdmin) ? adminThemeRefreshOptions : customerThemeRefreshOptions)
|
|
await checkPopupMessages()
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
stopThemeSync?.()
|
|
})
|
|
</script>
|
|
|
|
<style>
|
|
#app {
|
|
font-family: Avenir, Helvetica, Arial, sans-serif;
|
|
-webkit-font-smoothing: antialiased;
|
|
-moz-osx-font-smoothing: grayscale;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.app-container {
|
|
min-height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
position: relative;
|
|
}
|
|
|
|
.page-content {
|
|
flex: 1;
|
|
padding-bottom: 60px;
|
|
position: relative;
|
|
z-index: 1;
|
|
}
|
|
|
|
/* 当导航栏隐藏时,移除底部 padding */
|
|
.page-content.no-nav-padding {
|
|
padding-bottom: 0;
|
|
}
|
|
|
|
.fingertip-designer-date-picker-panel {
|
|
padding: 6px;
|
|
}
|
|
|
|
.fingertip-designer-date-picker-panel .ant-picker-panel-container {
|
|
overflow: hidden;
|
|
border-radius: 12px;
|
|
box-shadow: 0 18px 44px rgba(34, 40, 49, 0.18);
|
|
}
|
|
|
|
.fingertip-designer-date-picker-panel .ant-picker-panel {
|
|
border: 0;
|
|
}
|
|
|
|
.fingertip-designer-date-picker-panel .ant-picker-header {
|
|
padding: 8px 12px;
|
|
border-bottom-color: var(--theme-border);
|
|
}
|
|
|
|
.fingertip-designer-date-picker-panel .ant-picker-header button {
|
|
min-width: 34px;
|
|
height: 34px;
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.fingertip-designer-date-picker-panel .ant-picker-header-view {
|
|
line-height: 34px;
|
|
font-weight: 700;
|
|
}
|
|
|
|
.fingertip-designer-date-picker-panel .ant-picker-content th {
|
|
height: 34px;
|
|
color: var(--text-secondary);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.fingertip-designer-date-picker-panel .ant-picker-cell {
|
|
padding: 4px 0;
|
|
}
|
|
|
|
.fingertip-designer-date-picker-panel .ant-picker-cell-inner {
|
|
min-width: 34px;
|
|
height: 34px !important;
|
|
line-height: 34px !important;
|
|
border-radius: 8px !important;
|
|
transition: background .18s ease, color .18s ease, transform .18s ease;
|
|
}
|
|
|
|
.fingertip-designer-date-picker-panel .ant-picker-cell:hover .ant-picker-cell-inner {
|
|
background: var(--theme-primary-soft);
|
|
transform: translateY(-1px);
|
|
}
|
|
|
|
.fingertip-designer-date-picker-panel .ant-picker-cell-selected .ant-picker-cell-inner,
|
|
.fingertip-designer-date-picker-panel .ant-picker-cell-range-start .ant-picker-cell-inner,
|
|
.fingertip-designer-date-picker-panel .ant-picker-cell-range-end .ant-picker-cell-inner {
|
|
background: var(--theme-primary);
|
|
color: #fff;
|
|
font-weight: 700;
|
|
}
|
|
|
|
.fingertip-designer-date-picker-panel .ant-picker-footer {
|
|
border-top-color: var(--theme-border);
|
|
}
|
|
|
|
.fingertip-designer-date-time-panel .ant-picker-time-panel,
|
|
.fingertip-designer-time-panel .ant-picker-time-panel {
|
|
min-width: 150px;
|
|
}
|
|
|
|
.fingertip-designer-date-time-panel .ant-picker-time-panel-column,
|
|
.fingertip-designer-time-panel .ant-picker-time-panel-column {
|
|
width: 76px;
|
|
padding: 8px 6px;
|
|
}
|
|
|
|
.fingertip-designer-date-time-panel .ant-picker-time-panel-cell-inner,
|
|
.fingertip-designer-time-panel .ant-picker-time-panel-cell-inner {
|
|
height: 34px !important;
|
|
line-height: 34px !important;
|
|
border-radius: 8px !important;
|
|
text-align: center;
|
|
}
|
|
|
|
.fingertip-designer-date-time-panel .ant-picker-time-panel-cell-selected .ant-picker-time-panel-cell-inner,
|
|
.fingertip-designer-time-panel .ant-picker-time-panel-cell-selected .ant-picker-time-panel-cell-inner {
|
|
background: var(--theme-primary-soft);
|
|
color: var(--theme-primary);
|
|
font-weight: 700;
|
|
}
|
|
|
|
.ant-picker {
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.ant-picker-focused,
|
|
.ant-picker:hover {
|
|
border-color: var(--theme-primary);
|
|
box-shadow: var(--theme-focus-shadow);
|
|
}
|
|
|
|
.fingertip-designer-system-message-wrap .ant-modal {
|
|
max-width: calc(100vw - 32px);
|
|
}
|
|
|
|
.fingertip-designer-system-message-dialog .ant-modal-content {
|
|
overflow: hidden;
|
|
padding: 0;
|
|
border-radius: 8px;
|
|
background: var(--theme-card-bg);
|
|
box-shadow: 0 24px 70px rgba(38, 31, 36, 0.32);
|
|
}
|
|
|
|
.fingertip-designer-system-message-dialog .ant-modal-confirm-body-wrapper {
|
|
margin: 0;
|
|
}
|
|
|
|
.fingertip-designer-system-message-dialog .ant-modal-confirm-body {
|
|
display: block;
|
|
}
|
|
|
|
.fingertip-designer-system-message-dialog .ant-modal-confirm-content {
|
|
max-width: none;
|
|
margin: 0 !important;
|
|
color: inherit;
|
|
}
|
|
|
|
.fingertip-designer-system-message-dialog .ant-modal-confirm-btns {
|
|
display: flex;
|
|
justify-content: stretch;
|
|
margin: 0;
|
|
padding: 0 30px 30px;
|
|
background: var(--theme-card-bg);
|
|
}
|
|
|
|
.fingertip-designer-system-message-dialog .popup-message-ok-button {
|
|
width: 100%;
|
|
height: 44px;
|
|
border: 0;
|
|
border-radius: 8px;
|
|
color: #ffffff;
|
|
font-weight: 700;
|
|
background: var(--theme-gradient);
|
|
box-shadow: var(--theme-button-shadow);
|
|
}
|
|
|
|
.fingertip-designer-system-message-dialog .popup-message-ok-button:hover,
|
|
.fingertip-designer-system-message-dialog .popup-message-ok-button:focus {
|
|
color: #ffffff;
|
|
background: linear-gradient(135deg, var(--theme-accent) 0%, var(--theme-secondary) 100%);
|
|
}
|
|
|
|
.popup-message-ok-text {
|
|
display: inline-flex;
|
|
gap: 8px;
|
|
align-items: center;
|
|
}
|
|
|
|
@media (max-width: 640px) {
|
|
.fingertip-designer-system-message-dialog .ant-modal-content {
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.fingertip-designer-system-message-dialog .popup-message-ok-button {
|
|
width: 100%;
|
|
}
|
|
}
|
|
</style>
|