vxe-pc-ui 3.14.6 → 3.14.7

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 (605) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +134 -134
  3. package/es/checkbox/src/button.js +25 -4
  4. package/es/checkbox/src/checkbox.js +25 -4
  5. package/es/checkbox/src/group.js +25 -3
  6. package/es/checkbox/style.css +6 -3
  7. package/es/checkbox/style.min.css +1 -1
  8. package/es/language/ar-EG.js +4 -0
  9. package/es/language/de-DE.js +4 -0
  10. package/es/language/en-US.js +4 -0
  11. package/es/language/es-ES.js +4 -0
  12. package/es/language/fr-FR.js +4 -0
  13. package/es/language/hu-HU.js +4 -0
  14. package/es/language/hy-AM.js +4 -0
  15. package/es/language/id-ID.js +4 -0
  16. package/es/language/it-IT.js +4 -0
  17. package/es/language/ja-JP.js +4 -0
  18. package/es/language/ko-KR.js +4 -0
  19. package/es/language/ms-MY.js +4 -0
  20. package/es/language/nb-NO.js +4 -0
  21. package/es/language/pt-BR.js +4 -0
  22. package/es/language/ru-RU.js +4 -0
  23. package/es/language/th-TH.js +4 -0
  24. package/es/language/ug-CN.js +4 -0
  25. package/es/language/uk-UA.js +4 -0
  26. package/es/language/uz-UZ.js +4 -0
  27. package/es/language/vi-VN.js +4 -0
  28. package/es/language/zh-CHT.js +4 -0
  29. package/es/language/zh-CN.js +4 -0
  30. package/es/radio/src/button.js +26 -5
  31. package/es/radio/src/group.js +19 -2
  32. package/es/radio/src/radio.js +26 -5
  33. package/es/radio/style.css +5 -3
  34. package/es/radio/style.min.css +1 -1
  35. package/es/style.css +1 -1
  36. package/es/style.min.css +1 -1
  37. package/es/switch/src/switch.js +19 -11
  38. package/es/tree/style.css +11 -6
  39. package/es/tree/style.min.css +1 -1
  40. package/es/ui/index.js +1 -1
  41. package/es/ui/src/log.js +1 -1
  42. package/es/vxe-checkbox/style.css +6 -3
  43. package/es/vxe-checkbox/style.min.css +1 -1
  44. package/es/vxe-radio/style.css +5 -3
  45. package/es/vxe-radio/style.min.css +1 -1
  46. package/es/vxe-tree/style.css +11 -6
  47. package/es/vxe-tree/style.min.css +1 -1
  48. package/lib/checkbox/src/button.js +20 -3
  49. package/lib/checkbox/src/button.min.js +1 -1
  50. package/lib/checkbox/src/checkbox.js +20 -3
  51. package/lib/checkbox/src/checkbox.min.js +1 -1
  52. package/lib/checkbox/src/group.js +24 -2
  53. package/lib/checkbox/src/group.min.js +1 -1
  54. package/lib/checkbox/style/style.css +6 -3
  55. package/lib/checkbox/style/style.min.css +1 -1
  56. package/lib/index.umd.js +8817 -8594
  57. package/lib/index.umd.min.js +1 -1
  58. package/lib/language/ar-EG.js +4 -0
  59. package/lib/language/ar-EG.min.js +1 -1
  60. package/lib/language/ar-EG.umd.js +4 -0
  61. package/lib/language/de-DE.js +4 -0
  62. package/lib/language/de-DE.min.js +1 -1
  63. package/lib/language/de-DE.umd.js +4 -0
  64. package/lib/language/en-US.js +4 -0
  65. package/lib/language/en-US.min.js +1 -1
  66. package/lib/language/en-US.umd.js +4 -0
  67. package/lib/language/es-ES.js +4 -0
  68. package/lib/language/es-ES.min.js +1 -1
  69. package/lib/language/es-ES.umd.js +4 -0
  70. package/lib/language/fr-FR.js +4 -0
  71. package/lib/language/fr-FR.min.js +1 -1
  72. package/lib/language/fr-FR.umd.js +4 -0
  73. package/lib/language/hu-HU.js +4 -0
  74. package/lib/language/hu-HU.min.js +1 -1
  75. package/lib/language/hu-HU.umd.js +4 -0
  76. package/lib/language/hy-AM.js +4 -0
  77. package/lib/language/hy-AM.min.js +1 -1
  78. package/lib/language/hy-AM.umd.js +4 -0
  79. package/lib/language/id-ID.js +4 -0
  80. package/lib/language/id-ID.min.js +1 -1
  81. package/lib/language/id-ID.umd.js +4 -0
  82. package/lib/language/it-IT.js +4 -0
  83. package/lib/language/it-IT.min.js +1 -1
  84. package/lib/language/it-IT.umd.js +4 -0
  85. package/lib/language/ja-JP.js +4 -0
  86. package/lib/language/ja-JP.min.js +1 -1
  87. package/lib/language/ja-JP.umd.js +4 -0
  88. package/lib/language/ko-KR.js +4 -0
  89. package/lib/language/ko-KR.min.js +1 -1
  90. package/lib/language/ko-KR.umd.js +4 -0
  91. package/lib/language/ms-MY.js +4 -0
  92. package/lib/language/ms-MY.min.js +1 -1
  93. package/lib/language/ms-MY.umd.js +4 -0
  94. package/lib/language/nb-NO.js +4 -0
  95. package/lib/language/nb-NO.min.js +1 -1
  96. package/lib/language/nb-NO.umd.js +4 -0
  97. package/lib/language/pt-BR.js +4 -0
  98. package/lib/language/pt-BR.min.js +1 -1
  99. package/lib/language/pt-BR.umd.js +4 -0
  100. package/lib/language/ru-RU.js +4 -0
  101. package/lib/language/ru-RU.min.js +1 -1
  102. package/lib/language/ru-RU.umd.js +4 -0
  103. package/lib/language/th-TH.js +4 -0
  104. package/lib/language/th-TH.min.js +1 -1
  105. package/lib/language/th-TH.umd.js +4 -0
  106. package/lib/language/ug-CN.js +4 -0
  107. package/lib/language/ug-CN.min.js +1 -1
  108. package/lib/language/ug-CN.umd.js +4 -0
  109. package/lib/language/uk-UA.js +4 -0
  110. package/lib/language/uk-UA.min.js +1 -1
  111. package/lib/language/uk-UA.umd.js +4 -0
  112. package/lib/language/uz-UZ.js +4 -0
  113. package/lib/language/uz-UZ.min.js +1 -1
  114. package/lib/language/uz-UZ.umd.js +4 -0
  115. package/lib/language/vi-VN.js +4 -0
  116. package/lib/language/vi-VN.min.js +1 -1
  117. package/lib/language/vi-VN.umd.js +4 -0
  118. package/lib/language/zh-CHT.js +4 -0
  119. package/lib/language/zh-CHT.min.js +1 -1
  120. package/lib/language/zh-CHT.umd.js +4 -0
  121. package/lib/language/zh-CN.js +4 -0
  122. package/lib/language/zh-CN.min.js +1 -1
  123. package/lib/language/zh-CN.umd.js +4 -0
  124. package/lib/radio/src/button.js +20 -3
  125. package/lib/radio/src/button.min.js +1 -1
  126. package/lib/radio/src/group.js +18 -1
  127. package/lib/radio/src/group.min.js +1 -1
  128. package/lib/radio/src/radio.js +20 -3
  129. package/lib/radio/src/radio.min.js +1 -1
  130. package/lib/radio/style/style.css +5 -3
  131. package/lib/radio/style/style.min.css +1 -1
  132. package/lib/style.css +1 -1
  133. package/lib/style.min.css +1 -1
  134. package/lib/switch/src/switch.js +15 -10
  135. package/lib/switch/src/switch.min.js +1 -1
  136. package/lib/tree/style/style.css +11 -6
  137. package/lib/tree/style/style.min.css +1 -1
  138. package/lib/ui/index.js +1 -1
  139. package/lib/ui/index.min.js +1 -1
  140. package/lib/ui/src/log.js +1 -1
  141. package/lib/ui/src/log.min.js +1 -1
  142. package/lib/vxe-checkbox/style/style.css +6 -3
  143. package/lib/vxe-checkbox/style/style.min.css +1 -1
  144. package/lib/vxe-radio/style/style.css +5 -3
  145. package/lib/vxe-radio/style/style.min.css +1 -1
  146. package/lib/vxe-tree/style/style.css +11 -6
  147. package/lib/vxe-tree/style/style.min.css +1 -1
  148. package/package.json +89 -89
  149. package/packages/alert/index.ts +16 -16
  150. package/packages/alert/src/alert.ts +106 -106
  151. package/packages/anchor/index.ts +16 -16
  152. package/packages/anchor/src/anchor-link.ts +158 -158
  153. package/packages/anchor/src/anchor.ts +267 -267
  154. package/packages/anchor/src/util.ts +23 -23
  155. package/packages/anchor-link/index.ts +16 -16
  156. package/packages/avatar/index.ts +16 -16
  157. package/packages/avatar/src/avatar.ts +141 -141
  158. package/packages/backtop/index.ts +16 -16
  159. package/packages/backtop/src/backtop.ts +330 -330
  160. package/packages/badge/index.ts +16 -16
  161. package/packages/badge/src/badge.ts +87 -87
  162. package/packages/breadcrumb/index.ts +16 -16
  163. package/packages/breadcrumb/src/breadcrumb-item.ts +118 -118
  164. package/packages/breadcrumb/src/breadcrumb.ts +89 -89
  165. package/packages/breadcrumb-item/index.ts +16 -16
  166. package/packages/button/index.ts +16 -16
  167. package/packages/button/src/button-group.ts +113 -113
  168. package/packages/button/src/button.ts +956 -956
  169. package/packages/button-group/index.ts +16 -16
  170. package/packages/calendar/index.ts +16 -16
  171. package/packages/calendar/src/calendar.ts +1527 -1527
  172. package/packages/card/index.ts +16 -16
  173. package/packages/card/src/card.ts +162 -162
  174. package/packages/carousel/index.ts +16 -16
  175. package/packages/carousel/src/carousel-item.ts +117 -117
  176. package/packages/carousel/src/carousel.ts +460 -460
  177. package/packages/carousel/src/util.ts +21 -21
  178. package/packages/carousel-item/index.ts +16 -16
  179. package/packages/cascader/index.ts +16 -16
  180. package/packages/cascader/src/cascader.ts +943 -943
  181. package/packages/checkbox/index.ts +16 -16
  182. package/packages/checkbox/src/button.ts +206 -185
  183. package/packages/checkbox/src/checkbox.ts +211 -189
  184. package/packages/checkbox/src/group.ts +282 -259
  185. package/packages/checkbox-button/index.ts +16 -16
  186. package/packages/checkbox-group/index.ts +16 -16
  187. package/packages/col/index.ts +16 -16
  188. package/packages/collapse/index.ts +16 -16
  189. package/packages/collapse/src/collapse-pane.ts +136 -136
  190. package/packages/collapse/src/collapse.ts +259 -259
  191. package/packages/collapse/src/util.ts +21 -21
  192. package/packages/collapse-pane/index.ts +16 -16
  193. package/packages/color-picker/index.ts +16 -16
  194. package/packages/color-picker/src/color-picker.ts +1286 -1286
  195. package/packages/color-picker/src/util.ts +198 -198
  196. package/packages/components.ts +307 -307
  197. package/packages/context-menu/index.ts +54 -54
  198. package/packages/context-menu/src/context-menu.ts +727 -727
  199. package/packages/countdown/index.ts +16 -16
  200. package/packages/countdown/src/countdown.ts +276 -276
  201. package/packages/date-panel/index.ts +16 -16
  202. package/packages/date-panel/src/date-panel.ts +2024 -2024
  203. package/packages/date-panel/src/util.ts +244 -244
  204. package/packages/date-picker/index.ts +17 -17
  205. package/packages/date-picker/src/date-picker.ts +1249 -1249
  206. package/packages/date-range-picker/index.ts +16 -16
  207. package/packages/date-range-picker/src/date-range-picker.ts +1480 -1480
  208. package/packages/drawer/index.ts +87 -87
  209. package/packages/drawer/src/drawer.ts +767 -767
  210. package/packages/dynamics/index.ts +127 -127
  211. package/packages/empty/index.ts +16 -16
  212. package/packages/empty/src/empty.ts +80 -80
  213. package/packages/form/index.ts +16 -16
  214. package/packages/form/render/index.ts +617 -617
  215. package/packages/form/src/form-config-item.ts +84 -84
  216. package/packages/form/src/form-group.ts +125 -125
  217. package/packages/form/src/form-item.ts +217 -217
  218. package/packages/form/src/form.ts +1032 -1032
  219. package/packages/form/src/itemInfo.ts +80 -80
  220. package/packages/form/src/render.ts +398 -398
  221. package/packages/form/src/util.ts +92 -92
  222. package/packages/form-gather/index.ts +18 -18
  223. package/packages/form-group/index.ts +16 -16
  224. package/packages/form-item/index.ts +16 -16
  225. package/packages/icon/index.ts +16 -16
  226. package/packages/icon/src/icon.ts +75 -75
  227. package/packages/icon-picker/index.ts +16 -16
  228. package/packages/icon-picker/src/icon-picker.ts +753 -753
  229. package/packages/image/index.ts +16 -16
  230. package/packages/image/src/group.ts +162 -162
  231. package/packages/image/src/image.ts +303 -303
  232. package/packages/image/src/preview.ts +737 -737
  233. package/packages/image/src/util.ts +62 -62
  234. package/packages/image-group/index.ts +16 -16
  235. package/packages/image-preview/index.ts +19 -19
  236. package/packages/index.ts +8 -8
  237. package/packages/input/index.ts +16 -16
  238. package/packages/input/src/input.ts +3187 -3187
  239. package/packages/language/ar-EG.ts +844 -840
  240. package/packages/language/de-DE.ts +844 -840
  241. package/packages/language/en-US.ts +844 -840
  242. package/packages/language/es-ES.ts +844 -840
  243. package/packages/language/fr-FR.ts +844 -840
  244. package/packages/language/hu-HU.ts +844 -840
  245. package/packages/language/hy-AM.ts +844 -840
  246. package/packages/language/id-ID.ts +844 -840
  247. package/packages/language/it-IT.ts +844 -840
  248. package/packages/language/ja-JP.ts +844 -840
  249. package/packages/language/ko-KR.ts +844 -840
  250. package/packages/language/ms-MY.ts +844 -840
  251. package/packages/language/nb-NO.ts +844 -840
  252. package/packages/language/pt-BR.ts +844 -840
  253. package/packages/language/ru-RU.ts +844 -840
  254. package/packages/language/th-TH.ts +844 -840
  255. package/packages/language/ug-CN.ts +844 -840
  256. package/packages/language/uk-UA.ts +844 -840
  257. package/packages/language/uz-UZ.ts +844 -840
  258. package/packages/language/vi-VN.ts +844 -840
  259. package/packages/language/zh-CHT.ts +844 -840
  260. package/packages/language/zh-CN.ts +844 -840
  261. package/packages/language/zh-HK.ts +3 -3
  262. package/packages/language/zh-MO.ts +3 -3
  263. package/packages/language/zh-TC.ts +3 -3
  264. package/packages/language/zh-TW.ts +3 -3
  265. package/packages/layout-aside/index.ts +16 -16
  266. package/packages/layout-aside/src/layout-aside.ts +115 -115
  267. package/packages/layout-body/index.ts +16 -16
  268. package/packages/layout-body/src/layout-body.ts +137 -137
  269. package/packages/layout-container/index.ts +16 -16
  270. package/packages/layout-container/src/layout-container.ts +65 -65
  271. package/packages/layout-footer/index.ts +16 -16
  272. package/packages/layout-footer/src/layout-footer.ts +53 -53
  273. package/packages/layout-header/index.ts +16 -16
  274. package/packages/layout-header/src/layout-header.ts +49 -49
  275. package/packages/link/index.ts +16 -16
  276. package/packages/link/src/link.ts +153 -153
  277. package/packages/list/index.ts +16 -16
  278. package/packages/list/src/list.ts +492 -492
  279. package/packages/loading/index.ts +34 -34
  280. package/packages/loading/src/loading.ts +162 -162
  281. package/packages/mention/index.ts +16 -16
  282. package/packages/mention/src/mention.ts +54 -54
  283. package/packages/menu/index.ts +16 -16
  284. package/packages/menu/src/menu.ts +632 -632
  285. package/packages/modal/index.ts +150 -150
  286. package/packages/modal/src/modal.ts +1668 -1668
  287. package/packages/notice-bar/index.ts +16 -16
  288. package/packages/notice-bar/src/notice-bar.ts +182 -182
  289. package/packages/number-input/index.ts +16 -16
  290. package/packages/number-input/src/number-input.ts +1255 -1255
  291. package/packages/number-input/src/util.ts +12 -12
  292. package/packages/optgroup/index.ts +16 -16
  293. package/packages/option/index.ts +16 -16
  294. package/packages/pager/index.ts +16 -16
  295. package/packages/pager/src/pager.ts +913 -913
  296. package/packages/password-input/index.ts +16 -16
  297. package/packages/password-input/src/password-input.ts +466 -466
  298. package/packages/print/index.ts +18 -18
  299. package/packages/print/src/page-break.ts +78 -78
  300. package/packages/print/src/print.ts +266 -266
  301. package/packages/print/src/util.ts +284 -284
  302. package/packages/print-page-break/index.ts +14 -14
  303. package/packages/pulldown/index.ts +16 -16
  304. package/packages/pulldown/src/pulldown.ts +533 -533
  305. package/packages/radio/index.ts +16 -16
  306. package/packages/radio/src/button.ts +242 -221
  307. package/packages/radio/src/group.ts +270 -252
  308. package/packages/radio/src/radio.ts +249 -228
  309. package/packages/radio-button/index.ts +16 -16
  310. package/packages/radio-group/index.ts +16 -16
  311. package/packages/rate/index.ts +16 -16
  312. package/packages/rate/src/rate.ts +199 -199
  313. package/packages/result/index.ts +16 -16
  314. package/packages/result/src/result.ts +93 -93
  315. package/packages/row/index.ts +16 -16
  316. package/packages/row/src/col.ts +130 -130
  317. package/packages/row/src/row.ts +106 -106
  318. package/packages/segmented/index.ts +16 -16
  319. package/packages/segmented/src/segmented.ts +281 -281
  320. package/packages/select/index.ts +16 -16
  321. package/packages/select/src/optgroup.ts +107 -107
  322. package/packages/select/src/option-info.ts +20 -20
  323. package/packages/select/src/option.ts +103 -103
  324. package/packages/select/src/select.ts +2001 -2001
  325. package/packages/select/src/util.ts +47 -47
  326. package/packages/slider/index.ts +16 -16
  327. package/packages/slider/src/slider.ts +332 -332
  328. package/packages/split/index.ts +16 -16
  329. package/packages/split-pane/index.ts +17 -17
  330. package/packages/splitter/index.ts +16 -16
  331. package/packages/splitter/src/splitter-panel.ts +171 -171
  332. package/packages/splitter/src/splitter.ts +1032 -1032
  333. package/packages/splitter/src/util.ts +21 -21
  334. package/packages/splitter-panel/index.ts +16 -16
  335. package/packages/steps/index.ts +16 -16
  336. package/packages/steps/src/steps.ts +57 -57
  337. package/packages/switch/index.ts +16 -16
  338. package/packages/switch/src/switch.ts +287 -279
  339. package/packages/tab-pane/index.ts +16 -16
  340. package/packages/table-select/index.ts +16 -16
  341. package/packages/table-select/src/table-select.ts +904 -904
  342. package/packages/tabs/index.ts +16 -16
  343. package/packages/tabs/src/tab-pane.ts +137 -137
  344. package/packages/tabs/src/tabs.ts +1014 -1014
  345. package/packages/tabs/src/util.ts +21 -21
  346. package/packages/tag/index.ts +16 -16
  347. package/packages/tag/src/tag.ts +195 -195
  348. package/packages/text/index.ts +16 -16
  349. package/packages/text/src/text.ts +267 -267
  350. package/packages/text-ellipsis/index.ts +16 -16
  351. package/packages/text-ellipsis/src/text-ellipsis.ts +291 -291
  352. package/packages/textarea/index.ts +16 -16
  353. package/packages/textarea/src/textarea.ts +436 -436
  354. package/packages/timeline/index.ts +16 -16
  355. package/packages/timeline/src/timeline-item.ts +41 -41
  356. package/packages/timeline/src/timeline.ts +54 -54
  357. package/packages/timeline-item/index.ts +16 -16
  358. package/packages/tip/index.ts +19 -19
  359. package/packages/tip/src/tip.ts +112 -112
  360. package/packages/tooltip/index.ts +16 -16
  361. package/packages/tooltip/src/tooltip.ts +669 -669
  362. package/packages/tour/index.ts +16 -16
  363. package/packages/tour/src/tour.ts +54 -54
  364. package/packages/tree/index.ts +16 -16
  365. package/packages/tree/src/store.ts +15 -15
  366. package/packages/tree/src/tree.ts +3122 -3122
  367. package/packages/tree/src/util.ts +44 -44
  368. package/packages/tree-select/index.ts +16 -16
  369. package/packages/tree-select/src/tree-select.ts +1118 -1118
  370. package/packages/ui/index.ts +697 -697
  371. package/packages/ui/src/anime.ts +52 -52
  372. package/packages/ui/src/comp.ts +3 -3
  373. package/packages/ui/src/dom.ts +279 -279
  374. package/packages/ui/src/log.ts +6 -6
  375. package/packages/ui/src/utils.ts +49 -49
  376. package/packages/ui/src/vn.ts +60 -60
  377. package/packages/upload/index.ts +20 -20
  378. package/packages/upload/src/upload.ts +2129 -2129
  379. package/packages/upload/src/util.ts +109 -109
  380. package/packages/vxe-u-i/index.ts +4 -4
  381. package/packages/watermark/index.ts +31 -31
  382. package/packages/watermark/src/util.ts +176 -176
  383. package/packages/watermark/src/watermark.ts +166 -166
  384. package/styles/all.scss +90 -90
  385. package/styles/base.scss +16 -16
  386. package/styles/components/alert.scss +101 -101
  387. package/styles/components/anchor.scss +44 -44
  388. package/styles/components/avatar.scss +115 -115
  389. package/styles/components/backtop.scss +82 -82
  390. package/styles/components/badge.scss +45 -45
  391. package/styles/components/breadcrumb.scss +29 -29
  392. package/styles/components/button-group.scss +30 -30
  393. package/styles/components/button.scss +415 -415
  394. package/styles/components/calendar.scss +471 -471
  395. package/styles/components/card.scss +121 -121
  396. package/styles/components/carousel.scss +184 -184
  397. package/styles/components/cascader.scss +140 -140
  398. package/styles/components/checkbox-button.scss +57 -57
  399. package/styles/components/checkbox.scss +81 -81
  400. package/styles/components/collapse.scss +56 -56
  401. package/styles/components/color-picker.scss +409 -409
  402. package/styles/components/context-menu.scss +102 -102
  403. package/styles/components/countdown.scss +35 -35
  404. package/styles/components/date-panel.scss +505 -505
  405. package/styles/components/date-picker.scss +247 -247
  406. package/styles/components/date-range-picker.scss +252 -252
  407. package/styles/components/drawer.scss +298 -298
  408. package/styles/components/empty.scss +79 -79
  409. package/styles/components/form.scss +668 -668
  410. package/styles/components/icon-picker.scss +211 -211
  411. package/styles/components/icon.scss +1048 -1048
  412. package/styles/components/image-group.scss +2 -2
  413. package/styles/components/image-preview.scss +215 -215
  414. package/styles/components/image.scss +16 -16
  415. package/styles/components/input.scss +846 -846
  416. package/styles/components/layout-aside.scss +22 -22
  417. package/styles/components/layout-body.scss +14 -14
  418. package/styles/components/layout-container.scss +13 -13
  419. package/styles/components/layout-footer.scss +14 -14
  420. package/styles/components/layout-header.scss +11 -11
  421. package/styles/components/link.scss +115 -115
  422. package/styles/components/list.scss +40 -40
  423. package/styles/components/loading.scss +137 -137
  424. package/styles/components/menu.scss +150 -150
  425. package/styles/components/modal.scss +480 -480
  426. package/styles/components/notice-bar.scss +91 -91
  427. package/styles/components/number-input.scss +283 -283
  428. package/styles/components/old-icon.scss +4 -4
  429. package/styles/components/pager.scss +282 -282
  430. package/styles/components/password-input.scss +374 -374
  431. package/styles/components/print.scss +3 -3
  432. package/styles/components/pulldown.scss +75 -75
  433. package/styles/components/radio-button.scss +57 -57
  434. package/styles/components/radio.scss +79 -79
  435. package/styles/components/rate.scss +76 -76
  436. package/styles/components/result.scss +91 -91
  437. package/styles/components/row.scss +69 -69
  438. package/styles/components/segmented.scss +215 -215
  439. package/styles/components/select.scss +244 -244
  440. package/styles/components/slider.scss +139 -139
  441. package/styles/components/split.scss +1 -1
  442. package/styles/components/splitter.scss +318 -318
  443. package/styles/components/switch.scss +128 -128
  444. package/styles/components/table-select.scss +105 -105
  445. package/styles/components/tabs.scss +745 -745
  446. package/styles/components/tag.scss +184 -184
  447. package/styles/components/text-ellipsis.scss +130 -130
  448. package/styles/components/text.scss +123 -123
  449. package/styles/components/textarea.scss +106 -106
  450. package/styles/components/tip.scss +97 -97
  451. package/styles/components/tooltip.scss +141 -141
  452. package/styles/components/tree-select.scss +166 -166
  453. package/styles/components/tree.scss +294 -294
  454. package/styles/components/upload.scss +497 -497
  455. package/styles/components/watermark.scss +26 -26
  456. package/styles/helpers/baseMixin.scss +104 -95
  457. package/styles/helpers/baseVar.scss +3 -3
  458. package/styles/helpers/placement.scss +38 -38
  459. package/styles/theme/base.scss +214 -214
  460. package/styles/theme/dark.scss +119 -119
  461. package/styles/theme/light.scss +118 -118
  462. package/styles/variable.scss +111 -111
  463. package/types/all.d.ts +328 -328
  464. package/types/components/alert.d.ts +80 -80
  465. package/types/components/anchor-link.d.ts +84 -84
  466. package/types/components/anchor.d.ts +84 -84
  467. package/types/components/avatar.d.ts +81 -81
  468. package/types/components/backtop.d.ts +115 -115
  469. package/types/components/badge.d.ts +69 -69
  470. package/types/components/breadcrumb-item.d.ts +73 -73
  471. package/types/components/breadcrumb.d.ts +80 -80
  472. package/types/components/button-group.d.ts +113 -113
  473. package/types/components/button.d.ts +314 -314
  474. package/types/components/calendar.d.ts +254 -254
  475. package/types/components/card.d.ts +86 -86
  476. package/types/components/carousel-item.d.ts +68 -68
  477. package/types/components/carousel.d.ts +126 -126
  478. package/types/components/cascader.d.ts +250 -250
  479. package/types/components/checkbox-button.d.ts +93 -93
  480. package/types/components/checkbox-group.d.ts +138 -135
  481. package/types/components/checkbox.d.ts +115 -115
  482. package/types/components/col.d.ts +73 -73
  483. package/types/components/colgroup.d.ts +131 -131
  484. package/types/components/collapse-pane.d.ts +82 -82
  485. package/types/components/collapse.d.ts +115 -115
  486. package/types/components/color-picker.d.ts +164 -164
  487. package/types/components/column.d.ts +852 -852
  488. package/types/components/context-menu.d.ts +301 -301
  489. package/types/components/countdown.d.ts +99 -99
  490. package/types/components/date-panel.d.ts +269 -269
  491. package/types/components/date-picker.d.ts +322 -322
  492. package/types/components/date-range-picker.d.ts +336 -336
  493. package/types/components/drawer.d.ts +295 -295
  494. package/types/components/empty.d.ts +71 -71
  495. package/types/components/flow-design.d.ts +78 -78
  496. package/types/components/flow-view.d.ts +78 -78
  497. package/types/components/form-design.d.ts +364 -364
  498. package/types/components/form-gather.d.ts +72 -72
  499. package/types/components/form-group.d.ts +63 -63
  500. package/types/components/form-item.d.ts +405 -405
  501. package/types/components/form-view.d.ts +175 -175
  502. package/types/components/form.d.ts +463 -463
  503. package/types/components/gantt-module/gantt-view.d.ts +171 -171
  504. package/types/components/gantt-module/index.d.ts +1 -1
  505. package/types/components/gantt-plugins/extend-gantt-chart.d.ts +132 -132
  506. package/types/components/gantt-plugins/index.d.ts +1 -1
  507. package/types/components/gantt.d.ts +1201 -1201
  508. package/types/components/grid.d.ts +1038 -1038
  509. package/types/components/icon-picker.d.ts +185 -185
  510. package/types/components/icon.d.ts +80 -80
  511. package/types/components/image-group.d.ts +120 -120
  512. package/types/components/image-preview.d.ts +159 -159
  513. package/types/components/image.d.ts +166 -166
  514. package/types/components/input.d.ts +425 -425
  515. package/types/components/layout-aside.d.ts +73 -73
  516. package/types/components/layout-body.d.ts +84 -84
  517. package/types/components/layout-container.d.ts +66 -66
  518. package/types/components/layout-footer.d.ts +66 -66
  519. package/types/components/layout-header.d.ts +64 -64
  520. package/types/components/link.d.ts +104 -104
  521. package/types/components/list-design.d.ts +177 -177
  522. package/types/components/list-view.d.ts +190 -190
  523. package/types/components/list.d.ts +196 -196
  524. package/types/components/loading.d.ts +96 -96
  525. package/types/components/mention.d.ts +70 -70
  526. package/types/components/menu.d.ts +203 -203
  527. package/types/components/modal.d.ts +540 -540
  528. package/types/components/notice-bar.d.ts +95 -95
  529. package/types/components/number-input.d.ts +300 -300
  530. package/types/components/optgroup.d.ts +81 -81
  531. package/types/components/option.d.ts +95 -95
  532. package/types/components/pager.d.ts +322 -322
  533. package/types/components/password-input.d.ts +129 -129
  534. package/types/components/print-page-break.d.ts +62 -62
  535. package/types/components/print.d.ts +199 -199
  536. package/types/components/pulldown.d.ts +226 -226
  537. package/types/components/radio-button.d.ts +104 -104
  538. package/types/components/radio-group.d.ts +139 -136
  539. package/types/components/radio.d.ts +121 -121
  540. package/types/components/rate.d.ts +75 -75
  541. package/types/components/result.d.ts +77 -77
  542. package/types/components/row.d.ts +72 -72
  543. package/types/components/segmented.d.ts +117 -117
  544. package/types/components/select.d.ts +519 -519
  545. package/types/components/slider.d.ts +117 -117
  546. package/types/components/split-pane.d.ts +135 -135
  547. package/types/components/split.d.ts +318 -318
  548. package/types/components/splitter-panel.d.ts +98 -98
  549. package/types/components/splitter.d.ts +283 -283
  550. package/types/components/steps.d.ts +61 -61
  551. package/types/components/switch.d.ts +124 -124
  552. package/types/components/tab-pane.d.ts +107 -107
  553. package/types/components/table-module/custom.d.ts +115 -115
  554. package/types/components/table-module/edit.d.ts +245 -245
  555. package/types/components/table-module/export.d.ts +96 -96
  556. package/types/components/table-module/filter.d.ts +140 -140
  557. package/types/components/table-module/index.d.ts +7 -7
  558. package/types/components/table-module/keyboard.d.ts +26 -26
  559. package/types/components/table-module/menu.d.ts +26 -26
  560. package/types/components/table-module/validator.d.ts +53 -53
  561. package/types/components/table-plugins/extend-cell-area.d.ts +768 -768
  562. package/types/components/table-plugins/extend-pivot-table.d.ts +68 -68
  563. package/types/components/table-plugins/filters-combination.d.ts +15 -15
  564. package/types/components/table-plugins/filters-complex-input.d.ts +9 -9
  565. package/types/components/table-plugins/index.d.ts +4 -4
  566. package/types/components/table-select.d.ts +216 -216
  567. package/types/components/table.d.ts +7496 -7496
  568. package/types/components/tabs.d.ts +324 -324
  569. package/types/components/tag.d.ts +107 -107
  570. package/types/components/text-ellipsis.d.ts +105 -105
  571. package/types/components/text.d.ts +115 -115
  572. package/types/components/textarea.d.ts +237 -237
  573. package/types/components/timeline-item.d.ts +68 -68
  574. package/types/components/timeline.d.ts +70 -70
  575. package/types/components/tip.d.ts +76 -76
  576. package/types/components/toolbar.d.ts +329 -329
  577. package/types/components/tooltip.d.ts +169 -169
  578. package/types/components/tour.d.ts +70 -70
  579. package/types/components/tree-select.d.ts +299 -299
  580. package/types/components/tree.d.ts +836 -836
  581. package/types/components/upload.d.ts +432 -432
  582. package/types/components/watermark.d.ts +113 -113
  583. package/types/index.d.ts +4 -4
  584. package/types/ui/commands.d.ts +57 -57
  585. package/types/ui/formats.d.ts +62 -62
  586. package/types/ui/global-config.d.ts +254 -254
  587. package/types/ui/global-icon.d.ts +292 -292
  588. package/types/ui/hooks.d.ts +11 -11
  589. package/types/ui/index.d.ts +95 -95
  590. package/types/ui/interceptor.d.ts +54 -54
  591. package/types/ui/menus.d.ts +77 -77
  592. package/types/ui/renderer.d.ts +1042 -1042
  593. package/types/ui/validators.d.ts +38 -38
  594. /package/es/icon/{iconfont.1778317204332.ttf → iconfont.1778465052628.ttf} +0 -0
  595. /package/es/icon/{iconfont.1778317204332.woff → iconfont.1778465052628.woff} +0 -0
  596. /package/es/icon/{iconfont.1778317204332.woff2 → iconfont.1778465052628.woff2} +0 -0
  597. /package/es/{iconfont.1778317204332.ttf → iconfont.1778465052628.ttf} +0 -0
  598. /package/es/{iconfont.1778317204332.woff → iconfont.1778465052628.woff} +0 -0
  599. /package/es/{iconfont.1778317204332.woff2 → iconfont.1778465052628.woff2} +0 -0
  600. /package/lib/icon/style/{iconfont.1778317204332.ttf → iconfont.1778465052628.ttf} +0 -0
  601. /package/lib/icon/style/{iconfont.1778317204332.woff → iconfont.1778465052628.woff} +0 -0
  602. /package/lib/icon/style/{iconfont.1778317204332.woff2 → iconfont.1778465052628.woff2} +0 -0
  603. /package/lib/{iconfont.1778317204332.ttf → iconfont.1778465052628.ttf} +0 -0
  604. /package/lib/{iconfont.1778317204332.woff → iconfont.1778465052628.woff} +0 -0
  605. /package/lib/{iconfont.1778317204332.woff2 → iconfont.1778465052628.woff2} +0 -0
