hy-app 0.1.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/README.md +42 -0
- package/api/http.ts +138 -0
- package/api/index.ts +1 -0
- package/common/index.ts +1 -0
- package/common/versionControl.ts +102 -0
- package/components/dialog/TheDialog.vue +128 -0
- package/components/dialog/index.ts +38 -0
- package/components/hy-address-picker/hy-address-picker.vue +262 -0
- package/components/hy-address-picker/props.ts +27 -0
- package/components/hy-address-picker/typing.d.ts +98 -0
- package/components/hy-avatar/hy-avatar.vue +217 -0
- package/components/hy-avatar/props.ts +20 -0
- package/components/hy-avatar/typing.d.ts +64 -0
- package/components/hy-back-top/hy-back-top.vue +71 -0
- package/components/hy-back-top/props.ts +23 -0
- package/components/hy-back-top/typing.d.ts +49 -0
- package/components/hy-badge/hy-badge.vue +155 -0
- package/components/hy-badge/props.ts +19 -0
- package/components/hy-badge/typing.d.ts +60 -0
- package/components/hy-button/hy-button.vue +394 -0
- package/components/hy-button/props.ts +36 -0
- package/components/hy-button/typing.d.ts +125 -0
- package/components/hy-card/hy-card.vue +198 -0
- package/components/hy-card/props.ts +29 -0
- package/components/hy-card/typing.d.ts +112 -0
- package/components/hy-cell/hy-cell.vue +268 -0
- package/components/hy-cell/props.ts +20 -0
- package/components/hy-cell/typing.d.ts +98 -0
- package/components/hy-check-button/hy-check-button.vue +71 -0
- package/components/hy-check-button/props.ts +20 -0
- package/components/hy-check-button/typing.d.ts +79 -0
- package/components/hy-checkbox/hy-checkbox.vue +299 -0
- package/components/hy-checkbox/props.ts +28 -0
- package/components/hy-checkbox/typing.d.ts +77 -0
- package/components/hy-datetime-picker/hy-datetime-picker.vue +584 -0
- package/components/hy-datetime-picker/props.ts +36 -0
- package/components/hy-datetime-picker/typing.d.ts +135 -0
- package/components/hy-divider/hy-divider.vue +164 -0
- package/components/hy-divider/props.ts +21 -0
- package/components/hy-divider/typing.d.ts +64 -0
- package/components/hy-empty/hy-empty.vue +122 -0
- package/components/hy-empty/props.ts +21 -0
- package/components/hy-empty/typing.d.ts +68 -0
- package/components/hy-folding-panel/hy-folding-panel.vue +94 -0
- package/components/hy-folding-panel/props.ts +17 -0
- package/components/hy-folding-panel/typing.d.ts +59 -0
- package/components/hy-form/hy-form.vue +372 -0
- package/components/hy-form/props.ts +15 -0
- package/components/hy-form/typing.d.ts +51 -0
- package/components/hy-grid/hy-grid.vue +126 -0
- package/components/hy-grid/props.ts +16 -0
- package/components/hy-grid/typing.d.ts +62 -0
- package/components/hy-icon/hy-icon.vue +207 -0
- package/components/hy-icon/props.ts +24 -0
- package/components/hy-icon/typing.d.ts +80 -0
- package/components/hy-input/hy-input.vue +402 -0
- package/components/hy-input/props.ts +41 -0
- package/components/hy-input/typing.d.ts +148 -0
- package/components/hy-line/hy-line.vue +44 -0
- package/components/hy-line/props.ts +12 -0
- package/components/hy-line/typing.d.ts +32 -0
- package/components/hy-line-progress/hy-line-progress.vue +118 -0
- package/components/hy-line-progress/props.ts +12 -0
- package/components/hy-line-progress/typing.d.ts +28 -0
- package/components/hy-list/hy-list.vue +250 -0
- package/components/hy-list/props.ts +18 -0
- package/components/hy-list/typing.d.ts +50 -0
- package/components/hy-login/ThePhoneLogin.vue +106 -0
- package/components/hy-login/TheUserLogin.vue +391 -0
- package/components/hy-login/hy-login.vue +283 -0
- package/components/hy-login/props.ts +32 -0
- package/components/hy-login/typing.d.ts +60 -0
- package/components/hy-modal/hy-modal.vue +240 -0
- package/components/hy-modal/props.ts +24 -0
- package/components/hy-modal/typing.d.ts +70 -0
- package/components/hy-navbar/hy-navbar.vue +194 -0
- package/components/hy-navbar/props.ts +24 -0
- package/components/hy-navbar/typing.d.ts +81 -0
- package/components/hy-notice-bar/hy-column-notice.vue +130 -0
- package/components/hy-notice-bar/hy-notice-bar.vue +82 -0
- package/components/hy-notice-bar/hy-row-notice.vue +182 -0
- package/components/hy-notice-bar/props.ts +19 -0
- package/components/hy-notice-bar/typing.d.ts +56 -0
- package/components/hy-number-step/hy-number-step.vue +428 -0
- package/components/hy-number-step/props.ts +29 -0
- package/components/hy-number-step/typing.d.ts +104 -0
- package/components/hy-overlay/hy-overlay.vue +54 -0
- package/components/hy-overlay/props.ts +10 -0
- package/components/hy-overlay/typing.d.ts +24 -0
- package/components/hy-picker/hy-picker.vue +499 -0
- package/components/hy-picker/props.ts +30 -0
- package/components/hy-picker/typing.d.ts +115 -0
- package/components/hy-popup/hy-popup.vue +269 -0
- package/components/hy-popup/props.ts +21 -0
- package/components/hy-popup/typing.d.ts +68 -0
- package/components/hy-price/hy-price.vue +86 -0
- package/components/hy-price/props.ts +13 -0
- package/components/hy-price/typing.d.ts +36 -0
- package/components/hy-qrcode/hy-qrcode.vue +153 -0
- package/components/hy-qrcode/props.ts +20 -0
- package/components/hy-qrcode/qrcode.js +1364 -0
- package/components/hy-qrcode/typing.d.ts +64 -0
- package/components/hy-radio/hy-radio.vue +319 -0
- package/components/hy-radio/props.ts +28 -0
- package/components/hy-radio/typing.d.ts +85 -0
- package/components/hy-rate/hy-rate.vue +261 -0
- package/components/hy-rate/props.ts +18 -0
- package/components/hy-rate/typing.d.ts +60 -0
- package/components/hy-read-more/hy-read-more.vue +134 -0
- package/components/hy-read-more/props.ts +20 -0
- package/components/hy-read-more/typing.d.ts +44 -0
- package/components/hy-safe-bottom/hy-safe-bottom.vue +64 -0
- package/components/hy-scroll-list/hy-scroll-list.vue +146 -0
- package/components/hy-scroll-list/props.ts +12 -0
- package/components/hy-scroll-list/typing.d.ts +28 -0
- package/components/hy-search/hy-search.vue +294 -0
- package/components/hy-search/props.ts +29 -0
- package/components/hy-search/typing.d.ts +109 -0
- package/components/hy-slider/hy-slider.vue +511 -0
- package/components/hy-slider/props.ts +21 -0
- package/components/hy-slider/typing.d.ts +68 -0
- package/components/hy-steps/hy-steps.vue +352 -0
- package/components/hy-steps/props.ts +15 -0
- package/components/hy-steps/typing.d.ts +58 -0
- package/components/hy-subsection/hy-subsection.vue +272 -0
- package/components/hy-subsection/props.ts +16 -0
- package/components/hy-subsection/typing.d.ts +44 -0
- package/components/hy-swiper/hy-swiper-indicator.vue +105 -0
- package/components/hy-swiper/hy-swiper.vue +242 -0
- package/components/hy-swiper/props.ts +30 -0
- package/components/hy-swiper/typing.d.ts +107 -0
- package/components/hy-switch/hy-switch.vue +168 -0
- package/components/hy-switch/props.ts +16 -0
- package/components/hy-switch/typing.d.ts +48 -0
- package/components/hy-tabs/hy-tabs.vue +416 -0
- package/components/hy-tabs/props.ts +26 -0
- package/components/hy-tabs/typing.d.ts +86 -0
- package/components/hy-tag/hy-tag.vue +374 -0
- package/components/hy-tag/props.ts +22 -0
- package/components/hy-tag/typing.d.ts +76 -0
- package/components/hy-textarea/hy-textarea.vue +229 -0
- package/components/hy-textarea/props.ts +26 -0
- package/components/hy-textarea/typing.d.ts +27 -0
- package/components/hy-tooltip/hy-tooltip.vue +332 -0
- package/components/hy-tooltip/props.ts +17 -0
- package/components/hy-tooltip/typing.d.ts +52 -0
- package/components/hy-transition/hy-transition.vue +150 -0
- package/components/hy-transition/index.scss +113 -0
- package/components/hy-transition/props.ts +10 -0
- package/components/hy-transition/typing.d.ts +36 -0
- package/components/hy-upload/hy-upload.vue +557 -0
- package/components/hy-upload/props.ts +29 -0
- package/components/hy-upload/typing.d.ts +147 -0
- package/components/hy-warn/hy-warn.vue +228 -0
- package/components/hy-warn/props.ts +14 -0
- package/components/hy-warn/typing.d.ts +40 -0
- package/components/hy-waterfall/hy-waterfall.vue +51 -0
- package/components/hy-waterfall/props.ts +10 -0
- package/components/hy-waterfall/typing.d.ts +20 -0
- package/components/index.ts +162 -0
- package/components/message/TheMessage.vue +169 -0
- package/components/message/index.ts +54 -0
- package/components/u-form/form.js +22 -0
- package/components/u-form/hy-form.vue +324 -0
- package/components/u-form/props.js +49 -0
- package/components/u-form/schema.js +1451 -0
- package/components/u-form/u-form.vue +267 -0
- package/components/u-form/utils.js +65 -0
- package/components/u-form-item/formItem.js +24 -0
- package/components/u-form-item/hy-form-item.vue +360 -0
- package/components/u-form-item/props.js +57 -0
- package/components/u-form-item/u-form-item.vue +294 -0
- package/components/yk-dialog/yk-dialog.vue +129 -0
- package/components/yk-tabbar/props.ts +49 -0
- package/components/yk-tabbar/yk-tabbar.vue +224 -0
- package/config/color.ts +6 -0
- package/config/icon.ts +366 -0
- package/config/index.ts +2 -0
- package/global/index.ts +6 -0
- package/global/register-properties.ts +37 -0
- package/index.ts +8 -0
- package/libs/css/common.scss +0 -0
- package/libs/css/iconfont.css +379 -0
- package/libs/css/iconfont.ttf +0 -0
- package/libs/css/mixin.scss +15 -0
- package/package.json +42 -0
- package/public/icons/error.png +0 -0
- package/public/icons/success.png +0 -0
- package/public/icons/warning.png +0 -0
- package/store/index.ts +1 -0
- package/store/userInfo.ts +25 -0
- package/theme.scss +94 -0
- package/typing/index.ts +7 -0
- package/typing/modules/common.d.ts +50 -0
- package/typing/modules/dialog.ts +17 -0
- package/typing/modules/enum.ts +67 -0
- package/typing/modules/form.ts +161 -0
- package/typing/modules/http.ts +68 -0
- package/typing/modules/icon.d.ts +366 -0
- package/typing/modules/img.ts +15 -0
- package/typing/modules/rect.ts +10 -0
- package/utils/address.json +5890 -0
- package/utils/base64.ts +119 -0
- package/utils/index.ts +3 -0
- package/utils/inside.ts +310 -0
- package/utils/utils.ts +446 -0
|
@@ -0,0 +1,360 @@
|
|
|
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>
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,294 @@
|
|
|
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>
|