Commit edc402f8 by Lin

refactor(components): 优化接待中心组件的弹层和列表展示

- 将多个 scroll-view 组件替换为 list-view 以提升性能和用户体验
- 统一底部弹层高度设置,确保与其他组件一致
- 调整样式以支持更灵活的布局,改善标签和场景选择的展示效果
- 增强代码可读性,简化属性绑定和样式管理
1 parent ca7ad30a
......@@ -6,21 +6,31 @@
position="bottom"
:isFooter="false"
title="选择品牌"
:popupH="sheetPanelHeightPx"
:maxHeight="sheetPanelHeightPx"
@close="onBrandSheetClose"
>
<scroll-view class="tag-scroll" scroll-y="true">
<view class="tag-box">
<template v-for="(item, index) in brandList" :key="index">
<view
class="tag-item"
:class="{ checked: isBrandRowChecked(item as UTSJSONObject) }"
@click="onTapBrandRow(item as UTSJSONObject)"
>
<text class="tag-text">{{ formatBrandTagLabel(item as UTSJSONObject) }}</text>
</view>
</template>
</view>
</scroll-view>
<list-view
class="tag-list-view"
direction="vertical"
:bounces="false"
:show-scrollbar="true"
:style="tagScrollStyle"
>
<list-item class="tag-list-item" :type="0">
<view class="tag-box">
<template v-for="(item, index) in brandList" :key="index">
<view
class="tag-item"
:class="{ checked: isBrandRowChecked(item as UTSJSONObject) }"
@click="onTapBrandRow(item as UTSJSONObject)"
>
<text class="tag-text">{{ formatBrandTagLabel(item as UTSJSONObject) }}</text>
</view>
</template>
</view>
</list-item>
</list-view>
</MessageBox>
<!-- 第二步:底部弹框 — 根据所选品牌筛选的车型 tag -->
<MessageBox
......@@ -28,23 +38,32 @@
position="bottom"
:isFooter="false"
title="选择车型"
:maxHeight="1000"
:popupH="sheetPanelHeightPx"
:maxHeight="sheetPanelHeightPx"
back
@close="onModelSheetClose"
>
<scroll-view class="tag-scroll" scroll-y="true">
<view class="tag-box">
<template v-for="(item, index) in modelList" :key="index">
<view
class="tag-item"
:class="{ checked: isModelRowChecked(item as UTSJSONObject) }"
@click="onTapModelRow(item as UTSJSONObject)"
>
<text class="tag-text">{{ (item as UTSJSONObject).name }}</text>
</view>
</template>
</view>
</scroll-view>
<list-view
class="tag-list-view"
direction="vertical"
:bounces="false"
:show-scrollbar="true"
:style="tagScrollStyle"
>
<list-item class="tag-list-item" :type="0">
<view class="tag-box">
<template v-for="(item, index) in modelList" :key="index">
<view
class="tag-item"
:class="{ checked: isModelRowChecked(item as UTSJSONObject) }"
@click="onTapModelRow(item as UTSJSONObject)"
>
<text class="tag-text">{{ (item as UTSJSONObject).name }}</text>
</view>
</template>
</view>
</list-item>
</list-view>
</MessageBox>
</view>
</template>
......@@ -55,7 +74,7 @@
import { getMerchantCarBrandList, getCarBrandsListApi } from '@/api/common-api.uts'
import { dispatch } from '@/store/index.uts'
import { ComponentPublicInstance } from 'vue'
import { nextTick } from 'vue'
import { nextTick, computed } from 'vue'
import {
getMockFlatCarBrandRows,
getMockCarModelsList
......@@ -85,6 +104,39 @@
const brandSheetRef = ref<ComponentPublicInstance | null>(null)
const modelSheetRef = ref<ComponentPublicInstance | null>(null)
/** 底部弹层高度:半屏 px,与 MessageBox popupH/maxHeight 一致以固定面板高度(同 CustomerTags) */
const sheetPanelHeightPx = ref(400)
/** list-view 需明确 px 高度;扣除 tips-content padding、标题区、列表区 margin(同 CustomerTags) */
const TAG_SCROLL_VERTICAL_RESERVE_PX = 120
const tagScrollStyle = computed((): UTSJSONObject => {
const panel = sheetPanelHeightPx.value
const h = panel - TAG_SCROLL_VERTICAL_RESERVE_PX
const finalH = h > 160 ? h : 160
const out = {} as UTSJSONObject
out['height'] = `${finalH}px`
out['width'] = '100%'
return out
})
function updateSheetPanelHeight(): void {
try {
const info = uni.getSystemInfoSync()
const wh = info.windowHeight
if (wh != null) {
const h = wh as number
if (h > 0) {
sheetPanelHeightPx.value = Math.floor(h / 2)
return
}
}
} catch (_e) {
// ignore
}
sheetPanelHeightPx.value = 400
}
const brandList = ref<Array<any>>([])
const modelList = ref<Array<any>>([])
/** 第一步选中的行(含 brandId、brandName、name、id 等,与 CarBrands selectCar 一致) */
......@@ -128,6 +180,7 @@
}
function openModelSheet(): void {
updateSheetPanelHeight()
const r = modelSheetRef.value
const inst = r != null ? (r as ComponentPublicInstance) : null
if (inst != null) {
......@@ -381,6 +434,7 @@
/** 打开:mock 模式仅填充标签数据并弹出底部框,无请求/store/dispatch,避免异常进 catch */
function open(): void {
updateSheetPanelHeight()
if (USE_MOCK_CAR_BRAND_LIST) {
brandList.value = getMockFlatCarBrandRows()
nextTick(() => {
......@@ -455,15 +509,34 @@
<style scoped lang="scss">
.car-brand-select-root {
width: 100%;
display: flex;
flex-direction: column;
/* Android:避免父级 overflow:hidden 影响子 list-view 手势(同 CustomerTags / FormDetail) */
overflow: visible;
}
.tag-scroll {
max-height: 400px;
.tag-list-view {
width: 100%;
max-width: 100%;
align-self: stretch;
box-sizing: border-box;
flex-shrink: 0;
margin-top: 8px;
margin-bottom: 16px;
}
.tag-list-item {
width: 100%;
margin: 0;
box-sizing: border-box;
height: auto;
min-height: 0;
align-self: flex-start;
flex-grow: 0;
flex-shrink: 0;
}
.tag-box {
display: flex;
flex-direction: row;
......
......@@ -5,34 +5,44 @@
position="bottom"
:isFooter="false"
title="选择客户标签"
:popupH="sheetPanelHeightPx"
:maxHeight="sheetPanelHeightPx"
@close="onSheetClose"
>
<scroll-view class="tag-scroll" scroll-y="true" enable-flex>
<view class="tag-groups">
<template v-for="(group, gi) in tagGroups" :key="gi">
<view class="tag-section">
<text
v-if="hasSectionTitle(group as UTSJSONObject)"
class="section-title"
>{{ getCategoryTitle(group as UTSJSONObject) }}</text>
<view class="tag-box">
<template
v-for="(item, ti) in getGroupTags(group as UTSJSONObject)"
:key="ti"
>
<view
class="tag-item"
:class="{ checked: isRowChecked(item as UTSJSONObject) }"
@click="onTapRow(item as UTSJSONObject)"
<list-view
class="tag-list-view"
direction="vertical"
:bounces="false"
:show-scrollbar="true"
:style="tagScrollStyle"
>
<list-item class="tag-list-item" :type="0">
<view class="tag-groups">
<template v-for="(group, gi) in tagGroups" :key="gi">
<view class="tag-section">
<text
v-if="hasSectionTitle(group as UTSJSONObject)"
class="section-title"
>{{ getCategoryTitle(group as UTSJSONObject) }}</text>
<view class="tag-box">
<template
v-for="(item, ti) in getGroupTags(group as UTSJSONObject)"
:key="ti"
>
<text class="tag-text">{{ (item as UTSJSONObject)['label'] }}</text>
</view>
</template>
<view
class="tag-item"
:class="{ checked: isRowChecked(item as UTSJSONObject) }"
@click="onTapRow(item as UTSJSONObject)"
>
<text class="tag-text">{{ (item as UTSJSONObject)['label'] }}</text>
</view>
</template>
</view>
</view>
</view>
</template>
</view>
</scroll-view>
</template>
</view>
</list-item>
</list-view>
</MessageBox>
</view>
</template>
......@@ -40,7 +50,7 @@
<script setup lang="uts">
import MessageBox from '@/components/MessageBox.uvue'
import { findSenceTag } from '@/api/receiption.uts'
import { ref, nextTick } from 'vue'
import { ref, nextTick, computed } from 'vue'
import { ComponentPublicInstance } from 'vue'
/** 无接口或解析失败时的两级示例数据 */
......@@ -282,6 +292,41 @@
const sheetRef = ref<ComponentPublicInstance | null>(null)
const tagGroups = ref<Array<UTSJSONObject>>(buildMockTagGroups())
/** 底部弹出层高度:屏幕高度的 50%(App 端不用 vh,用 windowHeight 换算为 px) */
const sheetPanelHeightPx = ref(400)
/**
* 弹层内用 list-view + 明确 px 高度纵向滚动(同 FormDetail);scroll-view 在 MessageBox/un-popup 内部分端仍不生效。
* 从面板高度扣除:MessageBox .tips-content 上下 padding 48、标题区约 36、本区 margin 8+16。
*/
const TAG_SCROLL_VERTICAL_RESERVE_PX = 120
const tagScrollStyle = computed((): UTSJSONObject => {
const panel = sheetPanelHeightPx.value
const h = panel - TAG_SCROLL_VERTICAL_RESERVE_PX
const finalH = h > 160 ? h : 160
const out = {} as UTSJSONObject
out['height'] = `${finalH}px`
out['width'] = '100%'
return out
})
function updateSheetPanelHeight(): void {
try {
const info = uni.getSystemInfoSync()
const wh = info.windowHeight
if (wh != null) {
const h = wh as number
if (h > 0) {
sheetPanelHeightPx.value = Math.floor(h / 2)
return
}
}
} catch (e) {
console.error('getSystemInfoSync 失败:', e)
}
sheetPanelHeightPx.value = 400
}
function getGroupTags(group: UTSJSONObject): Array<UTSJSONObject> {
const t = group['tags']
......@@ -371,6 +416,7 @@
}
async function open(): Promise<void> {
updateSheetPanelHeight()
await loadTagListFromApi()
nextTick(() => {
nextTick(() => {
......@@ -394,18 +440,32 @@
width: 100%;
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
/* Android:滚动父级勿用 overflow:hidden,易导致子 list-view 手势异常(FormDetail 同注) */
overflow: visible;
}
/* 与 FormAdd 一致:scroll-view 需落在有界高度内;仅 max-height 在 App 端常无法触发纵向滚动 */
.tag-scroll {
flex: 1;
min-height: 0;
/* 高度由 tagScrollStyle 内联 px 指定 */
.tag-list-view {
width: 100%;
max-width: 100%;
align-self: stretch;
box-sizing: border-box;
flex-shrink: 0;
margin-top: 8px;
margin-bottom: 16px;
overflow: hidden;
}
.tag-list-item {
width: 100%;
margin: 0;
box-sizing: border-box;
height: auto;
min-height: 0;
align-self: flex-start;
flex-grow: 0;
flex-shrink: 0;
}
.tag-groups {
......
......@@ -5,21 +5,31 @@
position="bottom"
:isFooter="false"
title="选择接待场景"
:popupH="sheetPanelHeightPx"
:maxHeight="sheetPanelHeightPx"
@close="onSheetClose"
>
<scroll-view class="tag-scroll" scroll-y="true">
<view class="tag-box">
<template v-for="(item, index) in sceneList" :key="index">
<view
class="tag-item"
:class="{ checked: isRowChecked(item as UTSJSONObject) }"
@click="onTapRow(item as UTSJSONObject)"
>
<text class="tag-text">{{ (item as UTSJSONObject)['label'] }}</text>
</view>
</template>
</view>
</scroll-view>
<list-view
class="tag-list-view"
direction="vertical"
:bounces="false"
:show-scrollbar="true"
:style="tagScrollStyle"
>
<list-item class="tag-list-item" :type="0">
<view class="tag-box">
<template v-for="(item, index) in sceneList" :key="index">
<view
class="tag-item"
:class="{ checked: isRowChecked(item as UTSJSONObject) }"
@click="onTapRow(item as UTSJSONObject)"
>
<text class="tag-text">{{ (item as UTSJSONObject)['label'] }}</text>
</view>
</template>
</view>
</list-item>
</list-view>
</MessageBox>
</view>
</template>
......@@ -27,7 +37,7 @@
<script setup lang="uts">
import MessageBox from '@/components/MessageBox.uvue'
import { findAllSence } from '@/api/receiption.uts'
import { ref, nextTick } from 'vue'
import { ref, nextTick, computed } from 'vue'
import { ComponentPublicInstance } from 'vue'
/** 接口失败或空列表时的兜底数据 */
......@@ -116,6 +126,38 @@
const sheetRef = ref<ComponentPublicInstance | null>(null)
const sceneList = ref<Array<UTSJSONObject>>(buildMockSceneList())
/** 底部弹层半屏高度,与 MessageBox popupH/maxHeight 一致(同 CustomerTags) */
const sheetPanelHeightPx = ref(400)
const TAG_SCROLL_VERTICAL_RESERVE_PX = 120
const tagScrollStyle = computed((): UTSJSONObject => {
const panel = sheetPanelHeightPx.value
const h = panel - TAG_SCROLL_VERTICAL_RESERVE_PX
const finalH = h > 160 ? h : 160
const out = {} as UTSJSONObject
out['height'] = `${finalH}px`
out['width'] = '100%'
return out
})
function updateSheetPanelHeight(): void {
try {
const info = uni.getSystemInfoSync()
const wh = info.windowHeight
if (wh != null) {
const h = wh as number
if (h > 0) {
sheetPanelHeightPx.value = Math.floor(h / 2)
return
}
}
} catch (_e) {
// ignore
}
sheetPanelHeightPx.value = 400
}
async function loadSceneListFromApi(): Promise<void> {
try {
const params = { scene: 1 } as UTSJSONObject
......@@ -177,6 +219,7 @@
}
async function open(): Promise<void> {
updateSheetPanelHeight()
await loadSceneListFromApi()
nextTick(() => {
nextTick(() => {
......@@ -197,15 +240,33 @@
<style scoped lang="scss">
.scene-select-root {
width: 100%;
display: flex;
flex-direction: column;
overflow: visible;
}
.tag-scroll {
max-height: 400px;
.tag-list-view {
width: 100%;
max-width: 100%;
align-self: stretch;
box-sizing: border-box;
flex-shrink: 0;
margin-top: 8px;
margin-bottom: 16px;
}
.tag-list-item {
width: 100%;
margin: 0;
box-sizing: border-box;
height: auto;
min-height: 0;
align-self: flex-start;
flex-grow: 0;
flex-shrink: 0;
}
.tag-box {
display: flex;
flex-direction: row;
......
......@@ -112,11 +112,21 @@
const visible = ref<boolean>(false)
const popupRef= ref(null)
const popupStyle = computed(() => {
return {
width: props.popupW != null && props.popupW > 0 ? (props.popupW ?? 0) + 'px' : '100%',
minHeight: props.popupH != null && props.popupH > 0 ? (props.popupH ?? 0) + 'px' : '100%',
maxHeight: props.maxHeight != null && props.maxHeight > 0 ? (props.maxHeight ?? 0) + 'px' : '100%'
const w = props.popupW != null && props.popupW > 0 ? (props.popupW ?? 0) + 'px' : '100%'
const minH = props.popupH != null && props.popupH > 0 ? (props.popupH ?? 0) + 'px' : '100%'
const maxH = props.maxHeight != null && props.maxHeight > 0 ? (props.maxHeight ?? 0) + 'px' : '100%'
const style = {
width: w,
minHeight: minH,
maxHeight: maxH
} as UTSJSONObject
// 底部弹层且 min/max 为同一像素值时(如半屏高),固定 height,避免 App 端仅靠 max-height 时外层随内容增高、scroll-view 无法滚动
const ph = props.popupH != null ? props.popupH as number : 0
const mh = props.maxHeight != null ? props.maxHeight as number : 0
if (props.position === 'bottom' && ph > 0 && mh > 0 && ph === mh) {
style['height'] = mh + 'px'
}
return style
})
function onClose(): void {
emit('close')
......@@ -161,14 +171,18 @@
background: #ffffff;
border-radius: 10px;
height: 100%;
min-height: 0;
overflow: hidden;
display: flex;
flex-direction: column;
.tips-content {
width: 100%;
padding: 24px;
box-sizing: border-box;
height: calc(100% - 50px);
flex: 1;
min-height: 0;
position: relative;
display: flex;
flex-direction: column;
.icon-close-box {
position: absolute;
......@@ -184,6 +198,7 @@
.tips-title {
position: relative;
width: 100%;
flex-shrink: 0;
font-weight: 500;
font-size: 18px;
color: #292d33;
......@@ -200,6 +215,7 @@
.tips-text {
display: block;
flex-shrink: 0;
font-size: 15px;
color: #5a5e66;
letter-spacing: 0.5px;
......@@ -213,6 +229,7 @@
align-items: center;
justify-content: center;
height: 50px;
flex-shrink: 0;
border-top: 1px solid #e8e8e8;
flex-direction: row;
.close {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!