@fredwsw/frontend-rules 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +302 -0
- package/bin/cli.js +155 -0
- package/package.json +22 -0
- package/template/docs/uv-ui-docs/action-sheet-cn.md +180 -0
- package/template/docs/uv-ui-docs/album-cn.md +104 -0
- package/template/docs/uv-ui-docs/alert-cn.md +71 -0
- package/template/docs/uv-ui-docs/avatar-cn.md +149 -0
- package/template/docs/uv-ui-docs/back-top-cn.md +121 -0
- package/template/docs/uv-ui-docs/badge-cn.md +100 -0
- package/template/docs/uv-ui-docs/button-cn.md +181 -0
- package/template/docs/uv-ui-docs/calendar-cn.md +179 -0
- package/template/docs/uv-ui-docs/calendars-cn.md +264 -0
- package/template/docs/uv-ui-docs/cell-cn.md +163 -0
- package/template/docs/uv-ui-docs/checkbox-cn.md +164 -0
- package/template/docs/uv-ui-docs/code-cn.md +122 -0
- package/template/docs/uv-ui-docs/code-input-cn.md +127 -0
- package/template/docs/uv-ui-docs/collapse-cn.md +206 -0
- package/template/docs/uv-ui-docs/color-cn.md +122 -0
- package/template/docs/uv-ui-docs/count-down-cn.md +169 -0
- package/template/docs/uv-ui-docs/count-to-cn.md +125 -0
- package/template/docs/uv-ui-docs/datetime-picker-cn.md +167 -0
- package/template/docs/uv-ui-docs/divider-cn.md +90 -0
- package/template/docs/uv-ui-docs/drop-down-cn.md +287 -0
- package/template/docs/uv-ui-docs/empty-cn.md +76 -0
- package/template/docs/uv-ui-docs/form-cn.md +220 -0
- package/template/docs/uv-ui-docs/gap-cn.md +63 -0
- package/template/docs/uv-ui-docs/grid-cn.md +187 -0
- package/template/docs/uv-ui-docs/icon-cn.md +255 -0
- package/template/docs/uv-ui-docs/image-cn.md +170 -0
- package/template/docs/uv-ui-docs/index-list-cn.md +132 -0
- package/template/docs/uv-ui-docs/input-cn.md +157 -0
- package/template/docs/uv-ui-docs/keyboard-cn.md +156 -0
- package/template/docs/uv-ui-docs/layout-cn.md +215 -0
- package/template/docs/uv-ui-docs/line-cn.md +77 -0
- package/template/docs/uv-ui-docs/line-progress-cn.md +132 -0
- package/template/docs/uv-ui-docs/link-cn.md +97 -0
- package/template/docs/uv-ui-docs/list-cn.md +185 -0
- package/template/docs/uv-ui-docs/load-more-cn.md +144 -0
- package/template/docs/uv-ui-docs/loading-icon-cn.md +125 -0
- package/template/docs/uv-ui-docs/loading-page-cn.md +85 -0
- package/template/docs/uv-ui-docs/modal-cn.md +212 -0
- package/template/docs/uv-ui-docs/navbar-cn.md +171 -0
- package/template/docs/uv-ui-docs/no-network-cn.md +112 -0
- package/template/docs/uv-ui-docs/notice-bar-cn.md +119 -0
- package/template/docs/uv-ui-docs/notify-cn.md +185 -0
- package/template/docs/uv-ui-docs/number-box-cn.md +131 -0
- package/template/docs/uv-ui-docs/overlay-cn.md +122 -0
- package/template/docs/uv-ui-docs/parse-cn.md +177 -0
- package/template/docs/uv-ui-docs/pick-color-cn.md +147 -0
- package/template/docs/uv-ui-docs/picker-cn.md +159 -0
- package/template/docs/uv-ui-docs/popup-cn.md +184 -0
- package/template/docs/uv-ui-docs/qrcode-cn.md +150 -0
- package/template/docs/uv-ui-docs/radio-cn.md +166 -0
- package/template/docs/uv-ui-docs/rate-cn.md +91 -0
- package/template/docs/uv-ui-docs/read-more-cn.md +191 -0
- package/template/docs/uv-ui-docs/scroll-list-cn.md +188 -0
- package/template/docs/uv-ui-docs/search-cn.md +107 -0
- package/template/docs/uv-ui-docs/skeleton-cn.md +101 -0
- package/template/docs/uv-ui-docs/skeletons-cn.md +312 -0
- package/template/docs/uv-ui-docs/slider-cn.md +98 -0
- package/template/docs/uv-ui-docs/steps-cn.md +158 -0
- package/template/docs/uv-ui-docs/sticky-cn.md +82 -0
- package/template/docs/uv-ui-docs/subsection-cn.md +161 -0
- package/template/docs/uv-ui-docs/swipe-action-cn.md +207 -0
- package/template/docs/uv-ui-docs/swiper-cn.md +247 -0
- package/template/docs/uv-ui-docs/switch-cn.md +136 -0
- package/template/docs/uv-ui-docs/tabbar-cn.md +224 -0
- package/template/docs/uv-ui-docs/tabs-cn.md +260 -0
- package/template/docs/uv-ui-docs/tags-cn.md +191 -0
- package/template/docs/uv-ui-docs/text-cn.md +178 -0
- package/template/docs/uv-ui-docs/textarea-cn.md +132 -0
- package/template/docs/uv-ui-docs/toast-cn.md +110 -0
- package/template/docs/uv-ui-docs/tooltip-cn.md +91 -0
- package/template/docs/uv-ui-docs/transition-cn.md +202 -0
- package/template/docs/uv-ui-docs/upload-cn.md +156 -0
- package/template/docs/uv-ui-docs/vtabs-cn.md +190 -0
- package/template/docs/uv-ui-docs/waterfall-cn.md +276 -0
- package/template/rules/common.mdc +90 -0
- package/template/rules/uv-ui-docs.mdc +111 -0
- package/template/skills/code-simplifier/SKILL.md +109 -0
- package/template/skills/frontend-design/SKILL.md +44 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
---
|
|
2
|
+
group: 基础
|
|
3
|
+
category: Components
|
|
4
|
+
title: Button
|
|
5
|
+
subtitle: 按钮
|
|
6
|
+
description: 基于 uni-app button 二次封装,扩展更多主题色与尺寸能力。
|
|
7
|
+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*BD2JSKm8I-kAAAAAAAAAAAAADrJ8AQ/original
|
|
8
|
+
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*r29rQ51bNdwAAAAAAAAAAAAADrJ8AQ/original
|
|
9
|
+
demo:
|
|
10
|
+
cols: 2
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 何时使用 {#when-to-use}
|
|
14
|
+
|
|
15
|
+
按钮用于触发一个操作(提交、确认、取消、跳转等)。`uv-button` 基于 uni-app 的 `button` 组件二次封装,主要扩展点:
|
|
16
|
+
|
|
17
|
+
- `type`:提供更多主题色
|
|
18
|
+
- `size`:提供更多尺寸选项
|
|
19
|
+
|
|
20
|
+
> 完整示例下载地址:[uv-ui 插件市场](https://ext.dcloud.net.cn/plugin?name=uv-ui)
|
|
21
|
+
|
|
22
|
+
## 平台兼容性 {#platform}
|
|
23
|
+
|
|
24
|
+
| App(vue) | App(nvue) | H5 | 小程序 | VUE2 | VUE3 |
|
|
25
|
+
| --- | --- | --- | --- | --- | --- |
|
|
26
|
+
| √ | √ | √ | √ | √ | √ |
|
|
27
|
+
|
|
28
|
+
**组件名:** `uv-button`
|
|
29
|
+
|
|
30
|
+
## 注意事项 {#notice}
|
|
31
|
+
|
|
32
|
+
- 本组件扩展了更多能力,部分属性与官方 `button` 完全一致。更详细开放能力说明参考 uni-app 文档:[uni-app button 组件](https://uniapp.dcloud.net.cn/component/button.html)
|
|
33
|
+
- 受微信小程序限制,微信小程序中设置了 `form-type` 的 `uv-button` **无法触发** `form` 组件的 `@submit`(H5 和 App 正常)
|
|
34
|
+
- 如需给 `uv-button` 设置宽度,建议外层包一层 `view` 控制宽度,或使用 `customStyle`
|
|
35
|
+
- 微信小程序下直接写 class/内联样式可能受编译结构影响,推荐用 `customStyle`(对象,驼峰命名)传入
|
|
36
|
+
|
|
37
|
+
## 代码演示 {#examples}
|
|
38
|
+
|
|
39
|
+
### 基本使用 {#basic}
|
|
40
|
+
|
|
41
|
+
文字建议通过 `text` 传入。
|
|
42
|
+
|
|
43
|
+
```vue
|
|
44
|
+
<uv-button text="月落"></uv-button>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 多种形态 {#variants}
|
|
48
|
+
|
|
49
|
+
- `type`:default / primary / success / info / warning / error
|
|
50
|
+
- `plain`:镂空
|
|
51
|
+
- `hairline`:细边
|
|
52
|
+
- `disabled`:禁用
|
|
53
|
+
- `loading` + `loadingText`:加载态
|
|
54
|
+
- `icon`:图标按钮(配合 uv-icon)
|
|
55
|
+
- `shape`:square / circle
|
|
56
|
+
- `color`:支持 `linear-gradient(...)` 渐变
|
|
57
|
+
- `size`:normal / large / mini(以及组件扩展的更多值)
|
|
58
|
+
|
|
59
|
+
```vue
|
|
60
|
+
<template>
|
|
61
|
+
<view style="padding: 20px;">
|
|
62
|
+
<uv-button type="primary" text="确定"></uv-button>
|
|
63
|
+
<uv-button type="primary" :plain="true" text="镂空"></uv-button>
|
|
64
|
+
<uv-button type="primary" :plain="true" :hairline="true" text="细边"></uv-button>
|
|
65
|
+
<uv-button type="primary" :disabled="disabled" text="禁用"></uv-button>
|
|
66
|
+
<uv-button type="primary" loading loadingText="加载中"></uv-button>
|
|
67
|
+
<uv-button type="primary" icon="map" text="图标按钮"></uv-button>
|
|
68
|
+
<uv-button type="primary" shape="circle" text="按钮形状"></uv-button>
|
|
69
|
+
<uv-button text="渐变色按钮" color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"></uv-button>
|
|
70
|
+
<uv-button type="primary" size="small" text="大小尺寸"></uv-button>
|
|
71
|
+
</view>
|
|
72
|
+
</template>
|
|
73
|
+
<script>
|
|
74
|
+
export default {
|
|
75
|
+
data() {
|
|
76
|
+
return { disabled: true }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
</script>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 使用 customStyle 定义外部样式 {#custom-style}
|
|
83
|
+
|
|
84
|
+
非微信小程序平台根元素就是原生 `button`,样式改动相对容易;微信小程序因编译结构导致样式传递可能不稳定,推荐使用 `customStyle`(对象、驼峰命名)传入。
|
|
85
|
+
|
|
86
|
+
注意:nvue 中圆角等部分样式需要使用连字符写法(示例已包含)。
|
|
87
|
+
|
|
88
|
+
```vue
|
|
89
|
+
<template>
|
|
90
|
+
<view>
|
|
91
|
+
<uv-button :custom-style="customStyle" color="#fff" text="雪月夜"></uv-button>
|
|
92
|
+
</view>
|
|
93
|
+
</template>
|
|
94
|
+
<script>
|
|
95
|
+
export default {
|
|
96
|
+
computed: {
|
|
97
|
+
customStyle() {
|
|
98
|
+
return {
|
|
99
|
+
height: '80rpx',
|
|
100
|
+
background: '#3c9cff',
|
|
101
|
+
color: '#fff',
|
|
102
|
+
borderRadius: '40rpx',
|
|
103
|
+
'border-top-right-radius': '40rpx',
|
|
104
|
+
'border-bottom-left-radius': '40rpx',
|
|
105
|
+
'border-bottom-right-radius': '40rpx'
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
</script>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## API {#api}
|
|
114
|
+
|
|
115
|
+
### Button Props {#props}
|
|
116
|
+
|
|
117
|
+
| 属性名 | 类型 | 默认值 | 说明 | 可选值 |
|
|
118
|
+
| --- | --- | --- | --- | --- |
|
|
119
|
+
| hairline | Boolean | true | 是否显示细边框 | true \| false |
|
|
120
|
+
| type | String | info | 按钮样式类型 | info \| primary \| error \| warning \| success |
|
|
121
|
+
| size | String | normal | 按钮大小 | normal \| large \| mini |
|
|
122
|
+
| shape | String | square | 外观形状 | square \| circle |
|
|
123
|
+
| plain | Boolean | false | 是否镂空 | true \| false |
|
|
124
|
+
| disabled | Boolean | false | 是否禁用 | true \| false |
|
|
125
|
+
| loading | Boolean | false | 是否显示 loading 图标 | true \| false |
|
|
126
|
+
| loadingText | String | - | 加载中文字 | - |
|
|
127
|
+
| loadingMode | String | spinner | loading 图标类型 | 参考 LoadingIcon 模式 |
|
|
128
|
+
| loadingSize | String \| Number | 15 | loading 图标大小 | - |
|
|
129
|
+
| openType | String | - | 开放能力(同 uni-app button) | - |
|
|
130
|
+
| formType | String | - | 用于 form 的 submit/reset(同 uni-app button) | - |
|
|
131
|
+
| appParameter | String | - | open-type=launchApp 时向 App 传参(微信/QQ) | - |
|
|
132
|
+
| hoverStopPropagation | Boolean | true | 是否阻止祖先节点出现点击态(微信) | true \| false |
|
|
133
|
+
| lang | String | en | 返回用户信息语言 | zh_CN \| zh_TW \| en |
|
|
134
|
+
| sessionFrom | String | - | 会话来源(openType=contact) | - |
|
|
135
|
+
| sendMessageTitle | String | - | 会话消息卡片标题(openType=contact) | - |
|
|
136
|
+
| sendMessagePath | String | - | 会话消息卡片跳转路径(openType=contact) | - |
|
|
137
|
+
| sendMessageImg | String | - | 会话消息卡片图片(openType=contact) | - |
|
|
138
|
+
| showMessageCard | String | - | 是否显示会话消息卡片(openType=contact) | - |
|
|
139
|
+
| dataName | String | - | 小程序 data-xxx 额外参数,通过 `target.dataset.name` 取 | - |
|
|
140
|
+
| throttleTime | String \| Number | 0 | 节流时间(ms) | - |
|
|
141
|
+
| hoverStartTime | String \| Number | 0 | 按住多久出现点击态(ms) | - |
|
|
142
|
+
| hoverStayTime | String \| Number | 200 | 松开后点击态保留(ms) | - |
|
|
143
|
+
| text | String \| Number | - | 按钮文字(建议优先用 text,便于统一样式;nvue 下 slot 不易控样式) | - |
|
|
144
|
+
| icon | String | - | 按钮图标 | - |
|
|
145
|
+
| iconSize | String \| Number | - | 按钮图标大小(1.0.9) | - |
|
|
146
|
+
| iconColor | String | - | 图标颜色:plain=true 时与边框一致,否则默认白色(info 主题为黑色) | - |
|
|
147
|
+
| color | String | - | 按钮颜色,支持 `linear-gradient` | - |
|
|
148
|
+
| customTextStyle | Object \| String | - | 自定义文字样式(避免 customStyle 覆盖不到) | - |
|
|
149
|
+
| customStyle | Object \| String | - | 自定义外部样式(推荐对象驼峰命名) | - |
|
|
150
|
+
|
|
151
|
+
### Button Events {#events}
|
|
152
|
+
|
|
153
|
+
说明:在 H5、App 可以直接监听 `tap` 等同 click,但部分 HBuilder X 版本微信小程序对组件 `@tap` 可能无效,建议统一使用组件内部 `@click`。
|
|
154
|
+
|
|
155
|
+
| 事件名 | 说明 | 回调参数 | 平台差异说明 |
|
|
156
|
+
| --- | --- | --- | --- |
|
|
157
|
+
| @click | 按钮点击(请勿使用 @tap,微信小程序可能无效) | 点击事件对象及参数 | - |
|
|
158
|
+
| @getphonenumber | 获取用户手机号(open-type=getPhoneNumber) | - | 微信/支付宝/百度/抖音/快手/京东 |
|
|
159
|
+
| @getuserinfo | 获取用户信息(open-type=getUserInfo) | - | 微信/QQ/百度/快手/京东 |
|
|
160
|
+
| @error | 开放能力错误回调(open-type=launchApp) | - | 微信/QQ/快手/京东 |
|
|
161
|
+
| @opensetting | 从小程序打开 App 成功(open-type=launchApp) | - | 微信/QQ/百度/快手/京东 |
|
|
162
|
+
| @launchapp | 打开 App 成功(open-type=launchApp) | - | 微信/QQ/快手/京东 |
|
|
163
|
+
| @contact | 客服消息回调(open-type=contact) | - | 微信/QQ/百度/快手 |
|
|
164
|
+
| @chooseavatar | 获取用户头像(open-type=chooseAvatar) | - | 微信小程序 |
|
|
165
|
+
| @agreeprivacyauthorization | 同意隐私协议(open-type=agreePrivacyAuthorization) | - | 微信小程序 2.33.0 |
|
|
166
|
+
| @addgroupapp | 添加群应用(open-type=addGroupApp) | - | QQ 小程序 |
|
|
167
|
+
| @chooseaddress | 选择收货地址(open-type=chooseAddress) | - | 百度小程序 |
|
|
168
|
+
| @chooseinvoicetitle | 选择发票抬头(open-type=chooseInvoiceTitle) | - | 百度小程序 |
|
|
169
|
+
| @subscribe | 订阅消息授权(open-type=subscribe) | - | 百度小程序 |
|
|
170
|
+
| @login | 登录回调(open-type=login) | - | 百度小程序 |
|
|
171
|
+
| @im | 跳转 IM 成功回调(open-type=im) | - | 抖音小程序 2.68.0+ |
|
|
172
|
+
|
|
173
|
+
关于 `open-type` 的设置与回调详情,参考 uni-app 官方 button 文档。
|
|
174
|
+
|
|
175
|
+
### Button Slots {#slots}
|
|
176
|
+
|
|
177
|
+
| 名称 | 说明 |
|
|
178
|
+
| --- | --- |
|
|
179
|
+
| default | 默认插槽(按钮文本);建议统一使用 `text` 参数以保证样式一致 |
|
|
180
|
+
| suffix | 后置插槽,方便在按钮文字后追加图标等内容 |
|
|
181
|
+
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
---
|
|
2
|
+
group: 表单
|
|
3
|
+
category: Components
|
|
4
|
+
title: Calendar
|
|
5
|
+
subtitle: 日历
|
|
6
|
+
description: 用于单选日期、多选日期、范围选择等,包裹在底部弹起容器中。
|
|
7
|
+
demo:
|
|
8
|
+
cols: 2
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 何时使用 {#when-to-use}
|
|
12
|
+
|
|
13
|
+
`uv-calendar` 用于专业的日期选择场景,如入住离店等。与 Picker 的日期模式有重合,但本组件支持范围选择,Picker 可配置时分秒等,按需选择。
|
|
14
|
+
|
|
15
|
+
> 完整示例下载地址:[uv-ui 插件市场](https://ext.dcloud.net.cn/plugin?name=uv-ui)
|
|
16
|
+
|
|
17
|
+
## 平台兼容性 {#platform}
|
|
18
|
+
|
|
19
|
+
| App(vue) | App(nvue) | H5 | 小程序 | VUE2 | VUE3 |
|
|
20
|
+
| --- | --- | --- | --- | --- | --- |
|
|
21
|
+
| √ | √ | √ | √ | √ | √ |
|
|
22
|
+
|
|
23
|
+
**组件名:** `uv-calendar`
|
|
24
|
+
|
|
25
|
+
## 代码演示 {#examples}
|
|
26
|
+
|
|
27
|
+
### 基本使用 {#basic}
|
|
28
|
+
|
|
29
|
+
通过 ref 调用 `open()` 和 `close()` 控制打开/关闭,通过 `mode` 指定单选/多选/范围。
|
|
30
|
+
|
|
31
|
+
```vue
|
|
32
|
+
<template>
|
|
33
|
+
<view>
|
|
34
|
+
<uv-calendar ref="calendar" @confirm="confirm"></uv-calendar>
|
|
35
|
+
<button @click="open">打开</button>
|
|
36
|
+
</view>
|
|
37
|
+
</template>
|
|
38
|
+
<script>
|
|
39
|
+
export default {
|
|
40
|
+
methods: {
|
|
41
|
+
open() {
|
|
42
|
+
this.$refs.calendar.open()
|
|
43
|
+
},
|
|
44
|
+
confirm(e) {
|
|
45
|
+
console.log('日历选择:', e)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
</script>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 单个日期 {#single}
|
|
53
|
+
|
|
54
|
+
`mode="single"`,返回数组如 `["2021-07-01"]`。
|
|
55
|
+
|
|
56
|
+
```vue
|
|
57
|
+
<uv-calendar ref="calendar" mode="single" @confirm="confirm"></uv-calendar>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 多个日期 {#multiple}
|
|
61
|
+
|
|
62
|
+
`mode="multiple"`,返回数组如 `["2021-07-27", "2021-07-29", "2021-07-30"]`。
|
|
63
|
+
|
|
64
|
+
```vue
|
|
65
|
+
<uv-calendar ref="calendar" mode="multiple" @confirm="confirm"></uv-calendar>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 日期范围 {#range}
|
|
69
|
+
|
|
70
|
+
`mode="range"`,返回范围内所有日期数组,如入住离店。
|
|
71
|
+
|
|
72
|
+
```vue
|
|
73
|
+
<uv-calendar ref="calendar" mode="range" @confirm="confirm"></uv-calendar>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 自定义主题色 {#color}
|
|
77
|
+
|
|
78
|
+
```vue
|
|
79
|
+
<uv-calendar ref="calendar" mode="range" color="#f56c6c" @confirm="confirm"></uv-calendar>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 自定义文案 {#formatter}
|
|
83
|
+
|
|
84
|
+
通过 `setFormatter` 设置日期文案(bottomInfo、disabled 等)。在 `onReady` 中调用。
|
|
85
|
+
|
|
86
|
+
```vue
|
|
87
|
+
<template>
|
|
88
|
+
<uv-calendar
|
|
89
|
+
ref="calendar"
|
|
90
|
+
mode="range"
|
|
91
|
+
startText="住店"
|
|
92
|
+
endText="离店"
|
|
93
|
+
confirmDisabledText="请选择离店日期"
|
|
94
|
+
></uv-calendar>
|
|
95
|
+
</template>
|
|
96
|
+
<script>
|
|
97
|
+
export default {
|
|
98
|
+
onReady() {
|
|
99
|
+
this.$refs.calendar.setFormatter(this.formatter)
|
|
100
|
+
},
|
|
101
|
+
methods: {
|
|
102
|
+
formatter(day) {
|
|
103
|
+
const d = new Date()
|
|
104
|
+
const month = d.getMonth() + 1
|
|
105
|
+
const date = d.getDate()
|
|
106
|
+
if (day.month == month && day.day == date + 3) {
|
|
107
|
+
day.bottomInfo = '打8折'
|
|
108
|
+
day.dot = true
|
|
109
|
+
day.disabled = true
|
|
110
|
+
}
|
|
111
|
+
return day
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
</script>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 日期最大范围 {#max-date}
|
|
119
|
+
|
|
120
|
+
```vue
|
|
121
|
+
<uv-calendar ref="calendar" :maxDate="maxDate" @confirm="confirm"></uv-calendar>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 显示农历 {#lunar}
|
|
125
|
+
|
|
126
|
+
```vue
|
|
127
|
+
<uv-calendar ref="calendar" showLunar @confirm="confirm"></uv-calendar>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 默认日期 {#default-date}
|
|
131
|
+
|
|
132
|
+
```vue
|
|
133
|
+
<uv-calendar ref="calendar" mode="multiple" :defaultDate="defaultDateMultiple" @confirm="confirm"></uv-calendar>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## API {#api}
|
|
137
|
+
|
|
138
|
+
### Calendar Props {#props}
|
|
139
|
+
|
|
140
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
141
|
+
| --- | --- | --- | --- |
|
|
142
|
+
| title | 标题 | String | 日期选择 |
|
|
143
|
+
| showTitle | 是否显示标题 | Boolean | true |
|
|
144
|
+
| showSubtitle | 是否显示副标题 | Boolean | true |
|
|
145
|
+
| mode | 日期类型 | String | single |
|
|
146
|
+
| startText | range 时第一个日期底部文案 | String | 开始 |
|
|
147
|
+
| endText | range 时最后一个日期底部文案 | String | 结束 |
|
|
148
|
+
| color | 主题色 | String | #3c9cff |
|
|
149
|
+
| minDate | 最小可选日期 | Number \| String | 0 |
|
|
150
|
+
| maxDate | 最大可选日期 | Number \| String | 0 |
|
|
151
|
+
| defaultDate | 默认选中日期 | Array \| String \| Date | null |
|
|
152
|
+
| maxCount | multiple 时最多可选数量 | Number \| String | - |
|
|
153
|
+
| rowHeight | 日期行高 | Number \| String | 56 |
|
|
154
|
+
| showLunar | 是否显示农历 | Boolean | false |
|
|
155
|
+
| showMark | 是否显示月份背景色 | Boolean | true |
|
|
156
|
+
| confirmText | 确定按钮文字 | String | 确定 |
|
|
157
|
+
| confirmDisabledText | 禁用时确定按钮文字 | String | 确定 |
|
|
158
|
+
| closeOnClickOverlay | 点击遮罩是否关闭 | Boolean | false |
|
|
159
|
+
| closeOnClickConfirm | 点击确认是否关闭 | Boolean | true |
|
|
160
|
+
| readonly | 只读 | Boolean | false |
|
|
161
|
+
| maxRange | range 时最多可选天数 | Number \| String | - |
|
|
162
|
+
| round | 圆角 | String \| Number | 0 |
|
|
163
|
+
| monthNum | 最大展示月份数 | String \| Number | 3 |
|
|
164
|
+
|
|
165
|
+
### Calendar Methods {#methods}
|
|
166
|
+
|
|
167
|
+
| 方法名 | 说明 |
|
|
168
|
+
| --- | --- |
|
|
169
|
+
| open | 弹出日历 |
|
|
170
|
+
| close | 关闭日历 |
|
|
171
|
+
| setFormatter | 日期格式化函数 |
|
|
172
|
+
|
|
173
|
+
### Calendar Events {#events}
|
|
174
|
+
|
|
175
|
+
| 事件名 | 说明 | 回调参数 |
|
|
176
|
+
| --- | --- | --- |
|
|
177
|
+
| @confirm | 日期选择完成后 | 选择日期相关参数 |
|
|
178
|
+
| @close | 日历关闭时 | - |
|
|
179
|
+
| @change | 点击日期时 | { day, selected } |
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
---
|
|
2
|
+
group: 表单
|
|
3
|
+
category: Components
|
|
4
|
+
title: Calendars
|
|
5
|
+
subtitle: 新版日历(推荐)
|
|
6
|
+
description: 查看日期、选择单个/多个或任意范围日期,支持打点、自定义文案与主题。
|
|
7
|
+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*BD2JSKm8I-kAAAAAAAAAAAAADrJ8AQ/original
|
|
8
|
+
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*r29rQ51bNdwAAAAAAAAAAAAADrJ8AQ/original
|
|
9
|
+
demo:
|
|
10
|
+
cols: 2
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 何时使用 {#when-to-use}
|
|
14
|
+
|
|
15
|
+
新版日历组件 uv-calendars 用于解决老版本 uv-calendar 的性能问题,特别是日期选择范围受限、体验不佳等缺点。
|
|
16
|
+
|
|
17
|
+
- 查看日期、选择单个、多个或任意范围日期
|
|
18
|
+
- 打点、自定义文案、自定义主题
|
|
19
|
+
- 插入页面或弹窗展示
|
|
20
|
+
|
|
21
|
+
**常用场景:** 酒店日期预订、火车/机票选择、上下班打卡等。
|
|
22
|
+
|
|
23
|
+
> 完整示例下载地址:[uv-ui 插件市场](https://ext.dcloud.net.cn/plugin?name=uv-ui)
|
|
24
|
+
|
|
25
|
+
## 平台兼容性 {#platform}
|
|
26
|
+
|
|
27
|
+
| App(vue) | App(nvue) | H5 | 小程序 | VUE2 | VUE3 |
|
|
28
|
+
| --- | --- | --- | --- | --- | --- |
|
|
29
|
+
| √ | √ | √ | √ | √ | √ |
|
|
30
|
+
|
|
31
|
+
**组件名:** `uv-calendars`
|
|
32
|
+
|
|
33
|
+
## 注意事项 {#notice}
|
|
34
|
+
|
|
35
|
+
- 农历转换使用 `@1900-2100区间内的公历、农历互转` 方案
|
|
36
|
+
- `date` 属性需传入 **String**,如 `2023-08-03`,不要传 `new Date()`
|
|
37
|
+
- 通过 `insert` 区分事件:弹窗模式用 `@confirm`,插入模式用 `@change`
|
|
38
|
+
- 弹窗模式下无法阻止后面元素滚动,需在弹窗打开后手动禁止滚动穿透(可参考 uv-popup 等组件)
|
|
39
|
+
|
|
40
|
+
## 代码演示 {#examples}
|
|
41
|
+
|
|
42
|
+
### 基本使用 {#basic}
|
|
43
|
+
|
|
44
|
+
通过 ref 调用 `open()` 打开日历(弹窗模式)。
|
|
45
|
+
|
|
46
|
+
```vue
|
|
47
|
+
<template>
|
|
48
|
+
<view>
|
|
49
|
+
<uv-calendars ref="calendars" @confirm="confirm" />
|
|
50
|
+
<button @click="open">打开日历</button>
|
|
51
|
+
</view>
|
|
52
|
+
</template>
|
|
53
|
+
<script>
|
|
54
|
+
export default {
|
|
55
|
+
methods: {
|
|
56
|
+
open() {
|
|
57
|
+
this.$refs.calendars.open()
|
|
58
|
+
},
|
|
59
|
+
confirm(e) {
|
|
60
|
+
console.log(e)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
</script>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 插入模式 {#insert}
|
|
68
|
+
|
|
69
|
+
设置 `insert` 为 `true`,日历直接嵌入页面,不通过弹窗展示。此时使用 `@change` 而非 `@confirm`。
|
|
70
|
+
|
|
71
|
+
```vue
|
|
72
|
+
<template>
|
|
73
|
+
<view>
|
|
74
|
+
<uv-calendars insert @change="change" />
|
|
75
|
+
</view>
|
|
76
|
+
</template>
|
|
77
|
+
<script>
|
|
78
|
+
export default {
|
|
79
|
+
methods: {
|
|
80
|
+
change(e) {
|
|
81
|
+
console.log(e)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
</script>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 多日期模式 {#multiple}
|
|
89
|
+
|
|
90
|
+
设置 `mode="multiple"`。默认值可通过 `date` 设置,如 `['2023-08-26','2023-08-27','2023-08-28']`。
|
|
91
|
+
|
|
92
|
+
```vue
|
|
93
|
+
<template>
|
|
94
|
+
<view>
|
|
95
|
+
<uv-calendars ref="calendars" mode="multiple" @confirm="confirm" />
|
|
96
|
+
<button @click="open">打开日历</button>
|
|
97
|
+
</view>
|
|
98
|
+
</template>
|
|
99
|
+
<script>
|
|
100
|
+
export default {
|
|
101
|
+
methods: {
|
|
102
|
+
open() {
|
|
103
|
+
this.$refs.calendars.open()
|
|
104
|
+
},
|
|
105
|
+
confirm(e) {
|
|
106
|
+
console.log(e)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
</script>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 日期范围模式 {#range}
|
|
114
|
+
|
|
115
|
+
设置 `mode="range"`。默认值可通过 `date` 设置,如 `['2023-08-26','2023-08-29']`。
|
|
116
|
+
|
|
117
|
+
```vue
|
|
118
|
+
<template>
|
|
119
|
+
<view>
|
|
120
|
+
<uv-calendars ref="calendars" mode="range" @confirm="confirm" />
|
|
121
|
+
<button @click="open">打开日历</button>
|
|
122
|
+
</view>
|
|
123
|
+
</template>
|
|
124
|
+
<script>
|
|
125
|
+
export default {
|
|
126
|
+
methods: {
|
|
127
|
+
open() {
|
|
128
|
+
this.$refs.calendars.open()
|
|
129
|
+
},
|
|
130
|
+
confirm(e) {
|
|
131
|
+
console.log(e)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
</script>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### 自定义主题颜色 {#color}
|
|
139
|
+
|
|
140
|
+
通过 `color` 设置主题色,建议使用 16 进制,如 `#ff0000`。
|
|
141
|
+
|
|
142
|
+
```vue
|
|
143
|
+
<template>
|
|
144
|
+
<view>
|
|
145
|
+
<uv-calendars
|
|
146
|
+
ref="calendars"
|
|
147
|
+
mode="range"
|
|
148
|
+
color="#ff0000"
|
|
149
|
+
:date="['2023-08-08','2023-08-27']"
|
|
150
|
+
@confirm="confirm"
|
|
151
|
+
/>
|
|
152
|
+
<button @click="open">打开日历</button>
|
|
153
|
+
</view>
|
|
154
|
+
</template>
|
|
155
|
+
<script>
|
|
156
|
+
export default {
|
|
157
|
+
methods: {
|
|
158
|
+
open() {
|
|
159
|
+
this.$refs.calendars.open()
|
|
160
|
+
},
|
|
161
|
+
confirm(e) {
|
|
162
|
+
console.log(e)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
</script>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 自定义文案(打点) {#selected}
|
|
170
|
+
|
|
171
|
+
通过 `selected` 配置打点,格式为对象数组,详见 Selected Options。
|
|
172
|
+
|
|
173
|
+
```vue
|
|
174
|
+
<template>
|
|
175
|
+
<view>
|
|
176
|
+
<uv-calendars
|
|
177
|
+
ref="calendars"
|
|
178
|
+
mode="range"
|
|
179
|
+
title="选择日期"
|
|
180
|
+
start-text="住店"
|
|
181
|
+
end-text="离店"
|
|
182
|
+
:selected="selected"
|
|
183
|
+
@confirm="confirm"
|
|
184
|
+
/>
|
|
185
|
+
<button @click="open">打开日历</button>
|
|
186
|
+
</view>
|
|
187
|
+
</template>
|
|
188
|
+
<script>
|
|
189
|
+
export default {
|
|
190
|
+
data() {
|
|
191
|
+
const d = new Date()
|
|
192
|
+
const year = d.getFullYear()
|
|
193
|
+
let month = d.getMonth() + 1
|
|
194
|
+
month = month < 10 ? `0${month}` : month
|
|
195
|
+
return {
|
|
196
|
+
selected: [
|
|
197
|
+
{ date: `${year}-${month}-02`, info: '签到', badge: true, infoColor: '#ff0000' },
|
|
198
|
+
{ date: `${year}-${month}-06`, info: '余10', infoColor: '#19be6b', topinfo: '¥100', topinfoColor: '#19be6b' }
|
|
199
|
+
]
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
methods: {
|
|
203
|
+
open() {
|
|
204
|
+
this.$refs.calendars.open()
|
|
205
|
+
},
|
|
206
|
+
confirm(e) {
|
|
207
|
+
console.log(e)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
</script>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## API {#api}
|
|
215
|
+
|
|
216
|
+
### Calendars Props {#props}
|
|
217
|
+
|
|
218
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
219
|
+
| --- | --- | --- | --- |
|
|
220
|
+
| date | String \| Array | 今天 | 默认选中日期。单日期为字符串如 `2023-08-26`;multiple/range 为数组如 `['2023-08-26','2023-08-29']` |
|
|
221
|
+
| lunar | Boolean | false | 是否显示农历 |
|
|
222
|
+
| mode | String | - | 日期类型:不填(单日期)、`multiple`(多日期)、`range`(范围) |
|
|
223
|
+
| insert | Boolean | false | 是否插入模式,`true` 插入页面,`false` 弹窗模式 |
|
|
224
|
+
| clearDate | Boolean | true | 弹窗模式是否清空上次选择 |
|
|
225
|
+
| selected | Array | - | 打点配置,格式 `[{date, info, disable, ...}]`,见 Selected Options |
|
|
226
|
+
| startDate | String | - | 可选范围开始日期,如 `2023-01-01`,之前日期禁用 |
|
|
227
|
+
| endDate | String | - | 可选范围结束日期,如 `2023-02-01`,之后日期禁用 |
|
|
228
|
+
| showMonth | Boolean | true | 是否显示月份背景 |
|
|
229
|
+
| round | String \| Number | 8px | 弹窗模式圆角 |
|
|
230
|
+
| color | String | #3c9cff | 主题色,建议 16 进制 |
|
|
231
|
+
| confirmColor | String | #3c9cff | 确认按钮颜色 |
|
|
232
|
+
| cancelColor | String | #909193 | 取消按钮颜色 |
|
|
233
|
+
| closeOnClickOverlay | Boolean | true | 点击遮罩是否关闭 |
|
|
234
|
+
| startText | String | 开始 | range 模式下首日底部文案 |
|
|
235
|
+
| endText | String | 结束 | range 模式下末日底部文案 |
|
|
236
|
+
| allowSameDay | Boolean | false | range 模式下是否允许起止同一天 (1.0.11) |
|
|
237
|
+
| readonly | Boolean | false | 只读,禁止选择 (1.0.15) |
|
|
238
|
+
|
|
239
|
+
### Selected Options(selected 数组项) {#selected-options}
|
|
240
|
+
|
|
241
|
+
| 属性名 | 说明 |
|
|
242
|
+
| --- | --- |
|
|
243
|
+
| date | 日期,格式 `YYYY-mm-dd` |
|
|
244
|
+
| info | 底部文案 |
|
|
245
|
+
| infoColor | 底部文案颜色 |
|
|
246
|
+
| topinfo | 头部文案 |
|
|
247
|
+
| topinfoColor | 头部文案颜色 |
|
|
248
|
+
| badge | 是否显示右上角红点 |
|
|
249
|
+
| disable | 是否禁止点击 |
|
|
250
|
+
|
|
251
|
+
### Calendars Methods {#methods}
|
|
252
|
+
|
|
253
|
+
| 方法名 | 说明 |
|
|
254
|
+
| --- | --- |
|
|
255
|
+
| open | `insert` 为 false 时,调用此方法弹出日历 |
|
|
256
|
+
|
|
257
|
+
### Calendars Events {#events}
|
|
258
|
+
|
|
259
|
+
| 事件名 | 说明 | 返回 |
|
|
260
|
+
| --- | --- | --- |
|
|
261
|
+
| @confirm | 点击确定时触发 | 日期参数:fulldate(单)、multiple(多)、range(范围) |
|
|
262
|
+
| @close | 关闭日历时触发 | - |
|
|
263
|
+
| @change | 点击日期时触发 | 同上;insert 为 true 时生效 |
|
|
264
|
+
| @monthSwitch | 选择年月确认时触发 | `{ year, month }` |
|