提交 797b61ea 作者: 吴佳伟

fix: 地区字典改成本地存储,修复部分页面样式

上级 d86c6e60
...@@ -4,7 +4,7 @@ import { otherHttp } from '/@/utils/http/axios' ...@@ -4,7 +4,7 @@ import { otherHttp } from '/@/utils/http/axios'
enum Api { enum Api {
purchaseList = '/purchaseSell/bizPurchase/list', // 采购需求列表 purchaseList = '/purchaseSell/bizPurchase/list', // 采购需求列表
supplyList = '/purchaseSell/bizSupply/list', // 供应需求列表 supplyList = '/purchaseSell/bizSupply/list', // 供应需求列表
purchaseSellDetails = '/purchaseSell/bizPurchase/queryByld', // 产销详情 purchaseSellDetails = '/purchaseSell/bizPurchase/queryById', // 产销详情
purchaseSell = '/purchaseSell/bizPurchase/add', // 发布采购需求 purchaseSell = '/purchaseSell/bizPurchase/add', // 发布采购需求
supplyAdd = '/purchaseSell/bizSupply/add', // 发布供应需求 supplyAdd = '/purchaseSell/bizSupply/add', // 发布供应需求
bizPurchaseSupplyRecord = '/purchaseSell/bizPurchaseSupplyRecord/add', // 报价 bizPurchaseSupplyRecord = '/purchaseSell/bizPurchaseSupplyRecord/add', // 报价
......
// 上传请求
import { otherHttp } from '/@/utils/http/axios'
enum Api {
cascaderHn = '/region/cascader/hn', // 获取湖南省内 市/区县/乡镇级联数据
}
/**
* 查询湖南省 市/区县/乡镇
* @returns 市/区县/乡镇
*/
export function cascaderHn() {
return otherHttp.get({
url: Api.cascaderHn,
})
}
\ No newline at end of file
...@@ -8,7 +8,6 @@ enum Api { ...@@ -8,7 +8,6 @@ enum Api {
farmMachineAddFarm = '/farmMachine/machineWork/app/addFarm', // 发布农活服务 farmMachineAddFarm = '/farmMachine/machineWork/app/addFarm', // 发布农活服务
farmMachineEdit = '/farmMachine/machineWork/edit', // 编辑农机服务 farmMachineEdit = '/farmMachine/machineWork/edit', // 编辑农机服务
farmMachineRegister = '/farmMachine/machineWork/app/register', // 参与服务 farmMachineRegister = '/farmMachine/machineWork/app/register', // 参与服务
cascaderHn = '/region/cascader/hn',
} }
/** /**
...@@ -80,14 +79,4 @@ export function farmMachineRegister(params = {}) { ...@@ -80,14 +79,4 @@ export function farmMachineRegister(params = {}) {
url: Api.farmMachineRegister, url: Api.farmMachineRegister,
params, params,
}) })
}
/**
* 查询湖南省 市/区县/乡镇
* @returns 市/区县/乡镇
*/
export function cascaderHn() {
return otherHttp.get({
url: Api.cascaderHn,
})
} }
\ No newline at end of file
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import PriceDialog from './components/price-dialog.vue' import PriceDialog from './components/price-dialog.vue'
import Navigate from '@/utils/page/navigate' import Navigate from '@/utils/page/navigate'
import * as ChanxiaoAPI from '@/api/model/chanxiao' import * as ChanxiaoAPI from '@/api/model/chanxiao'
import { getText } from '@/utils/dict/area'
// 下拉刷新 // 下拉刷新
onPullDownRefresh(() => { onPullDownRefresh(() => {
...@@ -92,7 +93,7 @@ ...@@ -92,7 +93,7 @@
pageData.purchaseDemands = [...pageData.purchaseDemands, ...records] pageData.purchaseDemands = [...pageData.purchaseDemands, ...records]
pageData.purchaseDemands = pageData.purchaseDemands.map((item) => ({ pageData.purchaseDemands = pageData.purchaseDemands.map((item) => ({
...item, ...item,
location: `${item.province}${item.city}`, location: getText(`${item.province},${item.city},${item.country}`),
})) }))
pageData.total = total pageData.total = total
}) })
...@@ -109,7 +110,7 @@ ...@@ -109,7 +110,7 @@
pageData.supplyInfos = [...pageData.supplyInfos, ...records] pageData.supplyInfos = [...pageData.supplyInfos, ...records]
pageData.supplyInfos = pageData.supplyInfos.map((item) => ({ pageData.supplyInfos = pageData.supplyInfos.map((item) => ({
...item, ...item,
location: `${item.province}${item.city}`, location: getText(`${item.province},${item.city},${item.country}`),
})) }))
pageData.total = total pageData.total = total
}) })
......
...@@ -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 { areaTree, getCodeByText, getTextByCode } from '@/utils/areaData' import { areaOptions, getText } from '@/utils/dict/area'
import { useDictStore } from '@/store/modules/dict' import { useDictStore } from '@/store/modules/dict'
const dictStore = useDictStore() const dictStore = useDictStore()
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
text: item.text, text: item.text,
} }
}) })
pageData.options.address = areaTree pageData.options.address = areaOptions
} }
function getCurrentAddressInfo() { function getCurrentAddressInfo() {
...@@ -138,7 +138,7 @@ return ...@@ -138,7 +138,7 @@ return
function getDetails(id) { function getDetails(id) {
ChanxiaoAPI.purchaseSellDetails({ id }).then((res) => { ChanxiaoAPI.purchaseSellDetails({ id }).then((res) => {
pageData.form = res pageData.form = res
pageData.form.address = `${getTextByCode(res.province)}/${getTextByCode(res.city)}/${getTextByCode(res.country)}` pageData.form.address = `${res.province},${res.city},${res.country}`
pageData.form.classifyText = pageData.options.classify.find((item) => item.value == res.classify)?.text pageData.form.classifyText = pageData.options.classify.find((item) => item.value == res.classify)?.text
pageData.form.imageObj = pageData.form.image && parseUrlInfo(pageData.form.image) pageData.form.imageObj = pageData.form.image && parseUrlInfo(pageData.form.image)
}) })
...@@ -170,7 +170,7 @@ return ...@@ -170,7 +170,7 @@ return
pageData.show.classify = false pageData.show.classify = false
} }
function handleChangeAddress(e) { function handleChangeAddress(e) {
pageData.form.address = e.text.join('/') pageData.form.address = e.value.join(',')
pageData.show.address = false pageData.show.address = false
} }
...@@ -239,9 +239,9 @@ return ...@@ -239,9 +239,9 @@ return
function changeAddressValue(formData) { function changeAddressValue(formData) {
const addressValue = formData.address.split('/') const addressValue = formData.address.split('/')
if (addressValue.length === 3) { if (addressValue.length === 3) {
formData.province = getCodeByText(addressValue[0]) formData.province = addressValue[0]
formData.city = getCodeByText(addressValue[1]) formData.city = addressValue[1]
formData.country = getCodeByText(addressValue[2]) formData.country = addressValue[2]
} }
} }
</script> </script>
...@@ -314,7 +314,7 @@ return ...@@ -314,7 +314,7 @@ return
<text class="label">省/市/区县</text> <text class="label">省/市/区县</text>
<view class="time-input" @click="show.address = true"> <view class="time-input" @click="show.address = true">
<text class="select-text" :class="{ placeholder: !form.address }"> <text class="select-text" :class="{ placeholder: !form.address }">
{{ form.address || '请选择省/市/区县' }} {{ getText(form.address) || '请选择省/市/区县' }}
</text> </text>
</view> </view>
</view> </view>
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +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'
const userStore = useUserStore() const userStore = useUserStore()
const globSetting = useGlobSetting() const globSetting = useGlobSetting()
...@@ -92,41 +93,7 @@ ...@@ -92,41 +93,7 @@
const { show, options, form } = toRefs(pageData) const { show, options, form } = toRefs(pageData)
function initDict() { function initDict() {
nongjifuwu.cascaderHn().then((res) => { pageData.options.address = areaOptions
pageData.options.address = JSON.parse(JSON.stringify(res[0].children).replaceAll('label', 'text'))
})
}
function getScope(scope: any) {
if (!scope || !pageData.options.address) {
return ''
}
const values = scope.split(',')
const labels = []
// 递归查找label
const findLabel = (nodes, value) => {
for (const node of nodes) {
if (node.value === value) {
return node.text
}
if (node.children && node.children.length > 0) {
const found = findLabel(node.children, value)
if (found) {
return found
}
}
}
return null // 如果没找到,返回原始value
}
for (const value of values) {
const text = findLabel(pageData.options.address, value.trim())
labels.push(text)
}
return labels ? labels.join(' / ') : ''
} }
function getDetails(id) { function getDetails(id) {
...@@ -248,7 +215,7 @@ ...@@ -248,7 +215,7 @@
<text class="label">服务范围</text> <text class="label">服务范围</text>
<view class="time-input" @click="show.address = true"> <view class="time-input" @click="show.address = true">
<text class="select-text" :class="{ placeholder: !pageData.form.scope }"> <text class="select-text" :class="{ placeholder: !pageData.form.scope }">
{{ getScope(pageData.form.scope) || '请选择市/区县/乡镇' }} {{ getText(pageData.form.scope) || '请选择市/区县/乡镇' }}
</text> </text>
</view> </view>
</view> </view>
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +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'
const userStore = useUserStore() const userStore = useUserStore()
const globSetting = useGlobSetting() const globSetting = useGlobSetting()
...@@ -79,41 +80,7 @@ ...@@ -79,41 +80,7 @@
const { show, options, form } = toRefs(pageData) const { show, options, form } = toRefs(pageData)
function initDict() { function initDict() {
nongjifuwu.cascaderHn().then((res) => { pageData.options.address = areaOptions
pageData.options.address = JSON.parse(JSON.stringify(res[0].children).replaceAll('label', 'text'))
})
}
function getScope(scope: any) {
if (!scope || !pageData.options.address) {
return ''
}
const values = scope.split(',')
const labels = []
// 递归查找label
const findLabel = (nodes, value) => {
for (const node of nodes) {
if (node.value === value) {
return node.text
}
if (node.children && node.children.length > 0) {
const found = findLabel(node.children, value)
if (found) {
return found
}
}
}
return null // 如果没找到,返回原始value
}
for (const value of values) {
const text = findLabel(pageData.options.address, value.trim())
labels.push(text)
}
return labels ? labels.join(' / ') : ''
} }
function getDetails(id) { function getDetails(id) {
...@@ -235,7 +202,7 @@ ...@@ -235,7 +202,7 @@
<text class="label">服务范围</text> <text class="label">服务范围</text>
<view class="time-input" @click="show.address = true"> <view class="time-input" @click="show.address = true">
<text class="select-text" :class="{ placeholder: !pageData.form.scope }"> <text class="select-text" :class="{ placeholder: !pageData.form.scope }">
{{ getScope(pageData.form.scope) || '请选择市/区县/乡镇' }} {{ getText(pageData.form.scope) || '请选择市/区县/乡镇' }}
</text> </text>
</view> </view>
</view> </view>
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +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'
onLoad((option) => { onLoad((option) => {
pageData.search.serviceType = Number(option.type) || 1 pageData.search.serviceType = Number(option.type) || 1
...@@ -68,9 +69,7 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt' ...@@ -68,9 +69,7 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt'
} }
function getCascader() { function getCascader() {
NongjifuwuAPI.cascaderHn().then((res) => { pageData.options = areaOptions
pageData.options = JSON.parse(JSON.stringify(res[0].children).replaceAll('label', 'text'))
})
} }
// 分类标签点击事件 // 分类标签点击事件
...@@ -106,37 +105,7 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt' ...@@ -106,37 +105,7 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt'
applyDialogRef.value.open(item) applyDialogRef.value.open(item)
} }
function getScope(scope: any) {
if (!scope || !pageData.options || pageData.options.length === 0) {
return ''
}
const values = scope.split(',')
const labels = []
// 递归查找label
const findLabel = (nodes, value) => {
for (const node of nodes) {
if (node.value === value) {
return node.text
}
if (node.children && node.children.length > 0) {
const found = findLabel(node.children, value)
if (found) {
return found
}
}
}
return null // 如果没找到,返回原始value
}
for (const value of values) {
const text = findLabel(pageData.options, value.trim())
labels.push(text)
}
return labels ? labels.join(' / ') : ''
}
function handleChangeAddress(e) { function handleChangeAddress(e) {
pageData.search.scope = e.value.join(',') pageData.search.scope = e.value.join(',')
...@@ -165,7 +134,7 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt' ...@@ -165,7 +134,7 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt'
<view class="codefun-flex-row codefun-justify-between section_2"> <view class="codefun-flex-row codefun-justify-between section_2">
<text class="font_2 text_2">服务区域</text> <text class="font_2 text_2">服务区域</text>
<view class="codefun-flex-row codefun-items-center" @click="pageData.show.address = true"> <view class="codefun-flex-row codefun-items-center" @click="pageData.show.address = true">
<text class="font_2 text_3">{{ getScope(pageData.search.scope) || '选择区域' }}</text> <text class="font_2 text_3">{{ getText(pageData.search.scope) || '选择区域' }}</text>
<image <image
class="codefun-shrink-0 image_7 codefun-ml-4" class="codefun-shrink-0 image_7 codefun-ml-4"
src="/static/images/codefun/774cfe989f8417dc655fb301635f5893.png" src="/static/images/codefun/774cfe989f8417dc655fb301635f5893.png"
...@@ -206,7 +175,7 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt' ...@@ -206,7 +175,7 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt'
> >
<text class="font text_6">{{ item.name }}</text> <text class="font text_6">{{ item.name }}</text>
<text class="font_3 text_7 ellipsis" style="width: 100%; margin: 26rpx 0" <text class="font_3 text_7 ellipsis" style="width: 100%; margin: 26rpx 0"
>服务范围:{{ getScope(item.scope) }}</text >服务范围:{{ getText(item.scope) }}</text
> >
</view> </view>
<view class="flex justify-between" style="width: 100%"> <view class="flex justify-between" style="width: 100%">
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
import * as UserAPI from '@/api/model/userInfo' import * as UserAPI from '@/api/model/userInfo'
import { useDictStore } from '@/store/modules/dict' import { useDictStore } from '@/store/modules/dict'
import Navigate from '@/utils/page/navigate' import Navigate from '@/utils/page/navigate'
import * as AreaDict from '@/utils/dict/area'
const dictStore = useDictStore() const dictStore = useDictStore()
const model = reactive({ const model = reactive({
...@@ -127,6 +128,7 @@ ...@@ -127,6 +128,7 @@
// 获取字典列表 // 获取字典列表
dictStore.setDictList() dictStore.setDictList()
AreaDict.refreshDictData()
// 查询金刚区数据 // 查询金刚区数据
getServiceItems() getServiceItems()
......
import { cascaderHn } from '/@/api/model/dict'
const storageKey = 'app_dict_data_area_cascaderHn';
export const getDictData = () => {
// 先从本地加载数据
let dictData = getLocalDict();
if (!dictData) {
// 如果本地没有数据,则从接口获取
cascaderHn().then(res => uni.setStorageSync(storageKey, JSON.stringify(res[0].children).replaceAll('label', 'text')));
}
return dictData;
}
/**
* 获取本地数据
*/
export const getLocalDict = () => {
const data = uni.getStorageSync(storageKey);
if (data) {
return data ? JSON.parse(data) : null;
}
return null;
}
/**
* 刷新数据
*/
export const refreshDictData = () => {
// 删除本地数据
uni.removeStorageSync(storageKey);
// 重新获取数据
getDictData();
}
export const areaOptions = getDictData();
export const getText = (scope: String) => {
if (!scope || !areaOptions || areaOptions.length === 0) {
return ''
}
const values = scope.split(',')
const labels = []
// 递归查找label
const findLabel = (nodes, value) => {
for (const node of nodes) {
if (node.value === value) {
return node.text
}
if (node.children && node.children.length > 0) {
const found = findLabel(node.children, value)
if (found) {
return found
}
}
}
return null // 如果没找到,返回原始value
}
for (const value of values) {
const text = findLabel(areaOptions, value.trim())
labels.push(text)
}
return labels ? labels.join(' / ') : ''
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论