swordpass-ui 1.0.0

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 (330) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -0
  3. package/lib/demo.html +10 -0
  4. package/lib/img/icon_found_img.c785c1b7.png +0 -0
  5. package/lib/sword-vue-ui.common.js +61402 -0
  6. package/lib/sword-vue-ui.css +1 -0
  7. package/lib/sword-vue-ui.umd.js +61412 -0
  8. package/lib/sword-vue-ui.umd.min.js +6 -0
  9. package/package.json +109 -0
  10. package/packages/AddQueryStrategy/index.js +7 -0
  11. package/packages/AddQueryStrategy/src/main.vue +236 -0
  12. package/packages/Autocomplete/index.js +7 -0
  13. package/packages/Autocomplete/src/main.vue +192 -0
  14. package/packages/Button/index.js +7 -0
  15. package/packages/Button/src/main.vue +90 -0
  16. package/packages/Cascader/index.js +7 -0
  17. package/packages/Cascader/src/main.vue +210 -0
  18. package/packages/Chart/index.js +7 -0
  19. package/packages/Chart/src/Chart.vue +831 -0
  20. package/packages/Checkbox/index.js +7 -0
  21. package/packages/Checkbox/src/main.vue +200 -0
  22. package/packages/Collapse/index.js +7 -0
  23. package/packages/Collapse/src/ClCollapse.vue +67 -0
  24. package/packages/Collapse/src/ClCollapseItem.vue +21 -0
  25. package/packages/CollapseItem/index.js +7 -0
  26. package/packages/CustomDialog/index.js +7 -0
  27. package/packages/CustomDialog/src/customDialog.js +99 -0
  28. package/packages/CustomDialog/src/main.vue +1944 -0
  29. package/packages/DataView/index.js +7 -0
  30. package/packages/DataView/src/DataView.vue +45 -0
  31. package/packages/Date/index.js +7 -0
  32. package/packages/Date/src/main.vue +180 -0
  33. package/packages/DatePicker/index.js +7 -0
  34. package/packages/DatePicker/src/main.vue +155 -0
  35. package/packages/Demension/index.js +7 -0
  36. package/packages/Demension/src/main.vue +379 -0
  37. package/packages/Dialog/index.js +7 -0
  38. package/packages/Dialog/src/main.vue +160 -0
  39. package/packages/Dictionary/index.js +7 -0
  40. package/packages/Dictionary/src/main.vue +204 -0
  41. package/packages/DimensionSelector/index.js +7 -0
  42. package/packages/DimensionSelector/src/main.vue +359 -0
  43. package/packages/DimensionSelectorInput/index.js +7 -0
  44. package/packages/DimensionSelectorInput/src/main.vue +79 -0
  45. package/packages/Divider/index.js +7 -0
  46. package/packages/Divider/src/main.vue +38 -0
  47. package/packages/Duration/index.js +7 -0
  48. package/packages/Duration/src/main.vue +172 -0
  49. package/packages/Editor/index.js +7 -0
  50. package/packages/Editor/src/main.vue +280 -0
  51. package/packages/Explain/index.js +7 -0
  52. package/packages/Explain/src/main.vue +55 -0
  53. package/packages/FieldTail/index.js +7 -0
  54. package/packages/FieldTail/src/main.vue +163 -0
  55. package/packages/File/index.js +7 -0
  56. package/packages/File/src/FileCard.vue +169 -0
  57. package/packages/File/src/FileList.vue +180 -0
  58. package/packages/File/src/FileTable.vue +223 -0
  59. package/packages/File/src/main.vue +467 -0
  60. package/packages/FileUpload/index.js +7 -0
  61. package/packages/FileUpload/src/main.vue +222 -0
  62. package/packages/FlowChart/index.js +7 -0
  63. package/packages/FlowChart/src/main.vue +386 -0
  64. package/packages/FormItem/index.js +7 -0
  65. package/packages/FormItem/src/main.vue +167 -0
  66. package/packages/Global/index.js +12 -0
  67. package/packages/Global/src/GlobalQuery.vue +200 -0
  68. package/packages/Global/src/GlobalValidate.vue +69 -0
  69. package/packages/Icon/index.js +7 -0
  70. package/packages/Icon/src/icons/ad.js +14 -0
  71. package/packages/Icon/src/icons/address-book.js +14 -0
  72. package/packages/Icon/src/icons/arrow.js +14 -0
  73. package/packages/Icon/src/icons/attachment.js +18 -0
  74. package/packages/Icon/src/icons/balance.js +14 -0
  75. package/packages/Icon/src/icons/ban.js +14 -0
  76. package/packages/Icon/src/icons/bell.js +14 -0
  77. package/packages/Icon/src/icons/block.js +26 -0
  78. package/packages/Icon/src/icons/book.js +14 -0
  79. package/packages/Icon/src/icons/bookmark.js +14 -0
  80. package/packages/Icon/src/icons/bug.js +22 -0
  81. package/packages/Icon/src/icons/bullhorn.js +14 -0
  82. package/packages/Icon/src/icons/calc.js +14 -0
  83. package/packages/Icon/src/icons/checkbox.js +14 -0
  84. package/packages/Icon/src/icons/circle.js +14 -0
  85. package/packages/Icon/src/icons/close.js +14 -0
  86. package/packages/Icon/src/icons/cloud-sun.js +14 -0
  87. package/packages/Icon/src/icons/coffee.js +14 -0
  88. package/packages/Icon/src/icons/component.js +14 -0
  89. package/packages/Icon/src/icons/compress.js +14 -0
  90. package/packages/Icon/src/icons/copyright.js +14 -0
  91. package/packages/Icon/src/icons/dialog.js +14 -0
  92. package/packages/Icon/src/icons/download.js +14 -0
  93. package/packages/Icon/src/icons/duration.js +14 -0
  94. package/packages/Icon/src/icons/excel.js +18 -0
  95. package/packages/Icon/src/icons/expand.js +14 -0
  96. package/packages/Icon/src/icons/export.js +21 -0
  97. package/packages/Icon/src/icons/eye-slash.js +14 -0
  98. package/packages/Icon/src/icons/eye.js +14 -0
  99. package/packages/Icon/src/icons/file.js +18 -0
  100. package/packages/Icon/src/icons/form.js +14 -0
  101. package/packages/Icon/src/icons/ganged.js +14 -0
  102. package/packages/Icon/src/icons/gaode.js +27 -0
  103. package/packages/Icon/src/icons/gift.js +14 -0
  104. package/packages/Icon/src/icons/home.js +14 -0
  105. package/packages/Icon/src/icons/image.js +14 -0
  106. package/packages/Icon/src/icons/import.js +18 -0
  107. package/packages/Icon/src/icons/index.js +67 -0
  108. package/packages/Icon/src/icons/info.js +21 -0
  109. package/packages/Icon/src/icons/laptop.js +14 -0
  110. package/packages/Icon/src/icons/line.js +34 -0
  111. package/packages/Icon/src/icons/lock.js +14 -0
  112. package/packages/Icon/src/icons/map.js +18 -0
  113. package/packages/Icon/src/icons/more.js +19 -0
  114. package/packages/Icon/src/icons/move.js +14 -0
  115. package/packages/Icon/src/icons/org.js +18 -0
  116. package/packages/Icon/src/icons/palette.js +14 -0
  117. package/packages/Icon/src/icons/plan.js +17 -0
  118. package/packages/Icon/src/icons/ppt.js +18 -0
  119. package/packages/Icon/src/icons/question.js +18 -0
  120. package/packages/Icon/src/icons/radio.js +14 -0
  121. package/packages/Icon/src/icons/refresh.js +14 -0
  122. package/packages/Icon/src/icons/search.js +14 -0
  123. package/packages/Icon/src/icons/select.js +14 -0
  124. package/packages/Icon/src/icons/setting.js +18 -0
  125. package/packages/Icon/src/icons/simple-collapse.js +18 -0
  126. package/packages/Icon/src/icons/simple-expand.js +14 -0
  127. package/packages/Icon/src/icons/sort.js +22 -0
  128. package/packages/Icon/src/icons/sword.js +26 -0
  129. package/packages/Icon/src/icons/table.js +14 -0
  130. package/packages/Icon/src/icons/time.js +14 -0
  131. package/packages/Icon/src/icons/tree.js +14 -0
  132. package/packages/Icon/src/icons/typography.js +18 -0
  133. package/packages/Icon/src/icons/upload.js +18 -0
  134. package/packages/Icon/src/icons/user.js +14 -0
  135. package/packages/Icon/src/icons/users.js +30 -0
  136. package/packages/Icon/src/icons/video.js +14 -0
  137. package/packages/Icon/src/icons/word.js +18 -0
  138. package/packages/Icon/src/main.vue +432 -0
  139. package/packages/Image/index.js +7 -0
  140. package/packages/Image/src/main.vue +66 -0
  141. package/packages/Input/index.js +7 -0
  142. package/packages/Input/src/main.vue +552 -0
  143. package/packages/JobSelector/index.js +7 -0
  144. package/packages/JobSelector/src/main.vue +339 -0
  145. package/packages/JobSelectorInput/index.js +7 -0
  146. package/packages/JobSelectorInput/src/main.vue +87 -0
  147. package/packages/Map/index.js +7 -0
  148. package/packages/Map/src/Map.vue +427 -0
  149. package/packages/Milepost/index.js +7 -0
  150. package/packages/Milepost/src/main.vue +45 -0
  151. package/packages/OnlineForm/index.js +7 -0
  152. package/packages/OnlineForm/src/Form.vue +359 -0
  153. package/packages/OrgPostDialog/index.js +7 -0
  154. package/packages/OrgPostDialog/src/main.vue +244 -0
  155. package/packages/OrgSelector/index.js +7 -0
  156. package/packages/OrgSelector/src/main.vue +493 -0
  157. package/packages/OrgSelectorInput/index.js +7 -0
  158. package/packages/OrgSelectorInput/src/OrgSelectorInput.vue +216 -0
  159. package/packages/PostSelector/index.js +7 -0
  160. package/packages/PostSelector/src/main.vue +463 -0
  161. package/packages/PostSelectorInput/index.js +7 -0
  162. package/packages/PostSelectorInput/src/PostSelectorInput.vue +200 -0
  163. package/packages/Preview/index.js +7 -0
  164. package/packages/Preview/src/FillPage.vue +311 -0
  165. package/packages/Preview/src/FrameViewer.vue +135 -0
  166. package/packages/Preview/src/Loading.vue +126 -0
  167. package/packages/Preview/src/PdfViewer.vue +125 -0
  168. package/packages/Preview/src/TextViewer.vue +99 -0
  169. package/packages/Preview/src/main.vue +242 -0
  170. package/packages/Preview/src/watermark.js +124 -0
  171. package/packages/ProcessRecord/index.js +7 -0
  172. package/packages/ProcessRecord/src/main.vue +392 -0
  173. package/packages/Qrcode/index.js +7 -0
  174. package/packages/Qrcode/src/Qrcode.vue +105 -0
  175. package/packages/QuerySqlPreview/index.js +7 -0
  176. package/packages/QuerySqlPreview/src/QuerySqlPreview.vue +163 -0
  177. package/packages/Radio/index.js +7 -0
  178. package/packages/Radio/src/main.vue +172 -0
  179. package/packages/Rate/index.js +7 -0
  180. package/packages/Rate/src/main.vue +89 -0
  181. package/packages/ReadonlyInput/index.js +7 -0
  182. package/packages/ReadonlyInput/src/main.vue +92 -0
  183. package/packages/RelevantFlow/index.js +7 -0
  184. package/packages/RelevantFlow/src/main.vue +547 -0
  185. package/packages/RelevantFlow/src/relevantFlow.js +28 -0
  186. package/packages/RoleSelector/index.js +7 -0
  187. package/packages/RoleSelector/src/main.vue +358 -0
  188. package/packages/RoleSelectorInput/index.js +7 -0
  189. package/packages/RoleSelectorInput/src/main.vue +84 -0
  190. package/packages/SaveButton/index.js +7 -0
  191. package/packages/SaveButton/src/main.vue +73 -0
  192. package/packages/Select/index.js +7 -0
  193. package/packages/Select/src/main.vue +330 -0
  194. package/packages/SelectTree/index.js +7 -0
  195. package/packages/SelectTree/src/SelectTree.vue +352 -0
  196. package/packages/Selector/index.js +7 -0
  197. package/packages/Selector/src/main.vue +617 -0
  198. package/packages/SidebarDialog/index.js +7 -0
  199. package/packages/SidebarDialog/src/main.vue +156 -0
  200. package/packages/Slider/index.js +7 -0
  201. package/packages/Slider/src/main.vue +84 -0
  202. package/packages/Step/index.js +7 -0
  203. package/packages/StepLayout/index.js +7 -0
  204. package/packages/Steps/index.js +7 -0
  205. package/packages/Steps/src/Step.vue +122 -0
  206. package/packages/Steps/src/StepLayout.vue +35 -0
  207. package/packages/Steps/src/Steps.vue +65 -0
  208. package/packages/Subtable/index.js +33 -0
  209. package/packages/Subtable/src/SubDialog.vue +1926 -0
  210. package/packages/Subtable/src/SubExportDialog.vue +115 -0
  211. package/packages/Subtable/src/SubImportDialog.vue +316 -0
  212. package/packages/Subtable/src/SubPagination.vue +112 -0
  213. package/packages/Subtable/src/SubtableBackfill.vue +83 -0
  214. package/packages/Subtable/src/dialog.js +42 -0
  215. package/packages/Switch/index.js +7 -0
  216. package/packages/Switch/src/main.vue +83 -0
  217. package/packages/Table/index.js +7 -0
  218. package/packages/Table/src/CustomColumn.vue +351 -0
  219. package/packages/Table/src/Table.vue +979 -0
  220. package/packages/TableColumn/index.js +7 -0
  221. package/packages/TableColumn/src/main.vue +177 -0
  222. package/packages/TableSearchField/index.js +7 -0
  223. package/packages/TableSearchField/src/main.vue +334 -0
  224. package/packages/TableSearchPanel/index.js +7 -0
  225. package/packages/TableSearchPanel/src/main.vue +149 -0
  226. package/packages/Tabs/index.js +7 -0
  227. package/packages/Tabs/src/Tabs.vue +140 -0
  228. package/packages/Tag/index.js +7 -0
  229. package/packages/Tag/src/main.vue +264 -0
  230. package/packages/TemplateBatchUpdate/index.js +7 -0
  231. package/packages/TemplateBatchUpdate/src/TemplateBatchUpdateDialog.vue +174 -0
  232. package/packages/TemplateForm/index.js +7 -0
  233. package/packages/TemplateForm/src/main.vue +645 -0
  234. package/packages/TemplateFormDialog/index.js +7 -0
  235. package/packages/TemplateFormDialog/src/main.vue +61 -0
  236. package/packages/TemplateImportResult/index.js +7 -0
  237. package/packages/TemplateImportResult/src/main.vue +158 -0
  238. package/packages/TemplatePreview/index.js +19 -0
  239. package/packages/TemplatePreview/src/TemplatePreview.vue +169 -0
  240. package/packages/TemplatePreview/src/TemplatePreviewFile.vue +171 -0
  241. package/packages/TemplatePreview/src/TemplatePreviewImage.vue +83 -0
  242. package/packages/TemplateTaskCirculate/index.js +7 -0
  243. package/packages/TemplateTaskCirculate/src/main.vue +238 -0
  244. package/packages/Text/index.js +7 -0
  245. package/packages/Text/src/main.vue +57 -0
  246. package/packages/TimePicker/index.js +7 -0
  247. package/packages/TimePicker/src/main.vue +139 -0
  248. package/packages/TimeSelect/index.js +7 -0
  249. package/packages/TimeSelect/src/main.vue +96 -0
  250. package/packages/Tree/index.js +7 -0
  251. package/packages/Tree/src/main.vue +439 -0
  252. package/packages/TreeDialog/index.js +7 -0
  253. package/packages/TreeDialog/src/main.vue +293 -0
  254. package/packages/TreeListDialog/index.js +7 -0
  255. package/packages/TreeListDialog/src/main.vue +219 -0
  256. package/packages/Typography/index.js +8 -0
  257. package/packages/Typography/src/create-header.js +72 -0
  258. package/packages/UserDialog/index.js +7 -0
  259. package/packages/UserDialog/src/main.vue +250 -0
  260. package/packages/UserSelector/index.js +7 -0
  261. package/packages/UserSelector/src/main.vue +746 -0
  262. package/packages/UserSelectorInput/index.js +7 -0
  263. package/packages/UserSelectorInput/src/main.vue +319 -0
  264. package/packages/picture/index.js +7 -0
  265. package/packages/picture/src/main.vue +530 -0
  266. package/packages/plugins/Echarts.js +30 -0
  267. package/packages/plugins/Map.js +29 -0
  268. package/packages/plugins/Preview.js +49 -0
  269. package/packages/plugins/Qrcode.js +7 -0
  270. package/packages/plugins/XLSX.js +7 -0
  271. package/packages/plugins/wangeditor.js +19 -0
  272. package/src/assets/icon_found_img.png +0 -0
  273. package/src/assets/table-no-data.png +0 -0
  274. package/src/directive/badge.js +53 -0
  275. package/src/directive/copy.js +47 -0
  276. package/src/directive/ellipsis.js +6 -0
  277. package/src/directive/expandClick.js +23 -0
  278. package/src/directive/express.js +86 -0
  279. package/src/directive/form.js +122 -0
  280. package/src/directive/format.js +24 -0
  281. package/src/directive/formulas.js +708 -0
  282. package/src/directive/index.js +42 -0
  283. package/src/directive/permissionLine.js +59 -0
  284. package/src/directive/permissionLineLable.js +56 -0
  285. package/src/directive/permit.js +23 -0
  286. package/src/directive/popconfirm.js +86 -0
  287. package/src/directive/relatedQuery.js +61 -0
  288. package/src/directive/resize.js +18 -0
  289. package/src/directive/subSort.js +18 -0
  290. package/src/directive/tableDrag.js +25 -0
  291. package/src/directive/tooltip.js +37 -0
  292. package/src/filter/computerSize.js +23 -0
  293. package/src/filter/dateFormat.js +10 -0
  294. package/src/filter/index.js +10 -0
  295. package/src/index.js +267 -0
  296. package/src/locale/format.js +44 -0
  297. package/src/locale/index.js +48 -0
  298. package/src/locale/lang/en.js +59 -0
  299. package/src/locale/lang/zh-CN.js +58 -0
  300. package/src/locale/lang/zh-TW.js +57 -0
  301. package/src/locale/validate/dict.js +223 -0
  302. package/src/math.js +270 -0
  303. package/src/mixins/emitter.js +33 -0
  304. package/src/mixins/form.js +25 -0
  305. package/src/mixins/formDataUpdate.js +32 -0
  306. package/src/mixins/ganged.js +126 -0
  307. package/src/mixins/inputName.js +30 -0
  308. package/src/mixins/linkage.js +403 -0
  309. package/src/mixins/locale.js +9 -0
  310. package/src/mixins/mobileMode.js +27 -0
  311. package/src/mixins/onlineHottable.js +105 -0
  312. package/src/mixins/onlineSubtable.js +468 -0
  313. package/src/mixins/permission.js +84 -0
  314. package/src/mixins/querySqlPreview.js +747 -0
  315. package/src/mixins/regionValidator.js +70 -0
  316. package/src/mixins/script.js +35 -0
  317. package/src/mixins/templatePreview.js +3673 -0
  318. package/src/service.js +336 -0
  319. package/src/services/CustomQuery.js +199 -0
  320. package/src/services/SubPagination.js +132 -0
  321. package/src/styles/index.scss +7 -0
  322. package/src/styles/selector.scss +127 -0
  323. package/src/styles/variables.scss +71 -0
  324. package/src/util/base64.js +21 -0
  325. package/src/util/brower.js +15 -0
  326. package/src/util/clone.js +61 -0
  327. package/src/util/path.js +4 -0
  328. package/src/util/request.js +14 -0
  329. package/src/utils.js +1205 -0
  330. package/src/validate.js +184 -0
