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"
}, },
{ {
......
...@@ -123,72 +123,77 @@ export async function getSoureData( ...@@ -123,72 +123,77 @@ export async function getSoureData(
merchantId: shopMerchantId, merchantId: shopMerchantId,
...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>
} }
const insurance = materialInfoList.find(e => e.componentName == 'insurance') let materialInfoList: Array<any> = []
const hasEquity = toolList.find(e => e.id == insurance?.id) if (dataObj.materialInfoList != null) {
materialInfoList = dataObj.materialInfoList as Array<any>
if (insurance && hasEquity) { }
let configList
const insurance = (materialInfoList as Array<any>).find((e: any) => (e as UTSJSONObject).componentName == 'insurance')
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
}) })
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
if (keyList.includes(key)) { for (const key in eObj) {
const isArray = Array.isArray(e[key]) if (keyList.includes(key)) {
const isArray = Array.isArray(eObj[key])
if (isArray) {
await Promise.all( if (isArray) {
e[key].map(async i => { const arr = eObj[key] as Array<any>
await Promise.all( for (let i = 0; i < arr.length; i++) {
Object.keys(i).map(async k => { const item = arr[i]
if (k == 'detailUrl' && i[k]) { const itemObj = item as UTSJSONObject
i[k] = await getBase64(i[k]) for (const k in itemObj) {
} if (k == 'detailUrl' && itemObj[k] != null) {
}) itemObj[k] = await getBase64(itemObj[k] as string)
)
})
)
} else {
if (typeof e[key] === 'string' && e[key]) {
e[key] = await getBase64(e[key])
} }
if (e[key] && typeof e[key] === 'object') { }
await Promise.all( }
Object.keys(e[key]).map(async k => { } else {
if (e[key][k]) { if (typeof eObj[key] === 'string' && eObj[key] != null) {
e[key][k] = await getBase64(e[key][k]) eObj[key] = await getBase64(eObj[key] as string)
} }
}) if (eObj[key] != null && typeof eObj[key] === 'object') {
) const nestedObj = eObj[key] as UTSJSONObject
for (const k in nestedObj) {
if (nestedObj[k] != null) {
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);
}) })
......
...@@ -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!