mirror of https://github.com/halo-dev/halo-admin
feat: bundle core modules
parent
2538959339
commit
d8c14531e0
|
@ -15,7 +15,7 @@ export interface Plugin {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This components will be registered when plugin is activated.
|
* These components will be registered when plugin is activated.
|
||||||
*/
|
*/
|
||||||
components?: Component[];
|
components?: Component[];
|
||||||
|
|
||||||
|
|
53
src/main.ts
53
src/main.ts
|
@ -8,18 +8,8 @@ import "./setup/setupStyles";
|
||||||
import { setupComponents } from "./setup/setupComponents";
|
import { setupComponents } from "./setup/setupComponents";
|
||||||
import { registerMenu } from "@/router/menus.config";
|
import { registerMenu } from "@/router/menus.config";
|
||||||
|
|
||||||
// modules
|
// core modules
|
||||||
import dashboardModule from "./modules/dashboard/module";
|
import { coreModules } from "./modules";
|
||||||
import postModule from "./modules/contents/posts/module";
|
|
||||||
import sheetModule from "./modules/contents/sheets/module";
|
|
||||||
import commentModule from "./modules/contents/comments/module";
|
|
||||||
import attachmentModule from "./modules/contents/attachments/module";
|
|
||||||
import themeModule from "./modules/interface/themes/module";
|
|
||||||
import menuModule from "./modules/interface/menus/module";
|
|
||||||
import pluginModule from "./modules/system/plugins/module";
|
|
||||||
import userModule from "./modules/system/users/module";
|
|
||||||
import roleModule from "./modules/system/roles/module";
|
|
||||||
import settingModule from "./modules/system/settings/module";
|
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
|
@ -27,20 +17,35 @@ setupComponents(app);
|
||||||
|
|
||||||
app.use(createPinia());
|
app.use(createPinia());
|
||||||
|
|
||||||
async function registerModule(pluginModule: Plugin) {
|
function registerModule(pluginModule: Plugin) {
|
||||||
if (pluginModule.components) {
|
if (pluginModule.components) {
|
||||||
|
if (!Array.isArray(pluginModule.components)) {
|
||||||
|
console.error(`${pluginModule.name}: Plugin components must be an array`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (const component of pluginModule.components) {
|
for (const component of pluginModule.components) {
|
||||||
component.name && app.component(component.name, component);
|
component.name && app.component(component.name, component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pluginModule.routes) {
|
if (pluginModule.routes) {
|
||||||
|
if (!Array.isArray(pluginModule.routes)) {
|
||||||
|
console.error(`${pluginModule.name}: Plugin routes must be an array`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (const route of pluginModule.routes) {
|
for (const route of pluginModule.routes) {
|
||||||
router.addRoute(route);
|
router.addRoute(route);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pluginModule.menus) {
|
if (pluginModule.menus) {
|
||||||
|
if (!Array.isArray(pluginModule.menus)) {
|
||||||
|
console.error(`${pluginModule.name}: Plugin menus must be an array`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (const group of pluginModule.menus) {
|
for (const group of pluginModule.menus) {
|
||||||
for (const menu of group.items) {
|
for (const menu of group.items) {
|
||||||
registerMenu(group.name, menu);
|
registerMenu(group.name, menu);
|
||||||
|
@ -50,19 +55,7 @@ async function registerModule(pluginModule: Plugin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadCoreModules() {
|
function loadCoreModules() {
|
||||||
Array.from<Plugin>([
|
coreModules.forEach(registerModule);
|
||||||
dashboardModule,
|
|
||||||
postModule,
|
|
||||||
sheetModule,
|
|
||||||
commentModule,
|
|
||||||
attachmentModule,
|
|
||||||
themeModule,
|
|
||||||
menuModule,
|
|
||||||
pluginModule,
|
|
||||||
userModule,
|
|
||||||
roleModule,
|
|
||||||
settingModule,
|
|
||||||
]).forEach(registerModule);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadPluginModules() {
|
function loadPluginModules() {
|
||||||
|
@ -72,8 +65,12 @@ function loadPluginModules() {
|
||||||
initApp();
|
initApp();
|
||||||
|
|
||||||
async function initApp() {
|
async function initApp() {
|
||||||
loadCoreModules();
|
try {
|
||||||
loadPluginModules();
|
loadCoreModules();
|
||||||
|
loadPluginModules();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
app.use(router);
|
app.use(router);
|
||||||
app.mount("#app");
|
app.mount("#app");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
import dashboardModule from "./dashboard/module";
|
||||||
|
import postModule from "./contents/posts/module";
|
||||||
|
import sheetModule from "./contents/sheets/module";
|
||||||
|
import commentModule from "./contents/comments/module";
|
||||||
|
import attachmentModule from "./contents/attachments/module";
|
||||||
|
import themeModule from "./interface/themes/module";
|
||||||
|
import menuModule from "./interface/menus/module";
|
||||||
|
import pluginModule from "./system/plugins/module";
|
||||||
|
import userModule from "./system/users/module";
|
||||||
|
import roleModule from "./system/roles/module";
|
||||||
|
import settingModule from "./system/settings/module";
|
||||||
|
|
||||||
|
const coreModules = [
|
||||||
|
dashboardModule,
|
||||||
|
postModule,
|
||||||
|
sheetModule,
|
||||||
|
commentModule,
|
||||||
|
attachmentModule,
|
||||||
|
themeModule,
|
||||||
|
menuModule,
|
||||||
|
pluginModule,
|
||||||
|
userModule,
|
||||||
|
roleModule,
|
||||||
|
settingModule,
|
||||||
|
];
|
||||||
|
|
||||||
|
export { coreModules };
|
|
@ -13,6 +13,7 @@ import { useRoute, useRouter } from "vue-router";
|
||||||
import { roles } from "@/modules/system/roles/roles-mock";
|
import { roles } from "@/modules/system/roles/roles-mock";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { users } from "@/modules/system/users/users-mock";
|
import { users } from "@/modules/system/users/users-mock";
|
||||||
|
import { Starport } from "vue-starport";
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
|
@ -127,15 +128,21 @@ const handleRouteToUser = (username: string) => {
|
||||||
<div class="flex items-center px-4 py-4">
|
<div class="flex items-center px-4 py-4">
|
||||||
<div class="flex min-w-0 flex-1 items-center">
|
<div class="flex min-w-0 flex-1 items-center">
|
||||||
<div class="flex-shrink-0">
|
<div class="flex-shrink-0">
|
||||||
<div
|
<Starport
|
||||||
class="h-12 w-12 overflow-hidden rounded border bg-white hover:shadow-sm"
|
:duration="400"
|
||||||
|
:port="`user-profile-${user.name}`"
|
||||||
|
class="h-12 w-12"
|
||||||
>
|
>
|
||||||
<img
|
<div
|
||||||
:alt="user.name"
|
class="overflow-hidden rounded border bg-white hover:shadow-sm"
|
||||||
:src="user.avatar"
|
>
|
||||||
class="h-full w-full"
|
<img
|
||||||
/>
|
:alt="user.name"
|
||||||
</div>
|
:src="user.avatar"
|
||||||
|
class="h-full w-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Starport>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="min-w-0 flex-1 px-4 md:grid md:grid-cols-2 md:gap-4"
|
class="min-w-0 flex-1 px-4 md:grid md:grid-cols-2 md:gap-4"
|
||||||
|
|
|
@ -29,7 +29,6 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
path: ":username",
|
path: ":username",
|
||||||
component: UserProfileLayout,
|
component: UserProfileLayout,
|
||||||
alias: ["profile"],
|
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: "detail",
|
path: "detail",
|
||||||
|
|
Loading…
Reference in New Issue