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,329 @@
1
+ <template>
2
+ <view class="content">
3
+ <view class="cropper-wrapper" :style="{ height: cropperOpt.height + 'px' }">
4
+ <canvas
5
+ class="cropper"
6
+ :disable-scroll="true"
7
+ @touchstart="touchStart"
8
+ @touchmove="touchMove"
9
+ @touchend="touchEnd"
10
+ :style="{ width: cropperOpt.width, height: cropperOpt.height, backgroundColor: 'rgba(0, 0, 0, 0.8)' }"
11
+ canvas-id="cropper"
12
+ id="cropper"
13
+ ></canvas>
14
+ <canvas
15
+ class="cropper"
16
+ :disable-scroll="true"
17
+ :style="{
18
+ position: 'fixed',
19
+ top: `-${cropperOpt.width * cropperOpt.pixelRatio}px`,
20
+ left: `-${cropperOpt.height * cropperOpt.pixelRatio}px`,
21
+ width: `${cropperOpt.width * cropperOpt.pixelRatio}px`,
22
+ height: `${cropperOpt.height * cropperOpt.pixelRatio}`
23
+ }"
24
+ canvas-id="targetId"
25
+ id="targetId"
26
+ ></canvas>
27
+ </view>
28
+ <view class="cropper-buttons safe-area-padding" :style="{ height: bottomNavHeight + 'px' }">
29
+ <!-- #ifdef H5 -->
30
+ <view class="upload" @tap="uploadTap">选择图片</view>
31
+ <!-- #endif -->
32
+ <!-- #ifndef H5 -->
33
+ <view class="upload" @tap="uploadTap">重新选择</view>
34
+ <!-- #endif -->
35
+ <view class="getCropperImage" @tap="() => getCropperImage(false)">确定</view>
36
+ </view>
37
+ </view>
38
+ </template>
39
+
40
+ <script setup lang="ts">
41
+ import { ref, reactive, onMounted } from 'vue';
42
+ import { $u } from '../..';
43
+ // 兼容 UMD/ESM 导入 weCropper.js
44
+ // @ts-ignore
45
+ import WeCropper from './weCropper';
46
+
47
+ defineOptions({ name: 'u-avatar-cropper' });
48
+
49
+ /**
50
+ * 裁剪矩形框的样式,其中可包含的属性为lineWidth-边框宽度(单位rpx),color: 边框颜色,
51
+ * mask-遮罩颜色,一般设置为一个rgba的透明度,如"rgba(0, 0, 0, 0.35)"
52
+ */
53
+ const props = defineProps({
54
+ boundStyle: {
55
+ type: Object as () => {
56
+ lineWidth: number;
57
+ borderColor: string;
58
+ mask: string;
59
+ },
60
+ default: () => ({
61
+ lineWidth: 4,
62
+ borderColor: 'rgb(245, 245, 245)',
63
+ mask: 'rgba(0, 0, 0, 0.35)'
64
+ })
65
+ }
66
+ // // 裁剪框宽度,单位rpx
67
+ // rectWidth: {
68
+ // type: [String, Number],
69
+ // default: 400
70
+ // },
71
+ // // 裁剪框高度,单位rpx
72
+ // rectHeight: {
73
+ // type: [String, Number],
74
+ // default: 400
75
+ // },
76
+ // // 输出图片宽度,单位rpx
77
+ // destWidth: {
78
+ // type: [String, Number],
79
+ // default: 400
80
+ // },
81
+ // // 输出图片高度,单位rpx
82
+ // destHeight: {
83
+ // type: [String, Number],
84
+ // default: 400
85
+ // },
86
+ // // 输出的图片类型,如果发现裁剪的图片很大,可能是因为设置为了"png",改成"jpg"即可
87
+ // fileType: {
88
+ // type: String,
89
+ // default: 'jpg',
90
+ // },
91
+ // // 生成的图片质量
92
+ // // H5上无效,目前不考虑使用此参数
93
+ // quality: {
94
+ // type: [Number, String],
95
+ // default: 1
96
+ // }
97
+ });
98
+
99
+ /**
100
+ * 组合式API变量声明
101
+ * 保留所有说明注释
102
+ */
103
+ const bottomNavHeight = ref(50); // 底部导航的高度
104
+ const originWidth = ref(200);
105
+ const width = ref(0);
106
+ const height = ref(0);
107
+ const src = ref(''); // 选择的图片路径,用于在点击确定时,判断是否选择了图片
108
+ const destWidth = ref(200); // 输出图片宽度,单位px
109
+ const rectWidth = ref(200); // 裁剪框宽度,单位px
110
+ const fileType = ref('jpg'); // 输出的图片类型,如果'png'类型发现裁剪的图片太大,改成"jpg"即可
111
+
112
+ // cropperOpt 需响应式,且类型安全
113
+ const cropperOpt = reactive({
114
+ id: 'cropper',
115
+ targetId: 'targetCropper',
116
+ pixelRatio: 1,
117
+ width: 0,
118
+ height: 0,
119
+ scale: 2.5,
120
+ zoom: 8,
121
+ cut: {
122
+ x: 0,
123
+ y: 0,
124
+ width: originWidth.value,
125
+ height: originWidth.value
126
+ },
127
+ boundStyle: {
128
+ lineWidth: 0,
129
+ mask: '',
130
+ color: ''
131
+ }
132
+ });
133
+
134
+ let cropper: any = null; // WeCropper 实例,类型 any,建议后续补充类型声明
135
+
136
+ /**
137
+ * 组件挂载时初始化 cropper
138
+ * 保留所有说明注释
139
+ */
140
+ onMounted(() => {
141
+ // 获取系统信息
142
+ const rectInfo = uni.getSystemInfoSync();
143
+ width.value = rectInfo.windowWidth;
144
+ height.value = rectInfo.windowHeight - bottomNavHeight.value;
145
+ cropperOpt.width = width.value;
146
+ cropperOpt.height = height.value;
147
+ cropperOpt.pixelRatio = rectInfo.pixelRatio;
148
+
149
+ // 初始化裁剪框
150
+ cropperOpt.cut = {
151
+ x: (width.value - originWidth.value) / 2,
152
+ y: (height.value - originWidth.value) / 2,
153
+ width: originWidth.value,
154
+ height: originWidth.value
155
+ };
156
+ cropperOpt.boundStyle = {
157
+ lineWidth: uni.upx2px(props.boundStyle.lineWidth),
158
+ mask: props.boundStyle.mask,
159
+ color: props.boundStyle.borderColor
160
+ };
161
+
162
+ // 设置导航栏样式,以免用户在page.json中没有设置为黑色背景
163
+ uni.setNavigationBarColor({
164
+ frontColor: '#ffffff',
165
+ backgroundColor: '#000000'
166
+ });
167
+
168
+ // 初始化 cropper 实例
169
+ cropper = new WeCropper(cropperOpt)
170
+ .on('ready', (ctx: any) => {
171
+ // wecropper is ready for work!
172
+ })
173
+ .on('beforeImageLoad', (ctx: any) => {
174
+ // before picture loaded, i can do something
175
+ })
176
+ .on('imageLoad', (ctx: any) => {
177
+ // picture loaded
178
+ })
179
+ .on('beforeDraw', (ctx: any, instance: any) => {
180
+ // before canvas draw,i can do something
181
+ });
182
+
183
+ // 选择图片
184
+ uni.chooseImage({
185
+ count: 1, // 默认9
186
+ sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
187
+ sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
188
+ success: (res: UniApp.ChooseImageSuccessCallbackResult) => {
189
+ src.value = res.tempFilePaths[0];
190
+ // 获取裁剪图片资源后,给data添加src属性及其值
191
+ cropper.pushOrign(src.value);
192
+ }
193
+ });
194
+ });
195
+
196
+ /**
197
+ * 触摸开始事件
198
+ * @param e 事件对象
199
+ */
200
+ function touchStart(e: any) {
201
+ cropper && cropper.touchStart(e);
202
+ }
203
+
204
+ /**
205
+ * 触摸移动事件
206
+ * @param e 事件对象
207
+ */
208
+ function touchMove(e: any) {
209
+ cropper && cropper.touchMove(e);
210
+ }
211
+
212
+ /**
213
+ * 触摸结束事件
214
+ * @param e 事件对象
215
+ */
216
+ function touchEnd(e: any) {
217
+ cropper && cropper.touchEnd(e);
218
+ }
219
+
220
+ /**
221
+ * 获取裁剪后的图片
222
+ * @param isPre 是否预览
223
+ */
224
+ function getCropperImage(isPre = false) {
225
+ if (!src.value) return $u.toast('请先选择图片再裁剪');
226
+
227
+ const cropper_opt = {
228
+ destHeight: Number(destWidth.value), // uni.canvasToTempFilePath要求这些参数为数值
229
+ destWidth: Number(destWidth.value),
230
+ fileType: fileType.value
231
+ };
232
+ cropper.getCropperImage(cropper_opt, (path: string, err: any) => {
233
+ if (err) {
234
+ uni.showModal({
235
+ title: '温馨提示',
236
+ content: err.message
237
+ });
238
+ } else {
239
+ if (isPre) {
240
+ uni.previewImage({
241
+ current: '', // 当前显示图片的 http 链接
242
+ urls: [path] // 需要预览的图片 http 链接列表
243
+ });
244
+ } else {
245
+ uni.$emit('uAvatarCropper', path);
246
+ $u.route({
247
+ type: 'back'
248
+ });
249
+ }
250
+ }
251
+ });
252
+ }
253
+
254
+ /**
255
+ * 重新选择图片
256
+ */
257
+ function uploadTap() {
258
+ uni.chooseImage({
259
+ count: 1, // 默认9
260
+ sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
261
+ sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
262
+ success: (res: UniApp.ChooseImageSuccessCallbackResult) => {
263
+ src.value = res.tempFilePaths[0];
264
+ // 获取裁剪图片资源后,给data添加src属性及其值
265
+ cropper.pushOrign(src.value);
266
+ }
267
+ });
268
+ }
269
+ </script>
270
+
271
+ <style scoped lang="scss">
272
+ @import '../../libs/css/style.components.scss';
273
+
274
+ .content {
275
+ background: rgba(255, 255, 255, 1);
276
+ }
277
+
278
+ .cropper {
279
+ position: absolute;
280
+ top: 0;
281
+ left: 0;
282
+ width: 100%;
283
+ height: 100%;
284
+ z-index: 11;
285
+ }
286
+
287
+ .cropper-buttons {
288
+ background-color: #000000;
289
+ color: #eee;
290
+ }
291
+
292
+ .cropper-wrapper {
293
+ position: relative;
294
+ @include vue-flex;
295
+ flex-direction: row;
296
+ justify-content: space-between;
297
+ align-items: center;
298
+ width: 100%;
299
+ background-color: #000;
300
+ }
301
+
302
+ .cropper-buttons {
303
+ width: 100vw;
304
+ @include vue-flex;
305
+ flex-direction: row;
306
+ justify-content: space-between;
307
+ align-items: center;
308
+ position: fixed;
309
+ bottom: 0;
310
+ left: 0;
311
+ font-size: 28rpx;
312
+ }
313
+
314
+ .cropper-buttons .upload,
315
+ .cropper-buttons .getCropperImage {
316
+ width: 50%;
317
+ text-align: center;
318
+ }
319
+
320
+ .cropper-buttons .upload {
321
+ text-align: left;
322
+ padding-left: 50rpx;
323
+ }
324
+
325
+ .cropper-buttons .getCropperImage {
326
+ text-align: right;
327
+ padding-right: 50rpx;
328
+ }
329
+ </style>
@@ -0,0 +1,54 @@
1
+ /**
2
+ * we-cropper 类型声明文件
3
+ * 适用于 Vue3 + TypeScript 项目中 weCropper.js 的类型提示
4
+ */
5
+
6
+ export interface WeCropperOptions {
7
+ id?: string;
8
+ targetId?: string;
9
+ pixelRatio?: number;
10
+ width?: number;
11
+ height?: number;
12
+ scale?: number;
13
+ zoom?: number;
14
+ cut?: {
15
+ x?: number;
16
+ y?: number;
17
+ width?: number;
18
+ height?: number;
19
+ };
20
+ boundStyle?: {
21
+ lineWidth?: number;
22
+ borderColor?: string;
23
+ mask?: string;
24
+ color?: string;
25
+ };
26
+ [key: string]: any;
27
+ }
28
+
29
+ export type WeCropperEvent = (ctx: any, instance?: any) => void;
30
+
31
+ export interface WeCropperInstance {
32
+ pushOrign(src: string): Promise<void>;
33
+ pushOrigin(src: string): Promise<void>;
34
+ removeImage(): Promise<void>;
35
+ getCropperBase64(done?: (base64: string) => void): void;
36
+ getCropperImage(opt: any, fn: (path: string, err: any) => void): void;
37
+ update(): void;
38
+ touchStart(e: any): void;
39
+ touchMove(e: any): void;
40
+ touchEnd(e: any): void;
41
+ on(event: 'ready' | 'beforeImageLoad' | 'imageLoad' | 'beforeDraw', fn: WeCropperEvent): WeCropperInstance;
42
+ // 其它动态方法
43
+ [key: string]: any;
44
+ }
45
+
46
+ /**
47
+ * weCropper 构造函数类型
48
+ */
49
+ declare const WeCropper: {
50
+ new (options: WeCropperOptions): WeCropperInstance;
51
+ (options: WeCropperOptions): WeCropperInstance;
52
+ };
53
+
54
+ export default WeCropper;