@@ -1,1032 +1,1032 @@
1
- import { PropType, CreateElement, VNode } from 'vue'
2
- import { defineVxeComponent } from '../../ui/src/comp'
3
- import XEUtils from 'xe-utils'
4
- import { getConfig, validators, renderer, createEvent, globalMixins, globalEvents } from '../../ui'
5
- import { eqEmptyValue, getFuncText, isEnableConf } from '../../ui/src/utils'
6
- import { scrollToView } from '../../ui/src/dom'
7
- import { createItem, handleFieldOrItem, isHiddenItem, isActiveItem } from './util'
8
- import VxeTooltipComponent from '../../tooltip'
9
- import VxeFormConfigItem from './form-config-item'
10
- import VxeLoadingComponent from '../../loading'
11
- import { getSlotVNs } from '../../ui/src/vn'
12
- import { warnLog, errLog } from '../../ui/src/log'
13
-
14
- import '../render'
15
-
16
- import type { VxeFormPropTypes, VxeFormEmits, VxeComponentSizeType, ValueOf, FormReactData, VxeFormDefines, VxeFormItemPropTypes, FormInternalData, VxeTooltipConstructor } from '../../../types'
17
- import type { VxeGridConstructor, VxeGridPrivateMethods } from '../../../types/components/grid'
18
-
19
- class Rule {
20
- constructor (rule: any) {
21
- Object.assign(this, {
22
- $options: rule,
23
- required: rule.required,
24
- min: rule.min,
25
- max: rule.min,
26
- type: rule.type,
27
- pattern: rule.pattern,
28
- validator: rule.validator,
29
- trigger: rule.trigger,
30
- maxWidth: rule.maxWidth
31
- })
32
- }
33
-
34
- get content () {
35
- return getFuncText(this.$options.content || this.$options.message)
36
- }
37
-
38
- get message () {
39
- return this.content
40
- }
41
-
42
- [key: string]: any
43
- }
44
-
45
- // 如果存在 pattern,判断正则
46
- function validREValue (pattern: string | RegExp | undefined, val: string) {
47
- if (pattern && !(XEUtils.isRegExp(pattern) ? pattern : new RegExp(pattern)).test(val)) {
48
- return false
49
- }
50
- return true
51
- }
52
-
53
- // 如果存在 max,判断最大值
54
- function validMaxValue (max: string | number | undefined, num: number) {
55
- if (!XEUtils.eqNull(max) && num > XEUtils.toNumber(max)) {
56
- return false
57
- }
58
- return true
59
- }
60
-
61
- // 如果存在 min,判断最小值
62
- function validMinValue (min: string | number | undefined, num: number) {
63
- if (!XEUtils.eqNull(min) && num < XEUtils.toNumber(min)) {
64
- return false
65
- }
66
- return true
67
- }
68
-
69
- function validRuleValue (rule: VxeFormDefines.FormRule, val: any, required: boolean | undefined) {
70
- const { type, min, max, pattern } = rule
71
- const isArrType = type === 'array'
72
- const isNumType = type === 'number'
73
- const isStrType = type === 'string'
74
- const strVal = `${val}`
75
- if (!validREValue(pattern, strVal)) {
76
- return false
77
- }
78
- if (isArrType) {
79
- if (!XEUtils.isArray(val)) {
80
- return false
81
- }
82
- if (required) {
83
- if (!val.length) {
84
- return false
85
- }
86
- }
87
- if (!validMinValue(min, val.length)) {
88
- return false
89
- }
90
- if (!validMaxValue(max, val.length)) {
91
- return false
92
- }
93
- } else if (isNumType) {
94
- const numVal = Number(val)
95
- if (isNaN(numVal)) {
96
- return false
97
- }
98
- if (!validMinValue(min, numVal)) {
99
- return false
100
- }
101
- if (!validMaxValue(max, numVal)) {
102
- return false
103
- }
104
- } else {
105
- if (isStrType) {
106
- if (!XEUtils.isString(val)) {
107
- return false
108
- }
109
- }
110
- if (required) {
111
- if (!strVal) {
112
- return false
113
- }
114
- }
115
- if (!validMinValue(min, strVal.length)) {
116
- return false
117
- }
118
- if (!validMaxValue(max, strVal.length)) {
119
- return false
120
- }
121
- }
122
- return true
123
- }
124
-
125
- function checkRuleStatus (rule: VxeFormDefines.FormRule, data: any, val: any) {
126
- const { required, field } = rule
127
- const currVal = field ? XEUtils.get(data, field) : val
128
- const isEmptyVal = XEUtils.isArray(currVal) ? !currVal.length : eqEmptyValue(currVal)
129
- if (required) {
130
- if (isEmptyVal) {
131
- return false
132
- }
133
- if (!validRuleValue(rule, currVal, required)) {
134
- return false
135
- }
136
- } else {
137
- if (!isEmptyVal) {
138
- if (!validRuleValue(rule, currVal, required)) {
139
- return false
140
- }
141
- }
142
- }
143
- return true
144
- }
145
-
146
- function createInternalData (): FormInternalData {
147
- return {
148
- meTimeout: undefined,
149
- stTimeout: undefined,
150
- tooltipStore: {
151
- item: null,
152
- visible: false
153
- },
154
- itemFormatCache: {}
155
- }
156
- }
157
-
158
- export default /* define-vxe-component start */ defineVxeComponent({
159
- name: 'VxeForm',
160
- mixins: [
161
- globalMixins.sizeMixin
162
- ],
163
- props: {
164
- collapseStatus: {
165
- type: Boolean as PropType<VxeFormPropTypes.CollapseStatus>,
166
- default: true
167
- },
168
- loading: Boolean as PropType<VxeFormPropTypes.Loading>,
169
- data: Object as PropType<VxeFormPropTypes.Data>,
170
- size: {
171
- type: String as PropType<VxeFormPropTypes.Size>,
172
- default: () => getConfig().form.size || getConfig().size
173
- },
174
- span: {
175
- type: [String, Number] as PropType<VxeFormPropTypes.Span>,
176
- default: () => getConfig().form.span
177
- },
178
- align: {
179
- type: String as PropType<VxeFormPropTypes.Align>,
180
- default: () => getConfig().form.align
181
- },
182
- verticalAlign: {
183
- type: String as PropType<VxeFormPropTypes.VerticalAlign>,
184
- default: () => getConfig().form.verticalAlign
185
- },
186
- border: {
187
- type: Boolean as PropType<VxeFormPropTypes.Border>,
188
- default: () => getConfig().form.border
189
- },
190
- titleBackground: {
191
- type: Boolean as PropType<VxeFormPropTypes.TitleBackground>,
192
- default: () => getConfig().form.titleBackground
193
- },
194
- titleBold: {
195
- type: Boolean as PropType<VxeFormPropTypes.TitleBold>,
196
- default: () => getConfig().form.titleBold
197
- },
198
- titleAlign: {
199
- type: String as PropType<VxeFormPropTypes.TitleAlign>,
200
- default: () => getConfig().form.titleAlign
201
- },
202
- titleWidth: {
203
- type: [String, Number] as PropType<VxeFormPropTypes.TitleWidth>,
204
- default: () => getConfig().form.titleWidth
205
- },
206
- titleColon: {
207
- type: Boolean as PropType<VxeFormPropTypes.TitleColon>,
208
- default: () => getConfig().form.titleColon
209
- },
210
- titleAsterisk: {
211
- type: Boolean as PropType<VxeFormPropTypes.TitleAsterisk>,
212
- default: () => getConfig().form.titleAsterisk
213
- },
214
- titleOverflow: {
215
- type: [Boolean, String] as PropType<VxeFormPropTypes.TitleOverflow>,
216
- default: () => getConfig().form.titleOverflow
217
- },
218
- vertical: {
219
- type: Boolean as PropType<VxeFormPropTypes.Vertical>,
220
- default: () => getConfig().form.vertical
221
- },
222
- padding: {
223
- type: Boolean as PropType<VxeFormPropTypes.Padding>,
224
- default: () => getConfig().form.padding
225
- },
226
- className: [String, Function] as PropType<VxeFormPropTypes.ClassName>,
227
- readonly: Boolean as PropType<VxeFormPropTypes.Readonly>,
228
- disabled: Boolean as PropType<VxeFormPropTypes.Disabled>,
229
- items: Array as PropType<VxeFormPropTypes.Items>,
230
- rules: Object as PropType<VxeFormPropTypes.Rules>,
231
- preventSubmit: {
232
- type: Boolean as PropType<VxeFormPropTypes.PreventSubmit>,
233
- default: () => getConfig().form.preventSubmit
234
- },
235
- validConfig: Object as PropType<VxeFormPropTypes.ValidConfig>,
236
- tooltipConfig: Object as PropType<VxeFormPropTypes.TooltipConfig>,
237
- collapseConfig: Object as PropType<VxeFormPropTypes.CollapseConfig>,
238
- customLayout: {
239
- type: Boolean as PropType<VxeFormPropTypes.CustomLayout>,
240
- default: () => getConfig().form.customLayout
241
- },
242
- params: Object as PropType<VxeFormPropTypes.Params>
243
- },
244
- inject: {
245
- $xeGrid: {
246
- default: null
247
- }
248
- },
249
- provide () {
250
- const $xeForm = this
251
- return {
252
- $xeForm,
253
- xeFormItemInfo: null,
254
- $xeFormGroup: null,
255
- $xeFormItem: null
256
- }
257
- },
258
- data () {
259
- const xID = XEUtils.uniqueId()
260
- const reactData: FormReactData = {
261
- collapseAll: false,
262
- staticItems: [],
263
- formItems: [],
264
- itemWidth: 0
265
- }
266
- const internalData = createInternalData()
267
- return {
268
- xID,
269
- reactData,
270
- internalData,
271
-
272
- recalcFlag: 0
273
- }
274
- },
275
- computed: {
276
- ...({} as {
277
- computeSize(): VxeComponentSizeType
278
- $xeGrid(): (VxeGridConstructor & VxeGridPrivateMethods) | null
279
- }),
280
- computeValidOpts () {
281
- const $xeForm = this
282
- const props = $xeForm
283
-
284
- return Object.assign({}, getConfig().form.validConfig, props.validConfig)
285
- },
286
- computeTooltipOpts () {
287
- const $xeForm = this
288
- const props = $xeForm
289
-
290
- return Object.assign({}, getConfig().tooltip, getConfig().form.tooltipConfig, props.tooltipConfig)
291
- },
292
- computeCollapseOpts () {
293
- const $xeForm = this
294
- const props = $xeForm
295
-
296
- return Object.assign({}, getConfig().form.collapseConfig, props.collapseConfig)
297
- },
298
- computeAutoItemWidthList () {
299
- const $xeForm = this
300
- const props = $xeForm
301
- const reactData = $xeForm.reactData
302
-
303
- const { titleWidth: allTitleWidth, vertical: allVertical } = props
304
- const { formItems } = reactData
305
- const itemList: VxeFormDefines.ItemInfo[] = []
306
- XEUtils.eachTree(formItems, (item) => {
307
- const { titleWidth, vertical } = item
308
- if (titleWidth === 'auto') {
309
- itemList.push(item)
310
- } else {
311
- const itemVertical = XEUtils.eqNull(vertical) ? allVertical : vertical
312
- const itemTitleWidth = itemVertical ? null : (XEUtils.eqNull(titleWidth) ? allTitleWidth : titleWidth)
313
- if (itemTitleWidth === 'auto' && (!item.children || !item.children.length)) {
314
- itemList.push(item)
315
- }
316
- }
317
- }, { children: 'children' })
318
- return itemList
319
- }
320
- },
321
- methods: {
322
- //
323
- // Method
324
- //
325
- dispatchEvent (type: ValueOf<VxeFormEmits>, params: Record<string, any>, evnt: Event | null) {
326
- const $xeForm = this
327
- $xeForm.$emit(type, createEvent(evnt, { $form: $xeForm }, params))
328
- },
329
- callSlot (slotFunc: ((params: any, h: CreateElement) => any) | string | null, params: any, h: CreateElement) {
330
- const $xeForm = this
331
- const slots = $xeForm.$scopedSlots
332
-
333
- if (slotFunc) {
334
- if (XEUtils.isString(slotFunc)) {
335
- slotFunc = slots[slotFunc] || null
336
- }
337
- if (XEUtils.isFunction(slotFunc)) {
338
- return getSlotVNs(slotFunc.call($xeForm, params, h))
339
- }
340
- }
341
- return []
342
- },
343
- loadItem (list: VxeFormPropTypes.Items) {
344
- const $xeForm = this
345
- const slots = $xeForm.$scopedSlots
346
- const reactData = $xeForm.reactData
347
- const internalData = $xeForm.internalData
348
-
349
- if (list.length) {
350
- list.forEach((item) => {
351
- if (item.slots) {
352
- XEUtils.each(item.slots, (func) => {
353
- if (!XEUtils.isFunction(func)) {
354
- if (!slots[func]) {
355
- errLog('vxe.error.notSlot', [`[form] ${func}`])
356
- }
357
- }
358
- })
359
- }
360
- })
361
- }
362
- reactData.staticItems = XEUtils.mapTree(list, item => createItem($xeForm, item), { children: 'children' })
363
- internalData.itemFormatCache = {}
364
- return $xeForm.$nextTick().then(() => {
365
- return $xeForm.recalculate()
366
- })
367
- },
368
- getItems () {
369
- const $xeForm = this
370
- const reactData = $xeForm.reactData
371
-
372
- const itemList: VxeFormDefines.ItemInfo[] = []
373
- XEUtils.eachTree(reactData.formItems, item => {
374
- itemList.push(item)
375
- }, { children: 'children' })
376
- return itemList
377
- },
378
- getItemByField (field: string) {
379
- const $xeForm = this
380
- const reactData = $xeForm.reactData
381
-
382
- const rest = XEUtils.findTree(reactData.formItems, item => item.field === field, { children: 'children' })
383
- return rest ? rest.item : null
384
- },
385
- getCollapseStatus () {
386
- const $xeForm = this
387
- const reactData = $xeForm.reactData
388
-
389
- return reactData.collapseAll
390
- },
391
- toggleCollapse () {
392
- const $xeForm = this
393
- const reactData = $xeForm.reactData
394
-
395
- const status = !$xeForm.getCollapseStatus()
396
- reactData.collapseAll = status
397
- $xeForm.$emit('update:collapseStatus', status)
398
- return $xeForm.$nextTick()
399
- },
400
- toggleCollapseEvent (evnt: Event) {
401
- const $xeForm = this
402
- const props = $xeForm
403
- const $xeGrid = $xeForm.$xeGrid
404
-
405
- const actionRest = $xeForm.toggleCollapse()
406
- const status = $xeForm.getCollapseStatus()
407
- $xeForm.dispatchEvent('toggle-collapse', { status, collapse: status, data: props.data }, evnt)
408
- $xeForm.dispatchEvent('collapse', { status, collapse: status, data: props.data }, evnt)
409
- actionRest.then(() => {
410
- $xeForm.recalculate().then(() => {
411
- if ($xeGrid) {
412
- $xeGrid.recalculate(true)
413
- }
414
- })
415
- if ($xeGrid) {
416
- $xeGrid.recalculate()
417
- }
418
- })
419
- },
420
- clearValidate (fieldOrItem?: VxeFormItemPropTypes.Field | VxeFormItemPropTypes.Field[] | VxeFormDefines.ItemInfo | VxeFormDefines.ItemInfo[]) {
421
- const $xeForm = this
422
-
423
- if (fieldOrItem) {
424
- let fields: any = fieldOrItem
425
- if (!XEUtils.isArray(fieldOrItem)) {
426
- fields = [fieldOrItem]
427
- }
428
- fields.forEach((field: any) => {
429
- if (field) {
430
- const item = handleFieldOrItem($xeForm, field)
431
- if (item) {
432
- item.showError = false
433
- item.showIconMsg = false
434
- }
435
- }
436
- })
437
- } else {
438
- $xeForm.getItems().forEach((item) => {
439
- item.showError = false
440
- item.showIconMsg = false
441
- })
442
- }
443
- return $xeForm.$nextTick()
444
- },
445
- getResetValue (item: VxeFormDefines.ItemInfo, data: any, itemValue: any) {
446
- const $xeForm = this
447
- const $xeGrid = $xeForm.$xeGrid
448
-
449
- const { field, resetValue } = item
450
- if (XEUtils.isFunction(resetValue)) {
451
- return resetValue({ field, item, data, $form: $xeForm, $grid: $xeGrid })
452
- } else if (resetValue === null) {
453
- // 默认
454
- if (XEUtils.isArray(itemValue)) {
455
- return []
456
- }
457
- }
458
- return resetValue
459
- },
460
- reset () {
461
- const $xeForm = this
462
- const props = $xeForm
463
- const $xeGrid = $xeForm.$xeGrid
464
- const internalData = $xeForm.internalData
465
-
466
- const { data } = props
467
- const itemList = $xeForm.getItems()
468
- if (data) {
469
- itemList.forEach((item) => {
470
- const { field, itemRender } = item
471
- if (isEnableConf(itemRender)) {
472
- const { name, startField, endField } = itemRender
473
- const compConf = renderer.get(name)
474
- const fiResetMethod = compConf ? (compConf.formItemResetMethod || compConf.itemResetMethod) : null
475
- if (compConf && fiResetMethod) {
476
- fiResetMethod({ data, field, property: field, item, $form: $xeForm, $grid: $xeGrid })
477
- } else if (field) {
478
- const itemValue = XEUtils.get(data, field)
479
- XEUtils.set(data, field, $xeForm.getResetValue(item, data, itemValue))
480
- }
481
- if (startField && endField) {
482
- XEUtils.set(data, startField, $xeForm.getResetValue(item, data, XEUtils.get(data, startField)))
483
- XEUtils.set(data, endField, $xeForm.getResetValue(item, data, XEUtils.get(data, endField)))
484
- }
485
- }
486
- })
487
- }
488
- internalData.itemFormatCache = {}
489
- $xeForm.clearValidate()
490
- return $xeForm.recalculate()
491
- },
492
- resetEvent (evnt: Event) {
493
- const $xeForm = this
494
- const props = $xeForm
495
-
496
- evnt.preventDefault()
497
- $xeForm.reset()
498
- $xeForm.dispatchEvent('reset', { data: props.data }, evnt)
499
- },
500
- handleFocus (fields: string[]) {
501
- const $xeForm = this
502
- const props = $xeForm
503
- const $xeGrid = $xeForm.$xeGrid
504
-
505
- const el = $xeForm.$refs.refElem as HTMLFormElement
506
- if (el) {
507
- for (let i = 0; i < fields.length; i++) {
508
- const field = fields[i]
509
- const item = $xeForm.getItemByField(field)
510
- if (item && isEnableConf(item.itemRender)) {
511
- const { itemRender } = item
512
- const compConf = renderer.get(itemRender.name)
513
- // 定位到第一个
514
- if (!i) {
515
- scrollToView(el.querySelector(`.${item.id}`))
516
- }
517
- let inputElem: HTMLElement | null = null
518
- const autoFocus = itemRender.autoFocus || itemRender.autofocus || (compConf ? compConf.formItemAutoFocus : null)
519
- // 如果指定了聚焦 class
520
- if (XEUtils.isFunction(autoFocus)) {
521
- inputElem = autoFocus({ $form: $xeForm, $grid: $xeGrid, item, data: props.data, field })
522
- } else {
523
- if (autoFocus === true) {
524
- // 自动匹配模式,会自动匹配第一个可输入元素
525
- inputElem = el.querySelector(`.${item.id} input,textarea`)
526
- } else if (autoFocus) {
527
- inputElem = el.querySelector(`.${item.id} ${autoFocus}`) as HTMLInputElement
528
- }
529
- }
530
- if (inputElem) {
531
- inputElem.focus()
532
- break
533
- }
534
- }
535
- }
536
- }
537
- },
538
- /**
539
- * 校验数据
540
- * 按表格行、列顺序依次校验(同步或异步)
541
- * 校验规则根据索引顺序依次校验,如果是异步则会等待校验完成才会继续校验下一列
542
- * 如果校验失败则,触发回调或者 Promise<(ErrMap 校验不通过列的信息)>
543
- * 如果是传回调方式这返回一个 (ErrMap 校验不通过列的信息)
544
- *
545
- * rule 配置:
546
- * required=Boolean 是否必填
547
- * min=Number 最小长度
548
- * max=Number 最大长度
549
- * validator=Function({ itemValue, rule, rules, data, property }) 自定义校验,接收一个 Promise
550
- * trigger=change 触发方式
551
- */
552
- validItemRules (validType: string, fields: string | string[], val?: any): Promise<VxeFormDefines.ValidateErrorMapParams | undefined> {
553
- const $xeForm = this
554
- const props = $xeForm
555
-
556
- const { data, rules: formRules } = props
557
- const errorMaps: VxeFormDefines.ValidateErrorMapParams = {}
558
- if (!XEUtils.isArray(fields)) {
559
- fields = [fields]
560
- }
561
- return Promise.all(
562
- fields.map((property) => {
563
- const errorRules: Rule[] = []
564
- const syncVailds: Promise<any>[] = []
565
- if (property && formRules) {
566
- const rules = XEUtils.get(formRules, property)
567
- if (rules) {
568
- const itemValue = XEUtils.isUndefined(val) ? XEUtils.get(data, property) : val
569
- rules.forEach((rule) => {
570
- const { trigger, validator } = rule
571
- if (validType === 'all' || !trigger || validType === trigger) {
572
- if (validator) {
573
- const validParams = {
574
- itemValue,
575
- rule,
576
- rules,
577
- data,
578
- field: property,
579
- property,
580
- $form: $xeForm
581
- }
582
- let customValid: any
583
- if (XEUtils.isString(validator)) {
584
- const gvItem = validators.get(validator)
585
- if (gvItem) {
586
- const validatorMethod = gvItem.formItemValidatorMethod || gvItem.itemValidatorMethod
587
- if (validatorMethod) {
588
- customValid = validatorMethod(validParams)
589
- } else {
590
- warnLog('vxe.error.notValidators', [`[form] ${validator}`])
591
- }
592
- } else {
593
- errLog('vxe.error.notValidators', [`[form] ${validator}`])
594
- }
595
- } else {
596
- customValid = validator(validParams)
597
- }
598
- if (customValid) {
599
- if (XEUtils.isError(customValid)) {
600
- errorRules.push(new Rule({ type: 'custom', trigger, content: customValid.message, rule: new Rule(rule) }))
601
- } else if (customValid.catch) {
602
- // 如果为异步校验(注:异步校验是并发无序的)
603
- syncVailds.push(
604
- customValid.catch((e: any) => {
605
- errorRules.push(new Rule({ type: 'custom', trigger, content: e ? e.message : (rule.content || rule.message), rule: new Rule(rule) }))
606
- })
607
- )
608
- }
609
- }
610
- } else {
611
- if (!checkRuleStatus(rule, data, itemValue)) {
612
- errorRules.push(new Rule(rule))
613
- }
614
- }
615
- }
616
- })
617
- }
618
- }
619
- return Promise.all(syncVailds).then(() => {
620
- if (errorRules.length) {
621
- errorMaps[property] = errorRules.map(rule => {
622
- return {
623
- $form: $xeForm,
624
- rule,
625
- data,
626
- field: property,
627
- property
628
- }
629
- })
630
- }
631
- })
632
- })
633
- ).then(() => {
634
- if (!XEUtils.isEmpty(errorMaps)) {
635
- return Promise.reject(errorMaps)
636
- }
637
- })
638
- },
639
- beginValidate (itemList: VxeFormDefines.ItemInfo[], type?: string, callback?: any): Promise<VxeFormDefines.ValidateErrorMapParams | void> {
640
- const $xeForm = this
641
- const props = $xeForm
642
- const internalData = $xeForm.internalData
643
-
644
- const { data, rules: formRules } = props
645
- const validOpts = $xeForm.computeValidOpts
646
- const validRest: any = {}
647
- const validFields: string[] = []
648
- const itemValids: any[] = []
649
- clearTimeout(internalData.meTimeout)
650
- if (data && formRules) {
651
- itemList.forEach((item) => {
652
- const { field } = item
653
- if (field && !isHiddenItem($xeForm, item) && isActiveItem($xeForm, item)) {
654
- itemValids.push(
655
- $xeForm.validItemRules(type || 'all', field).then(() => {
656
- item.errRule = null
657
- }).catch((errorMaps: VxeFormDefines.ValidateErrorMapParams) => {
658
- const rest = errorMaps[field]
659
- if (!validRest[field]) {
660
- validRest[field] = []
661
- }
662
- validRest[field].push(rest)
663
- validFields.push(field)
664
- item.errRule = rest[0].rule
665
- return Promise.reject(rest)
666
- })
667
- )
668
- }
669
- })
670
- return Promise.all(itemValids).then(() => {
671
- if (callback) {
672
- callback()
673
- }
674
- }).catch(() => {
675
- return new Promise<void>((resolve) => {
676
- internalData.meTimeout = setTimeout(() => {
677
- itemList.forEach((item) => {
678
- if (item.errRule) {
679
- item.showError = true
680
- }
681
- })
682
- }, 20)
683
- if (validOpts.autoPos !== false) {
684
- $xeForm.$nextTick(() => {
685
- $xeForm.handleFocus(validFields)
686
- })
687
- }
688
- if (callback) {
689
- callback(validRest)
690
- resolve()
691
- } else {
692
- resolve(validRest)
693
- }
694
- })
695
- })
696
- }
697
- if (callback) {
698
- callback()
699
- }
700
- return Promise.resolve()
701
- },
702
- validate (callback: any) {
703
- const $xeForm = this
704
- const props = $xeForm
705
-
706
- const { readonly } = props
707
- $xeForm.clearValidate()
708
- if (readonly) {
709
- return $xeForm.$nextTick()
710
- }
711
- return $xeForm.beginValidate($xeForm.getItems(), '', callback).then((params) => {
712
- $xeForm.recalculate()
713
- return params
714
- })
715
- },
716
- validateField (fieldOrItem: VxeFormItemPropTypes.Field | VxeFormItemPropTypes.Field[] | VxeFormDefines.ItemInfo | VxeFormDefines.ItemInfo[], callback: any) {
717
- const $xeForm = this
718
- const props = $xeForm
719
-
720
- const { readonly } = props
721
- if (readonly) {
722
- return $xeForm.$nextTick()
723
- }
724
- let fields: any[] = []
725
- if (fieldOrItem) {
726
- if (XEUtils.isArray(fieldOrItem)) {
727
- fields = fieldOrItem
728
- } else {
729
- fields = [fieldOrItem]
730
- }
731
- }
732
- const itemList = fields.map(field => handleFieldOrItem($xeForm, field)) as VxeFormDefines.ItemInfo[]
733
- return $xeForm.beginValidate(itemList, '', callback).then((params) => {
734
- $xeForm.recalculate()
735
- return params
736
- })
737
- },
738
- handleSubmitEvent (evnt: Event) {
739
- const $xeForm = this
740
- const props = $xeForm
741
-
742
- const { readonly } = props
743
- $xeForm.clearValidate()
744
- if (readonly) {
745
- $xeForm.dispatchEvent('submit', { data: props.data }, evnt)
746
- $xeForm.recalculate()
747
- return
748
- }
749
- $xeForm.beginValidate($xeForm.getItems()).then((errMap) => {
750
- if (errMap) {
751
- $xeForm.dispatchEvent('submit-invalid', { data: props.data, errMap }, evnt)
752
- } else {
753
- $xeForm.dispatchEvent('submit', { data: props.data }, evnt)
754
- }
755
- $xeForm.recalculate()
756
- })
757
- },
758
- submitEvent (evnt: Event) {
759
- const $xeForm = this
760
- const props = $xeForm
761
-
762
- evnt.preventDefault()
763
- if (!props.preventSubmit) {
764
- $xeForm.handleSubmitEvent(evnt)
765
- }
766
- },
767
- closeTooltip () {
768
- const $xeForm = this
769
- const internalData = $xeForm.internalData
770
-
771
- const { tooltipStore } = internalData
772
- const $tooltip = $xeForm.$refs.refTooltip as VxeTooltipConstructor
773
- if (tooltipStore.visible) {
774
- Object.assign(tooltipStore, {
775
- item: null,
776
- visible: false
777
- })
778
- if ($tooltip) {
779
- $tooltip.close()
780
- }
781
- }
782
- return $xeForm.$nextTick()
783
- },
784
- triggerTitleTipEvent (evnt: MouseEvent, params: {
785
- item: VxeFormDefines.ItemInfo;
786
- }) {
787
- const $xeForm = this
788
- const internalData = $xeForm.internalData
789
-
790
- const { item } = params
791
- const { tooltipStore } = internalData
792
- const $tooltip = $xeForm.$refs.refTooltip as VxeTooltipConstructor
793
- const overflowElem = (evnt.currentTarget as HTMLDivElement).children[0]
794
- const content = (overflowElem.textContent || '').trim()
795
- const isCellOverflow = overflowElem.scrollWidth > overflowElem.clientWidth
796
- clearTimeout(internalData.stTimeout)
797
- if (tooltipStore.item !== item) {
798
- $xeForm.closeTooltip()
799
- }
800
- if (content && isCellOverflow) {
801
- Object.assign(tooltipStore, {
802
- item,
803
- visible: true
804
- })
805
- if ($tooltip) {
806
- $tooltip.open(overflowElem, content)
807
- }
808
- }
809
- },
810
- handleTitleTipLeaveEvent () {
811
- const $xeForm = this
812
- const internalData = $xeForm.internalData
813
-
814
- const tooltipOpts = $xeForm.computeTooltipOpts
815
- let $tooltip = $xeForm.$refs.refTooltip as VxeTooltipConstructor
816
- if ($tooltip) {
817
- $tooltip.setActived(false)
818
- }
819
- if (tooltipOpts.enterable) {
820
- internalData.stTimeout = setTimeout(() => {
821
- $tooltip = $xeForm.$refs.refTooltip as VxeTooltipConstructor
822
- if ($tooltip && !$tooltip.isActived()) {
823
- $xeForm.closeTooltip()
824
- }
825
- }, tooltipOpts.leaveDelay)
826
- } else {
827
- $xeForm.closeTooltip()
828
- }
829
- },
830
- handleValidIconEvent (evnt: Event, params: {
831
- item: VxeFormDefines.ItemInfo;
832
- }) {
833
- const { item } = params
834
- item.showIconMsg = !item.showIconMsg
835
- },
836
- triggerItemEvent (evnt: Event, field: string, itemValue?: any) {
837
- const $xeForm = this
838
-
839
- if (field) {
840
- return $xeForm.validItemRules(evnt ? (['blur'].includes(evnt.type) ? 'blur' : 'change') : 'all', field, itemValue)
841
- .then(() => {
842
- $xeForm.clearValidate(field)
843
- })
844
- .catch((errorMaps: VxeFormDefines.ValidateErrorMapParams) => {
845
- const rest = errorMaps[field]
846
- const item = $xeForm.getItemByField(field)
847
- if (rest && item) {
848
- item.showError = true
849
- item.errRule = rest[0].rule
850
- }
851
- })
852
- }
853
- return $xeForm.$nextTick()
854
- },
855
- /**
856
- * 更新项状态
857
- * 如果组件值 v-model 发生 change 时,调用改函数用于更新某一项编辑状态
858
- * 如果单元格配置了校验规则,则会进行校验
859
- */
860
- updateStatus (scope: any, itemValue?: any) {
861
- const $xeForm = this
862
-
863
- const { field } = scope
864
- return $xeForm.triggerItemEvent(new Event('change'), field, itemValue)
865
- },
866
- recalculate () {
867
- const $xeForm = this
868
-
869
- const autoItemWidthList = $xeForm.computeAutoItemWidthList
870
- const el = $xeForm.$refs.refElem as HTMLFormElement
871
- if (el && autoItemWidthList.length) {
872
- const itemElList = el.querySelectorAll<HTMLElement>(autoItemWidthList.map(item => `.vxe-form--item-title[itemid="${item.id}"]`).join(','))
873
- let maxItemWidth = 0
874
- XEUtils.arrayEach(itemElList, itemEl => {
875
- itemEl.style.width = ''
876
- maxItemWidth = Math.max(maxItemWidth, Math.ceil(itemEl.clientWidth + 2))
877
- })
878
- XEUtils.arrayEach(itemElList, itemEl => {
879
- itemEl.style.width = `${maxItemWidth}px`
880
- })
881
- }
882
- return $xeForm.$nextTick()
883
- },
884
- handleGlobalResizeEvent () {
885
- const $xeForm = this
886
-
887
- $xeForm.recalculate()
888
- },
889
-
890
- //
891
- // Render
892
- //
893
- renderVN (h: CreateElement): VNode {
894
- const $xeForm = this
895
- const props = $xeForm
896
- const slots = $xeForm.$scopedSlots
897
- const reactData = $xeForm.reactData
898
-
899
- const { loading, border, className, data, customLayout } = props
900
- const { formItems } = reactData
901
- // const formItems: any[] = []
902
- const vSize = $xeForm.computeSize
903
- const tooltipOpts = $xeForm.computeTooltipOpts
904
- const defaultSlot = slots.default
905
- return h('form', {
906
- ref: 'refElem',
907
- class: ['vxe-form', className ? (XEUtils.isFunction(className) ? className({ items: formItems, data, $form: $xeForm }) : className) : '', {
908
- [`size--${vSize}`]: vSize,
909
- 'is--border': border,
910
- 'custom--layout': customLayout,
911
- 'is--loading': loading
912
- }],
913
- on: {
914
- submit: $xeForm.submitEvent,
915
- reset: $xeForm.resetEvent
916
- }
917
- }, [
918
- h('div', {
919
- class: 'vxe-form--wrapper vxe-form--item-row'
920
- }, customLayout
921
- ? (defaultSlot ? defaultSlot({}) : [])
922
- : formItems.map((item, index) => {
923
- return h(VxeFormConfigItem, {
924
- key: index,
925
- props: {
926
- itemConfig: item
927
- }
928
- })
929
- })),
930
- h('div', {
931
- class: 'vxe-form-slots',
932
- ref: 'hideItem'
933
- }, customLayout ? [] : (defaultSlot ? defaultSlot({}) : [])),
934
- /**
935
- * 加载中
936
- */
937
- h(VxeLoadingComponent, {
938
- class: 'vxe-form--loading',
939
- props: {
940
- value: loading
941
- }
942
- }),
943
- /**
944
- * 工具提示
945
- */
946
- h(VxeTooltipComponent, {
947
- ref: 'refTooltip',
948
- ...tooltipOpts
949
- })
950
- ])
951
- }
952
- },
953
- watch: {
954
- vertical () {
955
- const $xeForm = this
956
-
957
- $xeForm.recalcFlag++
958
- },
959
- titleWidth () {
960
- const $xeForm = this
961
-
962
- $xeForm.recalcFlag++
963
- },
964
- recalcFlag () {
965
- const $xeForm = this
966
-
967
- $xeForm.$nextTick().then(() => {
968
- $xeForm.recalculate()
969
- })
970
- },
971
- 'reactData.staticItems' () {
972
- const $xeForm = this
973
- const reactData = $xeForm.reactData
974
-
975
- reactData.formItems = reactData.staticItems
976
- $xeForm.recalcFlag++
977
- },
978
- items () {
979
- const $xeForm = this
980
- const props = $xeForm
981
-
982
- $xeForm.loadItem(props.items || [])
983
- },
984
- collapseStatus (val) {
985
- const $xeForm = this
986
- const reactData = $xeForm.reactData
987
-
988
- reactData.collapseAll = !!val
989
- },
990
- readonly () {
991
- const $xeForm = this
992
-
993
- $xeForm.clearValidate()
994
- },
995
- disabled () {
996
- const $xeForm = this
997
-
998
- $xeForm.clearValidate()
999
- }
1000
- },
1001
- created () {
1002
- const $xeForm = this
1003
- const props = $xeForm
1004
- const reactData = $xeForm.reactData
1005
-
1006
- reactData.collapseAll = !!props.collapseStatus
1007
- },
1008
- mounted () {
1009
- const $xeForm = this
1010
- const props = $xeForm
1011
-
1012
- if (props.items) {
1013
- $xeForm.loadItem(props.items)
1014
- }
1015
- $xeForm.$nextTick(() => {
1016
- if (props.customLayout && props.items) {
1017
- errLog('vxe.error.errConflicts', ['[form] custom-layout', 'items'])
1018
- }
1019
- })
1020
- globalEvents.on($xeForm, 'resize', $xeForm.handleGlobalResizeEvent)
1021
- },
1022
- destroyed () {
1023
- const $xeForm = this
1024
- const internalData = $xeForm.internalData
1025
-
1026
- globalEvents.off($xeForm, 'resize')
1027
- XEUtils.assign(internalData, createInternalData())
1028
- },
1029
- render (this: any, h) {
1030
- return this.renderVN(h)
1031
- }
1032
- }) /* define-vxe-component end */
1
+ import { PropType, CreateElement, VNode } from 'vue'
2
+ import { defineVxeComponent } from '../../ui/src/comp'
3
+ import XEUtils from 'xe-utils'
4
+ import { getConfig, validators, renderer, createEvent, globalMixins, globalEvents } from '../../ui'
5
+ import { eqEmptyValue, getFuncText, isEnableConf } from '../../ui/src/utils'
6
+ import { scrollToView } from '../../ui/src/dom'
7
+ import { createItem, handleFieldOrItem, isHiddenItem, isActiveItem } from './util'
8
+ import VxeTooltipComponent from '../../tooltip'
9
+ import VxeFormConfigItem from './form-config-item'
10
+ import VxeLoadingComponent from '../../loading'
11
+ import { getSlotVNs } from '../../ui/src/vn'
12
+ import { warnLog, errLog } from '../../ui/src/log'
13
+
14
+ import '../render'
15
+
16
+ import type { VxeFormPropTypes, VxeFormEmits, VxeComponentSizeType, ValueOf, FormReactData, VxeFormDefines, VxeFormItemPropTypes, FormInternalData, VxeTooltipConstructor } from '../../../types'
17
+ import type { VxeGridConstructor, VxeGridPrivateMethods } from '../../../types/components/grid'
18
+
19
+ class Rule {
20
+ constructor (rule: any) {
21
+ Object.assign(this, {
22
+ $options: rule,
23
+ required: rule.required,
24
+ min: rule.min,
25
+ max: rule.min,
26
+ type: rule.type,
27
+ pattern: rule.pattern,
28
+ validator: rule.validator,
29
+ trigger: rule.trigger,
30
+ maxWidth: rule.maxWidth
31
+ })
32
+ }
33
+
34
+ get content () {
35
+ return getFuncText(this.$options.content || this.$options.message)
36
+ }
37
+
38
+ get message () {
39
+ return this.content
40
+ }
41
+
42
+ [key: string]: any
43
+ }
44
+
45
+ // 如果存在 pattern,判断正则
46
+ function validREValue (pattern: string | RegExp | undefined, val: string) {
47
+ if (pattern && !(XEUtils.isRegExp(pattern) ? pattern : new RegExp(pattern)).test(val)) {
48
+ return false
49
+ }
50
+ return true
51
+ }
52
+
53
+ // 如果存在 max,判断最大值
54
+ function validMaxValue (max: string | number | undefined, num: number) {
55
+ if (!XEUtils.eqNull(max) && num > XEUtils.toNumber(max)) {
56
+ return false
57
+ }
58
+ return true
59
+ }
60
+
61
+ // 如果存在 min,判断最小值
62
+ function validMinValue (min: string | number | undefined, num: number) {
63
+ if (!XEUtils.eqNull(min) && num < XEUtils.toNumber(min)) {
64
+ return false
65
+ }
66
+ return true
67
+ }
68
+
69
+ function validRuleValue (rule: VxeFormDefines.FormRule, val: any, required: boolean | undefined) {
70
+ const { type, min, max, pattern } = rule
71
+ const isArrType = type === 'array'
72
+ const isNumType = type === 'number'
73
+ const isStrType = type === 'string'
74
+ const strVal = `${val}`
75
+ if (!validREValue(pattern, strVal)) {
76
+ return false
77
+ }
78
+ if (isArrType) {
79
+ if (!XEUtils.isArray(val)) {
80
+ return false
81
+ }
82
+ if (required) {
83
+ if (!val.length) {
84
+ return false
85
+ }
86
+ }
87
+ if (!validMinValue(min, val.length)) {
88
+ return false
89
+ }
90
+ if (!validMaxValue(max, val.length)) {
91
+ return false
92
+ }
93
+ } else if (isNumType) {
94
+ const numVal = Number(val)
95
+ if (isNaN(numVal)) {
96
+ return false
97
+ }
98
+ if (!validMinValue(min, numVal)) {
99
+ return false
100
+ }
101
+ if (!validMaxValue(max, numVal)) {
102
+ return false
103
+ }
104
+ } else {
105
+ if (isStrType) {
106
+ if (!XEUtils.isString(val)) {
107
+ return false
108
+ }
109
+ }
110
+ if (required) {
111
+ if (!strVal) {
112
+ return false
113
+ }
114
+ }
115
+ if (!validMinValue(min, strVal.length)) {
116
+ return false
117
+ }
118
+ if (!validMaxValue(max, strVal.length)) {
119
+ return false
120
+ }
121
+ }
122
+ return true
123
+ }
124
+
125
+ function checkRuleStatus (rule: VxeFormDefines.FormRule, data: any, val: any) {
126
+ const { required, field } = rule
127
+ const currVal = field ? XEUtils.get(data, field) : val
128
+ const isEmptyVal = XEUtils.isArray(currVal) ? !currVal.length : eqEmptyValue(currVal)
129
+ if (required) {
130
+ if (isEmptyVal) {
131
+ return false
132
+ }
133
+ if (!validRuleValue(rule, currVal, required)) {
134
+ return false
135
+ }
136
+ } else {
137
+ if (!isEmptyVal) {
138
+ if (!validRuleValue(rule, currVal, required)) {
139
+ return false
140
+ }
141
+ }
142
+ }
143
+ return true
144
+ }
145
+
146
+ function createInternalData (): FormInternalData {
147
+ return {
148
+ meTimeout: undefined,
149
+ stTimeout: undefined,
150
+ tooltipStore: {
151
+ item: null,
152
+ visible: false
153
+ },
154
+ itemFormatCache: {}
155
+ }
156
+ }
157
+
158
+ export default /* define-vxe-component start */ defineVxeComponent({
159
+ name: 'VxeForm',
160
+ mixins: [
161
+ globalMixins.sizeMixin
162
+ ],
163
+ props: {
164
+ collapseStatus: {
165
+ type: Boolean as PropType<VxeFormPropTypes.CollapseStatus>,
166
+ default: true
167
+ },
168
+ loading: Boolean as PropType<VxeFormPropTypes.Loading>,
169
+ data: Object as PropType<VxeFormPropTypes.Data>,
170
+ size: {
171
+ type: String as PropType<VxeFormPropTypes.Size>,
172
+ default: () => getConfig().form.size || getConfig().size
173
+ },
174
+ span: {
175
+ type: [String, Number] as PropType<VxeFormPropTypes.Span>,
176
+ default: () => getConfig().form.span
177
+ },
178
+ align: {
179
+ type: String as PropType<VxeFormPropTypes.Align>,
180
+ default: () => getConfig().form.align
181
+ },
182
+ verticalAlign: {
183
+ type: String as PropType<VxeFormPropTypes.VerticalAlign>,
184
+ default: () => getConfig().form.verticalAlign
185
+ },
186
+ border: {
187
+ type: Boolean as PropType<VxeFormPropTypes.Border>,
188
+ default: () => getConfig().form.border
189
+ },
190
+ titleBackground: {
191
+ type: Boolean as PropType<VxeFormPropTypes.TitleBackground>,
192
+ default: () => getConfig().form.titleBackground
193
+ },
194
+ titleBold: {
195
+ type: Boolean as PropType<VxeFormPropTypes.TitleBold>,
196
+ default: () => getConfig().form.titleBold
197
+ },
198
+ titleAlign: {
199
+ type: String as PropType<VxeFormPropTypes.TitleAlign>,
200
+ default: () => getConfig().form.titleAlign
201
+ },
202
+ titleWidth: {
203
+ type: [String, Number] as PropType<VxeFormPropTypes.TitleWidth>,
204
+ default: () => getConfig().form.titleWidth
205
+ },
206
+ titleColon: {
207
+ type: Boolean as PropType<VxeFormPropTypes.TitleColon>,
208
+ default: () => getConfig().form.titleColon
209
+ },
210
+ titleAsterisk: {
211
+ type: Boolean as PropType<VxeFormPropTypes.TitleAsterisk>,
212
+ default: () => getConfig().form.titleAsterisk
213
+ },
214
+ titleOverflow: {
215
+ type: [Boolean, String] as PropType<VxeFormPropTypes.TitleOverflow>,
216
+ default: () => getConfig().form.titleOverflow
217
+ },
218
+ vertical: {
219
+ type: Boolean as PropType<VxeFormPropTypes.Vertical>,
220
+ default: () => getConfig().form.vertical
221
+ },
222
+ padding: {
223
+ type: Boolean as PropType<VxeFormPropTypes.Padding>,
224
+ default: () => getConfig().form.padding
225
+ },
226
+ className: [String, Function] as PropType<VxeFormPropTypes.ClassName>,
227
+ readonly: Boolean as PropType<VxeFormPropTypes.Readonly>,
228
+ disabled: Boolean as PropType<VxeFormPropTypes.Disabled>,
229
+ items: Array as PropType<VxeFormPropTypes.Items>,
230
+ rules: Object as PropType<VxeFormPropTypes.Rules>,
231
+ preventSubmit: {
232
+ type: Boolean as PropType<VxeFormPropTypes.PreventSubmit>,
233
+ default: () => getConfig().form.preventSubmit
234
+ },
235
+ validConfig: Object as PropType<VxeFormPropTypes.ValidConfig>,
236
+ tooltipConfig: Object as PropType<VxeFormPropTypes.TooltipConfig>,
237
+ collapseConfig: Object as PropType<VxeFormPropTypes.CollapseConfig>,
238
+ customLayout: {
239
+ type: Boolean as PropType<VxeFormPropTypes.CustomLayout>,
240
+ default: () => getConfig().form.customLayout
241
+ },
242
+ params: Object as PropType<VxeFormPropTypes.Params>
243
+ },
244
+ inject: {
245
+ $xeGrid: {
246
+ default: null
247
+ }
248
+ },
249
+ provide () {
250
+ const $xeForm = this
251
+ return {
252
+ $xeForm,
253
+ xeFormItemInfo: null,
254
+ $xeFormGroup: null,
255
+ $xeFormItem: null
256
+ }
257
+ },
258
+ data () {
259
+ const xID = XEUtils.uniqueId()
260
+ const reactData: FormReactData = {
261
+ collapseAll: false,
262
+ staticItems: [],
263
+ formItems: [],
264
+ itemWidth: 0
265
+ }
266
+ const internalData = createInternalData()
267
+ return {
268
+ xID,
269
+ reactData,
270
+ internalData,
271
+
272
+ recalcFlag: 0
273
+ }
274
+ },
275
+ computed: {
276
+ ...({} as {
277
+ computeSize(): VxeComponentSizeType
278
+ $xeGrid(): (VxeGridConstructor & VxeGridPrivateMethods) | null
279
+ }),
280
+ computeValidOpts () {
281
+ const $xeForm = this
282
+ const props = $xeForm
283
+
284
+ return Object.assign({}, getConfig().form.validConfig, props.validConfig)
285
+ },
286
+ computeTooltipOpts () {
287
+ const $xeForm = this
288
+ const props = $xeForm
289
+
290
+ return Object.assign({}, getConfig().tooltip, getConfig().form.tooltipConfig, props.tooltipConfig)
291
+ },
292
+ computeCollapseOpts () {
293
+ const $xeForm = this
294
+ const props = $xeForm
295
+
296
+ return Object.assign({}, getConfig().form.collapseConfig, props.collapseConfig)
297
+ },
298
+ computeAutoItemWidthList () {
299
+ const $xeForm = this
300
+ const props = $xeForm
301
+ const reactData = $xeForm.reactData
302
+
303
+ const { titleWidth: allTitleWidth, vertical: allVertical } = props
304
+ const { formItems } = reactData
305
+ const itemList: VxeFormDefines.ItemInfo[] = []
306
+ XEUtils.eachTree(formItems, (item) => {
307
+ const { titleWidth, vertical } = item
308
+ if (titleWidth === 'auto') {
309
+ itemList.push(item)
310
+ } else {
311
+ const itemVertical = XEUtils.eqNull(vertical) ? allVertical : vertical
312
+ const itemTitleWidth = itemVertical ? null : (XEUtils.eqNull(titleWidth) ? allTitleWidth : titleWidth)
313
+ if (itemTitleWidth === 'auto' && (!item.children || !item.children.length)) {
314
+ itemList.push(item)
315
+ }
316
+ }
317
+ }, { children: 'children' })
318
+ return itemList
319
+ }
320
+ },
321
+ methods: {
322
+ //
323
+ // Method
324
+ //
325
+ dispatchEvent (type: ValueOf<VxeFormEmits>, params: Record<string, any>, evnt: Event | null) {
326
+ const $xeForm = this
327
+ $xeForm.$emit(type, createEvent(evnt, { $form: $xeForm }, params))
328
+ },
329
+ callSlot (slotFunc: ((params: any, h: CreateElement) => any) | string | null, params: any, h: CreateElement) {
330
+ const $xeForm = this
331
+ const slots = $xeForm.$scopedSlots
332
+
333
+ if (slotFunc) {
334
+ if (XEUtils.isString(slotFunc)) {
335
+ slotFunc = slots[slotFunc] || null
336
+ }
337
+ if (XEUtils.isFunction(slotFunc)) {
338
+ return getSlotVNs(slotFunc.call($xeForm, params, h))
339
+ }
340
+ }
341
+ return []
342
+ },
343
+ loadItem (list: VxeFormPropTypes.Items) {
344
+ const $xeForm = this
345
+ const slots = $xeForm.$scopedSlots
346
+ const reactData = $xeForm.reactData
347
+ const internalData = $xeForm.internalData
348
+
349
+ if (list.length) {
350
+ list.forEach((item) => {
351
+ if (item.slots) {
352
+ XEUtils.each(item.slots, (func) => {
353
+ if (!XEUtils.isFunction(func)) {
354
+ if (!slots[func]) {
355
+ errLog('vxe.error.notSlot', [`[form] ${func}`])
356
+ }
357
+ }
358
+ })
359
+ }
360
+ })
361
+ }
362
+ reactData.staticItems = XEUtils.mapTree(list, item => createItem($xeForm, item), { children: 'children' })
363
+ internalData.itemFormatCache = {}
364
+ return $xeForm.$nextTick().then(() => {
365
+ return $xeForm.recalculate()
366
+ })
367
+ },
368
+ getItems () {
369
+ const $xeForm = this
370
+ const reactData = $xeForm.reactData
371
+
372
+ const itemList: VxeFormDefines.ItemInfo[] = []
373
+ XEUtils.eachTree(reactData.formItems, item => {
374
+ itemList.push(item)
375
+ }, { children: 'children' })
376
+ return itemList
377
+ },
378
+ getItemByField (field: string) {
379
+ const $xeForm = this
380
+ const reactData = $xeForm.reactData
381
+
382
+ const rest = XEUtils.findTree(reactData.formItems, item => item.field === field, { children: 'children' })
383
+ return rest ? rest.item : null
384
+ },
385
+ getCollapseStatus () {
386
+ const $xeForm = this
387
+ const reactData = $xeForm.reactData
388
+
389
+ return reactData.collapseAll
390
+ },
391
+ toggleCollapse () {
392
+ const $xeForm = this
393
+ const reactData = $xeForm.reactData
394
+
395
+ const status = !$xeForm.getCollapseStatus()
396
+ reactData.collapseAll = status
397
+ $xeForm.$emit('update:collapseStatus', status)
398
+ return $xeForm.$nextTick()
399
+ },
400
+ toggleCollapseEvent (evnt: Event) {
401
+ const $xeForm = this
402
+ const props = $xeForm
403
+ const $xeGrid = $xeForm.$xeGrid
404
+
405
+ const actionRest = $xeForm.toggleCollapse()
406
+ const status = $xeForm.getCollapseStatus()
407
+ $xeForm.dispatchEvent('toggle-collapse', { status, collapse: status, data: props.data }, evnt)
408
+ $xeForm.dispatchEvent('collapse', { status, collapse: status, data: props.data }, evnt)
409
+ actionRest.then(() => {
410
+ $xeForm.recalculate().then(() => {
411
+ if ($xeGrid) {
412
+ $xeGrid.recalculate(true)
413
+ }
414
+ })
415
+ if ($xeGrid) {
416
+ $xeGrid.recalculate()
417
+ }
418
+ })
419
+ },
420
+ clearValidate (fieldOrItem?: VxeFormItemPropTypes.Field | VxeFormItemPropTypes.Field[] | VxeFormDefines.ItemInfo | VxeFormDefines.ItemInfo[]) {
421
+ const $xeForm = this
422
+
423
+ if (fieldOrItem) {
424
+ let fields: any = fieldOrItem
425
+ if (!XEUtils.isArray(fieldOrItem)) {
426
+ fields = [fieldOrItem]
427
+ }
428
+ fields.forEach((field: any) => {
429
+ if (field) {
430
+ const item = handleFieldOrItem($xeForm, field)
431
+ if (item) {
432
+ item.showError = false
433
+ item.showIconMsg = false
434
+ }
435
+ }
436
+ })
437
+ } else {
438
+ $xeForm.getItems().forEach((item) => {
439
+ item.showError = false
440
+ item.showIconMsg = false
441
+ })
442
+ }
443
+ return $xeForm.$nextTick()
444
+ },
445
+ getResetValue (item: VxeFormDefines.ItemInfo, data: any, itemValue: any) {
446
+ const $xeForm = this
447
+ const $xeGrid = $xeForm.$xeGrid
448
+
449
+ const { field, resetValue } = item
450
+ if (XEUtils.isFunction(resetValue)) {
451
+ return resetValue({ field, item, data, $form: $xeForm, $grid: $xeGrid })
452
+ } else if (resetValue === null) {
453
+ // 默认
454
+ if (XEUtils.isArray(itemValue)) {
455
+ return []
456
+ }
457
+ }
458
+ return resetValue
459
+ },
460
+ reset () {
461
+ const $xeForm = this
462
+ const props = $xeForm
463
+ const $xeGrid = $xeForm.$xeGrid
464
+ const internalData = $xeForm.internalData
465
+
466
+ const { data } = props
467
+ const itemList = $xeForm.getItems()
468
+ if (data) {
469
+ itemList.forEach((item) => {
470
+ const { field, itemRender } = item
471
+ if (isEnableConf(itemRender)) {
472
+ const { name, startField, endField } = itemRender
473
+ const compConf = renderer.get(name)
474
+ const fiResetMethod = compConf ? (compConf.formItemResetMethod || compConf.itemResetMethod) : null
475
+ if (compConf && fiResetMethod) {
476
+ fiResetMethod({ data, field, property: field, item, $form: $xeForm, $grid: $xeGrid })
477
+ } else if (field) {
478
+ const itemValue = XEUtils.get(data, field)
479
+ XEUtils.set(data, field, $xeForm.getResetValue(item, data, itemValue))
480
+ }
481
+ if (startField && endField) {
482
+ XEUtils.set(data, startField, $xeForm.getResetValue(item, data, XEUtils.get(data, startField)))
483
+ XEUtils.set(data, endField, $xeForm.getResetValue(item, data, XEUtils.get(data, endField)))
484
+ }
485
+ }
486
+ })
487
+ }
488
+ internalData.itemFormatCache = {}
489
+ $xeForm.clearValidate()
490
+ return $xeForm.recalculate()
491
+ },
492
+ resetEvent (evnt: Event) {
493
+ const $xeForm = this
494
+ const props = $xeForm
495
+
496
+ evnt.preventDefault()
497
+ $xeForm.reset()
498
+ $xeForm.dispatchEvent('reset', { data: props.data }, evnt)
499
+ },
500
+ handleFocus (fields: string[]) {
501
+ const $xeForm = this
502
+ const props = $xeForm
503
+ const $xeGrid = $xeForm.$xeGrid
504
+
505
+ const el = $xeForm.$refs.refElem as HTMLFormElement
506
+ if (el) {
507
+ for (let i = 0; i < fields.length; i++) {
508
+ const field = fields[i]
509
+ const item = $xeForm.getItemByField(field)
510
+ if (item && isEnableConf(item.itemRender)) {
511
+ const { itemRender } = item
512
+ const compConf = renderer.get(itemRender.name)
513
+ // 定位到第一个
514
+ if (!i) {
515
+ scrollToView(el.querySelector(`.${item.id}`))
516
+ }
517
+ let inputElem: HTMLElement | null = null
518
+ const autoFocus = itemRender.autoFocus || itemRender.autofocus || (compConf ? compConf.formItemAutoFocus : null)
519
+ // 如果指定了聚焦 class
520
+ if (XEUtils.isFunction(autoFocus)) {
521
+ inputElem = autoFocus({ $form: $xeForm, $grid: $xeGrid, item, data: props.data, field })
522
+ } else {
523
+ if (autoFocus === true) {
524
+ // 自动匹配模式,会自动匹配第一个可输入元素
525
+ inputElem = el.querySelector(`.${item.id} input,textarea`)
526
+ } else if (autoFocus) {
527
+ inputElem = el.querySelector(`.${item.id} ${autoFocus}`) as HTMLInputElement
528
+ }
529
+ }
530
+ if (inputElem) {
531
+ inputElem.focus()
532
+ break
533
+ }
534
+ }
535
+ }
536
+ }
537
+ },
538
+ /**
539
+ * 校验数据
540
+ * 按表格行、列顺序依次校验(同步或异步)
541
+ * 校验规则根据索引顺序依次校验,如果是异步则会等待校验完成才会继续校验下一列
542
+ * 如果校验失败则,触发回调或者 Promise<(ErrMap 校验不通过列的信息)>
543
+ * 如果是传回调方式这返回一个 (ErrMap 校验不通过列的信息)
544
+ *
545
+ * rule 配置:
546
+ * required=Boolean 是否必填
547
+ * min=Number 最小长度
548
+ * max=Number 最大长度
549
+ * validator=Function({ itemValue, rule, rules, data, property }) 自定义校验,接收一个 Promise
550
+ * trigger=change 触发方式
551
+ */
552
+ validItemRules (validType: string, fields: string | string[], val?: any): Promise<VxeFormDefines.ValidateErrorMapParams | undefined> {
553
+ const $xeForm = this
554
+ const props = $xeForm
555
+
556
+ const { data, rules: formRules } = props
557
+ const errorMaps: VxeFormDefines.ValidateErrorMapParams = {}
558
+ if (!XEUtils.isArray(fields)) {
559
+ fields = [fields]
560
+ }
561
+ return Promise.all(
562
+ fields.map((property) => {
563
+ const errorRules: Rule[] = []
564
+ const syncVailds: Promise<any>[] = []
565
+ if (property && formRules) {
566
+ const rules = XEUtils.get(formRules, property)
567
+ if (rules) {
568
+ const itemValue = XEUtils.isUndefined(val) ? XEUtils.get(data, property) : val
569
+ rules.forEach((rule) => {
570
+ const { trigger, validator } = rule
571
+ if (validType === 'all' || !trigger || validType === trigger) {
572
+ if (validator) {
573
+ const validParams = {
574
+ itemValue,
575
+ rule,
576
+ rules,
577
+ data,
578
+ field: property,
579
+ property,
580
+ $form: $xeForm
581
+ }
582
+ let customValid: any
583
+ if (XEUtils.isString(validator)) {
584
+ const gvItem = validators.get(validator)
585
+ if (gvItem) {
586
+ const validatorMethod = gvItem.formItemValidatorMethod || gvItem.itemValidatorMethod
587
+ if (validatorMethod) {
588
+ customValid = validatorMethod(validParams)
589
+ } else {
590
+ warnLog('vxe.error.notValidators', [`[form] ${validator}`])
591
+ }
592
+ } else {
593
+ errLog('vxe.error.notValidators', [`[form] ${validator}`])
594
+ }
595
+ } else {
596
+ customValid = validator(validParams)
597
+ }
598
+ if (customValid) {
599
+ if (XEUtils.isError(customValid)) {
600
+ errorRules.push(new Rule({ type: 'custom', trigger, content: customValid.message, rule: new Rule(rule) }))
601
+ } else if (customValid.catch) {
602
+ // 如果为异步校验(注:异步校验是并发无序的)
603
+ syncVailds.push(
604
+ customValid.catch((e: any) => {
605
+ errorRules.push(new Rule({ type: 'custom', trigger, content: e ? e.message : (rule.content || rule.message), rule: new Rule(rule) }))
606
+ })
607
+ )
608
+ }
609
+ }
610
+ } else {
611
+ if (!checkRuleStatus(rule, data, itemValue)) {
612
+ errorRules.push(new Rule(rule))
613
+ }
614
+ }
615
+ }
616
+ })
617
+ }
618
+ }
619
+ return Promise.all(syncVailds).then(() => {
620
+ if (errorRules.length) {
621
+ errorMaps[property] = errorRules.map(rule => {
622
+ return {
623
+ $form: $xeForm,
624
+ rule,
625
+ data,
626
+ field: property,
627
+ property
628
+ }
629
+ })
630
+ }
631
+ })
632
+ })
633
+ ).then(() => {
634
+ if (!XEUtils.isEmpty(errorMaps)) {
635
+ return Promise.reject(errorMaps)
636
+ }
637
+ })
638
+ },
639
+ beginValidate (itemList: VxeFormDefines.ItemInfo[], type?: string, callback?: any): Promise<VxeFormDefines.ValidateErrorMapParams | void> {
640
+ const $xeForm = this
641
+ const props = $xeForm
642
+ const internalData = $xeForm.internalData
643
+
644
+ const { data, rules: formRules } = props
645
+ const validOpts = $xeForm.computeValidOpts
646
+ const validRest: any = {}
647
+ const validFields: string[] = []
648
+ const itemValids: any[] = []
649
+ clearTimeout(internalData.meTimeout)
650
+ if (data && formRules) {
651
+ itemList.forEach((item) => {
652
+ const { field } = item
653
+ if (field && !isHiddenItem($xeForm, item) && isActiveItem($xeForm, item)) {
654
+ itemValids.push(
655
+ $xeForm.validItemRules(type || 'all', field).then(() => {
656
+ item.errRule = null
657
+ }).catch((errorMaps: VxeFormDefines.ValidateErrorMapParams) => {
658
+ const rest = errorMaps[field]
659
+ if (!validRest[field]) {
660
+ validRest[field] = []
661
+ }
662
+ validRest[field].push(rest)
663
+ validFields.push(field)
664
+ item.errRule = rest[0].rule
665
+ return Promise.reject(rest)
666
+ })
667
+ )
668
+ }
669
+ })
670
+ return Promise.all(itemValids).then(() => {
671
+ if (callback) {
672
+ callback()
673
+ }
674
+ }).catch(() => {
675
+ return new Promise<void>((resolve) => {
676
+ internalData.meTimeout = setTimeout(() => {
677
+ itemList.forEach((item) => {
678
+ if (item.errRule) {
679
+ item.showError = true
680
+ }
681
+ })
682
+ }, 20)
683
+ if (validOpts.autoPos !== false) {
684
+ $xeForm.$nextTick(() => {
685
+ $xeForm.handleFocus(validFields)
686
+ })
687
+ }
688
+ if (callback) {
689
+ callback(validRest)
690
+ resolve()
691
+ } else {
692
+ resolve(validRest)
693
+ }
694
+ })
695
+ })
696
+ }
697
+ if (callback) {
698
+ callback()
699
+ }
700
+ return Promise.resolve()
701
+ },
702
+ validate (callback: any) {
703
+ const $xeForm = this
704
+ const props = $xeForm
705
+
706
+ const { readonly } = props
707
+ $xeForm.clearValidate()
708
+ if (readonly) {
709
+ return $xeForm.$nextTick()
710
+ }
711
+ return $xeForm.beginValidate($xeForm.getItems(), '', callback).then((params) => {
712
+ $xeForm.recalculate()
713
+ return params
714
+ })
715
+ },
716
+ validateField (fieldOrItem: VxeFormItemPropTypes.Field | VxeFormItemPropTypes.Field[] | VxeFormDefines.ItemInfo | VxeFormDefines.ItemInfo[], callback: any) {
717
+ const $xeForm = this
718
+ const props = $xeForm
719
+
720
+ const { readonly } = props
721
+ if (readonly) {
722
+ return $xeForm.$nextTick()
723
+ }
724
+ let fields: any[] = []
725
+ if (fieldOrItem) {
726
+ if (XEUtils.isArray(fieldOrItem)) {
727
+ fields = fieldOrItem
728
+ } else {
729
+ fields = [fieldOrItem]
730
+ }
731
+ }
732
+ const itemList = fields.map(field => handleFieldOrItem($xeForm, field)) as VxeFormDefines.ItemInfo[]
733
+ return $xeForm.beginValidate(itemList, '', callback).then((params) => {
734
+ $xeForm.recalculate()
735
+ return params
736
+ })
737
+ },
738
+ handleSubmitEvent (evnt: Event) {
739
+ const $xeForm = this
740
+ const props = $xeForm
741
+
742
+ const { readonly } = props
743
+ $xeForm.clearValidate()
744
+ if (readonly) {
745
+ $xeForm.dispatchEvent('submit', { data: props.data }, evnt)
746
+ $xeForm.recalculate()
747
+ return
748
+ }
749
+ $xeForm.beginValidate($xeForm.getItems()).then((errMap) => {
750
+ if (errMap) {
751
+ $xeForm.dispatchEvent('submit-invalid', { data: props.data, errMap }, evnt)
752
+ } else {
753
+ $xeForm.dispatchEvent('submit', { data: props.data }, evnt)
754
+ }
755
+ $xeForm.recalculate()
756
+ })
757
+ },
758
+ submitEvent (evnt: Event) {
759
+ const $xeForm = this
760
+ const props = $xeForm
761
+
762
+ evnt.preventDefault()
763
+ if (!props.preventSubmit) {
764
+ $xeForm.handleSubmitEvent(evnt)
765
+ }
766
+ },
767
+ closeTooltip () {
768
+ const $xeForm = this
769
+ const internalData = $xeForm.internalData
770
+
771
+ const { tooltipStore } = internalData
772
+ const $tooltip = $xeForm.$refs.refTooltip as VxeTooltipConstructor
773
+ if (tooltipStore.visible) {
774
+ Object.assign(tooltipStore, {
775
+ item: null,
776
+ visible: false
777
+ })
778
+ if ($tooltip) {
779
+ $tooltip.close()
780
+ }
781
+ }
782
+ return $xeForm.$nextTick()
783
+ },
784
+ triggerTitleTipEvent (evnt: MouseEvent, params: {
785
+ item: VxeFormDefines.ItemInfo;
786
+ }) {
787
+ const $xeForm = this
788
+ const internalData = $xeForm.internalData
789
+
790
+ const { item } = params
791
+ const { tooltipStore } = internalData
792
+ const $tooltip = $xeForm.$refs.refTooltip as VxeTooltipConstructor
793
+ const overflowElem = (evnt.currentTarget as HTMLDivElement).children[0]
794
+ const content = (overflowElem.textContent || '').trim()
795
+ const isCellOverflow = overflowElem.scrollWidth > overflowElem.clientWidth
796
+ clearTimeout(internalData.stTimeout)
797
+ if (tooltipStore.item !== item) {
798
+ $xeForm.closeTooltip()
799
+ }
800
+ if (content && isCellOverflow) {
801
+ Object.assign(tooltipStore, {
802
+ item,
803
+ visible: true
804
+ })
805
+ if ($tooltip) {
806
+ $tooltip.open(overflowElem, content)
807
+ }
808
+ }
809
+ },
810
+ handleTitleTipLeaveEvent () {
811
+ const $xeForm = this
812
+ const internalData = $xeForm.internalData
813
+
814
+ const tooltipOpts = $xeForm.computeTooltipOpts
815
+ let $tooltip = $xeForm.$refs.refTooltip as VxeTooltipConstructor
816
+ if ($tooltip) {
817
+ $tooltip.setActived(false)
818
+ }
819
+ if (tooltipOpts.enterable) {
820
+ internalData.stTimeout = setTimeout(() => {
821
+ $tooltip = $xeForm.$refs.refTooltip as VxeTooltipConstructor
822
+ if ($tooltip && !$tooltip.isActived()) {
823
+ $xeForm.closeTooltip()
824
+ }
825
+ }, tooltipOpts.leaveDelay)
826
+ } else {
827
+ $xeForm.closeTooltip()
828
+ }
829
+ },
830
+ handleValidIconEvent (evnt: Event, params: {
831
+ item: VxeFormDefines.ItemInfo;
832
+ }) {
833
+ const { item } = params
834
+ item.showIconMsg = !item.showIconMsg
835
+ },
836
+ triggerItemEvent (evnt: Event, field: string, itemValue?: any) {
837
+ const $xeForm = this
838
+
839
+ if (field) {
840
+ return $xeForm.validItemRules(evnt ? (['blur'].includes(evnt.type) ? 'blur' : 'change') : 'all', field, itemValue)
841
+ .then(() => {
842
+ $xeForm.clearValidate(field)
843
+ })
844
+ .catch((errorMaps: VxeFormDefines.ValidateErrorMapParams) => {
845
+ const rest = errorMaps[field]
846
+ const item = $xeForm.getItemByField(field)
847
+ if (rest && item) {
848
+ item.showError = true
849
+ item.errRule = rest[0].rule
850
+ }
851
+ })
852
+ }
853
+ return $xeForm.$nextTick()
854
+ },
855
+ /**
856
+ * 更新项状态
857
+ * 如果组件值 v-model 发生 change 时,调用改函数用于更新某一项编辑状态
858
+ * 如果单元格配置了校验规则,则会进行校验
859
+ */
860
+ updateStatus (scope: any, itemValue?: any) {
861
+ const $xeForm = this
862
+
863
+ const { field } = scope
864
+ return $xeForm.triggerItemEvent(new Event('change'), field, itemValue)
865
+ },
866
+ recalculate () {
867
+ const $xeForm = this
868
+
869
+ const autoItemWidthList = $xeForm.computeAutoItemWidthList
870
+ const el = $xeForm.$refs.refElem as HTMLFormElement
871
+ if (el && autoItemWidthList.length) {
872
+ const itemElList = el.querySelectorAll<HTMLElement>(autoItemWidthList.map(item => `.vxe-form--item-title[itemid="${item.id}"]`).join(','))
873
+ let maxItemWidth = 0
874
+ XEUtils.arrayEach(itemElList, itemEl => {
875
+ itemEl.style.width = ''
876
+ maxItemWidth = Math.max(maxItemWidth, Math.ceil(itemEl.clientWidth + 2))
877
+ })
878
+ XEUtils.arrayEach(itemElList, itemEl => {
879
+ itemEl.style.width = `${maxItemWidth}px`
880
+ })
881
+ }
882
+ return $xeForm.$nextTick()
883
+ },
884
+ handleGlobalResizeEvent () {
885
+ const $xeForm = this
886
+
887
+ $xeForm.recalculate()
888
+ },
889
+
890
+ //
891
+ // Render
892
+ //
893
+ renderVN (h: CreateElement): VNode {
894
+ const $xeForm = this
895
+ const props = $xeForm
896
+ const slots = $xeForm.$scopedSlots
897
+ const reactData = $xeForm.reactData
898
+
899
+ const { loading, border, className, data, customLayout } = props
900
+ const { formItems } = reactData
901
+ // const formItems: any[] = []
902
+ const vSize = $xeForm.computeSize
903
+ const tooltipOpts = $xeForm.computeTooltipOpts
904
+ const defaultSlot = slots.default
905
+ return h('form', {
906
+ ref: 'refElem',
907
+ class: ['vxe-form', className ? (XEUtils.isFunction(className) ? className({ items: formItems, data, $form: $xeForm }) : className) : '', {
908
+ [`size--${vSize}`]: vSize,
909
+ 'is--border': border,
910
+ 'custom--layout': customLayout,
911
+ 'is--loading': loading
912
+ }],
913
+ on: {
914
+ submit: $xeForm.submitEvent,
915
+ reset: $xeForm.resetEvent
916
+ }
917
+ }, [
918
+ h('div', {
919
+ class: 'vxe-form--wrapper vxe-form--item-row'
920
+ }, customLayout
921
+ ? (defaultSlot ? defaultSlot({}) : [])
922
+ : formItems.map((item, index) => {
923
+ return h(VxeFormConfigItem, {
924
+ key: index,
925
+ props: {
926
+ itemConfig: item
927
+ }
928
+ })
929
+ })),
930
+ h('div', {
931
+ class: 'vxe-form-slots',
932
+ ref: 'hideItem'
933
+ }, customLayout ? [] : (defaultSlot ? defaultSlot({}) : [])),
934
+ /**
935
+ * 加载中
936
+ */
937
+ h(VxeLoadingComponent, {
938
+ class: 'vxe-form--loading',
939
+ props: {
940
+ value: loading
941
+ }
942
+ }),
943
+ /**
944
+ * 工具提示
945
+ */
946
+ h(VxeTooltipComponent, {
947
+ ref: 'refTooltip',
948
+ ...tooltipOpts
949
+ })
950
+ ])
951
+ }
952
+ },
953
+ watch: {
954
+ vertical () {
955
+ const $xeForm = this
956
+
957
+ $xeForm.recalcFlag++
958
+ },
959
+ titleWidth () {
960
+ const $xeForm = this
961
+
962
+ $xeForm.recalcFlag++
963
+ },
964
+ recalcFlag () {
965
+ const $xeForm = this
966
+
967
+ $xeForm.$nextTick().then(() => {
968
+ $xeForm.recalculate()
969
+ })
970
+ },
971
+ 'reactData.staticItems' () {
972
+ const $xeForm = this
973
+ const reactData = $xeForm.reactData
974
+
975
+ reactData.formItems = reactData.staticItems
976
+ $xeForm.recalcFlag++
977
+ },
978
+ items () {
979
+ const $xeForm = this
980
+ const props = $xeForm
981
+
982
+ $xeForm.loadItem(props.items || [])
983
+ },
984
+ collapseStatus (val) {
985
+ const $xeForm = this
986
+ const reactData = $xeForm.reactData
987
+
988
+ reactData.collapseAll = !!val
989
+ },
990
+ readonly () {
991
+ const $xeForm = this
992
+
993
+ $xeForm.clearValidate()
994
+ },
995
+ disabled () {
996
+ const $xeForm = this
997
+
998
+ $xeForm.clearValidate()
999
+ }
1000
+ },
1001
+ created () {
1002
+ const $xeForm = this
1003
+ const props = $xeForm
1004
+ const reactData = $xeForm.reactData
1005
+
1006
+ reactData.collapseAll = !!props.collapseStatus
1007
+ },
1008
+ mounted () {
1009
+ const $xeForm = this
1010
+ const props = $xeForm
1011
+
1012
+ if (props.items) {
1013
+ $xeForm.loadItem(props.items)
1014
+ }
1015
+ $xeForm.$nextTick(() => {
1016
+ if (props.customLayout && props.items) {
1017
+ errLog('vxe.error.errConflicts', ['[form] custom-layout', 'items'])
1018
+ }
1019
+ })
1020
+ globalEvents.on($xeForm, 'resize', $xeForm.handleGlobalResizeEvent)
1021
+ },
1022
+ destroyed () {
1023
+ const $xeForm = this
1024
+ const internalData = $xeForm.internalData
1025
+
1026
+ globalEvents.off($xeForm, 'resize')
1027
+ XEUtils.assign(internalData, createInternalData())
1028
+ },
1029
+ render (this: any, h) {
1030
+ return this.renderVN(h)
1031
+ }
1032
+ }) /* define-vxe-component end */