x-essential-lib 0.10.8 → 0.10.10

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,4 +1,4 @@
1
- import { n as EventType, t as Emitter } from "./vendor.homyhtbu.js";
1
+ import { n as EventType, t as Emitter } from "./vendor.nvyu21oc.js";
2
2
  import { Ref } from "vue";
3
3
  import { RouteLocationNormalized } from "vue-router";
4
4
  import { AxiosInstance } from "axios";
@@ -243,6 +243,9 @@ type PermissionObject = {
243
243
  type PermissionObjects = {
244
244
  [key: string]: PermissionObject;
245
245
  };
246
+ declare function toPermissionObjects(permissions: {
247
+ [key: string]: string;
248
+ }): PermissionObjects;
246
249
  declare function isExist(instanceTree: InstanceTree | undefined, instance: string): boolean;
247
250
  declare function verifyPermission(permissionObjects: PermissionObjects, permission: Permission, instance: string): boolean;
248
251
  //#endregion
@@ -251,6 +254,8 @@ declare function provideDark(dark: Ref<boolean>): void;
251
254
  declare function injectDark(): Ref<boolean>;
252
255
  declare function provideLocale(locale: Ref<string>): void;
253
256
  declare function injectLocale(): Ref<string>;
257
+ declare function provideActiveOrg(activeOrg: Ref<string>): void;
258
+ declare function injectActiveOrg(): Ref<string>;
254
259
  declare function providePermissionObjects(permissionObjects: Ref<PermissionObjects>): void;
255
260
  declare function injectPermissionObjects(): Ref<PermissionObjects>;
256
261
  declare function providePermissionChecksum(permissionChecksum: Ref<string>): void;
@@ -270,9 +275,15 @@ interface RouteMeta {
270
275
  }
271
276
  declare function matchRouteMeta(path: string): RouteMeta | undefined;
272
277
  declare const routeTransName: import("vue").Ref<string, string>;
273
- declare function onBeforeEach(to: RouteLocationNormalized, from: RouteLocationNormalized, lastAppPath: string): {
278
+ declare function onBeforeEach(to: RouteLocationNormalized, from: RouteLocationNormalized, lastAppPath: string): Promise<{
274
279
  path: string;
275
- } | undefined;
280
+ query?: undefined;
281
+ } | {
282
+ path: string;
283
+ query: {
284
+ orgId: string;
285
+ };
286
+ } | undefined>;
276
287
  //#endregion
277
288
  //#region src/utils/type.d.ts
278
289
  declare const types: readonly ["string", "number", "boolean", "array", "object", "any"];
@@ -290,7 +301,16 @@ declare function popView(views: Ref<string[]>): void;
290
301
  declare function clearViews(views: Ref<string[]>): void;
291
302
  //#endregion
292
303
  //#region src/composables/microApp.d.ts
293
- declare function useMicroApp(dark: Ref<boolean | undefined>, locale: Ref<string>, permissionObjects: Ref<PermissionObjects>, permissionChecksum: Ref<string>, lastAppPath: Ref<string>, views: Ref<string[]>, customBack?: (m: RouteMeta) => void): void;
304
+ interface States {
305
+ dark: Ref<boolean | undefined>;
306
+ locale: Ref<string>;
307
+ activeOrg: Ref<string>;
308
+ permissionObjects: Ref<PermissionObjects>;
309
+ permissionChecksum: Ref<string>;
310
+ lastAppPath: Ref<string>;
311
+ views: Ref<string[]>;
312
+ }
313
+ declare function useMicroApp(states: States, syncLocale: () => Promise<void>, customBack?: (m: RouteMeta) => void): void;
294
314
  //#endregion
295
315
  //#region src/composables/permission.d.ts
296
316
  declare function usePermission(): {
@@ -533,4 +553,4 @@ declare const _default: {
533
553
  install: (app: import("vue").App) => void;
534
554
  };
535
555
  //#endregion
536
- export { Permission, PermissionObjects, RouteMeta, Type, addView, appAppear, clearViews, closeWaitDlg, createAxios, _default as default, delView, eventBus, getTypeColor, getTypeDefault, globalObjects, hasView, injectDark, injectLastAppPath, injectLocale, injectPermissionChecksum, injectPermissionObjects, injectViews, isEmpty, isExist, lastView, loadLocaleMessageEssential, matchRouteMeta, messageError, messageInfo, messageSuccess, messageWarning, onBeforeEach, openConfirmDlg, openNumberDlg, openPromptDlg, openWaitDlg, popView, provideDark, provideLastAppPath, provideLocale, providePermissionChecksum, providePermissionObjects, provideViews, routeTransName, types, useColor, useMicroApp, usePermission, useSystem, useViewStack, verifyPermission, waitMs, waitUtil };
556
+ export { Permission, PermissionObjects, RouteMeta, Type, addView, appAppear, clearViews, closeWaitDlg, createAxios, _default as default, delView, eventBus, getTypeColor, getTypeDefault, globalObjects, hasView, injectActiveOrg, injectDark, injectLastAppPath, injectLocale, injectPermissionChecksum, injectPermissionObjects, injectViews, isEmpty, isExist, lastView, loadLocaleMessageEssential, matchRouteMeta, messageError, messageInfo, messageSuccess, messageWarning, onBeforeEach, openConfirmDlg, openNumberDlg, openPromptDlg, openWaitDlg, popView, provideActiveOrg, provideDark, provideLastAppPath, provideLocale, providePermissionChecksum, providePermissionObjects, provideViews, routeTransName, toPermissionObjects, types, useColor, useMicroApp, usePermission, useSystem, useViewStack, verifyPermission, waitMs, waitUtil };
package/dist/index.js CHANGED
@@ -1,10 +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.homyhtbu.js";
2
+ import { a as api, i as mitt_default, o as usePreferredDark, r as toLower } from "./vendor.nvyu21oc.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
6
  import { useRoute, useRouter } from "vue-router";
7
7
  import axios from "axios";
8
+ import { getErrorMessage } from "x-error-lib";
9
+ import { createAxios as createAxios$1, messageError as messageError$1 } from "x-essential-lib";
8
10
 
9
11
  //#region src/composables/color.ts
10
12
  function useColor() {
@@ -79,10 +81,6 @@ function onRespRejected(error, onError) {
79
81
  function onUnauthorized() {
80
82
  api.remove("accessToken");
81
83
  api.remove("refreshToken");
82
- api.remove("userId");
83
- api.remove("userName");
84
- api.remove("phone");
85
- api.remove("activeOrg");
86
84
  useRouter().replace({ path: "/passport/login" });
87
85
  }
88
86
 
@@ -369,6 +367,15 @@ let Permission = /* @__PURE__ */ function(Permission) {
369
367
  Permission["filter_table"] = "filter_table";
370
368
  return Permission;
371
369
  }({});
370
+ function toPermissionObjects(permissions) {
371
+ const permissionObjects = {};
372
+ for (const key in permissions) {
373
+ if (key === "checksum") continue;
374
+ const value = permissions[key];
375
+ permissionObjects[key] = JSON.parse(value);
376
+ }
377
+ return permissionObjects;
378
+ }
372
379
  function isExist(instanceTree, instance) {
373
380
  if (!instanceTree) return false;
374
381
  let curr = instanceTree;
@@ -392,47 +399,63 @@ function verifyPermission(permissionObjects, permission, instance) {
392
399
 
393
400
  //#endregion
394
401
  //#region src/utils/provideInject.ts
395
- const darkKey = "essentialDark";
396
- const localeKey = "essentialLocale";
397
- const permissionObjectsKey = "essentialPermissionObjects";
398
- const permissionChecksumKey = "essentialPermissionChecksum";
399
- const lastAppPathKey = "essentialLastAppPath";
400
- const viewsKey = "essentialViews";
401
402
  function provideDark(dark) {
402
- provide(darkKey, dark);
403
+ provide("essentialDark", dark);
403
404
  }
404
405
  function injectDark() {
405
- return inject(darkKey);
406
+ return inject("essentialDark");
406
407
  }
407
408
  function provideLocale(locale) {
408
- provide(localeKey, locale);
409
+ provide("essentialLocale", locale);
409
410
  }
410
411
  function injectLocale() {
411
- return inject(localeKey);
412
+ return inject("essentialLocale");
413
+ }
414
+ function provideActiveOrg(activeOrg) {
415
+ provide("essentialActiveOrg", activeOrg);
416
+ }
417
+ function injectActiveOrg() {
418
+ return inject("essentialActiveOrg");
412
419
  }
413
420
  function providePermissionObjects(permissionObjects) {
414
- provide(permissionObjectsKey, permissionObjects);
421
+ provide("essentialPermissionObjects", permissionObjects);
415
422
  }
416
423
  function injectPermissionObjects() {
417
- return inject(permissionObjectsKey);
424
+ return inject("essentialPermissionObjects");
418
425
  }
419
426
  function providePermissionChecksum(permissionChecksum) {
420
- provide(permissionChecksumKey, permissionChecksum);
427
+ provide("essentialPermissionChecksum", permissionChecksum);
421
428
  }
422
429
  function injectPermissionChecksum() {
423
- return inject(permissionChecksumKey);
430
+ return inject("essentialPermissionChecksum");
424
431
  }
425
432
  function provideLastAppPath(lastAppPath) {
426
- provide(lastAppPathKey, lastAppPath);
433
+ provide("essentialLastAppPath", lastAppPath);
427
434
  }
428
435
  function injectLastAppPath() {
429
- return inject(lastAppPathKey);
436
+ return inject("essentialLastAppPath");
430
437
  }
431
438
  function provideViews(views) {
432
- provide(viewsKey, views);
439
+ provide("viewsKey", views);
433
440
  }
434
441
  function injectViews() {
435
- return inject(viewsKey);
442
+ return inject("viewsKey");
443
+ }
444
+
445
+ //#endregion
446
+ //#region src/api/orgbase/instance.ts
447
+ const instance = createAxios$1({
448
+ baseUrl: "http://localhost/orgbase/",
449
+ onError: (error) => {
450
+ messageError$1(getErrorMessage(error));
451
+ }
452
+ });
453
+ if (window.API_URL) instance.defaults.baseURL = window.API_URL + "/orgbase/";
454
+
455
+ //#endregion
456
+ //#region src/api/orgbase/index.ts
457
+ function PullPermission(request) {
458
+ return instance.post("pullPermission", request);
436
459
  }
437
460
 
438
461
  //#endregion
@@ -610,21 +633,40 @@ function onBeforeChange(toPath, fromPath, lastAppPath) {
610
633
  function isHasAccessToken() {
611
634
  return !!api.get("accessToken");
612
635
  }
613
- function onBeforeEach(to, from, lastAppPath) {
636
+ async function syncPermission(orgId) {
637
+ const { permissions } = await PullPermission({
638
+ orgId,
639
+ checksum: ""
640
+ });
641
+ eventBus.emit("updatePermission", [toPermissionObjects(permissions), permissions["checksum"] ?? ""]);
642
+ }
643
+ async function onBeforeEach(to, from, lastAppPath) {
614
644
  const hasAccessToken = isHasAccessToken();
615
645
  const toRouteMeta = matchRouteMeta(to.path);
616
646
  if (!toRouteMeta) return;
617
- if (toRouteMeta.requireAuth && !hasAccessToken) {
618
- const toPath = "/passport/login";
619
- onBeforeChange(toPath, from.path, lastAppPath);
620
- return { path: toPath };
647
+ if (toRouteMeta.requireAuth && !hasAccessToken) return { path: `/passport/login` };
648
+ if (hasAccessToken && to.path.startsWith("/passport/")) return { path: `/main` };
649
+ const orgId = to.query.orgId;
650
+ if (to.path.startsWith("/passport/")) onBeforeChange(to.path, from.path, lastAppPath);
651
+ else if (to.path.startsWith("/main")) try {
652
+ if (!orgId) throw new Error(`orgId not specified`);
653
+ await syncPermission(orgId);
654
+ eventBus.emit("updateActiveOrg", orgId);
655
+ onBeforeChange(to.path, from.path, lastAppPath);
656
+ } catch {
657
+ return {
658
+ path: `/main/${Date.now()}`,
659
+ query: { orgId: "public" }
660
+ };
621
661
  }
622
- if (hasAccessToken && to.path.startsWith("/passport/")) {
623
- const toPath = "/main";
624
- onBeforeChange(toPath, from.path, lastAppPath);
625
- return { path: toPath };
662
+ else try {
663
+ if (!orgId) throw new Error(`orgId not specified`);
664
+ await syncPermission(orgId);
665
+ eventBus.emit("updateActiveOrg", orgId);
666
+ onBeforeChange(to.path, from.path, lastAppPath);
667
+ } catch {
668
+ return { path: `/main` };
626
669
  }
627
- onBeforeChange(to.path, from.path, lastAppPath);
628
670
  }
629
671
 
630
672
  //#endregion
@@ -689,9 +731,10 @@ function clearViews(views) {
689
731
 
690
732
  //#endregion
691
733
  //#region src/composables/microApp.ts
692
- function useMicroApp(dark, locale, permissionObjects, permissionChecksum, lastAppPath, views, customBack) {
734
+ function useMicroApp(states, syncLocale, customBack) {
693
735
  const route = useRoute();
694
736
  const router = useRouter();
737
+ const { dark, locale, activeOrg, permissionObjects, permissionChecksum, lastAppPath, views } = states;
695
738
  const prefDark = usePreferredDark();
696
739
  const finalDark = ref(false);
697
740
  watchEffect(() => {
@@ -700,16 +743,27 @@ function useMicroApp(dark, locale, permissionObjects, permissionChecksum, lastAp
700
743
  else d = prefDark.value;
701
744
  finalDark.value = d;
702
745
  });
746
+ const theme = useTheme();
747
+ watchEffect(async () => {
748
+ await theme.change(finalDark.value ? "dark" : "light");
749
+ });
750
+ let pending = true;
751
+ router.beforeEach(async (to, from) => {
752
+ await syncLocale();
753
+ pending = false;
754
+ return onBeforeEach(to, from, lastAppPath.value);
755
+ });
756
+ watch(locale, async () => {
757
+ if (pending) return;
758
+ await syncLocale();
759
+ });
703
760
  provideDark(finalDark);
704
761
  provideLocale(locale);
762
+ provideActiveOrg(activeOrg);
705
763
  providePermissionObjects(permissionObjects);
706
764
  providePermissionChecksum(permissionChecksum);
707
765
  provideLastAppPath(lastAppPath);
708
766
  provideViews(views);
709
- const theme = useTheme();
710
- watchEffect(async () => {
711
- await theme.change(finalDark.value ? "dark" : "light");
712
- });
713
767
  async function handleBack() {
714
768
  if (!isEmpty(views)) {
715
769
  if (!hasView(views, "waitDlg")) popView(views);
@@ -744,10 +798,12 @@ function useMicroApp(dark, locale, permissionObjects, permissionChecksum, lastAp
744
798
  function onUpdateLocale(val) {
745
799
  locale.value = val;
746
800
  }
801
+ function onUpdateActiveOrg(val) {
802
+ activeOrg.value = val;
803
+ }
747
804
  function onUpdatePermission(val) {
748
- const v = val;
749
- permissionObjects.value = v[0];
750
- permissionChecksum.value = v[1];
805
+ permissionObjects.value = val[0];
806
+ permissionChecksum.value = val[1];
751
807
  }
752
808
  function onUpdateLastAppPath(val) {
753
809
  lastAppPath.value = val;
@@ -755,6 +811,7 @@ function useMicroApp(dark, locale, permissionObjects, permissionChecksum, lastAp
755
811
  onBeforeMount(() => {
756
812
  eventBus.on("updateDark", onUpdateDark);
757
813
  eventBus.on("updateLocale", onUpdateLocale);
814
+ eventBus.on("updateActiveOrg", onUpdateActiveOrg);
758
815
  eventBus.on("updatePermission", onUpdatePermission);
759
816
  eventBus.on("updateLastAppPath", onUpdateLastAppPath);
760
817
  eventBus.emit("syncGlobalState");
@@ -762,6 +819,7 @@ function useMicroApp(dark, locale, permissionObjects, permissionChecksum, lastAp
762
819
  onBeforeUnmount(() => {
763
820
  eventBus.off("updateDark", onUpdateDark);
764
821
  eventBus.off("updateLocale", onUpdateLocale);
822
+ eventBus.off("updateActiveOrg", onUpdateActiveOrg);
765
823
  eventBus.off("updatePermission", onUpdatePermission);
766
824
  eventBus.off("updateLastAppPath", onUpdateLastAppPath);
767
825
  });
@@ -1527,4 +1585,4 @@ async function loadLocaleMessageEssential(locale) {
1527
1585
  var src_default = { install };
1528
1586
 
1529
1587
  //#endregion
1530
- export { Permission, addView, appAppear, clearViews, closeWaitDlg, createAxios, src_default as default, delView, eventBus, getTypeColor, getTypeDefault, globalObjects, hasView, injectDark, injectLastAppPath, injectLocale, injectPermissionChecksum, injectPermissionObjects, injectViews, isEmpty, isExist, lastView, loadLocaleMessageEssential, matchRouteMeta, messageError, messageInfo, messageSuccess, messageWarning, onBeforeEach, openConfirmDlg, openNumberDlg, openPromptDlg, openWaitDlg, popView, provideDark, provideLastAppPath, provideLocale, providePermissionChecksum, providePermissionObjects, provideViews, routeTransName, types, useColor, useMicroApp, usePermission, useSystem, useViewStack, verifyPermission, waitMs, waitUtil };
1588
+ export { Permission, addView, appAppear, clearViews, closeWaitDlg, createAxios, src_default as default, delView, eventBus, getTypeColor, getTypeDefault, globalObjects, hasView, injectActiveOrg, injectDark, injectLastAppPath, injectLocale, injectPermissionChecksum, injectPermissionObjects, injectViews, isEmpty, isExist, lastView, loadLocaleMessageEssential, matchRouteMeta, messageError, messageInfo, messageSuccess, messageWarning, onBeforeEach, openConfirmDlg, openNumberDlg, openPromptDlg, openWaitDlg, popView, provideActiveOrg, provideDark, provideLastAppPath, provideLocale, providePermissionChecksum, providePermissionObjects, provideViews, routeTransName, toPermissionObjects, types, useColor, 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
- 61,
580
+ 65,
581
581
  () => [],
582
582
  []
583
583
  ];
584
584
  var Handler = [
585
- 62,
585
+ 66,
586
586
  (T) => [T],
587
587
  [
588
588
  "",
@@ -591,7 +591,7 @@ var Handler = [
591
591
  ]
592
592
  ];
593
593
  var WildcardHandler = [
594
- 63,
594
+ 67,
595
595
  (T) => [
596
596
  Record,
597
597
  T,
@@ -609,7 +609,7 @@ var WildcardHandler = [
609
609
  ]
610
610
  ];
611
611
  var EventHandlerList = [
612
- 64,
612
+ 68,
613
613
  (T) => [
614
614
  T,
615
615
  Handler,
@@ -623,7 +623,7 @@ var EventHandlerList = [
623
623
  ]
624
624
  ];
625
625
  var WildCardEventHandlerList = [
626
- 65,
626
+ 69,
627
627
  (T) => [
628
628
  Record,
629
629
  T,
@@ -639,7 +639,7 @@ var WildCardEventHandlerList = [
639
639
  ]
640
640
  ];
641
641
  var EventHandlerMap = [
642
- 66,
642
+ 70,
643
643
  (Events) => [
644
644
  EventType,
645
645
  Record,
@@ -665,7 +665,7 @@ var EventHandlerMap = [
665
665
  ]
666
666
  ];
667
667
  var Emitter = [
668
- 67,
668
+ 71,
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.8",
3
+ "version": "0.10.10",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -23,6 +23,9 @@
23
23
  "lint-staged": "lint-staged",
24
24
  "prepare": "husky"
25
25
  },
26
+ "dependencies": {
27
+ "x-error-lib": "^0.6.3"
28
+ },
26
29
  "devDependencies": {
27
30
  "@types/js-cookie": "^3.0.6",
28
31
  "@types/lodash-es": "^4.17.12",