feat: 前端支持平台子路径,托管时从平台登录进入
This commit is contained in:
+15
-5
@@ -3,8 +3,10 @@ import { h, onMounted, onUnmounted, ref } from "vue";
|
||||
import type { Component } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { NButton, NIcon, NLayout, NLayoutSider, NMenu } from "naive-ui";
|
||||
import { CloudDownloadOutline, HomeOutline, KeyOutline, ListOutline, LogOutOutline, PeopleOutline, PersonOutline, SettingsOutline } from "@vicons/ionicons5";
|
||||
import { api, clearSession, token } from "../shared/http";
|
||||
import { AppsOutline, CloudDownloadOutline, HomeOutline, KeyOutline, ListOutline, LogOutOutline, PeopleOutline, PersonOutline, SettingsOutline } from "@vicons/ionicons5";
|
||||
import { platformHome } from "../shared/base";
|
||||
import { api, clearSession, sessionInfo, token } from "../shared/http";
|
||||
import { hosted } from "../shared/installState";
|
||||
import ThemeButton from "./ThemeButton.vue";
|
||||
|
||||
function renderIcon(icon: Component) {
|
||||
@@ -13,13 +15,12 @@ function renderIcon(icon: Component) {
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const role = sessionStorage.getItem("decom-role");
|
||||
const name = sessionStorage.getItem("decom-name") || "";
|
||||
const { role, name } = sessionInfo();
|
||||
const collapsed = ref(window.innerWidth < 800);
|
||||
const items = role === "admin"
|
||||
? [
|
||||
{ label: "首页", key: "/admin", icon: renderIcon(HomeOutline) },
|
||||
{ label: "用户", key: "/admin/users", icon: renderIcon(PeopleOutline) },
|
||||
...(hosted ? [] : [{ label: "用户", key: "/admin/users", icon: renderIcon(PeopleOutline) }]),
|
||||
{ label: "大数据账号池", key: "/admin/pool", icon: renderIcon(KeyOutline) },
|
||||
{ label: "采集", key: "/admin/sources", icon: renderIcon(CloudDownloadOutline) },
|
||||
{ label: "设置", key: "/admin/settings", icon: renderIcon(SettingsOutline) },
|
||||
@@ -34,6 +35,7 @@ onMounted(() => window.addEventListener("resize", onResize));
|
||||
onUnmounted(() => window.removeEventListener("resize", onResize));
|
||||
|
||||
async function logout() {
|
||||
const fromPlatform = sessionInfo().kind === "platform";
|
||||
if (token()) {
|
||||
try {
|
||||
await api("/api/auth/logout", { method: "POST" });
|
||||
@@ -42,6 +44,10 @@ async function logout() {
|
||||
}
|
||||
}
|
||||
clearSession();
|
||||
if (fromPlatform) {
|
||||
window.location.assign(platformHome);
|
||||
return;
|
||||
}
|
||||
router.push("/login");
|
||||
}
|
||||
</script>
|
||||
@@ -73,6 +79,10 @@ async function logout() {
|
||||
:options="items"
|
||||
@update:value="(key) => router.push(String(key))"
|
||||
/>
|
||||
<a v-if="hosted" class="sider-back" :class="{ compact: collapsed }" :href="platformHome" :title="collapsed ? '返回平台' : undefined">
|
||||
<n-icon :size="collapsed ? 22 : 18"><AppsOutline /></n-icon>
|
||||
<span v-if="!collapsed">返回平台</span>
|
||||
</a>
|
||||
<div class="sider-user" :class="{ compact: collapsed }">
|
||||
<n-icon :size="18"><PersonOutline /></n-icon>
|
||||
<div v-if="!collapsed" class="who">
|
||||
|
||||
Reference in New Issue
Block a user