Browse Source

get参数编码

Xiao_123 8 months ago
parent
commit
874d2c478e
7 changed files with 262 additions and 74 deletions
  1. 15 45
      components/FilterList/index.vue
  2. 0 0
      hooks/useDictionaries.js
  3. 209 1
      package-lock.json
  4. 2 1
      package.json
  5. 24 26
      pages/index/position.vue
  6. 1 1
      utils/position.js
  7. 11 0
      utils/request.js

+ 15 - 45
components/FilterList/index.vue

@@ -1,26 +1,27 @@
 <template>
   <view class="labelColor itemBox">
     <view class="item" v-for="item in filterList" :key="item[props.idValue]">
-      <picker @change="e => handleClick(e, item)" :value="item.selected" :range="item.array">
+      <uni-data-picker 
+        :localdata="item.array" 
+        :clear-icon="true"
+        :popup-title="'请选择' + item[labelValue]" 
+        :map="item.map || { text: 'label', value: 'value' }"
+         @change="e => handleClick(e, item)"
+      >
         <view>
           {{ item[labelValue] }}
           <uni-icons type="icon-arrow-sortdown-smal" custom-prefix="iconfont" color="#999"/>
         </view>
-      </picker>
-      <!-- <uni-data-picker :localdata="item.array" :popup-title="'请选择' + item[labelValue]" :map="{ text: 'name', value: 'id' }">
-        <view>
-          {{ item[labelValue] }}
-          <uni-icons type="icon-arrow-sortdown-smal" custom-prefix="iconfont" color="#999"/>
-        </view>
-      </uni-data-picker> -->
+      </uni-data-picker>
     </view>
   </view>
 </template>
 
 <script setup>
 import { ref, watch } from 'vue'
-import { getDict } from '@/utils/useDictionaries'
+import { getDict } from '@/hooks/useDictionaries'
 
+const emit = defineEmits(['change'])
 const props = defineProps({
   list: { type: Array, default: () => [] },
   idValue: { type: String, default: 'id' },
@@ -32,51 +33,20 @@ const props = defineProps({
 })
 
 const handleClick = (e, item) => {
-  item.selected = e.detail.value
+  const obj = e.detail.value
+  item.value = obj.length && obj.length === 1 ? obj[0].value : obj[obj.length - 1].value
+  emit('change', item.key, item.value)
 }
 
-// const selectData = {
-//   城市: [{ label: '城市' }],
-//   行业: [{ label: '行业' }],
-//   求职类型: [{ label: '求职类型' }],
-//   薪资待遇: [{ label: '薪资待遇' }],
-//   工作经验: [{ label: '工作经验' }],
-// }
-
 // 获取字典数据
 const getData = (e) => {
-  getDict(e.dictType).then(({ data }) => {
-    e.source = data.data
-    e.array = data.data.map(e => e.label)
+  getDict(e.dictType, e.map ? {} : null, e.map ? e.dictType : 'dict').then(({ data }) => {
+    e.array = data.data
   })
-  // e.array = [
-  //   {
-  //     id: '110101',
-  //     name: '北京',
-  //     children: [
-  //       { id: '110101', name: '东城区' },
-  //       { id: '110102', name: '西城区' },
-  //       { id: '110105', name: '朝阳区' },
-  //       { id: '110106', name: '丰台区' },
-  //       { id: '110107', name: '石景山区' }
-  //     ]
-  //   },
-  //   {
-  //     id: '120000',
-  //     name: '天津',
-  //     children: [
-  //       { id: '120101', name: '和平区' },
-  //       { id: '120102', name: '河东区' },
-  //       { id: '120103', name: '河西区' },
-  //       { id: '120104', name: '南开区' },
-  //     ]
-  //   }
-  // ]
 }
 
 const setItemSelectData = () => {
   filterList.value.forEach(e => {
-    e.selected = 0
     getData(e)
   })
 }

+ 0 - 0
utils/useDictionaries.js → hooks/useDictionaries.js


+ 209 - 1
package-lock.json

@@ -10,7 +10,8 @@
         "luch-request": "^3.1.1",
         "pinia": "^2.2.2",
         "pinia-plugin-persist-uni": "^1.3.1",
-        "pinia-plugin-persistedstate": "^4.0.1"
+        "pinia-plugin-persistedstate": "^4.0.1",
+        "qs": "^6.13.0"
       }
     },
     "node_modules/@ampproject/remapping": {
@@ -618,6 +619,25 @@
         }
       }
     },
