@arkxos/arkos-core 0.1.0

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.
Files changed (62) hide show
  1. package/README.md +36 -0
  2. package/ark_dist/ark-meta.json +45 -0
  3. package/ark_dist/css/370.fbd21c4a.css +65 -0
  4. package/ark_dist/index.html +23 -0
  5. package/ark_dist/js/370.b7feb826.js +3 -0
  6. package/ark_dist/js/370.b7feb826.js.LICENSE.txt +16 -0
  7. package/ark_dist/js/370.b7feb826.js.map +1 -0
  8. package/ark_dist/js/app.87081276.js +1 -0
  9. package/ark_proxy/entry.js +48 -0
  10. package/ark_proxy_es/entry.js +18 -0
  11. package/package.json +114 -0
  12. package/scripts/check.js +13 -0
  13. package/scripts/meta.js +21 -0
  14. package/scripts/prepublishOnly.js +28 -0
  15. package/src/App.vue +25 -0
  16. package/src/access/tokenStorage.ts +10 -0
  17. package/src/api/index.js +13 -0
  18. package/src/api/model/auth.js +88 -0
  19. package/src/api/model/common.js +49 -0
  20. package/src/api/model/demo.js +56 -0
  21. package/src/api/model/system.js +114 -0
  22. package/src/api/systemApi.js +16 -0
  23. package/src/assets/logo.png +0 -0
  24. package/src/components/HelloWorld.vue +40 -0
  25. package/src/components/index.ts +12 -0
  26. package/src/configs/subApp.ts +9 -0
  27. package/src/core/api/http.ts +490 -0
  28. package/src/core/apitest/axios_config.js +10 -0
  29. package/src/core/apitest/index.js +10 -0
  30. package/src/core/apitest/mock/user.js +10 -0
  31. package/src/core/config/index.js +84 -0
  32. package/src/core/config/myConfig.js +14 -0
  33. package/src/core/i18n/i18nBuilder.ts +41 -0
  34. package/src/core/puzzle/readme.txt +4 -0
  35. package/src/core/router/router.js +80 -0
  36. package/src/core/system.ts +312 -0
  37. package/src/directive/authDirective.ts +61 -0
  38. package/src/directive/index.ts +16 -0
  39. package/src/entrance/libProperties.ts +57 -0
  40. package/src/entrance/libTypes.ts +47 -0
  41. package/src/enums/LanguageEnum.ts +5 -0
  42. package/src/hooks/message.ts +81 -0
  43. package/src/lang/en_US.ts +28 -0
  44. package/src/lang/index.ts +73 -0
  45. package/src/lang/zh_CN.ts +27 -0
  46. package/src/loadApp.ts +4 -0
  47. package/src/main.ts +16 -0
  48. package/src/plugins/access.ts +88 -0
  49. package/src/plugins/accessPlugin.ts +76 -0
  50. package/src/plugins/acl/index.js +24 -0
  51. package/src/plugins/priv.ts +23 -0
  52. package/src/shims-vue.d.ts +6 -0
  53. package/src/store/index.ts +22 -0
  54. package/src/store/modules/systemStore.ts +31 -0
  55. package/src/types/axios.d.ts +13 -0
  56. package/src/types/func.ts +14 -0
  57. package/src/types/global.d.ts +108 -0
  58. package/src/types/layout.d.ts +59 -0
  59. package/src/types/mitt.d.ts +42 -0
  60. package/src/types/pinia.d.ts +94 -0
  61. package/src/types/views.d.ts +27 -0
  62. package/src/utils/mitt.ts +8 -0
