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