import { getDictData } from '@/api/common/index' // 定义对应的api const DICT_CITY_API = { menduner_exp_type: getDictData } const setDict = (type, val, cacheTime) => { localStorage.setItem(type, JSON.stringify({ data: val, expire: Date.now() + cacheTime })) } export const getDict = (type) => { return new Promise((resolve) => { const item = localStorage.getItem(type) const catchData = item ? JSON.parse(item) : null if (catchData && catchData.expire && (Date.now() <= catchData.expire)) { return resolve(catchData.data) } // 传参按照规范参数传 const query = { type } DICT_CITY_API[type](query).then(data => { setDict(type, data, Date.now()) resolve({ data }) }) }) }