hy-app 0.5.15 → 0.5.16

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,267 +1,267 @@
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 > 0"
8
- :class="[
9
- `hy-steps-item__line--${direction}`,
10
- 'hy-steps-item__line',
11
- statusClass(i, item.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.desc" name="desc" :desc="item.desc" :index="i"></slot>
106
- <text v-else :style="{ fontSize: '12px', color: '#999' }">{{
107
- item.desc
108
- }}</text>
109
- </template>
110
- </view>
111
- <!-- 内容区域 -->
112
- </view>
113
- </template>
114
- </view>
115
- </template>
116
-
117
- <script lang="ts">
118
- export default {
119
- name: 'hy-steps',
120
- options: {
121
- addGlobalClass: true,
122
- virtualHost: true,
123
- styleIsolation: 'shared'
124
- }
125
- }
126
- </script>
127
-
128
- <script setup lang="ts">
129
- import { computed, ref, onMounted, getCurrentInstance, watch } from 'vue'
130
- import type { CSSProperties } from 'vue'
131
- import type { IStepsEmits } from './typing'
132
- import type { StepListVo } from './typing'
133
- import { addUnit, getRect, ColorConfig, IconConfig } from '../../libs'
134
- import stepsProps from './props'
135
- // 组件
136
- import HyIcon from '../hy-icon/hy-icon.vue'
137
-
138
- /**
139
- * 一般用于完成一个任务要分几个步骤,标识目前处于第几步的场景。
140
- * @displayName hy-steps
141
- */
142
- defineOptions({})
143
-
144
- const props = defineProps(stepsProps)
145
- const emit = defineEmits<IStepsEmits>()
146
-
147
- const size = ref<UniApp.NodeInfo>({
148
- height: 0,
149
- width: 0
150
- })
151
- const instance = getCurrentInstance()
152
-
153
- watch(
154
- () => props.current,
155
- (newVal: number) => {
156
- if (props.list[newVal - 1]?.error) {
157
- const index = props.list.findIndex((item) => item.error)
158
- emit('update:current', index)
159
- emit('change', index)
160
- }
161
- }
162
- )
163
-
164
- // 字体标题类名
165
- const titleClass = computed(() => {
166
- return (index: number, error: boolean) => {
167
- const classes = ['hy-steps-item__content__title']
168
- if (props.current === index) {
169
- classes.push('hy-steps-item__content__title--active')
170
-
171
- if (error) {
172
- classes.push('hy-steps-item__content__title--error')
173
- }
174
- }
175
-
176
- return classes
177
- }
178
- })
179
- // 字体颜色
180
- const textColor = computed(() => {
181
- return (index: number) => (index === props.current ? '#ffffff' : props.inactiveColor)
182
- })
183
-
184
- /**
185
- * @description 线条样式
186
- * */
187
- const lineStyle = computed(() => {
188
- return (temp: StepListVo, index: number): CSSProperties => {
189
- const style: CSSProperties = {}
190
- if (props.direction === 'row') {
191
- style.width = addUnit(size.value.width! - 25)
192
- style.left = addUnit(-size.value.width! / 2 + 12)
193
- } else {
194
- style.height = addUnit(size.value.height! - 30)
195
- style.top = addUnit(25)
196
- }
197
- style.backgroundColor = temp.error ? '' : index < props.current ? '' : props.inactiveColor
198
- return style
199
- }
200
- })
201
-
202
- const itemStyleInner = computed(() => {
203
- return {}
204
- })
205
- /**
206
- * @description 状态类名
207
- * */
208
- const statusClass = computed(() => {
209
- return (index: number, error: boolean = false) => {
210
- if (props.current == index) {
211
- return error ? 'error' : 'process'
212
- } else if (props.current > index) {
213
- return 'finish'
214
- } else {
215
- return 'wait'
216
- }
217
- }
218
- })
219
- const statusColor = computed(() => {
220
- return (index: number, error?: boolean) => {
221
- let colorTmp: string | number
222
- switch (statusClass.value(index, error)) {
223
- case 'finish':
224
- colorTmp = props.activeColor
225
- break
226
- case 'error':
227
- colorTmp = ColorConfig.error
228
- break
229
- case 'process':
230
- colorTmp = props.dot ? props.current : 'transparent'
231
- break
232
- default:
233
- colorTmp = props.inactiveColor
234
- break
235
- }
236
- return colorTmp
237
- }
238
- })
239
-
240
- const contentStyle = computed<CSSProperties>(() => {
241
- const style: CSSProperties = {}
242
- if (props.direction === 'column') {
243
- style.marginLeft = props.dot ? '2px' : '6px'
244
- style.marginTop = props.dot ? '0px' : '6px'
245
- } else {
246
- style.marginTop = props.dot ? '2px' : '6px'
247
- style.marginLeft = props.dot ? '2px' : '6px'
248
- }
249
-
250
- return style
251
- })
252
-
253
- onMounted(() => {
254
- getStepsItemRect()
255
- })
256
-
257
- // 获取组件的尺寸,用于设置横线的位置
258
- const getStepsItemRect = () => {
259
- getRect('.hy-steps-item', false, instance).then((rect) => {
260
- size.value = rect as UniApp.NodeInfo
261
- })
262
- }
263
- </script>
264
-
265
- <style lang="scss" scoped>
266
- @import './index.scss';
267
- </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 } 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 stepsRects = ref<UniApp.NodeInfo[]>([])
149
+ const instance = getCurrentInstance()
150
+
151
+ watch(
152
+ () => props.current,
153
+ (newVal: number) => {
154
+ if (props.list[newVal - 1]?.error) {
155
+ const index = props.list.findIndex((item) => item.error)
156
+ emit('update:current', index)
157
+ emit('change', index)
158
+ }
159
+ }
160
+ )
161
+
162
+ // 字体标题类名
163
+ const titleClass = computed(() => {
164
+ return (index: number, error: boolean) => {
165
+ const classes = ['hy-steps-item__content__title']
166
+ if (props.current === index) {
167
+ classes.push('hy-steps-item__content__title--active')
168
+
169
+ if (error) {
170
+ classes.push('hy-steps-item__content__title--error')
171
+ }
172
+ }
173
+
174
+ return classes
175
+ }
176
+ })
177
+ // 字体颜色
178
+ const textColor = computed(() => {
179
+ return (index: number) => (index === props.current ? '#ffffff' : props.inactiveColor)
180
+ })
181
+
182
+ /**
183
+ * @description 线条样式
184
+ * */
185
+ const lineStyle = computed(() => {
186
+ return (temp: StepListVo, index: number): CSSProperties => {
187
+ const style: CSSProperties = {}
188
+ if (!stepsRects.value.length) return style
189
+ if (props.direction === 'row') {
190
+ style.width = addUnit(stepsRects.value[index].width! - 25)
191
+ style.left = addUnit(stepsRects.value[index].width! / 2 + 12)
192
+ } else {
193
+ style.height = addUnit(stepsRects.value[index].height! - 30)
194
+ style.top = addUnit(25)
195
+ }
196
+ style.backgroundColor = temp.error ? '' : index < props.current ? '' : props.inactiveColor
197
+ return style
198
+ }
199
+ })
200
+
201
+ const itemStyleInner = computed(() => {
202
+ return {}
203
+ })
204
+ /**
205
+ * @description 状态类名
206
+ * */
207
+ const statusClass = computed(() => {
208
+ return (index: number, error: boolean = false, line: string) => {
209
+ console.log(index, props.current, line, error)
210
+ if (props.current == index) {
211
+ return error ? 'error' : 'process'
212
+ } else if (props.current > index) {
213
+ return 'finish'
214
+ } else {
215
+ return 'wait'
216
+ }
217
+ }
218
+ })
219
+ const statusColor = computed(() => {
220
+ return (index: number, error?: boolean) => {
221
+ let colorTmp: string | number
222
+ switch (statusClass.value(index, error)) {
223
+ case 'finish':
224
+ colorTmp = props.activeColor
225
+ break
226
+ case 'error':
227
+ colorTmp = ColorConfig.error
228
+ break
229
+ case 'process':
230
+ colorTmp = props.dot ? props.current : 'transparent'
231
+ break
232
+ default:
233
+ colorTmp = props.inactiveColor
234
+ break
235
+ }
236
+ return colorTmp
237
+ }
238
+ })
239
+
240
+ const contentStyle = computed<CSSProperties>(() => {
241
+ const style: CSSProperties = {}
242
+ if (props.direction === 'column') {
243
+ style.marginLeft = props.dot ? '2px' : '6px'
244
+ style.marginTop = props.dot ? '0px' : '0px'
245
+ } else {
246
+ style.marginTop = props.dot ? '2px' : '6px'
247
+ style.marginLeft = props.dot ? '0px' : '0px'
248
+ }
249
+
250
+ return style
251
+ })
252
+
253
+ onMounted(() => {
254
+ getStepsItemRect()
255
+ })
256
+
257
+ // 获取组件的尺寸,用于设置横线的位置
258
+ const getStepsItemRect = () => {
259
+ getRect('.hy-steps-item', true, instance).then((rect) => {
260
+ stepsRects.value = rect as UniApp.NodeInfo[]
261
+ })
262
+ }
263
+ </script>
264
+
265
+ <style lang="scss" scoped>
266
+ @import './index.scss';
267
+ </style>
@@ -114,10 +114,10 @@
114
114
 
