@truenewx/tnxvue3 3.4.2 → 3.4.4

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 (32) hide show
  1. package/package.json +14 -8
  2. package/src/element-plus/aj-captcha/api/index.js +2 -2
  3. package/src/element-plus/avatar/Avatar.vue +4 -27
  4. package/src/element-plus/date-picker/DatePicker.vue +8 -9
  5. package/src/element-plus/dialog/Dialog.vue +15 -15
  6. package/src/element-plus/drawer/Drawer.vue +2 -2
  7. package/src/element-plus/edit-table/EditTable.vue +10 -10
  8. package/src/element-plus/enum-select/EnumSelect.vue +30 -30
  9. package/src/element-plus/enum-view/EnumView.vue +1 -3
  10. package/src/element-plus/fetch-cascader/FetchCascader.vue +4 -4
  11. package/src/element-plus/fetch-select/FetchSelect.vue +3 -3
  12. package/src/element-plus/fetch-tags/FetchTags.vue +1 -1
  13. package/src/element-plus/fss-upload/FssUpload.vue +75 -114
  14. package/src/element-plus/fss-view/FssView.vue +28 -30
  15. package/src/element-plus/query-form/QueryForm.vue +3 -3
  16. package/src/element-plus/query-table/QueryTable.vue +12 -12
  17. package/src/element-plus/region-cascader/RegionCascader.vue +3 -3
  18. package/src/element-plus/select/Select.vue +56 -56
  19. package/src/element-plus/submit-form/SubmitForm.vue +5 -5
  20. package/src/element-plus/tnxel-validator.ts +347 -0
  21. package/src/element-plus/tnxel.ts +575 -0
  22. package/src/element-plus/transfer/Transfer.vue +2 -2
  23. package/src/element-plus/upload/Upload.vue +68 -70
  24. package/src/tdesign/desktop/tnxtdd.ts +5 -5
  25. package/src/tdesign/mobile/tnxtdm.css +0 -0
  26. package/src/tdesign/mobile/tnxtdm.ts +7 -6
  27. package/src/tdesign/{foundation/validator.ts → tnxtd-validator.ts} +4 -4
  28. package/src/tdesign/tnxtd.ts +6 -7
  29. package/src/tnxvue-router.ts +8 -14
  30. package/src/tnxvue.ts +53 -26
  31. package/tsconfig.json +32 -19
  32. package/src/element-plus/tnxel.js +0 -598
