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.
@@ -0,0 +1,142 @@
1
+ <template>
2
+ <view :class="`hy-skeleton ${customClass}`" :style="customStyle">
3
+ <view class="hy-skeleton__content" v-if="show">
4
+ <view
5
+ class="hy-skeleton__row"
6
+ v-for="(row, index) of parsedRowCols"
7
+ :key="`row-${index}`"
8
+ >
9
+ <view
10
+ v-for="(col, idx) of row"
11
+ :key="`col-${idx}`"
12
+ :class="col.class"
13
+ :style="col.style"
14
+ />
15
+ </view>
16
+ </view>
17
+ <view v-else>
18
+ <slot />
19
+ </view>
20
+ </view>
21
+ </template>
22
+
23
+ <script lang="ts">
24
+ export default {
25
+ // #ifdef H5
26
+ name: 'hy-skeleton',
27
+ // #endif
28
+ options: { virtualHost: true, addGlobalClass: true, styleIsolation: 'shared' }
29
+ }
30
+ </script>
31
+
32
+ <script lang="ts" setup>
33
+ import type { CSSProperties } from 'vue'
34
+ import { ref, computed, watch } from 'vue'
35
+ import type { SkeletonRowCol, SkeletonRowColObj } from './typing'
36
+ import skeletonProps from './props'
37
+ import { isNumber, addUnit, isArray } from '../../libs'
38
+
39
+ /**
40
+ * 用于等待加载内容所展示的占位图形组合,有动态效果加载效果,减少用户等待焦虑。
41
+ * @displayName hy-skeleton
42
+ */
43
+ defineOptions({})
44
+
45
+ const themeMap = {
46
+ avatar: [{ type: 'circle', height: '64px', width: '64px' }],
47
+ image: [{ type: 'rect', height: '64px', width: '64px' }],
48
+ text: [
49
+ 1,
50
+ [
51
+ { width: '24%', height: '16px', marginRight: '16px' },
52
+ { width: '76%', height: '16px' }
53
+ ]
54
+ ],
55
+ paragraph: [1, 1, 1, { width: '55%' }]
56
+ }
57
+ const props = defineProps(skeletonProps)
58
+ const rowCols = ref<SkeletonRowCol[]>([])
59
+
60
+ const parsedRowCols = computed(() => {
61
+ return rowCols.value.map((item) => {
62
+ if (isNumber(item)) {
63
+ return [
64
+ {
65
+ class: getColItemClass({ type: 'text' }),
66
+ style: {}
67
+ }
68
+ ]
69
+ }
70
+ if (Array.isArray(item)) {
71
+ return item.map((col) => {
72
+ return {
73
+ ...col,
74
+ class: getColItemClass(col),
75
+ style: getColItemStyle(col)
76
+ }
77
+ })
78
+ }
79
+ const nItem = item as SkeletonRowColObj
80
+
81
+ return [
82
+ {
83
+ ...nItem,
84
+ class: getColItemClass(nItem),
85
+ style: getColItemStyle(nItem)
86
+ }
87
+ ]
88
+ })
89
+ })
90
+
91
+ function getColItemClass(rowCol: SkeletonRowColObj) {
92
+ return [
93
+ 'hy-skeleton__col',
94
+ `hy-skeleton--type-${rowCol.type || 'text'}`,
95
+ { [`hy-skeleton--animation-${props.animation}`]: props.animation }
96
+ ]
97
+ }
98
+ function getColItemStyle(rowCol: SkeletonRowColObj) {
99
+ const style: CSSProperties = {}
100
+ const styleName = [
101
+ 'size',
102
+ 'width',
103
+ 'height',
104
+ 'margin',
105
+ 'background',
106
+ 'marginLeft',
107
+ 'marginRight',
108
+ 'borderRadius',
109
+ 'backgroundColor'
110
+ ]
111
+
112
+ for (const name of styleName) {
113
+ if (Object.prototype.hasOwnProperty.call(rowCol, name)) {
114
+ const px = addUnit(rowCol[name])
115
+
116
+ if (name === 'size') {
117
+ style.width = px
118
+ style.height = px
119
+ } else {
120
+ ;(style as any)[name] = px
121
+ }
122
+ }
123
+ }
124
+ return style
125
+ }
126
+
127
+ watch(
128
+ () => props.rowCol,
129
+ (rowCol) => {
130
+ rowCols.value = [
131
+ ...(isArray(rowCol) && rowCol.length ? props.rowCol : themeMap[props.theme])
132
+ ]
133
+ },
134
+ { immediate: true }
135
+ )
136
+
137
+ const show = computed(() => props.loading == undefined || props.loading === true)
138
+ </script>
139
+
140
+ <style lang="scss" scoped>
141
+ @import './index.scss';
142
+ </style>
@@ -0,0 +1,90 @@
1
+ @use "../../libs/css/theme" as *;
2
+ @use "../../libs/css/mixin" as *;
3
+
4
+
5
+ @include b(skeleton) {
6
+ box-sizing: border-box;
7
+
8
+ @include e(row) {
9
+ justify-content: space-between;
10
+ margin-bottom: $hy-border-margin-padding-base;
11
+ display: flex;
12
+ align-items: center;
13
+
14
+ &:only-child,
15
+ &:last-child {
16
+ margin-bottom: 0;
17
+ }
18
+ }
19
+ @include e(col) {
20
+ border-radius: $hy-border-radius-sm;
21
+ background-color: $hy-background--skeleton;
22
+ display: flex;
23
+ align-items: center;
24
+ justify-content: center;
25
+
26
+ &:first-child:last-child,
27
+ &:last-child {
28
+ margin-right: 0;
29
+ }
30
+ }
31
+ @include m(type) {
32
+ &-text {
33
+ width: 100%;
34
+ height: 20px;
35
+ border-radius: $hy-border-radius-sm;
36
+ }
37
+
38
+ &-rect {
39
+ width: 100%;
40
+ height: 20px;
41
+ border-radius: $hy-border-radius-base;
42
+ }
43
+
44
+ &-circle {
45
+ flex-shrink: 0;
46
+ width: 48px;
47
+ height: 48px;
48
+ border-radius: $hy-border-radius-circle;
49
+ }
50
+ }
51
+ @include m(animation) {
52
+ &-gradient {
53
+ position: relative;
54
+ overflow-x: hidden;
55
+
56
+ &::after {
57
+ content: ' ';
58
+ position: absolute;
59
+ animation: wd-skeleton-gradient 1.5s linear 2s infinite;
60
+ background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(0, 0, 0, 0.04), rgba(255, 255, 255, 0));
61
+ inset: 0;
62
+ }
63
+ }
64
+
65
+ &-flashed {
66
+ animation: wd-skeleton-flashed 2s linear 2s infinite;
67
+ }
68
+ }
69
+
70
+ @keyframes wd-skeleton-gradient {
71
+ 0% {
72
+ transform: translateX(-100%) skewX(-15deg);
73
+ }
74
+ 100% {
75
+ transform: translateX(100%) skewX(-15deg);
76
+ }
77
+ }
78
+ @keyframes wd-skeleton-flashed {
79
+ 0% {
80
+ opacity: 1;
81
+ }
82
+ 50% {
83
+ opacity: 0.3;
84
+ background-color: rgba(230, 230, 230, 0.3);
85
+ }
86
+ 100% {
87
+ opacity: 1;
88
+ }
89
+ }
90
+ }
@@ -0,0 +1,46 @@
1
+ import type { CSSProperties, PropType } from 'vue'
2
+ import type { SkeletonAnimation, SkeletonRowCol, SkeletonTheme } from './typing'
3
+
4
+ const skeletonProps = {
5
+ /**
6
+ * 骨架图风格,有基础、头像组合等两大类
7
+ * @values text,avatar,paragraph,image
8
+ */
9
+ theme: {
10
+ type: String as PropType<SkeletonTheme>,
11
+ default: 'text'
12
+ },
13
+ /**
14
+ * 用于设置行列数量、宽度高度、间距等。
15
+ * @example
16
+ * 【示例一】,`[1, 1, 2]` 表示输出三行骨架图,第一行一列,第二行一列,第三行两列。
17
+ * 【示例二】,`[1, 1, { width: '100px' }]` 表示自定义第三行的宽度为 `100px`。
18
+ * 【示例三】,`[1, 2, [{ width, height }, { width, height, marginLeft }]]` 表示第三行有两列,且自定义宽度、高度和间距
19
+ */
20
+ rowCol: {
21
+ type: Array as PropType<SkeletonRowCol>
22
+ },
23
+ /**
24
+ * 是否为加载状态,如果是则显示骨架图,如果不是则显示加载完成的内容
25
+ * @default true
26
+ */
27
+ loading: {
28
+ type: Boolean,
29
+ default: true
30
+ },
31
+ /**
32
+ * 动画效果,有「渐变加载动画」和「闪烁加载动画」两种。值为空则表示没有动画
33
+ */
34
+ animation: {
35
+ type: String as PropType<SkeletonAnimation>,
36
+ default: ''
37
+ },
38
+ /** 定义需要用到的外部样式 */
39
+ customStyle: {
40
+ type: Object as PropType<CSSProperties>
41
+ },
42
+ /** 自定义外部类名 */
43
+ customClass: String
44
+ }
45
+
46
+ export default skeletonProps
@@ -0,0 +1,31 @@
1
+ import type { ExtractPropTypes } from 'vue'
2
+ import skeletonProps from './props'
3
+
4
+ export type SkeletonTheme = 'text' | 'avatar' | 'paragraph' | 'image'
5
+ export type SkeletonAnimation = 'gradient' | 'flashed'
6
+ export type SkeletonRowColObj = {
7
+ [key: string]: any
8
+ type?: 'rect' | 'circle' | 'text'
9
+ size?: string | number
10
+ width?: string | number
11
+ height?: string | number
12
+ margin?: string | number
13
+ background?: string
14
+ marginLeft?: string | number
15
+ marginRight?: string | number
16
+ borderRadius?: string | number
17
+ backgroundColor?: string
18
+ }
19
+ export type SkeletonRowCol = number | SkeletonRowColObj | Array<SkeletonRowColObj>
20
+ export type SkeletonThemeVars = {
21
+ notifyPadding?: string
22
+ notifyFontSize?: string
23
+ notifyTextColor?: string
24
+ notifyLineHeight?: number | string
25
+ notifyDangerBackground?: string
26
+ notifyPrimaryBackground?: string
27
+ notifySuccessBackground?: string
28
+ notifyWarningBackground?: string
29
+ }
30
+
31
+ export type HySkeletonProps = ExtractPropTypes<typeof skeletonProps>