import { getDictData, getIndustryListData, getSkillList, getIndustryTreeData, getAreaListData, getAreaMapData, getPositionTreeData, getAreaTreeData, getPositionData } from '@/api/common' const setDict = (type, val, cacheTime = 7200) => { uni.setStorageSync(type, JSON.stringify({ data: val, expire: Date.now() + cacheTime * 1000 })) } export const getDict = (type, params, apiType = 'dict') => { if (!type) { return [] } return new Promise((resolve) => { const item = uni.getStorageSync(type) const catchData = item ? JSON.parse(item) : null if (catchData && catchData.expire && (Date.now() <= catchData.expire) && catchData.data) { return resolve({ data: catchData.data }) } // 传参按照规范参数传 const query = params ? params : { type } const apiFn = { dict: getDictData, positionTreeData: getPositionTreeData, // 职位tree areaTreeData: getAreaTreeData, // 区域tree industryTreeData: getIndustryTreeData, // 行业tree industryList: getIndustryListData, skillList: getSkillList, areaList: getAreaListData, areaMap: getAreaMapData, positionData: getPositionData } apiFn[apiType](query).then(data => { setDict(type, data, Date.now()) resolve({ data }) }) }) }