Files
GX.O3.WMS/APK/APP_O3/components/opsoft-input-verification/opsoft-input-verification.vue
T

320 lines
8.5 KiB
Vue
Executable File

<template>
<view class="opsoft-input" :class="borderClass" :style="inputStyle">
<view class="opsoft-input-row">
<view v-show="search" class="opsoft-search-icon" :style="searchIconStyle?searchIconStyle:defaultIconStyle" @tap="searchClick()" />
<input class="opsoft-uniinput" :value="modelValue" :type="inputType" :maxlength="maxlength"
@focus="inputFocus" @blur="inputBlur" @confirm="inputConfirm" @keyboardheightchange="keyboardHeightChange"
@input="inputListener" :hold-keyboard="true" :adjust-position="true" :auto-blur="true"
:confirm-hold="false" :cursor="cursorLength" :confirm-type="confirmText" :disabled="disableInput"
:placeholder="promptText" :placeholder-style="promptTextClass"/>
<view v-if="clear" class="opsoft-clear-icon" @tap="clearClick()"
:style="clearIconStyle?clearIconStyle:defaultIconStyle"/>
<view v-if="eye" :class="passwordShow?'opsoft-eye-icon':'opsoft-eye-close-icon'"
@tap="eyeClick()" :style="eyeIconStyle?eyeIconStyle:defaultIconStyle" />
</view>
<view v-show="errorText && errorText.length > 0 && errorAble" class="opsoft-verification-error">
{{errorText}}
</view>
</view>
</template>
<script>
export default {
name:"opsoft-input-verification",
props:{
promptTextClass: {type:String, default:""},
disable: {type:Boolean, default:false},
search: {type:Boolean, default:false},
clear: {type:Boolean, default:false},
eye: {type:Boolean, default:false},
password: {type:Boolean, default:false},
type: {type:String, default:"text"},
maxlength: {type:Number, default:-1},
readOnly: {type:Boolean, default:false},
confirmText: {type:String, default:"确定"},
modelValue: {type:String, required:true, default:""},
promptText: {type:String, default:""},
errorText: {type:String, default:""},
defaultBorderStyle: {type:Object, default:null},
errorBoderStyle: {type:Object, default:null},
focusBoderStyle: {type:Object, default:null},
disableBoderStyle: {type:Object, default:null},
readOnlyBoderStyle: {type:Object, default:null},
defaultIconStyle: {type:Object, default:null},
searchIconStyle: {type:Object, default:null},
eyeIconStyle: {type:Object, default:null},
clearIconStyle: {type:Object, default:null},
height: {type:String, default:""},
inputValidation: {type:Boolean, default:false},
},
data() {
return {
errorAble: false,
focusAble: false,
cursorLength: 0,
logicInputType: "password",
eyeClose: false,
}
},
computed: {
inputType:{
get:function() {
if (this.type == "password") {
return this.logicInputType;
}
if (this.type) {
return this.type;
}
return 'text';
},
},
disableInput:{
get:function() {
if (this.readOnly||this.disable) {
return true;
}
return false;
}
},
borderClass:{
get:function() {
if (this.readOnly) {
return "opsoft-input-readonly";
}
if (this.disable) {
return "opsoft-input-disable";
}
if (this.errorAble) {
return "opsoft-input-error";
}
if (this.focusAble) {
return "opsoft-input-focus";
}
return "opsoft-input-default";
}
},
inputStyle:{
get:function() {
let style = this.defaultBorderStyle;
if (this.readOnly && this.readOnlyBoderStyle) {
style = this.readOnlyBoderStyle;
}
if ( this.disable && this.disableBoderStyle) {
style = this.disableBoderStyle;
}
if (this.errorAble && this.errorBoderStyle) {
style = this.errorBoderStyle;
}
if (this.focusAble && this.focusBoderStyle) {
style = this.focusBoderStyle;
}
if ( this.height && this.height.length>0) {
style.height = this.height;
style.lineHeight = this.height;
}
return style;
}
},
passwordShow: {
get:function() {
if (this.eye && !this.eyeClose) {
return true;
}
return false;
}
},
passwordShow: {
get:function() {
if (this.eye && !this.eyeClose) {
return true;
}
return false;
}
},
},
onLoad() {
if (this.modelValue && this.modelValue.length > 0) {
this.cursorLength = this.modelValue.length;
}
},
methods: {
inputListener: function(event) {
let value = event.detail.value;
if (this.maxlenght >= 0) {
value = value.substr(0, this.maxlenght);
}
this.this.$emit('update:modelValue', value.toString());
this.this.$emit('inputChange', event);
},
verification: function(value){
this.$emit("inspectionFunction", value, val => {
this.errorAble = val;
});
},
inputListener: function(event) {
let value = event.detail.value;
if (this.maxlenght >= 0) {
value = value.substr(0, this.maxlenght);
}
this.$emit('update:modelValue', value.toString());
this.$emit('inputChange', event);
if (this.inputValidation) {
this.verification(value);
}
},
//聚焦
inputFocus: function(event) {
this.focusAble = true;
this.$emit('focusChange', event);
},
//失去焦点
inputBlur: function(event) {
this.focusAble = false;
this.$emit('blurChange', event);
const value = event.detail.value;
this.verification(value);
},
//回车事件
inputConfirm: function(event) {
const value = event.detail.value;
this.$emit("update:modelValue", value.toString());
this.$emit('confirmClick', event);
this.verification(value);
},
//键盘高度变化事件
keyboardHeightChange: function(event) {
this.$emit('keyboardHeightChange', event);
},
//清除输入信息
clearClick: function() {
this.$emit("update:modelValue", "");
this.$emit("clear");
this.$emit('inputChange', "");
},
//显示密码
eyeClick: function() {
this.eyeClose = !this.eyeClose;
if (this.eyeClose) {
this.logicInputType = "text";
}
else {
this.logicInputType = "password";
}
},
searchClick: function() {
this.$emit("searchClick", this.modelValue);
}
}
}
</script>
<style scoped>
.opsoft-input {
display: flex;
flex-direction: column;
color: rgba(0, 0, 0, 1);
font-size: 32rpx;
caret-color: rgba(0, 122, 255, 1);
padding-top: 20rpx;
padding-bottom: 20rpx;
--input-height: 48rpx;
}
.opsoft-input >.opsoft-verification-error{
height: 42rpx;
color: rgba(255, 82, 87, 1);
font-size: 28rpx;
overflow: hidden;
}
.opsoft-input-default {
}
.opsoft-input-focus {
}
.opsoft-input-error {
}
.opsoft-input-disable {
color: rgba(133, 139, 156, 1);
}
.opsoft-input-readonly {
}
.opsoft-input >.opsoft-input-row{
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
line-height: var(--input-height);
height: var(--input-height);
}
.opsoft-input-row >.opsoft-uniinput{
width: 100%;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.opsoft-input >.opsoft-input-row >.opsoft-clear-icon{
height: 32rpx;
width: 32rpx;
/* flex-shrink: 0;
flex-grow: 0; */
background-size: 28rpx 28rpx;
background-image: url(static/clear.svg);
background-repeat: no-repeat;
background-position:center center;
}
.opsoft-input >.opsoft-input-row >.opsoft-eye-close-icon{
height: 32rpx;
width: 32rpx;
flex-shrink: 0;
flex-grow: 0;
background-size: 28rpx 28rpx;
background-image: url(./static/eye-close.png);
background-repeat: no-repeat;
background-position:center center;
}
.opsoft-input >.opsoft-input-row >.opsoft-eye-icon{
height: 32rpx;
width: 32rpx;
flex-shrink: 0;
flex-grow: 0;
background-size: 28rpx 28rpx;
background-image: url(./static/eye.png);
background-repeat: no-repeat;
background-position:center center;
}
.opsoft-input >.opsoft-input-row >.opsoft-search-icon{
height: 32rpx;
width: 32rpx;
flex-shrink: 0;
flex-grow: 0;
background-size: 28rpx 28rpx;
background-image: url(./static/search.png);
background-repeat: no-repeat;
background-position:center center;
}
>>>.opsoft-input-row .uni-input-placeholder {
color: rgba(153, 153, 153, 0.9);
font-size: 32rpx;
line-height: var(--input-height);
height: var(--input-height);
}
.opsoft-input-row>>> .uni-input-input {
line-height: var(--input-height);
height: var(--input-height);
}
.opsoft-input-row>>> .opsoft-uniinput {
line-height: var(--input-height);
height: var(--input-height);
}
</style>