Commit 9652b787 by liimin

refactor: 优化布局适配,重构接待模块代码

- 抽离接待业务公共工具函数,消除重复代码与模块反向依赖
- 优化EntryGrid容器布局,移除固定高度变量适配多场景显示
- 重构TabBar组件,合并竖横屏布局解决uniapp-x渲染问题
- 修正接待列表跳转路径,完善页面方向状态同步逻辑
- 简化屏幕方向锁定重试逻辑,提升设备适配稳定性
- 完善接待中心列表刷新监听,确保表单保存后实时更新数据
1 parent 14743e3e
...@@ -91,7 +91,9 @@ function onEntryClick(key: string): void { ...@@ -91,7 +91,9 @@ function onEntryClick(key: string): void {
background-color: var(--module-entry-grid-bg, #ffffff); background-color: var(--module-entry-grid-bg, #ffffff);
border-radius: var(--module-entry-grid-radius, 8px); border-radius: var(--module-entry-grid-radius, 8px);
box-sizing: border-box; box-sizing: border-box;
overflow: visible; /* 兜底:若某设备下网格实际渲染高度超过容器(极端分辨率/字号),内部可滚动而非裁切。
uvue 不支持 overflow-x/overflow-y,统一用 overflow */
overflow: auto;
} }
.module-entry-grid__list { .module-entry-grid__list {
......
...@@ -220,8 +220,8 @@ ...@@ -220,8 +220,8 @@
display: flex; display: flex;
flex: 1; flex: 1;
flex-direction: column; flex-direction: column;
min-height: 0; min-height: 0;
overflow-y: scroll; overflow: scroll;
width: 100%; width: 100%;
padding: 0; padding: 0;
} }
......
...@@ -14,11 +14,11 @@ ...@@ -14,11 +14,11 @@
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { computed, nextTick, onShow, onMounted, ref, type Ref } from "vue"; import { computed, nextTick, onShow, onMounted, onResize, ref, type Ref } from "vue";
import { storage } from "@/utils/storage.uts"; import { storage } from "@/utils/storage.uts";
import TabBarShell from "./tabbar/TabBarShell.uvue"; import TabBarShell from "./tabbar/TabBarShell.uvue";
import { TAB_PAGE_VARS, TAB_COMPONENTS } from "./tabRegistry.uts"; import { TAB_PAGE_VARS, TAB_COMPONENTS } from "./tabRegistry.uts";
import { useOrientation } from "@/services/adapter/hooks/index.uts"; import { useOrientation, updateOrientation } from "@/services/adapter/hooks/index.uts";
const orientationHook = useOrientation(); const orientationHook = useOrientation();
...@@ -95,6 +95,13 @@ onMounted(() => { ...@@ -95,6 +95,13 @@ onMounted(() => {
activateTab(0); activateTab(0);
}); });
// 旋转时强制刷新全局方向状态(updateOrientation 会仅在值变化时更新,幂等安全)。
// 仅靠 app.mixin 的 onResize 在 uni-app x 下不一定触发,这里在宿主页显式兜底,
// 保证 isPortrait 在横竖屏切换时可靠更新(TabBarShell.mode / TabBarNav 方向都依赖它)。
onResize((options) => {
updateOrientation(true);
});
/** 登录状态校验 */ /** 登录状态校验 */
onShow(() => { onShow(() => {
const userInfoObj = storage.getUserInfo(); const userInfoObj = storage.getUserInfo();
......
<template>
<view class="home-tabbar home-tabbar-landscape">
<view class="hf-landscape-column">
<view class="user-box user-box-clickable hf-landscape-user"
@click="emit('jumpPersonCenter')">
<view class="hf-landscape-profile">
<un-avatar :text="avatarText"
shape="circle"
size="42"
bgColor="#2f6af7"
color="#ffffff"
fontSize="20" />
<text class="hf-landscape-name">{{ userName }}</text>
</view>
</view>
</view>
<view class="landscape-tabbar-wrap">
<view class="landscape-un-tabbar landscape-vertical-tabs">
<view v-for="(item, index) in tabs"
:key="index"
class="landscape-vertical-tabs__item"
:class="index === currentTabIndex ? 'landscape-vertical-tabs__item--active' : ''"
@click="emit('tabChange', index)">
<view class="landscape-vertical-tabs__inner">
<image class="landscape-vertical-tabs__icon"
mode="aspectFit"
:src="index === currentTabIndex ? item.iconSrcActive : item.iconSrcInactive" />
<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 class="home-tabbar-footer flex-col hf-landscape-footer">
<view class="hf-landscape-footer-divider"></view>
<view class="hf-landscape-footer-btn"
@tap="emit('switchStore')">
<image class="hf-landscape-footer-icon"
mode="aspectFit"
src="/static/images/home/scene-change.png" />
<text class="hf-landscape-footer-label">切换</text>
</view>
<view class="hf-landscape-footer-btn"
@tap="emit('setting')">
<image class="hf-landscape-footer-icon"
mode="aspectFit"
src="/static/images/home/setting.png" />
<text class="hf-landscape-footer-label">设置</text>
</view>
</view>
</view>
</template>
<script setup lang="uts">
import { ref, onMounted } from "vue";
import { TAB_ITEMS as tabs, resolveHomeFrameDisplayName } from "../tabRegistry.uts";
import { storage } from "@/utils/storage.uts";
const props = defineProps<{
currentTabIndex: number
}>();
const emit = defineEmits<{
tabChange: [name: string | number]
setting: []
jumpPersonCenter: []
switchStore: []
}>();
const userName = ref<string>("");
const avatarText = ref<string>("我");
onMounted(() => {
const userInfo = storage.getUserInfo();
if (userInfo != null) {
const name = resolveHomeFrameDisplayName(userInfo);
userName.value = name;
avatarText.value = name == "" ? "我" : name.substring(0, 1);
}
});
</script>
<style scoped lang="scss">
.home-tabbar {
display: flex;
flex-direction: column;
position: relative;
flex-shrink: 0;
background-color: var(--bg-card, #FFFFFF);
.hf-landscape-column,
.user-box,
.landscape-tabbar-wrap,
.home-tabbar-footer {
position: relative;
z-index: 1;
}
}
.home-tabbar-landscape {
min-height: 0;
height: 100%;
align-self: stretch;
}
.user-box {
padding-top: 46px;
}
.landscape-tabbar-wrap {
flex: 1;
min-height: 0;
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.home-tabbar-footer {
flex-shrink: 0;
}
.hf-landscape-column {
flex-shrink: 0;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
box-sizing: border-box;
padding: 14px 10px 0;
position: relative;
z-index: 1;
}
.hf-landscape-user {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
box-sizing: border-box;
padding-top: 0;
flex-shrink: 0;
}
.hf-landscape-profile {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.hf-landscape-name {
margin-top: 10px;
font-size: 14px;
font-weight: 600;
color: #1a2433;
line-height: 24px;
text-align: center;
width: 100%;
max-width: 104px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.hf-landscape-footer {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
box-sizing: border-box;
flex-shrink: 0;
padding: 20px 10px 28px;
}
.hf-landscape-footer-divider {
width: 40px;
height: 1px;
background-color: #e5edf8;
}
.hf-landscape-footer-btn {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-top: 8px;
border-radius: 8px;
transition: background-color 0.2s;
}
.hf-landscape-footer-btn:active {
background-color: #f5f7fa;
}
.hf-landscape-footer-icon {
width: 24px;
height: 24px;
flex-shrink: 0;
opacity: 0.7;
}
.hf-landscape-footer-label {
margin-top: 4px;
font-size: 11px;
color: #8a98b5;
text-align: center;
line-height: 16px;
}
.landscape-vertical-tabs {
flex: 1;
min-height: 0;
width: 100%;
padding-left: var(--tabbar-padding, 16px);
padding-right: var(--tabbar-padding, 16px);
padding-top: 8px;
padding-bottom: 8px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
box-sizing: border-box;
}
.landscape-vertical-tabs__item {
width: 100%;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 12px 0;
box-sizing: border-box;
}
.landscape-vertical-tabs__item + .landscape-vertical-tabs__item {
margin-top: 10px;
}
.landscape-vertical-tabs__inner {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.landscape-vertical-tabs__icon {
width: var(--tabbar-icon-size, 28px);
height: var(--tabbar-icon-size, 28px);
flex-shrink: 0;
}
.landscape-vertical-tabs__label {
margin-top: 6px;
font-size: 13px;
color: #8a98b5;
text-align: center;
width: 100%;
max-width: 104px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
<template>
<view class="portrait-tabbar">
<view v-for="(item, index) in tabs"
:key="index"
class="portrait-tabbar-item"
@click="emit('tabChange', index)">
<image class="portrait-tabbar-icon"
mode="aspectFit"
:src="index === currentTabIndex ? item.iconSrcActive : item.iconSrcInactive" />
<text class="portrait-tabbar-label"
:class="index === currentTabIndex ? 'portrait-tabbar-label--active' : ''">{{ item.label }}</text>
</view>
</view>
</template>
<script setup lang="uts">
import { TAB_ITEMS as tabs } from "../tabRegistry.uts";
const props = defineProps<{
currentTabIndex: number
}>();
const emit = defineEmits<{
tabChange: [name: string | number]
}>();
</script>
<style scoped lang="scss">
.portrait-tabbar {
width: 100%;
height: var(--tabbar-height, 60px);
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-around;
flex-shrink: 0;
background-color: #ffffff;
box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.05);
padding-bottom: env(safe-area-inset-bottom, 0px);
box-sizing: content-box;
}
.portrait-tabbar-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
flex: 1;
height: var(--tabbar-height, 60px);
}
.portrait-tabbar-icon {
width: var(--tabbar-icon-size, 28px);
height: var(--tabbar-icon-size, 28px);
}
.portrait-tabbar-label {
font-size: 12px;
color: #8a98b5;
margin-top: 3px;
line-height: 16px;
}
.portrait-tabbar-label--active {
color: #3773f8;
}
</style>
<template>
<!-- 单一 TabBar 导航组件:横竖屏共用同一份内容(5 个 tab)。
方向(flex-direction / justify-content)与 item/label 尺寸通过【内联样式】驱动,
由组件内 useOrientation() 读取全局方向状态计算(与父组件 TabBarShell 同源,
单一事实来源;本组件不再依赖父传 class/prop,也不依赖 var() 关键字替换 /
动态 class 切换 / 后代选择器——这些在 uniapp-x 下均不可靠)。
选中态:图标用 active/inactive 两张图切换;文字高亮用直接挂在 <text> 上的单类
.tabbar-nav__label--active(无后代选择器依赖,可靠)。选中色 #3773f8,图标用 --tabbar-icon-size。 -->
<view class="tabbar-nav"
:style="navStyle">
<view v-for="(item, index) in tabs"
:key="index"
class="tabbar-nav__item"
:style="itemStyle"
@click="emit('tabChange', index)">
<image class="tabbar-nav__icon"
mode="aspectFit"
:src="index === currentTabIndex ? item.iconSrcActive : item.iconSrcInactive" />
<text class="tabbar-nav__label"
:class="index === currentTabIndex ? 'tabbar-nav__label--active' : ''"
:style="labelStyle">{{ item.label }}</text>
</view>
</view>
</template>
<script setup lang="uts">
import { computed, type Ref } from "vue";
import { TAB_ITEMS as tabs } from "../tabRegistry.uts";
import { useOrientation } from "@/services/adapter/hooks/index.uts";
const props = defineProps<{
/** 当前 tab 下标 */
currentTabIndex: number
}>();
const emit = defineEmits<{
tabChange: [name: string | number]
}>();
// 方向:读取全局唯一状态(与 TabBarShell.mode 同源),组件内自行消费,
// 避免父→子透传 / 动态 class 在 uniapp-x 下的不可靠问题。
const orientationHook = useOrientation();
const isPortrait = computed((): boolean => (orientationHook.isPortrait as Ref<boolean>).value);
// 根容器:方向 + 对齐(内联样式赋值关键字属性,uniapp-x 可靠生效)
const navStyle = computed((): UTSJSONObject => {
return isPortrait.value
? { flexDirection: "row", justifyContent: "space-around" }
: { flexDirection: "column", justifyContent: "space-between", paddingTop: "12px", paddingBottom: "12px", paddingLeft: "8px", paddingRight: "8px", overflowY: "auto" };
});
// 每个 tab 项:横屏竖排占满宽度;竖屏横排等分高度
const itemStyle = computed((): UTSJSONObject => {
return isPortrait.value
? { flex: "1 1 0%", height: "100%" }
: { width: "100%", paddingTop: "9px", paddingBottom: "9px" };
});
// 文案:横竖屏字号差异(内联样式赋值长度,可靠)
const labelStyle = computed((): UTSJSONObject => {
return isPortrait.value
? { fontSize: "12px", lineHeight: "16px", marginTop: "3px" }
: { fontSize: "13px", lineHeight: "18px", marginTop: "6px" };
});
</script>
<style scoped lang="scss">
.tabbar-nav {
width: 100%;
/* 填满父容器(横屏侧边栏剩余高度 / 竖屏底部 60px),自身不撑开父级 */
flex: 1 1 auto;
min-height: 0;
display: flex;
align-items: center;
box-sizing: border-box;
}
.tabbar-nav__item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
box-sizing: border-box;
}
.tabbar-nav__icon {
width: var(--tabbar-icon-size, 28px);
height: var(--tabbar-icon-size, 28px);
flex-shrink: 0;
}
.tabbar-nav__label {
text-align: center;
width: 100%;
max-width: 104px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: #8a98b5;
}
/* 选中态文字高亮:直接挂在 <text> 上的单类(无后代选择器依赖,uniapp-x 可靠生效) */
.tabbar-nav__label--active {
color: #3773f8;
font-weight: 500;
}
</style>
<template> <template>
<layout-root :page-vars="pageVars"> <layout-root :page-vars="pageVars">
<!-- TabBar 壳组件:单棵 DOM 树,方向通过 CSS 类控制,slot 始终挂载不被销毁重建 --> <!-- TabBar 壳组件:单一 TabBarNav 实例。
<view class="scene-shell-root" :class="shellIsPortrait ? 'mode-portrait' : 'mode-landscape'"> 横屏:.scene-shell-nav 作为左侧栏(头像 + 竖排 tab);
<view v-show="!shellIsPortrait" class="scene-shell-sidebar"> 竖屏:.scene-shell-nav 作为底部栏(仅 tab)。
<Landscape :user-name="userName" 方向唯一来源是单个 `mode` 计算(见 script);所有绑定都读它:
:current-tab-index="props.activeTabIndex" 根容器 flex-direction 由 .mode-* 类驱动,nav 尺寸由 .scene-shell-nav--* self-class 字面量驱动,
@tab-change="(name: string | number) => onTabChange(name)" TabBarNav 方向由组件内 useOrientation() 自行消费(内联样式驱动,不依赖父传 class/prop),
@setting="onSetting" 头像显隐由 mode 决定。tab items 完全一致 -->
@jump-person-center="jumpPersonCenter" <view class="scene-shell-root" :class="'mode-' + mode">
@switch-store="onSwitchStore" /> <!-- 导航容器:横竖屏同一实例;尺寸由 self-class(.scene-shell-nav--*)显式写死,不依赖 var()(uniapp-x 下 var 嵌套/关键字不可靠) -->
<view class="scene-shell-nav" :class="'scene-shell-nav--' + mode">
<!-- 头像区:仅横屏显示(竖屏底部栏不放头像),点击进入个人中心 -->
<view v-show="mode === 'landscape'" class="shell-user" @click="jumpPersonCenter">
<un-avatar :text="avatarText"
shape="circle"
size="36"
bgColor="#2f6af7"
color="#ffffff"
fontSize="18" />
<text class="shell-user-name">{{ userName }}</text>
</view>
<TabBarNav :current-tab-index="props.activeTabIndex"
@tab-change="(name: string | number) => onTabChange(name)" />
</view> </view>
<!-- 内容区:始终填满剩余空间 -->
<view class="scene-shell-main"> <view class="scene-shell-main">
<slot></slot> <slot></slot>
</view> </view>
<view v-show="shellIsPortrait" class="scene-shell-tabbar">
<Portrait :current-tab-index="props.activeTabIndex"
@tab-change="(name: string | number) => onTabChange(name)" />
</view>
</view> </view>
<SettingBox :visible="showSetting"
@update:visible="onSettingVisible"
@switch-store="onSwitchStore" />
<SwitchStoreSheet :visible="showSwitchStore"
@update:visible="onSwitchStoreVisible"
@switched="onSwitchStoreDone" />
</layout-root> </layout-root>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { computed, onMounted, onShow, type Ref } from "vue"; import { computed, onMounted, onShow, type Ref } from "vue";
import SettingBox from "@/pages/person/SettingBox.uvue";
import SwitchStoreSheet from "@/components/SwitchStoreSheet.uvue";
import { useOrientation } from "@/services/adapter/hooks/index.uts"; import { useOrientation } from "@/services/adapter/hooks/index.uts";
import { requestRecordPermission } from "@/utils/permission.uts"; import { requestRecordPermission } from "@/utils/permission.uts";
import { storage } from "@/utils/storage.uts"; import { storage } from "@/utils/storage.uts";
import { hideNativeTabBar } from "@/utils/tabBarShell.uts"; import { hideNativeTabBar } from "@/utils/tabBarShell.uts";
import Landscape from "./Landscape.uvue"; import TabBarNav from "./TabBarNav.uvue";
import Portrait from "./Portrait.uvue";
import type { HomeFrameTabbarSource } from "../tabRegistry.uts"; import type { HomeFrameTabbarSource } from "../tabRegistry.uts";
import { useHomeFrameTabbar } from "../tabRegistry.uts"; import { useHomeFrameTabbar } from "../tabRegistry.uts";
defineSlots(); defineSlots();
const props = defineProps<{ const props = defineProps<{
/** 当前 tab 页下标:0 首页、1 任务、2 录单、3 报表、4 我的 */ /** 当前 tab 页下标:0 首页、1 任务、2 录单、3 报表、4 我的 */
activeTabIndex: number activeTabIndex: number
/** 页面 CSS 变量(由 index.uvue 从 TAB_PAGE_VARS 按 index 取值后传入) */ /** 页面 CSS 变量(由 index.uvue 从 TAB_PAGE_VARS 按 index 取值后传入) */
pageVars: UTSJSONObject pageVars: UTSJSONObject
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
tabChange: [name: string | number] tabChange: [name: string | number]
}>(); }>();
const orientationHook = useOrientation(); const orientationHook = useOrientation();
...@@ -61,6 +62,9 @@ const shellIsPortrait = computed((): boolean => { ...@@ -61,6 +62,9 @@ const shellIsPortrait = computed((): boolean => {
return (orientationHook.isPortrait as Ref<boolean>).value == true; return (orientationHook.isPortrait as Ref<boolean>).value == true;
}); });
/** 方向唯一来源:只算一次,模板所有绑定都读它('portrait' | 'landscape') */
const mode = computed((): string => (shellIsPortrait.value ? 'portrait' : 'landscape'));
const tabbarSource: HomeFrameTabbarSource = { const tabbarSource: HomeFrameTabbarSource = {
getTabIndex: (): number => props.activeTabIndex, getTabIndex: (): number => props.activeTabIndex,
getUserInfo: (): null | UTSJSONObject => { getUserInfo: (): null | UTSJSONObject => {
...@@ -70,14 +74,13 @@ const tabbarSource: HomeFrameTabbarSource = { ...@@ -70,14 +74,13 @@ const tabbarSource: HomeFrameTabbarSource = {
const _tabbar = useHomeFrameTabbar(tabbarSource); const _tabbar = useHomeFrameTabbar(tabbarSource);
const userName = _tabbar.userName; const userName = _tabbar.userName;
const showSetting = _tabbar.showSetting;
const showSwitchStore = _tabbar.showSwitchStore;
const onSettingVisible = _tabbar.onSettingVisible;
const onSetting = _tabbar.onSetting;
const jumpPersonCenter = _tabbar.jumpPersonCenter; const jumpPersonCenter = _tabbar.jumpPersonCenter;
const onSwitchStore = _tabbar.onSwitchStore;
const onSwitchStoreVisible = _tabbar.onSwitchStoreVisible; /** 头像文案:取用户名首字,空则「我」 */
const onSwitchStoreDone = _tabbar.onSwitchStoreDone; const avatarText = computed((): string => {
const n = (userName as Ref<string>).value;
return n == "" ? "我" : n.substring(0, 1);
});
/** tab 切换:preventNavigate 时仅 emit,否则跳回主容器 */ /** tab 切换:preventNavigate 时仅 emit,否则跳回主容器 */
function onTabChange(name: string | number): void { function onTabChange(name: string | number): void {
...@@ -104,23 +107,73 @@ onShow(() => { ...@@ -104,23 +107,73 @@ onShow(() => {
min-width: 0; min-width: 0;
} }
/* 竖屏:纵向排列 [内容区 | 底部TabBar] */ /* 竖屏:column-reverse —— DOM 中 .scene-shell-nav 在前、.scene-shell-main 在后,
反向后 nav 落到最底、main 在最顶(等价于把 nav 固定到底部,无需 order、不依赖后代选择器) */
.mode-portrait { .mode-portrait {
flex-direction: column; flex-direction: column-reverse;
} }
/* 横屏:横向排列 [侧边栏 | 内容区] */ /* 横屏:row —— nav 是 DOM 首个子项,自然落在最左(无需 order) */
.mode-landscape { .mode-landscape {
flex-direction: row; flex-direction: row;
} }
/* 侧边栏容器(横屏显示,竖屏由 v-show 隐藏) */ /* 导航容器:横竖屏共用的基础(作为 .scene-shell-root 的 flex 子项)。
.scene-shell-sidebar { 横竖屏尺寸差异用 self-class(.scene-shell-nav--landscape / --portrait)显式写死,
不走 var()(当前 uniapp-x 下 var() 嵌套引用/关键字替换均不可靠,曾导致横屏布局塌缩居中)。
方向由 .scene-shell-root 的 .mode-* 类驱动、nav 内部方向由 TabBarNav 自身 useOrientation + 内联样式驱动(不依赖父传 class/prop) */
.scene-shell-nav {
display: flex;
flex-direction: column;
flex-shrink: 0;
min-height: 0;
box-sizing: border-box;
/* 竖屏底栏预留底部安全区,避免内容压到 Home Indicator;
横屏侧栏放在左侧、底部多几 px 内边距无视觉影响 */
padding-bottom: env(safe-area-inset-bottom, 0px);
background-color: var(--bg-card, #FFFFFF);
/* 中性分隔阴影(横竖通用,避免依赖方向后代选择器) */
box-shadow: 0 0 6px rgba(0, 0, 0, 0.05);
}
/* 横屏左侧竖栏:固定宽度 + 撑满根高度(字面量,不依赖 var) */
.scene-shell-nav--landscape {
width: 88px;
height: 100%;
}
/* 竖屏底部横栏:占满宽度 + 固定高度(高度用单值 var --tabbar-height,可靠) */
.scene-shell-nav--portrait {
width: 100%;
height: var(--tabbar-height, 60px);
}
/* 头像区(仅横屏):点击进入个人中心 */
.shell-user {
width: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center;
box-sizing: border-box;
/* 顶部留白 + 与下方 tab 列表的缓冲间距,避免「首页」图标与头像贴边 */
padding: 18px 10px 8px;
flex-shrink: 0; flex-shrink: 0;
} }
.shell-user-name {
margin-top: 8px;
font-size: 13px;
font-weight: 600;
color: #1a2433;
line-height: 20px;
text-align: center;
width: 100%;
max-width: 104px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* 内容区:始终填满剩余空间 */ /* 内容区:始终填满剩余空间 */
.scene-shell-main { .scene-shell-main {
flex: 1 1 0%; flex: 1 1 0%;
...@@ -134,11 +187,5 @@ onShow(() => { ...@@ -134,11 +187,5 @@ onShow(() => {
padding: var(--page-edge-padding, 12px); padding: var(--page-edge-padding, 12px);
} }
/* 底部 TabBar 容器(竖屏显示,横屏由 v-show 隐藏) */ /* 导航容器横竖屏尺寸差异见上方 .scene-shell-nav--landscape / .scene-shell-nav--portrait 两个 self-class(显式写死 88px / 100%,不依赖 var) */
.scene-shell-tabbar {
display: flex;
flex-direction: column;
flex-shrink: 0;
height: var(--tabbar-height, 60px);
}
</style> </style>
...@@ -257,56 +257,7 @@ function getEmptyForm(): FormDataModel { ...@@ -257,56 +257,7 @@ function getEmptyForm(): FormDataModel {
} }
} }
/** 通用工具函数 */ import { fieldStr, parseIntSafe, arrivalRecordToDateString } from './helpers/reception-form.uts'
function fieldStr(data: UTSJSONObject | null, key: string): string {
if (data == null || data[key] == null) return ''
return `${data[key]}`
}
function parseIntSafe(s: string | null): number | null {
if (s == null || s === '') return null
const n = parseInt(s, 10)
return isNaN(n) ? null : n
}
/** 日期格式化辅助函数 */
function formatDateByTimestamp(timestamp: number): string {
const d = new Date(timestamp)
const y = d.getFullYear()
const m = (d.getMonth() + 1).toString().padStart(2, '0')
const day = d.getDate().toString().padStart(2, '0')
return `${y}-${m}-${day}`
}
/** 日期格式化:毫秒时间戳、数字串或 YYYY-MM-DD → 表单日期串 */
function arrivalRecordToDateString(v: any | null): string {
if (v == null) return ''
// 处理数字时间戳
if (typeof v === 'number') {
return v > 0 ? formatDateByTimestamp(v) : ''
}
const s = `${v}`.trim()
if (s === '') return ''
// 处理数字字符串(时间戳)
if (/^\d+$/.test(s) && s.length >= 10) {
const n = parseFloat(s)
if (!isNaN(n) && n > 0) {
return formatDateByTimestamp(n)
}
}
// 处理 YYYY-MM-DD 格式
if (s.length >= 10) {
const head = s.substring(0, 10)
const parts = head.split('-')
if (parts.length == 3) return head
}
return ''
}
const formData = ref<FormDataModel>(getEmptyForm()) const formData = ref<FormDataModel>(getEmptyForm())
const brandCascaderShow = ref(false) const brandCascaderShow = ref(false)
......
...@@ -31,9 +31,8 @@ ...@@ -31,9 +31,8 @@
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { type Ref, computed, onMounted, onShow, ref } from "vue"; import { computed, onMounted, onShow, onUnload, ref } from "vue";
import { getReceptions } from "@/api/modules/receptions.uts"; import { getReceptions } from "@/api/modules/receptions.uts";
import { useOrientation } from "@/services/adapter/hooks/index.uts";
import { DBRecord, recordService, type RecordData } from "@/services/recorder/index.uts"; import { DBRecord, recordService, type RecordData } from "@/services/recorder/index.uts";
import { storage } from "@/utils/storage.uts"; import { storage } from "@/utils/storage.uts";
import { delay } from "@/utils/delay.uts"; import { delay } from "@/utils/delay.uts";
...@@ -42,12 +41,6 @@ import { toStr } from "@/utils/common.uts"; ...@@ -42,12 +41,6 @@ import { toStr } from "@/utils/common.uts";
import ReceptionCustomerListTab from "./tabs/ReceptionCustomerListTab.uvue"; import ReceptionCustomerListTab from "./tabs/ReceptionCustomerListTab.uvue";
import pageVars from "./styles/index.vars"; import pageVars from "./styles/index.vars";
// 横竖屏检测
const orientationHook = useOrientation();
const isPortrait = computed((): boolean => {
return (orientationHook.isPortrait as Ref<boolean>).value;
});
/** 导航栏安全区高度(垂直 + 导航栏高度) */ /** 导航栏安全区高度(垂直 + 导航栏高度) */
const navbarStyle = computed((): UTSJSONObject => { const navbarStyle = computed((): UTSJSONObject => {
const raw = storage.get("statusBarHeight"); const raw = storage.get("statusBarHeight");
...@@ -273,6 +266,14 @@ function onUnsubmittedPendingChange(idx: number): void { ...@@ -273,6 +266,14 @@ function onUnsubmittedPendingChange(idx: number): void {
} }
} }
// 表单保存后通过 uni.$emit('refresh-reception-list') 触发,主动刷新当前筛选下的列表
function onReceptionListRefreshEvent(): void {
if (!receptionCenterPageReady.value) {
return;
}
void refreshReceptionListForCurrentFilter();
}
// ========== 生命周期 ========== // ========== 生命周期 ==========
onShow(async () => { onShow(async () => {
const userInfoObj = storage.getUserInfo(); const userInfoObj = storage.getUserInfo();
...@@ -298,7 +299,14 @@ onMounted(() => { ...@@ -298,7 +299,14 @@ onMounted(() => {
initGetReceptionRecordListImpl(); initGetReceptionRecordListImpl();
receptionCenterPageReady.value = true; receptionCenterPageReady.value = true;
void initListTabsLoad(false); void initListTabsLoad(false);
// 监听表单保存后的主动刷新事件(与 onShow 被动刷新互补,避免返回列表后数据滞后)
uni.$on('refresh-reception-list', onReceptionListRefreshEvent);
}); });
onUnload(() => {
uni.$off('refresh-reception-list', onReceptionListRefreshEvent);
});
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
......
...@@ -182,74 +182,7 @@ const materialGoodsCards = ref<GoodsCardItem[]>([]) ...@@ -182,74 +182,7 @@ const materialGoodsCards = ref<GoodsCardItem[]>([])
const materialGoodsFromApi = ref(false) const materialGoodsFromApi = ref(false)
function fieldStr(data: UTSJSONObject, key: string): string { import { fieldStr, parseIntSafe, arrivalRecordToDateString } from '../helpers/reception-form.uts'
const v = data[key]
if (v == null) {
return ''
}
return `${v}`
}
function parseIntSafe(s: string): number | null {
if (s == null || s == '') {
return null
}
const n = parseInt(s, 10)
if (isNaN(n)) {
return null
}
return n
}
/** 与 FormAdd 一致:arrivalDate / arrivalTime 多种形态 → YYYY-MM-DD */
function arrivalRecordToDateString(v: any | null): string {
if (v == null) {
return ''
}
if (typeof v == 'number') {
const ts = v as number
if (ts <= 0) {
return ''
}
const d = new Date(ts)
const y = d.getFullYear()
const m = (d.getMonth() + 1).toString().padStart(2, '0')
const day = d.getDate().toString().padStart(2, '0')
return `${y}-${m}-${day}`
}
const s = `${v}`.trim()
if (s == '') {
return ''
}
let allDigits = true
let j = 0
while (j < s.length) {
const c = s.charCodeAt(j) ?? -1
if (c < 48 || c > 57) {
allDigits = false
break
}
j++
}
if (allDigits && s.length >= 10) {
const n = parseFloat(s)
if (!isNaN(n) && n > 0) {
const d = new Date(n)
const y = d.getFullYear()
const m = (d.getMonth() + 1).toString().padStart(2, '0')
const day = d.getDate().toString().padStart(2, '0')
return `${y}-${m}-${day}`
}
}
const head = s.length >= 10 ? s.substring(0, 10) : ''
if (head.length == 10) {
const parts = head.split('-')
if (parts.length == 3) {
return head
}
}
return ''
}
/** 按 id 拉取详情并写入 resolvedDetail;失败时保持列表行数据并 toast(对齐 FormAdd.loadEditDetailIfNeeded) */ /** 按 id 拉取详情并写入 resolvedDetail;失败时保持列表行数据并 toast(对齐 FormAdd.loadEditDetailIfNeeded) */
async function loadDetailFromApiIfNeeded(row: UTSJSONObject): Promise<void> { async function loadDetailFromApiIfNeeded(row: UTSJSONObject): Promise<void> {
......
...@@ -183,10 +183,7 @@ const formData = ref<EditFormModel>(getEmptyForm()) ...@@ -183,10 +183,7 @@ const formData = ref<EditFormModel>(getEmptyForm())
const fullRecordSnapshot = ref<UTSJSONObject | null>(null) const fullRecordSnapshot = ref<UTSJSONObject | null>(null)
const submitLoading = ref(false) const submitLoading = ref(false)
function fieldStr(data: UTSJSONObject | null, key: string): string { import { fieldStr } from '../helpers/reception-form.uts'
if (data == null || data[key] == null) return ''
return `${data[key]}`
}
function resolveRecordId(r: UTSJSONObject): string { function resolveRecordId(r: UTSJSONObject): string {
const id = fieldStr(r, 'id') const id = fieldStr(r, 'id')
......
/**
* 接待表单共享工具(基础层)
* 收敛 FormAdd / FormDetail / ReceptionRecordEdit 中重复的工具函数,
* 消除三处近乎一致的 fieldStr / parseIntSafe / arrivalRecordToDateString 定义。
*/
import { get } from "@/utils/common.uts";
export function fieldStr(data: UTSJSONObject | null, key: string): string {
if (data == null || data[key] == null) return "";
return `${data[key]}`;
}
export function parseIntSafe(s: string | null): number | null {
if (s == null || s == "") return null;
const n = parseInt(s, 10);
return isNaN(n) ? null : n;
}
function formatDateByTimestamp(timestamp: number): string {
const d = new Date(timestamp);
const y = d.getFullYear();
const m = (d.getMonth() + 1).toString().padStart(2, "0");
const day = d.getDate().toString().padStart(2, "0");
return `${y}-${m}-${day}`;
}
/** 毫秒时间戳、数字串或 YYYY-MM-DD → 表单日期串 YYYY-MM-DD(三表单统一实现) */
export function arrivalRecordToDateString(v: any | null): string {
if (v == null) return "";
if (typeof v == "number") {
return v > 0 ? formatDateByTimestamp(v) : "";
}
const s = `${v}`.trim();
if (s == "") return "";
if (/^\d+$/.test(s) && s.length >= 10) {
const n = parseFloat(s);
if (!isNaN(n) && n > 0) {
return formatDateByTimestamp(n);
}
}
if (s.length >= 10) {
const head = s.substring(0, 10);
const parts = head.split("-");
if (parts.length == 3) return head;
}
return "";
}
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
import { get } from '@/utils/common.uts' import { get } from '@/utils/common.uts'
import { isBlankDisplayText, formatDateTimeLike } from '@/utils/format-utils.uts' import { isBlankDisplayText, formatDateTimeLike } from '@/utils/format-utils.uts'
import { getStr, getTs } from '../types/reception-center-helpers.uts' import { getStr, getTs, parseIntValue, parseNumberValue } from '../types/reception-center-helpers.uts'
import { parseIntValue, parseNumberValue } from '../receptionDetail.helpers.uts'
/** /**
* 解析日期字段为时间戳 * 解析日期字段为时间戳
......
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
* 合并自:receptionDetail.helper.uts / receptionDetail.qualityTransform.uts / lists/reception-detail-helpers.uts * 合并自:receptionDetail.helper.uts / receptionDetail.qualityTransform.uts / lists/reception-detail-helpers.uts
*/ */
import { get } from "@/utils/common.uts"; import { get } from "@/utils/common.uts";
// 基础数值工具已提升到 types 层(见 types/reception-center-helpers.uts),
// 此处 re-export 以保持外部(receptionDetail.uvue)的 import 路径不变。
import { parseNumberValue, parseIntValue } from "./types/reception-center-helpers.uts";
export { parseNumberValue, parseIntValue } from "./types/reception-center-helpers.uts";
// ============================================================ // ============================================================
// Part 1: 基础工具函数(原 receptionDetail.helper.uts) // Part 1: 基础工具函数(原 receptionDetail.helper.uts)
...@@ -15,21 +19,6 @@ export function toTrimmedString(raw: any | null): string { ...@@ -15,21 +19,6 @@ export function toTrimmedString(raw: any | null): string {
return `${raw}`.trim(); return `${raw}`.trim();
} }
export function parseNumberValue(raw: any | null): number | null {
if (raw == null) {
return null;
}
if (typeof raw == "number") {
return raw as number;
}
const s = toTrimmedString(raw);
if (s == "") {
return null;
}
const n = parseFloat(s);
return isNaN(n) ? null : n;
}
export function formatReceptionScore(item: UTSJSONObject | null | undefined): string { export function formatReceptionScore(item: UTSJSONObject | null | undefined): string {
if (item == null) { if (item == null) {
return "-"; return "-";
...@@ -68,21 +57,6 @@ export function formatReceptionScore(item: UTSJSONObject | null | undefined): st ...@@ -68,21 +57,6 @@ export function formatReceptionScore(item: UTSJSONObject | null | undefined): st
return "-"; return "-";
} }
export function parseIntValue(raw: any | null): number | null {
if (raw == null) {
return null;
}
if (typeof raw == "number") {
return raw as number;
}
const s = toTrimmedString(raw);
if (s == "") {
return null;
}
const n = parseInt(s);
return isNaN(n) ? null : n;
}
export function isSuccessCode(codeRaw: any | null): boolean { export function isSuccessCode(codeRaw: any | null): boolean {
const code = toTrimmedString(codeRaw); const code = toTrimmedString(codeRaw);
return code == "" || code == "0"; return code == "" || code == "0";
......
...@@ -323,9 +323,9 @@ function onReceptionCardClick(item: UTSJSONObject): void { ...@@ -323,9 +323,9 @@ function onReceptionCardClick(item: UTSJSONObject): void {
url: `/pages/receptionCenter/forms/FormDetail?record=${encodeURIComponent(JSON.stringify(item))}` url: `/pages/receptionCenter/forms/FormDetail?record=${encodeURIComponent(JSON.stringify(item))}`
}); });
} else { } else {
// 未提交:跳转到编辑页 // 未提交:跳转到本地记录编辑页(ReceptionRecordEdit 支持传入 record 作为兜底)
uni.navigateTo({ uni.navigateTo({
url: `/pages/receptionCenter/forms/FormEdit?record=${encodeURIComponent(JSON.stringify(item))}` url: `/pages/receptionCenter/forms/ReceptionRecordEdit?record=${encodeURIComponent(JSON.stringify(item))}`
}); });
} }
} }
......
...@@ -91,3 +91,46 @@ export function mergeByKey(existing: UTSJSONObject[], pageRows: UTSJSONObject[], ...@@ -91,3 +91,46 @@ export function mergeByKey(existing: UTSJSONObject[], pageRows: UTSJSONObject[],
} }
return merged return merged
} }
// ============================================================
// 基础数值/字符串工具(模块权威实现)
// 原分散在 receptionDetail.helpers.uts,提升到基础层供列表/详情/表单共享,
// 消除 reception-list-helpers 对详情大文件的反向依赖。
// ============================================================
export function toTrimmedString(raw: any | null): string {
if (raw == null) {
return "";
}
return `${raw}`.trim();
}
export function parseNumberValue(raw: any | null): number | null {
if (raw == null) {
return null;
}
if (typeof raw == "number") {
return raw as number;
}
const s = toTrimmedString(raw);
if (s == "") {
return null;
}
const n = parseFloat(s);
return isNaN(n) ? null : n;
}
export function parseIntValue(raw: any | null): number | null {
if (raw == null) {
return null;
}
if (typeof raw == "number") {
return raw as number;
}
const s = toTrimmedString(raw);
if (s == "") {
return null;
}
const n = parseInt(s);
return isNaN(n) ? null : n;
}
...@@ -41,9 +41,12 @@ ...@@ -41,9 +41,12 @@
/* 作为 flex 列容器,让内部 EntryGrid 用 flex:1 可靠填满,避免竖屏高度塌缩 */ /* 作为 flex 列容器,让内部 EntryGrid 用 flex:1 可靠填满,避免竖屏高度塌缩 */
display: flex; display: flex;
flex-direction: column; flex-direction: column;
/* 竖屏/横屏均给确定高度,作为网格填充的基准 */ /* 高度跟随 EntryGrid 真实内容高度(竖屏单行≈50px / 横屏 2×2≈224px),
height: var(--reports-entry-grid-wrap-height, 38px); 不再用固定 --reports-entry-grid-wrap-height,避免横竖屏或分辨率切换时
固定值与 grid 实际渲染高度不符而被裁短/留空。flex-shrink:0 确保不被挤压 */
height: auto;
flex-shrink: 0; flex-shrink: 0;
min-height: var(--module-entry-grid-min-height, 48px);
margin-top: var(--reports-entry-grid-wrap-margin-top, 0px); margin-top: var(--reports-entry-grid-wrap-margin-top, 0px);
box-sizing: border-box; box-sizing: border-box;
} }
......
...@@ -12,11 +12,10 @@ export default { ...@@ -12,11 +12,10 @@ export default {
"--reports-layout-padding": "10px 0 0", "--reports-layout-padding": "10px 0 0",
"--reports-entry-flex": "0 0 auto", "--reports-entry-flex": "0 0 auto",
"--reports-entry-width": "100%", "--reports-entry-width": "100%",
"--reports-entry-height": "50px", "--reports-entry-height": "auto",
"--reports-entry-min-height": "50px", "--reports-entry-min-height": "50px",
"--reports-entry-margin-right": "0px", "--reports-entry-margin-right": "0px",
"--reports-entry-margin-bottom": "12px", "--reports-entry-margin-bottom": "12px",
"--reports-entry-grid-wrap-height": "50px",
"--reports-entry-grid-wrap-margin-top": "0px", "--reports-entry-grid-wrap-margin-top": "0px",
"--module-entry-grid-min-height": "50px", "--module-entry-grid-min-height": "50px",
"--module-entry-grid-list-min-height": "50px", "--module-entry-grid-list-min-height": "50px",
...@@ -71,7 +70,6 @@ export default { ...@@ -71,7 +70,6 @@ export default {
"--reports-entry-min-height": "260px", "--reports-entry-min-height": "260px",
"--reports-entry-margin-right": "20px", "--reports-entry-margin-right": "20px",
"--reports-entry-margin-bottom": "0px", "--reports-entry-margin-bottom": "0px",
"--reports-entry-grid-wrap-height": "218px",
"--reports-entry-grid-wrap-margin-top": "12px", "--reports-entry-grid-wrap-margin-top": "12px",
"--reports-entry-overview-display": "flex", "--reports-entry-overview-display": "flex",
"--reports-entry-overview-margin": "12px 14px 0", "--reports-entry-overview-margin": "12px 14px 0",
...@@ -114,7 +112,6 @@ export default { ...@@ -114,7 +112,6 @@ export default {
"landscape-816x393": { "landscape-816x393": {
"--reports-entry-width": "220px", "--reports-entry-width": "220px",
"--reports-entry-height": "100%", "--reports-entry-height": "100%",
"--reports-entry-grid-wrap-height": "196px",
"--reports-entry-grid-wrap-margin-top": "10px", "--reports-entry-grid-wrap-margin-top": "10px",
"--reports-entry-overview-margin": "10px 10px 0", "--reports-entry-overview-margin": "10px 10px 0",
"--reports-entry-overview-padding": "10px", "--reports-entry-overview-padding": "10px",
......
...@@ -40,9 +40,12 @@ ...@@ -40,9 +40,12 @@
/* 作为 flex 列容器,让内部 EntryGrid 用 flex:1 可靠填满,避免竖屏高度塌缩 */ /* 作为 flex 列容器,让内部 EntryGrid 用 flex:1 可靠填满,避免竖屏高度塌缩 */
display: flex; display: flex;
flex-direction: column; flex-direction: column;
/* 竖屏/横屏均给确定高度,作为网格填充的基准 */ /* 高度跟随 EntryGrid 真实内容高度(竖屏单行≈50px / 横屏 2×2≈224px),
height: var(--tasks-entry-grid-wrap-height, 40px); 不再用固定 --tasks-entry-grid-wrap-height,避免横竖屏或分辨率切换时
固定值与 grid 实际渲染高度不符而被裁短/留空。flex-shrink:0 确保不被挤压 */
height: auto;
flex-shrink: 0; flex-shrink: 0;
min-height: var(--module-entry-grid-min-height, 48px);
margin-top: var(--tasks-entry-grid-wrap-margin-top, 0px); margin-top: var(--tasks-entry-grid-wrap-margin-top, 0px);
box-sizing: border-box; box-sizing: border-box;
} }
......
...@@ -19,11 +19,10 @@ export default { ...@@ -19,11 +19,10 @@ export default {
"--tasks-content-padding": "0px", "--tasks-content-padding": "0px",
"--tasks-entry-panel-flex": "0 0 auto", "--tasks-entry-panel-flex": "0 0 auto",
"--tasks-entry-panel-width": "100%", "--tasks-entry-panel-width": "100%",
"--tasks-entry-panel-height": "50px", "--tasks-entry-panel-height": "auto",
"--tasks-entry-panel-min-height": "50px", "--tasks-entry-panel-min-height": "50px",
"--tasks-entry-panel-margin-right": "0px", "--tasks-entry-panel-margin-right": "0px",
"--tasks-entry-panel-margin-bottom": "12px", "--tasks-entry-panel-margin-bottom": "12px",
"--tasks-entry-grid-wrap-height": "50px",
"--tasks-entry-grid-wrap-margin-top": "0px", "--tasks-entry-grid-wrap-margin-top": "0px",
"--module-entry-grid-min-height": "50px", "--module-entry-grid-min-height": "50px",
"--module-entry-grid-list-min-height": "50px", "--module-entry-grid-list-min-height": "50px",
...@@ -155,7 +154,6 @@ export default { ...@@ -155,7 +154,6 @@ export default {
"--tasks-entry-panel-min-height": "260px", "--tasks-entry-panel-min-height": "260px",
"--tasks-entry-panel-margin-right": "20px", "--tasks-entry-panel-margin-right": "20px",
"--tasks-entry-panel-margin-bottom": "0px", "--tasks-entry-panel-margin-bottom": "0px",
"--tasks-entry-grid-wrap-height": "218px",
"--tasks-entry-grid-wrap-margin-top": "12px", "--tasks-entry-grid-wrap-margin-top": "12px",
"--tasks-entry-overview-display": "flex", "--tasks-entry-overview-display": "flex",
"--tasks-entry-overview-margin": "12px 14px 0", "--tasks-entry-overview-margin": "12px 14px 0",
...@@ -279,7 +277,6 @@ export default { ...@@ -279,7 +277,6 @@ export default {
"landscape-816x393": { "landscape-816x393": {
"--tasks-entry-panel-width": "220px", "--tasks-entry-panel-width": "220px",
"--tasks-entry-panel-height": "100%", "--tasks-entry-panel-height": "100%",
"--tasks-entry-grid-wrap-height": "196px",
"--tasks-entry-grid-wrap-margin-top": "10px", "--tasks-entry-grid-wrap-margin-top": "10px",
"--tasks-entry-overview-margin": "10px 10px 0", "--tasks-entry-overview-margin": "10px 10px 0",
"--tasks-entry-overview-padding": "10px", "--tasks-entry-overview-padding": "10px",
......
...@@ -13,13 +13,16 @@ import { lockOrientation, unlockOrientation } from '@/utils/plus-screen.uts' ...@@ -13,13 +13,16 @@ import { lockOrientation, unlockOrientation } from '@/utils/plus-screen.uts'
// import { updateResolutionConfig } from '@/services/adapter/index.uts' // import { updateResolutionConfig } from '@/services/adapter/index.uts'
// #endif // #endif
var refreshTimer: number = 0
const POLICY_PHONE_LOCKED = 0 const POLICY_PHONE_LOCKED = 0
const POLICY_PAD_UNLOCKED = 1 const POLICY_PAD_UNLOCKED = 1
const POLICY_NEUTRAL = 2 const POLICY_NEUTRAL = 2
var lastAppliedOrientationPolicy: number = -1 var lastAppliedOrientationPolicy: number = -1
/** 小屏锁竖屏的补锁延迟点(ms):对抗框架在 onLaunch 之后重新套用竖屏 */
const PHONE_RELOCK_DELAYS: number[] = [280, 620]
/** Pad 解锁的延迟补解锁点(ms) */
const PAD_UNLOCK_DELAY = 320
function computeMaxScreenDim(): number { function computeMaxScreenDim(): number {
const systemInfo = uni.getSystemInfoSync() const systemInfo = uni.getSystemInfoSync()
let w = systemInfo.screenWidth let w = systemInfo.screenWidth
...@@ -54,7 +57,6 @@ function shouldLockHandsetPortrait(): boolean { ...@@ -54,7 +57,6 @@ function shouldLockHandsetPortrait(): boolean {
function logOrientationDiagnostics(context: string): void { function logOrientationDiagnostics(context: string): void {
const dev = uni.getDeviceInfo() const dev = uni.getDeviceInfo()
const sys = uni.getSystemInfoSync() const sys = uni.getSystemInfoSync()
const win = uni.getWindowInfo()
let devLine = "[orientation-diag] " + context + " getDeviceInfo=null" let devLine = "[orientation-diag] " + context + " getDeviceInfo=null"
if (dev != null) { if (dev != null) {
const dt = dev.deviceType != null ? (dev.deviceType as string) : "(null)" const dt = dev.deviceType != null ? (dev.deviceType as string) : "(null)"
...@@ -63,41 +65,27 @@ function logOrientationDiagnostics(context: string): void { ...@@ -63,41 +65,27 @@ function logOrientationDiagnostics(context: string): void {
devLine = "[orientation-diag] " + context + " getDeviceInfo.deviceType=" + dt + " deviceModel=" + dm + " deviceOrientation=" + dor devLine = "[orientation-diag] " + context + " getDeviceInfo.deviceType=" + dt + " deviceModel=" + dm + " deviceOrientation=" + dor
} }
const sysOrient = sys.deviceOrientation as string const sysOrient = sys.deviceOrientation as string
console.log(devLine + " systemInfo.deviceOrientation=" + sysOrient)
} }
// function scheduleRefresh(delayMs: number): void { /** 对同一个动作在多个延迟点重复执行(对抗框架在 onLaunch 之后重新套用方向) */
// if (refreshTimer != 0) { function scheduleRetries(action: () => void, delays: number[]): void {
// clearTimeout(refreshTimer) for (let i = 0; i < delays.length; i++) {
// } const d = delays[i]
// refreshTimer = setTimeout((): void => { setTimeout((): void => {
// layoutService.refreshScreenInfo() action()
// // updateResolutionConfig() }, d)
// refreshTimer = 0 }
// }, delayMs) }
// }
/** Pad 解锁后尺寸变化较慢,二次刷新(第二段不用 refreshTimer,避免互相 clear) */
// function scheduleRefreshAfterPadUnlock(): void {
// scheduleRefresh(250)
// setTimeout((): void => {
// layoutService.refreshScreenInfo()
// // updateResolutionConfig()
// }, 750)
// }
/** globalStyle pageOrientation=auto 时,框架可能在 onLaunch 之后才生效,需延迟再锁竖屏 */ /** globalStyle pageOrientation=auto 时,框架可能在 onLaunch 之后才生效,需延迟再锁竖屏 */
function applyPhonePortraitLocksWithRetry(): void { function applyPhonePortraitLocksWithRetry(): void {
console.log("[orientation-lock] 小屏手持机 → lockOrientation(portrait-primary)(含延迟补锁,对抗 auto)") console.log("[orientation-lock] 小屏手持机 → lockOrientation(portrait-primary)(含延迟补锁,对抗 auto)")
lockOrientation('portrait-primary') lockOrientation('portrait-primary')
setTimeout((): void => { scheduleRetries((): void => {
lockOrientation('portrait-primary')
console.log("[orientation-lock] 小屏 约280ms 补锁 portrait")
}, 280)
setTimeout((): void => {
lockOrientation('portrait-primary') lockOrientation('portrait-primary')
console.log("[orientation-lock] 小屏 约620ms 再补锁 portrait") console.log("[orientation-lock] 小屏 延迟补锁 portrait")
}, 620) }, PHONE_RELOCK_DELAYS)
// scheduleRefresh(450)
} }
export function applyScreenOrientationLock(): void { export function applyScreenOrientationLock(): void {
...@@ -123,8 +111,7 @@ export function applyScreenOrientationLock(): void { ...@@ -123,8 +111,7 @@ export function applyScreenOrientationLock(): void {
setTimeout((): void => { setTimeout((): void => {
unlockOrientation() unlockOrientation()
console.log("[orientation-lock] Pad 延迟再 unlock 一次(避免框架在 onLaunch 之后重新套用竖屏)") console.log("[orientation-lock] Pad 延迟再 unlock 一次(避免框架在 onLaunch 之后重新套用竖屏)")
}, 320) }, PAD_UNLOCK_DELAY)
// scheduleRefreshAfterPadUnlock()
} else { } else {
if (lastAppliedOrientationPolicy == POLICY_NEUTRAL) { if (lastAppliedOrientationPolicy == POLICY_NEUTRAL) {
return return
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!