vue2-client 1.16.77 → 1.16.79

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 (328) hide show
  1. package/.claude/settings.local.json +20 -20
  2. package/.cursorrules +19 -19
  3. package/.env.apply +19 -19
  4. package/.env.gaslink +19 -19
  5. package/.env.his +19 -19
  6. package/.env.liuli +20 -20
  7. package/.env.scada +19 -19
  8. package/.eslintrc.js +90 -90
  9. package/CHANGELOG.md +830 -830
  10. package/CLAUDE.md +97 -97
  11. package/Components.md +60 -60
  12. package/docs/LowCode/lowcode.md +155 -155
  13. package/docs/LowCode/lowcodeForDeveloper.md +230 -230
  14. package/docs/index.md +30 -30
  15. package/index.js +31 -31
  16. package/jest-transform-stub.js +8 -8
  17. package/jest.setup.js +7 -7
  18. package/jsconfig.json +19 -19
  19. package/package.json +112 -112
  20. package/public/his/editor/editor.html +51 -51
  21. package/public/his/editor/mock/bind_data.html +779 -779
  22. package/public/his/editor/mock/data_table.html +40 -40
  23. package/public/his/editor/mock/sign.html +75 -75
  24. package/public/his/editor/vender/JsBarcode.all.js +3669 -3669
  25. package/public/his/editor/vender/date97/My97DatePicker.htm +65 -65
  26. package/public/his/editor/vender/date97/WdatePicker.js +677 -677
  27. package/public/his/editor/vender/date97/calendar.js +4 -4
  28. package/public/his/editor/vender/date97/lang/en.js +13 -13
  29. package/public/his/editor/vender/date97/lang/zh-cn.js +13 -13
  30. package/public/his/editor/vender/date97/lang/zh-tw.js +13 -13
  31. package/public/his/editor/vender/date97/skin/WdatePicker.css +10 -10
  32. package/public/his/editor/vender/date97/skin/default/datepicker.css +328 -328
  33. package/public/his/editor/vender/date97/skin/ext/datepicker.css +308 -308
  34. package/public/his/editor/vender/date97/skin/whyGreen/datepicker.css +255 -255
  35. package/public/his/editor/vender/diff.js +1627 -1627
  36. package/public/his/editor/vender/editor.js +1 -1
  37. package/public/his/editor/vender/fabric.js +31187 -31187
  38. package/public/his/editor/vender/jquery/jquery.base64.js +190 -190
  39. package/public/his/editor/vender/jquery/jquery.js +10872 -10872
  40. package/public/his/editor/vender/jquery/jquery.print.js +255 -255
  41. package/public/his/editor/vender/jquery/zTreeStyle/zTreeStyle.css +96 -96
  42. package/public/his/editor/vender/mui/mui.min.css +4 -4
  43. package/public/his/editor/vender/mui/mui.min.js +5 -5
  44. package/public/his/editor/vender/mui/mui.picker.min.css +6 -6
  45. package/public/his/editor/vender/mui/mui.picker.min.js +6 -6
  46. package/public/his/editor/vender/qrcode.js +7 -7
  47. package/public/his/editor/vender/requirejs/require.js +2145 -2145
  48. package/public/his/editor/vender/signature/jSignature.CompressorSVG.js +518 -518
  49. package/public/his/editor/vender/signature/jSignature.UndoButton.js +164 -164
  50. package/public/his/editor/vender/signature/jSignature.js +1486 -1486
  51. package/public/his/editor/vender/validator.js +5094 -5094
  52. package/public/his/editor/vender/weui/weui.css +5659 -5659
  53. package/public/his/editor/vender/weui/weui.min.css +4 -4
  54. package/public/his/editor/vender/weui/weui.min.js +11 -11
  55. package/src/assets/img/querySlotDemo.svg +15 -15
  56. package/src/assets/svg/badtwo.svg +1 -1
  57. package/src/assets/svg/goodtwo.svg +1 -1
  58. package/src/base-client/components/AI/AskAiBtn.vue +136 -136
  59. package/src/base-client/components/AI/demo.vue +31 -31
  60. package/src/base-client/components/common/AddressSearchCombobox/IcMapIcon.vue +16 -16
  61. package/src/base-client/components/common/AddressSearchCombobox/demo.vue +36 -36
  62. package/src/base-client/components/common/AddressSearchCombobox/ic_map.svg +6 -6
  63. package/src/base-client/components/common/AmapMarker/AmapPointRendering.vue +120 -120
  64. package/src/base-client/components/common/CitySelect/index.js +3 -3
  65. package/src/base-client/components/common/CitySelect/index.md +109 -109
  66. package/src/base-client/components/common/CreateQuery/CreateQuery.vue +669 -669
  67. package/src/base-client/components/common/CreateQuery/CreateQueryItem.vue +1014 -1014
  68. package/src/base-client/components/common/CreateQuery/index.js +3 -3
  69. package/src/base-client/components/common/CreateQuery/index.md +42 -42
  70. package/src/base-client/components/common/CreateSimpleFormQuery/CreateSimpleFormQuery.vue +452 -452
  71. package/src/base-client/components/common/CreateSimpleFormQuery/CreateSimpleFormQueryItem.vue +511 -511
  72. package/src/base-client/components/common/CreateSimpleFormQuery/index.js +3 -3
  73. package/src/base-client/components/common/CreateSimpleFormQuery/index.md +42 -42
  74. package/src/base-client/components/common/FormGroupEdit/index.js +3 -3
  75. package/src/base-client/components/common/FormGroupEdit/index.md +43 -43
  76. package/src/base-client/components/common/FormGroupQuery/FormGroupQuery.vue +166 -166
  77. package/src/base-client/components/common/FormGroupQuery/index.js +3 -3
  78. package/src/base-client/components/common/FormGroupQuery/index.md +43 -43
  79. package/src/base-client/components/common/HIS/demo.vue +61 -61
  80. package/src/base-client/components/common/JSONToTree/jsontotree.vue +271 -271
  81. package/src/base-client/components/common/LowCodeComponent/LowCodeEditorModal.vue +108 -108
  82. package/src/base-client/components/common/LowCodeComponent/LowCodeEditorPanel.vue +413 -413
  83. package/src/base-client/components/common/LowCodeComponent/LowCodePageOrganization.vue +502 -502
  84. package/src/base-client/components/common/LowCodeComponent/LowCodeRender.vue +728 -728
  85. package/src/base-client/components/common/LowCodeComponent/LowCodeRenderEnter.vue +29 -29
  86. package/src/base-client/components/common/LowCodeComponent/LowCodeUIStore.vue +219 -219
  87. package/src/base-client/components/common/LowCodeComponent/modal/lowCodeAddPageModal.vue +117 -117
  88. package/src/base-client/components/common/LowCodeComponent/modal/lowCodeCustomJSModal.vue +80 -80
  89. package/src/base-client/components/common/LowCodeComponent/modal/lowCodeEventEditorModal.vue +398 -398
  90. package/src/base-client/components/common/LowCodeComponent/modal/lowCodeLifeCycleModal.vue +65 -65
  91. package/src/base-client/components/common/LowCodeComponent/modal/lowCodeLogicCallbackModal.vue +64 -64
  92. package/src/base-client/components/common/LowCodeComponent/modal/lowCodeLogicParamModal.vue +73 -73
  93. package/src/base-client/components/common/LowCodeComponent/modal/lowCodeRunFunctionParamModal.vue +76 -76
  94. package/src/base-client/components/common/PersonSetting/PersonSetting.vue +208 -208
  95. package/src/base-client/components/common/PersonSetting/index.js +3 -3
  96. package/src/base-client/components/common/Recording/Recording.vue +243 -243
  97. package/src/base-client/components/common/Recording/index.js +3 -3
  98. package/src/base-client/components/common/Tree/Tree.vue +149 -149
  99. package/src/base-client/components/common/Tree/index.js +2 -2
  100. package/src/base-client/components/common/Upload/Upload.vue +334 -334
  101. package/src/base-client/components/common/Upload/index.js +3 -3
  102. package/src/base-client/components/common/XAddForm/XAddForm.vue +113 -113
  103. package/src/base-client/components/common/XAddNativeForm/XAddNativeForm.vue +1280 -1280
  104. package/src/base-client/components/common/XAddNativeForm/index.md +146 -146
  105. package/src/base-client/components/common/XAddNativeFormOA/XAddNativeFormOA.vue +304 -304
  106. package/src/base-client/components/common/XAddNativeFormOA/index.js +3 -3
  107. package/src/base-client/components/common/XAddNativeFormOA/index.md +146 -146
  108. package/src/base-client/components/common/XAddReport/index.js +3 -3
  109. package/src/base-client/components/common/XAddReport/index.md +56 -56
  110. package/src/base-client/components/common/XBadge/XBadge.vue +94 -94
  111. package/src/base-client/components/common/XButtons/XButtonDemo.vue +28 -28
  112. package/src/base-client/components/common/XButtons/index.js +3 -3
  113. package/src/base-client/components/common/XButtons/index.md +61 -61
  114. package/src/base-client/components/common/XCalendar/XCalendar.vue +4 -4
  115. package/src/base-client/components/common/XCard/XCard.vue +64 -64
  116. package/src/base-client/components/common/XCheckList/XCheckList.vue +106 -106
  117. package/src/base-client/components/common/XCheckList/XCheckListDemo.vue +41 -41
  118. package/src/base-client/components/common/XDataCard/index.js +3 -3
  119. package/src/base-client/components/common/XDataCard/index.md +1 -1
  120. package/src/base-client/components/common/XDataDrawer/XDataDrawer.vue +180 -180
  121. package/src/base-client/components/common/XDataDrawer/index.js +3 -3
  122. package/src/base-client/components/common/XDataDrawer/index.md +41 -41
  123. package/src/base-client/components/common/XDatePicker/demo.vue +153 -153
  124. package/src/base-client/components/common/XDescriptions/index.js +3 -3
  125. package/src/base-client/components/common/XDescriptions/index.md +83 -83
  126. package/src/base-client/components/common/XDetailsView/XDetailsView.vue +238 -238
  127. package/src/base-client/components/common/XDetailsView/index.js +3 -3
  128. package/src/base-client/components/common/XForm/XStatusButton.vue +54 -54
  129. package/src/base-client/components/common/XForm/index.md +178 -178
  130. package/src/base-client/components/common/XForm/itemComponent/XClickChangeBtn/index.vue +49 -49
  131. package/src/base-client/components/common/XFormGroup/index.js +3 -3
  132. package/src/base-client/components/common/XFormGroup/index.md +38 -38
  133. package/src/base-client/components/common/XFormGroupDetails/XFormGroupDetails.vue +72 -72
  134. package/src/base-client/components/common/XFormGroupDetails/index.js +3 -3
  135. package/src/base-client/components/common/XFormTable/index.md +92 -92
  136. package/src/base-client/components/common/XLabelSelect/XLabelSelect.vue +110 -110
  137. package/src/base-client/components/common/XLabelSelect/XLabelSelectDemo.vue +35 -35
  138. package/src/base-client/components/common/XLicensePlate/XLicensePlate.vue +193 -193
  139. package/src/base-client/components/common/XLicensePlate/XLicensePlateDemo.vue +48 -48
  140. package/src/base-client/components/common/XPrint/OpenInvoice.vue +21 -21
  141. package/src/base-client/components/common/XPrint/PrintHtml.js +98 -98
  142. package/src/base-client/components/common/XPrint/css/hiPrintCss.js +359 -359
  143. package/src/base-client/components/common/XPrint/css/lodopCss.js +26 -26
  144. package/src/base-client/components/common/XPrint/css/print-lock.css +351 -351
  145. package/src/base-client/components/common/XPrint/index.vue +97 -97
  146. package/src/base-client/components/common/XReport/XReportDesign.vue +463 -463
  147. package/src/base-client/components/common/XReport/XReportJsonRender.vue +381 -381
  148. package/src/base-client/components/common/XReport/index.js +3 -3
  149. package/src/base-client/components/common/XReport/print.js +186 -186
  150. package/src/base-client/components/common/XReportDrawer/index.js +3 -3
  151. package/src/base-client/components/common/XReportGrid/index.js +3 -3
  152. package/src/base-client/components/common/XReportGrid/index.md +44 -44
  153. package/src/base-client/components/common/XReportSlot/XReportSlot.vue +110 -110
  154. package/src/base-client/components/common/XReportSlot/index.js +3 -3
  155. package/src/base-client/components/common/XReportSlot/index.md +48 -48
  156. package/src/base-client/components/common/XSimpleDescriptions/XSimpleDescriptions.vue +166 -166
  157. package/src/base-client/components/common/XSimpleDescriptions/index.js +3 -3
  158. package/src/base-client/components/common/XSimpleDescriptions/index.md +7 -7
  159. package/src/base-client/components/common/XStepView/XStepView.vue +252 -252
  160. package/src/base-client/components/common/XStepView/index.js +3 -3
  161. package/src/base-client/components/common/XStepView/index.md +31 -31
  162. package/src/base-client/components/common/XTab/XTabDemo.vue +22 -22
  163. package/src/base-client/components/common/XTab/index.js +3 -3
  164. package/src/base-client/components/common/XTable/CustomFuncCel.vue +51 -51
  165. package/src/base-client/components/common/XTable/TableCellRenderer.vue +161 -161
  166. package/src/base-client/components/common/XTable/XTableWrapper.vue +3 -3
  167. package/src/base-client/components/common/XTable/index.md +255 -255
  168. package/src/base-client/components/common/XTagGroup/index.vue +52 -52
  169. package/src/base-client/components/common/XTree/XTree.vue +424 -424
  170. package/src/base-client/components/common/XTree/XTreePro.vue +4 -4
  171. package/src/base-client/components/common/XTree/index.js +3 -3
  172. package/src/base-client/components/common/XTree/index.md +36 -36
  173. package/src/base-client/components/common/XTreeOne/XTreeOne.vue +113 -113
  174. package/src/base-client/components/common/XTreeOne/XTreeOnePro.vue +128 -128
  175. package/src/base-client/components/common/richTextModal/index.vue +56 -56
  176. package/src/base-client/components/common/richTextModal/richDemo.vue +48 -48
  177. package/src/base-client/components/his/XCharge/XChargeDemo.vue +145 -145
  178. package/src/base-client/components/his/XHisEditor/index.js +3 -3
  179. package/src/base-client/components/his/XRadio/XRadio.vue +1 -1
  180. package/src/base-client/components/index.js +51 -51
  181. package/src/base-client/components/layout/XTreeView/XTreeView.vue +130 -130
  182. package/src/base-client/components/layout/XTreeView/index.js +3 -3
  183. package/src/base-client/components/layout/XTreeView/index.md +46 -46
  184. package/src/base-client/components/system/DictionaryDetailsView/DictionaryDetailsView.vue +232 -232
  185. package/src/base-client/components/system/QueryParamsDetailsView/QueryParamsDetailsView.vue +281 -281
  186. package/src/base-client/plugins/Config.js +19 -19
  187. package/src/base-client/plugins/GetLoginInfoService.js +183 -183
  188. package/src/base-client/plugins/Recording.js +258 -258
  189. package/src/base-client/plugins/index.js +23 -23
  190. package/src/base-client/plugins/tabs-page-plugin.js +39 -39
  191. package/src/components/Charts/Bar.vue +62 -62
  192. package/src/components/Charts/ChartCard.vue +134 -134
  193. package/src/components/Charts/Liquid.vue +67 -67
  194. package/src/components/Charts/MiniArea.vue +39 -39
  195. package/src/components/Charts/MiniBar.vue +39 -39
  196. package/src/components/Charts/MiniProgress.vue +75 -75
  197. package/src/components/Charts/MiniSmoothArea.vue +40 -40
  198. package/src/components/Charts/Radar.vue +68 -68
  199. package/src/components/Charts/RankList.vue +77 -77
  200. package/src/components/Charts/TagCloud.vue +113 -113
  201. package/src/components/Charts/TransferBar.vue +64 -64
  202. package/src/components/Charts/Trend.vue +82 -82
  203. package/src/components/Charts/chart.less +12 -12
  204. package/src/components/Charts/smooth.area.less +13 -13
  205. package/src/components/CodeMirror/inedx.vue +118 -118
  206. package/src/components/CodeMirror/setting.js +40 -40
  207. package/src/components/FileImageItem/FileItem.vue +320 -320
  208. package/src/components/NumberInfo/NumberInfo.vue +54 -54
  209. package/src/components/NumberInfo/index.js +3 -3
  210. package/src/components/NumberInfo/index.less +54 -54
  211. package/src/components/NumberInfo/index.md +43 -43
  212. package/src/components/card/ChartCard.vue +79 -79
  213. package/src/components/chart/Bar.vue +60 -60
  214. package/src/components/chart/MiniArea.vue +67 -67
  215. package/src/components/chart/MiniBar.vue +59 -59
  216. package/src/components/chart/MiniProgress.vue +57 -57
  217. package/src/components/chart/Radar.vue +80 -80
  218. package/src/components/chart/RankingList.vue +60 -60
  219. package/src/components/chart/Trend.vue +79 -79
  220. package/src/components/chart/index.less +9 -9
  221. package/src/components/checkbox/ColorCheckbox.vue +157 -157
  222. package/src/components/checkbox/ImgCheckbox.vue +117 -117
  223. package/src/components/checkbox/ImgCheckboxGroup.vue +76 -76
  224. package/src/components/checkbox/index.js +9 -9
  225. package/src/components/exception/ExceptionPage.vue +70 -70
  226. package/src/components/g2Charts/constants.js +202 -202
  227. package/src/components/g2Charts/demo.vue +808 -808
  228. package/src/components/g2Charts/designer.vue +228 -228
  229. package/src/components/g2Charts/designerBaseConfig.vue +61 -61
  230. package/src/components/g2Charts/designerDataConfig.vue +259 -259
  231. package/src/components/g2Charts/designerStyleConfig.vue +16 -16
  232. package/src/components/g2Charts/index.vue +397 -397
  233. package/src/components/index.js +36 -36
  234. package/src/components/input/IInput.vue +66 -66
  235. package/src/components/menu/SideMenu.vue +75 -75
  236. package/src/components/menu/menu.js +273 -273
  237. package/src/components/setting/Setting.vue +234 -234
  238. package/src/components/tool/AStepItem.vue +60 -60
  239. package/src/config/CreateQueryConfig.js +325 -325
  240. package/src/config/default/antd.config.js +89 -89
  241. package/src/config/default/setting.config.js +55 -55
  242. package/src/font-style/font.css +60 -60
  243. package/src/layouts/CommonLayout.vue +56 -56
  244. package/src/layouts/PageLayout.vue +151 -151
  245. package/src/layouts/SinglePageView.vue +136 -136
  246. package/src/layouts/header/AdminHeader.vue +132 -132
  247. package/src/layouts/header/HeaderNotice.vue +177 -177
  248. package/src/layouts/header/InstitutionDetail.vue +181 -181
  249. package/src/layouts/tabs/TabsHead.vue +189 -189
  250. package/src/lib.js +1 -1
  251. package/src/mock/extend/index.js +84 -84
  252. package/src/mock/goods/index.js +108 -108
  253. package/src/pages/DefaultExample/index.vue +77 -77
  254. package/src/pages/DynamicStatistics/ChartSelector.vue +331 -331
  255. package/src/pages/DynamicStatistics/DataTabs.vue +83 -83
  256. package/src/pages/DynamicStatistics/DynamicTable.vue +128 -128
  257. package/src/pages/DynamicStatistics/EvaluationArea.vue +69 -69
  258. package/src/pages/DynamicStatistics/FavoriteList.vue +50 -50
  259. package/src/pages/DynamicStatistics/QuestionHistoryAndFavorites.vue +591 -591
  260. package/src/pages/DynamicStatistics/SearchBar.vue +192 -192
  261. package/src/pages/DynamicStatistics/index.vue +282 -282
  262. package/src/pages/Example/childIndex.vue +15 -15
  263. package/src/pages/Example/index.vue +30 -30
  264. package/src/pages/NewDynamicStatistics/ChartSelector.vue +331 -331
  265. package/src/pages/NewDynamicStatistics/DataTabs.vue +122 -122
  266. package/src/pages/NewDynamicStatistics/DynamicTable.vue +128 -128
  267. package/src/pages/NewDynamicStatistics/EvaluationArea.vue +69 -69
  268. package/src/pages/NewDynamicStatistics/FavoriteList.vue +50 -50
  269. package/src/pages/NewDynamicStatistics/QuestionHistoryAndFavorites.vue +289 -289
  270. package/src/pages/NewDynamicStatistics/SearchBar.vue +193 -193
  271. package/src/pages/NewDynamicStatistics/index.vue +258 -258
  272. package/src/pages/Recording/index.vue +77 -77
  273. package/src/pages/ServiceReview/index.vue +284 -284
  274. package/src/pages/SubExample/index.vue +26 -26
  275. package/src/pages/WorkflowDetail/WorkflowPageDetail/TrimTextTail.vue +23 -23
  276. package/src/pages/WorkflowDetail/WorkflowPageDetail/WorkFlowHandle.vue +1770 -1770
  277. package/src/pages/XReportView/index.vue +64 -64
  278. package/src/pages/XTreeOneProExample/index.vue +67 -67
  279. package/src/pages/dashboard/workplace/WorkPlace.vue +141 -141
  280. package/src/pages/login/Login.vue +379 -379
  281. package/src/pages/login/LoginV3.vue +389 -389
  282. package/src/pages/lowCode/lowCodeEditor.vue +1219 -1219
  283. package/src/pages/lowCode/lowCodeRenderPage.vue +43 -43
  284. package/src/pages/report/ReportTable.js +124 -124
  285. package/src/pages/resourceManage/orgListManage.vue +98 -98
  286. package/src/pages/system/dictionary/index.vue +44 -44
  287. package/src/pages/system/monitor/loginInfor/index.vue +37 -37
  288. package/src/pages/system/monitor/operLog/index.vue +37 -37
  289. package/src/pages/system/settings/modifyPassword.vue +117 -117
  290. package/src/pages/system/ticket/index.vue +480 -480
  291. package/src/pages/system/ticket/submitTicketSuccess.vue +484 -484
  292. package/src/pages/userInfoDetailManage/ChangeMeterRecordQuery/index.vue +64 -64
  293. package/src/pages/userInfoDetailManage/InfoChangeRecordQuery/index.vue +64 -64
  294. package/src/pages/userInfoDetailManage/InstructRecordQuery/index.vue +64 -64
  295. package/src/pages/userInfoDetailManage/MeterParamRecordQuery/index.vue +64 -64
  296. package/src/pages/userInfoDetailManage/TransferRecordQuery/index.vue +66 -66
  297. package/src/pages/userInfoDetailManage/WatchCollectionRecordQuery/index.vue +64 -64
  298. package/src/plugins/EventLogPlugin.js +33 -33
  299. package/src/plugins/FindParentsData.js +17 -17
  300. package/src/services/DataModel.js +30 -30
  301. package/src/services/LodopFuncs.js +137 -137
  302. package/src/services/api/TicketDetailsViewApi.js +46 -46
  303. package/src/services/api/cas.js +79 -79
  304. package/src/services/api/entity.js +18 -18
  305. package/src/services/api/index.js +17 -17
  306. package/src/store/modules/account.js +115 -115
  307. package/src/store/modules/index.js +5 -5
  308. package/src/store/modules/lowCode.js +33 -33
  309. package/src/store/modules/setting.js +119 -119
  310. package/src/theme/default/style.less +58 -58
  311. package/src/utils/authority-utils.js +85 -85
  312. package/src/utils/errorCode.js +6 -6
  313. package/src/utils/formatter.js +74 -74
  314. package/src/utils/htmlToPDF.js +108 -108
  315. package/src/utils/htmlToPDFApi.js +5 -5
  316. package/src/utils/login.js +188 -188
  317. package/src/utils/lowcode/lowcodeComponentMixin.js +120 -120
  318. package/src/utils/lowcode/lowcodeLog.js +29 -29
  319. package/src/utils/lowcode/lowcodeUtils.js +373 -373
  320. package/src/utils/lowcode/registerComponentForEditor.js +1 -1
  321. package/src/utils/lowcode/registerComponentForRender.js +11 -11
  322. package/src/utils/map-utils.js +47 -47
  323. package/src/utils/reg.js +95 -95
  324. package/src/utils/runEvalFunction.js +14 -14
  325. package/src/utils/theme-color-replacer-extend.js +92 -92
  326. package/src/utils/util.js +329 -329
  327. package/src/utils/waterMark.js +31 -31
  328. package//350/277/201/347/247/273/346/227/245/345/277/227.md +15 -15
