uview-pro 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +584 -574
- package/components/common/props.ts +22 -22
- package/components/u-action-sheet/types.ts +37 -37
- package/components/u-action-sheet/u-action-sheet.vue +178 -178
- package/components/u-alert-tips/types.ts +41 -41
- package/components/u-alert-tips/u-alert-tips.vue +238 -238
- package/components/u-avatar/types.ts +36 -36
- package/components/u-avatar/u-avatar.vue +217 -217
- package/components/u-avatar-cropper/types.ts +23 -23
- package/components/u-avatar-cropper/u-avatar-cropper.vue +297 -297
- package/components/u-avatar-cropper/weCropper.d.ts +62 -62
- package/components/u-avatar-cropper/weCropper.js +1281 -1281
- package/components/u-avatar-cropper/weCropper.ts +1276 -1276
- package/components/u-back-top/types.ts +36 -36
- package/components/u-back-top/u-back-top.vue +140 -140
- package/components/u-badge/types.ts +38 -38
- package/components/u-badge/u-badge.vue +183 -183
- package/components/u-button/types.ts +66 -66
- package/components/u-button/u-button.vue +579 -579
- package/components/u-calendar/types.ts +75 -75
- package/components/u-calendar/u-calendar.vue +793 -793
- package/components/u-car-keyboard/types.ts +14 -14
- package/components/u-car-keyboard/u-car-keyboard.vue +262 -262
- package/components/u-card/types.ts +61 -61
- package/components/u-card/u-card.vue +209 -209
- package/components/u-cell-group/types.ts +19 -19
- package/components/u-cell-group/u-cell-group.vue +60 -60
- package/components/u-cell-item/types.ts +56 -56
- package/components/u-cell-item/u-cell-item.vue +226 -226
- package/components/u-checkbox/types.ts +33 -33
- package/components/u-checkbox/u-checkbox.vue +282 -282
- package/components/u-checkbox-group/types.ts +34 -34
- package/components/u-checkbox-group/u-checkbox-group.vue +130 -130
- package/components/u-circle-progress/types.ts +54 -54
- package/components/u-circle-progress/u-circle-progress.vue +206 -206
- package/components/u-city-select/types.ts +22 -22
- package/components/u-city-select/u-city-select.vue +276 -276
- package/components/u-col/types.ts +32 -32
- package/components/u-col/u-col.vue +142 -142
- package/components/u-collapse/types.ts +33 -33
- package/components/u-collapse/u-collapse.vue +190 -190
- package/components/u-collapse-item/types.ts +27 -27
- package/components/u-collapse-item/u-collapse-item.vue +290 -290
- package/components/u-column-notice/types.ts +50 -50
- package/components/u-column-notice/u-column-notice.vue +222 -222
- package/components/u-count-down/types.ts +44 -44
- package/components/u-count-down/u-count-down.vue +286 -286
- package/components/u-count-to/types.ts +34 -34
- package/components/u-count-to/u-count-to.vue +266 -266
- package/components/u-divider/types.ts +33 -33
- package/components/u-divider/u-divider.vue +145 -145
- package/components/u-dropdown/types.ts +34 -34
- package/components/u-dropdown/u-dropdown.vue +330 -330
- package/components/u-dropdown-item/types.ts +29 -29
- package/components/u-dropdown-item/u-dropdown-item.vue +120 -120
- package/components/u-empty/types.ts +38 -38
- package/components/u-empty/u-empty.vue +103 -103
- package/components/u-field/types.ts +71 -71
- package/components/u-field/u-field.vue +388 -388
- package/components/u-form/types.ts +29 -29
- package/components/u-form/u-form.vue +130 -130
- package/components/u-form-item/types.ts +72 -72
- package/components/u-form-item/u-form-item.vue +447 -447
- package/components/u-full-screen/types.ts +16 -16
- package/components/u-full-screen/u-full-screen.vue +103 -103
- package/components/u-gap/types.ts +20 -20
- package/components/u-gap/u-gap.vue +50 -50
- package/components/u-grid/types.ts +21 -21
- package/components/u-grid/u-grid.vue +91 -91
- package/components/u-grid-item/types.ts +16 -16
- package/components/u-grid-item/u-grid-item.vue +130 -130
- package/components/u-icon/types.ts +61 -61
- package/components/u-icon/u-icon.vue +296 -296
- package/components/u-image/types.ts +51 -51
- package/components/u-image/u-image.vue +239 -239
- package/components/u-index-anchor/types.ts +16 -16
- package/components/u-index-anchor/u-index-anchor.vue +94 -94
- package/components/u-index-list/types.ts +43 -43
- package/components/u-index-list/u-index-list.vue +352 -352
- package/components/u-input/types.ts +137 -137
- package/components/u-input/u-input.vue +288 -288
- package/components/u-keyboard/types.ts +40 -40
- package/components/u-keyboard/u-keyboard.vue +178 -178
- package/components/u-lazy-load/types.ts +37 -37
- package/components/u-lazy-load/u-lazy-load.vue +246 -246
- package/components/u-line/types.ts +44 -44
- package/components/u-line/u-line.vue +68 -68
- package/components/u-line-progress/types.ts +58 -58
- package/components/u-line-progress/u-line-progress.vue +126 -126
- package/components/u-link/types.ts +43 -43
- package/components/u-link/u-link.vue +84 -84
- package/components/u-loading/types.ts +35 -35
- package/components/u-loading/u-loading.vue +105 -105
- package/components/u-loading-popup/types.ts +26 -26
- package/components/u-loading-popup/u-loading-popup.vue +253 -253
- package/components/u-loadmore/types.ts +79 -79
- package/components/u-loadmore/u-loadmore.vue +156 -156
- package/components/u-mask/types.ts +40 -40
- package/components/u-mask/u-mask.vue +113 -113
- package/components/u-message-input/types.ts +74 -74
- package/components/u-message-input/u-message-input.vue +281 -281
- package/components/u-modal/types.ts +118 -118
- package/components/u-modal/u-modal.vue +220 -220
- package/components/u-navbar/types.ts +103 -103
- package/components/u-navbar/u-navbar.vue +251 -251
- package/components/u-no-network/image.ts +2 -2
- package/components/u-no-network/types.ts +28 -28
- package/components/u-no-network/u-no-network.vue +303 -303
- package/components/u-notice-bar/types.ts +111 -111
- package/components/u-notice-bar/u-notice-bar.vue +189 -189
- package/components/u-number-box/types.ts +42 -42
- package/components/u-number-box/u-number-box.vue +321 -321
- package/components/u-number-keyboard/types.ts +26 -26
- package/components/u-number-keyboard/u-number-keyboard.vue +188 -188
- package/components/u-picker/types.ts +123 -123
- package/components/u-picker/u-picker.vue +685 -685
- package/components/u-popup/types.ts +59 -59
- package/components/u-popup/u-popup.vue +385 -385
- package/components/u-radio/types.ts +27 -27
- package/components/u-radio/u-radio.vue +279 -279
- package/components/u-radio-group/types.ts +31 -31
- package/components/u-radio-group/u-radio-group.vue +96 -96
- package/components/u-rate/types.ts +42 -42
- package/components/u-rate/u-rate.vue +249 -249
- package/components/u-read-more/types.ts +37 -37
- package/components/u-read-more/u-read-more.vue +172 -172
- package/components/u-root-portal/u-root-portal.vue +56 -56
- package/components/u-row/types.ts +22 -22
- package/components/u-row/u-row.vue +105 -105
- package/components/u-row-notice/types.ts +41 -41
- package/components/u-row-notice/u-row-notice.vue +256 -256
- package/components/u-safe-bottom/u-safe-bottom.vue +57 -57
- package/components/u-search/types.ts +55 -55
- package/components/u-search/u-search.vue +279 -279
- package/components/u-section/types.ts +34 -34
- package/components/u-section/u-section.vue +150 -150
- package/components/u-select/types.ts +45 -45
- package/components/u-select/u-select.vue +388 -388
- package/components/u-skeleton/types.ts +22 -22
- package/components/u-skeleton/u-skeleton.vue +231 -231
- package/components/u-slider/types.ts +34 -34
- package/components/u-slider/u-slider.vue +255 -255
- package/components/u-status-bar/u-status-bar.vue +74 -74
- package/components/u-steps/types.ts +30 -30
- package/components/u-steps/u-steps.vue +181 -181
- package/components/u-sticky/types.ts +24 -24
- package/components/u-sticky/u-sticky.vue +178 -178
- package/components/u-subsection/types.ts +38 -38
- package/components/u-subsection/u-subsection.vue +339 -339
- package/components/u-swipe-action/types.ts +52 -52
- package/components/u-swipe-action/u-swipe-action.vue +276 -276
- package/components/u-swiper/types.ts +49 -49
- package/components/u-swiper/u-swiper.vue +308 -308
- package/components/u-switch/types.ts +30 -30
- package/components/u-switch/u-switch.vue +150 -150
- package/components/u-tabbar/types.ts +38 -38
- package/components/u-tabbar/u-tabbar.vue +315 -315
- package/components/u-table/types.ts +27 -27
- package/components/u-table/u-table.vue +67 -67
- package/components/u-tabs/types.ts +53 -53
- package/components/u-tabs/u-tabs.vue +302 -302
- package/components/u-tabs-swiper/types.ts +55 -55
- package/components/u-tabs-swiper/u-tabs-swiper.vue +409 -409
- package/components/u-tag/types.ts +39 -39
- package/components/u-tag/u-tag.vue +268 -268
- package/components/u-td/types.ts +14 -14
- package/components/u-td/u-td.vue +98 -98
- package/components/u-text/types.ts +72 -72
- package/components/u-text/u-text.vue +343 -343
- package/components/u-th/types.ts +14 -14
- package/components/u-th/u-th.vue +92 -92
- package/components/u-time-line/u-time-line.vue +53 -53
- package/components/u-time-line-item/types.ts +16 -16
- package/components/u-time-line-item/u-time-line-item.vue +90 -90
- package/components/u-toast/types.ts +38 -38
- package/components/u-toast/u-toast.vue +240 -240
- package/components/u-top-tips/types.ts +16 -16
- package/components/u-top-tips/u-top-tips.vue +130 -130
- package/components/u-tr/types.ts +11 -11
- package/components/u-tr/u-tr.vue +39 -39
- package/components/u-upload/types.ts +82 -82
- package/components/u-upload/u-upload.vue +568 -568
- package/components/u-verification-code/types.ts +24 -24
- package/components/u-verification-code/u-verification-code.vue +176 -176
- package/components/u-waterfall/types.ts +18 -18
- package/components/u-waterfall/u-waterfall.vue +187 -187
- package/iconfont.css +913 -913
- package/index.scss +25 -25
- package/index.ts +38 -38
- package/libs/config/config.ts +26 -26
- package/libs/config/zIndex.ts +37 -37
- package/libs/css/color.scss +155 -155
- package/libs/css/common.scss +178 -178
- package/libs/css/style.components.scss +16 -16
- package/libs/css/style.h5.scss +8 -8
- package/libs/css/style.mp.scss +72 -72
- package/libs/css/style.nvue.scss +15 -15
- package/libs/css/style.vue.scss +188 -188
- package/libs/function/$parent.ts +24 -24
- package/libs/function/addUnit.ts +13 -13
- package/libs/function/color.ts +37 -37
- package/libs/function/colorGradient.ts +139 -139
- package/libs/function/debounce.ts +28 -28
- package/libs/function/deepClone.ts +39 -39
- package/libs/function/deepMerge.ts +35 -35
- package/libs/function/getParent.ts +63 -63
- package/libs/function/getRect.ts +26 -26
- package/libs/function/guid.ts +42 -42
- package/libs/function/md5.ts +403 -403
- package/libs/function/parent.ts +21 -21
- package/libs/function/queryParams.ts +64 -64
- package/libs/function/random.ts +16 -16
- package/libs/function/randomArray.ts +11 -11
- package/libs/function/route.ts +118 -118
- package/libs/function/styleUtils.ts +83 -83
- package/libs/function/sys.ts +15 -15
- package/libs/function/test.ts +289 -289
- package/libs/function/throttle.ts +31 -31
- package/libs/function/timeFormat.ts +55 -55
- package/libs/function/timeFrom.ts +48 -48
- package/libs/function/toast.ts +14 -14
- package/libs/function/trim.ts +21 -21
- package/libs/function/type2icon.ts +39 -39
- package/libs/hooks/index.ts +4 -4
- package/libs/hooks/useCompRelation.ts +364 -364
- package/libs/hooks/useComponent.ts +759 -759
- package/libs/hooks/useEmitter.ts +79 -79
- package/libs/hooks/useParent.ts +33 -33
- package/libs/hooks/useRect.ts +33 -33
- package/libs/index.ts +337 -337
- package/libs/request/auto-http.ts +76 -76
- package/libs/request/index.ts +242 -242
- package/libs/store/index.ts +88 -88
- package/libs/util/async-validator.d.ts +75 -75
- package/libs/util/async-validator.js +1 -1
- package/libs/util/calendar.d.ts +57 -57
- package/libs/util/emitter.ts +112 -112
- package/libs/util/eventBus.ts +86 -86
- package/libs/util/logger.ts +364 -364
- package/libs/util/mitt.ts +118 -118
- package/libs/util/parent.ts +20 -20
- package/package.json +4 -4
- package/readme.md +241 -241
- package/theme.scss +38 -38
- package/types/components.d.ts +97 -97
- package/types/global.d.ts +331 -331
- package/types/ignore-errors.d.ts +30 -30
- package/types/index.d.ts +19 -19
- package/types/uni-app.d.ts +63 -63
|
@@ -1,388 +1,388 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view
|
|
3
|
-
class="u-field"
|
|
4
|
-
:class="[{ 'u-border-top': props.borderTop, 'u-border-bottom': props.borderBottom }, customClass]"
|
|
5
|
-
:style="$u.toStyle(customStyle)"
|
|
6
|
-
>
|
|
7
|
-
<view
|
|
8
|
-
class="u-field-inner"
|
|
9
|
-
:class="[props.type === 'textarea' ? 'u-textarea-inner' : '', 'u-label-postion-' + props.labelPosition]"
|
|
10
|
-
>
|
|
11
|
-
<view
|
|
12
|
-
class="u-label"
|
|
13
|
-
:class="[props.required ? 'u-required' : '']"
|
|
14
|
-
:style="{
|
|
15
|
-
justifyContent: justifyContent,
|
|
16
|
-
flex: props.labelPosition === 'left' ? `0 0 ${props.labelWidth}rpx` : '1'
|
|
17
|
-
}"
|
|
18
|
-
>
|
|
19
|
-
<view class="u-icon-wrap" v-if="props.icon">
|
|
20
|
-
<u-icon
|
|
21
|
-
size="32"
|
|
22
|
-
:custom-style="props.iconStyle"
|
|
23
|
-
:name="props.icon"
|
|
24
|
-
:color="props.iconColor"
|
|
25
|
-
class="u-icon"
|
|
26
|
-
></u-icon>
|
|
27
|
-
</view>
|
|
28
|
-
<slot name="icon"></slot>
|
|
29
|
-
<text class="u-label-text" :class="[$slots.icon || props.icon ? 'u-label-left-gap' : '']">
|
|
30
|
-
{{ props.label }}
|
|
31
|
-
</text>
|
|
32
|
-
</view>
|
|
33
|
-
<view class="fild-body">
|
|
34
|
-
<view class="u-flex-1 u-flex" :style="[inputWrapStyle]">
|
|
35
|
-
<textarea
|
|
36
|
-
v-if="props.type === 'textarea'"
|
|
37
|
-
class="u-flex-1 u-textarea-class"
|
|
38
|
-
:style="[props.fieldStyle]"
|
|
39
|
-
:value="props.modelValue"
|
|
40
|
-
:placeholder="props.placeholder"
|
|
41
|
-
:placeholderStyle="props.placeholderStyle"
|
|
42
|
-
:disabled="props.disabled"
|
|
43
|
-
:maxlength="inputMaxlength"
|
|
44
|
-
:focus="props.focus"
|
|
45
|
-
:autoHeight="props.autoHeight"
|
|
46
|
-
:fixed="props.fixed"
|
|
47
|
-
@input="onInput"
|
|
48
|
-
@blur="onBlur"
|
|
49
|
-
@focus="onFocus"
|
|
50
|
-
@confirm="onConfirm"
|
|
51
|
-
@tap="fieldClick"
|
|
52
|
-
/>
|
|
53
|
-
<input
|
|
54
|
-
v-else
|
|
55
|
-
:style="[props.fieldStyle]"
|
|
56
|
-
:type="props.type"
|
|
57
|
-
class="u-flex-1 u-field__input-wrap"
|
|
58
|
-
:value="props.modelValue"
|
|
59
|
-
:password="props.password || props.type === 'password'"
|
|
60
|
-
:placeholder="props.placeholder"
|
|
61
|
-
:placeholderStyle="props.placeholderStyle"
|
|
62
|
-
:disabled="props.disabled"
|
|
63
|
-
:maxlength="inputMaxlength"
|
|
64
|
-
:focus="props.focus"
|
|
65
|
-
:confirmType="props.confirmType"
|
|
66
|
-
@focus="onFocus"
|
|
67
|
-
@blur="onBlur"
|
|
68
|
-
@input="onInput"
|
|
69
|
-
@confirm="onConfirm"
|
|
70
|
-
@tap="fieldClick"
|
|
71
|
-
/>
|
|
72
|
-
</view>
|
|
73
|
-
<u-icon
|
|
74
|
-
:size="props.clearSize"
|
|
75
|
-
v-if="props.clearable && props.modelValue != '' && focused"
|
|
76
|
-
name="close-circle-fill"
|
|
77
|
-
color="#c0c4cc"
|
|
78
|
-
class="u-clear-icon"
|
|
79
|
-
@click="onClear"
|
|
80
|
-
/>
|
|
81
|
-
<view class="u-button-wrap"><slot name="right" /></view>
|
|
82
|
-
<u-icon
|
|
83
|
-
v-if="props.rightIcon"
|
|
84
|
-
@click="rightIconClick"
|
|
85
|
-
:name="props.rightIcon"
|
|
86
|
-
color="#c0c4cc"
|
|
87
|
-
:style="[rightIconStyle]"
|
|
88
|
-
size="26"
|
|
89
|
-
class="u-arror-right"
|
|
90
|
-
/>
|
|
91
|
-
</view>
|
|
92
|
-
</view>
|
|
93
|
-
<view
|
|
94
|
-
v-if="props.errorMessage !== false && props.errorMessage != ''"
|
|
95
|
-
class="u-error-message"
|
|
96
|
-
:style="{
|
|
97
|
-
paddingLeft: props.labelWidth + 'rpx'
|
|
98
|
-
}"
|
|
99
|
-
>{{ props.errorMessage }}</view
|
|
100
|
-
>
|
|
101
|
-
</view>
|
|
102
|
-
</template>
|
|
103
|
-
|
|
104
|
-
<script lang="ts">
|
|
105
|
-
export default {
|
|
106
|
-
name: 'u-field',
|
|
107
|
-
options: {
|
|
108
|
-
addGlobalClass: true,
|
|
109
|
-
// #ifndef MP-TOUTIAO
|
|
110
|
-
virtualHost: true,
|
|
111
|
-
// #endif
|
|
112
|
-
styleIsolation: 'shared'
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
</script>
|
|
116
|
-
|
|
117
|
-
<script setup lang="ts">
|
|
118
|
-
import { FieldProps } from './types';
|
|
119
|
-
import { ref, computed } from 'vue';
|
|
120
|
-
import { $u } from '../..';
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* field 输入框
|
|
124
|
-
* @description 借助此组件,可以实现表单的输入, 有"text"和"textarea"类型的,此外,借助uView的picker和actionSheet组件可以快速实现上拉菜单,时间,地区选择等, 为表单解决方案的利器。
|
|
125
|
-
* @tutorial https://uviewpro.cn/zh/components/field.html
|
|
126
|
-
* @property {String} type 输入框的类型(默认text)
|
|
127
|
-
* @property {String} icon label左边的图标,限uView的图标名称
|
|
128
|
-
* @property {Object} icon-style 左边图标的样式,对象形式
|
|
129
|
-
* @property {Boolean} right-icon 输入框右边的图标名称,限uView的图标名称(默认false)
|
|
130
|
-
* @property {Boolean} required 是否必填,左侧显示红色"*"号(默认false)
|
|
131
|
-
* @property {String} label 输入框左边的文字提示
|
|
132
|
-
* @property {Boolean} password 是否密码输入方式(用点替换文字),type为text时有效(默认false)
|
|
133
|
-
* @property {Boolean} clearable 是否显示右侧清空内容的图标控件(输入框有内容,且获得焦点时才显示),点击可清空输入框内容(默认true)
|
|
134
|
-
* @property {Number | String} label-width label的宽度,单位rpx(默认130)
|
|
135
|
-
* @property {String} label-align label的文字对齐方式(默认left)
|
|
136
|
-
* @property {Object} field-style 自定义输入框的样式,对象形式
|
|
137
|
-
* @property {Number | String} clear-size 清除图标的大小,单位rpx(默认30)
|
|
138
|
-
* @property {String} input-align 输入框内容对齐方式(默认left)
|
|
139
|
-
* @property {Boolean} border-bottom 是否显示field的下边框(默认true)
|
|
140
|
-
* @property {Boolean} border-top 是否显示field的上边框(默认false)
|
|
141
|
-
* @property {String} icon-color 左边通过icon配置的图标的颜色(默认#606266)
|
|
142
|
-
* @property {Boolean} auto-height 是否自动增高输入区域,type为textarea时有效(默认true)
|
|
143
|
-
* @property {String Boolean} error-message 显示的错误提示内容,如果为空字符串或者false,则不显示错误信息
|
|
144
|
-
* @property {String} placeholder 输入框的提示文字
|
|
145
|
-
* @property {String} placeholder-style placeholder的样式(内联样式,字符串),如"color: #ddd"
|
|
146
|
-
* @property {Boolean} focus 是否自动获得焦点(默认false)
|
|
147
|
-
* @property {Boolean} fixed 如果type为textarea,且在一个"position:fixed"的区域,需要指明为true(默认false)
|
|
148
|
-
* @property {Boolean} disabled 是否不可输入(默认false)
|
|
149
|
-
* @property {Number String} maxlength 最大输入长度,设置为 -1 的时候不限制最大长度(默认140)
|
|
150
|
-
* @property {String} confirm-type 设置键盘右下角按钮的文字,仅在type="text"时生效(默认done)
|
|
151
|
-
* @event {Function} input 输入框内容发生变化时触发
|
|
152
|
-
* @event {Function} focus 输入框获得焦点时触发
|
|
153
|
-
* @event {Function} blur 输入框失去焦点时触发
|
|
154
|
-
* @event {Function} confirm 点击完成按钮时触发
|
|
155
|
-
* @event {Function} right-icon-click 通过right-icon生成的图标被点击时触发
|
|
156
|
-
* @event {Function} click 输入框被点击或者通过right-icon生成的图标被点击时触发,这样设计是考虑到传递右边的图标,一般都为需要弹出"picker"等操作时的场景,点击倒三角图标,理应发出此事件,见上方说明
|
|
157
|
-
* @example <u-field v-model="mobile" label="手机号" required :error-message="errorMessage"></u-field>
|
|
158
|
-
*/
|
|
159
|
-
|
|
160
|
-
const emit = defineEmits(['update:modelValue', 'focus', 'blur', 'confirm', 'right-icon-click', 'click']);
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* field 输入框
|
|
164
|
-
* @description 借助此组件,可以实现表单的输入, 有"text"和"textarea"类型的,此外,借助uView的picker和actionSheet组件可以快速实现上拉菜单,时间,地区选择等, 为表单解决方案的利器。
|
|
165
|
-
* @property {string} icon label左边的图标,限uView的图标名称
|
|
166
|
-
* @property {string} rightIcon 输入框右边的图标名称,限uView的图标名称(默认false)
|
|
167
|
-
* @property {boolean} required 是否必填,左边显示红色"*"号(默认false)
|
|
168
|
-
* @property {string} label 输入框左边的文字提示
|
|
169
|
-
* @property {boolean} password 是否密码输入方式(用点替换文字),type为text时有效(默认false)
|
|
170
|
-
* @property {boolean} clearable 是否显示右侧清空内容的图标控件(默认true)
|
|
171
|
-
* @property {number|string} labelWidth label的宽度,单位rpx(默认130)
|
|
172
|
-
* @property {string} labelAlign label的文字对齐方式(默认left)
|
|
173
|
-
* @property {string} inputAlign 输入框内容对齐方式(默认left)
|
|
174
|
-
* @property {string} iconColor 左边通过icon配置的图标的颜色(默认#606266)
|
|
175
|
-
* @property {boolean} autoHeight 是否自动增高输入区域,type为textarea时有效(默认true)
|
|
176
|
-
* @property {string|boolean} errorMessage 显示的错误提示内容,如果为空字符串或者false,则不显示错误信息
|
|
177
|
-
* @property {string} placeholder 输入框的提示文字
|
|
178
|
-
* @property {string} placeholderStyle placeholder的样式(内联样式,字符串),如"color: #ddd"
|
|
179
|
-
* @property {boolean} focus 是否自动获得焦点(默认false)
|
|
180
|
-
* @property {boolean} fixed 如果type为textarea,且在一个"position:fixed"的区域,需要指明为true(默认false)
|
|
181
|
-
* @property {boolean} disabled 是否不可输入(默认false)
|
|
182
|
-
* @property {number|string} maxlength 最大输入长度,设置为 -1 的时候不限制最大长度(默认140)
|
|
183
|
-
* @property {string} confirmType 设置键盘右下角按钮的文字,仅在type="text"时生效(默认done)
|
|
184
|
-
* @property {string} labelPosition label位置(默认left)
|
|
185
|
-
* @property {Record<string, any>} fieldStyle 自定义输入框的样式,对象形式
|
|
186
|
-
* @property {number|string} clearSize 清除图标的大小,单位rpx(默认30)
|
|
187
|
-
* @property {Record<string, any>} iconStyle 左侧图标样式
|
|
188
|
-
* @property {boolean} borderTop 是否显示field的上边框(默认false)
|
|
189
|
-
* @property {boolean} borderBottom 是否显示field的下边框(默认true)
|
|
190
|
-
* @property {boolean} trim 是否自动去除输入内容首尾空格(默认true)
|
|
191
|
-
* @property {string|number} value 输入框绑定值
|
|
192
|
-
* @property {string} type 输入框类型(text/textarea/password等,默认text)
|
|
193
|
-
*/
|
|
194
|
-
const props = defineProps(FieldProps);
|
|
195
|
-
|
|
196
|
-
const focused = ref(false);
|
|
197
|
-
const itemIndex = ref(0);
|
|
198
|
-
|
|
199
|
-
const inputWrapStyle = computed(() => {
|
|
200
|
-
const style: Record<string, string> = {};
|
|
201
|
-
style.textAlign = props.inputAlign;
|
|
202
|
-
// 判断label的位置,如果是left的话,让input左边两边有间隙
|
|
203
|
-
if (props.labelPosition === 'left') {
|
|
204
|
-
style.margin = '0 8rpx';
|
|
205
|
-
} else {
|
|
206
|
-
// 如果label是top的,input的左边就没必要有间隙了
|
|
207
|
-
style.marginRight = '8rpx';
|
|
208
|
-
}
|
|
209
|
-
return style;
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
const rightIconStyle = computed(() => {
|
|
213
|
-
const style: Record<string, string> = {};
|
|
214
|
-
// 方向属性已注释,保留原有逻辑
|
|
215
|
-
if (props.arrowDirection === 'top') style.transform = 'rotate(-90deg)';
|
|
216
|
-
if (props.arrowDirection === 'bottom') style.transform = 'rotate(90deg)';
|
|
217
|
-
else style.transform = 'rotate(0deg)';
|
|
218
|
-
return style;
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
const labelStyle = computed(() => {
|
|
222
|
-
const style: Record<string, string> = {};
|
|
223
|
-
if (props.labelAlign === 'left') style.justifyContent = 'flex-start';
|
|
224
|
-
if (props.labelAlign === 'center') style.justifyContent = 'center';
|
|
225
|
-
if (props.labelAlign === 'right') style.justifyContent = 'flex-end';
|
|
226
|
-
return style;
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
// uni不支持在computed中写style.justifyContent = 'center'的形式,故用此方法
|
|
230
|
-
const justifyContent = computed(() => {
|
|
231
|
-
if (props.labelAlign === 'left') return 'flex-start';
|
|
232
|
-
if (props.labelAlign === 'center') return 'center';
|
|
233
|
-
if (props.labelAlign === 'right') return 'flex-end';
|
|
234
|
-
return 'flex-start';
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
// 因为uniapp的input组件的maxlength组件必须要数值,这里转为数值,给用户可以传入字符串数值
|
|
238
|
-
const inputMaxlength = computed(() => Number(props.maxlength));
|
|
239
|
-
|
|
240
|
-
// label的位置
|
|
241
|
-
const fieldInnerStyle = computed(() => {
|
|
242
|
-
const style: Record<string, string> = {};
|
|
243
|
-
style.flexDirection = props.labelPosition === 'left' ? 'row' : 'column';
|
|
244
|
-
return style;
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
function onInput(event: any) {
|
|
248
|
-
// 兼容 uni-app input/textarea 事件参数
|
|
249
|
-
let value = event?.detail?.value ?? '';
|
|
250
|
-
// 判断是否去除空格
|
|
251
|
-
if (props.trim) value = $u.trim(value);
|
|
252
|
-
emit('update:modelValue', value);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function onFocus(event: any) {
|
|
256
|
-
focused.value = true;
|
|
257
|
-
emit('focus', event);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function onBlur(event: any) {
|
|
261
|
-
// 最开始使用的是监听图标@touchstart事件,自从hx2.8.4后,此方法在微信小程序出错
|
|
262
|
-
// 这里改为监听点击事件,手点击清除图标时,同时也发生了@blur事件,导致图标消失而无法点击,这里做一个延时
|
|
263
|
-
setTimeout(() => {
|
|
264
|
-
focused.value = false;
|
|
265
|
-
}, 100);
|
|
266
|
-
emit('blur', event);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function onConfirm(e: any) {
|
|
270
|
-
emit('confirm', e?.detail?.value ?? '');
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function onClear() {
|
|
274
|
-
emit('update:modelValue', '');
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
function rightIconClick() {
|
|
278
|
-
emit('right-icon-click');
|
|
279
|
-
emit('click');
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function fieldClick() {
|
|
283
|
-
emit('click');
|
|
284
|
-
}
|
|
285
|
-
</script>
|
|
286
|
-
|
|
287
|
-
<style lang="scss" scoped>
|
|
288
|
-
@import '../../libs/css/style.components.scss';
|
|
289
|
-
|
|
290
|
-
.u-field {
|
|
291
|
-
font-size: 28rpx;
|
|
292
|
-
padding: 20rpx 28rpx;
|
|
293
|
-
text-align: left;
|
|
294
|
-
position: relative;
|
|
295
|
-
color: $u-main-color;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
.u-field-inner {
|
|
299
|
-
@include vue-flex;
|
|
300
|
-
align-items: center;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
.u-textarea-inner {
|
|
304
|
-
align-items: flex-start;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
.u-textarea-class {
|
|
308
|
-
min-height: 96rpx;
|
|
309
|
-
width: auto;
|
|
310
|
-
font-size: 28rpx;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
.fild-body {
|
|
314
|
-
@include vue-flex;
|
|
315
|
-
flex: 1;
|
|
316
|
-
align-items: center;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
.u-arror-right {
|
|
320
|
-
margin-left: 8rpx;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
.u-label-text {
|
|
324
|
-
/* #ifndef APP-NVUE */
|
|
325
|
-
display: inline-flex;
|
|
326
|
-
/* #endif */
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
.u-label-left-gap {
|
|
330
|
-
margin-left: 6rpx;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
.u-label-postion-top {
|
|
334
|
-
flex-direction: column;
|
|
335
|
-
align-items: flex-start;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
.u-label {
|
|
339
|
-
width: 130rpx;
|
|
340
|
-
flex: 1 1 130rpx;
|
|
341
|
-
text-align: left;
|
|
342
|
-
position: relative;
|
|
343
|
-
@include vue-flex;
|
|
344
|
-
align-items: center;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
.u-required::before {
|
|
348
|
-
content: '*';
|
|
349
|
-
position: absolute;
|
|
350
|
-
left: -16rpx;
|
|
351
|
-
font-size: 14px;
|
|
352
|
-
color: $u-type-error;
|
|
353
|
-
height: 9px;
|
|
354
|
-
line-height: 1;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
.u-field__input-wrap {
|
|
358
|
-
position: relative;
|
|
359
|
-
overflow: hidden;
|
|
360
|
-
font-size: 28rpx;
|
|
361
|
-
height: 48rpx;
|
|
362
|
-
flex: 1;
|
|
363
|
-
width: auto;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
.u-clear-icon {
|
|
367
|
-
@include vue-flex;
|
|
368
|
-
align-items: center;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
.u-error-message {
|
|
372
|
-
color: $u-type-error;
|
|
373
|
-
font-size: 26rpx;
|
|
374
|
-
text-align: left;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
.placeholder-style {
|
|
378
|
-
color: rgb(150, 151, 153);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
.u-input-class {
|
|
382
|
-
font-size: 28rpx;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
.u-button-wrap {
|
|
386
|
-
margin-left: 8rpx;
|
|
387
|
-
}
|
|
388
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
class="u-field"
|
|
4
|
+
:class="[{ 'u-border-top': props.borderTop, 'u-border-bottom': props.borderBottom }, customClass]"
|
|
5
|
+
:style="$u.toStyle(customStyle)"
|
|
6
|
+
>
|
|
7
|
+
<view
|
|
8
|
+
class="u-field-inner"
|
|
9
|
+
:class="[props.type === 'textarea' ? 'u-textarea-inner' : '', 'u-label-postion-' + props.labelPosition]"
|
|
10
|
+
>
|
|
11
|
+
<view
|
|
12
|
+
class="u-label"
|
|
13
|
+
:class="[props.required ? 'u-required' : '']"
|
|
14
|
+
:style="{
|
|
15
|
+
justifyContent: justifyContent,
|
|
16
|
+
flex: props.labelPosition === 'left' ? `0 0 ${props.labelWidth}rpx` : '1'
|
|
17
|
+
}"
|
|
18
|
+
>
|
|
19
|
+
<view class="u-icon-wrap" v-if="props.icon">
|
|
20
|
+
<u-icon
|
|
21
|
+
size="32"
|
|
22
|
+
:custom-style="props.iconStyle"
|
|
23
|
+
:name="props.icon"
|
|
24
|
+
:color="props.iconColor"
|
|
25
|
+
class="u-icon"
|
|
26
|
+
></u-icon>
|
|
27
|
+
</view>
|
|
28
|
+
<slot name="icon"></slot>
|
|
29
|
+
<text class="u-label-text" :class="[$slots.icon || props.icon ? 'u-label-left-gap' : '']">
|
|
30
|
+
{{ props.label }}
|
|
31
|
+
</text>
|
|
32
|
+
</view>
|
|
33
|
+
<view class="fild-body">
|
|
34
|
+
<view class="u-flex-1 u-flex" :style="[inputWrapStyle]">
|
|
35
|
+
<textarea
|
|
36
|
+
v-if="props.type === 'textarea'"
|
|
37
|
+
class="u-flex-1 u-textarea-class"
|
|
38
|
+
:style="[props.fieldStyle]"
|
|
39
|
+
:value="props.modelValue"
|
|
40
|
+
:placeholder="props.placeholder"
|
|
41
|
+
:placeholderStyle="props.placeholderStyle"
|
|
42
|
+
:disabled="props.disabled"
|
|
43
|
+
:maxlength="inputMaxlength"
|
|
44
|
+
:focus="props.focus"
|
|
45
|
+
:autoHeight="props.autoHeight"
|
|
46
|
+
:fixed="props.fixed"
|
|
47
|
+
@input="onInput"
|
|
48
|
+
@blur="onBlur"
|
|
49
|
+
@focus="onFocus"
|
|
50
|
+
@confirm="onConfirm"
|
|
51
|
+
@tap="fieldClick"
|
|
52
|
+
/>
|
|
53
|
+
<input
|
|
54
|
+
v-else
|
|
55
|
+
:style="[props.fieldStyle]"
|
|
56
|
+
:type="props.type"
|
|
57
|
+
class="u-flex-1 u-field__input-wrap"
|
|
58
|
+
:value="props.modelValue"
|
|
59
|
+
:password="props.password || props.type === 'password'"
|
|
60
|
+
:placeholder="props.placeholder"
|
|
61
|
+
:placeholderStyle="props.placeholderStyle"
|
|
62
|
+
:disabled="props.disabled"
|
|
63
|
+
:maxlength="inputMaxlength"
|
|
64
|
+
:focus="props.focus"
|
|
65
|
+
:confirmType="props.confirmType"
|
|
66
|
+
@focus="onFocus"
|
|
67
|
+
@blur="onBlur"
|
|
68
|
+
@input="onInput"
|
|
69
|
+
@confirm="onConfirm"
|
|
70
|
+
@tap="fieldClick"
|
|
71
|
+
/>
|
|
72
|
+
</view>
|
|
73
|
+
<u-icon
|
|
74
|
+
:size="props.clearSize"
|
|
75
|
+
v-if="props.clearable && props.modelValue != '' && focused"
|
|
76
|
+
name="close-circle-fill"
|
|
77
|
+
color="#c0c4cc"
|
|
78
|
+
class="u-clear-icon"
|
|
79
|
+
@click="onClear"
|
|
80
|
+
/>
|
|
81
|
+
<view class="u-button-wrap"><slot name="right" /></view>
|
|
82
|
+
<u-icon
|
|
83
|
+
v-if="props.rightIcon"
|
|
84
|
+
@click="rightIconClick"
|
|
85
|
+
:name="props.rightIcon"
|
|
86
|
+
color="#c0c4cc"
|
|
87
|
+
:style="[rightIconStyle]"
|
|
88
|
+
size="26"
|
|
89
|
+
class="u-arror-right"
|
|
90
|
+
/>
|
|
91
|
+
</view>
|
|
92
|
+
</view>
|
|
93
|
+
<view
|
|
94
|
+
v-if="props.errorMessage !== false && props.errorMessage != ''"
|
|
95
|
+
class="u-error-message"
|
|
96
|
+
:style="{
|
|
97
|
+
paddingLeft: props.labelWidth + 'rpx'
|
|
98
|
+
}"
|
|
99
|
+
>{{ props.errorMessage }}</view
|
|
100
|
+
>
|
|
101
|
+
</view>
|
|
102
|
+
</template>
|
|
103
|
+
|
|
104
|
+
<script lang="ts">
|
|
105
|
+
export default {
|
|
106
|
+
name: 'u-field',
|
|
107
|
+
options: {
|
|
108
|
+
addGlobalClass: true,
|
|
109
|
+
// #ifndef MP-TOUTIAO
|
|
110
|
+
virtualHost: true,
|
|
111
|
+
// #endif
|
|
112
|
+
styleIsolation: 'shared'
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
</script>
|
|
116
|
+
|
|
117
|
+
<script setup lang="ts">
|
|
118
|
+
import { FieldProps } from './types';
|
|
119
|
+
import { ref, computed } from 'vue';
|
|
120
|
+
import { $u } from '../..';
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* field 输入框
|
|
124
|
+
* @description 借助此组件,可以实现表单的输入, 有"text"和"textarea"类型的,此外,借助uView的picker和actionSheet组件可以快速实现上拉菜单,时间,地区选择等, 为表单解决方案的利器。
|
|
125
|
+
* @tutorial https://uviewpro.cn/zh/components/field.html
|
|
126
|
+
* @property {String} type 输入框的类型(默认text)
|
|
127
|
+
* @property {String} icon label左边的图标,限uView的图标名称
|
|
128
|
+
* @property {Object} icon-style 左边图标的样式,对象形式
|
|
129
|
+
* @property {Boolean} right-icon 输入框右边的图标名称,限uView的图标名称(默认false)
|
|
130
|
+
* @property {Boolean} required 是否必填,左侧显示红色"*"号(默认false)
|
|
131
|
+
* @property {String} label 输入框左边的文字提示
|
|
132
|
+
* @property {Boolean} password 是否密码输入方式(用点替换文字),type为text时有效(默认false)
|
|
133
|
+
* @property {Boolean} clearable 是否显示右侧清空内容的图标控件(输入框有内容,且获得焦点时才显示),点击可清空输入框内容(默认true)
|
|
134
|
+
* @property {Number | String} label-width label的宽度,单位rpx(默认130)
|
|
135
|
+
* @property {String} label-align label的文字对齐方式(默认left)
|
|
136
|
+
* @property {Object} field-style 自定义输入框的样式,对象形式
|
|
137
|
+
* @property {Number | String} clear-size 清除图标的大小,单位rpx(默认30)
|
|
138
|
+
* @property {String} input-align 输入框内容对齐方式(默认left)
|
|
139
|
+
* @property {Boolean} border-bottom 是否显示field的下边框(默认true)
|
|
140
|
+
* @property {Boolean} border-top 是否显示field的上边框(默认false)
|
|
141
|
+
* @property {String} icon-color 左边通过icon配置的图标的颜色(默认#606266)
|
|
142
|
+
* @property {Boolean} auto-height 是否自动增高输入区域,type为textarea时有效(默认true)
|
|
143
|
+
* @property {String Boolean} error-message 显示的错误提示内容,如果为空字符串或者false,则不显示错误信息
|
|
144
|
+
* @property {String} placeholder 输入框的提示文字
|
|
145
|
+
* @property {String} placeholder-style placeholder的样式(内联样式,字符串),如"color: #ddd"
|
|
146
|
+
* @property {Boolean} focus 是否自动获得焦点(默认false)
|
|
147
|
+
* @property {Boolean} fixed 如果type为textarea,且在一个"position:fixed"的区域,需要指明为true(默认false)
|
|
148
|
+
* @property {Boolean} disabled 是否不可输入(默认false)
|
|
149
|
+
* @property {Number String} maxlength 最大输入长度,设置为 -1 的时候不限制最大长度(默认140)
|
|
150
|
+
* @property {String} confirm-type 设置键盘右下角按钮的文字,仅在type="text"时生效(默认done)
|
|
151
|
+
* @event {Function} input 输入框内容发生变化时触发
|
|
152
|
+
* @event {Function} focus 输入框获得焦点时触发
|
|
153
|
+
* @event {Function} blur 输入框失去焦点时触发
|
|
154
|
+
* @event {Function} confirm 点击完成按钮时触发
|
|
155
|
+
* @event {Function} right-icon-click 通过right-icon生成的图标被点击时触发
|
|
156
|
+
* @event {Function} click 输入框被点击或者通过right-icon生成的图标被点击时触发,这样设计是考虑到传递右边的图标,一般都为需要弹出"picker"等操作时的场景,点击倒三角图标,理应发出此事件,见上方说明
|
|
157
|
+
* @example <u-field v-model="mobile" label="手机号" required :error-message="errorMessage"></u-field>
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
const emit = defineEmits(['update:modelValue', 'focus', 'blur', 'confirm', 'right-icon-click', 'click']);
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* field 输入框
|
|
164
|
+
* @description 借助此组件,可以实现表单的输入, 有"text"和"textarea"类型的,此外,借助uView的picker和actionSheet组件可以快速实现上拉菜单,时间,地区选择等, 为表单解决方案的利器。
|
|
165
|
+
* @property {string} icon label左边的图标,限uView的图标名称
|
|
166
|
+
* @property {string} rightIcon 输入框右边的图标名称,限uView的图标名称(默认false)
|
|
167
|
+
* @property {boolean} required 是否必填,左边显示红色"*"号(默认false)
|
|
168
|
+
* @property {string} label 输入框左边的文字提示
|
|
169
|
+
* @property {boolean} password 是否密码输入方式(用点替换文字),type为text时有效(默认false)
|
|
170
|
+
* @property {boolean} clearable 是否显示右侧清空内容的图标控件(默认true)
|
|
171
|
+
* @property {number|string} labelWidth label的宽度,单位rpx(默认130)
|
|
172
|
+
* @property {string} labelAlign label的文字对齐方式(默认left)
|
|
173
|
+
* @property {string} inputAlign 输入框内容对齐方式(默认left)
|
|
174
|
+
* @property {string} iconColor 左边通过icon配置的图标的颜色(默认#606266)
|
|
175
|
+
* @property {boolean} autoHeight 是否自动增高输入区域,type为textarea时有效(默认true)
|
|
176
|
+
* @property {string|boolean} errorMessage 显示的错误提示内容,如果为空字符串或者false,则不显示错误信息
|
|
177
|
+
* @property {string} placeholder 输入框的提示文字
|
|
178
|
+
* @property {string} placeholderStyle placeholder的样式(内联样式,字符串),如"color: #ddd"
|
|
179
|
+
* @property {boolean} focus 是否自动获得焦点(默认false)
|
|
180
|
+
* @property {boolean} fixed 如果type为textarea,且在一个"position:fixed"的区域,需要指明为true(默认false)
|
|
181
|
+
* @property {boolean} disabled 是否不可输入(默认false)
|
|
182
|
+
* @property {number|string} maxlength 最大输入长度,设置为 -1 的时候不限制最大长度(默认140)
|
|
183
|
+
* @property {string} confirmType 设置键盘右下角按钮的文字,仅在type="text"时生效(默认done)
|
|
184
|
+
* @property {string} labelPosition label位置(默认left)
|
|
185
|
+
* @property {Record<string, any>} fieldStyle 自定义输入框的样式,对象形式
|
|
186
|
+
* @property {number|string} clearSize 清除图标的大小,单位rpx(默认30)
|
|
187
|
+
* @property {Record<string, any>} iconStyle 左侧图标样式
|
|
188
|
+
* @property {boolean} borderTop 是否显示field的上边框(默认false)
|
|
189
|
+
* @property {boolean} borderBottom 是否显示field的下边框(默认true)
|
|
190
|
+
* @property {boolean} trim 是否自动去除输入内容首尾空格(默认true)
|
|
191
|
+
* @property {string|number} value 输入框绑定值
|
|
192
|
+
* @property {string} type 输入框类型(text/textarea/password等,默认text)
|
|
193
|
+
*/
|
|
194
|
+
const props = defineProps(FieldProps);
|
|
195
|
+
|
|
196
|
+
const focused = ref(false);
|
|
197
|
+
const itemIndex = ref(0);
|
|
198
|
+
|
|
199
|
+
const inputWrapStyle = computed(() => {
|
|
200
|
+
const style: Record<string, string> = {};
|
|
201
|
+
style.textAlign = props.inputAlign;
|
|
202
|
+
// 判断label的位置,如果是left的话,让input左边两边有间隙
|
|
203
|
+
if (props.labelPosition === 'left') {
|
|
204
|
+
style.margin = '0 8rpx';
|
|
205
|
+
} else {
|
|
206
|
+
// 如果label是top的,input的左边就没必要有间隙了
|
|
207
|
+
style.marginRight = '8rpx';
|
|
208
|
+
}
|
|
209
|
+
return style;
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const rightIconStyle = computed(() => {
|
|
213
|
+
const style: Record<string, string> = {};
|
|
214
|
+
// 方向属性已注释,保留原有逻辑
|
|
215
|
+
if (props.arrowDirection === 'top') style.transform = 'rotate(-90deg)';
|
|
216
|
+
if (props.arrowDirection === 'bottom') style.transform = 'rotate(90deg)';
|
|
217
|
+
else style.transform = 'rotate(0deg)';
|
|
218
|
+
return style;
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const labelStyle = computed(() => {
|
|
222
|
+
const style: Record<string, string> = {};
|
|
223
|
+
if (props.labelAlign === 'left') style.justifyContent = 'flex-start';
|
|
224
|
+
if (props.labelAlign === 'center') style.justifyContent = 'center';
|
|
225
|
+
if (props.labelAlign === 'right') style.justifyContent = 'flex-end';
|
|
226
|
+
return style;
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// uni不支持在computed中写style.justifyContent = 'center'的形式,故用此方法
|
|
230
|
+
const justifyContent = computed(() => {
|
|
231
|
+
if (props.labelAlign === 'left') return 'flex-start';
|
|
232
|
+
if (props.labelAlign === 'center') return 'center';
|
|
233
|
+
if (props.labelAlign === 'right') return 'flex-end';
|
|
234
|
+
return 'flex-start';
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// 因为uniapp的input组件的maxlength组件必须要数值,这里转为数值,给用户可以传入字符串数值
|
|
238
|
+
const inputMaxlength = computed(() => Number(props.maxlength));
|
|
239
|
+
|
|
240
|
+
// label的位置
|
|
241
|
+
const fieldInnerStyle = computed(() => {
|
|
242
|
+
const style: Record<string, string> = {};
|
|
243
|
+
style.flexDirection = props.labelPosition === 'left' ? 'row' : 'column';
|
|
244
|
+
return style;
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
function onInput(event: any) {
|
|
248
|
+
// 兼容 uni-app input/textarea 事件参数
|
|
249
|
+
let value = event?.detail?.value ?? '';
|
|
250
|
+
// 判断是否去除空格
|
|
251
|
+
if (props.trim) value = $u.trim(value);
|
|
252
|
+
emit('update:modelValue', value);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function onFocus(event: any) {
|
|
256
|
+
focused.value = true;
|
|
257
|
+
emit('focus', event);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function onBlur(event: any) {
|
|
261
|
+
// 最开始使用的是监听图标@touchstart事件,自从hx2.8.4后,此方法在微信小程序出错
|
|
262
|
+
// 这里改为监听点击事件,手点击清除图标时,同时也发生了@blur事件,导致图标消失而无法点击,这里做一个延时
|
|
263
|
+
setTimeout(() => {
|
|
264
|
+
focused.value = false;
|
|
265
|
+
}, 100);
|
|
266
|
+
emit('blur', event);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function onConfirm(e: any) {
|
|
270
|
+
emit('confirm', e?.detail?.value ?? '');
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function onClear() {
|
|
274
|
+
emit('update:modelValue', '');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function rightIconClick() {
|
|
278
|
+
emit('right-icon-click');
|
|
279
|
+
emit('click');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function fieldClick() {
|
|
283
|
+
emit('click');
|
|
284
|
+
}
|
|
285
|
+
</script>
|
|
286
|
+
|
|
287
|
+
<style lang="scss" scoped>
|
|
288
|
+
@import '../../libs/css/style.components.scss';
|
|
289
|
+
|
|
290
|
+
.u-field {
|
|
291
|
+
font-size: 28rpx;
|
|
292
|
+
padding: 20rpx 28rpx;
|
|
293
|
+
text-align: left;
|
|
294
|
+
position: relative;
|
|
295
|
+
color: $u-main-color;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
.u-field-inner {
|
|
299
|
+
@include vue-flex;
|
|
300
|
+
align-items: center;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.u-textarea-inner {
|
|
304
|
+
align-items: flex-start;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.u-textarea-class {
|
|
308
|
+
min-height: 96rpx;
|
|
309
|
+
width: auto;
|
|
310
|
+
font-size: 28rpx;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
.fild-body {
|
|
314
|
+
@include vue-flex;
|
|
315
|
+
flex: 1;
|
|
316
|
+
align-items: center;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
.u-arror-right {
|
|
320
|
+
margin-left: 8rpx;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.u-label-text {
|
|
324
|
+
/* #ifndef APP-NVUE */
|
|
325
|
+
display: inline-flex;
|
|
326
|
+
/* #endif */
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.u-label-left-gap {
|
|
330
|
+
margin-left: 6rpx;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
.u-label-postion-top {
|
|
334
|
+
flex-direction: column;
|
|
335
|
+
align-items: flex-start;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.u-label {
|
|
339
|
+
width: 130rpx;
|
|
340
|
+
flex: 1 1 130rpx;
|
|
341
|
+
text-align: left;
|
|
342
|
+
position: relative;
|
|
343
|
+
@include vue-flex;
|
|
344
|
+
align-items: center;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
.u-required::before {
|
|
348
|
+
content: '*';
|
|
349
|
+
position: absolute;
|
|
350
|
+
left: -16rpx;
|
|
351
|
+
font-size: 14px;
|
|
352
|
+
color: $u-type-error;
|
|
353
|
+
height: 9px;
|
|
354
|
+
line-height: 1;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.u-field__input-wrap {
|
|
358
|
+
position: relative;
|
|
359
|
+
overflow: hidden;
|
|
360
|
+
font-size: 28rpx;
|
|
361
|
+
height: 48rpx;
|
|
362
|
+
flex: 1;
|
|
363
|
+
width: auto;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
.u-clear-icon {
|
|
367
|
+
@include vue-flex;
|
|
368
|
+
align-items: center;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
.u-error-message {
|
|
372
|
+
color: $u-type-error;
|
|
373
|
+
font-size: 26rpx;
|
|
374
|
+
text-align: left;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
.placeholder-style {
|
|
378
|
+
color: rgb(150, 151, 153);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
.u-input-class {
|
|
382
|
+
font-size: 28rpx;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
.u-button-wrap {
|
|
386
|
+
margin-left: 8rpx;
|
|
387
|
+
}
|
|
388
|
+
</style>
|