123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- <template>
- <view class="d-block tm-input overflow"
- :class="[
-
- black_tmeme?(bgTheme?'grey-darken-5':''):bgTheme,
- flat?'':`px-${padding[0]}`,
- 'round-'+ bgRound,
- `shadow-${color}-${bgShadow}`
- ]"
- >
- <view
- :class="(flat?'':` py-${padding[1]} `)+` ${borderBottom?black_tmeme?'border-grey-darken-4-b-1 ':'border-grey-lighten-4-b-1':''}`"
- >
- <view @click="onclickInput" :class="[vertical?'tm-input-col':'flex-between ']" :style="{
- width: '100%',height: 'auto',
- alignItems:inputType=='textarea'?'flex-start':'center'
- }">
-
- <view v-if="leftIcon||title" class="tm-input-left flex-start flex-shrink" :class="[vertical?'pb-24':'']">
-
- <view v-if="leftIcon" class="pr-16 vertical-align-middle flex-center">
- <tm-icons dense :name="leftIcon" :color="color_tmeme"></tm-icons>
- </view>
-
- <view v-if="title" class="d-inline-block "
- :style="{fontSize:title_size}"
- :class="[titleClass,black_tmeme?'bk text-grey-lighten-3':'']">
- <text v-if="required" class="text-red">*</text>
- <slot name="default" :title="title">
- {{title}}
- </slot>
- </view>
- </view>
- <view class="flex-between " :class="[disabled?'opacity-6':'',]" style="width: 100%;">
-
- <view class="tm-input-center relative fulled" >
- <view class="flex-start tm-input-center-wk"
- :class="['round-'+round,showIndent?'px-16':'',
- black_tmeme?(bgColor?'grey-darken-4 text-grey-lighten-3':'text-grey-lighten-3'):bgColor,
- `text-${textColor}`,isFocus&&focusShow?(black_tmeme?`border-${color_tmeme}-a-1`:`${color_tmeme} outlined `):``,
- `border-${black_tmeme?(borderColor?'grey-darken-4':''):borderColor}-a-1`,
-
- ]">
- <view class="flex-shrink px-16 flex-center" v-if="prefixpIcon" style="line-height: 0;">
- <tm-icons dense :name="prefixpIcon" :size="28" :color="(prefixpIconColor||color_tmeme)" ></tm-icons>
- </view>
- <view :style="{fontSize:font_size}" class="flex-shrink pr-24" :class="[titleClass,black_tmeme?'bk text-grey-lighten-3':'']" v-if="prefixpText">
- {{prefixpText}}
- </view>
-
-
- <input always-embed v-if="inputType!='textarea'" @confirm="$emit('confirm',$event)" @input="input"
- @keyboardheightchange="$emit('keyboardheightchange',$event)" @blur="blur"
- @focus="focusFun" :focus="focus_fs" :maxlength="maxlength" :adjust-position="adjustPosition"
- :auto-focus="autoFocus" :confirm-type="confirmType" :disabled="disabled"
- :password="password" :type="inputType" :value="value" class="tm-input-center-input "
- :class="['text-align-'+align,showError?'text-red':'',' py-5 ']" :placeholder="placeholder"
- :placeholder-class="black_tmeme? 'text-grey-darken-1 ':' ' +` text-size-n ` + placeholderClass"
- :style="{
- fontSize:font_size,
- height:height_rpx+'rpx'
- }"
- />
-
- <view v-if="disabled" class="absolute fulled t-0 r-0" :style="{
- height:height_rpx+'rpx'
- }"></view>
-
- <textarea always-embed v-if="inputType=='textarea'" @confirm="$emit('confirm',$event)" @input="input"
- @keyboardheightchange="$emit('keyboardheightchange',$event)" @blur="blur"
- @focus="focusFun" :focus="focus_fs" :maxlength="maxlength" :adjust-position="adjustPosition"
- :auto-focus="autoFocus" :confirm-type="confirmType" :disabled="disabled"
- :value="value" class="tm-input-center-input " :style="{
- height:height_rpx+'rpx',
- fontSize:font_size,
- }"
- :class="[maxlength>0?'pb-46':'','text-align-'+align,showError?'text-red':'','pt-16 fulled']" :placeholder="placeholder"
- :placeholder-class="black_tmeme? 'text-grey-darken-1 ':' text-grey-lighten-1 ' +` text-size-n `+ placeholderClass" >
- </textarea>
-
- <view v-if="clear&&valdata.length!=''" class="flex-center pl-16">
- <tm-icons @click.stop="clearVal" name="icon-times-circle-fill" :color="color_tmeme"></tm-icons>
- </view>
-
- <view v-if="suffixIcon" class="flex-center">
- <tm-icons :size="26" :name="suffixIcon" :color="(suffixIconColor||color_tmeme)"></tm-icons>
- </view>
- </view>
- <view v-if="maxlength>0&&inputType=='textarea'"
- :style="{bottom:'16rpx',right:'16rpx'}"
- class="tm-input-center-numXz text-align-right text-size-xxs pt-12 text-grey absolute fulled">{{valueLen}}/{{maxlength}}</view>
- </view>
-
- <view class="tm-input-right flex-end flex-shrink">
-
- <text v-if="suffix" class=" text-grey-darken-4 pl-10" :style="{fontSize:font_size}">{{suffix}}</text>
-
- <view v-if="rightIcon" class="pl-10" style="line-height: 0;">
- <tm-icons dense :name="rightIcon" color="grey-lighten-1"></tm-icons>
- </view>
-
- <slot name="rightBtn"></slot>
- </view>
- </view>
- </view>
-
- <view v-if="showError" class="text-size-xs text-red pt-12">{{errorText}}</view>
- </view>
- </view>
- </template>
- <script>
-
- import tmSheet from "@/tm-vuetify/components/tm-sheet/tm-sheet.vue"
- import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
- export default {
- components:{tmSheet,tmIcons},
- name:"tm-input",
- props: {
-
- name:{
- type:String,
- default:''
- },
- prefixpText:{
- type:String,
- default:''
- },
- flat: {
- type: Boolean,
- default: false
- },
-
- showIndent:{
- type:Boolean,
- default:true
- },
- maxlength: {
- type: Number,
- default: -1
- },
- black: {
- type:Boolean|String,
- default:null
- },
-
- focusShow: {
- type:Boolean|String,
- default:false
- },
- titleFontSize:{
- type:String,
- default:'n',
- },
- height:{
- type:Number|String,
- default:68
- },
-
- verify: {
- type: Function,
- default: ()=>{
- return (val) => {
- return {
- check: val?.length <= 0 ? false : true,
- text: "必填项不能为空。"
- };
- }
- }
- },
- titleClass: {
- type: String,
- default: 'text-grey-darken-4'
- },
-
- required: Boolean,
- adjustPosition: Boolean,
- autoFocus: Boolean,
- confirmType: String,
- disabled: Boolean,
- password: Boolean,
- inputType: {
- type: String,
- default: 'text'
- },
- value: {
- type: String|Number,
- default: ''
- },
-
- rightIcon: {
- type: String,
- default: ''
- },
-
- prefixpIcon: {
- type: String,
- default: ''
- },
- prefixpIconColor: {
- type: String,
- default: ''
- },
-
- leftIcon: {
- type: String,
- default: ''
- },
-
- suffix: {
- type: String,
- default: ''
- },
-
- suffixIcon: {
- type: String,
- default: ''
- },
- suffixIconColor:{
- type: String,
- default: ''
- },
-
- title: {
- type: String,
- default: ''
- },
- fontSize:{
- type:Number|String,
- default:'n'
- },
-
- align: {
- type: String,
- default: 'left'
- },
-
- clear: Boolean,
-
- color: {
- type: String,
- default: 'primary'
- },
-
- bgColor: {
- type: String,
- default: ''
- },
-
- borderColor: {
- type: String,
- default: ''
- },
-
- borderBottom: {
- type: Boolean,
- default: true
- },
-
- textColor: {
- type: String,
- default: 'black'
- },
- placeholder: {
- type: String,
- default: "请输入"
- },
- placeholderClass:{
- type:String,
- default:'text-grey-lighten-1'
- },
-
- vertical: Boolean,
- round:{
- type:Number|String,
- default:2
- },
- bgRound:{
- type:Number|String,
- default:0
- },
- bgShadow:{
- type:Number|String,
- default:0
- },
- bgTheme:{
- type:String,
- default:'white'
- },
-
- focus:{
- type:Boolean,
- default:false
- },
- padding:{
- type:Array,
- default:()=>{
- return [32,12];
- }
- },
-
- fllowTheme:{
- type:Boolean|String,
- default:true
- }
- },
- data() {
- return {
- showError: false,
- errorText: "请正确填写",
- FOCUS_Auto:false,
- isFocus:false,
- };
- },
- computed: {
- height_rpx:function(){
- return this.height;
- },
- font_size:function () {
-
- let font = {
- 'xxs':'20rpx',
- 'xs':'22rpx',
- 's':'24rpx',
- 'm':'26rpx',
- 'n':'28rpx',
- 'g':'32rpx',
- 'lg':'36rpx',
- 'xl':'40rpx'
- }
- if(typeof this.fontSize=='string') return font[this.fontSize];
- return this.fontSize+'rpx';
- },
- title_size:function () {
- let font = {
- 'xxs':'20rpx',
- 'xs':'22rpx',
- 's':'24rpx',
- 'm':'26rpx',
- 'n':'28rpx',
- 'g':'32rpx',
- 'lg':'36rpx',
- 'xl':'40rpx'
- }
- if(typeof this.titleFontSize=='string') return font[this.titleFontSize];
- return this.titleFontSize+'rpx';
- },
- focus_fs:{
- get:function(){
- return this.FOCUS_Auto;
- },
- set:function(val){
- this.FOCUS_Auto = val;
- }
- },
- black_tmeme: function() {
- if (this.black !== null) return this.black;
- return this.$tm.vx.state().tmVuetify.black;
- },
- color_tmeme:function(){
- if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
- return this.$tm.vx.state().tmVuetify.color;
- }
- return this.color;
- },
- valueLen:function(){
-
- let p = String(this.valdata);
- return p?.split('').length||0 ;
- },
- valdata:{
- get:function(){
- return this.value;
- },
- set:function(val){
- this.$emit('input', val)
- this.$emit('update:value', val)
- if (this.required) {
- this.$nextTick(function(){
- this.verifyInput();
- })
- }
- }
- }
- },
- mounten(){
- this.FOCUS_Auto = this.focus;
- },
- methods: {
- onclickInput(e){
- this.$emit('click',e)
- },
- input(e) {
- this.valdata = e.target.value;
- },
-
- verifyInput() {
-
- let verify = this.verify.bind(this, this.valdata||'');
- verify = verify.call(this,this.valdata||'')
- if(typeof verify ==='function'){
- verify = verify.call(this,this.valdata||'')
- }
-
- if (typeof verify !== 'object') verify = {};
- this.showError = !(verify.check??true);
- this.errorText = verify.text??"";
- return verify.check??true;
- },
-
- clearVerify() {
- this.showError = false;
- this.errorText = "";
- },
- blur(e) {
- this.isFocus=false;
- this.$emit('blur', e)
- },
- focusFun(e){
- this.isFocus=true;
- this.$emit('focus',e)
- },
- clearVal(e){
- this.valdata ="";
- this.$emit('clear', this.valdata)
- }
- },
- }
- </script>
- <style lang="scss" scoped>
- .tm-input {
- .tm-input-center {
- width: 100%;
- .tm-input-center-wk{
- transition: all 0.2s;
- }
- .tm-input-center-input {
- border: none;
- background: none;
- box-shadow: 0;
- width: 100%;
-
- }
- }
- .tm-input-left {
- flex-shrink: 0;
- height: 100%;
-
- min-width: 80rpx;
- padding-right: 24rpx;
- }
- .tm-input-col {
- .tm-input-left {
- max-width: inherit;
- padding-right: 0;
- }
- .tm-input-center {
- .tm-input-center-input {
- height: 76upx;
- }
- }
- }
- .tm-input-right {
- height: 100%;
- // width: 300upx;
- }
- }
- </style>
|