提交 4b730fe6 作者: 吴佳伟

fix: 修复打包后地区字典数据无法获取问题

上级 3dcec200
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import { useGlobSetting } from '/@/hooks/setting' import { useGlobSetting } from '/@/hooks/setting'
import * as ChanxiaoAPI from '@/api/model/chanxiao' import * as ChanxiaoAPI from '@/api/model/chanxiao'
import * as UserInfoAPI from '@/api/model/userInfo' import * as UserInfoAPI from '@/api/model/userInfo'
import { areaOptions, getText } from '@/utils/dict/area' import { getDictData, getText } from '@/utils/dict/area'
import { useDictStore } from '@/store/modules/dict' import { useDictStore } from '@/store/modules/dict'
const dictStore = useDictStore() const dictStore = useDictStore()
...@@ -109,14 +109,14 @@ ...@@ -109,14 +109,14 @@
const { show, options, form } = toRefs(pageData) const { show, options, form } = toRefs(pageData)
function initDict() { async function initDict() {
pageData.options.classify = dictStore.getDictList.classify.map((item) => { pageData.options.classify = dictStore.getDictList.classify.map((item) => {
return { return {
value: item.value, value: item.value,
text: item.text, text: item.text,
} }
}) })
pageData.options.address = areaOptions pageData.options.address = await getDictData()
} }
function getCurrentAddressInfo() { function getCurrentAddressInfo() {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import { useGlobSetting } from '/@/hooks/setting' import { useGlobSetting } from '/@/hooks/setting'
import * as ChanxiaoAPI from '@/api/model/chanxiao' import * as ChanxiaoAPI from '@/api/model/chanxiao'
import * as UserInfoAPI from '@/api/model/userInfo' import * as UserInfoAPI from '@/api/model/userInfo'
import { areaOptions, getText } from '@/utils/dict/area' import { getDictData, getText } from '@/utils/dict/area'
import { useDictStore } from '@/store/modules/dict' import { useDictStore } from '@/store/modules/dict'
const dictStore = useDictStore() const dictStore = useDictStore()
...@@ -123,8 +123,8 @@ ...@@ -123,8 +123,8 @@
const { show, options, form } = toRefs(pageData) const { show, options, form } = toRefs(pageData)
function initDict() { async function initDict() {
pageData.options.address = areaOptions pageData.options.address = await getDictData()
pageData.options.status = dictStore.getDictList.purchase_status.map((item) => { pageData.options.status = dictStore.getDictList.purchase_status.map((item) => {
return { return {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import * as UserInfoAPI from '@/api/model/userInfo' import * as UserInfoAPI from '@/api/model/userInfo'
import { areaTree, getCodeByText, getTextByCode } from '@/utils/areaData' import { areaTree, getCodeByText, getTextByCode } from '@/utils/areaData'
import { useDictStore } from '@/store/modules/dict' import { useDictStore } from '@/store/modules/dict'
import { areaOptions } from '@/utils/dict/area' import { getDictData } from '@/utils/dict/area'
const dictStore = useDictStore() const dictStore = useDictStore()
const userStore = useUserStore() const userStore = useUserStore()
...@@ -113,8 +113,8 @@ ...@@ -113,8 +113,8 @@
const { show, options, form } = toRefs(pageData) const { show, options, form } = toRefs(pageData)
function initDict() { async function initDict() {
pageData.options.area = areaOptions pageData.options.area = await getDictData()
pageData.options.urgentdegree = dictStore.getDictList.employment_urgent.map((item) => { pageData.options.urgentdegree = dictStore.getDictList.employment_urgent.map((item) => {
return { return {
value: item.value, value: item.value,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { reactive } from 'vue' import { reactive } from 'vue'
import * as NongjifuwuAPI from '@/api/model/nongjifuwu' import * as NongjifuwuAPI from '@/api/model/nongjifuwu'
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store/modules/user'
import { areaOptions, getText } from '@/utils/dict/area' import { getDictData, getText } from '@/utils/dict/area'
const { getUserInfo } = useUserStore() const { getUserInfo } = useUserStore()
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
pageData.areaShow.address = false pageData.areaShow.address = false
} }
onShow(() => { onShow(() => {
pageData.options = areaOptions pageData.options = getDictData()
}) })
defineExpose({ defineExpose({
open, open,
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store/modules/user'
import { useGlobSetting } from '/@/hooks/setting' import { useGlobSetting } from '/@/hooks/setting'
import * as nongjifuwu from '@/api/model/nongjifuwu' import * as nongjifuwu from '@/api/model/nongjifuwu'
import { areaOptions, getText } from '@/utils/dict/area' import { getDictData, getText } from '@/utils/dict/area'
const userStore = useUserStore() const userStore = useUserStore()
const globSetting = useGlobSetting() const globSetting = useGlobSetting()
...@@ -92,8 +92,8 @@ ...@@ -92,8 +92,8 @@
const { show, options, form } = toRefs(pageData) const { show, options, form } = toRefs(pageData)
function initDict() { async function initDict() {
pageData.options.address = areaOptions pageData.options.address = await getDictData()
} }
function getDetails(id) { function getDetails(id) {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store/modules/user'
import { useGlobSetting } from '/@/hooks/setting' import { useGlobSetting } from '/@/hooks/setting'
import * as nongjifuwu from '@/api/model/nongjifuwu' import * as nongjifuwu from '@/api/model/nongjifuwu'
import { areaOptions, getText } from '@/utils/dict/area' import { getDictData, getText } from '@/utils/dict/area'
const userStore = useUserStore() const userStore = useUserStore()
const globSetting = useGlobSetting() const globSetting = useGlobSetting()
...@@ -79,8 +79,8 @@ ...@@ -79,8 +79,8 @@
}) })
const { show, options, form } = toRefs(pageData) const { show, options, form } = toRefs(pageData)
function initDict() { async function initDict() {
pageData.options.address = areaOptions pageData.options.address = await getDictData()
} }
function getDetails(id) { function getDetails(id) {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import * as NongjifuwuAPI from '@/api/model/nongjifuwu' import * as NongjifuwuAPI from '@/api/model/nongjifuwu'
import Navigate from '@/utils/page/navigate' import Navigate from '@/utils/page/navigate'
import { s } from 'vite/dist/node/types.d-aGj9QkWt' import { s } from 'vite/dist/node/types.d-aGj9QkWt'
import { areaOptions, getText } from '@/utils/dict/area' import { getDictData, getText } from '@/utils/dict/area'
onLoad((option) => { onLoad((option) => {
pageData.search.serviceType = Number(option.type) || 1 pageData.search.serviceType = Number(option.type) || 1
...@@ -68,8 +68,8 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt' ...@@ -68,8 +68,8 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt'
}) })
} }
function getCascader() { async function getCascader() {
pageData.options = areaOptions pageData.options = await getDictData()
} }
// 分类标签点击事件 // 分类标签点击事件
......
...@@ -2,12 +2,15 @@ import { cascaderHn } from '/@/api/model/dict' ...@@ -2,12 +2,15 @@ import { cascaderHn } from '/@/api/model/dict'
const storageKey = 'app_dict_data_area_cascaderHn'; const storageKey = 'app_dict_data_area_cascaderHn';
export const getDictData = () => { export const getDictData = async () => {
// 先从本地加载数据 // 先从本地加载数据
let dictData = getLocalDict(); let dictData = getLocalDict();
if (!dictData) { if (!dictData) {
// 如果本地没有数据,则从接口获取 // 如果本地没有数据,则从接口获取
cascaderHn().then(res => uni.setStorageSync(storageKey, JSON.stringify(res[0].children).replaceAll('label', 'text'))); const res = await cascaderHn();
const data = JSON.stringify(res[0].children).replaceAll('label', 'text');
uni.setStorageSync(storageKey, data);
dictData = JSON.parse(data);
} }
return dictData; return dictData;
} }
...@@ -33,7 +36,7 @@ export const refreshDictData = () => { ...@@ -33,7 +36,7 @@ export const refreshDictData = () => {
getDictData(); getDictData();
} }
export const areaOptions = getDictData(); const areaOptions = await getDictData();
export const getText = (scope: string, spliced: string) => { export const getText = (scope: string, spliced: string) => {
if (!scope || !areaOptions || areaOptions.length === 0) { if (!scope || !areaOptions || areaOptions.length === 0) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论