uview-pro 0.0.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.
Files changed (149) hide show
  1. package/changelog.md +6 -0
  2. package/components/u-action-sheet/u-action-sheet.vue +205 -0
  3. package/components/u-alert-tips/u-alert-tips.vue +241 -0
  4. package/components/u-avatar/u-avatar.vue +220 -0
  5. package/components/u-avatar-cropper/u-avatar-cropper.vue +329 -0
  6. package/components/u-avatar-cropper/weCropper.d.ts +54 -0
  7. package/components/u-avatar-cropper/weCropper.js +1267 -0
  8. package/components/u-avatar-cropper/weCropper.ts +1254 -0
  9. package/components/u-back-top/u-back-top.vue +156 -0
  10. package/components/u-badge/u-badge.vue +189 -0
  11. package/components/u-button/u-button.vue +562 -0
  12. package/components/u-calendar/u-calendar.vue +725 -0
  13. package/components/u-car-keyboard/u-car-keyboard.vue +236 -0
  14. package/components/u-card/u-card.vue +240 -0
  15. package/components/u-cell-group/u-cell-group.vue +56 -0
  16. package/components/u-cell-item/u-cell-item.vue +245 -0
  17. package/components/u-checkbox/u-checkbox.vue +310 -0
  18. package/components/u-checkbox-group/u-checkbox-group.vue +134 -0
  19. package/components/u-circle-progress/u-circle-progress.vue +210 -0
  20. package/components/u-col/u-col.vue +135 -0
  21. package/components/u-collapse/u-collapse.vue +82 -0
  22. package/components/u-collapse-item/u-collapse-item.vue +190 -0
  23. package/components/u-column-notice/u-column-notice.vue +264 -0
  24. package/components/u-count-down/u-count-down.vue +333 -0
  25. package/components/u-count-to/u-count-to.vue +297 -0
  26. package/components/u-divider/u-divider.vue +141 -0
  27. package/components/u-dropdown/u-dropdown.vue +311 -0
  28. package/components/u-dropdown-item/u-dropdown-item.vue +135 -0
  29. package/components/u-empty/u-empty.vue +111 -0
  30. package/components/u-field/u-field.vue +469 -0
  31. package/components/u-form/u-form.vue +162 -0
  32. package/components/u-form-item/u-form-item.vue +476 -0
  33. package/components/u-full-screen/u-full-screen.vue +80 -0
  34. package/components/u-gap/u-gap.vue +48 -0
  35. package/components/u-grid/u-grid.vue +101 -0
  36. package/components/u-grid-item/u-grid-item.vue +136 -0
  37. package/components/u-icon/u-icon.vue +389 -0
  38. package/components/u-image/types.ts +48 -0
  39. package/components/u-image/u-image.vue +218 -0
  40. package/components/u-index-anchor/u-index-anchor.vue +101 -0
  41. package/components/u-index-list/u-index-list.vue +376 -0
  42. package/components/u-input/u-input.vue +462 -0
  43. package/components/u-keyboard/u-keyboard.vue +188 -0
  44. package/components/u-lazy-load/u-lazy-load.vue +288 -0
  45. package/components/u-line/u-line.vue +71 -0
  46. package/components/u-line-progress/u-line-progress.vue +128 -0
  47. package/components/u-link/u-link.vue +87 -0
  48. package/components/u-loading/u-loading.vue +111 -0
  49. package/components/u-loadmore/u-loadmore.vue +205 -0
  50. package/components/u-mask/u-mask.vue +137 -0
  51. package/components/u-message-input/u-message-input.vue +315 -0
  52. package/components/u-modal/u-modal.vue +284 -0
  53. package/components/u-navbar/u-navbar.vue +314 -0
  54. package/components/u-no-network/image.ts +2 -0
  55. package/components/u-no-network/u-no-network.vue +311 -0
  56. package/components/u-notice-bar/u-notice-bar.vue +274 -0
  57. package/components/u-number-box/u-number-box.vue +344 -0
  58. package/components/u-number-keyboard/u-number-keyboard.vue +170 -0
  59. package/components/u-parse/libs/CssHandler.js +100 -0
  60. package/components/u-parse/libs/MpHtmlParser.js +580 -0
  61. package/components/u-parse/libs/config.js +80 -0
  62. package/components/u-parse/libs/handler.wxs +22 -0
  63. package/components/u-parse/libs/trees.vue +505 -0
  64. package/components/u-parse/u-parse.vue +645 -0
  65. package/components/u-picker/u-picker.vue +808 -0
  66. package/components/u-popup/u-popup.vue +404 -0
  67. package/components/u-radio/u-radio.vue +272 -0
  68. package/components/u-radio-group/u-radio-group.vue +116 -0
  69. package/components/u-rate/u-rate.vue +349 -0
  70. package/components/u-read-more/u-read-more.vue +199 -0
  71. package/components/u-row/u-row.vue +95 -0
  72. package/components/u-row-notice/u-row-notice.vue +273 -0
  73. package/components/u-search/u-search.vue +298 -0
  74. package/components/u-section/u-section.vue +175 -0
  75. package/components/u-select/u-select.vue +387 -0
  76. package/components/u-skeleton/u-skeleton.vue +230 -0
  77. package/components/u-slider/u-slider.vue +293 -0
  78. package/components/u-steps/u-steps.vue +200 -0
  79. package/components/u-sticky/u-sticky.vue +189 -0
  80. package/components/u-subsection/u-subsection.vue +388 -0
  81. package/components/u-swipe-action/u-swipe-action.vue +289 -0
  82. package/components/u-swiper/u-swiper.vue +305 -0
  83. package/components/u-switch/u-switch.vue +146 -0
  84. package/components/u-tabbar/u-tabbar.vue +347 -0
  85. package/components/u-table/u-table.vue +104 -0
  86. package/components/u-tabs/u-tabs.vue +322 -0
  87. package/components/u-tabs-swiper/u-tabs-swiper.vue +426 -0
  88. package/components/u-tag/u-tag.vue +270 -0
  89. package/components/u-td/u-td.vue +76 -0
  90. package/components/u-th/u-th.vue +70 -0
  91. package/components/u-time-line/u-time-line.vue +39 -0
  92. package/components/u-time-line-item/u-time-line-item.vue +88 -0
  93. package/components/u-toast/types.ts +4 -0
  94. package/components/u-toast/u-toast.vue +238 -0
  95. package/components/u-top-tips/u-top-tips.vue +118 -0
  96. package/components/u-tr/u-tr.vue +24 -0
  97. package/components/u-upload/u-upload.vue +600 -0
  98. package/components/u-verification-code/u-verification-code.vue +194 -0
  99. package/components/u-waterfall/u-waterfall.vue +186 -0
  100. package/iconfont.css +910 -0
  101. package/index.scss +23 -0
  102. package/index.ts +166 -0
  103. package/libs/config/config.ts +26 -0
  104. package/libs/config/zIndex.ts +37 -0
  105. package/libs/css/color.scss +155 -0
  106. package/libs/css/common.scss +176 -0
  107. package/libs/css/style.components.scss +7 -0
  108. package/libs/css/style.h5.scss +8 -0
  109. package/libs/css/style.mp.scss +72 -0
  110. package/libs/css/style.nvue.scss +3 -0
  111. package/libs/css/style.vue.scss +175 -0
  112. package/libs/function/$parent.ts +22 -0
  113. package/libs/function/addUnit.ts +13 -0
  114. package/libs/function/color.ts +37 -0
  115. package/libs/function/colorGradient.ts +123 -0
  116. package/libs/function/debounce.ts +28 -0
  117. package/libs/function/deepClone.ts +39 -0
  118. package/libs/function/deepMerge.ts +34 -0
  119. package/libs/function/getParent.ts +59 -0
  120. package/libs/function/getRect.ts +26 -0
  121. package/libs/function/guid.ts +42 -0
  122. package/libs/function/md5.ts +397 -0
  123. package/libs/function/parent.ts +21 -0
  124. package/libs/function/queryParams.ts +60 -0
  125. package/libs/function/random.ts +16 -0
  126. package/libs/function/randomArray.ts +11 -0
  127. package/libs/function/route.ts +118 -0
  128. package/libs/function/sys.ts +15 -0
  129. package/libs/function/test.ts +229 -0
  130. package/libs/function/throttle.ts +31 -0
  131. package/libs/function/timeFormat.ts +54 -0
  132. package/libs/function/timeFrom.ts +48 -0
  133. package/libs/function/toast.ts +14 -0
  134. package/libs/function/trim.ts +21 -0
  135. package/libs/function/type2icon.ts +36 -0
  136. package/libs/hooks/useEmitter.ts +77 -0
  137. package/libs/hooks/useParent.ts +29 -0
  138. package/libs/request/index.ts +237 -0
  139. package/libs/store/index.ts +88 -0
  140. package/libs/util/area.ts +1 -0
  141. package/libs/util/async-validator.js +1356 -0
  142. package/libs/util/city.ts +1 -0
  143. package/libs/util/emitter.ts +112 -0
  144. package/libs/util/mitt.ts +118 -0
  145. package/libs/util/parent.ts +20 -0
  146. package/libs/util/province.ts +1 -0
  147. package/package.json +98 -0
  148. package/readme.md +165 -0
  149. package/theme.scss +38 -0
