Files

181 lines
6.0 KiB
Vue

<script>
/** 监听 Nuxt 版本清单与分块加载失败,提示用户保存表单后确认刷新,不自动打断操作。 */
import "~/assets/styles/BuildUpdateNotice.CuqdqvlF.css";
import { reloadNuxtApp as y } from "#app";
import { useNuxtApp } from "#app";
import { toDisplayString } from "vue";
import { onBeforeUnmount } from "vue";
import { ref } from "vue";
import { withCtx } from "vue";
import { createCommentVNode } from "vue";
import { isRef } from "vue";
import { createElementBlock } from "vue";
import { Fragment } from "vue";
import { createElementVNode } from "vue";
import { unref } from "vue";
import { defineComponent } from "vue";
import { createVNode } from "vue";
import { openBlock } from "vue";
import dialog from "primevue/dialog";
import button from "primevue/button";
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
var b = {
key: 0,
class: `build-notice`,
role: `status`,
"aria-live": `polite`,
},
x = {
class: `build-actions`,
},
S = Object.assign(
_plugin_vue_export_helper_t(
defineComponent({
__name: `BuildUpdateNotice`,
setup(d) {
let m = useNuxtApp(),
h = ref(!1),
v = ref(!1),
S = ref(!1),
C = ref(!1),
w = ``,
T = m.hook(`app:manifest:update`, (e) => {
(e?.id && e.id === w) || ((w = e?.id || ``), (h.value = !0));
}),
E = m.hook(`app:chunkError`, () => {
((C.value = !0), (h.value = !0));
});
onBeforeUnmount(() => {
// hook 返回取消注册函数;卸载后必须解绑,避免重复提示。
(T(), E());
});
function D() {
h.value = !1;
}
function O() {
v.value = !0;
}
function k() {
// 确认后强制完整刷新且不持久化 Nuxt 状态,避免新版本继续使用旧内存状态。
!S.value &&
v.value &&
((S.value = !0),
y({
force: !0,
persistState: !1,
}));
}
return (e, n) => {
let r = button,
d = dialog;
return (
openBlock(),
createElementBlock(
Fragment,
null,
[
unref(h)
? (openBlock(),
createElementBlock(`aside`, b, [
createElementVNode(`div`, null, [
createElementVNode(
`strong`,
null,
toDisplayString(
unref(C) ? `页面资源需要更新` : `发现新版本`,
),
1,
),
(n[2] ||= createElementVNode(
`p`,
null,
`请完成并保存当前操作后刷新页面。`,
-1,
)),
]),
createElementVNode(`div`, x, [
createVNode(r, {
label: `稍后`,
text: ``,
severity: `secondary`,
onClick: D,
}),
createVNode(r, {
label: `刷新页面`,
size: `small`,
onClick: O,
}),
]),
]))
: createCommentVNode(``, !0),
createVNode(
d,
{
visible: unref(v),
"onUpdate:visible": (n[1] ||= (e) =>
isRef(v) ? (v.value = e) : null),
header: `刷新页面`,
modal: ``,
closable: !unref(S),
draggable: !1,
style: {
width: `460px`,
maxWidth: `94vw`,
},
},
{
footer: withCtx(() => [
createVNode(
r,
{
label: `继续当前操作`,
severity: `secondary`,
disabled: unref(S),
onClick: (n[0] ||= (e) => (v.value = !1)),
},
null,
8,
[`disabled`],
),
createVNode(
r,
{
label: `确认刷新`,
loading: unref(S),
onClick: k,
},
null,
8,
[`loading`],
),
]),
default: withCtx(() => [
(n[3] ||= createElementVNode(
`p`,
null,
`刷新会清空尚未提交的表单。请确认支付、身份验证等操作已结束,且需要保留的信息已经保存。`,
-1,
)),
]),
_: 1,
},
8,
[`visible`, `closable`],
),
],
64,
)
);
};
},
}),
[[`__scopeId`, `data-v-fc2ba853`]],
),
{
__name: `BuildUpdateNotice`,
},
);
export { y as n };
export default S;
</script>