Commit c224b75d by 李伟康

refactor(car): 优化车型选择组件的数据处理和UI渲染

- 重构CarBrands组件的数据类型定义,统一使用any类型替代具体接口
- 优化车型品牌列表的渲染逻辑,使用template循环提高性能
- 修复base64转换功能,增加对不同数据类型的判断和异常处理
- 调整组件样式布局,修改选择项宽度以改善显示效果
- 优化员工选择组件的数据绑定和渲染方式
- 重构完成步骤组件的状态管理和表单验证逻辑
- 替换自定义弹窗组件为uni-popup,提升弹窗交互体验
- 优化工具箱组件的数据映射和显示逻辑
1 parent 61547116
......@@ -254,18 +254,39 @@ async function imgTransformBase64(imgList: Array<any>= [], keyList: string[]): P
/** 转 base64 */
async function getBase64(url: string): Promise<string> {
return new Promise((resolve, reject) => {
uni.request({
url,
method: "GET",
responseType: "arraybuffer",
success: res => {
const base64 = `data:image/png;base64,${uni.arrayBufferToBase64(res.data as ArrayBuffer)}`;
resolve(base64);
},
fail: err => {
resolve(url);
}
});
});
return new Promise((resolve, reject) => {
uni.request({
url,
method: "GET",
responseType: "arraybuffer",
success: res => {
try {
const data: any | null = res.data;
let base64: string;
if (data == null) {
console.warn('res.data is null or undefined');
resolve(url);
return;
}
if (typeof data === 'string') {
base64 = `data:image/png;base64,${data}`;
} else {
base64 = `data:image/png;base64,${uni.arrayBufferToBase64(data as ArrayBuffer)}`;
}
console.log('转换后的 base64:', base64.substring(0, 50) + '...');
resolve(base64);
} catch (e) {
console.error('转换 base64 失败:', e, 'res.data:', res.data);
resolve(url);
}
},
fail: err => {
console.error('请求失败:', err);
resolve(url);
}
});
});
}
......@@ -8,15 +8,14 @@
@close="handleClose"
>
<view class="select-box">
<view
class="select-item"
:class="{ checked: salesUuid == item.uuid }"
@click="handleSelect(item)"
v-for="(item, index) in employeeList"
:key="index"
>
{{ item.staffName }}
</view>
<template v-for="(item, index) in employeeList" :key="index" >
<view
:class="['select-item',{ checked: (salesUuid as string) == (item as UTSJSONObject).uuid }]"
@click="handleSelect(item)"
>
{{ (item as UTSJSONObject).staffName }}
</view>
</template>
</view>
</MessageBox>
</template>
......@@ -29,11 +28,6 @@
import { getEmployeeListApi } from '@/api/common-api.uts'
import { ComponentPublicInstance } from 'vue'
interface EmployeeItem {
staffName: string
uuid: string
}
type Props = {
title?: string
salesPropsUuid?: string
......@@ -71,10 +65,10 @@
// const employeeList = computed(() => {
// return state.user.employeeList
// })
const employeeList = ref<Array<EmployeeItem>>([])
const employeeList = ref<Array<any>>([])
watch(updateView.value,()=>{
const list = storage.get("employeeList") as UTSArray<EmployeeItem>
employeeList.value = list !== null ? list : []
const list = storage.get("employeeList") as UTSArray<Any>
employeeList.value = list != null ? list : []
}, { immediate: true, deep: true })
function close(): void {
......@@ -83,7 +77,7 @@
}
}
watch(watchStatus.value, (newval: number) => {
watch(watchStatus.value, () => {
close()
}, { immediate: true })
......@@ -101,7 +95,7 @@
// 获取销售人员列表
getEmployeeListApi({ merchantId: shopMerchantId }).then((res: any) => {
const employeeList = res as Array<EmployeeItem>
const employeeList = res as Array<any>
dispatch('setEmployeeList', employeeList)
const listToStore = employeeList != null ? employeeList : []
storage.set('employeeList', listToStore, 0)
......@@ -110,7 +104,7 @@
})
}
function handleSelect(item: EmployeeItem): void {
function handleSelect(item: any): void {
close()
emit('select', item)
}
......@@ -122,14 +116,17 @@
<style scoped lang="scss">
.select-box {
margin: 40rpx 0;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 32rpx;
display: flex;
flex-wrap: wrap;
overflow-y: scroll;
max-height: 50vh;
max-height: 800rpx;
padding-bottom: 60rpx;
flex-direction: row;
.select-item {
width: 48%;
/* width: 23.5%; */
margin-right: 2%;
margin-bottom: 32rpx;
text-align: center;
height: 68rpx;
line-height: 44rpx;
......@@ -139,6 +136,10 @@
font-size: 32rpx;
border-radius: 8rpx;
&:nth-child(4n) {
margin-right: 0;
}
&.checked {
border: 2rpx solid #292d33;
}
......
<template>
<CustomPopup
ref="popupRef"
:visible="visible"
:position="position"
:mask-closable="false"
:duration="300"
@update:visible="visible = $event as Boolean"
@close="onClose"
>
<un-popup :show="visible" @close="onClose" @open="open" :mode="position">
<view
:class="['tips-wrapper',{'radius': position === 'center'}]"
:style="{ width: (popupW ?? 0) + 'rpx', minHeight: (popupH ?? 0) + 'rpx', maxHeight: (maxHeight ?? 0) + 'rpx' }"
:style="popupStyle"
>
<view class="tips-content">
<view
class="icon-close-box flex"
@click="close"
@click="hide"
>
<uni-icons
class="icon-close"
......@@ -29,7 +21,7 @@
<template v-if="back">
<view
class="sprite-icon icon-back"
@click="close"
@click="hide"
>
</view>
</template>
......@@ -65,11 +57,10 @@
</slot>
</template>
</view>
</CustomPopup>
</un-popup>
</template>
<script setup lang="uts">
import CustomPopup from './CustomPopup.uvue'
import { ComponentPublicInstance } from 'vue'
const props = defineProps({
......@@ -120,7 +111,13 @@
const visible = ref<boolean>(false)
const popupRef= ref(null)
const popupStyle = computed(() => {
return {
width: props.popupW != null && props.popupW > 0 ? (props.popupW ?? 0) + 'rpx' : '100%',
minHeight: props.popupH != null && props.popupH > 0 ? (props.popupH ?? 0) + 'rpx' : '100%',
maxHeight: props.maxHeight != null && props.maxHeight > 0 ? (props.maxHeight ?? 0) + 'rpx' : '100%'
}
})
function onClose(): void {
emit('close')
}
......@@ -135,7 +132,9 @@
}
emit('close')
}
function hide(): void {
visible.value = false
}
function open(): void {
visible.value = true
}
......@@ -154,7 +153,7 @@
emit('confirm')
}
defineExpose({ open, close })
defineExpose({ open, close ,hide })
</script>
<style scoped lang="scss">
......@@ -162,13 +161,14 @@
background: #ffffff;
border-radius: 20rpx 20rpx 0 0;
height: 100%;
flex-direction: column;
.tips-content {
width: 100%;
padding: 48rpx;
box-sizing: border-box;
height: calc(100% - 100rpx);
position: relative;
flex-direction: column;
.icon-close-box {
position: absolute;
right: 0;
......@@ -230,6 +230,7 @@
text-align: center;
line-height: 44rpx;
font-weight: 500;
justify-content: center;
}
}
.radius{
......
<template>
<view class="tool-box" :style="toolStyle as string">
<view class="tool-box" :style="(toolStyle ?? '') as string">
<view :class="['btn', { hideIcon: !show }]" @click="show = false">
<view class="icon sprite-icon icon-tool-file">
</view>
......@@ -10,7 +10,7 @@
文件夹
</view>
<view class="list-body">
<template v-for="(item, index) in displayData" :key="index">
<template v-for="(item, index) in (displayData as Array<ToolItem>)" :key="index">
<view :class="['item', { active: item.id == props.id }]" @click="jump(item)">
<image class="icon" :src="item.shortTitleUrl" mode="scaleToFill" />
{{ item.shortTitle }}
......@@ -52,7 +52,10 @@
const props = defineProps({
type: String,
data: Array as () => Array<ToolItem>,
data:{
type: Array,
default: () => []
},
id: [String, Number],
showPayBtn: Boolean,
idKey: {
......@@ -64,11 +67,17 @@
const show = ref<boolean>(true)
const displayData = computed<Array<ToolItem>>(() => {
const displayData = computed(() => {
if (props.data == null) {
return []
return [] as Array<ToolItem>
}
return props.data as Array<ToolItem>
return (props.data as Array<UTSJSONObject>).map(element => {
return {
id: element.id,
shortTitleUrl: element.shortTitleUrl as string,
shortTitle: element.shortTitle as string
} as ToolItem
})
})
const watchStatus = computed(() => {
......
<template>
<view class="reception">
<image :src="(props.views as UTSJSONObject).detailUrl" class="reception-image">
</image>
</view>
</template>
<script setup lang="uts">
const props = defineProps({
views: UTSJSONObject,
title: String,
show: Boolean
})
</script>
<style lang="scss">
.reception {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
.reception-image {
width: 100%;
height: 100%;
}
}
</style>
......@@ -50,45 +50,55 @@ const toolList = ref<Array<any>>([]);
const mediaId = ref<number | string>("");
function setViewInfo(data: any): void {
const dataObj = data as UTSJSONObject;
moduleList.value = dataObj.moduleList as Array<any>;
toolList.value = dataObj.toolList as Array<any>;
mediaId.value = dataObj.id as string;
loadComplete.value = true;
// 将 state.user 转换为 UTSJSONObject 后合并
const userState = state.user as UTSJSONObject;
for (const key in dataObj) {
if (key !== "moduleList" && key !== "toolList" && key !== "id") {
userState[key] = dataObj[key];
}
}
// state.user = userState as UserStateType
const dataObj = data as UTSJSONObject;
moduleList.value = dataObj.moduleList as Array<any>;
toolList.value = dataObj.toolList as Array<any>;
const idValue = dataObj.id;
mediaId.value = typeof idValue === 'number' ? idValue.toString() : (idValue as string) ?? '';
loadComplete.value = true;
// 直接将数据属性设置到 state.user 上
// const userState = state.user as UserStateType;
// for (const key in dataObj) {
// if (key !== "moduleList" && key !== "toolList" && key !== "id") {
// (userState as any)[key] = dataObj[key];
// }
// }
}
function handleStart(): void {
const currentModuleList = moduleList.value;
if (currentModuleList.length === 0) {
return uni.showToast({
title: "该场景尚未配置素材,请联系总部人员",
icon: "none"
});
}
const firstItem = currentModuleList[0] as UTSJSONObject;
const firstId = firstItem.id as string;
uni.navigateTo({ url: `/pages/equity/detail/index?id=${firstId}&type=edit` });
}
async function getSoure(brandIdList: string[], subBrandIdList: string[]): Promise<void> {
const userInfo = storage.get("userInfo") as UTSJSONObject;
const shopMerchantId: string = (userInfo.shopMerchantId as string) ?? "";
const sceneType: number = (userInfo.sceneType as number) ?? 0;
const storageKey = `source_${sceneType}_${shopMerchantId}`;
const data = uni.getStorageSync(storageKey) as UTSJSONObject;
// const currentModuleList = moduleList.value;
// if (currentModuleList.length === 0) {
// return uni.showToast({
// title: "该场景尚未配置素材,请联系总部人员",
// icon: "none"
// });
// }
// const firstItem = currentModuleList[0] as UTSJSONObject;
// const firstId = firstItem.id as number;
// uni.navigateTo({ url: `/pages/equity/detail/index?id=${firstId}&type=edit` });
uni.navigateTo({ url: `/pages/equity/detail/index` });
if (data != null) {
setViewInfo(data);
}
}
async function getSoure(brandIdList: number[], subBrandIdList: number[]): Promise<void> {
const userInfo = storage.get("userInfo") as UTSJSONObject;
const shopMerchantId: string = (userInfo.shopMerchantId as string) ?? "";
const sceneType: number = (userInfo.sceneType as number) ?? 0;
const storageKey = `source_${sceneType}_${shopMerchantId}`;
const cachedData = uni.getStorageSync(storageKey);
let data: UTSJSONObject | null = null;
if (cachedData != null && cachedData !== '') {
try {
data = JSON.parse(cachedData as string) as UTSJSONObject;
} catch (e) {
console.error('解析缓存数据失败:', e);
}
}
console.log(data)
if (data != null) {
setViewInfo(data);
}
try {
const requestData = await getSoureData(shopMerchantId, sceneType, {
......@@ -110,7 +120,7 @@ async function getCarBrandsList(carBrandList: Array<any>, index: number) {
const item = carBrandList[index] as UTSJSONObject;
if (item == null) return;
const storageKey = `${(item.id as string) ?? ""}_${(item.brandId as string) ?? ""}_carlist`;
const storageKey = `${(item.id as number)}_${(item.brandId as number)}_carlist`;
const carList = uni.getStorageSync(storageKey);
if (index < carBrandList.length - 1) {
......@@ -136,14 +146,13 @@ function get_Vehicle_Sales_Data(): void {
const shopMerchantId = userInfo.shopMerchantId;
getMerchantCarBrandList([shopMerchantId ?? ""]).then((res: any) => {
const resObj = res as UTSJSONObject;
const data = resObj.data as UTSJSONObject;
const dataArray = data as Array<any>;
const dataArray = resObj.data as Array<any>;
const firstItem = dataArray[0] as UTSJSONObject;
const carBrandList = [] as any[];
const list = firstItem.carBrandList as Array<any>;
const brandIdList: string[] = [];
const subBrandIdList: string[] = [];
const brandIdList: number[] = [];
const subBrandIdList: number[] = [];
list?.forEach((e: any) => {
const eObj = e as UTSJSONObject;
const childs = eObj.childs as Array<any>;
......@@ -151,16 +160,16 @@ function get_Vehicle_Sales_Data(): void {
childs.forEach((i: any) => {
const iObj = i as UTSJSONObject;
iObj.brandName = (eObj.name as string) ?? "";
iObj.brandId = (eObj.id as string) ?? "";
iObj.brandId = (eObj.id as number);
carBrandList.push(iObj);
const idStr: string = (iObj.id as string) ?? "";
const idStr: number = (iObj.id as number);
subBrandIdList.push(idStr);
});
const idStr: string = (eObj.id as string) ?? "";
const idStr: number = (eObj.id as number);
brandIdList.push(idStr);
});
getSoure(brandIdList, subBrandIdList);
// getSoure(brandIdList, subBrandIdList);
dispatch("setCarBrandsList", carBrandList);
storage.set("carBrandList", carBrandList, 0);
if (carBrandList.length > 0) {
......@@ -183,11 +192,11 @@ onLoad((options) => {
console.log(mockdata, "===");
const userInfo = storage.get("userInfo") as UTSJSONObject;
const mockDataObj = mockdata as UTSJSONObject;
const channelType = userInfo.channelType as string;
if (channelType == "1" && mockDataObj.boutiqueDefaultCarBrandId != null) {
state.user.boutiqueDefaultCarBrandId = (mockDataObj.boutiqueDefaultCarBrandId as string) ?? ""; // 默认车辆品牌
const channelType = userInfo.channelType as number;
if (channelType == 1 && mockDataObj.boutiqueDefaultCarBrandId != null) {
state.user.boutiqueDefaultCarBrandId = (mockDataObj.boutiqueDefaultCarBrandId as number); // 默认车辆品牌
if (mockDataObj.defaultCarId != null) {
state.user.defaultCarId = (mockDataObj.defaultCarId as string) ?? "";// 默认车系
state.user.defaultCarId = (mockDataObj.defaultCarId as number);// 默认车系
}
}
});
......
......@@ -38,13 +38,13 @@ function parseCustomerInfo(raw: any): UTSJSONObject {
export class UserStateType {
static _C: string = "companion";
boutiqueCarList: any[] = [];
boutiqueDefaultCarBrandId: string = "";
boutiqueDefaultCarBrandId: number = 0;
boutiqueMediaConfig: Record<string, any> = {} as Record<string, any>;
carBrands: any[] = [];
currentCarInfo: Record<string, any> = {} as Record<string, any>;
currentCarInfo: UTSJSONObject = {} as UTSJSONObject;
customerInfo: UTSJSONObject = parseCustomerInfo(storage.get("customerInfo") as any);
customerKey: number = Date.now();
defaultCarId: string = "";
defaultCarId: number = 0;
employeeList: any[] = [];
haveCustomerAccess: boolean = true;
historyStatus: number = Date.now();
......@@ -127,7 +127,7 @@ export const actions = {
return null;
},
setCurrentCarInfo: (payload: any): any | null => {
(state as UserStateType).currentCarInfo = (payload != null ? payload : {}) as Record<string, any>;
(state as UserStateType).currentCarInfo = (payload != null ? payload : {}) as UTSJSONObject;
return null;
},
getCustomerInfo: (payload: any): any | null => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!