diff --git a/src/components/Select2/index.vue b/src/components/Select2/index.vue
index 244d98e9b..933acb3dd 100644
--- a/src/components/Select2/index.vue
+++ b/src/components/Select2/index.vue
@@ -1,11 +1,11 @@
+ >
+
@@ -37,7 +38,7 @@ export default {
* 如果元素滚动到底, 下面等式返回true, 没有则返回false:
* ele.scrollHeight - ele.scrollTop === ele.clientHeight;
*/
- const condition = this.scrollHeight - this.scrollTop <= this.clientHeight
+ const condition = this.scrollHeight - this.scrollTop - 30 <= this.clientHeight
if (condition) {
binding.value()
}
@@ -58,13 +59,25 @@ export default {
type: Function,
default: null
},
+ processSelected: {
+ type: Function,
+ default: null
+ },
options: {
type: Array,
- default: () => []
+ default: () => ([])
},
value: {
type: [Array, String, Number, Boolean],
- default: () => []
+ default: () => ([])
+ },
+ initial: {
+ type: Array,
+ default: () => ([])
+ },
+ multiple: {
+ type: Boolean,
+ default: true
}
},
data() {
@@ -91,7 +104,13 @@ export default {
const more = !!data.next
return { results: results, pagination: more }
},
- vaultOrDefault: this.value || []
+ defaultProcessSelected: data => {
+ return data.map(item => {
+ return { label: item.name, value: item.id }
+ })
+ },
+ valueSafe: [...this.value],
+ optionsSafe: this.options || []
}
},
computed: {
@@ -101,11 +120,35 @@ export default {
processResultsOrDefault() {
return this.processResults || this.defaultProcessResults
},
- optionsOrDefault() {
- return this.options || []
+ processSelectedOrDefault() {
+ return this.processSelected || this.defaultProcessSelected
+ },
+ initialOptions() {
+ const options = this.processSelectedOrDefault(this.initial)
+ return options
+ },
+ optionsValues() {
+ return this.optionsSafe.map((v) => v.value)
+ },
+ initialValues() {
+ return this.initialOptions.map(v => v.value)
+ }
+ },
+ watch: {
+ initialOptions: (newValue) => {
+ const notInclude = newValue.filter(v => {
+ return this.optionsValues.indexOf(v.value) === -1
+ })
+ this.optionsSafe = [...notInclude, ...this.optionsSafe]
+ const notIncludeValues = notInclude.map(v => v.value)
+ this.valueSafe = [...notIncludeValues, ...this.valueSafe]
}
},
mounted() {
+ if (this.initialOptions) {
+ this.valueSafe = [...this.initialValues, ...this.valueSafe]
+ this.optionsSafe = [...this.initialOptions, ...this.optionsSafe]
+ }
if (this.url) {
this.getOptions()
}
@@ -128,14 +171,13 @@ export default {
},
filterOptions(query) {
this.resetParams()
- this.options = []
+ this.optionsSafe = []
this.params.search = query
this.getOptions()
},
getOptions() {
this.loading = true
const params = this.makeParamsOrDefault(this.params)
- console.log(params)
this.$axios.get(this.url, { params: params }).then(resp => {
this.loading = false
const data = this.processResultsOrDefault(resp)
@@ -143,11 +185,12 @@ export default {
this.params.hasMore = false
}
data.results.forEach((v) => {
- this.options.push(v)
+ if (this.optionsValues.indexOf(v.value) === -1) {
+ this.optionsSafe.push(v)
+ }
})
}).catch(err => {
console.log(err)
- this.options = []
}).then(() => {
this.loading = false
})
diff --git a/src/views/users/UserCreateUpdate.vue b/src/views/users/UserCreateUpdate.vue
index 680a08130..780fc0adf 100644
--- a/src/views/users/UserCreateUpdate.vue
+++ b/src/views/users/UserCreateUpdate.vue
@@ -8,7 +8,7 @@
-
+