hy-app 0.6.6 → 0.6.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.
@@ -1,5 +1,5 @@
1
1
  import type { CSSProperties, PropType } from 'vue'
2
- import { useTranslate } from '@/package'
2
+ import { useTranslate } from '../../libs'
3
3
 
4
4
  const { t } = useTranslate('readMore')
5
5
 
@@ -525,7 +525,11 @@ function getContext() {
525
525
  // #ifndef MP-WEIXIN
526
526
  getRect(`#${canvasId.value}`, false, instance).then((canvasRect) => {
527
527
  setCanvasState(canvasRect.width!, canvasRect.height!)
528
+ // #ifdef MP-ALIPAY
529
+ canvasState.ctx = uni.createCanvasContext(canvasId.value)
530
+ // #else
528
531
  canvasState.ctx = uni.createCanvasContext(canvasId.value, instance.proxy)
532
+ // #endif
529
533
  if (canvasState.ctx) {
530
534
  canvasState.ctx.scale(pixelRatio.value, pixelRatio.value)
531
535
  }
@@ -579,40 +583,42 @@ function setLine() {
579
583
  function canvasToImage() {
580
584
  const { fileType, quality, exportScale } = props
581
585
  const { canvasWidth, canvasHeight } = canvasState
582
- uni.canvasToTempFilePath(
583
- {
584
- width: canvasWidth * exportScale,
585
- height: canvasHeight * exportScale,
586
- destWidth: canvasWidth * exportScale,
587
- destHeight: canvasHeight * exportScale,
588
- fileType,
589
- quality,
590
- canvasId: canvasId.value,
591
- canvas: canvas,
592
- success: (res) => {
593
- const result: SignatureResult = {
594
- tempFilePath: res.tempFilePath,
595
- width: (canvasWidth * exportScale) / pixelRatio.value,
596
- height: (canvasHeight * exportScale) / pixelRatio.value,
597
- success: true
598
- }
599
- // #ifdef MP-DINGTALK
600
- result.tempFilePath = (res as any).filePath
601
- // #endif
602
- emit('confirm', result)
603
- },
604
- fail: () => {
605
- const result: SignatureResult = {
606
- tempFilePath: '',
607
- width: (canvasWidth * exportScale) / pixelRatio.value,
608
- height: (canvasHeight * exportScale) / pixelRatio.value,
609
- success: false
610
- }
611
- emit('confirm', result)
586
+ const options = {
587
+ width: canvasWidth * exportScale,
588
+ height: canvasHeight * exportScale,
589
+ destWidth: canvasWidth * exportScale,
590
+ destHeight: canvasHeight * exportScale,
591
+ fileType,
592
+ quality,
593
+ canvasId: canvasId.value,
594
+ canvas: canvas,
595
+ success: (res: any) => {
596
+ const result: SignatureResult = {
597
+ tempFilePath: res.tempFilePath,
598
+ width: (canvasWidth * exportScale) / pixelRatio.value,
599
+ height: (canvasHeight * exportScale) / pixelRatio.value,
600
+ success: true
612
601
  }
602
+ // #ifdef MP-DINGTALK
603
+ result.tempFilePath = (res as any).filePath
604
+ // #endif
605
+ emit('confirm', result)
613
606
  },
614
- instance.proxy
615
- )
607
+ fail: () => {
608
+ const result: SignatureResult = {
609
+ tempFilePath: '',
610
+ width: (canvasWidth * exportScale) / pixelRatio.value,
611
+ height: (canvasHeight * exportScale) / pixelRatio.value,
612
+ success: false
613
+ }
614
+ emit('confirm', result)
615
+ }
616
+ }
617
+ // #ifdef MP-ALIPAY
618
+ uni.canvasToTempFilePath(options)
619
+ // #else
620
+ uni.canvasToTempFilePath(options, instance.proxy)
621
+ // #endif
616
622
  }
617
623
 
618
624
  function clearCanvas() {
@@ -1,275 +1,276 @@
1
- <template>
2
- <view :class="[`hy-steps--${direction}`, 'hy-steps']">
3
- <template v-for="(item, i) in list" :key="i">
4
- <view ref="hy-steps-item" :class="[`hy-steps-item--${direction}`, 'hy-steps-item']">
5
- <!-- 线条 -->
6
- <view
7
- v-if="i + 1 < list.length"
8
- :class="[
9
- `hy-steps-item__line--${direction}`,
10
- 'hy-steps-item__line',
11
- statusClass(i + 1, list[i + 1].error)
12
- ]"
13
- :style="lineStyle(item, i)"
14
- ></view>
15
- <!-- 线条 -->
16
-
17
- <!-- 步骤状态 -->
18
- <view
19
- :class="[
20
- `hy-steps-item__wrapper--${direction}`,
21
- dot ? `hy-steps-item__wrapper--dot` : statusClass(i, item.error),
22
- 'hy-steps-item__wrapper'
23
- ]"
24
- :style="itemStyleInner"
25
- >
26
- <slot v-if="$slots.icon" name="icon" :error="item?.error" :index="i"></slot>
27
- <template v-else>
28
- <view
29
- :class="[
30
- 'hy-steps-item__wrapper--dot__item',
31
- `hy-steps-item__wrapper--dot__${statusClass(i, item.error)}`
32
- ]"
33
- v-if="dot"
34
- :style="{
35
- backgroundColor: statusColor(i, item?.error)
36
- }"
37
- ></view>
38
- <view
39
- class="hy-steps-item__wrapper__icon"
40
- v-else-if="activeIcon || inactiveIcon"
41
- >
42
- <hy-icon
43
- :name="i <= current ? activeIcon : inactiveIcon"
44
- :size="iconSize"
45
- :color="i <= current ? activeColor : inactiveColor"
46
- ></hy-icon>
47
- </view>
48
- <view
49
- v-else
50
- :style="{
51
- backgroundColor:
52
- statusClass(i, item.error) === 'process'
53
- ? activeColor
54
- : 'transparent',
55
- borderColor: statusColor(i, item?.error)
56
- }"
57
- class="hy-steps-item__wrapper__circle"
58
- >
59
- <text
60
- v-if="
61
- statusClass(i, item.error) === 'process' ||
62
- statusClass(i, item.error) === 'wait'
63
- "
64
- class="hy-steps-item__wrapper__circle__text"
65
- :style="{
66
- color: textColor(i)
67
- }"
68
- >
69
- {{ i + 1 }}
70
- </text>
71
- <hy-icon
72
- v-else
73
- :color="
74
- statusClass(i, item.error) === 'error' ? 'error' : activeColor
75
- "
76
- :size="iconSize"
77
- :name="
78
- statusClass(i, item.error) === 'error'
79
- ? IconConfig.CLOSE
80
- : IconConfig.CHECK_MASK
81
- "
82
- ></hy-icon>
83
- </view>
84
- </template>
85
- </view>
86
- <!-- 步骤状态 -->
87
-
88
- <!-- 内容区域 -->
89
- <view
90
- class="hy-steps-item__content"
91
- :class="[`hy-steps-item__content--${direction}`]"
92
- :style="[contentStyle]"
93
- >
94
- <slot v-if="$slots.content" name="content" :record="item" :index="i"></slot>
95
- <template v-else>
96
- <slot
97
- v-if="$slots.title"
98
- name="title"
99
- :title="item.title"
100
- :index="i"
101
- ></slot>
102
- <text v-else :class="titleClass(i, item.error)">
103
- {{ item.title }}
104
- </text>
105
- <slot v-if="$slots.docs" name="docs" :desc="item.docs" :index="i"></slot>
106
- <text v-else :style="{ fontSize: '12px', color: '#999' }">{{
107
- item.docs
108
- }}</text>
109
- <text class="hy-steps-item__content--date">{{ item.date }}</text>
110
- </template>
111
- </view>
112
- <!-- 内容区域 -->
113
- </view>
114
- </template>
115
- </view>
116
- </template>
117
-
118
- <script lang="ts">
119
- export default {
120
- name: 'hy-steps',
121
- options: {
122
- addGlobalClass: true,
123
- virtualHost: true,
124
- styleIsolation: 'shared'
125
- }
126
- }
127
- </script>
128
-
129
- <script setup lang="ts">
130
- import { computed, ref, onMounted, getCurrentInstance, watch } from 'vue'
131
- import type { CSSProperties } from 'vue'
132
- import type { IStepsEmits } from './typing'
133
- import type { StepListVo } from './typing'
134
- import { addUnit, getRect, ColorConfig, IconConfig } from '../../libs'
135
- import stepsProps from './props'
136
- // 组件
137
- import HyIcon from '../hy-icon/hy-icon.vue'
138
-
139
- /**
140
- * 一般用于完成一个任务要分几个步骤,标识目前处于第几步的场景。
141
- * @displayName hy-steps
142
- */
143
- defineOptions({})
144
-
145
- const props = defineProps(stepsProps)
146
- const emit = defineEmits<IStepsEmits>()
147
-
148
- const itemRect = ref<UniApp.NodeInfo[]>([])
149
- const stepsRects = ref<UniApp.NodeInfo[]>([])
150
- const instance = getCurrentInstance()
151
-
152
- watch(
153
- () => props.current,
154
- (newVal: number) => {
155
- if (props.list[newVal - 1]?.error) {
156
- const index = props.list.findIndex((item) => item.error)
157
- emit('update:current', index)
158
- emit('change', index)
159
- }
160
- }
161
- )
162
-
163
- // 字体标题类名
164
- const titleClass = computed(() => {
165
- return (index: number, error: boolean) => {
166
- const classes = ['hy-steps-item__content__title']
167
- if (props.current === index) {
168
- classes.push('hy-steps-item__content__title--active')
169
-
170
- if (error) {
171
- classes.push('hy-steps-item__content__title--error')
172
- }
173
- }
174
-
175
- return classes
176
- }
177
- })
178
- // 字体颜色
179
- const textColor = computed(() => {
180
- return (index: number) => (index === props.current ? '#ffffff' : props.inactiveColor)
181
- })
182
-
183
- /**
184
- * 线条样式
185
- * */
186
- const lineStyle = computed(() => {
187
- return (temp: StepListVo, index: number): CSSProperties => {
188
- const style: CSSProperties = {}
189
- if (!stepsRects.value.length) return style
190
- if (props.direction === 'row') {
191
- style.width = addUnit(stepsRects.value[index].width! - itemRect.value[index].width!)
192
- style.left = addUnit(
193
- stepsRects.value[index].width! / 2 + itemRect.value[index].width! / 2
194
- )
195
- style.top = addUnit(itemRect.value[index].height! / 2)
196
- } else {
197
- style.height = addUnit(stepsRects.value[index].height! - itemRect.value[index].height!)
198
- style.left = addUnit(itemRect.value[index].width! / 2)
199
- style.top = addUnit(itemRect.value[index].height)
200
- }
201
- style.backgroundColor = temp.error ? '' : index < props.current ? '' : props.inactiveColor
202
- return style
203
- }
204
- })
205
-
206
- const itemStyleInner = computed(() => {
207
- return {}
208
- })
209
- /**
210
- * 状态类名
211
- * */
212
- const statusClass = computed(() => {
213
- return (index: number, error: boolean = false) => {
214
- if (props.current == index) {
215
- return error ? 'error' : 'process'
216
- } else if (props.current > index) {
217
- return 'finish'
218
- } else {
219
- return 'wait'
220
- }
221
- }
222
- })
223
- const statusColor = computed(() => {
224
- return (index: number, error?: boolean) => {
225
- let colorTmp: string | number
226
- switch (statusClass.value(index, error)) {
227
- case 'finish':
228
- colorTmp = props.activeColor
229
- break
230
- case 'error':
231
- colorTmp = ColorConfig.error
232
- break
233
- case 'process':
234
- colorTmp = props.dot ? props.current : 'transparent'
235
- break
236
- default:
237
- colorTmp = props.inactiveColor
238
- break
239
- }
240
- return colorTmp
241
- }
242
- })
243
-
244
- const contentStyle = computed<CSSProperties>(() => {
245
- const style: CSSProperties = {}
246
- if (props.direction === 'column') {
247
- style.marginLeft = props.dot ? '2px' : '6px'
248
- style.marginTop = props.dot ? '0px' : '0px'
249
- } else {
250
- style.marginTop = props.dot ? '2px' : '6px'
251
- style.marginLeft = props.dot ? '0px' : '0px'
252
- }
253
-
254
- return style
255
- })
256
-
257
- onMounted(() => {
258
- getStepsItemRect()
259
- })
260
-
261
- // 获取组件的尺寸,用于设置横线的位置
262
- const getStepsItemRect = () => {
263
- getRect('.hy-steps-item', true, instance).then((rect) => {
264
- stepsRects.value = rect as UniApp.NodeInfo[]
265
- })
266
-
267
- getRect('.hy-steps-item__wrapper', true, instance).then((rect) => {
268
- itemRect.value = rect as UniApp.NodeInfo[]
269
- })
270
- }
271
- </script>
272
-
273
- <style lang="scss" scoped>
274
- @import './index.scss';
275
- </style>
1
+ <template>
2
+ <view :class="[`hy-steps--${direction}`, 'hy-steps']">
3
+ <template v-for="(item, i) in list" :key="i">
4
+ <view ref="hy-steps-item" :class="[`hy-steps-item--${direction}`, 'hy-steps-item']">
5
+ <!-- 线条 -->
6
+ <view
7
+ v-if="i + 1 < list.length"
8
+ :class="[
9
+ `hy-steps-item__line--${direction}`,
10
+ 'hy-steps-item__line',
11
+ statusClass(i + 1, list[i + 1].error)
12
+ ]"
13
+ :style="lineStyle(item, i)"
14
+ ></view>
15
+ <!-- 线条 -->
16
+
17
+ <!-- 步骤状态 -->
18
+ <view
19
+ :class="[
20
+ `hy-steps-item__wrapper--${direction}`,
21
+ dot ? `hy-steps-item__wrapper--dot` : statusClass(i, item.error),
22
+ 'hy-steps-item__wrapper'
23
+ ]"
24
+ :style="itemStyleInner"
25
+ >
26
+ <slot v-if="$slots.icon" name="icon" :error="item?.error" :index="i"></slot>
27
+ <template v-else>
28
+ <view
29
+ :class="[
30
+ 'hy-steps-item__wrapper--dot__item',
31
+ `hy-steps-item__wrapper--dot__${statusClass(i, item.error)}`
32
+ ]"
33
+ v-if="dot"
34
+ :style="{
35
+ backgroundColor: statusColor(i, item?.error)
36
+ }"
37
+ ></view>
38
+ <view
39
+ class="hy-steps-item__wrapper__icon"
40
+ v-else-if="activeIcon || inactiveIcon"
41
+ >
42
+ <hy-icon
43
+ :name="i <= current ? activeIcon : inactiveIcon"
44
+ :size="iconSize"
45
+ :color="i <= current ? activeColor : inactiveColor"
46
+ ></hy-icon>
47
+ </view>
48
+ <view
49
+ v-else
50
+ :style="{
51
+ backgroundColor:
52
+ statusClass(i, item.error) === 'process'
53
+ ? activeColor
54
+ : 'transparent',
55
+ borderColor: statusColor(i, item?.error)
56
+ }"
57
+ class="hy-steps-item__wrapper__circle"
58
+ >
59
+ <text
60
+ v-if="
61
+ statusClass(i, item.error) === 'process' ||
62
+ statusClass(i, item.error) === 'wait'
63
+ "
64
+ class="hy-steps-item__wrapper__circle__text"
65
+ :style="{
66
+ color: textColor(i)
67
+ }"
68
+ >
69
+ {{ i + 1 }}
70
+ </text>
71
+ <hy-icon
72
+ v-else
73
+ :color="
74
+ statusClass(i, item.error) === 'error' ? 'error' : activeColor
75
+ "
76
+ :size="iconSize"
77
+ :name="
78
+ statusClass(i, item.error) === 'error'
79
+ ? IconConfig.CLOSE
80
+ : IconConfig.CHECK_MASK
81
+ "
82
+ ></hy-icon>
83
+ </view>
84
+ </template>
85
+ </view>
86
+ <!-- 步骤状态 -->
87
+
88
+ <!-- 内容区域 -->
89
+ <view
90
+ class="hy-steps-item__content"
91
+ :class="[`hy-steps-item__content--${direction}`]"
92
+ :style="[contentStyle]"
93
+ >
94
+ <slot v-if="$slots.content" name="content" :record="item" :index="i"></slot>
95
+ <template v-else>
96
+ <slot
97
+ v-if="$slots.title"
98
+ name="title"
99
+ :title="item.title"
100
+ :index="i"
101
+ ></slot>
102
+ <text v-else :class="titleClass(i, item.error)">
103
+ {{ item.title }}
104
+ </text>
105
+ <slot v-if="$slots.docs" name="docs" :desc="item.docs" :index="i"></slot>
106
+ <text v-else :style="{ fontSize: '12px', color: '#999' }">{{
107
+ item.docs
108
+ }}</text>
109
+ <text class="hy-steps-item__content--date">{{ item.date }}</text>
110
+ </template>
111
+ </view>
112
+ <!-- 内容区域 -->
113
+ </view>
114
+ </template>
115
+ </view>
116
+ </template>
117
+
118
+ <script lang="ts">
119
+ export default {
120
+ name: 'hy-steps',
121
+ options: {
122
+ addGlobalClass: true,
123
+ virtualHost: true,
124
+ styleIsolation: 'shared'
125
+ }
126
+ }
127
+ </script>
128
+
129
+ <script setup lang="ts">
130
+ import { computed, ref, onMounted, getCurrentInstance, watch, nextTick } from 'vue'
131
+ import type { CSSProperties } from 'vue'
132
+ import type { IStepsEmits } from './typing'
133
+ import type { StepListVo } from './typing'
134
+ import { addUnit, getRect, ColorConfig, IconConfig } from '../../libs'
135
+ import stepsProps from './props'
136
+ // 组件
137
+ import HyIcon from '../hy-icon/hy-icon.vue'
138
+
139
+ /**
140
+ * 一般用于完成一个任务要分几个步骤,标识目前处于第几步的场景。
141
+ * @displayName hy-steps
142
+ */
143
+ defineOptions({})
144
+
145
+ const props = defineProps(stepsProps)
146
+ const emit = defineEmits<IStepsEmits>()
147
+
148
+ const itemRect = ref<UniApp.NodeInfo[]>([])
149
+ const stepsRects = ref<UniApp.NodeInfo[]>([])
150
+ const instance = getCurrentInstance()
151
+
152
+ watch(
153
+ () => props.current,
154
+ (newVal: number) => {
155
+ if (props.list[newVal - 1]?.error) {
156
+ const index = props.list.findIndex((item) => item.error)
157
+ emit('update:current', index)
158
+ emit('change', index)
159
+ }
160
+ }
161
+ )
162
+
163
+ // 字体标题类名
164
+ const titleClass = computed(() => {
165
+ return (index: number, error: boolean) => {
166
+ const classes = ['hy-steps-item__content__title']
167
+ if (props.current === index) {
168
+ classes.push('hy-steps-item__content__title--active')
169
+
170
+ if (error) {
171
+ classes.push('hy-steps-item__content__title--error')
172
+ }
173
+ }
174
+
175
+ return classes
176
+ }
177
+ })
178
+ // 字体颜色
179
+ const textColor = computed(() => {
180
+ return (index: number) => (index === props.current ? '#ffffff' : props.inactiveColor)
181
+ })
182
+
183
+ /**
184
+ * 线条样式
185
+ * */
186
+ const lineStyle = computed(() => {
187
+ return (temp: StepListVo, index: number): CSSProperties => {
188
+ const style: CSSProperties = {}
189
+ style.backgroundColor = temp.error ? '' : index < props.current ? '' : props.inactiveColor
190
+
191
+ if (!stepsRects.value.length || !itemRect.value[index]) return style
192
+ if (props.direction === 'row') {
193
+ style.width = addUnit(stepsRects.value[index].width! - itemRect.value[index].width!)
194
+ style.left = addUnit(
195
+ stepsRects.value[index].width! / 2 + itemRect.value[index].width! / 2
196
+ )
197
+ style.top = addUnit(itemRect.value[index].height! / 2)
198
+ } else {
199
+ style.height = addUnit(stepsRects.value[index].height! - itemRect.value[index].height!)
200
+ style.left = addUnit(itemRect.value[index].width! / 2)
201
+ style.top = addUnit(itemRect.value[index].height)
202
+ }
203
+ return style
204
+ }
205
+ })
206
+
207
+ const itemStyleInner = computed(() => {
208
+ return {}
209
+ })
210
+ /**
211
+ * 状态类名
212
+ * */
213
+ const statusClass = computed(() => {
214
+ return (index: number, error: boolean = false) => {
215
+ if (props.current == index) {
216
+ return error ? 'error' : 'process'
217
+ } else if (props.current > index) {
218
+ return 'finish'
219
+ } else {
220
+ return 'wait'
221
+ }
222
+ }
223
+ })
224
+ const statusColor = computed(() => {
225
+ return (index: number, error?: boolean) => {
226
+ let colorTmp: string | number
227
+ switch (statusClass.value(index, error)) {
228
+ case 'finish':
229
+ colorTmp = props.activeColor
230
+ break
231
+ case 'error':
232
+ colorTmp = ColorConfig.error
233
+ break
234
+ case 'process':
235
+ colorTmp = props.dot ? props.current : 'transparent'
236
+ break
237
+ default:
238
+ colorTmp = props.inactiveColor
239
+ break
240
+ }
241
+ return colorTmp
242
+ }
243
+ })
244
+
245
+ const contentStyle = computed<CSSProperties>(() => {
246
+ const style: CSSProperties = {}
247
+ if (props.direction === 'column') {
248
+ style.marginLeft = props.dot ? '2px' : '6px'
249
+ style.marginTop = props.dot ? '0px' : '0px'
250
+ } else {
251
+ style.marginTop = props.dot ? '2px' : '6px'
252
+ style.marginLeft = props.dot ? '0px' : '0px'
253
+ }
254
+
255
+ return style
256
+ })
257
+
258
+ onMounted(() => {
259
+ getStepsItemRect()
260
+ })
261
+
262
+ // 获取组件的尺寸,用于设置横线的位置
263
+ const getStepsItemRect = () => {
264
+ getRect('.hy-steps-item', true, instance).then((rect) => {
265
+ stepsRects.value = rect as UniApp.NodeInfo[]
266
+ })
267
+
268
+ getRect('.hy-steps-item__wrapper', true, instance).then((rect) => {
269
+ itemRect.value = rect as UniApp.NodeInfo[]
270
+ })
271
+ }
272
+ </script>
273
+
274
+ <style lang="scss" scoped>
275
+ @import './index.scss';
276
+ </style>