Commit 3b2d2699 by Lin

功能(接待中心):增强布局响应能力并添加动态样式

- 根据屏幕分辨率实现了横屏和竖屏模式的动态样式。
- 引入了新的 UTS 样式变量,用于常见、横屏和竖屏配置。
- 更新组件以使用动态样式,提高布局的适应性。
- 添加了控制台日志以调试分辨率配置和布局同步。
- 清理了未使用的样式,并提高了各个组件的代码可读性。
1 parent 11bad5f5
...@@ -21,7 +21,7 @@ const styleObj = computed((): UTSJSONObject => { ...@@ -21,7 +21,7 @@ const styleObj = computed((): UTSJSONObject => {
}) })
useResolutionConfig() useResolutionConfig()
console.log('useResolutionConfigAAA', useResolutionConfig())
const LAYOUT_ROOT_POLL_MS = 350 const LAYOUT_ROOT_POLL_MS = 350
let layoutRootPollId: number | null = null let layoutRootPollId: number | null = null
let lastLayoutW = 0 let lastLayoutW = 0
......
<template> <template>
<!-- 接待中心 Tab 聚合页 --> <!-- 接待中心 Tab 聚合页 -->
<layout-root :key="isLandscape">
<!-- <view class="test" :style="dynamicModuleBoxStyle">
测试文案 {{ dynamicModuleBoxStyle}}
</view> -->
<view class="reception-center-page"> <view class="reception-center-page">
<!-- 顶部安全区 --> <!-- 顶部安全区 -->
<!-- <view class="reception-safe-top-spacer" :style="receptionSafeTopSpacerStyle"></view> --> <!-- <view class="reception-safe-top-spacer" :style="receptionSafeTopSpacerStyle"></view> -->
...@@ -161,11 +165,12 @@ ...@@ -161,11 +165,12 @@
<ReceptionDetail :item="receptionRecordItem" @close="onReceptionRecordDetailClose" /> <ReceptionDetail :item="receptionRecordItem" @close="onReceptionRecordDetailClose" />
</view> </view>
</view> </view>
</layout-root>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
// 接待中心 Tab 聚合页 // 接待中心 Tab 聚合页
import { ref, computed, onMounted, onUnmounted, watch } from 'vue' import { ref, computed, onMounted, onUnmounted, watch, onResize } from 'vue'
import { type UnPickerColumn, type UnPickerColumnItem, type UnPickerConfirmEvent, type UnTabItem } from '@/uni_modules/uview-unix' import { type UnPickerColumn, type UnPickerColumnItem, type UnPickerConfirmEvent, type UnTabItem } from '@/uni_modules/uview-unix'
import FormDetail from './forms/FormDetail.uvue' import FormDetail from './forms/FormDetail.uvue'
import ReceptionDetail from './receptionDetail.uvue' import ReceptionDetail from './receptionDetail.uvue'
...@@ -175,7 +180,11 @@ import type { CompareRow, OutputSummary } from './types/reception-output-types.u ...@@ -175,7 +180,11 @@ import type { CompareRow, OutputSummary } from './types/reception-output-types.u
import { getStr, getNum, getTs, getCurrentMonthRange, getTodayDayRangeStrings, getMockPerformanceData, isPerformanceDataEmpty, resolveHasMore, mergeByKey } from './types/reception-center-helpers.uts' import { getStr, getNum, getTs, getCurrentMonthRange, getTodayDayRangeStrings, getMockPerformanceData, isPerformanceDataEmpty, resolveHasMore, mergeByKey } from './types/reception-center-helpers.uts'
import { getMerchantPerformance, getCustomerFileList, getReceptionList } from '@/api/receiption.uts' import { getMerchantPerformance, getCustomerFileList, getReceptionList } from '@/api/receiption.uts'
import { storage } from '@/utils/storage.uts' import { storage } from '@/utils/storage.uts'
import { resolutionState } from '@/services/adapter/index.uts'
import { cssClassRef } from "@/services/adapter";
// 导入样式变量
import { getLandscapeConfig } from "./styles/landscape.uts";
import { getPortraitConfig } from "./styles/portrait.uts";
// ========== Tab 管理 ========== // ========== Tab 管理 ==========
// ========== Tab 管理 ========== // ========== Tab 管理 ==========
/** 主 Tab:0=业绩看板,1=客户列表 */ /** 主 Tab:0=业绩看板,1=客户列表 */
...@@ -184,6 +193,43 @@ const mainTabs: UnTabItem[] = [ ...@@ -184,6 +193,43 @@ const mainTabs: UnTabItem[] = [
{ name: '业绩看板' } as UnTabItem, { name: '业绩看板' } as UnTabItem,
{ name: '客户列表' } as UnTabItem { name: '客户列表' } as UnTabItem
] ]
// 动态样式 - 根据分辨率返回不同的样式
// 动态样式 - 根据分辨率返回不同的样式
const dynamicModuleBoxStyle = computed((): any => {
// 使用 cssClassRef.value 确保响应式
const adapterCls = cssClassRef.value;
// // 横屏配置
// const landscapeConfig = getLandscapeConfig(adapterCls);
// console.log('[receptionCenter] landscapeConfig', landscapeConfig);
// // 竖屏配置
// const portraitConfig = getPortraitConfig(adapterCls);
if (adapterCls.indexOf('layout-landscape-1174x768') >= 0) {
const cfg = getLandscapeConfig(adapterCls)
// 注意:getLandscapeConfig 返回模块级常量对象(同引用),computed 可能判定“值未变”从而不触发视图更新
// 这里返回一个新对象引用,确保 :style 能更新
return cfg != null ? ({ ...cfg } as UTSJSONObject) : ({} as UTSJSONObject);
// return {
// backgroundColor: '#134aff',
// height: '300px'
// };
}
if (adapterCls.indexOf('layout-portrait-768x1174') >= 0) {
const cfg = getPortraitConfig(adapterCls)
return cfg != null ? ({ ...cfg } as UTSJSONObject) : ({} as UTSJSONObject);
// return {
// backgroundColor: '#886efc',
// height: '60px'
// };
}
// computed 返回值不能为 null(UTS 中 Any? -> Any 会触发类型不匹配)
return {} as UTSJSONObject;
});
/** 客户列表下的二级 Tab:0=客户录入,1=接待复盘(原 rightTabIndex) */ /** 客户列表下的二级 Tab:0=客户录入,1=接待复盘(原 rightTabIndex) */
const listSubTabIndex = ref(0) const listSubTabIndex = ref(0)
...@@ -220,7 +266,6 @@ const RECEPTION_PAGE_SIZE = 10 ...@@ -220,7 +266,6 @@ const RECEPTION_PAGE_SIZE = 10
const receptionPageNum = ref(1) const receptionPageNum = ref(1)
const receptionListLoadingMore = ref(false) const receptionListLoadingMore = ref(false)
const receptionListHasMore = ref(true) const receptionListHasMore = ref(true)
const show = ref(false) const show = ref(false)
/** 已提交:战败/成交下拉 */ /** 已提交:战败/成交下拉 */
const showSubmittedResultPicker = ref(false) const showSubmittedResultPicker = ref(false)
...@@ -314,6 +359,8 @@ function syncReceptionDashboardLayout(): void { ...@@ -314,6 +359,8 @@ function syncReceptionDashboardLayout(): void {
`[ReceptionCenter] 屏幕方向变化:${nextSplit ? '横屏' : '竖屏'}(w=${w}, h=${h}, window=${ww}x${wh}, screen=${sw}x${sh})` `[ReceptionCenter] 屏幕方向变化:${nextSplit ? '横屏' : '竖屏'}(w=${w}, h=${h}, window=${ww}x${wh}, screen=${sw}x${sh})`
) )
} }
console.log('[ReceptionCenter] syncReceptionDashboardLayout');
// 横屏窄宽适配:避免右侧筛选区控件(如 segmented)在小于阈值时出现横向溢出 // 横屏窄宽适配:避免右侧筛选区控件(如 segmented)在小于阈值时出现横向溢出
const RECEPTION_FILTER_NARROW_WIDTH = 920 const RECEPTION_FILTER_NARROW_WIDTH = 920
const nextFilterNarrowMode = nextSplit && w > 0 && w < RECEPTION_FILTER_NARROW_WIDTH const nextFilterNarrowMode = nextSplit && w > 0 && w < RECEPTION_FILTER_NARROW_WIDTH
...@@ -326,6 +373,40 @@ let getPerformanceDataImpl: () => Promise<void> = async (): Promise<void> => {} ...@@ -326,6 +373,40 @@ let getPerformanceDataImpl: () => Promise<void> = async (): Promise<void> => {}
let getCustomerListImpl: (append: boolean) => Promise<void> = async (_append: boolean): Promise<void> => {} let getCustomerListImpl: (append: boolean) => Promise<void> = async (_append: boolean): Promise<void> => {}
let getReceptionRecordListImpl: (append: boolean) => Promise<void> = async (_append: boolean): Promise<void> => {} let getReceptionRecordListImpl: (append: boolean) => Promise<void> = async (_append: boolean): Promise<void> => {}
// onResize 回调可能在窗口尺寸变化过程中高频触发,这里做一次去重,避免控制台刷屏
let lastOnResizeWidth: number | null = null
let lastOnResizeHeight: number | null = null
onResize((res: any) => {
// 1) 直接打印回调参数(满足“打印返回参数”的需求)
console.log('[ReceptionCenter][onResize] res =', res)
// 2) 尝试从回调中提取 width/height 做去重(字段结构在不同端可能不同,必须防御性处理)
let w: number | null = null
let h: number | null = null
const obj = res as UTSJSONObject
const sizeRaw = obj['size']
if (sizeRaw != null) {
const sizeObj = sizeRaw as UTSJSONObject
const ww = sizeObj['windowWidth']
const wh = sizeObj['windowHeight']
if (typeof ww === 'number') { w = ww }
if (typeof wh === 'number') { h = wh }
} else {
const ww = obj['windowWidth']
const wh = obj['windowHeight']
if (typeof ww === 'number') { w = ww }
if (typeof wh === 'number') { h = wh }
}
if (w != null && h != null) {
if (lastOnResizeWidth != w || lastOnResizeHeight != h) {
lastOnResizeWidth = w
lastOnResizeHeight = h
console.log(`[ReceptionCenter][onResize] size = ${w}x${h}`)
}
}
})
function getPerformanceData(): Promise<void> { function getPerformanceData(): Promise<void> {
return getPerformanceDataImpl() return getPerformanceDataImpl()
} }
...@@ -1060,10 +1141,9 @@ function openReviewPicker(): void { ...@@ -1060,10 +1141,9 @@ function openReviewPicker(): void {
onMounted(() => { onMounted(() => {
// JS判断安全区顶部占位、横竖屏判断、以及 横屏窄宽时右侧筛选区的窄屏模式 // JS判断安全区顶部占位、横竖屏判断、以及 横屏窄宽时右侧筛选区的窄屏模式
// syncReceptionDashboardLayout() syncReceptionDashboardLayout()
// uni-app x(尤其 APP 端)对 onWindowResize 支持不稳定,这里统一用轮询保证兼容性 // uni-app x(尤其 APP 端)对 onWindowResize 支持不稳定,这里统一用轮询保证兼容性
// 如需 H5 实时监听,可在 H5 条件编译块里单独注册 // 如需 H5 实时监听,可在 H5 条件编译块里单独注册
receptionDashboardLayoutPollId = setInterval(syncReceptionDashboardLayout, RECEPTION_LAYOUT_POLL_MS)
// 页面加载后再次兜底计算(避免运行期时区/时间跳变导致不一致) // 页面加载后再次兜底计算(避免运行期时区/时间跳变导致不一致)
setTimeProgress() setTimeProgress()
...@@ -1104,7 +1184,10 @@ onUnmounted(() => { ...@@ -1104,7 +1184,10 @@ onUnmounted(() => {
}) })
</script> </script>
<style> <style scoped lang="scss">
// @import "./styles/common.scss";
// @import "./styles/landscape.scss";
// @import "./styles/portrait.scss";
/* 接待中心页面包一层:供预录表单绝对定位覆盖 */ /* 接待中心页面包一层:供预录表单绝对定位覆盖 */
.reception-center-page { .reception-center-page {
flex: 1; flex: 1;
......
// ========================================================================
// HomeFrame 公共样式变量 - UTS 定义
// ========================================================================
/**
* 模块盒子高度(默认值)
*/
export const MODULE_BOX_HEIGHT = 'var(--l-module-box-height)';
/**
* ToolBox 最小高度(默认值)
*/
export const TOOL_BOX_MIN_HEIGHT = 'var(--l-tool-box-min-height)';
/**
* Common Title 高度(默认值)
*/
export const COMMON_TITLE_HEIGHT = 'var(--l-common-title-height)';
/**
* Left Tabs 高度(默认)
*/
export const LEFT_TABS_HEIGHT = '540px';
/**
* Icon Box 尺寸(默认)
*/
export const ICON_BOX_SIZE = '52px';
export const ICON_BOX_RADIUS = '26px';
/**
* Tab Label 字体大小(默认)
*/
export const TAB_LABEL_FONTSIZE = '13px';
/**
* TabBar 高度(默认竖屏)
*/
export const TABBAR_HEIGHT_DEFAULT = 56;
/**
* TabBar 图标尺寸(默认竖屏)
*/
export const TABBAR_ICON_SIZE_DEFAULT = 24;
.layout { .layout-landscape-common {
&.layout-landscape-1920x1080 { .test {
.login { font-size: 24px;
width: 500px; color: #166fff;
padding-top: 30px; background-color: #050607;
.title {
font-size: 36px;
color: #1e293b;
}
.btn {
height: 54px;
}
}
}
&.layout-landscape-1174x768 {
.login {
width: 470px;
padding-top: 24px;
}
} }
}
&.layout-landscape-common { .layout-landscape-1174x768 {
.login { .test {
width: 48%; height: 300px;
min-width: 430px; font-size: 100px;
} color: #166fff;
background-color: #134aff;
} }
} }
\ No newline at end of file \ No newline at end of file
// ========================================================================
// HomeFrame 横屏样式变量 - UTS 定义(按分辨率)
// ========================================================================
/**
* 横屏配置类型
*/
export type LandscapeConfig = {
// index.uvue 布局
backgroundColor?: string
height?: string
}
/**
* 1174x768 横屏配置
*/
export const LANDSCAPE_1174x768: LandscapeConfig = {
backgroundColor: '#134aff',
height: '300px'
};
/**
* 1920x1080 横屏配置
*/
export const LANDSCAPE_1920x1080: LandscapeConfig = {
backgroundColor: '#134aff',
height: '300px'
};
/**
* 根据分辨率获取横屏配置
*/
export function getLandscapeConfig(resolutionKey: string): null | LandscapeConfig {
// UTS 中字符串比较可能有问题,使用 indexOf 替代
if (resolutionKey.indexOf('layout-landscape-1174x768') >= 0) {
return LANDSCAPE_1174x768;
}
if (resolutionKey.indexOf('layout-landscape-1920x1080') >= 0) {
return LANDSCAPE_1920x1080;
}
return null;
}
.layout { .layout-portrait-common {
&.layout-portrait-common { .test {
.login { font-size: 24px;
width: 88%; color: #166fff;
margin-top: 94px; background-color: #54ff7e;
padding: 24px 18px 18px;
.title {
font-size: 28px;
}
} }
} }
} .layout-portrait-640x979 {
.test {
font-size: 24px;
color: #166fff;
background-color: #886efc;
}
}
.layout-portrait-768x1174 {
.test {
height: 40px;
font-size: 20px;
color: #166fff;
background-color: #fc6e81;
}
}
\ No newline at end of file \ No newline at end of file
// ========================================================================
// HomeFrame 竖屏样式变量 - UTS 定义(按分辨率)
// ========================================================================
/**
* 竖屏标题组文字样式
*/
export type PortraitHeaderTitleGroup = {
fontSize?: string
color?: string
marginBottom?: string,
backgroundColor?: string
}
/**
* 竖屏配置类型
*/
export type PortraitConfig = {
// index.uvue 布局
backgroundColor?: string
height?: string
}
/**
* 768x1174 竖屏配置(Pad 竖屏)
*/
export const PORTRAIT_768x1174: PortraitConfig = {
backgroundColor: '#886efc',
height: '30px',
};
/**
* 其他竖屏分辨率(默认)
*/
export const PORTRAIT_COMMON: PortraitConfig = {
// LeftSide TabBar
tabbarHeight: 56,
tabbarIconSize: 24
};
/**
* 根据分辨率获取竖屏配置
*/
export function getPortraitConfig(resolutionKey: string): null | PortraitConfig {
// UTS 中字符串比较可能有问题,使用 indexOf 替代
if (resolutionKey.indexOf('layout-portrait-768x1174') >= 0) {
return PORTRAIT_768x1174;
}
return null;
}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<view class="card-header"> <view class="card-header">
<view class="header-surface"> <view class="header-surface">
<view class="header-top-row"> <view class="header-top-row">
<view class="header-title-group"> <view class="header-title-group" :style="dynamicModuleBoxStyle">
<text class="header-eyebrow">数据概览</text> <text class="header-eyebrow">数据概览</text>
<text class="header-title">业绩看板</text> <text class="header-title">业绩看板</text>
</view> </view>
...@@ -55,6 +55,10 @@ import CardFlow from '../cards/CardFlow.uvue' ...@@ -55,6 +55,10 @@ import CardFlow from '../cards/CardFlow.uvue'
import CardOutputValue from '../cards/CardOutputValue.uvue' import CardOutputValue from '../cards/CardOutputValue.uvue'
import CardMonthValue from '../cards/CardMonthValue.uvue' import CardMonthValue from '../cards/CardMonthValue.uvue'
import type { CompareRow, OutputSummary } from '../types/reception-output-types.uts' import type { CompareRow, OutputSummary } from '../types/reception-output-types.uts'
import { cssClassRef } from "@/services/adapter";
// 导入样式变量
import { getLandscapeConfig } from "../styles/landscape.uts";
import { getPortraitConfig } from "../styles/portrait.uts";
const props = defineProps<{ const props = defineProps<{
performanceData: UTSJSONObject performanceData: UTSJSONObject
...@@ -77,7 +81,21 @@ const emit = defineEmits<{ ...@@ -77,7 +81,21 @@ const emit = defineEmits<{
function onUpdateOutputTabIndex(index: number): void { function onUpdateOutputTabIndex(index: number): void {
emit('update:outputTabIndex', index) emit('update:outputTabIndex', index)
} }
const dynamicModuleBoxStyle = computed((): any => {
// 使用 cssClassRef.value 确保响应式
const adapterCls = cssClassRef.value;
// if (adapterCls.indexOf('layout-landscape-1174x768') >= 0) {
// const cfg = getLandscapeConfig(adapterCls).headerTitleGroup
// // 注意:getLandscapeConfig 返回模块级常量对象(同引用),computed 可能判定“值未变”从而不触发视图更新
// // 这里返回一个新对象引用,确保 :style 能更新
// return cfg != null ? ({ ...cfg } as UTSJSONObject) : ({} as UTSJSONObject);
// }
if (adapterCls.indexOf('layout-portrait-768x1174') >= 0) {
const cfg = getPortraitConfig(adapterCls)?.headerTitleGroup
return cfg != null ? ({ ...cfg } as UTSJSONObject) : ({} as UTSJSONObject);
}
return {} as UTSJSONObject;
});
const progressWidth = computed((): string => { const progressWidth = computed((): string => {
const raw = props.timeProgressPercent const raw = props.timeProgressPercent
const pct = (typeof raw == 'number' && isNaN(raw) != true) ? raw : 0 const pct = (typeof raw == 'number' && isNaN(raw) != true) ? raw : 0
......
...@@ -45,7 +45,14 @@ export function updateResolutionConfig(): void { ...@@ -45,7 +45,14 @@ export function updateResolutionConfig(): void {
let usedKey = key; let usedKey = key;
let cssClass = `layout-${prefix}-${key}`; let cssClass = `layout-${prefix}-${key}`;
let matchType = "exact"; let matchType = "exact";
console.log('target', target)
console.log('isLandscape', isLandscape)
console.log('configMap', configMap)
console.log('prefix', prefix)
console.log('key', key)
console.log('cssClass', cssClass)
console.log('matchType', matchType)
console.log('--------------------------------')
if (target == null) { if (target == null) {
if (isLandscape) { if (isLandscape) {
const near1174 = "1174x768"; const near1174 = "1174x768";
...@@ -75,16 +82,25 @@ export function updateResolutionConfig(): void { ...@@ -75,16 +82,25 @@ export function updateResolutionConfig(): void {
const nearPortrait = "768x1174"; const nearPortrait = "768x1174";
if (isNearResolution(Math.round(w), Math.round(h), 768, 1174, 64)) { if (isNearResolution(Math.round(w), Math.round(h), 768, 1174, 64)) {
const cfg768 = configMap.get(nearPortrait); const cfg768 = configMap.get(nearPortrait);
console.log('cfg768', cfg768)
if (cfg768 != null) { if (cfg768 != null) {
target = cfg768; target = cfg768;
usedKey = nearPortrait; usedKey = nearPortrait;
cssClass = `layout-${prefix}-${nearPortrait}`; cssClass = `layout-${prefix}-${nearPortrait}`;
matchType = "near-768x1174"; matchType = "near-768x1174";
} }
} }
} }
} }
console.log('--------------------------------')
console.log('target', target)
console.log('isLandscape', isLandscape)
console.log('configMap', configMap)
console.log('prefix', prefix)
console.log('key', key)
console.log('cssClass', cssClass)
console.log('matchType', matchType)
if (target == null) { if (target == null) {
target = configMap.get('common'); target = configMap.get('common');
usedKey = `${prefix}/common`; usedKey = `${prefix}/common`;
......
...@@ -25,6 +25,7 @@ const landscapeConfigs = { ...@@ -25,6 +25,7 @@ const landscapeConfigs = {
const portraitConfigs = { const portraitConfigs = {
"768x1174": pt_768x1174, "768x1174": pt_768x1174,
"640x979": pt_768x1174,
"common": pt_common "common": pt_common
} as UTSJSONObject; } as UTSJSONObject;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!