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 }