cloud-web-corejs 1.0.258 → 1.0.259

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 (248) hide show
  1. package/package.json +32 -25
  2. package/src/components/VabUpload/fileLibraryDialog.vue +296 -0
  3. package/src/components/VabUpload/index.js +22 -2
  4. package/src/components/VabUpload/index.vue +242 -231
  5. package/src/components/VabUpload/mixins/fileLibraryDialog.js +1112 -0
  6. package/src/components/VabUpload/mixins.js +1971 -1829
  7. package/src/components/VabUpload/privateProfileDialog.vue +2 -2
  8. package/src/components/baseArea/index.vue +1628 -0
  9. package/src/components/baseInputExport/mixins.js +48 -31
  10. package/src/components/baseInputNumber/index.vue +9 -9
  11. package/src/components/baseTabs/index.vue +16 -8
  12. package/src/components/code-editor/async.js +29 -0
  13. package/src/components/code-editor/index.vue +93 -4
  14. package/src/components/errorMsg/index.js +10 -9
  15. package/src/components/errorMsg/mixins.js +25 -23
  16. package/src/components/excelExport/exportFieldDialog.vue +40 -18
  17. package/src/components/excelExport/index.js +62 -3
  18. package/src/components/excelExport/index.vue +2 -1
  19. package/src/components/excelExport/mixins.js +496 -340
  20. package/src/components/excelImport/index.js +69 -7
  21. package/src/components/excelImport/mixins.js +841 -9
  22. package/src/components/fileLibrary/categoryMoveDialog.vue +109 -109
  23. package/src/components/fileLibrary/fileHistoryDialog.vue +1 -1
  24. package/src/components/fileLibrary/fileObjAuthDialog.vue +297 -298
  25. package/src/components/fileLibrary/fileObjAuthEdit.vue +1 -1
  26. package/src/components/fileLibrary/filterDialog.vue +1 -1
  27. package/src/components/fileLibrary/index.vue +1109 -1110
  28. package/src/components/fileLibrary/mixins/indexMixins.js +10 -0
  29. package/src/components/fileLibrary/propertiesDialog.vue +190 -190
  30. package/src/components/fileLibrary/recycleBinDialog.vue +237 -236
  31. package/src/components/formOplog/mixins.js +85 -80
  32. package/src/components/hiprint/view/design/index.vue +7 -2
  33. package/src/components/jsonImport/exportUtil.js +106 -0
  34. package/src/components/jsonImport/index.js +75 -50
  35. package/src/components/jsonImport/mixins.js +350 -348
  36. package/src/components/langImport/mixins.js +502 -500
  37. package/src/components/micro-view-host/contract.js +66 -0
  38. package/src/components/micro-view-host/index.vue +148 -0
  39. package/src/components/mobile/file/index.vue +10 -0
  40. package/src/components/mobile/wf/mixins/wfModifyDialogMixin.js +51 -47
  41. package/src/components/obsUpload/index.vue +234 -231
  42. package/src/components/obsUpload/mixins.js +1542 -1476
  43. package/src/components/onlineTalk/talkUserDialog.vue +1 -1
  44. package/src/components/table/CellSlot.vue +12 -10
  45. package/src/components/table/config.js +74 -1
  46. package/src/components/table/index.js +1208 -1
  47. package/src/components/table/tableFormMixin.js +285 -1
  48. package/src/components/table/util/index.js +38 -40
  49. package/src/components/table/vxeFilter/index.js +153 -2
  50. package/src/components/table/vxeFilter/mixin.js +305 -3
  51. package/src/components/tempStorage/tempStorageDialog.vue +1 -1
  52. package/src/components/vb-tabs/x-tabs.vue +10 -5
  53. package/src/components/wf/addTaskUserdialog.vue +1 -1
  54. package/src/components/wf/mixins/setCandidateDialog.js +217 -217
  55. package/src/components/wf/mixins/setCandidateDialog2.js +252 -252
  56. package/src/components/wf/wf.js +2224 -2203
  57. package/src/components/wf/wfUtil.js +2 -1
  58. package/src/components/xform/docs/2026-08 /345/210/227/350/241/250/345/257/274/345/207/272/350/204/261/346/225/217/345/210/227/345/211/224/351/231/244/350/220/275/345/234/260/346/226/207/346/241/243.md" +173 -0
  59. package/src/components/xform/form-designer/designer.js +1 -0
  60. package/src/components/xform/form-designer/form-widget/container-widget/containerMixin.js +110 -1
  61. package/src/components/xform/form-designer/form-widget/container-widget/data-table-mixin.js +282 -1
  62. package/src/components/xform/form-designer/form-widget/field-widget/area-select-widget.vue +272 -0
  63. package/src/components/xform/form-designer/form-widget/field-widget/autocomplete-widget.vue +119 -0
  64. package/src/components/xform/form-designer/form-widget/field-widget/fieldMixin.js +14 -0
  65. package/src/components/xform/form-designer/form-widget/field-widget/form-item-wrapper.vue +18 -73
  66. package/src/components/xform/form-designer/form-widget/field-widget/mixins/autocomplete-mixin.js +451 -0
  67. package/src/components/xform/form-designer/form-widget/field-widget/mixins/date-limit-mixin.js +157 -0
  68. package/src/components/xform/form-designer/form-widget/field-widget/mixins/utc-transform-mixin.js +75 -0
  69. package/src/components/xform/form-designer/form-widget/field-widget/save_submit_wf_button-widget.vue +112 -0
  70. package/src/components/xform/form-designer/form-widget/field-widget/script-input-widget.vue +149 -0
  71. package/src/components/xform/form-designer/form-widget/indexMixin.js +179 -1
  72. package/src/components/xform/form-designer/indexMixin.js +823 -1
  73. package/src/components/xform/form-designer/refMixinDesign.js +27 -1
  74. package/src/components/xform/form-designer/setting-panel/action-button-config-dialog.vue +241 -0
  75. package/src/components/xform/form-designer/setting-panel/form-dynamicField-setting.vue +601 -0
  76. package/src/components/xform/form-designer/setting-panel/form-setting.vue +6 -0
  77. package/src/components/xform/form-designer/setting-panel/index.vue +314 -309
  78. package/src/components/xform/form-designer/setting-panel/indexMixin.js +324 -1
  79. package/src/components/xform/form-designer/setting-panel/property-editor/container-data-table/data-table-editor.vue +8 -7
  80. package/src/components/xform/form-designer/setting-panel/property-editor/container-list-h5/list-h5-editor.vue +8 -7
  81. package/src/components/xform/form-designer/setting-panel/property-editor/container-table/table-dynamicField-editor.vue +344 -0
  82. package/src/components/xform/form-designer/setting-panel/property-editor/dropdownFlag-editor.vue +2 -2
  83. package/src/components/xform/form-designer/setting-panel/property-editor/field-area-select/areaDataType-editor.vue +25 -0
  84. package/src/components/xform/form-designer/setting-panel/property-editor/field-area-select/areaMinLevel-editor.vue +50 -0
  85. package/src/components/xform/form-designer/setting-panel/property-editor/field-area-select/areaName-editor.vue +20 -0
  86. package/src/components/xform/form-designer/setting-panel/property-editor/field-autocomplete/autocomplete-vabSearchName-editor.vue +199 -0
  87. package/src/components/xform/form-designer/setting-panel/property-editor/field-baseAttachment/baseAttachment-fileTypes-editor.vue +23 -0
  88. package/src/components/xform/form-designer/setting-panel/property-editor/field-cascader/showAllLevels-editor.vue +21 -0
  89. package/src/components/xform/form-designer/setting-panel/property-editor/field-date/date-dateLimit-editor.vue +157 -0
  90. package/src/components/xform/form-designer/setting-panel/property-editor/field-script-input/script-input-editor.vue +55 -0
  91. package/src/components/xform/form-designer/setting-panel/property-editor/field-vabUpload/vabUpload-fileTypes-editor.vue +23 -0
  92. package/src/components/xform/form-designer/setting-panel/property-editor/fileTypesEditorMixin.js +116 -0
  93. package/src/components/xform/form-designer/setting-panel/property-editor/fileTypesSelect.vue +176 -0
  94. package/src/components/xform/form-designer/setting-panel/property-editor/textFlag-editor.vue +3 -3
  95. package/src/components/xform/form-designer/setting-panel/property-editor/utcTransformEnabled-editor.vue +19 -0
  96. package/src/components/xform/form-designer/setting-panel/widgetPropertyDialogMixin.js +186 -0
  97. package/src/components/xform/form-designer/toolbar-panel/indexMixin.js +566 -1
  98. package/src/components/xform/form-designer/widget-panel/indexMixin.js +290 -1
  99. package/src/components/xform/form-render/compareDelList.vue +83 -0
  100. package/src/components/xform/form-render/compareView.vue +76 -0
  101. package/src/components/xform/form-render/container-item/containerItemMixin.js +378 -1
  102. package/src/components/xform/form-render/container-item/data-table-mixin.js +35 -0
  103. package/src/components/xform/form-render/container-item/detail-item.vue +41 -0
  104. package/src/components/xform/form-render/container-item/dynamicFieldEngine.js +285 -0
  105. package/src/components/xform/form-render/container-item/dynamicFieldMixin.js +416 -0
  106. package/src/components/xform/form-render/container-item/list-h5-item.vue +12 -0
  107. package/src/components/xform/form-render/dynamicDialogRender.js +195 -1
  108. package/src/components/xform/form-render/dynamicDrawerRender.js +229 -0
  109. package/src/components/xform/form-render/formDynamicFieldMixin.js +131 -0
  110. package/src/components/xform/form-render/refMixin.js +29 -1
  111. package/src/components/xform/mixins/scriptHttp.js +172 -1
  112. package/src/components/xform/utils/dynamicSchemaUtil.js +361 -0
  113. package/src/components/xform/utils/tableCellValidateUtil.js +148 -0
  114. package/src/components/xform/utils/textMaskUtil.js +179 -0
  115. package/src/components/xform/utils/treeTableUtil.js +1265 -0
  116. package/src/components/xform/utils/util.js +1 -0
  117. package/src/components/xform/utils/validators.js +133 -1
  118. package/src/directive/LimitNumber/index.js +143 -124
  119. package/src/microRouter/index.js +447 -0
  120. package/src/mixins/tableTree/index.js +77 -14
  121. package/src/permission.js +132 -107
  122. package/src/public-path.js +38 -0
  123. package/src/router/index.js +3 -3
  124. package/src/store/modules/micro.js +57 -0
  125. package/src/store/modules/permission.js +535 -371
  126. package/src/store/modules/tagsView.js +38 -21
  127. package/src/store/modules/user.js +409 -370
  128. package/src/utils/aes.js +9 -3
  129. package/src/utils/auth.js +1 -1
  130. package/src/utils/componentDialog.js +162 -40
  131. package/src/utils/global.js +35 -34
  132. package/src/utils/index.js +579 -579
  133. package/src/utils/keepAlive.js +8 -4
  134. package/src/utils/lazyPlugin.js +66 -0
  135. package/src/utils/menuAdapter.js +277 -0
  136. package/src/utils/repeatOpen.js +48 -0
  137. package/src/utils/request.js +417 -395
  138. package/src/utils/resolveViewComponent.js +203 -0
  139. package/src/utils/vab.js +14 -3
  140. package/src/utils/validate.js +104 -106
  141. package/src/views/bd/setting/bd_attach_setting/dialog.vue +1 -1
  142. package/src/views/bd/setting/bd_attach_setting/list.vue +1 -1
  143. package/src/views/bd/setting/bd_company_env/dialog.vue +1 -1
  144. package/src/views/bd/setting/bd_company_env/list.vue +1 -1
  145. package/src/views/bd/setting/formVersion/ftHistoryDialog.vue +488 -489
  146. package/src/views/bd/setting/form_import_log/list.vue +1 -1
  147. package/src/views/bd/setting/form_script/dialog.vue +1 -1
  148. package/src/views/bd/setting/form_script/form_list.vue +174 -166
  149. package/src/views/bd/setting/form_script/list.vue +1 -1
  150. package/src/views/bd/setting/form_script/list1.vue +1 -1
  151. package/src/views/bd/setting/form_script/mixins/form_list.js +330 -322
  152. package/src/views/bd/setting/form_template/dialog.vue +1 -1
  153. package/src/views/bd/setting/form_template/formDesignerDialog.vue +172 -171
  154. package/src/views/bd/setting/form_template/ftHistoryDialog.vue +1 -1
  155. package/src/views/bd/setting/form_template/itemList.vue +1 -1
  156. package/src/views/bd/setting/form_template/list.vue +3 -3
  157. package/src/views/bd/setting/form_template/mixins/edit.js +3 -3
  158. package/src/views/bd/setting/form_template/mixins/list.js +3 -3
  159. package/src/views/bd/setting/form_template/mixins/list2.js +3 -3
  160. package/src/views/bd/setting/form_template/mixins/wf_list.js +3 -3
  161. package/src/views/bd/setting/form_template/wfObjConfigDialog.vue +253 -254
  162. package/src/views/bd/setting/form_template/wf_list.vue +3 -3
  163. package/src/views/bd/setting/logic_param/edit.vue +20 -20
  164. package/src/views/bd/setting/logic_param/list.vue +1 -1
  165. package/src/views/bd/setting/menu_kind/dialog.vue +1 -1
  166. package/src/views/bd/setting/menu_kind/list.vue +1 -1
  167. package/src/views/bd/setting/push_data/list.vue +1 -1
  168. package/src/views/bd/setting/push_data_h/list.vue +1 -1
  169. package/src/views/bd/setting/request_async_setting/list.vue +1 -1
  170. package/src/views/bd/setting/request_setting/list.vue +1 -1
  171. package/src/views/bd/setting/table_model/dialog.vue +1 -1
  172. package/src/views/bd/setting/table_model/list.vue +1 -1
  173. package/src/views/bd/setting/table_model/zdDialog.vue +1 -1
  174. package/src/views/user/access_log/list.vue +1 -1
  175. package/src/views/user/access_log/list2.vue +1 -1
  176. package/src/views/user/api_request/list.vue +1 -1
  177. package/src/views/user/area/dialog.vue +1 -1
  178. package/src/views/user/area/list.vue +1 -1
  179. package/src/views/user/bill_setting/list.vue +1 -1
  180. package/src/views/user/bill_setting/userDialog.vue +1 -1
  181. package/src/views/user/code_rules/list.vue +1 -1
  182. package/src/views/user/commMenu/index.vue +2 -2
  183. package/src/views/user/common_attribute/list.vue +2 -2
  184. package/src/views/user/common_script/list.vue +1 -1
  185. package/src/views/user/company_info/dialog.vue +1 -1
  186. package/src/views/user/country/dialog.vue +1 -1
  187. package/src/views/user/country/list.vue +1 -1
  188. package/src/views/user/data_type_setting/dialog.vue +1 -1
  189. package/src/views/user/extend_datasource/dialog.vue +4 -1
  190. package/src/views/user/extend_datasource/edit.vue +2 -1
  191. package/src/views/user/extend_datasource/list.vue +4 -1
  192. package/src/views/user/fieldTranslation/list.vue +1 -1
  193. package/src/views/user/field_values_invisible/list.vue +1 -1
  194. package/src/views/user/file_type/list.vue +1 -1
  195. package/src/views/user/file_view_area/list.vue +1 -1
  196. package/src/views/user/file_view_ins/list.vue +22 -1
  197. package/src/views/user/form/view/list.vue +64 -1
  198. package/src/views/user/groups/dialog.vue +1 -1
  199. package/src/views/user/groups/list.vue +1 -1
  200. package/src/views/user/home/default.vue +2 -2
  201. package/src/views/user/home/default2.vue +1158 -1148
  202. package/src/views/user/home/index.vue +3 -10
  203. package/src/views/user/lang_tag/dialog.vue +1 -1
  204. package/src/views/user/lang_tag/list.vue +1 -1
  205. package/src/views/user/language_setting/list.vue +1 -1
  206. package/src/views/user/login/default.vue +0 -8
  207. package/src/views/user/login/indexMixin.js +547 -556
  208. package/src/views/user/menu/list.vue +25 -2
  209. package/src/views/user/menuFallback/index.vue +123 -0
  210. package/src/views/user/mobile_menu/list.vue +1 -1
  211. package/src/views/user/notify_message/dialog.vue +22 -1
  212. package/src/views/user/notify_message/list.vue +1 -1
  213. package/src/views/user/notify_template/list.vue +1 -1
  214. package/src/views/user/notify_template/list2.vue +1 -1
  215. package/src/views/user/oplog/list.vue +1 -1
  216. package/src/views/user/outLink/form_view.vue +5 -14
  217. package/src/views/user/outLink/index.vue +6 -1
  218. package/src/views/user/outLink/view.vue +5 -13
  219. package/src/views/user/position/dialog.vue +1 -1
  220. package/src/views/user/position/list.vue +1 -1
  221. package/src/views/user/project_tag/dialog.vue +1 -1
  222. package/src/views/user/project_tag/list.vue +1 -1
  223. package/src/views/user/push_setting/list.vue +1 -1
  224. package/src/views/user/request_setting/list.vue +1 -1
  225. package/src/views/user/role/dialog.vue +1 -1
  226. package/src/views/user/role/list.vue +1 -1
  227. package/src/views/user/sale_org/dialog.vue +1 -1
  228. package/src/views/user/sale_org/list.vue +1 -1
  229. package/src/views/user/system_notice/list.vue +1 -1
  230. package/src/views/user/system_parameter/list.vue +1 -1
  231. package/src/views/user/user/dialog.vue +1 -1
  232. package/src/views/user/user/edit.vue +306 -159
  233. package/src/views/user/user/form_dialog.vue +1 -1
  234. package/src/views/user/user/form_list.vue +1 -1
  235. package/src/views/user/user/list.vue +2 -2
  236. package/src/views/user/user_log_classify/list.vue +1 -1
  237. package/src/views/user/wf/iframe/index.vue +6 -1
  238. package/src/views/user/wf/iframe/index2.vue +6 -1
  239. package/src/views/user/wf/wfReport/index.vue +12 -6
  240. package/src/views/user/wf/wf_auto_submit_data/list.vue +2 -2
  241. package/src/views/user/wf/wf_manage/list.vue +97 -24
  242. package/src/views/user/wf/wf_manage/list2.vue +875 -0
  243. package/src/views/user/wf/wf_manage/wfContentDialog.vue +23 -1
  244. package/src/views/user/wf/wf_obj_config/dialog.vue +1 -1
  245. package/src/views/user/wf/wf_obj_config/list.vue +1 -1
  246. package/src/views/user/wf/wf_obj_config/list_form.vue +1 -1
  247. package/src/views/user/wf/wf_transfer_setting/list.vue +1 -1
  248. package/src/views/user/workbench_menu/list.vue +1 -1
