gcs-ui-lib 1.0.1

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 (231) hide show
  1. package/.env.development +5 -0
  2. package/.env.production +7 -0
  3. package/.eslintrc.js +5 -0
  4. package/README.md +97 -0
  5. package/_webpack.config.js +135 -0
  6. package/babel.config.js +16 -0
  7. package/lib/demo.html +10 -0
  8. package/lib/fonts/SIMSUN.5e0c362c.5e0c362c.ttf +0 -0
  9. package/lib/fonts/element-icons.535877f5.535877f5.woff +0 -0
  10. package/lib/fonts/element-icons.732389de.732389de.ttf +0 -0
  11. package/lib/fonts/iconfont.09d221ee.09d221ee.woff +0 -0
  12. package/lib/fonts/iconfont.1c4bfacc.1c4bfacc.ttf +0 -0
  13. package/lib/fonts/iconfont.a6f34dc7.a6f34dc7.woff2 +0 -0
  14. package/lib/fonts/iconfont.f4c32765.f4c32765.ttf +0 -0
  15. package/lib/gcs-ui-lib.common.js +106776 -0
  16. package/lib/gcs-ui-lib.css +3 -0
  17. package/lib/gcs-ui-lib.umd.js +106786 -0
  18. package/lib/gcs-ui-lib.umd.min.js +330 -0
  19. package/lib/img/bankbackground(1).e1f6e40f.jpg +0 -0
  20. package/lib/img/busibackground(2).7e09bf1f.jpg +0 -0
  21. package/lib/img/document.193a282d.svg +8 -0
  22. package/lib/img/folder.8e019792.svg +9 -0
  23. package/lib/img/icon.fc86764f.gif +0 -0
  24. package/npm +1 -0
  25. package/package.json +101 -0
  26. package/packages/AutoFillDetail/index.js +7 -0
  27. package/packages/AutoFillDetail/src/components/fillDetail.vue +188 -0
  28. package/packages/AutoFillDetail/src/demo/index.vue +18 -0
  29. package/packages/AutoFillDetail/src/main.vue +283 -0
  30. package/packages/AutoFillDetection/index.js +7 -0
  31. package/packages/AutoFillDetection/src/components/FillInfo.vue +36 -0
  32. package/packages/AutoFillDetection/src/components/HandEntred.vue +226 -0
  33. package/packages/AutoFillDetection/src/components/RuleHit.vue +105 -0
  34. package/packages/AutoFillDetection/src/components/SelectEntries.vue +192 -0
  35. package/packages/AutoFillDetection/src/components/config.js +359 -0
  36. package/packages/AutoFillDetection/src/demo/index.vue +18 -0
  37. package/packages/AutoFillDetection/src/main.vue +130 -0
  38. package/packages/AutoFillList/index.js +7 -0
  39. package/packages/AutoFillList/src/components/ImportRules.vue +407 -0
  40. package/packages/AutoFillList/src/components/ImportRulesDialog.vue +40 -0
  41. package/packages/AutoFillList/src/components/config.js +616 -0
  42. package/packages/AutoFillList/src/demo/index.vue +28 -0
  43. package/packages/AutoFillList/src/main.vue +559 -0
  44. package/packages/AutoFillRuleHistory/index.js +7 -0
  45. package/packages/AutoFillRuleHistory/src/demo/index.vue +23 -0
  46. package/packages/AutoFillRuleHistory/src/main.vue +422 -0
  47. package/packages/AutoFillService/index.js +7 -0
  48. package/packages/AutoFillService/src/components/BudgetAccountDialogForSetting.vue +588 -0
  49. package/packages/AutoFillService/src/components/BudgetAccountSettingDialog.vue +377 -0
  50. package/packages/AutoFillService/src/components/ConditionGroup.vue +413 -0
  51. package/packages/AutoFillService/src/components/CustomInput.vue +191 -0
  52. package/packages/AutoFillService/src/components/FillComponent.vue +371 -0
  53. package/packages/AutoFillService/src/components/SelectBudgetAccountDialog.vue +161 -0
  54. package/packages/AutoFillService/src/components/SelectDialog.vue +211 -0
  55. package/packages/AutoFillService/src/components/basic.vue +308 -0
  56. package/packages/AutoFillService/src/components/config.js +549 -0
  57. package/packages/AutoFillService/src/components/fillDetail.vue +145 -0
  58. package/packages/AutoFillService/src/components/fillRules.vue +787 -0
  59. package/packages/AutoFillService/src/components/paymentCategory.vue +297 -0
  60. package/packages/AutoFillService/src/components/paymentCategoryT.vue +292 -0
  61. package/packages/AutoFillService/src/customTemplate/FillBigDecimal.vue +50 -0
  62. package/packages/AutoFillService/src/customTemplate/FillDate.vue +54 -0
  63. package/packages/AutoFillService/src/customTemplate/FillInput.vue +33 -0
  64. package/packages/AutoFillService/src/customTemplate/FillMultiSelect.vue +70 -0
  65. package/packages/AutoFillService/src/customTemplate/FillSelect.vue +72 -0
  66. package/packages/AutoFillService/src/demo/index.vue +30 -0
  67. package/packages/AutoFillService/src/main.vue +432 -0
  68. package/packages/Bank/index.js +7 -0
  69. package/packages/Bank/src/demo/index.vue +18 -0
  70. package/packages/Bank/src/main.vue +70 -0
  71. package/packages/BranchBank/index.js +7 -0
  72. package/packages/BranchBank/src/demo/index.vue +18 -0
  73. package/packages/BranchBank/src/main.vue +97 -0
  74. package/packages/ConfigurableForm/index.js +7 -0
  75. package/packages/ConfigurableForm/src/components/config.js +63 -0
  76. package/packages/ConfigurableForm/src/components/detail.vue +158 -0
  77. package/packages/ConfigurableForm/src/demo/index.vue +279 -0
  78. package/packages/ConfigurableForm/src/main.vue +529 -0
  79. package/packages/DynamicForm/index.js +7 -0
  80. package/packages/DynamicForm/src/components/Amount.vue +51 -0
  81. package/packages/DynamicForm/src/components/AmountRange.vue +76 -0
  82. package/packages/DynamicForm/src/components/CheckboxGroup.vue +63 -0
  83. package/packages/DynamicForm/src/components/DMY.vue +126 -0
  84. package/packages/DynamicForm/src/components/Date.vue +51 -0
  85. package/packages/DynamicForm/src/components/DateRange.vue +51 -0
  86. package/packages/DynamicForm/src/components/Dialog.vue +247 -0
  87. package/packages/DynamicForm/src/components/Input.vue +48 -0
  88. package/packages/DynamicForm/src/components/InputNumber.vue +69 -0
  89. package/packages/DynamicForm/src/components/InputNumberRange.vue +47 -0
  90. package/packages/DynamicForm/src/components/LazySelect.vue +311 -0
  91. package/packages/DynamicForm/src/components/RadioGroup.vue +43 -0
  92. package/packages/DynamicForm/src/components/Rate.vue +57 -0
  93. package/packages/DynamicForm/src/components/Select.vue +307 -0
  94. package/packages/DynamicForm/src/components/Switch.vue +32 -0
  95. package/packages/DynamicForm/src/components/Textarea.vue +58 -0
  96. package/packages/DynamicForm/src/components/TimeSelect.vue +61 -0
  97. package/packages/DynamicForm/src/components/unitTreeSelect.vue +141 -0
  98. package/packages/DynamicForm/src/components/urlLinkInput.vue +100 -0
  99. package/packages/DynamicForm/src/demo/index.vue +486 -0
  100. package/packages/DynamicForm/src/fileUpload.js +232 -0
  101. package/packages/DynamicForm/src/formConfig.js +2910 -0
  102. package/packages/DynamicForm/src/helpers.js +18 -0
  103. package/packages/DynamicForm/src/main.vue +1095 -0
  104. package/packages/FileImport/index.js +7 -0
  105. package/packages/FileImport/src/demo/index.vue +29 -0
  106. package/packages/FileImport/src/main.vue +306 -0
  107. package/packages/MultiCurrencyStatistics/index.js +7 -0
  108. package/packages/MultiCurrencyStatistics/src/demo/index.vue +320 -0
  109. package/packages/MultiCurrencyStatistics/src/main.vue +200 -0
  110. package/packages/SelectTicket/index.js +7 -0
  111. package/packages/SelectTicket/src/Tree/index.vue +13 -0
  112. package/packages/SelectTicket/src/demo/index.vue +139 -0
  113. package/packages/SelectTicket/src/header.js +276 -0
  114. package/packages/SelectTicket/src/main.vue +581 -0
  115. package/packages/SelectTicket/src/printDialog/dialogO.vue +116 -0
  116. package/packages/SelectTicket/src/printDialog/index.vue +69 -0
  117. package/packages/SelectTicket/src/ticketDetail/billInformation/README.MD +6 -0
  118. package/packages/SelectTicket/src/ticketDetail/billInformation/mixins/index.js +35 -0
  119. package/packages/SelectTicket/src/ticketDetail/billInformation/obverse.vue +768 -0
  120. package/packages/SelectTicket/src/ticketDetail/billInformation/overview.vue +115 -0
  121. package/packages/SelectTicket/src/ticketDetail/billInformation/printList.vue +127 -0
  122. package/packages/SelectTicket/src/ticketDetail/billInformation/reverse.vue +205 -0
  123. package/packages/SelectTicket/src/ticketDetail/billInformation//351/231/204/345/212/240/344/277/235/350/257/201/344/277/241/346/201/257/345/255/227/346/256/265/345/257/271/347/205/247.md +246 -0
  124. package/packages/SelectTicket/src/ticketDetail/dialog.vue +73 -0
  125. package/packages/SelectTicket/src/ticketDetail/img/bankbackground(1).jpg +0 -0
  126. package/packages/SelectTicket/src/ticketDetail/img/busibackground(2).jpg +0 -0
  127. package/packages/SelectTicket/src/ticketDetail/img/icon.gif +0 -0
  128. package/packages/SelectTicket/src/ticketDetail/img/icon2.png +0 -0
  129. package/packages/SelectTicket/src/ticketDetail/img/noData.png +0 -0
  130. package/packages/SelectTicket/src/ticketDetail/index.vue +188 -0
  131. package/packages/SelectTreeUnit/index.js +7 -0
  132. package/packages/SelectTreeUnit/src/Tree/document.svg +8 -0
  133. package/packages/SelectTreeUnit/src/Tree/folder.svg +9 -0
  134. package/packages/SelectTreeUnit/src/Tree/index.vue +239 -0
  135. package/packages/SelectTreeUnit/src/demo/index.vue +219 -0
  136. package/packages/SelectTreeUnit/src/forEachs.js +16 -0
  137. package/packages/SelectTreeUnit/src/main.vue +1136 -0
  138. package/packages/SelectTreeUnitForm/index.js +7 -0
  139. package/packages/SelectTreeUnitForm/src/Tree/document.svg +8 -0
  140. package/packages/SelectTreeUnitForm/src/Tree/folder.svg +9 -0
  141. package/packages/SelectTreeUnitForm/src/Tree/index.vue +254 -0
  142. package/packages/SelectTreeUnitForm/src/demo/index.vue +230 -0
  143. package/packages/SelectTreeUnitForm/src/forEachs.js +16 -0
  144. package/packages/SelectTreeUnitForm/src/main.vue +1068 -0
  145. package/packages/StreamRefill/index.js +7 -0
  146. package/packages/StreamRefill/src/components/FillBigDecimal.vue +50 -0
  147. package/packages/StreamRefill/src/components/FillDate.vue +56 -0
  148. package/packages/StreamRefill/src/components/FillInput.vue +36 -0
  149. package/packages/StreamRefill/src/components/FillMultiSelect.vue +54 -0
  150. package/packages/StreamRefill/src/components/FillSelect.vue +51 -0
  151. package/packages/StreamRefill/src/demo/index.vue +254 -0
  152. package/packages/StreamRefill/src/main.vue +335 -0
  153. package/packages/Trade/index.js +7 -0
  154. package/packages/Trade/src/components/all/index.vue +913 -0
  155. package/packages/Trade/src/components/dynamicColumnMixin.js +69 -0
  156. package/packages/Trade/src/components/getDCloumn.js +15 -0
  157. package/packages/Trade/src/components/i18n.json +3337 -0
  158. package/packages/Trade/src/components/pendingEvent/index.vue +934 -0
  159. package/packages/Trade/src/components/server-config.js +60 -0
  160. package/packages/Trade/src/components/setUnitName.js +10 -0
  161. package/packages/Trade/src/components/specialHandle.js +171 -0
  162. package/packages/Trade/src/components/topendingTabs.js +21 -0
  163. package/packages/Trade/src/demo/index.vue +43 -0
  164. package/packages/Trade/src/main.vue +86 -0
  165. package/packages/ValidateQuota/index.js +58 -0
  166. package/packages/ValidateQuota/src/demo/index.vue +190 -0
  167. package/packages/ValidateQuota/src/main.vue +71 -0
  168. package/packages/ZipImport/index.js +7 -0
  169. package/packages/ZipImport/src/demo/index.vue +139 -0
  170. package/packages/ZipImport/src/main.vue +330 -0
  171. package/packages/approvel/index.js +8 -0
  172. package/packages/approvel/src/demo/index.vue +28 -0
  173. package/packages/approvel/src/main.vue +26 -0
  174. package/packages/approvel/src/progress.vue +167 -0
  175. package/packages/approvel/src/url.json +29 -0
  176. package/packages/extends/ElSelect.vue +180 -0
  177. package/packages/imgs/list-select.png +0 -0
  178. package/packages/imgs/list-unselect.png +0 -0
  179. package/packages/imgs/list.png +0 -0
  180. package/packages/imgs/tree-select.png +0 -0
  181. package/packages/imgs/tree-unselect.png +0 -0
  182. package/packages/imgs/tree.png +0 -0
  183. package/packages/inputTag/index.js +7 -0
  184. package/packages/inputTag/src/demo/index.vue +355 -0
  185. package/packages/inputTag/src/main.vue +502 -0
  186. package/public/favicon.ico +0 -0
  187. package/public/index.html +19 -0
  188. package/src/App.vue +61 -0
  189. package/src/api/aims.js +8 -0
  190. package/src/api/common.js +254 -0
  191. package/src/api/fileApi.js +33 -0
  192. package/src/api/setting.js +249 -0
  193. package/src/config/appSettings.js +12 -0
  194. package/src/config/favicon.ico +0 -0
  195. package/src/css/autoFill.scss +252 -0
  196. package/src/css/selectTreeUnit.scss +254 -0
  197. package/src/filter/filter.js +1 -0
  198. package/src/filter/index.js +274 -0
  199. package/src/fonts/demo.css +539 -0
  200. package/src/fonts/iconfont.css +21 -0
  201. package/src/fonts/iconfont.js +1 -0
  202. package/src/fonts/iconfont.json +23 -0
  203. package/src/fonts/iconfont.ttf +0 -0
  204. package/src/index.js +161 -0
  205. package/src/locale/format.js +47 -0
  206. package/src/locale/index.js +48 -0
  207. package/src/locale/lang/cn2hk.json +1270 -0
  208. package/src/locale/lang/en.js +73 -0
  209. package/src/locale/lang/es.js +7 -0
  210. package/src/locale/lang/index.js +66 -0
  211. package/src/locale/lang/ja.js +7 -0
  212. package/src/locale/lang/zh.js +74 -0
  213. package/src/locale/lang/zht.js +27 -0
  214. package/src/main.js +49 -0
  215. package/src/preview/page/Aside/index.vue +60 -0
  216. package/src/preview/router.js +107 -0
  217. package/src/utils/auth.js +12 -0
  218. package/src/utils/directive/asciiWidth.js +107 -0
  219. package/src/utils/directive/clickOutside.js +21 -0
  220. package/src/utils/directive/vtitle.js +140 -0
  221. package/src/utils/excel.js +538 -0
  222. package/src/utils/index.js +581 -0
  223. package/src/utils/request.js +157 -0
  224. package/src/utils/requestCache.js +68 -0
  225. package/src/utils/session.js +36 -0
  226. package/src/utils/thems.js +62 -0
  227. package/src/utils/token.js +26 -0
  228. package/src/utils/tools.js +317 -0
  229. package/src/utils/utils.js +513 -0
  230. package/types/favicon.ico +0 -0
  231. package/vue.config.js +49 -0
