bootstrap-vue-top 1.0.8 → 1.0.9
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/.browserslistrc +12 -0
- package/package.json +14 -9
- package/postcss.config.js +6 -0
- package/src/components/accordion/accordion-item.vue +27 -0
- package/src/components/accordion/accordion-keys.js +1 -0
- package/src/components/accordion/accordion.vue +84 -0
- package/src/components/alert/alert.js +10 -0
- package/src/components/alert-box/alert-box.vue +73 -0
- package/src/components/alert-box/index.js +25 -0
- package/src/components/alert-confirm/alert-confirm.vue +80 -0
- package/src/components/alert-confirm/index.js +26 -0
- package/src/components/alert-message/alert-message.vue +63 -0
- package/src/components/alert-message/index.js +27 -0
- package/src/components/backtop/backtop.vue +61 -0
- package/src/components/carousel/carousel.vue +107 -0
- package/src/components/collapse/collapse.js +8 -0
- package/src/components/dropdown/dropdown.js +11 -0
- package/src/components/image-preview/image-preview.vue +261 -0
- package/src/components/image-preview/index.js +26 -0
- package/src/components/loading/index.js +45 -0
- package/src/components/loading/loading-fullscreen.vue +47 -0
- package/src/components/loading/loading.vue +47 -0
- package/src/components/modal/modal.vue +83 -0
- package/src/components/modal-2/counter.js +25 -0
- package/src/components/modal-2/modal-2.vue +256 -0
- package/src/components/offcanvas/offcanvas.vue +71 -0
- package/src/components/pagination/pagination.vue +216 -0
- package/src/components/popover/popover.js +10 -0
- package/src/components/scrollspy/scrollspy.js +16 -0
- package/src/components/table/table-col.vue +61 -0
- package/src/components/table/table-keys.js +2 -0
- package/src/components/table/table.vue +320 -0
- package/src/components/tabs/tab-pane.vue +32 -0
- package/src/components/tabs/tabs-keys.js +1 -0
- package/src/components/tabs/tabs.vue +240 -0
- package/src/components/toast/index.js +29 -0
- package/src/components/toast/toast.vue +91 -0
- package/src/components/tooltip/tooltip.js +10 -0
- package/src/components/tree/tree-keys.js +7 -0
- package/src/components/tree/tree-node.vue +144 -0
- package/src/components/tree/tree.vue +92 -0
- package/src/components/treetable/treetable-col.vue +37 -0
- package/src/components/treetable/treetable-keys.js +3 -0
- package/src/components/treetable/treetable-node.vue +104 -0
- package/src/components/treetable/treetable.vue +114 -0
- package/src/components/uploader/file-uploader.vue +67 -0
- package/src/components/uploader/image-many-uploader.vue +173 -0
- package/src/components/uploader/image-one-uploader.vue +78 -0
- package/src/index.js +64 -0
- package/src/styles/alert.scss +33 -0
- package/src/styles/backtop.scss +7 -0
- package/src/styles/image-preview.scss +11 -0
- package/src/styles/index.scss +97 -0
- package/src/styles/loading.scss +12 -0
- package/src/styles/modal-2.scss +8 -0
- package/src/styles/uploader.scss +29 -0
- package/vite.config.js +58 -0
- package/dist/bootstrap-vue.css +0 -2
- package/dist/bootstrap-vue.js +0 -7714
- package/dist/bootstrap-vue.umd.cjs +0 -3
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Transition name="fadeIn" @after-leave="$emit('destroy')">
|
|
3
|
+
<div v-show="visible" ref="elementRef" class="image-preview" tabindex="-1" role="dialog" aria-modal="true">
|
|
4
|
+
<div class="d-flex w-100 h-100 justify-content-center align-items-center user-select-none">
|
|
5
|
+
<img
|
|
6
|
+
:src="data[index]"
|
|
7
|
+
class="mw-100 mh-100"
|
|
8
|
+
@load="handleLoad(index)"
|
|
9
|
+
@error="handleError"
|
|
10
|
+
:style="{ transform: `translate(${offsetX}px, ${offsetY}px) scale(${scale})` }"
|
|
11
|
+
@mousedown="startDrag"
|
|
12
|
+
@touchstart="startDragTouch"
|
|
13
|
+
draggable="false"
|
|
14
|
+
/>
|
|
15
|
+
</div>
|
|
16
|
+
<div v-if="isLoading" class="position-absolute top-50 translate-middle-y start-50 translate-middle-x">
|
|
17
|
+
<div class="spinner-grow" style="width: 3rem; height: 3rem" role="status">
|
|
18
|
+
<span class="visually-hidden">Loading...</span>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
<div class="position-absolute" style="top: 2rem; right: 2rem">
|
|
22
|
+
<button
|
|
23
|
+
type="button"
|
|
24
|
+
class="btn btn-secondary btn-lg"
|
|
25
|
+
style="
|
|
26
|
+
--bs-btn-padding-x: 0.5rem;
|
|
27
|
+
--bs-btn-padding-y: 0.5rem;
|
|
28
|
+
--bs-btn-line-height: 1;
|
|
29
|
+
--bs-btn-border-radius: 50%;
|
|
30
|
+
"
|
|
31
|
+
aria-label="Close"
|
|
32
|
+
@click="visible = false"
|
|
33
|
+
>
|
|
34
|
+
<bi-x-lg />
|
|
35
|
+
</button>
|
|
36
|
+
</div>
|
|
37
|
+
<template v-if="data.length > 1">
|
|
38
|
+
<div class="position-absolute start-50 translate-middle-x" style="bottom: 5rem">
|
|
39
|
+
<span class="badge text-bg-light">{{ index + 1 }} / {{ data.length }}</span>
|
|
40
|
+
</div>
|
|
41
|
+
</template>
|
|
42
|
+
|
|
43
|
+
<div class="position-absolute start-50 translate-middle-x" style="bottom: 2rem">
|
|
44
|
+
<div class="btn-group" role="group" aria-label="First group">
|
|
45
|
+
<template v-if="data.length > 1">
|
|
46
|
+
<button type="button" class="btn btn-secondary" @click="pre">
|
|
47
|
+
<bi-chevron-left />
|
|
48
|
+
</button>
|
|
49
|
+
<button type="button" class="btn btn-secondary" @click="next">
|
|
50
|
+
<bi-chevron-right />
|
|
51
|
+
</button>
|
|
52
|
+
</template>
|
|
53
|
+
<button type="button" class="btn btn-secondary" @click="scale = Math.min(2, scale + 0.2)">
|
|
54
|
+
<bi-zoom-in />
|
|
55
|
+
</button>
|
|
56
|
+
<button type="button" class="btn btn-secondary" @click="scale = Math.max(0.5, scale - 0.2)">
|
|
57
|
+
<bi-zoom-out />
|
|
58
|
+
</button>
|
|
59
|
+
<button type="button" class="btn btn-secondary" @click="reset">
|
|
60
|
+
<bi-arrow-repeat />
|
|
61
|
+
</button>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
</Transition>
|
|
66
|
+
</template>
|
|
67
|
+
|
|
68
|
+
<script setup>
|
|
69
|
+
import { onMounted, onBeforeUnmount, ref, shallowRef, nextTick } from 'vue';
|
|
70
|
+
import { createFocusTrap } from 'focus-trap';
|
|
71
|
+
|
|
72
|
+
const elementRef = shallowRef(null);
|
|
73
|
+
let focusTrapInstance = null;
|
|
74
|
+
|
|
75
|
+
const props = defineProps({
|
|
76
|
+
data: {
|
|
77
|
+
type: Array,
|
|
78
|
+
default: []
|
|
79
|
+
},
|
|
80
|
+
initIndex: {
|
|
81
|
+
type: Number,
|
|
82
|
+
default: 0
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const visible = ref(false);
|
|
87
|
+
const index = ref(props.initIndex);
|
|
88
|
+
|
|
89
|
+
const isLoading = ref(false); //图片加载中
|
|
90
|
+
const cache = new Map(); //图片缓存
|
|
91
|
+
|
|
92
|
+
onMounted(() => {
|
|
93
|
+
if (document.body.scrollHeight > window.innerHeight) {
|
|
94
|
+
document.body.style.cssText = `overflow: hidden; padding-right: ${window.innerWidth - document.body.clientWidth}px;`;
|
|
95
|
+
}
|
|
96
|
+
visible.value = true;
|
|
97
|
+
|
|
98
|
+
nextTick(() => {
|
|
99
|
+
//焦点陷阱
|
|
100
|
+
if (elementRef.value !== null) {
|
|
101
|
+
focusTrapInstance = createFocusTrap(elementRef.value, {
|
|
102
|
+
initialFocus: false
|
|
103
|
+
});
|
|
104
|
+
focusTrapInstance.activate();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
goto(index.value);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
//添加监听keydown
|
|
111
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
onBeforeUnmount(() => {
|
|
115
|
+
if (document.body.scrollHeight > window.innerHeight) {
|
|
116
|
+
document.body.style = null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
//停止焦点陷阱
|
|
120
|
+
if (focusTrapInstance !== null) {
|
|
121
|
+
focusTrapInstance.deactivate();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//移除监听keydown
|
|
125
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
function confirm() {
|
|
129
|
+
visible.value = false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function handleKeyDown(event) {
|
|
133
|
+
if (event.key === 'Escape') {
|
|
134
|
+
confirm();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function pre() {
|
|
139
|
+
if (index.value < props.data.length && index.value > 0) {
|
|
140
|
+
index.value--;
|
|
141
|
+
} else if (index.value === 0) {
|
|
142
|
+
index.value = props.data.length - 1;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
goto(index.value);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function next() {
|
|
149
|
+
if (index.value < props.data.length - 1) {
|
|
150
|
+
index.value++;
|
|
151
|
+
} else if (index.value === props.data.length - 1) {
|
|
152
|
+
index.value = 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
goto(index.value);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function goto(_index) {
|
|
159
|
+
if (cache.has(_index)) {
|
|
160
|
+
isLoading.value = false;
|
|
161
|
+
} else {
|
|
162
|
+
isLoading.value = true;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
reset();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const handleLoad = (_index) => {
|
|
169
|
+
isLoading.value = false;
|
|
170
|
+
cache.set(_index, props.data[_index]);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const handleError = (event) => {
|
|
174
|
+
isLoading.value = false;
|
|
175
|
+
event.target.src =
|
|
176
|
+
'data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22200%22 height=%22200%22%3E%3Crect fill=%22%23f5f5f5%22 width=%22200%22 height=%22200%22/%3E%3Ctext fill=%22%23999%22 font-family=%22sans-serif%22 font-size=%2216%22 x=%2250%25%22 y=%2250%25%22 text-anchor=%22middle%22 dy=%22.3em%22%3E图片加载失败%3C/text%3E%3C/svg%3E';
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// 图片状态
|
|
180
|
+
const offsetX = ref(0);
|
|
181
|
+
const offsetY = ref(0);
|
|
182
|
+
const scale = ref(1);
|
|
183
|
+
|
|
184
|
+
// 拖拽状态
|
|
185
|
+
let isDragging = false;
|
|
186
|
+
let startX = 0;
|
|
187
|
+
let startY = 0;
|
|
188
|
+
let startOffsetX = 0;
|
|
189
|
+
let startOffsetY = 0;
|
|
190
|
+
|
|
191
|
+
// ===== 鼠标拖拽 =====
|
|
192
|
+
const startDrag = (e) => {
|
|
193
|
+
if (e.button !== 0) return;
|
|
194
|
+
e.preventDefault();
|
|
195
|
+
|
|
196
|
+
isDragging = true;
|
|
197
|
+
|
|
198
|
+
startX = e.clientX;
|
|
199
|
+
startY = e.clientY;
|
|
200
|
+
startOffsetX = offsetX.value;
|
|
201
|
+
startOffsetY = offsetY.value;
|
|
202
|
+
|
|
203
|
+
document.addEventListener('mousemove', onDrag);
|
|
204
|
+
document.addEventListener('mouseup', endDrag);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const onDrag = (e) => {
|
|
208
|
+
if (!isDragging) return;
|
|
209
|
+
e.preventDefault();
|
|
210
|
+
// 如果有缩放,拖动距离随缩放比例变化(更自然)
|
|
211
|
+
offsetX.value = startOffsetX + (e.clientX - startX) / scale.value;
|
|
212
|
+
offsetY.value = startOffsetY + (e.clientY - startY) / scale.value;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const endDrag = () => {
|
|
216
|
+
isDragging = false;
|
|
217
|
+
document.removeEventListener('mousemove', onDrag);
|
|
218
|
+
document.removeEventListener('mouseup', endDrag);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// ===== 触摸拖拽 =====
|
|
222
|
+
const startDragTouch = (e) => {
|
|
223
|
+
e.preventDefault();
|
|
224
|
+
const touch = e.touches[0];
|
|
225
|
+
|
|
226
|
+
isDragging = true;
|
|
227
|
+
|
|
228
|
+
startX = touch.clientX;
|
|
229
|
+
startY = touch.clientY;
|
|
230
|
+
startOffsetX = offsetX.value;
|
|
231
|
+
startOffsetY = offsetY.value;
|
|
232
|
+
|
|
233
|
+
document.addEventListener('touchmove', onDragTouch);
|
|
234
|
+
document.addEventListener('touchend', endDragTouch);
|
|
235
|
+
document.addEventListener('touchcancel', endDragTouch);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const onDragTouch = (e) => {
|
|
239
|
+
if (!isDragging) return;
|
|
240
|
+
|
|
241
|
+
e.preventDefault();
|
|
242
|
+
|
|
243
|
+
const touch = e.touches[0];
|
|
244
|
+
|
|
245
|
+
offsetX.value = startOffsetX + (touch.clientX - startX) / scale.value;
|
|
246
|
+
offsetY.value = startOffsetY + (touch.clientY - startY) / scale.value;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const endDragTouch = () => {
|
|
250
|
+
isDragging = false;
|
|
251
|
+
document.removeEventListener('touchmove', onDragTouch);
|
|
252
|
+
document.removeEventListener('touchend', endDragTouch);
|
|
253
|
+
document.removeEventListener('touchcancel', endDragTouch);
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const reset = () => {
|
|
257
|
+
offsetX.value = 0;
|
|
258
|
+
offsetY.value = 0;
|
|
259
|
+
scale.value = 1;
|
|
260
|
+
};
|
|
261
|
+
</script>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createVNode, render } from 'vue';
|
|
2
|
+
import ImagePreview from './image-preview.vue';
|
|
3
|
+
|
|
4
|
+
let container = null;
|
|
5
|
+
const imagePreview = function (data, initIndex) {
|
|
6
|
+
if (container) {
|
|
7
|
+
render(null, container);
|
|
8
|
+
container = null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
container = document.createElement('div');
|
|
12
|
+
|
|
13
|
+
const vnode = createVNode(ImagePreview, {
|
|
14
|
+
data: data,
|
|
15
|
+
initIndex: initIndex,
|
|
16
|
+
onDestroy: () => {
|
|
17
|
+
render(null, container);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
render(vnode, container);
|
|
22
|
+
|
|
23
|
+
document.body.appendChild(container.firstElementChild);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default imagePreview;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createVNode, render } from 'vue';
|
|
2
|
+
import LoadingConstructor from './loading-fullscreen.vue';
|
|
3
|
+
|
|
4
|
+
const LoadingFullscreen = (function () {
|
|
5
|
+
let instance = null;
|
|
6
|
+
let count = 0;
|
|
7
|
+
|
|
8
|
+
function init() {
|
|
9
|
+
const container = document.createElement('div');
|
|
10
|
+
const vnode = createVNode(LoadingConstructor, {});
|
|
11
|
+
|
|
12
|
+
render(vnode, container);
|
|
13
|
+
document.body.appendChild(container.firstElementChild);
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
show() {
|
|
17
|
+
if (count === 0) {
|
|
18
|
+
vnode.component.exposed.show();
|
|
19
|
+
}
|
|
20
|
+
count++;
|
|
21
|
+
},
|
|
22
|
+
hide() {
|
|
23
|
+
count--;
|
|
24
|
+
if (count < 0) {
|
|
25
|
+
count = 0;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (count === 0) {
|
|
29
|
+
vnode.component.exposed.hide();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
getInstance() {
|
|
37
|
+
if (instance === null) {
|
|
38
|
+
instance = init();
|
|
39
|
+
}
|
|
40
|
+
return instance;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
|
|
45
|
+
export default LoadingFullscreen;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Transition name="fadeIn">
|
|
3
|
+
<div ref="elementRef" v-show="visible" class="loading-fullscreen text-center" tabindex="-1">
|
|
4
|
+
<div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem; margin-top: 25vh">
|
|
5
|
+
<span class="visually-hidden">Loading...</span>
|
|
6
|
+
</div>
|
|
7
|
+
</div>
|
|
8
|
+
</Transition>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script setup>
|
|
12
|
+
import { ref, shallowRef } from 'vue';
|
|
13
|
+
|
|
14
|
+
const elementRef = shallowRef(null);
|
|
15
|
+
|
|
16
|
+
const visible = ref(false);
|
|
17
|
+
|
|
18
|
+
function show() {
|
|
19
|
+
if (document.body.scrollHeight > window.innerHeight) {
|
|
20
|
+
document.body.style.cssText = `overflow: hidden; padding-right: ${window.innerWidth - document.body.clientWidth}px;`;
|
|
21
|
+
}
|
|
22
|
+
visible.value = true;
|
|
23
|
+
|
|
24
|
+
document.addEventListener('keydown', tabHandler);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function hide() {
|
|
28
|
+
if (document.body.scrollHeight > window.innerHeight) {
|
|
29
|
+
document.body.style = null;
|
|
30
|
+
}
|
|
31
|
+
visible.value = false;
|
|
32
|
+
|
|
33
|
+
document.removeEventListener('keydown', tabHandler);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const tabHandler = (e) => {
|
|
37
|
+
if (e.key === 'Tab') {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
elementRef.value.focus();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
defineExpose({
|
|
44
|
+
show,
|
|
45
|
+
hide
|
|
46
|
+
});
|
|
47
|
+
</script>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div ref="elementRef" class="position-relative" tabindex="-1">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
<Transition name="fadeIn">
|
|
5
|
+
<div
|
|
6
|
+
v-if="loading"
|
|
7
|
+
class="position-absolute top-0 start-0 w-100 h-100 text-center z-1"
|
|
8
|
+
style="background-color: rgba(255, 255, 255, 0.5)"
|
|
9
|
+
>
|
|
10
|
+
<div class="spinner-border text-primary" role="status" style="margin-top: 2rem">
|
|
11
|
+
<span class="visually-hidden">Loading...</span>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
</Transition>
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script setup>
|
|
19
|
+
import { shallowRef, watch } from 'vue';
|
|
20
|
+
|
|
21
|
+
const elementRef = shallowRef(null);
|
|
22
|
+
|
|
23
|
+
const props = defineProps({
|
|
24
|
+
loading: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
default: false
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
watch(
|
|
31
|
+
() => props.loading,
|
|
32
|
+
(newVal) => {
|
|
33
|
+
if (newVal) {
|
|
34
|
+
document.addEventListener('keydown', tabHandler);
|
|
35
|
+
} else {
|
|
36
|
+
document.removeEventListener('keydown', tabHandler);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const tabHandler = (e) => {
|
|
42
|
+
if (e.key === 'Tab') {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
elementRef.value.focus();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
</script>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :id="id" class="modal fade" tabindex="-1" :aria-labelledby="`${id}-label`" aria-hidden="true">
|
|
3
|
+
<div class="modal-dialog" :class="dialogClass">
|
|
4
|
+
<div class="modal-content">
|
|
5
|
+
<div class="modal-header">
|
|
6
|
+
<h1 class="modal-title fs-5" :id="`${id}-label`">{{ title }}</h1>
|
|
7
|
+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
8
|
+
</div>
|
|
9
|
+
<div class="modal-body">
|
|
10
|
+
<slot></slot>
|
|
11
|
+
</div>
|
|
12
|
+
<div v-if="$slots.footer" class="modal-footer">
|
|
13
|
+
<slot name="footer"></slot>
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup>
|
|
21
|
+
import { useId, onMounted, onBeforeUnmount } from 'vue';
|
|
22
|
+
import Modal from 'bootstrap/js/dist/modal';
|
|
23
|
+
|
|
24
|
+
const emit = defineEmits(['modal-shown']);
|
|
25
|
+
|
|
26
|
+
const id = useId();
|
|
27
|
+
const props = defineProps({
|
|
28
|
+
title: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: 'Modal'
|
|
31
|
+
},
|
|
32
|
+
backdrop: {
|
|
33
|
+
type: [String, Boolean],
|
|
34
|
+
default: true
|
|
35
|
+
},
|
|
36
|
+
dialogClass: {
|
|
37
|
+
type: String,
|
|
38
|
+
default: null
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
let previousFocus = null;
|
|
43
|
+
let modal = null;
|
|
44
|
+
onMounted(() => {
|
|
45
|
+
const modalEl = document.getElementById(id);
|
|
46
|
+
if (modal === null) {
|
|
47
|
+
modal = new Modal(modalEl, {
|
|
48
|
+
backdrop: props.backdrop
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
modalEl.addEventListener('show.bs.modal', (event) => {
|
|
52
|
+
previousFocus = document.activeElement;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
modalEl.addEventListener('shown.bs.modal', (event) => {
|
|
56
|
+
emit('modal-shown');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
modalEl.addEventListener('hide.bs.modal', function () {
|
|
60
|
+
if (document.activeElement && modalEl.contains(document.activeElement)) {
|
|
61
|
+
document.activeElement.blur();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
modalEl.addEventListener('hidden.bs.modal', function () {
|
|
66
|
+
previousFocus.focus();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
onBeforeUnmount(() => {
|
|
72
|
+
if (modal !== null) {
|
|
73
|
+
modal.dispose();
|
|
74
|
+
modal = null;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
defineExpose({
|
|
79
|
+
toggle: function () {
|
|
80
|
+
modal.toggle();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
</script>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// 私有变量
|
|
2
|
+
let count = 0;
|
|
3
|
+
|
|
4
|
+
// 导出公共API
|
|
5
|
+
export default {
|
|
6
|
+
increment(amount = 1) {
|
|
7
|
+
count += amount;
|
|
8
|
+
return count;
|
|
9
|
+
},
|
|
10
|
+
decrement(amount = 1) {
|
|
11
|
+
count = Math.max(0, count - amount);
|
|
12
|
+
return count;
|
|
13
|
+
},
|
|
14
|
+
reset() {
|
|
15
|
+
count = 0;
|
|
16
|
+
return 0;
|
|
17
|
+
},
|
|
18
|
+
get() {
|
|
19
|
+
return count;
|
|
20
|
+
},
|
|
21
|
+
set(value) {
|
|
22
|
+
count = Math.max(0, value);
|
|
23
|
+
return count;
|
|
24
|
+
}
|
|
25
|
+
};
|