| | |
| | | </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 { getServerName } from "./api.ts"; |
| | | 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 { getDevInfo } from "@/api/login"; |
| | | import { getApps } from "@/api/app" |
| | | import { getDevInfo } from "@/api/login" |
| | | |
| | | import config from "../../../../package.json"; |
| | | import config from "../../../../package.json" |
| | | |
| | | export default { |
| | | name: "app", |
| | |
| | | NotificationCenter, |
| | | NoticeTip, |
| | | Tools, |
| | | ToolsEntry, |
| | | ToolsEntry |
| | | }, |
| | | data() { |
| | | return { |
| | | buttonAuthority: sessionStorage.getItem("buttonAuthoritys") || [], |
| | | 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"; |
| | | if (sessionStorage.getItem("userInfo") && sessionStorage.getItem("userInfo") !== "") { |
| | | let loginName = JSON.parse(sessionStorage.getItem("userInfo")).username |
| | | return loginName === "superadmin" || loginName === "basic" |
| | | } |
| | | return false; |
| | | return false |
| | | }, |
| | | defaultBgUrl() { |
| | | if (JSON.parse(sessionStorage.getItem("userInfo"))) { |
| | | return JSON.parse(sessionStorage.getItem("userInfo")).backgroundpic; |
| | | return JSON.parse(sessionStorage.getItem("userInfo")).backgroundpic |
| | | } |
| | | return ""; |
| | | }, |
| | | return "" |
| | | } |
| | | }, |
| | | created() { |
| | | this.getServerName(); |
| | | this.getDevInfo(); |
| | | this.getServerName() |
| | | this.getDevInfo() |
| | | }, |
| | | mounted() { |
| | | document.getElementById("app").style.backgroundImage = `url(${ |
| | | this.defaultBgUrl || "/images/desktop/background.png" |
| | | })`; |
| | | this.showApps(); |
| | | let _that = this; |
| | | let msgResp = require("./mock/messages.json"); |
| | | 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); |
| | | }); |
| | | _that.addMessage(item) |
| | | }) |
| | | } |
| | | let weather = require("./mock/weather.json"); |
| | | let weather = require("./mock/weather.json") |
| | | if (weather.success) { |
| | | _that.addWeather(weather.data.data); |
| | | _that.addWeather(weather.data.data) |
| | | } |
| | | setTimeout(function () { |
| | | _that.addMessage( |
| | |
| | | tip: "消息", |
| | | title: "SmartAI", |
| | | body: "V" + config.version, |
| | | time: new Date(), |
| | | time: new Date() |
| | | }, |
| | | true |
| | | ); |
| | | }, 1000); |
| | | ) |
| | | }, 1000) |
| | | window.addEventListener("message", (e) => { |
| | | if (e.data.msg == "AppUpdate") { |
| | | this.showApps(); |
| | | this.showApps() |
| | | } |
| | | if (e.data.msg == "checkSN") { |
| | | this.$refs.desktop.validateSn(); |
| | | this.$refs.desktop.validateSn() |
| | | } |
| | | if (e.data.msg === "changeColor") { |
| | | const iframeArr = document.querySelectorAll("iframe"); |
| | | const iframeArr = document.querySelectorAll("iframe") |
| | | iframeArr.forEach((item) => { |
| | | item.contentWindow.postMessage( |
| | | { msg: "changeColor", color: e.data.color }, |
| | | "*" |
| | | ); |
| | | }); |
| | | item.contentWindow.postMessage({ msg: "changeColor", color: e.data.color }, "*") |
| | | }) |
| | | } |
| | | }); |
| | | }) |
| | | }, |
| | | methods: { |
| | | quit() { |
| | | this.$refs.tools.toLogout(); |
| | | this.$refs.tools.toLogout() |
| | | }, |
| | | onJumpToDock(name) { |
| | | this.$refs.dock_model.onJumpToDock(name); |
| | | this.$refs.dock_model.onJumpToDock(name) |
| | | }, |
| | | onChangeBg(v) { |
| | | document.getElementById("app").style.backgroundImage = "url(" + v + ")"; |
| | | document.getElementById("app").style.backgroundImage = "url(" + v + ")" |
| | | }, |
| | | showApps() { |
| | | let _that = this; |
| | | let _that = this |
| | | |
| | | getApps().then((rsp) => { |
| | | if (rsp && rsp.success) { |
| | | _that.$store.state.desktop.docks = []; |
| | | let installedApps = []; |
| | | rsp.data; |
| | | _that.$store.state.desktop.docks = [] |
| | | let installedApps = [] |
| | | rsp.data |
| | | rsp.data.forEach(function (item) { |
| | | if (item.installed) { |
| | | let temp = { |
| | |
| | | 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, |
| | |
| | | url: item.url, |
| | | version: item.version, |
| | | width: item.width, |
| | | isDefault: item.isDefault, |
| | | }; |
| | | isDefault: item.isDefault |
| | | } |
| | | |
| | | // 判断权限 |
| | | if ( |
| | | _that.isAdmin || |
| | | _that.buttonAuthority.indexOf(item.package) >= 0 |
| | | ) { |
| | | _that.$store.commit("desktop/addDock", temp); |
| | | } |
| | | // if (_that.isAdmin || _that.buttonAuthority.indexOf(item.package) >= 0) { |
| | | _that.$store.commit("desktop/addDock", temp) |
| | | // } |
| | | |
| | | installedApps.push(item.package); |
| | | installedApps.push(item.package) |
| | | } |
| | | }); |
| | | |
| | | sessionStorage.setItem("apps", installedApps.join(",")); |
| | | }) |
| | | sessionStorage.setItem("apps", installedApps.join(",")) |
| | | } |
| | | }); |
| | | }) |
| | | }, |
| | | addMessage: function (message, ding) { |
| | | this.$store.dispatch("desktop/addMessage", message); |
| | | 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); |
| | | this.$store.commit("desktop/addWeather", weather) |
| | | }, |
| | | screenShot(dock) { |
| | | //找到当前的iframe |
| | | 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(); |
| | | let shotSrc = canvas.toDataURL() |
| | | // this.$store.commit('desktop/addMinDock', { |
| | | // id: dock.id, |
| | | // src: dock.icon, |
| | |
| | | // }); |
| | | this.$store.commit("desktop/shotscreen", { |
| | | id: dock.id, |
| | | src: shotSrc, |
| | | }); |
| | | src: shotSrc |
| | | }) |
| | | }) |
| | | .catch((e) => { |
| | | this.$store.commit("desktop/shotscreen", { id: dock.id, src: "" }); |
| | | }); |
| | | this.$store.commit("desktop/shotscreen", { id: dock.id, src: "" }) |
| | | }) |
| | | }, |
| | | async getServerName() { |
| | | let res = await 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); |
| | | 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(); |
| | | const res = await getDevInfo() |
| | | if (res && res.success && res.data.deviceType.substr(0, 2) === "DS") { |
| | | sessionStorage.setItem("isShowPolling", "show"); |
| | | sessionStorage.setItem("isShowPolling", "show") |
| | | } |
| | | }, |
| | | }, |
| | | }; |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style> |