Commit 1eec0856 by 李伟康

refactor(uniappX): 优化代码健壮性并修复类型安全问题

- 将接口定义从 interface 改为 type 类型别名
- 添加 null 检查和类型断言确保运行时安全性
- 重构异步函数避免潜在的竞态条件
- 更新 HBuilderX 配置使用自定义运行环境
- 修复组件引用可能为空的情况
- 优化图片转base64处理逻辑提高性能
- 统一错误处理和异常捕获机制
1 parent f1259e46
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"configurations" : [ "configurations" : [
{ {
"customPlaygroundType" : "local", "customPlaygroundType" : "local",
"playground" : "standard", "playground" : "custom",
"type" : "uni-app:app-android" "type" : "uni-app:app-android"
}, },
{ {
......
...@@ -124,54 +124,59 @@ export async function getSoureData( ...@@ -124,54 +124,59 @@ export async function getSoureData(
...params ...params
}) })
if (res && res.id) { if (res != null && (res as UTSJSONObject).id != null) {
console.log(res.id, 'res.idres.idres.idres.id') console.log((res as UTSJSONObject).id, 'res.idres.idres.idres.id')
let data = await getEquityMaterialConfig({ let data = await getEquityMaterialConfig({
id: res.id id: (res as UTSJSONObject).id
}) })
if (data) { if (data != null) {
let { toolList, materialInfoList } = data const dataObj = data as UTSJSONObject
let storageName = `source_${sceneType}_${shopMerchantId}` const storageName = `source_${sceneType}_${shopMerchantId}`
let toolList: Array<any> = []
if (params.brandId && params.subBrandId) { if (dataObj.toolList != null) {
storageName += `_${params.brandId}_${params.subBrandId}` toolList = dataObj.toolList as Array<any>
}
let materialInfoList: Array<any> = []
if (dataObj.materialInfoList != null) {
materialInfoList = dataObj.materialInfoList as Array<any>
} }
const insurance = materialInfoList.find(e => e.componentName == 'insurance')
const hasEquity = toolList.find(e => e.id == insurance?.id)
if (insurance && hasEquity) { const insurance = (materialInfoList as Array<any>).find((e: any) => (e as UTSJSONObject).componentName == 'insurance')
let configList const hasEquity = (toolList as Array<any>).find((e: any) => (e as UTSJSONObject).id == (insurance as UTSJSONObject).id)
if (insurance != null && hasEquity != null) {
let configList: Array<any> = []
try { try {
configList = await findReceptionpriproConfigList({}) configList = await findReceptionpriproConfigList({}) as Array<any>
storage.set('findReceptionpriproConfigList', configList) storage.set('findReceptionpriproConfigList', configList, 0)
} catch (error) { } catch (error) {
configList = storage.get('findReceptionpriproConfigList') configList = storage.get('findReceptionpriproConfigList') as Array<any>
} }
const toolOtherList = configList.map(i => { const toolOtherList = (configList as Array<any>).map((i: any) => {
return { return {
id: hasEquity.id + 100 + i.id, id: ((hasEquity as UTSJSONObject).id as number) + 100 + ((i as UTSJSONObject).id as number),
shortTitle: i.productName, shortTitle: (i as UTSJSONObject).productName,
shortTitleUrl: i.procuctLog shortTitleUrl: (i as UTSJSONObject).procuctLog
} as UTSJSONObject } as UTSJSONObject
}) })
toolList = toolList.concat(toolOtherList) toolList = toolList.concat(toolOtherList)
const moduleOtherList = configList.map(i => { const moduleOtherList = (configList as Array<any>).map((i: any) => {
return { return {
id: hasEquity.id + 100 + i.id, id: ((hasEquity as UTSJSONObject).id as number) + 100 + ((i as UTSJSONObject).id as number),
title: i.productName, title: (i as UTSJSONObject).productName,
shortTitleUrl: i.procuctLog, shortTitleUrl: (i as UTSJSONObject).procuctLog,
productPoster: i.productPoster, productPoster: (i as UTSJSONObject).productPoster,
showAlt: false, showAlt: false,
componentName: 'CaseCenter', componentName: 'CaseCenter',
receptionpriproCusCaseList: i.receptionpriproCusCaseList, receptionpriproCusCaseList: (i as UTSJSONObject).receptionpriproCusCaseList,
hide: true, hide: true,
detailTitle: i.productName, detailTitle: (i as UTSJSONObject).productName,
thumbnail: 'https://img02.glsx.com.cn/weapp/resource/app-tape/common/qsyw.webp' thumbnail: 'https://img02.glsx.com.cn/weapp/resource/app-tape/common/qsyw.webp'
} as UTSJSONObject } as UTSJSONObject
}) })
...@@ -179,16 +184,16 @@ export async function getSoureData( ...@@ -179,16 +184,16 @@ export async function getSoureData(
materialInfoList = materialInfoList.concat(moduleOtherList) materialInfoList = materialInfoList.concat(moduleOtherList)
} }
data.toolList = await imgTransformBase64(toolList, ['shortTitleUrl']) dataObj.toolList = await imgTransformBase64(toolList, ['shortTitleUrl'])
data.moduleList = await imgTransformBase64(materialInfoList, ['thumbnail', 'receptionSourceDetailList', 'screenList']) dataObj.moduleList = await imgTransformBase64(materialInfoList, ['thumbnail', 'receptionSourceDetailList', 'screenList'])
uni.setStorageSync(storageName, { uni.setStorageSync(storageName, {
moduleList: data.moduleList, moduleList: dataObj.moduleList,
toolList: data.toolList, toolList: dataObj.toolList,
id: res.id id: (res as UTSJSONObject).id
}) })
return Promise.resolve(data) return Promise.resolve(dataObj)
} else { } else {
throw new Error('获取数据失败') throw new Error('获取数据失败')
} }
...@@ -197,7 +202,7 @@ export async function getSoureData( ...@@ -197,7 +202,7 @@ export async function getSoureData(
} }
} catch (error) { } catch (error) {
uni.hideLoading() uni.hideLoading()
if (error) { if (error != null) {
uni.showToast({ uni.showToast({
title: `${error}`, title: `${error}`,
icon: 'none', icon: 'none',
...@@ -209,46 +214,44 @@ export async function getSoureData( ...@@ -209,46 +214,44 @@ export async function getSoureData(
} }
/**批量图片转 base64 */ /**批量图片转 base64 */
async function imgTransformBase64(imgList: Array<any> = [], keyList: string[]): Promise<Array<any>> { async function imgTransformBase64(imgList: Array<any>= [], keyList: string[]): Promise<Array<any>> {
return await Promise.all( const result: Array<any> = []
imgList.map(async e => { for (let idx = 0; idx < imgList.length; idx++) {
await Promise.all( const e = imgList[idx]
Object.keys(e).map(async key => { const eObj = e as UTSJSONObject
for (const key in eObj) {
if (keyList.includes(key)) { if (keyList.includes(key)) {
const isArray = Array.isArray(e[key]) const isArray = Array.isArray(eObj[key])
if (isArray) { if (isArray) {
await Promise.all( const arr = eObj[key] as Array<any>
e[key].map(async i => { for (let i = 0; i < arr.length; i++) {
await Promise.all( const item = arr[i]
Object.keys(i).map(async k => { const itemObj = item as UTSJSONObject
if (k == 'detailUrl' && i[k]) { for (const k in itemObj) {
i[k] = await getBase64(i[k]) if (k == 'detailUrl' && itemObj[k] != null) {
itemObj[k] = await getBase64(itemObj[k] as string)
}
}
} }
})
)
})
)
} else { } else {
if (typeof e[key] === 'string' && e[key]) { if (typeof eObj[key] === 'string' && eObj[key] != null) {
e[key] = await getBase64(e[key]) eObj[key] = await getBase64(eObj[key] as string)
} }
if (e[key] && typeof e[key] === 'object') { if (eObj[key] != null && typeof eObj[key] === 'object') {
await Promise.all( const nestedObj = eObj[key] as UTSJSONObject
Object.keys(e[key]).map(async k => { for (const k in nestedObj) {
if (e[key][k]) { if (nestedObj[k] != null) {
e[key][k] = await getBase64(e[key][k]) nestedObj[k] = await getBase64(nestedObj[k] as string)
} }
})
)
} }
} }
} }
}) }
) }
return e result.push(e)
}) }
) return result
} }
/**转 base64 */ /**转 base64 */
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
uuid: string uuid: string
} }
interface Props { type Props = {
title?: string title?: string
salesPropsUuid?: string salesPropsUuid?: string
} }
......
...@@ -201,7 +201,7 @@ ...@@ -201,7 +201,7 @@
required: true required: true
}] }]
interface Props { type Props = {
sceneType?: number sceneType?: number
customerType?: number customerType?: number
titleTips?: string titleTips?: string
......
...@@ -107,14 +107,14 @@ ...@@ -107,14 +107,14 @@
import { ref } from "vue"; import { ref } from "vue";
import { getBoutiquePackageList as apiGetBoutiquePackageList, getBoutiqueMaterialConfig } from "@/api/boutique-api.uts"; import { getBoutiquePackageList as apiGetBoutiquePackageList, getBoutiqueMaterialConfig } from "@/api/boutique-api.uts";
import { getEmployeeList } from "@/api/common-api.uts"; import { getEmployeeListApi } from "@/api/common-api.uts";
import { getBoutiqueMockData, getMockData } from "@/api/system-api.uts"; import { getBoutiqueMockData, getMockData } from "@/api/system-api.uts";
import CenterPopup from "@/components/CenterPopup.uvue"; import CenterPopup from "@/components/CenterPopup.uvue";
import HomeFrame from "@/components/HomeFrame/index.uvue"; import HomeFrame from "@/components/HomeFrame/index.uvue";
import PackageDetailPopup from "@/pages/boutique/components/PackageDetailPopup.uvue"; import PackageDetailPopup from "@/pages/boutique/components/PackageDetailPopup.uvue";
import { dispatch, store } from "@/store/index.uts"; import { dispatch, store } from "@/store/index.uts";
import { storage } from "@/utils/storage.uts"; import { storage } from "@/utils/storage.uts";
import { onLoad, onShow } from "@dcloudio/uni-app"; // import { onLoad, onShow } from "@dcloudio/uni-app";
const _emptyArr: any[] = [] as any[]; const _emptyArr: any[] = [] as any[];
const homeRef = ref(null); const homeRef = ref(null);
...@@ -241,7 +241,7 @@ async function init(): Promise<void> { ...@@ -241,7 +241,7 @@ async function init(): Promise<void> {
customerType.value = -1; customerType.value = -1;
getEmployeeList({ merchantId: shopMerchantId, sceneList: [1], appQGFlag: 1 }) getEmployeeListApi({ merchantId: shopMerchantId, sceneList: [1], appQGFlag: 1 })
.then((res: any) => { .then((res: any) => {
dispatch("setEmployeeList", res); dispatch("setEmployeeList", res);
}) })
......
...@@ -18,37 +18,36 @@ ...@@ -18,37 +18,36 @@
:key="watchStatus" :key="watchStatus"
> >
<view class="form"> <view class="form">
<template v-for="(i, index) in formObject" :key="index"> <template v-for="(item, index) in formObject" :key="index">
<view <view
:class="['form-item', { active: focusIndex == index }]" :class="['form-item', { active: focusIndex == index }]"
> >
<view class="form-item-box"> <view class="form-item-box">
<template v-if="i.type == 'input'"> <template v-if="(item as FormItem).type == 'input'">
<input <input
:type="i.inputType" :type="(item as FormItem).inputType"
:maxlength="i.maxlength" :maxlength="(item as FormItem).maxlength"
v-model="customerInfo[i.key]" v-model="customerInfo[(item as FormItem).key]"
class="input" class="input"
@input="onInputCustomer" @input="onInputCustomer"
:placeholder="i.placeholder" :placeholder="(item as FormItem).placeholder"
@focus="focusIndex = index" @focus="focusIndex = index"
@blur="resetFocusIndex" @blur="resetFocusIndex"
/> />
<customer-autocomplete <customer-autocomplete
:showType="i.inputType" :showType="(item as FormItem).inputType"
:searchValue="customerInfo[i.key]" :searchValue="customerInfo[(item as FormItem).key]"
:show="focusIndex == index" :show="focusIndex == index"
@choose="onChooseCustomer" @choose="onChooseCustomer"
/> />
</template> </template>
<template v-else> <template v-else>
<view <view
:class="['select flex', { placeholderStyle: !customerInfo[i.key] }]" :class="['select flex', { placeholderStyle: !customerInfo[(item as FormItem).key] }]"
@click="showPopup(i.popKey, index)" @click="showPopup((item as FormItem).popKey, index)"
> >
<view class="value text-hide"> <view class="value text-hide">
{{ customerInfo[i.key] ? customerInfo[i.key] : i.placeholder }} {{ customerInfo[(item as FormItem).key] ? customerInfo[(item as FormItem).key] : (item as FormItem).placeholder }}
</view> </view>
<uni-icons <uni-icons
class="arrow" class="arrow"
...@@ -62,13 +61,13 @@ ...@@ -62,13 +61,13 @@
</view> </view>
</template> </template>
</view> </view>
</view>
<image <image
class="content-image" class="content-image"
:src="contentUrl()" :src="contentUrl()"
/> />
</view> </view>
</view> </view>
</view>
</template> </template>
</wn-canvas> </wn-canvas>
<car-brands <car-brands
...@@ -86,7 +85,7 @@ ...@@ -86,7 +85,7 @@
import { storage } from '@/utils/storage.uts' import { storage } from '@/utils/storage.uts'
import wnCanvas from '@/components/PanCanvas/index.uvue' import wnCanvas from '@/components/PanCanvas/index.uvue'
interface FormItem { type FormItem = {
placeholder: string placeholder: string
key: string key: string
type: string type: string
...@@ -101,8 +100,7 @@ ...@@ -101,8 +100,7 @@
penSwitch: Boolean, penSwitch: Boolean,
show: Boolean, show: Boolean,
title: String, title: String,
views: [Array, views: Array as () => Array<any> | UTSJSONObject
Object],
}) })
const emit = defineEmits(['scale']) const emit = defineEmits(['scale'])
...@@ -143,46 +141,59 @@ ...@@ -143,46 +141,59 @@
const isAito = computed(() => { const isAito = computed(() => {
const userInfo = storage.get('userInfo') const userInfo = storage.get('userInfo')
return userInfo?.channelType == 1 if (userInfo != null) {
return (userInfo as UTSJSONObject).channelType == 1
}
return false
}) })
watch(() => watchCustomerInfo.value, (newval) => { watch(() => watchCustomerInfo.value, (newval: any | null) => {
if (newval) { if (newval != null) {
customerInfo.value = newval as CustomerInfo customerInfo.value = newval as CustomerInfo
} }
}, { immediate: true }) }, { immediate: true })
watch(() => props.show, (n) => { watch(() => props.show, (n: boolean) => {
if (n && !customerInfo.value.carModel && isAito.value) { if (n && !customerInfo.value.carModel && isAito.value) {
setTimeout(() => { setTimeout(() => {
carBrandListVisibleRef.value?.$callMethod('autoSelect') if (carBrandListVisibleRef.value != null) {
(carBrandListVisibleRef.value as any).$callMethod('autoSelect')
}
}, 1000) }, 1000)
} }
}, { immediate: true }) }, { immediate: true })
const carBrandListVisibleRef = ref(null) type CarBrandRefType = any | null
const carBrandListVisibleRef = ref<CarBrandRefType>(null)
function onInputCustomer(): void { function onInputCustomer(): void {
store.dispatch?.('setCustomerInfo', customerInfo.value) if (store.dispatch != null) {
store.dispatch('setCustomerInfo', customerInfo.value)
}
} }
function onSelect(item: any, popkey: string): void { function onSelect(item: any, popkey: string): void {
customerInfo.value.carModel = item.name customerInfo.value.carModel = (item as UTSJSONObject).name
customerInfo.value.carModelId = item.id customerInfo.value.carModelId = (item as UTSJSONObject).id
carBrandListVisibleRef.value?.$callMethod('close') if (carBrandListVisibleRef.value != null) {
(carBrandListVisibleRef.value as any).$callMethod('close')
}
resetFocusIndex() resetFocusIndex()
} }
function showPopup(e: string, index: number): void { function showPopup(e: string, index: number): void {
focusIndex.value = index focusIndex.value = index
if (e == 'carBrandListVisible') { if (e == 'carBrandListVisible') {
carBrandListVisibleRef.value?.$callMethod('open') if (carBrandListVisibleRef.value != null) {
(carBrandListVisibleRef.value as any).$callMethod('open')
}
} }
} }
function closeAllPopup(): void { function closeAllPopup(): void {
carBrandListVisibleRef.value?.$callMethod('close') if (carBrandListVisibleRef.value != null) {
(carBrandListVisibleRef.value as any).$callMethod('close')
}
resetFocusIndex() resetFocusIndex()
} }
...@@ -191,36 +202,44 @@ ...@@ -191,36 +202,44 @@
} }
function onChooseCustomer(e: any): void { function onChooseCustomer(e: any): void {
const eObj = e as UTSJSONObject
customerInfo.value = { customerInfo.value = {
...customerInfo.value, ...customerInfo.value,
phoneNumber: e.ownerPhone, phoneNumber: eObj.ownerPhone,
customerName: e.ownerName customerName: eObj.ownerName
} }
// uni.$logger.local.info(`从客户档案选择:${JSON.stringify(e)}`) if (eObj.carModelId != null) {
customerInfo.value.carModelId = eObj.carModelId
if (e.carModelId) { customerInfo.value.carModel = eObj.brandModel
customerInfo.value.carModelId = e.carModelId customerInfo.value.carBrand = eObj.carBrand
customerInfo.value.carModel = e.brandModel customerInfo.value.carBrandId = eObj.carBrandId
customerInfo.value.carBrand = e.carBrand customerInfo.value.oneCarBrand = eObj.oneCarBrand
customerInfo.value.carBrandId = e.carBrandId customerInfo.value.oneCarBrandId = eObj.oneCarBrandId
customerInfo.value.oneCarBrand = e.oneCarBrand
customerInfo.value.oneCarBrandId = e.oneCarBrandId
} }
onInputCustomer() onInputCustomer()
} }
function contentUrl(): string { function contentUrl(): string {
const views = props.views as any const views = props.views
const carModelId = customerInfo.value.carModelId const carModelId = customerInfo.value.carModelId
if (Array.isArray(views)) { if (views != null && Array.isArray(views)) {
return (views as any)[carModelId ?? ''] || '/static/images/media/nothing.webp' const viewsArray = views as Array<any>
} else if ((views as UTSJSONObject).detailUrl) { if (carModelId != null) {
return (views as UTSJSONObject).detailUrl as string const result = viewsArray[carModelId]
} else { if (result != null) {
return result as string
}
}
return '/static/images/media/nothing.webp' return '/static/images/media/nothing.webp'
} else if (views != null) {
const viewsObj = views as UTSJSONObject
if (viewsObj.detailUrl != null) {
return viewsObj.detailUrl as string
}
} }
return '/static/images/media/nothing.webp'
} }
function onScale(e: any): void { function onScale(e: any): void {
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
}, },
] ]
interface Props { type Props = {
showPayPage?: boolean showPayPage?: boolean
} }
......
...@@ -104,7 +104,7 @@ ...@@ -104,7 +104,7 @@
field: string field: string
} }
interface Props { type Props = {
paymentType?: PaymentTypeItem[] paymentType?: PaymentTypeItem[]
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!