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

253 lines
6.7 KiB
Vue
Executable File

<template>
<view class="opsoft-input-row" :class="borderClass" :style="inputStyle">
<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.stop="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>
</template>
<script>
let _self;
export default {
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:""},
defaultBorderStyle: {type:Object, default:null},
focusBoderStyle: {type:Object, default:null},
disableBoderStyle: {type:Object, default:null},
readOnlyBoderStyle: {type:Object, default:null},
defaultIconStyle: {type:Object, default:()=>{return {}}},
searchIconStyle: {type:Object, default:null},
eyeIconStyle: {type:Object, default:null},
clearIconStyle: {type:Object, default:null},
height: {type:String, default:""},
},
data() {
return {
focusAble: false,
cursorLength: 0,
eyeClose: false,
logicInputType: "password",
placeholderStyle: "",
}
},
computed: {
inputType(){
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(){
if (this.readOnly) {
return "opsoft-input-readonly";
}
if (this.disable) {
return "opsoft-input-disable";
}
if (this.focusAble) {
return "opsoft-input-focus";
}
return "opsoft-input-default";
}
},
inputStyle:{
get(){
let style = this.defaultBorderStyle;
if (this.readOnly && this.readOnlyBoderStyle) {
style = this.readOnlyBoderStyle;
}
if (this.disable && this.disableBoderStyle) {
style = this.disableBoderStyle;
}
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(){
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.$emit('update:modelValue', value.toString());
this.$emit('inputChange', event);
},
//聚焦
inputFocus: function(event) {
this.focusAble = true;
this.$emit('focusChange', event);
},
//失去焦点
inputBlur: function(event) {
this.focusAble = false;
this.$emit('blurChange', event);
},
//回车事件
inputConfirm: function(event) {
const value = event.detail.value;
this.$emit("update:modelValue", value.toString());
this.$emit('confirmClick', event);
},
//键盘高度变化事件
keyboardHeightChange: function(event) {
this.$emit('keyboardHeightChange', event);
},
//清除输入信息
clearClick: function() {
this.$emit("update:modelValue", "");
this.$emit("clearClick");
},
//显示密码
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 lang="scss">
.opsoft-input-default {
}
.opsoft-input-focus {
}
.opsoft-input-disable {
color: rgba(133, 139, 156, 1);
}
.opsoft-input-readonly {
}
.opsoft-input-row {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
color: rgba(0, 0, 0, 1);
font-size: 32rpx;
caret-color: rgba(0, 122, 255, 1);
padding-top: 20rpx;
padding-bottom: 20rpx;
height: 48rpx;
line-height: 48rpx;
--input-height: 48rpx;
.opsoft-uniinput{
width: 100%;
}
.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-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-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-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;
}
::v-deep.uni-input-placeholder {
color: rgba(153, 153, 153, 0.9);
font-size: 32rpx;
line-height: var(--input-height);
height: var(--input-height);
}
::v-deep.uni-input-input {
line-height: var(--input-height);
height: var(--input-height);
}
::v-deep.opsoft-uniinput {
line-height: var(--input-height);
height: var(--input-height);
}
}
</style>