From 0c351de9ec95c18d386712ea9d857203d9730a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=87=AA=E5=B8=A6=E5=A4=A7=E4=BD=AC=E6=B0=94=E5=9C=BA?= <188633308@qq.com> Date: Mon, 31 May 2021 18:12:04 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E8=87=AA=E5=AE=9A=E4=B9=89=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web/src/main.js | 5 +++ .../house/member/selector/selectedList.vue | 24 +++++++---- .../house/member/selector/selectorList.vue | 22 ++++++---- Web/src/util/query/index.js | 41 +++++++++++++++++++ 4 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 Web/src/util/query/index.js diff --git a/Web/src/main.js b/Web/src/main.js index 1ab253b..3e6598c 100644 --- a/Web/src/main.js +++ b/Web/src/main.js @@ -66,6 +66,11 @@ Vue.prototype.$moment = moment */ import { auth } from './components/authorized' Vue.prototype.$auth = auth +/** + * 常用工具函数全局化 + */ +import { getSearchInfo } from './util/query' +Vue.prototype.$getSearchInfo = getSearchInfo /** * 注册全局组件 diff --git a/Web/src/pages/business/house/member/selector/selectedList.vue b/Web/src/pages/business/house/member/selector/selectedList.vue index afd452d..5cd1ca1 100644 --- a/Web/src/pages/business/house/member/selector/selectedList.vue +++ b/Web/src/pages/business/house/member/selector/selectedList.vue @@ -18,6 +18,9 @@ + + + - 全部 + 全部 {{item.value}} @@ -92,7 +95,12 @@ export default { /* 查询条件 */ query: { - type: 0, + type: '', + }, + + queryType: { + type: '=', + createdTime: ['>=', '<'], }, /* 表格字段 */ @@ -150,13 +158,15 @@ export default { */ loadData(params) { const query = this.$_.cloneDeep(this.query); - if (!query.userId) { - query.userId = this.userId; - } + const searchInfo = this.$getSearchInfo({ + query, + queryType: this.queryType, + }); return this.$api[api.page]({ ...params, - ...query, + userId: this.userId, + searchInfo, }).then((res) => { return res.data; }); diff --git a/Web/src/pages/business/house/member/selector/selectorList.vue b/Web/src/pages/business/house/member/selector/selectorList.vue index c3f2766..b53ed23 100644 --- a/Web/src/pages/business/house/member/selector/selectorList.vue +++ b/Web/src/pages/business/house/member/selector/selectorList.vue @@ -31,10 +31,10 @@ - 全部 + 全部 {{item.value}} @@ -90,7 +90,11 @@ export default { /* 查询条件 */ query: { - type: 0, + type: '', + }, + + queryType: { + type: '=', }, /* 表格字段 */ @@ -148,13 +152,15 @@ export default { */ loadData(params) { const query = this.$_.cloneDeep(this.query); - if (!query.userId) { - query.userId = this.userId; - } + const searchInfo = this.$getSearchInfo({ + query, + queryType: this.queryType, + }); return this.$api[api.page]({ ...params, - ...query, + userId: this.userId, + searchInfo, }).then((res) => { return res.data; }); @@ -175,7 +181,7 @@ export default { onResetQuery() { /** 在这里重置查询条件时,可对特殊的字段做保留处理 */ this.query = { - type: 0, + type: '', }; this.onQuery(); }, diff --git a/Web/src/util/query/index.js b/Web/src/util/query/index.js new file mode 100644 index 0000000..d7f46d6 --- /dev/null +++ b/Web/src/util/query/index.js @@ -0,0 +1,41 @@ +export const getSearchInfo = ({ query, queryType }) => { + const searchInfo = [] + Object.keys(query).forEach((p) => { + if (queryType && queryType.hasOwnProperty(p) && queryType[p].constructor === Array) { + queryType[p].forEach((q, i) => { + if (query[p] != null && query[p] != undefined) { + const _searchInfo = { + field: p, + value: [query[p][i]], + type: q, + } + searchInfo.push(_searchInfo) + } + }) + } else { + const _searchInfo = { + field: p, + value: [], + type: undefined, + } + + if (query[p] != null && query[p] != undefined) { + if (query[p].constructor === Array) { + _searchInfo.value = query[p] + } else { + _searchInfo.value = [query[p]] + } + } else { + return false + } + + if (queryType && queryType.hasOwnProperty(p)) { + _searchInfo.type = queryType[p] + } + + searchInfo.push(_searchInfo) + } + }) + + return searchInfo +} \ No newline at end of file