115
115
  @include e(title) {
116
116
  line-height: 25px;
117
- font-size: 13px;
117
+ font-size: 30rpx;
118
118
  @include m(active) {
119
119
  color: $hy-primary;
120
- font-size: 15px;
120
+ font-size: 34rpx;
121
121
  }
122
122
 
123
123
  @include m(error) {
@@ -136,6 +136,11 @@
136
136
  margin-left: $hy-border-margin-padding-sm;
137
137
  min-height: 60px;
138
138
  }
139
+
140
+ @include m(date) {
141
+ font-size: 24rpx;
142
+ color: #999;
143
+ }
139
144
  }
140
145
 
141
146
  /* 线条样式 */
@@ -1,21 +1,25 @@
1
- export interface StepListVo {
2
- /**
3
- * @description 标题
4
- * */
5
- title?: string
6
- /**
7
- * @description 描述
8
- * */
9
- desc?: string
10
- /**
11
- * @description 是否错误
12
- * */
13
- error?: boolean
14
- }
15
-
16
- export interface IStepsEmits {
17
- /** 值改成触发 */
18
- (e: 'change', index: number): void
19
- /** 值改成触发 */
20
- (e: 'update:current', index: number): void
21
- }
1
+ export interface StepListVo {
2
+ /**
3
+ * 标题
4
+ * */
5
+ title?: string
6
+ /**
7
+ * 描述
8
+ * */
9
+ docs?: string
10
+ /**
11
+ * 时间日期
12
+ * */
13
+ date?: string
14
+ /**
15
+ * 是否错误
16
+ * */
17
+ error?: boolean
18
+ }
19
+
20
+ export interface IStepsEmits {
21
+ /** 值改成触发 */
22
+ (e: 'change', index: number): void
23
+ /** 值改成触发 */
24
+ (e: 'update:current', index: number): void
25
+ }