退出登录

This commit is contained in:
luyuan 2020-11-24 15:54:51 +08:00
parent 817e7b9041
commit 7ac5c7c7a8
Signed by: theluyuan
GPG Key ID: A7972FD973317FF3
3 changed files with 73 additions and 55 deletions

View File

@ -1,75 +1,87 @@
<template> <template>
<!-- <div id="nav"> <!-- <div id="nav">
<router-link to="/">Home</router-link> | <router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link> <router-link to="/about">About</router-link>
</div> --> </div> -->
<a-config-provider :locale="len.$s() == 'zh' ? zh : en"> <a-config-provider :locale="len.$s() == 'zh' ? zh : en">
<router-view/> <router-view />
</a-config-provider> </a-config-provider>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from "vue";
import router from './router'; import router from "./router";
import store from './store'; import store from "./store";
import { getValue } from './utils/common'; import { getValue } from "./utils/common";
import { provideI18n } from "@/utils/i18n" import { provideI18n } from "@/utils/i18n";
import i18ninit from "@/i18n/init" import i18ninit from "@/i18n/init";
import enUS from 'ant-design-vue/es/locale/en_US'; import enUS from "ant-design-vue/es/locale/en_US";
import zhCN from 'ant-design-vue/es/locale/zh_CN'; import zhCN from "ant-design-vue/es/locale/zh_CN";
import dayjs, { locale } from 'dayjs'; import dayjs, { locale } from "dayjs";
import { getaddr } from './api'; import { getaddr } from "./api";
import { useRoute } from 'vue-router'; import { useRoute } from "vue-router";
export default defineComponent({ export default defineComponent({
setup(){ setup() {
console.log(i18ninit) console.log(i18ninit);
const len = provideI18n(i18ninit); const len = provideI18n(i18ninit);
// len.locale.value = !getValue("Lanvuage") ? 'zh' : getValue("Lanvuage"); function GetUrlRelativePath() {
if(getValue('token')){ const url = document.location.toString();
console.log("token") const arrUrl = url.split("//");
store.commit("login", true)
store.dispatch("getcode");
store.dispatch("setUserInfo");
const patn = useRoute().path;
if(patn == "/"){
router.push("/mine/archives").then(()=>{
location.reload()
})
}
}else{
console.log('ip')
store.dispatch("getip");
store.commit('setWlan')
router.push("/")
}
const zh = zhCN
const en = enUS
return{ const start = arrUrl[1].indexOf("/");
zh, let relUrl = arrUrl[1].substring(start); //stopstart
en,
len if (relUrl.indexOf("?") != -1) {
} relUrl = relUrl.split("?")[0];
} }
}) return relUrl;
}
// len.locale.value = !getValue("Lanvuage") ? 'zh' : getValue("Lanvuage");
if (getValue("token")) {
console.log("token");
store.commit("login", true);
store.dispatch("getcode");
store.dispatch("setUserInfo");
const patn = useRoute().path;
console.log(GetUrlRelativePath(), 444);
if (GetUrlRelativePath() == "/") {
router.push("/mine/archives").then(() => {
location.reload();
});
}
} else {
console.log("ip");
store.dispatch("getip");
store.commit("setWlan");
router.push("/");
}
const zh = zhCN;
const en = enUS;
return {
zh,
en,
len,
};
},
});
</script> </script>
<style lang="scss"> <style lang="scss">
div { div {
user-select: none; user-select: none;
} }
.one-line-hide { .one-line-hide {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
input::-webkit-outer-spin-button, input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button { input::-webkit-inner-spin-button {
-webkit-appearance: none; -webkit-appearance: none;
} }
input[type="number"]{ input[type="number"] {
-moz-appearance: textfield; -moz-appearance: textfield;
} }
</style> </style>

View File

@ -1167,3 +1167,7 @@ export async function setusername(src: string){
} }
console.log(res) console.log(res)
} }
export async function logoutapi() {
await get("logout");
}

View File

@ -130,6 +130,7 @@
} }
</style> </style>
<script lang="ts"> <script lang="ts">
import { logoutapi } from '@/api';
import { setToken } from '@/api/base'; import { setToken } from '@/api/base';
import router from '@/router'; import router from '@/router';
import store from '@/store'; import store from '@/store';
@ -230,6 +231,7 @@ export default defineComponent({
function logout(): void{ function logout(): void{
console.log("退出") console.log("退出")
logoutapi()
store.commit("login", false) store.commit("login", false)
saveValue("token", ""); saveValue("token", "");
setToken(); setToken();