From c0c034b3ef0fdf0fd9c802d5984dbd717db6817a Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期三, 06 九月 2023 17:54:55 +0800
Subject: [PATCH] 定制桌面.

---
 src/pages/desktop/index/App.vue |  220 ++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 145 insertions(+), 75 deletions(-)

diff --git a/src/pages/desktop/index/App.vue b/src/pages/desktop/index/App.vue
index 78897be..84e9b57 100644
--- a/src/pages/desktop/index/App.vue
+++ b/src/pages/desktop/index/App.vue
@@ -1,83 +1,131 @@
 <template>
   <div id="app" @contextmenu.prevent>
-    <tools></tools>
-    <desktop></desktop>
-    <tools-entry ref="dock_model"></tools-entry>
+    <tools ref="tools" @jumpToDock="onJumpToDock"></tools>
+    <desktop @quit="quit" 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>
 </template>
 
 <script>
-import html2canvas from 'html2canvas';
-import Desktop from './components/Desktop';
-import NotificationCenter from './components/NotificationCenter';
-import NoticeTip from './components/NoticeTip';
-import Tools from './components/Tools';
-import ToolsEntry from './components/ToolsEntry';
-import axios from 'axios'
+import html2canvas from "html2canvas"
+import Desktop from "./components/Desktop"
+import NotificationCenter from "./components/NotificationCenter"
+import NoticeTip from "./components/NoticeTip"
+import Tools from "./components/Tools"
+import ToolsEntry from "./components/ToolsEntry"
+import { getServerName } from "./api.ts"
 
