sard-uniapp 1.20.1 → 1.21.0
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 +26 -0
- package/README.md +3 -2
- package/components/config/index.d.ts +5 -0
- package/components/config/index.js +5 -0
- package/components/crop-image-agent/common.js +1 -1
- package/components/crop-image-agent/crop-image-agent.vue +1 -1
- package/components/dialog/README.md +19 -3
- package/components/dialog/common.d.ts +0 -1
- package/components/dialog/dialog.vue +1 -2
- package/components/dialog-agent/common.d.ts +5 -2
- package/components/dialog-agent/common.js +2 -2
- package/components/dialog-agent/dialog-agent.d.ts +7 -1
- package/components/dialog-agent/dialog-agent.vue +123 -9
- package/components/dialog-agent/index.d.ts +1 -1
- package/components/dialog-agent/index.js +1 -1
- package/components/fab/README.md +6 -0
- package/components/fab/fab.vue +1 -1
- package/components/list/README.md +19 -12
- package/components/list/common.d.ts +6 -1
- package/components/list/common.js +1 -0
- package/components/list/index.scss +8 -0
- package/components/list/list.vue +12 -2
- package/components/list-item/index.scss +6 -0
- package/components/list-item/list-item.vue +6 -3
- package/components/locale/lang/en-US.js +1 -1
- package/components/locale/lang/zh-CN.js +1 -1
- package/components/notify/README.md +38 -3
- package/components/notify/common.d.ts +5 -1
- package/components/notify/index.d.ts +1 -1
- package/components/notify/notify.d.ts +14 -7
- package/components/notify/notify.vue +25 -4
- package/components/notify-agent/common.d.ts +5 -2
- package/components/notify-agent/common.js +2 -2
- package/components/notify-agent/index.d.ts +1 -1
- package/components/notify-agent/index.js +1 -1
- package/components/notify-agent/notify-agent.d.ts +7 -1
- package/components/notify-agent/notify-agent.vue +90 -5
- package/components/popup/common.d.ts +11 -0
- package/components/toast/README.md +28 -6
- package/components/toast/common.d.ts +2 -1
- package/components/toast/toast.d.ts +5 -3
- package/components/toast/toast.vue +17 -3
- package/components/toast-agent/common.d.ts +5 -2
- package/components/toast-agent/common.js +2 -2
- package/components/toast-agent/index.d.ts +1 -1
- package/components/toast-agent/index.js +1 -1
- package/components/toast-agent/toast-agent.d.ts +7 -1
- package/components/toast-agent/toast-agent.vue +85 -5
- package/components/upload/README.md +31 -23
- package/components/upload/common.d.ts +4 -1
- package/components/upload/upload.vue +4 -4
- package/components/waterfall/README.md +162 -0
- package/components/waterfall/common.d.ts +32 -0
- package/components/waterfall/common.js +3 -0
- package/components/waterfall/index.d.ts +1 -0
- package/components/waterfall/index.js +1 -0
- package/components/waterfall/index.scss +7 -0
- package/components/waterfall/test/SimulatedImage.vue +53 -0
- package/components/waterfall/variables.scss +6 -0
- package/components/waterfall/waterfall.d.ts +23 -0
- package/components/waterfall/waterfall.vue +182 -0
- package/components/waterfall-item/common.d.ts +23 -0
- package/components/waterfall-item/common.js +1 -0
- package/components/waterfall-item/index.d.ts +1 -0
- package/components/waterfall-item/index.js +1 -0
- package/components/waterfall-item/index.scss +18 -0
- package/components/waterfall-item/waterfall-item.d.ts +10 -0
- package/components/waterfall-item/waterfall-item.vue +115 -0
- package/components/waterfall-load/common.d.ts +19 -0
- package/components/waterfall-load/common.js +1 -0
- package/components/waterfall-load/index.d.ts +1 -0
- package/components/waterfall-load/index.js +1 -0
- package/components/waterfall-load/index.scss +12 -0
- package/components/waterfall-load/waterfall-load.d.ts +14 -0
- package/components/waterfall-load/waterfall-load.vue +87 -0
- package/global.d.ts +3 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/index.scss +1 -0
- package/package.json +1 -1
- package/utils/utils.d.ts +1 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="waterfallClass" :style="waterfallStyle">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
import { mergeDefaults as _mergeDefaults, defineComponent as _defineComponent } from "vue";
|
|
9
|
+
import {
|
|
10
|
+
computed,
|
|
11
|
+
getCurrentInstance,
|
|
12
|
+
nextTick,
|
|
13
|
+
onMounted,
|
|
14
|
+
provide,
|
|
15
|
+
reactive,
|
|
16
|
+
ref,
|
|
17
|
+
watch
|
|
18
|
+
} from "vue";
|
|
19
|
+
import {
|
|
20
|
+
classNames,
|
|
21
|
+
stringifyStyle,
|
|
22
|
+
createBem,
|
|
23
|
+
getBoundingClientRect,
|
|
24
|
+
uniqid,
|
|
25
|
+
throttle
|
|
26
|
+
} from "../../utils";
|
|
27
|
+
import {
|
|
28
|
+
defaultWaterfallProps,
|
|
29
|
+
waterfallContextKey
|
|
30
|
+
} from "./common";
|
|
31
|
+
/**
|
|
32
|
+
* @property {string} rootClass 组件根元素类名,默认值:-。
|
|
33
|
+
* @property {StyleValue} rootStyle 组件根元素样式,默认值:-。
|
|
34
|
+
* @property {number} columns 自定义列数,默认值:2。
|
|
35
|
+
* @property {number} columnGap 列间距,单位px,默认值:16。
|
|
36
|
+
* @property {number} rowGap 行间距,单位px,默认值:16。
|
|
37
|
+
* @event {() => void} load 加载完时触发,无论是正常加载完,还是超时
|
|
38
|
+
* @event {() => void} loadstart 瀑布流项项开始加载时触发
|
|
39
|
+
*/
|
|
40
|
+
export default _defineComponent({
|
|
41
|
+
...{
|
|
42
|
+
options: {
|
|
43
|
+
virtualHost: true,
|
|
44
|
+
styleIsolation: "shared"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
__name: "waterfall",
|
|
48
|
+
props: _mergeDefaults({
|
|
49
|
+
rootStyle: { type: [Boolean, null, String, Object, Array], required: false, skipCheck: true },
|
|
50
|
+
rootClass: { type: String, required: false },
|
|
51
|
+
columns: { type: Number, required: false },
|
|
52
|
+
columnGap: { type: Number, required: false },
|
|
53
|
+
rowGap: { type: Number, required: false }
|
|
54
|
+
}, defaultWaterfallProps),
|
|
55
|
+
emits: ["load", "loadstart"],
|
|
56
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
57
|
+
const props = __props;
|
|
58
|
+
const emit = __emit;
|
|
59
|
+
const bem = createBem("waterfall");
|
|
60
|
+
const containerId = uniqid();
|
|
61
|
+
const instance = getCurrentInstance();
|
|
62
|
+
const containerWidth = ref(0);
|
|
63
|
+
const containerHeight = ref(0);
|
|
64
|
+
const columnWidth = computed(() => {
|
|
65
|
+
return (containerWidth.value - (props.columns - 1) * props.columnGap) / props.columns;
|
|
66
|
+
});
|
|
67
|
+
onMounted(async () => {
|
|
68
|
+
containerWidth.value = (await getBoundingClientRect(`.${containerId}`, instance)).width;
|
|
69
|
+
});
|
|
70
|
+
let loadStatus = "idle";
|
|
71
|
+
let loadedHandlers = [];
|
|
72
|
+
const onLoad = (handler) => {
|
|
73
|
+
nextTick(() => {
|
|
74
|
+
if (loadStatus === "idle") {
|
|
75
|
+
handler();
|
|
76
|
+
} else {
|
|
77
|
+
if (!loadedHandlers.includes(handler)) {
|
|
78
|
+
loadedHandlers.push(handler);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
const updateLoadStatus = () => {
|
|
84
|
+
const includeLoading = items.some((item) => !item.loaded);
|
|
85
|
+
if (includeLoading) {
|
|
86
|
+
if (loadStatus === "idle") {
|
|
87
|
+
loadStatus = "busy";
|
|
88
|
+
emit("loadstart");
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
if (loadStatus === "busy") {
|
|
92
|
+
loadedHandlers.forEach((handler) => handler());
|
|
93
|
+
loadedHandlers = [];
|
|
94
|
+
loadStatus = "idle";
|
|
95
|
+
emit("load");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const items = [];
|
|
100
|
+
const addItem = (item) => {
|
|
101
|
+
if (!items.includes(item)) {
|
|
102
|
+
items.push(item);
|
|
103
|
+
reflow();
|
|
104
|
+
updateLoadStatus();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const removeItem = (item) => {
|
|
108
|
+
if (items.includes(item)) {
|
|
109
|
+
items.splice(items.indexOf(item), 1);
|
|
110
|
+
reflow();
|
|
111
|
+
updateLoadStatus();
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const reflow = throttle(async () => {
|
|
115
|
+
const columns = Array(props.columns).fill(0).map((_, index) => {
|
|
116
|
+
return { colIndex: index, height: 0 };
|
|
117
|
+
});
|
|
118
|
+
for (const item of items) {
|
|
119
|
+
if (!item.loaded) {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
columns.sort((a, b) => a.height - b.height);
|
|
123
|
+
const minColumn = columns[0];
|
|
124
|
+
if (!minColumn) break;
|
|
125
|
+
await item.beforeReflow();
|
|
126
|
+
item.top = minColumn.height === 0 ? 0 : minColumn.height + props.rowGap;
|
|
127
|
+
item.left = (props.columnGap + columnWidth.value) * minColumn.colIndex;
|
|
128
|
+
item.visible = true;
|
|
129
|
+
minColumn.height = item.top + item.height;
|
|
130
|
+
}
|
|
131
|
+
containerHeight.value = columns.sort((a, b) => b.height - a.height)[0].height;
|
|
132
|
+
}, 50);
|
|
133
|
+
const onItemLoad = () => {
|
|
134
|
+
reflow();
|
|
135
|
+
updateLoadStatus();
|
|
136
|
+
};
|
|
137
|
+
watch([() => props.columns, () => props.columnGap, () => props.rowGap], () => {
|
|
138
|
+
setTimeout(() => {
|
|
139
|
+
reflow();
|
|
140
|
+
}, 50);
|
|
141
|
+
});
|
|
142
|
+
provide(
|
|
143
|
+
waterfallContextKey,
|
|
144
|
+
reactive({
|
|
145
|
+
addItem,
|
|
146
|
+
removeItem,
|
|
147
|
+
onItemLoad,
|
|
148
|
+
columnWidth
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
__expose({
|
|
152
|
+
reflow,
|
|
153
|
+
onLoad
|
|
154
|
+
});
|
|
155
|
+
const waterfallClass = computed(() => {
|
|
156
|
+
return classNames(bem.b(), containerId, props.rootClass);
|
|
157
|
+
});
|
|
158
|
+
const waterfallStyle = computed(() => {
|
|
159
|
+
return stringifyStyle(
|
|
160
|
+
{
|
|
161
|
+
height: containerHeight.value + "px"
|
|
162
|
+
},
|
|
163
|
+
props.rootStyle
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
const __returned__ = { props, emit, bem, containerId, instance, containerWidth, containerHeight, columnWidth, get loadStatus() {
|
|
167
|
+
return loadStatus;
|
|
168
|
+
}, set loadStatus(v) {
|
|
169
|
+
loadStatus = v;
|
|
170
|
+
}, get loadedHandlers() {
|
|
171
|
+
return loadedHandlers;
|
|
172
|
+
}, set loadedHandlers(v) {
|
|
173
|
+
loadedHandlers = v;
|
|
174
|
+
}, onLoad, updateLoadStatus, items, addItem, removeItem, reflow, onItemLoad, waterfallClass, waterfallStyle };
|
|
175
|
+
return __returned__;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
</script>
|
|
179
|
+
|
|
180
|
+
<style lang="scss">
|
|
181
|
+
@import './index.scss';
|
|
182
|
+
</style>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type StyleValue } from 'vue';
|
|
2
|
+
export interface WaterfallItemProps {
|
|
3
|
+
rootStyle?: StyleValue;
|
|
4
|
+
rootClass?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface WaterfallItemSlots {
|
|
7
|
+
default?(props: {
|
|
8
|
+
onLoad: () => void;
|
|
9
|
+
columnWidth: number;
|
|
10
|
+
}): any;
|
|
11
|
+
}
|
|
12
|
+
export interface WaterfallItemEmits {
|
|
13
|
+
}
|
|
14
|
+
export interface WaterfallItemExpose {
|
|
15
|
+
}
|
|
16
|
+
export interface WaterfallItemInfo {
|
|
17
|
+
height: number;
|
|
18
|
+
loaded: boolean;
|
|
19
|
+
visible: boolean;
|
|
20
|
+
top: number;
|
|
21
|
+
left: number;
|
|
22
|
+
beforeReflow: () => Promise<void>;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { WaterfallItemProps, WaterfallItemSlots, WaterfallItemEmits, WaterfallItemExpose, } from './common';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
@use '../style/base' as *;
|
|
2
|
+
|
|
3
|
+
@include bem(waterfall-item) {
|
|
4
|
+
@include b() {
|
|
5
|
+
@include universal;
|
|
6
|
+
position: absolute;
|
|
7
|
+
pointer-events: none;
|
|
8
|
+
opacity: 0;
|
|
9
|
+
transition:
|
|
10
|
+
opacity var(--sar-waterfall-duration),
|
|
11
|
+
transform var(--sar-waterfall-duration);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@include m(show) {
|
|
15
|
+
pointer-events: auto;
|
|
16
|
+
opacity: 1;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type WaterfallItemProps, type WaterfallItemSlots } from './common';
|
|
2
|
+
declare function __VLS_template(): Readonly<WaterfallItemSlots> & WaterfallItemSlots;
|
|
3
|
+
declare const __VLS_component: import("vue").DefineComponent<WaterfallItemProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<WaterfallItemProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
4
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
|
|
5
|
+
export default _default;
|
|
6
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
7
|
+
new (): {
|
|
8
|
+
$slots: S;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="waterfallItemClass" :style="waterfallItemStyle">
|
|
3
|
+
<slot :on-load="onLoad" :column-width="context.columnWidth"></slot>
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
import { defineComponent as _defineComponent } from "vue";
|
|
9
|
+
import {
|
|
10
|
+
computed,
|
|
11
|
+
getCurrentInstance,
|
|
12
|
+
inject,
|
|
13
|
+
onMounted,
|
|
14
|
+
onBeforeUnmount,
|
|
15
|
+
reactive,
|
|
16
|
+
ref,
|
|
17
|
+
watch
|
|
18
|
+
} from "vue";
|
|
19
|
+
import {
|
|
20
|
+
classNames,
|
|
21
|
+
stringifyStyle,
|
|
22
|
+
createBem,
|
|
23
|
+
uniqid,
|
|
24
|
+
getBoundingClientRect
|
|
25
|
+
} from "../../utils";
|
|
26
|
+
import { waterfallContextKey } from "../waterfall/common";
|
|
27
|
+
import { useTimeout } from "../../use";
|
|
28
|
+
export default _defineComponent({
|
|
29
|
+
...{
|
|
30
|
+
options: {
|
|
31
|
+
virtualHost: true,
|
|
32
|
+
styleIsolation: "shared"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
__name: "waterfall-item",
|
|
36
|
+
props: {
|
|
37
|
+
rootStyle: { type: [Boolean, null, String, Object, Array], required: false, skipCheck: true },
|
|
38
|
+
rootClass: { type: String, required: false }
|
|
39
|
+
},
|
|
40
|
+
setup(__props, { expose: __expose }) {
|
|
41
|
+
const props = __props;
|
|
42
|
+
const bem = createBem("waterfall-item");
|
|
43
|
+
const instance = getCurrentInstance();
|
|
44
|
+
const itemId = uniqid();
|
|
45
|
+
const item = reactive({
|
|
46
|
+
loaded: false,
|
|
47
|
+
visible: false,
|
|
48
|
+
height: 0,
|
|
49
|
+
top: 0,
|
|
50
|
+
left: 0,
|
|
51
|
+
beforeReflow: async () => {
|
|
52
|
+
await updateHeight();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
const updateHeight = async () => {
|
|
56
|
+
try {
|
|
57
|
+
item.height = (await getBoundingClientRect(`.${itemId}`, instance)).height;
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const context = inject(waterfallContextKey);
|
|
62
|
+
const onLoad = () => {
|
|
63
|
+
if (!item.loaded) {
|
|
64
|
+
item.loaded = true;
|
|
65
|
+
context.onItemLoad();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
onMounted(() => {
|
|
69
|
+
context.addItem(item);
|
|
70
|
+
});
|
|
71
|
+
onBeforeUnmount(() => {
|
|
72
|
+
context.removeItem(item);
|
|
73
|
+
});
|
|
74
|
+
__expose({});
|
|
75
|
+
const waterfallItemClass = computed(() => {
|
|
76
|
+
return classNames(
|
|
77
|
+
bem.b(),
|
|
78
|
+
bem.m("show", item.visible),
|
|
79
|
+
itemId,
|
|
80
|
+
props.rootClass
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
const laterVisible = ref(false);
|
|
84
|
+
const { start } = useTimeout(() => {
|
|
85
|
+
laterVisible.value = true;
|
|
86
|
+
}, 100);
|
|
87
|
+
watch(
|
|
88
|
+
() => item.visible,
|
|
89
|
+
() => {
|
|
90
|
+
if (item.visible) {
|
|
91
|
+
start();
|
|
92
|
+
} else {
|
|
93
|
+
laterVisible.value = false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
const waterfallItemStyle = computed(() => {
|
|
98
|
+
return stringifyStyle(
|
|
99
|
+
{
|
|
100
|
+
width: context.columnWidth + "px",
|
|
101
|
+
transform: `translate3d(${item.left}px,${item.top}px,0px)`,
|
|
102
|
+
transition: laterVisible.value ? `opacity var(--sar-waterfall-duration),transform var(--sar-waterfall-duration)` : `opacity var(--sar-waterfall-duration)`
|
|
103
|
+
},
|
|
104
|
+
props.rootStyle
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
const __returned__ = { props, bem, instance, itemId, item, updateHeight, context, onLoad, waterfallItemClass, laterVisible, start, waterfallItemStyle };
|
|
108
|
+
return __returned__;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
</script>
|
|
112
|
+
|
|
113
|
+
<style lang="scss">
|
|
114
|
+
@import './index.scss';
|
|
115
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type StyleValue } from 'vue';
|
|
2
|
+
export interface WaterfallLoadProps {
|
|
3
|
+
rootStyle?: StyleValue;
|
|
4
|
+
rootClass?: string;
|
|
5
|
+
maxWait?: number;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface WaterfallLoadSlots {
|
|
10
|
+
default?(props: {
|
|
11
|
+
onLoad: (event: any) => void;
|
|
12
|
+
overtime: boolean;
|
|
13
|
+
}): any;
|
|
14
|
+
}
|
|
15
|
+
export interface WaterfallLoadEmits {
|
|
16
|
+
(e: 'load'): void;
|
|
17
|
+
}
|
|
18
|
+
export interface WaterfallLoadExpose {
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { WaterfallLoadProps, WaterfallLoadSlots, WaterfallLoadEmits, WaterfallLoadExpose, } from './common';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type WaterfallLoadProps, type WaterfallLoadSlots } from './common';
|
|
2
|
+
declare function __VLS_template(): Readonly<WaterfallLoadSlots> & WaterfallLoadSlots;
|
|
3
|
+
declare const __VLS_component: import("vue").DefineComponent<WaterfallLoadProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
4
|
+
load: () => any;
|
|
5
|
+
}, string, import("vue").PublicProps, Readonly<WaterfallLoadProps> & Readonly<{
|
|
6
|
+
onLoad?: (() => any) | undefined;
|
|
7
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
8
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
|
|
9
|
+
export default _default;
|
|
10
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
11
|
+
new (): {
|
|
12
|
+
$slots: S;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="waterfallLoadClass" :style="waterfallLoadStyle">
|
|
3
|
+
<view :class="bem.e('content')">
|
|
4
|
+
<slot :on-load="onLoad" :overtime="overtime"></slot>
|
|
5
|
+
</view>
|
|
6
|
+
</view>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script>
|
|
10
|
+
import { defineComponent as _defineComponent } from "vue";
|
|
11
|
+
import { computed, onMounted, ref } from "vue";
|
|
12
|
+
import { classNames, createBem, stringifyStyle } from "../../utils";
|
|
13
|
+
import { useTimeout } from "../../use";
|
|
14
|
+
export default _defineComponent({
|
|
15
|
+
...{
|
|
16
|
+
options: {
|
|
17
|
+
virtualHost: true,
|
|
18
|
+
styleIsolation: "shared"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
__name: "waterfall-load",
|
|
22
|
+
props: {
|
|
23
|
+
rootStyle: { type: [Boolean, null, String, Object, Array], required: false, skipCheck: true },
|
|
24
|
+
rootClass: { type: String, required: false },
|
|
25
|
+
maxWait: { type: Number, required: false },
|
|
26
|
+
width: { type: Number, required: false },
|
|
27
|
+
height: { type: Number, required: false }
|
|
28
|
+
},
|
|
29
|
+
emits: ["load"],
|
|
30
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
31
|
+
const props = __props;
|
|
32
|
+
const emit = __emit;
|
|
33
|
+
const bem = createBem("waterfall-load");
|
|
34
|
+
let loaded = false;
|
|
35
|
+
const overtime = ref(false);
|
|
36
|
+
const currWidth = ref(props.width || 320);
|
|
37
|
+
const currHeight = ref(props.height || 240);
|
|
38
|
+
const paddingTop = computed(
|
|
39
|
+
() => currHeight.value / currWidth.value * 100 + "%"
|
|
40
|
+
);
|
|
41
|
+
const { start } = useTimeout(
|
|
42
|
+
() => {
|
|
43
|
+
if (!loaded) {
|
|
44
|
+
overtime.value = true;
|
|
45
|
+
emit("load");
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
() => props.maxWait || 0
|
|
49
|
+
);
|
|
50
|
+
const onLoad = ({ detail }) => {
|
|
51
|
+
loaded = true;
|
|
52
|
+
if (!overtime.value) {
|
|
53
|
+
if (detail.width) {
|
|
54
|
+
currWidth.value = detail.width;
|
|
55
|
+
currHeight.value = detail.height;
|
|
56
|
+
}
|
|
57
|
+
emit("load");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
onMounted(() => {
|
|
61
|
+
start();
|
|
62
|
+
});
|
|
63
|
+
__expose({});
|
|
64
|
+
const waterfallLoadClass = computed(() => {
|
|
65
|
+
return classNames(bem.b(), props.rootClass);
|
|
66
|
+
});
|
|
67
|
+
const waterfallLoadStyle = computed(() => {
|
|
68
|
+
return stringifyStyle(
|
|
69
|
+
{
|
|
70
|
+
paddingTop: paddingTop.value
|
|
71
|
+
},
|
|
72
|
+
props.rootStyle
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
const __returned__ = { props, emit, bem, get loaded() {
|
|
76
|
+
return loaded;
|
|
77
|
+
}, set loaded(v) {
|
|
78
|
+
loaded = v;
|
|
79
|
+
}, overtime, currWidth, currHeight, paddingTop, start, onLoad, waterfallLoadClass, waterfallLoadStyle };
|
|
80
|
+
return __returned__;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<style lang="scss">
|
|
86
|
+
@import './index.scss';
|
|
87
|
+
</style>
|
package/global.d.ts
CHANGED
|
@@ -125,6 +125,9 @@ declare module 'vue' {
|
|
|
125
125
|
SarToastAgent: typeof import('./components/toast-agent/toast-agent').default
|
|
126
126
|
SarTree: typeof import('./components/tree/tree').default
|
|
127
127
|
SarUpload: typeof import('./components/upload/upload').default
|
|
128
|
+
SarWaterfall: typeof import('./components/waterfall/waterfall').default
|
|
129
|
+
SarWaterfallItem: typeof import('./components/waterfall-item/waterfall-item').default
|
|
130
|
+
SarWaterfallLoad: typeof import('./components/waterfall-load/waterfall-load').default
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
|
package/index.d.ts
CHANGED
|
@@ -106,5 +106,8 @@ export * from './components/toast';
|
|
|
106
106
|
export * from './components/toast-agent';
|
|
107
107
|
export * from './components/tree';
|
|
108
108
|
export * from './components/upload';
|
|
109
|
+
export * from './components/waterfall';
|
|
110
|
+
export * from './components/waterfall-item';
|
|
111
|
+
export * from './components/waterfall-load';
|
|
109
112
|
export * from './use';
|
|
110
113
|
export * from './utils';
|
package/index.js
CHANGED
|
@@ -106,5 +106,8 @@ export * from './components/toast';
|
|
|
106
106
|
export * from './components/toast-agent';
|
|
107
107
|
export * from './components/tree';
|
|
108
108
|
export * from './components/upload';
|
|
109
|
+
export * from './components/waterfall';
|
|
110
|
+
export * from './components/waterfall-item';
|
|
111
|
+
export * from './components/waterfall-load';
|
|
109
112
|
export * from './use';
|
|
110
113
|
export * from './utils';
|
package/index.scss
CHANGED
package/package.json
CHANGED
package/utils/utils.d.ts
CHANGED
|
@@ -57,4 +57,4 @@ export declare const noop: () => void;
|
|
|
57
57
|
export declare function getMayPrimitiveOption(option: string | number | boolean | {
|
|
58
58
|
[key: PropertyKey]: any;
|
|
59
59
|
}, key: string): any;
|
|
60
|
-
export declare function sleep(time: number): Promise<
|
|
60
|
+
export declare function sleep(time: number): Promise<void>;
|