-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:wxs77577/rest-admin
- Loading branch information
Showing
9 changed files
with
1,759 additions
and
1,442 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<template> | ||
<v-select | ||
v-model="model" | ||
@search="getAjaxOptions" | ||
label="text" | ||
:options="newOptions" | ||
:multiple="multiple" | ||
> | ||
<div slot="no-options">{{noOptionsText}}</div> | ||
</v-select> | ||
</template> | ||
|
||
<script> | ||
import VSelect from "vue-select"; | ||
export default { | ||
components: { | ||
VSelect | ||
}, | ||
data() { | ||
return { | ||
newOptions: this.options.slice(0) | ||
}; | ||
}, | ||
props: { | ||
value: { | ||
deafult() { | ||
return this.multiple ? [] : null; | ||
} | ||
}, | ||
options: { | ||
default: () => [] | ||
}, | ||
name: {}, | ||
multiple: {}, | ||
field: {}, | ||
parent: {}, | ||
ajaxOptions: {}, | ||
noOptionsText: { | ||
default(){ | ||
return this.$t('messages.no_options_text') | ||
} | ||
}, | ||
q: '' | ||
}, | ||
computed: { | ||
model: { | ||
get() { | ||
if (this.multiple) { | ||
return this.newOptions.filter(v => this.value.includes(v.value)); | ||
} else { | ||
return this.newOptions.find(v => this.value === v.value); | ||
} | ||
}, | ||
set(val) { | ||
let ret; | ||
if (this.multiple) { | ||
const isChanged = JSON.stringify(val) !== JSON.stringify(this.value); | ||
if (isChanged) { | ||
ret = val.map(v => v.value); | ||
} | ||
} else { | ||
ret = val.value; | ||
} | ||
ret && this.$emit("input", ret); | ||
} | ||
} | ||
}, | ||
methods: { | ||
getAjaxOptions(q) { | ||
this.q = q | ||
this.fetchOptions() | ||
}, | ||
initOptionsForSelect2() { | ||
const parentOptions = this.parent[this.name + "_data"]; | ||
if (parentOptions) { | ||
this.newOptions = this.options.concat(parentOptions); | ||
} | ||
}, | ||
fetchOptions(query = {}) { | ||
const params = this.ajaxOptions; | ||
const { url, resource, where = {}, text, depends } = params; | ||
params.where = Object.assign({}, where, query); | ||
if (text) { | ||
options.where[text] = this.q; | ||
} | ||
const apiUrl = url | ||
? _.template(url)({ item: this.parent }) | ||
: resource + "/options"; | ||
this.$http.get(apiUrl, { params }).then(({ data }) => { | ||
this.model = { value: null }; | ||
this.newOptions = data; | ||
}); | ||
} | ||
}, | ||
mounted() { | ||
if (this.ajaxOptions) { | ||
const { url, resource, where, depends } = this.ajaxOptions; | ||
if (depends) { | ||
this.$watch( | ||
`parent.${depends}`, | ||
val => { | ||
console.log(val) | ||
this.fetchOptions({ [depends]: val }); | ||
}, | ||
{ | ||
// deep: true, | ||
immediate: true | ||
} | ||
); | ||
} else { | ||
this.fetchOptions(); | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.