+    "node_modules/call-bind": {
+      "version": "1.0.7",
+      "resolved": "https://registry.npmmirror.com/call-bind/-/call-bind-1.0.7.tgz",
+      "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==",
+      "license": "MIT",
+      "dependencies": {
+        "es-define-property": "^1.0.0",
+        "es-errors": "^1.3.0",
+        "function-bind": "^1.1.2",
+        "get-intrinsic": "^1.2.4",
+        "set-function-length": "^1.2.1"
+      },
+      "engines": {
+        "node": ">= 0.4"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/ljharb"
+      }
+    },
     "node_modules/caniuse-lite": {
       "version": "1.0.30001660",
       "resolved": "https://registry.npmmirror.com/caniuse-lite/-/caniuse-lite-1.0.30001660.tgz",
@@ -788,6 +808,23 @@
       "integrity": "sha512-2CGvfTM2c+IP/MhdRZMpaHhTc6zIlgz3tQXJ/VGAkc7mjMrjqSU28qiI63yEcy+fcYfd/K+NNJcGRzap4M4bqw==",
       "license": "MIT"
     },
+    "node_modules/define-data-property": {
+      "version": "1.1.4",
+      "resolved": "https://registry.npmmirror.com/define-data-property/-/define-data-property-1.1.4.tgz",
+      "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==",
+      "license": "MIT",
+      "dependencies": {
+        "es-define-property": "^1.0.0",
+        "es-errors": "^1.3.0",
+        "gopd": "^1.0.1"
+      },
+      "engines": {
+        "node": ">= 0.4"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/ljharb"
+      }
+    },
     "node_modules/defu": {
       "version": "6.1.4",
       "resolved": "https://registry.npmmirror.com/defu/-/defu-6.1.4.tgz",
@@ -818,6 +855,27 @@
       "integrity": "sha512-kpLJJi3zxTR1U828P+LIUDZ5ohixyo68/IcYOHLqnbTPr/wdgn4i1ECvmALN9E16JPA6cvCG5UG79gVwVdEK5w==",
       "license": "ISC"
     },
+    "node_modules/es-define-property": {
+      "version": "1.0.0",
+      "resolved": "https://registry.npmmirror.com/es-define-property/-/es-define-property-1.0.0.tgz",
+      "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==",
+      "license": "MIT",
+      "dependencies": {
+        "get-intrinsic": "^1.2.4"
+      },
+      "engines": {
+        "node": ">= 0.4"
+      }
+    },
+    "node_modules/es-errors": {
+      "version": "1.3.0",
+      "resolved": "https://registry.npmmirror.com/es-errors/-/es-errors-1.3.0.tgz",
+      "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
+      "license": "MIT",
+      "engines": {
+        "node": ">= 0.4"
+      }
+    },
     "node_modules/escalade": {
       "version": "3.2.0",
       "resolved": "https://registry.npmmirror.com/escalade/-/escalade-3.2.0.tgz",
@@ -946,6 +1004,15 @@
         "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
       }
     },
+    "node_modules/function-bind": {
+      "version": "1.1.2",
+      "resolved": "https://registry.npmmirror.com/function-bind/-/function-bind-1.1.2.tgz",
+      "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
+      "license": "MIT",
+      "funding": {
+        "url": "https://github.com/sponsors/ljharb"
+      }
+    },
     "node_modules/gensync": {
       "version": "1.0.0-beta.2",
       "resolved": "https://registry.npmmirror.com/gensync/-/gensync-1.0.0-beta.2.tgz",
@@ -955,6 +1022,25 @@
         "node": ">=6.9.0"
       }
     },
