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 ...@@ -254,18 +254,39 @@ async function imgTransformBase64(imgList: Array<any>= [], keyList: string[]): P
/** 转 base64 */ /** 转 base64 */
async function getBase64(url: string): Promise<string> { async function getBase64(url: string): Promise<string> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.request({ uni.request({
url, url,
method: "GET", method: "GET",
responseType: "arraybuffer", responseType: "arraybuffer",
success: res => { success: res => {
const base64 = `data:image/png;base64,${uni.arrayBufferToBase64(res.data as ArrayBuffer)}`; try {
resolve(base64); const data: any | null = res.data;
}, let base64: string;
fail: err => {
resolve(url); 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 @@ ...@@ -8,15 +8,14 @@
@close="handleClose" @close="handleClose"
> >
<view class="select-box"> <view class="select-box">
<view <template v-for="(item, index) in employeeList" :key="index" >
class="select-item" <view
:class="{ checked: salesUuid == item.uuid }" :class="['select-item',{ checked: (salesUuid as string) == (item as UTSJSONObject).uuid }]"
@click="handleSelect(item)" @click="handleSelect(item)"
v-for="(item, index) in employeeList" >
:key="index" {{ (item as UTSJSONObject).staffName }}
> </view>
{{ item.staffName }} </template>
</view>
</view> </view>
</MessageBox> </MessageBox>
</template> </template>
...@@ -29,11 +28,6 @@ ...@@ -29,11 +28,6 @@
import { getEmployeeListApi } from '@/api/common-api.uts' import { getEmployeeListApi } from '@/api/common-api.uts'
import { ComponentPublicInstance } from 'vue' import { ComponentPublicInstance } from 'vue'
interface EmployeeItem {
staffName: string
uuid: string
}
type Props = { type Props = {
title?: string title?: string
salesPropsUuid?: string salesPropsUuid?: string
...@@ -71,10 +65,10 @@ ...@@ -71,10 +65,10 @@
// const employeeList = computed(() => { // const employeeList = computed(() => {
// return state.user.employeeList // return state.user.employeeList
// }) // })
const employeeList = ref<Array<EmployeeItem>>([]) const employeeList = ref<Array<any>>([])
watch(updateView.value,()=>{ watch(updateView.value,()=>{
const list = storage.get("employeeList") as UTSArray<EmployeeItem> const list = storage.get("employeeList") as UTSArray<Any>
employeeList.value = list !== null ? list : [] employeeList.value = list != null ? list : []
}, { immediate: true, deep: true }) }, { immediate: true, deep: true })
function close(): void { function close(): void {
...@@ -83,7 +77,7 @@ ...@@ -83,7 +77,7 @@
} }
} }
watch(watchStatus.value, (newval: number) => { watch(watchStatus.value, () => {
close() close()
}, { immediate: true }) }, { immediate: true })
...@@ -101,7 +95,7 @@ ...@@ -101,7 +95,7 @@
// 获取销售人员列表 // 获取销售人员列表
getEmployeeListApi({ merchantId: shopMerchantId }).then((res: any) => { getEmployeeListApi({ merchantId: shopMerchantId }).then((res: any) => {
const employeeList = res as Array<EmployeeItem> const employeeList = res as Array<any>
dispatch('setEmployeeList', employeeList) dispatch('setEmployeeList', employeeList)
const listToStore = employeeList != null ? employeeList : [] const listToStore = employeeList != null ? employeeList : []
storage.set('employeeList', listToStore, 0) storage.set('employeeList', listToStore, 0)
...@@ -110,7 +104,7 @@ ...@@ -110,7 +104,7 @@
}) })
} }
function handleSelect(item: EmployeeItem): void { function handleSelect(item: any): void {
close() close()
emit('select', item) emit('select', item)
} }
...@@ -122,14 +116,17 @@ ...@@ -122,14 +116,17 @@
<style scoped lang="scss"> <style scoped lang="scss">
.select-box { .select-box {
margin: 40rpx 0; margin: 40rpx 0;
display: grid; display: flex;
grid-template-columns: repeat(4, 1fr); flex-wrap: wrap;
gap: 32rpx;
overflow-y: scroll; overflow-y: scroll;
max-height: 50vh; max-height: 800rpx;
padding-bottom: 60rpx; padding-bottom: 60rpx;
flex-direction: row;
.select-item { .select-item {
width: 48%;
/* width: 23.5%; */
margin-right: 2%;
margin-bottom: 32rpx;
text-align: center; text-align: center;
height: 68rpx; height: 68rpx;
line-height: 44rpx; line-height: 44rpx;
...@@ -139,6 +136,10 @@ ...@@ -139,6 +136,10 @@
font-size: 32rpx; font-size: 32rpx;
border-radius: 8rpx; border-radius: 8rpx;
&:nth-child(4n) {
margin-right: 0;
}
&.checked { &.checked {
border: 2rpx solid #292d33; border: 2rpx solid #292d33;
} }
......
<template> <template>
<CustomPopup <un-popup :show="visible" @close="onClose" @open="open" :mode="position">
ref="popupRef"
:visible="visible"
:position="position"
:mask-closable="false"
:duration="300"
@update:visible="visible = $event as Boolean"
@close="onClose"
>
<view <view
:class="['tips-wrapper',{'radius': position === 'center'}]" :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="tips-content">
<view <view
class="icon-close-box flex" class="icon-close-box flex"
@click="close" @click="hide"
> >
<uni-icons <uni-icons
class="icon-close" class="icon-close"
...@@ -29,7 +21,7 @@ ...@@ -29,7 +21,7 @@
<template v-if="back"> <template v-if="back">
<view <view
class="sprite-icon icon-back" class="sprite-icon icon-back"
@click="close" @click="hide"
> >
</view> </view>
</template> </template>
...@@ -65,11 +57,10 @@ ...@@ -65,11 +57,10 @@
</slot> </slot>
</template> </template>
</view> </view>
</CustomPopup> </un-popup>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import CustomPopup from './CustomPopup.uvue'
import { ComponentPublicInstance } from 'vue' import { ComponentPublicInstance } from 'vue'
const props = defineProps({ const props = defineProps({
...@@ -120,7 +111,13 @@ ...@@ -120,7 +111,13 @@
const visible = ref<boolean>(false) const visible = ref<boolean>(false)
const popupRef= ref(null) 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 { function onClose(): void {
emit('close') emit('close')
} }
...@@ -135,7 +132,9 @@ ...@@ -135,7 +132,9 @@
} }
emit('close') emit('close')
} }
function hide(): void {
visible.value = false
}
function open(): void { function open(): void {
visible.value = true visible.value = true
} }
...@@ -154,7 +153,7 @@ ...@@ -154,7 +153,7 @@
emit('confirm') emit('confirm')
} }
defineExpose({ open, close }) defineExpose({ open, close ,hide })
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
...@@ -162,13 +161,14 @@ ...@@ -162,13 +161,14 @@
background: #ffffff; background: #ffffff;
border-radius: 20rpx 20rpx 0 0; border-radius: 20rpx 20rpx 0 0;
height: 100%; height: 100%;
flex-direction: column;
.tips-content { .tips-content {
width: 100%;
padding: 48rpx; padding: 48rpx;
box-sizing: border-box; box-sizing: border-box;
height: calc(100% - 100rpx); height: calc(100% - 100rpx);
position: relative; position: relative;
flex-direction: column;
.icon-close-box { .icon-close-box {
position: absolute; position: absolute;
right: 0; right: 0;
...@@ -230,6 +230,7 @@ ...@@ -230,6 +230,7 @@
text-align: center; text-align: center;
line-height: 44rpx; line-height: 44rpx;
font-weight: 500; font-weight: 500;
justify-content: center;
} }
} }
.radius{ .radius{
......
<template> <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="['btn', { hideIcon: !show }]" @click="show = false">
<view class="icon sprite-icon icon-tool-file"> <view class="icon sprite-icon icon-tool-file">
</view> </view>
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
文件夹 文件夹
</view> </view>
<view class="list-body"> <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)"> <view :class="['item', { active: item.id == props.id }]" @click="jump(item)">
<image class="icon" :src="item.shortTitleUrl" mode="scaleToFill" /> <image class="icon" :src="item.shortTitleUrl" mode="scaleToFill" />
{{ item.shortTitle }} {{ item.shortTitle }}
...@@ -52,7 +52,10 @@ ...@@ -52,7 +52,10 @@
const props = defineProps({ const props = defineProps({
type: String, type: String,
data: Array as () => Array<ToolItem>, data:{
type: Array,
default: () => []
},
id: [String, Number], id: [String, Number],
showPayBtn: Boolean, showPayBtn: Boolean,
idKey: { idKey: {
...@@ -64,11 +67,17 @@ ...@@ -64,11 +67,17 @@
const show = ref<boolean>(true) const show = ref<boolean>(true)
const displayData = computed<Array<ToolItem>>(() => { const displayData = computed(() => {
if (props.data == null) { 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(() => { 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>>([]); ...@@ -50,45 +50,55 @@ const toolList = ref<Array<any>>([]);
const mediaId = ref<number | string>(""); const mediaId = ref<number | string>("");
function setViewInfo(data: any): void { function setViewInfo(data: any): void {
const dataObj = data as UTSJSONObject; const dataObj = data as UTSJSONObject;
moduleList.value = dataObj.moduleList as Array<any>; moduleList.value = dataObj.moduleList as Array<any>;
toolList.value = dataObj.toolList as Array<any>; toolList.value = dataObj.toolList as Array<any>;
mediaId.value = dataObj.id as string; const idValue = dataObj.id;
loadComplete.value = true; mediaId.value = typeof idValue === 'number' ? idValue.toString() : (idValue as string) ?? '';
loadComplete.value = true;
// 将 state.user 转换为 UTSJSONObject 后合并
const userState = state.user as UTSJSONObject; // 直接将数据属性设置到 state.user 上
for (const key in dataObj) { // const userState = state.user as UserStateType;
if (key !== "moduleList" && key !== "toolList" && key !== "id") { // for (const key in dataObj) {
userState[key] = dataObj[key]; // if (key !== "moduleList" && key !== "toolList" && key !== "id") {
} // (userState as any)[key] = dataObj[key];
} // }
// state.user = userState as UserStateType // }
} }
function handleStart(): void { function handleStart(): void {
const currentModuleList = moduleList.value; // const currentModuleList = moduleList.value;
if (currentModuleList.length === 0) { // if (currentModuleList.length === 0) {
return uni.showToast({ // return uni.showToast({
title: "该场景尚未配置素材,请联系总部人员", // title: "该场景尚未配置素材,请联系总部人员",
icon: "none" // icon: "none"
}); // });
} // }
const firstItem = currentModuleList[0] as UTSJSONObject; // const firstItem = currentModuleList[0] as UTSJSONObject;
const firstId = firstItem.id as string; // const firstId = firstItem.id as number;
uni.navigateTo({ url: `/pages/equity/detail/index?id=${firstId}&type=edit` }); // uni.navigateTo({ url: `/pages/equity/detail/index?id=${firstId}&type=edit` });
} uni.navigateTo({ url: `/pages/equity/detail/index` });
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;
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 { try {
const requestData = await getSoureData(shopMerchantId, sceneType, { const requestData = await getSoureData(shopMerchantId, sceneType, {
...@@ -110,7 +120,7 @@ async function getCarBrandsList(carBrandList: Array<any>, index: number) { ...@@ -110,7 +120,7 @@ async function getCarBrandsList(carBrandList: Array<any>, index: number) {
const item = carBrandList[index] as UTSJSONObject; const item = carBrandList[index] as UTSJSONObject;
if (item == null) return; 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); const carList = uni.getStorageSync(storageKey);
if (index < carBrandList.length - 1) { if (index < carBrandList.length - 1) {
...@@ -136,14 +146,13 @@ function get_Vehicle_Sales_Data(): void { ...@@ -136,14 +146,13 @@ function get_Vehicle_Sales_Data(): void {
const shopMerchantId = userInfo.shopMerchantId; const shopMerchantId = userInfo.shopMerchantId;
getMerchantCarBrandList([shopMerchantId ?? ""]).then((res: any) => { getMerchantCarBrandList([shopMerchantId ?? ""]).then((res: any) => {
const resObj = res as UTSJSONObject; const resObj = res as UTSJSONObject;
const data = resObj.data as UTSJSONObject; const dataArray = resObj.data as Array<any>;
const dataArray = data as Array<any>;
const firstItem = dataArray[0] as UTSJSONObject; const firstItem = dataArray[0] as UTSJSONObject;
const carBrandList = [] as any[]; const carBrandList = [] as any[];
const list = firstItem.carBrandList as Array<any>; const list = firstItem.carBrandList as Array<any>;
const brandIdList: string[] = []; const brandIdList: number[] = [];
const subBrandIdList: string[] = []; const subBrandIdList: number[] = [];
list?.forEach((e: any) => { list?.forEach((e: any) => {
const eObj = e as UTSJSONObject; const eObj = e as UTSJSONObject;
const childs = eObj.childs as Array<any>; const childs = eObj.childs as Array<any>;
...@@ -151,16 +160,16 @@ function get_Vehicle_Sales_Data(): void { ...@@ -151,16 +160,16 @@ function get_Vehicle_Sales_Data(): void {
childs.forEach((i: any) => { childs.forEach((i: any) => {
const iObj = i as UTSJSONObject; const iObj = i as UTSJSONObject;
iObj.brandName = (eObj.name as string) ?? ""; iObj.brandName = (eObj.name as string) ?? "";
iObj.brandId = (eObj.id as string) ?? ""; iObj.brandId = (eObj.id as number);
carBrandList.push(iObj); carBrandList.push(iObj);
const idStr: string = (iObj.id as string) ?? ""; const idStr: number = (iObj.id as number);
subBrandIdList.push(idStr); subBrandIdList.push(idStr);
}); });
const idStr: string = (eObj.id as string) ?? ""; const idStr: number = (eObj.id as number);
brandIdList.push(idStr); brandIdList.push(idStr);
}); });
getSoure(brandIdList, subBrandIdList); // getSoure(brandIdList, subBrandIdList);
dispatch("setCarBrandsList", carBrandList); dispatch("setCarBrandsList", carBrandList);
storage.set("carBrandList", carBrandList, 0); storage.set("carBrandList", carBrandList, 0);
if (carBrandList.length > 0) { if (carBrandList.length > 0) {
...@@ -183,11 +192,11 @@ onLoad((options) => { ...@@ -183,11 +192,11 @@ onLoad((options) => {
console.log(mockdata, "==="); console.log(mockdata, "===");
const userInfo = storage.get("userInfo") as UTSJSONObject; const userInfo = storage.get("userInfo") as UTSJSONObject;
const mockDataObj = mockdata as UTSJSONObject; const mockDataObj = mockdata as UTSJSONObject;
const channelType = userInfo.channelType as string; const channelType = userInfo.channelType as number;
if (channelType == "1" && mockDataObj.boutiqueDefaultCarBrandId != null) { if (channelType == 1 && mockDataObj.boutiqueDefaultCarBrandId != null) {
state.user.boutiqueDefaultCarBrandId = (mockDataObj.boutiqueDefaultCarBrandId as string) ?? ""; // 默认车辆品牌 state.user.boutiqueDefaultCarBrandId = (mockDataObj.boutiqueDefaultCarBrandId as number); // 默认车辆品牌
if (mockDataObj.defaultCarId != null) { 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 { ...@@ -38,13 +38,13 @@ function parseCustomerInfo(raw: any): UTSJSONObject {
export class UserStateType { export class UserStateType {
static _C: string = "companion"; static _C: string = "companion";
boutiqueCarList: any[] = []; boutiqueCarList: any[] = [];
boutiqueDefaultCarBrandId: string = ""; boutiqueDefaultCarBrandId: number = 0;
boutiqueMediaConfig: Record<string, any> = {} as Record<string, any>; boutiqueMediaConfig: Record<string, any> = {} as Record<string, any>;
carBrands: any[] = []; carBrands: any[] = [];
currentCarInfo: Record<string, any> = {} as Record<string, any>; currentCarInfo: UTSJSONObject = {} as UTSJSONObject;
customerInfo: UTSJSONObject = parseCustomerInfo(storage.get("customerInfo") as any); customerInfo: UTSJSONObject = parseCustomerInfo(storage.get("customerInfo") as any);
customerKey: number = Date.now(); customerKey: number = Date.now();
defaultCarId: string = ""; defaultCarId: number = 0;
employeeList: any[] = []; employeeList: any[] = [];
haveCustomerAccess: boolean = true; haveCustomerAccess: boolean = true;
historyStatus: number = Date.now(); historyStatus: number = Date.now();
...@@ -127,7 +127,7 @@ export const actions = { ...@@ -127,7 +127,7 @@ export const actions = {
return null; return null;
}, },
setCurrentCarInfo: (payload: any): any | 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; return null;
}, },
getCustomerInfo: (payload: any): any | 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!