cloud-web-corejs 1.0.303 → 1.0.307

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/src/utils/vab.js CHANGED
@@ -1,1305 +1,1334 @@
1
- /**version-1.0*/
2
- let install = {};
3
-
4
- import request from "./request";
5
- import * as lodash from "lodash";
6
- import { Loading, Message, MessageBox, Notification, Form } from "element-ui";
7
- import store from "../store";
8
- import ElImageViewer from "../components/VabUpload/image-viewer";
9
-
10
- import { getToken } from "./auth";
11
- import XEUtils from "xe-utils";
12
-
13
- import prefixConfig from "@/prefixConfig.js";
14
- import moment from "moment";
15
- import { openView } from "./repeatOpen";
16
- import { assetUrl } from "./assetUrl";
17
-
18
- let imFun = {
19
- request,
20
- lodash,
21
- Loading,
22
- Message,
23
- MessageBox,
24
- Notification,
25
- Form,
26
- store,
27
- getToken,
28
- prefixConfig,
29
- };
30
-
31
- const FILE_ICON_NAME_MAP = {
32
- word: "ico-wrod.svg",
33
- excel: "ico-excel.svg",
34
- ppt: "ico-ppt.svg",
35
- pdf: "ico-pdf.svg",
36
- picture: "ico-photo.svg",
37
- video: "ico-video.svg",
38
- audio: "ico-music.svg",
39
- html: "ico-html.svg",
40
- txt: "ico-txt.svg",
41
- java: "ico-java.svg",
42
- vue: "ico-vue.svg",
43
- ftl: "ico-ftl.svg",
44
- xml: "ico-xml.svg",
45
- flash: "ico-default_wenjian.svg",
46
- zip: "ico-yasuobao.svg",
47
- exe: "ico-default_wenjian.svg",
48
- psd: "ico-psd.svg",
49
- folder: "ico-wenjianjia.svg",
50
- other: "ico-default_wenjian.svg",
51
- };
52
-
53
- // 使用静态 require 建立明确的资源依赖图,避免动态目录 require 把业务图片一并打包。
54
- // webpack4/5 的返回值差异统一由 assetUrl 处理。
55
- const FILE_ICON_MODULE_MAP = {
56
- "ico-wrod.svg": require("@base/core-resources/images/ico-wrod.svg"),
57
- "ico-excel.svg": require("@base/core-resources/images/ico-excel.svg"),
58
- "ico-ppt.svg": require("@base/core-resources/images/ico-ppt.svg"),
59
- "ico-pdf.svg": require("@base/core-resources/images/ico-pdf.svg"),
60
- "ico-photo.svg": require("@base/core-resources/images/ico-photo.svg"),
61
- "ico-video.svg": require("@base/core-resources/images/ico-video.svg"),
62
- "ico-music.svg": require("@base/core-resources/images/ico-music.svg"),
63
- "ico-html.svg": require("@base/core-resources/images/ico-html.svg"),
64
- "ico-txt.svg": require("@base/core-resources/images/ico-txt.svg"),
65
- "ico-java.svg": require("@base/core-resources/images/ico-java.svg"),
66
- "ico-vue.svg": require("@base/core-resources/images/ico-vue.svg"),
67
- "ico-ftl.svg": require("@base/core-resources/images/ico-ftl.svg"),
68
- "ico-xml.svg": require("@base/core-resources/images/ico-xml.svg"),
69
- "ico-yasuobao.svg": require("@base/core-resources/images/ico-yasuobao.svg"),
70
- "ico-psd.svg": require("@base/core-resources/images/ico-psd.svg"),
71
- "ico-wenjianjia.svg": require("@base/core-resources/images/ico-wenjianjia.svg"),
72
- "ico-default_wenjian.svg": require("@base/core-resources/images/ico-default_wenjian.svg"),
73
- };
74
-
75
- function reqImg(name) {
76
- const mod = FILE_ICON_MODULE_MAP[name] || FILE_ICON_MODULE_MAP[FILE_ICON_NAME_MAP.other];
77
- return assetUrl(mod);
78
- }
79
-
80
- const FILE_ICON_TYPE_MAP = {
81
- doc: "word",
82
- docx: "word",
83
- xls: "excel",
84
- xlsx: "excel",
85
- ppt: "ppt",
86
- pptx: "ppt",
87
- pdf: "pdf",
88
- jpg: "picture",
89
- jpeg: "picture",
90
- png: "picture",
91
- gif: "picture",
92
- mp3: "video",
93
- mp4: "video",
94
- mpg: "video",
95
- mkv: "video",
96
- rmvb: "video",
97
- avi: "video",
98
- mov: "video",
99
- wav: "audio",
100
- html: "html",
101
- htm: "html",
102
- txt: "txt",
103
- java: "java",
104
- vue: "vue",
105
- ftl: "ftl",
106
- xml: "xml",
107
- swf: "flash",
108
- zip: "zip",
109
- rar: "zip",
110
- "7z": "zip",
111
- // exe: 'exe',
112
- psd: "psd",
113
- };
114
-
115
- let typeList = [
116
- "doc",
117
- "docx",
118
- "xls",
119
- "xlsx",
120
- "ppt",
121
- "pptx",
122
- "csv",
123
- "wps",
124
- "dps",
125
- "et",
126
- "ett",
127
- "wpt",
128
- "vsd",
129
- "vsdx",
130
- "wmf",
131
- "emf",
132
- "psd",
133
- "eps",
134
- "pdf",
135
- "xmind",
136
- "obj",
137
- "3ds",
138
- "stl",
139
- "ply",
140
- "gltf",
141
- "glb",
142
- "off",
143
- "3dm",
144
- "fbx",
145
- "dae",
146
- "wrl",
147
- "3mf",
148
- "ifc",
149
- "brep",
150
- "step",
151
- "iges",
152
- "fcstd",
153
- "bim",
154
- "dwg",
155
- "dxf",
156
- "dwf",
157
- "iges",
158
- "igs",
159
- "dwt",
160
- "dng",
161
- "ifc",
162
- "dwfx",
163
- "stl",
164
- "cf2",
165
- "plt",
166
- "txt",
167
- "xml",
168
- "md",
169
- "java",
170
- "php",
171
- "py",
172
- "js",
173
- "css",
174
- "zip",
175
- "rar",
176
- "jar",
177
- "tar",
178
- "gzip",
179
- "7z",
180
- "mp3",
181
- "wav",
182
- "mp4",
183
- "flv",
184
- "avi",
185
- "mov",
186
- "rm",
187
- "mkv",
188
- "mpeg",
189
- "mpg",
190
- "rmvb",
191
- "wmv",
192
- "3gp",
193
- "swf",
194
- "drawio",
195
- "tif",
196
- "tiff",
197
- "jfif",
198
- "webp",
199
- "tga",
200
- "svg",
201
- "vue",
202
- "ftl",
203
- ];
204
-
205
- const accessToken = imFun.store.getters["user/token"];
206
-
207
- const loadingText = "";
208
- const messageDuration = 3000;
209
-
210
- install = (Vue, opts = {}) => {
211
- /**http请求*/
212
- let $http = async function (option) {
213
- option = option || {};
214
- if (!option.loadingTarget && this.$el) {
215
- option.loadingTarget = this.$el;
216
- }
217
- if (!option.vueTarget) {
218
- option.vueTarget = this;
219
- }
220
- if (option.sync === false) {
221
- return await imFun.request(option);
222
- } else {
223
- return imFun.request(option);
224
- }
225
- };
226
-
227
- Vue.prototype.$commonHttp = function (opts) {
228
- let defaultOption = {
229
- addCreateInfo: true,
230
- queryCreateInfo: window.$vueRoot.$store.getters.queryCreateInfo || "0",
231
- };
232
- let option = Object.assign({}, defaultOption, opts);
233
- if (opts.addCreateInfo === null || opts.addCreateInfo === undefined) {
234
- option.addCreateInfo = defaultOption.addCreateInfo;
235
- }
236
- if (
237
- opts.queryCreateInfo === null ||
238
- opts.queryCreateInfo === undefined ||
239
- opts.queryCreateInfo === true
240
- ) {
241
- option.queryCreateInfo = defaultOption.queryCreateInfo;
242
- }
243
- if (opts.queryCreateInfo === false) {
244
- option.queryCreateInfo = "0";
245
- }
246
- return this.$http(option);
247
- };
248
-
249
- Object.assign($http, imFun.request);
250
- $http.prototype = imFun.request.prototype;
251
- Vue.prototype.$http = $http;
252
-
253
- /* 通用打开菜单/路由:开关开启时以独立标签重复打开,否则按原逻辑跳转
254
- * 用法:this.$openView('/path') 或 this.$openView({ path, query }[, route]) */
255
- Vue.prototype.$openView = function (location, route) {
256
- return openView(this.$router, location, route);
257
- };
258
-
259
- /* 全局accessToken */
260
- Vue.prototype.$baseAccessToken = () => {
261
- return accessToken || imFun.getToken();
262
- };
263
-
264
- /* 全局加载层 */
265
- Vue.prototype.$baseLoading = function (option) {
266
- let d = this.$el;
267
- let loading;
268
- option = option || {};
269
- if (!option.index) {
270
- let opts = {
271
- lock: true,
272
- background: "hsla(0,0%,100%,.8)",
273
- target: d,
274
- };
275
- Object.assign(opts, option);
276
- loading = imFun.Loading.service(opts);
277
- } else {
278
- let opts = {
279
- lock: true,
280
- spinner: "vab-loading-type" + option.index,
281
- background: "hsla(0,0%,100%,.8)",
282
- target: d,
283
- };
284
- Object.assign(opts, option);
285
- loading = imFun.Loading.service(opts);
286
- }
287
- return loading;
288
- };
289
- /* 全局多彩加载层 */
290
- Vue.prototype.$baseColorfullLoading = function (index, text) {
291
- let loading;
292
- if (!index) {
293
- loading = imFun.Loading.service({
294
- lock: true,
295
- text: text || loadingText,
296
- spinner: "dots-loader",
297
- background: "hsla(0,0%,100%,.8)",
298
- target: this.target,
299
- fullscreen: true,
300
- });
301
- } else {
302
- switch (index) {
303
- case 1:
304
- index = "dots";
305
- break;
306
- case 2:
307
- index = "gauge";
308
- break;
309
- case 3:
310
- index = "inner-circles";
311
- break;
312
- case 4:
313
- index = "plus";
314
- break;
315
- }
316
- loading = imFun.Loading.service({
317
- lock: true,
318
- text: text || loadingText,
319
- spinner: index + "-loader",
320
- background: "hsla(0,0%,100%,.8)",
321
- target: this.target,
322
- });
323
- }
324
- return loading;
325
- };
326
- /* 全局Message */
327
- Vue.prototype.$baseMessage = ({ message, type, onClose }) => {
328
- imFun.Message({
329
- offset: 60,
330
- showClose: true,
331
- message: message,
332
- type: type,
333
- dangerouslyUseHTMLString: true,
334
- duration: messageDuration,
335
- onClose: onClose,
336
- });
337
- };
338
-
339
- /* 全局Alert */
340
- Vue.prototype.$baseAlert = function (content, title, callback) {
341
- imFun.MessageBox.alert(content, title || "提示", {
342
- confirmButtonText: "确定",
343
- dangerouslyUseHTMLString: true,
344
- target: this.$el,
345
- confirmButtonClass: "icondui",
346
- customClass: "dialog-style",
347
- callback: (action) => {
348
- if (callback) {
349
- callback();
350
- }
351
- },
352
- });
353
- };
354
-
355
- /* 全局Confirm */
356
- Vue.prototype.$baseConfirm = function (content, title) {
357
- return imFun.MessageBox.confirm(content, title || "提示", {
358
- confirmButtonText: "确定",
359
- cancelButtonText: "取消",
360
- closeOnClickModal: false,
361
- type: "warning",
362
- customClass: "dialog-style",
363
- cancelButtonClass: "iconguanbi",
364
- confirmButtonClass: "icondui",
365
- });
366
- };
367
-
368
- /* 全局Notification */
369
- Vue.prototype.$baseNotify = (message, title, type, position) => {
370
- imFun.Notification({
371
- title: title,
372
- message: message,
373
- position: position || "top-right",
374
- type: type || "success",
375
- duration: messageDuration,
376
- });
377
- };
378
-
379
- /* 全局TableHeight */
380
- Vue.prototype.$baseTableHeight = (formType) => {
381
- let height = window.innerHeight;
382
- let paddingHeight = 400;
383
- const formHeight = 50;
384
-
385
- if (true) {
386
- paddingHeight = 365;
387
- }
388
-
389
- if ("number" === typeof formType) {
390
- height = height - paddingHeight - formHeight * formType;
391
- } else {
392
- height = height - paddingHeight;
393
- }
394
- return height;
395
- };
396
-
397
- /* 全局map图层 */
398
- Vue.prototype.$baseMap = () => {
399
- return new maptalks.Map("map", {
400
- center: [116.41348403785, 39.910843952376],
401
- zoom: 12,
402
- minZoom: 1,
403
- maxZoom: 19,
404
- spatialReference: {
405
- projection: "baidu",
406
- },
407
- attribution: {
408
- content: "© vue-admin-beautiful",
409
- },
410
- baseLayer: new maptalks.TileLayer("base", {
411
- cssFilter: "sepia(100%) invert(90%)",
412
- urlTemplate:
413
- "http://online{s}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&scaler=1&p=1",
414
- subdomains: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
415
- attribution:
416
- '&copy; <a target="_blank" href="http://map.baidu.com">Baidu</a>',
417
- }),
418
- });
419
- };
420
-
421
- /* 全局lodash */
422
- Vue.prototype.$baseLodash = imFun.lodash;
423
- /* 全局事件总线 */
424
- Vue.prototype.$baseEventBus = new Vue();
425
- /* 模板里 :src="$assetUrl(require(...))" 用,见 utils/assetUrl.js */
426
- Vue.prototype.$assetUrl = assetUrl;
427
-
428
- Vue.prototype.$commonFileUtil = {
429
- // 文件类型获取与判断接口
430
- getFileSuffix: function (name) {
431
- let i = name.lastIndexOf(".");
432
- if (i < 0) {
433
- // 默认是文本类型
434
- return "";
435
- }
436
- let suffix = name.substring(i + 1, name.length).toLowerCase();
437
- return suffix;
438
- },
439
- isBinary: function (suffix) {
440
- if (!suffix || suffix === "") {
441
- return false;
442
- }
443
- let fileTypeMap = {
444
- bin: true,
445
- exe: true,
446
- dll: true,
447
- so: true,
448
- lib: true,
449
- war: true,
450
- jar: true,
451
- };
452
- let type = fileTypeMap[suffix];
453
- if (undefined === type) {
454
- return false;
455
- }
456
- return true;
457
- },
458
- isPicture: function (suffix) {
459
- if (!suffix || suffix === "") {
460
- return false;
461
- }
462
-
463
- let fileTypeMap = {
464
- jpg: true,
465
- jpeg: true,
466
- png: true,
467
- gif: true,
468
- bmp: true,
469
- mpg: true,
470
- webp: true,
471
- };
472
-
473
- let type = fileTypeMap[suffix];
474
- if (undefined === type) {
475
- return false;
476
- }
477
-
478
- return true;
479
- },
480
- isVideo: function (suffix) {
481
- if (!suffix || suffix === "") {
482
- return false;
483
- }
484
- let fileTypeMap = {
485
- avi: true,
486
- mov: true,
487
- mpeg: true,
488
- mpg: true,
489
- mp4: true,
490
- rmvb: true,
491
- asf: true,
492
- flv: true,
493
- ogg: true,
494
- };
495
-
496
- let type = fileTypeMap[suffix];
497
- if (undefined === type) {
498
- return false;
499
- }
500
-
501
- return true;
502
- },
503
- isText: function (suffix) {
504
- if (!suffix || suffix === "") {
505
- return false;
506
- }
507
- let fileTypeMap = {
508
- txt: true,
509
- log: true,
510
- md: true,
511
- py: true,
512
- java: true,
513
- cpp: true,
514
- hpp: true,
515
- c: true,
516
- h: true,
517
- json: true,
518
- xml: true,
519
- html: true,
520
- sql: true,
521
- js: true,
522
- css: true,
523
- jsp: true,
524
- php: true,
525
- properties: true,
526
- conf: true,
527
- out: true,
528
- sh: true,
529
- bat: true,
530
- msg: true,
531
- cmake: true,
532
- yaml: true,
533
- yml: true,
534
- };
535
-
536
- let type = fileTypeMap[suffix];
537
- if (undefined === type) {
538
- return false;
539
- }
540
-
541
- return true;
542
- },
543
- isZip: function (suffix) {
544
- if (!suffix || suffix === "") {
545
- return false;
546
- }
547
- let fileTypeMap = {
548
- zip: true,
549
- war: true,
550
- rar: true,
551
- "7z": true,
552
- gz: true,
553
- tgz: true,
554
- xz: true,
555
- txz: true,
556
- bz2: true,
557
- tbz2: true,
558
- tar: true,
559
- };
560
-
561
- let type = fileTypeMap[suffix];
562
- if (undefined === type) {
563
- return false;
564
- }
565
-
566
- return true;
567
- },
568
- isOffice: function (suffix) {
569
- if (!suffix || suffix === "") {
570
- return false;
571
- }
572
- let fileTypeMap = {
573
- doc: true,
574
- docx: true,
575
- ppt: true,
576
- pptx: true,
577
- xls: true,
578
- xlsx: true,
579
- };
580
-
581
- let type = fileTypeMap[suffix];
582
- if (undefined === type) {
583
- return false;
584
- }
585
-
586
- return true;
587
- },
588
- isPdf: function (suffix) {
589
- if (!suffix || suffix === "") {
590
- return false;
591
- }
592
- let fileTypeMap = {
593
- pdf: true,
594
- };
595
-
596
- let type = fileTypeMap[suffix];
597
- if (undefined === type) {
598
- return false;
599
- }
600
-
601
- return true;
602
- },
603
- isPictureFile: function (fileName) {
604
- if (!fileName) return false;
605
- let typeStr = Object.prototype.toString.call(fileName);
606
- let suffix = null;
607
- if (typeStr === "[object Object]") {
608
- suffix = this.getFileSuffix(fileName.name);
609
- } else {
610
- suffix = this.getFileSuffix(fileName);
611
- }
612
- return this.isPicture(suffix);
613
- },
614
- isTextFile: function (fileName) {
615
- let suffix = this.getFileSuffix(fileName);
616
- return this.isText(suffix);
617
- },
618
- getShowUrl(url, showImagePreview) {
619
- let index = url.lastIndexOf("/");
620
- let filename;
621
- if (index >= 0) {
622
- filename = url.substring(url.lastIndexOf("/") + 1);
623
- } else {
624
- filename = url;
625
- }
626
-
627
- if (this.isPictureFile(filename) && showImagePreview !== false) {
628
- return url;
629
- } else {
630
- return this.getFileIconRequire(filename);
631
- }
632
- },
633
- resolveFileIconName: function (name, showType) {
634
- let iconType = this.getDiyFileIconType(name) || "other";
635
- if (showType) {
636
- iconType = showType;
637
- }
638
- return FILE_ICON_NAME_MAP[iconType];
639
- },
640
- getFileIconRequire: function (name, showType) {
641
- return reqImg(this.resolveFileIconName(name, showType));
642
- },
643
- getFileIconPath: function (name, showType) {
644
- return this.getFileIconRequire(name, showType);
645
- },
646
- getDiyFileIconType: function (name) {
647
- let suffix = this.getFileSuffix(name);
648
- if (suffix === "") {
649
- // 默认是文本类型
650
- return "";
651
- }
652
-
653
- let iconType = FILE_ICON_TYPE_MAP[suffix];
654
- if (undefined === iconType) {
655
- return "";
656
- }
657
- return iconType;
658
- },
659
- getFileExtension(urlString) {
660
- if (!urlString) return null;
661
- const url = new URL(urlString);
662
- // 获取路径部分,例如 "/images/photo.jpg"
663
- const pathname = url.pathname;
664
-
665
- // 使用 lastIndexOf 找到最后一个点的位置
666
- const lastDotIndex = pathname.lastIndexOf(".");
667
-
668
- // 如果没有点,或者点在最后一位(即没有后缀),返回空字符串
669
- if (lastDotIndex === -1 || lastDotIndex === pathname.length - 1) {
670
- return "";
671
- }
672
-
673
- // 截取点之后的部分
674
- return pathname.slice(lastDotIndex + 1).toLowerCase();
675
- },
676
- downloadFile: function () {
677
- let filePath, name;
678
- let opts;
679
- if (typeof arguments[0] === "string") {
680
- filePath = arguments[0];
681
- name = arguments[1];
682
- } else {
683
- opts = arguments[0];
684
- filePath = opts.filePath;
685
- name = opts.name;
686
- }
687
- if (filePath) {
688
- let url = null;
689
- if (filePath.indexOf("?") >= 0) {
690
- url = filePath + "&_d=true";
691
- } else {
692
- url = filePath + "?_d=true";
693
- }
694
- if (name) {
695
- let fileSuffix = this.getFileExtension(filePath);
696
- if (fileSuffix && !name.endsWith("." + fileSuffix)) {
697
- name = name + "." + fileSuffix;
698
- }
699
-
700
- url += "&_n=" + encodeURIComponent(name);
701
- }
702
- // window.open(url);
703
- openInNewTab(url);
704
- }
705
- },
706
- isPreviewFile(fileName) {
707
- let fileSuffix = this.getFileSuffix(fileName);
708
- return typeList.includes(fileSuffix);
709
- },
710
- };
711
-
712
- Vue.prototype.$openFilePreview = function () {
713
- let filePath;
714
- let opts;
715
- if (typeof arguments[0] === "string") {
716
- filePath = arguments[0];
717
- } else {
718
- let attachment = arguments[0];
719
- filePath = attachment.domain + attachment.url;
720
- }
721
- let fileSuffix = this.$commonFileUtil.getFileSuffix(filePath);
722
- if (!typeList.includes(fileSuffix)) {
723
- return;
724
- }
725
-
726
- this.$http({
727
- url: USER_PREFIX + "/sf_common/getFilePreviewUrl",
728
- method: `post`,
729
- data: {
730
- url: filePath,
731
- },
732
- isLoading: true,
733
- success: (res) => {
734
- if (res.objx) {
735
- openInNewTab(res.objx);
736
- }
737
- },
738
- });
739
- };
740
-
741
- function openInNewTab(url) {
742
- if (!url) return;
743
- let a = document.createElement("a");
744
- a.href = url;
745
- a.target = "_blank";
746
- document.body.appendChild(a);
747
- a.click();
748
- document.body.removeChild(a);
749
- }
750
-
751
- Vue.prototype.$getFilePreviewUrl = async function (obj, callback) {
752
- let filePath;
753
- let opts;
754
- if (typeof obj === "string") {
755
- filePath = obj;
756
- } else {
757
- let attachment = obj;
758
- filePath = attachment.domain + attachment.url;
759
- }
760
- let fileSuffix = this.$commonFileUtil.getFileSuffix(filePath);
761
- /*if (!typeList.includes(fileSuffix)) {
762
- return;
763
- }*/
764
-
765
- return this.$http({
766
- url: USER_PREFIX + "/sf_common/getFilePreviewUrl",
767
- method: `post`,
768
- data: {
769
- url: filePath,
770
- },
771
- isLoading: true,
772
- success: (res) => {
773
- callback && callback(res.objx);
774
- },
775
- });
776
- };
777
-
778
- Vue.prototype.$baseFilePreview = function (attachment, index) {
779
- let that = this;
780
- let openImagePreView = function (attachments, index) {
781
- let pictureIndex = -1;
782
- let pictureDtoList = [];
783
- index = index || 0;
784
- attachments.forEach((item, i) => {
785
- let typeStr = Object.prototype.toString.call(item);
786
- if (typeStr === "[object Object]") {
787
- if (that.$commonFileUtil.isPictureFile(item.url)) {
788
- if (i <= index) {
789
- pictureIndex++;
790
- }
791
- pictureDtoList.push(item.domain + item.url);
792
- }
793
- } else {
794
- if (that.$commonFileUtil.isPictureFile(item)) {
795
- if (i <= index) {
796
- pictureIndex++;
797
- }
798
- pictureDtoList.push(item);
799
- }
800
- }
801
- });
802
-
803
- let a = Vue.extend(ElImageViewer);
804
- let instance = new a({
805
- propsData: {
806
- onClose: () => {
807
- dom.remove();
808
- },
809
- initialIndex: pictureIndex,
810
- urlList: pictureDtoList,
811
- },
812
- });
813
- let dom = instance.$mount().$el;
814
- document.body.append(dom);
815
- };
816
- let openPreview = function (attachment, index) {
817
- if (Array.isArray(attachment)) {
818
- let currentFile = attachment[index];
819
- let typeStr = Object.prototype.toString.call(currentFile);
820
- let url =
821
- typeStr === "[object Object]"
822
- ? currentFile.domain + currentFile.url
823
- : currentFile;
824
- if (that.$commonFileUtil.isPictureFile(url)) {
825
- openImagePreView(attachment, index);
826
- } else if (that.$commonFileUtil.isPreviewFile(url)) {
827
- that.$openFilePreview(url);
828
- }
829
- } else {
830
- let typeStr = Object.prototype.toString.call(attachment);
831
- let url =
832
- typeStr === "[object Object]"
833
- ? attachment.domain + attachment.url
834
- : attachment;
835
- if (that.$commonFileUtil.isPictureFile(url)) {
836
- openImagePreView([url], 0);
837
- } else if (that.$commonFileUtil.isPreviewFile(url)) {
838
- that.$openFilePreview(url);
839
- }
840
- }
841
- };
842
- openPreview(attachment, index);
843
- };
844
-
845
- Vue.prototype.$openEditView = function (key) {
846
- this[key] = false;
847
- setTimeout(() => {
848
- this[key] = true;
849
- }, 200);
850
- };
851
-
852
- Vue.prototype.$baseReload = function (param) {
853
- this.$emit("reload", this, param);
854
- };
855
-
856
- Vue.prototype.$reloadHandle = function (target, param) {
857
- let visibleKey = target.$attrs["visible-key"] || "showEdit";
858
- let parentTarget = target.$attrs["parent-target"] || target.$parent;
859
- let originTarget = parentTarget.$refs._viewDialog ? parentTarget : target;
860
- let updateParam =
861
- param !== null &&
862
- param !== undefined &&
863
- param.updateParam !== null &&
864
- param.updateParam !== undefined
865
- ? param.updateParam
866
- : {};
867
- for (let key in updateParam) {
868
- originTarget.$emit("update:" + key, updateParam[key]);
869
- }
870
- parentTarget[visibleKey] = false;
871
- return new Promise((resolve) => {
872
- setTimeout(() => {
873
- parentTarget[visibleKey] = true;
874
- parentTarget.$nextTick(resolve);
875
- }, 200);
876
- });
877
- };
878
-
879
- Vue.prototype.$baseStartPickerOptions = function (value, type) {
880
- return {
881
- disabledDate: (time) => {
882
- if (value !== null && value !== undefined && value !== "") {
883
- let date = new Date(value.replace(/-/g, "/"));
884
- if (!type || type === "date") {
885
- date.setDate(date.getDate() + 1);
886
- return time.getTime() >= date.getTime();
887
- } else if (type === "year") {
888
- return time.getYear() > date.getYear();
889
- } else if (type === "month") {
890
- date.setMonth(date.getMonth() + 1);
891
- return time.getTime() >= date.getTime();
892
- }
893
- } else {
894
- return false;
895
- }
896
- },
897
- };
898
- };
899
-
900
- Vue.prototype.$baseEndPickerOptions = function (value, format) {
901
- return {
902
- disabledDate: (time) => {
903
- if (value !== null && value !== undefined && value !== "") {
904
- let date = new Date(value.replace(/-/g, "/"));
905
- return time.getTime() < date.getTime();
906
- } else {
907
- return false;
908
- }
909
- },
910
- };
911
- };
912
-
913
- //除法
914
- function baseDiv() {
915
- let value = 0;
916
- if (arguments.length) {
917
- value = arguments[0];
918
- for (let i = 1; i < arguments.length; i++) {
919
- value = XEUtils.divide(value, arguments[i]);
920
- }
921
- }
922
- return value;
923
- }
924
-
925
- //乘法
926
- function baseMul() {
927
- let value = 0;
928
- if (arguments.length) {
929
- value = arguments[0];
930
- for (let i = 1; i < arguments.length; i++) {
931
- value = XEUtils.multiply(value, arguments[i]);
932
- }
933
- }
934
- return value;
935
- }
936
-
937
- //加法
938
- function baseAdd() {
939
- let value = 0;
940
- if (arguments.length) {
941
- value = arguments[0];
942
- for (let i = 1; i < arguments.length; i++) {
943
- value = XEUtils.add(value, arguments[i]);
944
- }
945
- }
946
- return value;
947
- }
948
-
949
- //减法
950
- function baseSub() {
951
- let value = 0;
952
- if (arguments.length) {
953
- value = arguments[0];
954
- for (let i = 1; i < arguments.length; i++) {
955
- value = XEUtils.subtract(value, arguments[i]);
956
- }
957
- }
958
- return value;
959
- }
960
-
961
- Vue.prototype.$baseAdd = baseAdd;
962
- Vue.prototype.$baseSub = baseSub;
963
- Vue.prototype.$baseMul = baseMul;
964
- Vue.prototype.$baseDiv = baseDiv;
965
-
966
- /**
967
- * 格式化数字为带千分位的字符串。
968
- *
969
- * @param {string | number} value - 输入值
970
- * @param {Object} [options={}] - 配置
971
- * @param {boolean} [options.fixed=false] -
972
- * - `true`: 启用定点精度处理 —— 使用 toFixed(digits) 四舍五入并补零到指定小数位。
973
- * - `false`(默认): 保留原始小数形式(不四舍五入、不补零、保留尾随零)。
974
- * @param {number} [options.digits=2] - 小数位数(仅在 fixed: true 时生效)
975
- * @param {string} [options.thousandsSeparator=','] - 千分位分隔符(始终生效)
976
- * @param {string} [options.decimalSeparator='.'] - 小数点符号
977
- * @returns {string}
978
- *
979
- * @example
980
- * // 默认:保留原始小数
981
- * formatNumber(0.2); // "0.2"
982
- * formatNumber("0.2000"); // "0.2000"
983
- *
984
- * // 启用定点精度处理
985
- * formatNumber(0.2, { fixed: true }); // "0.20"
986
- * formatNumber("123.456", { fixed: true, digits: 1 }); // "123.5"
987
- * formatNumber(1000, { fixed: true, digits: 0 }); // "1,000"
988
- */
989
- function formatNumber(value, options = {}) {
990
- if (value === null || value === undefined || value === "") {
991
- return "";
992
- }
993
-
994
- const {
995
- fixed = false,
996
- digits = 2,
997
- thousandsSeparator = ",",
998
- decimalSeparator = ".",
999
- } = options;
1000
-
1001
- const isNumber = typeof value === "number";
1002
- let str = String(value).trim();
1003
-
1004
- // Normalize ".123" → "0.123"
1005
- if (str.charCodeAt(0) === 46) {
1006
- str = "0" + str;
1007
- } else if (str.startsWith("-.")) {
1008
- str = "-0." + str.slice(2);
1009
- }
1010
-
1011
- let intPart, decPart, isNegative;
1012
-
1013
- if (fixed) {
1014
- // ✅ 启用精度处理:toFixed + 补零
1015
- const num = isNumber ? value : parseFloat(str);
1016
- if (num !== num) return str;
1017
-
1018
- const fixedStr = num.toFixed(digits);
1019
- const dotIndex = fixedStr.indexOf(".");
1020
- intPart = dotIndex === -1 ? fixedStr : fixedStr.slice(0, dotIndex);
1021
- decPart = dotIndex === -1 ? "" : fixedStr.slice(dotIndex + 1);
1022
- isNegative = intPart.charCodeAt(0) === 45;
1023
- if (isNegative) intPart = intPart.slice(1);
1024
- } else {
1025
- // 保留原始小数
1026
- let s = str;
1027
- isNegative = s.charCodeAt(0) === 45;
1028
- if (isNegative) s = s.slice(1);
1029
-
1030
- const dotIndex = s.indexOf(".");
1031
- intPart = dotIndex === -1 ? s : s.slice(0, dotIndex);
1032
- decPart = dotIndex === -1 ? "" : s.slice(dotIndex + 1);
1033
-
1034
- if (intPart === "") intPart = "0";
1035
- if (!/^\d+$/.test(intPart)) return str;
1036
- }
1037
-
1038
- // 千分位(始终应用)
1039
- let fmtInt = intPart;
1040
- if (intPart !== "0") {
1041
- let out = "";
1042
- for (let i = intPart.length - 1, c = 0; i >= 0; i--, c++) {
1043
- if (c > 0 && c % 3 === 0) out = thousandsSeparator + out;
1044
- out = intPart[i] + out;
1045
- }
1046
- fmtInt = out;
1047
- }
1048
-
1049
- // 拼接
1050
- let result = isNegative ? "-" + fmtInt : fmtInt;
1051
- if (decPart) {
1052
- result += decimalSeparator + decPart;
1053
- } else if (fixed && digits > 0) {
1054
- result += decimalSeparator + "0".repeat(digits);
1055
- }
1056
-
1057
- return result;
1058
- }
1059
- Vue.prototype.$formatNumber = formatNumber;
1060
-
1061
- /**
1062
- * 生成一个符合 RFC4122 标准的随机 UUID (v4)
1063
- * @returns {string} 格式为 "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" 的 UUID 字符串
1064
- */
1065
- function generateUUID() {
1066
- const buf = new Uint8Array(16);
1067
- crypto.getRandomValues(buf);
1068
- buf[6] = (buf[6] & 0x0f) | 0x40; // version 4
1069
- buf[8] = (buf[8] & 0x3f) | 0x80; // variant RFC4122
1070
- const hex = Array.from(buf, (b) => b.toString(16).padStart(2, "0")).join(
1071
- ""
1072
- );
1073
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(
1074
- 12,
1075
- 16
1076
- )}-${hex.slice(16, 20)}-${hex.slice(20)}`;
1077
- }
1078
- Vue.prototype.$generateUUID = generateUUID;
1079
-
1080
- //数字精确位数
1081
- Vue.prototype.$currency = function (value, priceScale, priceRoundType) {
1082
- if (value !== null && value !== undefined) {
1083
- if (priceScale === null || priceScale === undefined) {
1084
- priceScale = 2;
1085
- }
1086
- if (priceRoundType === null || priceRoundType === undefined) {
1087
- priceRoundType = "roundHalfUp";
1088
- }
1089
- let price;
1090
- if (priceRoundType === "roundHalfUp") {
1091
- price = (
1092
- Math.round(value * Math.pow(10, priceScale)) /
1093
- Math.pow(10, priceScale)
1094
- ).toFixed(priceScale);
1095
- } else if (priceRoundType === "roundUp") {
1096
- price = (
1097
- Math.ceil(value * Math.pow(10, priceScale)) / Math.pow(10, priceScale)
1098
- ).toFixed(priceScale);
1099
- } else {
1100
- price = (
1101
- Math.floor(value * Math.pow(10, priceScale)) /
1102
- Math.pow(10, priceScale)
1103
- ).toFixed(priceScale);
1104
- }
1105
- return price;
1106
- }
1107
- };
1108
-
1109
- Vue.prototype.$getBaseDicts = async function (option) {
1110
- let isLoading = option.isLoading || false;
1111
- return this.$http({
1112
- url: USER_PREFIX + "/common_attribute/listItems",
1113
- method: `post`,
1114
- data: {
1115
- code: option.code,
1116
- enabled: true,
1117
- forCompany: true,
1118
- ...option.data,
1119
- },
1120
- isLoading: isLoading,
1121
- modalStrictly: true,
1122
- success: (res) => {
1123
- let dicts = res.objx || [];
1124
- let dictMap = {};
1125
- for (let item of dicts) {
1126
- dictMap[item.sn] = item.value;
1127
- }
1128
- /* dicts.forEach((item) => {
1129
- dictMap[item.sn] = item.value;
1130
- }); */
1131
- option.success &&
1132
- option.success({
1133
- dicts,
1134
- dictMap,
1135
- });
1136
- },
1137
- });
1138
- };
1139
-
1140
- imFun.Form.methods.$baseValidate = function (callback, opt) {
1141
- let that = this;
1142
- that.validate((valid, obj, c, d) => {
1143
- if (!valid && (!opt || opt.errorTip !== false)) {
1144
- this.$message({
1145
- message: this.$t2("必填项不能为空", "system.message.required"),
1146
- type: "error",
1147
- duration: 2000,
1148
- });
1149
- }
1150
- scrollToFirstError(that);
1151
- callback(valid, obj);
1152
- });
1153
- };
1154
-
1155
- function scrollToFirstError(formTarget) {
1156
- // 获取第一个验证失败的字段
1157
- // let formTarget = this.$refs['renderForm'];
1158
- const firstErrorField = Object.keys(formTarget.fields).find((key) => {
1159
- return formTarget.fields[key].validateState === "error";
1160
- });
1161
-
1162
- if (firstErrorField) {
1163
- const field = formTarget.fields[firstErrorField];
1164
-
1165
- let dom = field.$el;
1166
- if (dom) {
1167
- // 滚动到该字段位置
1168
- dom.scrollIntoView({
1169
- behavior: "smooth",
1170
- block: "center",
1171
- });
1172
-
1173
- // 添加高亮效果
1174
- dom.classList.add("highlight");
1175
-
1176
- // 3秒后移除高亮效果
1177
- setTimeout(() => {
1178
- dom.classList.remove("highlight");
1179
- }, 3000);
1180
- }
1181
- }
1182
- }
1183
-
1184
- Vue.prototype.$getBillInfo = async function (option) {
1185
- let defaultOption = {
1186
- url: null,
1187
- method: `post`,
1188
- data: {},
1189
- isLoading: true,
1190
- modalStrictly: true,
1191
- success: null,
1192
- };
1193
- let opt = Object.assign({}, defaultOption, option);
1194
- delete opt.wfConfig;
1195
- return this.$http({
1196
- ...opt,
1197
- success: (res, response) => {
1198
- option.success && option.success(res, response);
1199
- },
1200
- });
1201
- };
1202
-
1203
- Vue.prototype.$downloadByFileWhole = function (fileWhole, fileName) {
1204
- let that = this;
1205
- if (!fileWhole) {
1206
- this.$baseAlert("凭证信息不存在");
1207
- return;
1208
- }
1209
- let getDownloadDomian = function (callback) {
1210
- that.$http({
1211
- method: "post",
1212
- url: USER_PREFIX + "/common/fileDownloadUrl",
1213
- data: {},
1214
- isLoading: true,
1215
- success: (res) => {
1216
- callback(res.objx);
1217
- },
1218
- });
1219
- };
1220
- getDownloadDomian((domain) => {
1221
- if (fileName) {
1222
- fileWhole.fileName = fileName;
1223
- }
1224
- that.$http({
1225
- method: "post",
1226
- url: domain + "/docfile/download",
1227
- data: fileWhole,
1228
- isLoading: true,
1229
- success: (res) => {
1230
- // window.open(res.objx.url);
1231
- let url = res.objx.url;
1232
- openInNewTab(url);
1233
- },
1234
- });
1235
- });
1236
- };
1237
-
1238
- let isDef = function (value) {
1239
- return value !== undefined && value !== null;
1240
- };
1241
-
1242
- Vue.prototype.$t2 = function (defaultValue, path, values) {
1243
- let that = window.$vueRoot;
1244
- if (!that.hasOwnProperty("_i18n")) {
1245
- return defaultValue;
1246
- }
1247
- const i18n = that.$i18n;
1248
- path = path || defaultValue;
1249
- return i18n.te(path) ? i18n.t(path, values) : defaultValue;
1250
- };
1251
-
1252
- Vue.prototype.$t1 = function (path, values) {
1253
- let that = window.$vueRoot;
1254
- if (!that.hasOwnProperty("_i18n")) {
1255
- return path;
1256
- }
1257
- let lang = that.$i18n.locale;
1258
- const i18n = that.$i18n;
1259
- if (lang === "zh") {
1260
- let val = i18n._t(path, lang, { zh: { [path]: path } }, null, values);
1261
- return val;
1262
- } else {
1263
- if (!i18n.te(path)) {
1264
- return i18n._t(path, lang, { zh: { [path]: path } }, null, values);
1265
- } else {
1266
- return (
1267
- i18n.t(path, values) ||
1268
- i18n._t(path, lang, { zh: { [path]: path } }, null, values)
1269
- );
1270
- }
1271
- }
1272
- };
1273
-
1274
- Vue.prototype.$i18nVal = function (zhValue, enValue) {
1275
- let that = window.$vueRoot;
1276
- if (!that.hasOwnProperty("_i18n")) {
1277
- return zhValue;
1278
- }
1279
- let $i18n = that.$i18n;
1280
- let value = zhValue;
1281
- if ($i18n.locale === "zh") {
1282
- value = zhValue;
1283
- } else if ($i18n.locale === "en") {
1284
- value = enValue;
1285
- }
1286
- return value;
1287
- };
1288
-
1289
- Vue.prototype.$utcToLocal = function (utcTime) {
1290
- if (!utcTime) return utcTime;
1291
- let offsetHours = this.$store.getters.utcTransformOffset; // 时区偏移量,单位:小时
1292
- if (!offsetHours || offsetHours === 0) return utcTime;
1293
- let localTime = moment(utcTime).add(offsetHours, "hours");
1294
- return localTime.format("YYYY-MM-DD HH:mm:ss");
1295
- };
1296
-
1297
- Vue.prototype.$window = window;
1298
- };
1299
-
1300
- window && Object.assign(window, imFun.prefixConfig);
1301
- if (typeof window !== "undefined" && window.Vue) {
1302
- install(window.Vue);
1303
- }
1304
-
1305
- export default install;
1
+ /**version-1.0*/
2
+ let install = {};
3
+
4
+ import request from "./request";
5
+ import * as lodash from "lodash";
6
+ import { Loading, Message, MessageBox, Notification, Form } from "element-ui";
7
+ import store from "../store";
8
+ import ElImageViewer from "../components/VabUpload/image-viewer";
9
+
10
+ import { getToken } from "./auth";
11
+ import XEUtils from "xe-utils";
12
+
13
+ import prefixConfig from "@/prefixConfig.js";
14
+ import moment from "moment";
15
+ import { openView } from "./repeatOpen";
16
+ import { assetUrl } from "./assetUrl";
17
+ import {
18
+ buildBaseDictsKey,
19
+ invalidateBaseDicts,
20
+ loadBaseDicts,
21
+ toBaseDicts,
22
+ } from "./baseDictsCache";
23
+
24
+ let imFun = {
25
+ request,
26
+ lodash,
27
+ Loading,
28
+ Message,
29
+ MessageBox,
30
+ Notification,
31
+ Form,
32
+ store,
33
+ getToken,
34
+ prefixConfig,
35
+ };
36
+
37
+ const FILE_ICON_NAME_MAP = {
38
+ word: "ico-wrod.svg",
39
+ excel: "ico-excel.svg",
40
+ ppt: "ico-ppt.svg",
41
+ pdf: "ico-pdf.svg",
42
+ picture: "ico-photo.svg",
43
+ video: "ico-video.svg",
44
+ audio: "ico-music.svg",
45
+ html: "ico-html.svg",
46
+ txt: "ico-txt.svg",
47
+ java: "ico-java.svg",
48
+ vue: "ico-vue.svg",
49
+ ftl: "ico-ftl.svg",
50
+ xml: "ico-xml.svg",
51
+ flash: "ico-default_wenjian.svg",
52
+ zip: "ico-yasuobao.svg",
53
+ exe: "ico-default_wenjian.svg",
54
+ psd: "ico-psd.svg",
55
+ folder: "ico-wenjianjia.svg",
56
+ other: "ico-default_wenjian.svg",
57
+ };
58
+
59
+ // 使用静态 require 建立明确的资源依赖图,避免动态目录 require 把业务图片一并打包。
60
+ // webpack4/5 的返回值差异统一由 assetUrl 处理。
61
+ const FILE_ICON_MODULE_MAP = {
62
+ "ico-wrod.svg": require("@base/core-resources/images/ico-wrod.svg"),
63
+ "ico-excel.svg": require("@base/core-resources/images/ico-excel.svg"),
64
+ "ico-ppt.svg": require("@base/core-resources/images/ico-ppt.svg"),
65
+ "ico-pdf.svg": require("@base/core-resources/images/ico-pdf.svg"),
66
+ "ico-photo.svg": require("@base/core-resources/images/ico-photo.svg"),
67
+ "ico-video.svg": require("@base/core-resources/images/ico-video.svg"),
68
+ "ico-music.svg": require("@base/core-resources/images/ico-music.svg"),
69
+ "ico-html.svg": require("@base/core-resources/images/ico-html.svg"),
70
+ "ico-txt.svg": require("@base/core-resources/images/ico-txt.svg"),
71
+ "ico-java.svg": require("@base/core-resources/images/ico-java.svg"),
72
+ "ico-vue.svg": require("@base/core-resources/images/ico-vue.svg"),
73
+ "ico-ftl.svg": require("@base/core-resources/images/ico-ftl.svg"),
74
+ "ico-xml.svg": require("@base/core-resources/images/ico-xml.svg"),
75
+ "ico-yasuobao.svg": require("@base/core-resources/images/ico-yasuobao.svg"),
76
+ "ico-psd.svg": require("@base/core-resources/images/ico-psd.svg"),
77
+ "ico-wenjianjia.svg": require("@base/core-resources/images/ico-wenjianjia.svg"),
78
+ "ico-default_wenjian.svg": require("@base/core-resources/images/ico-default_wenjian.svg"),
79
+ };
80
+
81
+ function reqImg(name) {
82
+ const mod = FILE_ICON_MODULE_MAP[name] || FILE_ICON_MODULE_MAP[FILE_ICON_NAME_MAP.other];
83
+ return assetUrl(mod);
84
+ }
85
+
86
+ const FILE_ICON_TYPE_MAP = {
87
+ doc: "word",
88
+ docx: "word",
89
+ xls: "excel",
90
+ xlsx: "excel",
91
+ ppt: "ppt",
92
+ pptx: "ppt",
93
+ pdf: "pdf",
94
+ jpg: "picture",
95
+ jpeg: "picture",
96
+ png: "picture",
97
+ gif: "picture",
98
+ mp3: "video",
99
+ mp4: "video",
100
+ mpg: "video",
101
+ mkv: "video",
102
+ rmvb: "video",
103
+ avi: "video",
104
+ mov: "video",
105
+ wav: "audio",
106
+ html: "html",
107
+ htm: "html",
108
+ txt: "txt",
109
+ java: "java",
110
+ vue: "vue",
111
+ ftl: "ftl",
112
+ xml: "xml",
113
+ swf: "flash",
114
+ zip: "zip",
115
+ rar: "zip",
116
+ "7z": "zip",
117
+ // exe: 'exe',
118
+ psd: "psd",
119
+ };
120
+
121
+ let typeList = [
122
+ "doc",
123
+ "docx",
124
+ "xls",
125
+ "xlsx",
126
+ "ppt",
127
+ "pptx",
128
+ "csv",
129
+ "wps",
130
+ "dps",
131
+ "et",
132
+ "ett",
133
+ "wpt",
134
+ "vsd",
135
+ "vsdx",
136
+ "wmf",
137
+ "emf",
138
+ "psd",
139
+ "eps",
140
+ "pdf",
141
+ "xmind",
142
+ "obj",
143
+ "3ds",
144
+ "stl",
145
+ "ply",
146
+ "gltf",
147
+ "glb",
148
+ "off",
149
+ "3dm",
150
+ "fbx",
151
+ "dae",
152
+ "wrl",
153
+ "3mf",
154
+ "ifc",
155
+ "brep",
156
+ "step",
157
+ "iges",
158
+ "fcstd",
159
+ "bim",
160
+ "dwg",
161
+ "dxf",
162
+ "dwf",
163
+ "iges",
164
+ "igs",
165
+ "dwt",
166
+ "dng",
167
+ "ifc",
168
+ "dwfx",
169
+ "stl",
170
+ "cf2",
171
+ "plt",
172
+ "txt",
173
+ "xml",
174
+ "md",
175
+ "java",
176
+ "php",
177
+ "py",
178
+ "js",
179
+ "css",
180
+ "zip",
181
+ "rar",
182
+ "jar",
183
+ "tar",
184
+ "gzip",
185
+ "7z",
186
+ "mp3",
187
+ "wav",
188
+ "mp4",
189
+ "flv",
190
+ "avi",
191
+ "mov",
192
+ "rm",
193
+ "mkv",
194
+ "mpeg",
195
+ "mpg",
196
+ "rmvb",
197
+ "wmv",
198
+ "3gp",
199
+ "swf",
200
+ "drawio",
201
+ "tif",
202
+ "tiff",
203
+ "jfif",
204
+ "webp",
205
+ "tga",
206
+ "svg",
207
+ "vue",
208
+ "ftl",
209
+ ];
210
+
211
+ const accessToken = imFun.store.getters["user/token"];
212
+
213
+ const loadingText = "";
214
+ const messageDuration = 3000;
215
+
216
+ install = (Vue, opts = {}) => {
217
+ /**http请求*/
218
+ let $http = async function (option) {
219
+ option = option || {};
220
+ if (!option.loadingTarget && this.$el) {
221
+ option.loadingTarget = this.$el;
222
+ }
223
+ if (!option.vueTarget) {
224
+ option.vueTarget = this;
225
+ }
226
+ if (option.sync === false) {
227
+ return await imFun.request(option);
228
+ } else {
229
+ return imFun.request(option);
230
+ }
231
+ };
232
+
233
+ Vue.prototype.$commonHttp = function (opts) {
234
+ let defaultOption = {
235
+ addCreateInfo: true,
236
+ queryCreateInfo: window.$vueRoot.$store.getters.queryCreateInfo || "0",
237
+ };
238
+ let option = Object.assign({}, defaultOption, opts);
239
+ if (opts.addCreateInfo === null || opts.addCreateInfo === undefined) {
240
+ option.addCreateInfo = defaultOption.addCreateInfo;
241
+ }
242
+ if (
243
+ opts.queryCreateInfo === null ||
244
+ opts.queryCreateInfo === undefined ||
245
+ opts.queryCreateInfo === true
246
+ ) {
247
+ option.queryCreateInfo = defaultOption.queryCreateInfo;
248
+ }
249
+ if (opts.queryCreateInfo === false) {
250
+ option.queryCreateInfo = "0";
251
+ }
252
+ return this.$http(option);
253
+ };
254
+
255
+ Object.assign($http, imFun.request);
256
+ $http.prototype = imFun.request.prototype;
257
+ Vue.prototype.$http = $http;
258
+
259
+ /* 通用打开菜单/路由:开关开启时以独立标签重复打开,否则按原逻辑跳转
260
+ * 用法:this.$openView('/path') 或 this.$openView({ path, query }[, route]) */
261
+ Vue.prototype.$openView = function (location, route) {
262
+ return openView(this.$router, location, route);
263
+ };
264
+
265
+ /* 全局accessToken */
266
+ Vue.prototype.$baseAccessToken = () => {
267
+ return accessToken || imFun.getToken();
268
+ };
269
+
270
+ /* 全局加载层 */
271
+ Vue.prototype.$baseLoading = function (option) {
272
+ let d = this.$el;
273
+ let loading;
274
+ option = option || {};
275
+ if (!option.index) {
276
+ let opts = {
277
+ lock: true,
278
+ background: "hsla(0,0%,100%,.8)",
279
+ target: d,
280
+ };
281
+ Object.assign(opts, option);
282
+ loading = imFun.Loading.service(opts);
283
+ } else {
284
+ let opts = {
285
+ lock: true,
286
+ spinner: "vab-loading-type" + option.index,
287
+ background: "hsla(0,0%,100%,.8)",
288
+ target: d,
289
+ };
290
+ Object.assign(opts, option);
291
+ loading = imFun.Loading.service(opts);
292
+ }
293
+ return loading;
294
+ };
295
+ /* 全局多彩加载层 */
296
+ Vue.prototype.$baseColorfullLoading = function (index, text) {
297
+ let loading;
298
+ if (!index) {
299
+ loading = imFun.Loading.service({
300
+ lock: true,
301
+ text: text || loadingText,
302
+ spinner: "dots-loader",
303
+ background: "hsla(0,0%,100%,.8)",
304
+ target: this.target,
305
+ fullscreen: true,
306
+ });
307
+ } else {
308
+ switch (index) {
309
+ case 1:
310
+ index = "dots";
311
+ break;
312
+ case 2:
313
+ index = "gauge";
314
+ break;
315
+ case 3:
316
+ index = "inner-circles";
317
+ break;
318
+ case 4:
319
+ index = "plus";
320
+ break;
321
+ }
322
+ loading = imFun.Loading.service({
323
+ lock: true,
324
+ text: text || loadingText,
325
+ spinner: index + "-loader",
326
+ background: "hsla(0,0%,100%,.8)",
327
+ target: this.target,
328
+ });
329
+ }
330
+ return loading;
331
+ };
332
+ /* 全局Message */
333
+ Vue.prototype.$baseMessage = ({ message, type, onClose }) => {
334
+ imFun.Message({
335
+ offset: 60,
336
+ showClose: true,
337
+ message: message,
338
+ type: type,
339
+ dangerouslyUseHTMLString: true,
340
+ duration: messageDuration,
341
+ onClose: onClose,
342
+ });
343
+ };
344
+
345
+ /* 全局Alert */
346
+ Vue.prototype.$baseAlert = function (content, title, callback) {
347
+ imFun.MessageBox.alert(content, title || "提示", {
348
+ confirmButtonText: "确定",
349
+ dangerouslyUseHTMLString: true,
350
+ target: this.$el,
351
+ confirmButtonClass: "icondui",
352
+ customClass: "dialog-style",
353
+ callback: (action) => {
354
+ if (callback) {
355
+ callback();
356
+ }
357
+ },
358
+ });
359
+ };
360
+
361
+ /* 全局Confirm */
362
+ Vue.prototype.$baseConfirm = function (content, title) {
363
+ return imFun.MessageBox.confirm(content, title || "提示", {
364
+ confirmButtonText: "确定",
365
+ cancelButtonText: "取消",
366
+ closeOnClickModal: false,
367
+ type: "warning",
368
+ customClass: "dialog-style",
369
+ cancelButtonClass: "iconguanbi",
370
+ confirmButtonClass: "icondui",
371
+ });
372
+ };
373
+
374
+ /* 全局Notification */
375
+ Vue.prototype.$baseNotify = (message, title, type, position) => {
376
+ imFun.Notification({
377
+ title: title,
378
+ message: message,
379
+ position: position || "top-right",
380
+ type: type || "success",
381
+ duration: messageDuration,
382
+ });
383
+ };
384
+
385
+ /* 全局TableHeight */
386
+ Vue.prototype.$baseTableHeight = (formType) => {
387
+ let height = window.innerHeight;
388
+ let paddingHeight = 400;
389
+ const formHeight = 50;
390
+
391
+ if (true) {
392
+ paddingHeight = 365;
393
+ }
394
+
395
+ if ("number" === typeof formType) {
396
+ height = height - paddingHeight - formHeight * formType;
397
+ } else {
398
+ height = height - paddingHeight;
399
+ }
400
+ return height;
401
+ };
402
+
403
+ /* 全局map图层 */
404
+ Vue.prototype.$baseMap = () => {
405
+ return new maptalks.Map("map", {
406
+ center: [116.41348403785, 39.910843952376],
407
+ zoom: 12,
408
+ minZoom: 1,
409
+ maxZoom: 19,
410
+ spatialReference: {
411
+ projection: "baidu",
412
+ },
413
+ attribution: {
414
+ content: "&copy; vue-admin-beautiful",
415
+ },
416
+ baseLayer: new maptalks.TileLayer("base", {
417
+ cssFilter: "sepia(100%) invert(90%)",
418
+ urlTemplate:
419
+ "http://online{s}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&scaler=1&p=1",
420
+ subdomains: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
421
+ attribution:
422
+ '&copy; <a target="_blank" href="http://map.baidu.com">Baidu</a>',
423
+ }),
424
+ });
425
+ };
426
+
427
+ /* 全局lodash */
428
+ Vue.prototype.$baseLodash = imFun.lodash;
429
+ /* 全局事件总线 */
430
+ Vue.prototype.$baseEventBus = new Vue();
431
+ /* 模板里 :src="$assetUrl(require(...))" 用,见 utils/assetUrl.js */
432
+ Vue.prototype.$assetUrl = assetUrl;
433
+
434
+ Vue.prototype.$commonFileUtil = {
435
+ // 文件类型获取与判断接口
436
+ getFileSuffix: function (name) {
437
+ let i = name.lastIndexOf(".");
438
+ if (i < 0) {
439
+ // 默认是文本类型
440
+ return "";
441
+ }
442
+ let suffix = name.substring(i + 1, name.length).toLowerCase();
443
+ return suffix;
444
+ },
445
+ isBinary: function (suffix) {
446
+ if (!suffix || suffix === "") {
447
+ return false;
448
+ }
449
+ let fileTypeMap = {
450
+ bin: true,
451
+ exe: true,
452
+ dll: true,
453
+ so: true,
454
+ lib: true,
455
+ war: true,
456
+ jar: true,
457
+ };
458
+ let type = fileTypeMap[suffix];
459
+ if (undefined === type) {
460
+ return false;
461
+ }
462
+ return true;
463
+ },
464
+ isPicture: function (suffix) {
465
+ if (!suffix || suffix === "") {
466
+ return false;
467
+ }
468
+
469
+ let fileTypeMap = {
470
+ jpg: true,
471
+ jpeg: true,
472
+ png: true,
473
+ gif: true,
474
+ bmp: true,
475
+ mpg: true,
476
+ webp: true,
477
+ };
478
+
479
+ let type = fileTypeMap[suffix];
480
+ if (undefined === type) {
481
+ return false;
482
+ }
483
+
484
+ return true;
485
+ },
486
+ isVideo: function (suffix) {
487
+ if (!suffix || suffix === "") {
488
+ return false;
489
+ }
490
+ let fileTypeMap = {
491
+ avi: true,
492
+ mov: true,
493
+ mpeg: true,
494
+ mpg: true,
495
+ mp4: true,
496
+ rmvb: true,
497
+ asf: true,
498
+ flv: true,
499
+ ogg: true,
500
+ };
501
+
502
+ let type = fileTypeMap[suffix];
503
+ if (undefined === type) {
504
+ return false;
505
+ }
506
+
507
+ return true;
508
+ },
509
+ isText: function (suffix) {
510
+ if (!suffix || suffix === "") {
511
+ return false;
512
+ }
513
+ let fileTypeMap = {
514
+ txt: true,
515
+ log: true,
516
+ md: true,
517
+ py: true,
518
+ java: true,
519
+ cpp: true,
520
+ hpp: true,
521
+ c: true,
522
+ h: true,
523
+ json: true,
524
+ xml: true,
525
+ html: true,
526
+ sql: true,
527
+ js: true,
528
+ css: true,
529
+ jsp: true,
530
+ php: true,
531
+ properties: true,
532
+ conf: true,
533
+ out: true,
534
+ sh: true,
535
+ bat: true,
536
+ msg: true,
537
+ cmake: true,
538
+ yaml: true,
539
+ yml: true,
540
+ };
541
+
542
+ let type = fileTypeMap[suffix];
543
+ if (undefined === type) {
544
+ return false;
545
+ }
546
+
547
+ return true;
548
+ },
549
+ isZip: function (suffix) {
550
+ if (!suffix || suffix === "") {
551
+ return false;
552
+ }
553
+ let fileTypeMap = {
554
+ zip: true,
555
+ war: true,
556
+ rar: true,
557
+ "7z": true,
558
+ gz: true,
559
+ tgz: true,
560
+ xz: true,
561
+ txz: true,
562
+ bz2: true,
563
+ tbz2: true,
564
+ tar: true,
565
+ };
566
+
567
+ let type = fileTypeMap[suffix];
568
+ if (undefined === type) {
569
+ return false;
570
+ }
571
+
572
+ return true;
573
+ },
574
+ isOffice: function (suffix) {
575
+ if (!suffix || suffix === "") {
576
+ return false;
577
+ }
578
+ let fileTypeMap = {
579
+ doc: true,
580
+ docx: true,
581
+ ppt: true,
582
+ pptx: true,
583
+ xls: true,
584
+ xlsx: true,
585
+ };
586
+
587
+ let type = fileTypeMap[suffix];
588
+ if (undefined === type) {
589
+ return false;
590
+ }
591
+
592
+ return true;
593
+ },
594
+ isPdf: function (suffix) {
595
+ if (!suffix || suffix === "") {
596
+ return false;
597
+ }
598
+ let fileTypeMap = {
599
+ pdf: true,
600
+ };
601
+
602
+ let type = fileTypeMap[suffix];
603
+ if (undefined === type) {
604
+ return false;
605
+ }
606
+
607
+ return true;
608
+ },
609
+ isPictureFile: function (fileName) {
610
+ if (!fileName) return false;
611
+ let typeStr = Object.prototype.toString.call(fileName);
612
+ let suffix = null;
613
+ if (typeStr === "[object Object]") {
614
+ suffix = this.getFileSuffix(fileName.name);
615
+ } else {
616
+ suffix = this.getFileSuffix(fileName);
617
+ }
618
+ return this.isPicture(suffix);
619
+ },
620
+ isTextFile: function (fileName) {
621
+ let suffix = this.getFileSuffix(fileName);
622
+ return this.isText(suffix);
623
+ },
624
+ getShowUrl(url, showImagePreview) {
625
+ let index = url.lastIndexOf("/");
626
+ let filename;
627
+ if (index >= 0) {
628
+ filename = url.substring(url.lastIndexOf("/") + 1);
629
+ } else {
630
+ filename = url;
631
+ }
632
+
633
+ if (this.isPictureFile(filename) && showImagePreview !== false) {
634
+ return url;
635
+ } else {
636
+ return this.getFileIconRequire(filename);
637
+ }
638
+ },
639
+ resolveFileIconName: function (name, showType) {
640
+ let iconType = this.getDiyFileIconType(name) || "other";
641
+ if (showType) {
642
+ iconType = showType;
643
+ }
644
+ return FILE_ICON_NAME_MAP[iconType];
645
+ },
646
+ getFileIconRequire: function (name, showType) {
647
+ return reqImg(this.resolveFileIconName(name, showType));
648
+ },
649
+ getFileIconPath: function (name, showType) {
650
+ return this.getFileIconRequire(name, showType);
651
+ },
652
+ getDiyFileIconType: function (name) {
653
+ let suffix = this.getFileSuffix(name);
654
+ if (suffix === "") {
655
+ // 默认是文本类型
656
+ return "";
657
+ }
658
+
659
+ let iconType = FILE_ICON_TYPE_MAP[suffix];
660
+ if (undefined === iconType) {
661
+ return "";
662
+ }
663
+ return iconType;
664
+ },
665
+ getFileExtension(urlString) {
666
+ if (!urlString) return null;
667
+ const url = new URL(urlString);
668
+ // 获取路径部分,例如 "/images/photo.jpg"
669
+ const pathname = url.pathname;
670
+
671
+ // 使用 lastIndexOf 找到最后一个点的位置
672
+ const lastDotIndex = pathname.lastIndexOf(".");
673
+
674
+ // 如果没有点,或者点在最后一位(即没有后缀),返回空字符串
675
+ if (lastDotIndex === -1 || lastDotIndex === pathname.length - 1) {
676
+ return "";
677
+ }
678
+
679
+ // 截取点之后的部分
680
+ return pathname.slice(lastDotIndex + 1).toLowerCase();
681
+ },
682
+ downloadFile: function () {
683
+ let filePath, name;
684
+ let opts;
685
+ if (typeof arguments[0] === "string") {
686
+ filePath = arguments[0];
687
+ name = arguments[1];
688
+ } else {
689
+ opts = arguments[0];
690
+ filePath = opts.filePath;
691
+ name = opts.name;
692
+ }
693
+ if (filePath) {
694
+ let url = null;
695
+ if (filePath.indexOf("?") >= 0) {
696
+ url = filePath + "&_d=true";
697
+ } else {
698
+ url = filePath + "?_d=true";
699
+ }
700
+ if (name) {
701
+ let fileSuffix = this.getFileExtension(filePath);
702
+ if (fileSuffix && !name.endsWith("." + fileSuffix)) {
703
+ name = name + "." + fileSuffix;
704
+ }
705
+
706
+ url += "&_n=" + encodeURIComponent(name);
707
+ }
708
+ // window.open(url);
709
+ openInNewTab(url);
710
+ }
711
+ },
712
+ isPreviewFile(fileName) {
713
+ let fileSuffix = this.getFileSuffix(fileName);
714
+ return typeList.includes(fileSuffix);
715
+ },
716
+ };
717
+
718
+ Vue.prototype.$openFilePreview = function () {
719
+ let filePath;
720
+ let opts;
721
+ if (typeof arguments[0] === "string") {
722
+ filePath = arguments[0];
723
+ } else {
724
+ let attachment = arguments[0];
725
+ filePath = attachment.domain + attachment.url;
726
+ }
727
+ let fileSuffix = this.$commonFileUtil.getFileSuffix(filePath);
728
+ if (!typeList.includes(fileSuffix)) {
729
+ return;
730
+ }
731
+
732
+ this.$http({
733
+ url: USER_PREFIX + "/sf_common/getFilePreviewUrl",
734
+ method: `post`,
735
+ data: {
736
+ url: filePath,
737
+ },
738
+ isLoading: true,
739
+ success: (res) => {
740
+ if (res.objx) {
741
+ openInNewTab(res.objx);
742
+ }
743
+ },
744
+ });
745
+ };
746
+
747
+ function openInNewTab(url) {
748
+ if (!url) return;
749
+ let a = document.createElement("a");
750
+ a.href = url;
751
+ a.target = "_blank";
752
+ document.body.appendChild(a);
753
+ a.click();
754
+ document.body.removeChild(a);
755
+ }
756
+
757
+ Vue.prototype.$getFilePreviewUrl = async function (obj, callback) {
758
+ let filePath;
759
+ let opts;
760
+ if (typeof obj === "string") {
761
+ filePath = obj;
762
+ } else {
763
+ let attachment = obj;
764
+ filePath = attachment.domain + attachment.url;
765
+ }
766
+ let fileSuffix = this.$commonFileUtil.getFileSuffix(filePath);
767
+ /*if (!typeList.includes(fileSuffix)) {
768
+ return;
769
+ }*/
770
+
771
+ return this.$http({
772
+ url: USER_PREFIX + "/sf_common/getFilePreviewUrl",
773
+ method: `post`,
774
+ data: {
775
+ url: filePath,
776
+ },
777
+ isLoading: true,
778
+ success: (res) => {
779
+ callback && callback(res.objx);
780
+ },
781
+ });
782
+ };
783
+
784
+ Vue.prototype.$baseFilePreview = function (attachment, index) {
785
+ let that = this;
786
+ let openImagePreView = function (attachments, index) {
787
+ let pictureIndex = -1;
788
+ let pictureDtoList = [];
789
+ index = index || 0;
790
+ attachments.forEach((item, i) => {
791
+ let typeStr = Object.prototype.toString.call(item);
792
+ if (typeStr === "[object Object]") {
793
+ if (that.$commonFileUtil.isPictureFile(item.url)) {
794
+ if (i <= index) {
795
+ pictureIndex++;
796
+ }
797
+ pictureDtoList.push(item.domain + item.url);
798
+ }
799
+ } else {
800
+ if (that.$commonFileUtil.isPictureFile(item)) {
801
+ if (i <= index) {
802
+ pictureIndex++;
803
+ }
804
+ pictureDtoList.push(item);
805
+ }
806
+ }
807
+ });
808
+
809
+ let a = Vue.extend(ElImageViewer);
810
+ let instance = new a({
811
+ propsData: {
812
+ onClose: () => {
813
+ dom.remove();
814
+ },
815
+ initialIndex: pictureIndex,
816
+ urlList: pictureDtoList,
817
+ },
818
+ });
819
+ let dom = instance.$mount().$el;
820
+ document.body.append(dom);
821
+ };
822
+ let openPreview = function (attachment, index) {
823
+ if (Array.isArray(attachment)) {
824
+ let currentFile = attachment[index];
825
+ let typeStr = Object.prototype.toString.call(currentFile);
826
+ let url =
827
+ typeStr === "[object Object]"
828
+ ? currentFile.domain + currentFile.url
829
+ : currentFile;
830
+ if (that.$commonFileUtil.isPictureFile(url)) {
831
+ openImagePreView(attachment, index);
832
+ } else if (that.$commonFileUtil.isPreviewFile(url)) {
833
+ that.$openFilePreview(url);
834
+ }
835
+ } else {
836
+ let typeStr = Object.prototype.toString.call(attachment);
837
+ let url =
838
+ typeStr === "[object Object]"
839
+ ? attachment.domain + attachment.url
840
+ : attachment;
841
+ if (that.$commonFileUtil.isPictureFile(url)) {
842
+ openImagePreView([url], 0);
843
+ } else if (that.$commonFileUtil.isPreviewFile(url)) {
844
+ that.$openFilePreview(url);
845
+ }
846
+ }
847
+ };
848
+ openPreview(attachment, index);
849
+ };
850
+
851
+ Vue.prototype.$openEditView = function (key) {
852
+ this[key] = false;
853
+ setTimeout(() => {
854
+ this[key] = true;
855
+ }, 200);
856
+ };
857
+
858
+ Vue.prototype.$baseReload = function (param) {
859
+ this.$emit("reload", this, param);
860
+ };
861
+
862
+ Vue.prototype.$reloadHandle = function (target, param) {
863
+ let visibleKey = target.$attrs["visible-key"] || "showEdit";
864
+ let parentTarget = target.$attrs["parent-target"] || target.$parent;
865
+ let originTarget = parentTarget.$refs._viewDialog ? parentTarget : target;
866
+ let updateParam =
867
+ param !== null &&
868
+ param !== undefined &&
869
+ param.updateParam !== null &&
870
+ param.updateParam !== undefined
871
+ ? param.updateParam
872
+ : {};
873
+ for (let key in updateParam) {
874
+ originTarget.$emit("update:" + key, updateParam[key]);
875
+ }
876
+ parentTarget[visibleKey] = false;
877
+ return new Promise((resolve) => {
878
+ setTimeout(() => {
879
+ parentTarget[visibleKey] = true;
880
+ parentTarget.$nextTick(resolve);
881
+ }, 200);
882
+ });
883
+ };
884
+
885
+ Vue.prototype.$baseStartPickerOptions = function (value, type) {
886
+ return {
887
+ disabledDate: (time) => {
888
+ if (value !== null && value !== undefined && value !== "") {
889
+ let date = new Date(value.replace(/-/g, "/"));
890
+ if (!type || type === "date") {
891
+ date.setDate(date.getDate() + 1);
892
+ return time.getTime() >= date.getTime();
893
+ } else if (type === "year") {
894
+ return time.getYear() > date.getYear();
895
+ } else if (type === "month") {
896
+ date.setMonth(date.getMonth() + 1);
897
+ return time.getTime() >= date.getTime();
898
+ }
899
+ } else {
900
+ return false;
901
+ }
902
+ },
903
+ };
904
+ };
905
+
906
+ Vue.prototype.$baseEndPickerOptions = function (value, format) {
907
+ return {
908
+ disabledDate: (time) => {
909
+ if (value !== null && value !== undefined && value !== "") {
910
+ let date = new Date(value.replace(/-/g, "/"));
911
+ return time.getTime() < date.getTime();
912
+ } else {
913
+ return false;
914
+ }
915
+ },
916
+ };
917
+ };
918
+
919
+ //除法
920
+ function baseDiv() {
921
+ let value = 0;
922
+ if (arguments.length) {
923
+ value = arguments[0];
924
+ for (let i = 1; i < arguments.length; i++) {
925
+ value = XEUtils.divide(value, arguments[i]);
926
+ }
927
+ }
928
+ return value;
929
+ }
930
+
931
+ //乘法
932
+ function baseMul() {
933
+ let value = 0;
934
+ if (arguments.length) {
935
+ value = arguments[0];
936
+ for (let i = 1; i < arguments.length; i++) {
937
+ value = XEUtils.multiply(value, arguments[i]);
938
+ }
939
+ }
940
+ return value;
941
+ }
942
+
943
+ //加法
944
+ function baseAdd() {
945
+ let value = 0;
946
+ if (arguments.length) {
947
+ value = arguments[0];
948
+ for (let i = 1; i < arguments.length; i++) {
949
+ value = XEUtils.add(value, arguments[i]);
950
+ }
951
+ }
952
+ return value;
953
+ }
954
+
955
+ //减法
956
+ function baseSub() {
957
+ let value = 0;
958
+ if (arguments.length) {
959
+ value = arguments[0];
960
+ for (let i = 1; i < arguments.length; i++) {
961
+ value = XEUtils.subtract(value, arguments[i]);
962
+ }
963
+ }
964
+ return value;
965
+ }
966
+
967
+ Vue.prototype.$baseAdd = baseAdd;
968
+ Vue.prototype.$baseSub = baseSub;
969
+ Vue.prototype.$baseMul = baseMul;
970
+ Vue.prototype.$baseDiv = baseDiv;
971
+
972
+ /**
973
+ * 格式化数字为带千分位的字符串。
974
+ *
975
+ * @param {string | number} value - 输入值
976
+ * @param {Object} [options={}] - 配置
977
+ * @param {boolean} [options.fixed=false] -
978
+ * - `true`: 启用定点精度处理 —— 使用 toFixed(digits) 四舍五入并补零到指定小数位。
979
+ * - `false`(默认): 保留原始小数形式(不四舍五入、不补零、保留尾随零)。
980
+ * @param {number} [options.digits=2] - 小数位数(仅在 fixed: true 时生效)
981
+ * @param {string} [options.thousandsSeparator=','] - 千分位分隔符(始终生效)
982
+ * @param {string} [options.decimalSeparator='.'] - 小数点符号
983
+ * @returns {string}
984
+ *
985
+ * @example
986
+ * // 默认:保留原始小数
987
+ * formatNumber(0.2); // "0.2"
988
+ * formatNumber("0.2000"); // "0.2000"
989
+ *
990
+ * // 启用定点精度处理
991
+ * formatNumber(0.2, { fixed: true }); // "0.20"
992
+ * formatNumber("123.456", { fixed: true, digits: 1 }); // "123.5"
993
+ * formatNumber(1000, { fixed: true, digits: 0 }); // "1,000"
994
+ */
995
+ function formatNumber(value, options = {}) {
996
+ if (value === null || value === undefined || value === "") {
997
+ return "";
998
+ }
999
+
1000
+ const {
1001
+ fixed = false,
1002
+ digits = 2,
1003
+ thousandsSeparator = ",",
1004
+ decimalSeparator = ".",
1005
+ } = options;
1006
+
1007
+ const isNumber = typeof value === "number";
1008
+ let str = String(value).trim();
1009
+
1010
+ // Normalize ".123" → "0.123"
1011
+ if (str.charCodeAt(0) === 46) {
1012
+ str = "0" + str;
1013
+ } else if (str.startsWith("-.")) {
1014
+ str = "-0." + str.slice(2);
1015
+ }
1016
+
1017
+ let intPart, decPart, isNegative;
1018
+
1019
+ if (fixed) {
1020
+ // ✅ 启用精度处理:toFixed + 补零
1021
+ const num = isNumber ? value : parseFloat(str);
1022
+ if (num !== num) return str;
1023
+
1024
+ const fixedStr = num.toFixed(digits);
1025
+ const dotIndex = fixedStr.indexOf(".");
1026
+ intPart = dotIndex === -1 ? fixedStr : fixedStr.slice(0, dotIndex);
1027
+ decPart = dotIndex === -1 ? "" : fixedStr.slice(dotIndex + 1);
1028
+ isNegative = intPart.charCodeAt(0) === 45;
1029
+ if (isNegative) intPart = intPart.slice(1);
1030
+ } else {
1031
+ // 保留原始小数
1032
+ let s = str;
1033
+ isNegative = s.charCodeAt(0) === 45;
1034
+ if (isNegative) s = s.slice(1);
1035
+
1036
+ const dotIndex = s.indexOf(".");
1037
+ intPart = dotIndex === -1 ? s : s.slice(0, dotIndex);
1038
+ decPart = dotIndex === -1 ? "" : s.slice(dotIndex + 1);
1039
+
1040
+ if (intPart === "") intPart = "0";
1041
+ if (!/^\d+$/.test(intPart)) return str;
1042
+ }
1043
+
1044
+ // 千分位(始终应用)
1045
+ let fmtInt = intPart;
1046
+ if (intPart !== "0") {
1047
+ let out = "";
1048
+ for (let i = intPart.length - 1, c = 0; i >= 0; i--, c++) {
1049
+ if (c > 0 && c % 3 === 0) out = thousandsSeparator + out;
1050
+ out = intPart[i] + out;
1051
+ }
1052
+ fmtInt = out;
1053
+ }
1054
+
1055
+ // 拼接
1056
+ let result = isNegative ? "-" + fmtInt : fmtInt;
1057
+ if (decPart) {
1058
+ result += decimalSeparator + decPart;
1059
+ } else if (fixed && digits > 0) {
1060
+ result += decimalSeparator + "0".repeat(digits);
1061
+ }
1062
+
1063
+ return result;
1064
+ }
1065
+ Vue.prototype.$formatNumber = formatNumber;
1066
+
1067
+ /**
1068
+ * 生成一个符合 RFC4122 标准的随机 UUID (v4)
1069
+ * @returns {string} 格式为 "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" 的 UUID 字符串
1070
+ */
1071
+ function generateUUID() {
1072
+ const buf = new Uint8Array(16);
1073
+ crypto.getRandomValues(buf);
1074
+ buf[6] = (buf[6] & 0x0f) | 0x40; // version 4
1075
+ buf[8] = (buf[8] & 0x3f) | 0x80; // variant RFC4122
1076
+ const hex = Array.from(buf, (b) => b.toString(16).padStart(2, "0")).join(
1077
+ ""
1078
+ );
1079
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(
1080
+ 12,
1081
+ 16
1082
+ )}-${hex.slice(16, 20)}-${hex.slice(20)}`;
1083
+ }
1084
+ Vue.prototype.$generateUUID = generateUUID;
1085
+
1086
+ //数字精确位数
1087
+ Vue.prototype.$currency = function (value, priceScale, priceRoundType) {
1088
+ if (value !== null && value !== undefined) {
1089
+ if (priceScale === null || priceScale === undefined) {
1090
+ priceScale = 2;
1091
+ }
1092
+ if (priceRoundType === null || priceRoundType === undefined) {
1093
+ priceRoundType = "roundHalfUp";
1094
+ }
1095
+ let price;
1096
+ if (priceRoundType === "roundHalfUp") {
1097
+ price = (
1098
+ Math.round(value * Math.pow(10, priceScale)) /
1099
+ Math.pow(10, priceScale)
1100
+ ).toFixed(priceScale);
1101
+ } else if (priceRoundType === "roundUp") {
1102
+ price = (
1103
+ Math.ceil(value * Math.pow(10, priceScale)) / Math.pow(10, priceScale)
1104
+ ).toFixed(priceScale);
1105
+ } else {
1106
+ price = (
1107
+ Math.floor(value * Math.pow(10, priceScale)) /
1108
+ Math.pow(10, priceScale)
1109
+ ).toFixed(priceScale);
1110
+ }
1111
+ return price;
1112
+ }
1113
+ };
1114
+
1115
+ /**
1116
+ * 取基础字典。走 utils/baseDictsCache:同 key 并发只发一条,TTL 内直接复用结果。
1117
+ *
1118
+ * option.success 从 $http 的 success 里挪了出来 —— 命中缓存时根本不会发请求,
1119
+ * 留在 $http 配置里就永远不会被调到。回调时机因此晚了一个微任务,对调用方
1120
+ * (普遍是把 dicts 赋给 Vue data)没有影响。
1121
+ *
1122
+ * 额外可选参数:
1123
+ * option.cache === false / option.force —— 跳过缓存强制重取
1124
+ * option.cacheTtl —— 覆盖默认 TTL(毫秒),传 0 则只去重不缓存
1125
+ */
1126
+ Vue.prototype.$getBaseDicts = async function (option) {
1127
+ let isLoading = option.isLoading || false;
1128
+ // listItems 带 forCompany: true 发,结果是按公司隔离的;切换公司不刷新页面,
1129
+ // 缓存 key 必须带上公司编码,否则会命中上一家公司的字典。
1130
+ let key = buildBaseDictsKey(
1131
+ imFun.store.getters.companyCode,
1132
+ option.code,
1133
+ option.data
1134
+ );
1135
+ return loadBaseDicts({
1136
+ key,
1137
+ code: option.code,
1138
+ ttl: option.cacheTtl,
1139
+ force: option.force === true || option.cache === false,
1140
+ request: () =>
1141
+ this.$http({
1142
+ url: USER_PREFIX + "/common_attribute/listItems",
1143
+ method: `post`,
1144
+ data: {
1145
+ code: option.code,
1146
+ enabled: true,
1147
+ forCompany: true,
1148
+ ...option.data,
1149
+ },
1150
+ isLoading: isLoading,
1151
+ modalStrictly: true,
1152
+ }),
1153
+ }).then((res) => {
1154
+ if (res && res.type === "success") {
1155
+ option.success && option.success(toBaseDicts(res));
1156
+ }
1157
+ return res;
1158
+ });
1159
+ };
1160
+
1161
+ /**
1162
+ * 失效基础字典缓存。不传 code 则整体清空。
1163
+ * 字典维护页保存后要调它,否则改完最长要等一个 TTL 才生效。
1164
+ */
1165
+ Vue.prototype.$invalidateBaseDicts = function (code) {
1166
+ invalidateBaseDicts(code);
1167
+ };
1168
+
1169
+ imFun.Form.methods.$baseValidate = function (callback, opt) {
1170
+ let that = this;
1171
+ that.validate((valid, obj, c, d) => {
1172
+ if (!valid && (!opt || opt.errorTip !== false)) {
1173
+ this.$message({
1174
+ message: this.$t2("必填项不能为空", "system.message.required"),
1175
+ type: "error",
1176
+ duration: 2000,
1177
+ });
1178
+ }
1179
+ scrollToFirstError(that);
1180
+ callback(valid, obj);
1181
+ });
1182
+ };
1183
+
1184
+ function scrollToFirstError(formTarget) {
1185
+ // 获取第一个验证失败的字段
1186
+ // let formTarget = this.$refs['renderForm'];
1187
+ const firstErrorField = Object.keys(formTarget.fields).find((key) => {
1188
+ return formTarget.fields[key].validateState === "error";
1189
+ });
1190
+
1191
+ if (firstErrorField) {
1192
+ const field = formTarget.fields[firstErrorField];
1193
+
1194
+ let dom = field.$el;
1195
+ if (dom) {
1196
+ // 滚动到该字段位置
1197
+ dom.scrollIntoView({
1198
+ behavior: "smooth",
1199
+ block: "center",
1200
+ });
1201
+
1202
+ // 添加高亮效果
1203
+ dom.classList.add("highlight");
1204
+
1205
+ // 3秒后移除高亮效果
1206
+ setTimeout(() => {
1207
+ dom.classList.remove("highlight");
1208
+ }, 3000);
1209
+ }
1210
+ }
1211
+ }
1212
+
1213
+ Vue.prototype.$getBillInfo = async function (option) {
1214
+ let defaultOption = {
1215
+ url: null,
1216
+ method: `post`,
1217
+ data: {},
1218
+ isLoading: true,
1219
+ modalStrictly: true,
1220
+ success: null,
1221
+ };
1222
+ let opt = Object.assign({}, defaultOption, option);
1223
+ delete opt.wfConfig;
1224
+ return this.$http({
1225
+ ...opt,
1226
+ success: (res, response) => {
1227
+ option.success && option.success(res, response);
1228
+ },
1229
+ });
1230
+ };
1231
+
1232
+ Vue.prototype.$downloadByFileWhole = function (fileWhole, fileName) {
1233
+ let that = this;
1234
+ if (!fileWhole) {
1235
+ this.$baseAlert("凭证信息不存在");
1236
+ return;
1237
+ }
1238
+ let getDownloadDomian = function (callback) {
1239
+ that.$http({
1240
+ method: "post",
1241
+ url: USER_PREFIX + "/common/fileDownloadUrl",
1242
+ data: {},
1243
+ isLoading: true,
1244
+ success: (res) => {
1245
+ callback(res.objx);
1246
+ },
1247
+ });
1248
+ };
1249
+ getDownloadDomian((domain) => {
1250
+ if (fileName) {
1251
+ fileWhole.fileName = fileName;
1252
+ }
1253
+ that.$http({
1254
+ method: "post",
1255
+ url: domain + "/docfile/download",
1256
+ data: fileWhole,
1257
+ isLoading: true,
1258
+ success: (res) => {
1259
+ // window.open(res.objx.url);
1260
+ let url = res.objx.url;
1261
+ openInNewTab(url);
1262
+ },
1263
+ });
1264
+ });
1265
+ };
1266
+
1267
+ let isDef = function (value) {
1268
+ return value !== undefined && value !== null;
1269
+ };
1270
+
1271
+ Vue.prototype.$t2 = function (defaultValue, path, values) {
1272
+ let that = window.$vueRoot;
1273
+ if (!that.hasOwnProperty("_i18n")) {
1274
+ return defaultValue;
1275
+ }
1276
+ const i18n = that.$i18n;
1277
+ path = path || defaultValue;
1278
+ return i18n.te(path) ? i18n.t(path, values) : defaultValue;
1279
+ };
1280
+
1281
+ Vue.prototype.$t1 = function (path, values) {
1282
+ let that = window.$vueRoot;
1283
+ if (!that.hasOwnProperty("_i18n")) {
1284
+ return path;
1285
+ }
1286
+ let lang = that.$i18n.locale;
1287
+ const i18n = that.$i18n;
1288
+ if (lang === "zh") {
1289
+ let val = i18n._t(path, lang, { zh: { [path]: path } }, null, values);
1290
+ return val;
1291
+ } else {
1292
+ if (!i18n.te(path)) {
1293
+ return i18n._t(path, lang, { zh: { [path]: path } }, null, values);
1294
+ } else {
1295
+ return (
1296
+ i18n.t(path, values) ||
1297
+ i18n._t(path, lang, { zh: { [path]: path } }, null, values)
1298
+ );
1299
+ }
1300
+ }
1301
+ };
1302
+
1303
+ Vue.prototype.$i18nVal = function (zhValue, enValue) {
1304
+ let that = window.$vueRoot;
1305
+ if (!that.hasOwnProperty("_i18n")) {
1306
+ return zhValue;
1307
+ }
1308
+ let $i18n = that.$i18n;
1309
+ let value = zhValue;
1310
+ if ($i18n.locale === "zh") {
1311
+ value = zhValue;
1312
+ } else if ($i18n.locale === "en") {
1313
+ value = enValue;
1314
+ }
1315
+ return value;
1316
+ };
1317
+
1318
+ Vue.prototype.$utcToLocal = function (utcTime) {
1319
+ if (!utcTime) return utcTime;
1320
+ let offsetHours = this.$store.getters.utcTransformOffset; // 时区偏移量,单位:小时
1321
+ if (!offsetHours || offsetHours === 0) return utcTime;
1322
+ let localTime = moment(utcTime).add(offsetHours, "hours");
1323
+ return localTime.format("YYYY-MM-DD HH:mm:ss");
1324
+ };
1325
+
1326
+ Vue.prototype.$window = window;
1327
+ };
1328
+
1329
+ window && Object.assign(window, imFun.prefixConfig);
1330
+ if (typeof window !== "undefined" && window.Vue) {
1331
+ install(window.Vue);
1332
+ }
1333
+
1334
+ export default install;