提交 b8a36d05 作者: 方治民

fix: 修复顶级 await

上级 888440d5
......@@ -2,6 +2,7 @@ import { cascaderHn } from '/@/api/model/dict'
const storageKey = 'app_dict_data_area_cascaderHn';
let areaOptions = [];
export const getDictData = async () => {
// 先从本地加载数据
let dictData = getLocalDict();
......@@ -12,6 +13,8 @@ export const getDictData = async () => {
uni.setStorageSync(storageKey, data);
dictData = JSON.parse(data);
}
areaOptions = dictData;
return dictData;
}
......@@ -36,40 +39,38 @@ export const refreshDictData = () => {
getDictData();
}
const areaOptions = await getDictData();
export const getText = (scope: string, spliced: string) => {
if (!scope || !areaOptions || areaOptions.length === 0) {
return ''
}
if (!scope || !areaOptions || areaOptions.length === 0) {
return ''
}
const values = scope.split(',')
const labels = []
const values = scope.split(',')
const labels = []
// 递归查找label
const findLabel = (nodes, value) => {
for (const node of nodes) {
if (node.value === value) {
return node.text
}
if (node.children && node.children.length > 0) {
const found = findLabel(node.children, value)
if (found) {
return found
}
// 递归查找label
const findLabel = (nodes, value) => {
for (const node of nodes) {
if (node.value === value) {
return node.text
}
if (node.children && node.children.length > 0) {
const found = findLabel(node.children, value)
if (found) {
return found
}
}
return null // 如果没找到,返回原始value
}
return null // 如果没找到,返回原始value
}
for (const value of values) {
const text = findLabel(areaOptions, value.trim())
labels.push(text)
}
for (const value of values) {
const text = findLabel(areaOptions, value.trim())
labels.push(text)
}
if (spliced) {
return labels ? labels.join(spliced) : ''
} else {
return labels ? labels.join('') : ''
}
}
\ No newline at end of file
if (spliced) {
return labels ? labels.join(spliced) : ''
} else {
return labels ? labels.join('') : ''
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论