提交 b8a36d05 作者: 方治民

fix: 修复顶级 await

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