1
0
mirror of https://github.com/ZeroCatDev/Classworks.git synced 2026-03-21 09:13:10 +00:00
Classworks/assets/PwaInstallCard-uU1hg_zK.js

2 lines
7.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{D as K,A as O,X as f,Y as y,Z as e,k as _,j as t,a1 as l,_ as I,F as M,a2 as L,S as d,a8 as Q,$ as ee,b as C,e as q,r as A}from"./vendor-vue-B2vxubPy.js";import{c as D,E as te,d as E,l as B,n as R,o as T,p as W,i as h,M as U,f as j,q as F,k as ae,e as X,r as se,g as ne,s as ie,aC as oe,aD as le}from"./index-CFUCTEXJ.js";import{V as re}from"./VChip-DR8Ljy6R.js";import"./vendor-vuetify-s-yw_Hr8.js";const de={class:"d-flex flex-no-wrap justify-space-between"},ue={class:"pe-4"},ce={class:"mb-3"},we={__name:"PwaInstallCard",setup(pe){const g=C(!1),o=C(!1),m=C(!1),r=A({title:"",message:"",links:[]}),$={pending:"待授权",granted:"已完成",denied:"已拒绝",unavailable:"不可用"},G={pending:"mdi-progress-clock",granted:"mdi-check-circle",denied:"mdi-close-circle",unavailable:"mdi-help-circle"},k={pending:"primary",granted:"success",denied:"error",unavailable:"surface-variant"},n=A({pwa:{label:"安装应用",description:"将网站安装为独立应用,便于快速启动",status:"pending"},notification:{label:"通知权限",description:"允许接收作业、考试等通知提醒",status:"pending"},storage:{label:"离线存储",description:"启用持久化存储以获得更稳健的离线体验",status:"pending"}}),b=q(()=>[{key:"pwa",...n.pwa},{key:"notification",...n.notification},{key:"storage",...n.storage}]),V=q(()=>b.value.some(a=>a.status==="pending")),H={pwa:[{text:"MDN - 安装 PWA 指南",desc:"检查浏览器是否支持并手动触发安装",href:"https://developer.mozilla.org/zh-CN/docs/Web/Progressive_web_apps/Guides/Installing"},{text:"Microsoft Edge - PWA 体验",desc:"Edge 浏览器安装与 UX 说明",href:"https://learn.microsoft.com/zh-cn/microsoft-edge/progressive-web-apps/ux"}],notification:[{text:"MDN - 通知权限与用法",desc:"浏览器通知权限的工作方式与调试",href:"https://developer.mozilla.org/zh-CN/docs/Web/API/notification"}],storage:[{text:"MDN - Storage 持久化说明",desc:"了解持久化存储的可用性与申请方式",href:"https://developer.mozilla.org/zh-CN/docs/Web/API/StorageManager/persist"}]};let v;const p=async()=>{var w;if(ne("pwa.hideInstallCard")){g.value=!1;return}if(window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone===!0?n.pwa.status="granted":(window.deferredPwaPrompt,n.pwa.status="pending"),typeof Notification>"u")n.notification.status="unavailable";else{const c=Notification.permission;n.notification.status=c==="granted"?"granted":c==="denied"?"denied":"pending"}if((w=navigator.storage)!=null&&w.persisted){const c=await navigator.storage.persisted();n.storage.status=c?"granted":"pending"}else n.storage.status="unavailable";const i=b.value.some(c=>c.status!=="granted");g.value=i},x=async()=>{const a=window.deferredPwaPrompt;if(!a){n.pwa.status="pending",u("pwa","浏览器没有提供安装提示,可按文档手动安装。");return}a.prompt();const{outcome:s}=await a.userChoice;n.pwa.status=s==="accepted"?"granted":"denied",s!=="accepted"&&u("pwa","如果未出现安装弹窗,或被拒绝,请按说明手动安装。"),window.deferredPwaPrompt=null},P=async()=>{if(typeof Notification>"u"){n.notification.status="unavailable",u("notification","当前环境不支持通知 API可查看说明手动开启或更换浏览器。");return}const a=await oe();n.notification.status=a?"granted":"denied",a||u("notification","通知请求未被授予,请按说明检查浏览器或系统设置。")},N=async()=>{var s;if(!((s=navigator.storage)!=null&&s.persist)){n.storage.status="unavailable",u("storage","当前浏览器不支持持久化存储,可查看说明或更换浏览器。");return}const a=await le();n.storage.status=a?"granted":"denied",a||u("storage","未能启用持久化存储,可按说明检查浏览器或系统设置。")},Y=async()=>{if(!(!V.value||o.value)){o.value=!0;try{await x(),await P(),await N()}finally{o.value=!1,await p()}}},Z=async a=>{if(!o.value){o.value=!0;try{a==="pwa"?await x():a==="notification"?await P():a==="storage"&&await N()}finally{o.value=!1,await p()}}},u=(a,s="")=>{a==="pwa"?r.title="如何安装为应用":a==="notification"?r.title="如何开启通知":r.title="如何启用离线存储",r.message=s||"查看以下步骤获取更多说明。",r.links=H[a]||[],m.value=!0},J=()=>{ie("pwa.hideInstallCard",!0),g.value=!1},S=()=>{n.pwa.status!=="granted"&&(n.pwa.status="pending"),p()},z=()=>{p()};return K(()=>{p(),window.addEventListener("pwa-prompt-ready",S),v=window.matchMedia("(display-mode: standalone)"),v.addEventListener("change",z)}),O(()=>{window.removeEventListener("pwa-prompt-ready",S),v&&v.removeEventListener("change",z)}),(a,s)=>g.value?(f(),y(X,{key:0,class:"mb-4",color:"surface-variant",variant:"tonal"},{default:e(()=>[_("div",de,[_("div",ue,[t(D,{class:"text-h6"},{default:e(()=>[...s[2]||(s[2]=[l(" 安装应用与授权 ",-1)])]),_:1}),t(te,{class:"pb-1"},{default:e(()=>[...s[3]||(s[3]=[l(" 手动点选下方项目请求安装和权限,也可以直接关闭 ",-1)])]),_:1}),t(E,{class:"pt-0 pb-1"},{default:e(()=>[t(B,{density:"comfortable",lines:"two"},{default:e(()=>[(f(!0),I(M,null,L(b.value,i=>(f(),y(R,{key:i.key,disabled:o.value,onClick:()=>Z(i.key)},{prepend:e(()=>[t(U,{color:k[i.status],size:"32",variant:"tonal"},{default:e(()=>[t(j,{icon:G[i.status]},null,8,["icon"])]),_:2},1032,["color"])]),append:e(()=>[t(re,{color:k[i.status],size:"small",variant:"tonal",class:"me-2"},{default:e(()=>[l(d($[i.status]),1)]),_:2},1032,["color"]),t(h,{variant:"text",icon:"mdi-information",size:"small",disabled:o.value,onClick:Q(()=>u(i.key),["stop"])},null,8,["disabled","onClick"])]),default:e(()=>[t(T,null,{default:e(()=>[l(d(i.label),1)]),_:2},1024),t(W,null,{default:e(()=>[l(d(i.description),1)]),_:2},1024)]),_:2},1032,["disabled","onClick"]))),128))]),_:1})]),_:1}),t(F,null,{default:e(()=>[t(h,{class:"ms-2",variant:"outlined",size:"small",onClick:J},{default:e(()=>[...s[4]||(s[4]=[l(" 关闭 ",-1)])]),_:1}),t(h,{class:"ms-2",variant:"elevated",color:"primary",size:"small","prepend-icon":o.value?"mdi-timer-sand":"mdi-shield-check",disabled:!V.value||o.value,onClick:Y},{default:e(()=>[l(d(o.value?"处理中":"一次处理全部"),1)]),_:1},8,["prepend-icon","disabled"])]),_:1})]),t(U,{class:"ma-3",size:"100",rounded:"0"},{default:e(()=>[t(j,{icon:"mdi-monitor-cellphone",size:"80"})]),_:1})]),t(ae,{modelValue:m.value,"onUpdate:modelValue":s[1]||(s[1]=i=>m.value=i),"max-width":"520"},{default:e(()=>[t(X,null,{default:e(()=>[t(D,{class:"text-h6"},{default:e(()=>[l(d(r.title),1)]),_:1}),t(E,null,{default:e(()=>[_("p",ce,d(r.message),1),t(B,{density:"comfortable"},{default:e(()=>[(f(!0),I(M,null,L(r.links,(i,w)=>(f(),y(R,{key:w,href:i.href,target:"_blank",rel:"noopener"},{default:e(()=>[t(T,null,{default:e(()=>[l(d(i.text),1)]),_:2},1024),t(W,null,{default:e(()=>[l(d(i.desc),1)]),_:2},1024)]),_:2},1032,["href"]))),128))]),_:1})]),_:1}),t(F,null,{default:e(()=>[t(se),t(h,{variant:"text",onClick:s[0]||(s[0]=i=>m.value=!1)},{default:e(()=>[...s[5]||(s[5]=[l("我知道了",-1)])]),_:1})]),_:1})]),_:1})]),_:1},8,["modelValue"])]),_:1})):ee("",!0)}};export{we as default};