1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import {
- getDictData,
- getIndustryListData,
- getSkillList,
- getIndustryTreeData,
- getAreaListData,
- getAreaMapData,
- getPositionTreeData,
- getAreaTreeData,
- getPositionData
- } from '@/api/common'
- // const setDict = (type, val, cacheTime = 7200) => {
- const setDict = (type, val) => {
- if (type === 'areaTreeData') {
- const obj = val.data.find(e => e.name === '中国')
- val = obj?.children ? obj.children : []
- }
- // 一小时过期
- const currentTime = new Date()
- currentTime.setTime(currentTime.getTime() + 3600 * 1000)
-
- uni.setStorageSync(type, JSON.stringify({
- data: val,
- // expire: Date.now() + cacheTime * 1000
- expire: currentTime.getTime()
- }))
- }
- 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 && catchData.data?.data?.length) {
- 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())
- setDict(type, data)
- resolve({ data })
- })
- })
- }
|