@@ -1,1280 +1,1280 @@
1
- <template>
2
- <div id="XAddNativeForm">
3
- <a-form-model
4
- v-if="loaded"
5
- ref="selectForm"
6
- :zIndex="1001"
7
- :model="form"
8
- v-bind="formItemLayoutGen"
9
- :layout="layout">
10
- <template v-for="(item, key) in childTableData">
11
- <a-row
12
- v-if="childTablePriority"
13
- :gutter="16"
14
- :key="'childTableRow' + key">
15
- <a-card :title="item.name" :bordered="false" size="small">
16
- <x-form-table
17
- :key="'childTable_' + item.model"
18
- :title="item.name"
19
- :queryParamsName="item.childTableConfigName"
20
- :localEditMode="true"
21
- :fixed-query-form="childTableFixedQueryForm(item)"
22
- :service-name="serviceName"
23
- @innerXFormTableEmit="innerXFormTableEmit"
24
- @afterTableInit="childTableMounted(item)"
25
- :ref="'childXFormTable_' + item.model">
26
- </x-form-table>
27
- </a-card>
28
- </a-row>
29
- </template>
30
- <template v-if="isSimpleInlineMode">
31
- <a-row
32
- v-for="(row, rowIndex) in simpleInlineRows"
33
- :key="'simple-row-' + rowIndex"
34
- :gutter="0"
35
- type="flex">
36
- <a-col
37
- v-for="(item, itemIndex) in row.items"
38
- :key="'simple-item-' + itemIndex"
39
- :span="item.span">
40
- <x-form-item
41
- class="simple-inline-item"
42
- :attr="item.formItem"
43
- :disabled="itemDisabled(item.formItem)"
44
- :read-only="readonly(item.formItem)"
45
- :files="files"
46
- :form="form"
47
- :images="images"
48
- :service-name="serviceName"
49
- mode="新增/修改"
50
- layout="simple-inline"
51
- :rules="rules[`${item.formItem.name}${item.formItem.model}`]"
52
- :get-data-params="getDataParams"
53
- :env="env"
54
- @x-form-item-emit-func="emitFunc"
55
- @rowChoose="rowChoose"
56
- :setForm="setForm"
57
- :style="{ margin: 0, padding: '2px' }"
58
- />
59
- </a-col>
60
- </a-row>
61
- </template>
62
- <a-row ref="GroupItemRow" v-if="!isSimpleInlineMode">
63
- <a-col :span="3" v-if="!inXFormGroup && !(groups[0].groupName === DEFAULT_GROUP_NAME)">
64
- <a-tabs tab-position="left" v-model="activeTab" @change="scrollToGroup">
65
- <a-tab-pane
66
- v-for="(groupsItem,groupsIndex) in groups"
67
- :tab="groupsItem.groupName"
68
- :key="groupsIndex">
69
- </a-tab-pane>
70
- </a-tabs>
71
- </a-col>
72
- <a-col
73
- :span="(!inXFormGroup && !(groups[0].groupName === DEFAULT_GROUP_NAME)) ? 21: 24">
74
- <a-row
75
- :gutter="16"
76
- type="flex"
77
- :key="groupsIndex"
78
- v-for="(groupsItem,groupsIndex) in groups"
79
- >
80
- <a-col
81
- :span="24"
82
- :style="{ marginTop: groupsIndex === 0 ? '' : '8px',fontSize:inXFormGroup?'15px':'14px', marginLeft:'-5px' }"
83
- v-if="groupsItem.groupName !== DEFAULT_GROUP_NAME">
84
- <span class="xFormGroupTitle" :ref="`group-title-${groupsIndex}`">{{ groupsItem.groupName }}</span>
85
- </a-col>
86
- <x-form-item
87
- v-for="(item, index) in groupsItem.realJsonData"
88
- :key="index"
89
- :attr="item"
90
- :disabled="itemDisabled(item)"
91
- :read-only="readonly(item)"
92
- :files="files"
93
- v-bind="formItemLayoutGen"
94
- :style="layout === 'inline' ? { marginTop:'5px' } : undefined"
95
- :form="form"
96
- :images="images"
97
- :service-name="serviceName"
98
- mode="新增/修改"
99
- :layout="layout"
100
- :rules="rules[`${item.name}${item.model}`]"
101
- :get-data-params="getDataParams"
102
- :env="env"
103
- @x-form-item-emit-func="emitFunc"
104
- @rowChoose="rowChoose"
105
- :setForm="setForm"
106
- />
107
- </a-row>
108
- </a-col>
109
- </a-row>
110
- <a-row :gutter="16" v-for="(groupItem, groupIndex) in groupJsonData" :key="groupIndex" v-if="!isSimpleInlineMode">
111
- <a-card v-if="groupItem.groupItems.length > 0" :title="groupItem.name" :bordered="false" size="small">
112
- <x-form-item
113
- v-for="(item, index) in groupItem.groupItems"
114
- :key="index"
115
- :attr="item"
116
- :disabled="itemDisabled(item)"
117
- :readonly="readonly(item)"
118
- :files="files"
119
- v-bind="formItemLayoutGen"
120
- :style="layout ==='inline'?{marginTop:'5px'}:undefined"
121
- :form="form[groupItem.model]"
122
- :images="images"
123
- :service-name="serviceName"
124
- mode="新增/修改"
125
- :rules="rules[`${item.name}${item.model}`]"
126
- :get-data-params="getDataParams"
127
- :env="env"
128
- :setForm="setForm"
129
- @rowChoose="rowChoose"
130
- />
131
- </a-card>
132
- <template v-else>
133
- <slot
134
- name="groupFormItems"
135
- :form="form"
136
- :model="groupItem.model"
137
- :rules="rules"
138
- :modifyModelData="modifyModelData"></slot>
139
- </template>
140
- </a-row>
141
- <a-row :gutter="16" v-for="(item, key) in simpleFormJsonData" :key="'row' + key" v-if="!isSimpleInlineMode">
142
- <a-card v-if="item.value.length > 0" :title="item.name" :bordered="false" size="small">
143
- <x-form-item
144
- v-for="(formItem, formItemIndex) in item.value"
145
- :key="key + formItemIndex"
146
- :attr="formItem"
147
- :disabled="itemDisabled(formItem)"
148
- :readonly="readonly(formItem)"
149
- :files="files"
150
- v-bind="formItemLayoutGen"
151
- :style="layout ==='inline'?{marginTop:'5px'}:undefined"
152
- :form="form[groupItem.model]"
153
- :images="images"
154
- :service-name="serviceName"
155
- mode="新增/修改"
156
- :rules="rules[`${item.name}${item.model}`]"
157
- :get-data-params="getDataParams"
158
- :env="env"
159
- :setForm="setForm"
160
- @rowChoose="rowChoose"
161
- />
162
- </a-card>
163
- </a-row>
164
- <template v-for="(item, key) in childTableData">
165
- <a-row
166
- v-if="!childTablePriority"
167
- :gutter="16"
168
- :key="'childTableRow' + key">
169
- <a-card :title="item.name" :bordered="false" size="small">
170
- <x-form-table
171
- :key="'childTable_' + item.model"
172
- :title="item.name"
173
- :queryParamsName="item.childTableConfigName"
174
- :localEditMode="true"
175
- @innerXFormTableEmit="innerXFormTableEmit"
176
- :fixed-query-form="childTableFixedQueryForm(item)"
177
- :service-name="serviceName"
178
- @afterTableInit="childTableMounted(item)"
179
- :ref="'childXFormTable_' + item.model">
180
- </x-form-table>
181
- </a-card>
182
- </a-row>
183
- </template>
184
- <a-row type="flex" :justify="btnPlace" :style="{paddingLeft: '16px',paddingRight: '16px'}">
185
- <slot name="footer" :loading="loading">
186
- <a-button v-if="showSubmitBtn" :loading="loading" type="primary" @click="onSubmit()">{{ btnName }}</a-button>
187
- </slot>
188
- </a-row>
189
- </a-form-model>
190
- </div>
191
- </template>
192
- <script>
193
- import XFormItem from '@vue2-client/base-client/components/common/XForm/XFormItem'
194
- import { formatDate, setDataByRealKey } from '@vue2-client/utils/util'
195
- import * as util from '@vue2-client/utils/util'
196
- import { mapState } from 'vuex'
197
- import { addOrModify, getConfigByName, getConfigByNameAsync, runLogic } from '@vue2-client/services/api/common'
198
- import { checkIdNumber, REG_EMAIL, REG_LANDLINE, REG_PHONE } from '@vue2-client/utils/reg'
199
- import moment from 'moment/moment'
200
- import { executeStrFunction, executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
201
- import formValidationMixin from '@vue2-client/mixins/formValidationMixin'
202
-
203
- const DEFAULT_GROUP_NAME = '__default__'
204
- export default {
205
- name: 'XAddNativeForm',
206
- components: {
207
- XFormItem,
208
- XFormTable: () => import('@vue2-client/base-client/components/common/XFormTable/XFormTable.vue')
209
- },
210
- inject: {
211
- inXFormGroup: {
212
- default: false
213
- },
214
- formGroupContext: {
215
- default: null
216
- },
217
- formDataChange: {
218
- default: null
219
- }
220
- },
221
- props: {
222
- // 是否启用 horizontal 模式的自定义配置
223
- enableHorizontalCustom: {
224
- type: Boolean,
225
- default: false
226
- }
227
- },
228
- data () {
229
- return {
230
- DEFAULT_GROUP_NAME,
231
- // 预览模式
232
- viewMode: false,
233
- // 是否处理表单Key值
234
- isHandleFormKey: true,
235
- // 内容加载是否完成
236
- loaded: false,
237
- // 业务类型
238
- businessType: '',
239
- // 业务标题
240
- title: '',
241
- // 新增或修改业务是否执行中
242
- loading: false,
243
- // 表单Model
244
- form: {},
245
- // 配置名称
246
- configName: undefined,
247
- // 配置内容,用于查询配置生成器的预览
248
- configContent: undefined,
249
- // 表单项集合
250
- formItems: [],
251
- // 服务名称
252
- serviceName: undefined,
253
- // 是否显示提交按钮
254
- showSubmitBtn: true,
255
- // 修改有文件的表单时使用
256
- files: [],
257
- images: [],
258
- // 校验
259
- rules: {},
260
- // 调用logic获取数据源的追加参数
261
- getDataParams: {},
262
- // 动态简易表单集合
263
- simpleFormJsonData: {},
264
- // 待修改的数据集
265
- modifyModelData: {},
266
- // 当前环境
267
- env: 'prod',
268
- // 表单主键
269
- primaryKey: null,
270
- // 表单模式 horizontal | vertical | inline
271
- layout: 'horizontal',
272
- // 提交按钮名称
273
- btnName: '提交',
274
- // 提交按钮位置 start / center / end
275
- btnPlace: 'center',
276
- // 子表是否排在前面
277
- childTablePriority: false,
278
- // simple-inline布局配置
279
- simpleInline: null
280
- }
281
- },
282
- computed: {
283
- // 过滤出用于新增/修改场景的表单项
284
- realJsonData: function () {
285
- return this.formItems.filter((item) => {
286
- return item.addOrEdit && item.addOrEdit !== 'no' && item.addOrEdit !== 'silenceAdd' && item.addOrEdit !== 'version' && !this.itemDisabled(item)
287
- })
288
- },
289
- // 表单项组 / 不是 数据组
290
- groups: function () {
291
- if (!this.realJsonData || this.realJsonData.length === 0) {
292
- return [{
293
- groupName: DEFAULT_GROUP_NAME,
294
- realJsonData: this.realJsonData,
295
- xAddFormLayout: 'horizontal'
296
- }]
297
- }
298
- const uniqueGroups = new Set(this.realJsonData.map(item => item.group).filter(Boolean))
299
- const allGroup = Array.from(uniqueGroups).map(group => {
300
- return {
301
- groupName: group,
302
- realJsonData: this.realJsonData.filter(item => item.group === group),
303
- xAddFormLayout: 'horizontal'
304
- }
305
- })
306
- // 判断每一组得formJson 长度相加是否等于 realJsonData 长度 避免错误数据
307
- if (allGroup.reduce((total, item) => total + item.realJsonData.length, 0) === this.realJsonData.length) {
308
- return allGroup
309
- } else {
310
- return [{
311
- groupName: DEFAULT_GROUP_NAME,
312
- realJsonData: this.realJsonData,
313
- xAddFormLayout: 'horizontal'
314
- }]
315
- }
316
- },
317
- // 拥有自定义校验函数得表单项
318
- customValidateItems: function () {
319
- return this.formItems.filter((item) => {
320
- return item?.rule?.type === 'customJs'
321
- })
322
- },
323
- // 过滤出用于新增/修改场景的表单项
324
- groupJsonData: function () {
325
- return this.formItems.filter((item) => {
326
- return item.type === 'group'
327
- }).map((item) => {
328
- item.groupItems = item.groupItems.filter((item) => {
329
- return item.addOrEdit && item.addOrEdit !== 'no' && item.addOrEdit !== 'silenceAdd' && item.addOrEdit !== 'version' && !this.itemDisabled(item)
330
- }).map((groupItem) => {
331
- // 只保留第一个下划线后面的内容
332
- // 多层校验规则需要将prop设置为 key1.key2.....
333
- groupItem.prop = `${item.model}.${groupItem.model.substring(groupItem.model.indexOf('_') + 1)}`
334
- groupItem.model = groupItem.model.substring(groupItem.model.indexOf('_') + 1)
335
- return groupItem
336
- })
337
- return item
338
- }
339
- )
340
- },
341
- // 过滤出用于子表数据新增/修改场景的表单项
342
- childTableData: function () {
343
- return this.formItems.filter((item) => {
344
- return item.type === 'childTable'
345
- })
346
- },
347
- // 过滤出用于form子表数据新增/修改场景的表单项
348
- childFormData: function () {
349
- return this.formItems.filter((item) => {
350
- return item.type === 'rowEdit'
351
- })
352
- },
353
- // 过滤出用于静默新增场景的表单项
354
- silenceAddJsonData: function () {
355
- return this.formItems.filter(function (item) {
356
- return item.addOrEdit === 'silenceAdd'
357
- })
358
- },
359
- // 过滤出版本号表单项
360
- versionJsonData: function () {
361
- return this.formItems.filter(function (item) {
362
- return item.addOrEdit === 'version'
363
- })
364
- },
365
- formItemLayoutGen () {
366
- if (this.layout === 'simple-inline') {
367
- return {
368
- labelCol: { span: 0 },
369
- wrapperCol: { span: 24 }
370
- }
371
- }
372
- if (this.layout === 'horizontal') {
373
- // 如果启用了自定义配置,从 formItemLayout 读取(支持 0 值)
374
- if (this.enableHorizontalCustom && this.formItemLayout) {
375
- return {
376
- labelCol: {
377
- span: (this.formItemLayout.labelCol ?? 4),
378
- offset: (this.formItemLayout.offset ?? 2)
379
- },
380
- wrapperCol: { span: (this.formItemLayout.wrapperCol ?? 14) },
381
- }
382
- }
383
- // 默认配置
384
- return {
385
- labelCol: { span: 4, offset: 2 },
386
- wrapperCol: { span: 14 },
387
- }
388
- } else if (this.layout === 'vertical') {
389
- return {}
390
- } else {
391
- if (!this.formItemLayout.labelCol || !this.formItemLayout.wrapperCol) {
392
- return {
393
- labelCol: { span: 8 },
394
- wrapperCol: { span: 16 },
395
- }
396
- }
397
- return {
398
- labelCol: { span: this.formItemLayout.labelCol },
399
- wrapperCol: { span: this.formItemLayout.wrapperCol },
400
- }
401
- }
402
- },
403
- // simple-inline模式判断
404
- isSimpleInlineMode () {
405
- return this.layout === 'simple-inline' && this.simpleInline
406
- },
407
- // simple-inline布局行数据
408
- simpleInlineRows () {
409
- if (!this.isSimpleInlineMode) return []
410
- return this.simpleInline.rows.map(row => ({
411
- ...row,
412
- items: row.items.map(item => ({
413
- ...item,
414
- formItem: this.realJsonData.find(f =>
415
- f.model === item.key && f.name === item.title
416
- )
417
- })).filter(item => item.formItem)
418
- }))
419
- },
420
- ...mapState('account', { currUser: 'user' })
421
- },
422
- provide () {
423
- return {
424
- getComponentByName: this.getComponentByName,
425
- registerComponent: this.registerComponent,
426
- XFormContext: this,
427
- // 移除必填项
428
- removeRequired: this.removeRequired,
429
- // 设置必填项
430
- setRequired: this.setRequired,
431
- getSelf: () => this,
432
- }
433
- },
434
- watch: {
435
- form: {
436
- handler (val) {
437
- if (this.formDataChange && typeof this.formDataChange === 'function') {
438
- this.formDataChange(val)
439
- }
440
- },
441
- deep: true
442
- }
443
- },
444
- /** //todo 本来想要实现 配置 自定义函数时,表单项得红星提示,根据自定义校验函数得返回值来判断
445
- * 但是监听不到父组件formgorup得其他form得变化,所以暂时不实现
446
- */
447
- //
448
- // watch: {
449
- // form: {
450
- // handler (val) {
451
- // // 遍历表单配置
452
- // if (this.customValidateItems.length > 0) {
453
- // for (const item of this.customValidateItems) {
454
- // const itemIndex = this.formItems.findIndex(formItem => formItem.model === item.model)
455
- // if (itemIndex < 0) {
456
- // continue
457
- // }
458
- // try {
459
- // this.customJsValidate(null, val[item.model], (res) => {
460
- // // 如果返回error则设置错误信息
461
- // if (res instanceof Error) {
462
- // // 设置表单项的错误状态
463
- // this.$set(this.formItems[itemIndex], 'tempRequired', true)
464
- // } else {
465
- // // 清除错误状态
466
- // this.$set(this.formItems[itemIndex], 'tempRequired', true)
467
- // }
468
- // }, item)
469
- // } catch (e) {
470
- // console.error(e)
471
- // this.$set(this.formItems[itemIndex], 'tempRequired', true)
472
- // }
473
- // }
474
- // console.log('customValidateItems', JSON.stringify(this.customValidateItems))
475
- // }
476
- // },
477
- // deep: true
478
- // }
479
- // },
480
- mixins: [formValidationMixin],
481
- methods: {
482
- runLogic,
483
- getConfigByNameAsync,
484
- getConfigByName,
485
- init (params) {
486
- const {
487
- configName,
488
- configContent,
489
- formItems,
490
- formJson,
491
- viewMode,
492
- isHandleFormKey,
493
- isKeyHandle = true,
494
- showSubmitBtn = true,
495
- serviceName,
496
- primaryKey,
497
- modifyModelData = {},
498
- businessType,
499
- title,
500
- fixedAddForm = {},
501
- getDataParams = {},
502
- simpleFormJsonData = {},
503
- env = 'prod',
504
- layout,
505
- xAddFormLayout = 'horizontal',
506
- formItemLayout = {},
507
- btnName = '提交',
508
- childTablePriority = false,
509
- btnPlace = 'center',
510
- simpleInline = null,
511
- paramLogicName,
512
- paramLogicNameParam
513
- } = params
514
- this.loaded = false
515
- // 兼容需要省略 传递 layout: res.xAddFormLayout 可以使用 ...res 展开运算符 直接转递
516
- if (xAddFormLayout && layout === undefined) {
517
- this.layout = xAddFormLayout
518
- } else {
519
- this.layout = layout
520
- }
521
- this.formItemLayout = formItemLayout
522
- if ((isHandleFormKey === null || isHandleFormKey === undefined) && !isKeyHandle) {
523
- this.isHandleFormKey = isKeyHandle
524
- } else if (isHandleFormKey) {
525
- this.isHandleFormKey = isHandleFormKey
526
- } else {
527
- this.isHandleFormKey = isKeyHandle
528
- }
529
- this.childTablePriority = childTablePriority
530
- this.configName = configName
531
- this.configContent = configContent
532
- this.formItems = this.getFromItem(formItems, formJson)
533
- this.viewMode = viewMode
534
- this.showSubmitBtn = showSubmitBtn
535
- this.primaryKey = primaryKey
536
- this.serviceName = serviceName
537
- this.businessType = businessType
538
- this.title = title
539
- this.getDataParams = getDataParams
540
- this.simpleFormJsonData = simpleFormJsonData
541
- this.env = env
542
- this.btnName = btnName
543
- this.btnPlace = btnPlace
544
- this.simpleInline = simpleInline
545
- // 如果 fixedAddForm 有 selected_id 值,并且设置了处理表单key值,则多给 selected_id 加前缀 避免处理错误
546
- if (fixedAddForm.selected_id && this.isHandleFormKey) {
547
- fixedAddForm._selected_id = fixedAddForm.selected_id
548
- delete fixedAddForm.selected_id
549
- }
550
- // 设置普通表单项的相关参数
551
- const formData = Object.assign({}, fixedAddForm)
552
- if (paramLogicName) {
553
- runLogic(paramLogicName, paramLogicNameParam, this.serviceName).then(res => {
554
- Object.assign(formData, res)
555
- })
556
- }
557
- for (let i = 0; i < this.realJsonData.length; i++) {
558
- const item = this.realJsonData[i]
559
- this.setFormProps(formData, item, null)
560
- }
561
- // 设置表单分组项目相关参数
562
- for (let i = 0; i < this.groupJsonData.length; i++) {
563
- const groupItem = this.groupJsonData[i]
564
- formData[groupItem.model] = {}
565
- for (let j = 0; j < groupItem.groupItems.length; j++) {
566
- const item = groupItem.groupItems[j]
567
- this.setFormProps(formData[groupItem.model], item, item.prop)
568
- }
569
- }
570
- // 设置动态简易表单项的相关参数
571
- for (const key in this.simpleFormJsonData) {
572
- for (const item of this.simpleFormJsonData[key].value) {
573
- item.model = key + '@' + item.model
574
- this.setFormProps(formData, item, null)
575
- }
576
- }
577
-
578
- this.form = formData
579
- // 修改场景下对表单项赋值
580
- if (modifyModelData && modifyModelData.data) {
581
- this.modifyModelData = modifyModelData
582
- if (Object.keys(modifyModelData.data).length > 0) {
583
- this.getModifyModelData(modifyModelData)
584
- }
585
- }
586
- // 处理表单得附件
587
- if (modifyModelData && modifyModelData.files) {
588
- this.files = modifyModelData.files
589
- }
590
- if (modifyModelData && modifyModelData.images) {
591
- this.images = modifyModelData.images
592
- }
593
- this.loaded = true
594
- },
595
- scrollToGroup (index) {
596
- const groupElement = this.$refs[`group-title-${index}`][0]
597
- if (groupElement) {
598
- groupElement.scrollIntoView({ behavior: 'smooth' })
599
- }
600
- },
601
- registerComponent (componentName, component) {
602
- console.log('内部注册', this.$options.name, componentName)
603
- this.$refs[componentName] = component
604
- console.log('内部注册完成', this.$refs)
605
- },
606
- // 根据名字从注册到组件中获取组件
607
- getComponentByName (componentName) {
608
- console.log('内部取组件', this.$options.name, componentName)
609
- console.log('内部组件内容', this.$refs)
610
- return this.$refs[componentName]
611
- },
612
- // 兼容需要省略 传递 [formItems: res.formJson ] 可以使用 ...res 展开运算符 直接转递
613
- getFromItem (formItems, formJson) {
614
- const _formItems = formItems || formJson
615
- if (typeof formItems === 'string') {
616
- return JSON.parse(_formItems)
617
- } else {
618
- return JSON.parse(JSON.stringify(_formItems))
619
- }
620
- },
621
- innerXFormTableEmit (fun, record, id, actionType, index) {
622
- this.$emit(fun, record, id, actionType, index)
623
- },
624
- // 时间组件赋默认值
625
- // .type, item.formDefault
626
- getDateRange ({ type, formDefault: defaultValue, formValueFormat }) {
627
- // const format = type === 'datePicker' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'
628
- let format = 'YYYY-MM-DD HH:mm:ss'
629
- if (formValueFormat) {
630
- format = formValueFormat
631
- }
632
- let start
633
- switch (defaultValue) {
634
- case 'curYear':
635
- start = moment().startOf('year').format(format)
636
- break
637
- case 'curMonth':
638
- start = moment().startOf('month').format(format)
639
- break
640
- case 'curDay':
641
- start = moment().startOf('day').format(format)
642
- break
643
- case 'curTime':
644
- start = moment().format(format)
645
- break
646
- default:
647
- return defaultValue
648
- }
649
- return start
650
- },
651
- setFormProps (formData, item, groupItem) {
652
- const rulesKey = `${item.name}${item.model}`
653
- if (formData[item.model] === undefined || formData[item.model] === null) {
654
- formData[item.model] = undefined
655
- }
656
- if (!formData[item.model] && item.formDefault) {
657
- if (['datePicker', 'rangePicker', 'yearPicker', 'monthPicker', 'yearRangePicker', 'monthRangePicker'].includes(item.type)) {
658
- formData[item.model] = this.getDateRange(item)
659
- } else if (['treeSelect', 'select', 'checkbox'].includes(item.type) && ['curOrgId', 'curDepId', 'curUserId'].includes(item.formDefault)) {
660
- if (item.formDefault === 'curOrgId') {
661
- formData[item.model] = item.type === 'select' ? this.currUser.orgid : [this.currUser.orgid]
662
- }
663
- if (item.formDefault === 'curDepId') {
664
- formData[item.model] = item.type === 'select' ? this.currUser.depids : [this.currUser.depids]
665
- }
666
- if (item.formDefault === 'curUserId') {
667
- formData[item.model] = item.type === 'select' ? this.currUser.id : [this.currUser.id]
668
- }
669
- } else if (['addressSearch'].includes(item.type)) {
670
- formData[item.model] = item.formDefault
671
- formData[`${item.model}_lng_lat`] = item.formDefault_lng_lat
672
- } else {
673
- formData[item.model] = item.formDefault
674
- }
675
- }
676
- // 处理表单校验情况
677
- if (item.rule) {
678
- if (groupItem) {
679
- this.rules[groupItem] = []
680
- } else {
681
- this.rules[rulesKey] = []
682
- }
683
- const required = item.rule.required ? item.rule.required === true || item.rule.required === 'true' : false
684
- let trigger
685
- let message
686
- if (required) {
687
- switch (item.type) {
688
- case 'select':
689
- case 'checkbox':
690
- case 'radio':
691
- case 'treeSelect':
692
- case 'rangePicker':
693
- case 'monthPicker':
694
- case 'yearPicker':
695
- case 'datePicker':
696
- case 'file':
697
- case 'image':
698
- case 'citySelect':
699
- case 'addressSearch':
700
- case 'personSetting':
701
- message = '请选择' + item.name
702
- trigger = 'change'
703
- break
704
- default:
705
- message = '请输入' + item.name
706
- trigger = 'blur'
707
- }
708
- if (groupItem) {
709
- this.rules[groupItem].push({
710
- required: true,
711
- message: message,
712
- trigger: trigger
713
- })
714
- } else {
715
- this.rules[rulesKey].push({
716
- required: true,
717
- message: message,
718
- trigger: trigger
719
- })
720
- }
721
- }
722
-
723
- switch (item.rule.type) {
724
- case 'number':
725
- case 'integer':
726
- case 'float':
727
- // eslint-disable-next-line no-case-declarations
728
- let defaultValue
729
- // eslint-disable-next-line no-case-declarations
730
- let message
731
- switch (item.rule.type) {
732
- case 'number':
733
- item.numberInput = true
734
- message = '数字'
735
- defaultValue = 0
736
- break
737
- case 'integer':
738
- item.numberInput = true
739
- message = '整数'
740
- defaultValue = 0
741
- break
742
- case 'float':
743
- item.numberInput = true
744
- message = '小数'
745
- defaultValue = 0.0
746
- break
747
- }
748
- if (groupItem) {
749
- this.rules[groupItem].push({
750
- type: item.rule.type,
751
- message: item.name + '必须为' + message,
752
- transform: (value) => {
753
- if (value && value.length !== 0) {
754
- return Number(value)
755
- } else {
756
- return defaultValue
757
- }
758
- },
759
- trigger: 'blur'
760
- })
761
- } else {
762
- this.rules[rulesKey].push({
763
- type: item.rule.type,
764
- message: item.name + '必须为' + message,
765
- transform: (value) => {
766
- if (value && value.length !== 0) {
767
- return Number(value)
768
- } else {
769
- return defaultValue
770
- }
771
- },
772
- trigger: 'blur'
773
- })
774
- }
775
- break
776
- case 'email': {
777
- const validator = (rule, value, callback) => {
778
- if (value && !REG_EMAIL.test(value)) {
779
- callback(new Error('请输入正确的邮箱地址'))
780
- } else {
781
- callback()
782
- }
783
- }
784
- this.rules[groupItem || rulesKey].push({
785
- type: 'email',
786
- validator: validator,
787
- message: '请输入正确的邮箱地址',
788
- trigger: 'blur'
789
- })
790
- break
791
- }
792
- case 'userPhone': {
793
- this.rules[groupItem || rulesKey].push({
794
- type: 'userPhone',
795
- validator: (rule, value, callback) => {
796
- if (value && !REG_PHONE.test(value)) {
797
- callback(new Error('请输入正确的手机号码'))
798
- } else {
799
- callback()
800
- }
801
- },
802
- message: '请输入正确的手机号码',
803
- trigger: 'blur'
804
- })
805
- break
806
- }
807
- case 'idNumber': {
808
- this.rules[groupItem || rulesKey].push({
809
- validator: (rule, value, callback) => {
810
- if (value && !checkIdNumber(value)) {
811
- callback(new Error('请输入正确的身份证号码'))
812
- } else {
813
- callback()
814
- }
815
- },
816
- trigger: 'blur'
817
- })
818
- break
819
- }
820
- case 'landlineNumber': {
821
- this.rules[rulesKey].push({
822
- validator: (rule, value, callback) => {
823
- if (value && !REG_LANDLINE.test(value)) {
824
- callback(new Error('请输入正确的座机号码'))
825
- } else {
826
- callback()
827
- }
828
- },
829
- trigger: 'blur'
830
- })
831
- break
832
- }
833
- // 大于0
834
- case 'greaterThanZero': {
835
- item.numberInput = true
836
- this.rules[rulesKey].push({
837
- validator: (rule, value, callback) => {
838
- if (isNaN(value) || value <= 0) {
839
- callback(new Error('请输入一个大于0的数字'))
840
- } else {
841
- callback()
842
- }
843
- },
844
- trigger: 'blur'
845
- })
846
- break
847
- }
848
- // 大于等于0
849
- case 'greaterThanOrEqualZero': {
850
- item.numberInput = true
851
- this.rules[rulesKey].push({
852
- validator: (rule, value, callback) => {
853
- if (isNaN(value) || value < 0) {
854
- callback(new Error('请输入一个大于等于0的数字'))
855
- } else {
856
- callback()
857
- }
858
- },
859
- trigger: 'blur'
860
- })
861
- break
862
- }
863
- case 'stringLength': {
864
- this.rules[rulesKey].push({
865
- validator: (rule, value, callback) => {
866
- if (value && value.length < item.rule.minLen) {
867
- callback(new Error('长度不能少于' + item.rule.minLen + '个字符'))
868
- } else if (value && value.length > item.rule.maxLen) {
869
- callback(new Error('长度不能超过' + item.rule.maxLen + '个字符'))
870
- } else {
871
- callback()
872
- }
873
- },
874
- trigger: 'blur'
875
- })
876
- break
877
- }
878
- case 'customJs': {
879
- this.rules[rulesKey].push({
880
- validator: (rule, value, callback) => {
881
- this.customJsValidate(rule, value, callback, item)
882
- },
883
- trigger: 'blur'
884
- })
885
- break
886
- }
887
- }
888
- }
889
- },
890
- childTableMounted (item) {
891
- // 子表初始化时,设置表格数据
892
- if (this.form[item.model] && this.form[item.model].length > 0) {
893
- this.$refs[`childXFormTable_${item.model}`][0].setTableData(this.form[item.model])
894
- }
895
- },
896
- customJsValidate (rule, value, callback, item) {
897
- if (item.rule.customValidatorFunc) {
898
- executeStrFunctionByContext(this, item.rule.customValidatorFunc, [rule, value, callback, this.form, item, this.util, runLogic, getConfigByNameAsync])
899
- } else {
900
- callback()
901
- }
902
- },
903
- itemDisabled (value) {
904
- return (this.businessType === '新增' && value.addOrEdit === 'edit') ||
905
- (this.businessType === '修改' && value.addOrEdit === 'add')
906
- },
907
- readonly (value) {
908
- return value.addOrEdit === 'readonly'
909
- },
910
- async onSubmit () {
911
- const valid = await this.validateForm()
912
- if (!valid) return false
913
- if (this.viewMode) {
914
- this.$message.info('预览模式禁止新增和修改')
915
- return false
916
- }
917
- this.loading = true
918
- const requestForm = this.prepareForm()
919
- await this.appendSilenceAddFields(requestForm)
920
- const realForm = this.handleFormKeys(requestForm)
921
- // 增加子表数据
922
- if (this.childTableData.length > 0) {
923
- for (const item of this.childTableData) {
924
- const childModel = item.model
925
- const childDataRef = this.$refs['childXFormTable_' + item.model][0].getTableData()
926
- const childData = []
927
- for (const item of childDataRef) {
928
- childData.push(JSON.parse(JSON.stringify(item)))
929
- }
930
- for (let i = 0; i < childData.length; i++) {
931
- childData[i] = this.handleFormKeys(childData[i])
932
- // 外键不需要带表别名,所以此处放到表单处理后赋值
933
- if (realForm.id) {
934
- childData[i][item.childTableForeignKeyName] = realForm.id
935
- }
936
- }
937
- realForm[childModel] = childData
938
- }
939
- }
940
- // 增加form子表数据
941
- if (this.childFormData.length > 0) {
942
- for (const item of this.childFormData) {
943
- const childModel = item.model
944
- const childData = this.$refs[item.model].getTableData()
945
- for (let i = 0; i < childData.length; i++) {
946
- childData[i] = this.handleFormKeys(childData[i], true)
947
- // 外键不需要带表别名,所以此处放到表单处理后赋值
948
- if (realForm.id) {
949
- childData[i][item.foreignKey] = realForm.id
950
- }
951
- }
952
- realForm[childModel] = childData
953
- }
954
- }
955
- if (this.$listeners.onSubmit) {
956
- // 交由父级处理
957
- this.$emit('onSubmit', {
958
- businessType: this.businessType,
959
- serviceName: this.serviceName,
960
- realForm: realForm,
961
- currUserName: this.currUser.name,
962
- currUserId: this.currUser.id,
963
- orgId: this.currUser.orgid
964
- })
965
- } else {
966
- this.defaultSubmit(realForm)
967
- }
968
- },
969
-
970
- async asyncSubmit () {
971
- return new Promise((resolve, reject) => {
972
- this.$refs.selectForm.validate(async valid => {
973
- if (!valid) {
974
- reject(new Error('Form validation failed'))
975
- return
976
- }
977
- this.loading = true
978
- const requestForm = this.prepareForm()
979
- await this.appendSilenceAddFields(requestForm)
980
- const realForm = this.handleFormKeys(requestForm)
981
- resolve({
982
- realForm,
983
- businessType: this.businessType,
984
- serviceName: this.serviceName,
985
- currUserName: this.currUser.name,
986
- currUserId: this.currUser.id,
987
- orgId: this.currUser.orgid
988
- })
989
- })
990
- })
991
- },
992
-
993
- validateForm () {
994
- return new Promise((resolve) => {
995
- this.$refs.selectForm.validate(valid => resolve(valid))
996
- })
997
- },
998
-
999
- childTableFixedQueryForm (item) {
1000
- if (this.modifyModelData?.primaryKeyData) {
1001
- const fixedForm = {}
1002
- fixedForm[item.childTableForeignKeyName] = Object.values(this.modifyModelData.primaryKeyData)[0]
1003
- return fixedForm
1004
- }
1005
- return null
1006
- },
1007
-
1008
- prepareForm () {
1009
- const form = { ...this.form }
1010
- for (const key of Object.keys(form)) {
1011
- const value = form[key]
1012
- if (value === null || (typeof value === 'object' && Object.keys(value).length === 0)) {
1013
- form[key] = undefined
1014
- }
1015
- }
1016
- return form
1017
- },
1018
-
1019
- async appendSilenceAddFields (form) {
1020
- if (this.businessType === '新增') {
1021
- for (const item of this.silenceAddJsonData) {
1022
- switch (item.silencePurpose) {
1023
- case 'createTime':
1024
- form[item.model] = formatDate('now')
1025
- break
1026
- case 'operator':
1027
- form[item.model] = this.currUser.name
1028
- break
1029
- case 'operatorId':
1030
- form[item.model] = this.currUser.id
1031
- break
1032
- case 'orgId':
1033
- form[item.model] = this.currUser.orgid
1034
- break
1035
- case 'orgName':
1036
- form[item.model] = this.currUser.orgs
1037
- break
1038
- case 'depId':
1039
- form[item.model] = this.currUser.depids
1040
- break
1041
- case 'depName':
1042
- form[item.model] = this.currUser.deps
1043
- break
1044
- }
1045
- }
1046
- for (const item of this.silenceAddJsonData.filter((item) => item.silencePurpose === 'customize')) {
1047
- const result = await runLogic(item.silenceSource, form, this.serviceName)
1048
- if (result) {
1049
- const keys = Object.keys(result)
1050
- if (keys.length === 1 && keys[0] === 'value') {
1051
- form[item.model] = result.value
1052
- } else {
1053
- form[item.model] = result
1054
- }
1055
- } else {
1056
- form[item.model] = result
1057
- }
1058
- }
1059
- }
1060
- },
1061
-
1062
- handleFormKeys (form, mustHandleKey = false) {
1063
- const realForm = {}
1064
- for (const key of Object.keys(form)) {
1065
- const value = form[key]
1066
- const extraFormKeyTagIndex = key.indexOf('@')
1067
- if (extraFormKeyTagIndex !== -1) {
1068
- const extraFormKey = key.substring(0, extraFormKeyTagIndex)
1069
- const realKey = key.substring(extraFormKeyTagIndex + 1)
1070
- if (!realForm[extraFormKey]) {
1071
- realForm[extraFormKey] = {}
1072
- }
1073
- realForm[extraFormKey][realKey] = value
1074
- } else {
1075
- const realKey = this.isHandleFormKey || mustHandleKey ? this.getRealKey(key, mustHandleKey) : key
1076
- // 如果发生重名,不覆盖,把key的别名带上
1077
- if (realForm[realKey]) {
1078
- realForm[key] = value
1079
- } else {
1080
- realForm[realKey] = value
1081
- }
1082
- }
1083
- }
1084
- return realForm
1085
- },
1086
- // 默认提交事件
1087
- defaultSubmit (realForm, callback) {
1088
- // 新增移除id
1089
- if (this.businessType === '新增') {
1090
- delete realForm.id
1091
- }
1092
- // 组织请求
1093
- const requestParameters = {
1094
- queryParamsName: this.configName,
1095
- queryParams: this.configContent,
1096
- form: realForm,
1097
- businessType: this.businessType,
1098
- operator: this.currUser.name
1099
- }
1100
- addOrModify(requestParameters, this.serviceName, this.env === 'dev').then(data => {
1101
- this.$message.success(this.businessType + '成功!')
1102
- // commit
1103
- this.$emit('afterSubmit', { type: this.businessType, id: data.id, data: data, form: requestParameters.form })
1104
- this.loading = false
1105
- if (callback) {
1106
- callback()
1107
- }
1108
- }).catch(e => {
1109
- this.loading = false
1110
- this.$message.error(this.businessType + '失败:' + e)
1111
- })
1112
- },
1113
- // 获取表单字段实际值
1114
- getRealKey (key, mustHandleKey = false) {
1115
- if (key === 'selected_id') return key
1116
- if (this.isHandleFormKey || mustHandleKey) {
1117
- return key.substring(key.indexOf('_') + 1)
1118
- } else {
1119
- return key
1120
- }
1121
- },
1122
- /**
1123
- * 获取被修改记录数据
1124
- * @param modifyModelData 被修改记录的数据
1125
- */
1126
- getModifyModelData (modifyModelData) {
1127
- if (modifyModelData.primaryKeyData) {
1128
- this.form = Object.assign(this.form, modifyModelData.primaryKeyData)
1129
- }
1130
- // 对动态简易表单项特殊处理
1131
- for (const key in modifyModelData.data) {
1132
- const realKey = this.isHandleFormKey ? this.getRealKey(key) : key
1133
- if (this.simpleFormJsonData[realKey]) {
1134
- const extraForm = JSON.parse(modifyModelData.data[key])
1135
- for (const key in extraForm) {
1136
- const model = realKey + '@' + key
1137
- this.form[model] = extraForm[key]
1138
- }
1139
- }
1140
- }
1141
- // 对普通表单项处理
1142
- for (let i = 0; i < this.realJsonData.length; i++) {
1143
- if (['FilesId', 'Images'].includes(this.realJsonData[i])) {
1144
- // 附件需要跳过 因为会通过 modifyModelData中的files,images属性给upload赋值
1145
- // 新增修改表单每次提交时只会提交最新添加的文件
1146
- continue
1147
- }
1148
- const item = this.realJsonData[i]
1149
- // 地址选择器 需要传递 经纬度字段, 配置中添加 `${item.model}_lng_lat` CRUD 只需勾选 SQL生成查询项
1150
- if (['addressSearch'].includes(item.type)) {
1151
- this.form[item.model] = modifyModelData.data[item.model] + ''
1152
- this.form[`${item.model}_lng_lat`] = modifyModelData.data[`${item.model}_lng_lat`] + ''
1153
- continue
1154
- }
1155
- if (modifyModelData.data[item.model] || modifyModelData.data[item.model] === 0) {
1156
- if (modifyModelData.data[item.model] instanceof Array) {
1157
- this.form[item.model] = modifyModelData.data[item.model]
1158
- } else {
1159
- this.form[item.model] = modifyModelData.data[item.model] + ''
1160
- }
1161
- }
1162
- }
1163
- // 对分组表单进行处理
1164
- for (let i = 0; i < this.groupJsonData.length; i++) {
1165
- const item = this.groupJsonData[i]
1166
- try {
1167
- if (modifyModelData.data[item.model]) {
1168
- this.form[item.model] = JSON.parse(modifyModelData.data[item.model])
1169
- }
1170
- } catch (e) {
1171
- if (modifyModelData.data[item.model]) {
1172
- this.form[item.model] = modifyModelData.data[item.model]
1173
- }
1174
- }
1175
- }
1176
- // 追加版本号信息
1177
- for (const item of this.versionJsonData) {
1178
- if (!modifyModelData.data[item.model]) {
1179
- this.form[item.model] = 0
1180
- } else {
1181
- this.form[item.model] = modifyModelData.data[item.model] + ''
1182
- }
1183
- }
1184
- },
1185
- setForm (obj) {
1186
- this.form = Object.assign(this.form, obj)
1187
- // 给子表赋外键条件
1188
- if (this.childFormData.length > 0) {
1189
- for (const item of this.childFormData) {
1190
- const child = this.$refs[item.model]
1191
- // 获取子表别名,以便在条件上添加别名
1192
- const alias = child.realQueryConfig.tableAliasName
1193
- // 有主键,且主键有值,添加主键条件
1194
- if (this.primaryKey && this.form[this.primaryKey]) {
1195
- const foreignKey = item.foreignKey
1196
- const fixedQueryForm = { [alias + '_' + foreignKey]: this.form[this.primaryKey] }
1197
- if (!child.fixedQueryForm) {
1198
- child.fixedQueryForm = fixedQueryForm
1199
- } else {
1200
- Object.assign(child.fixedQueryForm, fixedQueryForm)
1201
- }
1202
- child.refreshTable()
1203
- }
1204
- }
1205
- }
1206
- },
1207
- setFormWithKey (obj) {
1208
- setDataByRealKey(this.form, obj)
1209
- },
1210
- setFormWithNoKey (obj) {
1211
- setDataByRealKey(this.form, obj)
1212
- },
1213
- emitFunc (func, data, value) {
1214
- this.$emit(func, data, value)
1215
- this.$emit('x-form-item-emit-func', func, data, value)
1216
- },
1217
- // 直接转发事件的函数
1218
- emitEvent (event, ...args) {
1219
- this.$emit(event, ...args)
1220
- },
1221
- close () {
1222
- this.loaded = false
1223
- },
1224
- /**
1225
- * 行选择事件
1226
- * @param row 选中行集合
1227
- * @param attr 表单项属性
1228
- */
1229
- async rowChoose (row, attr, callback) {
1230
- // 如果配置了自定义函数
1231
- if (attr.dataChangeFunc) {
1232
- await executeStrFunction(attr.dataChangeFunc, [this.form, this.setForm, {
1233
- ...attr,
1234
- selectRows: row
1235
- }, util, this.mode, runLogic, getConfigByNameAsync])
1236
- } else {
1237
- // 默认填充选中行数据到当前表单
1238
- setDataByRealKey(this.form, row[0])
1239
- }
1240
- if (callback) {
1241
- callback()
1242
- }
1243
- },
1244
- }
1245
- }
1246
- </script>
1247
-
1248
- <style scoped lang="less">
1249
- :deep(.ant-form-inline .ant-form-item ) {
1250
- display: block !important;
1251
- }
1252
-
1253
- :deep(.ant-form-item-with-help) {
1254
- margin-bottom: 0;
1255
- }
1256
-
1257
- .xFormGroupTitle {
1258
- font-weight: bold;
1259
- color: @primary-color;
1260
- }
1261
-
1262
- .simple-inline-item {
1263
- max-width: 100% !important;
1264
- }
1265
-
1266
- /* simple-inline模式样式 */
1267
- :deep(.simple-inline-item .ant-form-item) {
1268
- margin: 0 !important;
1269
- padding: 2px !important;
1270
-
1271
- .ant-form-item-label {
1272
- display: none !important;
1273
- }
1274
-
1275
- .ant-form-item-control-wrapper,
1276
- .ant-form-item-control {
1277
- width: 100% !important;
1278
- }
1279
- }
1280
- </style>
1
+ <template>
2
+ <div id="XAddNativeForm">
3
+ <a-form-model
4
+ v-if="loaded"
5
+ ref="selectForm"
6
+ :zIndex="1001"
7
+ :model="form"
8
+ v-bind="formItemLayoutGen"
9
+ :layout="layout">
10
+ <template v-for="(item, key) in childTableData">
11
+ <a-row
12
+ v-if="childTablePriority"
13
+ :gutter="16"
14
+ :key="'childTableRow' + key">
15
+ <a-card :title="item.name" :bordered="false" size="small">
16
+ <x-form-table
17
+ :key="'childTable_' + item.model"
18
+ :title="item.name"
19
+ :queryParamsName="item.childTableConfigName"
20
+ :localEditMode="true"
21
+ :fixed-query-form="childTableFixedQueryForm(item)"
22
+ :service-name="serviceName"
23
+ @innerXFormTableEmit="innerXFormTableEmit"
24
+ @afterTableInit="childTableMounted(item)"
25
+ :ref="'childXFormTable_' + item.model">
26
+ </x-form-table>
27
+ </a-card>
28
+ </a-row>
29
+ </template>
30
+ <template v-if="isSimpleInlineMode">
31
+ <a-row
32
+ v-for="(row, rowIndex) in simpleInlineRows"
33
+ :key="'simple-row-' + rowIndex"
34
+ :gutter="0"
35
+ type="flex">
36
+ <a-col
37
+ v-for="(item, itemIndex) in row.items"
38
+ :key="'simple-item-' + itemIndex"
39
+ :span="item.span">
40
+ <x-form-item
41
+ class="simple-inline-item"
42
+ :attr="item.formItem"
43
+ :disabled="itemDisabled(item.formItem)"
44
+ :read-only="readonly(item.formItem)"
45
+ :files="files"
46
+ :form="form"
47
+ :images="images"
48
+ :service-name="serviceName"
49
+ mode="新增/修改"
50
+ layout="simple-inline"
51
+ :rules="rules[`${item.formItem.name}${item.formItem.model}`]"
52
+ :get-data-params="getDataParams"
53
+ :env="env"
54
+ @x-form-item-emit-func="emitFunc"
55
+ @rowChoose="rowChoose"
56
+ :setForm="setForm"
57
+ :style="{ margin: 0, padding: '2px' }"
58
+ />
59
+ </a-col>
60
+ </a-row>
61
+ </template>
62
+ <a-row ref="GroupItemRow" v-if="!isSimpleInlineMode">
63
+ <a-col :span="3" v-if="!inXFormGroup && !(groups[0].groupName === DEFAULT_GROUP_NAME)">
64
+ <a-tabs tab-position="left" v-model="activeTab" @change="scrollToGroup">
65
+ <a-tab-pane
66
+ v-for="(groupsItem,groupsIndex) in groups"
67
+ :tab="groupsItem.groupName"
68
+ :key="groupsIndex">
69
+ </a-tab-pane>
70
+ </a-tabs>
71
+ </a-col>
72
+ <a-col
73
+ :span="(!inXFormGroup && !(groups[0].groupName === DEFAULT_GROUP_NAME)) ? 21: 24">
74
+ <a-row
75
+ :gutter="16"
76
+ type="flex"
77
+ :key="groupsIndex"
78
+ v-for="(groupsItem,groupsIndex) in groups"
79
+ >
80
+ <a-col
81
+ :span="24"
82
+ :style="{ marginTop: groupsIndex === 0 ? '' : '8px',fontSize:inXFormGroup?'15px':'14px', marginLeft:'-5px' }"
83
+ v-if="groupsItem.groupName !== DEFAULT_GROUP_NAME">
84
+ <span class="xFormGroupTitle" :ref="`group-title-${groupsIndex}`">{{ groupsItem.groupName }}</span>
85
+ </a-col>
86
+ <x-form-item
87
+ v-for="(item, index) in groupsItem.realJsonData"
88
+ :key="index"
89
+ :attr="item"
90
+ :disabled="itemDisabled(item)"
91
+ :read-only="readonly(item)"
92
+ :files="files"
93
+ v-bind="formItemLayoutGen"
94
+ :style="layout === 'inline' ? { marginTop:'5px' } : undefined"
95
+ :form="form"
96
+ :images="images"
97
+ :service-name="serviceName"
98
+ mode="新增/修改"
99
+ :layout="layout"
100
+ :rules="rules[`${item.name}${item.model}`]"
101
+ :get-data-params="getDataParams"
102
+ :env="env"
103
+ @x-form-item-emit-func="emitFunc"
104
+ @rowChoose="rowChoose"
105
+ :setForm="setForm"
106
+ />
107
+ </a-row>
108
+ </a-col>
109
+ </a-row>
110
+ <a-row :gutter="16" v-for="(groupItem, groupIndex) in groupJsonData" :key="groupIndex" v-if="!isSimpleInlineMode">
111
+ <a-card v-if="groupItem.groupItems.length > 0" :title="groupItem.name" :bordered="false" size="small">
112
+ <x-form-item
113
+ v-for="(item, index) in groupItem.groupItems"
114
+ :key="index"
115
+ :attr="item"
116
+ :disabled="itemDisabled(item)"
117
+ :readonly="readonly(item)"
118
+ :files="files"
119
+ v-bind="formItemLayoutGen"
120
+ :style="layout ==='inline'?{marginTop:'5px'}:undefined"
121
+ :form="form[groupItem.model]"
122
+ :images="images"
123
+ :service-name="serviceName"
124
+ mode="新增/修改"
125
+ :rules="rules[`${item.name}${item.model}`]"
126
+ :get-data-params="getDataParams"
127
+ :env="env"
128
+ :setForm="setForm"
129
+ @rowChoose="rowChoose"
130
+ />
131
+ </a-card>
132
+ <template v-else>
133
+ <slot
134
+ name="groupFormItems"
135
+ :form="form"
136
+ :model="groupItem.model"
137
+ :rules="rules"
138
+ :modifyModelData="modifyModelData"></slot>
139
+ </template>
140
+ </a-row>
141
+ <a-row :gutter="16" v-for="(item, key) in simpleFormJsonData" :key="'row' + key" v-if="!isSimpleInlineMode">
142
+ <a-card v-if="item.value.length > 0" :title="item.name" :bordered="false" size="small">
143
+ <x-form-item
144
+ v-for="(formItem, formItemIndex) in item.value"
145
+ :key="key + formItemIndex"
146
+ :attr="formItem"
147
+ :disabled="itemDisabled(formItem)"
148
+ :readonly="readonly(formItem)"
149
+ :files="files"
150
+ v-bind="formItemLayoutGen"
151
+ :style="layout ==='inline'?{marginTop:'5px'}:undefined"
152
+ :form="form[groupItem.model]"
153
+ :images="images"
154
+ :service-name="serviceName"
155
+ mode="新增/修改"
156
+ :rules="rules[`${item.name}${item.model}`]"
157
+ :get-data-params="getDataParams"
158
+ :env="env"
159
+ :setForm="setForm"
160
+ @rowChoose="rowChoose"
161
+ />
162
+ </a-card>
163
+ </a-row>
164
+ <template v-for="(item, key) in childTableData">
165
+ <a-row
166
+ v-if="!childTablePriority"
167
+ :gutter="16"
168
+ :key="'childTableRow' + key">
169
+ <a-card :title="item.name" :bordered="false" size="small">
170
+ <x-form-table
171
+ :key="'childTable_' + item.model"
172
+ :title="item.name"
173
+ :queryParamsName="item.childTableConfigName"
174
+ :localEditMode="true"
175
+ @innerXFormTableEmit="innerXFormTableEmit"
176
+ :fixed-query-form="childTableFixedQueryForm(item)"
177
+ :service-name="serviceName"
178
+ @afterTableInit="childTableMounted(item)"
179
+ :ref="'childXFormTable_' + item.model">
180
+ </x-form-table>
181
+ </a-card>
182
+ </a-row>
183
+ </template>
184
+ <a-row type="flex" :justify="btnPlace" :style="{paddingLeft: '16px',paddingRight: '16px'}">
185
+ <slot name="footer" :loading="loading">
186
+ <a-button v-if="showSubmitBtn" :loading="loading" type="primary" @click="onSubmit()">{{ btnName }}</a-button>
187
+ </slot>
188
+ </a-row>
189
+ </a-form-model>
190
+ </div>
191
+ </template>
192
+ <script>
193
+ import XFormItem from '@vue2-client/base-client/components/common/XForm/XFormItem'
194
+ import { formatDate, setDataByRealKey } from '@vue2-client/utils/util'
195
+ import * as util from '@vue2-client/utils/util'
196
+ import { mapState } from 'vuex'
197
+ import { addOrModify, getConfigByName, getConfigByNameAsync, runLogic } from '@vue2-client/services/api/common'
198
+ import { checkIdNumber, REG_EMAIL, REG_LANDLINE, REG_PHONE } from '@vue2-client/utils/reg'
199
+ import moment from 'moment/moment'
200
+ import { executeStrFunction, executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
201
+ import formValidationMixin from '@vue2-client/mixins/formValidationMixin'
202
+
203
+ const DEFAULT_GROUP_NAME = '__default__'
204
+ export default {
205
+ name: 'XAddNativeForm',
206
+ components: {
207
+ XFormItem,
208
+ XFormTable: () => import('@vue2-client/base-client/components/common/XFormTable/XFormTable.vue')
209
+ },
210
+ inject: {
211
+ inXFormGroup: {
212
+ default: false
213
+ },
214
+ formGroupContext: {
215
+ default: null
216
+ },
217
+ formDataChange: {
218
+ default: null
219
+ }
220
+ },
221
+ props: {
222
+ // 是否启用 horizontal 模式的自定义配置
223
+ enableHorizontalCustom: {
224
+ type: Boolean,
225
+ default: false
226
+ }
227
+ },
228
+ data () {
229
+ return {
230
+ DEFAULT_GROUP_NAME,
231
+ // 预览模式
232
+ viewMode: false,
233
+ // 是否处理表单Key值
234
+ isHandleFormKey: true,
235
+ // 内容加载是否完成
236
+ loaded: false,
237
+ // 业务类型
238
+ businessType: '',
239
+ // 业务标题
240
+ title: '',
241
+ // 新增或修改业务是否执行中
242
+ loading: false,
243
+ // 表单Model
244
+ form: {},
245
+ // 配置名称
246
+ configName: undefined,
247
+ // 配置内容,用于查询配置生成器的预览
248
+ configContent: undefined,
249
+ // 表单项集合
250
+ formItems: [],
251
+ // 服务名称
252
+ serviceName: undefined,
253
+ // 是否显示提交按钮
254
+ showSubmitBtn: true,
255
+ // 修改有文件的表单时使用
256
+ files: [],
257
+ images: [],
258
+ // 校验
259
+ rules: {},
260
+ // 调用logic获取数据源的追加参数
261
+ getDataParams: {},
262
+ // 动态简易表单集合
263
+ simpleFormJsonData: {},
264
+ // 待修改的数据集
265
+ modifyModelData: {},
266
+ // 当前环境
267
+ env: 'prod',
268
+ // 表单主键
269
+ primaryKey: null,
270
+ // 表单模式 horizontal | vertical | inline
271
+ layout: 'horizontal',
272
+ // 提交按钮名称
273
+ btnName: '提交',
274
+ // 提交按钮位置 start / center / end
275
+ btnPlace: 'center',
276
+ // 子表是否排在前面
277
+ childTablePriority: false,
278
+ // simple-inline布局配置
279
+ simpleInline: null
280
+ }
281
+ },
282
+ computed: {
283
+ // 过滤出用于新增/修改场景的表单项
284
+ realJsonData: function () {
285
+ return this.formItems.filter((item) => {
286
+ return item.addOrEdit && item.addOrEdit !== 'no' && item.addOrEdit !== 'silenceAdd' && item.addOrEdit !== 'version' && !this.itemDisabled(item)
287
+ })
288
+ },
289
+ // 表单项组 / 不是 数据组
290
+ groups: function () {
291
+ if (!this.realJsonData || this.realJsonData.length === 0) {
292
+ return [{
293
+ groupName: DEFAULT_GROUP_NAME,
294
+ realJsonData: this.realJsonData,
295
+ xAddFormLayout: 'horizontal'
296
+ }]
297
+ }
298
+ const uniqueGroups = new Set(this.realJsonData.map(item => item.group).filter(Boolean))
299
+ const allGroup = Array.from(uniqueGroups).map(group => {
300
+ return {
301
+ groupName: group,
302
+ realJsonData: this.realJsonData.filter(item => item.group === group),
303
+ xAddFormLayout: 'horizontal'
304
+ }
305
+ })
306
+ // 判断每一组得formJson 长度相加是否等于 realJsonData 长度 避免错误数据
307
+ if (allGroup.reduce((total, item) => total + item.realJsonData.length, 0) === this.realJsonData.length) {
308
+ return allGroup
309
+ } else {
310
+ return [{
311
+ groupName: DEFAULT_GROUP_NAME,
312
+ realJsonData: this.realJsonData,
313
+ xAddFormLayout: 'horizontal'
314
+ }]
315
+ }
316
+ },
317
+ // 拥有自定义校验函数得表单项
318
+ customValidateItems: function () {
319
+ return this.formItems.filter((item) => {
320
+ return item?.rule?.type === 'customJs'
321
+ })
322
+ },
323
+ // 过滤出用于新增/修改场景的表单项
324
+ groupJsonData: function () {
325
+ return this.formItems.filter((item) => {
326
+ return item.type === 'group'
327
+ }).map((item) => {
328
+ item.groupItems = item.groupItems.filter((item) => {
329
+ return item.addOrEdit && item.addOrEdit !== 'no' && item.addOrEdit !== 'silenceAdd' && item.addOrEdit !== 'version' && !this.itemDisabled(item)
330
+ }).map((groupItem) => {
331
+ // 只保留第一个下划线后面的内容
332
+ // 多层校验规则需要将prop设置为 key1.key2.....
333
+ groupItem.prop = `${item.model}.${groupItem.model.substring(groupItem.model.indexOf('_') + 1)}`
334
+ groupItem.model = groupItem.model.substring(groupItem.model.indexOf('_') + 1)
335
+ return groupItem
336
+ })
337
+ return item
338
+ }
339
+ )
340
+ },
341
+ // 过滤出用于子表数据新增/修改场景的表单项
342
+ childTableData: function () {
343
+ return this.formItems.filter((item) => {
344
+ return item.type === 'childTable'
345
+ })
346
+ },
347
+ // 过滤出用于form子表数据新增/修改场景的表单项
348
+ childFormData: function () {
349
+ return this.formItems.filter((item) => {
350
+ return item.type === 'rowEdit'
351
+ })
352
+ },
353
+ // 过滤出用于静默新增场景的表单项
354
+ silenceAddJsonData: function () {
355
+ return this.formItems.filter(function (item) {
356
+ return item.addOrEdit === 'silenceAdd'
357
+ })
358
+ },
359
+ // 过滤出版本号表单项
360
+ versionJsonData: function () {
361
+ return this.formItems.filter(function (item) {
362
+ return item.addOrEdit === 'version'
363
+ })
364
+ },
365
+ formItemLayoutGen () {
366
+ if (this.layout === 'simple-inline') {
367
+ return {
368
+ labelCol: { span: 0 },
369
+ wrapperCol: { span: 24 }
370
+ }
371
+ }
372
+ if (this.layout === 'horizontal') {
373
+ // 如果启用了自定义配置,从 formItemLayout 读取(支持 0 值)
374
+ if (this.enableHorizontalCustom && this.formItemLayout) {
375
+ return {
376
+ labelCol: {
377
+ span: (this.formItemLayout.labelCol ?? 4),
378
+ offset: (this.formItemLayout.offset ?? 2)
379
+ },
380
+ wrapperCol: { span: (this.formItemLayout.wrapperCol ?? 14) },
381
+ }
382
+ }
383
+ // 默认配置
384
+ return {
385
+ labelCol: { span: 4, offset: 2 },
386
+ wrapperCol: { span: 14 },
387
+ }
388
+ } else if (this.layout === 'vertical') {
389
+ return {}
390
+ } else {
391
+ if (!this.formItemLayout.labelCol || !this.formItemLayout.wrapperCol) {
392
+ return {
393
+ labelCol: { span: 8 },
394
+ wrapperCol: { span: 16 },
395
+ }
396
+ }
397
+ return {
398
+ labelCol: { span: this.formItemLayout.labelCol },
399
+ wrapperCol: { span: this.formItemLayout.wrapperCol },
400
+ }
401
+ }
402
+ },
403
+ // simple-inline模式判断
404
+ isSimpleInlineMode () {
405
+ return this.layout === 'simple-inline' && this.simpleInline
406
+ },
407
+ // simple-inline布局行数据
408
+ simpleInlineRows () {
409
+ if (!this.isSimpleInlineMode) return []
410
+ return this.simpleInline.rows.map(row => ({
411
+ ...row,
412
+ items: row.items.map(item => ({
413
+ ...item,
414
+ formItem: this.realJsonData.find(f =>
415
+ f.model === item.key && f.name === item.title
416
+ )
417
+ })).filter(item => item.formItem)
418
+ }))
419
+ },
420
+ ...mapState('account', { currUser: 'user' })
421
+ },
422
+ provide () {
423
+ return {
424
+ getComponentByName: this.getComponentByName,
425
+ registerComponent: this.registerComponent,
426
+ XFormContext: this,
427
+ // 移除必填项
428
+ removeRequired: this.removeRequired,
429
+ // 设置必填项
430
+ setRequired: this.setRequired,
431
+ getSelf: () => this,
432
+ }
433
+ },
434
+ watch: {
435
+ form: {
436
+ handler (val) {
437
+ if (this.formDataChange && typeof this.formDataChange === 'function') {
438
+ this.formDataChange(val)
439
+ }
440
+ },
441
+ deep: true
442
+ }
443
+ },
444
+ /** //todo 本来想要实现 配置 自定义函数时,表单项得红星提示,根据自定义校验函数得返回值来判断
445
+ * 但是监听不到父组件formgorup得其他form得变化,所以暂时不实现
446
+ */
447
+ //
448
+ // watch: {
449
+ // form: {
450
+ // handler (val) {
451
+ // // 遍历表单配置
452
+ // if (this.customValidateItems.length > 0) {
453
+ // for (const item of this.customValidateItems) {
454
+ // const itemIndex = this.formItems.findIndex(formItem => formItem.model === item.model)
455
+ // if (itemIndex < 0) {
456
+ // continue
457
+ // }
458
+ // try {
459
+ // this.customJsValidate(null, val[item.model], (res) => {
460
+ // // 如果返回error则设置错误信息
461
+ // if (res instanceof Error) {
462
+ // // 设置表单项的错误状态
463
+ // this.$set(this.formItems[itemIndex], 'tempRequired', true)
464
+ // } else {
465
+ // // 清除错误状态
466
+ // this.$set(this.formItems[itemIndex], 'tempRequired', true)
467
+ // }
468
+ // }, item)
469
+ // } catch (e) {
470
+ // console.error(e)
471
+ // this.$set(this.formItems[itemIndex], 'tempRequired', true)
472
+ // }
473
+ // }
474
+ // console.log('customValidateItems', JSON.stringify(this.customValidateItems))
475
+ // }
476
+ // },
477
+ // deep: true
478
+ // }
479
+ // },
480
+ mixins: [formValidationMixin],
481
+ methods: {
482
+ runLogic,
483
+ getConfigByNameAsync,
484
+ getConfigByName,
485
+ init (params) {
486
+ const {
487
+ configName,
488
+ configContent,
489
+ formItems,
490
+ formJson,
491
+ viewMode,
492
+ isHandleFormKey,
493
+ isKeyHandle = true,
494
+ showSubmitBtn = true,
495
+ serviceName,
496
+ primaryKey,
497
+ modifyModelData = {},
498
+ businessType,
499
+ title,
500
+ fixedAddForm = {},
501
+ getDataParams = {},
502
+ simpleFormJsonData = {},
503
+ env = 'prod',
504
+ layout,
505
+ xAddFormLayout = 'horizontal',
506
+ formItemLayout = {},
507
+ btnName = '提交',
508
+ childTablePriority = false,
509
+ btnPlace = 'center',
510
+ simpleInline = null,
511
+ paramLogicName,
512
+ paramLogicNameParam
513
+ } = params
514
+ this.loaded = false
515
+ // 兼容需要省略 传递 layout: res.xAddFormLayout 可以使用 ...res 展开运算符 直接转递
516
+ if (xAddFormLayout && layout === undefined) {
517
+ this.layout = xAddFormLayout
518
+ } else {
519
+ this.layout = layout
520
+ }
521
+ this.formItemLayout = formItemLayout
522
+ if ((isHandleFormKey === null || isHandleFormKey === undefined) && !isKeyHandle) {
523
+ this.isHandleFormKey = isKeyHandle
524
+ } else if (isHandleFormKey) {
525
+ this.isHandleFormKey = isHandleFormKey
526
+ } else {
527
+ this.isHandleFormKey = isKeyHandle
528
+ }
529
+ this.childTablePriority = childTablePriority
530
+ this.configName = configName
531
+ this.configContent = configContent
532
+ this.formItems = this.getFromItem(formItems, formJson)
533
+ this.viewMode = viewMode
534
+ this.showSubmitBtn = showSubmitBtn
535
+ this.primaryKey = primaryKey
536
+ this.serviceName = serviceName
537
+ this.businessType = businessType
538
+ this.title = title
539
+ this.getDataParams = getDataParams
540
+ this.simpleFormJsonData = simpleFormJsonData
541
+ this.env = env
542
+ this.btnName = btnName
543
+ this.btnPlace = btnPlace
544
+ this.simpleInline = simpleInline
545
+ // 如果 fixedAddForm 有 selected_id 值,并且设置了处理表单key值,则多给 selected_id 加前缀 避免处理错误
546
+ if (fixedAddForm.selected_id && this.isHandleFormKey) {
547
+ fixedAddForm._selected_id = fixedAddForm.selected_id
548
+ delete fixedAddForm.selected_id
549
+ }
550
+ // 设置普通表单项的相关参数
551
+ const formData = Object.assign({}, fixedAddForm)
552
+ if (paramLogicName) {
553
+ runLogic(paramLogicName, paramLogicNameParam, this.serviceName).then(res => {
554
+ Object.assign(formData, res)
555
+ })
556
+ }
557
+ for (let i = 0; i < this.realJsonData.length; i++) {
558
+ const item = this.realJsonData[i]
559
+ this.setFormProps(formData, item, null)
560
+ }
561
+ // 设置表单分组项目相关参数
562
+ for (let i = 0; i < this.groupJsonData.length; i++) {
563
+ const groupItem = this.groupJsonData[i]
564
+ formData[groupItem.model] = {}
565
+ for (let j = 0; j < groupItem.groupItems.length; j++) {
566
+ const item = groupItem.groupItems[j]
567
+ this.setFormProps(formData[groupItem.model], item, item.prop)
568
+ }
569
+ }
570
+ // 设置动态简易表单项的相关参数
571
+ for (const key in this.simpleFormJsonData) {
572
+ for (const item of this.simpleFormJsonData[key].value) {
573
+ item.model = key + '@' + item.model
574
+ this.setFormProps(formData, item, null)
575
+ }
576
+ }
577
+
578
+ this.form = formData
579
+ // 修改场景下对表单项赋值
580
+ if (modifyModelData && modifyModelData.data) {
581
+ this.modifyModelData = modifyModelData
582
+ if (Object.keys(modifyModelData.data).length > 0) {
583
+ this.getModifyModelData(modifyModelData)
584
+ }
585
+ }
586
+ // 处理表单得附件
587
+ if (modifyModelData && modifyModelData.files) {
588
+ this.files = modifyModelData.files
589
+ }
590
+ if (modifyModelData && modifyModelData.images) {
591
+ this.images = modifyModelData.images
592
+ }
593
+ this.loaded = true
594
+ },
595
+ scrollToGroup (index) {
596
+ const groupElement = this.$refs[`group-title-${index}`][0]
597
+ if (groupElement) {
598
+ groupElement.scrollIntoView({ behavior: 'smooth' })
599
+ }
600
+ },
601
+ registerComponent (componentName, component) {
602
+ console.log('内部注册', this.$options.name, componentName)
603
+ this.$refs[componentName] = component
604
+ console.log('内部注册完成', this.$refs)
605
+ },
606
+ // 根据名字从注册到组件中获取组件
607
+ getComponentByName (componentName) {
608
+ console.log('内部取组件', this.$options.name, componentName)
609
+ console.log('内部组件内容', this.$refs)
610
+ return this.$refs[componentName]
611
+ },
612
+ // 兼容需要省略 传递 [formItems: res.formJson ] 可以使用 ...res 展开运算符 直接转递
613
+ getFromItem (formItems, formJson) {
614
+ const _formItems = formItems || formJson
615
+ if (typeof formItems === 'string') {
616
+ return JSON.parse(_formItems)
617
+ } else {
618
+ return JSON.parse(JSON.stringify(_formItems))
619
+ }
620
+ },
621
+ innerXFormTableEmit (fun, record, id, actionType, index) {
622
+ this.$emit(fun, record, id, actionType, index)
623
+ },
624
+ // 时间组件赋默认值
625
+ // .type, item.formDefault
626
+ getDateRange ({ type, formDefault: defaultValue, formValueFormat }) {
627
+ // const format = type === 'datePicker' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'
628
+ let format = 'YYYY-MM-DD HH:mm:ss'
629
+ if (formValueFormat) {
630
+ format = formValueFormat
631
+ }
632
+ let start
633
+ switch (defaultValue) {
634
+ case 'curYear':
635
+ start = moment().startOf('year').format(format)
636
+ break
637
+ case 'curMonth':
638
+ start = moment().startOf('month').format(format)
639
+ break
640
+ case 'curDay':
641
+ start = moment().startOf('day').format(format)
642
+ break
643
+ case 'curTime':
644
+ start = moment().format(format)
645
+ break
646
+ default:
647
+ return defaultValue
648
+ }
649
+ return start
650
+ },
651
+ setFormProps (formData, item, groupItem) {
652
+ const rulesKey = `${item.name}${item.model}`
653
+ if (formData[item.model] === undefined || formData[item.model] === null) {
654
+ formData[item.model] = undefined
655
+ }
656
+ if (!formData[item.model] && item.formDefault) {
657
+ if (['datePicker', 'rangePicker', 'yearPicker', 'monthPicker', 'yearRangePicker', 'monthRangePicker'].includes(item.type)) {
658
+ formData[item.model] = this.getDateRange(item)
659
+ } else if (['treeSelect', 'select', 'checkbox'].includes(item.type) && ['curOrgId', 'curDepId', 'curUserId'].includes(item.formDefault)) {
660
+ if (item.formDefault === 'curOrgId') {
661
+ formData[item.model] = item.type === 'select' ? this.currUser.orgid : [this.currUser.orgid]
662
+ }
663
+ if (item.formDefault === 'curDepId') {
664
+ formData[item.model] = item.type === 'select' ? this.currUser.depids : [this.currUser.depids]
665
+ }
666
+ if (item.formDefault === 'curUserId') {
667
+ formData[item.model] = item.type === 'select' ? this.currUser.id : [this.currUser.id]
668
+ }
669
+ } else if (['addressSearch'].includes(item.type)) {
670
+ formData[item.model] = item.formDefault
671
+ formData[`${item.model}_lng_lat`] = item.formDefault_lng_lat
672
+ } else {
673
+ formData[item.model] = item.formDefault
674
+ }
675
+ }
676
+ // 处理表单校验情况
677
+ if (item.rule) {
678
+ if (groupItem) {
679
+ this.rules[groupItem] = []
680
+ } else {
681
+ this.rules[rulesKey] = []
682
+ }
683
+ const required = item.rule.required ? item.rule.required === true || item.rule.required === 'true' : false
684
+ let trigger
685
+ let message
686
+ if (required) {
687
+ switch (item.type) {
688
+ case 'select':
689
+ case 'checkbox':
690
+ case 'radio':
691
+ case 'treeSelect':
692
+ case 'rangePicker':
693
+ case 'monthPicker':
694
+ case 'yearPicker':
695
+ case 'datePicker':
696
+ case 'file':
697
+ case 'image':
698
+ case 'citySelect':
699
+ case 'addressSearch':
700
+ case 'personSetting':
701
+ message = '请选择' + item.name
702
+ trigger = 'change'
703
+ break
704
+ default:
705
+ message = '请输入' + item.name
706
+ trigger = 'blur'
707
+ }
708
+ if (groupItem) {
709
+ this.rules[groupItem].push({
710
+ required: true,
711
+ message: message,
712
+ trigger: trigger
713
+ })
714
+ } else {
715
+ this.rules[rulesKey].push({
716
+ required: true,
717
+ message: message,
718
+ trigger: trigger
719
+ })
720
+ }
721
+ }
722
+
723
+ switch (item.rule.type) {
724
+ case 'number':
725
+ case 'integer':
726
+ case 'float':
727
+ // eslint-disable-next-line no-case-declarations
728
+ let defaultValue
729
+ // eslint-disable-next-line no-case-declarations
730
+ let message
731
+ switch (item.rule.type) {
732
+ case 'number':
733
+ item.numberInput = true
734
+ message = '数字'
735
+ defaultValue = 0
736
+ break
737
+ case 'integer':
738
+ item.numberInput = true
739
+ message = '整数'
740
+ defaultValue = 0
741
+ break
742
+ case 'float':
743
+ item.numberInput = true
744
+ message = '小数'
745
+ defaultValue = 0.0
746
+ break
747
+ }
748
+ if (groupItem) {
749
+ this.rules[groupItem].push({
750
+ type: item.rule.type,
751
+ message: item.name + '必须为' + message,
752
+ transform: (value) => {
753
+ if (value && value.length !== 0) {
754
+ return Number(value)
755
+ } else {
756
+ return defaultValue
757
+ }
758
+ },
759
+ trigger: 'blur'
760
+ })
761
+ } else {
762
+ this.rules[rulesKey].push({
763
+ type: item.rule.type,
764
+ message: item.name + '必须为' + message,
765
+ transform: (value) => {
766
+ if (value && value.length !== 0) {
767
+ return Number(value)
768
+ } else {
769
+ return defaultValue
770
+ }
771
+ },
772
+ trigger: 'blur'
773
+ })
774
+ }
775
+ break
776
+ case 'email': {
777
+ const validator = (rule, value, callback) => {
778
+ if (value && !REG_EMAIL.test(value)) {
779
+ callback(new Error('请输入正确的邮箱地址'))
780
+ } else {
781
+ callback()
782
+ }
783
+ }
784
+ this.rules[groupItem || rulesKey].push({
785
+ type: 'email',
786
+ validator: validator,
787
+ message: '请输入正确的邮箱地址',
788
+ trigger: 'blur'
789
+ })
790
+ break
791
+ }
792
+ case 'userPhone': {
793
+ this.rules[groupItem || rulesKey].push({
794
+ type: 'userPhone',
795
+ validator: (rule, value, callback) => {
796
+ if (value && !REG_PHONE.test(value)) {
797
+ callback(new Error('请输入正确的手机号码'))
798
+ } else {
799
+ callback()
800
+ }
801
+ },
802
+ message: '请输入正确的手机号码',
803
+ trigger: 'blur'
804
+ })
805
+ break
806
+ }
807
+ case 'idNumber': {
808
+ this.rules[groupItem || rulesKey].push({
809
+ validator: (rule, value, callback) => {
810
+ if (value && !checkIdNumber(value)) {
811
+ callback(new Error('请输入正确的身份证号码'))
812
+ } else {
813
+ callback()
814
+ }
815
+ },
816
+ trigger: 'blur'
817
+ })
818
+ break
819
+ }
820
+ case 'landlineNumber': {
821
+ this.rules[rulesKey].push({
822
+ validator: (rule, value, callback) => {
823
+ if (value && !REG_LANDLINE.test(value)) {
824
+ callback(new Error('请输入正确的座机号码'))
825
+ } else {
826
+ callback()
827
+ }
828
+ },
829
+ trigger: 'blur'
830
+ })
831
+ break
832
+ }
833
+ // 大于0
834
+ case 'greaterThanZero': {
835
+ item.numberInput = true
836
+ this.rules[rulesKey].push({
837
+ validator: (rule, value, callback) => {
838
+ if (isNaN(value) || value <= 0) {
839
+ callback(new Error('请输入一个大于0的数字'))
840
+ } else {
841
+ callback()
842
+ }
843
+ },
844
+ trigger: 'blur'
845
+ })
846
+ break
847
+ }
848
+ // 大于等于0
849
+ case 'greaterThanOrEqualZero': {
850
+ item.numberInput = true
851
+ this.rules[rulesKey].push({
852
+ validator: (rule, value, callback) => {
853
+ if (isNaN(value) || value < 0) {
854
+ callback(new Error('请输入一个大于等于0的数字'))
855
+ } else {
856
+ callback()
857
+ }
858
+ },
859
+ trigger: 'blur'
860
+ })
861
+ break
862
+ }
863
+ case 'stringLength': {
864
+ this.rules[rulesKey].push({
865
+ validator: (rule, value, callback) => {
866
+ if (value && value.length < item.rule.minLen) {
867
+ callback(new Error('长度不能少于' + item.rule.minLen + '个字符'))
868
+ } else if (value && value.length > item.rule.maxLen) {
869
+ callback(new Error('长度不能超过' + item.rule.maxLen + '个字符'))
870
+ } else {
871
+ callback()
872
+ }
873
+ },
874
+ trigger: 'blur'
875
+ })
876
+ break
877
+ }
878
+ case 'customJs': {
879
+ this.rules[rulesKey].push({
880
+ validator: (rule, value, callback) => {
881
+ this.customJsValidate(rule, value, callback, item)
882
+ },
883
+ trigger: 'blur'
884
+ })
885
+ break
886
+ }
887
+ }
888
+ }
889
+ },
890
+ childTableMounted (item) {
891
+ // 子表初始化时,设置表格数据
892
+ if (this.form[item.model] && this.form[item.model].length > 0) {
893
+ this.$refs[`childXFormTable_${item.model}`][0].setTableData(this.form[item.model])
894
+ }
895
+ },
896
+ customJsValidate (rule, value, callback, item) {
897
+ if (item.rule.customValidatorFunc) {
898
+ executeStrFunctionByContext(this, item.rule.customValidatorFunc, [rule, value, callback, this.form, item, this.util, runLogic, getConfigByNameAsync])
899
+ } else {
900
+ callback()
901
+ }
902
+ },
903
+ itemDisabled (value) {
904
+ return (this.businessType === '新增' && value.addOrEdit === 'edit') ||
905
+ (this.businessType === '修改' && value.addOrEdit === 'add')
906
+ },
907
+ readonly (value) {
908
+ return value.addOrEdit === 'readonly'
909
+ },
910
+ async onSubmit () {
911
+ const valid = await this.validateForm()
912
+ if (!valid) return false
913
+ if (this.viewMode) {
914
+ this.$message.info('预览模式禁止新增和修改')
915
+ return false
916
+ }
917
+ this.loading = true
918
+ const requestForm = this.prepareForm()
919
+ await this.appendSilenceAddFields(requestForm)
920
+ const realForm = this.handleFormKeys(requestForm)
921
+ // 增加子表数据
922
+ if (this.childTableData.length > 0) {
923
+ for (const item of this.childTableData) {
924
+ const childModel = item.model
925
+ const childDataRef = this.$refs['childXFormTable_' + item.model][0].getTableData()
926
+ const childData = []
927
+ for (const item of childDataRef) {
928
+ childData.push(JSON.parse(JSON.stringify(item)))
929
+ }
930
+ for (let i = 0; i < childData.length; i++) {
931
+ childData[i] = this.handleFormKeys(childData[i])
932
+ // 外键不需要带表别名,所以此处放到表单处理后赋值
933
+ if (realForm.id) {
934
+ childData[i][item.childTableForeignKeyName] = realForm.id
935
+ }
936
+ }
937
+ realForm[childModel] = childData
938
+ }
939
+ }
940
+ // 增加form子表数据
941
+ if (this.childFormData.length > 0) {
942
+ for (const item of this.childFormData) {
943
+ const childModel = item.model
944
+ const childData = this.$refs[item.model].getTableData()
945
+ for (let i = 0; i < childData.length; i++) {
946
+ childData[i] = this.handleFormKeys(childData[i], true)
947
+ // 外键不需要带表别名,所以此处放到表单处理后赋值
948
+ if (realForm.id) {
949
+ childData[i][item.foreignKey] = realForm.id
950
+ }
951
+ }
952
+ realForm[childModel] = childData
953
+ }
954
+ }
955
+ if (this.$listeners.onSubmit) {
956
+ // 交由父级处理
957
+ this.$emit('onSubmit', {
958
+ businessType: this.businessType,
959
+ serviceName: this.serviceName,
960
+ realForm: realForm,
961
+ currUserName: this.currUser.name,
962
+ currUserId: this.currUser.id,
963
+ orgId: this.currUser.orgid
964
+ })
965
+ } else {
966
+ this.defaultSubmit(realForm)
967
+ }
968
+ },
969
+
970
+ async asyncSubmit () {
971
+ return new Promise((resolve, reject) => {
972
+ this.$refs.selectForm.validate(async valid => {
973
+ if (!valid) {
974
+ reject(new Error('Form validation failed'))
975
+ return
976
+ }
977
+ this.loading = true
978
+ const requestForm = this.prepareForm()
979
+ await this.appendSilenceAddFields(requestForm)
980
+ const realForm = this.handleFormKeys(requestForm)
981
+ resolve({
982
+ realForm,
983
+ businessType: this.businessType,
984
+ serviceName: this.serviceName,
985
+ currUserName: this.currUser.name,
986
+ currUserId: this.currUser.id,
987
+ orgId: this.currUser.orgid
988
+ })
989
+ })
990
+ })
991
+ },
992
+
993
+ validateForm () {
994
+ return new Promise((resolve) => {
995
+ this.$refs.selectForm.validate(valid => resolve(valid))
996
+ })
997
+ },
998
+
999
+ childTableFixedQueryForm (item) {
1000
+ if (this.modifyModelData?.primaryKeyData) {
1001
+ const fixedForm = {}
1002
+ fixedForm[item.childTableForeignKeyName] = Object.values(this.modifyModelData.primaryKeyData)[0]
1003
+ return fixedForm
1004
+ }
1005
+ return null
1006
+ },
1007
+
1008
+ prepareForm () {
1009
+ const form = { ...this.form }
1010
+ for (const key of Object.keys(form)) {
1011
+ const value = form[key]
1012
+ if (value === null || (typeof value === 'object' && Object.keys(value).length === 0)) {
1013
+ form[key] = undefined
1014
+ }
1015
+ }
1016
+ return form
1017
+ },
1018
+
1019
+ async appendSilenceAddFields (form) {
1020
+ if (this.businessType === '新增') {
1021
+ for (const item of this.silenceAddJsonData) {
1022
+ switch (item.silencePurpose) {
1023
+ case 'createTime':
1024
+ form[item.model] = formatDate('now')
1025
+ break
1026
+ case 'operator':
1027
+ form[item.model] = this.currUser.name
1028
+ break
1029
+ case 'operatorId':
1030
+ form[item.model] = this.currUser.id
1031
+ break
1032
+ case 'orgId':
1033
+ form[item.model] = this.currUser.orgid
1034
+ break
1035
+ case 'orgName':
1036
+ form[item.model] = this.currUser.orgs
1037
+ break
1038
+ case 'depId':
1039
+ form[item.model] = this.currUser.depids
1040
+ break
1041
+ case 'depName':
1042
+ form[item.model] = this.currUser.deps
1043
+ break
1044
+ }
1045
+ }
1046
+ for (const item of this.silenceAddJsonData.filter((item) => item.silencePurpose === 'customize')) {
1047
+ const result = await runLogic(item.silenceSource, form, this.serviceName)
1048
+ if (result) {
1049
+ const keys = Object.keys(result)
1050
+ if (keys.length === 1 && keys[0] === 'value') {
1051
+ form[item.model] = result.value
1052
+ } else {
1053
+ form[item.model] = result
1054
+ }
1055
+ } else {
1056
+ form[item.model] = result
1057
+ }
1058
+ }
1059
+ }
1060
+ },
1061
+
1062
+ handleFormKeys (form, mustHandleKey = false) {
1063
+ const realForm = {}
1064
+ for (const key of Object.keys(form)) {
1065
+ const value = form[key]
1066
+ const extraFormKeyTagIndex = key.indexOf('@')
1067
+ if (extraFormKeyTagIndex !== -1) {
1068
+ const extraFormKey = key.substring(0, extraFormKeyTagIndex)
1069
+ const realKey = key.substring(extraFormKeyTagIndex + 1)
1070
+ if (!realForm[extraFormKey]) {
1071
+ realForm[extraFormKey] = {}
1072
+ }
1073
+ realForm[extraFormKey][realKey] = value
1074
+ } else {
1075
+ const realKey = this.isHandleFormKey || mustHandleKey ? this.getRealKey(key, mustHandleKey) : key
1076
+ // 如果发生重名,不覆盖,把key的别名带上
1077
+ if (realForm[realKey]) {
1078
+ realForm[key] = value
1079
+ } else {
1080
+ realForm[realKey] = value
1081
+ }
1082
+ }
1083
+ }
1084
+ return realForm
1085
+ },
1086
+ // 默认提交事件
1087
+ defaultSubmit (realForm, callback) {
1088
+ // 新增移除id
1089
+ if (this.businessType === '新增') {
1090
+ delete realForm.id
1091
+ }
1092
+ // 组织请求
1093
+ const requestParameters = {
1094
+ queryParamsName: this.configName,
1095
+ queryParams: this.configContent,
1096
+ form: realForm,
1097
+ businessType: this.businessType,
1098
+ operator: this.currUser.name
1099
+ }
1100
+ addOrModify(requestParameters, this.serviceName, this.env === 'dev').then(data => {
1101
+ this.$message.success(this.businessType + '成功!')
1102
+ // commit
1103
+ this.$emit('afterSubmit', { type: this.businessType, id: data.id, data: data, form: requestParameters.form })
1104
+ this.loading = false
1105
+ if (callback) {
1106
+ callback()
1107
+ }
1108
+ }).catch(e => {
1109
+ this.loading = false
1110
+ this.$message.error(this.businessType + '失败:' + e)
1111
+ })
1112
+ },
1113
+ // 获取表单字段实际值
1114
+ getRealKey (key, mustHandleKey = false) {
1115
+ if (key === 'selected_id') return key
1116
+ if (this.isHandleFormKey || mustHandleKey) {
1117
+ return key.substring(key.indexOf('_') + 1)
1118
+ } else {
1119
+ return key
1120
+ }
1121
+ },
1122
+ /**
1123
+ * 获取被修改记录数据
1124
+ * @param modifyModelData 被修改记录的数据
1125
+ */
1126
+ getModifyModelData (modifyModelData) {
1127
+ if (modifyModelData.primaryKeyData) {
1128
+ this.form = Object.assign(this.form, modifyModelData.primaryKeyData)
1129
+ }
1130
+ // 对动态简易表单项特殊处理
1131
+ for (const key in modifyModelData.data) {
1132
+ const realKey = this.isHandleFormKey ? this.getRealKey(key) : key
1133
+ if (this.simpleFormJsonData[realKey]) {
1134
+ const extraForm = JSON.parse(modifyModelData.data[key])
1135
+ for (const key in extraForm) {
1136
+ const model = realKey + '@' + key
1137
+ this.form[model] = extraForm[key]
1138
+ }
1139
+ }
1140
+ }
1141
+ // 对普通表单项处理
1142
+ for (let i = 0; i < this.realJsonData.length; i++) {
1143
+ if (['FilesId', 'Images'].includes(this.realJsonData[i])) {
1144
+ // 附件需要跳过 因为会通过 modifyModelData中的files,images属性给upload赋值
1145
+ // 新增修改表单每次提交时只会提交最新添加的文件
1146
+ continue
1147
+ }
1148
+ const item = this.realJsonData[i]
1149
+ // 地址选择器 需要传递 经纬度字段, 配置中添加 `${item.model}_lng_lat` CRUD 只需勾选 SQL生成查询项
1150
+ if (['addressSearch'].includes(item.type)) {
1151
+ this.form[item.model] = modifyModelData.data[item.model] + ''
1152
+ this.form[`${item.model}_lng_lat`] = modifyModelData.data[`${item.model}_lng_lat`] + ''
1153
+ continue
1154
+ }
1155
+ if (modifyModelData.data[item.model] || modifyModelData.data[item.model] === 0) {
1156
+ if (modifyModelData.data[item.model] instanceof Array) {
1157
+ this.form[item.model] = modifyModelData.data[item.model]
1158
+ } else {
1159
+ this.form[item.model] = modifyModelData.data[item.model] + ''
1160
+ }
1161
+ }
1162
+ }
1163
+ // 对分组表单进行处理
1164
+ for (let i = 0; i < this.groupJsonData.length; i++) {
1165
+ const item = this.groupJsonData[i]
1166
+ try {
1167
+ if (modifyModelData.data[item.model]) {
1168
+ this.form[item.model] = JSON.parse(modifyModelData.data[item.model])
1169
+ }
1170
+ } catch (e) {
1171
+ if (modifyModelData.data[item.model]) {
1172
+ this.form[item.model] = modifyModelData.data[item.model]
1173
+ }
1174
+ }
1175
+ }
1176
+ // 追加版本号信息
1177
+ for (const item of this.versionJsonData) {
1178
+ if (!modifyModelData.data[item.model]) {
1179
+ this.form[item.model] = 0
1180
+ } else {
1181
+ this.form[item.model] = modifyModelData.data[item.model] + ''
1182
+ }
1183
+ }
1184
+ },
1185
+ setForm (obj) {
1186
+ this.form = Object.assign(this.form, obj)
1187
+ // 给子表赋外键条件
1188
+ if (this.childFormData.length > 0) {
1189
+ for (const item of this.childFormData) {
1190
+ const child = this.$refs[item.model]
1191
+ // 获取子表别名,以便在条件上添加别名
1192
+ const alias = child.realQueryConfig.tableAliasName
1193
+ // 有主键,且主键有值,添加主键条件
1194
+ if (this.primaryKey && this.form[this.primaryKey]) {
1195
+ const foreignKey = item.foreignKey
1196
+ const fixedQueryForm = { [alias + '_' + foreignKey]: this.form[this.primaryKey] }
1197
+ if (!child.fixedQueryForm) {
1198
+ child.fixedQueryForm = fixedQueryForm
1199
+ } else {
1200
+ Object.assign(child.fixedQueryForm, fixedQueryForm)
1201
+ }
1202
+ child.refreshTable()
1203
+ }
1204
+ }
1205
+ }
1206
+ },
1207
+ setFormWithKey (obj) {
1208
+ setDataByRealKey(this.form, obj)
1209
+ },
1210
+ setFormWithNoKey (obj) {
1211
+ setDataByRealKey(this.form, obj)
1212
+ },
1213
+ emitFunc (func, data, value) {
1214
+ this.$emit(func, data, value)
1215
+ this.$emit('x-form-item-emit-func', func, data, value)
1216
+ },
1217
+ // 直接转发事件的函数
1218
+ emitEvent (event, ...args) {
1219
+ this.$emit(event, ...args)
1220
+ },
1221
+ close () {
1222
+ this.loaded = false
1223
+ },
1224
+ /**
1225
+ * 行选择事件
1226
+ * @param row 选中行集合
1227
+ * @param attr 表单项属性
1228
+ */
1229
+ async rowChoose (row, attr, callback) {
1230
+ // 如果配置了自定义函数
1231
+ if (attr.dataChangeFunc) {
1232
+ await executeStrFunction(attr.dataChangeFunc, [this.form, this.setForm, {
1233
+ ...attr,
1234
+ selectRows: row
1235
+ }, util, this.mode, runLogic, getConfigByNameAsync])
1236
+ } else {
1237
+ // 默认填充选中行数据到当前表单
1238
+ setDataByRealKey(this.form, row[0])
1239
+ }
1240
+ if (callback) {
1241
+ callback()
1242
+ }
1243
+ },
1244
+ }
1245
+ }
1246
+ </script>
1247
+
1248
+ <style scoped lang="less">
1249
+ :deep(.ant-form-inline .ant-form-item ) {
1250
+ display: block !important;
1251
+ }
1252
+
1253
+ :deep(.ant-form-item-with-help) {
1254
+ margin-bottom: 0;
1255
+ }
1256
+
1257
+ .xFormGroupTitle {
1258
+ font-weight: bold;
1259
+ color: @primary-color;
1260
+ }
1261
+
1262
+ .simple-inline-item {
1263
+ max-width: 100% !important;
1264
+ }
1265
+
1266
+ /* simple-inline模式样式 */
1267
+ :deep(.simple-inline-item .ant-form-item) {
1268
+ margin: 0 !important;
1269
+ padding: 2px !important;
1270
+
1271
+ .ant-form-item-label {
1272
+ display: none !important;
1273
+ }
1274
+
1275
+ .ant-form-item-control-wrapper,
1276
+ .ant-form-item-control {
1277
+ width: 100% !important;
1278
+ }
1279
+ }
1280
+ </style>