emis-app/components/tpx-input/tpx-input.vue

153 lines
2.8 KiB
Vue
Raw Normal View History

2023-12-18 16:30:33 +00:00
<template>
2024-01-31 06:45:51 +00:00
<u-input shape="circle" :placeholder="placeholder" :modelValue="value" :clearable="clearable"
2024-05-23 05:38:13 +00:00
:custom-style="inputStyle" :readonly="readonly" :type="type" :inputAlign="inputAlign"
2024-01-31 06:45:51 +00:00
:placeholder-style="`color: #999;${placeholderStyle};` " @change="handleChange"
2024-06-11 07:22:26 +00:00
@blur="handleFocus" @focus="handleBlur"
2024-06-11 09:31:02 +00:00
:formatter="formatter" :disabled="disabled" :focus="autoFocus"
2024-01-31 06:45:51 +00:00
>
2024-12-08 03:19:10 +00:00
<template v-if="suffix || $slots.suffix" #suffix>
<text v-if="suffix" class="font-26 clr-sub pl-10">{{suffix}}</text>
<slot v-if="$slots.suffix" name="suffix"></slot>
2024-01-31 06:45:51 +00:00
</template>
</u-input>
2023-12-18 16:30:33 +00:00
</template>
<script>
export default {
2024-01-31 06:45:51 +00:00
computed: {
inputStyle(){
2024-06-02 10:16:18 +00:00
let bgColor = '#F6F6F6'
let sty1 = 'border:0;border-radius: 10rpx;padding: 11rpx 20rpx;'
2024-06-10 17:07:56 +00:00
// if(this.isWhite) {
// bgColor = '#fff'
2024-07-07 08:14:01 +00:00
// sty1 += 'border: 2rpx solid #dadbde;'
2024-06-10 17:07:56 +00:00
// }
if(true) {
2024-06-02 10:16:18 +00:00
bgColor = '#fff'
2024-07-07 08:14:01 +00:00
sty1 += 'border: 2rpx solid #dadbde;'
2024-06-02 10:16:18 +00:00
}
if(!this.disabled) {
sty1 += `background-color:${bgColor};`
}
2024-01-31 06:45:51 +00:00
return `${sty1};${this.customStyle};`
}
},
2023-12-18 16:30:33 +00:00
props: {
2024-01-31 06:45:51 +00:00
isWhite: {
default () {
return false
}
},
suffix: {
default () {
return ''
}
},
clearable: {
default () {
return false
}
},
2024-05-03 17:17:45 +00:00
type: {
default () {
return ''
}
},
2024-03-04 11:09:51 +00:00
readonly: {
default () {
return false
}
},
2023-12-18 16:30:33 +00:00
value: {
default () {
return ''
}
},
2024-05-28 04:32:43 +00:00
disabled:{
default () {
return false
}
},
2023-12-18 16:30:33 +00:00
placeholder:{
default () {
return ''
}
},
2024-05-27 03:01:17 +00:00
_digit:{ // 保留小数位
},
2024-06-02 08:37:54 +00:00
_maxNum:{ // 最大数值
},
2023-12-18 16:30:33 +00:00
customStyle:{
default () {
return ''
}
},
placeholderStyle:{
default () {
return ''
}
},
2024-05-23 05:38:13 +00:00
inputAlign:{
default () {
return ''
}
},
2024-06-11 09:31:02 +00:00
autoFocus: {
default () {
return false
}
},
2023-12-18 16:30:33 +00:00
},
data() {
2023-12-30 15:28:01 +00:00
return {
}
2023-12-18 16:30:33 +00:00
},
created() {
},
onHide() {
},
2024-01-30 03:09:14 +00:00
unmounted() {},
2023-12-18 16:30:33 +00:00
methods: {
2024-06-11 07:22:26 +00:00
handleFocus(){
this.$emit('focus')
},
handleBlur(){
this.$emit('blur')
},
2023-12-18 16:30:33 +00:00
handleChange(val){
this.$emit('change', val)
this.$emit('update:value', val)
2024-05-27 03:01:17 +00:00
},
formatter(val) {
2024-06-02 08:37:54 +00:00
let newVal = val
2024-12-12 17:13:49 +00:00
if((this.type == 'number' || this._digit || this._maxNum) && (typeof val == 'string' && val)) {
newVal = Number(val) // 需要格式化输入框的格式
// 判断是否输入了数字
if(!isNaN(newVal)) {
if(this._digit) {
let reg = new RegExp(`^\\d*(\\.?\\d{0,${this._digit}})`, 'g')
newVal = val.match(reg)[0]
}
if(typeof this._maxNum != 'undefined') {
if(newVal > Number(this._maxNum)) {
newVal = this._maxNum
}
}
} else {
newVal = ''
2024-06-02 08:37:54 +00:00
}
2024-05-27 03:01:17 +00:00
}
2024-06-02 08:37:54 +00:00
return newVal
2023-12-18 16:30:33 +00:00
}
}
}
</script>
<style scoped lang="scss">
</style>