From 878ce80ef3ca88a2c108fbc713cd6ea461c44de1 Mon Sep 17 00:00:00 2001
From: ZZJ <zzjdsg2300@163.com>
Date: 星期三, 13 十月 2021 13:51:03 +0800
Subject: [PATCH] 拓扑图

---
 src/pages/desktop/index/App.vue |  129 +++++++++++++++++++++++++++++++++++-------
 1 files changed, 107 insertions(+), 22 deletions(-)

diff --git a/src/pages/desktop/index/App.vue b/src/pages/desktop/index/App.vue
index a89ad1d..08d5c56 100644
--- a/src/pages/desktop/index/App.vue
+++ b/src/pages/desktop/index/App.vue
@@ -1,8 +1,8 @@
 <template>
-  <div id="app" @contextmenu.prevent="">
-    <tools></tools>
-    <desktop></desktop>
-    <tools-entry ref="dock_model"></tools-entry>
+  <div id="app" @contextmenu.prevent>
+    <tools @jumpToDock="onJumpToDock"></tools>
+    <desktop ref="desktop"></desktop>
+    <tools-entry @changeBackground="onChangeBg" ref="dock_model"></tools-entry>
     <notice-tip ref="notice_tip_model"></notice-tip>
     <notification-center></notification-center>
   </div>
@@ -15,31 +15,48 @@
 import NoticeTip from './components/NoticeTip';
 import Tools from './components/Tools';
 import ToolsEntry from './components/ToolsEntry';
-import axios from 'axios'
+
+import { getApps } from '@/api/app'
+
+import config from '../../../../package.json'
 
 export default {
   name: 'app',
   components: {
     Desktop, NotificationCenter, NoticeTip, Tools, ToolsEntry
   },
-  
-  mounted() {
-    document.getElementById('app').style.backgroundImage = process.env.VUE_APP_MAIN_URL;
-    let _that = this;
-    let user_res = require("./mock/userData.json")
-    if (user_res.success) {
-      user_res.data.docks.forEach(function (item) {
-        _that.$store.commit('desktop/addDock', item);
-      });
+  data() {
+    return {
+      buttonAuthority: sessionStorage.getItem('buttonAuthoritys') || [],
+      defaultBgUrl:"/images/desktop/background.png"
     }
-
+  },
+  computed: {
+    isAdmin() {
+      if (
+        sessionStorage.getItem('userInfo') &&
+        sessionStorage.getItem('userInfo') !== ''
+      ) {
+        let loginName = JSON.parse(sessionStorage.getItem('userInfo')).username
+        return (
+          loginName === 'superadmin' || loginName === 'basic'
+        )
+      }
+      return false
+    }
+  },
+  mounted() {
+    // document.getElementById('app').style.backgroundImage = process.env.VUE_APP_MAIN_URL;
+    const url = localStorage.getItem("backgroundPic")
+    document.getElementById('app').style.backgroundImage = `url(${url||this.defaultBgUrl})`
+    this.showApps();
+    let _that = this;
     let msgResp = require("./mock/messages.json")
     if (msgResp.success) {
       msgResp.data.forEach(function (item) {
         _that.addMessage(item);
       })
     }
-
     let weather = require("./mock/weather.json")
     if (weather.success) {
       _that.addWeather(weather.data.data);
@@ -49,13 +66,81 @@
         id: 'N2',
         icon: '/images/desktop/message.png',
         tip: '娑堟伅',
-        title: 'SmartAi',
-        body: 'v1.0.0',
+        title: 'SmartAI',
+        body: 'V' + config.version,
         time: new Date()
       }, true);
     }, 1000);
+    window.addEventListener('message', (e) => {
+      if (e.data.msg == 'AppUpdate') {
+        this.showApps();
+      }
+      if (e.data.msg=='checkSN') {
+        debugger
+        this.$refs.desktop.validateSn()
+      }
+      if (e.data.msg === 'changeColor') {
+        const iframeArr = document.querySelectorAll("iframe")
+        iframeArr.forEach(item=>{
+          item.contentWindow.postMessage({msg:'changeColor',color:e.data.color},"*")
+        })
+      }
+    });
   },
   methods: {
+    onJumpToDock(name){
+      this.$refs.dock_model.onJumpToDock(name)
+    },
+    onChangeBg(v){
+       document.getElementById('app').style.backgroundImage = "url(" + v + ")"
+       this.defaultBgUrl = v
+      localStorage.setItem("backgroundPic", v)
+    },
+    showApps() {
+      let _that = this;
+
+      getApps().then(rsp => {
+        if (rsp && rsp.success) {
+          _that.$store.state.desktop.docks = [];
+          let installedApps = [];
+          rsp.data
+          rsp.data.forEach(function (item) {
+            if (item.installed) {
+              let temp = {
+                id: item.id,
+                create_by: item.create_by,
+                create_time: item.create_time,
+                height: item.height,
+                icon: item.icon,
+                src: item.iconBlob ? 'data:image/png;base64,' + item.iconBlob : item.icon,
+                installed: item.installed,
+                isDelete: item.isDelete,
+                isUpgrade: item.isUpgrade,
+                title: item.title,
+                name: item.package,
+                remoteVersion: item.remoteVersion,
+                type: item.type,
+                update_by: item.update_by,
+                update_time: item.update_time,
+                url: item.url,
+                version: item.version,
+                width: item.width,
+                isDefault: item.isDefault
+              }
+
+              // 鍒ゆ柇鏉冮檺
+              if (_that.isAdmin || _that.buttonAuthority.indexOf(item.package) >= 0) {
+                _that.$store.commit('desktop/addDock', temp);
+              }
+
+              installedApps.push(item.package);
+            }
+          });
+
+          sessionStorage.setItem("apps", installedApps.join(","));
+        }
+      })
+    },
     addMessage: function (message, ding) {
       this.$store.dispatch('desktop/addMessage', message);
       // if (ding) {
@@ -66,7 +151,7 @@
     addWeather: function (weather) {
       this.$store.commit('desktop/addWeather', weather);
     },
-    screenShot(dock){
+    screenShot(dock) {
       //鎵惧埌褰撳墠鐨刬frame
       let curIframe = Array.from(document.querySelectorAll('iframe')).find(iframe => iframe.src.indexOf(dock.url) >= 0);
       //淇濆瓨褰撳墠搴旂敤蹇収
@@ -86,10 +171,10 @@
         //   type: "3",
         //   screenshot: shotSrc
         // });
-        this.$store.commit('desktop/shotscreen', {id:dock.id, src:shotSrc});
-        
+        this.$store.commit('desktop/shotscreen', { id: dock.id, src: shotSrc });
+
       }).catch(e => {
-        this.$store.commit('desktop/shotscreen', {id:dock.id, src:''});
+        this.$store.commit('desktop/shotscreen', { id: dock.id, src: '' });
       });
     }
   }

--
Gitblit v1.8.0