@@ -0,0 +1,404 @@
1
+ <template>
2
+ <view v-if="visibleSync" :style="[customStyle, { zIndex: Number(uZindex) - 1 }]" class="u-drawer" hover-stop-propagation>
3
+ <u-mask
4
+ :duration="duration"
5
+ :custom-style="maskCustomStyle"
6
+ :maskClickAble="maskCloseAble"
7
+ :z-index="Number(uZindex) - 2"
8
+ :show="showDrawer && mask"
9
+ @click="maskClick"
10
+ ></u-mask>
11
+ <view
12
+ class="u-drawer-content"
13
+ @tap="modeCenterClose(mode)"
14
+ :class="[
15
+ safeAreaInsetBottom ? 'safe-area-inset-bottom' : '',
16
+ 'u-drawer-' + mode,
17
+ showDrawer ? 'u-drawer-content-visible' : '',
18
+ zoom && mode == 'center' ? 'u-animation-zoom' : ''
19
+ ]"
20
+ @touchmove.stop.prevent
21
+ @tap.stop.prevent
22
+ :style="[style]"
23
+ >
24
+ <view class="u-mode-center-box" @tap.stop.prevent @touchmove.stop.prevent v-if="mode == 'center'" :style="[centerStyle]">
25
+ <u-icon
26
+ @click="close"
27
+ v-if="closeable"
28
+ class="u-close"
29
+ :class="['u-close--' + closeIconPos]"
30
+ :name="closeIcon"
31
+ :color="closeIconColor"
32
+ :size="closeIconSize"
33
+ ></u-icon>
34
+ <scroll-view class="u-drawer__scroll-view" scroll-y="true">
35
+ <slot />
36
+ </scroll-view>
37
+ </view>
38
+ <scroll-view class="u-drawer__scroll-view" scroll-y="true" v-else>
39
+ <slot />
40
+ </scroll-view>
41
+ <view @tap="close" class="u-close" :class="['u-close--' + closeIconPos]">
42
+ <u-icon v-if="mode != 'center' && closeable" :name="closeIcon" :color="closeIconColor" :size="closeIconSize"></u-icon>
43
+ </view>
44
+ </view>
45
+ </view>
46
+ </template>
47
+
48
+ <script setup lang="ts">
49
+ import { ref, computed, watch, onMounted, nextTick } from 'vue';
50
+ import { $u } from '../..';
51
+
52
+ defineOptions({
53
+ name: 'u-popup'
54
+ });
55
+
56
+ /**
57
+ * popup 弹窗
58
+ * @description 弹出层容器,用于展示弹窗、信息提示等内容,支持上、下、左、右和中部弹出。组件只提供容器,内部内容由用户自定义
59
+ * @tutorial https://www.uviewui.com/components/popup.html
60
+ * @property {String} mode 弹出方向(默认left)
61
+ * @property {Boolean} mask 是否显示遮罩(默认true)
62
+ * @property {Stringr | Number} length mode=left | 见官网说明(默认auto)
63
+ * @property {Boolean} zoom 是否开启缩放动画,只在mode为center时有效(默认true)
64
+ * @property {Boolean} safe-area-inset-bottom 是否开启底部安全区适配(默认false)
65
+ * @property {Boolean} mask-close-able 点击遮罩是否可以关闭弹出层(默认true)
66
+ * @property {Object} custom-style 用户自定义样式
67
+ * @property {Stringr | Number} negative-top 中部弹出时,往上偏移的值
68
+ * @property {Numberr | String} border-radius 弹窗圆角值(默认0)
69
+ * @property {Numberr | String} z-index 弹出内容的z-index值(默认1075)
70
+ * @property {Boolean} closeable 是否显示关闭图标(默认false)
71
+ * @property {String} close-icon 关闭图标的名称,只能uView的内置图标
72
+ * @property {String} close-icon-pos 自定义关闭图标位置(默认top-right)
73
+ * @property {String} close-icon-color 关闭图标的颜色(默认#909399)
74
+ * @property {Number | String} close-icon-size 关闭图标的大小,单位rpx(默认30)
75
+ * @event {Function} open 弹出层打开
76
+ * @event {Function} close 弹出层收起
77
+ * @example <u-popup v-model="show"><view>出淤泥而不染,濯清涟而不妖</view></u-popup>
78
+ */
79
+
80
+ const props = defineProps({
81
+ // 显示状态
82
+ show: { type: Boolean, default: false },
83
+ // 弹出方向,left|right|top|bottom|center
84
+ mode: { type: String, default: 'left' },
85
+ // 是否显示遮罩
86
+ mask: { type: Boolean, default: true },
87
+ // 抽屉的宽度(mode=left|right),或者高度(mode=top|bottom),单位rpx,或者"auto"
88
+ // 或者百分比"50%",表示由内容撑开高度或者宽度
89
+ length: { type: [Number, String], default: 'auto' },
90
+ // 是否开启缩放动画,只在mode=center时有效
91
+ zoom: { type: Boolean, default: true },
92
+ // 是否开启底部安全区适配,开启的话,会在iPhoneX机型底部添加一定的内边距
93
+ safeAreaInsetBottom: { type: Boolean, default: false },
94
+ // 是否可以通过点击遮罩进行关闭
95
+ maskCloseAble: { type: Boolean, default: true },
96
+ // 用户自定义样式
97
+ customStyle: { type: Object, default: () => ({}) },
98
+ modelValue: { type: Boolean, default: false },
99
+ // 此为内部参数,不在文档对外使用,为了解决Picker和keyboard等融合了弹窗的组件
100
+ // 对v-model双向绑定多层调用造成报错不能修改props值的问题
101
+ popup: { type: Boolean, default: true },
102
+ borderRadius: { type: [Number, String], default: 0 },
103
+ zIndex: { type: [Number, String], default: '' },
104
+ // 是否显示关闭图标
105
+ closeable: { type: Boolean, default: false },
106
+ // 关闭图标的名称,只能uView的内置图标
107
+ closeIcon: { type: String, default: 'close' },
108
+ // 自定义关闭图标位置,top-left为左上角,top-right为右上角,bottom-left为左下角,bottom-right为右下角
109
+ closeIconPos: { type: String, default: 'top-right' },
110
+ // 关闭图标的颜色
111
+ closeIconColor: { type: String, default: '#909399' },
112
+ // 关闭图标的大小,单位rpx
113
+ closeIconSize: { type: [String, Number], default: '30' },
114
+ // 宽度,只对左,右,中部弹出时起作用,单位rpx,或者"auto"
115
+ // 或者百分比"50%",表示由内容撑开高度或者宽度,优先级高于length参数
116
+ width: { type: String, default: '' },
117
+ // 高度,只对上,下,中部弹出时起作用,单位rpx,或者"auto"
118
+ // 或者百分比"50%",表示由内容撑开高度或者宽度,优先级高于length参数
119
+ height: { type: String, default: '' },
120
+ // 给一个负的margin-top,往上偏移,避免和键盘重合的情况,仅在mode=center时有效
121
+ negativeTop: { type: [String, Number], default: 0 },
122
+ // 遮罩的样式,一般用于修改遮罩的透明度
123
+ maskCustomStyle: { type: Object, default: () => ({}) },
124
+ // 遮罩打开或收起的动画过渡时间,单位ms
125
+ duration: { type: [String, Number], default: 250 }
126
+ });
127
+ const emit = defineEmits(['update:modelValue', 'open', 'close']);
128
+
129
+ // 组件内部状态
130
+ const visibleSync = ref(false);
131
+ const showDrawer = ref(false);
132
+ const timer = ref<ReturnType<typeof setTimeout> | null>(null);
133
+ const closeFromInner = ref(false); // value的值改变,是发生在内部还是外部
134
+ // 根据mode的位置,设定其弹窗的宽度(mode = left|right),或者高度(mode = top|bottom)
135
+ const style = computed(() => {
136
+ let style: Record<string, any> = {};
137
+ // 如果是左边或者上边弹出时,需要给translate设置为负值,用于隐藏
138
+ if (props.mode == 'left' || props.mode == 'right') {
139
+ style = {
140
+ width: props.width ? getUnitValue(props.width) : getUnitValue(props.length),
141
+ height: '100%',
142
+ transform: `translate3D(${props.mode == 'left' ? '-100%' : '100%'},0px,0px)`
143
+ };
144
+ } else if (props.mode == 'top' || props.mode == 'bottom') {
145
+ style = {
146
+ width: '100%',
147
+ height: props.height ? getUnitValue(props.height) : getUnitValue(props.length),
148
+ transform: `translate3D(0px,${props.mode == 'top' ? '-100%' : '100%'},0px)`
149
+ };
150
+ }
151
+ // 如果用户设置了borderRadius值,添加弹窗的圆角
152
+ style.zIndex = uZindex.value;
153
+ if (props.borderRadius) {
154
+ switch (props.mode) {
155
+ case 'left':
156
+ style.borderRadius = `0 ${props.borderRadius}rpx ${props.borderRadius}rpx 0`;
157
+ break;
158
+ case 'top':
159
+ style.borderRadius = `0 0 ${props.borderRadius}rpx ${props.borderRadius}rpx`;
160
+ break;
161
+ case 'right':
162
+ style.borderRadius = `${props.borderRadius}rpx 0 0 ${props.borderRadius}rpx`;
163
+ break;
164
+ case 'bottom':
165
+ style.borderRadius = `${props.borderRadius}rpx ${props.borderRadius}rpx 0 0`;
166
+ break;
167
+ default:
168
+ }
169
+ // 不加可能圆角无效
170
+ style.overflow = 'hidden';
171
+ }
172
+ if (props.duration) style.transition = `all ${Number(props.duration) / 1000}s linear`;
173
+ return style;
174
+ });
175
+
176
+ // 中部弹窗的特有样式
177
+ const centerStyle = computed(() => {
178
+ let style: Record<string, any> = {};
179
+ style.width = props.width ? getUnitValue(props.width) : getUnitValue(props.length);
180
+
181
+ // 中部弹出的模式,如果没有设置高度,就用auto值,由内容撑开高度
182
+ style.height = props.height ? getUnitValue(props.height) : 'auto';
183
+ style.zIndex = uZindex.value;
184
+ style.marginTop = `-${$u.addUnit(props.negativeTop)}`;
185
+ if (props.borderRadius) {
186
+ style.borderRadius = `${props.borderRadius}rpx`;
187
+ // 不加可能圆角无效
188
+ style.overflow = 'hidden';
189
+ }
190
+ return style;
191
+ });
192
+
193
+ // 计算整理后的z-index值
194
+ const uZindex = computed(() => (props.zIndex ? props.zIndex : $u.zIndex.popup));
195
+
196
+ watch(
197
+ () => props.modelValue,
198
+ val => {
199
+ if (val) {
200
+ open();
201
+ } else if (!closeFromInner.value) {
202
+ close();
203
+ }
204
+ closeFromInner.value = false;
205
+ }
206
+ );
207
+
208
+ onMounted(() => {
209
+ if (props.modelValue) open();
210
+ });
211
+
212
+ /**
213
+ * 判断传入的值,是否带有单位,如果没有,就默认用rpx单位
214
+ */
215
+ function getUnitValue(val: string | number) {
216
+ if (/(%|px|rpx|auto)$/.test(String(val))) return val;
217
+ else return val + 'rpx';
218
+ }
219
+
220
+ /**
221
+ * 遮罩被点击
222
+ */
223
+ function maskClick() {
224
+ close();
225
+ }
226
+
227
+ /**
228
+ * 关闭弹窗
229
+ */
230
+ function close() {
231
+ // 标记关闭是内部发生的,否则修改了value值,导致watch中对value检测,导致再执行一遍close
232
+ // 造成@close事件触发两次
233
+ closeFromInner.value = true;
234
+ change('showDrawer', 'visibleSync', false);
235
+ }
236
+
237
+ /**
238
+ * 中部弹出时,点击内容区域关闭弹窗
239
+ */
240
+ function modeCenterClose(mode: string) {
241
+ // 中部弹出时,需要.u-drawer-content将居中内容,此元素会铺满屏幕,点击需要关闭弹窗
242
+ // 让其只在mode=center时起作用
243
+ if (mode != 'center' || !props.maskCloseAble) return;
244
+ close();
245
+ }
246
+
247
+ /**
248
+ * 打开弹窗
249
+ */
250
+ function open() {
251
+ change('visibleSync', 'showDrawer', true);
252
+ }
253
+
254
+ /**
255
+ * 控制弹窗显示/隐藏的动画和状态
256
+ * 此处的原理是,关闭时先通过动画隐藏弹窗和遮罩,再移除整个组件
257
+ * 打开时,先渲染组件,延时一定时间再让遮罩和弹窗的动画起作用
258
+ */
259
+ function change(param1: 'showDrawer' | 'visibleSync', param2: 'visibleSync' | 'showDrawer', status: boolean) {
260
+ // 如果this.popup为false,意味着为picker,actionsheet等组件调用了popup组件
261
+ if (props.popup === true) {
262
+ emit('update:modelValue', status);
263
+ }
264
+ (param1 === 'showDrawer' ? showDrawer : visibleSync).value = status;
265
+ if (status) {
266
+ // #ifdef H5 || MP
267
+ timer.value = setTimeout(() => {
268
+ (param2 === 'showDrawer' ? showDrawer : visibleSync).value = status;
269
+ emit(status ? 'open' : 'close');
270
+ }, 50);
271
+ // #endif
272
+ // #ifndef H5 || MP
273
+ nextTick(() => {
274
+ (param2 === 'showDrawer' ? showDrawer : visibleSync).value = status;
275
+ emit(status ? 'open' : 'close');
276
+ });
277
+ // #endif
278
+ } else {
279
+ timer.value = setTimeout(() => {
280
+ (param2 === 'showDrawer' ? showDrawer : visibleSync).value = status;
281
+ emit(status ? 'open' : 'close');
282
+ }, Number(props.duration));
283
+ }
284
+ }
285
+ </script>
286
+
287
+ <style scoped lang="scss">
288
+ @import '../../libs/css/style.components.scss';
289
+
290
+ .u-drawer {
291
+ /* #ifndef APP-NVUE */
292
+ display: block;
293
+ /* #endif */
294
+ position: fixed;
295
+ top: 0;
296
+ left: 0;
297
+ right: 0;
298
+ bottom: 0;
299
+ overflow: hidden;
300
+ }
301
+
302
+ .u-drawer-content {
303
+ /* #ifndef APP-NVUE */
304
+ display: block;
305
+ /* #endif */
306
+ position: absolute;
307
+ z-index: 1003;
308
+ transition: all 0.25s linear;
309
+ }
310
+
311
+ .u-drawer__scroll-view {
312
+ width: 100%;
313
+ height: 100%;
314
+ }
315
+
316
+ .u-drawer-left {
317
+ top: 0;
318
+ bottom: 0;
319
+ left: 0;
320
+ background-color: #ffffff;
321
+ }
322
+
323
+ .u-drawer-right {
324
+ right: 0;
325
+ top: 0;
326
+ bottom: 0;
327
+ background-color: #ffffff;
328
+ }
329
+
330
+ .u-drawer-top {
331
+ top: 0;
332
+ left: 0;
333
+ right: 0;
334
+ background-color: #ffffff;
335
+ }
336
+
337
+ .u-drawer-bottom {
338
+ bottom: 0;
339
+ left: 0;
340
+ right: 0;
341
+ background-color: #ffffff;
342
+ }
343
+
344
+ .u-drawer-center {
345
+ @include vue-flex;
346
+ flex-direction: column;
347
+ bottom: 0;
348
+ left: 0;
349
+ right: 0;
350
+ top: 0;
351
+ justify-content: center;
352
+ align-items: center;
353
+ opacity: 0;
354
+ z-index: 99999;
355
+ }
356
+
357
+ .u-mode-center-box {
358
+ min-width: 100rpx;
359
+ min-height: 100rpx;
360
+ /* #ifndef APP-NVUE */
361
+ display: block;
362
+ /* #endif */
363
+ position: relative;
364
+ background-color: #ffffff;
365
+ }
366
+
367
+ .u-drawer-content-visible.u-drawer-center {
368
+ transform: scale(1);
369
+ opacity: 1;
370
+ }
371
+
372
+ .u-animation-zoom {
373
+ transform: scale(1.15);
374
+ }
375
+
376
+ .u-drawer-content-visible {
377
+ transform: translate3D(0px, 0px, 0px) !important;
378
+ }
379
+
380
+ .u-close {
381
+ position: absolute;
382
+ z-index: 3;
383
+ }
384
+
385
+ .u-close--top-left {
386
+ top: 30rpx;
387
+ left: 30rpx;
388
+ }
389
+
390
+ .u-close--top-right {
391
+ top: 30rpx;
392
+ right: 30rpx;
393
+ }
394
+
395
+ .u-close--bottom-left {
396
+ bottom: 30rpx;
397
+ left: 30rpx;
398
+ }
399
+
400
+ .u-close--bottom-right {
401
+ right: 30rpx;
402
+ bottom: 30rpx;
403
+ }
404
+ </style>
@@ -0,0 +1,272 @@
1
+ <template>
2
+ <view class="u-radio" :style="[radioStyle]">
3
+ <view class="u-radio__icon-wrap" @tap="toggle" :class="[iconClass]" :style="[iconStyle]">
4
+ <u-icon class="u-radio__icon-wrap__icon" name="checkbox-mark" :size="elIconSize" :color="iconColor" />
5
+ </view>
6
+ <view
7
+ class="u-radio__label"
8
+ @tap="onClickLabel"
9
+ :style="{
10
+ fontSize: $u.addUnit(labelSize)
11
+ }"
12
+ >
13
+ <slot />
14
+ </view>
15
+ </view>
16
+ </template>
17
+
18
+ <script setup lang="ts">
19
+ import { computed, inject } from 'vue';
20
+ import { $u } from '../..';
21
+
22
+ defineOptions({
23
+ name: 'u-radio'
24
+ });
25
+
26
+ /**
27
+ * radio 单选框
28
+ * @description 单选框用于有一个选择,用户只能选择其中一个的场景。搭配u-radio-group使用
29
+ * @tutorial https://www.uviewui.com/components/radio.html
30
+ * @property {String|Number} icon-size 图标大小,单位rpx(默认24)
31
+ * @property {String|Number} label-size label字体大小,单位rpx(默认28)
32
+ * @property {String|Number} name radio组件的标示符
33
+ * @property {String} shape 形状,见上方说明(默认circle)
34
+ * @property {Boolean} disabled 是否禁用(默认false)
35
+ * @property {Boolean} label-disabled 点击文本是否可以操作radio(默认true)
36
+ * @property {String} active-color 选中时的颜色,如设置parent的active-color将失效
37
+ * @event {Function} change 某个radio状态发生变化时触发(选中状态)
38
+ * @example <u-radio :label-disabled="false">门掩黄昏,无计留春住</u-radio>
39
+ */
40
+
41
+ const props = defineProps({
42
+ /** radio的名称 */
43
+ name: { type: [String, Number], default: '' },
44
+ /** 形状,square为方形,circle为原型 */
45
+ shape: { type: String, default: '' },
46
+ /** 是否禁用 */
47
+ disabled: { type: [String, Boolean], default: '' },
48
+ /** 是否禁止点击提示语选中复选框 */
49
+ labelDisabled: { type: [String, Boolean], default: '' },
50
+ /** 选中状态下的颜色,如设置此值,将会覆盖parent的activeColor值 */
51
+ activeColor: { type: String, default: '' },
52
+ /** 图标的大小,单位rpx */
53
+ iconSize: { type: [String, Number], default: '' },
54
+ /** label的字体大小,rpx单位 */
55
+ labelSize: { type: [String, Number], default: '' }
56
+ });
57
+
58
+ const emit = defineEmits(['change']);
59
+
60
+ // 获取父组件u-radio-group的provide数据
61
+ const parent = inject<any>('u-radio-group', null);
62
+
63
+ // 父组件的默认值
64
+ const parentData = computed(
65
+ () =>
66
+ parent?.getData?.() || {
67
+ iconSize: null,
68
+ labelDisabled: null,
69
+ disabled: null,
70
+ shape: null,
71
+ activeColor: null,
72
+ size: null,
73
+ width: null,
74
+ height: null,
75
+ value: null,
76
+ wrap: null
77
+ }
78
+ );
79
+
80
+ /**
81
+ * 是否禁用,如果父组件u-radio-group禁用的话,将会忽略子组件的配置
82
+ */
83
+ const elDisabled = computed(() => (props.disabled !== '' ? props.disabled : parentData.value.disabled !== null ? parentData.value.disabled : false));
84
+
85
+ /**
86
+ * 是否禁用label点击
87
+ */
88
+ const elLabelDisabled = computed(() => (props.labelDisabled !== '' ? props.labelDisabled : parentData.value.labelDisabled !== null ? parentData.value.labelDisabled : false));
89
+
90
+ /**
91
+ * 组件尺寸,对应size的值,默认值为34rpx
92
+ * 兼容无size属性场景
93
+ */
94
+ const elSize = computed(() => {
95
+ // 若props无size,直接用默认值
96
+ // 兼容老代码,parentData.value.size 可能不存在
97
+ return (props as any).size ? (props as any).size : parentData.value.size ? parentData.value.size : 34;
98
+ });
99
+
100
+ /**
101
+ * 组件的勾选图标的尺寸,默认20
102
+ */
103
+ const elIconSize = computed(() => (props.iconSize ? props.iconSize : parentData.value.iconSize ? parentData.value.iconSize : 20));
104
+
105
+ /**
106
+ * 组件选中激活时的颜色
107
+ */
108
+ const elActiveColor = computed(() => (props.activeColor ? props.activeColor : parentData.value.activeColor ? parentData.value.activeColor : 'primary'));
109
+
110
+ /**
111
+ * 组件的形状
112
+ */
113
+ const elShape = computed(() => (props.shape ? props.shape : parentData.value.shape ? parentData.value.shape : 'circle'));
114
+
115
+ /**
116
+ * 设置radio的状态,要求radio的name等于parent的value时才为选中状态
117
+ */
118
+ const iconStyle = computed(() => {
119
+ let style: Record<string, string> = {};
120
+ if (elActiveColor.value && parentData.value.value == props.name && !elDisabled.value) {
121
+ style.borderColor = elActiveColor.value;
122
+ style.backgroundColor = elActiveColor.value;
123
+ }
124
+ style.width = $u.addUnit(elSize.value);
125
+ style.height = $u.addUnit(elSize.value);
126
+ return style;
127
+ });
128
+
129
+ const iconColor = computed(() => (props.name == parentData.value.value ? '#ffffff' : 'transparent'));
130
+
131
+ const iconClass = computed(() => {
132
+ let classes: string[] = [];
133
+ classes.push('u-radio__icon-wrap--' + elShape.value);
134
+ if (props.name == parentData.value.value) classes.push('u-radio__icon-wrap--checked');
135
+ if (elDisabled.value) classes.push('u-radio__icon-wrap--disabled');
136
+ if (props.name == parentData.value.value && elDisabled.value) classes.push('u-radio__icon-wrap--disabled--checked');
137
+ // 支付宝小程序无法动态绑定一个数组类名,否则解析出来的结果会带有",",而导致失效
138
+ return classes.join(' ');
139
+ });
140
+
141
+ const radioStyle = computed(() => {
142
+ let style: Record<string, string> = {};
143
+ if (parentData.value.width) {
144
+ style.width = $u.addUnit(parentData.value.width);
145
+ // #ifdef MP
146
+ // 各家小程序因为它们特殊的编译结构,使用float布局
147
+ style.float = 'left';
148
+ // #endif
149
+ // #ifndef MP
150
+ // H5和APP使用flex布局
151
+ style.flex = `0 0 ${$u.addUnit(parentData.value.width)}`;
152
+ // #endif
153
+ }
154
+ if (parentData.value.wrap) {
155
+ style.width = '100%';
156
+ // #ifndef MP
157
+ // H5和APP使用flex布局,将宽度设置100%,即可自动换行
158
+ style.flex = '0 0 100%';
159
+ // #endif
160
+ }
161
+ return style;
162
+ });
163
+
164
+ /**
165
+ * 点击label
166
+ */
167
+ function onClickLabel() {
168
+ if (!elLabelDisabled.value && !elDisabled.value) {
169
+ setRadioCheckedStatus();
170
+ }
171
+ }
172
+ /**
173
+ * 点击icon
174
+ */
175
+ function toggle() {
176
+ if (!elDisabled.value) {
177
+ setRadioCheckedStatus();
178
+ }
179
+ }
180
+ /**
181
+ * 发出事件
182
+ */
183
+ function emitEvent() {
184
+ // u-radio的name不等于父组件的v-model的值时(意味着未选中),才发出事件,避免多次点击触发事件
185
+ if (parentData.value.value != props.name) emit('change', props.name);
186
+ }
187
+ /**
188
+ * 改变组件选中状态
189
+ * 这里的改变的依据是,更改本组件的parentData.value值为本组件的name值,同时通过父组件遍历所有u-radio实例
190
+ * 将本组件外的其他u-radio的parentData.value都设置为空(由computed计算后,都被取消选中状态),因而只剩下一个为选中状态
191
+ */
192
+ function setRadioCheckedStatus() {
193
+ emitEvent();
194
+ if (parent && parent.setValue) {
195
+ parent.setValue(props.name);
196
+ parentData.value.value = props.name;
197
+ }
198
+ }
199
+ </script>
200
+
201
+ <style lang="scss" scoped>
202
+ @import '../../libs/css/style.components.scss';
203
+
204
+ .u-radio {
205
+ /* #ifndef APP-NVUE */
206
+ display: inline-flex;
207
+ /* #endif */
208
+ align-items: center;
209
+ overflow: hidden;
210
+ user-select: none;
211
+ line-height: 1.8;
212
+
213
+ &__icon-wrap {
214
+ color: $u-content-color;
215
+ @include vue-flex;
216
+ flex: none;
217
+ align-items: center;
218
+ justify-content: center;
219
+ box-sizing: border-box;
220
+ width: 42rpx;
221
+ height: 42rpx;
222
+ color: transparent;
223
+ text-align: center;
224
+ transition-property: color, border-color, background-color;
225
+ font-size: 20px;
226
+ border: 1px solid #c8c9cc;
227
+ transition-duration: 0.2s;
228
+
229
+ /* #ifdef MP-TOUTIAO */
230
+ // 头条小程序兼容性问题,需要设置行高为0,否则图标偏下
231
+ &__icon {
232
+ line-height: 0;
233
+ }
234
+ /* #endif */
235
+
236
+ &--circle {
237
+ border-radius: 100%;
238
+ }
239
+
240
+ &--square {
241
+ border-radius: 3px;
242
+ }
243
+
244
+ &--checked {
245
+ color: #fff;
246
+ background-color: #2979ff;
247
+ border-color: #2979ff;
248
+ }
249
+
250
+ &--disabled {
251
+ background-color: #ebedf0;
252
+ border-color: #c8c9cc;
253
+ }
254
+
255
+ &--disabled--checked {
256
+ color: #c8c9cc !important;
257
+ }
258
+ }
259
+
260
+ &__label {
261
+ word-wrap: break-word;
262
+ margin-left: 10rpx;
263
+ margin-right: 24rpx;
264
+ color: $u-content-color;
265
+ font-size: 30rpx;
266
+
267
+ &--disabled {
268
+ color: #c8c9cc;
269
+ }
270
+ }
271
+ }
272
+ </style>