uview-pro 0.3.7 → 0.3.8

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 CHANGED
@@ -1,3 +1,28 @@
1
+ ## 0.3.8(2025-11-04)
2
+
3
+ ### 📦‍ Build System | 打包构建
4
+
5
+ - 新增钉钉小程序运行和打包命令 ([a5b4ab3](https://github.com/anyup/uView-Pro/commit/a5b4ab3abab95b4c56bf02415f1785371f7f19ee))
6
+
7
+ ### 🐛 Bug Fixes | Bug 修复
8
+
9
+ - **u-circle-progress:** 修复微信小程序 canvas 2d 环形进度条绘制问题,适配不同平台的 canvas 上下文 ([e7ab701](https://github.com/anyup/uView-Pro/commit/e7ab701bcbd83e7861aeb9a104269265c6b38a56))
10
+
11
+ ### ✨ Features | 新功能
12
+
13
+ - **u-fab:** 新增悬浮按钮组件及演示示例 ([85848de](https://github.com/anyup/uView-Pro/commit/85848de6bae15d91942a633959459ae8e6ecb857))
14
+ - **u-fab:** 优化悬浮组件功能和交互,新增预设定位position、拖动吸边autoStick属性 ([65a4bde](https://github.com/anyup/uView-Pro/commit/65a4bde2331c8b2a49933bb4c5d7e1f97a11c56a))
15
+ - **u-text:** 新增 u-text 组件默认插槽支持 ([a7b6e59](https://github.com/anyup/uView-Pro/commit/a7b6e5944afbcd48920c25a58c07642544ff3d3e))
16
+
17
+ ### ♻️ Code Refactoring | 代码重构
18
+
19
+ - **fab:** 优化 fab 组件示例代码 ([ca71fa2](https://github.com/anyup/uView-Pro/commit/ca71fa28fa86baa53384eb366384d97a0b8d84b2))
20
+ - **u-fab:** 重构 gap 属性以支持对象类型 ([bee34bf](https://github.com/anyup/uView-Pro/commit/bee34bffd6a7587e9a82fe3e35cc64c096d8d2b3))
21
+
22
+ ### 👥 Contributors
23
+
24
+ <a href="https://github.com/anyup"><img src="https://github.com/anyup.png?size=40" width="40" height="40" alt="anyup" title="anyup"/></a> <a href="https://github.com/wjp980108"><img src="https://github.com/wjp980108.png?size=40" width="40" height="40" alt="wjp980108" title="wjp980108"/></a>
25
+
1
26
  ## 0.3.7(2025-10-28)
2
27
 
3
28
  ### 🐛 Bug Fixes | Bug 修复
@@ -14,8 +14,10 @@
14
14
  "
15
15
  >
16
16
  <!-- 支付宝小程序不支持canvas-id属性,必须用id属性 -->
17
+ <!-- #ifdef MP-WEIXIN || MP-TOUTIAO -->
17
18
  <canvas
18
19
  class="u-canvas-bg"
20
+ type="2d"
19
21
  :canvas-id="elBgId"
20
22
  :id="elBgId"
21
23
  :style="{
@@ -25,6 +27,7 @@
25
27
  ></canvas>
26
28
  <canvas
27
29
  class="u-canvas"
30
+ type="2d"
28
31
  :canvas-id="elId"
29
32
  :id="elId"
30
33
  :style="{
@@ -32,6 +35,27 @@
32
35
  height: widthPx + 'px'
33
36
  }"
34
37
  ></canvas>
38
+ <!-- #endif -->
39
+ <!-- #ifndef MP-WEIXIN || MP-TOUTIAO -->
40
+ <canvas
41
+ class="u-canvas-bg"
42
+ :canvas-id="elBgId"
43
+ :id="elBgId"
44
+ :style="{
45
+ width: widthPx + 'px',
46
+ height: widthPx + 'px'
47
+ }"
48
+ ></canvas>
49
+ <canvas
50
+ class="u-canvas"
51
+ :canvas-id="elId"
52
+ :id="elId"
53
+ :style="{
54
+ width: widthPx + 'px',
55
+ height: widthPx + 'px'
56
+ }"
57
+ ></canvas>
58
+ <!-- #endif -->
35
59
  <slot></slot>
36
60
  </view>
37
61
  </template>
@@ -50,9 +74,12 @@ export default {
50
74
  </script>
51
75
 
52
76
  <script setup lang="ts">
53
- import { ref, computed, watch, onMounted, getCurrentInstance } from 'vue';
77
+ import { ref, computed, watch, onMounted, getCurrentInstance, onBeforeMount } from 'vue';
54
78
  import { $u } from '../..';
55
79
  import { CircleProgressProps } from './types';
80
+ // #ifdef MP-WEIXIN || MP-TOUTIAO
81
+ import { canvas2d } from '../../libs/util/canvas-2d';
82
+ // #endif
56
83
 
57
84
  /**
58
85
  * circleProgress 环形进度条
@@ -72,12 +99,17 @@ const props = defineProps(CircleProgressProps);
72
99
 
73
100
  let elBgId = $u.guid(); // 非微信端的时候,需用动态的id,否则一个页面多个圆形进度条组件数据会混乱
74
101
  let elId = $u.guid();
75
- // #ifdef MP-WEIXIN
76
- elBgId = 'uCircleProgressBgId'; // 微信小程序中不能使用$u.guid()形式动态生成id值,否则会报错
77
- elId = 'uCircleProgressElId';
102
+ // #ifdef MP-WEIXIN || MP-TOUTIAO
103
+ // elBgId = 'uCircleProgressBgId'; // 微信小程序中不能使用$u.guid()形式动态生成id值,否则会报错
104
+ // elId = 'uCircleProgressElId';
78
105
  // #endif
79
106
  const instance = getCurrentInstance();
80
107
 
108
+ const pixelRatio = ref<number>(1); // 像素比
109
+
110
+ // 存储 MP-WEIXIN 下通过 selectorQuery 获取到的 canvas node,方便在绘制前清空
111
+ const canvasNodeMap = new Map<string, any>();
112
+
81
113
  const widthPx = computed(() =>
82
114
  typeof uni !== 'undefined' && uni.upx2px ? uni.upx2px(Number(props.width)) : Number(props.width)
83
115
  );
@@ -99,6 +131,10 @@ const circleColor = computed(() => {
99
131
  return props.activeColor;
100
132
  });
101
133
 
134
+ onBeforeMount(() => {
135
+ pixelRatio.value = uni.getSystemInfoSync().pixelRatio;
136
+ });
137
+
102
138
  // 监听percent变化,动态绘制进度
103
139
  watch(
104
140
  () => props.percent,
@@ -126,11 +162,55 @@ onMounted(() => {
126
162
  }, 50);
127
163
  });
128
164
 
165
+ /**
166
+ * 获取canvas上下文
167
+ */
168
+ function getContext(canvasId) {
169
+ return new Promise<UniApp.CanvasContext>(resolve => {
170
+ let ctx = null;
171
+ // #ifndef MP-WEIXIN || MP-TOUTIAO
172
+ ctx = uni.createCanvasContext(canvasId, instance);
173
+ resolve(ctx);
174
+ // #endif
175
+ // #ifdef MP-WEIXIN || MP-TOUTIAO
176
+ uni.createSelectorQuery()
177
+ .in(instance?.proxy)
178
+ .select(`#${canvasId}`)
179
+ .node(res => {
180
+ if (res && res.node) {
181
+ const canvas = res.node;
182
+ ctx = canvas2d(canvas.getContext('2d') as CanvasRenderingContext2D);
183
+ canvas.width = widthPx.value * pixelRatio.value;
184
+ canvas.height = widthPx.value * pixelRatio.value;
185
+ ctx.scale(pixelRatio.value, pixelRatio.value);
186
+ // 存储 canvas node,后续绘制时用于清空画布
187
+ canvasNodeMap.set(canvasId, canvas);
188
+ resolve(ctx);
189
+ }
190
+ })
191
+ .exec();
192
+ // #endif
193
+ });
194
+ }
195
+
129
196
  /**
130
197
  * 绘制底部灰色圆环
131
198
  */
132
- function drawProgressBg() {
133
- const ctx = uni.createCanvasContext(elBgId, instance);
199
+ async function drawProgressBg() {
200
+ const ctx = await getContext(elBgId);
201
+ // #ifdef MP-WEIXIN || MP-TOUTIAO
202
+ // 清空背景画布(如果可用)以确保绘制一致性
203
+ try {
204
+ if (typeof ctx.clearRect === 'function') {
205
+ const node = canvasNodeMap.get(elBgId);
206
+ const w = node ? node.width : widthPx.value * pixelRatio.value;
207
+ const h = node ? node.height : widthPx.value * pixelRatio.value;
208
+ ctx.clearRect(0, 0, w, h);
209
+ }
210
+ } catch (e) {
211
+ // ignore
212
+ }
213
+ // #endif
134
214
  ctx.setLineWidth(borderWidthPx.value); // 设置圆环宽度
135
215
  ctx.setStrokeStyle(props.inactiveColor); // 线条颜色
136
216
  ctx.beginPath(); // 开始描绘路径
@@ -144,13 +224,26 @@ function drawProgressBg() {
144
224
  * 绘制进度圆环
145
225
  * @param progress 当前进度
146
226
  */
147
- function drawCircleByProgress(progress: number) {
227
+ async function drawCircleByProgress(progress: number) {
148
228
  // 第一次操作进度环时将上下文保存到了this.data中,直接使用即可
149
229
  let ctx = progressContext.value;
150
230
  if (!ctx) {
151
- ctx = uni.createCanvasContext(elId, instance);
231
+ ctx = await getContext(elId);
152
232
  progressContext.value = ctx;
153
233
  }
234
+ // #ifdef MP-WEIXIN || MP-TOUTIAO
235
+ // 清空进度画布,避免旧的更大进度残留,导致无法降低的视觉错误
236
+ try {
237
+ if (typeof ctx.clearRect === 'function') {
238
+ const node = canvasNodeMap.get(elId);
239
+ const w = node ? node.width : widthPx.value * pixelRatio.value;
240
+ const h = node ? node.height : widthPx.value * pixelRatio.value;
241
+ ctx.clearRect(0, 0, w, h);
242
+ }
243
+ } catch (e) {
244
+ // ignore
245
+ }
246
+ // #endif
154
247
  // 表示进度的两端为圆形
155
248
  ctx.setLineCap('round');
156
249
  // 设置线条的宽度和颜色
@@ -0,0 +1,75 @@
1
+ import type { CSSProperties, ExtractPropTypes, PropType } from 'vue';
2
+ import type { FabDirection, FabGap, FabPosition, ThemeType } from '../../types/global';
3
+ import { baseProps } from '../common/props';
4
+
5
+ /**
6
+ * fab 悬浮按钮类型定义
7
+ * @description 供 u-fab 组件 props 使用
8
+ */
9
+
10
+ export const FabProps = {
11
+ ...baseProps,
12
+ /** 按钮的预置样式,primary,info,error,warning,success */
13
+ type: { type: String as PropType<ThemeType>, default: 'primary' },
14
+ /** 是否禁止状态 */
15
+ disabled: { type: Boolean, default: false },
16
+ /** 按钮能否可以拖动 */
17
+ draggable: { type: Boolean, default: false },
18
+ /** 按钮与边缘的间距,单位 px。支持 number 或对象 {top,left,right,bottom},优先级按键存在顺序 */
19
+ gap: {
20
+ type: Object as PropType<FabGap>,
21
+ default: () => ({
22
+ top: 16,
23
+ left: 16,
24
+ right: 16,
25
+ bottom: 16
26
+ })
27
+ },
28
+ /** 拖动结束时是否自动吸边(仅当 draggable 为 true 时生效) */
29
+ autoStick: { type: Boolean, default: true },
30
+ /** 预设定位:控制组件默认停靠位置 */
31
+ position: {
32
+ type: String as PropType<FabPosition>,
33
+ default: 'right-bottom'
34
+ },
35
+ /** 菜单出现的方向 */
36
+ direction: { type: String as PropType<FabDirection>, default: 'top' },
37
+ /** 按钮自定义层级 */
38
+ zIndex: { type: Number, default: 99 }
39
+ };
40
+
41
+ export type FabProps = ExtractPropTypes<typeof FabProps>;
42
+
43
+ interface DirectionConfig {
44
+ opposite: keyof CSSProperties;
45
+ sizeKey: 'width' | 'height';
46
+ positionKey: 'left' | 'top';
47
+ flexBase: 'row' | 'row-reverse' | 'column' | 'column-reverse';
48
+ }
49
+
50
+ export const directionConfig: Record<FabDirection, DirectionConfig> = {
51
+ top: {
52
+ opposite: 'bottom',
53
+ sizeKey: 'width',
54
+ positionKey: 'left',
55
+ flexBase: 'column'
56
+ },
57
+ bottom: {
58
+ opposite: 'top',
59
+ sizeKey: 'width',
60
+ positionKey: 'left',
61
+ flexBase: 'column-reverse'
62
+ },
63
+ left: {
64
+ opposite: 'right',
65
+ sizeKey: 'height',
66
+ positionKey: 'top',
67
+ flexBase: 'row'
68
+ },
69
+ right: {
70
+ opposite: 'left',
71
+ sizeKey: 'height',
72
+ positionKey: 'top',
73
+ flexBase: 'row-reverse'
74
+ }
75
+ };
@@ -0,0 +1,328 @@
1
+ <template>
2
+ <view
3
+ class="u-fab"
4
+ :style="$u.toStyle(fabStyle, customStyle)"
5
+ :class="[customClass]"
6
+ @touchstart="handleTouchstart"
7
+ @touchmove.stop.prevent="handleTouchmove"
8
+ @touchend="handleTouchend"
9
+ >
10
+ <view class="u-fab-trigger" id="trigger">
11
+ <slot name="trigger">
12
+ <u-button
13
+ custom-class="u-fab-trigger-btn"
14
+ custom-style="width:112rpx;height:112rpx;border-radius:112rpx;"
15
+ :type="type"
16
+ :disabled="disabled"
17
+ :throttle-time="0"
18
+ @click="handleBtnClick"
19
+ >
20
+ <u-icon :name="expansion ? 'close' : 'plus'" size="36rpx"></u-icon>
21
+ </u-button>
22
+ </slot>
23
+ </view>
24
+ <view class="u-fab-actions" id="actions" :class="{ 'u-fab-actions__show': expansion }" :style="actionsStyle">
25
+ <slot></slot>
26
+ </view>
27
+ </view>
28
+ </template>
29
+
30
+ <script lang="ts">
31
+ export default {
32
+ name: 'u-fab',
33
+ options: {
34
+ addGlobalClass: true,
35
+ // #ifndef MP-TOUTIAO
36
+ virtualHost: true,
37
+ // #endif
38
+ styleIsolation: 'shared'
39
+ }
40
+ };
41
+ </script>
42
+
43
+ <script setup lang="ts">
44
+ import { directionConfig, FabProps } from './types.ts';
45
+ import { computed, getCurrentInstance, onMounted, reactive, ref, useSlots, watch } from 'vue';
46
+ import { $u } from '../../';
47
+
48
+ const props = defineProps(FabProps);
49
+ const emit = defineEmits(['trigger']);
50
+
51
+ const slots = useSlots();
52
+ const instance = getCurrentInstance();
53
+ const sysInfo = $u.sys();
54
+ const dragging = ref(true);
55
+ const minLeft = ref(0);
56
+ const maxLeft = ref(0);
57
+ const minTop = ref(0);
58
+ const maxTop = ref(0);
59
+ const expansion = ref(false);
60
+ const direction = ref(props.direction);
61
+ const effectiveWindowHeight = ref(sysInfo.windowHeight);
62
+ // #ifdef H5
63
+ effectiveWindowHeight.value = sysInfo.windowTop + sysInfo.windowHeight;
64
+ // #endif
65
+ const position = reactive({
66
+ top: 0,
67
+ left: 0
68
+ });
69
+ const actions = ref();
70
+ const btnInfo = ref({
71
+ width: 56,
72
+ height: 56
73
+ });
74
+ const start = reactive({
75
+ x: 0,
76
+ y: 0
77
+ });
78
+
79
+ // 计算悬浮按钮样式
80
+ const fabStyle = computed(() => {
81
+ const style: Record<string, any> = {
82
+ transition: dragging.value ? 'none' : 'all 0.3s ease',
83
+ zIndex: props.zIndex,
84
+ left: `${position.left}px`,
85
+ top: `${position.top}px`
86
+ };
87
+ return style;
88
+ });
89
+
90
+ // 动画样式
91
+ const actionsStyle = computed(() => {
92
+ const config = directionConfig[direction.value];
93
+ const base: Record<string, any> = {
94
+ [config.opposite]: '100%',
95
+ [config.sizeKey]: '100%',
96
+ [config.positionKey]: 0,
97
+ flexDirection: config.flexBase,
98
+ transition: 'all 0.28s cubic-bezier(0.3, 0, 0.2, 1)'
99
+ };
100
+
101
+ // 展开/收缩动画:根据方向设置初始偏移
102
+ const offset = 12; // rpx/px 相对轻微偏移,视觉更顺滑
103
+ if (expansion.value) {
104
+ base.transform = 'translate3d(0,0,0) scale(1)';
105
+ base.opacity = 1;
106
+ } else {
107
+ // 隐藏时做一个方向上的微位移并缩放以优化动画感
108
+ if (direction.value === 'top') base.transform = `translate3d(0, ${offset}px, 0) scale(0.96)`;
109
+ else if (direction.value === 'bottom') base.transform = `translate3d(0, -${offset}px, 0) scale(0.96)`;
110
+ else if (direction.value === 'left') base.transform = `translate3d(${offset}px, 0, 0) scale(0.96)`;
111
+ else base.transform = `translate3d(-${offset}px, 0, 0) scale(0.96)`;
112
+ base.opacity = 0;
113
+ }
114
+
115
+ return base;
116
+ });
117
+
118
+ watch(
119
+ () => [props.position, props.gap],
120
+ () => {
121
+ initPosition();
122
+ }
123
+ );
124
+
125
+ watch(
126
+ () => props.direction,
127
+ () => {
128
+ if (expansion.value) direction.value = calcDirection();
129
+ }
130
+ );
131
+
132
+ // helper:支持 gap 为 number 或对象形式
133
+ function getGap(side: 'top' | 'left' | 'right' | 'bottom') {
134
+ const g = props.gap as any;
135
+ if (typeof g === 'number') return g;
136
+ if (g && typeof g === 'object' && g[side] !== undefined) return Number(g[side]);
137
+ return 0;
138
+ }
139
+
140
+ // 拖动开始事件
141
+ function handleTouchstart(e: TouchEvent) {
142
+ if (props.disabled || !props.draggable) return;
143
+
144
+ const touches = e.touches[0];
145
+ start.x = touches.clientX;
146
+ start.y = touches.clientY;
147
+ dragging.value = true;
148
+ }
149
+
150
+ // 拖动移动事件
151
+ function handleTouchmove(e: TouchEvent) {
152
+ if (props.disabled || !props.draggable) return;
153
+
154
+ const touches = e.touches[0];
155
+ const deltaX = touches.clientX - start.x;
156
+ const deltaY = touches.clientY - start.y;
157
+
158
+ position.left += deltaX;
159
+ position.top += deltaY;
160
+
161
+ start.x = touches.clientX;
162
+ start.y = touches.clientY;
163
+
164
+ // 设置边界,防止拖出边界
165
+ position.left = Math.max(minLeft.value, Math.min(maxLeft.value, position.left));
166
+ position.top = Math.max(minTop.value, Math.min(maxTop.value, position.top));
167
+ }
168
+
169
+ // 拖动结束事件
170
+ function handleTouchend() {
171
+ if (props.disabled || !props.draggable) return;
172
+
173
+ dragging.value = false;
174
+
175
+ // 如果 autoStick 为 false,则释放后不进行自动吸边,仅做边界限制
176
+ if (props.autoStick === false) {
177
+ position.left = Math.max(minLeft.value, Math.min(maxLeft.value, position.left));
178
+ position.top = Math.max(minTop.value, Math.min(maxTop.value, position.top));
179
+ return;
180
+ }
181
+
182
+ const middle = sysInfo.windowWidth / 2;
183
+ const buttonCenter = position.left + btnInfo.value.width / 2;
184
+
185
+ // 自动吸边,按钮中心位置大于视口的一半时,自动依附在右边,不然就是左边
186
+ position.left =
187
+ buttonCenter > middle ? sysInfo.windowWidth - btnInfo.value.width - getGap('right') : getGap('left');
188
+
189
+ if (expansion.value) direction.value = calcDirection();
190
+ }
191
+
192
+ // 按钮点击事件
193
+ function handleBtnClick() {
194
+ if (slots?.default) {
195
+ expansion.value = !expansion.value;
196
+ if (expansion.value) direction.value = calcDirection();
197
+ } else {
198
+ emit('trigger');
199
+ }
200
+ }
201
+
202
+ // 计算方向
203
+ function calcDirection() {
204
+ if (!actions.value) return props.direction;
205
+
206
+ let dir = props.direction;
207
+
208
+ const actionsHeight = actions.value?.height || 0;
209
+ const actionsWidth = actions.value?.width || 0;
210
+
211
+ // 菜单展开时,如果位置不够,则反转方向
212
+ if (dir === 'top') {
213
+ // 按钮上方剩余空间: 按钮顶部 - 顶部边距
214
+ if (position.top - minTop.value < actionsHeight) dir = 'bottom';
215
+ } else if (dir === 'bottom') {
216
+ // 按钮下方剩余空间: 有效窗口高度 - (按钮顶部 + 按钮高 + 边距)
217
+ const bottom = effectiveWindowHeight.value - (position.top + btnInfo.value.height + getGap('bottom'));
218
+ if (bottom < actionsHeight) dir = 'top';
219
+ } else if (dir === 'left') {
220
+ // 按钮左侧剩余空间: 有效窗口宽度 - 边距
221
+ if (position.left - getGap('left') < actionsWidth) dir = 'right';
222
+ } else if (dir === 'right') {
223
+ // 按钮右侧剩余空间: 有效窗口宽度 - (按钮左侧 + 按钮宽 + 边距)
224
+ const right = sysInfo.windowWidth - (position.left + btnInfo.value.width + getGap('right'));
225
+ if (right < actionsWidth) dir = 'left';
226
+ }
227
+
228
+ return dir;
229
+ }
230
+
231
+ // 初始化位置
232
+ function initPosition() {
233
+ // 根据 props.position 计算初始 left/top
234
+ const pos = props.position || 'right-bottom';
235
+ const winW = sysInfo.windowWidth;
236
+ const winH = effectiveWindowHeight.value;
237
+
238
+ switch (pos) {
239
+ case 'left-top':
240
+ position.left = getGap('left');
241
+ position.top = getGap('top') + sysInfo.windowTop;
242
+ break;
243
+ case 'right-top':
244
+ position.left = winW - btnInfo.value.width - getGap('right');
245
+ position.top = getGap('top') + sysInfo.windowTop;
246
+ break;
247
+ case 'left-bottom':
248
+ position.left = getGap('left');
249
+ position.top = winH - btnInfo.value.height - getGap('bottom');
250
+ break;
251
+ case 'right-bottom':
252
+ position.left = winW - btnInfo.value.width - getGap('right');
253
+ position.top = winH - btnInfo.value.height - getGap('bottom');
254
+ break;
255
+ case 'left-center':
256
+ position.left = getGap('left');
257
+ position.top = Math.round((winH - btnInfo.value.height) / 2);
258
+ break;
259
+ case 'right-center':
260
+ position.left = winW - btnInfo.value.width - getGap('right');
261
+ position.top = Math.round((winH - btnInfo.value.height) / 2);
262
+ break;
263
+ case 'top-center':
264
+ position.left = Math.round((winW - btnInfo.value.width) / 2);
265
+ position.top = getGap('top') + sysInfo.windowTop;
266
+ break;
267
+ case 'bottom-center':
268
+ position.left = Math.round((winW - btnInfo.value.width) / 2);
269
+ position.top = winH - btnInfo.value.height - getGap('bottom');
270
+ break;
271
+ default:
272
+ position.left = winW - btnInfo.value.width - getGap('right');
273
+ position.top = winH - btnInfo.value.height - getGap('bottom');
274
+ break;
275
+ }
276
+ }
277
+
278
+ onMounted(async () => {
279
+ btnInfo.value = await $u.getRect('#trigger', instance);
280
+ actions.value = await $u.getRect('#actions', instance);
281
+
282
+ initPosition();
283
+
284
+ minLeft.value = getGap('left');
285
+ minTop.value = getGap('top') + sysInfo.windowTop;
286
+ maxLeft.value = sysInfo.windowWidth - btnInfo.value.width - getGap('right');
287
+ maxTop.value = effectiveWindowHeight.value - btnInfo.value.height - getGap('bottom');
288
+ });
289
+
290
+ defineExpose({
291
+ toggle: handleBtnClick
292
+ });
293
+ </script>
294
+
295
+ <style scoped lang="scss">
296
+ .u-fab {
297
+ position: fixed;
298
+
299
+ .u-fab-trigger {
300
+ :deep(.u-fab-trigger-btn) {
301
+ width: 112rpx;
302
+ height: 112rpx;
303
+ border-radius: 112rpx;
304
+
305
+ &::after {
306
+ border-radius: 112rpx;
307
+ }
308
+ }
309
+ }
310
+
311
+ .u-fab-actions {
312
+ position: absolute;
313
+ display: flex;
314
+ justify-content: center;
315
+ align-items: center;
316
+ visibility: hidden;
317
+ opacity: 0;
318
+ transform-origin: center;
319
+ will-change: transform, opacity;
320
+ transition: all 0.28s cubic-bezier(0.3, 0, 0.2, 1);
321
+
322
+ &.u-fab-actions__show {
323
+ visibility: visible;
324
+ opacity: 1;
325
+ }
326
+ }
327
+ }
328
+ </style>
@@ -22,10 +22,12 @@
22
22
  :class="['u-text__price', props.type && `u-text__value--${props.type}`]"
23
23
  :style="textValueStyle"
24
24
  >
25
- {{ displayValue }}
25
+ <slot>¥{{ displayValue }}</slot>
26
26
  </text>
27
27
  <!-- link 模式 -->
28
- <u-link v-else-if="props.mode === 'link'" :href="props.href" underLine>{{ displayValue }}</u-link>
28
+ <u-link v-else-if="props.mode === 'link'" :href="props.href" underLine>
29
+ <slot>{{ displayValue }}</slot>
30
+ </u-link>
29
31
  <template v-else-if="props.openType && isMp">
30
32
  <button
31
33
  class="u-reset-button u-text__value"
@@ -46,7 +48,7 @@
46
48
  :show-message-card="props.showMessageCard"
47
49
  :app-parameter="props.appParameter"
48
50
  >
49
- {{ displayValue }}
51
+ <slot>{{ displayValue }}</slot>
50
52
  </button>
51
53
  </template>
52
54
  <!-- 默认模式 -->
@@ -56,7 +58,7 @@
56
58
  :style="textValueStyle"
57
59
  :class="[props.type && `u-text__value--${props.type}`, props.lines ? `u-line-${props.lines}` : '']"
58
60
  >
59
- {{ displayValue }}
61
+ <slot>{{ displayValue }}</slot>
60
62
  </text>
61
63
  <!-- 后缀图标 -->
62
64
  <view class="u-text__icon u-text__suffix-icon" v-if="props.suffixIcon">
@@ -0,0 +1,49 @@
1
+ /**
2
+ * 适配 canvas 2d 上下文
3
+ * @param ctx canvas 2d 上下文
4
+ * @returns
5
+ */
6
+ export function canvas2d(ctx: CanvasRenderingContext2D): UniApp.CanvasContext {
7
+ return Object.assign(ctx, {
8
+ setFillStyle(color: string | CanvasGradient) {
9
+ ctx.fillStyle = color;
10
+ },
11
+ setStrokeStyle(color: string | CanvasGradient | CanvasPattern) {
12
+ ctx.strokeStyle = color;
13
+ },
14
+ setLineWidth(lineWidth: number) {
15
+ ctx.lineWidth = lineWidth;
16
+ },
17
+ setLineCap(lineCap: 'butt' | 'round' | 'square') {
18
+ ctx.lineCap = lineCap;
19
+ },
20
+
21
+ setFontSize(font: string) {
22
+ ctx.font = font;
23
+ },
24
+ setGlobalAlpha(alpha: number) {
25
+ ctx.globalAlpha = alpha;
26
+ },
27
+ setLineJoin(lineJoin: 'bevel' | 'round' | 'miter') {
28
+ ctx.lineJoin = lineJoin;
29
+ },
30
+ setTextAlign(align: 'left' | 'center' | 'right') {
31
+ ctx.textAlign = align;
32
+ },
33
+ setMiterLimit(miterLimit: number) {
34
+ ctx.miterLimit = miterLimit;
35
+ },
36
+ setShadow(offsetX: number, offsetY: number, blur: number, color: string) {
37
+ ctx.shadowOffsetX = offsetX;
38
+ ctx.shadowOffsetY = offsetY;
39
+ ctx.shadowBlur = blur;
40
+ ctx.shadowColor = color;
41
+ },
42
+ setTextBaseline(textBaseline: 'top' | 'bottom' | 'middle') {
43
+ ctx.textBaseline = textBaseline;
44
+ },
45
+ createCircularGradient() {},
46
+ draw() {},
47
+ addColorStop() {}
48
+ }) as unknown as UniApp.CanvasContext;
49
+ }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "id": "uview-pro",
3
3
  "name": "uview-pro",
4
- "displayName": "【Vue3重构版】uView Pro|基于Vue3+TS全面重构的70+精选UI组件库",
5
- "version": "0.3.7",
6
- "description": "uView Pro,是全面支持Vue3的uni-app生态框架,70+精选组件已使用TypeScript重构,已全面支持uni-app Vue3.0",
4
+ "displayName": "【Vue3重构版】uView Pro|基于Vue3+TS全面重构的80+精选UI组件库",
5
+ "version": "0.3.8",
6
+ "description": "uView Pro,是全面支持Vue3的uni-app生态框架,80+精选组件已使用TypeScript重构,已全面支持uni-app Vue3.0",
7
7
  "main": "index.ts",
8
8
  "module": "index.ts",
9
9
  "browser": "index.ts",
@@ -95,6 +95,7 @@ declare module 'vue' {
95
95
  uStatusBar: (typeof import('../components/u-status-bar/u-status-bar.vue'))['default'];
96
96
  uSafeBottom: (typeof import('../components/u-safe-bottom/u-safe-bottom.vue'))['default'];
97
97
  uTextarea: (typeof import('../components/u-textarea/u-textarea.vue'))['default'];
98
+ uFab: (typeof import('../components/u-fab/u-fab.vue'))['default'];
98
99
  }
99
100
  }
100
101
 
package/types/global.d.ts CHANGED
@@ -290,6 +290,21 @@ export type TagSize = 'default' | 'mini' | 'medium';
290
290
  export type ToastPosition = 'top' | 'center' | 'bottom';
291
291
  export type UploadSizeType = 'original' | 'compressed';
292
292
  export type UploadSourceType = 'album' | 'camera';
293
+ // fab 组件 position
294
+ export type FabPosition =
295
+ | 'left-top'
296
+ | 'right-top'
297
+ | 'left-bottom'
298
+ | 'right-bottom'
299
+ | 'left-center'
300
+ | 'right-center'
301
+ | 'top-center'
302
+ | 'bottom-center';
303
+ // fab 组件 direction
304
+ export type FabDirection = 'top' | 'bottom' | 'left' | 'right';
305
+ // fab 组件 gap
306
+ export type FabGap = Partial<Record<'top' | 'left' | 'right' | 'bottom', number>>;
307
+
293
308
  // 自定义主题色
294
309
  export type ThemeColor = Partial<{
295
310
  primary: string;