GenerateDialog.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <a-modal
  3. v-model:open="visible"
  4. :title="element.options.title"
  5. :width="element.options.width || '50%'"
  6. :mask-closable="false"
  7. :closable="element.options.showClose"
  8. destroy-on-close
  9. :ref="`generate-dialog-${element.model}`"
  10. :style="{
  11. top: element.options.top || '15vh'
  12. }"
  13. :z-index="3000"
  14. :wrap-class-name="'fm-generate-ant-dialog '
  15. + ((!element.options.showCancel && !element.options.showOk) ? 'no-footer ' : '')
  16. + (element.options.center ? 'center ' : '')
  17. + (element.options?.customClass ? element.options?.customClass : '')"
  18. @cancel="close"
  19. >
  20. <div >
  21. <template v-for="item in element.list">
  22. <generate-col-item
  23. v-if="item.type == 'grid'"
  24. :key="`grid-${item.key}`"
  25. :model="dialogModel"
  26. :rules="rules"
  27. :element="item"
  28. :remote="remote"
  29. :blanks="blanks"
  30. :display="displayFields"
  31. :edit="edit"
  32. :remote-option="remoteOption"
  33. :platform="platform"
  34. :preview="preview"
  35. :container-key="containerKey"
  36. :data-source-value="dataSourceValue"
  37. :event-function="eventFunction"
  38. :print-read="printRead"
  39. :is-dialog="true"
  40. :dialog-name="element.model"
  41. :config="config"
  42. :group="element.model"
  43. :field-node="element.model"
  44. >
  45. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  46. <slot :name="blank.name" :model="scope.model"></slot>
  47. </template>
  48. </generate-col-item>
  49. <generate-tab-item
  50. v-else-if="item.type == 'tabs'"
  51. :key="`tabs-${item.key}`"
  52. :model="dialogModel"
  53. :rules="rules"
  54. :element="item"
  55. :remote="remote"
  56. :blanks="blanks"
  57. :display="displayFields"
  58. :edit="edit"
  59. :remote-option="remoteOption"
  60. :platform="platform"
  61. :preview="preview"
  62. :container-key="containerKey"
  63. :data-source-value="dataSourceValue"
  64. :event-function="eventFunction"
  65. :print-read="printRead"
  66. :is-dialog="true"
  67. :dialog-name="element.model"
  68. :config="config"
  69. :group="element.model"
  70. :field-node="element.model"
  71. >
  72. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  73. <slot :name="blank.name" :model="scope.model"></slot>
  74. </template>
  75. </generate-tab-item>
  76. <generate-collapse
  77. v-else-if="item.type == 'collapse'"
  78. :key="`collapse-${item.key}`"
  79. :model="dialogModel"
  80. :rules="rules"
  81. :element="item"
  82. :remote="remote"
  83. :blanks="blanks"
  84. :display="displayFields"
  85. :edit="edit"
  86. :remote-option="remoteOption"
  87. :platform="platform"
  88. :preview="preview"
  89. :container-key="containerKey"
  90. :data-source-value="dataSourceValue"
  91. :event-function="eventFunction"
  92. :print-read="printRead"
  93. :is-dialog="true"
  94. :dialog-name="element.model"
  95. :config="config"
  96. :group="element.model"
  97. :field-node="element.model"
  98. >
  99. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  100. <slot :name="blank.name" :model="scope.model"></slot>
  101. </template>
  102. </generate-collapse>
  103. <generate-report
  104. v-else-if="item.type == 'report'"
  105. :key="`report-${item.key}`"
  106. :model="dialogModel"
  107. :rules="rules"
  108. :element="item"
  109. :remote="remote"
  110. :blanks="blanks"
  111. :display="displayFields"
  112. :edit="edit"
  113. :remote-option="remoteOption"
  114. :platform="platform"
  115. :preview="preview"
  116. :container-key="containerKey"
  117. :data-source-value="dataSourceValue"
  118. :event-function="eventFunction"
  119. :print-read="printRead"
  120. :is-dialog="true"
  121. :dialog-name="element.model"
  122. :config="config"
  123. :group="element.model"
  124. :field-node="element.model"
  125. >
  126. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  127. <slot :name="blank.name" :model="scope.model"></slot>
  128. </template>
  129. </generate-report>
  130. <generate-card
  131. v-else-if="item.type == 'card'"
  132. :key="`card-${item.key}`"
  133. :model="dialogModel"
  134. :rules="rules"
  135. :element="item"
  136. :remote="remote"
  137. :blanks="blanks"
  138. :display="displayFields"
  139. :edit="edit"
  140. :remote-option="remoteOption"
  141. :platform="platform"
  142. :preview="preview"
  143. :container-key="containerKey"
  144. :data-source-value="dataSourceValue"
  145. :event-function="eventFunction"
  146. :print-read="printRead"
  147. :is-dialog="true"
  148. :dialog-name="element.model"
  149. :config="config"
  150. :group="element.model"
  151. :field-node="element.model"
  152. >
  153. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  154. <slot :name="blank.name" :model="scope.model"></slot>
  155. </template>
  156. </generate-card>
  157. <generate-inline
  158. v-else-if="item.type == 'inline'"
  159. :key="`inline-${item.key}`"
  160. :model="dialogModel"
  161. :rules="rules"
  162. :element="item"
  163. :remote="remote"
  164. :blanks="blanks"
  165. :display="displayFields"
  166. :edit="edit"
  167. :remote-option="remoteOption"
  168. :platform="platform"
  169. :preview="preview"
  170. :container-key="containerKey"
  171. :data-source-value="dataSourceValue"
  172. :event-function="eventFunction"
  173. :print-read="printRead"
  174. :is-dialog="true"
  175. :dialog-name="element.model"
  176. :config="config"
  177. :group="element.model"
  178. :field-node="element.model"
  179. >
  180. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  181. <slot :name="blank.name" :model="scope.model"></slot>
  182. </template>
  183. </generate-inline>
  184. <generate-form-item
  185. v-else
  186. :key="`form-item-${item.key}`"
  187. :models="dialogModel"
  188. :rules="rules"
  189. :widget="item"
  190. :remote="remote"
  191. :blanks="blanks"
  192. :display="displayFields"
  193. :edit="edit"
  194. :remote-option="remoteOption"
  195. :platform="platform"
  196. :preview="preview"
  197. :container-key="containerKey"
  198. :data-source-value="dataSourceValue"
  199. :event-function="eventFunction"
  200. :print-read="printRead"
  201. :is-dialog="true"
  202. :dialog-name="element.model"
  203. :config="config"
  204. :group="element.model"
  205. :field-node="element.model"
  206. >
  207. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  208. <slot :name="blank.name" :model="scope.model"></slot>
  209. </template>
  210. </generate-form-item>
  211. </template>
  212. </div>
  213. <template #footer>
  214. <div>
  215. <a-button key="back" v-if="element.options.showCancel" @click="handleCancel">{{element.options.cancelText}}</a-button>
  216. <a-button key="submit" type="primary" v-if="element.options.showOk" :loading="element.options.confirmLoading" @click="handleConfirm">{{element.options.okText}}</a-button>
  217. </div>
  218. </template>
  219. </a-modal>
  220. </template>
  221. <script>
  222. import GenerateFormItem from './GenerateFormItem.vue'
  223. import GenerateColItem from './GenerateColItem.vue'
  224. import GenerateTabItem from './GenerateTabItem.vue'
  225. import GenerateReport from './GenerateReport.vue'
  226. import GenerateInline from './GenereteInline.vue'
  227. import GenerateCollapse from './GenerateCollapse.vue'
  228. import GenerateCard from './GenerateCard.vue'
  229. import { generateDialogMixin } from '../../mixins/generateDialog'
  230. export default {
  231. name: 'generate-dialog',
  232. components: {
  233. GenerateColItem,
  234. GenerateFormItem,
  235. GenerateInline,
  236. GenerateReport,
  237. GenerateTabItem,
  238. GenerateCollapse,
  239. GenerateCard
  240. },
  241. mixins: [generateDialogMixin],
  242. props: ['config', 'models', 'rules', 'element', 'remote', 'blanks', 'edit', 'remoteOption', 'platform', 'preview', 'containerKey', 'dataSourceValue', 'eventFunction', 'printRead', 'group', 'fieldNode'],
  243. data () {
  244. return {
  245. activeElement: ''
  246. }
  247. },
  248. mounted () {
  249. this.generateComponentInstance && this.generateComponentInstance(this.element.model, this.$refs[`generate-dialog-${this.element.model}`].$parent)
  250. this.$nextTick(() => {
  251. window.document.querySelector('.fm-generate-ant-dialog')?.removeAttribute('tabindex')
  252. setTimeout(() => {
  253. this.clearValidate()
  254. })
  255. })
  256. },
  257. methods: {
  258. open () {
  259. this.activeElement = document.activeElement
  260. document.activeElement && document.activeElement.blur()
  261. this.visible = true
  262. if (this.element && this.element.events && this.element.events.onOpen) {
  263. let funcKey = this.element.events.onOpen
  264. this.$nextTick(() => {
  265. this.eventFunction[funcKey]({field: this.element.model, currentRef: this})
  266. })
  267. }
  268. },
  269. close () {
  270. if (this.activeElement) {
  271. this.activeElement.focus()
  272. this.activeElement = ''
  273. }
  274. this.visible = false
  275. if (this.element && this.element.events && this.element.events.onClose) {
  276. let funcKey = this.element.events.onClose
  277. this.eventFunction[funcKey]({field: this.element.model, currentRef: this})
  278. }
  279. },
  280. validate () {
  281. return new Promise((resolve, reject) => {
  282. let realFields = this._getAllRuleFields()
  283. this.getFormComponent().validate(realFields).then(() => {
  284. resolve()
  285. }).catch(()=> {
  286. reject()
  287. })
  288. })
  289. },
  290. clearValidate () {
  291. let realFields = this._getAllRuleFields()
  292. this.getFormComponent().clearValidate(realFields)
  293. },
  294. _getAllRuleFields () {
  295. let realFields = []
  296. Object.keys(this.dialogModel).forEach((v) => {
  297. if (Array.isArray(this.dialogModel[v])) {
  298. const currentArray = this.dialogModel[v]
  299. currentArray.forEach((o, i) => {
  300. Object.keys(o).forEach((key) => {
  301. realFields.push(`${this.element.model}.${v}.${i}.${key}`)
  302. })
  303. })
  304. } else {
  305. realFields.push(`${this.element.model}.${v}`)
  306. }
  307. })
  308. return realFields.map(item => item.split('.'))
  309. }
  310. }
  311. }
  312. </script>
  313. <style lang="scss">
  314. .fm-generate-ant-dialog{
  315. &.no-footer{
  316. .ant-modal-footer{
  317. display: none;
  318. }
  319. }
  320. &.center{
  321. .ant-modal-header{
  322. text-align: center;
  323. }
  324. .ant-modal-footer{
  325. text-align: center;
  326. }
  327. }
  328. .ant-form-item{
  329. .ant-pagination{
  330. float: right;
  331. }
  332. }
  333. }
  334. </style>