Commit 2a2d8788 by liimin

refactor(tab&router): 重构Tab导航架构,整合页面至统一主容器

统一全站Tab导航与路由逻辑,将所有Tab页面整合到pages/main/index统一容器中:
- 替换原/pages/index/index为/pages/main/index作为根Tab路由,修正全站所有路由跳转路径
- 新增Tab注册表统一管理组件,支持懒加载提升首屏性能
- 重构个人中心与EntryGrid组件,优化代码可读性与渲染性能
- 新增任务面板数据缓存,避免Tab切换时的loading闪烁问题
- 修复TabBar选中态样式,优化横竖屏布局适配逻辑
- 规范全站导航行为,修正多处路由跳转不一致问题
1 parent 540d1b39
<template> <template>
<view :class="gridClass"> <view :class="gridClass">
<view class="module-entry-grid__list"> <view class="module-entry-grid__list">
<view v-for="(item, index) in entryItems" <view v-for="(item, index) in resolvedItems"
:key="index" :key="index"
class="module-entry-grid__item" class="module-entry-grid__item"
:class="getItemClass(item)" :class="item.itemClass"
@click="onEntryClick(getItemKey(item))"> @click="onEntryClick(item.key)">
<image class="module-entry-grid__icon" <image class="module-entry-grid__icon"
mode="aspectFit" mode="aspectFit"
:src="getItemIconSrc(item)" /> :src="item.iconSrc" />
<text :class="getLabelClass(item)">{{ getItemLabel(item) }}</text> <text :class="item.labelClass">{{ item.label }}</text>
</view> </view>
</view> </view>
</view> </view>
...@@ -31,50 +31,46 @@ const emit = defineEmits<{ ...@@ -31,50 +31,46 @@ const emit = defineEmits<{
const orientationHook = useOrientation(); const orientationHook = useOrientation();
const entryItems = computed((): UTSJSONObject[] => {
return props.items;
});
const gridClass = computed((): string => { const gridClass = computed((): string => {
const isPortraitRef = orientationHook.isPortrait as Ref<boolean>; const isPortrait = (orientationHook.isPortrait as Ref<boolean>).value == true;
if (isPortraitRef.value == true) { if (isPortrait) {
return "module-entry-grid"; return "module-entry-grid";
} }
const windowHeightRef = orientationHook.windowHeight as Ref<number>; const wh = (orientationHook.windowHeight as Ref<number>).value;
if (windowHeightRef.value <= 430) { return wh <= 430
return "module-entry-grid module-entry-grid--landscape module-entry-grid--compact"; ? "module-entry-grid module-entry-grid--landscape module-entry-grid--compact"
} : "module-entry-grid module-entry-grid--landscape";
return "module-entry-grid module-entry-grid--landscape";
}); });
function getItemKey(item: UTSJSONObject): string { type EntryItemView = {
const value = item["key"]; key: string
return value != null ? `${value}` : ""; label: string
} iconSrc: string
itemClass: string
function getItemLabel(item: UTSJSONObject): string { labelClass: string
const value = item["label"]; }
return value != null ? `${value}` : "";
} /** 预计算所有 item 的展示数据,避免模板中逐项多次函数调用 */
const resolvedItems = computed((): EntryItemView[] => {
function getItemIconSrc(item: UTSJSONObject): string { const result: EntryItemView[] = [];
const key = getItemKey(item); const activeKey = props.activeKey;
const fieldName = key == props.activeKey ? "activeIconSrc" : "iconSrc"; for (let i = 0; i < props.items.length; i++) {
const value = item[fieldName]; const item = props.items[i];
return value != null ? `${value}` : ""; const key = `${item["key"] ?? ""}`;
} const active = key == activeKey;
const iconField = active ? "activeIconSrc" : "iconSrc";
function isItemActive(item: UTSJSONObject): boolean { result.push({
return getItemKey(item) == props.activeKey; key: key,
} label: `${item["label"] ?? ""}`,
iconSrc: `${item[iconField] ?? ""}`,
function getItemClass(item: UTSJSONObject): string { itemClass: active ? "module-entry-grid__item--active" : "",
return isItemActive(item) ? "module-entry-grid__item--active" : ""; labelClass: active
} ? "module-entry-grid__label module-entry-grid__label--active"
: "module-entry-grid__label",
function getLabelClass(item: UTSJSONObject): string { } as EntryItemView);
return isItemActive(item) ? "module-entry-grid__label module-entry-grid__label--active" : "module-entry-grid__label"; }
} return result;
});
function onEntryClick(key: string): void { function onEntryClick(key: string): void {
if (key == props.activeKey) return; if (key == props.activeKey) return;
......
...@@ -11,9 +11,11 @@ import { updateOrientation, useScreenVars } from '@/services/adapter/hooks/index ...@@ -11,9 +11,11 @@ import { updateOrientation, useScreenVars } from '@/services/adapter/hooks/index
const props = defineProps<{ const props = defineProps<{
pageVars?: UTSJSONObject | null pageVars?: UTSJSONObject | null
}>() }>()
// 通过 provide 注入 pageVars,供子组件使用 // 通过 provide 注入 pageVars(响应式),供子组件使用
provide('PAGE_VARS', props.pageVars ?? null) provide('PAGE_VARS', computed((): UTSJSONObject | null => props.pageVars ?? null))
const styleObject = useScreenVars(props.pageVars ?? null) const styleObject = useScreenVars(props.pageVars ?? null, (): UTSJSONObject | null => {
return props.pageVars ?? null
})
</script> </script>
<style> <style>
......
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
<image class="landscape-vertical-tabs__icon" <image class="landscape-vertical-tabs__icon"
mode="aspectFit" mode="aspectFit"
:src="index === currentTabIndex ? item.iconSrcActive : item.iconSrcInactive" /> :src="index === currentTabIndex ? item.iconSrcActive : item.iconSrcInactive" />
<text class="landscape-vertical-tabs__label">{{ item.label }}</text> <text class="landscape-vertical-tabs__label"
:style="{ color: index === currentTabIndex ? '#3773f8' : '#8a98b5', fontWeight: index === currentTabIndex ? '500' : '400' }">{{ item.label }}</text>
</view> </view>
</view> </view>
</view> </view>
...@@ -311,7 +312,7 @@ function handleSwitchStore(): void { ...@@ -311,7 +312,7 @@ function handleSwitchStore(): void {
white-space: nowrap; white-space: nowrap;
} }
.landscape-vertical-tabs__item--active .landscape-vertical-tabs__label { .landscape-vertical-tabs__label--active {
color: #3773f8; color: #3773f8;
font-weight: 500; font-weight: 500;
} }
......
...@@ -56,10 +56,12 @@ import personVars from "@/pages/person/styles/index.vars"; ...@@ -56,10 +56,12 @@ import personVars from "@/pages/person/styles/index.vars";
defineSlots(); defineSlots();
const props = defineProps<{ const props = defineProps<{
/** 当前 tab 页下标:0 首页、1 我的(与 un-tabbar 高亮一致) */ /** 当前 tab 页下标:0 首页、1 任务、2 录单、3 报表、4 我的 */
activeTabIndex: number activeTabIndex: number
/** 页面 CSS 变量,不传时根据 activeTabIndex 自动匹配 */ /** 页面 CSS 变量,不传时根据 activeTabIndex 自动匹配 */
pageVars?: UTSJSONObject pageVars?: UTSJSONObject
/** 设为 true 时,tab 切换仅 emit 事件(父组件自行管理切换),不执行 navigateToTab */
preventNavigate?: boolean
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
...@@ -71,8 +73,7 @@ const emit = defineEmits<{ ...@@ -71,8 +73,7 @@ const emit = defineEmits<{
const orientationHook = useOrientation(); const orientationHook = useOrientation();
const shellIsPortrait = computed((): boolean => { const shellIsPortrait = computed((): boolean => {
const ip = orientationHook.isPortrait as Ref<boolean>; return (orientationHook.isPortrait as Ref<boolean>).value == true;
return ip.value == true;
}); });
/** 页面 CSS 变量:优先使用显式传入,否则根据 activeTabIndex 自动匹配 */ /** 页面 CSS 变量:优先使用显式传入,否则根据 activeTabIndex 自动匹配 */
...@@ -103,9 +104,13 @@ const onSwitchStore = _tabbar.onSwitchStore; ...@@ -103,9 +104,13 @@ const onSwitchStore = _tabbar.onSwitchStore;
const onSwitchStoreVisible = _tabbar.onSwitchStoreVisible; const onSwitchStoreVisible = _tabbar.onSwitchStoreVisible;
const onSwitchStoreDone = _tabbar.onSwitchStoreDone; const onSwitchStoreDone = _tabbar.onSwitchStoreDone;
/** 统一处理 tab 切换:导航页面 + 转发事件给外部 */ /** 统一处理 tab 切换:有 preventNavigate 时仅 emit,否则走旧逻辑 navigate */
function onTabChange(name: string | number): void { function onTabChange(name: string | number): void {
const idx = name as number; const idx = name as number;
if (props.preventNavigate == true) {
emit("tabChange", idx);
return;
}
navigateToTab(idx, props.activeTabIndex); navigateToTab(idx, props.activeTabIndex);
emit("tabChange", name); emit("tabChange", name);
} }
......
...@@ -108,35 +108,11 @@ function switchTabPage(pagesJsonPath: string): void { ...@@ -108,35 +108,11 @@ function switchTabPage(pagesJsonPath: string): void {
} }
/** /**
* 统一 tab 导航函数:可在 TabBar 子组件内部直接调用, * 统一 tab 导航函数(旧逻辑保留,供未改造页面兜底)。
* 外部同时可通过 @tab-change 事件监听做差异化操作。 * 新架构下所有 tab 页面已合并到 pages/main/index,此处统一跳回主容器。
*/ */
export function navigateToTab(index: number, currentTabIndex: number): void { export function navigateToTab(_index: number, _currentTabIndex: number): void {
if (index == currentTabIndex) { uni.reLaunch({ url: "/pages/main/index" });
return;
}
if (index == 0) {
switchTabPage("pages/index/index");
return;
}
if (index == 1) {
switchTabPage("pages/tasks/tasks");
return;
}
if (index == 2) {
// uni.navigateTo({ url: "/pages/orderEntry/index" });
switchTabPage("pages/orderEntry/index");
return;
}
if (index == 3) {
switchTabPage("pages/reports/reports");
return;
}
if (index == 4) {
switchTabPage("pages/person/myCenter");
return;
}
} }
export function useHomeFrameTabbar(source: HomeFrameTabbarSource) { export function useHomeFrameTabbar(source: HomeFrameTabbarSource) {
......
...@@ -116,9 +116,9 @@ function jumpPage(item: MerchantItem, openSceneArr: number[]): void { ...@@ -116,9 +116,9 @@ function jumpPage(item: MerchantItem, openSceneArr: number[]): void {
newUserInfo.sceneType = usedCarSceneType; newUserInfo.sceneType = usedCarSceneType;
storage.set("userInfo", newUserInfo, 0); storage.set("userInfo", newUserInfo, 0);
uni.switchTab({ uni.switchTab({
url: "/pages/index/index", url: "/pages/main/index",
fail: (_err: any) => { fail: (_err: any) => {
uni.reLaunch({ url: "/pages/index/index" }); uni.reLaunch({ url: "/pages/main/index" });
} }
}); });
}).catch((error): void => { }).catch((error): void => {
......
...@@ -112,7 +112,7 @@ function jump(info: UTSJSONObject, data: any | null): void { ...@@ -112,7 +112,7 @@ function jump(info: UTSJSONObject, data: any | null): void {
storage.remove("boutique_YQorderSetting"); storage.remove("boutique_YQorderSetting");
const url = "/pages/index/index"; const url = "/pages/main/index";
console.log(`准备跳转: ${ url}`); console.log(`准备跳转: ${ url}`);
uni.switchTab({ uni.switchTab({
url, url,
...@@ -125,7 +125,7 @@ function jump(info: UTSJSONObject, data: any | null): void { ...@@ -125,7 +125,7 @@ function jump(info: UTSJSONObject, data: any | null): void {
info.channelType = 1; info.channelType = 1;
storage.set("userInfo", info, 0); storage.set("userInfo", info, 0);
const url = "/pages/index/index"; const url = "/pages/main/index";
console.log(`准备跳转(catch): ${ url}`); console.log(`准备跳转(catch): ${ url}`);
uni.switchTab({ uni.switchTab({
url, url,
......
...@@ -35,19 +35,12 @@ ...@@ -35,19 +35,12 @@
} }
}, },
{ {
"path": "pages/person/myCenter", "path": "pages/main/index",
"style": { "style": {
"navigationStyle": "custom" "navigationStyle": "custom"
} }
}, },
{ {
"path": "pages/index/index",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "首页"
}
},
{
"path": "pages/index/reception", "path": "pages/index/reception",
"style": { "style": {
"navigationStyle": "custom", "navigationStyle": "custom",
...@@ -65,7 +58,7 @@ ...@@ -65,7 +58,7 @@
"path": "pages/equity/detail/index", "path": "pages/equity/detail/index",
"style": { "style": {
"navigationStyle": "custom", "navigationStyle": "custom",
"popGesture": "none" // 禁用 iOS 系统侧滑返回,使用自定义检测 "popGesture": "none"
} }
}, },
{ {
...@@ -104,13 +97,6 @@ ...@@ -104,13 +97,6 @@
} }
}, },
{ {
"path": "pages/tasks/tasks",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "任务"
}
},
{
"path": "pages/tasks/dailyReportCreate", "path": "pages/tasks/dailyReportCreate",
"style": { "style": {
"navigationStyle": "custom", "navigationStyle": "custom",
...@@ -130,20 +116,6 @@ ...@@ -130,20 +116,6 @@
"navigationStyle": "custom", "navigationStyle": "custom",
"navigationBarTitleText": "策略详情" "navigationBarTitleText": "策略详情"
} }
},
{
"path": "pages/orderEntry/index",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "录单"
}
},
{
"path": "pages/reports/reports",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "报表"
}
} }
], ],
...@@ -182,38 +154,13 @@ ...@@ -182,38 +154,13 @@
"fontSize": "11px", "fontSize": "11px",
"iconWidth": "24px", "iconWidth": "24px",
"height": "50px", "height": "50px",
// ✅ 性能优化:TabBar 切换动画
"animation": false, "animation": false,
"list": [ "list": [
{ {
"pagePath": "pages/index/index", "pagePath": "pages/main/index",
"text": "首页", "text": "首页",
"iconPath": "static/images/tabbar/home.png", "iconPath": "static/images/tabbar/home.png",
"selectedIconPath": "static/images/tabbar/home-active.png" "selectedIconPath": "static/images/tabbar/home-active.png"
},
{
"pagePath": "pages/tasks/tasks",
"text": "任务",
"iconPath": "static/images/tabbar/home.png",
"selectedIconPath": "static/images/tabbar/home-active.png"
},
{
"pagePath": "pages/orderEntry/index",
"text": "录单",
"iconPath": "static/images/tabbar/home.png",
"selectedIconPath": "static/images/tabbar/home-active.png"
},
{
"pagePath": "pages/person/myCenter",
"text": "我的",
"iconPath": "static/images/tabbar/study.png",
"selectedIconPath": "static/images/tabbar/study-active.png"
},
{
"pagePath": "pages/reports/reports",
"text": "报表",
"iconPath": "static/images/tabbar/home.png",
"selectedIconPath": "static/images/tabbar/home-active.png"
} }
] ]
}, },
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
<script setup lang="uts"> <script setup lang="uts">
onLoad(() => { onLoad(() => {
uni.switchTab({ uni.switchTab({
url: "/pages/index/index", url: "/pages/main/index",
fail: (_err: any) => { fail: (_err: any) => {
uni.reLaunch({ url: "/pages/index/index" }); uni.reLaunch({ url: "/pages/main/index" });
} }
}); });
}); });
......
...@@ -330,7 +330,7 @@ const doLogin = async (): Promise<void> => { ...@@ -330,7 +330,7 @@ const doLogin = async (): Promise<void> => {
profile["shopMerchantId"] = storeId; profile["shopMerchantId"] = storeId;
profile["shopMerchantName"] = storeName !== "" ? storeName : "门店"; profile["shopMerchantName"] = storeName !== "" ? storeName : "门店";
storage.set("userInfo", profile, 0); storage.set("userInfo", profile, 0);
uni.switchTab({ url: "/pages/index/index" }); uni.reLaunch({ url: "/pages/main/index" });
} else { } else {
// 多门店:跳转选店页 // 多门店:跳转选店页
switchTabSelectStoreWithStoresPayload(storesToUse); switchTabSelectStoreWithStoresPayload(storesToUse);
......
...@@ -151,7 +151,7 @@ function completeStoreSelection(): void { ...@@ -151,7 +151,7 @@ function completeStoreSelection(): void {
storage.remove("loginForm"); storage.remove("loginForm");
// 跳转首页 // 跳转首页
uni.switchTab({ url: "/pages/index/index" }); uni.reLaunch({ url: "/pages/main/index" });
} }
/** StoreGrid 选中回调 */ /** StoreGrid 选中回调 */
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
<script setup lang="uts"> <script setup lang="uts">
onLoad(() => { onLoad(() => {
uni.switchTab({ uni.switchTab({
url: "/pages/index/index", url: "/pages/main/index",
fail: (_err: any) => { fail: (_err: any) => {
uni.reLaunch({ url: "/pages/index/index" }); uni.reLaunch({ url: "/pages/main/index" });
} }
}); });
}); });
......
<template> <template>
<TabBarShell :active-tab-index="0">
<view class="index-shell-page"> <view class="index-shell-page">
<view class="index-shell-scene-stretch"> <view class="index-shell-scene-stretch">
<view class="tab-panel"> <view class="tab-panel">
<RecordStart /> <RecordStart />
<ScenePanelShell /> <ScenePanelShell />
</view> </view>
</view> </view>
</view> </view>
</TabBarShell>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import TabBarShell from "@/components/TabBar/TabBarShell.uvue";
import RecordStart from "./RecordStart.uvue"; import RecordStart from "./RecordStart.uvue";
import ScenePanelShell from "./ScenePanelShell.uvue"; import ScenePanelShell from "./ScenePanelShell.uvue";
import { provideSceneContext } from "./sceneContext.uts"; import { provideSceneContext } from "./sceneContext.uts";
import { storage } from "@/utils/storage.uts";
/** 当前场景 ID(默认精品,后续可从用户配置读取) */ defineProps<{
provideSceneContext("boutique"); activeIndex?: number
}>();
onShow(async () => { provideSceneContext("boutique");
const userInfoObj = storage.getUserInfo();
if (userInfoObj == null || JSON.stringify(userInfoObj) === "{}") {
storage.remove("userInfo");
storage.remove("sessionId");
uni.reLaunch({ url: "/pages/common/login/index" });
return;
}
const shopMerchantId = (userInfoObj["shopMerchantId"] as string) ?? "";
if (shopMerchantId == null || shopMerchantId === "") {
storage.remove("userInfo");
storage.remove("sessionId");
uni.reLaunch({ url: "/pages/common/login/index" });
return;
}
});
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
......
<template>
<TabBarShell :active-tab-index="activeTabIndex"
:page-vars="activePageVars"
:prevent-navigate="true"
@tab-change="handleTabChange">
<template v-for="(_, index) in TAB_PAGE_VARS" :key="index">
<view v-if="tabMounted[index]" v-show="activeTabIndex === index" class="tab-panel">
<component :is="tabComponents[index]" :active-index="activeTabIndex" />
</view>
</template>
</TabBarShell>
</template>
<script setup lang="uts">
import { computed, onShow, onMounted, ref } from "vue";
import { storage } from "@/utils/storage.uts";
import TabBarShell from "@/components/TabBar/TabBarShell.uvue";
import { TAB_PAGE_VARS, resolveTabComponent, getTotalTabCount } from "./tabRegistry.uts";
const totalCount = getTotalTabCount();
/** 当前激活的 tab 下标 */
const activeTabIndex = ref<number>(0);
// ── 以下定义顺序不能颠倒(UTS 不支持函数声明提升)──
function createLazyFlags(): boolean[] {
const arr: boolean[] = [];
for (let i = 0; i < totalCount; i++) {
arr.push(i == 0);
}
return arr;
}
/** 懒加载标记:根据注册表长度自动生成,避免启动时全部初始化 */
const tabMounted = ref<boolean[]>(createLazyFlags());
/** 预计算 tab 组件数组(模板不支持函数调用,用数组下标替代) */
const tabComponents = computed((): any[] => {
const result: any[] = [];
for (let i = 0; i < totalCount; i++) {
result.push(resolveTabComponent(i));
}
return result;
});
/** 当前 tab 对应的 pageVars */
const activePageVars = computed((): UTSJSONObject => {
return TAB_PAGE_VARS[activeTabIndex.value];
});
/** 标记 tab 为已激活(懒加载首次挂载) */
function activateTab(index: number): void {
const arr = tabMounted.value;
if (arr[index] == false) {
arr[index] = true;
}
}
function handleTabChange(index: number): void {
if (index == activeTabIndex.value) return;
activateTab(index);
activeTabIndex.value = index;
}
onMounted(() => {
activateTab(0);
});
/** 登录状态校验 */
onShow(() => {
const userInfoObj = storage.getUserInfo();
if (userInfoObj == null || (userInfoObj["shopMerchantId"] as string ?? "") == "") {
storage.remove("userInfo");
storage.remove("sessionId");
uni.reLaunch({ url: "/pages/common/login/index" });
return;
}
});
</script>
<style scoped lang="scss">
.tab-panel {
width: 100%;
height: 100%;
min-height: 0;
min-width: 0;
overflow: hidden;
}
</style>
/**
* Tab 注册表 —— 新增/删除 tab 的唯一维护入口。
*
* 新增 tab 步骤(共 3 步,全在此文件内):
* 1. 顶部添加 import 组件 + vars
* 2. TAB_COMPONENTS 数组末尾追加组件
* 3. TAB_PAGE_VARS 数组末尾追加对应的 vars
*
* index.uvue 无需任何修改。
*/
// ── Tab 内容组件 ──
import HomeContent from "@/pages/index/index.uvue";
import TasksContent from "@/pages/tasks/index.uvue";
import OrderContent from "@/pages/orderEntry/index.uvue";
import ReportsContent from "@/pages/reports/index.uvue";
import PersonContent from "@/pages/person/index.uvue";
// ── Tab 样式变量(横竖屏布局适配) ──
import homeVars from "@/pages/index/styles/index.vars";
import taskVars from "@/pages/tasks/styles/index.vars.uts";
import orderVars from "@/pages/orderEntry/styles/index.vars.uts";
import reportVars from "@/pages/reports/styles/index.vars.uts";
import personVars from "@/pages/person/styles/index.vars.uts";
// ════════════════════════════════════════════════════════
// 维护区:新增 tab 时在此追加对应项(顺序 = tab 展示顺序)
// ════════════════════════════════════════════════════════
const TAB_COMPONENTS = [
HomeContent,
TasksContent,
OrderContent,
ReportsContent,
PersonContent,
];
/** 导出供模板 v-for 遍历 + pageVars 查找 */
export const TAB_PAGE_VARS: UTSJSONObject[] = [
homeVars as UTSJSONObject,
taskVars as UTSJSONObject,
orderVars as UTSJSONObject,
reportVars as UTSJSONObject,
personVars as UTSJSONObject,
];
// ════════════════════════════════════════════════════════
// 自动 API(以下代码无需修改)
// ════════════════════════════════════════════════════════
export function resolveTabComponent(index: number): any {
return TAB_COMPONENTS[index];
}
export function getTotalTabCount(): number {
return TAB_COMPONENTS.length;
}
<template> <template>
<TabBarShell ref="shellRef" :active-tab-index="2" :page-vars="pageVars as UTSJSONObject">
<view class="order-entry-page"> <view class="order-entry-page">
<!-- 页面头部 --> <!-- 页面头部 -->
<view class="page-header"> <view class="page-header">
...@@ -38,19 +37,21 @@ ...@@ -38,19 +37,21 @@
</scroll-view> </scroll-view>
</view> </view>
</view> </view>
</TabBarShell>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import TabBarShell from "@/components/TabBar/TabBarShell.uvue";
import {getCustomersListApi} from "@/api/modules/customers.uts"; import {getCustomersListApi} from "@/api/modules/customers.uts";
import pageVars from "./styles/index.vars"; import { ref, computed, onMounted, nextTick, watch } from "vue";
import { ref, computed, onMounted, nextTick } from "vue";
import WorkOrder from "./components/WorkOrder.uvue"; import WorkOrder from "./components/WorkOrder.uvue";
import ContractOrder from "./components/ContractOrder.uvue"; import ContractOrder from "./components/ContractOrder.uvue";
import SalesOrder from "./components/SalesOrder.uvue"; import SalesOrder from "./components/SalesOrder.uvue";
import RecentOrderEntry from "./components/RecentOrderEntry.uvue"; import RecentOrderEntry from "./components/RecentOrderEntry.uvue";
import type { UnSelectOption } from '@/uni_modules/uview-unix' import type { UnSelectOption } from '@/uni_modules/uview-unix'
const props = defineProps<{
activeIndex?: number
}>();
type TabItem = { type TabItem = {
name: string; name: string;
iconType: string; iconType: string;
...@@ -83,6 +84,13 @@ onMounted(() => { ...@@ -83,6 +84,13 @@ onMounted(() => {
}); });
}); });
/** tab 切换到"录单"时刷新客户列表(替代原 onShow 逻辑) */
watch((): number => props.activeIndex ?? -1, (newVal: number): void => {
if (newVal == 2) {
getCustomersList();
}
});
const tabs = ref<TabItem[]>([ const tabs = ref<TabItem[]>([
{ name: "施工单", iconType: "warning-fill", componentName: WorkOrder }, { name: "施工单", iconType: "warning-fill", componentName: WorkOrder },
{ name: "合同单", iconType: "file-text-fill", componentName: ContractOrder }, { name: "合同单", iconType: "file-text-fill", componentName: ContractOrder },
...@@ -99,6 +107,5 @@ const activeEntryComponent = computed((): any => { ...@@ -99,6 +107,5 @@ const activeEntryComponent = computed((): any => {
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
// 引入拆分后的样式文件
@import "./styles/common.scss"; @import "./styles/common.scss";
</style> </style>
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { computed, onMounted, onUnmounted, ref, nextTick } from "vue"; import { computed, onMounted, onUnmounted, ref, nextTick, watch } from "vue";
import { useOrientation, useScreenVars } from "@/services/adapter/hooks"; import { useOrientation, useScreenVars } from "@/services/adapter/hooks";
...@@ -179,9 +179,7 @@ onMounted(() => { ...@@ -179,9 +179,7 @@ onMounted(() => {
}); });
}); });
onShow((): void => {
extractUserInfo();
});
onUnmounted((): void => { onUnmounted((): void => {
uni.$off(STORE_SWITCHED, handleStoreSwitched); uni.$off(STORE_SWITCHED, handleStoreSwitched);
......
<template> <template>
<TabBarShell ref="shellRef" <view>
:active-tab-index="4">
<!-- ✅ 修复空指针:骨架屏和真实内容同时渲染 -->
<PersonSkeleton v-if="!userInfoLoaded" /> <PersonSkeleton v-if="!userInfoLoaded" />
<MyCenterMain @loaded="onMyCenterLoaded" /> <MyCenterMain :active-index="activeIndex" @loaded="onMyCenterLoaded" />
</TabBarShell> </view>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { ref } from "vue"; import { ref } from "vue";
import TabBarShell from "@/components/TabBar/TabBarShell.uvue";
import MyCenterMain from "./MyCenterMain.uvue"; import MyCenterMain from "./MyCenterMain.uvue";
import PersonSkeleton from "./skeleton/PersonSkeleton.uvue"; import PersonSkeleton from "./skeleton/PersonSkeleton.uvue";
const shellRef = ref(null); const props = defineProps<{
activeIndex?: number
}>();
// ✅ 修复白屏:跟踪用户信息加载状态
const userInfoLoaded = ref<boolean>(false); const userInfoLoaded = ref<boolean>(false);
/**
* MyCenterMain 组件加载完成回调
*/
function onMyCenterLoaded(): void { function onMyCenterLoaded(): void {
userInfoLoaded.value = true; userInfoLoaded.value = true;
} }
......
<template> <template>
<TabBarShell ref="shellRef"
:active-tab-index="3"
:page-vars="reportPageVars as UTSJSONObject">
<view class="reports-page"> <view class="reports-page">
<view class="reports-layout"> <view class="reports-layout">
<view class="reports-entry-panel"> <view class="reports-entry-panel">
...@@ -39,14 +36,12 @@ ...@@ -39,14 +36,12 @@
</view> </view>
</view> </view>
</view> </view>
</TabBarShell>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { computed, ref } from "vue"; import { computed, ref } from "vue";
import EntryGrid from "@/components/EntryGrid.uvue"; import EntryGrid from "@/components/EntryGrid.uvue";
import TabBarShell from "@/components/TabBar/TabBarShell.uvue";
import BrandReportPanel from "./components/BrandReportPanel.uvue"; import BrandReportPanel from "./components/BrandReportPanel.uvue";
import ReportOverview from "./components/ReportOverview.uvue"; import ReportOverview from "./components/ReportOverview.uvue";
...@@ -57,9 +52,11 @@ import { PERSONAL_REPORT_METRICS, type ReportMetric } from "./constants/overview ...@@ -57,9 +52,11 @@ import { PERSONAL_REPORT_METRICS, type ReportMetric } from "./constants/overview
import { REPORT_ENTRY_CONFIGS, type ReportEntryKey } from "./constants/reportEntries.uts"; import { REPORT_ENTRY_CONFIGS, type ReportEntryKey } from "./constants/reportEntries.uts";
import { STORE_REPORTS, type StoreReport } from "./constants/storeReportData.uts"; import { STORE_REPORTS, type StoreReport } from "./constants/storeReportData.uts";
import { SUMMARY_REPORT_METRICS, SUMMARY_STORES, type SummaryMetric } from "./constants/summaryReportData.uts"; import { SUMMARY_REPORT_METRICS, SUMMARY_STORES, type SummaryMetric } from "./constants/summaryReportData.uts";
import reportPageVars from "./styles/index.vars.uts";
const shellRef = ref(null); defineProps<{
activeIndex?: number
}>();
const reportEntryConfigs = REPORT_ENTRY_CONFIGS; const reportEntryConfigs = REPORT_ENTRY_CONFIGS;
const activeEntryKey = ref<ReportEntryKey>("personal"); const activeEntryKey = ref<ReportEntryKey>("personal");
......
<template> <template>
<DailyReportForm <DailyReportForm
v-if="showCreateForm" v-if="showCreateForm"
@back="onBackToList" /> @back="onBackToList" />
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
:show-scrollbar="false" :show-scrollbar="false"
@scrolltolower="onScrollToLower"> @scrolltolower="onScrollToLower">
<view class="daily-list"> <view class="daily-list">
<view v-for="(item, index) in reports" <view v-for="(item, index) in visibleReports"
:key="index" :key="index"
class="daily-report-card"> class="daily-report-card">
<view class="daily-report-card__header"> <view class="daily-report-card__header">
...@@ -83,6 +83,7 @@ import { computed, onMounted, ref } from "vue"; ...@@ -83,6 +83,7 @@ import { computed, onMounted, ref } from "vue";
import { getDailyReportsList } from "@/api/modules/tasks.uts"; import { getDailyReportsList } from "@/api/modules/tasks.uts";
import DailyReportForm from "./DailyReportForm.uvue"; import DailyReportForm from "./DailyReportForm.uvue";
import { dailyReportsCache, hasDailyReportsCache, setDailyReportsCache } from "./taskPanelCache.uts";
type DailyReportStat = { type DailyReportStat = {
label: string label: string
...@@ -112,8 +113,11 @@ type DailyReportsResponse = { ...@@ -112,8 +113,11 @@ type DailyReportsResponse = {
const DEFAULT_PAGE_NUM = 1; const DEFAULT_PAGE_NUM = 1;
const SCROLL_LOWER_INTERVAL_MS = 500; const SCROLL_LOWER_INTERVAL_MS = 500;
const INITIAL_RENDER_COUNT = 24;
const RENDER_BATCH_COUNT = 24;
const reports = ref<DailyReportItem[]>([]); const reports = ref<DailyReportItem[]>([]);
const renderedCount = ref<number>(INITIAL_RENDER_COUNT);
const pageNum = ref<number>(DEFAULT_PAGE_NUM); const pageNum = ref<number>(DEFAULT_PAGE_NUM);
const loading = ref<boolean>(false); const loading = ref<boolean>(false);
const hasMore = ref<boolean>(true); const hasMore = ref<boolean>(true);
...@@ -153,6 +157,13 @@ const dailySummaryItems = computed((): TaskSummaryCardItem[] => { ...@@ -153,6 +157,13 @@ const dailySummaryItems = computed((): TaskSummaryCardItem[] => {
] as TaskSummaryCardItem[]; ] as TaskSummaryCardItem[];
}); });
const visibleReports = computed((): DailyReportItem[] => {
if (reports.value.length <= renderedCount.value) {
return reports.value;
}
return reports.value.slice(0, renderedCount.value);
});
function readValue(data: UTSJSONObject, key: string, fallback: string = ""): string { function readValue(data: UTSJSONObject, key: string, fallback: string = ""): string {
const value = data[key]; const value = data[key];
return value != null && `${value}` != "" ? `${value}` : fallback; return value != null && `${value}` != "" ? `${value}` : fallback;
...@@ -236,19 +247,20 @@ function resolveDailyReportItems(response: any): UTSJSONObject[] { ...@@ -236,19 +247,20 @@ function resolveDailyReportItems(response: any): UTSJSONObject[] {
return [] as UTSJSONObject[]; return [] as UTSJSONObject[];
} }
async function loadReports(append: boolean): Promise<void> { function loadReports(append: boolean): void {
if (loading.value) return; if (loading.value) return;
if (append && !hasMore.value) return; if (append && !hasMore.value) return;
loading.value = true; loading.value = true;
if (!append) { if (!append) {
pageNum.value = DEFAULT_PAGE_NUM; pageNum.value = DEFAULT_PAGE_NUM;
hasMore.value = true; hasMore.value = true;
renderedCount.value = INITIAL_RENDER_COUNT;
} }
try { getDailyReportsList({
const response = await getDailyReportsList({
pageNum: pageNum.value pageNum: pageNum.value
} as UTSJSONObject); } as UTSJSONObject).then((response: any): void => {
const items = resolveDailyReportItems(response); const items = resolveDailyReportItems(response);
setDailyReportsCache(items);
const nextReports = normalizeDailyReports(items); const nextReports = normalizeDailyReports(items);
if (append) { if (append) {
reports.value = reports.value.concat(nextReports); reports.value = reports.value.concat(nextReports);
...@@ -259,21 +271,25 @@ async function loadReports(append: boolean): Promise<void> { ...@@ -259,21 +271,25 @@ async function loadReports(append: boolean): Promise<void> {
if (items.length > 0) { if (items.length > 0) {
pageNum.value++; pageNum.value++;
} }
} catch (_e) { loading.value = false;
}).catch((_e) => {
if (!append) { if (!append) {
reports.value = [] as DailyReportItem[]; reports.value = [] as DailyReportItem[];
} }
hasMore.value = false; hasMore.value = false;
} finally {
loading.value = false; loading.value = false;
} });
} }
function onScrollToLower(): void { function onScrollToLower(): void {
const now = Date.now(); const now = Date.now();
if (now - lastScrollToLowerAt < SCROLL_LOWER_INTERVAL_MS) return; if (now - lastScrollToLowerAt < SCROLL_LOWER_INTERVAL_MS) return;
lastScrollToLowerAt = now; lastScrollToLowerAt = now;
void loadReports(true); if (renderedCount.value < reports.value.length) {
renderedCount.value = Math.min(renderedCount.value + RENDER_BATCH_COUNT, reports.value.length);
return;
}
loadReports(true);
} }
function onCreateDailyReport(): void { function onCreateDailyReport(): void {
...@@ -287,11 +303,16 @@ function onCreateDailyReport(): void { ...@@ -287,11 +303,16 @@ function onCreateDailyReport(): void {
function onBackToList(): void { function onBackToList(): void {
showCreateForm.value = false; showCreateForm.value = false;
void loadReports(false); loadReports(false);
} }
onMounted((): void => { onMounted((): void => {
void loadReports(false); // 切回时先渲染缓存,避免重新请求导致 loading 闪烁/卡顿
if (hasDailyReportsCache) {
reports.value = normalizeDailyReports(dailyReportsCache);
renderedCount.value = INITIAL_RENDER_COUNT;
}
loadReports(false);
}); });
</script> </script>
......
<template> <template>
<view class="study-module"> <view class="study-module">
<view class="tasks-summary-grid"> <view class="tasks-summary-grid">
<view v-for="(item, index) in studySummaryItems" <view v-for="(item, index) in studySummaryItems"
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
import { computed, onMounted, ref } from "vue"; import { computed, onMounted, ref } from "vue";
import { getLearnTasksList } from "@/api/modules/tasks.uts"; import { getLearnTasksList } from "@/api/modules/tasks.uts";
import { studyCoursesCache, hasStudyCoursesCache, setStudyCoursesCache } from "./taskPanelCache.uts";
type StudyCourse = { type StudyCourse = {
title: string title: string
...@@ -177,7 +178,7 @@ function resolveCourseItems(response: any): UTSJSONObject[] { ...@@ -177,7 +178,7 @@ function resolveCourseItems(response: any): UTSJSONObject[] {
return [] as UTSJSONObject[]; return [] as UTSJSONObject[];
} }
async function loadCourses(append: boolean): Promise<void> { function loadCourses(append: boolean): void {
if (loading.value) return; if (loading.value) return;
if (append && !hasMore.value) return; if (append && !hasMore.value) return;
loading.value = true; loading.value = true;
...@@ -185,11 +186,11 @@ async function loadCourses(append: boolean): Promise<void> { ...@@ -185,11 +186,11 @@ async function loadCourses(append: boolean): Promise<void> {
pageNum.value = DEFAULT_PAGE_NUM; pageNum.value = DEFAULT_PAGE_NUM;
hasMore.value = true; hasMore.value = true;
} }
try { getLearnTasksList({
const response = await getLearnTasksList({
pageNum: pageNum.value pageNum: pageNum.value
} as UTSJSONObject); } as UTSJSONObject).then((response: any): void => {
const items = resolveCourseItems(response); const items = resolveCourseItems(response);
setStudyCoursesCache(items);
const nextCourses = normalizeCourses(items); const nextCourses = normalizeCourses(items);
if (append) { if (append) {
courses.value = courses.value.concat(nextCourses); courses.value = courses.value.concat(nextCourses);
...@@ -200,21 +201,21 @@ async function loadCourses(append: boolean): Promise<void> { ...@@ -200,21 +201,21 @@ async function loadCourses(append: boolean): Promise<void> {
if (items.length > 0) { if (items.length > 0) {
pageNum.value++; pageNum.value++;
} }
} catch (_e) { loading.value = false;
}).catch((_e) => {
if (!append) { if (!append) {
courses.value = [] as StudyCourse[]; courses.value = [] as StudyCourse[];
} }
hasMore.value = false; hasMore.value = false;
} finally {
loading.value = false; loading.value = false;
} });
} }
function onScrollToLower(): void { function onScrollToLower(): void {
const now = Date.now(); const now = Date.now();
if (now - lastScrollToLowerAt < SCROLL_LOWER_INTERVAL_MS) return; if (now - lastScrollToLowerAt < SCROLL_LOWER_INTERVAL_MS) return;
lastScrollToLowerAt = now; lastScrollToLowerAt = now;
void loadCourses(true); loadCourses(true);
} }
function onCourseClick(item: StudyCourse): void { function onCourseClick(item: StudyCourse): void {
...@@ -231,7 +232,11 @@ function getStatusClass(statusText: string): string { ...@@ -231,7 +232,11 @@ function getStatusClass(statusText: string): string {
} }
onMounted((): void => { onMounted((): void => {
void loadCourses(false); // 切回时先渲染缓存,避免重新请求导致 loading 闪烁/卡顿
if (hasStudyCoursesCache) {
courses.value = normalizeCourses(studyCoursesCache);
}
loadCourses(false);
}); });
</script> </script>
......
/**
* 任务面板数据缓存(模块级单例)
*
* 任务页子面板采用 v-if 切换(重建组件,渲染最可靠),
* 为避免切回时重新请求接口导致 loading 闪烁/卡顿,
* 将接口原始数据缓存在模块级,组件重建后先用缓存渲染,再静默刷新。
*/
/** 日报列表原始数据缓存(接口原始 JSON 项) */
export let dailyReportsCache: UTSJSONObject[] = [] as UTSJSONObject[];
export let hasDailyReportsCache: boolean = false;
/** 学习任务列表原始数据缓存 */
export let studyCoursesCache: UTSJSONObject[] = [] as UTSJSONObject[];
export let hasStudyCoursesCache: boolean = false;
/** 更新日报缓存 */
export function setDailyReportsCache(items: UTSJSONObject[]): void {
dailyReportsCache = items;
hasDailyReportsCache = true;
}
/** 更新学习任务缓存 */
export function setStudyCoursesCache(items: UTSJSONObject[]): void {
studyCoursesCache = items;
hasStudyCoursesCache = true;
}
<template> <template>
<TabBarShell ref="shellRef"
:active-tab-index="1"
:page-vars="taskPageVars as UTSJSONObject">
<view class="tasks-page"> <view class="tasks-page">
<view class="tasks-layout"> <view class="tasks-layout">
<view class="tasks-entry-panel"> <view class="tasks-entry-panel">
...@@ -39,13 +36,10 @@ ...@@ -39,13 +36,10 @@
</view> </view>
</view> </view>
</view> </view>
</TabBarShell>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { computed, ref } from "vue"; import { computed, onMounted, ref } from "vue";
import TabBarShell from "@/components/TabBar/TabBarShell.uvue";
import DailyReport from "./components/DailyReport.uvue"; import DailyReport from "./components/DailyReport.uvue";
import ReviewPanel from "./components/ReviewPanel.uvue"; import ReviewPanel from "./components/ReviewPanel.uvue";
...@@ -55,9 +49,10 @@ import EntryGrid from "@/components/EntryGrid.uvue"; ...@@ -55,9 +49,10 @@ import EntryGrid from "@/components/EntryGrid.uvue";
import { STRATEGY_ITEMS, type StrategyItem } from "./constants/strategyData.uts"; import { STRATEGY_ITEMS, type StrategyItem } from "./constants/strategyData.uts";
import { PENDING_REVIEW_ITEMS, REVIEWED_ITEMS, type ReviewItem, type ReviewStatus } from "./constants/reviewData.uts"; import { PENDING_REVIEW_ITEMS, REVIEWED_ITEMS, type ReviewItem, type ReviewStatus } from "./constants/reviewData.uts";
import { TASK_ENTRY_CONFIGS, type TaskEntryKey } from "./constants/taskEntries.uts"; import { TASK_ENTRY_CONFIGS, type TaskEntryKey } from "./constants/taskEntries.uts";
import taskPageVars from "./styles/index.vars.uts";
const shellRef = ref(null); defineProps<{
activeIndex?: number
}>();
const taskEntryConfigs = TASK_ENTRY_CONFIGS; const taskEntryConfigs = TASK_ENTRY_CONFIGS;
const activeEntryKey = ref<TaskEntryKey>("daily"); const activeEntryKey = ref<TaskEntryKey>("daily");
...@@ -166,13 +161,7 @@ const activeEntryLabel = computed((): string => { ...@@ -166,13 +161,7 @@ const activeEntryLabel = computed((): string => {
return "日报"; return "日报";
}); });
const activeOverview = computed((): TaskOverview => { /** 动态组件:按 activeEntryKey 解析当前面板(UTS 中自定义组件 v-if 不可靠,用动态组件最稳定) */
if (activeEntryKey.value == "study") return STUDY_OVERVIEW;
if (activeEntryKey.value == "strategy") return createStrategyOverview();
if (activeEntryKey.value == "review") return createReviewOverview();
return DAILY_OVERVIEW;
});
const activeEntryComponent = computed((): any => { const activeEntryComponent = computed((): any => {
if (activeEntryKey.value == "study") return StudyPanel; if (activeEntryKey.value == "study") return StudyPanel;
if (activeEntryKey.value == "strategy") return StrategyPanel; if (activeEntryKey.value == "strategy") return StrategyPanel;
...@@ -180,11 +169,30 @@ const activeEntryComponent = computed((): any => { ...@@ -180,11 +169,30 @@ const activeEntryComponent = computed((): any => {
return DailyReport; return DailyReport;
}); });
/** 预计算:策略/审阅的数据基于静态常量,只需算一次 */
const STRATEGY_OVERVIEW = createStrategyOverview();
const REVIEW_OVERVIEW = createReviewOverview();
const activeOverview = computed((): TaskOverview => {
if (activeEntryKey.value == "study") return STUDY_OVERVIEW;
if (activeEntryKey.value == "strategy") return STRATEGY_OVERVIEW;
if (activeEntryKey.value == "review") return REVIEW_OVERVIEW;
return DAILY_OVERVIEW;
});
function onEntryChange(key: string): void { function onEntryChange(key: string): void {
if (key == activeEntryKey.value) return;
activeEntryKey.value = key as TaskEntryKey; activeEntryKey.value = key as TaskEntryKey;
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@import "./styles/common.scss"; @import "./styles/common.scss";
.tasks-panel-item {
width: 100%;
height: 100%;
min-width: 0;
min-height: 0;
}
</style> </style>
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
<script setup lang="uts"> <script setup lang="uts">
onLoad(() => { onLoad(() => {
uni.switchTab({ uni.switchTab({
url: "/pages/index/index", url: "/pages/main/index",
fail: (_err: any) => { fail: (_err: any) => {
uni.reLaunch({ url: "/pages/index/index" }); uni.reLaunch({ url: "/pages/main/index" });
} }
}); });
}); });
......
...@@ -6,10 +6,11 @@ import type { OptionalVars } from '@/types' ...@@ -6,10 +6,11 @@ import type { OptionalVars } from '@/types'
/** /**
* 获取屏幕变量的响应式 Hook * 获取屏幕变量的响应式 Hook
* @param pageVars 页面特定的变量配置(可选),如果不传则尝试从 provide/inject 获取 * @param pageVars 页面特定的变量配置(可选,一次性快照),如果不传则尝试从 provide/inject 获取
* @param pageVarsGetter 响应式获取 pageVars 的函数(可选),用于 tab 切换等场景,确保 CSS 变量及时更新
* @returns 响应式的屏幕变量对象 * @returns 响应式的屏幕变量对象
*/ */
export function useScreenVars(pageVars: OptionalVars | null = null): ComputedRef<UTSJSONObject> { export function useScreenVars(pageVars: OptionalVars | null = null, pageVarsGetter: (() => UTSJSONObject | null) | null = null): ComputedRef<UTSJSONObject> {
// ✅ 强制更新方向信息,确保 resolutionKey 正确(解决横屏首次加载样式不匹配问题) // ✅ 强制更新方向信息,确保 resolutionKey 正确(解决横屏首次加载样式不匹配问题)
updateOrientation(true); updateOrientation(true);
...@@ -44,15 +45,18 @@ export function useScreenVars(pageVars: OptionalVars | null = null): ComputedRef ...@@ -44,15 +45,18 @@ export function useScreenVars(pageVars: OptionalVars | null = null): ComputedRef
) )
const globalResolutions = getAsObject(globalScreenVars, `resolutions.${fullResKey}`) const globalResolutions = getAsObject(globalScreenVars, `resolutions.${fullResKey}`)
// ✅ 优先使用 getter 获取最新 pageVars(支持 tab 切换等动态场景)
const currentPV: UTSJSONObject | null = pageVarsGetter != null ? pageVarsGetter() : effectivePageVars
// 页面配置 // 页面配置
let pageCommon: OptionalVars = null let pageCommon: OptionalVars = null
let pageOrient: OptionalVars = null let pageOrient: OptionalVars = null
let pageResolutions: OptionalVars = null let pageResolutions: OptionalVars = null
if (effectivePageVars != null) { if (currentPV != null) {
pageCommon = getAsObject(effectivePageVars, 'common') pageCommon = getAsObject(currentPV, 'common')
pageOrient = getAsObject(effectivePageVars, orient) pageOrient = getAsObject(currentPV, orient)
pageResolutions = getAsObject(effectivePageVars, `resolutions.${fullResKey}`) pageResolutions = getAsObject(currentPV, `resolutions.${fullResKey}`)
} }
// 合并配置(优先级从低到高) // 合并配置(优先级从低到高)
...@@ -72,6 +76,13 @@ export function useScreenVars(pageVars: OptionalVars | null = null): ComputedRef ...@@ -72,6 +76,13 @@ export function useScreenVars(pageVars: OptionalVars | null = null): ComputedRef
// 监听方向和分辨率变化(合并为一个 watch,减少重复代码) // 监听方向和分辨率变化(合并为一个 watch,减少重复代码)
watch([orientationKey, resolutionKey], updateScreenVars) watch([orientationKey, resolutionKey], updateScreenVars)
// ✅ 如果有 getter,额外监听 pageVars 引用变化(tab 切换时触发 CSS 变量更新)
if (pageVarsGetter != null) {
const getter = pageVarsGetter as () => UTSJSONObject | null
const pvTracker = computed((): UTSJSONObject | null => getter())
watch(pvTracker, updateScreenVars)
}
// 返回 computed,让调用方可以直接使用 .value 或在模板中自动解包 // 返回 computed,让调用方可以直接使用 .value 或在模板中自动解包
return computed(() => screenVarsValue.value) return computed(() => screenVarsValue.value)
} }
...@@ -51,8 +51,8 @@ export class Router { ...@@ -51,8 +51,8 @@ export class Router {
// 获取默认路径,支持 home 和 login // 获取默认路径,支持 home 和 login
defaultPath(name: "home" | "login") { defaultPath(name: "home" | "login") {
const paths = { const paths = {
home: PAGES[0].path, // 首页为第一个页面 home: "/pages/main/index", // 主 TabBar 容器页
login: "/pages/user/login" login: "/pages/common/login/index"
}; };
return get(paths, name) as string; return get(paths, name) as string;
...@@ -326,7 +326,7 @@ export class Router { ...@@ -326,7 +326,7 @@ export class Router {
login = debounce(() => { login = debounce(() => {
if (!this.isLoginPage(this.path())) { if (!this.isLoginPage(this.path())) {
this.push({ this.push({
path: "/pages/user/login", path: this.defaultPath("login"),
mode: "reLaunch" mode: "reLaunch"
}); });
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!