@@ -0,0 +1,80 @@
1
+
2
+ import { createRouter, createWebHashHistory } from 'vue-router';
3
+ import { ElNotification } from 'element-plus';
4
+ import NProgress from 'nprogress'
5
+ import 'nprogress/nprogress.css'
6
+ import system from '../system';
7
+ import config from '../config/index'
8
+
9
+ // 创建一个路由器实例
10
+ const router = createRouter({
11
+ history: createWebHashHistory(),
12
+ base: '__dirname',
13
+ routes: [],
14
+ // 设置滚动条位置
15
+ scrollBehavior: to => {
16
+ if (document.getElementById('con')) {
17
+ if (to.meta.scrollTop) {
18
+ document.getElementById('con').scrollTop = to.meta.scrollTop;
19
+ } else {
20
+ document.getElementById('con').scrollTop = 0;
21
+ }
22
+ }
23
+ }
24
+ });
25
+
26
+ router.beforeEach((to, from, next) => {
27
+ markScroll(to, from, next);
28
+
29
+ NProgress.start()
30
+
31
+ // 动态标题
32
+ document.title = to.meta.title ? `${to.meta.title} - ${config.ArkosTitle}` : `${config.ArkosTitle}`
33
+
34
+ system.plugins.forEach((plugin) => {
35
+ if (!plugin.beforeRouter) {
36
+ return;
37
+ }
38
+ plugin.beforeRouter(to, from, next);
39
+ })
40
+
41
+ next();
42
+ });
43
+
44
+ router.afterEach((to, from) => {
45
+ // afterEach(to, from)
46
+ NProgress.done()
47
+ });
48
+
49
+ router.onError((error) => {
50
+ NProgress.done();
51
+ ElNotification.error({
52
+ title: '路由错误',
53
+ message: error.message
54
+ });
55
+ });
56
+
57
+ // 记录滚动条位置
58
+ function markScroll (to, from, next) {
59
+ if (document.getElementById('con')) { from.meta.scrollTop = document.getElementById('con').scrollTop; }
60
+ // 根据url打开标签
61
+ if (
62
+ !from.name &&
63
+ to.path != '/mainIndex' &&
64
+ to.name &&
65
+ PUZZLE_CONFIG.pageHome != to.name
66
+ ) {
67
+ // store.commit("ADD_TAB", to.name);
68
+ }
69
+ }
70
+
71
+ // 防止路由到错误地址
72
+ // router.beforeEach((to, from, next) => {
73
+ // if (to.matched.length > 0)
74
+ // next();
75
+ // });
76
+
77
+ // 错误捕获
78
+ // router.onError(err => { });
79
+
80
+ export default router;
@@ -0,0 +1,312 @@
1
+ import { sessionCache, errorHandler, tool } from '@arkxos/arkos-util'
2
+ import systemStore from '../store/modules/systemStore'
3
+ import { preFetchLib } from '@arkxio/ark-micro';
4
+ import api from '../api';
5
+
6
+ function handleMenus (menus, result) {
7
+ if (!menus) {
8
+ return;
9
+ }
10
+ // console.log('handleMenus', menus)
11
+ for (const item of menus) {
12
+ const isFolder = item.children && item.children.length > 0;
13
+ const isLeaf = !isFolder;
14
+ if (isLeaf) {
15
+ result.push(item);
16
+ } else if (item.children) {
17
+ handleMenus(item.children, result);
18
+ }
19
+ }
20
+ }
21
+
22
+ const system = {
23
+ plugins: [],
24
+ puzzleLoaders: {},
25
+ // devModuleImporter(customDevModuleImporter) {
26
+ // _import.devModuleImporter = customDevModuleImporter
27
+ // },
28
+ async dynamicLoadModule(type, name, host, version) {
29
+ console.log('dynamic load puzzle', type, name, version)
30
+ return preFetchLib(name)
31
+ // console.log('remoteModule', remoteModule)
32
+ // window.PUZZLE_SUCCESS = window.PUZZLE_SUCCESS || [];
33
+ // window.PUZZLE_SUCCESS.push(name);
34
+ // resolve({ default: remoteModule });
35
+ // })
36
+ },
37
+ staticRouters: [],
38
+ puzzles: [],
39
+ $pinia: undefined,
40
+ $router: undefined,
41
+
42
+ themeRootRoute: undefined,
43
+ installPlugin (plugin) {
44
+ this.plugins.push(plugin);
45
+ },
46
+ // 路由数据处理
47
+ fixMenuPath (menus, parentMenu, puzzleCode) {
48
+ menus.forEach(menu => {
49
+ // const puzzlePath = menu.puzzleCode.replace('/', '_')
50
+
51
+ if (!menu.path.startsWith('http') && !menu.path.startsWith('/')) {
52
+ menu.path = parentMenu?.path + '/' + menu.path
53
+ }
54
+ if (menu.children) {
55
+ this.fixMenuPath(menu.children, menu, menu.puzzleCode)
56
+ }
57
+ })
58
+ },
59
+ async queryMenus () {
60
+ const menusResponse = await api.system.menu.myMenus.get()
61
+ const responseData = menusResponse.data;
62
+ const menus = responseData.menu || responseData;
63
+
64
+ tool.data.set('MENU', menus)
65
+ if (responseData.permissions) {
66
+ tool.data.set('PERMISSIONS', responseData.permissions)
67
+ }
68
+
69
+ tool.data.set('DASHBOARDGRID', responseData?.dashboardGrid)
70
+
71
+ console.log('queryMenus', menus);
72
+ this.fixMenuPath(menus);
73
+ console.log('fixedMenus', menus)
74
+
75
+ const puzzleInfos = {};
76
+ menus.forEach(item => {
77
+ if (!item.appCode) {
78
+ return;
79
+ }
80
+ if (!puzzleInfos[item.appCode]) {
81
+ puzzleInfos[item.appCode] = {
82
+ puzzleCode: item.appCode,
83
+ menus: []
84
+ };
85
+ }
86
+ puzzleInfos[item.appCode].menus.push(item);
87
+ })
88
+ await this.assemblePuzzles(puzzleInfos, this.themeRootRoute);
89
+
90
+ // 替换 @arkxos/arkos-example
91
+ const exampleAppMenu = menus.find(item => item.appCode === '@arkxos/arkos-example')
92
+ const exampleAppMenuIndex = menus.indexOf(exampleAppMenu);
93
+ menus.splice(exampleAppMenuIndex, 1);
94
+
95
+ for (const puzzleCode in puzzleInfos) {
96
+ const puzzle = puzzleInfos[puzzleCode];
97
+ if (puzzle.staticMenus && puzzle.staticMenus.length > 0) {
98
+ this.fixMenuPath(puzzle.staticMenus);
99
+ menus.push(...puzzle.staticMenus)
100
+ }
101
+ }
102
+
103
+ systemStore().setMenus(menus);
104
+
105
+ return menus;
106
+ },
107
+ async assemblePuzzles (puzzleInfos, themeRootRoute) {
108
+ const pages = themeRootRoute.children;
109
+
110
+ // 尝试获取模块 / 异步获取
111
+ for (const puzzleCode in puzzleInfos) {
112
+ const puzzle = puzzleInfos[puzzleCode];
113
+ let puzzleLoader;
114
+ if (system.puzzleLoaders[puzzleCode]) {
115
+ puzzleLoader = system.puzzleLoaders[puzzleCode]
116
+ } else {
117
+ puzzleLoader = system.dynamicLoadModule
118
+ }
119
+ console.log('prepare load puzzle[' + puzzleCode + '], loader is ', puzzleLoader)
120
+ const p = await puzzleLoader('puzzles', puzzleCode, '', '')
121
+ {
122
+ console.log('load puzzle ' + puzzleCode, p)
123
+ console.log('import app[' + puzzle.puzzleCode + ']', p)
124
+
125
+ this.app.use(p)
126
+
127
+ // @ts-ignore
128
+ if (p.mockApis && window.ArkMock) {
129
+ // @ts-ignore
130
+ window.ArkMock.mockApiRequests(p.mockApis)
131
+ }
132
+
133
+ // 需要生成路由的菜单
134
+ // const flatMenus = [];
135
+ // // 扁平化授权的菜单,存储到 flatMenus
136
+ // handleMenus(puzzle.children, flatMenus);
137
+
138
+ // 路由
139
+ // const menuRoutes = [];
140
+ // if (p.staticRoutes) {
141
+ // menuRoutes.push(...p.staticRoutes);
142
+ // }
143
+ let puzzleMenus = puzzle.menus; // 后台查询出来的模块菜单
144
+ if (puzzleCode === '@arkxos/arkos-example') {
145
+ puzzleMenus = p.staticMenus;
146
+ }
147
+ puzzle.staticMenus = p.staticMenus;
148
+
149
+ const menuRouter = this.filterAsyncRouter(puzzleMenus, null, p.loadComponent) || [];
150
+ // if (p.loadComponent) {
151
+ // const routesFromMenu = p.buildRoute(flatMenus, puzzle.puzzleCode);
152
+ // menuRoutes.push(...routesFromMenu);
153
+ // }
154
+ let allRouters = []
155
+ console.log('allRouters add staticRoutes', allRouters)
156
+ if (menuRouter && menuRouter.length > 0) {
157
+ allRouters.push(...menuRouter)
158
+ }
159
+ console.log('allRouters add menuRouter', allRouters)
160
+ allRouters = this.flatAsyncRoutes(menuRouter)
161
+ if (p.staticRoutes && p.staticRoutes.length > 0) {
162
+ allRouters.push(...p.staticRoutes)
163
+ }
164
+ console.log('allRouters after flatAsyncRoutes', allRouters)
165
+ allRouters.forEach(item => {
166
+ system.$router.addRoute('layout', item)
167
+ })
168
+
169
+ console.log('system.$router', system.$router.getRoutes())
170
+
171
+ // if (!themeRootRoute.children) {
172
+ // themeRootRoute.children = []
173
+ // }
174
+ // themeRootRoute.children.push(...menuRoutes)
175
+
176
+ pages.push(...allRouters);
177
+
178
+ console.log('puzzle root route[' + puzzle.puzzleCode + ']', themeRootRoute)
179
+ // system.$router.addRoute(themeRootRoute);
180
+
181
+ // Store
182
+ for (const name in p.store) {
183
+ console.log('store name: ', name)
184
+ const userStore = p.store[name];
185
+ // execute user sotre will active the store
186
+ try {
187
+ userStore();
188
+ } catch (err) {
189
+ console.log(puzzle.id + ' store error,' + err)
190
+ }
191
+ // this.$store.registerModule(name, p.store[name]);
192
+ }
193
+ }
194
+ }
195
+ // 储存路由表
196
+ // systemStore
197
+
198
+ const store = system.$pinia._s.get('arkOsPermission');
199
+ if (store) {
200
+ store.setPages(pages);
201
+ }
202
+ console.log('permission store', store)
203
+ console.log('system.$pinia', system.$pinia)
204
+ const store2 = system.$pinia._s.get('arkOsPermission');
205
+ console.log('permission store 2', store2)
206
+ },
207
+ // 转换
208
+ filterAsyncRouter(routerMap, parent, loadComponent) {
209
+ if (!routerMap) {
210
+ return null;
211
+ }
212
+ if (!Array.isArray(routerMap)) {
213
+ routerMap = [routerMap]
214
+ }
215
+ const accessedRouters = []
216
+ routerMap.forEach(item => {
217
+ item.meta = item.meta ? item.meta : {};
218
+ // 处理外部链接特殊路由
219
+ if (item.meta.type == 'iframe') {
220
+ item.meta.url = item.path;
221
+ item.path = `/i/${item.name}`;
222
+ item.meta.iframe = 'iframe'
223
+ }
224
+ // let path = parent ? (parent.path + '/' + item.path) : item.path
225
+ // console.log('route path: ', item.path)
226
+ // MAP转路由对象
227
+ const route = {
228
+ path: item.path,
229
+ query: item.query,
230
+ name: item.name,
231
+ meta: item.meta,
232
+ redirect: item.redirect,
233
+ children: item.children ? this.filterAsyncRouter(item.children, item, loadComponent) : null,
234
+ component: item.meta.type == 'iframe' ? null : loadComponent(item)
235
+ }
236
+ accessedRouters.push(route)
237
+ })
238
+ return accessedRouters
239
+ },
240
+ // 路由扁平化
241
+ flatAsyncRoutes(routes, breadcrumb = []) {
242
+ const res = []
243
+ routes.forEach(route => {
244
+ const tmp = { ...route }
245
+ if (tmp.children) {
246
+ const childrenBreadcrumb = [...breadcrumb]
247
+ childrenBreadcrumb.push(route)
248
+ const tmpRoute = { ...route }
249
+ tmpRoute.meta.breadcrumb = childrenBreadcrumb
250
+ delete tmpRoute.children
251
+ res.push(tmpRoute)
252
+ const childrenRoutes = this.flatAsyncRoutes(tmp.children, childrenBreadcrumb)
253
+ childrenRoutes.map(item => {
254
+ res.push(item)
255
+ })
256
+ } else {
257
+ const tmpBreadcrumb = [...breadcrumb]
258
+ tmpBreadcrumb.push(tmp)
259
+ tmp.meta.breadcrumb = tmpBreadcrumb
260
+ res.push(tmp)
261
+ }
262
+ })
263
+ return res
264
+ },
265
+ // installPlugin (plugin) {
266
+ // // this.plugins.push(plugin);
267
+ // this.app.use(plugin)
268
+ // },
269
+ async assembleTheme (themeInfo) {
270
+ console.log('load os theme ' + themeInfo.name)
271
+ const theme = await system.dynamicLoadModule('os-themes', themeInfo.name, themeInfo.host, themeInfo.version);
272
+
273
+ console.log('load theme after', theme)
274
+ // 路由注册
275
+ // console.log('this.$router.addRoute', this.$router.addRoute)
276
+ // this.$router.addRoute(...frame.routerStatic);
277
+ theme.routerStatic.forEach(item => {
278
+ this.staticRouters.push(item)
279
+ console.log('add route', item)
280
+ })
281
+ // Store 注册
282
+ for (const name in theme.store) {
283
+ const userStore = theme.store[name];
284
+ console.log('store name: ', name)
285
+ // execute user sotre will active the store
286
+ try {
287
+ userStore();
288
+ } catch (err) {
289
+ console.log(err)
290
+ }
291
+
292
+ // this.$store.registerModule(name, frame.store[name]);
293
+ }
294
+ // 嵌套路由 / 默认两级路由
295
+ const themeRootRouteList = theme.routerStatic.filter(item => item.path == '/');
296
+ let themeRootRoute;
297
+ if (themeRootRouteList && themeRootRouteList.length > 0) {
298
+ themeRootRoute = themeRootRouteList[0];
299
+ }
300
+
301
+ this.themeRootRoute = themeRootRoute;
302
+
303
+ this.app.use(theme)
304
+
305
+ console.log('load theme finish', theme)
306
+
307
+ // system.$router.addRoute(themeRootRoute)
308
+ return themeRootRoute;
309
+ },
310
+ }
311
+
312
+ export default system
@@ -0,0 +1,61 @@
1
+ import type { App } from 'vue';
2
+ import systemStore from '../store/modules/systemStore';
3
+ import { judementSameArr, tool } from '@arkxos/arkos-util';
4
+ import { hasPriv } from '../plugins/priv'
5
+
6
+ /**
7
+ * 用户权限指令
8
+ * @directive 单个权限验证(v-auth="xxx")
9
+ * @directive 多个权限验证,满足一个则显示(v-auths="[xxx,xxx]")
10
+ * @directive 多个权限验证,全部满足则显示(v-auth-all="[xxx,xxx]")
11
+ */
12
+ export function authDirective(app: App) {
13
+ // 单个权限验证(v-auth="xxx")
14
+ app.directive('auth', {
15
+ mounted(el, binding) {
16
+ // 「其他角色」按钮权限校验
17
+ const { value } = binding;
18
+ if (!hasPriv(value)) {
19
+ el.parentNode && el.parentNode.removeChild(el);
20
+ }
21
+ }
22
+ });
23
+ // 多个权限验证,满足一个则显示(v-auths="[xxx,xxx]")
24
+ app.directive('auths', {
25
+ mounted(el, binding) {
26
+ if (!hasPriv(binding.value)) {
27
+ el.parentNode && el.parentNode.removeChild(el);
28
+ }
29
+ }
30
+ });
31
+ // 多个权限验证,全部满足则显示(v-auth-all="[xxx,xxx]")
32
+ app.directive('auth-all', {
33
+ mounted(el, binding) {
34
+ const stores = systemStore();
35
+ const flag = judementSameArr(binding.value, stores.userInfo.permissions);
36
+ if (!flag) {
37
+ el.parentNode.removeChild(el);
38
+ }
39
+ },
40
+ });
41
+
42
+ // 角色权限
43
+ app.directive('roles', {
44
+ mounted(el, binding) {
45
+ const { value } = binding;
46
+ // const { roles } = useUserStore();
47
+ const roles = tool.data.get('roles');
48
+ if (value && value instanceof Array && value.length > 0) {
49
+ const hasRole = roles.some((role: string) => {
50
+ return role === 'admin' || value.includes(role);
51
+ });
52
+ if (!hasRole) {
53
+ el.parentNode && el.parentNode.removeChild(el);
54
+ return false;
55
+ }
56
+ } else {
57
+ throw new Error("check roles! Like v-has-roles=\"['admin','test']\"");
58
+ }
59
+ },
60
+ });
61
+ }
@@ -0,0 +1,16 @@
1
+
2
+ import { App } from 'vue';
3
+ import { hasPriv } from '../plugins/priv'
4
+ import { authDirective } from './authDirective';
5
+
6
+ export const installPlugin = function (app: App) {
7
+ console.log('installPlugin priv')
8
+
9
+ // 用户权限指令
10
+ authDirective(app);
11
+
12
+ app.config.globalProperties.hasPriv = hasPriv;
13
+ app.config.globalProperties.hasAuthority = hasPriv;
14
+
15
+ console.log('app.config.globalProperties', app.config.globalProperties)
16
+ };
@@ -0,0 +1,57 @@
1
+ /*
2
+ |--------------------------------------------------------------------------
3
+ |
4
+ | 这些组件暴露给使用方
5
+ |
6
+ |--------------------------------------------------------------------------
7
+ */
8
+ import system from '../core/system'
9
+ import router from '../core/router/router'
10
+ import store from '../store';
11
+ import systemStore from '../store/modules/systemStore'
12
+ import request, { http, globalHeaders } from '../core/api/http'
13
+ import config from '../core/config/index'
14
+ import api from '../api'
15
+ import { installPlugin } from '../directive/index'
16
+ import accessPlugin from '../plugins/accessPlugin'
17
+ import access from '../plugins/access'
18
+ import { getToken, removeToken, setToken } from '../access/tokenStorage'
19
+ import { LanguageEnum } from '../enums/LanguageEnum';
20
+ import i18n from '../lang/index'
21
+ import i18nBuilder from '../core/i18n/i18nBuilder'
22
+ import emitter from '../utils/mitt';
23
+ // import * as utils from "@arkxos/arkos-util/src/utils";
24
+ import { useMessage, useMessageBox } from '../hooks/message';
25
+ // system.init();
26
+ // system.installPlugin(accessPlugin)
27
+
28
+ export const comps = {
29
+ system,
30
+ installPlugin,
31
+ access,
32
+ accessPlugin,
33
+ router,
34
+ store,
35
+ systemStore,
36
+ request,
37
+ http,
38
+ globalHeaders,
39
+ config,
40
+ api,
41
+ getToken,
42
+ setToken,
43
+ removeToken,
44
+ LanguageEnum,
45
+ i18n,
46
+ i18nBuilder,
47
+
48
+ // tool
49
+ emitter,
50
+
51
+ // message
52
+ useMessage,
53
+ useMessageBox
54
+ }
55
+ export type LibProperties = typeof comps;
56
+
57
+ export default comps
@@ -0,0 +1,47 @@
1
+ /*
2
+ |--------------------------------------------------------------------------
3
+ |
4
+ | 组件类型导出文件,同时也作为 rollup 的打包入口文件,因只提供类型,rollup 打包后是一个
5
+ | 仅包含 hel-lib-proxy 的空壳文件,对模块使用方的包体构建大小无影响
6
+ | 模块使用方 通过 npm i xxx-lib 后,只要在头文件处执行过 preFetchLib
7
+ | 则整个项目项使用本地模块一样载入提供方的组件,并可以点击到 node_modules 查看源码
8
+ |
9
+ |--------------------------------------------------------------------------
10
+ */
11
+ import type { LibProperties } from './libProperties';
12
+ import { exposeLib } from '@arkxio/ark-lib-proxy';
13
+ import { LIB_NAME } from '../configs/subApp';
14
+
15
+ export const lib = exposeLib<LibProperties>(LIB_NAME);
16
+
17
+ // suport writing: import { regs, num, myMod } from 'hel-tpl-remote-lib';
18
+ export const {
19
+ system,
20
+ installPlugin,
21
+ access,
22
+ accessPlugin,
23
+ router,
24
+ store,
25
+ systemStore,
26
+ request,
27
+ http,
28
+ globalHeaders,
29
+ config,
30
+ api,
31
+ getToken,
32
+ setToken,
33
+ removeToken,
34
+ LanguageEnum,
35
+ i18n,
36
+ i18nBuilder,
37
+
38
+ emitter,
39
+
40
+ // message
41
+ useMessage,
42
+ useMessageBox
43
+ } = lib;
44
+
45
+ export type Lib = LibProperties;
46
+
47
+ export default lib;
@@ -0,0 +1,5 @@
1
+ export enum LanguageEnum {
2
+ zh_CN = 'zh-cn',
3
+
4
+ en_US = 'en_US'
5
+ }
@@ -0,0 +1,81 @@
1
+ import { ElMessage, ElMessageBox } from 'element-plus';
2
+ // import i18n from '../i18n';
3
+ import i18n from '../lang/index'
4
+ const { t } = i18n.global;
5
+
6
+ interface MessageImplements {
7
+ info(title: string): void;
8
+ wraning(title: string): void;
9
+ success(title: string): void;
10
+ error(title: string): void;
11
+ }
12
+
13
+ export function useMessage() {
14
+ class MessageClass implements MessageImplements {
15
+ // 普通提示
16
+ info(title: string): void {
17
+ ElMessage.info(title);
18
+ }
19
+
20
+ // 警告提示
21
+ wraning(title: string): void {
22
+ ElMessage.warning(title);
23
+ }
24
+
25
+ // 成功提示
26
+ success(title: string): void {
27
+ ElMessage.success(title);
28
+ }
29
+
30
+ // 错误提示
31
+ error(title: string): void {
32
+ ElMessage.error(title);
33
+ }
34
+ }
35
+
36
+ return new MessageClass();
37
+ }
38
+
39
+ export function useMessageBox() {
40
+ class MessageBoxClass implements MessageImplements {
41
+ // 普通提示
42
+ info(msg: string): void {
43
+ ElMessageBox.alert(msg, t('message.box.title'));
44
+ }
45
+
46
+ // 警告提示
47
+ wraning(msg: string): void {
48
+ ElMessageBox.alert(msg, t('message.box.title'), { type: 'warning' });
49
+ }
50
+
51
+ // 成功提示
52
+ success(msg: string): void {
53
+ ElMessageBox.alert(msg, t('message.box.title'), { type: 'success' });
54
+ }
55
+
56
+ // 错误提示
57
+ error(msg: string): void {
58
+ ElMessageBox.alert(msg, t('message.box.title'), { type: 'error' });
59
+ }
60
+
61
+ // 确认窗体
62
+ confirm(msg: string) {
63
+ return ElMessageBox.confirm(msg, t('message.box.title'), {
64
+ confirmButtonText: t('common.confirmButtonText'),
65
+ cancelButtonText: t('common.cancelButtonText'),
66
+ type: 'warning',
67
+ });
68
+ }
69
+
70
+ // 提交内容
71
+ prompt(msg: string) {
72
+ return ElMessageBox.prompt(msg, t('message.box.title'), {
73
+ confirmButtonText: t('common.confirmButtonText'),
74
+ cancelButtonText: t('common.cancelButtonText'),
75
+ type: 'warning',
76
+ });
77
+ }
78
+ }
79
+
80
+ return new MessageBoxClass();
81
+ }
@@ -0,0 +1,28 @@
1
+ export default {
2
+ // 路由国际化
3
+ route: {
4
+ dashboard: 'Dashboard',
5
+ document: 'Document'
6
+ },
7
+ // 登录页面国际化
8
+ login: {
9
+ username: 'Username',
10
+ password: 'Password',
11
+ login: 'Login',
12
+ code: 'Verification Code',
13
+ copyright: ''
14
+ },
15
+ // 导航栏国际化
16
+ navbar: {
17
+ full: 'Full Screen',
18
+ language: 'Language',
19
+ dashboard: 'Dashboard',
20
+ document: 'Document',
21
+ message: 'Message',
22
+ layoutSize: 'Layout Size',
23
+ selectTenant: 'Select Tenant',
24
+ layoutSetting: 'Layout Setting',
25
+ personalCenter: 'Personal Center',
26
+ logout: 'Logout'
27
+ }
28
+ };