@@ -1,598 +0,0 @@
1
- // tnxel.js
2
- /**
3
- * 基于ElementPlus的扩展支持
4
- */
5
- import ElementPlus, {ElLoading, ElMessage, ElMessageBox} from 'element-plus';
6
- import ElementPlus_zh_CN from 'element-plus/es/locale/lang/zh-cn';
7
- import tnxbs from '@truenewx/tnxcore/src/tnxbs'; // 二次封装组件中使用了Bootstrap的基础样式
8
- import tnxvue from '../tnxvue.js';
9
-
10
- import CaptchaVerify from './aj-captcha/Verify.vue';
11
- import Avatar from './avatar/Avatar.vue';
12
- import Alert from './alert/Alert.vue';
13
- import Button from './button/Button.vue';
14
- import CheckIcon from './check-icon/CheckIcon.vue';
15
- import CloseErrorButton from './close-error-button/CloseErrorButton.vue';
16
- import Curd from './curd/Curd.vue';
17
- import DatePicker from './date-picker/DatePicker.vue';
18
- import DateRange from './date-range/DateRange.vue';
19
- import DateTimePicker from './datetime-picker/DateTimePicker.vue';
20
- import DetailForm from './detail-form/DetailForm.vue';
21
- import Dialog from './dialog/Dialog.vue';
22
- import Drawer from './drawer/Drawer.vue';
23
- import DropdownItem from './dropdown-item/DropdownItem.vue';
24
- import EditTable from './edit-table/EditTable.vue';
25
- import EnumSelect from './enum-select/EnumSelect.vue';
26
- import EnumView from './enum-view/EnumView.vue';
27
- import FetchCascader from './fetch-cascader/FetchCascader.vue';
28
- import FetchSelect from './fetch-select/FetchSelect.vue';
29
- import FetchTags from './fetch-tags/FetchTags.vue';
30
- import FssUpload from './fss-upload/FssUpload.vue';
31
- import FssView from './fss-view/FssView.vue';
32
- import Icon from './icon/Icon.vue';
33
- import InputDropdown from './input-dropdown/InputDropdown.vue';
34
- import InputNumber from './input-number/InputNumber.vue';
35
- import Paged from './paged/Paged.vue';
36
- import PermissionTree from './permission-tree/PermissionTree.vue';
37
- import QueryForm from './query-form/QueryForm.vue';
38
- import QueryTable from './query-table/QueryTable.vue';
39
- import RegionCascader from './region-cascader/RegionCascader.vue';
40
- import Select from './select/Select.vue';
41
- import Slider from './slider/Slider.vue';
42
- import StepsNav from './steps-nav/StepsNav.vue';
43
- import SubmitForm from './submit-form/SubmitForm.vue';
44
- import TabColumn from './table-column/TableColumn.vue';
45
- import Tabs from './tabs/Tabs.vue';
46
- import Transfer from './transfer/Transfer.vue';
47
- import Upload from './upload/Upload.vue';
48
-
49
- import './tnxel.css';
50
-
51
- const $ = tnxbs.libs.$;
52
-
53
- export const build = tnxvue.build;
54
-
55
- export default build('tnxel', () => {
56
- const components = Object.assign({}, tnxvue.components, {
57
- CaptchaVerify, // 只使用了ElementPlus的图标
58
-
59
- Alert,
60
- Avatar,
61
- Button,
62
- CheckIcon,
63
- CloseErrorButton,
64
- Curd,
65
- DatePicker,
66
- DateRange,
67
- DateTimePicker,
68
- DetailForm,
69
- Dialog,
70
- Drawer,
71
- DropdownItem,
72
- EditTable,
73
- EnumSelect,
74
- EnumView,
75
- FetchCascader,
76
- FetchSelect,
77
- FetchTags,
78
- FssUpload,
79
- FssView,
80
- Icon,
81
- InputDropdown,
82
- InputNumber,
83
- Paged,
84
- PermissionTree,
85
- QueryForm,
86
- QueryTable,
87
- RegionCascader,
88
- Select,
89
- Slider,
90
- StepsNav,
91
- SubmitForm,
92
- TabColumn,
93
- Tabs,
94
- Transfer,
95
- Upload,
96
- });
97
-
98
- const dialogContainerClass = 'tnxel-dialog-container';
99
- const drawerContainerClass = 'tnxel-drawer-container';
100
-
101
- const tnxel = Object.assign({}, tnxbs, tnxvue, {
102
- components,
103
- componentDefaultApp: undefined, // 组件的默认app,从服务端获取数据的组件以此为远程请求的默认app
104
- dialogInstances: [], // 对话框堆栈
105
- dialog(content, title, buttons, options, contentProps) {
106
- this._closeMessage();
107
-
108
- let componentOptions = {};
109
- if (window.tnx.util.isComponent(content)) {
110
- componentOptions.components = {
111
- 'tnxel-dialog-content': content
112
- };
113
- content = null;
114
- }
115
- let componentDefinition = Object.assign({}, Dialog, componentOptions);
116
-
117
- const dialogId = 'dialog-' + (new Date().getTime());
118
- $('body').append('<div class="' + dialogContainerClass + '" id="' + dialogId + '"></div>');
119
- if (!(buttons instanceof Array)) {
120
- buttons = [];
121
- }
122
- const containerSelector = '.' + dialogContainerClass + '#' + dialogId;
123
- options = options || {};
124
- let dialogVm = window.tnx.createVueInstance(componentDefinition, null, {
125
- modelValue: true,
126
- container: containerSelector,
127
- title: title,
128
- content: content,
129
- contentProps: contentProps,
130
- buttons: buttons,
131
- theme: options.theme,
132
- });
133
- const dialog = dialogVm.mount(containerSelector);
134
- dialog.options = Object.assign(dialog.options || {}, options);
135
- dialog.options.onClosed = window.tnx.util.function.around(dialog.options.onClosed, function (onClosed) {
136
- dialogVm.unmount();
137
- window.tnx.dialogInstances.remove(dialog);
138
- let $container = $(containerSelector);
139
- $container.next('.el-overlay').remove();
140
- $container.remove();
141
- if (onClosed) {
142
- onClosed.call(dialog);
143
- }
144
- });
145
- window.tnx.dialogInstances.push(dialog);
146
- return dialog;
147
- },
148
- closeDialog(all) {
149
- return new Promise((resolve) => {
150
- if (window.tnx.dialogInstances.length) {
151
- let dialog = window.tnx.dialogInstances.pop();
152
- let promises = [];
153
- while (dialog) {
154
- promises.push(dialog.close());
155
- if (all) {
156
- dialog = window.tnx.dialogInstances.pop();
157
- } else {
158
- break;
159
- }
160
- }
161
- Promise.all(promises).then(resolve);
162
- } else {
163
- resolve();
164
- }
165
- });
166
- },
167
- drawerInstances: [], // 抽屉堆栈
168
- drawer(content, title, buttons, options, contentProps) {
169
- this._closeMessage();
170
-
171
- let componentOptions = {};
172
- if (this.util.isComponent(content)) {
173
- componentOptions.components = {
174
- 'tnxel-drawer-content': content
175
- };
176
- content = null;
177
- }
178
- let componentDefinition = Object.assign({}, Drawer, componentOptions);
179
-
180
- const drawerId = 'drawer-' + (new Date().getTime());
181
- $('body').append('<div class="' + drawerContainerClass + '" id="' + drawerId + '"></div>');
182
- if (!(buttons instanceof Array)) {
183
- buttons = [];
184
- }
185
- const containerSelector = '.' + drawerContainerClass + '#' + drawerId;
186
- options = options || {};
187
- let drawerVm = window.tnx.createVueInstance(componentDefinition, null, {
188
- content: content,
189
- title: title,
190
- contentProps: contentProps,
191
- buttons: buttons,
192
- theme: options.theme,
193
- });
194
- const drawer = drawerVm.mount(containerSelector);
195
- drawer.id = drawerId;
196
- drawer.options = Object.assign(drawer.options || {}, options);
197
- drawer.options.onClosed = this.util.function.around(drawer.options.onClosed, function (onClosed) {
198
- drawerVm.unmount();
199
- window.tnx.drawerInstances.remove(drawer);
200
- let $container = $(containerSelector);
201
- $container.next('.el-overlay').remove();
202
- $container.remove();
203
- if (onClosed) {
204
- onClosed.call(drawer);
205
- }
206
- });
207
- window.tnx.drawerInstances.push(drawer);
208
- return drawer;
209
- },
210
- closeDrawer(all) {
211
- return new Promise((resolve) => {
212
- if (window.tnx.drawerInstances.length) {
213
- let drawer = window.tnx.drawerInstances.pop();
214
- let promises = [];
215
- while (drawer) {
216
- promises.push(drawer.close());
217
- if (all) {
218
- drawer = window.tnx.drawerInstances.pop();
219
- } else {
220
- break;
221
- }
222
- }
223
- Promise.all(promises).then(resolve);
224
- } else {
225
- resolve();
226
- }
227
- });
228
- },
229
- _closeMessage() {
230
- ElMessage.closeAll();
231
- this.closeLoading();
232
- },
233
- _handleZIndex(selector) {
234
- setTimeout(() => {
235
- const topZIndex = window.tnx.util.dom.minTopZIndex(2);
236
- if (selector.endsWith(':last')) {
237
- selector = selector.substring(0, selector.length - ':last'.length);
238
- }
239
- let element = $(selector);
240
- if (element.length > 0) {
241
- element = $(element[element.length - 1]);
242
- }
243
- const zIndex = Number(element.css('zIndex'));
244
- if (isNaN(zIndex) || topZIndex > zIndex) {
245
- element.css('zIndex', topZIndex);
246
- const modal = element.next();
247
- if (modal.is('.v-modal')) {
248
- modal.css('zIndex', topZIndex - 1);
249
- }
250
- }
251
- });
252
- },
253
- alert(message, title, options) {
254
- if (typeof title === 'object') {
255
- options = title;
256
- title = '提示';
257
- }
258
- options = Object.assign({
259
- dangerouslyUseHTMLString: true,
260
- type: 'warning',
261
- confirmButtonText: '确定',
262
- }, options);
263
- this._closeMessage();
264
- const promise = ElMessageBox.alert(message, title || '提示', options);
265
- this._handleZIndex('.el-message-box__wrapper:last');
266
- this.app.eventBus.emit('tnx.alert', options);
267
- return promise;
268
- },
269
- success(message, options) {
270
- options = Object.assign({
271
- dangerouslyUseHTMLString: true,
272
- }, options, {
273
- type: 'success',
274
- confirmButtonText: '确定',
275
- });
276
- this._closeMessage();
277
- const promise = ElMessageBox.alert(message, '成功', options);
278
- this._handleZIndex('.el-message-box__wrapper:last');
279
- this.app.eventBus.emit('tnx.success', options);
280
- return promise;
281
- },
282
- error(message, options) {
283
- options = Object.assign({
284
- dangerouslyUseHTMLString: true,
285
- }, options, {
286
- type: 'error',
287
- confirmButtonText: '确定',
288
- });
289
- this._closeMessage();
290
- const promise = ElMessageBox.alert(message, '错误', options);
291
- this._handleZIndex('.el-message-box__wrapper:last');
292
- this.app.eventBus.emit('tnx.error', options);
293
- // 打印TypeError对象,便于调试
294
- if (typeof message === 'object' && message.name === 'TypeError') {
295
- console.error(message);
296
- }
297
- return promise;
298
- },
299
- confirm(message, title = '确认', options) {
300
- if (typeof title === 'object') {
301
- options = title;
302
- title = '确认';
303
- }
304
- options = Object.assign({
305
- type: 'question',
306
- confirmButtonText: '确定',
307
- cancelButtonText: '取消',
308
- }, options, {
309
- dangerouslyUseHTMLString: true,
310
- distinguishCancelAndClose: true,
311
- });
312
- if (options.type === 'question') {
313
- options.type = 'info';
314
- options.icon = tnxvue.libs.Vue.markRaw(Icon.components.QuestionFilled);
315
- }
316
- if (options.reverse) {
317
- options.customClass = 'reverse';
318
- let buttonText = options.confirmButtonText;
319
- options.confirmButtonText = options.cancelButtonText;
320
- options.cancelButtonText = buttonText;
321
- }
322
-
323
- this._closeMessage();
324
- return new Promise(resolve => {
325
- ElMessageBox.confirm(message, title, options).then(() => {
326
- resolve(true);
327
- }).catch(() => {
328
- resolve(false);
329
- });
330
- this._handleZIndex('.el-message-box__wrapper:last');
331
- this.app.eventBus.emit('tnx.confirm', options);
332
- })
333
-
334
- },
335
- toast(message, timeout, options) {
336
- options = Object.assign({
337
- type: 'success', // 默认为成功主题,可更改为其它主题
338
- offset: this.util.dom.getDocHeight() * 0.4,
339
- dangerouslyUseHTMLString: true,
340
- }, options, {
341
- center: true, // 因为是竖向排列,所以必须居中
342
- showClose: false,
343
- message: message,
344
- duration: timeout || 1500,
345
- customClass: 'tnxel-toast',
346
- });
347
-
348
- this._closeMessage();
349
- const messageInstance = ElMessage(options);
350
- this._handleZIndex('.el-message:last');
351
- this.app.eventBus.emit('tnx.toast', options);
352
-
353
- // 创建一个Promise,在消息关闭时resolve
354
- return new Promise((resolve) => {
355
- const originalOnClose = options.onClose;
356
- options.onClose = () => {
357
- if (originalOnClose) {
358
- originalOnClose();
359
- }
360
- resolve();
361
- };
362
- // 如果消息实例有close方法,重新设置onClose
363
- if (messageInstance && messageInstance.close) {
364
- const originalClose = messageInstance.close;
365
- messageInstance.close = () => {
366
- originalClose.call(messageInstance);
367
- options.onClose();
368
- };
369
- }
370
- });
371
- },
372
- showLoading(message, options) {
373
- if (typeof message !== 'string') {
374
- options = message;
375
- message = undefined;
376
- }
377
- options = Object.assign({
378
- dangerouslyUseHTMLString: true,
379
- }, options, {
380
- text: message,
381
- });
382
- return new Promise((resolve, reject) => {
383
- window.tnx._closeMessage();
384
- try {
385
- window.tnx.loadingInstance = ElLoading.service(options);
386
- this._handleZIndex('.el-loading-mask');
387
- window.tnx.app.eventBus.emit('tnx.showLoading', options);
388
- let vm = window.tnx.loadingInstance.vm;
389
- if (vm) {
390
- window.tnx.nextTickTimeout(vm, () => {
391
- resolve(window.tnx.loadingInstance);
392
- }, 500);
393
- } else {
394
- resolve(window.tnx.loadingInstance);
395
- }
396
- } catch (e) {
397
- window.tnx.loadingInstance = null;
398
- console.error(e);
399
- reject(e);
400
- }
401
- });
402
- },
403
- closeLoading() {
404
- if (window.tnx.loadingInstance) { // 确保绝对的单例
405
- window.tnx.loadingInstance.close();
406
- window.tnx.loadingInstance = undefined;
407
- }
408
- },
409
- hideLoading() {
410
- this.closeLoading();
411
- },
412
- validateUploaded(vm, reject) {
413
- let result = true;
414
- let formRef = null;
415
- let refKeys = Object.keys(vm.$refs);
416
- for (let refKey of refKeys) {
417
- let refObj = vm.$refs[refKey];
418
- if (Array.isArray(refObj)) {
419
- for (let ref of refObj) {
420
- if (typeof ref.validateUploaded === 'function') {
421
- if (ref.validateUploaded(reject) === false) {
422
- result = false;
423
- break;
424
- }
425
- }
426
- }
427
- } else if (refObj.$el.tagName === 'FORM' && typeof refObj.disable === 'function') {
428
- formRef = refObj;
429
- } else {
430
- if (typeof refObj.validateUploaded === 'function') {
431
- if (refObj.validateUploaded(reject) === false) {
432
- result = false;
433
- break;
434
- }
435
- }
436
- }
437
- }
438
- if (!result && formRef) {
439
- formRef.disable(false);
440
- }
441
- return result;
442
- },
443
- });
444
-
445
- tnxel.libs.ElementPlus = ElementPlus;
446
-
447
- tnxel.install = tnxel.util.function.around(tnxel.install, function (install, vm) {
448
- install.call(tnxel, vm);
449
- // 始终安装ElementPlus,以避免对于不同Vue实例未安装的问题
450
- vm.use(ElementPlus, {
451
- locale: ElementPlus_zh_CN,
452
- });
453
- });
454
-
455
- tnxel.router.beforeLeave =
456
- tnxel.util.function.around(tnxel.router.beforeLeave, function (beforeLeave, router, from) {
457
- // 页面跳转前关闭当前页面中可能存在的所有消息框和对话框
458
- window.tnx._closeMessage();
459
- window.tnx.closeDialog(true);
460
- beforeLeave.call(window.tnx.router, router, from);
461
- });
462
-
463
- tnxel.date = {
464
- formatDateTime: function (row, column, cellValue) {
465
- if (cellValue) {
466
- return new Date(cellValue).formatDateTime();
467
- }
468
- return undefined;
469
- },
470
- formatDate: function (row, column, cellValue) {
471
- if (cellValue) {
472
- return new Date(cellValue).formatDate();
473
- }
474
- return undefined;
475
- },
476
- formatTime: function (row, column, cellValue) {
477
- if (typeof cellValue === 'number') {
478
- cellValue = new Date(cellValue);
479
- }
480
- if (cellValue instanceof Date) {
481
- cellValue = cellValue.formatTime();
482
- }
483
- if (typeof cellValue === 'string') {
484
- return cellValue;
485
- }
486
- return undefined;
487
- },
488
- formatTimeMinute: function (row, column, cellValue) {
489
- if (typeof cellValue === 'number') {
490
- cellValue = new Date(cellValue);
491
- }
492
- if (cellValue instanceof Date) {
493
- cellValue = cellValue.formatTimeMinute();
494
- }
495
- if (typeof cellValue === 'string') {
496
- let array = cellValue.split(':');
497
- if (array.length > 1) {
498
- return array[0] + ':' + array[1];
499
- }
500
- }
501
- return undefined;
502
- },
503
- formatDateMinute: function (row, column, cellValue) {
504
- if (cellValue) {
505
- return new Date(cellValue).formatDateMinute();
506
- }
507
- return undefined;
508
- },
509
- formatDateMonth: function (row, column, cellValue) {
510
- if (cellValue) {
511
- return new Date(cellValue).formatDateMonth();
512
- }
513
- return undefined;
514
- },
515
- formatPermanentableDate: function (row, column, cellValue) {
516
- if (Array.isArray(cellValue)) {
517
- cellValue = cellValue[column];
518
- }
519
- return tnxvue.util.date.formatPermanentableDate(cellValue);
520
- },
521
- /**
522
- * 将Java标准的日期格式转换为Day.js的日期格式
523
- * @param format Java标准的日期格式
524
- * @returns {String} Day.js的日期格式
525
- */
526
- toDayJsDateFormat(format) {
527
- return format.replaceAll('y', 'Y').replaceAll('d', 'D');
528
- },
529
- };
530
-
531
- tnxel.number = {
532
- formatPercent: function (row, column, cellValue) {
533
- if (typeof cellValue !== 'number') {
534
- cellValue = parseFloat(cellValue);
535
- }
536
- if (!isNaN(cellValue)) {
537
- return cellValue.toPercent();
538
- }
539
- return undefined;
540
- }
541
- }
542
-
543
- tnxel.boolean = {
544
- items: {
545
- getText(type, value) {
546
- let items = this[type];
547
- if (Array.isArray(items)) {
548
- for (let item of items) {
549
- if (item.value === value) {
550
- return item.text;
551
- }
552
- }
553
- }
554
- return undefined;
555
- },
556
- has: [{
557
- value: true,
558
- text: '有',
559
- }, {
560
- value: false,
561
- text: '无',
562
- }]
563
- },
564
- format: function (row, column, cellValue) {
565
- if (typeof cellValue === 'boolean') {
566
- cellValue = cellValue.toText();
567
- }
568
- return cellValue;
569
- },
570
- formatHas: function (row, column, cellValue) {
571
- if (typeof cellValue === 'boolean') {
572
- cellValue = tnxel.boolean.items.getText('has', cellValue);
573
- }
574
- return cellValue;
575
- }
576
- }
577
-
578
- tnxel.table = {}
579
-
580
- const rpc = tnxel.app.rpc;
581
- rpc.handleErrors = tnxel.util.function.around(rpc.handleErrors, function (handleErrors, errors, options) {
582
- if (options && options.form) {
583
- let forms;
584
- if (Array.isArray(options.form)) {
585
- forms = options.form;
586
- } else {
587
- forms = [options.form];
588
- }
589
- forms.forEach(form => {
590
- if (typeof form.disable === 'function') {
591
- form.disable(false);
592
- }
593
- });
594
- }
595
- return handleErrors.call(rpc, errors, options);
596
- });
597
- return tnxel;
598
- });