提交 3944651f 编写于 作者: D DCloud_LXH

chore: button、input-data.vue

上级 20d084de
<script lang="uts"> <script lang="uts">
export default { export default {
name: "input-data", name: "input-data",
props: { props: {
title: { title: {
type: String, type: String,
required: true required: true
}, },
type: { type: {
type: String, type: String,
required: true required: true
}, },
defaultValue: { defaultValue: {
type: String, type: String,
required: true, required: true,
default: '' default: ''
} }
}, },
data() { data() {
return { return {
inputClearValue: '' as any, inputClearValue: '' as any,
showClearIcon: false, showClearIcon: false,
inputType: 'text' inputType: 'text'
} }
}, },
created() { created() {
switch (this.type) { switch (this.type) {
case 'number': case 'number':
this.inputType = 'number' this.inputType = 'number'
break; break;
} }
this.inputClearValue = this.getValue(this.defaultValue) this.inputClearValue = this.getValue(this.defaultValue)
}, },
methods: { methods: {
input: function (event : InputEvent) { input: function (event : InputEvent) {
// @ts-ignore // @ts-ignore
this.inputClearValue = event.detail.value this.inputClearValue = event.detail.value
if ((this.inputClearValue as string).length > 0) { if ((this.inputClearValue as string).length > 0) {
this.showClearIcon = true this.showClearIcon = true
} else { } else {
this.showClearIcon = false this.showClearIcon = false
} }
this.$emit('confirm', this.getValue(this.inputClearValue)) this.$emit('confirm', this.getValue(this.inputClearValue))
}, },
clearIcon: function () { clearIcon: function () {
this.inputClearValue = '' this.inputClearValue = ''
this.showClearIcon = false this.showClearIcon = false
}, this.$emit('confirm', this.getValue(this.inputClearValue))
// @ts-ignore },
confirm(e : InputConfirmEvent) { // @ts-ignore
// this.$emit('confirm', this.getValue(e.detail.value)) confirm(e : InputConfirmEvent) {
}, // this.$emit('confirm', this.getValue(e.detail.value))
blur() { },
this.showClearIcon = false blur() {
}, this.showClearIcon = false
focus() { },
let inputValue = this.inputClearValue focus() {
if (typeof inputValue !== 'string') { let inputValue = this.inputClearValue
inputValue = inputValue.toString() if (typeof inputValue !== 'string') {
} inputValue = inputValue.toString()
if ((inputValue as string).length > 0) { }
this.showClearIcon = true if ((inputValue as string).length > 0) {
} else { this.showClearIcon = true
this.showClearIcon = false } else {
} this.showClearIcon = false
}, }
getValue(value : any) : any { },
switch (this.type) { getValue(value : any) : any {
case 'number': switch (this.type) {
return parseFloat(value as string) case 'number':
} return parseFloat(value as string)
}
return value return value
} }
} }
} }
</script> </script>
<template> <template>
<view class="uni-padding-wrap"> <view class="uni-padding-wrap">
<view class="uni-title uni-common-mt"> <view class="uni-title uni-common-mt">
<text class="uni-title-text"> {{title}} </text> <text class="uni-title-text"> {{title}} </text>
</view> </view>
</view> </view>
<view class="uni-input-wrapper input-wrapper"> <view class="uni-input-wrapper input-wrapper">
<input class="uni-input" :type="inputType" :value="inputClearValue" :placeholder="title" @input="input" <input class="uni-input" :type="inputType" :value="inputClearValue" :placeholder="title" @input="input"
@confirm="confirm" @blur="blur" @focus="focus"/> @confirm="confirm" @blur="blur" @focus="focus" />
<image class="input-wrapper_image" src="/static/icons/clear.png" v-if="showClearIcon" @click="clearIcon"> <image class="input-wrapper_image" src="/static/icons/clear.png" v-if="showClearIcon" @click="clearIcon">
</image> </image>
</view> </view>
</template> </template>
<style> <style>
.input-wrapper { .uni-input-wrapper {
border: 1px solid rgba(0, 0, 0, .08); padding: 8px 13px;
justify-content: center; margin: 10rpx 0;
padding: 0; flex-direction: row;
margin: 0 20rpx; flex-wrap: nowrap;
background-color: #FFF; background-color: #ffffff;
} }
.input-wrapper_image { .input-wrapper {
width: 22px; border: 1px solid rgba(0, 0, 0, .08);
height: 22px; flex-direction: row;
align-self: center; justify-content: center;
margin-right: 10rpx; padding: 0;
} margin: 0 20rpx;
}
.input-wrapper_image {
width: 22px;
height: 22px;
align-self: center;
margin-right: 10rpx;
}
</style> </style>
...@@ -37,18 +37,18 @@ ...@@ -37,18 +37,18 @@
</script> </script>
<template> <template>
<view class="main">
<button :disabled="disabled_boolean" :size="size_enum[size_enum_current].name"
:type="type_enum[type_enum_current].name" :plain="plain_boolean" @click="button_click"
@touchstart="button_touchstart" @touchmove="button_touchmove" @touchcancel="button_touchcancel"
@touchend="button_touchend" @tap="button_tap" @longpress="button_longpress" class="btn"
:style="default_style ? style : ''" :hover-class="default_style ? 'is-hover' : 'button-hover'">
{{ text }}
</button>
</view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
<scroll-view style="flex: 1"> <scroll-view style="flex: 1">
<!-- #endif --> <!-- #endif -->
<view class="main">
<button :disabled="disabled_boolean" :size="size_enum[size_enum_current].name"
:type="type_enum[type_enum_current].name" :plain="plain_boolean" @click="button_click"
@touchstart="button_touchstart" @touchmove="button_touchmove" @touchcancel="button_touchcancel"
@touchend="button_touchend" @tap="button_tap" @longpress="button_longpress" class="btn"
:style="default_style ? style : ''" :hover-class="default_style ? 'is-hover' : 'button-hover'">
{{ text }}
</button>
</view>
<view class="content"> <view class="content">
<boolean-data :defaultValue="false" title="按钮是否镂空,背景色透明" @change="change_plain_boolean"></boolean-data> <boolean-data :defaultValue="false" title="按钮是否镂空,背景色透明" @change="change_plain_boolean"></boolean-data>
<boolean-data :defaultValue="false" title="是否禁用" @change="change_disabled_boolean"></boolean-data> <boolean-data :defaultValue="false" title="是否禁用" @change="change_disabled_boolean"></boolean-data>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册