Commit 1eec0856 by 李伟康

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

- 将接口定义从 interface 改为 type 类型别名
- 添加 null 检查和类型断言确保运行时安全性
- 重构异步函数避免潜在的竞态条件
- 更新 HBuilderX 配置使用自定义运行环境
- 修复组件引用可能为空的情况
- 优化图片转base64处理逻辑提高性能
- 统一错误处理和异常捕获机制
1 parent f1259e46
......@@ -3,7 +3,7 @@
"configurations" : [
{
"customPlaygroundType" : "local",
"playground" : "standard",
"playground" : "custom",
"type" : "uni-app:app-android"
},
{
......
......@@ -123,72 +123,77 @@ export async function getSoureData(
merchantId: shopMerchantId,
...params
})
if (res && res.id) {
console.log(res.id, 'res.idres.idres.idres.id')
if (res != null && (res as UTSJSONObject).id != null) {
console.log((res as UTSJSONObject).id, 'res.idres.idres.idres.id')
let data = await getEquityMaterialConfig({
id: res.id
id: (res as UTSJSONObject).id
})
if (data) {
let { toolList, materialInfoList } = data
let storageName = `source_${sceneType}_${shopMerchantId}`
if (params.brandId && params.subBrandId) {
storageName += `_${params.brandId}_${params.subBrandId}`
if (data != null) {
const dataObj = data as UTSJSONObject
const storageName = `source_${sceneType}_${shopMerchantId}`
let toolList: Array<any> = []
if (dataObj.toolList != null) {
toolList = dataObj.toolList as Array<any>
}
const insurance = materialInfoList.find(e => e.componentName == 'insurance')
const hasEquity = toolList.find(e => e.id == insurance?.id)
if (insurance && hasEquity) {
let configList
let materialInfoList: Array<any> = []
if (dataObj.materialInfoList != null) {
materialInfoList = dataObj.materialInfoList as Array<any>
}
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 {
configList = await findReceptionpriproConfigList({})
storage.set('findReceptionpriproConfigList', configList)
configList = await findReceptionpriproConfigList({}) as Array<any>
storage.set('findReceptionpriproConfigList', configList, 0)
} 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 {
id: hasEquity.id + 100 + i.id,
shortTitle: i.productName,
shortTitleUrl: i.procuctLog
id: ((hasEquity as UTSJSONObject).id as number) + 100 + ((i as UTSJSONObject).id as number),
shortTitle: (i as UTSJSONObject).productName,
shortTitleUrl: (i as UTSJSONObject).procuctLog
} as UTSJSONObject
})
toolList = toolList.concat(toolOtherList)
const moduleOtherList = configList.map(i => {
const moduleOtherList = (configList as Array<any>).map((i: any) => {
return {
id: hasEquity.id + 100 + i.id,
title: i.productName,
shortTitleUrl: i.procuctLog,
productPoster: i.productPoster,
id: ((hasEquity as UTSJSONObject).id as number) + 100 + ((i as UTSJSONObject).id as number),
title: (i as UTSJSONObject).productName,
shortTitleUrl: (i as UTSJSONObject).procuctLog,
productPoster: (i as UTSJSONObject).productPoster,
showAlt: false,
componentName: 'CaseCenter',
receptionpriproCusCaseList: i.receptionpriproCusCaseList,
receptionpriproCusCaseList: (i as UTSJSONObject).receptionpriproCusCaseList,
hide: true,
detailTitle: i.productName,
detailTitle: (i as UTSJSONObject).productName,
thumbnail: 'https://img02.glsx.com.cn/weapp/resource/app-tape/common/qsyw.webp'
} as UTSJSONObject
})
materialInfoList = materialInfoList.concat(moduleOtherList)
}
data.toolList = await imgTransformBase64(toolList, ['shortTitleUrl'])
data.moduleList = await imgTransformBase64(materialInfoList, ['thumbnail', 'receptionSourceDetailList', 'screenList'])
dataObj.toolList = await imgTransformBase64(toolList, ['shortTitleUrl'])
dataObj.moduleList = await imgTransformBase64(materialInfoList, ['thumbnail', 'receptionSourceDetailList', 'screenList'])
uni.setStorageSync(storageName, {
moduleList: data.moduleList,
toolList: data.toolList,
id: res.id
moduleList: dataObj.moduleList,
toolList: dataObj.toolList,
id: (res as UTSJSONObject).id
})
return Promise.resolve(data)
return Promise.resolve(dataObj)
} else {
throw new Error('获取数据失败')
}
......@@ -197,7 +202,7 @@ export async function getSoureData(
}
} catch (error) {
uni.hideLoading()
if (error) {
if (error != null) {
uni.showToast({
title: `${error}`,
icon: 'none',
......@@ -209,46 +214,44 @@ export async function getSoureData(
}
/**批量图片转 base64 */
async function imgTransformBase64(imgList: Array<any> = [], keyList: string[]): Promise<Array<any>> {
return await Promise.all(
imgList.map(async e => {
await Promise.all(
Object.keys(e).map(async key => {
if (keyList.includes(key)) {
const isArray = Array.isArray(e[key])
if (isArray) {
await Promise.all(
e[key].map(async i => {
await Promise.all(
Object.keys(i).map(async k => {
if (k == 'detailUrl' && i[k]) {
i[k] = await getBase64(i[k])
}
})
)
})
)
} else {
if (typeof e[key] === 'string' && e[key]) {
e[key] = await getBase64(e[key])
async function imgTransformBase64(imgList: Array<any>= [], keyList: string[]): Promise<Array<any>> {
const result: Array<any> = []
for (let idx = 0; idx < imgList.length; idx++) {
const e = imgList[idx]
const eObj = e as UTSJSONObject
for (const key in eObj) {
if (keyList.includes(key)) {
const isArray = Array.isArray(eObj[key])
if (isArray) {
const arr = eObj[key] as Array<any>
for (let i = 0; i < arr.length; i++) {
const item = arr[i]
const itemObj = item as UTSJSONObject
for (const k in itemObj) {
if (k == 'detailUrl' && itemObj[k] != null) {
itemObj[k] = await getBase64(itemObj[k] as string)
}
if (e[key] && typeof e[key] === 'object') {
await Promise.all(
Object.keys(e[key]).map(async k => {
if (e[key][k]) {
e[key][k] = await getBase64(e[key][k])
}
})
)
}
}
} else {
if (typeof eObj[key] === 'string' && eObj[key] != null) {
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 */
......
......@@ -34,7 +34,7 @@
uuid: string
}
interface Props {
type Props = {
title?: string
salesPropsUuid?: string
}
......
......@@ -201,7 +201,7 @@
required: true
}]
interface Props {
type Props = {
sceneType?: number
customerType?: number
titleTips?: string
......
......@@ -107,14 +107,14 @@
import { ref } from "vue";
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 CenterPopup from "@/components/CenterPopup.uvue";
import HomeFrame from "@/components/HomeFrame/index.uvue";
import PackageDetailPopup from "@/pages/boutique/components/PackageDetailPopup.uvue";
import { dispatch, store } from "@/store/index.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 homeRef = ref(null);
......@@ -241,7 +241,7 @@ async function init(): Promise<void> {
customerType.value = -1;
getEmployeeList({ merchantId: shopMerchantId, sceneList: [1], appQGFlag: 1 })
getEmployeeListApi({ merchantId: shopMerchantId, sceneList: [1], appQGFlag: 1 })
.then((res: any) => {
dispatch("setEmployeeList", res);
})
......
......@@ -83,7 +83,7 @@
},
]
interface Props {
type Props = {
showPayPage?: boolean
}
......
......@@ -104,7 +104,7 @@
field: string
}
interface Props {
type Props = {
paymentType?: PaymentTypeItem[]
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!