index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <design-framework>
  3. <template #components>
  4. <table-components :group-list="groupList"></table-components>
  5. </template>
  6. <template #toolbar>
  7. <cip-button-text size="default" @click="previewJson">预览JSON</cip-button-text>
  8. </template>
  9. <div class="form-drawing-container">
  10. <el-form class="form-item-wrap" :size="tableConfig.tableSize||'default'" :label-width="`${tableConfig.labelWidth}px`" :label-position="tableConfig.labelPosition">
  11. <form-drawing-table field-key="tableData"
  12. :select-id="selectId"
  13. :config="tableConfig.config"
  14. @update:config="updateConfig"
  15. @click="handleSelectItem(tableConfig)"
  16. @onSelectItem="handleSelectItem"></form-drawing-table>
  17. </el-form>
  18. </div>
  19. <template #property>
  20. <table-property :selectItem="selectItem"
  21. :data="formConfig"
  22. :property-tabs="propertyTabs"
  23. :defaultActiveType="defaultActiveType"
  24. @update:selectItem="updateSelectItem"
  25. ></table-property>
  26. </template>
  27. <cip-dialog v-model="previewJsonVisible" title="预览JSON" top="5vh" :show-only="true">
  28. <cip-code-mirror :modelValue="previewJsonResult"></cip-code-mirror>
  29. </cip-dialog>
  30. </design-framework>
  31. </template>
  32. <script>
  33. import { computed, ref } from 'vue'
  34. import { ElForm } from 'element-plus'
  35. import DesignFramework from './framework'
  36. import TableComponents from './table-components'
  37. import TableProperty from './form-property'
  38. import FormDrawingTable from './form-drawing'
  39. import CipDialog from '@cip/components/cip-dialog'
  40. import CipCodeMirror from '@cip/components/cip-code-mirror'
  41. import { formConfigListFlat, except } from './util'
  42. import { componentsGroupList } from './components-config.js'
  43. import CipButtonText from '@cip/components/cip-button-text'
  44. export default {
  45. components: { ElForm, DesignFramework, TableComponents, TableProperty, CipButtonText, CipDialog, FormDrawingTable, CipCodeMirror },
  46. props: {
  47. formConfig: Object,
  48. isDefaultConfig: {
  49. type: Boolean,
  50. default: true
  51. },
  52. tableDefaultConfig: Object,
  53. componentsGroupList: { // 字段组件配置
  54. type: Array,
  55. default: () => componentsGroupList
  56. },
  57. propertyTabs: Array, // 需要的属性面板tab列表
  58. defaultActiveType: String // 默认选中的属性面板
  59. },
  60. emits: ['update:tableConfig'],
  61. setup (props, { emit }) {
  62. const previewFormVisible = ref(false)
  63. const preview = () => {
  64. previewFormVisible.value = true
  65. }
  66. const previewJsonVisible = ref(false)
  67. const previewJsonResult = ref('')
  68. const previewJson = () => {
  69. previewJsonResult.value = tableConfig.value
  70. previewJsonVisible.value = true
  71. }
  72. /**
  73. * 转成列表待用组件
  74. * 筛出子表单和文字组件,将布局组件中的字段提出
  75. */
  76. const selectItem = ref({})
  77. const selectId = ref('')
  78. // 拿到表单设计组件配置项,使用里边的label来做默认值
  79. const componentsList = ref([])
  80. props.componentsGroupList.forEach(i => {
  81. componentsList.value = componentsList.value.concat(i.components)
  82. })
  83. const groupList = computed(() => {
  84. if (!props.isDefaultConfig) {
  85. const list = toGroupList(props.formConfig.list) ?? []
  86. list[0].components.map(i => {
  87. if (i.label === '') i.label = componentsList.value.find(v => v.type === i.type)?.label ?? ''
  88. return i
  89. })
  90. return list
  91. } else {
  92. return props.componentsGroupList
  93. }
  94. })
  95. // 备选表单字段保留的字段格式
  96. const assignConfig = (i) => {
  97. return {
  98. key: i.key,
  99. id: i.id,
  100. type: i.config.type,
  101. label: i.config.label,
  102. search: i.config.search ?? true,
  103. fieldAlias: i.config.fieldAlias ?? i.config.label ?? ''
  104. }
  105. }
  106. const toGroupList = (formData) => {
  107. return [{
  108. groupName: 'basic',
  109. label: '表单字段',
  110. components: formConfigListFlat(formData).filter(v => !except.includes(v.config.type)).map(i => assignConfig(i))
  111. }]
  112. }
  113. /**
  114. * 列表配置项
  115. */
  116. const tableConfig = ref({
  117. config: {
  118. type: 'table',
  119. class: 'disabled-table',
  120. icon: 'el-icon-edit',
  121. list: props.tableDefaultConfig?.list ?? []
  122. }
  123. })
  124. const updateConfig = (val) => {
  125. emit('update:tableConfig', val)
  126. }
  127. const handleSelectItem = (item) => {
  128. selectItem.value = item
  129. selectId.value = item.id
  130. }
  131. const updateSelectItem = val => {
  132. selectItem.value.key = val.key || ''
  133. selectItem.value.config = val
  134. // eslint-disable-next-line
  135. for (const i in tableConfig.value?.config?.list) {
  136. if (tableConfig.value.config.list[i].key === val.key) {
  137. tableConfig.value.config.list[i] = { config: val, key: val.key, id: val.id }
  138. }
  139. }
  140. updateConfig(tableConfig.value)
  141. }
  142. return {
  143. groupList,
  144. previewFormVisible,
  145. preview,
  146. previewJsonVisible,
  147. previewJsonResult,
  148. previewJson,
  149. tableConfig: tableConfig.value,
  150. updateConfig,
  151. selectItem,
  152. selectId,
  153. handleSelectItem,
  154. updateSelectItem
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="less">
  160. @import "./form-drawing/index";
  161. .empty-form--text{
  162. position: absolute;
  163. left: 0;
  164. right:0;
  165. top: 0;
  166. bottom: 0;
  167. display: flex;
  168. align-items: center;
  169. justify-content: center;
  170. color: #999;
  171. z-index: 1;
  172. }
  173. </style>