zova-ui-empty 5.0.137 → 5.0.138

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zova-ui-empty",
3
- "version": "5.0.137",
3
+ "version": "5.0.138",
4
4
  "description": "A vue3 empty framework with ioc",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -35,7 +35,8 @@
35
35
  "vue": "^3.4.29",
36
36
  "vue-router": "^4.3.3",
37
37
  "zod": "^3.23.8",
38
- "zova": "^5.0.100",
38
+ "zova": "^5.0.101",
39
+ "zova-module-a-data": "^5.0.3",
39
40
  "zova-module-a-pinia": "^5.0.18",
40
41
  "zova-module-a-router": "^5.0.38",
41
42
  "zova-module-a-style": "^5.0.12"
@@ -51,5 +52,5 @@
51
52
  "zova-vite": "^1.0.105"
52
53
  },
53
54
  "license": "MIT",
54
- "gitHead": "90bb78df182aa8db862d6b44e86d23aa33b195fa"
55
+ "gitHead": "32a2f957769f38b297d22235e188478b92b9301e"
55
56
  }
package/src/boot/main.ts CHANGED
@@ -1,15 +1,13 @@
1
1
  import { createApp } from 'vue';
2
- import createRouter from './router.js';
3
- import App from './app.vue';
2
+ import App from './app/index.vue';
4
3
  import { zova } from './zova.js';
5
4
 
6
5
  import '../css/settings.scss';
7
6
 
