Files
zkxw/mobile-h5/pages/index/index.vue
zlwuandCursor ac8e471aca fix: align sample registration, freight scope, and OA datetime display
Let customer-service quick register write storage, certificate, and insurance separately without extra menu or data-scope checks. List freight by document data scope like the web admin, allow protocol staff outside the collection region, and pad OA datetimes to seconds so PC date pickers can show historical minute values.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-20 17:30:30 +08:00

336 lines
8.8 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="page-shell">
<view
v-if="envBanner.show"
class="env-banner"
:class="'env-banner--' + envBanner.tone"
>
<text class="env-banner__text">{{ envBanner.label }}</text>
</view>
<view class="home-header">
<view class="home-header__top">
<view class="brand">中科兴皖 · 移动工作台</view>
</view>
<view class="hello">您好,{{ userName }}</view>
<view class="meta">
<view class="meta__left">
<text v-if="postName">{{ postName }}</text>
<view v-if="postName && deptName" class="dot" />
<text v-if="deptName">{{ deptName }}</text>
</view>
<view class="meta__right">
<text class="home-logout" @click="onLogout">退出登录</text>
</view>
</view>
</view>
<view class="home-body">
<view class="home-banner">
<swiper
class="home-banner__swiper"
:circular="banners.length > 1"
:indicator-dots="banners.length > 1"
indicator-color="rgba(255,255,255,0.45)"
indicator-active-color="#22c55e"
:autoplay="false"
>
<swiper-item v-for="item in banners" :key="item.id">
<view class="home-banner__item">
<video
v-if="item.type === 'video'"
class="home-banner__video"
:src="item.src"
:muted="true"
:autoplay="true"
:loop="true"
:controls="false"
:show-center-play-btn="false"
:show-play-btn="false"
:show-fullscreen-btn="false"
:enable-progress-gesture="false"
object-fit="cover"
playsinline
webkit-playsinline
preload="auto"
/>
<image
v-else
class="home-banner__image"
:src="item.src"
mode="aspectFill"
/>
</view>
</swiper-item>
</swiper>
</view>
<view v-if="menusLoading" class="panel">
<view class="home-menus-loading">
<view class="pulse-dots" aria-hidden="true">
<view class="pulse-dot" />
<view class="pulse-dot" />
<view class="pulse-dot" />
</view>
<text class="home-menus-loading__text">加载菜单…</text>
</view>
</view>
<view v-else-if="menuRegions.length" class="menu-regions">
<view
v-for="region in menuRegions"
:key="region.key"
class="menu-region"
:class="'menu-region--' + region.tone"
>
<view class="menu-region__hd">
<view class="menu-region__left">
<view class="menu-region__mark" />
<text class="menu-region__title">{{ region.title }}</text>
</view>
<text v-if="region.hint" class="menu-region__hint">{{
region.hint
}}</text>
</view>
<view class="menu-region__bd">
<MenuGrid
:menus="region.menus"
:show-group-title="false"
@select="onMenuSelect"
/>
</view>
</view>
</view>
<view v-else class="panel">
<VanEmpty
description="暂无可用菜单权限"
tip="请联系管理员开通功能入口"
/>
</view>
</view>
</view>
</template>
<script>
import { ENV_BANNER } from '../../utils/config.js'
import MenuGrid from '../../components/MenuGrid.vue'
import VanEmpty from '../../components/van-empty/van-empty.vue'
import {
clearSession,
fetchCurrentUser,
getUser
} from '../../utils/auth.js'
import { fetchMyMobileMenus } from '../../utils/menu.js'
import { groupMenusByRegion } from '../../utils/menu-regions.js'
import {
formatOaBadgeCount,
refreshOaMenuBadges
} from '../../utils/oa-badge.js'
const HOME_BANNER_IMAGE = '/static/home-banner.jpg'
const FALLBACK_MENUS = [
{
id: 'oa-start',
title: '发起审批',
groupTitle: 'OA工作流',
icon: 'approve',
path: '/pages/oa/start/index',
iconBg: 'transparent'
}
]
function applyUserToState(vm, user) {
if (!user) return
vm.userName =
user.realName || user.displayName || user.username || vm.userName || ''
const posts = Array.isArray(user.postNames) ? user.postNames : []
vm.postName = posts.filter(Boolean).join('、')
vm.deptName = user.deptName || user.regionName || ''
}
export default {
components: { MenuGrid, VanEmpty },
data() {
return {
envBanner: ENV_BANNER,
userName: '',
postName: '',
deptName: '',
menus: [],
menusLoading: true,
banners: [
{
id: 'banner-image-1',
type: 'image',
src: HOME_BANNER_IMAGE
}
]
}
},
computed: {
menuRegions() {
return groupMenusByRegion(this.menus)
}
},
onShow() {
applyUserToState(this, getUser())
fetchCurrentUser()
.then((user) => {
if (user) applyUserToState(this, user)
})
.catch(() => {
/* 本地缓存已展示,忽略刷新失败 */
})
this.loadMenus()
},
methods: {
mergeBadgesIntoMenus(menus, badgeMap) {
const map = badgeMap || {}
return (menus || []).map((m) => {
const path = m && m.path ? m.path : ''
if (!Object.prototype.hasOwnProperty.call(map, path)) {
return m
}
const n = Number(map[path]) || 0
return {
...m,
badgeCount: n,
badge: formatOaBadgeCount(n)
}
})
},
async refreshMenuBadges() {
try {
const map = await refreshOaMenuBadges()
this.menus = this.mergeBadgesIntoMenus(this.menus, map)
} catch (_) {
/* 角标失败不阻塞菜单 */
}
},
async loadMenus() {
// 仅首次(尚无菜单)显示加载态,避免二次 onShow 闪一下空宫格
if (!this.menus.length) {
this.menusLoading = true
}
try {
const list = await fetchMyMobileMenus()
if (list && list.length) {
this.menus = list.filter((m) => {
const path = String((m && m.path) || '')
const id = String((m && m.id) || '')
return (
path.indexOf('form-sink') < 0 &&
id.indexOf('form-sink') < 0 &&
String((m && m.title) || '').indexOf('水槽') < 0
)
})
await this.refreshMenuBadges()
return
}
if (!this.menus.length) {
this.menus = [...FALLBACK_MENUS]
}
await this.refreshMenuBadges()
} catch (e) {
/* 接口未就绪时用过渡菜单,避免首页完全空白 */
if (!this.menus.length) {
this.menus = [...FALLBACK_MENUS]
}
await this.refreshMenuBadges()
} finally {
this.menusLoading = false
}
},
onMenuSelect(m) {
if (m.path) {
uni.navigateTo({ url: m.path })
}
},
onLogout() {
clearSession()
uni.reLaunch({ url: '/pages/login/index' })
}
}
}
</script>
<style lang="scss" scoped>
.home-menus-loading {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 28rpx;
min-height: 240rpx;
padding: 48rpx 32rpx;
box-sizing: border-box;
}
.pulse-dots {
display: flex;
align-items: center;
gap: 16rpx;
}
.pulse-dot {
width: 16rpx;
height: 16rpx;
border-radius: 50%;
background: var(--brand-green, #22c55e);
animation: home-menu-pulse 1.2s ease-in-out infinite;
}
.pulse-dot:nth-child(2) {
animation-delay: 0.15s;
opacity: 0.75;
}
.pulse-dot:nth-child(3) {
animation-delay: 0.3s;
opacity: 0.55;
}
.home-menus-loading__text {
font-size: 26rpx;
font-weight: 500;
color: var(--text-muted, #5f7a6d);
line-height: 1.4;
}
@keyframes home-menu-pulse {
0%,
80%,
100% {
transform: translateY(0);
}
40% {
transform: translateY(-10rpx);
}
}
.env-banner {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
padding: 12rpx 24rpx;
box-sizing: border-box;
}
.env-banner__text {
font-size: 22rpx;
font-weight: 700;
letter-spacing: 0.04em;
line-height: 1.3;
}
.env-banner--local {
background: #f59e0b;
color: #451a03;
}
.env-banner--test {
background: #3b82f6;
color: #eff6ff;
}
</style>