+    "node_modules/get-intrinsic": {
+      "version": "1.2.4",
+      "resolved": "https://registry.npmmirror.com/get-intrinsic/-/get-intrinsic-1.2.4.tgz",
+      "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==",
+      "license": "MIT",
+      "dependencies": {
+        "es-errors": "^1.3.0",
+        "function-bind": "^1.1.2",
+        "has-proto": "^1.0.1",
+        "has-symbols": "^1.0.3",
+        "hasown": "^2.0.0"
+      },
+      "engines": {
+        "node": ">= 0.4"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/ljharb"
+      }
+    },
     "node_modules/get-stream": {
       "version": "8.0.1",
       "resolved": "https://registry.npmmirror.com/get-stream/-/get-stream-8.0.1.tgz",
@@ -1027,6 +1113,18 @@
         "url": "https://github.com/sponsors/sindresorhus"
       }
     },
+    "node_modules/gopd": {
+      "version": "1.0.1",
+      "resolved": "https://registry.npmmirror.com/gopd/-/gopd-1.0.1.tgz",
+      "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==",
+      "license": "MIT",
+      "dependencies": {
+        "get-intrinsic": "^1.1.3"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/ljharb"
+      }
+    },
     "node_modules/has-flag": {
       "version": "3.0.0",
       "resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-3.0.0.tgz",
@@ -1036,12 +1134,60 @@
         "node": ">=4"
       }
     },
+    "node_modules/has-property-descriptors": {
+      "version": "1.0.2",
+      "resolved": "https://registry.npmmirror.com/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz",
+      "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==",
+      "license": "MIT",
+      "dependencies": {
+        "es-define-property": "^1.0.0"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/ljharb"
+      }
+    },
+    "node_modules/has-proto": {
+      "version": "1.0.3",
+      "resolved": "https://registry.npmmirror.com/has-proto/-/has-proto-1.0.3.tgz",
+      "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==",
+      "license": "MIT",
+      "engines": {
+        "node": ">= 0.4"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/ljharb"
+      }
+    },
+    "node_modules/has-symbols": {
+      "version": "1.0.3",
+      "resolved": "https://registry.npmmirror.com/has-symbols/-/has-symbols-1.0.3.tgz",
+      "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
+      "license": "MIT",
+      "engines": {
+        "node": ">= 0.4"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/ljharb"
+      }
+    },
     "node_modules/hash-sum": {
       "version": "2.0.0",
       "resolved": "https://registry.npmmirror.com/hash-sum/-/hash-sum-2.0.0.tgz",
       "integrity": "sha512-WdZTbAByD+pHfl/g9QSsBIIwy8IT+EsPiKDs0KNX+zSHhdDLFKdZu0BQHljvO+0QI/BasbMSUa8wYNCZTvhslg==",
       "license": "MIT"
     },
+    "node_modules/hasown": {
+      "version": "2.0.2",
+      "resolved": "https://registry.npmmirror.com/hasown/-/hasown-2.0.2.tgz",
+      "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
+      "license": "MIT",
+      "dependencies": {
+        "function-bind": "^1.1.2"
+      },
+      "engines": {
+        "node": ">= 0.4"
+      }
+    },
     "node_modules/hookable": {
       "version": "5.5.3",
       "resolved": "https://registry.npmmirror.com/hookable/-/hookable-5.5.3.tgz",
@@ -1416,6 +1562,18 @@
         "node": "^14.16.0 || >=16.10.0"
       }
     },
+    "node_modules/object-inspect": {
+      "version": "1.13.2",
+      "resolved": "https://registry.npmmirror.com/object-inspect/-/object-inspect-1.13.2.tgz",
+      "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==",
+      "license": "MIT",
+      "engines": {
+        "node": ">= 0.4"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/ljharb"
+      }
+    },
     "node_modules/ohash": {
       "version": "1.1.3",
       "resolved": "https://registry.npmmirror.com/ohash/-/ohash-1.1.3.tgz",
@@ -1593,6 +1751,21 @@
         "pathe": "^1.1.2"
       }
     },