@@ -0,0 +1,708 @@
1
+ import { Notification } from 'element-ui'
2
+ import utils from '@/utils.js'
3
+
4
+ const conformanceJudge = (value, vnode) => {
5
+ if (Number.isNaN(value)) {
6
+ console.error(
7
+ `在组件:${JSON.stringify(
8
+ vnode.componentOptions.propsData
9
+ )}上设置的计算公式计算结果为NaN,请检查公式。`
10
+ )
11
+ return false
12
+ }
13
+ return true
14
+ }
15
+
16
+ const formula = {
17
+ bind(el, binding, vnode) {
18
+ if (!conformanceJudge(binding.value.value, vnode)) {
19
+ return
20
+ }
21
+ const propsData = vnode.context.$options.propsData
22
+ //初始化的时候,如果没有值,则用公式的计算结果来赋值给当前字段
23
+ let oldVal = utils.getValueByPath(propsData, binding.value.bindPath)
24
+
25
+ if (oldVal == undefined) {
26
+ let pathAry = binding.value.bindPath.split('.')
27
+ if (pathAry.length == 3) {
28
+ vnode.context.$set(vnode.context.data[pathAry[1]], pathAry[2], '')
29
+ } else if (pathAry.length == 4) {
30
+ let key = /^(\w+)\[(\d+)\]$/.exec(pathAry[2])
31
+ vnode.context.$set(
32
+ vnode.context.data[pathAry[1]][key[1]][key[2]],
33
+ pathAry[3],
34
+ ''
35
+ )
36
+ }
37
+ }
38
+
39
+ if (propsData && !oldVal) {
40
+ let value = binding.value.value
41
+ if (binding.value.value instanceof Date) {
42
+ value = binding.value.value.format(binding.value.format)
43
+ }
44
+ utils.setValueByPath(propsData, binding.value.bindPath, value)
45
+ vnode.context.$forceUpdate()
46
+ }
47
+ },
48
+ update(el, binding, vnode) {
49
+ if (!conformanceJudge(binding.value.value, vnode)) {
50
+ return
51
+ }
52
+ const propsData = vnode.context.$options.propsData
53
+ if (binding.oldValue.value instanceof Date) {
54
+ if (binding.oldValue.value.getTime() !== binding.value.value.getTime()) {
55
+ const value = binding.value.value.format(binding.value.format)
56
+ utils.setValueByPath(propsData, binding.value.bindPath, value)
57
+ vnode.context.$forceUpdate()
58
+ }
59
+ } else {
60
+ if (binding.oldValue.value != binding.value.value) {
61
+ utils.setValueByPath(
62
+ propsData,
63
+ binding.value.bindPath,
64
+ binding.value.value
65
+ )
66
+ vnode.context.$forceUpdate()
67
+ }
68
+ }
69
+ },
70
+ }
71
+
72
+ const Formulas = {
73
+ d1900: new Date(Date.UTC(1900, 0, 1)),
74
+ WEEK_STARTS: [
75
+ undefined,
76
+ 0,
77
+ 1,
78
+ undefined,
79
+ undefined,
80
+ undefined,
81
+ undefined,
82
+ undefined,
83
+ undefined,
84
+ undefined,
85
+ undefined,
86
+ undefined,
87
+ 1,
88
+ 2,
89
+ 3,
90
+ 4,
91
+ 5,
92
+ 6,
93
+ 0,
94
+ ],
95
+ /**
96
+ * 冀中能源业务开发的计算公式
97
+ */
98
+ //根据传入的年月得到上月的月份
99
+ LastMonth: (y, m) => {
100
+ m = parseInt(m)
101
+ y = parseInt(y)
102
+ if (m > 0 && m < 13 && y > 0) {
103
+ if (m === 1) {
104
+ return 12
105
+ }
106
+ let v = m - 1
107
+ if (v < 10) {
108
+ v = '0' + v
109
+ }
110
+ return v
111
+ }
112
+ },
113
+ //根据传入的年月得到上个月的年份
114
+ LastYear: (y, m) => {
115
+ m = parseInt(m)
116
+ y = parseInt(y)
117
+ if (m > 0 && m < 13 && y > 0) {
118
+ if (m === 1) {
119
+ return y - 1
120
+ }
121
+ return y
122
+ }
123
+ },
124
+
125
+ /**
126
+ * 数学公式
127
+ */
128
+ ABS: (number) => {
129
+ number = Formulas.parseNumber(number)
130
+ return Math.abs(number)
131
+ },
132
+ AVERAGE: (...number) => {
133
+ let avg = 0
134
+ number.forEach((item) => {
135
+ avg += Formulas.parseNumber(item)
136
+ })
137
+ if (number.length === 0) return 0
138
+ return avg / number.length
139
+ },
140
+ AVERAGESUB: (obj) => {
141
+ let array = Formulas.getArrayByPath(obj)
142
+ return Formulas.AVERAGE(...array)
143
+ },
144
+ CEILING: (number, significance) => {
145
+ number = Formulas.parseNumber(number)
146
+ significance = Formulas.ABS(significance)
147
+ if (significance === 0) {
148
+ return 0
149
+ }
150
+ let precision = -Math.floor(Math.log(significance) / Math.log(10))
151
+ if (number > 0) {
152
+ return Formulas.ROUND(
153
+ Math.ceil(number / significance) * significance,
154
+ precision
155
+ )
156
+ } else {
157
+ return Formulas.ROUND(
158
+ Math.floor(number / significance) * significance,
159
+ precision
160
+ )
161
+ }
162
+ },
163
+ COUNT: (...args) => {
164
+ return args.length
165
+ },
166
+ COUNTSUB: (obj) => {
167
+ let array = obj.data
168
+ return array.length
169
+ },
170
+ COUNTIF: (list, condition) => {
171
+ if (!condition.startsWith('>') && !condition.startsWith('<')) {
172
+ if (isNaN(condition)) {
173
+ condition = "==='" + condition + "'"
174
+ } else {
175
+ condition = '===' + condition
176
+ }
177
+ }
178
+ let i = 0
179
+ // eslint-disable-next-line
180
+ list.forEach((item) => {
181
+ if (eval('item' + condition)) {
182
+ i++
183
+ }
184
+ })
185
+ return i
186
+ },
187
+ COUNTIFSUB: (obj, condition) => {
188
+ let array = Formulas.getArrayByPath(obj)
189
+ return Formulas.COUNTIF(array, condition)
190
+ },
191
+ FIXED: (decimal, digits) => {
192
+ decimal = Formulas.parseNumber(decimal)
193
+ digits = Formulas.parseNumber(digits)
194
+ return Number(decimal).toFixed(digits)
195
+ },
196
+ FLOOR: (number, significance) => {
197
+ number = Formulas.parseNumber(number)
198
+ significance = Formulas.ABS(significance)
199
+
200
+ if (significance === 0) {
201
+ return 0
202
+ }
203
+ let precision = -Math.floor(Math.log(significance) / Math.log(10))
204
+ if (number > 0) {
205
+ return Formulas.ROUND(
206
+ Math.floor(number / significance) * significance,
207
+ precision
208
+ )
209
+ } else {
210
+ return Formulas.ROUND(
211
+ Math.ceil(number / significance) * significance,
212
+ precision
213
+ )
214
+ }
215
+ },
216
+ INT: (number) => {
217
+ number = Formulas.parseNumber(number)
218
+ return parseInt(number)
219
+ },
220
+ LARGE: (array, index) => {
221
+ index = Formulas.parseNumber(index)
222
+ return array.sort(function(a, b) {
223
+ return b - a
224
+ })[index - 1]
225
+ },
226
+ LARGESUB: (obj, index) => {
227
+ let array = Formulas.getArrayByPath(obj)
228
+ return Formulas.LARGE(array, index)
229
+ },
230
+ LOG: (number, base) => {
231
+ number = Formulas.parseNumber(number)
232
+ base = Formulas.parseNumber(base)
233
+ if (base === 0) return 0
234
+ return Math.log(number) / Math.log(base)
235
+ },
236
+ MAX: (...args) => {
237
+ args = Formulas.parseNumberArray(args)
238
+ if (args.length === 0) {
239
+ return 0
240
+ }
241
+ return Math.max(...args)
242
+ },
243
+ MAXSUB: (obj) => {
244
+ let array = Formulas.getArrayByPath(obj)
245
+ return Formulas.MAX(...array)
246
+ },
247
+ MIN: (...args) => {
248
+ args = Formulas.parseNumberArray(args)
249
+ if (args.length === 0) {
250
+ return 0
251
+ }
252
+ return Math.min(...args)
253
+ },
254
+ MINSUB: (obj) => {
255
+ let array = Formulas.getArrayByPath(obj)
256
+ return Formulas.MIN(...array)
257
+ },
258
+ MOD: (dividend, divisor) => {
259
+ dividend = Formulas.parseNumber(dividend)
260
+ divisor = Formulas.parseNumber(divisor)
261
+ let modules = Math.abs(dividend % divisor)
262
+ return divisor > 0 ? modules : -modules
263
+ },
264
+ POWER: (number, power) => {
265
+ number = Formulas.parseNumber(number)
266
+ power = Formulas.parseNumber(power)
267
+ return Math.pow(number, power)
268
+ },
269
+ PRODUCT: (...args) => {
270
+ let total = 1
271
+ args.forEach((item) => {
272
+ item = Formulas.parseNumber(item)
273
+ total *= item
274
+ })
275
+ return args.length === 0 ? 0 : total
276
+ },
277
+ PRODUCTSUB: (obj) => {
278
+ let array = Formulas.getArrayByPath(obj)
279
+ return Formulas.PRODUCT(...array)
280
+ },
281
+ RAND: () => {
282
+ return Math.random()
283
+ },
284
+ ROUND: (number, digit) => {
285
+ return Math.round(number * 10 ** digit) / 10 ** digit
286
+ },
287
+ SMALL: (array, index) => {
288
+ array = Formulas.parseNumberArray(array)
289
+ return array.sort(function(a, b) {
290
+ return a - b
291
+ })[index - 1]
292
+ },
293
+ SMALLSUB: (obj, index) => {
294
+ let array = Formulas.getArrayByPath(obj)
295
+ return Formulas.SMALL(array, index)
296
+ },
297
+ SQRT: (number) => {
298
+ number = Formulas.parseNumber(number)
299
+ return Math.sqrt(number)
300
+ },
301
+ SUM: (...args) => {
302
+ let num = 0
303
+ args.forEach((item) => {
304
+ item = Formulas.parseNumber(item)
305
+ num += item
306
+ })
307
+ return num
308
+ },
309
+ SUMSUB: (obj) => {
310
+ let array = Formulas.getArrayByPath(obj)
311
+ return Formulas.SUM(...array)
312
+ },
313
+ SUMPRODUCT: (...arrays) => {
314
+ if (!arrays) return 0
315
+ let min = Number.MAX_VALUE
316
+ let total = 0
317
+ arrays.forEach((array) => {
318
+ if (array.length < min) {
319
+ min = array.length
320
+ }
321
+ })
322
+ for (let i = 0; i < min; i++) {
323
+ let p = 1
324
+ for (let j = 0; j < arrays.length; j++) {
325
+ p *= Formulas.parseNumber(arrays[j][i])
326
+ }
327
+ total += p
328
+ }
329
+ return total
330
+ },
331
+ SUMPRODUCTSUB: (...arrays) => {
332
+ if (!arrays) return 0
333
+ let newArrays = []
334
+ arrays.forEach((obj) => {
335
+ newArrays.push(Formulas.getArrayByPath(obj))
336
+ })
337
+ return Formulas.SUMPRODUCT(...newArrays)
338
+ },
339
+ /**
340
+ * 文本函数
341
+ * @param args
342
+ * @returns {string}
343
+ * @constructor
344
+ */
345
+ CONCATENATE: (...args) => {
346
+ let str = ''
347
+ args.forEach((item) => {
348
+ if (item) {
349
+ str += item
350
+ }
351
+ })
352
+ return str
353
+ },
354
+ CHAR: (number) => {
355
+ number = Formulas.parseNumber(number)
356
+ return String.fromCharCode(number)
357
+ },
358
+ EXACT: (str1, str2) => {
359
+ return str1 === str2
360
+ },
361
+ ISEMPTY: (str) => {
362
+ return str ? true : false
363
+ },
364
+ LEFT: (str, number) => {
365
+ number = Formulas.parseNumber(number)
366
+ return str.substr(str, number)
367
+ },
368
+ LEN: (str) => {
369
+ return str.length
370
+ },
371
+ LOWER: (str) => {
372
+ return str.toLowerCase()
373
+ },
374
+ MID: (str, start, length) => {
375
+ return str.substr(start - 1, length)
376
+ },
377
+ REPLACE: (str, start, length, newStr) => {
378
+ let replaceStr = Formulas.MID(str, start, length)
379
+ if (!replaceStr) return str + newStr
380
+ return str.replace(replaceStr, newStr)
381
+ },
382
+ REPT: (str, count) => {
383
+ let result = ''
384
+ for (let i = 0; i < Formulas.parseNumber(count); i++) {
385
+ result += str
386
+ }
387
+ return result
388
+ },
389
+ RIGHT: (str, length) => {
390
+ return str.substr(str.length - length, str.length)
391
+ },
392
+ UPPER: (str) => {
393
+ return str.toUpperCase()
394
+ },
395
+ TEXT: (number) => {
396
+ return number + ''
397
+ },
398
+ VALUE: (str) => {
399
+ return Formulas.parseNumber(str)
400
+ },
401
+ TRIM: (str) => {
402
+ return str.trim()
403
+ },
404
+ COUNTNO: (field, char) => {
405
+ if (field == '') {
406
+ return 0
407
+ } else if (field.indexOf(char) > -1) {
408
+ return field.split(char).length
409
+ } else {
410
+ return 1
411
+ }
412
+ },
413
+ //逻辑函数
414
+ AND: (...args) => {
415
+ let result = true
416
+ args.forEach((arg) => {
417
+ if (!arg) {
418
+ result = false
419
+ }
420
+ })
421
+ return result
422
+ },
423
+ FALSE: () => {
424
+ return false
425
+ },
426
+ IF: (arg, then_value, otherwise_value) => {
427
+ return arg ? then_value : otherwise_value
428
+ },
429
+ NOT: (arg) => {
430
+ return !arg
431
+ },
432
+ OR: (...args) => {
433
+ let result = false
434
+ args.forEach((arg) => {
435
+ if (arg) {
436
+ result = true
437
+ }
438
+ })
439
+ return result
440
+ },
441
+ TRUE: () => {
442
+ return true
443
+ },
444
+ XOR: (...args) => {
445
+ let count = 0
446
+ args.forEach((arg) => {
447
+ if (!arg) {
448
+ count++
449
+ }
450
+ })
451
+ return count !== args.length && count !== 0
452
+ },
453
+ //时间函数
454
+ DATE: (timestamp) => {
455
+ let date = Formulas.parseDate(timestamp)
456
+ if (date == 'Invalid Date') {
457
+ Notification.error({
458
+ title: '错误',
459
+ message: '无效日期',
460
+ })
461
+ return
462
+ }
463
+ return date
464
+ },
465
+ DATEDELTA: (string, days) => {
466
+ let timestamp = new Date(string).getTime()
467
+ timestamp += days * 86400000
468
+ return Formulas.DATE(timestamp)
469
+ },
470
+ HALFDAY: (startDate, endDate) => {
471
+ let half = 0.5
472
+ let startDay = Formulas.second(Formulas.parseStringToDate(startDate))
473
+ let endDay = Formulas.second(Formulas.parseStringToDate(endDate))
474
+ if (isNaN(startDay) || isNaN(endDay)) {
475
+ return ''
476
+ }
477
+ let halfDay = Math.ceil((endDay - startDay) / 43200)
478
+ return halfDay * half
479
+ },
480
+ COUNTHOURS: (startDate, endDate) => {
481
+ let startDay = Formulas.second(Formulas.parseStringToDate(startDate))
482
+ let endDay = Formulas.second(Formulas.parseStringToDate(endDate))
483
+ if (isNaN(startDay) || isNaN(endDay)) {
484
+ return ''
485
+ }
486
+ let hours = Math.ceil((endDay - startDay) / 3600)
487
+ return hours
488
+ },
489
+ DAY: (timestamp) => {
490
+ let date = Formulas.DATE(timestamp)
491
+ return date.getDate()
492
+ },
493
+ DAYS: (startDate, endDate) => {
494
+ let startDay = Formulas.serial(Formulas.parseStringToDate(startDate))
495
+ let endDay = Formulas.serial(Formulas.parseStringToDate(endDate))
496
+ if (isNaN(startDay) || isNaN(endDay)) {
497
+ return ''
498
+ }
499
+ return endDay - startDay
500
+ },
501
+ DAYS360: (startDate, endDate, method) => {
502
+ if (!startDate || !endDate) {
503
+ return 0
504
+ }
505
+ startDate = Formulas.parseStringToDate(startDate)
506
+ endDate = Formulas.parseStringToDate(endDate)
507
+ let sm = startDate.getMonth()
508
+ let em = endDate.getMonth()
509
+ let sd, ed
510
+ if (method) {
511
+ sd = startDate.getDate() === 31 ? 30 : startDate.getDate()
512
+ ed = endDate.getDate() === 31 ? 30 : endDate.getDate()
513
+ } else {
514
+ let smd = new Date(startDate.getFullYear(), sm + 1, 0).getDate()
515
+ let emd = new Date(endDate.getFullYear(), em + 1, 0).getDate()
516
+ sd = startDate.getDate() === smd ? 30 : startDate.getDate()
517
+ if (endDate.getDate() === emd) {
518
+ if (sd < 30) {
519
+ em++
520
+ ed = 1
521
+ } else {
522
+ ed = 30
523
+ }
524
+ } else {
525
+ ed = endDate.getDate()
526
+ }
527
+ }
528
+
529
+ return (
530
+ 360 * (endDate.getFullYear() - startDate.getFullYear()) +
531
+ 30 * (em - sm) +
532
+ (ed - sd)
533
+ )
534
+ },
535
+ HOUR: (timestamp) => {
536
+ let date = Formulas.DATE(timestamp)
537
+ return date.getHours()
538
+ },
539
+ ISOWEEKNUM: (date) => {
540
+ date = Formulas.parseStringToDate(date)
541
+ date.setHours(0, 0, 0)
542
+ date.setDate(date.getDate() + 4 - (date.getDay() || 7))
543
+ let yearStart = new Date(date.getFullYear(), 0, 1)
544
+ return Math.ceil(((date - yearStart) / 86400000 + 1) / 7)
545
+ },
546
+ MINUTE: (timestamp) => {
547
+ let date = Formulas.DATE(timestamp)
548
+ return date.getMinutes()
549
+ },
550
+ MONTH: (timestamp) => {
551
+ let date = Formulas.DATE(timestamp)
552
+ return date.getMonth() + 1
553
+ },
554
+ NOW: () => {
555
+ return Formulas.parseDate(new Date().getTime())
556
+ },
557
+ SECOND: (timestamp) => {
558
+ let date = Formulas.DATE(timestamp)
559
+ return date.getSeconds()
560
+ },
561
+ SYSTIME: () => {
562
+ //todo
563
+ },
564
+ TIME: (hour, minute, second) => {
565
+ hour = Formulas.parseNumber(hour)
566
+ minute = Formulas.parseNumber(minute)
567
+ second = Formulas.parseNumber(second)
568
+ hour = hour < 0 ? 0 : hour
569
+ minute = minute < 0 ? 0 : minute
570
+ second = second < 0 ? 0 : second
571
+ return (3600 * hour + 60 * minute + second) / 86400
572
+ },
573
+ TIMESTAMP: (date) => {
574
+ if (date) {
575
+ date = Formulas.parseStringToDate(date)
576
+ return date.getTime()
577
+ }
578
+ },
579
+ TODAY: () => {
580
+ return new Date().toLocaleDateString()
581
+ },
582
+ WEEKNUM: (date, returnType) => {
583
+ if (!date) {
584
+ return
585
+ }
586
+ date = Formulas.parseStringToDate(date)
587
+ if (returnType === undefined) {
588
+ returnType = 1
589
+ }
590
+ if (returnType === 21) return Formulas.ISOWEEKNUM(date)
591
+ let week_start = Formulas.WEEK_STARTS[returnType]
592
+ let jan = new Date(date.getFullYear(), 0, 1)
593
+ let inc = jan.getDay() < week_start ? 1 : 0
594
+ jan -= Math.abs(jan.getDay() - week_start) * 24 * 60 * 60 * 1000
595
+
596
+ return Math.floor((date - jan) / (1000 * 60 * 60 * 24) / 7 + 1) + inc
597
+ },
598
+ YEAR: (timestamp) => {
599
+ let date = new Date(timestamp)
600
+ return date.getFullYear()
601
+ },
602
+ UUID: () => {
603
+ function u4() {
604
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
605
+ }
606
+ return (
607
+ u4() +
608
+ u4() +
609
+ '-' +
610
+ u4() +
611
+ '-' +
612
+ u4() +
613
+ '-' +
614
+ u4() +
615
+ '-' +
616
+ u4() +
617
+ u4() +
618
+ u4()
619
+ )
620
+ },
621
+ WEEKDAY: (date, returnNum) => {
622
+ if (!date) {
623
+ return
624
+ }
625
+ date = Formulas.parseStringToDate(date)
626
+ const weekDayDic = ['日', '一', '二', '三', '四', '五', '六']
627
+ const weekDay = date.getDay()
628
+ return returnNum ? weekDay : `星期${weekDayDic[weekDay]}`
629
+ },
630
+ //高级函数:
631
+ CURRENCY: (x) => {
632
+ let tmp = Formulas.parseNumber(x)
633
+ //TODO 转换为人民币大写
634
+ return utils.convertCurrency(tmp)
635
+ },
636
+ THOUSAND: (x) => {
637
+ if (x || x === 0) {
638
+ x = x + ''
639
+ }
640
+ //let tmp = Formulas.parseNumber(x);
641
+ let reg = /(\d)(?=(?:\d{3})+\b)/g
642
+ return x.replace(reg, '$1,')
643
+ },
644
+ /**
645
+ * 异常统一处理
646
+ * @param {*} err
647
+ * @param {*} typeName
648
+ */
649
+ throwErr(err, typeName) {
650
+ Notification.error({
651
+ title: typeName + '公式运算错误',
652
+ message: err,
653
+ })
654
+ throw err
655
+ },
656
+ /**
657
+ * 类型判断
658
+ * @param {*} value
659
+ * @param {*} type
660
+ */
661
+ typeofType(value, type) {
662
+ if (value !== '' && typeof value != type) {
663
+ throw '传入参数必须是' + type + '类型'
664
+ }
665
+ },
666
+ parseNumber(number) {
667
+ number = parseFloat(number)
668
+ if (isNaN(number)) return 0
669
+ return number
670
+ },
671
+ parseNumberArray(array) {
672
+ return array.map((item) => {
673
+ return Formulas.parseNumber(item)
674
+ })
675
+ },
676
+ parseDate(timestamp) {
677
+ timestamp = Formulas.parseNumber(timestamp)
678
+ return new Date(timestamp)
679
+ },
680
+ parseStringToDate(str) {
681
+ if (!str) {
682
+ return new Date('')
683
+ }
684
+ return new Date(Date.parse(str.replace(/-/g, '/')))
685
+ },
686
+ getArrayByPath(obj) {
687
+ let array = []
688
+ if (!obj.data) return array
689
+ obj.data.forEach((item) => {
690
+ array.push(Formulas.parseNumber(item[obj.path]))
691
+ })
692
+ return array
693
+ },
694
+ serial(date) {
695
+ let addOn = date > -2203891200000 ? 2 : 1
696
+ return Math.ceil((date - Formulas.d1900) / 86400000) + addOn
697
+ },
698
+ second(date) {
699
+ let addOn = date > -2203891200000 ? 2 : 1
700
+ return Math.ceil((date - Formulas.d1900) / 1000) + addOn
701
+ },
702
+ }
703
+
704
+ Formulas.install = (Vue) => {
705
+ Vue.prototype.$Formulas = Formulas
706
+ }
707
+
708
+ export { formula, Formulas }