emis-app/components/tpx-input/tpx-input.vue
2024-05-27 11:01:17 +08:00

109 lines
1.8 KiB
Vue

<template>
<u-input shape="circle" :placeholder="placeholder" :modelValue="value" :clearable="clearable"
:custom-style="inputStyle" :readonly="readonly" :type="type" :inputAlign="inputAlign"
:placeholder-style="`color: #999;${placeholderStyle};` " @change="handleChange"
:formatter="formatter"
>
<template v-if="suffix" #suffix>
<text class="font-26 clr-sub pl-10">{{suffix}}</text>
</template>
</u-input>
</template>
<script>
export default {
computed: {
inputStyle(){
let sty1 = 'border:0;border-radius: 10rpx;background-color: #F6F6F6;padding: 11rpx 20rpx;'
this.isWhite && (sty1 += 'background-color: #fff;border: 1rpx solid #dadbde;')
return `${sty1};${this.customStyle};`
}
},
props: {
isWhite: {
default () {
return false
}
},
suffix: {
default () {
return ''
}
},
clearable: {
default () {
return false
}
},
type: {
default () {
return ''
}
},
readonly: {
default () {
return false
}
},
value: {
default () {
return ''
}
},
placeholder:{
default () {
return ''
}
},
_digit:{ // 保留小数位
},
customStyle:{
default () {
return ''
}
},
placeholderStyle:{
default () {
return ''
}
},
inputAlign:{
default () {
return ''
}
},
},
data() {
return {
}
},
created() {
},
onHide() {
},
unmounted() {},
methods: {
handleChange(val){
this.$emit('change', val)
this.$emit('update:value', val)
},
formatter(val) {
if(this._digit) {
let reg = new RegExp(`^\\d*(\\.?\\d{0,${this._digit}})`, 'g')
let newVal = val.match(reg)[0]
return newVal
}
return val
}
}
}
</script>
<style scoped lang="scss">
</style>