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.
- package/changelog.md +6 -0
- package/components/u-action-sheet/u-action-sheet.vue +205 -0
- package/components/u-alert-tips/u-alert-tips.vue +241 -0
- package/components/u-avatar/u-avatar.vue +220 -0
- package/components/u-avatar-cropper/u-avatar-cropper.vue +329 -0
- package/components/u-avatar-cropper/weCropper.d.ts +54 -0
- package/components/u-avatar-cropper/weCropper.js +1267 -0
- package/components/u-avatar-cropper/weCropper.ts +1254 -0
- package/components/u-back-top/u-back-top.vue +156 -0
- package/components/u-badge/u-badge.vue +189 -0
- package/components/u-button/u-button.vue +562 -0
- package/components/u-calendar/u-calendar.vue +725 -0
- package/components/u-car-keyboard/u-car-keyboard.vue +236 -0
- package/components/u-card/u-card.vue +240 -0
- package/components/u-cell-group/u-cell-group.vue +56 -0
- package/components/u-cell-item/u-cell-item.vue +245 -0
- package/components/u-checkbox/u-checkbox.vue +310 -0
- package/components/u-checkbox-group/u-checkbox-group.vue +134 -0
- package/components/u-circle-progress/u-circle-progress.vue +210 -0
- package/components/u-col/u-col.vue +135 -0
- package/components/u-collapse/u-collapse.vue +82 -0
- package/components/u-collapse-item/u-collapse-item.vue +190 -0
- package/components/u-column-notice/u-column-notice.vue +264 -0
- package/components/u-count-down/u-count-down.vue +333 -0
- package/components/u-count-to/u-count-to.vue +297 -0
- package/components/u-divider/u-divider.vue +141 -0
- package/components/u-dropdown/u-dropdown.vue +311 -0
- package/components/u-dropdown-item/u-dropdown-item.vue +135 -0
- package/components/u-empty/u-empty.vue +111 -0
- package/components/u-field/u-field.vue +469 -0
- package/components/u-form/u-form.vue +162 -0
- package/components/u-form-item/u-form-item.vue +476 -0
- package/components/u-full-screen/u-full-screen.vue +80 -0
- package/components/u-gap/u-gap.vue +48 -0
- package/components/u-grid/u-grid.vue +101 -0
- package/components/u-grid-item/u-grid-item.vue +136 -0
- package/components/u-icon/u-icon.vue +389 -0
- package/components/u-image/types.ts +48 -0
- package/components/u-image/u-image.vue +218 -0
- package/components/u-index-anchor/u-index-anchor.vue +101 -0
- package/components/u-index-list/u-index-list.vue +376 -0
- package/components/u-input/u-input.vue +462 -0
- package/components/u-keyboard/u-keyboard.vue +188 -0
- package/components/u-lazy-load/u-lazy-load.vue +288 -0
- package/components/u-line/u-line.vue +71 -0
- package/components/u-line-progress/u-line-progress.vue +128 -0
- package/components/u-link/u-link.vue +87 -0
- package/components/u-loading/u-loading.vue +111 -0
- package/components/u-loadmore/u-loadmore.vue +205 -0
- package/components/u-mask/u-mask.vue +137 -0
- package/components/u-message-input/u-message-input.vue +315 -0
- package/components/u-modal/u-modal.vue +284 -0
- package/components/u-navbar/u-navbar.vue +314 -0
- package/components/u-no-network/image.ts +2 -0
- package/components/u-no-network/u-no-network.vue +311 -0
- package/components/u-notice-bar/u-notice-bar.vue +274 -0
- package/components/u-number-box/u-number-box.vue +344 -0
- package/components/u-number-keyboard/u-number-keyboard.vue +170 -0
- package/components/u-parse/libs/CssHandler.js +100 -0
- package/components/u-parse/libs/MpHtmlParser.js +580 -0
- package/components/u-parse/libs/config.js +80 -0
- package/components/u-parse/libs/handler.wxs +22 -0
- package/components/u-parse/libs/trees.vue +505 -0
- package/components/u-parse/u-parse.vue +645 -0
- package/components/u-picker/u-picker.vue +808 -0
- package/components/u-popup/u-popup.vue +404 -0
- package/components/u-radio/u-radio.vue +272 -0
- package/components/u-radio-group/u-radio-group.vue +116 -0
- package/components/u-rate/u-rate.vue +349 -0
- package/components/u-read-more/u-read-more.vue +199 -0
- package/components/u-row/u-row.vue +95 -0
- package/components/u-row-notice/u-row-notice.vue +273 -0
- package/components/u-search/u-search.vue +298 -0
- package/components/u-section/u-section.vue +175 -0
- package/components/u-select/u-select.vue +387 -0
- package/components/u-skeleton/u-skeleton.vue +230 -0
- package/components/u-slider/u-slider.vue +293 -0
- package/components/u-steps/u-steps.vue +200 -0
- package/components/u-sticky/u-sticky.vue +189 -0
- package/components/u-subsection/u-subsection.vue +388 -0
- package/components/u-swipe-action/u-swipe-action.vue +289 -0
- package/components/u-swiper/u-swiper.vue +305 -0
- package/components/u-switch/u-switch.vue +146 -0
- package/components/u-tabbar/u-tabbar.vue +347 -0
- package/components/u-table/u-table.vue +104 -0
- package/components/u-tabs/u-tabs.vue +322 -0
- package/components/u-tabs-swiper/u-tabs-swiper.vue +426 -0
- package/components/u-tag/u-tag.vue +270 -0
- package/components/u-td/u-td.vue +76 -0
- package/components/u-th/u-th.vue +70 -0
- package/components/u-time-line/u-time-line.vue +39 -0
- package/components/u-time-line-item/u-time-line-item.vue +88 -0
- package/components/u-toast/types.ts +4 -0
- package/components/u-toast/u-toast.vue +238 -0
- package/components/u-top-tips/u-top-tips.vue +118 -0
- package/components/u-tr/u-tr.vue +24 -0
- package/components/u-upload/u-upload.vue +600 -0
- package/components/u-verification-code/u-verification-code.vue +194 -0
- package/components/u-waterfall/u-waterfall.vue +186 -0
- package/iconfont.css +910 -0
- package/index.scss +23 -0
- package/index.ts +166 -0
- package/libs/config/config.ts +26 -0
- package/libs/config/zIndex.ts +37 -0
- package/libs/css/color.scss +155 -0
- package/libs/css/common.scss +176 -0
- package/libs/css/style.components.scss +7 -0
- package/libs/css/style.h5.scss +8 -0
- package/libs/css/style.mp.scss +72 -0
- package/libs/css/style.nvue.scss +3 -0
- package/libs/css/style.vue.scss +175 -0
- package/libs/function/$parent.ts +22 -0
- package/libs/function/addUnit.ts +13 -0
- package/libs/function/color.ts +37 -0
- package/libs/function/colorGradient.ts +123 -0
- package/libs/function/debounce.ts +28 -0
- package/libs/function/deepClone.ts +39 -0
- package/libs/function/deepMerge.ts +34 -0
- package/libs/function/getParent.ts +59 -0
- package/libs/function/getRect.ts +26 -0
- package/libs/function/guid.ts +42 -0
- package/libs/function/md5.ts +397 -0
- package/libs/function/parent.ts +21 -0
- package/libs/function/queryParams.ts +60 -0
- package/libs/function/random.ts +16 -0
- package/libs/function/randomArray.ts +11 -0
- package/libs/function/route.ts +118 -0
- package/libs/function/sys.ts +15 -0
- package/libs/function/test.ts +229 -0
- package/libs/function/throttle.ts +31 -0
- package/libs/function/timeFormat.ts +54 -0
- package/libs/function/timeFrom.ts +48 -0
- package/libs/function/toast.ts +14 -0
- package/libs/function/trim.ts +21 -0
- package/libs/function/type2icon.ts +36 -0
- package/libs/hooks/useEmitter.ts +77 -0
- package/libs/hooks/useParent.ts +29 -0
- package/libs/request/index.ts +237 -0
- package/libs/store/index.ts +88 -0
- package/libs/util/area.ts +1 -0
- package/libs/util/async-validator.js +1356 -0
- package/libs/util/city.ts +1 -0
- package/libs/util/emitter.ts +112 -0
- package/libs/util/mitt.ts +118 -0
- package/libs/util/parent.ts +20 -0
- package/libs/util/province.ts +1 -0
- package/package.json +98 -0
- package/readme.md +165 -0
- package/theme.scss +38 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
class="u-circle-progress"
|
|
4
|
+
:style="{
|
|
5
|
+
width: widthPx + 'px',
|
|
6
|
+
height: widthPx + 'px',
|
|
7
|
+
backgroundColor: bgColor
|
|
8
|
+
}"
|
|
9
|
+
>
|
|
10
|
+
<!-- 支付宝小程序不支持canvas-id属性,必须用id属性 -->
|
|
11
|
+
<canvas
|
|
12
|
+
class="u-canvas-bg"
|
|
13
|
+
type="2d"
|
|
14
|
+
:canvas-id="elBgId"
|
|
15
|
+
:id="elBgId"
|
|
16
|
+
:style="{
|
|
17
|
+
width: widthPx + 'px',
|
|
18
|
+
height: widthPx + 'px'
|
|
19
|
+
}"
|
|
20
|
+
></canvas>
|
|
21
|
+
<canvas
|
|
22
|
+
class="u-canvas"
|
|
23
|
+
type="2d"
|
|
24
|
+
:canvas-id="elId"
|
|
25
|
+
:id="elId"
|
|
26
|
+
:style="{
|
|
27
|
+
width: widthPx + 'px',
|
|
28
|
+
height: widthPx + 'px'
|
|
29
|
+
}"
|
|
30
|
+
></canvas>
|
|
31
|
+
<slot></slot>
|
|
32
|
+
</view>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<script setup lang="ts">
|
|
36
|
+
import { ref, computed, watch, onMounted } from 'vue';
|
|
37
|
+
import { $u } from '../..';
|
|
38
|
+
|
|
39
|
+
defineOptions({
|
|
40
|
+
name: 'u-circle-progress'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* circleProgress 环形进度条
|
|
45
|
+
* @description 展示操作或任务的当前进度,比如上传文件,是一个圆形的进度条。注意:此组件的percent值只能动态增加,不能动态减少。
|
|
46
|
+
* @tutorial https://www.uviewui.com/components/circleProgress.html
|
|
47
|
+
* @property {String Number} percent 圆环进度百分比值,为数值类型,0-100
|
|
48
|
+
* @property {String} inactive-color 圆环的底色,默认为灰色(该值无法动态变更)(默认#ececec)
|
|
49
|
+
* @property {String} active-color 圆环激活部分的颜色(该值无法动态变更)(默认#19be6b)
|
|
50
|
+
* @property {String Number} width 整个圆环组件的宽度,高度默认等于宽度值,单位rpx(默认200)
|
|
51
|
+
* @property {String Number} border-width 圆环的边框宽度,单位rpx(默认14)
|
|
52
|
+
* @property {String Number} duration 整个圆环执行一圈的时间,单位ms(默认呢1500)
|
|
53
|
+
* @property {String} type 如设置,active-color值将会失效
|
|
54
|
+
* @property {String} bg-color 整个组件背景颜色,默认为白色
|
|
55
|
+
* @example <u-circle-progress active-color="#2979ff" :percent="80"></u-circle-progress>
|
|
56
|
+
*/
|
|
57
|
+
const props = defineProps({
|
|
58
|
+
/** 圆环进度百分比值 */
|
|
59
|
+
percent: {
|
|
60
|
+
type: Number,
|
|
61
|
+
default: 0,
|
|
62
|
+
// 限制值在0到100之间
|
|
63
|
+
validator: (val: number) => val >= 0 && val <= 100
|
|
64
|
+
},
|
|
65
|
+
/** 底部圆环的颜色(灰色的圆环) */
|
|
66
|
+
inactiveColor: { type: String, default: '#ececec' },
|
|
67
|
+
/** 圆环激活部分的颜色 */
|
|
68
|
+
activeColor: { type: String, default: '#19be6b' },
|
|
69
|
+
/** 圆环线条的宽度,单位rpx */
|
|
70
|
+
borderWidth: { type: [Number, String], default: 14 },
|
|
71
|
+
/** 整个圆形的宽度,单位rpx */
|
|
72
|
+
width: { type: [Number, String], default: 200 },
|
|
73
|
+
/** 整个圆环执行一圈的时间,单位ms */
|
|
74
|
+
duration: { type: [Number, String], default: 1500 },
|
|
75
|
+
/** 主题类型 */
|
|
76
|
+
type: { type: String, default: '' },
|
|
77
|
+
/** 整个圆环进度区域的背景色 */
|
|
78
|
+
bgColor: { type: String, default: '#ffffff' }
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
let elBgId = $u.guid(); // 非微信端的时候,需用动态的id,否则一个页面多个圆形进度条组件数据会混乱
|
|
82
|
+
let elId = $u.guid();
|
|
83
|
+
// #ifdef MP-WEIXIN
|
|
84
|
+
elBgId = 'uCircleProgressBgId'; // 微信小程序中不能使用$u.guid()形式动态生成id值,否则会报错
|
|
85
|
+
elId = 'uCircleProgressElId';
|
|
86
|
+
// #endif
|
|
87
|
+
|
|
88
|
+
const widthPx = computed(() => (typeof uni !== 'undefined' && uni.upx2px ? uni.upx2px(Number(props.width)) : Number(props.width)));
|
|
89
|
+
const borderWidthPx = computed(() => (typeof uni !== 'undefined' && uni.upx2px ? uni.upx2px(Number(props.borderWidth)) : Number(props.borderWidth)));
|
|
90
|
+
const startAngle = -Math.PI / 2; // canvas画圆的起始角度,默认为3点钟方向,定位到12点钟方向
|
|
91
|
+
const progressContext = ref<any>(null); // 活动圆的canvas上下文
|
|
92
|
+
const newPercent = ref(props.percent); // 当动态修改进度值的时候,保存进度值的变化前后值,用于比较用
|
|
93
|
+
const oldPercent = ref(0); // 当动态修改进度值的时候,保存进度值的变化前后值,用于比较用
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 有type主题时,优先起作用
|
|
97
|
+
*/
|
|
98
|
+
const circleColor = computed(() => {
|
|
99
|
+
if (props.type && ['success', 'error', 'info', 'primary', 'warning'].includes(props.type)) {
|
|
100
|
+
return $u.color[props.type as keyof typeof $u.color] as string;
|
|
101
|
+
}
|
|
102
|
+
return props.activeColor;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// 监听percent变化,动态绘制进度
|
|
106
|
+
watch(
|
|
107
|
+
() => props.percent,
|
|
108
|
+
(nVal, oVal = 0) => {
|
|
109
|
+
let next = nVal > 100 ? 100 : nVal;
|
|
110
|
+
let prev = oVal < 0 ? 0 : oVal;
|
|
111
|
+
newPercent.value = next;
|
|
112
|
+
oldPercent.value = prev;
|
|
113
|
+
setTimeout(() => {
|
|
114
|
+
// 无论是百分比值增加还是减少,需要操作还是原来的旧的百分比值
|
|
115
|
+
// 将此值减少或者新增到新的百分比值
|
|
116
|
+
drawCircleByProgress(prev);
|
|
117
|
+
}, 50);
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
onMounted(() => {
|
|
122
|
+
// 赋值,用于加载后第一个画圆使用
|
|
123
|
+
newPercent.value = props.percent;
|
|
124
|
+
oldPercent.value = 0;
|
|
125
|
+
// 在h5端,必须要做一点延时才起作用,this.$nextTick()无效(HX2.4.7)
|
|
126
|
+
setTimeout(() => {
|
|
127
|
+
drawProgressBg();
|
|
128
|
+
drawCircleByProgress(oldPercent.value);
|
|
129
|
+
}, 50);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 绘制底部灰色圆环
|
|
134
|
+
*/
|
|
135
|
+
function drawProgressBg() {
|
|
136
|
+
const ctx = uni.createCanvasContext(elBgId);
|
|
137
|
+
|
|
138
|
+
ctx.setLineWidth(borderWidthPx.value); // 设置圆环宽度
|
|
139
|
+
ctx.setStrokeStyle(props.inactiveColor); // 线条颜色
|
|
140
|
+
ctx.beginPath(); // 开始描绘路径
|
|
141
|
+
const radius = widthPx.value / 2; // 设置一个原点(110,110),半径为100的圆的路径到当前路径
|
|
142
|
+
ctx.arc(radius, radius, radius - borderWidthPx.value, 0, 2 * Math.PI, false);
|
|
143
|
+
ctx.stroke(); // 对路径进行描绘
|
|
144
|
+
ctx.draw();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 绘制进度圆环
|
|
149
|
+
* @param progress 当前进度
|
|
150
|
+
*/
|
|
151
|
+
function drawCircleByProgress(progress: number) {
|
|
152
|
+
// 第一次操作进度环时将上下文保存到了this.data中,直接使用即可
|
|
153
|
+
let ctx = progressContext.value;
|
|
154
|
+
if (!ctx) {
|
|
155
|
+
ctx = uni.createCanvasContext(elId);
|
|
156
|
+
progressContext.value = ctx;
|
|
157
|
+
}
|
|
158
|
+
// 表示进度的两端为圆形
|
|
159
|
+
ctx.setLineCap('round');
|
|
160
|
+
// 设置线条的宽度和颜色
|
|
161
|
+
ctx.setLineWidth(borderWidthPx.value);
|
|
162
|
+
ctx.setStrokeStyle(circleColor.value);
|
|
163
|
+
// 将总过渡时间除以100,得出每修改百分之一进度所需的时间
|
|
164
|
+
let time = Math.floor(Number(props.duration) / 100);
|
|
165
|
+
// 结束角的计算依据为:将2π分为100份,乘以当前的进度值,得出终止点的弧度值,加起始角,为整个圆从默认的
|
|
166
|
+
// 3点钟方向开始画图,转为更好理解的12点钟方向开始作图,这需要起始角和终止角同时加上this.startAngle值
|
|
167
|
+
let endAngle = ((2 * Math.PI) / 100) * progress + startAngle;
|
|
168
|
+
ctx.beginPath();
|
|
169
|
+
// 半径为整个canvas宽度的一半
|
|
170
|
+
let radius = widthPx.value / 2;
|
|
171
|
+
ctx.arc(radius, radius, radius - borderWidthPx.value, startAngle, endAngle, false);
|
|
172
|
+
ctx.stroke();
|
|
173
|
+
ctx.draw();
|
|
174
|
+
// 如果变更后新值大于旧值,意味着增大了百分比
|
|
175
|
+
if (newPercent.value > oldPercent.value) {
|
|
176
|
+
// 每次递增百分之一
|
|
177
|
+
progress++;
|
|
178
|
+
// 如果新增后的值,大于需要设置的值百分比值,停止继续增加
|
|
179
|
+
if (progress > newPercent.value) return;
|
|
180
|
+
} else {
|
|
181
|
+
// 同理于上面
|
|
182
|
+
progress--;
|
|
183
|
+
if (progress < newPercent.value) return;
|
|
184
|
+
}
|
|
185
|
+
setTimeout(() => {
|
|
186
|
+
// 定时器,每次操作间隔为time值,为了让进度条有动画效果
|
|
187
|
+
drawCircleByProgress(progress);
|
|
188
|
+
}, time);
|
|
189
|
+
}
|
|
190
|
+
</script>
|
|
191
|
+
|
|
192
|
+
<style lang="scss" scoped>
|
|
193
|
+
@import '../../libs/css/style.components.scss';
|
|
194
|
+
.u-circle-progress {
|
|
195
|
+
position: relative;
|
|
196
|
+
/* #ifndef APP-NVUE */
|
|
197
|
+
display: inline-flex;
|
|
198
|
+
/* #endif */
|
|
199
|
+
align-items: center;
|
|
200
|
+
justify-content: center;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.u-canvas-bg {
|
|
204
|
+
position: absolute;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.u-canvas {
|
|
208
|
+
position: absolute;
|
|
209
|
+
}
|
|
210
|
+
</style>
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-col" :class="['u-col-' + span]" :style="colStyle" @tap="onClick">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { computed, inject } from 'vue';
|
|
9
|
+
|
|
10
|
+
defineOptions({
|
|
11
|
+
name: 'u-col'
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* col 布局单元格
|
|
16
|
+
* @description 通过基础的 12 分栏,迅速简便地创建布局(搭配<u-row>使用)
|
|
17
|
+
* @tutorial https://www.uviewui.com/components/layout.html
|
|
18
|
+
* @property {String|Number} span 栅格占据的列数,总12等分(默认0)
|
|
19
|
+
* @property {String} text-align 文字水平对齐方式(默认left)
|
|
20
|
+
* @property {String|Number} offset 分栏左边偏移,计算方式与span相同(默认0)
|
|
21
|
+
* @example <u-col span="3"><view class="demo-layout bg-purple"></view></u-col>
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const emit = defineEmits<{ (e: 'click'): void }>();
|
|
25
|
+
|
|
26
|
+
const props = defineProps({
|
|
27
|
+
/** 占父容器宽度的多少等分,总分为12份 */
|
|
28
|
+
span: { type: [Number, String], default: 12 },
|
|
29
|
+
/** 指定栅格左侧的间隔数(总12栏) */
|
|
30
|
+
offset: { type: [Number, String], default: 0 },
|
|
31
|
+
/** 水平排列方式,可选值为`start`(或`flex-start`)、`end`(或`flex-end`)、`center`、`around`(或`space-around`)、`between`(或`space-between`) */
|
|
32
|
+
justify: { type: String, default: 'start' },
|
|
33
|
+
/** 垂直对齐方式,可选值为top、center、bottom */
|
|
34
|
+
align: { type: String, default: 'center' },
|
|
35
|
+
/** 文字对齐方式 */
|
|
36
|
+
textAlign: { type: String, default: 'left' },
|
|
37
|
+
/** 是否阻止事件传播 */
|
|
38
|
+
stop: { type: Boolean, default: true }
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* gutter 给col添加间距,左右边距各占一半,从父组件u-row获取
|
|
43
|
+
*/
|
|
44
|
+
const gutter = inject('u-row-gutter', 20);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 计算水平排列方式
|
|
48
|
+
* @returns {string}
|
|
49
|
+
*/
|
|
50
|
+
const uJustify = computed(() => {
|
|
51
|
+
if (props.justify === 'end' || props.justify === 'start') return 'flex-' + props.justify;
|
|
52
|
+
else if (props.justify === 'around' || props.justify === 'between') return 'space-' + props.justify;
|
|
53
|
+
else return props.justify;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 计算垂直对齐方式
|
|
58
|
+
* @returns {string}
|
|
59
|
+
*/
|
|
60
|
+
const uAlignItem = computed(() => {
|
|
61
|
+
if (props.align === 'top') return 'flex-start';
|
|
62
|
+
if (props.align === 'bottom') return 'flex-end';
|
|
63
|
+
else return props.align;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 计算样式对象
|
|
68
|
+
*/
|
|
69
|
+
const colStyle = computed<any>(() => ({
|
|
70
|
+
padding: `0 ${Number(gutter) / 2}rpx`,
|
|
71
|
+
marginLeft: `${(100 / 12) * Number(props.offset)}%`,
|
|
72
|
+
flex: `0 0 ${(100 / 12) * Number(props.span)}%`,
|
|
73
|
+
alignItems: uAlignItem.value,
|
|
74
|
+
justifyContent: uJustify.value,
|
|
75
|
+
textAlign: props.textAlign
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 点击事件
|
|
80
|
+
* @param e 事件对象
|
|
81
|
+
*/
|
|
82
|
+
function onClick(e: Event) {
|
|
83
|
+
emit('click');
|
|
84
|
+
}
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<style lang="scss">
|
|
88
|
+
@import '../../libs/css/style.components.scss';
|
|
89
|
+
|
|
90
|
+
.u-col {
|
|
91
|
+
/* #ifdef MP-WEIXIN || MP-QQ || MP-TOUTIAO */
|
|
92
|
+
float: left;
|
|
93
|
+
/* #endif */
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.u-col-0 {
|
|
97
|
+
width: 0;
|
|
98
|
+
}
|
|
99
|
+
.u-col-1 {
|
|
100
|
+
width: calc(100% / 12);
|
|
101
|
+
}
|
|
102
|
+
.u-col-2 {
|
|
103
|
+
width: calc(100% / 12 * 2);
|
|
104
|
+
}
|
|
105
|
+
.u-col-3 {
|
|
106
|
+
width: calc(100% / 12 * 3);
|
|
107
|
+
}
|
|
108
|
+
.u-col-4 {
|
|
109
|
+
width: calc(100% / 12 * 4);
|
|
110
|
+
}
|
|
111
|
+
.u-col-5 {
|
|
112
|
+
width: calc(100% / 12 * 5);
|
|
113
|
+
}
|
|
114
|
+
.u-col-6 {
|
|
115
|
+
width: calc(100% / 12 * 6);
|
|
116
|
+
}
|
|
117
|
+
.u-col-7 {
|
|
118
|
+
width: calc(100% / 12 * 7);
|
|
119
|
+
}
|
|
120
|
+
.u-col-8 {
|
|
121
|
+
width: calc(100% / 12 * 8);
|
|
122
|
+
}
|
|
123
|
+
.u-col-9 {
|
|
124
|
+
width: calc(100% / 12 * 9);
|
|
125
|
+
}
|
|
126
|
+
.u-col-10 {
|
|
127
|
+
width: calc(100% / 12 * 10);
|
|
128
|
+
}
|
|
129
|
+
.u-col-11 {
|
|
130
|
+
width: calc(100% / 12 * 11);
|
|
131
|
+
}
|
|
132
|
+
.u-col-12 {
|
|
133
|
+
width: calc(100% / 12 * 12);
|
|
134
|
+
}
|
|
135
|
+
</style>
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-collapse">
|
|
3
|
+
<slot />
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { ref, provide } from 'vue';
|
|
9
|
+
|
|
10
|
+
defineOptions({
|
|
11
|
+
name: 'u-collapse'
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* collapse 手风琴
|
|
16
|
+
* @description 通过折叠面板收纳内容区域
|
|
17
|
+
* @tutorial https://www.uviewui.com/components/collapse.html
|
|
18
|
+
* @property {Boolean} accordion 是否手风琴模式(默认true)
|
|
19
|
+
* @property {Boolean} arrow 是否显示标题右侧的箭头(默认true)
|
|
20
|
+
* @property {String} arrow-color 标题右侧箭头的颜色(默认#909399)
|
|
21
|
+
* @property {Object} head-style 标题自定义样式,对象形式
|
|
22
|
+
* @property {Object} body-style 主体自定义样式,对象形式
|
|
23
|
+
* @property {String} hover-class 样式类名,按下时有效(默认u-hover-class)
|
|
24
|
+
* @event {Function} change 当前激活面板展开时触发(如果是手风琴模式,参数activeNames类型为String,否则为Array)
|
|
25
|
+
* @example <u-collapse></u-collapse>
|
|
26
|
+
*/
|
|
27
|
+
const props = defineProps({
|
|
28
|
+
/** 是否手风琴模式 */
|
|
29
|
+
accordion: { type: Boolean, default: true },
|
|
30
|
+
/** 头部的样式 */
|
|
31
|
+
headStyle: { type: Object, default: () => ({}) },
|
|
32
|
+
/** 主体的样式 */
|
|
33
|
+
bodyStyle: { type: Object, default: () => ({}) },
|
|
34
|
+
/** 每一个item的样式 */
|
|
35
|
+
itemStyle: { type: Object, default: () => ({}) },
|
|
36
|
+
/** 是否显示右侧的箭头 */
|
|
37
|
+
arrow: { type: Boolean, default: true },
|
|
38
|
+
/** 箭头的颜色 */
|
|
39
|
+
arrowColor: { type: String, default: '#909399' },
|
|
40
|
+
/** 标题部分按压时的样式类,"none"为无效果 */
|
|
41
|
+
hoverClass: { type: String, default: 'u-hover-class' }
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const emit = defineEmits(['change']);
|
|
45
|
+
|
|
46
|
+
// 子元素集合
|
|
47
|
+
const childrens = ref<any[]>([]);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 重新初始化一次内部的所有子元素的高度计算,用于异步获取数据渲染的情况
|
|
51
|
+
*/
|
|
52
|
+
function init() {
|
|
53
|
+
childrens.value.forEach((vm, index) => {
|
|
54
|
+
vm.init && vm.init();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* collapse item被点击,由collapse item调用父组件方法
|
|
60
|
+
*/
|
|
61
|
+
function onChange(index: string | number) {
|
|
62
|
+
emit('change', index);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
provide('u-collapse', {
|
|
66
|
+
childrens,
|
|
67
|
+
props,
|
|
68
|
+
init,
|
|
69
|
+
onChange
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
defineExpose({
|
|
73
|
+
props,
|
|
74
|
+
childrens,
|
|
75
|
+
init,
|
|
76
|
+
onChange
|
|
77
|
+
});
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<style lang="scss" scoped>
|
|
81
|
+
@import '../../libs/css/style.components.scss';
|
|
82
|
+
</style>
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-collapse-item" :style="itemStyle">
|
|
3
|
+
<view :hover-stay-time="200" class="u-collapse-head" @tap.stop="headClick" :hover-class="hoverClass" :style="headStyle">
|
|
4
|
+
<template v-if="!slots['title-all']">
|
|
5
|
+
<view v-if="!slots['title']" class="u-collapse-title u-line-1" :style="[{ textAlign: align ? align : 'left' }, isShow && activeStyle && !arrow ? activeStyle : '']">
|
|
6
|
+
{{ title }}
|
|
7
|
+
</view>
|
|
8
|
+
<slot v-else name="title" />
|
|
9
|
+
<view class="u-icon-wrap">
|
|
10
|
+
<u-icon v-if="arrow" :color="arrowColor" :class="{ 'u-arrow-down-icon-active': isShow }" class="u-arrow-down-icon" name="arrow-down"></u-icon>
|
|
11
|
+
</view>
|
|
12
|
+
</template>
|
|
13
|
+
<slot v-else name="title-all" />
|
|
14
|
+
</view>
|
|
15
|
+
<view class="u-collapse-body" :style="{ height: isShow ? height + 'px' : '0' }">
|
|
16
|
+
<view class="u-collapse-content" :id="elId" :style="bodyStyle">
|
|
17
|
+
<slot></slot>
|
|
18
|
+
</view>
|
|
19
|
+
</view>
|
|
20
|
+
</view>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script setup lang="ts">
|
|
24
|
+
import { ref, watch, onMounted, useSlots, getCurrentInstance, nextTick, inject } from 'vue';
|
|
25
|
+
import { $u } from '../..';
|
|
26
|
+
|
|
27
|
+
defineOptions({
|
|
28
|
+
name: 'u-collapse-item'
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* collapseItem 手风琴Item
|
|
33
|
+
* @description 通过折叠面板收纳内容区域(搭配u-collapse使用)
|
|
34
|
+
* @tutorial https://www.uviewui.com/components/collapse.html
|
|
35
|
+
* @property {String} title 面板标题
|
|
36
|
+
* @property {String Number} index 主要用于事件的回调,标识那个Item被点击
|
|
37
|
+
* @property {Boolean} disabled 面板是否可以打开或收起(默认false)
|
|
38
|
+
* @property {Boolean} open 设置某个面板的初始状态是否打开(默认false)
|
|
39
|
+
* @property {String Number} name 唯一标识符,如不设置,默认用当前collapse-item的索引值
|
|
40
|
+
* @property {String} align 标题的对齐方式(默认left)
|
|
41
|
+
* @property {Object} active-style 不显示箭头时,可以添加当前选择的collapse-item活动样式,对象形式
|
|
42
|
+
* @event {Function} change 某个item被打开或者收起时触发
|
|
43
|
+
* @example <u-collapse-item :title="item.head" v-for="(item, index) in itemList" :key="index">{{item.body}}</u-collapse-item>
|
|
44
|
+
*/
|
|
45
|
+
const props = defineProps({
|
|
46
|
+
/** 标题 */
|
|
47
|
+
title: { type: String, default: '' },
|
|
48
|
+
/** 标题的对齐方式 */
|
|
49
|
+
align: { type: String, default: 'left' },
|
|
50
|
+
/** 是否可以点击收起 */
|
|
51
|
+
disabled: { type: Boolean, default: false },
|
|
52
|
+
/** collapse显示与否 */
|
|
53
|
+
open: { type: Boolean, default: false },
|
|
54
|
+
/** 唯一标识符 */
|
|
55
|
+
name: { type: [Number, String], default: '' },
|
|
56
|
+
/** 活动样式 */
|
|
57
|
+
activeStyle: { type: Object, default: () => ({}) },
|
|
58
|
+
/** 标识当前为第几个 */
|
|
59
|
+
index: { type: [String, Number], default: '' }
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const emit = defineEmits(['change']);
|
|
63
|
+
const slots = useSlots();
|
|
64
|
+
const instance = getCurrentInstance();
|
|
65
|
+
|
|
66
|
+
const isShow = ref(false);
|
|
67
|
+
const elId = ref('');
|
|
68
|
+
const height = ref(0); // body内容的高度
|
|
69
|
+
const headStyle = ref<Record<string, any>>({}); // 头部样式,对象形式
|
|
70
|
+
const bodyStyle = ref<Record<string, any>>({}); // 主体部分样式
|
|
71
|
+
const itemStyle = ref<Record<string, any>>({}); // 每个item的整体样式
|
|
72
|
+
const arrowColor = ref(''); // 箭头的颜色
|
|
73
|
+
const hoverClass = ref(''); // 头部按下时的效果样式类
|
|
74
|
+
const arrow = ref(true); // 是否显示右侧箭头
|
|
75
|
+
// let parent: any = null
|
|
76
|
+
const parent = inject<any>('u-collapse', null);
|
|
77
|
+
// 监听 open 属性变化
|
|
78
|
+
watch(
|
|
79
|
+
() => props.open,
|
|
80
|
+
val => {
|
|
81
|
+
isShow.value = val;
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 异步获取内容,或者动态修改了内容时,需要重新初始化
|
|
87
|
+
*/
|
|
88
|
+
function init() {
|
|
89
|
+
if (parent) {
|
|
90
|
+
// 不存在时才添加本实例
|
|
91
|
+
if (!parent.childrens.value.includes(instance?.proxy)) parent.childrens.value.push(instance?.proxy);
|
|
92
|
+
headStyle.value = parent.props.headStyle;
|
|
93
|
+
bodyStyle.value = parent.props.bodyStyle;
|
|
94
|
+
arrowColor.value = parent.props.arrowColor;
|
|
95
|
+
hoverClass.value = parent.props.hoverClass;
|
|
96
|
+
arrow.value = parent.props.arrow;
|
|
97
|
+
itemStyle.value = parent.props.itemStyle;
|
|
98
|
+
}
|
|
99
|
+
elId.value = $u.guid();
|
|
100
|
+
nextTick(() => {
|
|
101
|
+
queryRect();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 点击collapsehead头部
|
|
107
|
+
*/
|
|
108
|
+
function headClick() {
|
|
109
|
+
if (props.disabled) return;
|
|
110
|
+
isShow.value = !isShow.value;
|
|
111
|
+
// 触发本组件的事件
|
|
112
|
+
emit('change', {
|
|
113
|
+
index: props.index,
|
|
114
|
+
show: isShow.value
|
|
115
|
+
});
|
|
116
|
+
// 只有在打开时才发出事件
|
|
117
|
+
if (isShow.value) parent && parent.onChange && parent.onChange(props.index);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 查询内容高度
|
|
122
|
+
*/
|
|
123
|
+
function queryRect() {
|
|
124
|
+
// getRect为uView自带的节点查询简化方法,详见文档介绍:https://www.uviewui.com/js/getRect.html
|
|
125
|
+
// 组件内部一般用this.$uGetRect,对外的为this.$u.getRect,二者功能一致,名称不同
|
|
126
|
+
$u.getRect('#' + elId.value, instance).then((res: any) => {
|
|
127
|
+
height.value = res.height;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
onMounted(() => {
|
|
132
|
+
init();
|
|
133
|
+
});
|
|
134
|
+
defineExpose({
|
|
135
|
+
init,
|
|
136
|
+
isShow,
|
|
137
|
+
elId,
|
|
138
|
+
height,
|
|
139
|
+
headStyle,
|
|
140
|
+
bodyStyle,
|
|
141
|
+
itemStyle,
|
|
142
|
+
arrowColor,
|
|
143
|
+
hoverClass,
|
|
144
|
+
arrow
|
|
145
|
+
});
|
|
146
|
+
</script>
|
|
147
|
+
|
|
148
|
+
<style lang="scss" scoped>
|
|
149
|
+
@import '../../libs/css/style.components.scss';
|
|
150
|
+
|
|
151
|
+
.u-collapse-head {
|
|
152
|
+
position: relative;
|
|
153
|
+
@include vue-flex;
|
|
154
|
+
justify-content: space-between;
|
|
155
|
+
align-items: center;
|
|
156
|
+
color: $u-main-color;
|
|
157
|
+
font-size: 30rpx;
|
|
158
|
+
line-height: 1;
|
|
159
|
+
padding: 24rpx 0;
|
|
160
|
+
text-align: left;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.u-collapse-title {
|
|
164
|
+
flex: 1;
|
|
165
|
+
overflow: hidden;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.u-arrow-down-icon {
|
|
169
|
+
transition: all 0.3s;
|
|
170
|
+
margin-right: 20rpx;
|
|
171
|
+
margin-left: 14rpx;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.u-arrow-down-icon-active {
|
|
175
|
+
transform: rotate(180deg);
|
|
176
|
+
transform-origin: center center;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.u-collapse-body {
|
|
180
|
+
overflow: hidden;
|
|
181
|
+
transition: all 0.3s;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.u-collapse-content {
|
|
185
|
+
overflow: hidden;
|
|
186
|
+
font-size: 28rpx;
|
|
187
|
+
color: $u-tips-color;
|
|
188
|
+
text-align: left;
|
|
189
|
+
}
|
|
190
|
+
</style>
|