2023-11-09 06:56:06 +00:00
|
|
|
import { createApp } from "vue";
|
|
|
|
import type { DirectiveBinding } from "vue";
|
|
|
|
import { createPinia } from "pinia";
|
|
|
|
import App from "./App.vue";
|
|
|
|
import router from "./router";
|
2024-06-25 04:31:44 +00:00
|
|
|
import { consoleApiClient } from "@halo-dev/api-client";
|
2023-11-09 06:56:06 +00:00
|
|
|
// setup
|
|
|
|
import "@/setup/setupStyles";
|
|
|
|
import { setupComponents } from "@/setup/setupComponents";
|
|
|
|
import { setupI18n, i18n, getBrowserLanguage } from "@/locales";
|
|
|
|
// core modules
|
|
|
|
import { hasPermission } from "@/utils/permission";
|
|
|
|
import { useRoleStore } from "@/stores/role";
|
|
|
|
import { useThemeStore } from "@console/stores/theme";
|
|
|
|
import { useUserStore } from "@/stores/user";
|
|
|
|
import { useSystemConfigMapStore } from "@console/stores/system-configmap";
|
|
|
|
import { setupVueQuery } from "@/setup/setupVueQuery";
|
|
|
|
import { useGlobalInfoStore } from "@/stores/global-info";
|
2023-11-13 08:56:08 +00:00
|
|
|
import {
|
|
|
|
setupCoreModules,
|
|
|
|
setupPluginModules,
|
|
|
|
} from "@console/setup/setupModules";
|
2024-06-25 04:31:44 +00:00
|
|
|
import { setupApiClient } from "@/setup/setupApiClient";
|
2023-11-09 06:56:06 +00:00
|
|
|
|
|
|
|
const app = createApp(App);
|
|
|
|
|
|
|
|
setupComponents(app);
|
|
|
|
setupI18n(app);
|
|
|
|
setupVueQuery(app);
|
2024-06-25 04:31:44 +00:00
|
|
|
setupApiClient();
|
2023-11-09 06:56:06 +00:00
|
|
|
|
|
|
|
app.use(createPinia());
|
|
|
|
|
|
|
|
async function loadUserPermissions() {
|
2024-06-25 04:31:44 +00:00
|
|
|
const { data: currentPermissions } =
|
|
|
|
await consoleApiClient.user.getPermissions({
|
|
|
|
name: "-",
|
|
|
|
});
|
2023-11-09 06:56:06 +00:00
|
|
|
const roleStore = useRoleStore();
|
|
|
|
roleStore.$patch({
|
|
|
|
permissions: currentPermissions,
|
|
|
|
});
|
|
|
|
app.directive(
|
|
|
|
"permission",
|
|
|
|
(el: HTMLElement, binding: DirectiveBinding<string[]>) => {
|
|
|
|
const uiPermissions = Array.from<string>(
|
|
|
|
currentPermissions.uiPermissions
|
|
|
|
);
|
|
|
|
const { value } = binding;
|
|
|
|
const { any, enable } = binding.modifiers;
|
|
|
|
|
|
|
|
if (hasPermission(uiPermissions, value, any)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
//TODO
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
el?.remove?.();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function loadActivatedTheme() {
|
|
|
|
const themeStore = useThemeStore();
|
|
|
|
await themeStore.fetchActivatedTheme();
|
|
|
|
}
|
|
|
|
|
|
|
|
(async function () {
|
|
|
|
await initApp();
|
|
|
|
})();
|
|
|
|
|
|
|
|
async function initApp() {
|
|
|
|
try {
|
|
|
|
setupCoreModules(app);
|
|
|
|
|
|
|
|
const userStore = useUserStore();
|
|
|
|
await userStore.fetchCurrentUser();
|
|
|
|
|
|
|
|
// set locale
|
|
|
|
i18n.global.locale.value =
|
|
|
|
localStorage.getItem("locale") || getBrowserLanguage();
|
|
|
|
|
|
|
|
const globalInfoStore = useGlobalInfoStore();
|
|
|
|
await globalInfoStore.fetchGlobalInfo();
|
|
|
|
|
|
|
|
if (userStore.isAnonymous) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await loadUserPermissions();
|
|
|
|
|
|
|
|
try {
|
|
|
|
await setupPluginModules(app);
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Failed to load plugins", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// load system configMap
|
|
|
|
const systemConfigMapStore = useSystemConfigMapStore();
|
|
|
|
await systemConfigMapStore.fetchSystemConfigMap();
|
|
|
|
|
|
|
|
if (globalInfoStore.globalInfo?.userInitialized) {
|
|
|
|
await loadActivatedTheme();
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
} finally {
|
|
|
|
app.use(router);
|
|
|
|
app.mount("#app");
|
|
|
|
}
|
|
|
|
}
|