You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zhishifufei_uniapp/utils/address.js

52 lines
1013 B

10 months ago
import { getAddress } from "@/api/public";
import { ADDRESS_DATA_KEY } from "@/constants/storage-keys";
import utils from "@/utils/utils";
const handleProcessData = list => {
return list.map(i => {
let data = {
value: i.v,
text: i.v
};
if (i.c && i.c.length) {
data.children = handleProcessData(i.c);
}
return data;
});
}
const getAddressData = async () => {
let data = [];
try {
const res = await utils.wrapFn(uni.getStorage, {
key: ADDRESS_DATA_KEY
});
data = res.data;
} catch {
}
if (Array.isArray(data) && data.length > 0) return data;
data = await getAddress();
if (data && data.length) {
data = handleProcessData(data);
try {
utils.wrapFn(uni.setStorage, {
key: ADDRESS_DATA_KEY,
data
});
} catch {
}
return data;
}
}
export {
getAddressData
}