hy-app 0.2.11 → 0.2.13
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/component-helper.ts +177 -0
- package/components/hy-action-sheet/hy-action-sheet.vue +9 -3
- package/components/hy-action-sheet/props.ts +2 -2
- package/components/hy-action-sheet/typing.d.ts +49 -16
- package/components/hy-button/hy-button.vue +144 -13
- package/components/hy-button/props.ts +158 -32
- package/components/hy-button/typing.d.ts +71 -32
- package/components/index.ts +114 -122
- package/components.json +3287 -0
- package/dist/attributes.json +1 -0
- package/dist/docs/components/hy-action-sheet/hy-action-sheet.md +41 -0
- package/dist/docs/components/hy-address-picker/hy-address-picker.md +25 -0
- package/dist/docs/components/hy-avatar/hy-avatar.md +19 -0
- package/dist/docs/components/hy-back-top/hy-back-top.md +19 -0
- package/dist/docs/components/hy-badge/hy-badge.md +13 -0
- package/dist/docs/components/hy-button/hy-button.md +61 -0
- package/dist/docs/components/hy-calendar/header.md +17 -0
- package/dist/docs/components/hy-calendar/hy-calendar.md +27 -0
- package/dist/docs/components/hy-calendar/month.md +38 -0
- package/dist/docs/components/hy-card/hy-card.md +24 -0
- package/dist/docs/components/hy-cell/hy-cell.md +26 -0
- package/dist/docs/components/hy-check-button/hy-check-button.md +14 -0
- package/dist/docs/components/hy-checkbox/hy-checkbox.md +21 -0
- package/dist/docs/components/hy-code-input/hy-code-input.md +15 -0
- package/dist/docs/components/hy-config-provider/hy-config-provider.md +13 -0
- package/dist/docs/components/hy-count-down/hy-count-down.md +34 -0
- package/dist/docs/components/hy-count-to/hy-count-to.md +31 -0
- package/dist/docs/components/hy-datetime-picker/hy-datetime-picker.md +25 -0
- package/dist/docs/components/hy-divider/hy-divider.md +13 -0
- package/dist/docs/components/hy-dropdown/hy-dropdown.md +13 -0
- package/dist/docs/components/hy-dropdown-item/hy-dropdown-item.md +20 -0
- package/dist/docs/components/hy-empty/hy-empty.md +20 -0
- package/dist/docs/components/hy-float-button/hy-float-button.md +20 -0
- package/dist/docs/components/hy-folding-panel/hy-folding-panel.md +24 -0
- package/dist/docs/components/hy-form/hy-form.md +29 -0
- package/dist/docs/components/hy-grid/hy-grid.md +19 -0
- package/dist/docs/components/hy-icon/hy-icon.md +13 -0
- package/dist/docs/components/hy-image/hy-image.md +22 -0
- package/dist/docs/components/hy-input/hy-input.md +29 -0
- package/dist/docs/components/hy-line/hy-line.md +7 -0
- package/dist/docs/components/hy-line-progress/hy-line-progress.md +13 -0
- package/dist/docs/components/hy-list/hy-list.md +25 -0
- package/dist/docs/components/hy-loading/hy-loading.md +14 -0
- package/dist/docs/components/hy-login/ThePhoneLogin.md +20 -0
- package/dist/docs/components/hy-login/TheUserLogin.md +44 -0
- package/dist/docs/components/hy-login/hy-login.md +14 -0
- package/dist/docs/components/hy-menu/hy-menu.md +21 -0
- package/dist/docs/components/hy-modal/hy-modal.md +23 -0
- package/dist/docs/components/hy-navbar/hy-navbar.md +22 -0
- package/dist/docs/components/hy-notice-bar/hy-column-notice.md +20 -0
- package/dist/docs/components/hy-notice-bar/hy-notice-bar.md +14 -0
- package/dist/docs/components/hy-notice-bar/hy-row-notice.md +20 -0
- package/dist/docs/components/hy-notify/hy-notify.md +23 -0
- package/dist/docs/components/hy-number-step/hy-number-step.md +27 -0
- package/dist/docs/components/hy-overlay/hy-overlay.md +19 -0
- package/dist/docs/components/hy-pagination/hy-pagination.md +14 -0
- package/dist/docs/components/hy-parse/hy-parse.md +46 -0
- package/dist/docs/components/hy-parse/node/node.md +7 -0
- package/dist/docs/components/hy-picker/hy-picker.md +32 -0
- package/dist/docs/components/hy-popover/hy-popover.md +34 -0
- package/dist/docs/components/hy-popup/hy-popup.md +22 -0
- package/dist/docs/components/hy-price/hy-price.md +13 -0
- package/dist/docs/components/hy-qrcode/hy-qrcode.md +15 -0
- package/dist/docs/components/hy-radio/hy-radio.md +21 -0
- package/dist/docs/components/hy-rate/hy-rate.md +14 -0
- package/dist/docs/components/hy-read-more/hy-read-more.md +21 -0
- package/dist/docs/components/hy-scroll-list/hy-scroll-list.md +21 -0
- package/dist/docs/components/hy-search/hy-search.md +27 -0
- package/dist/docs/components/hy-signature/hy-signature.md +45 -0
- package/dist/docs/components/hy-slider/hy-slider.md +24 -0
- package/dist/docs/components/hy-status-bar/hy-status-bar.md +13 -0
- package/dist/docs/components/hy-steps/hy-steps.md +23 -0
- package/dist/docs/components/hy-submit-bar/hy-submit-bar.md +21 -0
- package/dist/docs/components/hy-subsection/hy-subsection.md +14 -0
- package/dist/docs/components/hy-swipe-action/hy-swipe-action.md +29 -0
- package/dist/docs/components/hy-swiper/hy-swiper-indicator.md +23 -0
- package/dist/docs/components/hy-swiper/hy-swiper.md +22 -0
- package/dist/docs/components/hy-switch/hy-switch.md +20 -0
- package/dist/docs/components/hy-tabBar/hy-tabBar.md +13 -0
- package/dist/docs/components/hy-tabs/hy-tabs.md +27 -0
- package/dist/docs/components/hy-tag/hy-tag.md +21 -0
- package/dist/docs/components/hy-text/hy-text.md +13 -0
- package/dist/docs/components/hy-textarea/hy-textarea.md +19 -0
- package/dist/docs/components/hy-toast/hy-toast.md +17 -0
- package/dist/docs/components/hy-tooltip/hy-tooltip.md +13 -0
- package/dist/docs/components/hy-transition/hy-transition.md +25 -0
- package/dist/docs/components/hy-upload/hy-upload.md +25 -0
- package/dist/docs/components/hy-warn/hy-warn.md +14 -0
- package/dist/docs/components/hy-waterfall/hy-waterfall.md +30 -0
- package/dist/docs/components/hy-watermark/hy-watermark.md +7 -0
- package/dist/docs/components/message/TheMessage.md +17 -0
- package/dist/docs/components/yk-dialog/yk-dialog.md +7 -0
- package/dist/tags.json +1 -0
- package/dist/web-types.json +1 -0
- package/docgen.config.js +14 -0
- package/global.d.ts +101 -0
- package/package.json +29 -33
- package/web-types.config.js +7 -0
- package/web-types.json +1 -0
- package/components/dialog/TheDialog.vue +0 -128
- package/components/dialog/index.ts +0 -38
- package/components/hy-safe-bottom/hy-safe-bottom.vue +0 -60
- package/components/hy-safe-bottom/index.scss +0 -5
- package/components/message/TheMessage.vue +0 -169
- package/components/message/index.ts +0 -54
- package/components/u-form/form.js +0 -22
- package/components/u-form/hy-form.vue +0 -324
- package/components/u-form/props.js +0 -49
- package/components/u-form/schema.js +0 -1451
- package/components/u-form/u-form.vue +0 -267
- package/components/u-form/utils.js +0 -65
- package/components/u-form-item/formItem.js +0 -24
- package/components/u-form-item/hy-form-item.vue +0 -360
- package/components/u-form-item/props.js +0 -57
- package/components/u-form-item/u-form-item.vue +0 -294
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view
|
|
3
|
-
class="u-form-item"
|
|
4
|
-
:class="{
|
|
5
|
-
'u-form-item--error':
|
|
6
|
-
!!message.value && parentData.errorType === 'message'
|
|
7
|
-
}"
|
|
8
|
-
>
|
|
9
|
-
<view
|
|
10
|
-
class="u-form-item__body"
|
|
11
|
-
@tap="clickHandler"
|
|
12
|
-
:style="[
|
|
13
|
-
customStyle,
|
|
14
|
-
{
|
|
15
|
-
flexDirection:
|
|
16
|
-
(labelPosition || parentData.labelPosition) === 'left'
|
|
17
|
-
? 'row'
|
|
18
|
-
: 'column'
|
|
19
|
-
}
|
|
20
|
-
]"
|
|
21
|
-
>
|
|
22
|
-
<!-- 微信小程序中,将一个参数设置空字符串,结果会变成字符串"true" -->
|
|
23
|
-
<slot name="label">
|
|
24
|
-
<!-- {{required}} -->
|
|
25
|
-
<view
|
|
26
|
-
class="u-form-item__body__left"
|
|
27
|
-
v-if="required.value || leftIcon.value || label.value"
|
|
28
|
-
:style="{
|
|
29
|
-
width: addUnit(labelWidth.value || parentData.value.labelWidth),
|
|
30
|
-
marginBottom: parentData.value.labelPosition === 'left' ? 0 : '5px'
|
|
31
|
-
}"
|
|
32
|
-
>
|
|
33
|
-
<!-- 为了块对齐 -->
|
|
34
|
-
<view class="u-form-item__body__left__content">
|
|
35
|
-
<!-- nvue不支持伪元素before -->
|
|
36
|
-
<text
|
|
37
|
-
v-if="required.value"
|
|
38
|
-
class="u-form-item__body__left__content__required"
|
|
39
|
-
>*</text
|
|
40
|
-
>
|
|
41
|
-
<view
|
|
42
|
-
class="u-form-item__body__left__content__icon"
|
|
43
|
-
v-if="leftIcon.value"
|
|
44
|
-
>
|
|
45
|
-
<u-icon
|
|
46
|
-
:name="leftIcon.value"
|
|
47
|
-
:custom-style="leftIconStyle.value"
|
|
48
|
-
></u-icon>
|
|
49
|
-
</view>
|
|
50
|
-
<text
|
|
51
|
-
class="u-form-item__body__left__content__label"
|
|
52
|
-
:style="[
|
|
53
|
-
parentData.value.labelStyle,
|
|
54
|
-
{
|
|
55
|
-
justifyContent:
|
|
56
|
-
parentData.value.labelAlign === 'left'
|
|
57
|
-
? 'flex-start'
|
|
58
|
-
: parentData.value.labelAlign === 'center'
|
|
59
|
-
? 'center'
|
|
60
|
-
: 'flex-end'
|
|
61
|
-
}
|
|
62
|
-
]"
|
|
63
|
-
>{{ label.value }}</text
|
|
64
|
-
>
|
|
65
|
-
</view>
|
|
66
|
-
</view>
|
|
67
|
-
</slot>
|
|
68
|
-
<view class="u-form-item__body__right">
|
|
69
|
-
<view class="u-form-item__body__right__content">
|
|
70
|
-
<view class="u-form-item__body__right__content__slot">
|
|
71
|
-
<slot />
|
|
72
|
-
</view>
|
|
73
|
-
<view class="item__body__right__content__icon" v-if="$slots.right">
|
|
74
|
-
<slot name="right" />
|
|
75
|
-
</view>
|
|
76
|
-
</view>
|
|
77
|
-
</view>
|
|
78
|
-
</view>
|
|
79
|
-
<slot name="error">
|
|
80
|
-
<text
|
|
81
|
-
v-if="!!message.value && parentData.value.errorType === 'message'"
|
|
82
|
-
class="u-form-item__body__right__message"
|
|
83
|
-
:style="{
|
|
84
|
-
marginLeft: addUnit(
|
|
85
|
-
parentData.value.labelPosition === 'top'
|
|
86
|
-
? 0
|
|
87
|
-
: labelWidth.value || parentData.value.labelWidth
|
|
88
|
-
)
|
|
89
|
-
}"
|
|
90
|
-
>{{ message.value }}</text
|
|
91
|
-
>
|
|
92
|
-
</slot>
|
|
93
|
-
<u-line
|
|
94
|
-
v-if="borderBottom.value"
|
|
95
|
-
:color="
|
|
96
|
-
message.value && parentData.value.errorType === 'border-bottom'
|
|
97
|
-
? error
|
|
98
|
-
: propsLine.value.color
|
|
99
|
-
"
|
|
100
|
-
:customStyle="`margin-top: ${
|
|
101
|
-
message.value && parentData.value.errorType === 'message' ? '5px' : 0
|
|
102
|
-
}`"
|
|
103
|
-
></u-line>
|
|
104
|
-
</view>
|
|
105
|
-
</template>
|
|
106
|
-
|
|
107
|
-
<script setup lang="ts">
|
|
108
|
-
// import { props } from "./props";
|
|
109
|
-
// import defProps from "../../libs/config/props.js";
|
|
110
|
-
import { ColorConfig } from "../../config";
|
|
111
|
-
import { getProperty, setProperty } from "../u-form/utils";
|
|
112
|
-
import { addUnit, error } from "../../utils";
|
|
113
|
-
import {
|
|
114
|
-
ref,
|
|
115
|
-
reactive,
|
|
116
|
-
onMounted,
|
|
117
|
-
watch,
|
|
118
|
-
defineProps,
|
|
119
|
-
nextTick,
|
|
120
|
-
provide
|
|
121
|
-
} from "vue";
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Form 表单
|
|
125
|
-
* @description 此组件一般用于表单场景,可以配置Input输入框,Select弹出框,进行表单验证等。
|
|
126
|
-
* @tutorial https://ijry.github.io/uview-plus/components/form.html
|
|
127
|
-
* @property {String} label input的label提示语
|
|
128
|
-
* @property {String} prop 绑定的值
|
|
129
|
-
* @property {Array} rules 绑定的规则
|
|
130
|
-
* @property {String | Boolean} borderBottom 是否显示表单域的下划线边框
|
|
131
|
-
* @property {String | Number} labelWidth label的宽度,单位px
|
|
132
|
-
* @property {String} rightIcon 右侧图标
|
|
133
|
-
* @property {String} leftIcon 左侧图标
|
|
134
|
-
* @property {String | Object} leftIconStyle 左侧图标的样式
|
|
135
|
-
* @property {Boolean} required 是否显示左边的必填星号,只作显示用,具体校验必填的逻辑,请在rules中配置 (默认 false )
|
|
136
|
-
*
|
|
137
|
-
* @example <u-form-item label="姓名" prop="userInfo.name" borderBottom ref="item1"></u-form-item>
|
|
138
|
-
*/
|
|
139
|
-
import defProps from "./formItem";
|
|
140
|
-
const props = defineProps({
|
|
141
|
-
// input的label提示语
|
|
142
|
-
label: {
|
|
143
|
-
type: String,
|
|
144
|
-
default: () => defProps.formItem.label
|
|
145
|
-
},
|
|
146
|
-
// 绑定的值
|
|
147
|
-
prop: {
|
|
148
|
-
type: String,
|
|
149
|
-
default: () => defProps.formItem.prop
|
|
150
|
-
},
|
|
151
|
-
// 绑定的规则
|
|
152
|
-
rules: {
|
|
153
|
-
type: Array,
|
|
154
|
-
default: () => defProps.formItem.rules
|
|
155
|
-
},
|
|
156
|
-
// 是否显示表单域的下划线边框
|
|
157
|
-
borderBottom: {
|
|
158
|
-
type: [String, Boolean],
|
|
159
|
-
default: () => defProps.formItem.borderBottom
|
|
160
|
-
},
|
|
161
|
-
// label的位置,left-左边,top-上边
|
|
162
|
-
labelPosition: {
|
|
163
|
-
type: String,
|
|
164
|
-
default: () => defProps.formItem.labelPosition
|
|
165
|
-
},
|
|
166
|
-
// label的宽度,单位px
|
|
167
|
-
labelWidth: {
|
|
168
|
-
type: [String, Number],
|
|
169
|
-
default: () => defProps.formItem.labelWidth
|
|
170
|
-
},
|
|
171
|
-
// 右侧图标
|
|
172
|
-
rightIcon: {
|
|
173
|
-
type: String,
|
|
174
|
-
default: () => defProps.formItem.rightIcon
|
|
175
|
-
},
|
|
176
|
-
// 左侧图标
|
|
177
|
-
leftIcon: {
|
|
178
|
-
type: String,
|
|
179
|
-
default: () => defProps.formItem.leftIcon
|
|
180
|
-
},
|
|
181
|
-
// 是否显示左边的必填星号,只作显示用,具体校验必填的逻辑,请在rules中配置
|
|
182
|
-
required: {
|
|
183
|
-
type: Boolean,
|
|
184
|
-
default: () => defProps.formItem.required
|
|
185
|
-
},
|
|
186
|
-
leftIconStyle: {
|
|
187
|
-
type: [String, Object],
|
|
188
|
-
default: () => defProps.formItem.leftIconStyle
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// 定义发射的事件
|
|
193
|
-
const emit = defineEmits(["click"]);
|
|
194
|
-
|
|
195
|
-
const formItemRef = reactive({
|
|
196
|
-
children: [111]
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
nextTick(() => {
|
|
200
|
-
formItemRef.children.push(11122);
|
|
201
|
-
provide("formItemRef", formItemRef);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
// 错误提示语
|
|
205
|
-
const message = ref("");
|
|
206
|
-
// 父组件数据
|
|
207
|
-
const parentData = reactive({
|
|
208
|
-
// 提示文本的位置
|
|
209
|
-
labelPosition: "left",
|
|
210
|
-
// 提示文本对齐方式
|
|
211
|
-
labelAlign: "left",
|
|
212
|
-
// 提示文本的样式
|
|
213
|
-
labelStyle: {},
|
|
214
|
-
// 提示文本的宽度
|
|
215
|
-
labelWidth: 45,
|
|
216
|
-
// 错误提示方式
|
|
217
|
-
errorType: "message"
|
|
218
|
-
});
|
|
219
|
-
const color = ref(ColorConfig.error);
|
|
220
|
-
const itemRules = ref([]);
|
|
221
|
-
|
|
222
|
-
// 计算属性
|
|
223
|
-
const propsLine = ref("");
|
|
224
|
-
|
|
225
|
-
// 方法
|
|
226
|
-
const clickHandler = () => {
|
|
227
|
-
emit("click");
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
const addUnitFunc = addUnit;
|
|
231
|
-
|
|
232
|
-
const init = () => {
|
|
233
|
-
// 父组件的实例
|
|
234
|
-
updateParentData();
|
|
235
|
-
if (!parent) {
|
|
236
|
-
error("u-form-item需要结合u-form组件使用");
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
// 手动设置校验的规则,如果规则中有函数的话,微信小程序中会过滤掉,所以只能手动调用设置规则
|
|
241
|
-
const setRules = (rules) => {
|
|
242
|
-
// 判断是否有规则
|
|
243
|
-
if (rules.length === 0) {
|
|
244
|
-
itemRules.value = [];
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
itemRules.value = rules;
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
// 获取父组件的参数
|
|
251
|
-
const updateParentData = () => {
|
|
252
|
-
// 此方法写在mixin中
|
|
253
|
-
// getParentData("u-form");
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
// 移除u-form-item的校验结果
|
|
257
|
-
const clearValidate = () => {
|
|
258
|
-
message.value = null;
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
// 清空当前的组件的校验结果,并重置为初始值
|
|
262
|
-
const resetField = () => {
|
|
263
|
-
// 找到原始值
|
|
264
|
-
const value = getProperty(parent.originalModel, prop);
|
|
265
|
-
// 将u-form的model的prop属性链还原原始值
|
|
266
|
-
setProperty(parent.model, prop, value);
|
|
267
|
-
// 移除校验结果
|
|
268
|
-
message.value = null;
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
onMounted(() => {
|
|
272
|
-
init();
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
watch(() => props.rules, {
|
|
276
|
-
immediate: true,
|
|
277
|
-
handler(n) {
|
|
278
|
-
setRules(n);
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
</script>
|
|
282
|
-
|
|
283
|
-
<style lang="scss" scoped>
|
|
284
|
-
@import "../../libs/css/mixin.scss";
|
|
285
|
-
|
|
286
|
-
.u-form-item {
|
|
287
|
-
@include flex(column);
|
|
288
|
-
font-size: 14px;
|
|
289
|
-
color: $u-main-color;
|
|
290
|
-
|
|
291
|
-
&__body {
|
|
292
|
-
@include flex;
|
|
293
|
-
padding: 10px 0;
|
|
294
|
-
|
|
295
|
-
&__left {
|
|
296
|
-
@include flex;
|
|
297
|
-
align-items: center;
|
|
298
|
-
|
|
299
|
-
&__content {
|
|
300
|
-
position: relative;
|
|
301
|
-
@include flex;
|
|
302
|
-
align-items: center;
|
|
303
|
-
padding-right: 10rpx;
|
|
304
|
-
flex: 1;
|
|
305
|
-
|
|
306
|
-
&__icon {
|
|
307
|
-
margin-right: 8rpx;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
&__required {
|
|
311
|
-
position: absolute;
|
|
312
|
-
left: -9px;
|
|
313
|
-
color: $u-error;
|
|
314
|
-
line-height: 20px;
|
|
315
|
-
font-size: 20px;
|
|
316
|
-
top: 3px;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
&__label {
|
|
320
|
-
@include flex;
|
|
321
|
-
align-items: center;
|
|
322
|
-
flex: 1;
|
|
323
|
-
color: $u-main-color;
|
|
324
|
-
font-size: 15px;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
&__right {
|
|
330
|
-
flex: 1;
|
|
331
|
-
|
|
332
|
-
&__content {
|
|
333
|
-
@include flex;
|
|
334
|
-
align-items: center;
|
|
335
|
-
flex: 1;
|
|
336
|
-
|
|
337
|
-
&__slot {
|
|
338
|
-
flex: 1;
|
|
339
|
-
/* #ifndef MP */
|
|
340
|
-
@include flex;
|
|
341
|
-
align-items: center;
|
|
342
|
-
/* #endif */
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
&__icon {
|
|
346
|
-
margin-left: 10rpx;
|
|
347
|
-
color: $u-light-color;
|
|
348
|
-
font-size: 30rpx;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
&__message {
|
|
353
|
-
font-size: 12px;
|
|
354
|
-
line-height: 12px;
|
|
355
|
-
color: $u-error;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
</style>
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export const defineMixin = (options) => {
|
|
2
|
-
return options;
|
|
3
|
-
};
|
|
4
|
-
import defProps from "./formItem";
|
|
5
|
-
export const props = defineMixin({
|
|
6
|
-
props: {
|
|
7
|
-
// input的label提示语
|
|
8
|
-
label: {
|
|
9
|
-
type: String,
|
|
10
|
-
default: () => defProps.formItem.label
|
|
11
|
-
},
|
|
12
|
-
// 绑定的值
|
|
13
|
-
prop: {
|
|
14
|
-
type: String,
|
|
15
|
-
default: () => defProps.formItem.prop
|
|
16
|
-
},
|
|
17
|
-
// 绑定的规则
|
|
18
|
-
rules: {
|
|
19
|
-
type: Array,
|
|
20
|
-
default: () => defProps.formItem.rules
|
|
21
|
-
},
|
|
22
|
-
// 是否显示表单域的下划线边框
|
|
23
|
-
borderBottom: {
|
|
24
|
-
type: [String, Boolean],
|
|
25
|
-
default: () => defProps.formItem.borderBottom
|
|
26
|
-
},
|
|
27
|
-
// label的位置,left-左边,top-上边
|
|
28
|
-
labelPosition: {
|
|
29
|
-
type: String,
|
|
30
|
-
default: () => defProps.formItem.labelPosition
|
|
31
|
-
},
|
|
32
|
-
// label的宽度,单位px
|
|
33
|
-
labelWidth: {
|
|
34
|
-
type: [String, Number],
|
|
35
|
-
default: () => defProps.formItem.labelWidth
|
|
36
|
-
},
|
|
37
|
-
// 右侧图标
|
|
38
|
-
rightIcon: {
|
|
39
|
-
type: String,
|
|
40
|
-
default: () => defProps.formItem.rightIcon
|
|
41
|
-
},
|
|
42
|
-
// 左侧图标
|
|
43
|
-
leftIcon: {
|
|
44
|
-
type: String,
|
|
45
|
-
default: () => defProps.formItem.leftIcon
|
|
46
|
-
},
|
|
47
|
-
// 是否显示左边的必填星号,只作显示用,具体校验必填的逻辑,请在rules中配置
|
|
48
|
-
required: {
|
|
49
|
-
type: Boolean,
|
|
50
|
-
default: () => defProps.formItem.required
|
|
51
|
-
},
|
|
52
|
-
leftIconStyle: {
|
|
53
|
-
type: [String, Object],
|
|
54
|
-
default: () => defProps.formItem.leftIconStyle
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view
|
|
3
|
-
class="u-form-item"
|
|
4
|
-
:class="{
|
|
5
|
-
'u-form-item--error': !!message && parentData.errorType === 'message'
|
|
6
|
-
}"
|
|
7
|
-
>
|
|
8
|
-
<view
|
|
9
|
-
class="u-form-item__body"
|
|
10
|
-
@tap="clickHandler"
|
|
11
|
-
:style="[
|
|
12
|
-
customStyle,
|
|
13
|
-
{
|
|
14
|
-
flexDirection:
|
|
15
|
-
(labelPosition || parentData.labelPosition) === 'left'
|
|
16
|
-
? 'row'
|
|
17
|
-
: 'column'
|
|
18
|
-
}
|
|
19
|
-
]"
|
|
20
|
-
>
|
|
21
|
-
<!-- 微信小程序中,将一个参数设置空字符串,结果会变成字符串"true" -->
|
|
22
|
-
<slot name="label">
|
|
23
|
-
<!-- {{required}} -->
|
|
24
|
-
<view
|
|
25
|
-
class="u-form-item__body__left"
|
|
26
|
-
v-if="required || leftIcon || label"
|
|
27
|
-
:style="{
|
|
28
|
-
width: addUnit(labelWidth || parentData.labelWidth),
|
|
29
|
-
marginBottom: parentData.labelPosition === 'left' ? 0 : '5px'
|
|
30
|
-
}"
|
|
31
|
-
>
|
|
32
|
-
<!-- 为了块对齐 -->
|
|
33
|
-
<view class="u-form-item__body__left__content">
|
|
34
|
-
<!-- nvue不支持伪元素before -->
|
|
35
|
-
<text
|
|
36
|
-
v-if="required"
|
|
37
|
-
class="u-form-item__body__left__content__required"
|
|
38
|
-
>*</text
|
|
39
|
-
>
|
|
40
|
-
<view
|
|
41
|
-
class="u-form-item__body__left__content__icon"
|
|
42
|
-
v-if="leftIcon"
|
|
43
|
-
>
|
|
44
|
-
<u-icon :name="leftIcon" :custom-style="leftIconStyle"></u-icon>
|
|
45
|
-
</view>
|
|
46
|
-
<text
|
|
47
|
-
class="u-form-item__body__left__content__label"
|
|
48
|
-
:style="[
|
|
49
|
-
parentData.labelStyle,
|
|
50
|
-
{
|
|
51
|
-
justifyContent:
|
|
52
|
-
parentData.labelAlign === 'left'
|
|
53
|
-
? 'flex-start'
|
|
54
|
-
: parentData.labelAlign === 'center'
|
|
55
|
-
? 'center'
|
|
56
|
-
: 'flex-end'
|
|
57
|
-
}
|
|
58
|
-
]"
|
|
59
|
-
>{{ label }}</text
|
|
60
|
-
>
|
|
61
|
-
</view>
|
|
62
|
-
</view>
|
|
63
|
-
</slot>
|
|
64
|
-
<view class="u-form-item__body__right">
|
|
65
|
-
<view class="u-form-item__body__right__content">
|
|
66
|
-
<view class="u-form-item__body__right__content__slot">
|
|
67
|
-
<slot />
|
|
68
|
-
</view>
|
|
69
|
-
<view class="item__body__right__content__icon" v-if="$slots.right">
|
|
70
|
-
<slot name="right" />
|
|
71
|
-
</view>
|
|
72
|
-
</view>
|
|
73
|
-
</view>
|
|
74
|
-
</view>
|
|
75
|
-
<slot name="error">
|
|
76
|
-
<text
|
|
77
|
-
v-if="!!message && parentData.errorType === 'message'"
|
|
78
|
-
class="u-form-item__body__right__message"
|
|
79
|
-
:style="{
|
|
80
|
-
marginLeft: addUnit(
|
|
81
|
-
parentData.labelPosition === 'top'
|
|
82
|
-
? 0
|
|
83
|
-
: labelWidth || parentData.labelWidth
|
|
84
|
-
)
|
|
85
|
-
}"
|
|
86
|
-
>{{ message }}</text
|
|
87
|
-
>
|
|
88
|
-
</slot>
|
|
89
|
-
<u-line
|
|
90
|
-
v-if="borderBottom"
|
|
91
|
-
:color="
|
|
92
|
-
message && parentData.errorType === 'border-bottom'
|
|
93
|
-
? error
|
|
94
|
-
: propsLine.color
|
|
95
|
-
"
|
|
96
|
-
:customStyle="`margin-top: ${
|
|
97
|
-
message && parentData.errorType === 'message' ? '5px' : 0
|
|
98
|
-
}`"
|
|
99
|
-
></u-line>
|
|
100
|
-
</view>
|
|
101
|
-
</template>
|
|
102
|
-
|
|
103
|
-
<script>
|
|
104
|
-
import { props } from "./props";
|
|
105
|
-
// import defProps from "../../libs/config/props.js";
|
|
106
|
-
import { ColorConfig } from "../../config";
|
|
107
|
-
import { getProperty, setProperty } from "../u-form/utils";
|
|
108
|
-
import { addUnit, error } from "../../utils";
|
|
109
|
-
/**
|
|
110
|
-
* Form 表单
|
|
111
|
-
* @description 此组件一般用于表单场景,可以配置Input输入框,Select弹出框,进行表单验证等。
|
|
112
|
-
* @tutorial https://ijry.github.io/uview-plus/components/form.html
|
|
113
|
-
* @property {String} label input的label提示语
|
|
114
|
-
* @property {String} prop 绑定的值
|
|
115
|
-
* @property {Array} rules 绑定的规则
|
|
116
|
-
* @property {String | Boolean} borderBottom 是否显示表单域的下划线边框
|
|
117
|
-
* @property {String | Number} labelWidth label的宽度,单位px
|
|
118
|
-
* @property {String} rightIcon 右侧图标
|
|
119
|
-
* @property {String} leftIcon 左侧图标
|
|
120
|
-
* @property {String | Object} leftIconStyle 左侧图标的样式
|
|
121
|
-
* @property {Boolean} required 是否显示左边的必填星号,只作显示用,具体校验必填的逻辑,请在rules中配置 (默认 false )
|
|
122
|
-
*
|
|
123
|
-
* @example <u-form-item label="姓名" prop="userInfo.name" borderBottom ref="item1"></u-form-item>
|
|
124
|
-
*/
|
|
125
|
-
export default {
|
|
126
|
-
name: "u-form-item",
|
|
127
|
-
mixins: [props],
|
|
128
|
-
provide() {
|
|
129
|
-
return {
|
|
130
|
-
uFormItem: this.$props
|
|
131
|
-
};
|
|
132
|
-
},
|
|
133
|
-
data() {
|
|
134
|
-
return {
|
|
135
|
-
// 错误提示语
|
|
136
|
-
message: "",
|
|
137
|
-
parentData: {
|
|
138
|
-
// 提示文本的位置
|
|
139
|
-
labelPosition: "left",
|
|
140
|
-
// 提示文本对齐方式
|
|
141
|
-
labelAlign: "left",
|
|
142
|
-
// 提示文本的样式
|
|
143
|
-
labelStyle: {},
|
|
144
|
-
// 提示文本的宽度
|
|
145
|
-
labelWidth: 45,
|
|
146
|
-
// 错误提示方式
|
|
147
|
-
errorType: "message"
|
|
148
|
-
},
|
|
149
|
-
color: ColorConfig.error,
|
|
150
|
-
itemRules: []
|
|
151
|
-
};
|
|
152
|
-
},
|
|
153
|
-
// 组件创建完成时,将当前实例保存到u-form中
|
|
154
|
-
computed: {
|
|
155
|
-
propsLine() {
|
|
156
|
-
return "";
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
mounted() {
|
|
160
|
-
this.init();
|
|
161
|
-
},
|
|
162
|
-
emits: ["click"],
|
|
163
|
-
watch: {
|
|
164
|
-
// 监听规则的变化
|
|
165
|
-
rules: {
|
|
166
|
-
immediate: true,
|
|
167
|
-
handler(n) {
|
|
168
|
-
this.setRules(n);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
methods: {
|
|
173
|
-
addUnit,
|
|
174
|
-
init() {
|
|
175
|
-
// 父组件的实例
|
|
176
|
-
this.updateParentData();
|
|
177
|
-
if (!this.parent) {
|
|
178
|
-
error("u-form-item需要结合u-form组件使用");
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
// 手动设置校验的规则,如果规则中有函数的话,微信小程序中会过滤掉,所以只能手动调用设置规则
|
|
182
|
-
setRules(rules) {
|
|
183
|
-
// 判断是否有规则
|
|
184
|
-
if (rules.length === 0) {
|
|
185
|
-
this.itemRules = [];
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
this.itemRules = rules;
|
|
189
|
-
},
|
|
190
|
-
// 获取父组件的参数
|
|
191
|
-
updateParentData() {
|
|
192
|
-
// 此方法写在mixin中
|
|
193
|
-
this.getParentData("u-form");
|
|
194
|
-
},
|
|
195
|
-
// 移除u-form-item的校验结果
|
|
196
|
-
clearValidate() {
|
|
197
|
-
this.message = null;
|
|
198
|
-
},
|
|
199
|
-
// 清空当前的组件的校验结果,并重置为初始值
|
|
200
|
-
resetField() {
|
|
201
|
-
// 找到原始值
|
|
202
|
-
const value = getProperty(this.parent.originalModel, this.prop);
|
|
203
|
-
// 将u-form的model的prop属性链还原原始值
|
|
204
|
-
setProperty(this.parent.model, this.prop, value);
|
|
205
|
-
// 移除校验结果
|
|
206
|
-
this.message = null;
|
|
207
|
-
},
|
|
208
|
-
// 点击组件
|
|
209
|
-
clickHandler() {
|
|
210
|
-
this.$emit("click");
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
</script>
|
|
215
|
-
|
|
216
|
-
<style lang="scss" scoped>
|
|
217
|
-
@import "../../libs/css/mixin.scss";
|
|
218
|
-
@import "../../theme.scss";
|
|
219
|
-
|
|
220
|
-
.u-form-item {
|
|
221
|
-
@include flex(column);
|
|
222
|
-
font-size: 14px;
|
|
223
|
-
color: #303133ff;
|
|
224
|
-
|
|
225
|
-
&__body {
|
|
226
|
-
@include flex;
|
|
227
|
-
padding: 10px 0;
|
|
228
|
-
|
|
229
|
-
&__left {
|
|
230
|
-
@include flex;
|
|
231
|
-
align-items: center;
|
|
232
|
-
|
|
233
|
-
&__content {
|
|
234
|
-
position: relative;
|
|
235
|
-
@include flex;
|
|
236
|
-
align-items: center;
|
|
237
|
-
padding-right: 10rpx;
|
|
238
|
-
flex: 1;
|
|
239
|
-
|
|
240
|
-
&__icon {
|
|
241
|
-
margin-right: 8rpx;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
&__required {
|
|
245
|
-
position: absolute;
|
|
246
|
-
left: -9px;
|
|
247
|
-
color: $hy-error;
|
|
248
|
-
line-height: 20px;
|
|
249
|
-
font-size: 20px;
|
|
250
|
-
top: 3px;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
&__label {
|
|
254
|
-
@include flex;
|
|
255
|
-
align-items: center;
|
|
256
|
-
flex: 1;
|
|
257
|
-
color: #303133ff;
|
|
258
|
-
font-size: 15px;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
&__right {
|
|
264
|
-
flex: 1;
|
|
265
|
-
|
|
266
|
-
&__content {
|
|
267
|
-
@include flex;
|
|
268
|
-
align-items: center;
|
|
269
|
-
flex: 1;
|
|
270
|
-
|
|
271
|
-
&__slot {
|
|
272
|
-
flex: 1;
|
|
273
|
-
/* #ifndef MP */
|
|
274
|
-
@include flex;
|
|
275
|
-
align-items: center;
|
|
276
|
-
/* #endif */
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
&__icon {
|
|
280
|
-
margin-left: 10rpx;
|
|
281
|
-
color: #c0c4ccff;
|
|
282
|
-
font-size: 30rpx;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
&__message {
|
|
287
|
-
font-size: 12px;
|
|
288
|
-
line-height: 12px;
|
|
289
|
-
color: $hy-error;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
</style>
|