refactor: 组件就近迁移、操作菜单组件化并统一页面命名

- 组件文件统一 PascalCase 并就近迁入所属目录
- 操作菜单抽为 ActionSheet 组件,危险操作确认拆为 useConfirmAction
- 导航栏测量拆为 useNavbarMetrics 并收缩对外接口
- 页面方法按动词约定重命名,show 前缀与 handle 误用一并修正
- 通知与菜单接口类型改用字面量联合并修正取值注释
- 多行空壳注释收回单行
This commit is contained in:
Ray.Hao committed 2026-10-16 16:50:56 +08:00
1 parent 1e3954ce0c
commit cb1a1e349f
63 files changed
+1653 -1423

No files matched your search

+54 -47
View File
@@ -1,10 +1,11 @@
<template>
<view>
<!-- 轮播图 -->
<!-- 轮播图:height 控制轨道与图片高度,custom-style 给根节点确定高度(小程序内部 scroll-view 用 100%) -->
<view class="relative">
<wd-swiper
v-model:current="activeSlideIndex"
custom-class="swiper-box"
custom-style="height: 420rpx"
height="420rpx"
:list="swiperList"
autoplay
/>
@@ -17,8 +18,7 @@
<wd-grid-item
v-for="(item, index) in quickNavList"
:key="index"
use-slot
@click="handleNavClickWithGuard(item)"
@click="handleNavItemClick(item)"
>
<view class="quick-nav-card__item">
<image class="quick-nav-card__icon" :src="item.icon" mode="aspectFit" />
@@ -39,7 +39,7 @@
</view>
<!-- 数据统计 -->
<view class="grid grid-cols-2 gap-16rpx m-24rpx">
<view class="home__stats">
<view class="stat-card stat-card--uv">
<image class="stat-card__icon" src="/static/icons/uv.svg" mode="aspectFit" />
<view class="stat-card__header">
@@ -79,7 +79,7 @@
</view>
</view>
</view>
<view class="w-full h-600rpx px-20rpx box-border">
<view class="chart-wrapper__canvas">
<qiun-data-charts
type="area"
:chartData="chartData"
@@ -118,20 +118,20 @@ interface NavItem {
const userStore = useUserStore();
const themeStore = useThemeStore();
const { handleNavClick } = useNavigation();
const { navigate } = useNavigation();
const activeSlideIndex = ref(0);
const trendDays = ref(7);
const swiperList = ref(["https://www.youlai.tech/storage/youlai/bg02.png"]);
/** 访问概览数据 */
// 访问概览数据
const visitOverviewData = ref<VisitOverview>({
todayUvCount: 0,
todayPvCount: 0,
} as VisitOverview);
/** 通知公告文本 */
// 公告列表:只取前两条拼成滚动文案
const noticeList = ref<NoticeItem[]>([]);
const noticeText = computed(() => {
const titles = noticeList.value
@@ -141,30 +141,19 @@ const noticeText = computed(() => {
return titles.length ? titles.join(" ") : "暂无通知";
});
const userPerms = computed(() => userStore.userInfo?.perms || []);
const isAuthenticated = computed(() => userStore.isAuthenticated);
const hasAnyPerm = computed(() => userPerms.value.length > 0);
/** 默认菜单(未登录时显示) */
const defaultNavList = computed(() => {
// 快捷入口最多展示的数量
const QUICK_NAV_LIMIT = 4;
// 快捷入口:未登录时展示前几个作为引导,点击后统一跳登录页;
// 已登录按权限过滤,不足 4 个就显示多少
const quickNavList = computed<NavItem[]>(() => {
const result: NavItem[] = [];
for (const group of workMenuGroups) {
for (const item of group.children) {
result.push(item);
if (result.length >= 4) return result;
}
}
return result;
});
/** 快捷入口:已登录按权限过滤,未登录显示默认菜单 */
const quickNavList = computed(() => {
if (!isAuthenticated.value || !hasAnyPerm.value) return defaultNavList.value;
const result: NavItem[] = [];
for (const group of workMenuGroups) {
for (const item of group.children) {
if (hasPermission(item.perm)) result.push(item);
if (result.length >= 4) return result;
if (!isAuthenticated.value || hasPermission(item.perm)) result.push(item);
if (result.length >= QUICK_NAV_LIMIT) return result;
}
}
return result;
@@ -190,7 +179,7 @@ const chartOpts = computed(() => ({
},
}));
/** 加载通知公告 */
// 加载公告:未登录不发请求,直接清空列表
async function loadNoticeData() {
if (!isAuthenticated.value) {
noticeList.value = [];
@@ -204,14 +193,14 @@ async function loadNoticeData() {
}
}
/** 加载访问概览统计 */
// 加载访问概览:失败保留初始值,不打断页面
function loadVisitOverviewData() {
LogAPI.getVisitOverview()
.then((data) => (visitOverviewData.value = data))
.catch(() => {});
}
/** 加载访问趋势图表 */
// 加载访问趋势:按当前天数取数,失败回落到空图表
async function loadVisitTrendData() {
const endDate = dayjs().format("YYYY-MM-DD");
const startDate = dayjs()
@@ -233,21 +222,33 @@ async function loadVisitTrendData() {
}
}
/** 快捷导航点击(未登录跳转登录) */
function handleNavClickWithGuard(item: NavItem) {
if (!isAuthenticated.value || !hasAnyPerm.value) {
uni.navigateTo({ url: "/pages/login/index" });
// 快捷导航点击:未登录先跳登录页,已登录按权限跳转
function handleNavItemClick(item: NavItem) {
if (!isAuthenticated.value) {
navigateToLogin();
return;
}
handleNavClick(item);
navigate(item);
}
/** 跳转通知公告列表 */
// 跳登录页并带上来路,登录成功后原路返回
function navigateToLogin() {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const redirect = encodeURIComponent(`/${currentPage.route}`);
uni.navigateTo({ url: `/pages/login/index?redirect=${redirect}` });
}
// 公告页需要登录态,未登录先跳登录页
function handleNoticeClick() {
if (!isAuthenticated.value) {
navigateToLogin();
return;
}
uni.navigateTo({ url: "/subPages/work/notice/index" });
}
/** 切换趋势时间范围 */
// 切换趋势范围:同一范围重复点击不发请求
function switchRange(value: number) {
if (trendDays.value === value) return;
trendDays.value = value;
@@ -265,15 +266,6 @@ onShow(() => {
});
</script>
<!-- 非 scoped:覆盖 wd-swiper 内部节点高度 -->
<style lang="scss">
.swiper-box,
.swiper-box .wd-swiper__item,
.swiper-box image {
height: 420rpx;
}
</style>
<style lang="scss" scoped>
.hero-fade {
position: absolute;
@@ -291,6 +283,14 @@ onShow(() => {
);
}
/* 统计卡片网格:一组布局样式集中在这里,模板只留一个语义类 */
.home__stats {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16rpx;
margin: 24rpx;
}
.chart-wrapper {
box-sizing: border-box;
overflow: hidden;
@@ -299,6 +299,13 @@ onShow(() => {
border-radius: 16rpx;
box-shadow: var(--shadow-sm);
&__canvas {
box-sizing: border-box;
width: 100%;
height: 600rpx;
padding: 0 20rpx;
}
&__header {
display: flex;
gap: 24rpx;
@@ -33,11 +33,13 @@
<view
class="bind-mobile__code-btn"
:class="
countdown > 0 ? 'bind-mobile__code-btn--disabled' : 'bind-mobile__code-btn--active'
remainingSeconds > 0
? 'bind-mobile__code-btn--disabled'
: 'bind-mobile__code-btn--active'
"
@click="handleSendCode"
>
{{ countdown > 0 ? `${countdown}s` : "获取验证码" }}
{{ remainingSeconds > 0 ? `${remainingSeconds}s` : "获取验证码" }}
</view>
</view>
@@ -75,15 +77,21 @@ const emit = defineEmits<{
const toast = useToast();
const userStore = useUserStore();
const { countdown, sendCode, resetCountdown } = useSmsLoginCode();
const { remainingSeconds, sendCode, resetCountdown } = useSmsLoginCode();
const mobile = ref("18888888888");
const code = ref("");
const isSubmitting = ref(false);
/** 待绑定的微信 openid,由父组件通过 open 传入 */
// 待绑定的微信 openid,由父组件通过 open 传入,不随表单清理
let openid = "";
/** 打开弹窗并记录待绑定的 openid */
/**
* 打开绑定弹窗
*
* 重置手机号与验证码(避免上一次输入残留),并记录待绑定的 openid。
*
* @param boundOpenid - 静默登录返回的微信 openid
*/
function open(boundOpenid: string) {
openid = boundOpenid;
mobile.value = "18888888888";
@@ -91,6 +99,7 @@ function open(boundOpenid: string) {
visible.value = true;
}
// 关闭弹窗:停掉倒计时并清空验证码,手机号保留便于再次打开
function handleClose() {
resetCountdown();
code.value = "";
@@ -100,6 +109,7 @@ async function handleSendCode() {
await sendCode(mobile.value);
}
// 确认绑定:本地校验通过后换会话,成功后由父组件跳转
async function handleConfirm() {
if (isSubmitting.value) return;
if (!isValidMobile(mobile.value)) {
@@ -167,7 +177,7 @@ defineExpose({ open });
&--active {
color: var(--color-primary);
background-color: var(--color-primary-light);
background-color: var(--color-primary-soft);
}
&--disabled {
+13 -12
View File
@@ -7,7 +7,7 @@
</view>
<!-- 导航栏:透明悬浮于渐变背景上,返回逻辑由组件内聚(栈空时回首页) -->
<custom-navbar bg-color="transparent" placeholder />
<app-navbar background="transparent" placeholder />
<!-- 主内容 -->
<view class="login__body">
@@ -215,7 +215,7 @@ import { useUserStore } from "@/store/modules/user";
import { useSmsLoginCode, isValidMobile } from "@/composables/useSmsLoginCode";
import { getErrorMessage } from "@/utils/error";
import AuthAPI from "@/api/auth";
import BindMobilePopup from "./components/bind-mobile-popup.vue";
import BindMobilePopup from "./components/BindMobilePopup.vue";
definePage({
name: "login",
@@ -234,7 +234,7 @@ const isLoggingIn = ref(false);
const isPwdVisible = ref(false);
const hasAcceptedPolicy = ref(false);
const loginMode = ref<"PASSWORD" | "SMS" | "WECHAT">("PASSWORD");
const { countdown: smsCountdown, sendCode } = useSmsLoginCode();
const { remainingSeconds: smsCountdown, sendCode } = useSmsLoginCode();
const formData = ref({
username: "admin",
@@ -397,12 +397,12 @@ const handleSendCode = async () => {
await sendCode(formData.value.username);
};
// 微信登录
/** 微信手机号快捷填充按钮回调事件 */
// 微信手机号快捷登录的事件载荷:手机号需要 code 换取,用户取消时为空
interface WxPhoneLoginEvent {
detail: { code?: string };
}
// 微信一键登录:未勾选协议时先弹协议确认,再继续换号流程
const handleWechatPhoneLogin = async (e: WxPhoneLoginEvent) => {
const phoneCode = e.detail.code;
if (!hasAcceptedPolicy.value) {
@@ -410,7 +410,7 @@ const handleWechatPhoneLogin = async (e: WxPhoneLoginEvent) => {
return;
}
if (!phoneCode) {
await handleWechatSilentLogin();
await doWechatSilentLogin();
return;
}
await doWechatPhoneLogin(phoneCode);
@@ -418,7 +418,7 @@ const handleWechatPhoneLogin = async (e: WxPhoneLoginEvent) => {
async function doWechatPhoneLogin(phoneCode: string) {
if (!phoneCode) {
await handleWechatSilentLogin();
await doWechatSilentLogin();
return;
}
isLoggingIn.value = true;
@@ -429,13 +429,13 @@ async function doWechatPhoneLogin(phoneCode: string) {
await completeLogin();
} catch {
toast.info("正在尝试其他登录方式...");
await handleWechatSilentLogin();
await doWechatSilentLogin();
} finally {
isLoggingIn.value = false;
}
}
const handleWechatSilentLogin = async () => {
const doWechatSilentLogin = async () => {
isLoggingIn.value = true;
try {
const { code } = await uni.login();
@@ -453,12 +453,13 @@ const handleWechatSilentLogin = async () => {
}
};
/** 绑定手机号成功后的会话初始化与跳转 */
// 登录成功:补拉用户资料后回跳来源页面,延迟用于展示成功提示
async function completeLogin() {
await userStore.loadUserInfo();
setTimeout(() => uni.reLaunch({ url: redirect.value }), 800);
}
// 协议入口:按类型区分用户协议与隐私政策
const navigateToAgreement = (type: string) => {
const url =
type === "user"
@@ -482,7 +483,7 @@ onLoad((options) => {
135deg,
var(--color-bg-page) 0%,
var(--color-bg-card) 50%,
var(--color-primary-light) 100%
var(--color-primary-soft) 100%
);
}
@@ -709,7 +710,7 @@ onLoad((options) => {
border-radius: 16rpx;
&--active {
color: var(--color-primary);
background-color: var(--color-primary-light);
background-color: var(--color-primary-soft);
}
&--disabled {
@@ -1,13 +1,8 @@
<template>
<view class="menu-section">
<text class="menu-section__title">{{ title }}</text>
<view class="menu-list">
<view
v-for="item in items"
:key="item.key"
class="menu-row"
@click="emit('select', item.key)"
>
<view class="menu-section__list">
<view v-for="item in items" :key="item.id" class="menu-row" @click="emit('select', item.id)">
<view class="menu-row__icon" :class="`menu-row__icon--${item.tone}`">
<wd-icon :name="item.icon" size="18" :color="iconColors[item.tone]" />
</view>
@@ -23,8 +18,14 @@
</template>
<script lang="ts" setup>
export interface MenuItem {
key: string;
/**
* 设置菜单项
*
* 只描述展示所需字段,跳转目标与动作由调用方的配置补充。
*/
export interface SettingsMenuItem {
/** 稳定标识,用于分发,不用展示文案 */
id: string;
icon: string;
tone: "primary" | "warning" | "danger" | "success" | "info";
title: string;
@@ -32,9 +33,10 @@ export interface MenuItem {
value?: string;
}
const iconColors: Record<MenuItem["tone"], string> = {
// 语义色映射:tone 决定图标底色变体与图标颜色
const iconColors: Record<SettingsMenuItem["tone"], string> = {
primary: "var(--color-primary)",
warning: "var(--color-primary)",
warning: "var(--color-warning)",
danger: "var(--color-danger)",
success: "var(--color-success)",
info: "var(--color-info)",
@@ -42,11 +44,16 @@ const iconColors: Record<MenuItem["tone"], string> = {
defineProps<{
title: string;
items: MenuItem[];
items: SettingsMenuItem[];
}>();
/**
* select:上报被点击项
*
* 载荷是菜单项 id 而不是标题,展示文案可能重复,不能作为标识。
*/
const emit = defineEmits<{
select: [key: string];
select: [id: string];
}>();
</script>
@@ -66,7 +73,7 @@ const emit = defineEmits<{
}
}
.menu-list {
.menu-section__list {
overflow: hidden;
}
@@ -91,11 +98,14 @@ const emit = defineEmits<{
height: 72rpx;
border-radius: 22rpx;
&--primary,
&--warning {
&--primary {
background: var(--color-primary-alpha-15);
}
&--warning {
background: var(--color-warning-light);
}
&--danger {
background: var(--color-danger-light);
}
@@ -1,31 +1,32 @@
<template>
<view class="community-card" @click="emit('open')">
<image class="community-card__bg" src="/static/images/official-bg.png" mode="aspectFill" />
<view class="community-card__mask" />
<view class="community-card__logo">
<image src="/static/images/logo.png" mode="aspectFit" class="w-full h-full" />
<view class="official-card" @click="emit('open')">
<image class="official-card__bg" src="/static/images/official-bg.png" mode="aspectFill" />
<view class="official-card__mask" />
<view class="official-card__logo">
<image class="official-card__logo-img" src="/static/images/logo.png" mode="aspectFit" />
</view>
<view class="community-card__body">
<view class="community-card__title-row">
<text class="community-card__title">关注有来技术</text>
<wd-tag type="success" plain custom-class="community-card__tag">官方社区</wd-tag>
<view class="official-card__body">
<view class="official-card__title-row">
<text class="official-card__title">关注有来技术</text>
<wd-tag type="success" variant="plain" custom-class="official-card__tag">官方社区</wd-tag>
</view>
<text class="community-card__desc">开源更新、实战内容、交流群入口,统一在这里查看</text>
<text class="official-card__desc">开源更新、实战内容、交流群入口,统一在这里查看</text>
</view>
<view class="community-card__arrow">
<view class="official-card__arrow">
<wd-icon name="right" size="16" color="var(--color-text-secondary)" />
</view>
</view>
</template>
<script lang="ts" setup>
/** open:请求进入公众号介绍页,目标地址由父级决定 */
const emit = defineEmits<{
open: [];
}>();
</script>
<style lang="scss" scoped>
.community-card {
.official-card {
position: relative;
display: flex;
gap: 24rpx;
@@ -37,7 +38,7 @@ const emit = defineEmits<{
box-shadow: var(--shadow-md);
}
.community-card__bg {
.official-card__bg {
position: absolute;
top: 0;
right: 0;
@@ -47,10 +48,9 @@ const emit = defineEmits<{
width: 100%;
height: 100%;
pointer-events: none;
opacity: 1;
}
.community-card__mask {
.official-card__mask {
position: absolute;
top: 0;
right: 0;
@@ -65,7 +65,7 @@ const emit = defineEmits<{
);
}
.community-card__logo {
.official-card__logo {
position: relative;
z-index: var(--z-content);
box-sizing: border-box;
@@ -78,14 +78,19 @@ const emit = defineEmits<{
box-shadow: var(--shadow-sm);
}
.community-card__body {
.official-card__logo-img {
width: 100%;
height: 100%;
}
.official-card__body {
position: relative;
z-index: var(--z-content);
flex: 1;
min-width: 0;
}
.community-card__arrow {
.official-card__arrow {
position: relative;
z-index: var(--z-content);
display: flex;
@@ -97,14 +102,14 @@ const emit = defineEmits<{
border-radius: 999rpx;
}
.community-card__title-row {
.official-card__title-row {
display: flex;
gap: 16rpx;
align-items: center;
margin-top: 14rpx;
}
.community-card__title {
.official-card__title {
flex-shrink: 0;
font-size: 32rpx;
font-weight: 600;
@@ -114,14 +119,14 @@ const emit = defineEmits<{
}
/* wd-tag 外层是自定义组件节点,压掉其行高避免与标题错位 */
.community-card__tag {
.official-card__tag {
display: flex;
flex-shrink: 0;
align-items: center;
line-height: 1;
}
.community-card__desc {
.official-card__desc {
display: -webkit-box;
margin-top: 10rpx;
overflow: hidden;
@@ -1,14 +1,14 @@
<template>
<view class="profile-card">
<view class="profile-card__header">
<view class="profile-card__left" @click="emit('profile')">
<view class="profile-card__avatar-wrap" @click="emit('profile')">
<image class="profile-card__avatar" :src="avatar" mode="aspectFill" lazy-load />
<view v-if="isAuthenticated" class="profile-card__online-dot" />
<view v-if="isAuthenticated" class="profile-card__auth-dot" />
</view>
<view class="profile-card__main" @click="emit('profile')">
<view class="profile-card__info" @click="emit('profile')">
<view class="profile-card__top">
<text class="profile-card__name">{{ name }}</text>
<text class="profile-card__name">{{ displayName }}</text>
</view>
<view v-if="isAuthenticated" class="profile-card__tags">
@@ -29,17 +29,13 @@
<text v-else class="profile-card__hint">登录使用更多功能</text>
</view>
<view
v-if="isAuthenticated"
class="profile-card__scan"
aria-label="扫一扫"
@click.stop="emit('scan')"
>
<!-- 组件内唯一的扫描入口:调起相机扫 PC 端登录二维码,登录在扫码确认页完成 -->
<view v-if="isAuthenticated" class="profile-card__scan" @click.stop="emit('scan')">
<wd-icon name="scan" size="18" color="var(--color-text-inverse)" />
</view>
<view v-else class="profile-card__action" @click.stop="emit('login')">
<wd-button custom-class="profile-card__button" size="small">立即登录</wd-button>
<view v-else class="profile-card__login" @click.stop="emit('login')">
<wd-button custom-class="profile-card__login-button" size="small">立即登录</wd-button>
</view>
</view>
</view>
@@ -47,13 +43,20 @@
<script lang="ts" setup>
defineProps<{
/** 已登录时展示账号与部门,未登录展示登录入口 */
isAuthenticated: boolean;
avatar: string;
name: string;
/** 展示用昵称,区别于账号 username */
displayName: string;
username: string;
deptName: string;
}>();
/**
* profile / login / scan:只上报点击意图
*
* scan 表示请求调起扫码流程,票据校验与登录在扫码确认页完成。
*/
const emit = defineEmits<{
profile: [];
login: [];
@@ -62,18 +65,19 @@ const emit = defineEmits<{
</script>
<style lang="scss" scoped>
/* 卡片落在 Hero 主色渐变上,前景固定白色:背景始终用半透明玻璃色,
不支持 backdrop-filter 时只是少了模糊,不会退化成白底白字 */
.profile-card {
position: relative;
display: flex;
padding: 28rpx 28rpx;
overflow: hidden;
background: var(--color-bg-card-alpha-95);
background: linear-gradient(135deg, var(--color-glass) 0%, var(--color-glass-light) 100%);
border: 1rpx solid var(--color-border-glass);
border-radius: 28rpx;
box-shadow: var(--shadow-md);
@supports (backdrop-filter: blur(20px)) or (-webkit-backdrop-filter: blur(20px)) {
background: linear-gradient(135deg, var(--color-glass) 0%, var(--color-glass-light) 100%);
-webkit-backdrop-filter: blur(20px);
backdrop-filter: blur(20px);
}
@@ -86,7 +90,7 @@ const emit = defineEmits<{
width: 100%;
}
.profile-card__left {
.profile-card__avatar-wrap {
position: relative;
flex-shrink: 0;
width: 120rpx;
@@ -103,7 +107,8 @@ const emit = defineEmits<{
box-shadow: var(--shadow-sm);
}
.profile-card__online-dot {
/* 认证状态标识:依据登录态,不表示实时在线 */
.profile-card__auth-dot {
position: absolute;
right: 4rpx;
bottom: 4rpx;
@@ -114,7 +119,7 @@ const emit = defineEmits<{
border-radius: 50%;
}
.profile-card__main {
.profile-card__info {
flex: 1;
min-width: 0;
}
@@ -153,21 +158,21 @@ const emit = defineEmits<{
align-items: center;
align-self: flex-start;
justify-content: center;
width: 64rpx;
height: 64rpx;
width: 88rpx;
height: 88rpx;
margin-left: auto;
background: var(--color-glass-light);
border: 1rpx solid var(--color-border-glass);
border-radius: 999rpx;
}
.profile-card__action {
.profile-card__login {
flex-shrink: 0;
align-self: center;
margin-left: auto;
}
.profile-card__button {
.profile-card__login-button {
flex-shrink: 0;
min-width: 156rpx;
height: 72rpx;
@@ -1,7 +1,7 @@
<template>
<view class="quick-cards">
<view class="quick-actions">
<view class="quick-card" @click="emit('profile')">
<view class="quick-card__icon quick-card__icon--info">
<view class="quick-card__icon quick-card__icon--primary">
<wd-icon name="user" size="28" color="var(--color-primary)" />
</view>
<view class="quick-card__body">
@@ -22,6 +22,7 @@
</template>
<script lang="ts" setup>
/** profile / account:只上报点击意图,登录校验与跳转由父级决定 */
const emit = defineEmits<{
profile: [];
account: [];
@@ -29,14 +30,13 @@ const emit = defineEmits<{
</script>
<style lang="scss" scoped>
.quick-cards {
.quick-actions {
position: relative;
z-index: var(--z-sticky);
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 20rpx;
margin-top: 24rpx;
margin-bottom: 0;
}
.quick-card {
@@ -62,8 +62,8 @@ const emit = defineEmits<{
height: 84rpx;
border-radius: 22rpx;
&--info {
background: var(--color-primary-light);
&--primary {
background: var(--color-primary-soft);
}
&--success {
+133 -110
View File
@@ -1,42 +1,47 @@
<template>
<view>
<view class="mine-hero" :style="{ paddingTop: `${navbar.totalHeight.value}px` }">
<custom-navbar
:bg-color="isScrolled ? headerBackground : 'transparent'"
<view class="mine">
<view class="mine__hero" :style="{ paddingTop: `${navbar.totalHeightPx.value}px` }">
<view class="mine__hero-bg" :style="{ background: heroGradient }" />
<app-navbar
:background="isScrolled ? heroGradient : 'transparent'"
title-color="var(--color-text-inverse)"
icon-color="var(--color-text-inverse)"
:show-back="false"
:placeholder="false"
>
<template #center>
<text class="mine-navbar__title">个人中心</text>
<text class="mine__navbar-title">个人中心</text>
</template>
</custom-navbar>
</app-navbar>
<view class="mine-hero__content">
<view class="mine__hero-content">
<profile-card
:is-authenticated="isAuthenticated"
:avatar="avatar"
:name="displayName"
:display-name="displayName"
:username="username"
:dept-name="deptName"
@profile="openProfile"
@profile="navigateToProfile"
@login="navigateToLogin"
@scan="scanLogin"
@scan="scanForLogin"
/>
<view class="community-slot">
<view class="community-slot__bg" :style="{ background: headerBackground }" />
<community-card @open="openOfficialAccount" />
<view class="mine__community">
<official-account-card @open="navigateToOfficialAccount" />
</view>
<quick-cards v-if="isAuthenticated" @profile="openProfile" @account="openAccount" />
<quick-actions
v-if="isAuthenticated"
@profile="navigateToProfile"
@account="navigateToAccountSecurity"
/>
</view>
</view>
<view class="mine-body">
<menu-section title="系统工具" :items="toolMenus" @select="handleMenuSelect" />
<menu-section title="帮助与支持" :items="helpMenus" @select="handleMenuSelect" />
<view class="mine__body">
<menu-section title="系统工具" :items="toolMenuItems" @select="handleMenuSelect" />
<menu-section title="帮助与支持" :items="helpMenuItems" @select="handleMenuSelect" />
<wd-button
v-if="isAuthenticated"
@@ -44,19 +49,16 @@
variant="plain"
size="large"
block
@click="confirmLogout"
:disabled="isLoggingOut"
@click="requestLogout"
>
退出登录
</wd-button>
</view>
<wd-loading
v-if="isClearing"
v-model="isClearing"
text="正在清理..."
mask
custom-class="loading-center"
/>
<view v-if="isClearing" class="mine__cache-loading">
<wd-loading text="正在清理..." inherit-color />
</view>
</view>
</template>
@@ -66,14 +68,14 @@ import { onPageScroll, onShow } from "@dcloudio/uni-app";
import { storeToRefs } from "pinia";
import { useUserStore, useThemeStore } from "@/store";
import { useRouter } from "uni-mini-router";
import { useNavbar } from "@/composables/useNavbar";
import { useNavbarMetrics } from "@/composables/useNavbarMetrics";
import { useScanLogin } from "@/composables/useScanLogin";
import { useLogout } from "@/composables/useLogout";
import { useCacheCleaner } from "@/composables/useCacheCleaner";
import ProfileCard from "./components/profile-card.vue";
import CommunityCard from "./components/community-card.vue";
import QuickCards from "./components/quick-cards.vue";
import MenuSection, { type MenuItem } from "./components/menu-section.vue";
import ProfileCard from "./components/ProfileCard.vue";
import OfficialAccountCard from "./components/OfficialAccountCard.vue";
import QuickActions from "./components/QuickActions.vue";
import MenuSection, { type SettingsMenuItem } from "./components/MenuSection.vue";
definePage({
name: "mine",
@@ -81,14 +83,18 @@ definePage({
layout: "tabbar",
});
// 菜单项:route 跳转页面,action 执行本地动作
type SettingsMenuEntry = SettingsMenuItem &
({ kind: "route"; target: string; requiresAuth?: boolean } | { kind: "action" });
const userStore = useUserStore();
const themeStore = useThemeStore();
const router = useRouter();
const navbar = useNavbar({ hasTabbar: true });
const { scanLogin } = useScanLogin();
const { confirmLogout } = useLogout();
const navbar = useNavbarMetrics();
const { scanForLogin } = useScanLogin();
const { isLoggingOut, requestLogout } = useLogout();
/** 滚动后导航栏补上渐变背景,否则内容会从透明导航栏下穿过 */
// 滚动后导航栏补上背景,否则内容会从透明导航栏下穿过
const isScrolled = ref(false);
onPageScroll(({ scrollTop }) => {
isScrolled.value = scrollTop > 0;
@@ -107,40 +113,51 @@ const displayName = computed(() =>
const username = computed(() => userInfo.value?.username || "未设置账号");
const deptName = computed(() => (isAuthenticated.value ? userInfo.value?.deptName || "" : ""));
const headerBackground = computed(() => {
// 主色渐变:Hero 画布与滚动后的导航栏共用一份,主题色为 6 位十六进制时叠加透明度
const heroGradient = computed(() => {
const color = themeStore.themeVars.colorTheme || "var(--color-primary)";
const colorWithAlpha = color.length === 7 ? `${color}E6` : color;
const colorWithAlpha2 = color.length === 7 ? `${color}CC` : color;
return `linear-gradient(135deg, ${colorWithAlpha} 0%, ${colorWithAlpha2} 100%)`;
const heroStartColor = color.length === 7 ? `${color}E6` : color;
const heroEndColor = color.length === 7 ? `${color}CC` : color;
return `linear-gradient(135deg, ${heroStartColor} 0%, ${heroEndColor} 100%)`;
});
const appVersion = ref("1.0.0");
const {
usageText: storageUsageText,
isClearing,
loadUsage: loadStorageUsage,
clear: clearCache,
} = useCacheCleaner();
// 版本号:构建时注入,小程序端会被发布版本覆盖
const appVersion = ref(import.meta.env.VITE_APP_VERSION);
const { usageText: storageUsageText, isClearing, loadUsage, clearCache } = useCacheCleaner();
// 常用功能在前,维护操作在后
const toolMenus = computed<MenuItem[]>(() => [
const toolMenuItems = computed<SettingsMenuEntry[]>(() => [
{
key: "notice",
id: "notice",
kind: "route",
target: "/subPages/work/notice/index",
requiresAuth: true,
icon: "notification",
tone: "primary",
title: "消息通知",
desc: "查看系统通知与公告",
},
{ key: "theme", icon: "settings", tone: "primary", title: "主题设置", desc: "主题色与明暗模式" },
{
key: "network",
id: "theme",
kind: "route",
target: "/subPages/mine/settings/theme/index",
icon: "settings",
tone: "primary",
title: "主题设置",
desc: "主题色与明暗模式",
},
{
id: "network",
kind: "route",
target: "/subPages/mine/settings/network/index",
icon: "wifi",
tone: "primary",
title: "网络检测",
desc: "检测网络与服务器连接",
},
{
key: "clear-cache",
id: "clear-cache",
kind: "action",
icon: "delete",
tone: "danger",
title: "清理缓存",
@@ -149,16 +166,20 @@ const toolMenus = computed<MenuItem[]>(() => [
},
]);
const helpMenus = computed<MenuItem[]>(() => [
const helpMenuItems = computed<SettingsMenuEntry[]>(() => [
{
key: "agreement",
id: "agreement",
kind: "route",
target: "/subPages/mine/settings/agreement/index",
icon: "file",
tone: "success",
title: "用户协议",
desc: "了解产品使用规则",
},
{
key: "about",
id: "about",
kind: "route",
target: "/subPages/mine/about/index",
icon: "info-circle",
tone: "info",
title: "关于系统",
@@ -167,146 +188,148 @@ const helpMenus = computed<MenuItem[]>(() => [
},
]);
const menuRoutes: Record<string, string> = {
notice: "/subPages/work/notice/index",
network: "/subPages/mine/settings/network/index",
theme: "/subPages/mine/settings/theme/index",
agreement: "/subPages/mine/settings/agreement/index",
about: "/subPages/mine/about/index",
};
// 菜单分发:先按 id 找到配置,再按 kind 走跳转或本地动作
function handleMenuSelect(id: string) {
const entry = [...toolMenuItems.value, ...helpMenuItems.value].find((item) => item.id === id);
if (!entry) return;
function handleMenuSelect(key: string) {
if (key === "clear-cache") {
if (entry.kind === "action") {
clearCache();
return;
}
if (key === "notice" && !isAuthenticated.value) {
if (entry.requiresAuth && !isAuthenticated.value) {
navigateToLogin();
return;
}
const path = menuRoutes[key];
if (path) {
router.push({ path });
}
router.push({ path: entry.target });
}
// 登录
const navigateToLogin = () => {
// 登录页带回跳地址,登录成功后原路返回
function navigateToLogin() {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const currentPagePath = `/${currentPage.route}`;
router.push({ path: "/pages/login/index", query: { redirect: currentPagePath } });
};
}
const openProfile = () => {
// 资料页要求登录,未登录先跳登录页
function navigateToProfile() {
if (!isAuthenticated.value) {
navigateToLogin();
return;
}
router.push({ path: "/subPages/mine/profile/index" });
};
}
// 账号和安全
const openAccount = () => {
// 账号安全页要求登录,未登录先跳登录页
function navigateToAccountSecurity() {
if (!isAuthenticated.value) {
navigateToLogin();
return;
}
router.push({ path: "/subPages/mine/account/index" });
};
}
// 有来技术公众号
const openOfficialAccount = () => {
// 公众号介绍页对游客开放,不需要登录
function navigateToOfficialAccount() {
uni.navigateTo({
url: "/subPages/mine/official/index",
});
};
}
// 已登录但资料为空:token 在、userInfo 缺失的断档态由补拉修复
const hasUserProfile = computed(() => {
const info = userInfo.value;
return !!(info && (info.userId || info.username || info.nickname));
});
const loadUserInfoIfNeeded = async () => {
// 已登录但资料未加载时补拉(loadUserInfo),专治「token 在、userInfo 空」的断档态
// 资料未加载时补拉一次,失败不阻塞页面渲染
async function ensureUserInfoLoaded() {
if (!isAuthenticated.value || hasUserProfile.value) return;
try {
await userStore.loadUserInfo();
} catch {
// ignore
// 补拉失败保持空态,下次 onShow 再试
}
};
}
const syncMiniProgramVersion = () => {
// 小程序端版本号以发布版本为准,其他端取构建时注入的包版本
function syncAppVersion() {
// #ifdef MP-WEIXIN
appVersion.value = uni.getAccountInfoSync().miniProgram.version || "1.0.0";
appVersion.value = uni.getAccountInfoSync().miniProgram.version || appVersion.value;
// #endif
};
}
onShow(async () => {
await loadUserInfoIfNeeded();
await loadStorageUsage();
syncMiniProgramVersion();
await ensureUserInfoLoaded();
await loadUsage();
syncAppVersion();
});
</script>
<style lang="scss" scoped>
.mine-hero {
position: relative;
padding-bottom: 24rpx;
overflow: visible;
.mine {
min-height: 100vh;
}
/* 渐变以社区卡片为锚点:底边压在卡片中线、上沿穿到导航栏后面,形成卡片被背景分割的效果 */
.community-slot {
.mine__hero {
position: relative;
}
.community-slot__bg {
/* Hero 画布由页面拥有:固定高度从屏幕顶部铺到社区卡片中线,不随卡片显隐或文案换行变化 */
.mine__hero-bg {
position: absolute;
right: -28rpx;
bottom: 50%;
left: -28rpx;
z-index: -1;
height: 800rpx;
top: 0;
right: 0;
left: 0;
z-index: var(--z-base);
height: 480rpx;
pointer-events: none;
}
.mine-hero__content {
.mine__hero-content {
position: relative;
z-index: var(--z-sticky);
z-index: var(--z-content);
display: flex;
flex-direction: column;
gap: 20rpx;
padding: 20rpx 28rpx 0;
}
.mine-navbar__title {
.mine__community {
position: relative;
}
.mine__navbar-title {
font-size: 32rpx;
font-weight: 600;
color: var(--color-text-inverse);
letter-spacing: 2rpx;
}
.mine-body {
.mine__body {
position: relative;
z-index: var(--z-base);
z-index: var(--z-content);
display: flex;
flex-direction: column;
gap: 24rpx;
padding: 0 28rpx 40rpx;
margin-top: 0;
padding: 24rpx 28rpx 40rpx;
background: var(--color-bg-page);
border-top-left-radius: 48rpx;
border-top-right-radius: 48rpx;
}
.loading-center {
.mine__cache-loading {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: var(--z-overlay);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: var(--color-text-inverse);
background: var(--color-overlay);
border-radius: 24rpx;
}
</style>
+12 -14
View File
@@ -1,17 +1,15 @@
<template>
<view>
<custom-navbar title="工作台" :show-back="false" placeholder />
<!-- tabbar 壳为全出血(index/mine 的沉浸式头需要贴边),工作台网格用工具类补齐
横向 32rpx / 顶部 16rpx,与 default 壳的 .page 内边距保持一致 -->
<app-navbar title="工作台" :show-back="false" placeholder />
<!-- tabbar 壳为全出血(index/mine 的沉浸式头需要贴边),工作台网格需要自己补横向留白 -->
<view class="px-32rpx pt-16rpx">
<template v-for="(item, index) in visibleGridList" :key="index">
<template v-for="(item, index) in visibleGroups" :key="index">
<wd-card :title="item.title">
<wd-grid clickable :column="4">
<wd-grid-item
v-for="(child, childIndex) in item.children"
:key="childIndex"
use-slot
@click="handleNavClick(child)"
@click="navigate(child)"
>
<view class="p-2">
<image class="w-72rpx h-72rpx rounded-8rpx" :src="child.icon" />
@@ -29,7 +27,7 @@
import { computed } from "vue";
import { useNavigation } from "@/composables/useNavigation";
import { workMenuGroups } from "@/config/work-menu";
import { hasPermission as checkPermission } from "@/utils/permission";
import { hasPermission } from "@/utils/permission";
definePage({
name: "work",
@@ -40,20 +38,20 @@ definePage({
layout: "tabbar",
});
const { handleNavClick } = useNavigation();
const { navigate } = useNavigation();
// 检查是否有权限
const hasPermission = (perm: string) => {
// 无权限码的菜单视为公开入口,其余按当前账号的权限码判断
const isMenuAllowed = (perm: string) => {
if (!perm) return true;
return checkPermission(perm);
return hasPermission(perm);
};
// 根据权限过滤后的菜单列表
const visibleGridList = computed(() => {
// 根据权限过滤后的菜单分组,未授权分组整体不展示
const visibleGroups = computed(() => {
return workMenuGroups
.map((group) => ({
...group,
children: group.children.filter((item) => hasPermission(item.perm)),
children: group.children.filter((item) => isMenuAllowed(item.perm)),
}))
.filter((group) => group.children.length > 0);
});