@ctzy-web-client/web-base-client-vue 1.0.1
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/es/_virtual/_plugin-vue_export-helper.mjs +9 -0
- package/es/_virtual/_rollupPluginBabelHelpers.mjs +2830 -0
- package/es/application/Application2.mjs +42 -0
- package/es/application/MicroApplication.mjs +49 -0
- package/es/application/app.mjs +34 -0
- package/es/application/application.mjs +312 -0
- package/es/application/index.mjs +11 -0
- package/es/application/micro-application.mjs +59 -0
- package/es/constants/index.mjs +1 -0
- package/es/hooks/index.mjs +11 -0
- package/es/hooks/use-data-form/index.mjs +18 -0
- package/es/hooks/use-data-table/index.mjs +18 -0
- package/es/hooks/use-data-table-page/index.mjs +47 -0
- package/es/hooks/use-event-dispatcher/index.mjs +14 -0
- package/es/hooks/use-global-config/index.mjs +47 -0
- package/es/hooks/use-keydown/index.mjs +2 -0
- package/es/hooks/use-keydown/use-keydown.mjs +24 -0
- package/es/hooks/use-keydown/use-save-keydown.mjs +12 -0
- package/es/hooks/use-namespace/index.mjs +68 -0
- package/es/hooks/use-service/index.mjs +9 -0
- package/es/hooks/use-value/index.mjs +9 -0
- package/es/index.mjs +20 -0
- package/es/interceptors/RequestInterceptors.mjs +25 -0
- package/es/interceptors/RouterInterceptors.mjs +36 -0
- package/es/interceptors/index.mjs +2 -0
- package/es/ioc/ReactiveInstantiationService.mjs +14 -0
- package/es/ioc/index.mjs +1 -0
- package/es/utils/index.mjs +1 -0
- package/es/utils/pageDataParser.mjs +21 -0
- package/lib/_virtual/_plugin-vue_export-helper.js +13 -0
- package/lib/_virtual/_rollupPluginBabelHelpers.js +2948 -0
- package/lib/application/Application2.js +46 -0
- package/lib/application/MicroApplication.js +53 -0
- package/lib/application/app.js +38 -0
- package/lib/application/application.js +316 -0
- package/lib/application/index.js +18 -0
- package/lib/application/micro-application.js +63 -0
- package/lib/constants/index.js +2 -0
- package/lib/hooks/index.js +30 -0
- package/lib/hooks/use-data-form/index.js +22 -0
- package/lib/hooks/use-data-table/index.js +22 -0
- package/lib/hooks/use-data-table-page/index.js +51 -0
- package/lib/hooks/use-event-dispatcher/index.js +18 -0
- package/lib/hooks/use-global-config/index.js +52 -0
- package/lib/hooks/use-keydown/index.js +11 -0
- package/lib/hooks/use-keydown/use-keydown.js +28 -0
- package/lib/hooks/use-keydown/use-save-keydown.js +16 -0
- package/lib/hooks/use-namespace/index.js +73 -0
- package/lib/hooks/use-service/index.js +13 -0
- package/lib/hooks/use-value/index.js +13 -0
- package/lib/index.js +68 -0
- package/lib/interceptors/RequestInterceptors.js +29 -0
- package/lib/interceptors/RouterInterceptors.js +40 -0
- package/lib/interceptors/index.js +11 -0
- package/lib/ioc/ReactiveInstantiationService.js +18 -0
- package/lib/ioc/index.js +9 -0
- package/lib/utils/index.js +9 -0
- package/lib/utils/pageDataParser.js +25 -0
- package/package.json +37 -0
- package/src/application/Application.js +538 -0
- package/src/application/MicroApplication.js +67 -0
- package/src/application/app.vue +22 -0
- package/src/application/application.vue +36 -0
- package/src/application/index.js +11 -0
- package/src/application/micro-application.vue +56 -0
- package/src/constants/index.js +0 -0
- package/src/hooks/index.js +9 -0
- package/src/hooks/use-data-form/index.js +24 -0
- package/src/hooks/use-data-table/index.js +22 -0
- package/src/hooks/use-data-table-page/index.js +48 -0
- package/src/hooks/use-event-dispatcher/index.js +15 -0
- package/src/hooks/use-global-config/index.js +49 -0
- package/src/hooks/use-keydown/index.js +2 -0
- package/src/hooks/use-keydown/use-keydown.js +35 -0
- package/src/hooks/use-keydown/use-save-keydown.js +13 -0
- package/src/hooks/use-namespace/index.js +90 -0
- package/src/hooks/use-service/index.js +15 -0
- package/src/hooks/use-value/index.js +15 -0
- package/src/index.js +8 -0
- package/src/interceptors/RequestInterceptors.js +46 -0
- package/src/interceptors/RouterInterceptors.js +47 -0
- package/src/interceptors/index.js +2 -0
- package/src/ioc/ReactiveInstantiationService.js +29 -0
- package/src/ioc/index.js +1 -0
- package/src/utils/index.js +1 -0
- package/src/utils/pageDataParser.js +27 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { defineComponent, watch, provide, ref, openBlock, createElementBlock, normalizeClass, unref, renderSlot } from 'vue';
|
|
2
|
+
import { applicationKey } from '@ctzy-web-client/tokens';
|
|
3
|
+
import { useRoute } from 'vue-router';
|
|
4
|
+
import '../hooks/index.mjs';
|
|
5
|
+
import _export_sfc from '../_virtual/_plugin-vue_export-helper.mjs';
|
|
6
|
+
import { useNamespace } from '../hooks/use-namespace/index.mjs';
|
|
7
|
+
import { provideGlobalConfig } from '../hooks/use-global-config/index.mjs';
|
|
8
|
+
|
|
9
|
+
const __default__ = defineComponent({
|
|
10
|
+
name: "BwaApplication"
|
|
11
|
+
});
|
|
12
|
+
const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
|
|
13
|
+
props: {
|
|
14
|
+
application: {
|
|
15
|
+
type: Object,
|
|
16
|
+
required: true
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
setup(__props) {
|
|
20
|
+
const props = __props;
|
|
21
|
+
const ns = useNamespace("application");
|
|
22
|
+
watch(
|
|
23
|
+
useRoute(),
|
|
24
|
+
(currentRoute) => {
|
|
25
|
+
props.application.emitParentApplication("route-change", currentRoute);
|
|
26
|
+
},
|
|
27
|
+
{ immediate: true }
|
|
28
|
+
);
|
|
29
|
+
provide(applicationKey, ref(props.application));
|
|
30
|
+
provideGlobalConfig({ [applicationKey]: props.application }, null, true);
|
|
31
|
+
return (_ctx, _cache) => {
|
|
32
|
+
return openBlock(), createElementBlock("div", {
|
|
33
|
+
class: normalizeClass(unref(ns).b())
|
|
34
|
+
}, [
|
|
35
|
+
renderSlot(_ctx.$slots, "default")
|
|
36
|
+
], 2);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
var Application = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "application.vue"]]);
|
|
41
|
+
|
|
42
|
+
export { Application as default };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { loadMicroApp } from 'qiankun';
|
|
2
|
+
|
|
3
|
+
class MicroApplication {
|
|
4
|
+
constructor(options, application) {
|
|
5
|
+
options = options || {};
|
|
6
|
+
this.name = options.name;
|
|
7
|
+
this.entry = options.entry;
|
|
8
|
+
this.extendOptions = (options == null ? void 0 : options.extendOptions) || {};
|
|
9
|
+
this.ownerApplication = application;
|
|
10
|
+
this._microApp = null;
|
|
11
|
+
this.container = null;
|
|
12
|
+
}
|
|
13
|
+
_loadMicroApp() {
|
|
14
|
+
return loadMicroApp({
|
|
15
|
+
name: this.name,
|
|
16
|
+
entry: this.entry,
|
|
17
|
+
container: this.container,
|
|
18
|
+
props: {
|
|
19
|
+
extendOptions: this.extendOptions,
|
|
20
|
+
ownerApplication: this.ownerApplication
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async mountApplication() {
|
|
25
|
+
var _a;
|
|
26
|
+
if (((_a = this._microApp) == null ? void 0 : _a.getStatus()) === "UNMOUNTING") {
|
|
27
|
+
await this._microApp.unmountPromise();
|
|
28
|
+
}
|
|
29
|
+
if (!this._microApp) {
|
|
30
|
+
this.container = document.createElement("div");
|
|
31
|
+
this._microApp = this._loadMicroApp();
|
|
32
|
+
}
|
|
33
|
+
await this._microApp.mountPromise;
|
|
34
|
+
if (this._microApp.getStatus() === "NOT_MOUNTED") {
|
|
35
|
+
await this._microApp.mount();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async unmountApplication() {
|
|
39
|
+
if (!this._microApp) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (this._microApp.getStatus() !== "MOUNTED") {
|
|
43
|
+
await this._microApp.mountPromise;
|
|
44
|
+
}
|
|
45
|
+
await this._microApp.unmount();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { MicroApplication };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { toRefs, openBlock, createBlock, unref, withCtx, Suspense, createVNode } from 'vue';
|
|
2
|
+
import Application from './application2.mjs';
|
|
3
|
+
import { RouterView } from 'vue-router';
|
|
4
|
+
import _export_sfc from '../_virtual/_plugin-vue_export-helper.mjs';
|
|
5
|
+
|
|
6
|
+
const _sfc_main = {
|
|
7
|
+
__name: "app",
|
|
8
|
+
props: {
|
|
9
|
+
applicaiton: {
|
|
10
|
+
Object,
|
|
11
|
+
required: true
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
setup(__props) {
|
|
15
|
+
const props = __props;
|
|
16
|
+
const { applicaiton } = toRefs(props);
|
|
17
|
+
return (_ctx, _cache) => {
|
|
18
|
+
return openBlock(), createBlock(Application, { application: unref(applicaiton) }, {
|
|
19
|
+
default: withCtx(() => [
|
|
20
|
+
(openBlock(), createBlock(Suspense, null, {
|
|
21
|
+
default: withCtx(() => [
|
|
22
|
+
createVNode(unref(RouterView))
|
|
23
|
+
]),
|
|
24
|
+
_: 1
|
|
25
|
+
}))
|
|
26
|
+
]),
|
|
27
|
+
_: 1
|
|
28
|
+
}, 8, ["application"]);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var App = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "app.vue"]]);
|
|
33
|
+
|
|
34
|
+
export { App as default };
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { createApp, reactive, h } from 'vue';
|
|
2
|
+
import { createWebHistory, createMemoryHistory, createWebHashHistory, createRouter } from 'vue-router';
|
|
3
|
+
import { EventDispatcher, HttpRequest } from '@ctzy-web-client/support';
|
|
4
|
+
import { IocContainer, InstantiationService, SERVICE_INFO } from '@ctzy-web-client/ioc';
|
|
5
|
+
import { SimpleOrm, DataModelAdapter } from '@ctzy-web-client/data-model';
|
|
6
|
+
import { MicroApplication } from './MicroApplication.mjs';
|
|
7
|
+
import '../utils/index.mjs';
|
|
8
|
+
import App from './app.mjs';
|
|
9
|
+
import '../interceptors/index.mjs';
|
|
10
|
+
import '../ioc/index.mjs';
|
|
11
|
+
import { ReactiveInstantiationService } from '../ioc/ReactiveInstantiationService.mjs';
|
|
12
|
+
import { RequestInterceptors } from '../interceptors/RequestInterceptors.mjs';
|
|
13
|
+
import { RouterInterceptors } from '../interceptors/RouterInterceptors.mjs';
|
|
14
|
+
import { pageDataParser } from '../utils/pageDataParser.mjs';
|
|
15
|
+
|
|
16
|
+
class Application extends EventDispatcher {
|
|
17
|
+
constructor(appName, options) {
|
|
18
|
+
super();
|
|
19
|
+
this.appName = appName;
|
|
20
|
+
this.options = options || {};
|
|
21
|
+
this._app = null;
|
|
22
|
+
this._router = null;
|
|
23
|
+
this._history = null;
|
|
24
|
+
this._iocContainer = new IocContainer();
|
|
25
|
+
this.parent = null;
|
|
26
|
+
this.microApplications = [];
|
|
27
|
+
this.subApplications = [];
|
|
28
|
+
this._targetSelector = "";
|
|
29
|
+
this._extendOptions = null;
|
|
30
|
+
this._plugins = [];
|
|
31
|
+
this.global = options.global;
|
|
32
|
+
this.applicationSlots = /* @__PURE__ */ new Map();
|
|
33
|
+
if (!this.global) {
|
|
34
|
+
throw new Error("options.global \u4E0D\u5B58\u5728");
|
|
35
|
+
}
|
|
36
|
+
this._viewportMountPromise = null;
|
|
37
|
+
this.global.__INNER_APPLICATION__ = this;
|
|
38
|
+
this._initEvent();
|
|
39
|
+
this._initIocContainer();
|
|
40
|
+
this._setRequestInterceptors();
|
|
41
|
+
this._exportLifecycle();
|
|
42
|
+
this._resolveRoutesPromise = null;
|
|
43
|
+
this._mountResolve = null;
|
|
44
|
+
}
|
|
45
|
+
addApplicationSlot(type, id, slot) {
|
|
46
|
+
let withTypeSlots = this.applicationSlots.get(type);
|
|
47
|
+
if (!withTypeSlots) {
|
|
48
|
+
withTypeSlots = /* @__PURE__ */ new Map();
|
|
49
|
+
this.applicationSlots.set(type, withTypeSlots);
|
|
50
|
+
}
|
|
51
|
+
withTypeSlots.set(id, slot);
|
|
52
|
+
this.emit("slot-change", type);
|
|
53
|
+
this.emitParentApplication("slot-change", type);
|
|
54
|
+
}
|
|
55
|
+
removeApplicationSlot(type, id) {
|
|
56
|
+
const withTypeSlots = this.applicationSlots.get(type);
|
|
57
|
+
if (!withTypeSlots) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
withTypeSlots.delete(id);
|
|
61
|
+
this.emit("slot-change", type);
|
|
62
|
+
this.emitParentApplication("slot-change", type);
|
|
63
|
+
}
|
|
64
|
+
getApplicationSlots(type) {
|
|
65
|
+
let withTypeSlots = this.applicationSlots.get(type);
|
|
66
|
+
if (!withTypeSlots) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
return Array.from(withTypeSlots.values());
|
|
70
|
+
}
|
|
71
|
+
getIocContainer() {
|
|
72
|
+
return this._iocContainer;
|
|
73
|
+
}
|
|
74
|
+
getInstantiationService() {
|
|
75
|
+
return this.getIocContainer().getService(InstantiationService);
|
|
76
|
+
}
|
|
77
|
+
createInstance(Clazz, options) {
|
|
78
|
+
return this.getInstantiationService().createInstance(Clazz, options);
|
|
79
|
+
}
|
|
80
|
+
_initIocContainer() {
|
|
81
|
+
this._iocContainer.setInstantiationService(ReactiveInstantiationService);
|
|
82
|
+
this._iocContainer.registerService(RequestInterceptors, RequestInterceptors, {
|
|
83
|
+
overwrite: true
|
|
84
|
+
});
|
|
85
|
+
this._iocContainer.registerService(RouterInterceptors, RouterInterceptors, {
|
|
86
|
+
overwrite: true
|
|
87
|
+
});
|
|
88
|
+
this._iocContainer.registerService(HttpRequest, HttpRequest, {
|
|
89
|
+
overwrite: true,
|
|
90
|
+
args: [this.options.request || {}]
|
|
91
|
+
});
|
|
92
|
+
this._iocContainer.registerService(SimpleOrm, SimpleOrm, {
|
|
93
|
+
overwrite: false
|
|
94
|
+
});
|
|
95
|
+
this._iocContainer.registerService(DataModelAdapter, DataModelAdapter, {
|
|
96
|
+
overwrite: false
|
|
97
|
+
});
|
|
98
|
+
this._iocContainer.registerService("Application", Application, {
|
|
99
|
+
overwrite: false
|
|
100
|
+
});
|
|
101
|
+
this._iocContainer._serviceCollection.setInstance("Application", this);
|
|
102
|
+
this._iocContainer.registerValue("AppName", this.appName || "");
|
|
103
|
+
const delayRegisterServices = this.global.__DELAY_REGISTER_SERVICES__ || [];
|
|
104
|
+
for (const Service of delayRegisterServices) {
|
|
105
|
+
const serviceOptions = Service[SERVICE_INFO];
|
|
106
|
+
this._iocContainer.registerService(serviceOptions.value, Service, serviceOptions);
|
|
107
|
+
}
|
|
108
|
+
Reflect.deleteProperty(this.global, "__DELAY_REGISTER_SERVICES__");
|
|
109
|
+
}
|
|
110
|
+
_setRequestInterceptors() {
|
|
111
|
+
const httpRequest = this._iocContainer.getService(HttpRequest);
|
|
112
|
+
const requestInterceptors = this._iocContainer.getService(RequestInterceptors);
|
|
113
|
+
httpRequest.setOptions(this.options.request);
|
|
114
|
+
httpRequest.addRequestInterceptors(requestInterceptors.request.bind(requestInterceptors), requestInterceptors.requestError.bind(requestInterceptors));
|
|
115
|
+
httpRequest.addResponseInterceptors(requestInterceptors.response.bind(requestInterceptors), requestInterceptors.requestError.bind(requestInterceptors));
|
|
116
|
+
}
|
|
117
|
+
_setRouteInterceptors() {
|
|
118
|
+
const routerInterceptors = this._iocContainer.getService(RouterInterceptors);
|
|
119
|
+
this._router.beforeEach(routerInterceptors.beforeEach.bind(routerInterceptors));
|
|
120
|
+
this._router.beforeResolve(routerInterceptors.beforeResolve.bind(routerInterceptors));
|
|
121
|
+
this._router.afterEach(routerInterceptors.afterEach.bind(routerInterceptors));
|
|
122
|
+
}
|
|
123
|
+
_initVue() {
|
|
124
|
+
this._app = createApp({
|
|
125
|
+
setup: () => {
|
|
126
|
+
const applicaiton = reactive(this);
|
|
127
|
+
return () => h(this.options.app || App, {
|
|
128
|
+
applicaiton
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
this._plugins.forEach((plugin) => {
|
|
133
|
+
this._app.use(plugin);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
_initRouter() {
|
|
137
|
+
var _a;
|
|
138
|
+
if (!this._app) {
|
|
139
|
+
throw new Error("Vue\u5B9E\u4F8B\u4E0D\u5B58\u5728");
|
|
140
|
+
}
|
|
141
|
+
let history = null;
|
|
142
|
+
let base = this.options.routeBaseUrl || "/";
|
|
143
|
+
if (this.global.__POWERED_BY_QIANKUN__ && base === "/") {
|
|
144
|
+
base = `/${this.appName}`;
|
|
145
|
+
}
|
|
146
|
+
if ((_a = this._extendOptions) == null ? void 0 : _a.base) {
|
|
147
|
+
base = this._extendOptions.base + base;
|
|
148
|
+
}
|
|
149
|
+
switch (this.options.routeMode) {
|
|
150
|
+
case "hash":
|
|
151
|
+
history = createWebHashHistory(base);
|
|
152
|
+
break;
|
|
153
|
+
case "memory":
|
|
154
|
+
history = createMemoryHistory(base);
|
|
155
|
+
break;
|
|
156
|
+
default:
|
|
157
|
+
history = createWebHistory(base);
|
|
158
|
+
}
|
|
159
|
+
this._history = history;
|
|
160
|
+
this._router = createRouter({
|
|
161
|
+
history,
|
|
162
|
+
routes: []
|
|
163
|
+
});
|
|
164
|
+
this._setRouteInterceptors();
|
|
165
|
+
this._app.use(this._router);
|
|
166
|
+
}
|
|
167
|
+
async _resolveRoutes() {
|
|
168
|
+
let pageDefines = await pageDataParser(this.options.pages);
|
|
169
|
+
if (!this._router) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
pageDefines = pageDefines.filter((pageDefine) => typeof pageDefine.name === "string" && typeof pageDefine.route === "string");
|
|
173
|
+
const routes = pageDefines.map((define) => ({
|
|
174
|
+
name: define.name,
|
|
175
|
+
redirect: define.redirect,
|
|
176
|
+
path: define.route,
|
|
177
|
+
props: define.props || ((route) => Object.assign(route.params, route.query)),
|
|
178
|
+
meta: define.meta,
|
|
179
|
+
component: define.component,
|
|
180
|
+
children: []
|
|
181
|
+
}));
|
|
182
|
+
const rootRoutes = [];
|
|
183
|
+
for (let i = 0, length = routes.length; i < length; i++) {
|
|
184
|
+
const pageDefine = pageDefines[i];
|
|
185
|
+
const route = routes[i];
|
|
186
|
+
for (let j = 0; j < length; j++) {
|
|
187
|
+
if (i === j) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const innerPageDefine = pageDefines[j];
|
|
191
|
+
const innerRoute = routes[j];
|
|
192
|
+
if (pageDefine.name == null || innerPageDefine.name == null) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (pageDefine.name === innerPageDefine.parent) {
|
|
196
|
+
route.children.push(innerRoute);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (!pageDefine.parent) {
|
|
200
|
+
rootRoutes.push(route);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
for (const rootRoute of rootRoutes) {
|
|
204
|
+
this._router.addRoute(rootRoute);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
_initEvent() {
|
|
208
|
+
this.on("subApplicationCreate", (application) => {
|
|
209
|
+
this.subApplications.push(application);
|
|
210
|
+
});
|
|
211
|
+
this.on("subApplicationDestroy", (application) => {
|
|
212
|
+
this.subApplications = this.subApplications.filter((app) => app !== application);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
_exportLifecycle() {
|
|
216
|
+
if (!this.global.__POWERED_BY_QIANKUN__ || !this.appName) {
|
|
217
|
+
this._viewportMountPromise = Promise.resolve();
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (!this.global.moudleQiankunAppLifeCycles) {
|
|
221
|
+
this.global.moudleQiankunAppLifeCycles = {};
|
|
222
|
+
}
|
|
223
|
+
this.global.moudleQiankunAppLifeCycles[this.appName] = {
|
|
224
|
+
bootstrap: async (props) => {
|
|
225
|
+
},
|
|
226
|
+
mount: async ({
|
|
227
|
+
ownerApplication,
|
|
228
|
+
container,
|
|
229
|
+
extendOptions = {}
|
|
230
|
+
}) => {
|
|
231
|
+
var _a;
|
|
232
|
+
this.parent = ownerApplication || null;
|
|
233
|
+
this._extendOptions = extendOptions;
|
|
234
|
+
this._initVue();
|
|
235
|
+
this._initRouter();
|
|
236
|
+
if (ownerApplication) {
|
|
237
|
+
this._iocContainer.setParent(ownerApplication.getIocContainer());
|
|
238
|
+
}
|
|
239
|
+
if (this._targetSelector) {
|
|
240
|
+
this._app.mount(container.querySelector(this._targetSelector));
|
|
241
|
+
}
|
|
242
|
+
this._resolveRoutesPromise = this._resolveRoutes();
|
|
243
|
+
this._resolveRoutesPromise.then(() => {
|
|
244
|
+
this._resolveRoutesPromise = null;
|
|
245
|
+
});
|
|
246
|
+
if (typeof this._mountResolve === "function") {
|
|
247
|
+
this._mountResolve();
|
|
248
|
+
}
|
|
249
|
+
(_a = this.parent) == null ? void 0 : _a.emit("subApplicationCreate", this);
|
|
250
|
+
},
|
|
251
|
+
unmount: async () => {
|
|
252
|
+
var _a;
|
|
253
|
+
(_a = this.parent) == null ? void 0 : _a.emit("subApplicationDestroy", this);
|
|
254
|
+
this.parent = null;
|
|
255
|
+
this._history.destroy();
|
|
256
|
+
this._app.unmount();
|
|
257
|
+
this._app = null;
|
|
258
|
+
this._router = null;
|
|
259
|
+
this._extendOptions = null;
|
|
260
|
+
this._iocContainer.setParent(null);
|
|
261
|
+
if (this._targetSelector) {
|
|
262
|
+
this.unmount();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
getMicroApplication(name) {
|
|
268
|
+
var _a;
|
|
269
|
+
return (_a = this.microApplications.find((microApplication) => microApplication.name === name)) != null ? _a : null;
|
|
270
|
+
}
|
|
271
|
+
createMicroApplication(options) {
|
|
272
|
+
const microApplication = new MicroApplication(options, this);
|
|
273
|
+
this.microApplications.push(microApplication);
|
|
274
|
+
return microApplication;
|
|
275
|
+
}
|
|
276
|
+
emitParentApplication(eventName, ...args) {
|
|
277
|
+
if (!this.parent) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
this.parent.emit("fromSubApplication", this.appName, eventName, ...args);
|
|
281
|
+
}
|
|
282
|
+
use(plugin) {
|
|
283
|
+
this._plugins.push(plugin);
|
|
284
|
+
return this;
|
|
285
|
+
}
|
|
286
|
+
async mount(target) {
|
|
287
|
+
if (typeof target !== "string") {
|
|
288
|
+
throw new Error("mount: \u6307\u63A5\u53D7\u5B57\u7B26\u4E32\u53C2\u6570\u3002");
|
|
289
|
+
}
|
|
290
|
+
if (this.global.__POWERED_BY_QIANKUN__) {
|
|
291
|
+
const mountPromise = new Promise((resolve) => {
|
|
292
|
+
this._mountResolve = resolve;
|
|
293
|
+
});
|
|
294
|
+
this._targetSelector = target;
|
|
295
|
+
await mountPromise;
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
this._initVue();
|
|
299
|
+
this._initRouter();
|
|
300
|
+
this._app.mount(target);
|
|
301
|
+
this._resolveRoutesPromise = this._resolveRoutes();
|
|
302
|
+
this._resolveRoutesPromise.then(() => {
|
|
303
|
+
this._resolveRoutesPromise = null;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
unmount() {
|
|
307
|
+
var _a;
|
|
308
|
+
(_a = this._app) == null ? void 0 : _a.unmount();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export { Application };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { withInstall } from 'element-plus/es/utils/vue/install';
|
|
2
|
+
import Application from './application2.mjs';
|
|
3
|
+
import MicroApplication from './micro-application.mjs';
|
|
4
|
+
export { Application } from './Application.mjs';
|
|
5
|
+
|
|
6
|
+
const BwaApplication = withInstall(Application, {
|
|
7
|
+
MicroApplication
|
|
8
|
+
});
|
|
9
|
+
const BwaMicroApplication = withInstall(MicroApplication);
|
|
10
|
+
|
|
11
|
+
export { BwaApplication, BwaMicroApplication, BwaApplication as default };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { defineComponent, ref, computed, onMounted, onBeforeUnmount, withAsyncContext, setBlockTracking, createElementVNode, normalizeClass, unref } from 'vue';
|
|
2
|
+
import { applicationKey } from '@ctzy-web-client/tokens';
|
|
3
|
+
import '../hooks/index.mjs';
|
|
4
|
+
import _export_sfc from '../_virtual/_plugin-vue_export-helper.mjs';
|
|
5
|
+
import { useNamespace } from '../hooks/use-namespace/index.mjs';
|
|
6
|
+
import { useGlobalConfig } from '../hooks/use-global-config/index.mjs';
|
|
7
|
+
|
|
8
|
+
const __default__ = defineComponent({
|
|
9
|
+
name: "BwaMcrioApplication"
|
|
10
|
+
});
|
|
11
|
+
const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
|
|
12
|
+
props: {
|
|
13
|
+
name: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true
|
|
16
|
+
},
|
|
17
|
+
entry: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true
|
|
20
|
+
},
|
|
21
|
+
extendOptions: {
|
|
22
|
+
type: Object
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
async setup(__props) {
|
|
26
|
+
let __temp, __restore;
|
|
27
|
+
const props = __props;
|
|
28
|
+
const ns = useNamespace("application");
|
|
29
|
+
const application = useGlobalConfig(applicationKey);
|
|
30
|
+
const el = ref(null);
|
|
31
|
+
const microApplication = computed(
|
|
32
|
+
() => application.value.getMicroApplication(props.name) || application.value.createMicroApplication({
|
|
33
|
+
name: props.name,
|
|
34
|
+
entry: props.entry,
|
|
35
|
+
extendOptions: props.extendOptions
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
const mountApplicationPromise = microApplication.value.mountApplication();
|
|
39
|
+
onMounted(() => {
|
|
40
|
+
el.value.appendChild(microApplication.value.container);
|
|
41
|
+
});
|
|
42
|
+
onBeforeUnmount(() => {
|
|
43
|
+
el.value.removeChild(microApplication.value.container);
|
|
44
|
+
microApplication.value.unmountApplication();
|
|
45
|
+
});
|
|
46
|
+
;
|
|
47
|
+
[__temp, __restore] = withAsyncContext(() => mountApplicationPromise), await __temp, __restore();
|
|
48
|
+
return (_ctx, _cache) => {
|
|
49
|
+
return _cache[0] || (setBlockTracking(-1), _cache[0] = createElementVNode("div", {
|
|
50
|
+
ref_key: "el",
|
|
51
|
+
ref: el,
|
|
52
|
+
class: normalizeClass(unref(ns).b("mcrio"))
|
|
53
|
+
}, null, 2), setBlockTracking(1), _cache[0]);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
var MicroApplication = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "micro-application.vue"]]);
|
|
58
|
+
|
|
59
|
+
export { MicroApplication as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { provideGlobalConfig, useGlobalConfig } from './use-global-config/index.mjs';
|
|
2
|
+
export { defaultNamespace, useNamespace } from './use-namespace/index.mjs';
|
|
3
|
+
export { useDataForm } from './use-data-form/index.mjs';
|
|
4
|
+
export { useDataTable } from './use-data-table/index.mjs';
|
|
5
|
+
export { useService } from './use-service/index.mjs';
|
|
6
|
+
export { useValue } from './use-value/index.mjs';
|
|
7
|
+
import './use-keydown/index.mjs';
|
|
8
|
+
export { useEventDispatcher } from './use-event-dispatcher/index.mjs';
|
|
9
|
+
export { useDataTablePage } from './use-data-table-page/index.mjs';
|
|
10
|
+
export { useKeydown } from './use-keydown/use-keydown.mjs';
|
|
11
|
+
export { useSaveKeydown } from './use-keydown/use-save-keydown.mjs';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { DataForm } from '@ctzy-web-client/data-model';
|
|
3
|
+
import { applicationKey } from '@ctzy-web-client/tokens';
|
|
4
|
+
import { useGlobalConfig } from '../use-global-config/index.mjs';
|
|
5
|
+
|
|
6
|
+
const useDataForm = (model, options = {}) => {
|
|
7
|
+
const application = useGlobalConfig(applicationKey);
|
|
8
|
+
const dataForm = ref(application.value.createInstance(DataForm, {
|
|
9
|
+
args: [{
|
|
10
|
+
model,
|
|
11
|
+
...options
|
|
12
|
+
}]
|
|
13
|
+
}));
|
|
14
|
+
dataForm.value.init();
|
|
15
|
+
return dataForm;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { useDataForm };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { DataTable } from '@ctzy-web-client/data-model';
|
|
3
|
+
import { applicationKey } from '@ctzy-web-client/tokens';
|
|
4
|
+
import { useGlobalConfig } from '../use-global-config/index.mjs';
|
|
5
|
+
|
|
6
|
+
const useDataTable = (model, options = {}) => {
|
|
7
|
+
const application = useGlobalConfig(applicationKey);
|
|
8
|
+
const dataTable = ref(application.value.createInstance(DataTable, {
|
|
9
|
+
args: [{
|
|
10
|
+
model,
|
|
11
|
+
...options
|
|
12
|
+
}]
|
|
13
|
+
}));
|
|
14
|
+
dataTable.value.init();
|
|
15
|
+
return dataTable;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { useDataTable };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { unref } from 'vue';
|
|
2
|
+
import { useRouter, useRoute } from 'vue-router';
|
|
3
|
+
import { useEventDispatcher } from '../use-event-dispatcher/index.mjs';
|
|
4
|
+
|
|
5
|
+
const useDataTablePage = (dataTable, options = {}) => {
|
|
6
|
+
options = {
|
|
7
|
+
...options
|
|
8
|
+
};
|
|
9
|
+
options.currentPage = options.currentPage || "currentPage";
|
|
10
|
+
options.pageSize = options.pageSize || "pageSize";
|
|
11
|
+
const router = useRouter();
|
|
12
|
+
const route = useRoute();
|
|
13
|
+
let {
|
|
14
|
+
currentPage = unref(dataTable).pageNum,
|
|
15
|
+
pageSize = unref(dataTable).pageSize
|
|
16
|
+
} = unref(route).query;
|
|
17
|
+
currentPage = parseInt(currentPage);
|
|
18
|
+
pageSize = parseInt(pageSize);
|
|
19
|
+
if (isNaN(currentPage)) {
|
|
20
|
+
currentPage = unref(dataTable).pageNum;
|
|
21
|
+
}
|
|
22
|
+
if (isNaN(pageSize)) {
|
|
23
|
+
pageSize = unref(dataTable).pageSize;
|
|
24
|
+
}
|
|
25
|
+
unref(dataTable).pageNum = currentPage;
|
|
26
|
+
unref(dataTable).pageSize = pageSize;
|
|
27
|
+
useEventDispatcher(dataTable, "current-page-change", (currentPage2) => {
|
|
28
|
+
const query = unref(router.currentRoute).query;
|
|
29
|
+
router.replace({
|
|
30
|
+
query: {
|
|
31
|
+
...query,
|
|
32
|
+
currentPage: currentPage2
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
useEventDispatcher(dataTable, "page-size-change", (pageSize2) => {
|
|
37
|
+
const query = unref(router.currentRoute).query;
|
|
38
|
+
router.replace({
|
|
39
|
+
query: {
|
|
40
|
+
...query,
|
|
41
|
+
pageSize: pageSize2
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { useDataTablePage };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { onMounted, unref, onUnmounted } from 'vue';
|
|
2
|
+
|
|
3
|
+
const useEventDispatcher = (eventDispatcher, eventName, handler) => {
|
|
4
|
+
onMounted(() => {
|
|
5
|
+
unref(eventDispatcher).on(eventName, handler);
|
|
6
|
+
});
|
|
7
|
+
const off = () => {
|
|
8
|
+
unref(eventDispatcher).off(eventName, handler);
|
|
9
|
+
};
|
|
10
|
+
onUnmounted(off);
|
|
11
|
+
return off;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useEventDispatcher };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ref, getCurrentInstance, inject, computed, provide, unref } from 'vue';
|
|
2
|
+
import { configProviderContextKey } from '@ctzy-web-client/tokens';
|
|
3
|
+
|
|
4
|
+
const globalConfig = ref();
|
|
5
|
+
function useGlobalConfig(key, defaultValue) {
|
|
6
|
+
const config = getCurrentInstance() ? inject(configProviderContextKey, globalConfig) : globalConfig;
|
|
7
|
+
if (key) {
|
|
8
|
+
return computed(() => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
return (_b = (_a = config.value) == null ? void 0 : _a[key]) != null ? _b : defaultValue;
|
|
11
|
+
});
|
|
12
|
+
} else {
|
|
13
|
+
return config;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const provideGlobalConfig = (config, app, global = false) => {
|
|
17
|
+
var _a;
|
|
18
|
+
const inSetup = !!getCurrentInstance();
|
|
19
|
+
const oldConfig = inSetup ? useGlobalConfig() : void 0;
|
|
20
|
+
const provideFn = (_a = app == null ? void 0 : app.provide) != null ? _a : inSetup ? provide : void 0;
|
|
21
|
+
if (!provideFn) {
|
|
22
|
+
console.warn("provideGlobalConfig", "provideGlobalConfig() can only be used inside setup().");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const context = computed(() => {
|
|
26
|
+
const cfg = unref(config);
|
|
27
|
+
if (!(oldConfig == null ? void 0 : oldConfig.value))
|
|
28
|
+
return cfg;
|
|
29
|
+
return mergeConfig(oldConfig.value, cfg);
|
|
30
|
+
});
|
|
31
|
+
provideFn(configProviderContextKey, context);
|
|
32
|
+
if (global || !globalConfig.value) {
|
|
33
|
+
globalConfig.value = context.value;
|
|
34
|
+
}
|
|
35
|
+
return context;
|
|
36
|
+
};
|
|
37
|
+
const mergeConfig = (a, b) => {
|
|
38
|
+
var _a;
|
|
39
|
+
const keys = [.../* @__PURE__ */ new Set([...Reflect.ownKeys(a), ...Reflect.ownKeys(b)])];
|
|
40
|
+
const obj = {};
|
|
41
|
+
for (const key of keys) {
|
|
42
|
+
obj[key] = (_a = b[key]) != null ? _a : a[key];
|
|
43
|
+
}
|
|
44
|
+
return obj;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { provideGlobalConfig, useGlobalConfig };
|