From 84792fd1dc21cd0e70c1e07bf429ba203736b263 Mon Sep 17 00:00:00 2001 From: Shao Huan Qing Date: Wed, 2 Jun 2021 21:52:53 +0800 Subject: [PATCH] window --- .vuepress/enhanceApp.js | 26 ++++++++++- .vuepress/login-manager.js | 35 -------------- .vuepress/theme/components/OnlineChat.vue | 46 +++++++++++-------- .../theme/components/OnlineChatLogin.vue | 2 +- 4 files changed, 53 insertions(+), 56 deletions(-) delete mode 100644 .vuepress/login-manager.js diff --git a/.vuepress/enhanceApp.js b/.vuepress/enhanceApp.js index 41c5c7b..a674056 100644 --- a/.vuepress/enhanceApp.js +++ b/.vuepress/enhanceApp.js @@ -13,9 +13,9 @@ import Container from './grid/Container' import Grid from './grid/Grid' import GridItem from './grid/GridItem' import defaults from './grid/utils/defaults' -import './login-manager.js' import Comp from './comp/index' +import Cookies from 'js-cookie' const VueFractionGrid = { install (Vue, options) { @@ -88,6 +88,30 @@ export default ({ duration: 1200 }); }, 200) + + let TOKEN_KEY = 'kb-user-center-token' + + let domain = window.location.hostname + if (domain.indexOf('kuboard.cn') >= 0) { + domain = 'kuboard.cn' + } + window.KbUcloginStatus = { + status: Cookies.get(TOKEN_KEY) !== null && Cookies.get(TOKEN_KEY) !== undefined, + user: undefined + } + Vue.prototype.$login = function (token) { + // axios.defaults.headers.common['Authorization'] = token; + // localStorage.setItem(TOKEN_KEY, token) + Cookies.set(TOKEN_KEY, token, { domain: domain, expires: 7, path: '/' }) + window.KbUcloginStatus.status = true + } + + Vue.prototype.$logout = function () { + window.KbUcloginStatus.status = false + // localStorage.removeItem(TOKEN_KEY) + Cookies.remove(TOKEN_KEY, { domain: domain, expires: 7, path: '/' }) + // delete (axios.defaults.headers.common['Authorization']) + } } // console.log('sharing', sharing) Vue.prototype.$isSharing = sharing diff --git a/.vuepress/login-manager.js b/.vuepress/login-manager.js deleted file mode 100644 index dbc84e9..0000000 --- a/.vuepress/login-manager.js +++ /dev/null @@ -1,35 +0,0 @@ -import Vue from 'vue' -import Cookies from 'js-cookie' - -let TOKEN_KEY = 'kb-user-center-token' - -let domain = '' -if (typeof window !== 'undefined') { - domain = window.location.hostname - window.KbUcloginStatus = { - status: Cookies.get(TOKEN_KEY) !== null && Cookies.get(TOKEN_KEY) !== undefined, - user: undefined - } -} -if (domain.indexOf('kuboard.cn') >= 0) { - domain = 'kuboard.cn' -} - - -Vue.prototype.$login = function (token) { - // axios.defaults.headers.common['Authorization'] = token; - // localStorage.setItem(TOKEN_KEY, token) - Cookies.set(TOKEN_KEY, token, { domain: domain, expires: 7, path: '/' }) - if (typeof window !== 'undefined') { - window.KbUcloginStatus.status = true - } -} - -Vue.prototype.$logout = function () { - if (typeof window !== 'undefined') { - window.KbUcloginStatus.status = false - } - // localStorage.removeItem(TOKEN_KEY) - Cookies.remove(TOKEN_KEY, { domain: domain, expires: 7, path: '/' }) - // delete (axios.defaults.headers.common['Authorization']) -} diff --git a/.vuepress/theme/components/OnlineChat.vue b/.vuepress/theme/components/OnlineChat.vue index 368b9f2..f84c30d 100644 --- a/.vuepress/theme/components/OnlineChat.vue +++ b/.vuepress/theme/components/OnlineChat.vue @@ -15,37 +15,45 @@ import axios from 'axios' import {format} from 'date-fns' import Cookies from 'js-cookie' -(function(a, b, c, d, e, j, s) { - a[d] = a[d] || function() { - (a[d].a = a[d].a || []).push(arguments) - }; - j = b.createElement(c), - s = b.getElementsByTagName(c)[0]; - j.async = true; - j.charset = 'UTF-8'; - j.src = 'https://static.meiqia.com/widget/loader.js'; - s.parentNode.insertBefore(j, s); -})(window, document, 'script', '_MEIQIA'); -_MEIQIA('entId', '961dff7f89ddc015ac1f8e193bf774d0'); -_MEIQIA('manualInit'); -_MEIQIA('withoutBtn'); - let TOKEN_KEY = 'kb-user-center-token' export default { props: { }, data() { - console.log(window.location.search, 'search') - return { - showLogout: false, - isdebugging: window.location.search === '?showLogin=true' + if (typeof window !== 'undefined') { + console.log(window.location.search, 'search') + return { + showLogout: false, + isdebugging: window.location.search === '?showLogin=true' + } + } else { + return { + showLogout: false, + isdebugging: false + } } }, computed: { }, components: { OnlineChatLogin }, mounted () { + if (typeof window !== 'undefined') { + (function(a, b, c, d, e, j, s) { + a[d] = a[d] || function() { + (a[d].a = a[d].a || []).push(arguments) + }; + j = b.createElement(c), + s = b.getElementsByTagName(c)[0]; + j.async = true; + j.charset = 'UTF-8'; + j.src = 'https://static.meiqia.com/widget/loader.js'; + s.parentNode.insertBefore(j, s); + })(window, document, 'script', '_MEIQIA'); + _MEIQIA('entId', '961dff7f89ddc015ac1f8e193bf774d0'); + _MEIQIA('manualInit'); + _MEIQIA('withoutBtn'); + } }, methods: { showChat () { diff --git a/.vuepress/theme/components/OnlineChatLogin.vue b/.vuepress/theme/components/OnlineChatLogin.vue index 55d50a2..23cc36f 100644 --- a/.vuepress/theme/components/OnlineChatLogin.vue +++ b/.vuepress/theme/components/OnlineChatLogin.vue @@ -170,7 +170,7 @@ export default { this.$login(resp.data.data) this.loginLoading = false console.log(this.goStandAlone) - if (this.goStandAlone) { + if (this.goStandAlone && typeof window !== 'undefined') { window.location.href = '/chat/' } else { this.$emit('loginSuccess')