功能:完善门店能力与用户安全配置
This commit is contained in:
@@ -14,17 +14,24 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, provide, ref, watch } from 'vue'
|
||||
/**
|
||||
* 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, provide, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ConfigProvider } from 'ant-design-vue'
|
||||
import { ConfigProvider, Modal } from 'ant-design-vue'
|
||||
import BottomNav from './components/BottomNav.vue'
|
||||
import { cartApi } from './api/cart'
|
||||
import { userApi, type SystemMessageVO } from './api/user'
|
||||
import antdLocale from './config/antdv-locale'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
/** routerReady is a reactive state variable used by the template and event handlers. */
|
||||
const routerReady = ref(false)
|
||||
|
||||
/** isHiddenNav is a reactive state variable used by the template and event handlers. */
|
||||
const isHiddenNav = computed(() => {
|
||||
if (!routerReady.value) {
|
||||
return true
|
||||
@@ -38,9 +45,13 @@ const isHiddenNav = computed(() => {
|
||||
})
|
||||
|
||||
// 全局购物车数量状态
|
||||
/** 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 {
|
||||
// 检查用户是否已登录
|
||||
@@ -61,10 +72,61 @@ const loadCartCount = async () => {
|
||||
}
|
||||
|
||||
// 提供更新购物车数量的方法
|
||||
/** updateCartCount is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const updateCartCount = async () => {
|
||||
await loadCartCount()
|
||||
}
|
||||
|
||||
/** 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()
|
||||
}
|
||||
Modal.info({
|
||||
title: item.title,
|
||||
content: h('div', { class: 'popup-message-body' }, [
|
||||
item.content ? h('div', { class: 'popup-message-content' }, item.content) : null,
|
||||
item.imageUrl ? h('img', { class: 'popup-message-image', src: item.imageUrl, alt: '消息图片' }) : null
|
||||
]),
|
||||
okText: '我知道了',
|
||||
async onOk() {
|
||||
await markShownAndResolve()
|
||||
},
|
||||
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)
|
||||
|
||||
@@ -74,6 +136,7 @@ watch(() => route.path, async () => {
|
||||
const isAdminPage = route.matched.some(r => r.meta.isAdmin)
|
||||
if (!isAdminPage) {
|
||||
await loadCartCount()
|
||||
await checkPopupMessages()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -83,6 +146,7 @@ loadCartCount()
|
||||
onMounted(async () => {
|
||||
await router.isReady()
|
||||
routerReady.value = true
|
||||
await checkPopupMessages()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -112,4 +176,123 @@ onMounted(async () => {
|
||||
.page-content.no-nav-padding {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.yumi-date-picker-panel {
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
.yumi-date-picker-panel .ant-picker-panel-container {
|
||||
overflow: hidden;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 18px 44px rgba(34, 40, 49, 0.18);
|
||||
}
|
||||
|
||||
.yumi-date-picker-panel .ant-picker-panel {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.yumi-date-picker-panel .ant-picker-header {
|
||||
padding: 8px 12px;
|
||||
border-bottom-color: #eef1f5;
|
||||
}
|
||||
|
||||
.yumi-date-picker-panel .ant-picker-header button {
|
||||
min-width: 34px;
|
||||
height: 34px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.yumi-date-picker-panel .ant-picker-header-view {
|
||||
line-height: 34px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.yumi-date-picker-panel .ant-picker-content th {
|
||||
height: 34px;
|
||||
color: #7b8494;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.yumi-date-picker-panel .ant-picker-cell {
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.yumi-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;
|
||||
}
|
||||
|
||||
.yumi-date-picker-panel .ant-picker-cell:hover .ant-picker-cell-inner {
|
||||
background: #eef6ff;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.yumi-date-picker-panel .ant-picker-cell-selected .ant-picker-cell-inner,
|
||||
.yumi-date-picker-panel .ant-picker-cell-range-start .ant-picker-cell-inner,
|
||||
.yumi-date-picker-panel .ant-picker-cell-range-end .ant-picker-cell-inner {
|
||||
background: #1677ff;
|
||||
color: #fff;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.yumi-date-picker-panel .ant-picker-footer {
|
||||
border-top-color: #eef1f5;
|
||||
}
|
||||
|
||||
.yumi-date-time-panel .ant-picker-time-panel,
|
||||
.yumi-time-panel .ant-picker-time-panel {
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
.yumi-date-time-panel .ant-picker-time-panel-column,
|
||||
.yumi-time-panel .ant-picker-time-panel-column {
|
||||
width: 76px;
|
||||
padding: 8px 6px;
|
||||
}
|
||||
|
||||
.yumi-date-time-panel .ant-picker-time-panel-cell-inner,
|
||||
.yumi-time-panel .ant-picker-time-panel-cell-inner {
|
||||
height: 34px !important;
|
||||
line-height: 34px !important;
|
||||
border-radius: 8px !important;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.yumi-date-time-panel .ant-picker-time-panel-cell-selected .ant-picker-time-panel-cell-inner,
|
||||
.yumi-time-panel .ant-picker-time-panel-cell-selected .ant-picker-time-panel-cell-inner {
|
||||
background: #eef6ff;
|
||||
color: #1677ff;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.ant-picker {
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.ant-picker-focused,
|
||||
.ant-picker:hover {
|
||||
border-color: #1677ff;
|
||||
box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.12);
|
||||
}
|
||||
|
||||
.popup-message-body {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.popup-message-content {
|
||||
white-space: pre-wrap;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.popup-message-image {
|
||||
width: 100%;
|
||||
max-height: 360px;
|
||||
object-fit: contain;
|
||||
border-radius: 8px;
|
||||
background: #fff7f8;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user