-import { getApps } from '@/api/app'
-import { findAllSdk } from '@/api/taskMange'
+import { getApps } from "@/api/app"
+import { getDevInfo } from "@/api/login"
+
+import config from "../../../../package.json"
 
 export default {
-  name: 'app',
+  name: "app",
   components: {
-    Desktop, NotificationCenter, NoticeTip, Tools, ToolsEntry
+    Desktop,
+    NotificationCenter,
+    NoticeTip,
+    Tools,
+    ToolsEntry
   },
-
+  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
+    },
+    defaultBgUrl() {
+      if (JSON.parse(sessionStorage.getItem("userInfo"))) {
+        return JSON.parse(sessionStorage.getItem("userInfo")).backgroundpic
+      }
+      return ""
+    }
+  },
+  created() {
+    this.getServerName()
+    this.getDevInfo()
+  },
   mounted() {
-    document.getElementById('app').style.backgroundImage = process.env.VUE_APP_MAIN_URL;
-    this.showApps();
-
-    let _that = this;
+    document.getElementById("app").style.backgroundImage = `url(${this.defaultBgUrl ||
+      "/images/desktop/background.png"})`
+    this.showApps()
+    let _that = this
     let msgResp = require("./mock/messages.json")
     if (msgResp.success) {
-      msgResp.data.forEach(function (item) {
-        _that.addMessage(item);
+      msgResp.data.forEach(function(item) {
+        _that.addMessage(item)
       })
     }
-
     let weather = require("./mock/weather.json")
     if (weather.success) {
-      _that.addWeather(weather.data.data);
+      _that.addWeather(weather.data.data)
     }
-    setTimeout(function () {
-      _that.addMessage({
-        id: 'N2',
-        icon: '/images/desktop/message.png',
-        tip: '娑堟伅',
-        title: 'SmartAi',
-        body: 'v1.0.0',
-        time: new Date()
-      }, true);
-    }, 1000);
-    window.addEventListener('message',(e) => {
-      if(e.data.msg == 'AppUpdate'){
-        console.log('搴旂敤鏇存柊')
-        this.showApps();
+    setTimeout(function() {
+      _that.addMessage(
+        {
+          id: "N2",
+          icon: "/images/desktop/message.png",
+          tip: "娑堟伅",
+          title: "SmartAI",
+          body: "V" + config.version,
+          time: new Date()
+        },
+        true
+      )
+    }, 1000)
+    window.addEventListener("message", (e) => {
+      if (e.data.msg == "AppUpdate") {
+        this.showApps()
       }
-    });
-    findAllSdk().then(() => {
-
-    });
+      if (e.data.msg == "checkSN") {
+        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: {
+    quit() {
+      this.$refs.tools.toLogout()
+    },
+    onJumpToDock(name) {
+      this.$refs.dock_model.onJumpToDock(name)
+    },
+    onChangeBg(v) {
+      document.getElementById("app").style.backgroundImage = "url(" + v + ")"
+    },
     showApps() {
-      let _that = this;
+      let _that = this
 
-      getApps().then(rsp => {
+      getApps().then((rsp) => {
         if (rsp && rsp.success) {
-          _that.$store.state.desktop.docks = [];
-          rsp.data.forEach(function (item) {
-            if(item.installed){
+          _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,
+                src: item.iconBlob ? "data:image/png;base64," + item.iconBlob : item.icon,
                 installed: item.installed,
                 isDelete: item.isDelete,
                 isUpgrade: item.isUpgrade,
@@ -92,52 +140,74 @@
                 width: item.width,
                 isDefault: item.isDefault
               }
-              
-              _that.$store.commit('desktop/addDock', temp);
-              console.log(item)
-              console.log('apps update')
-              //console.log(this.$store.state.desktop.docks)
+
+              // 鍒ゆ柇鏉冮檺
+              // 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);
+    addMessage: function(message, ding) {
+      this.$store.dispatch("desktop/addMessage", message)
       // if (ding) {
       //   new Audio('sounds/ping.mp3').play();
       // }
-      this.$refs.notice_tip_model.showTip(message);
+      this.$refs.notice_tip_model.showTip(message)
     },
-    addWeather: function (weather) {
-      this.$store.commit('desktop/addWeather', weather);
+    addWeather: function(weather) {
+      this.$store.commit("desktop/addWeather", weather)
     },
     screenShot(dock) {
       //鎵惧埌褰撳墠鐨刬frame
-      let curIframe = Array.from(document.querySelectorAll('iframe')).find(iframe => iframe.src.indexOf(dock.url) >= 0);
+      let curIframe = Array.from(document.querySelectorAll("iframe")).find(
+        (iframe) => iframe.src.indexOf(dock.url) >= 0
+      )
       //淇濆瓨褰撳墠搴旂敤蹇収
       html2canvas(curIframe.contentWindow.document.body, {
         dpi: window.devicePixelRatio * 4,
         logging: true, //鏌ョ湅html2canvas鍐呴儴鎵ц娴佺▼
         removeContainer: true,
         imageTimeout: 0,
-        useCORS: true, //寮�鍚法鍩熼厤缃�
+        useCORS: true //寮�鍚法鍩熼厤缃�
         //allowTaint: true
-      }).then(canvas => {
-        let shotSrc = canvas.toDataURL();
-        // this.$store.commit('desktop/addMinDock', {
-        //   id: dock.id,
-        //   src: dock.icon,
-        //   alt: dock.title,
-        //   type: "3",
-        //   screenshot: shotSrc
-        // });
-        this.$store.commit('desktop/shotscreen', { id: dock.id, src: shotSrc });
-
-      }).catch(e => {
-        this.$store.commit('desktop/shotscreen', { id: dock.id, src: '' });
-      });
+      })
+        .then((canvas) => {
+          let shotSrc = canvas.toDataURL()
+          // this.$store.commit('desktop/addMinDock', {
+          //   id: dock.id,
+          //   src: dock.icon,
+          //   alt: dock.title,
+          //   type: "3",
+          //   screenshot: shotSrc
+          // });
+          this.$store.commit("desktop/shotscreen", {
+            id: dock.id,
+            src: shotSrc
+          })
+        })
+        .catch((e) => {
+          this.$store.commit("desktop/shotscreen", { id: dock.id, src: "" })
+        })
+    },
+    async getServerName() {
+      let res = await getServerName()
+      if (res && res.success) {
+        this.serverTitle = res.data.serverName
+        window.document.title = res.data.serverName ? res.data.serverName : "SmartAI"
+        sessionStorage.setItem("title", res.data.serverName)
+      }
+    },
+    async getDevInfo() {
+      const res = await getDevInfo()
+      if (res && res.success && res.data.deviceType.substr(0, 2) === "DS") {
+        sessionStorage.setItem("isShowPolling", "show")
+      }
     }
   }
 }

--
Gitblit v1.8.0