+    "node_modules/qs": {
+      "version": "6.13.0",
+      "resolved": "https://registry.npmmirror.com/qs/-/qs-6.13.0.tgz",
+      "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==",
+      "license": "BSD-3-Clause",
+      "dependencies": {
+        "side-channel": "^1.0.6"
+      },
+      "engines": {
+        "node": ">=0.6"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/ljharb"
+      }
+    },
     "node_modules/queue-microtask": {
       "version": "1.2.3",
       "resolved": "https://registry.npmmirror.com/queue-microtask/-/queue-microtask-1.2.3.tgz",
@@ -1686,6 +1859,23 @@
         "node": ">=10"
       }
     },
+    "node_modules/set-function-length": {
+      "version": "1.2.2",
+      "resolved": "https://registry.npmmirror.com/set-function-length/-/set-function-length-1.2.2.tgz",
+      "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==",
+      "license": "MIT",
+      "dependencies": {
+        "define-data-property": "^1.1.4",
+        "es-errors": "^1.3.0",
+        "function-bind": "^1.1.2",
+        "get-intrinsic": "^1.2.4",
+        "gopd": "^1.0.1",
+        "has-property-descriptors": "^1.0.2"
+      },
+      "engines": {
+        "node": ">= 0.4"
+      }
+    },
     "node_modules/shebang-command": {
       "version": "2.0.0",
       "resolved": "https://registry.npmmirror.com/shebang-command/-/shebang-command-2.0.0.tgz",
@@ -1707,6 +1897,24 @@
         "node": ">=8"
       }
     },
+    "node_modules/side-channel": {
+      "version": "1.0.6",
+      "resolved": "https://registry.npmmirror.com/side-channel/-/side-channel-1.0.6.tgz",
+      "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==",
+      "license": "MIT",
+      "dependencies": {
+        "call-bind": "^1.0.7",
+        "es-errors": "^1.3.0",
+        "get-intrinsic": "^1.2.4",
+        "object-inspect": "^1.13.1"
+      },
+      "engines": {
+        "node": ">= 0.4"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/ljharb"
+      }
+    },
     "node_modules/signal-exit": {
       "version": "4.1.0",
       "resolved": "https://registry.npmmirror.com/signal-exit/-/signal-exit-4.1.0.tgz",

+ 2 - 1
package.json

@@ -5,6 +5,7 @@
     "luch-request": "^3.1.1",
     "pinia": "^2.2.2",
     "pinia-plugin-persist-uni": "^1.3.1",
-    "pinia-plugin-persistedstate": "^4.0.1"
+    "pinia-plugin-persistedstate": "^4.0.1",
+    "qs": "^6.13.0"
   }
 }

+ 24 - 26
pages/index/position.vue

@@ -1,6 +1,6 @@
 <template>
   <view class="box defaultBgc">
-    <scroll-view class="scrollBox" scroll-y="true" @scrolltolower="loadingMore" @refresherrefresh="refresh" style="position:relative;">
+    <scroll-view class="scrollBox" scroll-y="true" :refresher-enabled="false" @scrolltolower="loadingMore" style="position:relative;">
       <view class="white-bgc">
         <uni-search-bar
           v-model="query.content"
@@ -13,7 +13,7 @@
       </view>
       <view class="white-bgc px-10 pb-10 mb-10">
         <SwiperAd :list="swiperAdList"></SwiperAd>
-        <FilterList :list="filterList" idValue="label" class="ss-m-t-30"></FilterList>
+        <FilterList :list="filterList" idValue="label" class="ss-m-t-30" @change="handleSearch"></FilterList>
       </view>
       <PositionList class="pb-10" :list="positionListData" :noMore="noMore"></PositionList>
     </scroll-view>
@@ -22,35 +22,39 @@
 
 <script setup>
 import SwiperAd from '@/components/SwiperAd'
-// import SearchBar from '@/components/SearchBar'
 import FilterList from '@/components/FilterList'
 import PositionList from '@/components/PositionList'
