uview-pro 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +156 -1
- package/components/u-action-sheet/u-action-sheet.vue +4 -4
- package/components/u-avatar/u-avatar.vue +1 -1
- package/components/u-badge/u-badge.vue +1 -1
- package/components/u-button/u-button.vue +102 -25
- package/components/u-card/u-card.vue +1 -1
- package/components/u-cell-group/u-cell-group.vue +1 -1
- package/components/u-cell-item/u-cell-item.vue +1 -1
- package/components/u-checkbox/u-checkbox.vue +1 -1
- package/components/u-checkbox-group/u-checkbox-group.vue +1 -1
- package/components/u-circle-progress/u-circle-progress.vue +1 -1
- package/components/u-city-select/u-city-select.vue +244 -0
- package/components/u-col/u-col.vue +1 -1
- package/components/u-collapse/u-collapse.vue +1 -1
- package/components/u-collapse-item/u-collapse-item.vue +2 -2
- package/components/u-count-down/u-count-down.vue +1 -1
- package/components/u-count-to/u-count-to.vue +1 -1
- package/components/u-divider/u-divider.vue +1 -1
- package/components/u-empty/u-empty.vue +1 -1
- package/components/u-field/u-field.vue +1 -1
- package/components/u-gap/u-gap.vue +1 -1
- package/components/u-grid/u-grid.vue +1 -1
- package/components/u-grid-item/u-grid-item.vue +1 -1
- package/components/u-icon/u-icon.vue +29 -23
- package/components/u-index-anchor/u-index-anchor.vue +1 -1
- package/components/u-index-list/u-index-list.vue +1 -1
- package/components/u-keyboard/u-keyboard.vue +1 -1
- package/components/u-lazy-load/u-lazy-load.vue +1 -1
- package/components/u-line/u-line.vue +1 -1
- package/components/u-line-progress/u-line-progress.vue +1 -1
- package/components/u-link/u-link.vue +1 -1
- package/components/u-loading/u-loading.vue +1 -1
- package/components/u-loadmore/u-loadmore.vue +1 -1
- package/components/u-mask/u-mask.vue +1 -1
- package/components/u-message-input/u-message-input.vue +1 -1
- package/components/u-modal/u-modal.vue +1 -1
- package/components/u-navbar/u-navbar.vue +1 -1
- package/components/u-no-network/u-no-network.vue +1 -1
- package/components/u-notice-bar/u-notice-bar.vue +1 -1
- package/components/u-number-box/u-number-box.vue +1 -1
- package/components/u-picker/u-picker.vue +1 -1
- package/components/u-popup/u-popup.vue +1 -1
- package/components/u-radio/u-radio.vue +1 -1
- package/components/u-radio-group/u-radio-group.vue +1 -1
- package/components/u-rate/u-rate.vue +1 -1
- package/components/u-read-more/u-read-more.vue +1 -1
- package/components/u-row/u-row.vue +1 -1
- package/components/u-search/u-search.vue +1 -1
- package/components/u-section/u-section.vue +1 -1
- package/components/u-skeleton/u-skeleton.vue +1 -1
- package/components/u-steps/u-steps.vue +1 -1
- package/components/u-sticky/u-sticky.vue +1 -1
- package/components/u-subsection/u-subsection.vue +1 -1
- package/components/u-swipe-action/u-swipe-action.vue +1 -1
- package/components/u-swiper/u-swiper.vue +1 -1
- package/components/u-switch/u-switch.vue +1 -1
- package/components/u-table/u-table.vue +1 -1
- package/components/u-tabs/u-tabs.vue +1 -1
- package/components/u-tabs-swiper/u-tabs-swiper.vue +1 -1
- package/components/u-tag/u-tag.vue +1 -1
- package/components/u-td/u-td.vue +1 -1
- package/components/u-th/u-th.vue +1 -1
- package/components/u-time-line/u-time-line.vue +1 -1
- package/components/u-time-line-item/u-time-line-item.vue +1 -1
- package/components/u-toast/u-toast.vue +1 -1
- package/components/u-top-tips/u-top-tips.vue +1 -1
- package/components/u-tr/u-tr.vue +1 -1
- package/components/u-upload/u-upload.vue +12 -6
- package/components/u-verification-code/u-verification-code.vue +1 -1
- package/components/u-waterfall/u-waterfall.vue +1 -1
- package/libs/function/md5.ts +3 -1
- package/libs/request/auto-http.ts +76 -0
- package/libs/request/uni-http.md +156 -0
- package/libs/request/uni-http.ts +434 -0
- package/package.json +5 -3
- package/readme.md +33 -15
|
@@ -26,7 +26,7 @@ defineOptions({
|
|
|
26
26
|
/**
|
|
27
27
|
* radio 单选框
|
|
28
28
|
* @description 单选框用于有一个选择,用户只能选择其中一个的场景。搭配u-radio-group使用
|
|
29
|
-
* @tutorial https://uview-pro.
|
|
29
|
+
* @tutorial https://uview-pro.netlify.app/components/radio.html
|
|
30
30
|
* @property {String|Number} icon-size 图标大小,单位rpx(默认24)
|
|
31
31
|
* @property {String|Number} label-size label字体大小,单位rpx(默认28)
|
|
32
32
|
* @property {String|Number} name radio组件的标示符
|
|
@@ -15,7 +15,7 @@ defineOptions({
|
|
|
15
15
|
/**
|
|
16
16
|
* radioGroup 单选框父组件
|
|
17
17
|
* @description 单选框用于有一个选择,用户只能选择其中一个的场景。搭配u-radio使用
|
|
18
|
-
* @tutorial https://uview-pro.
|
|
18
|
+
* @tutorial https://uview-pro.netlify.app/components/radio.html
|
|
19
19
|
* @property {Boolean} disabled 是否禁用所有radio(默认false)
|
|
20
20
|
* @property {String|Number} size 组件整体的大小,单位rpx(默认40)
|
|
21
21
|
* @property {String} active-color 选中时的颜色,应用到所有子Radio组件(默认#2979ff)
|
|
@@ -29,7 +29,7 @@ defineOptions({
|
|
|
29
29
|
/**
|
|
30
30
|
* rate 评分
|
|
31
31
|
* @description 该组件一般用于满意度调查,星型评分的场景
|
|
32
|
-
* @tutorial https://uview-pro.
|
|
32
|
+
* @tutorial https://uview-pro.netlify.app/components/rate.html
|
|
33
33
|
* @property {String|Number} count 最多可选的星星数量(默认5)
|
|
34
34
|
* @property {String|Number} current 默认选中的星星数量(默认0)
|
|
35
35
|
* @property {Boolean} disabled 是否禁止用户操作(默认false)
|
|
@@ -36,7 +36,7 @@ defineOptions({ name: 'u-read-more' });
|
|
|
36
36
|
/**
|
|
37
37
|
* readMore 阅读更多
|
|
38
38
|
* @description 该组件一般用于内容较长,预先收起一部分,点击展开全部内容的场景。
|
|
39
|
-
* @tutorial https://uview-pro.
|
|
39
|
+
* @tutorial https://uview-pro.netlify.app/components/readMore.html
|
|
40
40
|
* @property {String|Number} showHeight 内容超出此高度才会显示展开全文按钮,单位rpx(默认400)
|
|
41
41
|
* @property {Boolean} toggle 展开后是否显示收起按钮(默认false)
|
|
42
42
|
* @property {String} closeText 关闭时的提示文字(默认“展开阅读全文”)
|
|
@@ -21,7 +21,7 @@ defineOptions({
|
|
|
21
21
|
/**
|
|
22
22
|
* row 行布局
|
|
23
23
|
* @description 通过基础的 12 分栏,迅速简便地创建布局。
|
|
24
|
-
* @tutorial https://uview-pro.
|
|
24
|
+
* @tutorial https://uview-pro.netlify.app/components/layout.html#row-props
|
|
25
25
|
* @property {String|Number} gutter 栅格间隔,左右各为此值的一半,单位rpx(默认0)
|
|
26
26
|
* @property {String} justify 水平排列方式(微信小程序暂不支持)默认(start(或flex-start))
|
|
27
27
|
* @property {String} align 垂直排列方式(默认center)
|
|
@@ -58,7 +58,7 @@ defineOptions({ name: 'u-search' });
|
|
|
58
58
|
/**
|
|
59
59
|
* search 搜索框
|
|
60
60
|
* @description 搜索组件,集成了常见搜索框所需功能,用户可以一键引入,开箱即用。
|
|
61
|
-
* @tutorial https://uview-pro.
|
|
61
|
+
* @tutorial https://uview-pro.netlify.app/components/search.html
|
|
62
62
|
* @property {String} shape 搜索框形状,round-圆形,square-方形(默认round)
|
|
63
63
|
* @property {String} bg-color 搜索框背景颜色(默认#f2f2f2)
|
|
64
64
|
* @property {String} border-color 边框颜色,配置了颜色,才会有边框
|
|
@@ -45,7 +45,7 @@ defineOptions({ name: 'u-section' });
|
|
|
45
45
|
/**
|
|
46
46
|
* section 查看更多
|
|
47
47
|
* @description 该组件一般用于分类信息有很多,但是限于篇幅只能列出一部分,让用户通过"查看更多"获得更多信息的场景,实际效果见演示。
|
|
48
|
-
* @tutorial https://uview-pro.
|
|
48
|
+
* @tutorial https://uview-pro.netlify.app/components/section.html
|
|
49
49
|
* @property {String} title 左边主标题
|
|
50
50
|
* @property {String} subTitle 右边副标题(默认更多)
|
|
51
51
|
* @property {Boolean} right 是否显示右边的内容(默认true)
|
|
@@ -15,7 +15,7 @@ defineOptions({ name: 'u-skeleton' });
|
|
|
15
15
|
/**
|
|
16
16
|
* skeleton 骨架屏
|
|
17
17
|
* @description 骨架屏一般用于页面在请求远程数据尚未完成时,页面用灰色块预显示本来的页面结构,给用户更好的体验。
|
|
18
|
-
* @tutorial https://uview-pro.
|
|
18
|
+
* @tutorial https://uview-pro.netlify.app/components/skeleton.html
|
|
19
19
|
* @property {String} elColor 骨架块状元素的背景颜色(默认#e5e5e5)
|
|
20
20
|
* @property {String} bgColor 骨架组件背景颜色(默认#ffffff)
|
|
21
21
|
* @property {Boolean} animation 骨架块是否显示动画效果(默认false)
|
|
@@ -28,7 +28,7 @@ defineOptions({ name: 'u-steps' });
|
|
|
28
28
|
/**
|
|
29
29
|
* steps 步骤条
|
|
30
30
|
* @description 该组件一般用于完成一个任务要分几个步骤,标识目前处于第几步的场景。
|
|
31
|
-
* @tutorial https://uview-pro.
|
|
31
|
+
* @tutorial https://uview-pro.netlify.app/components/steps.html
|
|
32
32
|
* @property {String} mode 设置模式(默认dot)
|
|
33
33
|
* @property {Array<{name: string}>} list 数轴条数据,数组。具体见上方示例
|
|
34
34
|
* @property {String} type type主题(默认primary)
|
|
@@ -33,7 +33,7 @@ defineOptions({ name: 'u-sticky' });
|
|
|
33
33
|
/**
|
|
34
34
|
* sticky 吸顶
|
|
35
35
|
* @description 该组件与CSS中position: sticky属性实现的效果一致,当组件达到预设的到顶部距离时, 就会固定在指定位置,组件位置大于预设的顶部距离时,会重新按照正常的布局排列。
|
|
36
|
-
* @tutorial https://uview-pro.
|
|
36
|
+
* @tutorial https://uview-pro.netlify.app/components/sticky.html
|
|
37
37
|
* @property {String|Number} offsetTop 吸顶时与顶部的距离,单位rpx(默认0)
|
|
38
38
|
* @property {String|Number} index 自定义标识,用于区分是哪一个组件
|
|
39
39
|
* @property {Boolean} enable 是否开启吸顶功能(默认true)
|
|
@@ -23,7 +23,7 @@ defineOptions({ name: 'u-subsection' });
|
|
|
23
23
|
/**
|
|
24
24
|
* subsection 分段器
|
|
25
25
|
* @description 该分段器一般用于用户从几个选项中选择某一个的场景
|
|
26
|
-
* @tutorial https://uview-pro.
|
|
26
|
+
* @tutorial https://uview-pro.netlify.app/components/subsection.html
|
|
27
27
|
* @property {Array} list 选项的数组,形式见上方"基本使用"
|
|
28
28
|
* @property {String | Number} current 初始化时默认选中的选项索引值(默认0)
|
|
29
29
|
* @property {String} activeColor 激活时的颜色,mode为subsection时固定为白色(默认#303133)
|
|
@@ -32,7 +32,7 @@ defineOptions({ name: 'u-swipe-action' });
|
|
|
32
32
|
/**
|
|
33
33
|
* swipeAction 左滑单元格
|
|
34
34
|
* @description 该组件一般用于左滑唤出操作菜单的场景,用的最多的是左滑删除操作。
|
|
35
|
-
* @tutorial https://uview-pro.
|
|
35
|
+
* @tutorial https://uview-pro.netlify.app/components/swipeAction.html
|
|
36
36
|
* @property {String} bg-color 整个组件背景颜色(默认#ffffff)
|
|
37
37
|
* @property {Array} options 数组形式,可以配置背景颜色和文字
|
|
38
38
|
* @property {String|Number} index 标识符,点击时候用于区分点击了哪一个,用v-for循环时的index即可
|
|
@@ -62,7 +62,7 @@ defineOptions({ name: 'u-swiper' });
|
|
|
62
62
|
/**
|
|
63
63
|
* swiper 轮播图
|
|
64
64
|
* @description 该组件一般用于导航轮播,广告展示等场景,可开箱即用
|
|
65
|
-
* @tutorial https://uview-pro.
|
|
65
|
+
* @tutorial https://uview-pro.netlify.app/components/swiper.html
|
|
66
66
|
* @property {Array} list 轮播图数据,见官网"基本使用"说明
|
|
67
67
|
* @property {Boolean} title 是否显示标题文字,需要配合list参数,见官网说明(默认false)
|
|
68
68
|
* @property {String} mode 指示器模式,见官网说明(默认round)
|
|
@@ -23,7 +23,7 @@ defineOptions({
|
|
|
23
23
|
/**
|
|
24
24
|
* switch 开关选择器
|
|
25
25
|
* @description 选择开关一般用于只有两个选择,且只能选其一的场景。
|
|
26
|
-
* @tutorial https://uview-pro.
|
|
26
|
+
* @tutorial https://uview-pro.netlify.app/components/switch.html
|
|
27
27
|
* @property {Boolean} loading 是否处于加载中(默认false)
|
|
28
28
|
* @property {Boolean} disabled 是否禁用(默认false)
|
|
29
29
|
* @property {String|Number} size 开关尺寸,单位rpx(默认50)
|
|
@@ -12,7 +12,7 @@ defineOptions({ name: 'u-table' });
|
|
|
12
12
|
/**
|
|
13
13
|
* table 表格
|
|
14
14
|
* @description 表格组件一般用于展示大量结构化数据的场景
|
|
15
|
-
* @tutorial https://uview-pro.
|
|
15
|
+
* @tutorial https://uview-pro.netlify.app/components/table.html
|
|
16
16
|
* @property {String} border-color 表格边框的颜色(默认#e4e7ed)
|
|
17
17
|
* @property {String} bg-color 表格的背景颜色(默认#ffffff)
|
|
18
18
|
* @property {String} align 单元格的内容对齐方式,作用类似css的text-align(默认center)
|
|
@@ -24,7 +24,7 @@ defineOptions({ name: 'u-tabs' });
|
|
|
24
24
|
/**
|
|
25
25
|
* tabs 标签
|
|
26
26
|
* @description 该组件,是一个tabs标签组件,在标签多的时候,可以配置为左右滑动,标签少的时候,可以禁止滑动。 该组件的一个特点是配置为滚动模式时,激活的tab会自动移动到组件的中间位置。
|
|
27
|
-
* @tutorial https://uview-pro.
|
|
27
|
+
* @tutorial https://uview-pro.netlify.app/components/tabs.html
|
|
28
28
|
* @property {Boolean} is-scroll tabs是否可以左右拖动(默认true)
|
|
29
29
|
* @property {Array} list 标签数组,元素为对象,如[{name: '推荐'}]
|
|
30
30
|
* @property {String|Number} current 指定哪个tab为激活状态(默认0)
|
|
@@ -21,7 +21,7 @@ defineOptions({ name: 'u-tabs-swiper' });
|
|
|
21
21
|
/**
|
|
22
22
|
* tabsSwiper 全屏选项卡
|
|
23
23
|
* @description 该组件内部实现主要依托于uniapp的scroll-view和swiper组件,主要特色是切换过程中,tabsSwiper文字的颜色可以渐变,底部滑块可以 跟随式滑动,活动tab滚动居中等。应用场景可以用于需要左右切换页面,比如商城的订单中心(待收货-待付款-待评价-已退货)等应用场景。
|
|
24
|
-
* @tutorial https://uview-pro.
|
|
24
|
+
* @tutorial https://uview-pro.netlify.app/components/tabsSwiper.html
|
|
25
25
|
* @property {Boolean} is-scroll tabs是否可以左右拖动(默认true)
|
|
26
26
|
* @property {Array} list 标签数组,元素为对象,如[{name: '推荐'}]
|
|
27
27
|
* @property {String|Number} current 指定哪个tab为激活状态(默认0)
|
|
@@ -23,7 +23,7 @@ defineOptions({
|
|
|
23
23
|
/**
|
|
24
24
|
* tag 提示
|
|
25
25
|
* @description 该组件一般用于标记和选择
|
|
26
|
-
* @tutorial https://uview-pro.
|
|
26
|
+
* @tutorial https://uview-pro.netlify.app/components/tag.html
|
|
27
27
|
* @property {String} type 主题类型(默认primary)
|
|
28
28
|
* @property {String} size 标签大小(默认default)
|
|
29
29
|
* @property {String} shape 标签形状(默认square)
|
package/components/u-td/u-td.vue
CHANGED
|
@@ -13,7 +13,7 @@ defineOptions({ name: 'u-td' });
|
|
|
13
13
|
/**
|
|
14
14
|
* td td单元格
|
|
15
15
|
* @description 表格组件一般用于展示大量结构化数据的场景(搭配u-table使用)
|
|
16
|
-
* @tutorial https://uview-pro.
|
|
16
|
+
* @tutorial https://uview-pro.netlify.app/components/table.html#td-props
|
|
17
17
|
* @property {String | Number} width 单元格宽度百分比或者具体带单位的值,如30%, 200rpx等,一般使用百分比,单元格宽度默认为均分tr的长度(默认auto)
|
|
18
18
|
* @example <u-td>二年级</u-td>
|
|
19
19
|
*/
|
package/components/u-th/u-th.vue
CHANGED
|
@@ -13,7 +13,7 @@ defineOptions({ name: 'u-th' });
|
|
|
13
13
|
/**
|
|
14
14
|
* th th单元格
|
|
15
15
|
* @description 表格组件一般用于展示大量结构化数据的场景(搭配u-table使用)
|
|
16
|
-
* @tutorial https://uview-pro.
|
|
16
|
+
* @tutorial https://uview-pro.netlify.app/components/table.html#td-props
|
|
17
17
|
* @property {String | Number} width 标题单元格宽度百分比或者具体带单位的值,如30%,200rpx等,一般使用百分比,单元格宽度默认为均分tr的长度
|
|
18
18
|
* @example 暂无示例
|
|
19
19
|
*/
|
|
@@ -10,7 +10,7 @@ defineOptions({ name: 'u-time-line' });
|
|
|
10
10
|
/**
|
|
11
11
|
* timeLine 时间轴
|
|
12
12
|
* @description 时间轴组件一般用于物流信息展示,各种跟时间相关的记录等场景。
|
|
13
|
-
* @tutorial https://uview-pro.
|
|
13
|
+
* @tutorial https://uview-pro.netlify.app/components/timeLine.html
|
|
14
14
|
* @example <u-time-line></u-time-line>
|
|
15
15
|
*/
|
|
16
16
|
|
|
@@ -17,7 +17,7 @@ defineOptions({ name: 'u-time-line-item' });
|
|
|
17
17
|
/**
|
|
18
18
|
* timeLineItem 时间轴Item
|
|
19
19
|
* @description 时间轴组件一般用于物流信息展示,各种跟时间相关的记录等场景。(搭配u-time-line使用)
|
|
20
|
-
* @tutorial https://uview-pro.
|
|
20
|
+
* @tutorial https://uview-pro.netlify.app/components/timeLine.html
|
|
21
21
|
* @property {String} bg-color 左边节点的背景颜色,一般通过slot内容自定义背景颜色即可(默认#ffffff)
|
|
22
22
|
* @property {String | Number} node-top 节点左边图标绝对定位的top值,单位rpx
|
|
23
23
|
* @example <u-time-line-item node-top="2">...</u-time-line-item>
|
|
@@ -25,7 +25,7 @@ defineOptions({
|
|
|
25
25
|
/**
|
|
26
26
|
* toast 消息提示
|
|
27
27
|
* @description 此组件表现形式类似uni的uni.showToastAPI,但也有不同的地方。
|
|
28
|
-
* @tutorial https://uview-pro.
|
|
28
|
+
* @tutorial https://uview-pro.netlify.app/components/toast.html
|
|
29
29
|
* @property {String|Number} z-index toast展示时的z-index值
|
|
30
30
|
* @event {Function} show 显示toast,如需一进入页面就显示toast,请在onReady生命周期调用
|
|
31
31
|
* @example <u-toast ref="uToast" />
|
|
@@ -11,7 +11,7 @@ defineOptions({ name: 'u-top-tips' });
|
|
|
11
11
|
/**
|
|
12
12
|
* topTips 顶部提示
|
|
13
13
|
* @description 该组件一般用于页面顶部向下滑出一个提示,尔后自动收起的场景。
|
|
14
|
-
* @tutorial https://uview-pro.
|
|
14
|
+
* @tutorial https://uview-pro.netlify.app/components/topTips.html
|
|
15
15
|
* @property {String|Number} navbarHeight 导航栏高度(包含状态栏高度在内),单位PX
|
|
16
16
|
* @property {String|Number} zIndex z-index值(默认975)
|
|
17
17
|
* @example <u-top-tips ref="uTips"></u-top-tips>
|
package/components/u-tr/u-tr.vue
CHANGED
|
@@ -10,7 +10,7 @@ defineOptions({ name: 'u-tr' });
|
|
|
10
10
|
/**
|
|
11
11
|
* tr 表格行标签
|
|
12
12
|
* @description 表格组件一般用于展示大量结构化数据的场景(搭配<u-table>使用)
|
|
13
|
-
* @tutorial https://uview-pro.
|
|
13
|
+
* @tutorial https://uview-pro.netlify.app/components/table.html
|
|
14
14
|
* @example <u-tr></u-tr>
|
|
15
15
|
*/
|
|
16
16
|
</script>
|
|
@@ -61,7 +61,7 @@ defineOptions({
|
|
|
61
61
|
/**
|
|
62
62
|
* upload 图片上传
|
|
63
63
|
* @description 该组件用于上传图片场景
|
|
64
|
-
* @tutorial https://uview-pro.
|
|
64
|
+
* @tutorial https://uview-pro.netlify.app/components/upload.html
|
|
65
65
|
* @property {String} action 服务器上传地址
|
|
66
66
|
* @property {String Number} max-count 最大选择图片的数量(默认99)
|
|
67
67
|
* @property {Boolean} custom-btn 如果需要自定义选择图片的按钮,设置为true(默认false)
|
|
@@ -95,6 +95,8 @@ defineOptions({
|
|
|
95
95
|
* @event {Function} on-progress 图片上传过程中的进度变化过程触发
|
|
96
96
|
* @event {Function} on-uploaded 所有图片上传完毕触发
|
|
97
97
|
* @event {Function} on-choose-complete 每次选择图片后触发,只是让外部可以得知每次选择后,内部的文件列表
|
|
98
|
+
* @event {Function} on-choose-fail 文件选择失败时触发
|
|
99
|
+
* @event {Function} on-list-change 文件列表发生变化时触发
|
|
98
100
|
* @example <u-upload :action="action" :file-list="fileList" ></u-upload>
|
|
99
101
|
*/
|
|
100
102
|
|
|
@@ -193,13 +195,17 @@ watch(
|
|
|
193
195
|
!tmp && lists.value.push({ url: value.url, error: false, progress: 100 });
|
|
194
196
|
});
|
|
195
197
|
},
|
|
196
|
-
{ immediate: true }
|
|
198
|
+
{ immediate: true, deep: true }
|
|
197
199
|
);
|
|
198
200
|
|
|
199
201
|
// 监听 lists 变化,发出事件
|
|
200
|
-
watch(
|
|
201
|
-
|
|
202
|
-
|
|
202
|
+
watch(
|
|
203
|
+
lists,
|
|
204
|
+
n => {
|
|
205
|
+
emit('on-list-change', n, props.index);
|
|
206
|
+
},
|
|
207
|
+
{ deep: true }
|
|
208
|
+
);
|
|
203
209
|
|
|
204
210
|
/**
|
|
205
211
|
* 清除列表
|
|
@@ -502,7 +508,7 @@ function checkFileExt(file: any) {
|
|
|
502
508
|
return noArrowExt;
|
|
503
509
|
}
|
|
504
510
|
|
|
505
|
-
defineExpose({ clear, reUpload, selectFile, upload, retry, remove, doPreviewImage });
|
|
511
|
+
defineExpose({ clear, reUpload, selectFile, upload, retry, remove, doPreviewImage, lists });
|
|
506
512
|
</script>
|
|
507
513
|
|
|
508
514
|
<style lang="scss" scoped>
|
|
@@ -12,7 +12,7 @@ defineOptions({ name: 'u-verification-code' });
|
|
|
12
12
|
/**
|
|
13
13
|
* verificationCode 验证码输入框
|
|
14
14
|
* @description 考虑到用户实际发送验证码的场景,可能是一个按钮,也可能是一段文字,提示语各有不同,所以本组件不提供界面显示,只提供提示语,由用户将提示语嵌入到具体的场景
|
|
15
|
-
* @tutorial https://uview-pro.
|
|
15
|
+
* @tutorial https://uview-pro.netlify.app/components/verificationCode.html
|
|
16
16
|
* @property {Number|String} seconds 倒计时所需的秒数(默认60)
|
|
17
17
|
* @property {String} startText 开始前的提示语,见官网说明(默认获取验证码)
|
|
18
18
|
* @property {String} changeText 倒计时期间的提示语,必须带有字母"x",见官网说明(默认X秒重新获取)
|
|
@@ -17,7 +17,7 @@ defineOptions({ name: 'u-waterfall' });
|
|
|
17
17
|
/**
|
|
18
18
|
* waterfall 瀑布流
|
|
19
19
|
* @description 这是一个瀑布流形式的组件,内容分为左右两列,结合uView的懒加载组件效果更佳。相较于某些只是奇偶数左右分别,或者没有利用vue作用域插槽的做法,uView的瀑布流实现了真正的 组件化,搭配LazyLoad 懒加载和loadMore 加载更多组件,让您开箱即用,眼前一亮。
|
|
20
|
-
* @tutorial https://uview-pro.
|
|
20
|
+
* @tutorial https://uview-pro.netlify.app/components/waterfall.html
|
|
21
21
|
* @property {Array} flow-list 用于渲染的数据
|
|
22
22
|
* @property {String | Number} add-time 单条数据添加到队列的时间间隔,单位ms,见上方注意事项说明(默认200)
|
|
23
23
|
* @example <u-waterfall :flowList="flowList"></u-waterfall>
|
package/libs/function/md5.ts
CHANGED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import deepMerge from '../function/deepMerge';
|
|
2
|
+
|
|
3
|
+
export function isFunction(f: any): boolean {
|
|
4
|
+
return typeof f === 'function';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function isPromise(p: any): boolean {
|
|
8
|
+
return !!(p && p.then && p.catch);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isArray(arr: any) {
|
|
12
|
+
return Object.prototype.toString.call(arr) === '[object Array]';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 构建基础类
|
|
17
|
+
*/
|
|
18
|
+
class Builder<T> {
|
|
19
|
+
instance: any;
|
|
20
|
+
|
|
21
|
+
constructor(instance: any) {
|
|
22
|
+
this.instance = instance;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param urlConfig url 配置表
|
|
27
|
+
* @param extra 其他请求方法对象
|
|
28
|
+
* @returns Object
|
|
29
|
+
*/
|
|
30
|
+
dispatch(urlConfig: Record<string, any>, extra: Record<string, any> = {}): Record<string, any> {
|
|
31
|
+
const builder: Record<string, any> = {};
|
|
32
|
+
// 创建 API
|
|
33
|
+
Object.keys(urlConfig).forEach(name => {
|
|
34
|
+
builder[name] = this.use.bind(this, urlConfig[name]);
|
|
35
|
+
});
|
|
36
|
+
return { ...builder, ...extra };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 发送请求
|
|
40
|
+
* @param {*} urlConfig : url 配置表
|
|
41
|
+
* @demo urlConfig = { login: { url: '/user/login', method: 'GET', loading: true } }
|
|
42
|
+
* @param {*} config : 开放配置,用户主动配置的
|
|
43
|
+
* @demo api.login({ params: { username: "admin" } })
|
|
44
|
+
* @returns Promise
|
|
45
|
+
*/
|
|
46
|
+
use(urlConfig: Record<string, any>, config: Record<string, any> = {}): Promise<T> {
|
|
47
|
+
// 请求地址
|
|
48
|
+
let url = config?.url ?? urlConfig.url;
|
|
49
|
+
// 兼容 restful url,如果是使用url为function,则为restful格式
|
|
50
|
+
if (config.url && isFunction(config.url)) {
|
|
51
|
+
url = `${urlConfig.url}${config.url()}`;
|
|
52
|
+
}
|
|
53
|
+
// 请求类型,get,post,put,delete
|
|
54
|
+
const method = config?.method ?? urlConfig?.method ?? 'GET';
|
|
55
|
+
// 如果有自定义的工厂函数基础类
|
|
56
|
+
const options = { ...deepMerge(urlConfig, config), url, method };
|
|
57
|
+
if (isFunction(this.instance) || isPromise(this.instance)) {
|
|
58
|
+
return this.instance(options);
|
|
59
|
+
}
|
|
60
|
+
// 如果是使用的 instance
|
|
61
|
+
// 默认的请求基础类
|
|
62
|
+
return this.instance.request(options);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Http 基础类
|
|
68
|
+
*/
|
|
69
|
+
class AutoHttp {
|
|
70
|
+
static get Builder() {
|
|
71
|
+
return Builder;
|
|
72
|
+
}
|
|
73
|
+
constructor() {}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { AutoHttp };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# uni-http 使用说明(useHttp hooks 版)
|
|
2
|
+
|
|
3
|
+
> 本文档适用于 uView Pro 3.x 及以上版本,推荐使用 hooks 方式引入 Http 请求库。
|
|
4
|
+
|
|
5
|
+
## 目录
|
|
6
|
+
- [简介](#简介)
|
|
7
|
+
- [快速开始](#快速开始)
|
|
8
|
+
- [类型定义](#类型定义)
|
|
9
|
+
- [拦截器用法](#拦截器用法)
|
|
10
|
+
- [常见用例](#常见用例)
|
|
11
|
+
- [常见问题](#常见问题)
|
|
12
|
+
- [类型提示与 TS 支持](#类型提示与 TS 支持)
|
|
13
|
+
- [FAQ](#faq)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 简介
|
|
18
|
+
|
|
19
|
+
`uni-http` 是基于 Promise 封装的 uni-app HTTP 请求库,支持全局配置、请求/响应拦截、类型安全、hooks 化调用,适配多端。推荐通过 `useHttp` hooks 工厂函数创建实例,支持全局单例和按需实例化。
|
|
20
|
+
|
|
21
|
+
## 快速开始
|
|
22
|
+
|
|
23
|
+
### 1. 引入 useHttp
|
|
24
|
+
```ts
|
|
25
|
+
import useHttp from '@/uni_modules/uview-pro/libs/request/uni-http';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. 创建 http 实例
|
|
29
|
+
```ts
|
|
30
|
+
const http = useHttp({
|
|
31
|
+
baseURL: 'https://api.example.com',
|
|
32
|
+
timeout: 10000,
|
|
33
|
+
header: { 'Content-Type': 'application/json' }
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 3. 发起请求
|
|
38
|
+
```ts
|
|
39
|
+
// GET
|
|
40
|
+
http.get('/user/info', { params: { id: 1 } })
|
|
41
|
+
.then(res => { /* ... */ })
|
|
42
|
+
.catch(err => { /* ... */ });
|
|
43
|
+
|
|
44
|
+
// POST
|
|
45
|
+
http.post('/user/update', { name: '张三' })
|
|
46
|
+
.then(res => { /* ... */ });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 类型定义
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
interface HttpRequestConfig {
|
|
53
|
+
baseURL?: string;
|
|
54
|
+
timeout?: number;
|
|
55
|
+
header?: Record<string, any>;
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface HttpResponse<T = any> {
|
|
60
|
+
code: number;
|
|
61
|
+
data: T;
|
|
62
|
+
msg: string;
|
|
63
|
+
[key: string]: any;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface Http {
|
|
67
|
+
get<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
|
|
68
|
+
post<T = any>(url: string, data?: any, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
|
|
69
|
+
put<T = any>(url: string, data?: any, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
|
|
70
|
+
delete<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
|
|
71
|
+
// ... 其他方法
|
|
72
|
+
setRequestInterceptor(fn: (config: HttpRequestConfig) => HttpRequestConfig | Promise<HttpRequestConfig>): void;
|
|
73
|
+
setResponseInterceptor(fn: (response: HttpResponse) => HttpResponse | Promise<HttpResponse>): void;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 拦截器用法
|
|
78
|
+
|
|
79
|
+
### 请求拦截器
|
|
80
|
+
```ts
|
|
81
|
+
http.setRequestInterceptor(config => {
|
|
82
|
+
// 可统一添加 token、日志等
|
|
83
|
+
config.header = config.header || {};
|
|
84
|
+
config.header.Authorization = 'Bearer ' + uni.getStorageSync('token');
|
|
85
|
+
return config;
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 响应拦截器
|
|
90
|
+
```ts
|
|
91
|
+
http.setResponseInterceptor(response => {
|
|
92
|
+
if (response.code !== 0) {
|
|
93
|
+
uni.showToast({ title: response.msg || '请求失败', icon: 'none' });
|
|
94
|
+
}
|
|
95
|
+
return response;
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 常见用例
|
|
100
|
+
|
|
101
|
+
### 1. 全局单例
|
|
102
|
+
```ts
|
|
103
|
+
// src/common/http.ts
|
|
104
|
+
import useHttp from '@/uni_modules/uview-pro/libs/request/uni-http';
|
|
105
|
+
const http = useHttp({ baseURL: 'https://api.example.com' });
|
|
106
|
+
export default http;
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 2. 组件内按需实例化
|
|
110
|
+
```ts
|
|
111
|
+
import useHttp from '@/uni_modules/uview-pro/libs/request/uni-http';
|
|
112
|
+
const http = useHttp();
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### 3. 类型推断
|
|
116
|
+
```ts
|
|
117
|
+
interface UserInfo { id: number; name: string; }
|
|
118
|
+
const res = await http.get<UserInfo>('/user/info');
|
|
119
|
+
console.log(res.data.id);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### 4. 错误处理
|
|
123
|
+
```ts
|
|
124
|
+
http.get('/error/api').catch(err => {
|
|
125
|
+
uni.showToast({ title: err.message, icon: 'none' });
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## 常见问题
|
|
130
|
+
|
|
131
|
+
- **Q: 如何全局配置 baseURL、header?**
|
|
132
|
+
A: 在 useHttp({ baseURL, header }) 传入即可。
|
|
133
|
+
- **Q: 如何自定义拦截器?**
|
|
134
|
+
A: 通过 setRequestInterceptor/setResponseInterceptor。
|
|
135
|
+
- **Q: 支持多实例吗?**
|
|
136
|
+
A: 支持,useHttp 可多次调用。
|
|
137
|
+
- **Q: 支持类型推断吗?**
|
|
138
|
+
A: 支持,泛型参数自动推断返回数据类型。
|
|
139
|
+
|
|
140
|
+
## 类型提示与 TS 支持
|
|
141
|
+
|
|
142
|
+
- 完全 TypeScript 支持,类型自动推断。
|
|
143
|
+
- 推荐在 `tsconfig.json` 中包含 `uni-http.ts` 路径。
|
|
144
|
+
|
|
145
|
+
## FAQ
|
|
146
|
+
|
|
147
|
+
- **Q: 还能用 new Http() 吗?**
|
|
148
|
+
A: 不推荐,已废弃。请统一使用 useHttp。
|
|
149
|
+
- **Q: 如何清理拦截器?**
|
|
150
|
+
A: 暂不支持移除,建议重新实例化。
|
|
151
|
+
- **Q: 支持 uni.uploadFile、downloadFile 吗?**
|
|
152
|
+
A: 暂未内置,可自行扩展。
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
如有更多问题,欢迎提 Issue 或 PR。
|