buildBlocks.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <!-- 标签页布局 -->
  3. <a-tabs
  4. v-if="record.type === 'tabs'"
  5. class="grid-row"
  6. :default-active-key="0"
  7. :tabBarGutter="record.options.tabBarGutter"
  8. :type="record.options.type"
  9. :size="record.options.size"
  10. :tabPosition="record.options.tabPosition"
  11. :animated="record.options.animated"
  12. v-model="activeKey"
  13. >
  14. <a-tab-pane
  15. v-for="(tabItem, index) in record.columns"
  16. :key="index"
  17. :tab="tabItem.label"
  18. :forceRender="true"
  19. >
  20. <buildBlocks
  21. ref="nestedComponents"
  22. @handleReset="$emit('handleReset')"
  23. @change="handleChange"
  24. v-for="item in tabItem.list"
  25. :disabled="disabled"
  26. :dynamicData="dynamicData"
  27. :key="item.key"
  28. :record="item"
  29. :formConfig="formConfig"
  30. :config="config"
  31. />
  32. </a-tab-pane>
  33. </a-tabs>
  34. <!-- 栅格布局 -->
  35. <a-row
  36. v-else-if="record.type === 'grid'"
  37. class="grid-row"
  38. :gutter="record.options.gutter"
  39. >
  40. <a-col
  41. class="grid-col"
  42. v-for="(colItem, idnex) in record.columns"
  43. :key="idnex"
  44. :span="colItem.span || 0"
  45. >
  46. <buildBlocks
  47. ref="nestedComponents"
  48. @handleReset="$emit('handleReset')"
  49. @change="handleChange"
  50. v-for="item in colItem.list"
  51. :disabled="disabled"
  52. :dynamicData="dynamicData"
  53. :key="item.key"
  54. :record="item"
  55. :formConfig="formConfig"
  56. :config="config"
  57. />
  58. </a-col>
  59. </a-row>
  60. <!-- 卡片布局 -->
  61. <a-card
  62. v-else-if="record.type === 'card'"
  63. class="grid-row"
  64. :title="record.label"
  65. >
  66. <buildBlocks
  67. ref="nestedComponents"
  68. @handleReset="$emit('handleReset')"
  69. @change="handleChange"
  70. v-for="item in record.list"
  71. :disabled="disabled"
  72. :dynamicData="dynamicData"
  73. :key="item.key"
  74. :record="item"
  75. :formConfig="formConfig"
  76. :config="config"
  77. />
  78. </a-card>
  79. <!-- 表格布局 -->
  80. <table
  81. v-else-if="record.type === 'table'"
  82. class="kk-table-9136076486841527"
  83. :class="{
  84. bright: record.options.bright,
  85. small: record.options.small,
  86. bordered: record.options.bordered
  87. }"
  88. :style="record.options.customStyle"
  89. >
  90. <tr v-for="(trItem, trIndex) in record.trs" :key="trIndex">
  91. <td
  92. class="table-td"
  93. v-for="(tdItem, tdIndex) in trItem.tds.filter(
  94. item => item.colspan && item.rowspan
  95. )"
  96. :key="tdIndex"
  97. :colspan="tdItem.colspan"
  98. :rowspan="tdItem.rowspan"
  99. >
  100. <buildBlocks
  101. ref="nestedComponents"
  102. @handleReset="$emit('handleReset')"
  103. @change="handleChange"
  104. v-for="item in tdItem.list"
  105. :disabled="disabled"
  106. :dynamicData="dynamicData"
  107. :key="item.key"
  108. :record="item"
  109. :formConfig="formConfig"
  110. :config="config"
  111. />
  112. </td>
  113. </tr>
  114. </table>
  115. <KFormItem
  116. v-else-if="!record.options.hidden"
  117. ref="nestedComponents"
  118. @handleReset="$emit('handleReset')"
  119. @change="handleChange"
  120. :disabled="disabled"
  121. :dynamicData="dynamicData"
  122. :key="record.key"
  123. :record="record"
  124. :formConfig="formConfig"
  125. :config="config"
  126. />
  127. </template>
  128. <script>
  129. /*
  130. * author kcz
  131. * date 2019-11-20
  132. */
  133. import KFormItem from "../KFormItem/index";
  134. export default {
  135. name: "buildBlocks",
  136. props: {
  137. record: {
  138. type: Object,
  139. required: true
  140. },
  141. formConfig: {
  142. type: Object,
  143. required: true
  144. },
  145. config: {
  146. type: Object,
  147. default: () => ({})
  148. },
  149. dynamicData: {
  150. type: Object,
  151. required: true
  152. },
  153. disabled: {
  154. type: Boolean,
  155. default: false
  156. },
  157. validatorError: {
  158. type: [Object, null],
  159. default: () => ({})
  160. }
  161. },
  162. components: {
  163. KFormItem
  164. },
  165. data() {
  166. return {
  167. activeKey: 0
  168. };
  169. },
  170. methods: {
  171. validationSubform() {
  172. // 验证动态表格
  173. const nestedComponents = this.$refs.nestedComponents;
  174. if (
  175. typeof nestedComponents === "object" &&
  176. nestedComponents instanceof Array
  177. ) {
  178. for (let i = 0; nestedComponents.length > i; i++) {
  179. if (!nestedComponents[i].validationSubform()) {
  180. return false;
  181. }
  182. }
  183. return true;
  184. } else if (typeof nestedComponents !== "undefined") {
  185. return nestedComponents.validationSubform();
  186. } else {
  187. return true;
  188. }
  189. },
  190. handleChange(value, key) {
  191. this.$emit("change", value, key);
  192. }
  193. },
  194. watch: {
  195. /**
  196. * @author: lizhichao<meteoroc@outlook.com>
  197. * @description: 监视validatorError对象,当检测到Tabs中有表单校验无法通过时,切换到最近校验失败的tab页。
  198. */
  199. validatorError: {
  200. deep: true,
  201. handler: function(n) {
  202. const errorItems = Object.keys(n);
  203. if (errorItems.length) {
  204. if (!this.record.columns) return false;
  205. for (let i = 0; i < this.record.columns.length; i++) {
  206. const err = this.record.columns[i].list.filter(item =>
  207. errorItems.includes(item.model)
  208. );
  209. if (err.length) {
  210. this.activeKey = i;
  211. break;
  212. }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. };
  219. </script>