@@ -0,0 +1,140 @@
1
+ let tooltip = undefined
2
+ import getWidth from './asciiWidth.js'
3
+ const popClass = 'at-title-pop-' + Date.now()
4
+
5
+ function tipInit(Vue) {
6
+ const el = document.createElement('div')
7
+ document.body.appendChild(el)
8
+
9
+ tooltip = new Vue({
10
+ data() {
11
+ return {
12
+ visible: false
13
+ }
14
+ },
15
+ render(_h) {
16
+ var _vm = this
17
+ return _h(
18
+ 'el-popover',
19
+ {
20
+ ref: 'title-pop',
21
+ attrs: {
22
+ value: _vm.visible,
23
+ trigger: 'manual',
24
+ placement: 'top',
25
+ 'popper-class': 'n20-title-pop',
26
+ },
27
+ on: {
28
+ input(v) {
29
+ _vm.visible = v
30
+ }
31
+ }
32
+ },
33
+ [_h('span', { staticClass: popClass })]
34
+ )
35
+ }
36
+ }).$mount(el)
37
+ }
38
+
39
+ function tipShow(el, arg) {
40
+ let text = undefined
41
+ if (el.$tooltipTitle) {
42
+ if (!el.$tooltipTitleOverflow || el.clientWidth < el.scrollWidth) {
43
+ text = el.$tooltipTitle
44
+ }
45
+ } else {
46
+ let _input = el.querySelector('.el-input__inner')
47
+ if (_input && _input.clientWidth < _input.scrollWidth) {
48
+ text = _input.value
49
+ }
50
+ }
51
+
52
+ if (text) {
53
+ let popEl = document.querySelector('.' + popClass)
54
+ if (arg === 'br') {
55
+ popEl.innerText = String(text).replace(/,/g, '\n')
56
+ } else {
57
+ popEl.innerText = text
58
+ }
59
+
60
+ if (tooltip.$refs['title-pop'].referenceElm !== el) {
61
+ tooltip.$refs['title-pop'].doDestroy()
62
+ tooltip.$refs['title-pop'].referenceElm = el
63
+ }
64
+
65
+ tooltip.visible = true
66
+ }
67
+ }
68
+
69
+ function tipHide(el) {
70
+ if (tooltip.$refs['title-pop'].referenceElm === el) {
71
+ tooltip.visible = false
72
+ }
73
+ }
74
+
75
+ const TitleDirective = {}
76
+ TitleDirective.install = (Vue) => {
77
+ if (Vue.prototype.$isServer) return
78
+ Vue.directive('title', {
79
+ bind: function (el, binding, vnode) {
80
+ tooltip || tipInit(Vue)
81
+
82
+ el.$tooltipTitleOverflow = vnode.data.attrs && vnode.data.attrs['show-overflow-tooltip']
83
+ el.$tooltipTitle = binding.value
84
+
85
+ let vmethods = vnode.child ? vnode.child.$options : vnode.context.$options
86
+ vmethods.deactivated || (vmethods.deactivated = [])
87
+
88
+ vmethods.deactivated.push(tipHide.bind(null, el))
89
+ el.$tipShow = () => tipShow(el, binding.arg)
90
+ el.$tipHide = () => tipHide(el)
91
+ el.addEventListener('mouseenter', el.$tipShow)
92
+ el.addEventListener('mouseleave', el.$tipHide)
93
+ },
94
+ update: function (el, binding) {
95
+ el.$tooltipTitle = binding.value
96
+ },
97
+ unbind: function (el, binding) {
98
+ tipHide(el)
99
+ el.removeEventListener('mouseenter', el.$tipShow)
100
+ el.removeEventListener('mouseleave', el.$tipHide)
101
+ }
102
+ })
103
+ }
104
+
105
+ const HoverTooltip = {}
106
+ HoverTooltip.install = (Vue) => {
107
+ if (Vue.prototype.$isServer) return
108
+ Vue.directive('hover-tooltip', {
109
+ bind(el, binding, vnode) {
110
+ tooltip || tipInit(Vue)
111
+
112
+ el.$tooltipTitle = binding.value
113
+
114
+ let vmethods = vnode.child ? vnode.child.$options : vnode.context.$options
115
+ vmethods.deactivated || (vmethods.deactivated = [])
116
+
117
+ vmethods.deactivated.push(tipHide.bind(null, el))
118
+ el.$tipShow = () => tipShow(el, binding.arg)
119
+ el.$tipHide = () => tipHide(el)
120
+ el.addEventListener('mouseenter', () => {
121
+ console.log(getWidth(binding.value))
122
+ if (getWidth(binding.value) > (binding.arg || 98)) {
123
+ return el.$tipShow()
124
+ }
125
+ })
126
+
127
+ el.addEventListener('mouseleave', el.$tipHide)
128
+ },
129
+ update: function (el, binding) {
130
+ el.$tooltipTitle = binding.value
131
+ },
132
+ unbind: function (el, binding) {
133
+ tipHide(el)
134
+ el.removeEventListener('mouseenter', el.$tipShow)
135
+ el.removeEventListener('mouseleave', el.$tipHide)
136
+ }
137
+ })
138
+ }
139
+
140
+ export { TitleDirective, HoverTooltip }
@@ -0,0 +1,538 @@
1
+
2
+ import XLSX from "xlsx";
3
+ //引入xlsx
4
+ /**
5
+ * 导入excel的函数
6
+ * @param {*} file
7
+ */
8
+ const importsExcel = (file) => {
9
+ //使用promise导入
10
+ return new Promise((resolve, reject) => {
11
+ // 获取上传的文件对象
12
+ const { files } = file.target; //获取里面的所有文件
13
+ // 通过FileReader对象读取文件
14
+ const fileReader = new FileReader();
15
+
16
+ fileReader.onload = event => { //异步操作 excel文件加载完成以后触发
17
+ try {
18
+ const { result } = event.target;
19
+ // 以二进制流方式读取得到整份excel表格对象
20
+ const workbook = XLSX.read(result, { type: 'binary' });
21
+ let data = []; // 存储获取到的数据
22
+ // 遍历每张工作表进行读取(这里默认只读取第一张表)
23
+ for (const sheet in workbook.Sheets) {
24
+ if (workbook.Sheets.hasOwnProperty(sheet)) {
25
+ data = data.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet]));
26
+ }
27
+ }
28
+ resolve(data);//导出数据
29
+ } catch (e) {
30
+ // 这里可以抛出文件类型错误不正确的相关提示
31
+ reject("失败");//导出失败
32
+ }
33
+ };
34
+ // 以二进制方式打开文件
35
+ fileReader.readAsBinaryString(files[0]);
36
+ })
37
+
38
+ }
39
+ /**
40
+ * 导出excel
41
+ * @param {*} headers
42
+ * @param {*} data
43
+ * @param {*} fileName
44
+ */
45
+ const exportExcel = (headers, data, fileName = 'demo.xlsx') => {
46
+
47
+ const _headers = headers
48
+ .map((item, i) => Object.assign({}, { key: item.key, title: item.title, position: String.fromCharCode(65 + i) + 1 }))
49
+ .reduce((prev, next) => Object.assign({}, prev, { [next.position]: { key: next.key, v: next.title } }), {});
50
+ const _data = data
51
+ .map((item, i) => headers.map((key, j) => Object.assign({}, { content: item[key.key], position: String.fromCharCode(65 + j) + (i + 2) })))
52
+ // 对刚才的结果进行降维处理(二维数组变成一维数组)
53
+ .reduce((prev, next) => prev.concat(next))
54
+ // 转换成 worksheet 需要的结构
55
+ .reduce((prev, next) => Object.assign({}, prev, { [next.position]: { v: next.content } }), {});
56
+
57
+ // 合并 headers 和 data
58
+ const output = Object.assign({}, _headers, _data);
59
+ // 获取所有单元格的位置
60
+ const outputPos = Object.keys(output);
61
+ // 计算出范围 ,["A1",..., "H2"]
62
+ const ref = `${outputPos[0]}:${outputPos[outputPos.length - 1]}`;
63
+
64
+ // 构建 workbook 对象
65
+ const wb = {
66
+ SheetNames: ['mySheet'],
67
+ Sheets: {
68
+ mySheet: Object.assign(
69
+ {},
70
+ output,
71
+ {
72
+ '!ref': ref,
73
+ '!cols': [{ wpx: 45 }, { wpx: 100 }, { wpx: 200 }, { wpx: 80 }, { wpx: 150 }, { wpx: 100 }, { wpx: 300 }, { wpx: 300 }],
74
+ },
75
+ ),
76
+ },
77
+ };
78
+
79
+ // 导出 Excel
80
+ XLSX.writeFile(wb, fileName);
81
+
82
+ }
83
+
84
+ const exportToExcel = currName => {
85
+ console.log(document.querySelector(`#table${currName}`), window.saveAs);
86
+ let fix = document.querySelector(`#table${currName} .el-table__fixed`);
87
+ let workbook = XLSX.utils.book_new();
88
+ // let tableSheet = XLSX.utils.table_to_sheet(document.querySelector(`#table${currName}`));
89
+ let tableSheet = null
90
+ if (fix) {
91
+ tableSheet = XLSX.utils.table_to_sheet(document.querySelector(`#table${currName}`).removeChild(fix));
92
+ document.querySelector(`#table${currName}`).appendChild(fix);
93
+ } else {
94
+ tableSheet = XLSX.utils.table_to_sheet(document.querySelector(`#table${currName}`));
95
+ }
96
+ XLSX.utils.book_append_sheet(workbook, tableSheet, currName)
97
+ let wbOut = XLSX.write(workbook, {
98
+ bookType: 'xlsx',
99
+ bookSST: true,
100
+ type: 'array'
101
+ })
102
+ try {
103
+ // window.saveAs(
104
+ // new Blob([wbOut],{type:'application/octet-stream'}),
105
+ // 'demo.xlsx'
106
+ // )
107
+ XLSX.writeFile(workbook, 'demo.xlsx');
108
+ } catch (error) {
109
+ console.log(error, wbOut);
110
+ }
111
+ }
112
+ /**
113
+ * 导出多sheet表格
114
+ * @param { Object} headers {label: '表头的中文名称', prop: ‘表格的英文名称’}
115
+ * @param { Object } data
116
+ * data数据示例
117
+ * {
118
+ * sheet: [],
119
+ * sheet1: [],
120
+ * sheet2: []
121
+ * }
122
+ */
123
+ const exportToMulExcel = (headers, data, mergess) => {
124
+ let workbook = XLSX.utils.book_new();
125
+ let headerMap = {};
126
+ // let headerRows = excelHeader.length;
127
+ let excelHeader = buildHeader(headers);
128
+ let merges = doMerges(excelHeader)
129
+ headers.forEach(item => {
130
+ headerMap[item.prop] = item.label;
131
+ })
132
+ console.log(excelHeader, merges);
133
+ // let ws = aoa_to_sheet(headers, headers.length);
134
+ // ws['!merges'] = merges;
135
+ // merges.forEach(item => {
136
+ // ws['!merges'].push(XLSX.utils.decode_range(item))
137
+ // })
138
+ for (let key in data) {
139
+ let tableSheet = [];
140
+ let dataList = [];
141
+ if (data[key].length > 0) {
142
+ dataList = extractData(data[key], headers);
143
+ } else {
144
+ dataList = [];
145
+ }
146
+ console.log(dataList);
147
+ dataList = dataList.map(item => {
148
+ return item.map(item2 => {
149
+ return isNaN(item2) || item2 == null ? item2 : parseFloat(item2).toFixed(2)
150
+ })
151
+ return
152
+ })
153
+ var sheet = XLSX.utils.aoa_to_sheet(excelHeader.concat(dataList));
154
+ sheet['!merges'] = merges
155
+ XLSX.utils.book_append_sheet(workbook, sheet, key);
156
+
157
+ }
158
+ let wbOut = XLSX.write(workbook, {
159
+ bookType: 'xlsx',
160
+ bookSST: true,
161
+ type: 'array'
162
+ })
163
+ try {
164
+ console.log(workbook)
165
+ XLSX.writeFile(workbook, 'demo.xlsx');
166
+ } catch (error) {
167
+ console.log(error, wbOut);
168
+ }
169
+ }
170
+ const flat = (revealList) => {
171
+ let result = []
172
+ revealList.forEach(e => {
173
+ if (e.children?.length > 0) {
174
+ result.push(...flat(e.children))
175
+ } else if (e.hasOwnProperty('prop')) {
176
+ result.push(e)
177
+ }
178
+ })
179
+ return result;
180
+ }
181
+ const extractData = (selectionData, revealList) => {
182
+ // 列
183
+ let headerList = flat(revealList);
184
+ // 导出的结果集
185
+ let excelRows = [];
186
+ // 如果有child集合的话会用到
187
+ let dataKeys = new Set(Object.keys(selectionData[0]));
188
+ selectionData.some(e => {
189
+ if (e.children && e.children.length > 0) {
190
+ let childKeys = Object.keys(e.children[0]);
191
+ for (let i = 0; i < childKeys.length; i++) {
192
+ dataKeys.delete(childKeys[i]);
193
+ }
194
+ return true;
195
+ }
196
+ })
197
+ flatData(selectionData, (list) => {
198
+ excelRows.push(...buildExcelRow(dataKeys, headerList, list));
199
+ })
200
+ return excelRows;
201
+ }
202
+ const buildExcelRow = (mainKeys, headers, rawDataList) => {
203
+ // 合计行
204
+ let sumCols = [];
205
+ // 数据行
206
+ let rows = [];
207
+ for (let i = 0; i < rawDataList.length; i++) {
208
+ let cols = []
209
+ let rawData = rawDataList[i];
210
+ // 提取数据
211
+ for (let j = 0; j < headers.length; j++) {
212
+ let header = headers[j];
213
+ // 父元素键需要行合并
214
+ if (rawData['rowSpan'] === 0 && mainKeys.has(header.prop)) {
215
+ cols.push('!$ROW_SPAN_PLACEHOLDER')
216
+ } else {
217
+ let value;
218
+ value = rawData[header.prop];
219
+ cols.push(value)
220
+ // 如果该列需要合计,并且是数字类型
221
+ if (header['summable'] && typeof value === 'number') {
222
+ sumCols[j] = (sumCols[j] ? sumCols[j] : 0) + value;
223
+ }
224
+ }
225
+ }
226
+ rows.push(cols);
227
+ }
228
+ return rows;
229
+ }
230
+ const flatData = (list, eachDataCallBack) => {
231
+ let resultList = [];
232
+ for (let i = 0; i < list.length; i++) {
233
+ let data = list[i];
234
+ let rawDataList = [];
235
+ // 每个子元素都和父元素合并成一条数据
236
+ if (data.children && data.children.length > 0) {
237
+ for (let j = 0; j < data.children.length; j++) {
238
+ delete data.children[j].bsm
239
+ let copy = Object.assign({}, data, data.children[j]);
240
+ rawDataList.push(copy);
241
+ copy['rowSpan'] = (j > 0 ? 0 : data.children.length);
242
+ }
243
+ } else {
244
+ data['rowSpan'] = 1;
245
+ rawDataList.push(data);
246
+ }
247
+ resultList.push(...rawDataList);
248
+ if (typeof eachDataCallBack === 'function') {
249
+ eachDataCallBack(rawDataList)
250
+ }
251
+ }
252
+ return resultList;
253
+ }
254
+ const aoa_to_sheet = (data, headerRows) => {
255
+ const ws = {};
256
+ const range = { s: { c: 10000000, r: 10000000 }, e: { c: 0, r: 0 } };
257
+ for (let R = 0; R !== data.length; ++R) {
258
+ for (let C = 0; C !== data[R].length; ++C) {
259
+ if (range.s.r > R) {
260
+ range.s.r = R;
261
+ }
262
+ if (range.s.c > C) {
263
+ range.s.c = C;
264
+ }
265
+ if (range.e.r < R) {
266
+ range.e.r = R;
267
+ }
268
+ if (range.e.c < C) {
269
+ range.e.c = C;
270
+ }
271
+ /// 这里生成cell的时候,使用上面定义的默认样式
272
+ const cell = {
273
+ v: data[R][C] || '',
274
+ s: {
275
+ font: { name: "宋体", sz: 11, color: { auto: 1 } },
276
+ alignment: {
277
+ /// 自动换行
278
+ wrapText: 1,
279
+ // 居中
280
+ horizontal: "center",
281
+ vertical: "center",
282
+ indent: 0
283
+ }
284
+ }
285
+ };
286
+ // 头部列表加边框
287
+ if (R < headerRows) {
288
+ cell.s.border = {
289
+ top: { style: 'thin', color: { rgb: "000000" } },
290
+ left: { style: 'thin', color: { rgb: "000000" } },
291
+ bottom: { style: 'thin', color: { rgb: "000000" } },
292
+ right: { style: 'thin', color: { rgb: "000000" } },
293
+ };
294
+ cell.s.fill = {
295
+ patternType: 'solid',
296
+ fgColor: { theme: 3, "tint": 0.3999755851924192, rgb: 'DDD9C4' },
297
+ bgColor: { theme: 7, "tint": 0.3999755851924192, rgb: '8064A2' }
298
+ }
299
+ }
300
+ const cell_ref = XLSX.utils.encode_cell({ c: C, r: R });
301
+ if (typeof cell.v === 'number') {
302
+ cell.t = 'n';
303
+ } else if (typeof cell.v === 'boolean') {
304
+ cell.t = 'b';
305
+ } else {
306
+ cell.t = 's';
307
+ }
308
+ ws[cell_ref] = cell;
309
+ }
310
+ }
311
+ if (range.s.c < 10000000) {
312
+ ws['!ref'] = XLSX.utils.encode_range(range);
313
+ }
314
+ return ws;
315
+ }
316
+ const pushRowSpanPlaceHolder = (arr, count) => {
317
+ for (let i = 0; i < count; i++) {
318
+ arr.push('!$ROW_SPAN_PLACEHOLDER')
319
+ }
320
+ }
321
+ const pushColSpanPlaceHolder = (arr, count) => {
322
+ for (let i = 0; i < count; i++) {
323
+ arr.push('!$COL_SPAN_PLACEHOLDER')
324
+ }
325
+ }
326
+ const buildHeader = (revealList) => {
327
+ let excelHeader = [];
328
+ // 构建生成excel表头需要的数据结构
329
+ getHeader(revealList, excelHeader, 0, 0);
330
+ // 多行表头长短不一,短的向长的看齐,不够的补上行合并占位符
331
+ let max = Math.max(...(excelHeader.map(a => a.length)))
332
+ excelHeader.filter(e => e.length < max).forEach(
333
+ e => pushRowSpanPlaceHolder(e, max - e.length))
334
+ return excelHeader;
335
+ }
336
+ const getHeader = (headers, excelHeader, deep, perOffset) => {
337
+ let offset = 0
338
+ let cur = excelHeader[deep]
339
+ if (!cur) {
340
+ cur = excelHeader[deep] = []
341
+ }
342
+ // 填充行合并占位符
343
+ pushRowSpanPlaceHolder(cur, perOffset - cur.length)
344
+ for (let i = 0; i < headers.length; i++) {
345
+ let head = headers[i]
346
+ cur.push(head.label)
347
+ if (head.hasOwnProperty('children') && Array.isArray(head.children)
348
+ && head.children.length > 0) {
349
+ let childOffset = getHeader(head.children, excelHeader, deep + 1,
350
+ cur.length - 1)
351
+ // 填充列合并占位符
352
+ pushColSpanPlaceHolder(cur, childOffset - 1)
353
+ offset += childOffset
354
+ } else {
355
+ offset++
356
+ }
357
+ }
358
+ return offset;
359
+
360
+ }
361
+ const doMerges = (arr) => {
362
+ // 要么横向合并 要么纵向合并
363
+ let deep = arr.length;
364
+ let merges = [];
365
+ for (let y = 0; y < deep; y++) {
366
+ // 先处理横向合并
367
+ let row = arr[y];
368
+ let colSpan = 0
369
+ for (let x = 0; x < row.length; x++) {
370
+ if (row[x] === '!$COL_SPAN_PLACEHOLDER') {
371
+ row[x] = undefined;
372
+ if(x+1 === row.length){
373
+ merges.push({ s: { r: y, c: x - colSpan - 1}, e: { r: y, c: x } })
374
+ }
375
+ colSpan++
376
+ } else if (colSpan > 0 && x > colSpan) {
377
+ merges.push({ s: { r: y, c: x - colSpan - 1 }, e: { r: y, c: x - 1 } })
378
+ colSpan = 0
379
+ } else {
380
+ colSpan = 0
381
+ }
382
+ }
383
+ }
384
+ // 再处理纵向合并
385
+ let colLength = arr[0].length
386
+ for (let x = 0; x < colLength; x++) {
387
+ let rowSpan = 0
388
+ for (let y = 0; y < deep; y++) {
389
+ if (arr[y][x] === '!$ROW_SPAN_PLACEHOLDER') {
390
+ arr[y][x] = undefined;
391
+ if(y+1 === deep){
392
+ merges.push({ s: { r: y - rowSpan , c: x }, e: { r: y , c: x } })
393
+ }
394
+ rowSpan++;
395
+ } else if (rowSpan > 0 && y > rowSpan) {
396
+ merges.push({ s: { r: y - rowSpan - 1, c: x }, e: { r: y - 1, c: x } })
397
+ rowSpan = 0;
398
+ } else {
399
+ rowSpan = 0;
400
+ }
401
+ }
402
+ }
403
+ return merges;
404
+ }
405
+ const export_json_to_excel = ({
406
+ multiHeader = [],
407
+ header,
408
+ data,
409
+ filename,
410
+ merges = [],
411
+ list = [],
412
+ autoWidth = true,
413
+ bookType = 'xlsx'
414
+ } = {}) => {
415
+ /* original data */
416
+ filename = filename || 'excel-list'
417
+ data = [...data]
418
+ data.unshift(header);
419
+
420
+ for (let i = multiHeader.length - 1; i > -1; i--) {
421
+ data.unshift(multiHeader[i])
422
+ }
423
+
424
+ var wb = XLSX.utils.book_new(),
425
+ ws = sheet_from_array_of_arrays(data);
426
+ list.map((item) => {
427
+ XLSX.utils.book_append_sheet(wb, XLSX.utils.json_to_sheet(data[item]), item)
428
+ })
429
+
430
+
431
+ if (merges.length > 0) {
432
+ if (!ws['!merges']) ws['!merges'] = [];
433
+ merges.forEach(item => {
434
+ ws['!merges'].push(XLSX.utils.decode_range(item))
435
+ })
436
+ }
437
+
438
+ if (autoWidth) {
439
+ /*设置worksheet每列的最大宽度*/
440
+ const colWidth = data.map(row => row.map(val => {
441
+ /*先判断是否为null/undefined*/
442
+ if (val == null) {
443
+ return {
444
+ 'wch': 10
445
+ };
446
+ }
447
+ /*再判断是否为中文*/
448
+ else if (val.toString().charCodeAt(0) > 255) {
449
+ return {
450
+ 'wch': val.toString().length * 2
451
+ };
452
+ } else {
453
+ return {
454
+ 'wch': val.toString().length
455
+ };
456
+ }
457
+ }))
458
+ /*以第一行为初始值*/
459
+ let result = colWidth[0];
460
+ for (let i = 1; i < colWidth.length; i++) {
461
+ for (let j = 0; j < colWidth[i].length; j++) {
462
+ if (result[j]['wch'] < colWidth[i][j]['wch']) {
463
+ result[j]['wch'] = colWidth[i][j]['wch'];
464
+ }
465
+ }
466
+ }
467
+ ws['!cols'] = result;
468
+ }
469
+
470
+ /* add worksheet to workbook */
471
+ // wb.SheetNames.push(ws_name);
472
+ // wb.Sheets[ws_name] = ws;
473
+
474
+ var wbout = XLSX.write(wb, {
475
+ bookType: bookType,
476
+ bookSST: false,
477
+ type: 'binary'
478
+ });
479
+ // saveAs(new Blob([s2ab(wbout)], {
480
+ // type: "application/octet-stream"
481
+ // }), `${filename}.${bookType}`);
482
+ XLSX.writeFile(wbout, 'demo.xlsx');
483
+ }
484
+
485
+ const toJson = (file, name)=>{
486
+ let pro = new Promise((resolve, reject) => {
487
+ if (file instanceof Blob) {
488
+ file.arrayBuffer().then((array) => {
489
+ try {
490
+ const workbook = XLSX.read(array, { type: 'array', cellDates: true })
491
+ resolve(workbook)
492
+ } catch (err) {
493
+ reject(err)
494
+ }
495
+ })
496
+ } else if (file instanceof ArrayBuffer) {
497
+ try {
498
+ const workbook = XLSX.read(file, { type: 'array', cellDates: true })
499
+ resolve(workbook)
500
+ } catch (err) {
501
+ reject(err)
502
+ }
503
+ }
504
+ })
505
+
506
+ return pro.then((workbook) => {
507
+ let sheetName = name || workbook.SheetNames[0]
508
+ let workSheet = workbook.Sheets[sheetName]
509
+ console.log(workSheet, 'workSheet')
510
+ if (!workSheet) return Promise.reject(`工作表:${name} 不存在`)
511
+ let rowsc = XLSX.utils.sheet_to_json(workSheet, {header: 1 , mergeCells:true})
512
+ //
513
+ let header1 = rowsc[0].reduce((acc, val, idx) => {
514
+ acc[idx] = val;
515
+ return acc;
516
+ }, {});
517
+ let header2 = rowsc[1].reduce((acc, val, idx) => {
518
+ acc[idx] = val;
519
+ return acc;
520
+ }, {});
521
+ const h = {
522
+ ...header1,
523
+ ...header2
524
+ }
525
+ let h1 = Object.values(h)
526
+ console.log(h1, rowsc, 'rowsc')
527
+ let rows = [h1,...rowsc.slice(2)]
528
+ return Promise.resolve(rows)
529
+ })
530
+ }
531
+ export {
532
+ importsExcel,
533
+ exportExcel,
534
+ exportToExcel,
535
+ exportToMulExcel,
536
+ export_json_to_excel,
537
+ toJson
538
+ }