提交 797b61ea 作者: 吴佳伟

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

上级 d86c6e60
......@@ -4,7 +4,7 @@ import { otherHttp } from '/@/utils/http/axios'
enum Api {
purchaseList = '/purchaseSell/bizPurchase/list', // 采购需求列表
supplyList = '/purchaseSell/bizSupply/list', // 供应需求列表
purchaseSellDetails = '/purchaseSell/bizPurchase/queryByld', // 产销详情
purchaseSellDetails = '/purchaseSell/bizPurchase/queryById', // 产销详情
purchaseSell = '/purchaseSell/bizPurchase/add', // 发布采购需求
supplyAdd = '/purchaseSell/bizSupply/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 {
farmMachineAddFarm = '/farmMachine/machineWork/app/addFarm', // 发布农活服务
farmMachineEdit = '/farmMachine/machineWork/edit', // 编辑农机服务
farmMachineRegister = '/farmMachine/machineWork/app/register', // 参与服务
cascaderHn = '/region/cascader/hn',
}
/**
......@@ -81,13 +80,3 @@ export function farmMachineRegister(params = {}) {
params,
})
}
\ No newline at end of file
/**
* 查询湖南省 市/区县/乡镇
* @returns 市/区县/乡镇
*/
export function cascaderHn() {
return otherHttp.get({
url: Api.cascaderHn,
})
}
\ No newline at end of file
......@@ -4,6 +4,7 @@
import PriceDialog from './components/price-dialog.vue'
import Navigate from '@/utils/page/navigate'
import * as ChanxiaoAPI from '@/api/model/chanxiao'
import { getText } from '@/utils/dict/area'
// 下拉刷新
onPullDownRefresh(() => {
......@@ -92,7 +93,7 @@
pageData.purchaseDemands = [...pageData.purchaseDemands, ...records]
pageData.purchaseDemands = pageData.purchaseDemands.map((item) => ({
...item,
location: `${item.province}${item.city}`,
location: getText(`${item.province},${item.city},${item.country}`),
}))
pageData.total = total
})
......@@ -109,7 +110,7 @@
pageData.supplyInfos = [...pageData.supplyInfos, ...records]
pageData.supplyInfos = pageData.supplyInfos.map((item) => ({
...item,
location: `${item.province}${item.city}`,
location: getText(`${item.province},${item.city},${item.country}`),
}))
pageData.total = total
})
......
......@@ -5,7 +5,7 @@
import { useGlobSetting } from '/@/hooks/setting'
import * as ChanxiaoAPI from '@/api/model/chanxiao'
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'
const dictStore = useDictStore()
......@@ -116,7 +116,7 @@
text: item.text,
}
})
pageData.options.address = areaTree
pageData.options.address = areaOptions
}
function getCurrentAddressInfo() {
......@@ -138,7 +138,7 @@ return
function getDetails(id) {
ChanxiaoAPI.purchaseSellDetails({ id }).then((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.imageObj = pageData.form.image && parseUrlInfo(pageData.form.image)
})
......@@ -170,7 +170,7 @@ return
pageData.show.classify = false
}
function handleChangeAddress(e) {
pageData.form.address = e.text.join('/')
pageData.form.address = e.value.join(',')
pageData.show.address = false
}
......@@ -239,9 +239,9 @@ return
function changeAddressValue(formData) {
const addressValue = formData.address.split('/')
if (addressValue.length === 3) {
formData.province = getCodeByText(addressValue[0])
formData.city = getCodeByText(addressValue[1])
formData.country = getCodeByText(addressValue[2])
formData.province = addressValue[0]
formData.city = addressValue[1]
formData.country = addressValue[2]
}
}
</script>
......@@ -314,7 +314,7 @@ return
<text class="label">省/市/区县</text>
<view class="time-input" @click="show.address = true">
<text class="select-text" :class="{ placeholder: !form.address }">
{{ form.address || '请选择省/市/区县' }}
{{ getText(form.address) || '请选择省/市/区县' }}
</text>
</view>
</view>
......
......@@ -5,7 +5,7 @@
import { useGlobSetting } from '/@/hooks/setting'
import * as ChanxiaoAPI from '@/api/model/chanxiao'
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'
const dictStore = useDictStore()
......@@ -124,8 +124,7 @@
const { show, options, form } = toRefs(pageData)
function initDict() {
pageData.options.address = areaTree
console.log(dictStore.getDictList.purchase_status)
pageData.options.address = areaOptions
pageData.options.status = dictStore.getDictList.purchase_status.map((item) => {
return {
......@@ -159,7 +158,7 @@
function getDetails(id) {
ChanxiaoAPI.purchaseSellDetails({ id }).then((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.statusText = pageData.options.status.find((item) => item.value == res.status).text
pageData.form.classifyText = pageData.options.classify.find((item) => item.value == res.classify).text
pageData.form.imageObj = pageData.form.image && parseUrlInfo(pageData.form.image)
......@@ -196,7 +195,7 @@
pageData.show.classify = false
}
function handleChangeAddress(e) {
pageData.form.address = e.text.join('/')
pageData.form.address = e.value.join(',')
pageData.show.address = false
}
function handleChangeStatus(e) {
......@@ -268,11 +267,11 @@
* @param formData 表单数据
*/
function changeAddressValue(formData) {
const addressValue = formData.address.split('/')
const addressValue = formData.address.split(',')
if (addressValue.length === 3) {
formData.province = getCodeByText(addressValue[0])
formData.city = getCodeByText(addressValue[1])
formData.country = getCodeByText(addressValue[2])
formData.province = addressValue[0]
formData.city = addressValue[1]
formData.country = addressValue[2]
}
}
</script>
......@@ -366,7 +365,7 @@
<text class="label">省/市/区县</text>
<view class="select-input" @click="show.address = true">
<text class="time-text" :class="{ placeholder: !form.address }">
{{ form.address || '请选择省/市/区县' }}
{{ getText(form.address) || '请选择省/市/区县' }}
</text>
</view>
</view>
......@@ -385,13 +384,13 @@
<view class="time-range">
<view class="time-input" @click="show.time1 = true">
<text class="time-text" :class="{ placeholder: !form.supplyStartDate }">
{{ form.supplyStartDate || '供应开始时间' }}
{{ form.supplyStartDate || '开始时间' }}
</text>
</view>
<text class="time-separator">-</text>
<view class="time-input" @click="show.time2 = true">
<text class="time-text" :class="{ placeholder: !form.supplyEndDate }">
{{ form.supplyEndDate || '供应结束时间' }}
{{ form.supplyEndDate || '结束时间' }}
</text>
</view>
</view>
......@@ -492,6 +491,7 @@
background-color: #e6f5e8;
width: 750rpx;
overflow-x: hidden;
.mt20 {
margin-top: 30rpx;
background: #fff;
......@@ -504,7 +504,7 @@
margin: 30rpx auto;
}
.supply-form {
.purchase-form {
background: transparent;
}
......@@ -534,6 +534,8 @@
// 添加点击区域样式
.select-input {
position: relative;
}
}
.form-row {
display: flex;
......@@ -699,6 +701,7 @@
}
}
}
::v-deep .uni-input-placeholder {
font-size: 28rpx !important;
color: #999999 !important;
......@@ -721,6 +724,4 @@
margin-bottom: 0;
padding: 0;
}
}
}
</style>
......@@ -4,6 +4,7 @@
import { useUserStore } from '@/store/modules/user'
import { useGlobSetting } from '/@/hooks/setting'
import * as nongjifuwu from '@/api/model/nongjifuwu'
import { areaOptions, getText } from '@/utils/dict/area'
const userStore = useUserStore()
const globSetting = useGlobSetting()
......@@ -92,41 +93,7 @@
const { show, options, form } = toRefs(pageData)
function initDict() {
nongjifuwu.cascaderHn().then((res) => {
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(' / ') : ''
pageData.options.address = areaOptions
}
function getDetails(id) {
......@@ -248,7 +215,7 @@
<text class="label">服务范围</text>
<view class="time-input" @click="show.address = true">
<text class="select-text" :class="{ placeholder: !pageData.form.scope }">
{{ getScope(pageData.form.scope) || '请选择市/区县/乡镇' }}
{{ getText(pageData.form.scope) || '请选择市/区县/乡镇' }}
</text>
</view>
</view>
......
......@@ -4,6 +4,7 @@
import { useUserStore } from '@/store/modules/user'
import { useGlobSetting } from '/@/hooks/setting'
import * as nongjifuwu from '@/api/model/nongjifuwu'
import { areaOptions, getText } from '@/utils/dict/area'
const userStore = useUserStore()
const globSetting = useGlobSetting()
......@@ -79,41 +80,7 @@
const { show, options, form } = toRefs(pageData)
function initDict() {
nongjifuwu.cascaderHn().then((res) => {
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(' / ') : ''
pageData.options.address = areaOptions
}
function getDetails(id) {
......@@ -235,7 +202,7 @@
<text class="label">服务范围</text>
<view class="time-input" @click="show.address = true">
<text class="select-text" :class="{ placeholder: !pageData.form.scope }">
{{ getScope(pageData.form.scope) || '请选择市/区县/乡镇' }}
{{ getText(pageData.form.scope) || '请选择市/区县/乡镇' }}
</text>
</view>
</view>
......
......@@ -6,6 +6,7 @@
import * as NongjifuwuAPI from '@/api/model/nongjifuwu'
import Navigate from '@/utils/page/navigate'
import { s } from 'vite/dist/node/types.d-aGj9QkWt'
import { areaOptions, getText } from '@/utils/dict/area'
onLoad((option) => {
pageData.search.serviceType = Number(option.type) || 1
......@@ -68,9 +69,7 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt'
}
function getCascader() {
NongjifuwuAPI.cascaderHn().then((res) => {
pageData.options = JSON.parse(JSON.stringify(res[0].children).replaceAll('label', 'text'))
})
pageData.options = areaOptions
}
// 分类标签点击事件
......@@ -106,37 +105,7 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt'
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) {
pageData.search.scope = e.value.join(',')
......@@ -165,7 +134,7 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt'
<view class="codefun-flex-row codefun-justify-between section_2">
<text class="font_2 text_2">服务区域</text>
<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
class="codefun-shrink-0 image_7 codefun-ml-4"
src="/static/images/codefun/774cfe989f8417dc655fb301635f5893.png"
......@@ -206,7 +175,7 @@ import { s } from 'vite/dist/node/types.d-aGj9QkWt'
>
<text class="font text_6">{{ item.name }}</text>
<text class="font_3 text_7 ellipsis" style="width: 100%; margin: 26rpx 0"
>服务范围:{{ getScope(item.scope) }}</text
>服务范围:{{ getText(item.scope) }}</text
>
</view>
<view class="flex justify-between" style="width: 100%">
......
......@@ -8,6 +8,7 @@
import * as UserAPI from '@/api/model/userInfo'
import { useDictStore } from '@/store/modules/dict'
import Navigate from '@/utils/page/navigate'
import * as AreaDict from '@/utils/dict/area'
const dictStore = useDictStore()
const model = reactive({
......@@ -127,6 +128,7 @@
// 获取字典列表
dictStore.setDictList()
AreaDict.refreshDictData()
// 查询金刚区数据
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论