@@ -1,1829 +1,1971 @@
1
- /**version-1.0*/
2
- let tmixins, tViewMixins, pmixins;
3
- import axios from "axios";
4
- import SparkMD5 from "spark-md5";
5
- import settingConfig from "@/settings.js";
6
-
7
- let imFun = {
8
- axios,
9
- SparkMD5,
10
- };
11
-
12
- tmixins = {
13
- name: "VabUpload",
14
- props: {
15
- auto: {
16
- type: Boolean,
17
- default: true,
18
- },
19
- url: {
20
- type: String,
21
- default: "/upload",
22
- },
23
- name: {
24
- type: String,
25
- default: "file",
26
- },
27
- limit: {
28
- type: Number,
29
- default: () => 100000,
30
- },
31
- size: {
32
- type: Number,
33
- default: 200,
34
- },
35
- accept: {
36
- type: String,
37
- default: "file",
38
- },
39
- chunkSize: {
40
- type: Number,
41
- default: 5, //5MB
42
- },
43
- confirmUpload: {
44
- type: Function,
45
- },
46
- pickPrivateProfile: {
47
- type: Boolean,
48
- default: true,
49
- },
50
- multi: {
51
- type: [String, Boolean],
52
- default: true,
53
- },
54
- uploadingLimit: {
55
- type: Number,
56
- default: 5, //5MB
57
- },
58
- isPartUpload: {
59
- type: Boolean,
60
- default: () => {
61
- return settingConfig.isPartUpload ?? true;
62
- },
63
- },
64
- autoConfirmAfterUpload: {
65
- type: Boolean,
66
- default: false,
67
- },
68
- },
69
- data() {
70
- return {
71
- show: false,
72
- loading: false,
73
- dialogVisible: false,
74
- dialogImageUrl: "",
75
- action: "",
76
- headers: {},
77
- fileList: [],
78
- picture: "picture",
79
- allImgNum: 0,
80
- imgNum: 0,
81
- imgSuccessNum: 0,
82
- imgErrorNum: 0,
83
- typeList: null,
84
- title: this.$t2("上传", "components.VabUpload.title"),
85
- dialogFormVisible: false,
86
- data: {},
87
- fileViewDialogVisible: false,
88
- fileViewInfo: {},
89
- total: 0,
90
- video: null,
91
- btn: false,
92
- filePartMap: {},
93
- uploading: false,
94
- hasReadyFile: false,
95
- showLocalUploadBtn: false,
96
- showPrivateUploadBtn: false,
97
- showPrivateProfileDialog: false,
98
- pasteList: [],
99
- pasteAreaStatus: false,
100
- option: {},
101
- editFileIndex: -1,
102
- showFileNameDialog: false,
103
- editFileName: null,
104
- editFileSuffix: null,
105
- beforeUploadFlag: false,
106
- uploadUrl: null,
107
- };
108
- },
109
- beforeDestroy() {
110
- this.removePasteEvent();
111
- },
112
- filters: {
113
- btnText(btn) {
114
- return btn
115
- ? this.$t2("继续", "components.VabUpload.continue")
116
- : this.$t2("暂停", "components.VabUpload.pause");
117
- },
118
- totalText(total) {
119
- return total > 100 ? 100 : total;
120
- },
121
- },
122
- computed: {
123
- percentage() {
124
- if (this.allImgNum == 0) return 0;
125
- return ((this.imgNum / this.allImgNum, 2) * 100).toFixed(0);
126
- },
127
- fileMaxSize() {
128
- return this.formatFileSize(this.size * 1024 * 1024);
129
- },
130
- errorQuantity() {
131
- return this.fileList.filter((file) => file.status == "fail").length;
132
- },
133
- totalQuantity() {
134
- return this.fileList.length;
135
- },
136
- successQuantity() {
137
- return this.fileList.filter((file) => file.status == "success").length;
138
- },
139
- isMulti: function () {
140
- let isMulti = true;
141
- if (this.multi === "false" || this.multi === false || this.limit === 1) {
142
- isMulti = false;
143
- }
144
- return isMulti;
145
- },
146
- },
147
- methods: {
148
- updateUploadingStatus() {
149
- var target = this.$refs.upload;
150
- let uploading, hasReadyFile;
151
- if (target) {
152
- var fileList = target.uploadFiles;
153
- let n = fileList.find((item) => {
154
- // return item.percentage != 100;
155
- return item.status == "uploading" || item.status == "preUpload";
156
- });
157
- uploading = n == null ? false : true;
158
-
159
- let readyFiles = fileList.filter((file) => file.status == "ready");
160
- hasReadyFile = readyFiles.length > 0;
161
- } else {
162
- uploading = false;
163
- hasReadyFile = false;
164
- }
165
-
166
- this.uploading = uploading;
167
- this.hasReadyFile = hasReadyFile;
168
- this.checkPreUploadList();
169
- return uploading;
170
- },
171
- submitUpload() {
172
- let successDone = () => {
173
- this.$refs.upload.submit();
174
- };
175
- var files = this.$refs.upload.uploadFiles;
176
- let readyFiles = files.filter((file) => file.status == "ready");
177
- if (this.confirmUpload) {
178
- if (readyFiles.length) {
179
- this.confirmUpload({
180
- files: files,
181
- done: successDone,
182
- });
183
- }
184
- } else {
185
- successDone();
186
- }
187
- },
188
- handleProgress(event, file, fileList) {
189
- // this.loading = true
190
- // this.show = true
191
- },
192
- handleChange(file, fileList) {
193
- let maxSize = this.size * 1024 * 1024;
194
- if (file.size > maxSize) {
195
- fileList.map((item, index) => {
196
- if (item === file) {
197
- fileList.splice(index, 1);
198
- }
199
- });
200
- this.fileList = fileList;
201
- let errorText =
202
- "文件[" + file.name + "]大小超出限制" + this.fileMaxSize;
203
- this.$message({
204
- message: this.$t2(errorText, "components.VabUpload.warnMsg1", {
205
- fileName: file.name,
206
- fileMaxSize: this.fileMaxSize,
207
- }),
208
- type: "error",
209
- duration: 3 * 1000,
210
- });
211
- file.raw.status = "fail";
212
- return false;
213
- } else {
214
- this.fileList = fileList;
215
- this.allImgNum = fileList.length;
216
- }
217
- this.updateUploadingStatus();
218
- },
219
- handleSuccess(response, file, fileList) {
220
- if (file.percentage == 100) {
221
- this.imgNum = this.imgNum + 1;
222
- this.imgSuccessNum = this.imgSuccessNum + 1;
223
- }
224
- if (fileList.length === this.imgNum) {
225
- this.fileList = fileList;
226
-
227
- // 添加自动确认功能
228
- // 当所有文件上传完成且 autoConfirmAfterUpload 为 true 时,自动调用 submitImage 方法
229
- if (this.autoConfirmAfterUpload) {
230
- // 使用 nextTick 确保所有文件状态已更新
231
- this.$nextTick(() => {
232
- this.submitImage();
233
- });
234
- return; // 自动确认后直接返回,不执行后续的 setTimeout
235
- }
236
-
237
- }
238
-
239
- setTimeout(() => {
240
- this.loading = false;
241
- this.show = false;
242
- }, 1000);
243
- this.updateUploadingStatus();
244
- },
245
- handleError(err, file, fileList) {
246
- this.imgNum = this.imgNum + 1;
247
- this.imgErrorNum = this.imgErrorNum + 1;
248
- setTimeout(() => {
249
- this.loading = false;
250
- this.show = false;
251
- }, 1000);
252
- this.updateUploadingStatus();
253
- },
254
- handleRemove(file, fileList) {
255
- this.imgNum = this.imgNum - 1;
256
- this.allNum = this.allNum - 1;
257
- this.updateUploadingStatus();
258
- },
259
- handlePreview(file) {
260
- this.dialogImageUrl = file.url;
261
- this.dialogVisible = true;
262
- },
263
- handleExceed(files, fileList) {
264
- let errorMsg = `当前限制选择 ${this.limit} 个文件,本次选择了
265
- ${files.length}
266
- 个文件`;
267
- this.$message({
268
- message: this.$t2(errorMsg, "components.VabUpload.warnMsg2", {
269
- limit: this.limit,
270
- size: files.length,
271
- }),
272
- type: "error",
273
- duration: 5 * 1000,
274
- });
275
- },
276
- handleShow(option) {
277
- this.title = this.$t2("上传", "components.VabUpload.title");
278
- // this.data = data;
279
- this.option = option;
280
- this.clearFileInfo();
281
- this.initPickUploadMode();
282
- this.pasteAreaStatus = false;
283
- this.dialogFormVisible = true;
284
- /*document.removeEventListener('paste', this.pasteEvent);
285
- document.addEventListener('paste', this.pasteEvent);*/
286
-
287
- this.removePasteEvent();
288
- this.addPasteEvent();
289
- if(!option.files?.length){
290
- this.initUploadUrl();
291
- }else{
292
- this.initUploadUrl(()=>{
293
- this.handleUpload(option.files)
294
- });
295
- }
296
- },
297
- handleUpload(fileRawList){
298
- let target = this.$refs.upload;
299
- let innerTarget = target.$refs["upload-inner"];
300
- if (fileRawList.length) {
301
- innerTarget.uploadFiles(fileRawList);
302
- }
303
- },
304
- addPasteEvent() {
305
- document.addEventListener("click", this.blurPasteEvent);
306
- document.addEventListener("paste", this.pasteEvent);
307
- /* if(this.option.copy){
308
-
309
- } */
310
- },
311
- removePasteEvent() {
312
- document.removeEventListener("click", this.blurPasteEvent);
313
- document.removeEventListener("paste", this.pasteEvent);
314
- },
315
- blurPasteEvent() {
316
- this.pasteAreaStatus = false;
317
- },
318
- handleClose() {
319
- let target = this.$refs.upload;
320
- (target.uploadFiles || []).forEach((uploadFile) => {
321
- if (uploadFile.status == "uploading" || uploadFile.status == "ready") {
322
- uploadFile.raw.abort &&
323
- uploadFile.raw.abort(
324
- this.$t2("取消上传", "components.VabUpload.cancelUpload")
325
- );
326
- }
327
- });
328
- this.picture = "picture";
329
- this.clearFileInfo();
330
- this.dialogFormVisible = false;
331
- },
332
- clearFileInfo() {
333
- this.fileList = [];
334
- this.allImgNum = 0;
335
- this.imgNum = 0;
336
- this.imgSuccessNum = 0;
337
- this.imgErrorNum = 0;
338
- },
339
- initUploadUrl(callback) {
340
- let mineUploadUrl = window.BASE_FILEURL;
341
- return this.$http({
342
- url: mineUploadUrl,
343
- method: "post",
344
- data: {
345
- isAuth: false,
346
- },
347
- success: (res) => {
348
- this.uploadUrl = res.objx;
349
- callback && callback();
350
- },
351
- });
352
- },
353
- handleBeforeUpload(file, checkFile, callback) {
354
- /*if (checkFile !== false) {
355
- let target = this.$refs.upload;
356
- let nFile = target.getFile(file);
357
- if (!nFile) {
358
- return false;
359
- }
360
- }
361
- let mineUploadUrl = window.BASE_FILEURL;
362
- return await this.$http({
363
- url: mineUploadUrl,
364
- method: 'post',
365
- data: {
366
- isAuth: false
367
- },
368
- success: res => {
369
- this.uploadUrl = res.objx;
370
- callback && callback()
371
- }
372
- });*/
373
- callback && callback();
374
- },
375
- formatFileSize(fileSize) {
376
- return formatFileSize(fileSize);
377
- },
378
- //自定义上传
379
- async uploadSectionFile(param, isCustom, uploadConfig) {
380
- if (!this.uploadUrl) {
381
- await this.initUploadUrl();
382
- }
383
- let that = this;
384
- var fileObj = param.file;
385
-
386
- let source;
387
-
388
- var form = new FormData();
389
- // 文件对象
390
- form.append("file", fileObj);
391
-
392
- let target = that.$refs.upload;
393
- let file = target ? target.getFile(fileObj) : null;
394
- if (file) {
395
- file.status = "uploading";
396
- }
397
-
398
- let isLoading = uploadConfig?.isLoading === true;
399
- var uploadUrl = this.uploadUrl;
400
- if (uploadUrl) {
401
- var abort;
402
- let config = {
403
- isLoading: isLoading,
404
- headers: {
405
- "Content-Type": "multipart/form-data",
406
- },
407
- cancelToken: new imFun.axios.CancelToken(function executor(c) {
408
- if (!isCustom) {
409
- abort = c;
410
- if (file) file.abort = c;
411
- }
412
- }),
413
- onUploadProgress: (progressEvent) => {
414
- if (isCustom || file) {
415
- // progressEvent.loaded:已上传文件大小
416
- // progressEvent.total:被上传文件的总大小
417
- progressEvent.percent = Math.floor(
418
- (progressEvent.loaded * 100) / progressEvent.total
419
- );
420
- if (!isCustom) {
421
- param.onProgress(progressEvent, fileObj);
422
- }
423
- uploadConfig &&
424
- uploadConfig.onProgress &&
425
- uploadConfig.onProgress(progressEvent, fileObj);
426
- }
427
- },
428
- failMsg: false,
429
- }; //添加请求头
430
-
431
- let req = this.$http
432
- .post(uploadUrl, form, config)
433
- .then((res1) => {
434
- uploadConfig &&
435
- uploadConfig.callback &&
436
- uploadConfig.callback(res1, fileObj);
437
- if (!isCustom) {
438
- if (res1.type == "success") {
439
- param.onSuccess(res1, fileObj);
440
- } else {
441
- // param.onError(new Error(res1.content || '上传异常'));
442
- this.handleFileError(
443
- new Error(
444
- res1.content ||
445
- this.$t2(
446
- "上传异常",
447
- "components.VabUpload.uploadException"
448
- )
449
- ),
450
- fileObj
451
- );
452
- }
453
- }
454
- })
455
- .catch((error, a, b, c) => {
456
- // let {err} = error;
457
- try {
458
- // param.onError(err, fileObj);
459
- if (!isCustom) {
460
- this.handleFileError(error, fileObj);
461
- }
462
- uploadConfig &&
463
- uploadConfig.error &&
464
- uploadConfig.error(error, fileObj);
465
- } catch (tt) {}
466
- });
467
- req.abort = () => {
468
- abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
469
- };
470
- //return req;
471
- }
472
- },
473
- singerUpload(uploadConfig) {
474
- let onUploadProgress = uploadConfig.onUploadProgress;
475
- let success = uploadConfig.success;
476
- let file = uploadConfig.file;
477
- this.handleBeforeUpload(file, false, () => {
478
- this.uploadSectionFile(
479
- {
480
- file: file,
481
- },
482
- true,
483
- uploadConfig
484
- );
485
- });
486
- },
487
- //begin
488
- fileParse(file, type = "base64", callback) {
489
- /*return new Promise(resolve => {
490
-
491
- });*/
492
- let fileRead = new FileReader();
493
- if (type === "base64") {
494
- fileRead.readAsDataURL(file);
495
- } else if (type === "buffer") {
496
- fileRead.readAsArrayBuffer(file);
497
- }
498
- fileRead.onload = (ev) => {
499
- callback(ev.target.result);
500
- // resolve(ev.target.result);
501
- };
502
- },
503
- getFileMd5(file, callback){
504
- // 判断是否为大文件(例如大于10MB)
505
- const isLargeFile = file.size > 20 * 1024 * 1024;
506
-
507
- if (!isLargeFile) {
508
- this.fileParse(file,"buffer", (buffer)=>{
509
- let spark = new imFun.SparkMD5.ArrayBuffer();
510
- spark.append(buffer);
511
- let hash = spark.end();
512
- callback(hash)
513
- })
514
- }else{
515
- this.calculateFileMD5(file, callback)
516
- }
517
- },
518
- calculateFileMD5(file, callback) {
519
- const chunkSize = 16 * 1024 * 1024; // 2MB一块
520
- const chunks = Math.ceil(file.size / chunkSize);
521
- let currentChunk = 0;
522
- const spark = new imFun.SparkMD5.ArrayBuffer();
523
- const fileReader = new FileReader();
524
-
525
- // 处理读取错误
526
- fileReader.onerror = function() {
527
- console.error('文件读取错误');
528
- callback(null);
529
- };
530
-
531
- // 处理进度回调(可选)
532
- const onProgress = (progress) => {
533
- // 可以在这里更新进度条
534
- console.log('MD5计算进度: ' + Math.round(progress * 100) + '%');
535
- };
536
-
537
- // 递归读取下一块
538
- const loadNext = () => {
539
- const start = currentChunk * chunkSize;
540
- const end = Math.min(start + chunkSize, file.size);
541
-
542
- fileReader.readAsArrayBuffer(file.slice(start, end));
543
- };
544
-
545
- // 每块读取完成后的处理
546
- fileReader.onload = function(e) {
547
- spark.append(e.target.result);
548
- currentChunk++;
549
-
550
- // 更新进度
551
- // onProgress(currentChunk / chunks);
552
-
553
- // 继续读取下一块或完成
554
- if (currentChunk < chunks) {
555
- loadNext();
556
- } else {
557
- // 所有块读取完成,计算最终MD5
558
- const md5 = spark.end();
559
- callback(md5);
560
- }
561
- };
562
-
563
- // 开始处理
564
- loadNext();
565
- },
566
- changeFile(param) {
567
- if (!param.file || param.file.status == "fail") return;
568
- let target = this.$refs.upload;
569
- if (!target) return;
570
- let fileObj = target.getFile(param.file);
571
- fileObj.status = "preUpload";
572
- fileObj.param = {
573
- file: param.file,
574
- onSuccess: param.onSuccess,
575
- onProgress: param.onProgress,
576
- onError: param.onError,
577
- };
578
- this.checkPreUploadList();
579
- },
580
- checkPreUploadList() {
581
- let uploadingLimit = this.option.uploadingLimit || this.uploadingLimit;
582
- let target = this.$refs.upload;
583
- let fileList1 = (target.uploadFiles || []).filter((item) => {
584
- return item.status == "preUpload";
585
- });
586
- let fileList2 = (target.uploadFiles || []).filter((item) => {
587
- return item.status == "uploading";
588
- });
589
- if (fileList2.length < uploadingLimit && fileList1.length > 0) {
590
- let num = uploadingLimit - fileList2.length;
591
- if (num) {
592
- let toNum = Math.min(fileList1.length, num);
593
- for (let i = 0; i < toNum; i++) {
594
- let fileRaw = fileList1[i].raw;
595
- this.uploadFile(fileRaw);
596
- }
597
- }
598
- }
599
- },
600
- async uploadFile(file) {
601
- if (!file || file.status == "fail") return;
602
- let target = this.$refs.upload;
603
- if (!target) return;
604
- let fileObj = target.getFile(file);
605
- if (fileObj.status != "preUpload") return;
606
- if (!this.isPartUpload) {
607
- this.uploadSectionFile(fileObj.param);
608
- return;
609
- }
610
-
611
- if (!this.uploadUrl) {
612
- await this.initUploadUrl();
613
- }
614
- this.total = 0;
615
- target.handleProgress({ percent: 0 }, file);
616
-
617
- // 解析为BUFFER数据
618
- // 我们会把文件切片处理:把一个文件分割成为好几个部分(固定数量/固定大小)
619
- // 每一个切片有自己的部分数据和自己的名字
620
- // HASH_1.mp4
621
- // HASH_2.mp4
622
- // ...
623
-
624
- this.getFileMd5(file, (md5) => {
625
- /* let spark = new imFun.SparkMD5.ArrayBuffer(),
626
- chunkSize = this.chunkSize * 1024 * 1024, // Read in chunks of 2MB
627
- chunks = Math.ceil(file.size / chunkSize),
628
- hash,
629
- suffix;
630
- spark.append(buffer);
631
- hash = spark.end(); */
632
-
633
- let chunkSize = this.chunkSize * 1024 * 1024, // Read in chunks of 2MB
634
- chunks = Math.ceil(file.size / chunkSize),
635
- hash = md5,
636
- suffix;
637
-
638
- let nameSplit = /\.([0-9a-zA-Z]+)$/i.exec(file.name);
639
-
640
- suffix = nameSplit && nameSplit.length > 1 ? nameSplit[1] : "";
641
-
642
- let checkUrl = this.uploadUrl.replace(
643
- "/docfile/upload",
644
- "/docfile/check"
645
- );
646
- let checkData = {
647
- name: file.name,
648
- md5: hash,
649
- };
650
- let abort;
651
- let checkReq = this.$http({
652
- url: checkUrl,
653
- method: "post",
654
- cancelToken: new imFun.axios.CancelToken(function executor(c) {
655
- abort = c;
656
- file.abort = c;
657
- }),
658
- data: checkData,
659
- failMsg: false,
660
- modal: false,
661
- callback: (res) => {
662
- if (res.type == "success") {
663
- let resData = res.objx || {};
664
- let chunkParam = {
665
- fullFile: file,
666
- chunkSize: chunkSize,
667
- chunks: chunks,
668
- chunkIndex: 0,
669
- md5: hash,
670
- uuid: resData.uuid,
671
- };
672
- file.chunkParam = chunkParam;
673
-
674
- this.sendRequest(file);
675
- } else {
676
- this.handleFileError(
677
- new Error(
678
- res.content ||
679
- this.$t2("上传异常", "components.VabUpload.uploadException")
680
- ),
681
- file
682
- );
683
- }
684
- },
685
- error: (e) => {
686
- this.handleFileError(e, file);
687
- },
688
- });
689
- checkReq.abort = () => {
690
- abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
691
- };
692
- });
693
- },
694
- async sendRequest(fullFile) {
695
- let that = this;
696
- let uploadUrl = this.uploadUrl;
697
- let chunkParam = fullFile.chunkParam;
698
- let target = that.$refs.upload;
699
- let abort;
700
- let config = {
701
- headers: {
702
- "Content-Type": "multipart/form-data",
703
- },
704
- cancelToken: new imFun.axios.CancelToken(function executor(c) {
705
- /* let target = that.$refs.upload;
706
- let filem = target.getFile(file);
707
- abort = c;
708
- filem.abort = c; */
709
- abort = c;
710
- fullFile.abort = c;
711
- }),
712
- onUploadProgress: (progressEvent) => {
713
- if (!target || !fullFile) return;
714
- let file = target.getFile(fullFile);
715
- if (file) {
716
- // progressEvent.loaded:已上传文件大小
717
- // progressEvent.total:被上传文件的总大小
718
- let start = chunkParam.start;
719
- let uploadedSize =
720
- start +
721
- Math.floor(
722
- (chunkParam.currentSize * progressEvent.loaded) /
723
- progressEvent.total
724
- );
725
- let percent = Math.floor((uploadedSize * 100) / fullFile.size);
726
- if (percent == 100) {
727
- percent = 99;
728
- }
729
- progressEvent.percent = percent;
730
- target.handleProgress(progressEvent, fullFile);
731
- }
732
- },
733
- failMsg: false,
734
- modal: false,
735
- }; //添加请求头
736
-
737
- let chunkIndex = chunkParam.chunkIndex;
738
- let chunkSize = chunkParam.chunkSize;
739
- var start = chunkIndex * chunkSize,
740
- end =
741
- start + chunkSize >= fullFile.size
742
- ? fullFile.size
743
- : start + chunkParam.chunkSize;
744
- chunkParam.currentSize = end - start;
745
- chunkParam.start = start;
746
- chunkParam.end = end;
747
-
748
- let preFormData = {
749
- file: fullFile.slice(start, end),
750
- name: fullFile.name,
751
- chunks: chunkParam.chunks,
752
- chunk: chunkIndex,
753
- md5: chunkParam.md5,
754
- uuid: chunkParam.uuid,
755
- fileSize: fullFile.size,
756
- };
757
-
758
- let formData = new FormData();
759
- Object.keys(preFormData).forEach((key) => {
760
- formData.append(key, preFormData[key]);
761
- });
762
-
763
- let req = this.$http
764
- .post(uploadUrl, formData, config)
765
- .then((res1) => {
766
- if (res1.type == "success") {
767
- if (preFormData.chunk + 1 >= preFormData.chunks) {
768
- let mergeData = {};
769
- Object.keys(preFormData).forEach((key) => {
770
- if (key != "file" && key != "chunk") {
771
- mergeData[key] = preFormData[key];
772
- }
773
- });
774
- let _param = {
775
- mergeData: mergeData,
776
- chunkParam: chunkParam,
777
- };
778
- this.mergeFile(_param);
779
- } else {
780
- chunkParam.chunkIndex = chunkParam.chunkIndex + 1;
781
- this.sendRequest(fullFile);
782
- }
783
- } else {
784
- this.handleFileError(
785
- new Error(
786
- res1.content ||
787
- this.$t2("上传异常", "components.VabUpload.uploadException")
788
- ),
789
- fullFile
790
- );
791
- }
792
- return res1;
793
- })
794
- .catch((err) => {
795
- try {
796
- if (!abort) {
797
- this.handleFileError(err, fullFile);
798
- }
799
- } catch (tt) {}
800
- });
801
- req.abort = () => {
802
- abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
803
- };
804
- },
805
- mergeFile(param) {
806
- let mergeData = param.mergeData;
807
- let chunkParam = param.chunkParam;
808
- let fullFile = chunkParam.fullFile;
809
- let mergeUrl = this.uploadUrl.replace(
810
- "/docfile/upload",
811
- "/docfile/merge"
812
- );
813
- let target = this.$refs.upload;
814
- this.$http({
815
- url: mergeUrl,
816
- method: "post",
817
- data: mergeData,
818
- failMsg: false,
819
- modal: false,
820
- cancelToken: new imFun.axios.CancelToken(function executor(c) {
821
- if (fullFile) fullFile.abort = c;
822
- }),
823
- callback: (res) => {
824
- if (!target || !fullFile) return;
825
- if (res.type == "success") {
826
- let file = target.getFile(fullFile);
827
- if (file) {
828
- target.handleProgress(
829
- {
830
- percent: 100,
831
- },
832
- fullFile
833
- );
834
- target.handleSuccess(res, fullFile);
835
- }
836
- } else {
837
- this.handleFileError(
838
- new Error(
839
- res.content ||
840
- this.$t2("上传异常", "components.VabUpload.uploadException")
841
- ),
842
- fullFile
843
- );
844
- }
845
- },
846
- error: (e) => {
847
- if (!target || !fullFile) return;
848
- if (fullFile) {
849
- let file = target.getFile(fullFile);
850
- if (file) {
851
- this.handleFileError(e, fullFile);
852
- }
853
- }
854
- },
855
- });
856
- },
857
- handleBtn() {
858
- let target = this.$refs.upload;
859
- let fileList = (target.uploadFiles || []).filter((item) => {
860
- return item.status == "uploading" || item.status == "ready";
861
- });
862
- if (this.btn) {
863
- //断点续传
864
- this.abort = false;
865
- this.btn = false;
866
- fileList.forEach((uploadFile) => {
867
- let nextChunk = uploadFile.raw.nextChunk;
868
- this.sendRequest(uploadFile.raw.partList, nextChunk);
869
- });
870
- } else {
871
- //暂停上传
872
- fileList.forEach((uploadFile) => {
873
- uploadFile.raw.abort(
874
- this.$t2("取消上传", "components.VabUpload.cancelUpload")
875
- );
876
- });
877
- this.btn = true;
878
- this.abort = true;
879
- }
880
- },
881
- //end
882
- getShowImage(file, fileName) {
883
- fileName = fileName || file.name;
884
- if (this.$commonFileUtil.isPictureFile(fileName)) {
885
- return file.showUrl || file.url;
886
- } else {
887
- return this.$commonFileUtil.getFileIconRequire(fileName);
888
- }
889
- },
890
- removeFile(sfile) {
891
- var target = this.$refs.upload;
892
- var index;
893
- var fileList = target.uploadFiles;
894
- for (let i = 0; i < fileList.length; i++) {
895
- let file = fileList[i];
896
- if (sfile.uid == file.uid) {
897
- index = i;
898
- if (sfile.status == "uploading") {
899
- // file.status == 'delete'
900
- //target.abort(file);
901
- file.raw.abort &&
902
- file.raw.abort(
903
- this.$t2("取消上传", "components.VabUpload.cancelUpload")
904
- );
905
- }
906
- break;
907
- }
908
- }
909
-
910
- target.uploadFiles.splice(index, 1);
911
- this.handleChange(sfile, target.uploadFiles);
912
- },
913
- submitImage() {
914
- var target = this.$refs.upload;
915
- var fileList = target.uploadFiles;
916
- let fileInfos = [];
917
- let fileDatas = [];
918
- for (let i = 0; i < fileList.length; i++) {
919
- let file = fileList[i];
920
- if (file.status == "uploading") {
921
- this.$message({
922
- message: this.$t2(
923
- "文件上传中",
924
- "components.VabUpload.fileUploading"
925
- ),
926
- type: "error",
927
- duration: 2000,
928
- });
929
- return;
930
- }
931
- if (file.status == "success") {
932
- let fileData = file.response.objx;
933
- fileData.name = file.name;
934
- let fileInfo = {
935
- name: file.name,
936
- fileData: fileData,
937
- file: file.raw,
938
- };
939
- fileInfos.push(fileInfo);
940
- fileDatas.push(fileData);
941
- }
942
- }
943
- this.handleClose();
944
- this.$emit("callback", fileInfos, fileDatas);
945
- this.callback && this.callback(fileDatas, fileInfos);
946
- },
947
- showViewDialog(lineData) {
948
- var data = lineData.fileData ? lineData.fileData : lineData;
949
-
950
- let thumbnail = data ? data.thumbnail || "" : "";
951
-
952
- var realUrl = data.domain + data.url;
953
- var showUrl = "";
954
- let fileName = lineData ? lineData.name || "" : "";
955
- if (!this.$commonFileUtil.isPictureFile(fileName)) {
956
- showUrl = this.$commonFileUtil.getFileIconRequire(fileName);
957
- } else if (thumbnail) {
958
- showUrl = data.domain + thumbnail;
959
- } else {
960
- showUrl = data.domain + data.url;
961
- }
962
-
963
- var preName = "";
964
- var suffix = "";
965
- var i = fileName.lastIndexOf(".");
966
- if (i >= 0) {
967
- suffix = fileName.substring(i + 1, fileName.length).toLowerCase();
968
- }
969
- this.fileViewInfo = {
970
- realUrl: realUrl,
971
- showUrl: showUrl,
972
- fileName: fileName,
973
- suffix: suffix,
974
- data: data,
975
- };
976
- this.fileViewDialogVisible = true;
977
- },
978
- getShowUrl(attachment, field) {
979
- let showUrl = null;
980
- let typeStr = Object.prototype.toString.call(attachment);
981
- if (typeStr == "[object Object]") {
982
- let showField = field ? field : "medium";
983
- let fullUrl =
984
- attachment.domain +
985
- (attachment[showField] ? attachment[showField] : attachment.url);
986
- showUrl = this.$commonFileUtil.getShowUrl(fullUrl);
987
- } else {
988
- showUrl = this.$commonFileUtil.getShowUrl(attachment);
989
- }
990
- return showUrl;
991
- },
992
- addPrivateFiles(rows) {
993
- var target = this.$refs.upload;
994
- let uploadFiles = target.uploadFiles;
995
- let sourceSns = uploadFiles
996
- .filter((row) => {
997
- return !!(
998
- row.response &&
999
- row.response.objx &&
1000
- row.response.objx.sourceSn
1001
- );
1002
- })
1003
- .map((row) => row.response.objx.sourceSn);
1004
-
1005
- let newFiles = rows
1006
- .filter((row) => !row.dirs && !sourceSns.includes(row.sn))
1007
- .map((row) => {
1008
- let item = {
1009
- status: "success",
1010
- name: row.fileName,
1011
- size: row.fileSize,
1012
- percentage: 100,
1013
- uid: row.fileSn,
1014
- raw: {
1015
- lastModified: "",
1016
- lastModifiedDate: new Date(),
1017
- name: row.fileName,
1018
- size: row.fileSize,
1019
- type: "",
1020
- uid: row.fileSn,
1021
- webkitRelativePath: "",
1022
- },
1023
- response: {
1024
- time: "",
1025
- type: "success",
1026
- objx: {
1027
- thumbnail: row.thumbnail,
1028
- extension: row.extension,
1029
- large: row.large,
1030
- fileSize: row.fileSize,
1031
- domain: row.domain,
1032
- source: row.source,
1033
- medium: row.medium,
1034
- url: row.url,
1035
- sourceSn: row.sn,
1036
- },
1037
- content: "success",
1038
- rmid: null,
1039
- },
1040
- url: row.domain + row.url,
1041
- showUrl: this.getShowUrl(row),
1042
- };
1043
- return item;
1044
- });
1045
- uploadFiles.push(...newFiles);
1046
- },
1047
- confirmPrivateProfileDialog(rows) {
1048
- this.addPrivateFiles(rows);
1049
- },
1050
- initPrivateUploadBt() {
1051
- if (settingConfig.privateProfileCode && this.pickPrivateProfile) {
1052
- this.$http({
1053
- url: USER_PREFIX + "/file_store_area/getByCode",
1054
- method: "post",
1055
- data: { stringOne: settingConfig.privateProfileCode },
1056
- failMsg: false,
1057
- errorMsg: false,
1058
- success: (res) => {
1059
- this.showPrivateUploadBtn = res.objx ? true : false;
1060
- },
1061
- });
1062
- } else {
1063
- this.showPrivateUploadBtn = false;
1064
- }
1065
- },
1066
- initPickUploadMode() {
1067
- this.showLocalUploadBtn = false;
1068
- this.showPrivateUploadBtn = false;
1069
- this.$http({
1070
- url: USER_PREFIX + "/system_parameter/getByCode",
1071
- method: "post",
1072
- data: { code: "pickUploadMode" },
1073
- success: (res) => {
1074
- let value = !res.objx || !res.objx.value ? "2" : res.objx.value;
1075
- if (value == "0") {
1076
- //启用本地上传,个人文档上传
1077
- this.showLocalUploadBtn = true;
1078
- this.initPrivateUploadBt();
1079
- } else if (value == "1") {
1080
- //启用个人文档上传
1081
- this.initPrivateUploadBt();
1082
- } else if (value == "2") {
1083
- //启用本地上传
1084
- this.showLocalUploadBtn = true;
1085
- }
1086
- },
1087
- });
1088
- },
1089
- pasteEvent(e) {
1090
- // e.preventDefault();
1091
- e.stopPropagation();
1092
- if (!this.pasteAreaStatus) {
1093
- return;
1094
- }
1095
- if (!(e.clipboardData && e.clipboardData.items)) {
1096
- return;
1097
- }
1098
- let files = Array.from(e.clipboardData.files);
1099
- let getFileSuffix = this.$commonFileUtil.getFileSuffix;
1100
- if (files.length) {
1101
- let fileList = files.map((rawFile) => {
1102
- let name = rawFile.name;
1103
- let index = name.lastIndexOf(".");
1104
- let fileSuffix = getFileSuffix(name);
1105
- let fileName =
1106
- index >= 0 ? name.substring(0, index).toString() : name.toString();
1107
- let file = {
1108
- name: rawFile.name,
1109
- size: rawFile.size,
1110
- raw: rawFile,
1111
- showUrl: URL.createObjectURL(rawFile),
1112
- fileName: fileName,
1113
- fileSuffix: fileSuffix,
1114
- };
1115
- return file;
1116
- });
1117
- this.pasteList.push(...fileList);
1118
- }
1119
- },
1120
- deletePasteFile(index) {
1121
- this.pasteList.splice(index, 1);
1122
- },
1123
- confirmPasteFile() {
1124
- let target = this.$refs.upload;
1125
- let innerTarget = target.$refs["upload-inner"];
1126
- let pasteList = this.$baseLodash.cloneDeep(this.pasteList);
1127
- let files = pasteList.map((item) => {
1128
- let name = item.name;
1129
- let fileRaw = item.raw;
1130
- fileRaw.fileName = name;
1131
- return fileRaw;
1132
- });
1133
- innerTarget.uploadFiles(files);
1134
- this.$nextTick(() => {
1135
- target.uploadFiles.forEach((uploadFile) => {
1136
- let fileRaw = uploadFile.raw;
1137
- if (fileRaw.fileName) {
1138
- uploadFile.name = fileRaw.fileName;
1139
- delete fileRaw.fileName;
1140
- }
1141
- });
1142
- });
1143
- this.pasteList = [];
1144
- },
1145
- changeFileName(file) {
1146
- if (file.fileSuffix) {
1147
- file.name = (file.fileName + "." + file.fileSuffix).toString();
1148
- } else {
1149
- file.name = file.fileName.toString();
1150
- }
1151
- },
1152
- handleFileError(err, rawFile) {
1153
- let target = this.$refs.upload;
1154
- if (!target) return;
1155
- const file = target.getFile(rawFile);
1156
- const fileList = target.uploadFiles;
1157
-
1158
- file.status = "fail";
1159
- file.failMsg = err && err.message ? err.message : null;
1160
-
1161
- // fileList.splice(fileList.indexOf(file), 1);
1162
-
1163
- target.onError(err, file, target.uploadFiles);
1164
- target.onChange(file, target.uploadFiles);
1165
- this.updateUploadingStatus();
1166
- },
1167
- choosePasteArea(e) {
1168
- e.stopPropagation();
1169
- this.pasteAreaStatus = true;
1170
- },
1171
- openFileNameDialog(row, index) {
1172
- this.editFileName = row.fileName?.toString();
1173
- this.editFileSuffix = row.fileSuffix?.toString();
1174
- this.editFileIndex = index;
1175
- this.showFileNameDialog = true;
1176
- },
1177
- confirmFileNameDialog() {
1178
- if (!this.editFileName) {
1179
- this.$message({
1180
- message: this.$t2("文件名不能为空", "components.VabUpload.warnMsg3"),
1181
- type: "error",
1182
- showClose: true,
1183
- duration: 3000,
1184
- });
1185
- return;
1186
- }
1187
- let editFileIndex = this.editFileIndex;
1188
- let file = this.pasteList[editFileIndex];
1189
- file.fileName = this.editFileName.toString();
1190
- file.name = (file.fileName + "." + file.fileSuffix).toString();
1191
- this.showFileNameDialog = false;
1192
- },
1193
- },
1194
- };
1195
-
1196
- tViewMixins = {
1197
- props: {
1198
- resultType: String,
1199
- dataType: String,
1200
- callback: Function,
1201
- file: {
1202
- type: [Array, Object, String],
1203
- },
1204
- multi: {
1205
- type: [String, Boolean],
1206
- default: true,
1207
- },
1208
- auto: {
1209
- type: Boolean,
1210
- default: true,
1211
- },
1212
- limit: {
1213
- type: Number,
1214
- default: 100000,
1215
- },
1216
- size: {
1217
- type: Number,
1218
- default: 200,
1219
- },
1220
- accept: {
1221
- type: String,
1222
- default: "file",
1223
- },
1224
- chunkSize: {
1225
- type: Number,
1226
- default: 5, //5MB
1227
- },
1228
- confirmUpload: {
1229
- type: Function,
1230
- },
1231
- pickPrivateProfile: {
1232
- type: Boolean,
1233
- default: true,
1234
- },
1235
- uploadingLimit: {
1236
- type: Number,
1237
- default: 5, //5MB
1238
- },
1239
- isPartUpload: {
1240
- type: Boolean,
1241
- default: () => {
1242
- return settingConfig.isPartUpload ?? true;
1243
- }
1244
- },
1245
- autoConfirmAfterPasteUpload: {
1246
- type: Boolean,
1247
- default: false,
1248
- },
1249
- },
1250
- data() {
1251
- return {
1252
- attachments: [],
1253
- pictureList: [],
1254
- pictureDtoList: [],
1255
- showPropertiesDialog: false,
1256
- editAttachment: null,
1257
- showViewer: false,
1258
- chooseIndex: 0,
1259
- fileServerInfo: {},
1260
- model: null
1261
- };
1262
- },
1263
- computed: {
1264
- fileServerPreviewEnabled(){
1265
- return this.getFileServerPreviewEnabled();
1266
- },
1267
- fileShowImageEnabled(){
1268
- return this.getFileShowImageEnabled();
1269
- },
1270
- fileMaxSize() {
1271
- return this.size;
1272
- },
1273
- showUploadBtn: function () {
1274
- if (!this.isMulti) {
1275
- return this.attachments.length == 0;
1276
- } else {
1277
- return this.limit ? this.limit > this.attachments.length : true;
1278
- }
1279
- },
1280
- isMulti: function () {
1281
- let isMulti = true;
1282
- if (this.multi === "false" || this.multi === false || this.limit === 1) {
1283
- isMulti = false;
1284
- }
1285
- return isMulti;
1286
- },
1287
- },
1288
- watch: {
1289
- file(val) {
1290
- this.initFile();
1291
- },
1292
- attachments(val) {
1293
- let that = this;
1294
- let pictureList = [];
1295
- let pictureDtoList = [];
1296
- if (val) {
1297
- val.forEach((item) => {
1298
- if (item) {
1299
- let typeStr = Object.prototype.toString.call(item);
1300
- if (
1301
- typeStr == "[object Object]" &&
1302
- Object.keys(this.file).length > 0
1303
- ) {
1304
- if (that.$commonFileUtil.isPictureFile(item.url)) {
1305
- pictureList.push(item.domain + item.url);
1306
- pictureDtoList.push(item);
1307
- }
1308
- } else {
1309
- if (that.$commonFileUtil.isPictureFile(item)) {
1310
- pictureList.push(item);
1311
- pictureDtoList.push(item);
1312
- }
1313
- }
1314
- }
1315
- });
1316
- }
1317
- this.pictureList = pictureList;
1318
- this.pictureDtoList = pictureDtoList;
1319
- },
1320
- },
1321
- created() {
1322
- this.initFileServerInfo();
1323
- this.initFile();
1324
- },
1325
- methods: {
1326
- pasteEvent(e) {
1327
- e.stopPropagation();
1328
- if (!(e.clipboardData && e.clipboardData.items)) {
1329
- return
1330
- }
1331
- let files = Array.from(e.clipboardData.files);
1332
- if (files.length) {
1333
- this.openUploadDialog(files, this.autoConfirmAfterPasteUpload)
1334
- }
1335
- },
1336
- uploadEnterOver() {
1337
- // if (this.isLoading) return;
1338
- document.addEventListener('paste', this.pasteEvent);
1339
- },
1340
- uploadEnterLeave() {
1341
- document.removeEventListener('paste', this.pasteEvent);
1342
- },
1343
- getFileServerPreviewEnabled(){
1344
- let value = window.$vueRoot.$store.getters.fileServerInfo?.fileServerPreviewEnabled ?? (settingConfig.fileServerPreviewEnabled ?? true);
1345
- if(this.$attrs.fileServerPreviewEnabled!== null && this.$attrs.fileServerPreviewEnabled!== undefined){
1346
- value = this.$attrs.fileServerPreviewEnabled
1347
- }
1348
- return value;
1349
- },
1350
- getFileShowImageEnabled(){
1351
- let value = window.$vueRoot.$store.getters.fileServerInfo?.fileShowImageEnabled ?? (settingConfig.fileShowImageEnabled ?? true);
1352
- if(this.$attrs.fileShowImageEnabled!== null && this.$attrs.fileShowImageEnabled!== undefined){
1353
- value = this.$attrs.fileShowImageEnabled
1354
- }
1355
- return value;
1356
- },
1357
- openUploadDialog(files,autoConfirmAfterUpload) {
1358
- this.$baseUpload.open({
1359
- files,
1360
- autoConfirmAfterUpload,
1361
- ...this.fileServerInfo,
1362
- ...this._props,
1363
- ...this.$attrs,
1364
- limit: this.limit,
1365
- multi: this.multi,
1366
- accept: this.accept ? this.accept : "file",
1367
- auto: this.auto,
1368
- size: this.fileMaxSize,
1369
- chunkSize: this.chunkSize,
1370
- callback: this.fileConfirm,
1371
- pickPrivateProfile: this.pickPrivateProfile,
1372
- confirmUpload: this.confirmUpload,
1373
- otherParams: this.$attrs,
1374
- });
1375
- },
1376
- initFileServerInfo() {
1377
- if (this.$attrs.model) {
1378
- this.model = this.$attrs.model;
1379
- // this.fileServerInfo = this.$attrs.fileServerInfo;
1380
- } else {
1381
- this.model = window.$vueRoot.$store.getters.fileServerInfo?.model ?? null;
1382
- /* getFileServerInfo(this, (res) => {
1383
- if (res) {
1384
- let fileServerInfo = res;
1385
- this.model = fileServerInfo.model
1386
- this.fileServerInfo = fileServerInfo;
1387
- }else{
1388
- this.model = null;
1389
- this.fileServerInfo = null;
1390
- }
1391
- }) */
1392
- }
1393
- },
1394
- initFile() {
1395
- if (this.file) {
1396
- let typeStr = Object.prototype.toString.call(this.file);
1397
- if (!this.dataType) {
1398
- if (typeStr == "[object Array]") {
1399
- this.attachments = this.file;
1400
- } else if (
1401
- typeStr == "[object Object]" &&
1402
- Object.keys(this.file).length > 0
1403
- ) {
1404
- this.attachments = [this.file];
1405
- } else {
1406
- this.attachments = [];
1407
- }
1408
- } else {
1409
- this.attachments = [this.file];
1410
- }
1411
- } else {
1412
- this.attachments = [];
1413
- }
1414
- },
1415
- deleteFile(index) {
1416
- if (!this.$listeners.delete || this.$listeners.delete(index) !== false) {
1417
- this.attachments.splice(index, 1);
1418
- this.updatePropFile();
1419
- this.$emit("afterDelete", this.attachments);
1420
- }
1421
- },
1422
- fileConfirm(rows, fileInfos) {
1423
- if (rows.length > 0) {
1424
- if (this.isMulti) {
1425
- let limit = this.limit;
1426
- if (limit) {
1427
- let oSize = this.file?.length ?? 0;
1428
- let vailSize = limit - oSize;
1429
- if (vailSize > 0) {
1430
- rows = rows.length < vailSize ? rows : rows.slice(0, vailSize);
1431
- } else {
1432
- rows = [];
1433
- }
1434
- }
1435
- } else {
1436
- rows = [rows[0]];
1437
- }
1438
-
1439
- let attachments = this.attachments;
1440
- let dataType = this.dataType;
1441
- let eRows = [];
1442
- if (dataType != null) {
1443
- eRows = rows.map((row) => {
1444
- return row.domain + (row[dataType] || row["url"]);
1445
- });
1446
- } else {
1447
- eRows = rows;
1448
- }
1449
-
1450
- if (
1451
- !this.$listeners.confirm ||
1452
- this.$listeners.confirm(eRows, fileInfos) !== false
1453
- ) {
1454
- if (this.isMulti) {
1455
- this.attachments = attachments.concat(eRows);
1456
- } else {
1457
- this.attachments = eRows;
1458
- }
1459
- this.updatePropFile();
1460
- this.$emit("callback", eRows, fileInfos);
1461
- }
1462
- }
1463
- },
1464
- updatePropFile() {
1465
- if (this.isMulti) {
1466
- this.$emit("update:file", this.attachments);
1467
- } else {
1468
- let result =
1469
- this.attachments && this.attachments.length
1470
- ? this.attachments[0]
1471
- : null;
1472
- if (
1473
- this.resultType == "Array" ||
1474
- (this.multi !== "false" && this.multi !== false)
1475
- ) {
1476
- result = result ? [result] : [];
1477
- }
1478
- this.$emit("update:file", result);
1479
- }
1480
- this.handleChange();
1481
- },
1482
- handleChange() {
1483
- this.$emit("change", this.attachments);
1484
- },
1485
- getRealPictureList(index) {
1486
- let pictureIndex = -1;
1487
- this.attachments.find((item, i) => {
1488
- let typeStr = Object.prototype.toString.call(item);
1489
- if (typeStr == "[object Object]") {
1490
- if (this.$commonFileUtil.isPictureFile(item.url)) {
1491
- pictureIndex++;
1492
- }
1493
- } else {
1494
- if (this.$commonFileUtil.isPictureFile(item)) {
1495
- pictureIndex++;
1496
- }
1497
- }
1498
- return index == i;
1499
- });
1500
- return this.pictureList
1501
- .slice(pictureIndex)
1502
- .concat(this.pictureList.slice(0, pictureIndex));
1503
- },
1504
- getRealPictureDTOList() {
1505
- let index = this.chooseIndex || 0;
1506
- let pictureIndex = -1;
1507
- this.attachments.find((item, i) => {
1508
- let typeStr = Object.prototype.toString.call(item);
1509
- if (typeStr == "[object Object]") {
1510
- if (this.$commonFileUtil.isPictureFile(item.url)) {
1511
- pictureIndex++;
1512
- }
1513
- } else {
1514
- if (this.$commonFileUtil.isPictureFile(item)) {
1515
- pictureIndex++;
1516
- }
1517
- }
1518
- return index == i;
1519
- });
1520
- let res = this.pictureDtoList
1521
- .slice(pictureIndex)
1522
- .concat(this.pictureDtoList.slice(0, pictureIndex));
1523
- return res;
1524
- },
1525
- openImagePreView(index) {
1526
- // this.chooseIndex = index;
1527
- let pictureIndex = -1;
1528
- this.attachments.find((item, i) => {
1529
- let typeStr = Object.prototype.toString.call(item);
1530
- if (typeStr == "[object Object]") {
1531
- if (this.$commonFileUtil.isPictureFile(item.url)) {
1532
- pictureIndex++;
1533
- }
1534
- } else {
1535
- if (this.$commonFileUtil.isPictureFile(item)) {
1536
- pictureIndex++;
1537
- }
1538
- }
1539
- return index == i;
1540
- });
1541
- this.chooseIndex = pictureIndex;
1542
- this.showViewer = true;
1543
- },
1544
- openPropertiesDialog(attachment) {
1545
- this.editAttachment = attachment;
1546
- this.showPropertiesDialog = true;
1547
- },
1548
- closeViewer() {
1549
- this.showViewer = false;
1550
- },
1551
- hasPreview(attachment) {
1552
- let fileServerPreviewEnabled = this.getFileServerPreviewEnabled();
1553
- let typeStr = Object.prototype.toString.call(attachment);
1554
- let url =
1555
- typeStr == "[object Object]"
1556
- ? attachment.domain + attachment.url
1557
- : attachment;
1558
- if (fileServerPreviewEnabled) {
1559
- return (
1560
- this.$commonFileUtil.isPictureFile(url) ||
1561
- this.$commonFileUtil.isPreviewFile(url)
1562
- );
1563
- } else {
1564
- return this.$commonFileUtil.isPictureFile(url);
1565
- }
1566
- },
1567
- openPreview(attachment, index) {
1568
- let fileServerPreviewEnabled = this.getFileServerPreviewEnabled();
1569
- let typeStr = Object.prototype.toString.call(attachment);
1570
- let url =
1571
- typeStr == "[object Object]"
1572
- ? attachment.domain + attachment.url
1573
- : attachment;
1574
- if (this.$commonFileUtil.isPictureFile(url)) {
1575
- this.openImagePreView(index);
1576
- } else if (fileServerPreviewEnabled && this.$commonFileUtil.isPreviewFile(url)) {
1577
- this.$openFilePreview(url);
1578
- }
1579
- },
1580
- getAttachmentName(attachment) {
1581
- let name = null;
1582
- let typeStr = Object.prototype.toString.call(attachment);
1583
- if (typeStr == "[object Object]") {
1584
- name = attachment.name;
1585
- } else {
1586
- let url = attachment;
1587
- if (url) {
1588
- var i = url.lastIndexOf("/");
1589
- if (i >= 0) {
1590
- name = url.substring(i + 1, url.length);
1591
- }
1592
- }
1593
- }
1594
- return name;
1595
- },
1596
- getShowUrl(attachment, field) {
1597
- let showUrl = null;
1598
- let showImagePreview = this.getFileShowImageEnabled();
1599
- let typeStr = Object.prototype.toString.call(attachment);
1600
- if (typeStr == "[object Object]") {
1601
- let showField = field ? field : "medium";
1602
- let fullUrl = attachment.domain + (showImagePreview && attachment[showField] ? attachment[showField] : attachment.url);
1603
- showUrl = this.$commonFileUtil.getShowUrl(fullUrl, showImagePreview);
1604
- } else {
1605
- showUrl = this.$commonFileUtil.getShowUrl(attachment, showImagePreview);
1606
- }
1607
- return showUrl;
1608
- },
1609
- downloadFile(attachment) {
1610
- let typeStr = Object.prototype.toString.call(attachment);
1611
- if (typeStr == "[object Object]") {
1612
- this.$commonFileUtil.downloadFile(
1613
- attachment.domain + attachment.url,
1614
- attachment.name
1615
- );
1616
- } else {
1617
- this.$commonFileUtil.downloadFile(attachment);
1618
- }
1619
- },
1620
- formatFileSize(fileSize) {
1621
- return formatFileSize(fileSize);
1622
- },
1623
- },
1624
- };
1625
-
1626
- pmixins = {
1627
- name: "propertiesDialog",
1628
- components: {},
1629
- created() {
1630
- this.attachmentDTO = this.$attrs.editAttachment;
1631
- this.current_prefix =
1632
- this.attachmentDTO && this.attachmentDTO.serverName
1633
- ? "/" + this.attachmentDTO.serverName
1634
- : "";
1635
- },
1636
- mounted() {
1637
- this.initTableM1();
1638
- },
1639
- data() {
1640
- return {
1641
- showDialog: true,
1642
- falseValue: false,
1643
- vxeOption: {},
1644
- showContent: true,
1645
- attachmentDTO: {},
1646
- current_prefix: "",
1647
- };
1648
- },
1649
- methods: {
1650
- saveData() {
1651
- this.$refs.editForm.validate((valid) => {
1652
- if (valid) {
1653
- this.$baseConfirm(
1654
- this.$t2("您确定要保存吗?", "components.VabUpload.saveTip")
1655
- ).then(() => {
1656
- let formData = commonDataUtil.handleForm(this.attachmentDTO);
1657
-
1658
- var url = this.current_prefix + "/attachment/attribute/save";
1659
- this.$http({
1660
- url: url,
1661
- method: "post",
1662
- data: formData,
1663
- isLoading: true,
1664
- success: (res) => {
1665
- this.$message({
1666
- message: res.content,
1667
- type: "success",
1668
- duration: 500,
1669
- onClose: (t) => {
1670
- this.reloadContent();
1671
- },
1672
- });
1673
- },
1674
- });
1675
- });
1676
- }
1677
- });
1678
- },
1679
- dialogClose() {
1680
- this.$emit("update:visiable", false);
1681
- },
1682
- reloadContent() {
1683
- this.getData();
1684
- },
1685
- getData() {
1686
- this.$http({
1687
- url: this.current_prefix + "/attachment/attribute/list",
1688
- method: "post",
1689
- data: {
1690
- id: this.attachmentDTO.id,
1691
- },
1692
- isLoading: true,
1693
- // modalStrictly: true,
1694
- success: (res) => {
1695
- this.$set(
1696
- this.attachmentDTO,
1697
- "attachmentAttributeDTOs",
1698
- res.objx || []
1699
- );
1700
- },
1701
- });
1702
- this.getUserBasicInfos();
1703
- },
1704
- getUserBasicInfos() {
1705
- let createBy = this.attachmentDTO.createBy;
1706
- if (!!this.attachmentDTO._createBy || !createBy) return;
1707
- this.$http({
1708
- url: USER_PREFIX + `/userb/getUserBasicInfos`,
1709
- method: "post",
1710
- data: [createBy],
1711
- isLoading: true,
1712
- // modalStrictly: true,
1713
- success: (res) => {
1714
- let _createBy = createBy;
1715
- if (res.objx?.length) {
1716
- let nickName = res.objx[0].nickName;
1717
- let queryCreateInfo =
1718
- window.$vueRoot.$store.getters.queryCreateInfo || "0";
1719
- if (nickName) {
1720
- if (queryCreateInfo == "1") {
1721
- _createBy = createBy + "(" + nickName + ")";
1722
- } else if (queryCreateInfo == "2") {
1723
- _createBy = nickName;
1724
- }
1725
- }
1726
- }
1727
- this.$set(this.attachmentDTO, "_createBy", _createBy);
1728
- },
1729
- });
1730
- },
1731
- initTableM1() {
1732
- //明细
1733
- var that = this;
1734
- const tableRef = "table-m1";
1735
- const tableOption = {
1736
- vue: this,
1737
- tableRef: tableRef,
1738
- tableName: "components_vabUpload_propertiesDialog_list-m1",
1739
- columns: [
1740
- {
1741
- type: "checkbox",
1742
- fixed: "left",
1743
- width: 48,
1744
- resizable: false,
1745
- },
1746
- {
1747
- title: this.$t2("属性名称", "components.VabUpload.attributeName"),
1748
- field: "attributeName",
1749
- width: 200,
1750
- slots: {
1751
- default: "attributeName",
1752
- },
1753
- },
1754
- {
1755
- title: this.$t2("属性值", "components.VabUpload.attributeValue"),
1756
- field: "attributeValue",
1757
- width: 200,
1758
- slots: {
1759
- default: "attributeValue",
1760
- },
1761
- },
1762
- {
1763
- width: 50,
1764
- fixed: "right",
1765
- title: "",
1766
- sortable: false,
1767
- slots: {
1768
- default: "operate",
1769
- },
1770
- },
1771
- ],
1772
- };
1773
- this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
1774
- this.vxeOption = opts;
1775
- });
1776
- this.getData();
1777
- },
1778
- addItem() {
1779
- this.attachmentDTO.attachmentAttributeDTOs.push({});
1780
- },
1781
- formatFileSize(fileSize) {
1782
- return formatFileSize(fileSize);
1783
- },
1784
- },
1785
- };
1786
-
1787
- function getFileServerInfo(that, callback) {
1788
- that.$http({
1789
- url: USER_PREFIX + "/logic_param/getFileServerInfo",
1790
- method: "post",
1791
- data: {},
1792
- failMsg: false,
1793
- errorMsg: false,
1794
- modal: false,
1795
- success: (res) => {
1796
- if (res.objx) {
1797
- callback && callback(res.objx);
1798
- } else {
1799
- callback && callback();
1800
- }
1801
- },
1802
- error: (err) => {
1803
- callback && callback();
1804
- },
1805
- });
1806
- }
1807
-
1808
- function formatFileSize(fileSize) {
1809
- fileSize = fileSize || 0;
1810
- if (fileSize < 1024) {
1811
- return fileSize + "B";
1812
- } else if (fileSize < 1024 * 1024) {
1813
- var temp = fileSize / 1024;
1814
- temp = temp.toFixed(2);
1815
- return temp + "KB";
1816
- } else if (fileSize < 1024 * 1024 * 1024) {
1817
- var temp = fileSize / (1024 * 1024);
1818
- temp = temp.toFixed(2);
1819
- return temp + "MB";
1820
- } else {
1821
- var temp = fileSize / (1024 * 1024 * 1024);
1822
- temp = temp.toFixed(2);
1823
- return temp + "GB";
1824
- }
1825
- }
1826
-
1827
- export const mixins = tmixins;
1828
- export const viewMixins = tViewMixins;
1829
- export const propertiesMixins = pmixins;
1
+ /**version-1.0*/
2
+ let tmixins, tViewMixins, pmixins;
3
+ import axios from "axios";
4
+ import SparkMD5 from "spark-md5";
5
+ import settingConfig from "@/settings.js";
6
+
7
+ let imFun = {
8
+ axios,
9
+ SparkMD5,
10
+ };
11
+
12
+ tmixins = {
13
+ name: "VabUpload",
14
+ props: {
15
+ auto: {
16
+ type: Boolean,
17
+ default: true,
18
+ },
19
+ url: {
20
+ type: String,
21
+ default: "/upload",
22
+ },
23
+ name: {
24
+ type: String,
25
+ default: "file",
26
+ },
27
+ limit: {
28
+ type: Number,
29
+ default: () => 100000,
30
+ },
31
+ /* 单个文件大小限制(MB),0 表示不限制 */
32
+ size: {
33
+ type: Number,
34
+ default: () => {
35
+ return settingConfig.uploadFileSize ?? 200;
36
+ },
37
+ },
38
+ accept: {
39
+ type: String,
40
+ default: "file",
41
+ },
42
+ /* 允许上传的文件格式,数组或逗号分隔字符串,如 ['doc','xlsx'] / 'doc,xlsx';为空表示不限制 */
43
+ fileTypes: {
44
+ type: [Array, String],
45
+ default: () => [],
46
+ },
47
+ chunkSize: {
48
+ type: Number,
49
+ default: 5, //5MB
50
+ },
51
+ confirmUpload: {
52
+ type: Function,
53
+ },
54
+ pickPrivateProfile: {
55
+ type: Boolean,
56
+ default: true,
57
+ },
58
+ multi: {
59
+ type: [String, Boolean],
60
+ default: true,
61
+ },
62
+ uploadingLimit: {
63
+ type: Number,
64
+ default: 5, //5MB
65
+ },
66
+ isPartUpload: {
67
+ type: Boolean,
68
+ default: () => {
69
+ return settingConfig.isPartUpload ?? true;
70
+ },
71
+ },
72
+ autoConfirmAfterUpload: {
73
+ type: Boolean,
74
+ default: false,
75
+ },
76
+ showFileLibraryButton: Boolean,
77
+ storeAreaPrefix: String,
78
+ storeAreaCode: String,
79
+ },
80
+ data() {
81
+ return {
82
+ fileLibraryName: null,
83
+ show: false,
84
+ loading: false,
85
+ dialogVisible: false,
86
+ dialogImageUrl: "",
87
+ action: "",
88
+ headers: {},
89
+ fileList: [],
90
+ picture: "picture",
91
+ allImgNum: 0,
92
+ imgNum: 0,
93
+ imgSuccessNum: 0,
94
+ imgErrorNum: 0,
95
+ typeList: null,
96
+ title: this.$t2("上传", "components.VabUpload.title"),
97
+ dialogFormVisible: false,
98
+ data: {},
99
+ fileViewDialogVisible: false,
100
+ fileViewInfo: {},
101
+ total: 0,
102
+ video: null,
103
+ btn: false,
104
+ filePartMap: {},
105
+ uploading: false,
106
+ hasReadyFile: false,
107
+ showLocalUploadBtn: false,
108
+ showPrivateUploadBtn: false,
109
+ showPrivateProfileDialog: false,
110
+ pasteList: [],
111
+ pasteAreaStatus: false,
112
+ option: {},
113
+ editFileIndex: -1,
114
+ showFileNameDialog: false,
115
+ editFileName: null,
116
+ editFileSuffix: null,
117
+ beforeUploadFlag: false,
118
+ uploadUrl: null,
119
+ };
120
+ },
121
+ beforeDestroy() {
122
+ this.removePasteEvent();
123
+ },
124
+ filters: {
125
+ btnText(btn) {
126
+ return btn
127
+ ? this.$t2("继续", "components.VabUpload.continue")
128
+ : this.$t2("暂停", "components.VabUpload.pause");
129
+ },
130
+ totalText(total) {
131
+ return total > 100 ? 100 : total;
132
+ },
133
+ },
134
+ computed: {
135
+ percentage() {
136
+ if (this.allImgNum == 0) return 0;
137
+ return ((this.imgNum / this.allImgNum, 2) * 100).toFixed(0);
138
+ },
139
+ fileMaxSize() {
140
+ return this.formatFileSize(this.size * 1024 * 1024);
141
+ },
142
+ errorQuantity() {
143
+ return this.fileList.filter((file) => file.status == "fail").length;
144
+ },
145
+ totalQuantity() {
146
+ return this.fileList.length;
147
+ },
148
+ successQuantity() {
149
+ return this.fileList.filter((file) => file.status == "success").length;
150
+ },
151
+ isMulti: function () {
152
+ let isMulti = true;
153
+ if (this.multi === "false" || this.multi === false || this.limit === 1) {
154
+ isMulti = false;
155
+ }
156
+ return isMulti;
157
+ },
158
+ /* 允许上传的文件后缀(小写、去掉点号),为空数组表示不限制 */
159
+ allowedFileTypes() {
160
+ let types = this.fileTypes;
161
+ if (typeof types === "string") {
162
+ types = types.split(",");
163
+ }
164
+ if (!Array.isArray(types)) {
165
+ return [];
166
+ }
167
+ return types
168
+ .map((type) => String(type).trim().replace(/^\./, "").toLowerCase())
169
+ .filter((type) => !!type);
170
+ },
171
+ /* 限制了上传格式时用后缀列表覆盖 accept,未限制则沿用外部传入的 accept */
172
+ uploadAccept() {
173
+ let types = this.allowedFileTypes;
174
+ if (!types.length) {
175
+ return this.accept;
176
+ }
177
+ return types.map((type) => "." + type).join(",");
178
+ },
179
+ allowedFileTypesText() {
180
+ return this.allowedFileTypes.join("、");
181
+ },
182
+ },
183
+ methods: {
184
+ /* 校验文件后缀是否在允许的上传格式内,未配置格式时一律通过 */
185
+ checkFileType(file) {
186
+ let types = this.allowedFileTypes;
187
+ if (!types.length) {
188
+ return true;
189
+ }
190
+ let suffix = this.$commonFileUtil.getFileSuffix(file.name || "");
191
+ return types.indexOf(suffix) > -1;
192
+ },
193
+ showFileTypeError(fileName) {
194
+ this.$message({
195
+ message: this.$t2(
196
+ "文件[" + fileName + "]格式不支持,仅允许" + this.allowedFileTypesText,
197
+ "components.VabUpload.warnMsg4",
198
+ {
199
+ fileName: fileName,
200
+ fileTypes: this.allowedFileTypesText,
201
+ }
202
+ ),
203
+ type: "error",
204
+ duration: 3 * 1000,
205
+ });
206
+ },
207
+ openFileLibraryDialog() {
208
+ this.$openFileLibraryDialog({
209
+ prefix: this.storeAreaPrefix,
210
+ storeAreaCode: this.storeAreaCode,
211
+ callback: ({ rows, fileRows }) => {
212
+ this.addFileLibraryFiles(rows);
213
+ },
214
+ });
215
+ },
216
+ initFileLibraryTitle() {
217
+ this.fileLibraryName = null;
218
+ this.$http({
219
+ method: "post",
220
+ url: USER_PREFIX + "/file_store_area/getByCode",
221
+ data: {
222
+ stringOne: this.storeAreaCode,
223
+ },
224
+ isLoading: true,
225
+ success: (res) => {
226
+ let fileStoreArea = res.objx;
227
+ if (fileStoreArea) {
228
+ this.fileLibraryName = fileStoreArea.storeAreaName;
229
+ }
230
+ },
231
+ });
232
+ },
233
+ updateUploadingStatus() {
234
+ var target = this.$refs.upload;
235
+ let uploading, hasReadyFile;
236
+ if (target) {
237
+ var fileList = target.uploadFiles;
238
+ let n = fileList.find((item) => {
239
+ // return item.percentage != 100;
240
+ return item.status == "uploading" || item.status == "preUpload";
241
+ });
242
+ uploading = n == null ? false : true;
243
+
244
+ let readyFiles = fileList.filter((file) => file.status == "ready");
245
+ hasReadyFile = readyFiles.length > 0;
246
+ } else {
247
+ uploading = false;
248
+ hasReadyFile = false;
249
+ }
250
+
251
+ this.uploading = uploading;
252
+ this.hasReadyFile = hasReadyFile;
253
+ this.checkPreUploadList();
254
+ return uploading;
255
+ },
256
+ submitUpload() {
257
+ let successDone = () => {
258
+ this.$refs.upload.submit();
259
+ };
260
+ var files = this.$refs.upload.uploadFiles;
261
+ let readyFiles = files.filter((file) => file.status == "ready");
262
+ if (this.confirmUpload) {
263
+ if (readyFiles.length) {
264
+ this.confirmUpload({
265
+ files: files,
266
+ done: successDone,
267
+ });
268
+ }
269
+ } else {
270
+ successDone();
271
+ }
272
+ },
273
+ handleProgress(event, file, fileList) {
274
+ // this.loading = true
275
+ // this.show = true
276
+ },
277
+ handleChange(file, fileList) {
278
+ /* 格式校验只针对仍在列表中的文件,removeFile 移除后也会回调本方法,不能重复报错 */
279
+ if (fileList.indexOf(file) > -1 && !this.checkFileType(file)) {
280
+ fileList.splice(fileList.indexOf(file), 1);
281
+ this.fileList = fileList;
282
+ this.showFileTypeError(file.name);
283
+ if (file.raw) {
284
+ file.raw.status = "fail";
285
+ }
286
+ return false;
287
+ }
288
+ /* size 为 0(或未配置限制)时不做大小校验 */
289
+ let maxSize = this.size * 1024 * 1024;
290
+ if (maxSize > 0 && file.size > maxSize) {
291
+ fileList.map((item, index) => {
292
+ if (item === file) {
293
+ fileList.splice(index, 1);
294
+ }
295
+ });
296
+ this.fileList = fileList;
297
+ let errorText =
298
+ "文件[" + file.name + "]大小超出限制" + this.fileMaxSize;
299
+ this.$message({
300
+ message: this.$t2(errorText, "components.VabUpload.warnMsg1", {
301
+ fileName: file.name,
302
+ fileMaxSize: this.fileMaxSize,
303
+ }),
304
+ type: "error",
305
+ duration: 3 * 1000,
306
+ });
307
+ file.raw.status = "fail";
308
+ return false;
309
+ } else {
310
+ this.fileList = fileList;
311
+ this.allImgNum = fileList.length;
312
+ }
313
+ this.updateUploadingStatus();
314
+ },
315
+ handleSuccess(response, file, fileList) {
316
+ if (file.percentage == 100) {
317
+ this.imgNum = this.imgNum + 1;
318
+ this.imgSuccessNum = this.imgSuccessNum + 1;
319
+ }
320
+ if (fileList.length === this.imgNum) {
321
+ this.fileList = fileList;
322
+
323
+ // 添加自动确认功能
324
+ // 当所有文件上传完成且 autoConfirmAfterUpload 为 true 时,自动调用 submitImage 方法
325
+ if (this.autoConfirmAfterUpload) {
326
+ // 使用 nextTick 确保所有文件状态已更新
327
+ this.$nextTick(() => {
328
+ this.submitImage();
329
+ });
330
+ return; // 自动确认后直接返回,不执行后续的 setTimeout
331
+ }
332
+ }
333
+
334
+ setTimeout(() => {
335
+ this.loading = false;
336
+ this.show = false;
337
+ }, 1000);
338
+ this.updateUploadingStatus();
339
+ },
340
+ handleError(err, file, fileList) {
341
+ this.imgNum = this.imgNum + 1;
342
+ this.imgErrorNum = this.imgErrorNum + 1;
343
+ setTimeout(() => {
344
+ this.loading = false;
345
+ this.show = false;
346
+ }, 1000);
347
+ this.updateUploadingStatus();
348
+ },
349
+ handleRemove(file, fileList) {
350
+ this.imgNum = this.imgNum - 1;
351
+ this.allNum = this.allNum - 1;
352
+ this.updateUploadingStatus();
353
+ },
354
+ handlePreview(file) {
355
+ this.dialogImageUrl = file.url;
356
+ this.dialogVisible = true;
357
+ },
358
+ handleExceed(files, fileList) {
359
+ let errorMsg = `当前限制选择 ${this.limit} 个文件,本次选择了
360
+ ${files.length}
361
+ 个文件`;
362
+ this.$message({
363
+ message: this.$t2(errorMsg, "components.VabUpload.warnMsg2", {
364
+ limit: this.limit,
365
+ size: files.length,
366
+ }),
367
+ type: "error",
368
+ duration: 5 * 1000,
369
+ });
370
+ },
371
+ handleShow(option) {
372
+ this.title = this.$t2("上传", "components.VabUpload.title");
373
+ // this.data = data;
374
+ this.option = option;
375
+ this.clearFileInfo();
376
+ this.initPickUploadMode();
377
+ this.pasteAreaStatus = false;
378
+ this.dialogFormVisible = true;
379
+ /*document.removeEventListener('paste', this.pasteEvent);
380
+ document.addEventListener('paste', this.pasteEvent);*/
381
+
382
+ this.removePasteEvent();
383
+ this.addPasteEvent();
384
+ this.initFileLibraryTitle();
385
+ if (!option.files?.length) {
386
+ this.initUploadUrl();
387
+ } else {
388
+ this.initUploadUrl(() => {
389
+ this.handleUpload(option.files);
390
+ });
391
+ }
392
+ },
393
+ handleUpload(fileRawList) {
394
+ let target = this.$refs.upload;
395
+ let innerTarget = target.$refs["upload-inner"];
396
+ if (fileRawList.length) {
397
+ innerTarget.uploadFiles(fileRawList);
398
+ }
399
+ },
400
+ addPasteEvent() {
401
+ document.addEventListener("click", this.blurPasteEvent);
402
+ document.addEventListener("paste", this.pasteEvent);
403
+ /* if(this.option.copy){
404
+
405
+ } */
406
+ },
407
+ removePasteEvent() {
408
+ document.removeEventListener("click", this.blurPasteEvent);
409
+ document.removeEventListener("paste", this.pasteEvent);
410
+ },
411
+ blurPasteEvent() {
412
+ this.pasteAreaStatus = false;
413
+ },
414
+ handleClose() {
415
+ let target = this.$refs.upload;
416
+ (target.uploadFiles || []).forEach((uploadFile) => {
417
+ if (uploadFile.status == "uploading" || uploadFile.status == "ready") {
418
+ uploadFile.raw.abort &&
419
+ uploadFile.raw.abort(
420
+ this.$t2("取消上传", "components.VabUpload.cancelUpload")
421
+ );
422
+ }
423
+ });
424
+ this.picture = "picture";
425
+ this.clearFileInfo();
426
+ this.dialogFormVisible = false;
427
+ },
428
+ clearFileInfo() {
429
+ this.fileList = [];
430
+ this.allImgNum = 0;
431
+ this.imgNum = 0;
432
+ this.imgSuccessNum = 0;
433
+ this.imgErrorNum = 0;
434
+ },
435
+ initUploadUrl(callback) {
436
+ let mineUploadUrl = window.BASE_FILEURL;
437
+ return this.$http({
438
+ url: mineUploadUrl,
439
+ method: "post",
440
+ data: {
441
+ isAuth: false,
442
+ },
443
+ success: (res) => {
444
+ this.uploadUrl = res.objx;
445
+ callback && callback();
446
+ },
447
+ });
448
+ },
449
+ handleBeforeUpload(file, checkFile, callback) {
450
+ /*if (checkFile !== false) {
451
+ let target = this.$refs.upload;
452
+ let nFile = target.getFile(file);
453
+ if (!nFile) {
454
+ return false;
455
+ }
456
+ }
457
+ let mineUploadUrl = window.BASE_FILEURL;
458
+ return await this.$http({
459
+ url: mineUploadUrl,
460
+ method: 'post',
461
+ data: {
462
+ isAuth: false
463
+ },
464
+ success: res => {
465
+ this.uploadUrl = res.objx;
466
+ callback && callback()
467
+ }
468
+ });*/
469
+ callback && callback();
470
+ },
471
+ formatFileSize(fileSize) {
472
+ return formatFileSize(fileSize);
473
+ },
474
+ //自定义上传
475
+ async uploadSectionFile(param, isCustom, uploadConfig) {
476
+ if (!this.uploadUrl) {
477
+ await this.initUploadUrl();
478
+ }
479
+ let that = this;
480
+ var fileObj = param.file;
481
+
482
+ let source;
483
+
484
+ var form = new FormData();
485
+ // 文件对象
486
+ form.append("file", fileObj);
487
+
488
+ let target = that.$refs.upload;
489
+ let file = target ? target.getFile(fileObj) : null;
490
+ if (file) {
491
+ file.status = "uploading";
492
+ }
493
+
494
+ let isLoading = uploadConfig?.isLoading === true;
495
+ var uploadUrl = this.uploadUrl;
496
+ if (uploadUrl) {
497
+ var abort;
498
+ let config = {
499
+ isLoading: isLoading,
500
+ headers: {
501
+ "Content-Type": "multipart/form-data",
502
+ },
503
+ cancelToken: new imFun.axios.CancelToken(function executor(c) {
504
+ if (!isCustom) {
505
+ abort = c;
506
+ if (file) file.abort = c;
507
+ }
508
+ }),
509
+ onUploadProgress: (progressEvent) => {
510
+ if (isCustom || file) {
511
+ // progressEvent.loaded:已上传文件大小
512
+ // progressEvent.total:被上传文件的总大小
513
+ progressEvent.percent = Math.floor(
514
+ (progressEvent.loaded * 100) / progressEvent.total
515
+ );
516
+ if (!isCustom) {
517
+ param.onProgress(progressEvent, fileObj);
518
+ }
519
+ uploadConfig &&
520
+ uploadConfig.onProgress &&
521
+ uploadConfig.onProgress(progressEvent, fileObj);
522
+ }
523
+ },
524
+ failMsg: false,
525
+ }; //添加请求头
526
+
527
+ let req = this.$http
528
+ .post(uploadUrl, form, config)
529
+ .then((res1) => {
530
+ uploadConfig &&
531
+ uploadConfig.callback &&
532
+ uploadConfig.callback(res1, fileObj);
533
+ if (!isCustom) {
534
+ if (res1.type == "success") {
535
+ param.onSuccess(res1, fileObj);
536
+ } else {
537
+ // param.onError(new Error(res1.content || '上传异常'));
538
+ this.handleFileError(
539
+ new Error(
540
+ res1.content ||
541
+ this.$t2(
542
+ "上传异常",
543
+ "components.VabUpload.uploadException"
544
+ )
545
+ ),
546
+ fileObj
547
+ );
548
+ }
549
+ }
550
+ })
551
+ .catch((error, a, b, c) => {
552
+ // let {err} = error;
553
+ try {
554
+ // param.onError(err, fileObj);
555
+ if (!isCustom) {
556
+ this.handleFileError(error, fileObj);
557
+ }
558
+ uploadConfig &&
559
+ uploadConfig.error &&
560
+ uploadConfig.error(error, fileObj);
561
+ } catch (tt) {}
562
+ });
563
+ req.abort = () => {
564
+ abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
565
+ };
566
+ //return req;
567
+ }
568
+ },
569
+ singerUpload(uploadConfig) {
570
+ let onUploadProgress = uploadConfig.onUploadProgress;
571
+ let success = uploadConfig.success;
572
+ let file = uploadConfig.file;
573
+ this.handleBeforeUpload(file, false, () => {
574
+ this.uploadSectionFile(
575
+ {
576
+ file: file,
577
+ },
578
+ true,
579
+ uploadConfig
580
+ );
581
+ });
582
+ },
583
+ //begin
584
+ fileParse(file, type = "base64", callback) {
585
+ /*return new Promise(resolve => {
586
+
587
+ });*/
588
+ let fileRead = new FileReader();
589
+ if (type === "base64") {
590
+ fileRead.readAsDataURL(file);
591
+ } else if (type === "buffer") {
592
+ fileRead.readAsArrayBuffer(file);
593
+ }
594
+ fileRead.onload = (ev) => {
595
+ callback(ev.target.result);
596
+ // resolve(ev.target.result);
597
+ };
598
+ },
599
+ getFileMd5(file, callback) {
600
+ // 判断是否为大文件(例如大于10MB)
601
+ const isLargeFile = file.size > 20 * 1024 * 1024;
602
+
603
+ if (!isLargeFile) {
604
+ this.fileParse(file, "buffer", (buffer) => {
605
+ let spark = new imFun.SparkMD5.ArrayBuffer();
606
+ spark.append(buffer);
607
+ let hash = spark.end();
608
+ callback(hash);
609
+ });
610
+ } else {
611
+ this.calculateFileMD5(file, callback);
612
+ }
613
+ },
614
+ calculateFileMD5(file, callback) {
615
+ const chunkSize = 16 * 1024 * 1024; // 2MB一块
616
+ const chunks = Math.ceil(file.size / chunkSize);
617
+ let currentChunk = 0;
618
+ const spark = new imFun.SparkMD5.ArrayBuffer();
619
+ const fileReader = new FileReader();
620
+
621
+ // 处理读取错误
622
+ fileReader.onerror = function () {
623
+ console.error("文件读取错误");
624
+ callback(null);
625
+ };
626
+
627
+ // 处理进度回调(可选)
628
+ const onProgress = (progress) => {
629
+ // 可以在这里更新进度条
630
+ console.log("MD5计算进度: " + Math.round(progress * 100) + "%");
631
+ };
632
+
633
+ // 递归读取下一块
634
+ const loadNext = () => {
635
+ const start = currentChunk * chunkSize;
636
+ const end = Math.min(start + chunkSize, file.size);
637
+
638
+ fileReader.readAsArrayBuffer(file.slice(start, end));
639
+ };
640
+
641
+ // 每块读取完成后的处理
642
+ fileReader.onload = function (e) {
643
+ spark.append(e.target.result);
644
+ currentChunk++;
645
+
646
+ // 更新进度
647
+ // onProgress(currentChunk / chunks);
648
+
649
+ // 继续读取下一块或完成
650
+ if (currentChunk < chunks) {
651
+ loadNext();
652
+ } else {
653
+ // 所有块读取完成,计算最终MD5
654
+ const md5 = spark.end();
655
+ callback(md5);
656
+ }
657
+ };
658
+
659
+ // 开始处理
660
+ loadNext();
661
+ },
662
+ changeFile(param) {
663
+ if (!param.file || param.file.status == "fail") return;
664
+ let target = this.$refs.upload;
665
+ if (!target) return;
666
+ let fileObj = target.getFile(param.file);
667
+ fileObj.status = "preUpload";
668
+ fileObj.param = {
669
+ file: param.file,
670
+ onSuccess: param.onSuccess,
671
+ onProgress: param.onProgress,
672
+ onError: param.onError,
673
+ };
674
+ this.checkPreUploadList();
675
+ },
676
+ checkPreUploadList() {
677
+ let uploadingLimit = this.option.uploadingLimit || this.uploadingLimit;
678
+ let target = this.$refs.upload;
679
+ let fileList1 = (target.uploadFiles || []).filter((item) => {
680
+ return item.status == "preUpload";
681
+ });
682
+ let fileList2 = (target.uploadFiles || []).filter((item) => {
683
+ return item.status == "uploading";
684
+ });
685
+ if (fileList2.length < uploadingLimit && fileList1.length > 0) {
686
+ let num = uploadingLimit - fileList2.length;
687
+ if (num) {
688
+ let toNum = Math.min(fileList1.length, num);
689
+ for (let i = 0; i < toNum; i++) {
690
+ let fileRaw = fileList1[i].raw;
691
+ this.uploadFile(fileRaw);
692
+ }
693
+ }
694
+ }
695
+ },
696
+ async uploadFile(file) {
697
+ if (!file || file.status == "fail") return;
698
+ let target = this.$refs.upload;
699
+ if (!target) return;
700
+ let fileObj = target.getFile(file);
701
+ if (fileObj.status != "preUpload") return;
702
+ if (!this.isPartUpload) {
703
+ this.uploadSectionFile(fileObj.param);
704
+ return;
705
+ }
706
+
707
+ if (!this.uploadUrl) {
708
+ await this.initUploadUrl();
709
+ }
710
+ this.total = 0;
711
+ target.handleProgress({ percent: 0 }, file);
712
+
713
+ // 解析为BUFFER数据
714
+ // 我们会把文件切片处理:把一个文件分割成为好几个部分(固定数量/固定大小)
715
+ // 每一个切片有自己的部分数据和自己的名字
716
+ // HASH_1.mp4
717
+ // HASH_2.mp4
718
+ // ...
719
+
720
+ this.getFileMd5(file, (md5) => {
721
+ /* let spark = new imFun.SparkMD5.ArrayBuffer(),
722
+ chunkSize = this.chunkSize * 1024 * 1024, // Read in chunks of 2MB
723
+ chunks = Math.ceil(file.size / chunkSize),
724
+ hash,
725
+ suffix;
726
+ spark.append(buffer);
727
+ hash = spark.end(); */
728
+
729
+ let chunkSize = this.chunkSize * 1024 * 1024, // Read in chunks of 2MB
730
+ chunks = Math.ceil(file.size / chunkSize),
731
+ hash = md5,
732
+ suffix;
733
+
734
+ let nameSplit = /\.([0-9a-zA-Z]+)$/i.exec(file.name);
735
+
736
+ suffix = nameSplit && nameSplit.length > 1 ? nameSplit[1] : "";
737
+
738
+ let checkUrl = this.uploadUrl.replace(
739
+ "/docfile/upload",
740
+ "/docfile/check"
741
+ );
742
+ let checkData = {
743
+ name: file.name,
744
+ md5: hash,
745
+ };
746
+ let abort;
747
+ let checkReq = this.$http({
748
+ url: checkUrl,
749
+ method: "post",
750
+ cancelToken: new imFun.axios.CancelToken(function executor(c) {
751
+ abort = c;
752
+ file.abort = c;
753
+ }),
754
+ data: checkData,
755
+ failMsg: false,
756
+ modal: false,
757
+ callback: (res) => {
758
+ if (res.type == "success") {
759
+ let resData = res.objx || {};
760
+ let chunkParam = {
761
+ fullFile: file,
762
+ chunkSize: chunkSize,
763
+ chunks: chunks,
764
+ chunkIndex: 0,
765
+ md5: hash,
766
+ uuid: resData.uuid,
767
+ };
768
+ file.chunkParam = chunkParam;
769
+
770
+ this.sendRequest(file);
771
+ } else {
772
+ this.handleFileError(
773
+ new Error(
774
+ res.content ||
775
+ this.$t2("上传异常", "components.VabUpload.uploadException")
776
+ ),
777
+ file
778
+ );
779
+ }
780
+ },
781
+ error: (e) => {
782
+ this.handleFileError(e, file);
783
+ },
784
+ });
785
+ checkReq.abort = () => {
786
+ abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
787
+ };
788
+ });
789
+ },
790
+ async sendRequest(fullFile) {
791
+ let that = this;
792
+ let uploadUrl = this.uploadUrl;
793
+ let chunkParam = fullFile.chunkParam;
794
+ let target = that.$refs.upload;
795
+ let abort;
796
+ let config = {
797
+ headers: {
798
+ "Content-Type": "multipart/form-data",
799
+ },
800
+ cancelToken: new imFun.axios.CancelToken(function executor(c) {
801
+ /* let target = that.$refs.upload;
802
+ let filem = target.getFile(file);
803
+ abort = c;
804
+ filem.abort = c; */
805
+ abort = c;
806
+ fullFile.abort = c;
807
+ }),
808
+ onUploadProgress: (progressEvent) => {
809
+ if (!target || !fullFile) return;
810
+ let file = target.getFile(fullFile);
811
+ if (file) {
812
+ // progressEvent.loaded:已上传文件大小
813
+ // progressEvent.total:被上传文件的总大小
814
+ let start = chunkParam.start;
815
+ let uploadedSize =
816
+ start +
817
+ Math.floor(
818
+ (chunkParam.currentSize * progressEvent.loaded) /
819
+ progressEvent.total
820
+ );
821
+ let percent = Math.floor((uploadedSize * 100) / fullFile.size);
822
+ if (percent == 100) {
823
+ percent = 99;
824
+ }
825
+ progressEvent.percent = percent;
826
+ target.handleProgress(progressEvent, fullFile);
827
+ }
828
+ },
829
+ failMsg: false,
830
+ modal: false,
831
+ }; //添加请求头
832
+
833
+ let chunkIndex = chunkParam.chunkIndex;
834
+ let chunkSize = chunkParam.chunkSize;
835
+ var start = chunkIndex * chunkSize,
836
+ end =
837
+ start + chunkSize >= fullFile.size
838
+ ? fullFile.size
839
+ : start + chunkParam.chunkSize;
840
+ chunkParam.currentSize = end - start;
841
+ chunkParam.start = start;
842
+ chunkParam.end = end;
843
+
844
+ let preFormData = {
845
+ file: fullFile.slice(start, end),
846
+ name: fullFile.name,
847
+ chunks: chunkParam.chunks,
848
+ chunk: chunkIndex,
849
+ md5: chunkParam.md5,
850
+ uuid: chunkParam.uuid,
851
+ fileSize: fullFile.size,
852
+ };
853
+
854
+ let formData = new FormData();
855
+ Object.keys(preFormData).forEach((key) => {
856
+ formData.append(key, preFormData[key]);
857
+ });
858
+
859
+ let req = this.$http
860
+ .post(uploadUrl, formData, config)
861
+ .then((res1) => {
862
+ if (res1.type == "success") {
863
+ if (preFormData.chunk + 1 >= preFormData.chunks) {
864
+ let mergeData = {};
865
+ Object.keys(preFormData).forEach((key) => {
866
+ if (key != "file" && key != "chunk") {
867
+ mergeData[key] = preFormData[key];
868
+ }
869
+ });
870
+ let _param = {
871
+ mergeData: mergeData,
872
+ chunkParam: chunkParam,
873
+ };
874
+ this.mergeFile(_param);
875
+ } else {
876
+ chunkParam.chunkIndex = chunkParam.chunkIndex + 1;
877
+ this.sendRequest(fullFile);
878
+ }
879
+ } else {
880
+ this.handleFileError(
881
+ new Error(
882
+ res1.content ||
883
+ this.$t2("上传异常", "components.VabUpload.uploadException")
884
+ ),
885
+ fullFile
886
+ );
887
+ }
888
+ return res1;
889
+ })
890
+ .catch((err) => {
891
+ try {
892
+ if (!abort) {
893
+ this.handleFileError(err, fullFile);
894
+ }
895
+ } catch (tt) {}
896
+ });
897
+ req.abort = () => {
898
+ abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
899
+ };
900
+ },
901
+ mergeFile(param) {
902
+ let mergeData = param.mergeData;
903
+ let chunkParam = param.chunkParam;
904
+ let fullFile = chunkParam.fullFile;
905
+ let mergeUrl = this.uploadUrl.replace(
906
+ "/docfile/upload",
907
+ "/docfile/merge"
908
+ );
909
+ let target = this.$refs.upload;
910
+ this.$http({
911
+ url: mergeUrl,
912
+ method: "post",
913
+ data: mergeData,
914
+ failMsg: false,
915
+ modal: false,
916
+ cancelToken: new imFun.axios.CancelToken(function executor(c) {
917
+ if (fullFile) fullFile.abort = c;
918
+ }),
919
+ callback: (res) => {
920
+ if (!target || !fullFile) return;
921
+ if (res.type == "success") {
922
+ let file = target.getFile(fullFile);
923
+ if (file) {
924
+ target.handleProgress(
925
+ {
926
+ percent: 100,
927
+ },
928
+ fullFile
929
+ );
930
+ target.handleSuccess(res, fullFile);
931
+ }
932
+ } else {
933
+ this.handleFileError(
934
+ new Error(
935
+ res.content ||
936
+ this.$t2("上传异常", "components.VabUpload.uploadException")
937
+ ),
938
+ fullFile
939
+ );
940
+ }
941
+ },
942
+ error: (e) => {
943
+ if (!target || !fullFile) return;
944
+ if (fullFile) {
945
+ let file = target.getFile(fullFile);
946
+ if (file) {
947
+ this.handleFileError(e, fullFile);
948
+ }
949
+ }
950
+ },
951
+ });
952
+ },
953
+ handleBtn() {
954
+ let target = this.$refs.upload;
955
+ let fileList = (target.uploadFiles || []).filter((item) => {
956
+ return item.status == "uploading" || item.status == "ready";
957
+ });
958
+ if (this.btn) {
959
+ //断点续传
960
+ this.abort = false;
961
+ this.btn = false;
962
+ fileList.forEach((uploadFile) => {
963
+ let nextChunk = uploadFile.raw.nextChunk;
964
+ this.sendRequest(uploadFile.raw.partList, nextChunk);
965
+ });
966
+ } else {
967
+ //暂停上传
968
+ fileList.forEach((uploadFile) => {
969
+ uploadFile.raw.abort(
970
+ this.$t2("取消上传", "components.VabUpload.cancelUpload")
971
+ );
972
+ });
973
+ this.btn = true;
974
+ this.abort = true;
975
+ }
976
+ },
977
+ //end
978
+ getShowImage(file, fileName) {
979
+ fileName = fileName || file.name;
980
+ if (this.$commonFileUtil.isPictureFile(fileName)) {
981
+ return file.showUrl || file.url;
982
+ } else {
983
+ return this.$commonFileUtil.getFileIconRequire(fileName);
984
+ }
985
+ },
986
+ removeFile(sfile) {
987
+ var target = this.$refs.upload;
988
+ var index;
989
+ var fileList = target.uploadFiles;
990
+ for (let i = 0; i < fileList.length; i++) {
991
+ let file = fileList[i];
992
+ if (sfile.uid == file.uid) {
993
+ index = i;
994
+ if (sfile.status == "uploading") {
995
+ // file.status == 'delete'
996
+ //target.abort(file);
997
+ file.raw.abort &&
998
+ file.raw.abort(
999
+ this.$t2("取消上传", "components.VabUpload.cancelUpload")
1000
+ );
1001
+ }
1002
+ break;
1003
+ }
1004
+ }
1005
+
1006
+ target.uploadFiles.splice(index, 1);
1007
+ this.handleChange(sfile, target.uploadFiles);
1008
+ },
1009
+ submitImage() {
1010
+ var target = this.$refs.upload;
1011
+ var fileList = target.uploadFiles;
1012
+ let fileInfos = [];
1013
+ let fileDatas = [];
1014
+ for (let i = 0; i < fileList.length; i++) {
1015
+ let file = fileList[i];
1016
+ if (file.status == "uploading") {
1017
+ this.$message({
1018
+ message: this.$t2(
1019
+ "文件上传中",
1020
+ "components.VabUpload.fileUploading"
1021
+ ),
1022
+ type: "error",
1023
+ duration: 2000,
1024
+ });
1025
+ return;
1026
+ }
1027
+ if (file.status == "success") {
1028
+ let fileData = file.response.objx;
1029
+ fileData.name = file.name;
1030
+ let fileInfo = {
1031
+ name: file.name,
1032
+ fileData: fileData,
1033
+ file: file.raw,
1034
+ };
1035
+ fileInfos.push(fileInfo);
1036
+ fileDatas.push(fileData);
1037
+ }
1038
+ }
1039
+ this.handleClose();
1040
+ this.$emit("callback", fileInfos, fileDatas);
1041
+ this.callback && this.callback(fileDatas, fileInfos);
1042
+ },
1043
+ showViewDialog(lineData) {
1044
+ var data = lineData.fileData ? lineData.fileData : lineData;
1045
+
1046
+ let thumbnail = data ? data.thumbnail || "" : "";
1047
+
1048
+ var realUrl = data.domain + data.url;
1049
+ var showUrl = "";
1050
+ let fileName = lineData ? lineData.name || "" : "";
1051
+ if (!this.$commonFileUtil.isPictureFile(fileName)) {
1052
+ showUrl = this.$commonFileUtil.getFileIconRequire(fileName);
1053
+ } else if (thumbnail) {
1054
+ showUrl = data.domain + thumbnail;
1055
+ } else {
1056
+ showUrl = data.domain + data.url;
1057
+ }
1058
+
1059
+ var preName = "";
1060
+ var suffix = "";
1061
+ var i = fileName.lastIndexOf(".");
1062
+ if (i >= 0) {
1063
+ suffix = fileName.substring(i + 1, fileName.length).toLowerCase();
1064
+ }
1065
+ this.fileViewInfo = {
1066
+ realUrl: realUrl,
1067
+ showUrl: showUrl,
1068
+ fileName: fileName,
1069
+ suffix: suffix,
1070
+ data: data,
1071
+ };
1072
+ this.fileViewDialogVisible = true;
1073
+ },
1074
+ getShowUrl(attachment, field) {
1075
+ let showUrl = null;
1076
+ let typeStr = Object.prototype.toString.call(attachment);
1077
+ if (typeStr == "[object Object]") {
1078
+ let showField = field ? field : "medium";
1079
+ let fullUrl =
1080
+ attachment.domain +
1081
+ (attachment[showField] ? attachment[showField] : attachment.url);
1082
+ showUrl = this.$commonFileUtil.getShowUrl(fullUrl);
1083
+ } else {
1084
+ showUrl = this.$commonFileUtil.getShowUrl(attachment);
1085
+ }
1086
+ return showUrl;
1087
+ },
1088
+ addFileLibraryFiles(rows) {
1089
+ var target = this.$refs.upload;
1090
+ let uploadFiles = target.uploadFiles;
1091
+ let sourceSns = uploadFiles
1092
+ .filter((row) => {
1093
+ return !!(
1094
+ row.response &&
1095
+ row.response.objx &&
1096
+ row.response.objx.sourceSn
1097
+ );
1098
+ })
1099
+ .map((row) => row.response.objx.sourceSn);
1100
+
1101
+ let newFiles = rows
1102
+ .filter((row) => !row.dirs && !sourceSns.includes(row.sn))
1103
+ .filter((row) => {
1104
+ /* 文件库/个人文档选来的文件不走 el-upload,需在此处补做格式校验 */
1105
+ if (this.checkFileType({ name: row.fileName })) {
1106
+ return true;
1107
+ }
1108
+ this.showFileTypeError(row.fileName);
1109
+ return false;
1110
+ })
1111
+ .map((row) => {
1112
+ let item = {
1113
+ status: "success",
1114
+ name: row.fileName,
1115
+ size: row.fileSize,
1116
+ percentage: 100,
1117
+ uid: row.fileSn,
1118
+ raw: {
1119
+ lastModified: "",
1120
+ lastModifiedDate: new Date(),
1121
+ name: row.fileName,
1122
+ size: row.fileSize,
1123
+ type: "",
1124
+ uid: row.fileSn,
1125
+ webkitRelativePath: "",
1126
+ },
1127
+ response: {
1128
+ time: "",
1129
+ type: "success",
1130
+ objx: {
1131
+ thumbnail: row.thumbnail,
1132
+ extension: row.extension,
1133
+ large: row.large,
1134
+ fileSize: row.fileSize,
1135
+ domain: row.domain,
1136
+ source: row.source,
1137
+ medium: row.medium,
1138
+ url: row.url,
1139
+ sourceSn: row.sn,
1140
+
1141
+ attachCode: row.attachCode,
1142
+ docCategory: row.docCategory,
1143
+ drawingCode: row.drawingCode,
1144
+ version: row.version,
1145
+ rev: row.rev,
1146
+ },
1147
+ content: "success",
1148
+ rmid: null,
1149
+ },
1150
+ url: row.domain + row.url,
1151
+ showUrl: this.getShowUrl(row),
1152
+ };
1153
+ return item;
1154
+ });
1155
+ uploadFiles.push(...newFiles);
1156
+ },
1157
+ confirmPrivateProfileDialog(rows) {
1158
+ this.addFileLibraryFiles(rows);
1159
+ },
1160
+ initPrivateUploadBt() {
1161
+ if (settingConfig.privateProfileCode && this.pickPrivateProfile) {
1162
+ this.$http({
1163
+ url: USER_PREFIX + "/file_store_area/getByCode",
1164
+ method: "post",
1165
+ data: { stringOne: settingConfig.privateProfileCode },
1166
+ failMsg: false,
1167
+ errorMsg: false,
1168
+ success: (res) => {
1169
+ this.showPrivateUploadBtn = res.objx ? true : false;
1170
+ },
1171
+ });
1172
+ } else {
1173
+ this.showPrivateUploadBtn = false;
1174
+ }
1175
+ },
1176
+ initPickUploadMode() {
1177
+ this.showLocalUploadBtn = false;
1178
+ this.showPrivateUploadBtn = false;
1179
+ this.$http({
1180
+ url: USER_PREFIX + "/system_parameter/getByCode",
1181
+ method: "post",
1182
+ data: { code: "pickUploadMode" },
1183
+ success: (res) => {
1184
+ let value = !res.objx || !res.objx.value ? "2" : res.objx.value;
1185
+ if (value == "0") {
1186
+ //启用本地上传,个人文档上传
1187
+ if (this.option.showLocalUploadBtn !== false)
1188
+ this.showLocalUploadBtn = true;
1189
+ this.initPrivateUploadBt();
1190
+ } else if (value == "1") {
1191
+ //启用个人文档上传
1192
+ this.initPrivateUploadBt();
1193
+ } else if (value == "2") {
1194
+ //启用本地上传
1195
+ if (this.option.showLocalUploadBtn !== false)
1196
+ this.showLocalUploadBtn = true;
1197
+ }
1198
+ },
1199
+ });
1200
+ },
1201
+ pasteEvent(e) {
1202
+ // e.preventDefault();
1203
+ e.stopPropagation();
1204
+ if (!this.pasteAreaStatus) {
1205
+ return;
1206
+ }
1207
+ if (!(e.clipboardData && e.clipboardData.items)) {
1208
+ return;
1209
+ }
1210
+ let files = Array.from(e.clipboardData.files);
1211
+ let getFileSuffix = this.$commonFileUtil.getFileSuffix;
1212
+ if (files.length) {
1213
+ let fileList = files.map((rawFile) => {
1214
+ let name = rawFile.name;
1215
+ let index = name.lastIndexOf(".");
1216
+ let fileSuffix = getFileSuffix(name);
1217
+ let fileName =
1218
+ index >= 0 ? name.substring(0, index).toString() : name.toString();
1219
+ let file = {
1220
+ name: rawFile.name,
1221
+ size: rawFile.size,
1222
+ raw: rawFile,
1223
+ showUrl: URL.createObjectURL(rawFile),
1224
+ fileName: fileName,
1225
+ fileSuffix: fileSuffix,
1226
+ };
1227
+ return file;
1228
+ });
1229
+ this.pasteList.push(...fileList);
1230
+ }
1231
+ },
1232
+ deletePasteFile(index) {
1233
+ this.pasteList.splice(index, 1);
1234
+ },
1235
+ confirmPasteFile() {
1236
+ let target = this.$refs.upload;
1237
+ let innerTarget = target.$refs["upload-inner"];
1238
+ let pasteList = this.$baseLodash.cloneDeep(this.pasteList);
1239
+ let files = pasteList.map((item) => {
1240
+ let name = item.name;
1241
+ let fileRaw = item.raw;
1242
+ fileRaw.fileName = name;
1243
+ return fileRaw;
1244
+ });
1245
+ innerTarget.uploadFiles(files);
1246
+ this.$nextTick(() => {
1247
+ target.uploadFiles.forEach((uploadFile) => {
1248
+ let fileRaw = uploadFile.raw;
1249
+ if (fileRaw.fileName) {
1250
+ uploadFile.name = fileRaw.fileName;
1251
+ delete fileRaw.fileName;
1252
+ }
1253
+ });
1254
+ });
1255
+ this.pasteList = [];
1256
+ },
1257
+ changeFileName(file) {
1258
+ if (file.fileSuffix) {
1259
+ file.name = (file.fileName + "." + file.fileSuffix).toString();
1260
+ } else {
1261
+ file.name = file.fileName.toString();
1262
+ }
1263
+ },
1264
+ handleFileError(err, rawFile) {
1265
+ let target = this.$refs.upload;
1266
+ if (!target) return;
1267
+ const file = target.getFile(rawFile);
1268
+ const fileList = target.uploadFiles;
1269
+
1270
+ file.status = "fail";
1271
+ file.failMsg = err && err.message ? err.message : null;
1272
+
1273
+ // fileList.splice(fileList.indexOf(file), 1);
1274
+
1275
+ target.onError(err, file, target.uploadFiles);
1276
+ target.onChange(file, target.uploadFiles);
1277
+ this.updateUploadingStatus();
1278
+ },
1279
+ choosePasteArea(e) {
1280
+ e.stopPropagation();
1281
+ this.pasteAreaStatus = true;
1282
+ },
1283
+ openFileNameDialog(row, index) {
1284
+ this.editFileName = row.fileName?.toString();
1285
+ this.editFileSuffix = row.fileSuffix?.toString();
1286
+ this.editFileIndex = index;
1287
+ this.showFileNameDialog = true;
1288
+ },
1289
+ confirmFileNameDialog() {
1290
+ if (!this.editFileName) {
1291
+ this.$message({
1292
+ message: this.$t2("文件名不能为空", "components.VabUpload.warnMsg3"),
1293
+ type: "error",
1294
+ showClose: true,
1295
+ duration: 3000,
1296
+ });
1297
+ return;
1298
+ }
1299
+ let editFileIndex = this.editFileIndex;
1300
+ let file = this.pasteList[editFileIndex];
1301
+ file.fileName = this.editFileName.toString();
1302
+ file.name = (file.fileName + "." + file.fileSuffix).toString();
1303
+ this.showFileNameDialog = false;
1304
+ },
1305
+ },
1306
+ };
1307
+
1308
+ tViewMixins = {
1309
+ props: {
1310
+ resultType: String,
1311
+ dataType: String,
1312
+ callback: Function,
1313
+ file: {
1314
+ type: [Array, Object, String],
1315
+ },
1316
+ multi: {
1317
+ type: [String, Boolean],
1318
+ default: true,
1319
+ },
1320
+ auto: {
1321
+ type: Boolean,
1322
+ default: true,
1323
+ },
1324
+ limit: {
1325
+ type: Number,
1326
+ default: 100000,
1327
+ },
1328
+ /* 单个文件大小限制(MB),0 表示不限制 */
1329
+ size: {
1330
+ type: Number,
1331
+ default: () => {
1332
+ return settingConfig.uploadFileSize ?? 200;
1333
+ },
1334
+ },
1335
+ accept: {
1336
+ type: String,
1337
+ default: "file",
1338
+ },
1339
+ /* 允许上传的文件格式,数组或逗号分隔字符串,如 ['doc','xlsx'] / 'doc,xlsx';为空表示不限制 */
1340
+ fileTypes: {
1341
+ type: [Array, String],
1342
+ default: () => [],
1343
+ },
1344
+ chunkSize: {
1345
+ type: Number,
1346
+ default: 5, //5MB
1347
+ },
1348
+ confirmUpload: {
1349
+ type: Function,
1350
+ },
1351
+ pickPrivateProfile: {
1352
+ type: Boolean,
1353
+ default: true,
1354
+ },
1355
+ uploadingLimit: {
1356
+ type: Number,
1357
+ default: 5, //5MB
1358
+ },
1359
+ isPartUpload: {
1360
+ type: Boolean,
1361
+ default: () => {
1362
+ return settingConfig.isPartUpload ?? true;
1363
+ },
1364
+ },
1365
+ autoConfirmAfterPasteUpload: {
1366
+ type: Boolean,
1367
+ default: false,
1368
+ },
1369
+ },
1370
+ data() {
1371
+ return {
1372
+ attachments: [],
1373
+ pictureList: [],
1374
+ pictureDtoList: [],
1375
+ showPropertiesDialog: false,
1376
+ editAttachment: null,
1377
+ showViewer: false,
1378
+ chooseIndex: 0,
1379
+ fileServerInfo: {},
1380
+ model: null,
1381
+ };
1382
+ },
1383
+ computed: {
1384
+ fileServerPreviewEnabled() {
1385
+ return this.getFileServerPreviewEnabled();
1386
+ },
1387
+ fileShowImageEnabled() {
1388
+ return this.getFileShowImageEnabled();
1389
+ },
1390
+ fileMaxSize() {
1391
+ return this.size;
1392
+ },
1393
+ showUploadBtn: function () {
1394
+ if (!this.isMulti) {
1395
+ return this.attachments.length == 0;
1396
+ } else {
1397
+ return this.limit ? this.limit > this.attachments.length : true;
1398
+ }
1399
+ },
1400
+ isMulti: function () {
1401
+ let isMulti = true;
1402
+ if (this.multi === "false" || this.multi === false || this.limit === 1) {
1403
+ isMulti = false;
1404
+ }
1405
+ return isMulti;
1406
+ },
1407
+ },
1408
+ watch: {
1409
+ file(val) {
1410
+ this.initFile();
1411
+ },
1412
+ attachments(val) {
1413
+ let that = this;
1414
+ let pictureList = [];
1415
+ let pictureDtoList = [];
1416
+ if (val) {
1417
+ val.forEach((item) => {
1418
+ if (item) {
1419
+ let typeStr = Object.prototype.toString.call(item);
1420
+ if (
1421
+ typeStr == "[object Object]" &&
1422
+ Object.keys(this.file).length > 0
1423
+ ) {
1424
+ if (that.$commonFileUtil.isPictureFile(item.url)) {
1425
+ pictureList.push(item.domain + item.url);
1426
+ pictureDtoList.push(item);
1427
+ }
1428
+ } else {
1429
+ if (that.$commonFileUtil.isPictureFile(item)) {
1430
+ pictureList.push(item);
1431
+ pictureDtoList.push(item);
1432
+ }
1433
+ }
1434
+ }
1435
+ });
1436
+ }
1437
+ this.pictureList = pictureList;
1438
+ this.pictureDtoList = pictureDtoList;
1439
+ },
1440
+ },
1441
+ created() {
1442
+ this.initFileServerInfo();
1443
+ this.initFile();
1444
+ },
1445
+ methods: {
1446
+ pasteEvent(e) {
1447
+ e.stopPropagation();
1448
+ if (!(e.clipboardData && e.clipboardData.items)) {
1449
+ return;
1450
+ }
1451
+ let files = Array.from(e.clipboardData.files);
1452
+ if (files.length) {
1453
+ this.openUploadDialog(files, this.autoConfirmAfterPasteUpload);
1454
+ }
1455
+ },
1456
+ uploadEnterOver() {
1457
+ // if (this.isLoading) return;
1458
+ document.addEventListener("paste", this.pasteEvent);
1459
+ },
1460
+ uploadEnterLeave() {
1461
+ document.removeEventListener("paste", this.pasteEvent);
1462
+ },
1463
+ getFileServerPreviewEnabled() {
1464
+ let value =
1465
+ window.$vueRoot.$store.getters.fileServerInfo
1466
+ ?.fileServerPreviewEnabled ??
1467
+ settingConfig.fileServerPreviewEnabled ??
1468
+ true;
1469
+ if (
1470
+ this.$attrs.fileServerPreviewEnabled !== null &&
1471
+ this.$attrs.fileServerPreviewEnabled !== undefined
1472
+ ) {
1473
+ value = this.$attrs.fileServerPreviewEnabled;
1474
+ }
1475
+ return value;
1476
+ },
1477
+ getFileShowImageEnabled() {
1478
+ let value =
1479
+ window.$vueRoot.$store.getters.fileServerInfo?.fileShowImageEnabled ??
1480
+ settingConfig.fileShowImageEnabled ??
1481
+ true;
1482
+ if (
1483
+ this.$attrs.fileShowImageEnabled !== null &&
1484
+ this.$attrs.fileShowImageEnabled !== undefined
1485
+ ) {
1486
+ value = this.$attrs.fileShowImageEnabled;
1487
+ }
1488
+ return value;
1489
+ },
1490
+ openUploadDialog(files, autoConfirmAfterUpload) {
1491
+ this.$baseUpload.open({
1492
+ files,
1493
+ autoConfirmAfterUpload,
1494
+ ...this.fileServerInfo,
1495
+ ...this._props,
1496
+ ...this.$attrs,
1497
+ limit: this.limit,
1498
+ multi: this.multi,
1499
+ accept: this.accept ? this.accept : "file",
1500
+ fileTypes: this.fileTypes,
1501
+ auto: this.auto,
1502
+ size: this.fileMaxSize,
1503
+ chunkSize: this.chunkSize,
1504
+ callback: this.fileConfirm,
1505
+ pickPrivateProfile: this.pickPrivateProfile,
1506
+ confirmUpload: this.confirmUpload,
1507
+ otherParams: this.$attrs,
1508
+ });
1509
+ },
1510
+ initFileServerInfo() {
1511
+ if (this.$attrs.model) {
1512
+ this.model = this.$attrs.model;
1513
+ // this.fileServerInfo = this.$attrs.fileServerInfo;
1514
+ } else {
1515
+ this.model =
1516
+ window.$vueRoot.$store.getters.fileServerInfo?.model ?? null;
1517
+ /* getFileServerInfo(this, (res) => {
1518
+ if (res) {
1519
+ let fileServerInfo = res;
1520
+ this.model = fileServerInfo.model
1521
+ this.fileServerInfo = fileServerInfo;
1522
+ }else{
1523
+ this.model = null;
1524
+ this.fileServerInfo = null;
1525
+ }
1526
+ }) */
1527
+ }
1528
+ },
1529
+ initFile() {
1530
+ if (this.file) {
1531
+ let typeStr = Object.prototype.toString.call(this.file);
1532
+ if (!this.dataType) {
1533
+ if (typeStr == "[object Array]") {
1534
+ this.attachments = this.file;
1535
+ } else if (
1536
+ typeStr == "[object Object]" &&
1537
+ Object.keys(this.file).length > 0
1538
+ ) {
1539
+ this.attachments = [this.file];
1540
+ } else {
1541
+ this.attachments = [];
1542
+ }
1543
+ } else {
1544
+ this.attachments = [this.file];
1545
+ }
1546
+ } else {
1547
+ this.attachments = [];
1548
+ }
1549
+ },
1550
+ deleteFile(index) {
1551
+ if (!this.$listeners.delete || this.$listeners.delete(index) !== false) {
1552
+ this.attachments.splice(index, 1);
1553
+ this.updatePropFile();
1554
+ this.$emit("afterDelete", this.attachments);
1555
+ }
1556
+ },
1557
+ fileConfirm(rows, fileInfos) {
1558
+ if (rows.length > 0) {
1559
+ if (this.isMulti) {
1560
+ let limit = this.limit;
1561
+ if (limit) {
1562
+ let oSize = this.file?.length ?? 0;
1563
+ let vailSize = limit - oSize;
1564
+ if (vailSize > 0) {
1565
+ rows = rows.length < vailSize ? rows : rows.slice(0, vailSize);
1566
+ } else {
1567
+ rows = [];
1568
+ }
1569
+ }
1570
+ } else {
1571
+ rows = [rows[0]];
1572
+ }
1573
+
1574
+ let attachments = this.attachments;
1575
+ let dataType = this.dataType;
1576
+ let eRows = [];
1577
+ if (dataType != null) {
1578
+ eRows = rows.map((row) => {
1579
+ return row.domain + (row[dataType] || row["url"]);
1580
+ });
1581
+ } else {
1582
+ eRows = rows;
1583
+ }
1584
+
1585
+ if (
1586
+ !this.$listeners.confirm ||
1587
+ this.$listeners.confirm(eRows, fileInfos) !== false
1588
+ ) {
1589
+ if (this.isMulti) {
1590
+ this.attachments = attachments.concat(eRows);
1591
+ } else {
1592
+ this.attachments = eRows;
1593
+ }
1594
+ this.updatePropFile();
1595
+ this.$emit("callback", eRows, fileInfos);
1596
+ }
1597
+ }
1598
+ },
1599
+ updatePropFile() {
1600
+ if (this.isMulti) {
1601
+ this.$emit("update:file", this.attachments);
1602
+ } else {
1603
+ let result =
1604
+ this.attachments && this.attachments.length
1605
+ ? this.attachments[0]
1606
+ : null;
1607
+ if (
1608
+ this.resultType == "Array" ||
1609
+ (this.multi !== "false" && this.multi !== false)
1610
+ ) {
1611
+ result = result ? [result] : [];
1612
+ }
1613
+ this.$emit("update:file", result);
1614
+ }
1615
+ this.handleChange();
1616
+ },
1617
+ handleChange() {
1618
+ this.$emit("change", this.attachments);
1619
+ },
1620
+ getRealPictureList(index) {
1621
+ let pictureIndex = -1;
1622
+ this.attachments.find((item, i) => {
1623
+ let typeStr = Object.prototype.toString.call(item);
1624
+ if (typeStr == "[object Object]") {
1625
+ if (this.$commonFileUtil.isPictureFile(item.url)) {
1626
+ pictureIndex++;
1627
+ }
1628
+ } else {
1629
+ if (this.$commonFileUtil.isPictureFile(item)) {
1630
+ pictureIndex++;
1631
+ }
1632
+ }
1633
+ return index == i;
1634
+ });
1635
+ return this.pictureList
1636
+ .slice(pictureIndex)
1637
+ .concat(this.pictureList.slice(0, pictureIndex));
1638
+ },
1639
+ getRealPictureDTOList() {
1640
+ let index = this.chooseIndex || 0;
1641
+ let pictureIndex = -1;
1642
+ this.attachments.find((item, i) => {
1643
+ let typeStr = Object.prototype.toString.call(item);
1644
+ if (typeStr == "[object Object]") {
1645
+ if (this.$commonFileUtil.isPictureFile(item.url)) {
1646
+ pictureIndex++;
1647
+ }
1648
+ } else {
1649
+ if (this.$commonFileUtil.isPictureFile(item)) {
1650
+ pictureIndex++;
1651
+ }
1652
+ }
1653
+ return index == i;
1654
+ });
1655
+ let res = this.pictureDtoList
1656
+ .slice(pictureIndex)
1657
+ .concat(this.pictureDtoList.slice(0, pictureIndex));
1658
+ return res;
1659
+ },
1660
+ openImagePreView(index) {
1661
+ // this.chooseIndex = index;
1662
+ let pictureIndex = -1;
1663
+ this.attachments.find((item, i) => {
1664
+ let typeStr = Object.prototype.toString.call(item);
1665
+ if (typeStr == "[object Object]") {
1666
+ if (this.$commonFileUtil.isPictureFile(item.url)) {
1667
+ pictureIndex++;
1668
+ }
1669
+ } else {
1670
+ if (this.$commonFileUtil.isPictureFile(item)) {
1671
+ pictureIndex++;
1672
+ }
1673
+ }
1674
+ return index == i;
1675
+ });
1676
+ this.chooseIndex = pictureIndex;
1677
+ this.showViewer = true;
1678
+ },
1679
+ openPropertiesDialog(attachment) {
1680
+ this.editAttachment = attachment;
1681
+ this.showPropertiesDialog = true;
1682
+ },
1683
+ closeViewer() {
1684
+ this.showViewer = false;
1685
+ },
1686
+ hasPreview(attachment) {
1687
+ let fileServerPreviewEnabled = this.getFileServerPreviewEnabled();
1688
+ let typeStr = Object.prototype.toString.call(attachment);
1689
+ let url =
1690
+ typeStr == "[object Object]"
1691
+ ? attachment.domain + attachment.url
1692
+ : attachment;
1693
+ if (fileServerPreviewEnabled) {
1694
+ return (
1695
+ this.$commonFileUtil.isPictureFile(url) ||
1696
+ this.$commonFileUtil.isPreviewFile(url)
1697
+ );
1698
+ } else {
1699
+ return this.$commonFileUtil.isPictureFile(url);
1700
+ }
1701
+ },
1702
+ openPreview(attachment, index) {
1703
+ let fileServerPreviewEnabled = this.getFileServerPreviewEnabled();
1704
+ let typeStr = Object.prototype.toString.call(attachment);
1705
+ let url =
1706
+ typeStr == "[object Object]"
1707
+ ? attachment.domain + attachment.url
1708
+ : attachment;
1709
+ if (this.$commonFileUtil.isPictureFile(url)) {
1710
+ this.openImagePreView(index);
1711
+ } else if (
1712
+ fileServerPreviewEnabled &&
1713
+ this.$commonFileUtil.isPreviewFile(url)
1714
+ ) {
1715
+ this.$openFilePreview(url);
1716
+ }
1717
+ },
1718
+ getAttachmentName(attachment) {
1719
+ let name = null;
1720
+ let typeStr = Object.prototype.toString.call(attachment);
1721
+ if (typeStr == "[object Object]") {
1722
+ name = attachment.name;
1723
+ } else {
1724
+ let url = attachment;
1725
+ if (url) {
1726
+ var i = url.lastIndexOf("/");
1727
+ if (i >= 0) {
1728
+ name = url.substring(i + 1, url.length);
1729
+ }
1730
+ }
1731
+ }
1732
+ return name;
1733
+ },
1734
+ getShowUrl(attachment, field) {
1735
+ let showUrl = null;
1736
+ let showImagePreview = this.getFileShowImageEnabled();
1737
+ let typeStr = Object.prototype.toString.call(attachment);
1738
+ if (typeStr == "[object Object]") {
1739
+ let showField = field ? field : "medium";
1740
+ let fullUrl =
1741
+ attachment.domain +
1742
+ (showImagePreview && attachment[showField]
1743
+ ? attachment[showField]
1744
+ : attachment.url);
1745
+ showUrl = this.$commonFileUtil.getShowUrl(fullUrl, showImagePreview);
1746
+ } else {
1747
+ showUrl = this.$commonFileUtil.getShowUrl(attachment, showImagePreview);
1748
+ }
1749
+ return showUrl;
1750
+ },
1751
+ downloadFile(attachment) {
1752
+ let typeStr = Object.prototype.toString.call(attachment);
1753
+ if (typeStr == "[object Object]") {
1754
+ this.$commonFileUtil.downloadFile(
1755
+ attachment.domain + attachment.url,
1756
+ attachment.name
1757
+ );
1758
+ } else {
1759
+ this.$commonFileUtil.downloadFile(attachment);
1760
+ }
1761
+ },
1762
+ formatFileSize(fileSize) {
1763
+ return formatFileSize(fileSize);
1764
+ },
1765
+ },
1766
+ };
1767
+
1768
+ pmixins = {
1769
+ name: "propertiesDialog",
1770
+ components: {},
1771
+ created() {
1772
+ this.attachmentDTO = this.$attrs.editAttachment;
1773
+ this.current_prefix =
1774
+ this.attachmentDTO && this.attachmentDTO.serverName
1775
+ ? "/" + this.attachmentDTO.serverName
1776
+ : "";
1777
+ },
1778
+ mounted() {
1779
+ this.initTableM1();
1780
+ },
1781
+ data() {
1782
+ return {
1783
+ showDialog: true,
1784
+ falseValue: false,
1785
+ vxeOption: {},
1786
+ showContent: true,
1787
+ attachmentDTO: {},
1788
+ current_prefix: "",
1789
+ };
1790
+ },
1791
+ methods: {
1792
+ saveData() {
1793
+ this.$refs.editForm.validate((valid) => {
1794
+ if (valid) {
1795
+ this.$baseConfirm(
1796
+ this.$t2("您确定要保存吗?", "components.VabUpload.saveTip")
1797
+ ).then(() => {
1798
+ let formData = commonDataUtil.handleForm(this.attachmentDTO);
1799
+
1800
+ var url = this.current_prefix + "/attachment/attribute/save";
1801
+ this.$http({
1802
+ url: url,
1803
+ method: "post",
1804
+ data: formData,
1805
+ isLoading: true,
1806
+ success: (res) => {
1807
+ this.$message({
1808
+ message: res.content,
1809
+ type: "success",
1810
+ duration: 500,
1811
+ onClose: (t) => {
1812
+ this.reloadContent();
1813
+ },
1814
+ });
1815
+ },
1816
+ });
1817
+ });
1818
+ }
1819
+ });
1820
+ },
1821
+ dialogClose() {
1822
+ this.$emit("update:visiable", false);
1823
+ },
1824
+ reloadContent() {
1825
+ this.getData();
1826
+ },
1827
+ getData() {
1828
+ this.$http({
1829
+ url: this.current_prefix + "/attachment/attribute/list",
1830
+ method: "post",
1831
+ data: {
1832
+ id: this.attachmentDTO.id,
1833
+ },
1834
+ isLoading: true,
1835
+ // modalStrictly: true,
1836
+ success: (res) => {
1837
+ this.$set(
1838
+ this.attachmentDTO,
1839
+ "attachmentAttributeDTOs",
1840
+ res.objx || []
1841
+ );
1842
+ },
1843
+ });
1844
+ this.getUserBasicInfos();
1845
+ },
1846
+ getUserBasicInfos() {
1847
+ let createBy = this.attachmentDTO.createBy;
1848
+ if (!!this.attachmentDTO._createBy || !createBy) return;
1849
+ this.$http({
1850
+ url: USER_PREFIX + `/userb/getUserBasicInfos`,
1851
+ method: "post",
1852
+ data: [createBy],
1853
+ isLoading: true,
1854
+ // modalStrictly: true,
1855
+ success: (res) => {
1856
+ let _createBy = createBy;
1857
+ if (res.objx?.length) {
1858
+ let nickName = res.objx[0].nickName;
1859
+ let queryCreateInfo =
1860
+ window.$vueRoot.$store.getters.queryCreateInfo || "0";
1861
+ if (nickName) {
1862
+ if (queryCreateInfo == "1") {
1863
+ _createBy = createBy + "(" + nickName + ")";
1864
+ } else if (queryCreateInfo == "2") {
1865
+ _createBy = nickName;
1866
+ }
1867
+ }
1868
+ }
1869
+ this.$set(this.attachmentDTO, "_createBy", _createBy);
1870
+ },
1871
+ });
1872
+ },
1873
+ initTableM1() {
1874
+ //明细
1875
+ var that = this;
1876
+ const tableRef = "table-m1";
1877
+ const tableOption = {
1878
+ vue: this,
1879
+ tableRef: tableRef,
1880
+ tableName: "components_vabUpload_propertiesDialog_list-m1",
1881
+ columns: [
1882
+ {
1883
+ type: "checkbox",
1884
+ fixed: "left",
1885
+ width: 48,
1886
+ resizable: false,
1887
+ },
1888
+ {
1889
+ title: this.$t2("属性名称", "components.VabUpload.attributeName"),
1890
+ field: "attributeName",
1891
+ width: 200,
1892
+ slots: {
1893
+ default: "attributeName",
1894
+ },
1895
+ },
1896
+ {
1897
+ title: this.$t2("属性值", "components.VabUpload.attributeValue"),
1898
+ field: "attributeValue",
1899
+ width: 200,
1900
+ slots: {
1901
+ default: "attributeValue",
1902
+ },
1903
+ },
1904
+ {
1905
+ width: 50,
1906
+ fixed: "right",
1907
+ title: "",
1908
+ sortable: false,
1909
+ slots: {
1910
+ default: "operate",
1911
+ },
1912
+ },
1913
+ ],
1914
+ };
1915
+ this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
1916
+ this.vxeOption = opts;
1917
+ });
1918
+ this.getData();
1919
+ },
1920
+ addItem() {
1921
+ this.attachmentDTO.attachmentAttributeDTOs.push({});
1922
+ },
1923
+ formatFileSize(fileSize) {
1924
+ return formatFileSize(fileSize);
1925
+ },
1926
+ },
1927
+ };
1928
+
1929
+ function getFileServerInfo(that, callback) {
1930
+ that.$http({
1931
+ url: USER_PREFIX + "/logic_param/getFileServerInfo",
1932
+ method: "post",
1933
+ data: {},
1934
+ failMsg: false,
1935
+ errorMsg: false,
1936
+ modal: false,
1937
+ success: (res) => {
1938
+ if (res.objx) {
1939
+ callback && callback(res.objx);
1940
+ } else {
1941
+ callback && callback();
1942
+ }
1943
+ },
1944
+ error: (err) => {
1945
+ callback && callback();
1946
+ },
1947
+ });
1948
+ }
1949
+
1950
+ function formatFileSize(fileSize) {
1951
+ fileSize = fileSize || 0;
1952
+ if (fileSize < 1024) {
1953
+ return fileSize + "B";
1954
+ } else if (fileSize < 1024 * 1024) {
1955
+ var temp = fileSize / 1024;
1956
+ temp = temp.toFixed(2);
1957
+ return temp + "KB";
1958
+ } else if (fileSize < 1024 * 1024 * 1024) {
1959
+ var temp = fileSize / (1024 * 1024);
1960
+ temp = temp.toFixed(2);
1961
+ return temp + "MB";
1962
+ } else {
1963
+ var temp = fileSize / (1024 * 1024 * 1024);
1964
+ temp = temp.toFixed(2);
1965
+ return temp + "GB";
1966
+ }
1967
+ }
1968
+
1969
+ export const mixins = tmixins;
1970
+ export const viewMixins = tViewMixins;
1971
+ export const propertiesMixins = pmixins;