Browse Source

唤起提醒

1
mo 1 year ago
parent
commit
1bb4b8ceb0
3 changed files with 42 additions and 6 deletions
  1. 1 1
      dev-dist/sw.js
  2. 39 3
      src/views/login/index.tsx
  3. 2 2
      vite.config.ts

+ 1 - 1
dev-dist/sw.js

@@ -82,7 +82,7 @@ define(['./workbox-5357ef54'], (function (workbox) { 'use strict';
     "revision": "3ca0b8505b4bec776b69afdba2768812"
   }, {
     "url": "index.html",
-    "revision": "0.j9uk7h7ksmg"
+    "revision": "0.2s59qd9m0j8"
   }], {});
   workbox.cleanupOutdatedCaches();
   workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {

+ 39 - 3
src/views/login/index.tsx

@@ -35,6 +35,40 @@ export default defineComponent({
 
       // }, 2000)
 
+
+      if (window.matchMedia('(display-mode: standalone)').matches) {
+        console.log('应用内打开')
+      }else{
+        console.log(popEvent.value,'popEvent.value')
+        if(popEvent.value){
+        showModalMask.value = true;
+        setTimeout(()=>{
+          const btn = document.querySelector('#submitBtn')
+          console.log(btn)
+          if(btn){
+            btn.addEventListener('click', () => {
+              console.log(popEvent.value )
+              if( !popEvent.value ) {
+                return;
+              }
+
+              popEvent.value.prompt();
+              popEvent.value.userChoice.then( (choiceResult:any) => {
+                if (choiceResult.outcome === 'accepted') {
+                  console.log('用户已同意添加到桌面')
+                  showModalMask.value = false;
+                } else {
+                  console.log('用户已取消添加到桌面')
+                  showModalMask.value = false;
+                }
+              })
+            })
+          }
+        },500)
+
+      }
+      }
+
     }
 
 
@@ -46,9 +80,9 @@ export default defineComponent({
 
     onMounted(async () => {
       const relatedApps = await navigator.getInstalledRelatedApps();
-      console.log(relatedApps,'navigator.getInstalledRelatedApps()')
+      console.log(relatedApps)
 
-      //     showModalMask.value = true;
+      //
 
     })
 
@@ -119,10 +153,12 @@ export default defineComponent({
             {/* <NButton>确定</NButton> */}
             <NSpace style={{ padding: '20px 0 0 0' }} justify="center">
           <NButton
+          {...{id
+          :'submitBtn'}}
             class={styles.submitAppBtn}
             round
             type="primary"
-            // onClick={() => onSubmit()}
+
             >
             确定
           </NButton>

+ 2 - 2
vite.config.ts

@@ -83,12 +83,12 @@ export default defineConfig({
             purpose: 'any maskable'
           }
         ],
-        prefer_related_applications: true,
+        prefer_related_applications: false,
         related_applications: [
           {
             platform: 'webapp',
             id: 'yyszkt',
-            url: 'https://test.lexiaoya.cn/classroom/manifest.webmanifest'
+            url: './manifest.webmanifest'
           }
         ]
       },