From cefa54c9db1eab5db1d1757c1045e6ba37e7b58c Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 22 Apr 2020 13:35:22 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9select,=20?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=8D=95=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/RelationCard/index.vue | 4 +-- src/components/Select2/index.vue | 40 ++++++++++------------- src/i18n/langs/cn.js | 3 +- src/views/users/UserGroupDetail/index.vue | 6 ++-- 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/components/RelationCard/index.vue b/src/components/RelationCard/index.vue index 98ee74f08..992c86521 100644 --- a/src/components/RelationCard/index.vue +++ b/src/components/RelationCard/index.vue @@ -17,7 +17,7 @@ - {{ obj.value }} + {{ obj.label }} @@ -57,7 +57,7 @@ export default { default: () => [] }, objects: { - type: Array, + type: [Array, null], default: null }, value: { diff --git a/src/components/Select2/index.vue b/src/components/Select2/index.vue index 08a6cffbd..b9b5d8eb1 100644 --- a/src/components/Select2/index.vue +++ b/src/components/Select2/index.vue @@ -8,6 +8,7 @@ :multiple="multiple" filterable remote + popper-append-to-body class="select2" v-bind="$attrs" v-on="$listeners" @@ -54,27 +55,27 @@ export default { // 去这个地址获取options url: { type: String, - required: true + default: null }, // 可以将请求的参数进行转换,同jquery select2 makeParams makeParams: { type: Function, - default: prams => { - const page = prams.page || 1 + default: (params) => { + const page = params.page || 1 const p = { - offset: (page - 1) * prams.pageSize, - limit: prams.pageSize + offset: (page - 1) * params.pageSize, + limit: params.pageSize } - prams = Object.assign(prams, p) - delete prams['page'] - delete prams['pageSize'] - return prams + params = Object.assign(params, p) + delete params['page'] + delete params['pageSize'] + return params } }, // 对返回的数据进行处理, 同jquery select2 processResults processResults: { type: Function, - default: data => { + default(data) { let results = data.results results = results.map((item) => { return { label: item.name, value: item.id } @@ -93,11 +94,6 @@ export default { type: Boolean, default: true }, - // 是否将选中的作为默认选择的, 如果是,则会把选择的数据放入到 options中,并且框中会选中 - isSelectedValue: { - type: Boolean, - default: true - }, pageSize: { type: Number, default: 20 @@ -110,15 +106,11 @@ export default { hasMore: true, pageSize: this.pageSize } - let validValue = this.value - if (this.multiple) { - validValue = this.isSelectedValue ? [...this.value] : [] - } return { loading: false, + validValue: this.multiple ? [] : '', defaultParams: defaultParams, params: Object.assign({}, defaultParams), - validValue: validValue, totalOptions: this.options || [], initialOptions: [] } @@ -148,7 +140,8 @@ export default { }, safeMakeParams(params) { params = _.cloneDeep(params) - return this.makeParams.bind(this)(params) + delete params['hasMore'] + return this.makeParams(params) }, filterOptions(query) { this.resetParams() @@ -163,10 +156,11 @@ export default { data = this.processResults.bind(this)(data) data.results.forEach((v) => { this.initialOptions.push(v) - if (this.isSelectedValue && this.optionsValues.indexOf(v.value) === -1) { + if (this.optionsValues.indexOf(v.value) === -1) { this.totalOptions.push(v) } }) + // 如果还有其它页,继续获取, 如果没有就停止 if (!data.pagination) { this.$emit('loadInitialOptionsDone', this.initialOptions) this.params.hasMore = false @@ -179,7 +173,6 @@ export default { const params = this.safeMakeParams(this.params) const resp = await this.$axios.get(this.url, { params: params }) const data = this.processResults.bind(this)(resp) - console.log(data) if (!data.pagination) { this.params.hasMore = false } @@ -200,6 +193,7 @@ export default { this.$log.debug('Start get select2 options') await this.getOptions() } + this.validValue = this.value } } } diff --git a/src/i18n/langs/cn.js b/src/i18n/langs/cn.js index aefc2006c..b673b5ce0 100644 --- a/src/i18n/langs/cn.js +++ b/src/i18n/langs/cn.js @@ -75,7 +75,8 @@ const cn = { 'Active selected': '激活所选', 'rows': '行', 'Basic Info': '基本信息', - 'Add': '添加' + 'Add': '添加', + 'Members': '成员' }, route: { 'dashboard': '仪表盘', diff --git a/src/views/users/UserGroupDetail/index.vue b/src/views/users/UserGroupDetail/index.vue index 8698f4755..3621e295c 100644 --- a/src/views/users/UserGroupDetail/index.vue +++ b/src/views/users/UserGroupDetail/index.vue @@ -51,7 +51,7 @@ export default { icon: 'fa-user', title: this.$tc('Members'), url: '/api/v1/users/users/', - value: [], + objectsId: [], loading: true }, cardTitle: this.$tc('Basic Info') @@ -82,9 +82,9 @@ export default { mounted() { getUserGroupMembers(this.$route.params.id).then(data => { for (const i of data) { - this.relationConfig.value.push(i.user) + this.relationConfig.objectsId.push(i.user) } - console.log(this.relationConfig.value) + console.log(this.relationConfig.objectsId) }).finally(() => { this.relationConfig.loading = false })