123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <template>
- <el-input v-if="attrs.type == 'textarea'" :type="attrs.type" v-model="value" @input="onChange" :rows="attrs.rows" :show-word-limit="attrs.showWordLimit" :show-password="attrs.showPassword" :placeholder="placeholder"
- :maxlength="attrs.maxlength" :minlength="attrs.minlength" :clearable="attrs.clearable" :disabled="disabledValue" :prefix-icon="attrs.prefixIcon"
- :suffix-icon="attrs.suffixIcon" :readonly="attrs.readonly" :autosize="attrs.autosize"></el-input>
- <vxe-input
- v-else
- ref="input"
- v-model="value"
- :placeholder="placeholder"
- :maxlength="attrs.maxlength"
- :minlength="attrs.minlength"
- :clearable="attrs.clearable"
- :disabled="disabledValue"
- :size="attrs.size?attrs.size:'medium'"
- :type="attrs.type"
- :min="attrs.min"
- :max="attrs.max"
- :step="attrs.step"
- :align="attrs.align"
- :prefix-icon="attrs.prefixIcon"
- :suffix-icon="attrs.suffixIcon"
- :readonly="attrs.readonly"
- @input="onChange"
- @clear="onChange"
- ></vxe-input>
- </template>
- <script lang="ts">
- /*
- config:{
- attr:{
- type:'text, number(数字), integer(整数),textarea,float(小数),password(密码),positiveNumber(正数),positiveInteger(正整数)',
- align:'left, center, right'
- min:0 //最小值
- max:'' //最大值
- step:'' //间隔
- onceEdit: true/false //只能编辑一次
- prefixIcon:'' //头部图标
- suffixIcon:'' //尾部图标
- }
- }
- */
- import { Component, Prop, Vue, Watch } from "vue-property-decorator";
- import VueViews from '@/benyun/compVue/VueViews'
- @Component
- export default class ByInput extends VueViews {
- value:any=null;
- @Watch('propValue')
- propValueChange(v:any){
- this.setValue(v);
- }
- created(){
- if(this.propConfig){
- this.setConfig(this.propConfig)
- }
- if(this.propValue){
- this.setValue(this.propValue)
- }
- if((this.attrs.defaultValue || this.attrs.defaultValue === 0) && !this.value){
- this.setValue(this.attrs.defaultValue);
- this.onChange();
- }
- }
- get disabledValue(){
- let n = false;
- if(this.attrs.disabled){
- n = true
- }
- if(this.attrs.onceEdit && this.parentValue && this.parentValue.id){
- return n = true
- }
- return n;
- }
- get placeholder(){
- if(this.disabledValue){
- return ''
- }
- if(this.attrs.placeholder){
- return this.attrs.placeholder
- }
- return ''
- }
- mounted(){
- }
- setValue(data:any){
- if(data || data === 0){
- this.value = (this as any).$lodash.cloneDeep(data);
- if(this.attrs.type == 'number'){
- if(data !== '-') {
- this.value = Number(data);
- }
-
- }
- }else{
- this.value = null;
- }
- }
- getValue(){
- return (this as any).$lodash.cloneDeep(this.value);
- }
- // 清空数据
- clearValue(){
- this.value = '';
- if((this.attrs.defaultValue || this.attrs.defaultValue === 0) && !this.value){
- this.setValue(this.attrs.defaultValue);
- this.onChange();
- }
- }
- onChange(){
- this.$emit('onChange',this.value);
-
- }
- }
- </script>
- <style lang="scss" scoped>
- </style>
- <style lang="scss">
- .el-input--small{
- font-size: 14px !important;
- }
- .vxe-input--inner[disabled]{
- background-color: #F5F7FA;
- border-color: #dfe4ed;
- color: #C0C4CC;
- cursor: not-allowed;
- }
- </style>
|