x-essential-lib 0.10.20 → 0.10.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { n as EventType, t as Emitter } from "./vendor.bri8m5ch.js";
1
+ import { n as EventType, t as Emitter } from "./vendor.dqdzrw43.js";
2
2
  import { Ref } from "vue";
3
- import { RouteLocationNormalized } from "vue-router";
4
3
  import { AxiosInstance } from "axios";
4
+ import { RouteLocationNormalized } from "vue-router";
5
5
 
6
6
  //#region src/composables/color.d.ts
7
7
  declare function useColor(): {
@@ -254,16 +254,8 @@ declare function provideDark(dark: Ref<boolean>): void;
254
254
  declare function injectDark(): Ref<boolean>;
255
255
  declare function provideLocale(locale: Ref<string>): void;
256
256
  declare function injectLocale(): Ref<string>;
257
- declare function provideActiveOrg(activeOrg: Ref<string>): void;
258
- declare function injectActiveOrg(): Ref<string>;
259
- declare function provideActiveOrgName(activeOrgName: Ref<string>): void;
260
- declare function injectActiveOrgName(): Ref<string>;
261
257
  declare function providePermissionObjects(permissionObjects: Ref<PermissionObjects>): void;
262
258
  declare function injectPermissionObjects(): Ref<PermissionObjects>;
263
- declare function providePermissionChecksum(permissionChecksum: Ref<string>): void;
264
- declare function injectPermissionChecksum(): Ref<string>;
265
- declare function provideLastAppPath(lastAppPath: Ref<string>): void;
266
- declare function injectLastAppPath(): Ref<string>;
267
259
  declare function provideViews(views: Ref<string[]>): void;
268
260
  declare function injectViews(): Ref<string[]>;
269
261
  //#endregion
@@ -279,12 +271,6 @@ declare function matchRouteMeta(path: string): RouteMeta | undefined;
279
271
  declare const routeTransName: import("vue").Ref<string, string>;
280
272
  declare function onBeforeEach(to: RouteLocationNormalized, from: RouteLocationNormalized, lastAppPath: string): Promise<{
281
273
  path: string;
282
- query?: undefined;
283
- } | {
284
- path: string;
285
- query: {
286
- orgId: string;
287
- };
288
274
  } | undefined>;
289
275
  //#endregion
290
276
  //#region src/utils/type.d.ts
@@ -302,18 +288,23 @@ declare function delView(views: Ref<string[]>, name: string): void;
302
288
  declare function popView(views: Ref<string[]>): void;
303
289
  declare function clearViews(views: Ref<string[]>): void;
304
290
  //#endregion
305
- //#region src/composables/microApp.d.ts
291
+ //#region src/composables/globalStates.d.ts
306
292
  interface GlobalStates {
307
- dark: Ref<boolean | undefined>;
293
+ darkRaw: Ref<boolean | undefined>;
294
+ dark: Ref<boolean>;
308
295
  locale: Ref<string>;
309
296
  activeOrg: Ref<string>;
297
+ activeOrgNameRaw: Ref<string>;
310
298
  activeOrgName: Ref<string>;
311
299
  permissionObjects: Ref<PermissionObjects>;
312
300
  permissionChecksum: Ref<string>;
313
301
  lastAppPath: Ref<string>;
314
302
  views: Ref<string[]>;
315
303
  }
316
- declare function useMicroApp(globalStates: GlobalStates, base?: boolean, customBack?: (m: RouteMeta) => void): void;
304
+ declare function useGlobalStates(globalStates: GlobalStates, base?: boolean): void;
305
+ //#endregion
306
+ //#region src/composables/microApp.d.ts
307
+ declare function useMicroApp(globalStates: GlobalStates, ignoreSyncOrg?: boolean, onRouteChange?: () => Promise<void>, customBack?: (m: RouteMeta) => void): void;
317
308
  //#endregion
318
309
  //#region src/composables/permission.d.ts
319
310
  declare function usePermission(): {
@@ -560,4 +551,4 @@ declare const _default: {
560
551
  install: (app: import("vue").App) => void;
561
552
  };
562
553
  //#endregion
563
- export { Permission, PermissionObjects, RouteMeta, Type, addView, appAppear, clearViews, closeWaitDlg, createAxios, _default as default, delView, eventBus, getTypeColor, getTypeDefault, globalObjects, hasView, injectActiveOrg, injectActiveOrgName, injectDark, injectLastAppPath, injectLocale, injectPermissionChecksum, injectPermissionObjects, injectViews, isEmpty, isExist, lastView, loadLocaleMessageEssential, matchRouteMeta, messageError, messageInfo, messageSuccess, messageWarning, onBeforeEach, openConfirmDlg, openNumberDlg, openPromptDlg, openWaitDlg, popView, provideActiveOrg, provideActiveOrgName, provideDark, provideLastAppPath, provideLocale, providePermissionChecksum, providePermissionObjects, provideViews, routeTransName, toPermissionObjects, types, useColor, useMicroApp, usePermission, useSystem, useViewStack, verifyPermission, waitMs, waitUtil };
554
+ export { GlobalStates, Permission, PermissionObjects, RouteMeta, Type, addView, appAppear, clearViews, closeWaitDlg, createAxios, _default as default, delView, eventBus, getTypeColor, getTypeDefault, globalObjects, hasView, injectDark, injectLocale, injectPermissionObjects, injectViews, isEmpty, isExist, lastView, loadLocaleMessageEssential, matchRouteMeta, messageError, messageInfo, messageSuccess, messageWarning, onBeforeEach, openConfirmDlg, openNumberDlg, openPromptDlg, openWaitDlg, popView, provideDark, provideLocale, providePermissionObjects, provideViews, routeTransName, toPermissionObjects, types, useColor, useGlobalStates, useMicroApp, usePermission, useSystem, useViewStack, verifyPermission, waitMs, waitUtil };
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  (function(){try{document.getElementById(`x-essential-lib`)?.remove();const e = document.createElement(`style`);e.setAttribute(`id`, `x-essential-lib`);const t = document.createTextNode(`.fade-leave-active[data-v-x-essential-lib-c3545c8d]{transition:opacity .5s}.fade-leave-to[data-v-x-essential-lib-c3545c8d]{opacity:0}.x-cont[data-v-x-essential-lib-c3545c8d]{justify-content:center;align-items:center;display:flex;position:absolute;inset:0}.lds-spinner[data-v-x-essential-lib-c3545c8d]{color:official;width:40px;height:40px;display:inline-block;position:relative}.lds-spinner div[data-v-x-essential-lib-c3545c8d]{transform-origin:20px 20px;animation:1.2s linear infinite lds-spinner-x-essential-lib-c3545c8d}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:after{content:" ";background:#9e9e9e;border-radius:5%;width:2px;height:6px;display:block;position:absolute;top:3px;left:18px}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:first-child{animation-delay:-1.1s;transform:rotate(0)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(2){animation-delay:-1s;transform:rotate(30deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(3){animation-delay:-.9s;transform:rotate(60deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(4){animation-delay:-.8s;transform:rotate(90deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(5){animation-delay:-.7s;transform:rotate(120deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(6){animation-delay:-.6s;transform:rotate(150deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(7){animation-delay:-.5s;transform:rotate(180deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(8){animation-delay:-.4s;transform:rotate(210deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(9){animation-delay:-.3s;transform:rotate(240deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(10){animation-delay:-.2s;transform:rotate(270deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(11){animation-delay:-.1s;transform:rotate(300deg)}.lds-spinner div[data-v-x-essential-lib-c3545c8d]:nth-child(12){animation-delay:0s;transform:rotate(330deg)}@keyframes lds-spinner-x-essential-lib-c3545c8d{0%{opacity:1}to{opacity:0}}.x-item[data-v-x-essential-lib-cfcda9d9]{width:600px}@media (width<=600px){.x-item[data-v-x-essential-lib-cfcda9d9]{width:calc(100vw - 16px)}}.x-cont[data-v-x-essential-lib-b973907d]{z-index:9999;position:fixed;bottom:20px;left:50%;transform:translate(-50%)}`);e.appendChild(t);document.head.appendChild(e);}catch(e){console.error('rolldown-plugin-inject-css', e);}})()
2
- import { a as api, i as mitt_default, o as usePreferredDark, r as toLower } from "./vendor.bri8m5ch.js";
2
+ import { a as api, i as mitt_default, o as usePreferredDark, r as toLower } from "./vendor.dqdzrw43.js";
3
3
  import { Fragment, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, inject, isRef, normalizeStyle, onBeforeMount, onBeforeUnmount, onMounted, openBlock, provide, ref, renderList, resolveComponent, toDisplayString, unref, useTemplateRef, watch, watchEffect, withCtx, withKeys, withModifiers } from "vue";
4
4
  import { useI18n } from "vue-i18n";
5
5
  import { useDisplay, useTheme } from "vuetify";
6
- import { useRoute, useRouter } from "vue-router";
6
+ import axios from "axios";
7
+ import { onBeforeRouteUpdate, useRoute, useRouter } from "vue-router";
7
8
  import { getErrorMessage } from "x-error-lib";
8
9
  import { createAxios as createAxios$1, messageError as messageError$1 } from "x-essential-lib";
9
- import axios from "axios";
10
10
 
11
11
  //#region src/composables/color.ts
12
12
  function useColor() {
@@ -36,25 +36,6 @@ function useColor() {
36
36
  };
37
37
  }
38
38
 
39
- //#endregion
40
- //#region src/api/orgbase/instance.ts
41
- const instance = createAxios$1({
42
- baseUrl: "http://localhost/orgbase/",
43
- onError: (error) => {
44
- messageError$1(getErrorMessage(error));
45
- }
46
- });
47
- if (window.API_URL) instance.defaults.baseURL = window.API_URL + "/orgbase/";
48
-
49
- //#endregion
50
- //#region src/api/orgbase/index.ts
51
- function GetOrgName(request) {
52
- return instance.post("getOrgName", request);
53
- }
54
- function PullPermission(request) {
55
- return instance.post("pullPermission", request);
56
- }
57
-
58
39
  //#endregion
59
40
  //#region src/utils/axios.ts
60
41
  function createAxios(options) {
@@ -90,17 +71,24 @@ function onRespRejected(error, onError) {
90
71
  const resp = error.response;
91
72
  if (!resp) return Promise.reject(error);
92
73
  if (resp.status === 401) onUnauthorized();
93
- if (resp.data?.message) onError(resp.data?.message);
94
- else onError({
95
- code: resp.status,
96
- message: resp.statusText
97
- });
98
- return Promise.reject(error);
74
+ const msg = resp.data?.message;
75
+ if (msg) {
76
+ onError(msg);
77
+ return Promise.reject(msg);
78
+ } else {
79
+ const obj = {
80
+ code: resp.status,
81
+ message: resp.statusText
82
+ };
83
+ onError(obj);
84
+ return Promise.reject(obj);
85
+ }
99
86
  }
100
87
  function onUnauthorized() {
88
+ const router = useRouter();
101
89
  api.remove("accessToken");
102
90
  api.remove("refreshToken");
103
- useRouter().replace({ path: "/passport/login" });
91
+ router.replace({ path: `/passport/login` });
104
92
  }
105
93
 
106
94
  //#endregion
@@ -430,36 +418,12 @@ function provideLocale(locale) {
430
418
  function injectLocale() {
431
419
  return inject("essentialLocale");
432
420
  }
433
- function provideActiveOrg(activeOrg) {
434
- provide("essentialActiveOrg", activeOrg);
435
- }
436
- function injectActiveOrg() {
437
- return inject("essentialActiveOrg");
438
- }
439
- function provideActiveOrgName(activeOrgName) {
440
- provide("essentialActiveOrgName", activeOrgName);
441
- }
442
- function injectActiveOrgName() {
443
- return inject("essentialActiveOrgName");
444
- }
445
421
  function providePermissionObjects(permissionObjects) {
446
422
  provide("essentialPermissionObjects", permissionObjects);
447
423
  }
448
424
  function injectPermissionObjects() {
449
425
  return inject("essentialPermissionObjects");
450
426
  }
451
- function providePermissionChecksum(permissionChecksum) {
452
- provide("essentialPermissionChecksum", permissionChecksum);
453
- }
454
- function injectPermissionChecksum() {
455
- return inject("essentialPermissionChecksum");
456
- }
457
- function provideLastAppPath(lastAppPath) {
458
- provide("essentialLastAppPath", lastAppPath);
459
- }
460
- function injectLastAppPath() {
461
- return inject("essentialLastAppPath");
462
- }
463
427
  function provideViews(views) {
464
428
  provide("viewsKey", views);
465
429
  }
@@ -639,48 +603,13 @@ function onBeforeChange(toPath, fromPath, lastAppPath) {
639
603
  function isHasAccessToken() {
640
604
  return !!api.get("accessToken");
641
605
  }
642
- async function syncOrg(orgId) {
643
- if (orgId !== "public") {
644
- const { name } = await GetOrgName({ orgId });
645
- eventBus.emit("updateActiveOrg", [orgId, name]);
646
- } else eventBus.emit("updateActiveOrg", [orgId, ""]);
647
- }
648
- async function syncPermission(orgId) {
649
- if (orgId !== "public") {
650
- const { permissions } = await PullPermission({
651
- orgId,
652
- checksum: ""
653
- });
654
- eventBus.emit("updatePermission", [toPermissionObjects(permissions), permissions["checksum"] ?? ""]);
655
- } else eventBus.emit("updatePermission", [{}, ""]);
656
- }
657
606
  async function onBeforeEach(to, from, lastAppPath) {
658
607
  const hasAccessToken = isHasAccessToken();
659
608
  const toRouteMeta = matchRouteMeta(to.path);
660
609
  if (!toRouteMeta) return;
661
610
  if (toRouteMeta.requireAuth && !hasAccessToken) return { path: `/passport/login` };
662
- if (hasAccessToken && to.path.startsWith("/passport/")) return {
663
- path: `/main/${Date.now()}`,
664
- query: { orgId: "public" }
665
- };
666
- if (to.path.startsWith("/passport/")) onBeforeChange(to.path, from.path, lastAppPath);
667
- else {
668
- const orgId = to.query.orgId;
669
- if (!orgId) return {
670
- path: `/main/${Date.now()}`,
671
- query: { orgId: "public" }
672
- };
673
- try {
674
- await syncOrg(orgId);
675
- await syncPermission(orgId);
676
- onBeforeChange(to.path, from.path, lastAppPath);
677
- } catch {
678
- return {
679
- path: `/main/${Date.now()}`,
680
- query: { orgId: "public" }
681
- };
682
- }
683
- }
611
+ if (hasAccessToken && to.path.startsWith("/passport/")) return { path: `/main/${Date.now()}` };
612
+ onBeforeChange(to.path, from.path, lastAppPath);
684
613
  }
685
614
 
686
615
  //#endregion
@@ -744,118 +673,133 @@ function clearViews(views) {
744
673
  }
745
674
 
746
675
  //#endregion
747
- //#region src/composables/microApp.ts
748
- function useMicroApp(globalStates, base, customBack) {
676
+ //#region src/composables/globalStates.ts
677
+ function useGlobalStates(globalStates, base) {
749
678
  const { t } = useI18n();
750
- const route = useRoute();
751
- const router = useRouter();
752
- const { dark, locale, activeOrg, activeOrgName, permissionObjects, permissionChecksum, lastAppPath, views } = globalStates;
679
+ const { darkRaw, dark, locale, activeOrg, activeOrgNameRaw, activeOrgName, permissionObjects, permissionChecksum, lastAppPath, views } = globalStates;
680
+ provideDark(dark);
681
+ provideLocale(locale);
682
+ providePermissionObjects(permissionObjects);
683
+ provideViews(views);
753
684
  const prefDark = usePreferredDark();
754
- const finalDark = ref(false);
755
685
  watchEffect(() => {
756
686
  let d;
757
- if (typeof dark.value === "boolean") d = dark.value;
687
+ if (typeof darkRaw.value === "boolean") d = darkRaw.value;
758
688
  else d = prefDark.value;
759
- finalDark.value = d;
689
+ dark.value = d;
760
690
  });
761
691
  const theme = useTheme();
762
692
  watchEffect(async () => {
763
- await theme.change(finalDark.value ? "dark" : "light");
693
+ await theme.change(dark.value ? "dark" : "light");
764
694
  });
765
- provideDark(finalDark);
766
- provideLocale(locale);
767
- provideActiveOrg(activeOrg);
768
- provideActiveOrgName(activeOrgName);
769
- providePermissionObjects(permissionObjects);
770
- providePermissionChecksum(permissionChecksum);
771
- provideLastAppPath(lastAppPath);
772
- provideViews(views);
773
- function extractPathFromUrl(url) {
774
- return new URL(url).pathname;
775
- }
776
- function onBeforeAppChange(e) {
777
- const lastAppPath = extractPathFromUrl(e.detail.oldUrl);
778
- eventBus.emit("updateLastAppPath", lastAppPath);
779
- }
780
- if (base) {
781
- onMounted(() => {
782
- window.addEventListener("single-spa:before-app-change", onBeforeAppChange);
783
- });
784
- onBeforeUnmount(() => {
785
- window.removeEventListener("single-spa:before-app-change", onBeforeAppChange);
786
- });
695
+ watchEffect(() => {
696
+ if (activeOrg.value === "public") activeOrgName.value = t("x-essential-lib.publicDomain");
697
+ else activeOrgName.value = activeOrgNameRaw.value;
698
+ });
699
+ function onUpdateDark(val) {
700
+ darkRaw.value = val;
787
701
  }
788
- function syncStatusBar() {
789
- if (typeof StatusBar !== "object") return;
790
- if (finalDark.value) StatusBar.styleLightContent();
791
- else StatusBar.styleDefault();
702
+ function onUpdateLocale(val) {
703
+ locale.value = val;
792
704
  }
793
- const running = ref(true);
794
- function onPause() {
795
- running.value = false;
705
+ function onUpdateActiveOrg(val) {
706
+ activeOrg.value = val[0];
707
+ activeOrgNameRaw.value = val[1];
796
708
  }
797
- function onResume() {
798
- running.value = true;
709
+ function onUpdatePermission(val) {
710
+ permissionObjects.value = val[0];
711
+ permissionChecksum.value = val[1];
799
712
  }
800
- async function onBackButton() {
801
- eventBus.emit("back");
713
+ function onUpdateLastAppPath(val) {
714
+ lastAppPath.value = val;
802
715
  }
803
- function onDeviceReady() {
804
- console.log("onDeviceReady");
805
- document.addEventListener("pause", onPause, false);
806
- document.addEventListener("resume", onResume, false);
807
- document.addEventListener("backbutton", onBackButton, false);
808
- setInterval(() => {
809
- syncStatusBar();
810
- }, 1e3);
811
- navigator.splashscreen.hide();
716
+ function onSyncGlobalStates() {
717
+ eventBus.emit("updateDark", dark.value);
718
+ eventBus.emit("updateLocale", locale.value);
719
+ eventBus.emit("updateActiveOrg", [activeOrg.value, activeOrgNameRaw.value]);
720
+ eventBus.emit("updatePermission", [permissionObjects.value, permissionChecksum.value]);
721
+ eventBus.emit("updateLastAppPath", lastAppPath.value);
812
722
  }
813
- if (base) {
814
- onMounted(() => {
815
- document.addEventListener("deviceready", onDeviceReady, false);
816
- });
817
- onBeforeUnmount(() => {
818
- document.removeEventListener("deviceready", onDeviceReady, false);
819
- });
820
- watch(finalDark, (val) => {
821
- window.dispatchEvent(new CustomEvent("darkChange", { detail: val }));
822
- syncStatusBar();
823
- }, { immediate: true });
723
+ onBeforeMount(() => {
724
+ eventBus.on("updateDark", onUpdateDark);
725
+ eventBus.on("updateLocale", onUpdateLocale);
726
+ eventBus.on("updateActiveOrg", onUpdateActiveOrg);
727
+ eventBus.on("updatePermission", onUpdatePermission);
728
+ eventBus.on("updateLastAppPath", onUpdateLastAppPath);
729
+ if (base) eventBus.on("syncGlobalStates", onSyncGlobalStates);
730
+ else eventBus.emit("syncGlobalStates");
731
+ });
732
+ onBeforeUnmount(() => {
733
+ eventBus.off("updateDark", onUpdateDark);
734
+ eventBus.off("updateLocale", onUpdateLocale);
735
+ eventBus.off("updateActiveOrg", onUpdateActiveOrg);
736
+ eventBus.off("updatePermission", onUpdatePermission);
737
+ eventBus.off("updateLastAppPath", onUpdateLastAppPath);
738
+ if (base) eventBus.off("syncGlobalStates", onSyncGlobalStates);
739
+ });
740
+ }
741
+
742
+ //#endregion
743
+ //#region src/api/orgbase/instance.ts
744
+ const instance = createAxios$1({
745
+ baseUrl: "http://localhost/orgbase/",
746
+ onError: (error) => {
747
+ messageError$1(getErrorMessage(error));
824
748
  }
825
- let handle;
826
- async function syncPermission() {
827
- if (!running.value) return;
828
- if (!api.get("accessToken")) return;
749
+ });
750
+ if (window.API_URL) instance.defaults.baseURL = window.API_URL + "/orgbase/";
751
+
752
+ //#endregion
753
+ //#region src/api/orgbase/index.ts
754
+ function GetOrgName(request) {
755
+ return instance.post("getOrgName", request);
756
+ }
757
+ function PullPermission(request) {
758
+ return instance.post("pullPermission", request);
759
+ }
760
+
761
+ //#endregion
762
+ //#region src/composables/microApp.ts
763
+ function useMicroApp(globalStates, ignoreSyncOrg, onRouteChange, customBack) {
764
+ const route = useRoute();
765
+ const router = useRouter();
766
+ useGlobalStates(globalStates);
767
+ const { activeOrg, views } = globalStates;
768
+ async function syncOrg() {
769
+ const orgId = route.query.orgId;
770
+ if (!orgId) {
771
+ router.replace(`/main/${Date.now()}`);
772
+ return false;
773
+ }
774
+ if (orgId === "public") {
775
+ eventBus.emit("updateActiveOrg", [orgId, ""]);
776
+ eventBus.emit("updatePermission", [{}, ""]);
777
+ return true;
778
+ }
829
779
  try {
830
- const { update, permissions } = await PullPermission({
831
- orgId: activeOrg.value,
832
- checksum: permissionChecksum.value
780
+ const { name } = await GetOrgName({ orgId });
781
+ const { permissions } = await PullPermission({
782
+ orgId,
783
+ checksum: ""
833
784
  });
834
- if (!update) return;
835
- eventBus.emit("updatePermission", [toPermissionObjects(permissions), permissions["checksum"] ?? ""]);
785
+ eventBus.emit("updateActiveOrg", [orgId, name]);
786
+ eventBus.emit("updatePermission", [toPermissionObjects(permissions), permissions.checksum ?? ""]);
787
+ return true;
836
788
  } catch (e) {
837
- console.error(e);
789
+ if (e === "org not found" || e === "org member not found") router.replace(`/main/${Date.now()}`);
790
+ return false;
838
791
  }
839
792
  }
840
- async function startTimer() {
841
- window.clearTimeout(handle);
842
- handle = window.setTimeout(async () => {
843
- await syncPermission();
844
- if (handle) await startTimer();
845
- }, 3e3);
846
- }
847
- function stopTimer() {
848
- window.clearTimeout(handle);
849
- handle = void 0;
850
- }
851
- if (base) {
852
- onMounted(async () => {
853
- await startTimer();
854
- });
855
- onBeforeUnmount(() => {
856
- stopTimer();
857
- });
793
+ async function fetch() {
794
+ if (!ignoreSyncOrg && !await syncOrg()) return;
795
+ await onRouteChange?.();
858
796
  }
797
+ onBeforeMount(async () => {
798
+ await fetch();
799
+ });
800
+ onBeforeRouteUpdate(async () => {
801
+ await fetch();
802
+ });
859
803
  async function handleBack() {
860
804
  if (!isEmpty(views)) {
861
805
  if (!hasView(views, "waitDlg")) popView(views);
@@ -881,61 +825,13 @@ function useMicroApp(globalStates, base, customBack) {
881
825
  return;
882
826
  }
883
827
  }
884
- if (!base) {
885
- onMounted(() => {
886
- window.addEventListener("keydown", onKeyDown);
887
- eventBus.on("back", handleBack);
888
- });
889
- onBeforeUnmount(() => {
890
- window.removeEventListener("keydown", onKeyDown);
891
- eventBus.off("back", handleBack);
892
- });
893
- }
894
- function onUpdateDark(val) {
895
- dark.value = val;
896
- }
897
- function onUpdateLocale(val) {
898
- locale.value = val;
899
- }
900
- const activeOrgNameRaw = ref("");
901
- watchEffect(() => {
902
- if (activeOrg.value === "public") activeOrgName.value = t("x-essential-lib.publicDomain");
903
- else activeOrgName.value = activeOrgNameRaw.value;
904
- });
905
- function onUpdateActiveOrg(val) {
906
- activeOrg.value = val[0];
907
- activeOrgNameRaw.value = val[1];
908
- }
909
- function onUpdatePermission(val) {
910
- permissionObjects.value = val[0];
911
- permissionChecksum.value = val[1];
912
- }
913
- function onUpdateLastAppPath(val) {
914
- lastAppPath.value = val;
915
- }
916
- function onSyncGlobalStates() {
917
- eventBus.emit("updateDark", dark.value);
918
- eventBus.emit("updateLocale", locale.value);
919
- eventBus.emit("updateActiveOrg", [activeOrg.value, activeOrgNameRaw.value]);
920
- eventBus.emit("updatePermission", [permissionObjects.value, permissionChecksum.value]);
921
- eventBus.emit("updateLastAppPath", lastAppPath.value);
922
- }
923
- onBeforeMount(() => {
924
- eventBus.on("updateDark", onUpdateDark);
925
- eventBus.on("updateLocale", onUpdateLocale);
926
- eventBus.on("updateActiveOrg", onUpdateActiveOrg);
927
- eventBus.on("updatePermission", onUpdatePermission);
928
- eventBus.on("updateLastAppPath", onUpdateLastAppPath);
929
- if (base) eventBus.on("syncGlobalStates", onSyncGlobalStates);
930
- else eventBus.emit("syncGlobalStates");
828
+ onMounted(() => {
829
+ window.addEventListener("keydown", onKeyDown);
830
+ eventBus.on("back", handleBack);
931
831
  });
932
832
  onBeforeUnmount(() => {
933
- eventBus.off("updateDark", onUpdateDark);
934
- eventBus.off("updateLocale", onUpdateLocale);
935
- eventBus.off("updateActiveOrg", onUpdateActiveOrg);
936
- eventBus.off("updatePermission", onUpdatePermission);
937
- eventBus.off("updateLastAppPath", onUpdateLastAppPath);
938
- if (base) eventBus.off("syncGlobalStates", onSyncGlobalStates);
833
+ window.removeEventListener("keydown", onKeyDown);
834
+ eventBus.off("back", handleBack);
939
835
  });
940
836
  }
941
837
 
@@ -1699,4 +1595,4 @@ async function loadLocaleMessageEssential(locale) {
1699
1595
  var src_default = { install };
1700
1596
 
1701
1597
  //#endregion
1702
- export { Permission, addView, appAppear, clearViews, closeWaitDlg, createAxios, src_default as default, delView, eventBus, getTypeColor, getTypeDefault, globalObjects, hasView, injectActiveOrg, injectActiveOrgName, injectDark, injectLastAppPath, injectLocale, injectPermissionChecksum, injectPermissionObjects, injectViews, isEmpty, isExist, lastView, loadLocaleMessageEssential, matchRouteMeta, messageError, messageInfo, messageSuccess, messageWarning, onBeforeEach, openConfirmDlg, openNumberDlg, openPromptDlg, openWaitDlg, popView, provideActiveOrg, provideActiveOrgName, provideDark, provideLastAppPath, provideLocale, providePermissionChecksum, providePermissionObjects, provideViews, routeTransName, toPermissionObjects, types, useColor, useMicroApp, usePermission, useSystem, useViewStack, verifyPermission, waitMs, waitUtil };
1598
+ export { Permission, addView, appAppear, clearViews, closeWaitDlg, createAxios, src_default as default, delView, eventBus, getTypeColor, getTypeDefault, globalObjects, hasView, injectDark, injectLocale, injectPermissionObjects, injectViews, isEmpty, isExist, lastView, loadLocaleMessageEssential, matchRouteMeta, messageError, messageInfo, messageSuccess, messageWarning, onBeforeEach, openConfirmDlg, openNumberDlg, openPromptDlg, openWaitDlg, popView, provideDark, provideLocale, providePermissionObjects, provideViews, routeTransName, toPermissionObjects, types, useColor, useGlobalStates, useMicroApp, usePermission, useSystem, useViewStack, verifyPermission, waitMs, waitUtil };
@@ -577,12 +577,12 @@ function toLower(value) {
577
577
  //#endregion
578
578
  //#region node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/index.d.ts
579
579
  var EventType = [
580
- 67,
580
+ 60,
581
581
  () => [],
582
582
  []
583
583
  ];
584
584
  var Handler = [
585
- 68,
585
+ 61,
586
586
  (T) => [T],
587
587
  [
588
588
  "",
@@ -591,7 +591,7 @@ var Handler = [
591
591
  ]
592
592
  ];
593
593
  var WildcardHandler = [
594
- 69,
594
+ 62,
595
595
  (T) => [
596
596
  Record,
597
597
  T,
@@ -609,7 +609,7 @@ var WildcardHandler = [
609
609
  ]
610
610
  ];
611
611
  var EventHandlerList = [
612
- 70,
612
+ 63,
613
613
  (T) => [
614
614
  T,
615
615
  Handler,
@@ -623,7 +623,7 @@ var EventHandlerList = [
623
623
  ]
624
624
  ];
625
625
  var WildCardEventHandlerList = [
626
- 71,
626
+ 64,
627
627
  (T) => [
628
628
  Record,
629
629
  T,
@@ -639,7 +639,7 @@ var WildCardEventHandlerList = [
639
639
  ]
640
640
  ];
641
641
  var EventHandlerMap = [
642
- 72,
642
+ 65,
643
643
  (Events) => [
644
644
  EventType,
645
645
  Record,
@@ -665,7 +665,7 @@ var EventHandlerMap = [
665
665
  ]
666
666
  ];
667
667
  var Emitter = [
668
- 73,
668
+ 66,
669
669
  (Key, Events) => [
670
670
  EventType,
671
671
  Record,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-essential-lib",
3
- "version": "0.10.20",
3
+ "version": "0.10.21",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -38,14 +38,15 @@
38
38
  "mitt": "^3.0.1",
39
39
  "oxfmt": "^0.55.0",
40
40
  "oxlint": "^1.70.0",
41
+ "picomatch": "^4.0.5",
41
42
  "rolldown": "^1.1.2",
42
43
  "sass": "^1.101.0",
43
44
  "tsdown": "^0.22.3",
44
45
  "typescript": "^6.0.3",
45
46
  "vite": "^8.0.16",
46
47
  "x-config-lib": "^0.1.5",
47
- "x-config-oxfmt": "^0.1.4",
48
- "x-config-oxlint": "^0.1.4"
48
+ "x-config-oxfmt": "^0.1.5",
49
+ "x-config-oxlint": "^0.1.6"
49
50
  },
50
51
  "peerDependencies": {
51
52
  "axios": "^1.18.0",
@@ -53,9 +54,5 @@
53
54
  "vue-i18n": "^11.4.6",
54
55
  "vue-router": "^5.1.0",
55
56
  "vuetify": "^4.1.2"
56
- },
57
- "lint-staged": {
58
- "*.{js,jsx,ts,tsx,vue}": "oxlint",
59
- "*": "oxfmt --no-error-on-unmatched-pattern"
60
57
  }
61
58
  }