8
- async function start({ app, router }) {
9
- await zova({ app, router });
10
- app.use(router);
7
+ async function start({ app }) {
8
+ await zova({ app });
11
9
  app.mount('#app');
12
10
  }
13
11
 
14
12
  const app = createApp(App);
15
- start({ app, router: createRouter() });
13
+ start({ app });
package/src/boot/zova.ts CHANGED
@@ -6,9 +6,7 @@ import { modulesMeta } from '../../.zova/modules-meta.js';
6
6
  import { AppMonkey } from '../front/config/monkey.js';
7
7
  import { locales } from '../front/config/locales.js';
8
8
  import config from '../../.zova/config.js';
9
- import { Router } from 'vue-router';
10
9
 
11
- export async function zova({ app, router }: { app: App; router: Router }) {
12
- app.provide('a-router:appRouter', router);
10
+ export async function zova({ app }: { app: App }) {
13
11
  await PluginZova.install(app, { modulesMeta, AppMonkey, locales, config });
14
12
  }
@@ -13,8 +13,8 @@ export class AppMonkey extends BeanSimple implements IMonkeyApp, IMonkeySystem,
13
13
  async moduleLoading(_module: IModule) {}
14
14
  async moduleLoaded(_module: IModule) {}
15
15
  async configLoaded(_module: IModule, _config) {}
16
- async appInitialize() {}
17
- async appInitialized() {}
16
+ async appInitialize(_bean: BeanContainerLike) {}
17
+ async appInitialized(_bean: BeanContainerLike) {}
18
18
  async beanInit(_bean: BeanContainerLike, _beanInstance: BeanBase) {}
19
19
  async beanInited(_bean: BeanContainerLike, _beanInstance: BeanBase) {}
20
20
  beanDispose(_bean: BeanContainerLike, _beanInstance: BeanBase) {}
@@ -0,0 +1,61 @@
1
+ import { Bean, BeanBase } from 'zova';
2
+ import axios, { AxiosInstance } from 'axios';
3
+ import { markRaw } from 'vue';
4
+
5
+ const SymbolApi = Symbol('SymbolApi');
6
+
7
+ export type BeanApiLike = BeanApi & AxiosInstance;
8
+
9
+ // const __ApiMethods = ['delete', 'get', 'head', 'options', 'post', 'put', 'patch'];
10
+
11
+ @Bean({ scene: 'bean', name: 'api', containerScope: 'ctx' })
12
+ export class BeanApi extends BeanBase {
13
+ private [SymbolApi]: AxiosInstance;
14
+
15
+ protected async __init__() {
16
+ const baseURL = `${this.app.config.api.baseURL || ''}${this.app.config.api.prefix || ''}/`;
17
+ this[SymbolApi] = markRaw(axios.create({ baseURL }));
18
+ this._addInterceptors(this[SymbolApi]);
19
+ }
20
+
21
+ protected __get__(prop) {
22
+ return this[SymbolApi] && this[SymbolApi][prop];
23
+ }
24
+
25
+ private _addInterceptors(api: AxiosInstance) {
26
+ // request
27
+ api.interceptors.request.use(
28
+ config => {
29
+ if (this.app.config.base.jwt) {
30
+ config.headers.Authorization = 'Bearer ';
31
+ }
32
+ return config;
33
+ },
34
+ error => {
35
+ return Promise.reject(error);
36
+ },
37
+ );
38
+ // response
39
+ api.interceptors.response.use(
40
+ response => {
41
+ const contentType = response.headers['content-type'];
42
+ if (!contentType || contentType.indexOf('application/json') === -1) return response;
43
+ if (response.data.code !== 0) {
44
+ const error = new Error();
45
+ error.code = response.data.code;
46
+ error.message = response.data.message;
47
+ return Promise.reject(error);
48
+ }
49
+ // return data
50
+ return response.data.data;
51
+ },
52
+ error => {
53
+ if (error.response) {
54
+ error.code = (error.response.data && error.response.data.code) || error.response.status;
55
+ error.message = (error.response.data && error.response.data.message) || error.response.statusText;
56
+ }
57
+ return Promise.reject(error);
58
+ },
59
+ );
60
+ }
61
+ }
@@ -1,13 +1,13 @@
1
1
  import { BeanBase, BeanContainerLike, BeanSimple, IMonkeySystem } from 'zova';
2
2
  import axios from 'axios';
3
- import { StoreApiLike } from './bean/store.api.js';
3
+ import { BeanApiLike } from './bean/bean.api.js';
4
4
 
5
5
  export class Monkey extends BeanSimple implements IMonkeySystem {
6
- async appInitialize() {
6
+ async appInitialize(bean: BeanContainerLike) {
7
7
  this.app.meta.$axios = axios;
8
- this.app.meta.$api = (await this.app.bean._getBean('home-api.store.api', false)) as StoreApiLike;
8
+ this.app.meta.$api = (await bean._getBean('home-api.bean.api', false)) as BeanApiLike;
9
9
  }
10
- async appInitialized() {}
10
+ async appInitialized(_bean: BeanContainerLike) {}
11
11
  async beanInit(bean: BeanContainerLike, beanInstance: BeanBase) {
12
12
  const self = this;
13
13
  bean.defineProperty(beanInstance, '$api', {
@@ -1,8 +1,8 @@
1
- export * from '../bean/store.api.js';
2
- import { StoreApi } from '../bean/store.api.js';
1
+ export * from '../bean/bean.api.js';
2
+ import { BeanApi } from '../bean/bean.api.js';
3
3
  import 'zova';
4
4
  declare module 'zova' {
5
5
  export interface IBeanRecord {
6
- 'home-api.store.api': StoreApi;
6
+ 'home-api.bean.api': BeanApi;
7
7
  }
8
8
  }
@@ -1,13 +1,13 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { StoreApiLike } from './bean/store.api.js';
2
+ import { BeanApiLike } from './bean/bean.api.js';
3
3
 
4
4
  import 'zova';
5
5
  declare module 'zova' {
6
6
  export interface AppMeta {
7
7
  $axios: AxiosInstance;
8
- $api: StoreApiLike;
8
+ $api: BeanApiLike;
9
9
  }
10
10
  export interface BeanBase {
11
- $api: StoreApiLike;
11
+ $api: BeanApiLike;
12
12
  }
13
13
  }
@@ -29,7 +29,7 @@ const __MenuData = [
29
29
 
30
30
  export default defineFakeRoute([
31
31
  {
32
- url: '/home/mock/getMenu',
32
+ url: '/home/layout/menu/select',
33
33
  method: 'get',
34
34
  response: () => {
35
35
  return {
@@ -1 +1 @@
1
- export {};
1
+ export * from './menu.js';
@@ -0,0 +1,9 @@
1
+ export interface ServiceMenuEntity {
2
+ title: string;
3
+ caption?: string;
4
+ icon?: string;
5
+ href?: string;
6
+ to?: string;
7
+ folder?: boolean;
8
+ separator?: boolean;
9
+ }
@@ -1 +1,5 @@
1
- export const services = {};
1
+ import menu from './menu.js';
2
+
3
+ export const services = {
4
+ menu,
5
+ };
@@ -0,0 +1,8 @@
1
+ import { ZovaApplication } from 'zova';
2
+ import { ServiceMenuEntity } from '../interface/menu.js';
3
+
4
+ export default (app: ZovaApplication) => {
5
+ return {
6
+ select: () => app.meta.$api.get<any, ServiceMenuEntity[]>('/home/layout/menu/select'),
7
+ };
8
+ };
@@ -0,0 +1,19 @@
1
+ import { Data } from 'zova';
2
+ import { BeanDataBase } from 'zova-module-a-data';
3
+ import { ScopeModule } from '../resource/this.js';
4
+
5
+ @Data()
6
+ export class DataMenu extends BeanDataBase<ScopeModule> {
7
+ select() {
8
+ return this.$useQuery({
9
+ queryKey: ['select'],
10
+ queryFn: async () => {
11
+ const data = await this.scope.service.menu.select();
12
+ return data.filter(item => {
13
+ if (!item.to) return true;
14
+ return this.$router.checkPathValid(item.to);
15
+ });
16
+ },
17
+ });
18
+ }
19
+ }
@@ -1,5 +1,7 @@
1
- import { BeanControllerBase, Local } from 'zova';
2
- import * as ControllerEssentialLink from '../../component/essentialLink/controller.js';
1
+ import { BeanControllerBase, Local, Use } from 'zova';
2
+ import { DataMenu } from '../../bean/data.menu.js';
3
+ import { DataQuery } from 'zova-module-a-data';
4
+ import { ServiceMenuEntity } from '../../api/index.js';
3
5
 
4
6
  export interface Props {}
5
7
 
@@ -7,25 +9,18 @@ export type Emits = {};
7
9
 
8
10
  export interface Slots {}
9
11
 
10
- export type TypeMenuItem = ControllerEssentialLink.Props & { folder?: boolean; separator?: boolean };
11
-
12
12
  @Local()
13
13
  export class ControllerLayoutDefault extends BeanControllerBase<unknown, Props, Emits, Slots> {
14
14
  static $propsDefault = {};
15
15
 
16
+ @Use()
17
+ $$dataMenu: DataMenu;
18
+
19
+ queryMenus: DataQuery<ServiceMenuEntity[]>;
16
20
  leftDrawerOpen: boolean = false;
17
- menu: TypeMenuItem[];
18
21
 
19
22
  protected async __init__() {
20
- await this.loadMenu();
21
- }
22
-
23
- async loadMenu() {
24
- const res = await this.$api.get('/home/mock/getMenu');
25
- this.menu = res.data.data.filter(item => {
26
- if (!item.to) return true;
27
- return this.$router.checkPathValid(item.to);
28
- });
23
+ this.queryMenus = this.$$dataMenu.select();
29
24
  }
30
25
 
31
26
  toggleLeftDrawer() {
@@ -1,13 +1,14 @@
1
1
  import { BeanRenderBase, Local } from 'zova';
2
- import type { ControllerLayoutDefault, TypeMenuItem } from './controller.js';
2
+ import type { ControllerLayoutDefault } from './controller.js';
3
3
  import { JSX } from 'vue/jsx-runtime';
4
4
  import EssentialLink from '../essentialLink/index.vue';
5
+ import { ServiceMenuEntity } from '../../api/index.js';
5
6
 
6
7
  export interface RenderLayoutDefault extends ControllerLayoutDefault {}
7
8
 
8
9
  @Local()
9
10
  export class RenderLayoutDefault extends BeanRenderBase {
10
- _renderMenuItem(item: TypeMenuItem) {
11
+ _renderMenuItem(item: ServiceMenuEntity) {
11
12
  if (item.separator) {
12
13
  return <div class="menu-separator"> - - - </div>;
13
14
  }
@@ -26,8 +27,9 @@ export class RenderLayoutDefault extends BeanRenderBase {
26
27
  );
27
28
  }
28
29
  _renderMenu() {
30
+ if (this.queryMenus.isLoading || !this.queryMenus.data) return;
29
31
  const domItems: JSX.Element[] = [];
30
- for (const item of this.menu) {
32
+ for (const item of this.queryMenus.data) {
31
33
  domItems.push(this._renderMenuItem(item));
32
34
  }
33
35
  return <div class="menu-list">{domItems}</div>;
@@ -1,4 +1,8 @@
1
+ export * from '../bean/data.menu.js';
2
+ import { DataMenu } from '../bean/data.menu.js';
1
3
  import 'zova';
2
4
  declare module 'zova' {
3
- export interface IBeanRecord {}
5
+ export interface IBeanRecord {
6
+ 'home-layout.data.menu': DataMenu;
7
+ }
4
8
  }
@@ -1,10 +1,10 @@
1
1
  import { Local } from 'zova';
2
2
  import { ScopeModule } from '../resource/this.js';
3
- import { StoreRouterLike, BeanRouterBase } from 'zova-module-a-router';
3
+ import { BeanRouterLike, BeanRouterBase } from 'zova-module-a-router';
4
4
 
5
5
  @Local()
6
6
  export class Router extends BeanRouterBase<ScopeModule> {
7
- protected onRouterGuards(router: StoreRouterLike) {
7
+ protected onRouterGuards(router: BeanRouterLike) {
8
8
  router.beforeEach(async _to => {
9
9
  //console.log(to);
10
10
  });
@@ -4,11 +4,11 @@ import { Router } from './local/router.js';
4
4
  export class Monkey extends BeanSimple implements IMonkeySystem {
5
5
  router: Router;
6
6
 
7
- async appInitialize() {
7
+ async appInitialize(bean: BeanContainerLike) {
8
8
  // router
9
- this.router = await this.bean._newBean(Router, false);
9
+ this.router = await bean._newBean(Router, false);
10
10
  }
11
- async appInitialized() {}
11
+ async appInitialized(_bean: BeanContainerLike) {}
12
12
 
13
13
  async beanInit(_bean: BeanContainerLike, _beanInstance: BeanBase) {}
14
14
  async beanInited(_bean: BeanContainerLike, _beanInstance: BeanBase) {}
@@ -1,22 +0,0 @@
1
- import { BeanBase, Store } from 'zova';
2
- import axios, { AxiosInstance } from 'axios';
3
- import { markRaw } from 'vue';
4
-
5
- const SymbolApi = Symbol('SymbolApi');
6
-
7
- export type StoreApiLike = StoreApi & AxiosInstance;
8
-
9
- // const __ApiMethods = ['delete', 'get', 'head', 'options', 'post', 'put', 'patch'];
10
-
11
- @Store()
12
- export class StoreApi extends BeanBase {
13
- private [SymbolApi]: AxiosInstance;
14
-
15
- protected async __init__() {
16
- const baseURL = `${this.app.config.api.baseURL || ''}${this.app.config.api.prefix || ''}/`;
17
- this[SymbolApi] = markRaw(axios.create({ baseURL }));
18
- }
19
- protected __get__(prop) {
20
- return this[SymbolApi] && this[SymbolApi][prop];
21
- }
22
- }