Commit ba51dd98 by yangxiaolei

inputCurrency 增加依赖收集功能

parent 169002c7
<template> <template>
<el-input :class="{'redClass':red && isDisable}" v-storeModify :id="id" ref="form-item" v-model="model" v-bind="attrs" v-on="$listeners" v-bind:disabled="isDisable"> <el-input :class="{'redClass':red && isDisplay}" v-storeModify :id="id" ref="form-item" v-model="model" v-bind="attrs" v-on="$listeners" v-bind:disabled="isDisable">
<template v-slot:suffix> <template v-slot:suffix>
<slot name="suffix"></slot> <slot name="suffix"></slot>
</template> </template>
...@@ -76,6 +76,11 @@ export default { ...@@ -76,6 +76,11 @@ export default {
return this.mode === 'display' || this.disabled return this.mode === 'display' || this.disabled
} }
}, },
isDisplay: {
get () {
return this.mode === 'display'
}
},
highlight () { highlight () {
return this.$store.state.Status.highlights.indexOf(this.id) !== -1 return this.$store.state.Status.highlights.indexOf(this.id) !== -1
}, },
......
<template> <template>
<el-input <el-input
:id="id" :id="id"
v-storeModify
:class="{'redClass':isDisplay && isDisable}"
ref="form-item" ref="form-item"
class="m-input-currency" class="m-input-currency"
v-model="model" v-model="model"
...@@ -15,6 +17,44 @@ ...@@ -15,6 +17,44 @@
<script> <script>
import BigNumber from "bignumber.js"; import BigNumber from "bignumber.js";
export default { export default {
inject: ["root"],
directives:{
storeModify:{
update(el,bind,vnode){
let _this = vnode.context
let key = vnode.parent.data.model.expression
let keyArray = key.split('.')
let curKey = keyArray.pop()
let resultKey = keyArray.join(".")
let deepData = _this.getProperty(resultKey,_this.root)
if(deepData && Array.isArray(deepData.modifySet)){
if(deepData.modifySet.includes(curKey)){
_this.red = true
}
}
el.onchange = (...args)=>{
console.log("12")
if(deepData.modifySet){
if(Array.isArray(deepData.modifySet)){
if(deepData.modifySet.includes(curKey)){
return
}
deepData.modifySet.push(curKey)
}
} else {
deepData.modifySet = [curKey]
}
}
}
}
},
data(){
return {
red:false
}
},
props: { props: {
value: { value: {
type: [String, Number], type: [String, Number],
...@@ -69,6 +109,11 @@ export default { ...@@ -69,6 +109,11 @@ export default {
get() { get() {
return this.mode === "display" || this.disabled; return this.mode === "display" || this.disabled;
} }
},
isDisplay: {
get () {
return this.mode === 'display'
}
} }
}, },
methods: { methods: {
...@@ -153,6 +198,15 @@ export default { ...@@ -153,6 +198,15 @@ export default {
} }
return this.value; return this.value;
}, },
getProperty(str, value) {
let keys = str?.split('.')
for (let key of keys) {
if (value) {
value = value[key]
}
}
return value
},
formatValue(value) { formatValue(value) {
if (value !== null && value !== undefined && value.toString) { if (value !== null && value !== undefined && value.toString) {
var temp = value var temp = value
...@@ -211,7 +265,11 @@ export default { ...@@ -211,7 +265,11 @@ export default {
}; };
</script> </script>
<style> <style lang="less" scoped>
.redClass /deep/ .el-input__inner{
border-color: red;
}
/* .el-input.highlight .el-input__inner{ /* .el-input.highlight .el-input__inner{
border-color: red; border-color: red;
} */ } */
......
<template> <template>
<el-input-number :id="id" :class="{'highlight': highlight}" ref="form-item" v-model="model" :controls="false" v-bind="$attrs" v-on="$listeners" v-bind:disabled="isDisable"/> <el-input-number :id="id" v-storeModify :class="{'highlight': highlight,'redClass':red && isDisable}" ref="form-item" v-model="model" :controls="false" v-bind="$attrs" v-on="$listeners" v-bind:disabled="isDisable"/>
</template> </template>
<script> <script>
export default { export default {
inject: ["root"],
directives:{
storeModify:{
update(el,bind,vnode){
let _this = vnode.context
let key = vnode.parent.data.model.expression
let keyArray = key.split('.')
let curKey = keyArray.pop()
let resultKey = keyArray.join(".")
let deepData = _this.getProperty(resultKey,_this.root)
if(deepData && Array.isArray(deepData.modifySet)){
if(deepData.modifySet.includes(curKey)){
_this.red = true
}
}
el.onchange = (...args)=>{
if(deepData.modifySet){
if(Array.isArray(deepData.modifySet)){
if(deepData.modifySet.includes(curKey)){
return
}
deepData.modifySet.push(curKey)
}
} else {
deepData.modifySet = [curKey]
}
}
}
}
},
data(){
return {
red:false
}
},
props: { props: {
value: { value: {
type: Number, type: Number,
...@@ -38,14 +75,28 @@ export default { ...@@ -38,14 +75,28 @@ export default {
highlight () { highlight () {
return this.$store.state.Status.highlights.indexOf(this.id) !== -1 return this.$store.state.Status.highlights.indexOf(this.id) !== -1
} }
},
methods:{
getProperty(str, value) {
let keys = str?.split('.')
for (let key of keys) {
if (value) {
value = value[key]
}
}
return value
}
} }
} }
</script> </script>
<style scope> <style lang="less" scoped>
.el-input-number .el-input__inner { .el-input-number .el-input__inner {
text-align: left; text-align: left;
} }
.el-input.highlight .el-input__inner{ .el-input.highlight .el-input__inner{
border-color: red; border-color: red;
} }
.redClass /deep/ .el-input__inner{
border-color: red;
}
</style> </style>
\ No newline at end of file
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