feat: 用户入口改用自有账号,管理入口只从应用托管进入
This commit is contained in:
+19
-9
@@ -1,10 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { h, onMounted, onUnmounted, ref } from "vue";
|
||||
import { computed, 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 { AppsOutline, CloudDownloadOutline, HomeOutline, KeyOutline, ListOutline, LogOutOutline, PeopleOutline, PersonOutline, SettingsOutline } from "@vicons/ionicons5";
|
||||
import { appUrl, platformHome } from "../shared/base";
|
||||
import { appUrl } from "../shared/base";
|
||||
import { api, clearSession, sessionInfo, token } from "../shared/http";
|
||||
import { hosted } from "../shared/installState";
|
||||
import ThemeButton from "./ThemeButton.vue";
|
||||
@@ -17,21 +17,30 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { role, name } = sessionInfo();
|
||||
const collapsed = ref(window.innerWidth < 800);
|
||||
const items = role === "admin"
|
||||
const loginMode = ref("local");
|
||||
const items = computed(() => role === "admin"
|
||||
? [
|
||||
{ label: "首页", key: "/admin", icon: renderIcon(HomeOutline) },
|
||||
...(hosted ? [] : [{ label: "用户", key: "/admin/users", icon: renderIcon(PeopleOutline) }]),
|
||||
...(!hosted || loginMode.value === "local" ? [{ 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) },
|
||||
]
|
||||
: [{ label: "任务", key: "/tasks", icon: renderIcon(ListOutline) }];
|
||||
: [{ label: "任务", key: "/tasks", icon: renderIcon(ListOutline) }]);
|
||||
|
||||
function onResize() {
|
||||
if (window.innerWidth < 800) collapsed.value = true;
|
||||
}
|
||||
|
||||
onMounted(() => window.addEventListener("resize", onResize));
|
||||
onMounted(async () => {
|
||||
window.addEventListener("resize", onResize);
|
||||
if (role !== "admin") return;
|
||||
try {
|
||||
loginMode.value = (await api<{ mode: string }>("/api/auth/mode")).mode;
|
||||
} catch {
|
||||
loginMode.value = "local";
|
||||
}
|
||||
});
|
||||
onUnmounted(() => window.removeEventListener("resize", onResize));
|
||||
|
||||
async function logout() {
|
||||
@@ -42,8 +51,9 @@ async function logout() {
|
||||
/* 本地会话仍会清掉 */
|
||||
}
|
||||
}
|
||||
const admin = role === "admin";
|
||||
clearSession();
|
||||
window.location.assign(appUrl("login"));
|
||||
window.location.assign(hosted && admin ? "/hosting" : appUrl("login"));
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -74,9 +84,9 @@ 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">
|
||||
<a v-if="hosted && role === 'admin'" class="sider-back" :class="{ compact: collapsed }" href="/hosting" :title="collapsed ? '返回应用托管' : undefined" @click="clearSession()">
|
||||
<n-icon :size="collapsed ? 22 : 18"><AppsOutline /></n-icon>
|
||||
<span v-if="!collapsed">返回平台</span>
|
||||
<span v-if="!collapsed">返回应用托管</span>
|
||||
</a>
|
||||
<div class="sider-user" :class="{ compact: collapsed }">
|
||||
<n-icon :size="18"><PersonOutline /></n-icon>
|
||||
|
||||
Reference in New Issue
Block a user