Commit b943f812 authored by 何虹's avatar 何虹 💬

优化组件

parent 0a056cc4
<template> <template>
<div style="width:500px"> <div style="width:500px">
<hsSelectPlus <hsSwitch
ref='select'
v-model="selectValue"
:allSourceData='allSourceData'
:requestMethod='requestMethod'
></hsSelectPlus>
<el-button @click="change1">change1</el-button>
<el-button @click="change2">change2</el-button>
<hsCheckboxGroup
v-model="checkList" v-model="checkList"
:allSourceData='configData' :allSourceData='configData'
></hsCheckboxGroup> ></hsSwitch>
</div> </div>
</template> </template>
...@@ -21,77 +13,20 @@ export default { ...@@ -21,77 +13,20 @@ export default {
mixins: [uc], mixins: [uc],
data() { data() {
return { return {
checkList:'B,A', value1: "",
selectValue: "1052069380861628416", checkList: "",
allSourceData: {
config: {
url: "",
isInnerRequest: true,
proxyTag: "commonUtilAPI",
ref: {
const_id: "0",
table_name: "im_store_group",
columns: "id,name",
remote_condition: "",
displayfield: "",
writebackfield: []
},
dyncQueryParms: {},
multiple: false,
disabled: false,
size: "mini",
clearable: true,
title: "标题",
placeholder: "请选择",
value: "id",
label: "name",
is_computed: false
},
sourceData: []
},
show: false,
config: {
url: "",
proxyTag: "commonUtilAPI",
ref: {
const_id: "0",
table_name: "im_store_group",
columns: "id,name",
remote_condition: "",
displayfield: "",
writebackfield: []
},
dyncQueryParms: {},
multiple: false,
disabled: false,
size: "mini",
clearable: true,
title: "标题",
placeholder: "请选择",
value: "id",
label: "name",
is_computed: false
},
configData: { configData: {
sourceData: [ sourceData: [],
{ config: {
label: "A" activeText: "A",
}, inactiveText: "B",
{ changeed: () => {
label: "B" console.log(21312);
} }
], }
config: {}
} }
}; };
}, },
methods: { methods: {}
change1() {
this.allSourceData.sourceData = [{ value: 1, label: 2 }];
},
change2() {
this.allSourceData.sourceData = [{ value: 2, label: 3 }];
}
}
}; };
</script> </script>
\ No newline at end of file
<template> <template>
<div class="hsInputBox" :id='elId'> <div
<div class="inputCurr"> class="hsInputBox"
<span>{{valueTxt}}</span> :id='elId'
</div> >
<jsoneditor v-model='jsoneditorVisible' <div class="inputCurr">
:elInfo='elInfo' <span>{{valueTxt}}</span>
:layout='layout' </div>
:jsoneditorCloseAfter='jsoneditorCloseAfter' <jsoneditor
:jsoneditorOpenAfter='jsoneditorOpenAfter' v-model='jsoneditorVisible'
> :elInfo='elInfo'
:layout='layout'
:jsoneditorCloseAfter='jsoneditorCloseAfter'
:jsoneditorOpenAfter='jsoneditorOpenAfter'
>
</jsoneditor> </jsoneditor>
</div> </div>
</template> </template>
<script> <script>
import ucComponent from '../ucClass/uc_component' import ucComponent from "../ucClass/uc_component";
import jsoneditor from '../common/jsoneditor' import jsoneditor from "../common/jsoneditor";
export default { export default {
mixins: [ucComponent], mixins: [ucComponent],
components: { components: {
jsoneditor jsoneditor
}, },
name: 'hsComputed', name: "hsComputed",
props: { props: {
allSourceData: { allSourceData: {
type: Object, type: Object,
default() { default() {
return {} return {};
} }
}, },
elInfo: { elInfo: {
type: Object, type: Object,
default() { default() {
return {} return {};
} }
}, },
value: '', value: "",
layout: {}, layout: {},
jsoneditorCloseAfter: { jsoneditorCloseAfter: {
type: Function type: Function
...@@ -45,73 +49,72 @@ export default { ...@@ -45,73 +49,72 @@ export default {
formData: { formData: {
type: Object, type: Object,
default() { default() {
return {} return {};
} }
} }
}, },
watch: { watch: {
allSourceData: { allSourceData: {
handler: function(newVal, oldVal) { handler: function(newVal, oldVal) {
const { config } = newVal const { config } = newVal;
this.initConfig(config) this.initConfig(config);
}, },
deep: true deep: true
}, },
value(val) { value(val) {
this.value_inner = val this.value_inner = val;
}, },
value_inner(val) { value_inner(val) {
this.$emit('input', val) this.$emit("input", val);
}, },
formData: { formData: {
handler: function(newVal, oldVal) { handler: function(newVal, oldVal) {
this.computedTxt(newVal) this.valueTxt = this.computedTxt(newVal);
}, },
deep: true deep: true
} }
}, },
data() { data() {
return { return {
elId: '', elId: "",
value_inner: '', value_inner: "",
jsoneditorVisible: false, jsoneditorVisible: false,
sourceData: [], sourceData: [],
configData: { configData: {},
}, valueTxt: "0"
valueTxt: '0' };
}
}, },
mounted() { mounted() {
this.$nextTick(() => { this.$nextTick(() => {
const { config, sourceData } = this.allSourceData const { config, sourceData } = this.allSourceData;
this.sourceData = sourceData this.sourceData = sourceData;
this.initConfig(config) this.initConfig(config);
}) });
}, },
methods: { methods: {
computedTxt() { computedTxt() {
const { click } = this.configData const { click } = this.configData;
const type = typeof click const type = typeof click;
if (type === 'function') { if (type === "function") {
click(this.formData) return click(this.formData);
} }
}, },
initConfig(config = {}) { initConfig(config = {}) {
this.configData = Object.assign(this.configData, config) this.configData = Object.assign(this.configData, config);
this.computedTxt() this.valueTxt = this.computedTxt();
} }
} }
} };
</script> </script>
<style scoped> <style scoped>
.hsInputBox{ .hsInputBox {
padding: 1px; padding: 1px;
width:100%; width: 100%;
height:100%; height: 100%;
display: flex; display: flex;
} }
.inputCurr{ .inputCurr {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
......
<template> <template>
<div :id='elId' class="selectBoxPlus" style='width:100%;height:100%;'> <div
<div class="contarnBox" style='width:100%;height:100%;'> :id='elId'
<div class="selectTitle" v-show='configData.title'>{{configData.title}}</div> class="selectBoxPlus"
<div class="selectCurr" style='width:80%;height:100%;'> style='width:100%;height:100%;'
<template v-if='elInfo.el=="hsDatePicker"'> >
<el-date-picker <div
size='mini' class="contarnBox"
v-model="value_inner" style='width:100%;height:100%;'
:type="configData.type" >
:value-format="configData.valueFormat" <div
:placeholder="configData.placeholder" class="selectTitle"
:range-separator="configData.rangeSeparator" v-show='configData.title'
:start-placeholder="configData.startPlaceholder" >{{configData.title}}</div>
:end-placeholder="configData.endPlaceholder"> <div
</el-date-picker> class="selectCurr"
</template> style='width:80%;height:100%;'
</div> >
<el-date-picker
@change='changed'
size='mini'
v-model="value_inner"
:type="configData.type"
:value-format="configData.valueFormat"
:placeholder="configData.placeholder"
:range-separator="configData.rangeSeparator"
:start-placeholder="configData.startPlaceholder"
:end-placeholder="configData.endPlaceholder"
>
</el-date-picker>
</div>
</div> </div>
<jsoneditor v-model='jsoneditorVisible' <jsoneditor
:elInfo='elInfo' v-model='jsoneditorVisible'
:layout='layout' :elInfo='elInfo'
:jsoneditorCloseAfter='jsoneditorCloseAfter' :layout='layout'
:jsoneditorOpenAfter='jsoneditorOpenAfter' :jsoneditorCloseAfter='jsoneditorCloseAfter'
> :jsoneditorOpenAfter='jsoneditorOpenAfter'
>
</jsoneditor> </jsoneditor>
</div> </div>
</template> </template>
<script> <script>
import jsoneditor from '../common/jsoneditor' import jsoneditor from "../common/jsoneditor";
import ucComponent from '../ucClass/uc_component' import ucComponent from "../ucClass/uc_component";
export default { export default {
mixins: [ucComponent], mixins: [ucComponent],
components: { components: {
jsoneditor jsoneditor
}, },
name: 'hsDatePicker', name: "hsDatePicker",
props: { props: {
elInfo: { elInfo: {
type: Object, type: Object,
default() { default() {
return {} return {};
} }
}, },
allSourceData: { allSourceData: {
type: Object, type: Object,
default() { default() {
return {} return {};
} }
}, },
value: '', value: "",
layout: {}, layout: {},
jsoneditorCloseAfter: { jsoneditorCloseAfter: {
type: Function type: Function
...@@ -60,81 +74,92 @@ export default { ...@@ -60,81 +74,92 @@ export default {
watch: { watch: {
allSourceData: { allSourceData: {
handler: function(newVal, oldVal) { handler: function(newVal, oldVal) {
const { config } = newVal const { config } = newVal;
this.initConfig(config) this.initConfig(config);
}, },
deep: true deep: true
}, },
value(val) { value(val) {
this.value_inner = val this.value_inner = val;
}, },
value_inner(val) { value_inner(val) {
this.$emit('input', val) this.$emit("input", val);
} }
}, },
data() { data() {
return { return {
elId: '', elId: "",
value_inner: '', value_inner: "",
jsoneditorVisible: false, jsoneditorVisible: false,
configData: {} configData: {}
} };
}, },
mounted() { mounted() {
const { config } = this.allSourceData const { config } = this.allSourceData;
this.initConfig(config) this.initConfig(config);
}, },
methods: { methods: {
execAction(actionName, value) {
const type = typeof actionName;
if (type === "function") {
actionName(value, this.formData);
}
},
changed(value) {
this.$emit('changed',value);
const { changed } = this.configData;
this.execAction(changed,value)
},
initConfig(config) { initConfig(config) {
if (!config) return if (!config) return;
this.configData = config this.configData = config;
} }
} }
} };
</script> </script>
<style scoped> <style scoped>
.hsInputBox{ .hsInputBox {
padding: 1px; padding: 1px;
width:100%; width: 100%;
height:100%; height: 100%;
display: flex; display: flex;
} }
.hsInputInner{ .hsInputInner {
height: 80%; height: 80%;
width: 80%; width: 80%;
} }
.inputTitle{ .inputTitle {
flex:1; flex: 1;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.inputCurr{ .inputCurr {
flex:1; flex: 1;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 100%; height: 100%;
} }
.contarnBox{ .contarnBox {
display: flex; display: flex;
} }
.selectTitle{ .selectTitle {
flex:1; flex: 1;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.selectCurr{ .selectCurr {
flex: 3; flex: 3;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.selectBoxPlus>>> .el-select>.el-input{ .selectBoxPlus >>> .el-select > .el-input {
height: 100%; height: 100%;
} }
.selectBoxPlus>>>.el-select .el-input__inner{ .selectBoxPlus >>> .el-select .el-input__inner {
height: 100%; height: 100%;
} }
</style> </style>
<template> <template>
<div class="hsControlBoxOut" :id='elId'> <div
<div class="hsControlBoxInner"> class="hsControlBoxOut"
<el-switch :id='elId'
v-model="value_inner" >
:active-text="configData.activeText" <div class="hsControlBoxInner">
:inactive-text="configData.inactiveText" <el-switch
@change='change' v-model="value_inner"
:disabled='disabled' :active-text="configData.activeText"
> :inactive-text="configData.inactiveText"
</el-switch> @change='change'
</div> :disabled='configData.disabled'
<jsoneditor v-model='jsoneditorVisible' >
:elInfo='elInfo' </el-switch>
:layout='layout' </div>
:jsoneditorCloseAfter='jsoneditorCloseAfter' <jsoneditor
:jsoneditorOpenAfter='jsoneditorOpenAfter' v-model='jsoneditorVisible'
> :elInfo='elInfo'
:layout='layout'
:jsoneditorCloseAfter='jsoneditorCloseAfter'
:jsoneditorOpenAfter='jsoneditorOpenAfter'
>
</jsoneditor> </jsoneditor>
</div> </div>
</template> </template>
<script> <script>
import ucComponent from '../ucClass/uc_component' import ucComponent from "../ucClass/uc_component";
import jsoneditor from '../common/jsoneditor' import jsoneditor from "../common/jsoneditor";
export default { export default {
mixins: [ucComponent], mixins: [ucComponent],
components: { components: {
jsoneditor jsoneditor
}, },
name: 'hsSwitch', name: "hsSwitch",
props: { props: {
disabled: { disabled: {
type: Boolean, type: Boolean,
...@@ -36,16 +40,16 @@ export default { ...@@ -36,16 +40,16 @@ export default {
allSourceData: { allSourceData: {
type: Object, type: Object,
default() { default() {
return {} return {};
} }
}, },
elInfo: { elInfo: {
type: Object, type: Object,
default() { default() {
return {} return {};
} }
}, },
value: '', value: "",
layout: {}, layout: {},
jsoneditorCloseAfter: { jsoneditorCloseAfter: {
type: Function type: Function
...@@ -57,74 +61,84 @@ export default { ...@@ -57,74 +61,84 @@ export default {
watch: { watch: {
allSourceData: { allSourceData: {
handler: function(newVal, oldVal) { handler: function(newVal, oldVal) {
const { config } = newVal const { config } = newVal;
this.initConfig(config) this.initConfig(config);
}, },
deep: true deep: true
}, },
value(val) { value(val) {
// 只接受0、1、true、false // 只接受0、1、true、false
if (typeof val === 'boolean') { if (typeof val === "boolean") {
this.value_inner = val this.value_inner = val;
} else { } else {
this.value_inner = !!Number(val) this.value_inner = !!Number(val);
} }
}, },
value_inner(val) { value_inner(val) {
if (typeof this.value === 'boolean') { if (typeof this.value === "boolean") {
this.$emit('input', val) this.$emit("input", val);
} else { } else {
let v = val let v = val;
if (typeof this.value === 'string') { if (typeof this.value === "string") {
v = Number(val) + '' v = Number(val) + "";
} else { } else {
v = Number(val) v = Number(val);
} }
this.$emit('input', v) this.$emit("input", v);
} }
} }
}, },
data() { data() {
return { return {
elId: '', elId: "",
value_inner: false, value_inner: false,
jsoneditorVisible: false, jsoneditorVisible: false,
sourceData: [], sourceData: [],
configData: { configData: {
activeText:'',
inactiveText:''
} }
} };
}, },
mounted() { mounted() {
this.$nextTick(() => { this.$nextTick(() => {
const { config, sourceData } = this.allSourceData const { config, sourceData } = this.allSourceData;
this.sourceData = sourceData this.sourceData = sourceData;
this.initConfig(config) this.initConfig(config);
if (typeof this.value === 'boolean') { if (typeof this.value === "boolean") {
this.value_inner = this.value this.value_inner = this.value;
} else { } else {
this.value_inner = !!Number(this.value) this.value_inner = !!Number(this.value);
} }
}) });
}, },
methods: { methods: {
execAction(actionName, value) {
const type = typeof actionName;
if (type === "function") {
actionName(value, this.formData);
}
},
change(val) { change(val) {
const { changeed } = this.configData;
this.execAction(changeed)
}, },
initConfig(config = {}) { initConfig(config = {}) {
this.configData = Object.assign(this.configData, config) this.configData = Object.assign(this.configData, config);
} }
} }
} };
</script> </script>
<style scoped> <style scoped>
.hsControlBoxOut{ .hsControlBoxOut {
padding: 1px; padding: 1px;
width:100%; width: 100%;
height:100%; height: 100%;
display: flex; display: flex;
box-sizing:border-box; box-sizing: border-box;
} }
.hsControlBoxInner{ .hsControlBoxInner {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment