Explorar el Código

添加当前设别判断

zhujindu hace 1 año
padre
commit
4db071a587
Se han modificado 1 ficheros con 29 adiciones y 21 borrados
  1. 29 21
      src/App.vue

+ 29 - 21
src/App.vue

@@ -1,36 +1,44 @@
 <template>
   <div id="app" class="bgcolor">
-    <router-view/>
+    <router-view />
   </div>
 </template>
 <script>
-import watermark from 'watermark-dom'
+import watermark from "watermark-dom";
 
 export default {
   name: "App",
-  mounted(){
-    setTimeout(()=>{
+  created() {
+    // 是否为移动端
+    let isMobile = window.navigator.userAgent.match(
+      /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
+    );
+    localStorage.setItem("isMobile", !!isMobile);
+  },
+  mounted() {
+    setTimeout(() => {
       let username = localStorage.getItem("nickName");
-      if(username){
+      if (username) {
         let now = new Date();
         let year = now.getFullYear();
-        let month = now.getMonth()+1;
+        let month = now.getMonth() + 1;
         let day = now.getDate();
-        month = month<10?'0'+month:month;
-        day = day<10?'0'+day:day;
-        let date = year+'-'+month+'-'+day;
+        month = month < 10 ? "0" + month : month;
+        day = day < 10 ? "0" + day : day;
+        let date = year + "-" + month + "-" + day;
         watermark.load({
-          watermark_txt: username+'@立邦'+date,watermark_fontsize:'13px',
-          watermark_width:100,
-          watermark_rows:0,
-          watermark_cols:3,
-          watermark_height:50,
-          watermark_x_space:10,
-          watermark_y_space:60,
-          watermark_alpha:0.1,
-        })
+          watermark_txt: username + "@立邦" + date,
+          watermark_fontsize: "13px",
+          watermark_width: 100,
+          watermark_rows: 0,
+          watermark_cols: 3,
+          watermark_height: 50,
+          watermark_x_space: 10,
+          watermark_y_space: 60,
+          watermark_alpha: 0.1,
+        });
       }
-    },1000)
-  }
+    }, 1000);
+  },
 };
-</script>
+</script>