UNPKG

efview

Version:

A high quality Service UI components Library with Vue.js

182 lines (179 loc) 5.37 kB
export default { name: 'probase', data() { return { value: '', text: '', svalue: '', evalue: '', type: '', hackReset: true, }; }, created() { this.type = this.config.type; }, mounted () { if(this.autofocus) { this.$nextTick(() =>{ this.setFocus(true); }); } }, methods: { input(obj) { // 去除字符串左右空格 if (obj) { let proList = ['text', 'value', 'svalue', 'evalue']; proList.forEach(el => { if (obj[el] !== undefined) { if (typeof obj[el] === 'string') { obj[el] = obj[el].trim(); } } }); } this.value = obj.value; if (obj.text !== undefined) { this.text = obj.text; } if (obj.svalue !== undefined) { this.svalue = obj.svalue; } if (obj.evalue !== undefined) { this.evalue = obj.evalue; } this.$emit('input', obj); }, setPro(value) { this.$refs.myControl.setPro(value); }, setReadOnly(value) { this.$refs.myControl.setReadOnly(value); }, getPro(name) { return this.$refs.myControl.getPro(name); }, getValue() { if (this.config.textName) { let obj = {}; obj.text = this.text; obj.value = this.value; return obj; } else if (this.config.sname) { let obj = {}; obj.svalue = this.svalue; obj.evalue = this.evalue; return obj; } else { return this.value; } }, setValue(value) { this.value = value; }, setText(value) { this.text = value; }, setSvalue(svalue) { this.svalue = svalue; }, setEvalue(evalue) { this.evalue = evalue; }, reset() { this.hackReset = false; this.$nextTick(() => { this.hackReset = true; }); }, setFocus(value) { if (this.$refs.myControl && this.$refs.myControl.setFocus) { this.$refs.myControl.setFocus(value); } }, keyDown(value) { let name = value + 'KeyDown'; if (this[name]) { this[name](); } }, enterKeyDown() { let self= this; let para = {}; para.controlName = self.config.name; if (self.config.sname) { para.controlName = self.config.sname; } para.name = 'enterKeyDown'; self.$emit('doAction', para); }, doAction (obj) { this.$emit('doAction' , obj); }, }, props: { config: { type: Object, default: null, }, valueData: { type: Object, default() { return {}; }, }, autofocus: { type: Boolean, default: false, }, readOnly:{ type:Boolean, default: false, } }, watch: { valueData: { handler(data) { if ( this.config.textName && data[this.config.textName] !== undefined ) { if (this.text !== data[this.config.textName]) { this.text = data[this.config.textName]; } } let flag = false; if ( this.config.sname && data[this.config.sname] !== undefined ) { flag = true; if (this.svalue !== data[this.config.sname]) { this.svalue = data[this.config.sname]; } } if ( this.config.ename && data[this.config.sname] !== undefined ) { if (this.evalue !== data[this.config.ename]) { this.evalue = data[this.config.ename]; } } if (!flag && this.config.name && data[this.config.name] !== undefined) { if (this.value !== data[this.config.name]) { this.value = data[this.config.name]; } } if (this.config.proName) { if (this.$refs.myControl) { this.$refs.myControl.setProValue(data); } } }, deep: true, immediate: true, }, }, };