@gmcb/uv-ui 0.2.27 → 0.3.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/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/README.md +95 -141
- package/docs/api/configs/color.md +52 -0
- package/docs/api/index.md +77 -0
- package/docs/api/mixins/mpShare.md +95 -0
- package/docs/api/request/apiManage.md +88 -0
- package/docs/api/request/http.md +451 -0
- package/docs/api/utils/colorSwitch.md +78 -0
- package/docs/api/utils/debounce.md +104 -0
- package/docs/api/utils/fastUse.md +246 -0
- package/docs/api/utils/getRect.md +238 -0
- package/docs/api/utils/guid.md +41 -0
- package/docs/api/utils/index.md +55 -0
- package/docs/api/utils/intro.md +25 -0
- package/docs/api/utils/object.md +171 -0
- package/docs/api/utils/queryParams.md +68 -0
- package/docs/api/utils/random.md +23 -0
- package/docs/api/utils/randomArray.md +28 -0
- package/docs/api/utils/route.md +121 -0
- package/docs/api/utils/test.md +237 -0
- package/docs/api/utils/time.md +81 -0
- package/docs/api/utils/trim.md +24 -0
- package/docs/components/actionSheet.md +236 -0
- package/docs/components/addQQGroup.md +5 -0
- package/docs/components/album.md +91 -0
- package/docs/components/alert.md +83 -0
- package/docs/components/avatar.md +152 -0
- package/docs/components/backTop.md +181 -0
- package/docs/components/badge.md +117 -0
- package/docs/components/button.md +196 -0
- package/docs/components/calendar.md +398 -0
- package/docs/components/calendars.md +294 -0
- package/docs/components/cell.md +185 -0
- package/docs/components/checkbox.md +281 -0
- package/docs/components/circleProgress.md +5 -0
- package/docs/components/code.md +162 -0
- package/docs/components/codeInput.md +175 -0
- package/docs/components/collapse.md +250 -0
- package/docs/components/color.md +324 -0
- package/docs/components/common.md +126 -0
- package/docs/components/countDown.md +166 -0
- package/docs/components/countTo.md +140 -0
- package/docs/components/datetimePicker.md +283 -0
- package/docs/components/diff1.x.md +190 -0
- package/docs/components/divider.md +88 -0
- package/docs/components/downloadSetting.md +54 -0
- package/docs/components/dropDown.md +375 -0
- package/docs/components/empty.md +99 -0
- package/docs/components/feature.md +261 -0
- package/docs/components/form.md +736 -0
- package/docs/components/gap.md +49 -0
- package/docs/components/grid.md +225 -0
- package/docs/components/icon.md +101 -0
- package/docs/components/image.md +182 -0
- package/docs/components/index.md +110 -0
- package/docs/components/indexList.md +133 -0
- package/docs/components/input.md +250 -0
- package/docs/components/install.md +59 -0
- package/docs/components/intro.md +32 -0
- package/docs/components/keyboard.md +226 -0
- package/docs/components/layout.md +310 -0
- package/docs/components/line.md +85 -0
- package/docs/components/lineProgress.md +141 -0
- package/docs/components/link.md +89 -0
- package/docs/components/list.md +223 -0
- package/docs/components/loadMore.md +140 -0
- package/docs/components/loadingIcon.md +144 -0
- package/docs/components/loadingPage.md +92 -0
- package/docs/components/modal.md +230 -0
- package/docs/components/more.md +13 -0
- package/docs/components/navbar.md +192 -0
- package/docs/components/noNetwork.md +116 -0
- package/docs/components/noticeBar.md +131 -0
- package/docs/components/notify.md +204 -0
- package/docs/components/npmSetting.md +64 -0
- package/docs/components/numberBox.md +257 -0
- package/docs/components/nvue.md +170 -0
- package/docs/components/overlay.md +117 -0
- package/docs/components/parse.md +204 -0
- package/docs/components/pickColor.md +112 -0
- package/docs/components/picker.md +357 -0
- package/docs/components/popup.md +221 -0
- package/docs/components/problem.md +300 -0
- package/docs/components/qrcode.md +169 -0
- package/docs/components/quickstart.md +33 -0
- package/docs/components/radio.md +256 -0
- package/docs/components/rate.md +128 -0
- package/docs/components/read.md +163 -0
- package/docs/components/readMore.md +227 -0
- package/docs/components/resource.md +17 -0
- package/docs/components/scrollList.md +218 -0
- package/docs/components/search.md +160 -0
- package/docs/components/setting.md +111 -0
- package/docs/components/settingDesc.md +66 -0
- package/docs/components/skeleton.md +105 -0
- package/docs/components/skeletons.md +323 -0
- package/docs/components/slider.md +157 -0
- package/docs/components/steps.md +189 -0
- package/docs/components/sticky.md +76 -0
- package/docs/components/subsection.md +183 -0
- package/docs/components/swipeAction.md +279 -0
- package/docs/components/swiper.md +352 -0
- package/docs/components/switch.md +216 -0
- package/docs/components/tabbar.md +263 -0
- package/docs/components/table.md +5 -0
- package/docs/components/tabs.md +364 -0
- package/docs/components/tag.md +227 -0
- package/docs/components/testPic.md +20 -0
- package/docs/components/text.md +157 -0
- package/docs/components/textarea.md +121 -0
- package/docs/components/toast.md +124 -0
- package/docs/components/tooltip.md +98 -0
- package/docs/components/transition.md +404 -0
- package/docs/components/upload.md +253 -0
- package/docs/components/vtabs.md +332 -0
- package/docs/components/vueUse.md +45 -0
- package/docs/components/vuexDetail.md +103 -0
- package/docs/components/waterfall.md +651 -0
- package/docs/faq/index.md +53 -0
- package/docs/guide/codeHint.md +44 -0
- package/docs/guide/customIcon.md +168 -0
- package/docs/guide/demo.md +92 -0
- package/docs/guide/design.md +56 -0
- package/docs/guide/globalVariable.md +239 -0
- package/docs/guide/i18n.md +194 -0
- package/docs/guide/index.md +28 -0
- package/docs/guide/note.md +74 -0
- package/docs/guide/safeAreaInset.md +64 -0
- package/docs/guide/theme.md +67 -0
- package/docs/index.md +88 -0
- package/libs/config/config.js +0 -10
- package/libs/css/color.scss +15 -14
- package/package.json +7 -2
- package/theme.scss +2 -1
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
## Parse 富文本解析器 <to-api/>
|
|
2
|
+
|
|
3
|
+
<demo-model url="/pages/componentsB/parse/parse"></demo-model>
|
|
4
|
+
|
|
5
|
+
::: tip ✈
|
|
6
|
+
|
|
7
|
+
**组件名:uv-parse**
|
|
8
|
+
|
|
9
|
+
[点击下载&安装](https://ext.dcloud.net.cn/plugin?name=uv-parse)
|
|
10
|
+
|
|
11
|
+
:::
|
|
12
|
+
|
|
13
|
+
该组件一般用于富文本解析场景,比如解析文章内容,商品详情,带原生HTML标签的各类字符串等,此组件和uni-app官方的`rich-text`组件功能有重合之处,但是也有不同的地方。
|
|
14
|
+
|
|
15
|
+
#### 相同点:
|
|
16
|
+
- 二者都能解析HTML字符串
|
|
17
|
+
|
|
18
|
+
#### 不同点:
|
|
19
|
+
- 对于轻量、简单的字符串,`rich-text`性能更好
|
|
20
|
+
- 对于复杂的字符串,使用`parse`组件效果更好,有更多的自定义属性和效果
|
|
21
|
+
|
|
22
|
+
总结:如果是简单的场景,比如一段简单的文字和图片内容,可以优先使用`rich-text`组件,在文章内容,商品详情等复杂的文本详情,可以优先使用`parse`组件。
|
|
23
|
+
|
|
24
|
+
:::tip 提示
|
|
25
|
+
此组件源于开源的优秀作品[mp-html](https://github.com/jin-yufeng/mp-html),本文档只对重要的功能进行介绍,如果需要更详细的说明,请参考[mp-html官方文档](https://jin-yufeng.gitee.io/mp-html/#/overview/quickstart?id=uni-app)。
|
|
26
|
+
:::
|
|
27
|
+
|
|
28
|
+
### 平台兼容性
|
|
29
|
+
|
|
30
|
+
|App(vue)|App(nvue)|H5|小程序|VUE2|VUE3|
|
|
31
|
+
|:-:|:-:|:-:|:-:|:-:|:-:|
|
|
32
|
+
|√|√|√|√|√|√|
|
|
33
|
+
|
|
34
|
+
:::warning 注意事项
|
|
35
|
+
> 为了避免错误使用,给大家带来不好的开发体验,请在使用组件前仔细阅读下面的注意事项,可以帮你避免一些错误。
|
|
36
|
+
1. 如果你是npm安装方式 + app-nvue(其他可忽略),则需要注意static目录下需要创建相应的uv-parse文件,可以到uv-ui-npm项目去复制:[https://gitee.com/climblee/uv-ui-npm/tree/master/static](https://gitee.com/climblee/uv-ui-npm/tree/master/static)
|
|
37
|
+
:::
|
|
38
|
+
|
|
39
|
+
### 基本使用
|
|
40
|
+
|
|
41
|
+
通过`content`参数绑定需要解析的内容即可。
|
|
42
|
+
|
|
43
|
+
```vue
|
|
44
|
+
<template>
|
|
45
|
+
<view class="uv-content">
|
|
46
|
+
<uv-parse :content="content"></uv-parse>
|
|
47
|
+
</view>
|
|
48
|
+
</template>
|
|
49
|
+
<script setup>
|
|
50
|
+
import { ref } from 'vue';
|
|
51
|
+
|
|
52
|
+
const content = ref(`
|
|
53
|
+
<p>露从今夜白,月是故乡明</p>
|
|
54
|
+
<img src="https://cdn.uviewui.com/uview/swiper/2.jpg" />
|
|
55
|
+
`);
|
|
56
|
+
|
|
57
|
+
</script>
|
|
58
|
+
<style lang="scss" scoped>
|
|
59
|
+
.uv-content {
|
|
60
|
+
padding: 24rpx;
|
|
61
|
+
}
|
|
62
|
+
</style>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 长按复制
|
|
66
|
+
|
|
67
|
+
可以通过设置`selectable`参数为`true`来实现长按复制的效果
|
|
68
|
+
|
|
69
|
+
```vue
|
|
70
|
+
<uv-parse :content="content" :selectable="true"></uv-parse>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 设置样式
|
|
74
|
+
|
|
75
|
+
可以有两种方法可设置富文本的样式:
|
|
76
|
+
|
|
77
|
+
- 通过组件的`tagStyle`参数可以精细化的对单独的标签设置样式,注意此方式设置的样式为**字符串**的形式,而非**对象**形式:
|
|
78
|
+
|
|
79
|
+
```vue
|
|
80
|
+
<template>
|
|
81
|
+
<view class="uv-content">
|
|
82
|
+
<uv-parse :content="content" :tagStyle="style"></uv-parse>
|
|
83
|
+
</view>
|
|
84
|
+
</template>
|
|
85
|
+
<script setup>
|
|
86
|
+
import { ref } from 'vue';
|
|
87
|
+
|
|
88
|
+
const content = ref(`
|
|
89
|
+
<p>露从今夜白,月是故乡明</p>
|
|
90
|
+
<img src="https://cdn.uviewui.com/uview/swiper/2.jpg" />
|
|
91
|
+
`);
|
|
92
|
+
const style = ref({
|
|
93
|
+
// 字符串的形式
|
|
94
|
+
p: 'color: red;font-size:32rpx',
|
|
95
|
+
span: 'font-size: 30rpx'
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
</script>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
- 通过父元素标签,统一设置全文的颜色,行高,字体大小等,注意这种方式无法对单独的标签设置样式:
|
|
102
|
+
|
|
103
|
+
```vue
|
|
104
|
+
<template>
|
|
105
|
+
<view class="uv-content">
|
|
106
|
+
<uv-parse :content="content"></uv-parse>
|
|
107
|
+
</view>
|
|
108
|
+
</template>
|
|
109
|
+
<script setup>
|
|
110
|
+
import { ref } from 'vue';
|
|
111
|
+
|
|
112
|
+
const content = ref(`
|
|
113
|
+
<p>露从今夜白,月是故乡明</p>
|
|
114
|
+
<img src="https://cdn.uviewui.com/uview/swiper/2.jpg" />
|
|
115
|
+
`);
|
|
116
|
+
|
|
117
|
+
</script>
|
|
118
|
+
<style lang="scss" scoped>
|
|
119
|
+
.uv-content {
|
|
120
|
+
padding: 24rpx;
|
|
121
|
+
font-size: 32rpx;
|
|
122
|
+
color: $uv-content-color;
|
|
123
|
+
line-height: 1.6;
|
|
124
|
+
}
|
|
125
|
+
</style>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 懒加载和占位图
|
|
129
|
+
|
|
130
|
+
- 设置`lazyLoad`为`true`即可开启图片懒加载功能
|
|
131
|
+
- 设置`loadingImg`为网络路径或者base64图片,可以在图片加载完成前展示占位图
|
|
132
|
+
|
|
133
|
+
```vue
|
|
134
|
+
<uv-parse :content="content" :lazyLoad="true" :loadingImg="/xxx/xxx.jpg"></uv-parse>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 链接跳转/锚点
|
|
138
|
+
|
|
139
|
+
H5、App(含NVUE)外链可以直接打开,小程序端将自动复制链接
|
|
140
|
+
小程序端`a`标签设置`app-id`后可以跳转到其他小程序
|
|
141
|
+
|
|
142
|
+
```vue
|
|
143
|
+
<a href="#">跳转到顶部</a>
|
|
144
|
+
<a href="#list">跳转到列表</a>
|
|
145
|
+
<a href="https://www.uvui.cn">外部链接</a>
|
|
146
|
+
<a href="/pages/demo/demo">内部链接</a>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
<br>
|
|
150
|
+
|
|
151
|
+
### 其他配置
|
|
152
|
+
|
|
153
|
+
本组件还有其他更多的配置功能,如获取页面的所有图片数组,跳转页内锚点,视频播放等,如需更多的配置信息,请移步`mp-html`官方文档:[mp-html文档](https://jin-yufeng.gitee.io/mp-html/#/overview/quickstart?id=uni-app)
|
|
154
|
+
|
|
155
|
+
<br>
|
|
156
|
+
|
|
157
|
+
### 完整示例
|
|
158
|
+
|
|
159
|
+
::: tip 完整示例下载地址
|
|
160
|
+
|
|
161
|
+
[https://ext.dcloud.net.cn/plugin?name=uv-ui](https://ext.dcloud.net.cn/plugin?name=uv-ui)
|
|
162
|
+
|
|
163
|
+
:::
|
|
164
|
+
|
|
165
|
+
### API
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
### Parse Props
|
|
169
|
+
|
|
170
|
+
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|
|
171
|
+
|:- |:- |:- |:- | :- |
|
|
172
|
+
|container-style <badge text="1.0.3" /> | 容器的样式 | String | - | - |
|
|
173
|
+
|content | 用于渲染的 `html` 字符串 | String | - | - |
|
|
174
|
+
|copy-link | 是否允许外部链接被点击时自动复制 | Boolean | true | true | false |
|
|
175
|
+
|domain | 主域名(用于链接拼接) | String | - | - |
|
|
176
|
+
|error-img | 图片出错时的占位图链接 | String | - | - |
|
|
177
|
+
|lazy-load | 是否开启图片懒加载 | Boolean | false | true | false |
|
|
178
|
+
|loading-img | 图片加载过程中的占位图链接 | String | - | - |
|
|
179
|
+
|pause-video | 是否在播放一个视频时自动暂停其他视频 | Boolean | true | true | false |
|
|
180
|
+
|preview-img | 是否开启图片被点击时自动预览 | Boolean | true | true | false |
|
|
181
|
+
|scroll-table| 是否给每个表格添加一个滚动层使其能单独横向滚动 | Boolean | false | true |false |
|
|
182
|
+
|selectable | 是否开启长按复制内容 | Boolean | false | true |
|
|
183
|
+
|set-title | 是否将 `title` 标签的内容设置到页面标题 | Boolean | true | true |false |
|
|
184
|
+
|show-img-menu| 是否允许图片被长按时显示菜单 | Boolean | true | true |false |
|
|
185
|
+
|tag-style | 设置标签的默认样式 | Object | - | - |
|
|
186
|
+
|use-anchor | 是否使用锚点链接 | Boolean| false | true |false |
|
|
187
|
+
|
|
188
|
+
### Parse Events
|
|
189
|
+
|
|
190
|
+
|事件名|说明|回调参数|
|
|
191
|
+
|:-|:-|:-|
|
|
192
|
+
| @load |dom 树加载完成时触发 |所有节点被添加到节点树中时触发,无返回值,可以调用 api |
|
|
193
|
+
| @ready |渲染完成时触发 |返回 boundingClientRect 的查询结果(包含宽高、位置等信息),所有图片(除懒加载)加载完成时才会触发,图片较大时可能 延时较长 |
|
|
194
|
+
| @error |出错时触发 |返回一个 object,其中 source 是错误来源,errMsg 为错误信息,target 包含出错标签的具体信息 |
|
|
195
|
+
| @imgtap |图片被点击时触发 |返回一个 object,其中 src 是图片链接。可以在 img 标签 设置 ignore="1" 在事件中调用将不进行预览 |
|
|
196
|
+
| @linktap |在链接被点击时触发 |返回一个 object,其中包含了被点击的 a 标签的所有属性。如果需要链接不进行跳转/复制等操作,可以在 a 标签设置href="javascript:;"。可在该事件中进行下载文档等进一步操作 |
|
|
197
|
+
| @play | 音视频播放时触发 | - |
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
<style scoped>
|
|
201
|
+
h3[id=parse-events] + table thead tr th:nth-child(3){
|
|
202
|
+
width: 60%;
|
|
203
|
+
}
|
|
204
|
+
</style>
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# PickColor 颜色选择
|
|
2
|
+
|
|
3
|
+
`uv-pick-color` 用于选择 RGBA 颜色,支持设置初始颜色、预置颜色,并通过 `confirm` 事件返回选择结果。
|
|
4
|
+
|
|
5
|
+
## 基础用法
|
|
6
|
+
|
|
7
|
+
```vue
|
|
8
|
+
<template>
|
|
9
|
+
<view>
|
|
10
|
+
<uv-pick-color ref="pickerColor" @confirm="confirm" />
|
|
11
|
+
<button @click="openColor">打开</button>
|
|
12
|
+
</view>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script setup>
|
|
16
|
+
import { ref } from 'vue';
|
|
17
|
+
|
|
18
|
+
const pickerColor = ref(null);
|
|
19
|
+
function openColor() {
|
|
20
|
+
pickerColor.value.open();
|
|
21
|
+
}
|
|
22
|
+
function confirm(value) {
|
|
23
|
+
console.log('confirm', value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
</script>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 初始颜色
|
|
30
|
+
|
|
31
|
+
```vue
|
|
32
|
+
<template>
|
|
33
|
+
<uv-pick-color ref="pickerColor" :color="color" @confirm="confirm" />
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<script setup>
|
|
37
|
+
import { ref } from 'vue';
|
|
38
|
+
|
|
39
|
+
const pickerColor = ref(null);
|
|
40
|
+
const color = ref({
|
|
41
|
+
r: 60,
|
|
42
|
+
g: 156,
|
|
43
|
+
b: 255,
|
|
44
|
+
a: 1
|
|
45
|
+
});
|
|
46
|
+
function confirm(value) {
|
|
47
|
+
console.log(value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
</script>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 预置颜色
|
|
54
|
+
|
|
55
|
+
```vue
|
|
56
|
+
<template>
|
|
57
|
+
<uv-pick-color ref="pickerColor" :prefab-color="prefabColor" @confirm="confirm" />
|
|
58
|
+
</template>
|
|
59
|
+
|
|
60
|
+
<script setup>
|
|
61
|
+
import { ref } from 'vue';
|
|
62
|
+
|
|
63
|
+
const pickerColor = ref(null);
|
|
64
|
+
const prefabColor = ref([{
|
|
65
|
+
r: 60,
|
|
66
|
+
g: 156,
|
|
67
|
+
b: 255,
|
|
68
|
+
a: 1
|
|
69
|
+
}, {
|
|
70
|
+
r: 245,
|
|
71
|
+
g: 108,
|
|
72
|
+
b: 108,
|
|
73
|
+
a: 1
|
|
74
|
+
}]);
|
|
75
|
+
function confirm(value) {
|
|
76
|
+
console.log(value);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
</script>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Props
|
|
83
|
+
|
|
84
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
85
|
+
| --- | --- | --- | --- |
|
|
86
|
+
| `color` | 初始颜色。 | `Object` | `{ r: 0, g: 0, b: 0, a: 0 }` |
|
|
87
|
+
| `prefabColor` | 底部预置颜色。 | `Array` | `[]` |
|
|
88
|
+
| `closeOnClickOverlay` | 是否允许点击遮罩关闭。 | `Boolean` | `false` |
|
|
89
|
+
| `title` | 顶部标题。 | `String` | - |
|
|
90
|
+
| `cancelText` | 取消按钮文字。 | `String` | `取消` |
|
|
91
|
+
| `confirmText` | 确认按钮文字。 | `String` | `确定` |
|
|
92
|
+
| `cancelColor` | 取消按钮颜色。 | `String` | `#909193` |
|
|
93
|
+
| `confirmColor` | 确认按钮颜色。 | `String` | `#3c9cff` |
|
|
94
|
+
|
|
95
|
+
## Methods
|
|
96
|
+
|
|
97
|
+
| 方法 | 说明 |
|
|
98
|
+
| --- | --- |
|
|
99
|
+
| `open()` | 打开颜色选择器。 |
|
|
100
|
+
| `close()` | 关闭颜色选择器。 |
|
|
101
|
+
|
|
102
|
+
## Events
|
|
103
|
+
|
|
104
|
+
| 事件 | 说明 | 回调参数 |
|
|
105
|
+
| --- | --- | --- |
|
|
106
|
+
| `confirm` | 点击确认按钮触发。 | 颜色值,例如 `{ hex: '#000000', rgba: { r: 0, g: 0, b: 0, a: 0 } }` |
|
|
107
|
+
| `cancel` | 点击取消按钮触发。 | - |
|
|
108
|
+
| `close` | 组件关闭时触发。 | - |
|
|
109
|
+
|
|
110
|
+
## 平台
|
|
111
|
+
|
|
112
|
+
支持 App(vue)、H5、小程序和 Vue 3;nvue 暂不支持。
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
## Picker 选择器 <to-api/>
|
|
2
|
+
|
|
3
|
+
<demo-model url="/pages/componentsB/picker/picker"></demo-model>
|
|
4
|
+
|
|
5
|
+
::: tip ✈
|
|
6
|
+
|
|
7
|
+
**组件名:uv-picker**
|
|
8
|
+
|
|
9
|
+
[点击下载&安装](https://ext.dcloud.net.cn/plugin?name=uv-picker)
|
|
10
|
+
|
|
11
|
+
:::
|
|
12
|
+
|
|
13
|
+
此选择器用于单列,多列,多列联动的选择场景。
|
|
14
|
+
|
|
15
|
+
### 平台兼容性
|
|
16
|
+
|
|
17
|
+
|App(vue)|App(nvue)|H5|小程序|VUE2|VUE3|
|
|
18
|
+
|:-:|:-:|:-:|:-:|:-:|:-:|
|
|
19
|
+
|√|√|√|√|√|√|
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### 基本使用
|
|
23
|
+
|
|
24
|
+
- 通过`ref`调用`open()`控制组件的打开。
|
|
25
|
+
- 都通过传入数组`columns`配置选择项。
|
|
26
|
+
|
|
27
|
+
:::warning 注意
|
|
28
|
+
columns参数中是数组中嵌套数组:`columns: [ ['中国', '美国', '日本'] ]`,否则显示异常
|
|
29
|
+
:::
|
|
30
|
+
|
|
31
|
+
```vue
|
|
32
|
+
<template>
|
|
33
|
+
<view>
|
|
34
|
+
<uv-picker ref="picker" :columns="columns" @confirm="confirm"></uv-picker>
|
|
35
|
+
<button @click="openPicker">打开</button>
|
|
36
|
+
</view>
|
|
37
|
+
</template>
|
|
38
|
+
<script setup>
|
|
39
|
+
import { ref } from 'vue';
|
|
40
|
+
|
|
41
|
+
const picker = ref(null);
|
|
42
|
+
const columns = ref([['中国', '美国', '日本']]);
|
|
43
|
+
function openPicker() {
|
|
44
|
+
picker.value.open();
|
|
45
|
+
}
|
|
46
|
+
function confirm(e) {
|
|
47
|
+
console.log('confirm', e);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
</script>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 多列模式与多列联动
|
|
54
|
+
|
|
55
|
+
此模式通过传入`columns`参数,此参数为二维数组,通过`change`事件完成联动操作。
|
|
56
|
+
|
|
57
|
+
```vue
|
|
58
|
+
<template>
|
|
59
|
+
<view>
|
|
60
|
+
<uv-picker ref="picker" :columns="columns" @confirm="confirm" @change="change"></uv-picker>
|
|
61
|
+
<button @click="openPicker">打开</button>
|
|
62
|
+
</view>
|
|
63
|
+
</template>
|
|
64
|
+
<script setup>
|
|
65
|
+
import { ref } from 'vue';
|
|
66
|
+
|
|
67
|
+
const picker = ref(null);
|
|
68
|
+
const columns = ref([['中国', '美国'], ['深圳', '厦门', '上海', '拉萨']]);
|
|
69
|
+
const columnData = ref([['深圳', '厦门', '上海', '拉萨'], ['得州', '华盛顿', '纽约', '阿拉斯加']]);
|
|
70
|
+
function openPicker() {
|
|
71
|
+
picker.value.open();
|
|
72
|
+
}
|
|
73
|
+
function confirm(e) {
|
|
74
|
+
console.log('confirm', e);
|
|
75
|
+
}
|
|
76
|
+
function change(e) {
|
|
77
|
+
const {
|
|
78
|
+
columnIndex,
|
|
79
|
+
index
|
|
80
|
+
} = e;
|
|
81
|
+
if (columnIndex === 0) {
|
|
82
|
+
picker.value.setColumnValues(1, columnData.value[index]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
</script>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 省市区三级联动
|
|
90
|
+
|
|
91
|
+
需要用到该示例中的regions.json文件,可以到[uv-ui](https://ext.dcloud.net.cn/plugin?id=12287)项目中相应目录找到
|
|
92
|
+
|
|
93
|
+
**注意:uvui项目中提供的regions.json只做演示数据,不一定准确,开发者可以使用其他更准确的数据,只要格式一样即可**
|
|
94
|
+
|
|
95
|
+
```vue
|
|
96
|
+
<template>
|
|
97
|
+
<view>
|
|
98
|
+
<uv-picker ref="picker" :columns="addressList" :loading="loading" keyName="name" @change="change" @confirm="confirm">
|
|
99
|
+
</uv-picker>
|
|
100
|
+
<button @click="open">打开</button>
|
|
101
|
+
</view>
|
|
102
|
+
</template>
|
|
103
|
+
<script setup>
|
|
104
|
+
import { computed, ref } from 'vue';
|
|
105
|
+
|
|
106
|
+
const picker = ref(null);
|
|
107
|
+
const loading = ref(true);
|
|
108
|
+
const provinces = ref([]);
|
|
109
|
+
const citys = ref([]);
|
|
110
|
+
const areas = ref([]);
|
|
111
|
+
const pickerValue = ref([0, 0, 0]);
|
|
112
|
+
const defaultValue = ref([3442, 1, 2]);
|
|
113
|
+
getData();
|
|
114
|
+
const addressList = computed(() => {
|
|
115
|
+
return [provinces.value, citys.value, areas.value];
|
|
116
|
+
});
|
|
117
|
+
function getData() {
|
|
118
|
+
uni.request({
|
|
119
|
+
method: 'GET',
|
|
120
|
+
url: '/static/uvui/example/regions.json',
|
|
121
|
+
success: res => {
|
|
122
|
+
const {
|
|
123
|
+
statusCode,
|
|
124
|
+
data
|
|
125
|
+
} = res;
|
|
126
|
+
if (statusCode === 200) {
|
|
127
|
+
console.log('获取的数据:', res);
|
|
128
|
+
provinces.value = data.sort((left, right) => Number(left.code) > Number(right.code) ? 1 : -1);
|
|
129
|
+
console.log(provinces.value);
|
|
130
|
+
handlePickValueDefault();
|
|
131
|
+
setTimeout(() => {
|
|
132
|
+
loading.value = false;
|
|
133
|
+
}, 200);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function handlePickValueDefault() {
|
|
139
|
+
// 设置省
|
|
140
|
+
pickerValue.value[0] = provinces.value.findIndex(item => Number(item.id) === defaultValue.value[0]);
|
|
141
|
+
// 设置市
|
|
142
|
+
citys.value = provinces.value[pickerValue.value[0]]?.children || [];
|
|
143
|
+
pickerValue.value[1] = citys.value.findIndex(item => Number(item.id) === defaultValue.value[1]);
|
|
144
|
+
// 设置区
|
|
145
|
+
areas.value = citys.value[pickerValue.value[1]]?.children || [];
|
|
146
|
+
pickerValue.value[2] = areas.value.findIndex(item => Number(item.id) === defaultValue.value[2]);
|
|
147
|
+
// 重置下位置
|
|
148
|
+
picker.value.setIndexs([pickerValue.value[0], pickerValue.value[1], pickerValue.value[2]], true);
|
|
149
|
+
}
|
|
150
|
+
function change(e) {
|
|
151
|
+
if (loading.value) return;
|
|
152
|
+
const {
|
|
153
|
+
columnIndex,
|
|
154
|
+
index,
|
|
155
|
+
indexs
|
|
156
|
+
} = e;
|
|
157
|
+
// 改变了省
|
|
158
|
+
if (columnIndex === 0) {
|
|
159
|
+
citys.value = provinces.value[index]?.children || [];
|
|
160
|
+
areas.value = citys.value[0]?.children || [];
|
|
161
|
+
picker.value.setIndexs([index, 0, 0], true);
|
|
162
|
+
} else if (columnIndex === 1) {
|
|
163
|
+
areas.value = citys.value[index]?.children || [];
|
|
164
|
+
picker.value.setIndexs(indexs, true);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function open() {
|
|
168
|
+
picker.value.open();
|
|
169
|
+
handlePickValueDefault();
|
|
170
|
+
}
|
|
171
|
+
function confirm(e) {
|
|
172
|
+
console.log('确认选择的地区:', e);
|
|
173
|
+
uni.showToast({
|
|
174
|
+
icon: 'none',
|
|
175
|
+
title: `${e.value[0].name}/${e.value[1].name}/${e.value[2].name}`
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
</script>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 加载状态
|
|
183
|
+
|
|
184
|
+
由于需要多列联动,此模式和上面的"多列模式"基本相同,在加载之前将`loading`设置为`true`,数据获取完成之后再置为`false`即可。
|
|
185
|
+
|
|
186
|
+
```vue
|
|
187
|
+
<template>
|
|
188
|
+
<view>
|
|
189
|
+
<uv-picker ref="picker" :loading="loading" :columns="columns" @change="change"></uv-picker>
|
|
190
|
+
<button @click="openPicker">打开</button>
|
|
191
|
+
</view>
|
|
192
|
+
</template>
|
|
193
|
+
<script setup>
|
|
194
|
+
import { ref } from 'vue';
|
|
195
|
+
|
|
196
|
+
const picker = ref(null);
|
|
197
|
+
const loading = ref(false);
|
|
198
|
+
const columns = ref([['中国', '美国'], ['深圳', '厦门', '上海', '拉萨']]);
|
|
199
|
+
const columnData = ref([['深圳', '厦门', '上海', '拉萨'], ['得州', '华盛顿', '纽约', '阿拉斯加']]);
|
|
200
|
+
function openPicker() {
|
|
201
|
+
picker.value.open();
|
|
202
|
+
}
|
|
203
|
+
function confirm(e) {
|
|
204
|
+
console.log('confirm', e);
|
|
205
|
+
}
|
|
206
|
+
function change(e) {
|
|
207
|
+
console.log('change');
|
|
208
|
+
const {
|
|
209
|
+
columnIndex,
|
|
210
|
+
index
|
|
211
|
+
} = e;
|
|
212
|
+
if (columnIndex === 0) {
|
|
213
|
+
loading.value = true;
|
|
214
|
+
setTimeout(() => {
|
|
215
|
+
picker.value.setColumnValues(1, columnData.value[index]);
|
|
216
|
+
loading.value = false;
|
|
217
|
+
}, 2000);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
</script>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### 自定义选项值
|
|
225
|
+
|
|
226
|
+
参数`columns`可以传入自定义选项值,可以通过`keyName`参数控制对应的显示属性。
|
|
227
|
+
|
|
228
|
+
```vue
|
|
229
|
+
<template>
|
|
230
|
+
<view>
|
|
231
|
+
<uv-picker ref="picker" :columns="columns" keyName="label" @confirm="confirm"></uv-picker>
|
|
232
|
+
<button @click="openPicker">打开</button>
|
|
233
|
+
</view>
|
|
234
|
+
</template>
|
|
235
|
+
<script setup>
|
|
236
|
+
import { ref } from 'vue';
|
|
237
|
+
|
|
238
|
+
const picker = ref(null);
|
|
239
|
+
const columns = ref([[{
|
|
240
|
+
label: '雪月夜',
|
|
241
|
+
// 其他属性值
|
|
242
|
+
id: 2021
|
|
243
|
+
// ...
|
|
244
|
+
}, {
|
|
245
|
+
label: '冷夜雨',
|
|
246
|
+
id: 804
|
|
247
|
+
}]]);
|
|
248
|
+
function openPicker() {
|
|
249
|
+
picker.value.open();
|
|
250
|
+
}
|
|
251
|
+
function confirm(e) {
|
|
252
|
+
console.log('confirm', e);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
</script>
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### 自定义颜色
|
|
259
|
+
|
|
260
|
+
通过`color`和`activeColor`属性分别设置文本颜色和文本选中颜色
|
|
261
|
+
|
|
262
|
+
```vue
|
|
263
|
+
<template>
|
|
264
|
+
<view>
|
|
265
|
+
<uv-picker ref="picker" :columns="columns" color="red" activeColor="blue" @confirm="confirm"></uv-picker>
|
|
266
|
+
<button @click="openPicker">打开</button>
|
|
267
|
+
</view>
|
|
268
|
+
</template>
|
|
269
|
+
<script setup>
|
|
270
|
+
import { ref } from 'vue';
|
|
271
|
+
|
|
272
|
+
const picker = ref(null);
|
|
273
|
+
const columns = ref([['中国', '美国', '日本']]);
|
|
274
|
+
function openPicker() {
|
|
275
|
+
picker.value.open();
|
|
276
|
+
}
|
|
277
|
+
function confirm(e) {
|
|
278
|
+
console.log('confirm', e);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
</script>
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### 默认值
|
|
285
|
+
|
|
286
|
+
- **通过defaultIndex设置:**
|
|
287
|
+
|
|
288
|
+
此组件的所有模式,都可以设置默认值,通过`defaultIndex`数组参数配置,数组元素的0表示选中每列的哪个值(从0开始),下面分别对几种模式进行说明:
|
|
289
|
+
|
|
290
|
+
**注意:** `defaultIndex`数组的长度,必须与列数相同,否则无效。
|
|
291
|
+
|
|
292
|
+
1. 单列模式
|
|
293
|
+
|
|
294
|
+
如设置`defaultIndex`为`[1]`表示默认选中第2个(从0开始),`[5]`表示选中第6个。
|
|
295
|
+
|
|
296
|
+
2. 多列模式
|
|
297
|
+
|
|
298
|
+
如设置`defaultIndex`为`[1, 3]`表示第一列默认选中第2个,第二列默认选中第4个。
|
|
299
|
+
|
|
300
|
+
- **通过setIndexs()方法设置:**
|
|
301
|
+
|
|
302
|
+
也可以通过模板 ref 调用 `picker.value?.setIndexs([1], true)` 进行设置,第一个参数与 `defaultIndex` 规则一样。
|
|
303
|
+
|
|
304
|
+
### 完整示例
|
|
305
|
+
|
|
306
|
+
::: tip 完整示例下载地址
|
|
307
|
+
|
|
308
|
+
[https://ext.dcloud.net.cn/plugin?name=uv-ui](https://ext.dcloud.net.cn/plugin?name=uv-ui)
|
|
309
|
+
|
|
310
|
+
:::
|
|
311
|
+
|
|
312
|
+
### API
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
### Picker Props
|
|
316
|
+
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|
|
317
|
+
|:- |:- |:- |:- |:- |
|
|
318
|
+
| columns | 设置每一列的数据,见上方说明 | Array | - | - |
|
|
319
|
+
| keyName | 自定义`columns`参数中需要展示的`text`属性键名 | String | - | - |
|
|
320
|
+
| showToolbar | 是否显示顶部的操作栏 | Boolean | true | true | false |
|
|
321
|
+
| title | 顶部中间的标题 | String | - | - |
|
|
322
|
+
| round <badge text="1.0.10" /> | 弹窗圆角 | String | Number | 0 | - |
|
|
323
|
+
| loading | 加载状态 | Boolean | false | true | false |
|
|
324
|
+
| itemHeight | 各列中,单个选项的高度 | String | Number | 44 | - |
|
|
325
|
+
| cancelText | 取消按钮的文字 | String | 取消 | - |
|
|
326
|
+
| confirmText | 确认按钮的文字 | String | 确认 | - |
|
|
327
|
+
| cancelColor | 取消按钮的颜色 | String | #909193 | - |
|
|
328
|
+
| confirmColor | 确认按钮的颜色 | String | #3c9cff | - |
|
|
329
|
+
| color <badge text="1.0.5" /> | 文本颜色 | String | #606266 | - |
|
|
330
|
+
| activeColor <badge text="1.0.5" /> | 选中文本颜色 | String | #606266 | - |
|
|
331
|
+
| visibleItemCount | 每列中可见选项的数量 | String | Number | 5 | - |
|
|
332
|
+
| closeOnClickOverlay | 是否允许点击遮罩关闭选择器 | Boolean | true | true | false |
|
|
333
|
+
| closeOnClickConfirm | 是否允许点击确认关闭选择器 | Boolean | true | true | false |
|
|
334
|
+
| defaultIndex | 各列的默认索引。如果设置该值不生效,请使用下方的`setIndexs()`方法 | Array | - | - |
|
|
335
|
+
| immediateChange | 是否在手指松开时立即触发`change`事件。若不开启则会在滚动动画结束后触发`change`事件,只在微信`2.21.1`及以上有效 | Boolean | true | true | false |
|
|
336
|
+
|
|
337
|
+
### Picker Methods
|
|
338
|
+
| 名称 | 说明 |
|
|
339
|
+
|:- |:- |
|
|
340
|
+
| open | 弹出颜色选择组件 |
|
|
341
|
+
| close | 关闭颜色选择组件 |
|
|
342
|
+
| setIndexs | 设置对应列的选择值,eg:`picker.value?.setIndexs([1], true)` |
|
|
343
|
+
| setColumnValues | 多列联动时需要用到,见[上方用法](/components/picker.html#多列模式与多列联动) |
|
|
344
|
+
|
|
345
|
+
### Picker Events
|
|
346
|
+
|事件名 |说明 |回调参数 |
|
|
347
|
+
|:- |:- |:- |
|
|
348
|
+
| @confirm | 点击确定按钮触发 | Array: 见上方"回调参数"部分说明 |
|
|
349
|
+
| @change | 当选择值变化时触发 | Array: 见上方"回调参数"部分说明 |
|
|
350
|
+
| @cancel | 点击取消按钮触发 | - |
|
|
351
|
+
| @close | 关闭选择器时触发 | - |
|
|
352
|
+
|
|
353
|
+
<style scoped>
|
|
354
|
+
h3[id=picker-methods] + table thead tr th:nth-child(2) {
|
|
355
|
+
width: 70%;
|
|
356
|
+
}
|
|
357
|
+
</style>
|