-import { swiperAdListTest, positionList } from '@/utils/testData'
+import { swiperAdListTest } from '@/utils/testData'
 import { dealDictObjData } from '@/utils/position'
 import { getJobAdvertisedSearch } from '@/api/position';
 import { ref, reactive } from 'vue'
-import { onPullDownRefresh } from '@dcloudio/uni-app';
-
 
 const swiperAdList = ref(swiperAdListTest)
 const filterList = ref([
-  // { label: '城市', dictType: 'areaTreeData', mode: 'multiSelector' },
-  // { label: '行业', dictType: 'industryTreeData', mode: 'multiSelector' },
-  { label: '求职类型', dictType: 'menduner_job_type' },
-  { label: '薪资待遇', dictType: 'menduner_pay_scope' },
-  { label: '工作经验', dictType: 'menduner_exp_type' },
+  { label: '城市', dictType: 'areaTreeData', key: 'areaIds', map: { text: 'name', value: 'id' } },
+  { label: '行业', dictType: 'industryTreeData',key: 'industryIds', map: { text: 'nameCn', value: 'id' } },
+  { label: '求职类型', dictType: 'menduner_job_type', key: 'jobType' },
+  { label: '薪资待遇', dictType: 'menduner_pay_scope', key: 'payType' },
+  { label: '工作经验', dictType: 'menduner_exp_type', key: 'expType' },
 ])
 
 // 
 const positionListData = ref([])
 const noMore = ref(false)
-const query = reactive({ pageSize: 10, pageNo: 1, content: '' })
+const query = reactive({ 
+  pageSize: 10, 
+  pageNo: 1, 
+  content: '',
+  areaIds: [],
+  industryIds: [],
+  jobType: [],
+  payType: [],
+  expType: []
+})
 //
 const getData = async () => {
-  console.log('getData->query', query)
   const res = await getJobAdvertisedSearch(query)
   const list = res?.data?.list || []
-  // const list = positionList
   if (list?.length) {
     list.forEach(e => {
       e.job = { ...e.job, ...dealDictObjData({}, e.job) }
@@ -59,10 +63,15 @@ const getData = async () => {
     positionListData.value = positionListData.value.concat(list)
   }
   if (list?.length < query.pageSize) noMore.value = true
-  // console.log('列表', positionListData.value)
 }
 getData()
 
+const handleSearch = (key, value) => {
+  query[key][0] = value
+  console.log(query, 'query')
+  onSearch()
+}
+
 const onSearch = () => {
   query.pageNo = 1
   noMore.value = false
@@ -75,17 +84,6 @@ const loadingMore = () => { // 加载更多
   getData()
 }
 
-const refresh = () => { // 下拉刷新
-  onSearch(searchContent.value)
-}
-
-
-//下拉刷新
-onPullDownRefresh(() => { // 下拉刷新
-  // debugger
-  onSearch(searchContent.value)
-})
-
 </script>
 
 <style scoped lang="scss">

+ 1 - 1
utils/position.js

@@ -1,5 +1,5 @@
 import { reactive, ref } from 'vue'
-import { getDict } from './useDictionaries'
+import { getDict } from '../hooks/useDictionaries'
 import { getPublicRatio } from '@/api/user'
 
 const dictObj = reactive({

+ 11 - 0
utils/request.js

@@ -7,6 +7,7 @@ import Request from 'luch-request';
 import { refreshToken } from '@/api/common';
 import { userStore } from '@/store/user'
 import { baseUrl, tenantId, apiPath } from './config'
+import qs from 'qs'
 
 const options = {
 	// 显示操作成功消息 默认不显示
@@ -104,6 +105,16 @@ http.interceptors.request.use(
 
     config.header['Accept'] = '*/*';
     config.header['tenant-id'] = tenantId;
+
+		// get参数编码
+		const params = config.params || {}
+    if (config.method === 'GET' && params) {
+      config.params = {}
+      const paramsStr = qs.stringify(params, { allowDots: true })
+      if (paramsStr) {
+        config.url = config.url + '?' + paramsStr
+      }
+    }
 		return config;
 	},
 	(error) => {