Skip to content

Commit

Permalink
Merge branch 'master' of github.com:wxs77577/rest-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
maohuangyan committed Apr 16, 2019
2 parents f9d3226 + d0e6398 commit b9ba320
Show file tree
Hide file tree
Showing 9 changed files with 1,759 additions and 1,442 deletions.
2,927 changes: 1,565 additions & 1,362 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@alfsnd/vue-bootstrap-select": "^0.4.1",
"@riophae/vue-treeselect": "0.0.38",
"axios": "^0.18.0",
"bootstrap": "^4.1.0",
"bootstrap-vue": "^2.0.0-rc.11",
"bootswatch": "^4.1.1",
"bootstrap": ">=4.3.1",
"bootstrap-vue": "^2.0.0-rc.14",
"bootswatch": "^4.3.1",
"clipboard": "^2.0.1",
"cropperjs": "^1.4.1",
"dayjs": "^1.6.6",
Expand All @@ -25,26 +26,26 @@
"vue": "^2",
"vue-element-loading": "^1.0.4",
"vue-html5-editor": "^1.1.1",
"vue-i18n": "^7.6.0",
"vue-i18n": "^8.10.0",
"vue-router": "^3.0.1",
"vue-select": "^2.3.0",
"vue-snotify": "^3.1.0",
"vue2-datepicker": "^1.6.0",
"vue2-datepicker": "^2.11.0",
"vuedraggable": "^2.15.0",
"vuex": "^3",
"vuex-router-sync": "^5.0.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3",
"@vue/cli-plugin-eslint": "^3",
"@vue/cli-service": "^3",
"@vue/cli-plugin-babel": "^3.5.5",
"@vue/cli-plugin-eslint": "^3.5.1",
"@vue/cli-service": "^3.5.3",
"body-parser": "^1.18.3",
"express": "^5.0.0-alpha.7",
"faker": "^4.1.0",
"node-sass": "^4.11.0",
"nodemon": "^1.18.3",
"nodemon": "^1.18.11",
"sass-loader": "^7.0.1",
"vue-template-compiler": "^2.5.16"
"vue-template-compiler": "^2.6.10"
},
"eslintConfig": {
"root": true,
Expand Down
2 changes: 1 addition & 1 deletion src/components/DataValue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default {
value() {
// const path = this.name.replace(/\]/g, '').replace(/\[/g, '.').split('.').pop()
// console.log(this.name)
let value = _.get(this.model || {}, this.name);
let value = _.get(this.model || {}, this.field.refLabel || this.field.ref || this.name);
if (!value) {
return value
}
Expand Down
104 changes: 49 additions & 55 deletions src/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,7 @@
:name="name"
></b-form-select>
<div v-else-if="['select2'].includes(field.type)">
<b-select
:name="name"
@search="getAjaxOptions"
label="text"
v-bind="field"
:options="options"
:value="selectedValue"
@input="handleSelect"
:placeholder="field.placeholder || ''"
selectLabel
/>
<b-select v-model="model" v-bind="field" :parent="parent"></b-select>
</div>
<b-tree-select
:normalizer="treeSelectNormalizer"
Expand Down Expand Up @@ -91,7 +81,15 @@
:parent="parent"
/>
<div v-else-if="['switch', 'checkbox'].includes(field.type)">
<b-form-checkbox variant="success" v-bind="field" size="lg" pill type="3d" :id="id" v-model="model"/>
<b-form-checkbox
variant="success"
v-bind="field"
size="lg"
pill
type="3d"
:id="id"
v-model="model"
/>
</div>
<!-- <b-ueditor :state="state" v-else-if="['wysiwyg', 'html'].includes(field.type)" :id="id" v-bind="field" v-model="model" /> -->

Expand Down Expand Up @@ -162,7 +160,12 @@
</b-table>
<b-draggable v-model="model" v-else>
<transition-group tag="div" class="row">
<b-col v-for="(item, i) in model" :key="`draggable-${name}-${i}`" cols="" :lg="field.item_cols || 6">
<b-col
v-for="(item, i) in model"
:key="`draggable-${name}-${i}`"
cols
:lg="field.item_cols || 6"
>
<b-card class="mb-4">
<b-row slot="header" class="justify-content-between">
<b-col>No. {{i + 1}}</b-col>
Expand Down Expand Up @@ -190,7 +193,7 @@
</b-card>
</b-col>
<b-col
cols=""
cols
:lg="field.item_cols || 6"
:key="-1"
class="d-flex align-items-center justify-content-center"
Expand Down Expand Up @@ -278,7 +281,8 @@ import BDraggable from "vuedraggable";
import BTreeSelect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.min.css";
// import BSelect from "vue-multiselect"
import BSelect from "vue-select";
import BSelect from "./FormSelect2";
// import BSelect from "@alfsnd/vue-bootstrap-select";
// import "vue-multiselect/dist/vue-multiselect.min.css"
import BDatePicker from "vue2-datepicker";
// import BUeditor from "./UEditor"
Expand Down Expand Up @@ -393,6 +397,18 @@ export default {
isIntl() {
return this.field.intl || this.field.multilingual;
},
selectedValue1() {
let value = this.initSelectedValue
if (this.isArrayValue) {
value = _.filter(
this.options,
v => this.value && this.value.includes(v.value)
);
} else {
value = _.find(this.options, v => this.value == v.value);
}
return value;
},
model: {
get() {
const isArray =
Expand Down Expand Up @@ -429,17 +445,18 @@ export default {
return {
currentLanguage: this.field.currentLanguage || "en",
options: this.field.options || [],
selectedValue: isArray && !this.value ? [] : this.value
initSelectedValue: isArray && !this.value ? [] : this.value,
selectedValue: isArray && !this.value ? [] : this.value,
};
},
methods: {
addRow() {
if (!this.parent[this.name]) {
this.$set(this.parent, this.name, [])
this.$set(this.parent, this.name, []);
}
this.$nextTick(() => {
this.model.push({})
})
this.model.push({});
});
},
initEditor() {
const language = "zh-cn";
Expand Down Expand Up @@ -564,14 +581,17 @@ export default {
};
},
handleSelect(val) {
console.log(val)
return
if (this.isSelect2) {
if (this.isArrayValue) {
val = _.uniq(_.map(val, "value"));
} else {
val = val ? val.value : null;
}
}
this.$emit("input", val, this.currentLanguage);
// this.$emit("input", val, this.currentLanguage);
},
getFormatter(field) {
if (field.format) {
Expand All @@ -580,29 +600,7 @@ export default {
return v => v;
},
getAjaxOptions(q) {
if (!this.field.ajaxOptions) {
return;
}
const options = this.field.ajaxOptions;
if (!options.where) {
options.where = {};
}
options.where[options.text] = q;
this.$http
.get(options.resource + "/options", {
params: options
})
.then(({ data }) => {
this.options = data;
});
},
initOptionsForSelect2() {
const parentOptions = this.parent[this.name + "_data"];
if (parentOptions) {
this.options = this.options.concat(parentOptions);
}
}
},
mounted() {
if (this.field.type == "html") {
Expand All @@ -621,19 +619,15 @@ export default {
if (this.field.type == "html") {
this.initEditor();
}
if (this.field.ajaxOptions && this.field.ajaxOptions.search !== true) {
this.getAjaxOptions();
}
// if (this.field.ajaxOptions && this.field.ajaxOptions.search !== true) {
// this.getAjaxOptions();
// }
if (this.isSelect2) {
this.initOptionsForSelect2();
if (this.isArrayValue) {
this.selectedValue = _.filter(
this.options,
v => this.value && this.value.includes(v.value)
);
} else {
this.selectedValue = _.find(this.options, v => this.value == v.value);
}
// this.initOptionsForSelect2();
// this.$watch("options", () => {
// });
}
}
};
Expand Down
119 changes: 119 additions & 0 deletions src/components/FormSelect2.vue
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>

3 changes: 2 additions & 1 deletion src/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"deleted_all": "All deleted",
"confirm_delete": "Are you sure you want to delete?",
"image_size": "Size limit: {width}x{height}",
"confirm_delete_all": "Are you sure you want to delete all data?"
"confirm_delete_all": "Are you sure you want to delete all data?",
"no_options_text": "No Options Here!"
},
"errors": {

Expand Down
3 changes: 2 additions & 1 deletion src/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"deleted_all": "全部删除成功",
"confirm_delete": "确定要删除吗?",
"image_size": "尺寸要求:{width}x{height}",
"confirm_delete_all": "此次操作不可恢复,确定要全部删除吗?"
"confirm_delete_all": "此次操作不可恢复,确定要全部删除吗?",
"no_options_text": "暂无可选项"
},
"errors": {
"too_large": "请上传小于{limit}KB的文件",
Expand Down
Loading

0 comments on commit b9ba320

Please sign in to comment.