@truenewx/tnxvue3 3.4.3 → 3.4.5

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 (47) hide show
  1. package/package.json +12 -6
  2. package/src/bootstrap-vue/dialog/Dialog.vue +22 -10
  3. package/src/element-plus/aj-captcha/api/index.js +2 -2
  4. package/src/element-plus/avatar/Avatar.vue +4 -27
  5. package/src/element-plus/date-picker/DatePicker.vue +8 -9
  6. package/src/element-plus/dialog/Dialog.vue +34 -22
  7. package/src/element-plus/drawer/Drawer.vue +22 -5
  8. package/src/element-plus/edit-table/EditTable.vue +10 -10
  9. package/src/element-plus/enum-select/EnumSelect.vue +30 -30
  10. package/src/element-plus/enum-view/EnumView.vue +1 -3
  11. package/src/element-plus/fetch-cascader/FetchCascader.vue +4 -4
  12. package/src/element-plus/fetch-select/FetchSelect.vue +3 -3
  13. package/src/element-plus/fetch-tags/FetchTags.vue +1 -1
  14. package/src/element-plus/fss-upload/FssUpload.vue +76 -115
  15. package/src/element-plus/fss-view/FssView.vue +28 -30
  16. package/src/element-plus/icon/Icon.vue +3 -0
  17. package/src/element-plus/query-form/QueryForm.vue +3 -3
  18. package/src/element-plus/query-table/QueryTable.vue +12 -12
  19. package/src/element-plus/region-cascader/RegionCascader.vue +3 -3
  20. package/src/element-plus/select/Select.vue +56 -56
  21. package/src/element-plus/submit-form/SubmitForm.vue +5 -5
  22. package/src/element-plus/tnxel-validator.ts +347 -0
  23. package/src/element-plus/tnxel.css +0 -8
  24. package/src/element-plus/tnxel.ts +561 -0
  25. package/src/element-plus/transfer/Transfer.vue +2 -2
  26. package/src/element-plus/upload/Upload.vue +68 -70
  27. package/src/tdesign/desktop/tnxtdd.ts +5 -5
  28. package/src/tdesign/mobile/calendar/Calendar.vue +121 -0
  29. package/src/tdesign/mobile/date-time-picker/DateTimePicker.vue +147 -0
  30. package/src/tdesign/mobile/dialog/Dialog.vue +179 -0
  31. package/src/tdesign/mobile/dialog/DialogContent.vue +13 -0
  32. package/src/tdesign/mobile/drawer/Drawer.vue +176 -0
  33. package/src/tdesign/mobile/drawer/DrawerContent.vue +13 -0
  34. package/src/tdesign/mobile/enum-select/EnumSelect.vue +160 -0
  35. package/src/tdesign/mobile/popup/Popup.vue +106 -0
  36. package/src/tdesign/mobile/region-picker/RegionPicker.vue +223 -0
  37. package/src/tdesign/mobile/select/Select.vue +478 -0
  38. package/src/tdesign/mobile/slide-radio-group/SlideRadioGroup.vue +392 -0
  39. package/src/tdesign/mobile/tnxtdm.css +132 -0
  40. package/src/tdesign/mobile/tnxtdm.ts +310 -7
  41. package/src/tdesign/{foundation/validator.ts → tnxtd-validator.ts} +18 -17
  42. package/src/tdesign/tnxtd.css +66 -0
  43. package/src/tdesign/tnxtd.ts +10 -7
  44. package/src/tnxvue-router.ts +65 -18
  45. package/src/tnxvue.ts +71 -31
  46. package/tsconfig.json +33 -19
  47. package/src/element-plus/tnxel.js +0 -598
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import {
5
5
  createRouter,
6
+ createWebHistory,
6
7
  createWebHashHistory,
7
8
  Router,
8
9
  RouteRecordRaw,
@@ -12,29 +13,25 @@ import {
12
13
  RouteLocationNormalizedLoadedGeneric,
13
14
  NavigationGuardNext,
14
15
  } from 'vue-router';
15
- import NetUtil from '../../tnxcore/src/util/net';
16
+ import * as NetUtil from '../../tnxcore/src/util/net.ts';
16
17
 
17
- export type RouteItem = RouteRecordRaw & {
18
+ export type RouteItem = {
19
+ caption: string;
18
20
  path: string;
21
+ anonymous?: boolean; // 是否可以匿名访问
19
22
  icon?: string;
20
- meta?: {
21
- superiorPath?: string;
22
- page?: string;
23
- cache: Record<string, any>;
24
- historyFrom?: any;
25
- isHistory: () => boolean;
26
- };
27
23
  page?: string;
28
24
  component?: () => Promise<any>;
29
25
  redirect?: never;
30
26
  alias?: string;
31
27
  subs?: RouteItem[];
28
+ parent?: RouteItem;
32
29
  }
33
30
 
34
- function addRoute(routes: RouteRecordRaw[], superiorPath: string, item: RouteItem, fnImportPage: (page: string) => Promise<any>): void {
31
+ function addRoute(routes: RouteRecordRaw[], superiorPath: string, item: RouteItem, fnImportPage?: (page: string) => Promise<any>): void {
35
32
  if (item && item.path) {
36
33
  let page = item.page || item.path.replace(/\/:[a-zA-Z0-9_]+/g, '');
37
- let route: RouteItem = {
34
+ let route: RouteRecordRaw = {
38
35
  path: item.path,
39
36
  meta: {
40
37
  superiorPath: superiorPath,
@@ -46,7 +43,7 @@ function addRoute(routes: RouteRecordRaw[], superiorPath: string, item: RouteIte
46
43
  },
47
44
  component: item.component,
48
45
  };
49
- if (!route.component) {
46
+ if (!route.component && fnImportPage) {
50
47
  route.component = () => {
51
48
  return fnImportPage(page);
52
49
  };
@@ -62,7 +59,7 @@ function addRoute(routes: RouteRecordRaw[], superiorPath: string, item: RouteIte
62
59
  }
63
60
  }
64
61
 
65
- function applyItemsToRoutes(superiorPath: string, items: RouteItem[], routes: RouteRecordRaw[], fnImportPage: (page: string) => Promise<any>): void {
62
+ function applyItemsToRoutes(superiorPath: string, items: RouteItem[], routes: RouteRecordRaw[], fnImportPage?: (page: string) => Promise<any>): void {
66
63
  if (items && items.length) {
67
64
  items.forEach(item => {
68
65
  if (item) {
@@ -93,21 +90,51 @@ function getCurrentRoute(router: Router): RouteLocationNormalizedLoadedGeneric {
93
90
  return router.currentRoute.value;
94
91
  }
95
92
 
93
+ function findItemByPath(parent: RouteItem, items: RouteItem[], path: string): RouteItem | null {
94
+ for (const item of items) {
95
+ if (item.path === path) {
96
+ item.parent = parent;
97
+ return item;
98
+ }
99
+ if (item.subs) {
100
+ const found = findItemByPath(item, item.subs, path);
101
+ if (found) {
102
+ return found;
103
+ }
104
+ }
105
+ }
106
+ return null;
107
+ }
108
+
109
+ export class RouteMenu {
110
+
111
+ items: RouteItem[];
112
+
113
+ constructor(items: RouteItem[]) {
114
+ this.items = items;
115
+ }
116
+
117
+ findItem(path: string): RouteItem | null {
118
+ return findItemByPath(null, this.items, path);
119
+ }
120
+
121
+ }
122
+
96
123
  export type VueRouter = Router & {
97
124
  history: RouterHistory;
98
125
  prev?: RouteLocationNormalizedLoaded;
99
- $beforeLeaveHandlers: Record<string, (to: RouteLocationNormalized) => boolean>;
126
+ $beforeLeaveHandlers: Record<string, (to: RouteLocationNormalized) => boolean | Promise<boolean>>;
100
127
  beforeLeave: (handler: (to: RouteLocationNormalized) => boolean) => void;
101
128
  pushState: (path: string) => boolean;
102
129
  replaceState: (path: string) => boolean;
103
130
  backTo: (path?: string) => void;
104
131
  }
105
132
 
106
- export default function (items: RouteItem[], fnImportPage: (page: string) => Promise<any>): VueRouter {
133
+ export default function (items: RouteItem[], useHashHistory = true, fnImportPage?: (page: string) => Promise<any>): VueRouter {
107
134
  const routes: RouteRecordRaw[] = [];
108
135
  applyItemsToRoutes('', items, routes, fnImportPage);
109
136
 
110
- const routerHistory = createWebHashHistory();
137
+ const routerHistory = useHashHistory ? createWebHashHistory() : createWebHistory();
111
138
  const router: VueRouter = createRouter({
112
139
  history: routerHistory,
113
140
  routes,
@@ -127,7 +154,7 @@ export default function (items: RouteItem[], fnImportPage: (page: string) => Pro
127
154
 
128
155
  // 注册离开页面前事件处理支持
129
156
  router.$beforeLeaveHandlers = {};
130
- router.beforeLeave = function (handler: (to: RouteLocationNormalized) => boolean): void {
157
+ router.beforeLeave = function (handler: (to: RouteLocationNormalized) => boolean | Promise<boolean>): void {
131
158
  let $route = getCurrentRoute(router);
132
159
  let path = $route.path;
133
160
  router.$beforeLeaveHandlers[path] = handler;
@@ -136,8 +163,28 @@ export default function (items: RouteItem[], fnImportPage: (page: string) => Pro
136
163
  router.beforeEach((to: RouteLocationNormalized, from: RouteLocationNormalizedLoaded, next: NavigationGuardNext): void => {
137
164
  let allow = true;
138
165
  let beforeLeaveHandler = router.$beforeLeaveHandlers[from.path];
166
+ if (!beforeLeaveHandler) {
167
+ let toItem = findItemByPath(null, items, to.path);
168
+ if (toItem && !toItem.anonymous) {
169
+ beforeLeaveHandler = async (to: RouteLocationNormalized): Promise<boolean> => {
170
+ let logined = await window.tnx.auth.isLogined();
171
+ if (!logined) {
172
+ window.tnx.api.toLogin(to.path);
173
+ }
174
+ return logined;
175
+ };
176
+ }
177
+ }
139
178
  if (beforeLeaveHandler) {
140
- if (beforeLeaveHandler(to) === false) {
179
+ let result = beforeLeaveHandler(to);
180
+ if (result instanceof Promise) {
181
+ result.then((allowed: boolean): void => {
182
+ if (allowed) {
183
+ next();
184
+ }
185
+ });
186
+ return;
187
+ } else if (result === false) {
141
188
  allow = false;
142
189
  }
143
190
  }
package/src/tnxvue.ts CHANGED
@@ -1,15 +1,18 @@
1
1
  /**
2
2
  * 基于Vue 3的扩展支持
3
3
  */
4
- import Tnx from '../../tnxcore/src/tnxcore';
4
+ import Tnx, {util} from '../../tnxcore/src/tnxcore.ts';
5
5
  import Text from './text/Text.vue';
6
6
  import Percent from './percent/Percent.vue';
7
7
  import * as Vue from 'vue';
8
8
  import mitt, {Emitter, EventType} from 'mitt';
9
9
  import {Router} from 'vue-router';
10
+ import {VueRouter} from './tnxvue-router.ts';
11
+
12
+ export {util};
10
13
 
11
14
  export type EventBus = Emitter<Record<EventType, unknown>> & {
12
- once(name: EventType, handler: (arg: unknown) => void): void;
15
+ once(name: EventType, handler: (event: unknown) => void): void;
13
16
  };
14
17
 
15
18
  export type ButtonOptions = {
@@ -24,6 +27,7 @@ export type DialogOptions = {
24
27
  click?: boolean | ((yes: boolean, close: () => void) => boolean | undefined) | ((close: () => void) => boolean | undefined);
25
28
  buttonText?: string | string[];
26
29
  buttons?: ButtonOptions[];
30
+ width?: number | string;
27
31
  }
28
32
 
29
33
  export type OpenType = 'alert' | 'confirm' | 'close' | 'none';
@@ -37,35 +41,35 @@ export type OpenOptions = DialogOptions & {
37
41
 
38
42
  export default class TnxVue extends Tnx {
39
43
 
40
- router: Router;
44
+ router: VueRouter;
41
45
  eventBus: EventBus;
42
46
 
43
- static {
44
- TnxVue.Libs.Vue = Vue;
45
- }
46
-
47
- components: Record<string, Vue.Component | Vue.DefineComponent> = {
47
+ /**
48
+ * 需要注册到Vue中的组件清单
49
+ */
50
+ components: Record<string, Vue.Component> = {
48
51
  Text,
49
52
  Percent,
50
53
  };
51
54
 
52
- constructor(apiBaseUrl: string) {
53
- super(apiBaseUrl);
55
+ constructor(apiBaseUrl: string, id: string = 'tnxvue') {
56
+ super(apiBaseUrl, id);
57
+ this.libs.Vue = Vue;
54
58
  }
55
59
 
56
- install(app: Vue.App) {
60
+ install(app: Vue.App): void {
57
61
  for (let key of Object.keys(this.components)) {
58
62
  const component = this.components[key];
59
63
  app.component(component.name, component);
60
64
  }
61
65
  }
62
66
 
63
- createVueApp(rootComponent: Vue.Component, router: Router, rootProps?: Record<string, any>): Vue.App {
67
+ createVueApp(rootComponent: Vue.Component, router?: Router, rootProps?: Record<string, any>): Vue.App {
64
68
  let app = Vue.createApp(rootComponent, rootProps);
65
69
  app.use(this);
66
70
  if (router) {
67
71
  app.use(router);
68
- this.router = app.config.globalProperties.$router;
72
+ this.router = app.config.globalProperties.$router as VueRouter;
69
73
  } else if (this.router) {
70
74
  app.config.globalProperties.$router = this.router;
71
75
  }
@@ -73,7 +77,7 @@ export default class TnxVue extends Tnx {
73
77
  if (!this.eventBus) {
74
78
  this.eventBus = mitt() as EventBus;
75
79
  }
76
- this.eventBus.once = (name: EventType, handler: (arg: unknown) => void) => {
80
+ this.eventBus.once = (name: EventType, handler: (event: unknown) => void) => {
77
81
  this.eventBus.all.set(name, [handler]);
78
82
  }
79
83
 
@@ -135,7 +139,16 @@ export default class TnxVue extends Tnx {
135
139
  });
136
140
  }
137
141
 
138
- dialog(content: string | Vue.Component | Vue.DefineComponent,
142
+ /**
143
+ * 判断指定对象是否组件实例
144
+ * @param obj 对象
145
+ * @returns {boolean} 是否组件实例
146
+ */
147
+ isComponent(obj: any): boolean {
148
+ return (typeof obj === 'object') && (typeof obj.render === 'function');
149
+ }
150
+
151
+ dialog(content: string | Vue.Component,
139
152
  title?: string,
140
153
  options: DialogOptions = {},
141
154
  contentProps: Record<string, any> = {}) {
@@ -162,7 +175,7 @@ export default class TnxVue extends Tnx {
162
175
 
163
176
  protected getDefaultDialogButtons(
164
177
  type: OpenType,
165
- click: boolean | ((yes: boolean, close: () => void) => boolean | undefined) | ((close: () => void) => boolean | undefined),
178
+ click: boolean | string | ((yes: boolean, close: () => void) => boolean | undefined) | ((close: () => void) => boolean | undefined),
166
179
  theme?: string): ButtonOptions[] {
167
180
  if (click !== false) {
168
181
  if (type === 'none') {
@@ -172,6 +185,9 @@ export default class TnxVue extends Tnx {
172
185
  text: '确定',
173
186
  type: theme || 'primary',
174
187
  click(close: () => void) {
188
+ if (typeof click === 'string') {
189
+ click = this[click];
190
+ }
175
191
  if (typeof click === 'function') {
176
192
  return click.call(this, true, close);
177
193
  }
@@ -179,6 +195,9 @@ export default class TnxVue extends Tnx {
179
195
  }, {
180
196
  text: '取消',
181
197
  click(close: () => void) {
198
+ if (typeof click === 'string') {
199
+ click = this[click];
200
+ }
182
201
  if (typeof click === 'function') {
183
202
  return click.call(this, false, close);
184
203
  }
@@ -189,6 +208,9 @@ export default class TnxVue extends Tnx {
189
208
  text: '关闭',
190
209
  type: theme,
191
210
  click(close: () => void) {
211
+ if (typeof click === 'string') {
212
+ click = this[click];
213
+ }
192
214
  if (typeof click === 'function') {
193
215
  return click.call(this, close);
194
216
  }
@@ -199,6 +221,9 @@ export default class TnxVue extends Tnx {
199
221
  text: '确定',
200
222
  type: theme || 'primary',
201
223
  click(close: () => void) {
224
+ if (typeof click === 'string') {
225
+ click = this[click];
226
+ }
202
227
  if (typeof click === 'function') {
203
228
  return click.call(this, close);
204
229
  }
@@ -209,7 +234,12 @@ export default class TnxVue extends Tnx {
209
234
  return [];
210
235
  }
211
236
 
212
- drawer(content: string | Vue.Component | Vue.DefineComponent,
237
+ closeDialog(all?: boolean): void {
238
+ // 默认不实现,由UI框架扩展层实现
239
+ throw new Error('Unsupported function');
240
+ }
241
+
242
+ drawer(content: string | Vue.Component,
213
243
  title?: string,
214
244
  options: DrawerOptions = {},
215
245
  contentProps: Record<string, any> = {}) {
@@ -218,12 +248,31 @@ export default class TnxVue extends Tnx {
218
248
  throw new Error('Unsupported function');
219
249
  }
220
250
 
221
- open(component: Vue.Component | Vue.DefineComponent, props?: Record<string, any>, options: OpenOptions = {}) {
251
+ closeDrawer(all?: boolean): void {
252
+ // 默认不实现,由UI框架扩展层实现
253
+ throw new Error('Unsupported function');
254
+ }
255
+
256
+ showLoading(message?: string): Promise<void> {
257
+ // 默认不实现,由UI框架扩展层实现
258
+ throw new Error('Unsupported function');
259
+ }
260
+
261
+ closeLoading(): void {
262
+ // 默认不实现,由UI框架扩展层实现
263
+ throw new Error('Unsupported function');
264
+ }
265
+
266
+ hideLoading(): void {
267
+ this.closeLoading();
268
+ }
269
+
270
+ open(component: Vue.Component, props?: Record<string, any>, options: OpenOptions = {}) {
222
271
  const c = component as any;
223
- if (typeof c.open === 'function') {
224
- options = Object.assign({}, c.open(props), options);
225
- } else if (c.methods && typeof c.methods.open === 'function') {
226
- options = Object.assign({}, c.methods.open(props), options);
272
+ if (typeof c.openOptions === 'function') {
273
+ options = Object.assign({}, c.openOptions(props), options);
274
+ } else if (c.openOptions) {
275
+ options = Object.assign({}, c.openOptions, options);
227
276
  }
228
277
 
229
278
  let mode = options.mode;
@@ -236,13 +285,4 @@ export default class TnxVue extends Tnx {
236
285
  return this.dialog(component, title, options, props);
237
286
  }
238
287
 
239
- /**
240
- * 判断指定对象是否组件实例
241
- * @param obj 对象
242
- * @returns {boolean} 是否组件实例
243
- */
244
- isComponent(obj: any): boolean {
245
- return (typeof obj === 'object') && (typeof obj.render === 'function');
246
- }
247
-
248
288
  }
package/tsconfig.json CHANGED
@@ -1,21 +1,35 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ESNext",
5
- "moduleResolution": "Bundler",
6
- "strict": false,
7
- "noImplicitAny": false,
8
- "allowJs": false,
9
- "resolveJsonModule": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "lib": [
13
- "ES2020",
14
- "DOM"
15
- ],
16
- "types": []
17
- },
18
- "include": [
19
- "src/**/*"
20
- ]
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "emitDeclarationOnly": true,
7
+ "declaration": true,
8
+ "declarationMap": true,
9
+ "outDir": "types",
10
+ "allowImportingTsExtensions": true,
11
+ "strict": false,
12
+ "noImplicitAny": false,
13
+ "allowJs": false,
14
+ "resolveJsonModule": true,
15
+ "esModuleInterop": true,
16
+ "skipLibCheck": true,
17
+ "lib": [
18
+ "ES2020",
19
+ "DOM"
20
+ ],
21
+ "types": [],
22
+ "baseUrl": ".",
23
+ "paths": {
24
+ "@/*": [
25
+ "src/*"
26
+ ]
27
+ }
28
+ },
29
+ "include": [
30
+ "src/**/*.ts",
31
+ "src/**/*.vue",
32
+ "sample/**/*.ts",
33
+ "node_modules/tdesign-vue-next/global.d.ts"
34
+ ]
21
35
  }