-
-
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+ Drag and drop files to here to upload.
+
+
+
+
+
+
+
+
+
diff --git a/src/main.ts b/src/main.ts
index b34c4a4..5e5a0f5 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -4,63 +4,28 @@ import 'virtual:uno.css';
import { createHead } from '@unhead/vue';
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
+import { setupEruda } from './plugins/eruda';
+import { setupPrimeVue } from './plugins/primevue';
+import { setupRouter } from './plugins/router';
+import { setupVueI18n } from './plugins/vue-i18n';
-import { DataLoaderPlugin } from 'unplugin-vue-router/data-loaders';
-import { createI18n } from 'vue-i18n';
import App from './App.vue';
-import { router } from './router';
-
-import Aura from '@primevue/themes/aura';
-import zhCN from 'primelocale/zh-CN.json';
-import PrimeVue from 'primevue/config';
-import 'primeicons/primeicons.css';
-
-/* https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n#static-bundle-importing
- * All i18n resources specified in the plugin `include` option can be loaded
- * at once using the import syntax
- */
-import messages from '@intlify/unplugin-vue-i18n/messages';
async function init() {
if ((import.meta.env.MODE === 'development' || 1 === 1) && 0) {
- // TODO: https://github.com/hu3dao/vite-plugin-debug/
- // https://eruda.liriliri.io/zh/docs/#快速上手
- await import('eruda').then(({ default: eruda }) => {
- eruda.init({
- defaults: {
- transparency: 0.9,
- },
- });
- // eruda.show();
- });
+ await setupEruda();
}
- console.debug(`messages :>> `, messages);
- const app = createApp(App)
+ const app = createApp(App) //
.use(createHead())
- .use(createPinia().use(piniaPluginPersistedstate))
- // Register the plugin before the router
- .use(DataLoaderPlugin, { router })
- // adding the router will trigger the initial navigation
- .use(router)
- .use(
- // https://vue-i18n.intlify.dev/guide/essentials/started.html#registering-the-i18n-plugin
- createI18n({
- legacy: false, // you must set `false`, to use Composition API
- locale: navigator.language,
- messages,
- }),
- )
- .use(PrimeVue, {
- locale: zhCN['zh-CN'], // usePrimeVue().config.locale
- theme: { preset: Aura },
- options: {
- prefix: 'p',
- darkModeSelector: 'system',
- cssLayer: false,
- },
- });
+ .use(createPinia().use(piniaPluginPersistedstate));
+
+ setupVueI18n(app);
+ setupPrimeVue(app);
+ setupRouter(app);
+
app.config.globalProperties.$__DEV__ = $__DEV__;
+
app.mount('#app');
}
diff --git a/src/plugins/eruda.ts b/src/plugins/eruda.ts
new file mode 100644
index 0000000..9859031
--- /dev/null
+++ b/src/plugins/eruda.ts
@@ -0,0 +1,12 @@
+export async function setupEruda() {
+ // TODO: https://github.com/hu3dao/vite-plugin-debug/
+ // https://eruda.liriliri.io/zh/docs/#快速上手
+ await import('eruda').then(({ default: eruda }) => {
+ eruda.init({
+ defaults: {
+ transparency: 0.9,
+ },
+ });
+ // eruda.show();
+ });
+}
diff --git a/src/utils/primevue.ts b/src/plugins/primevue.ts
similarity index 78%
rename from src/utils/primevue.ts
rename to src/plugins/primevue.ts
index b5bdaa5..91dcd97 100644
--- a/src/utils/primevue.ts
+++ b/src/plugins/primevue.ts
@@ -13,7 +13,7 @@ interface HConfirmationOptions extends ConfirmationOptions {
rejectProps?: import('primevue/button').ButtonProps;
acceptProps?: import('primevue/button').ButtonProps;
}
-export const ConfirmationService = {
+const ConfirmationService = {
require: (options: HConfirmationOptions) => {
ConfirmationEventBus.emit('confirm', options);
},
@@ -29,7 +29,7 @@ export const ConfirmationService = {
import ToastEventBus from 'primevue/toasteventbus';
import type { ToastServiceMethods } from 'primevue/toastservice';
// https://github.com/primefaces/primevue/blob/61929eae7526015af0362fc5889f2af7527403d1/packages/primevue/src/toastservice/ToastService.js
-export const ToastService: ToastServiceMethods = {
+const ToastService: ToastServiceMethods = {
add: (message) => {
ToastEventBus.emit('add', message);
},
@@ -51,7 +51,7 @@ export const ToastService: ToastServiceMethods = {
import DynamicDialogEventBus from 'primevue/dynamicdialogeventbus';
import type { DialogServiceMethods } from 'primevue/dialogservice';
// https://github.com/primefaces/primevue/blob/18367429f624285ff32d0ef775c1825a43a02fb1/packages/primevue/src/dialogservice/DialogService.js#L7
-export const DialogService: DialogServiceMethods = {
+const DialogService: DialogServiceMethods = {
open: (content, options) => {
const instance = {
content: content && markRaw(content),
@@ -68,7 +68,34 @@ export const DialogService: DialogServiceMethods = {
},
};
-export function useDialogRef() {
+function useDialogRef() {
type DialogRef = ComputedRef;
return inject('dialogRef');
}
+
+import Aura from '@primevue/themes/aura';
+import zhCN from 'primelocale/zh-CN.json';
+import PrimeVue from 'primevue/config';
+import 'primeicons/primeicons.css';
+function setupPrimeVue(app: import('vue').App) {
+ app.use(PrimeVue, {
+ locale: {
+ ...zhCN['zh-CN'],
+ noFileChosenMessage: '未选择文件',
+ }, // usePrimeVue().config.locale
+ theme: { preset: Aura },
+ options: {
+ prefix: 'p',
+ darkModeSelector: 'system',
+ cssLayer: false,
+ },
+ });
+}
+
+export {
+ ConfirmationService,
+ ToastService,
+ DialogService,
+ useDialogRef,
+ setupPrimeVue, //
+};
diff --git a/src/plugins/router.ts b/src/plugins/router.ts
new file mode 100644
index 0000000..fae4892
--- /dev/null
+++ b/src/plugins/router.ts
@@ -0,0 +1,28 @@
+import { DataLoaderPlugin } from 'unplugin-vue-router/data-loaders';
+import { createLogGuard, createProgressGuard, createStackGuard } from 'utils4u/vue-router';
+import { createRouter, createWebHistory } from 'vue-router';
+import { handleHotUpdate, routes } from 'vue-router/auto-routes';
+
+export const router = createRouter({
+ history: createWebHistory(import.meta.env.BASE_URL),
+ routes,
+ strict: true,
+});
+router.onError((error) => {
+ console.debug('🚨 [router error]: ', error);
+});
+if (import.meta.hot) handleHotUpdate(router);
+if ($__DEV__) Object.assign(window, { router });
+
+export function setupRouter(app: import('vue').App) {
+ app
+ // Register the plugin before the router
+ .use(DataLoaderPlugin, { router })
+ // adding the router will trigger the initial navigation
+ .use(router);
+
+ // 警告:路由守卫的创建顺序会影响执行流程,请勿调整
+ createProgressGuard(router);
+ createLogGuard(router);
+ Object.assign(window, { stack: createStackGuard(router) });
+}
diff --git a/src/plugins/vue-i18n.ts b/src/plugins/vue-i18n.ts
new file mode 100644
index 0000000..e873c59
--- /dev/null
+++ b/src/plugins/vue-i18n.ts
@@ -0,0 +1,19 @@
+import { createI18n } from 'vue-i18n';
+
+/* https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n#static-bundle-importing
+ * All i18n resources specified in the plugin `include` option can be loaded
+ * at once using the import syntax
+ */
+import messages from '@intlify/unplugin-vue-i18n/messages';
+console.debug(`messages :>> `, messages);
+
+export function setupVueI18n(app: import('vue').App) {
+ app.use(
+ // https://vue-i18n.intlify.dev/guide/essentials/started.html#registering-the-i18n-plugin
+ createI18n({
+ legacy: false, // you must set `false`, to use Composition API
+ locale: navigator.language,
+ messages,
+ }),
+ );
+}
diff --git a/src/router/index.ts b/src/router/index.ts
deleted file mode 100644
index b233d56..0000000
--- a/src/router/index.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { createProgressGuard, createLogGuard, createStackGuard } from 'utils4u/vue-router';
-import { createRouter, createWebHistory, type Router } from 'vue-router';
-import { routes, handleHotUpdate } from 'vue-router/auto-routes';
-
-export const router = createRouter({
- history: createWebHistory(import.meta.env.BASE_URL),
- routes,
- strict: true,
-});
-
-if ($__DEV__) Object.assign(window, { router });
-
-setupRouterGuard(router);
-
-// Don't change the order of creation
-function setupRouterGuard(router: Router) {
- createProgressGuard(router);
- createLogGuard(router);
- Object.assign(window, { stack: createStackGuard(router) });
-
- router.onError((error) => {
- console.debug('🚨 [router error]: ', error);
- });
-}
-
-if (import.meta.hot) {
- handleHotUpdate(router);
-}