index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <a-row :gutter="10">
  3. <a-col :span="5">
  4. <a-card title="基础">
  5. <a-row>
  6. <VueDraggable v-model="componentBaseList" :animation="150" :group="{ name: 'people', pull: 'clone', put: false }" :sort="false" :clone="onClone">
  7. <a-col :span="12" v-for="item in componentBaseList" :key="item.id">
  8. <div class="hover type">
  9. <a-space>
  10. <a-icon type="profile" /> {{ item.name }}
  11. </a-space>
  12. </div>
  13. </a-col>
  14. </VueDraggable>
  15. </a-row>
  16. </a-card>
  17. <a-card title="高级">
  18. <a-row>
  19. <VueDraggable v-model="componenHidetList" :animation="150" :group="{ name: 'people', pull: 'clone', put: false }" :sort="false" :clone="onClone">
  20. <a-col :span="12" v-for="item in componenHidetList" :key="item.id">
  21. <div class="hover type">
  22. <a-space>
  23. <a-icon type="profile" /> {{ item.name }}
  24. </a-space>
  25. </div>
  26. </a-col>
  27. </VueDraggable>
  28. </a-row>
  29. </a-card>
  30. </a-col>
  31. <a-col :span="15">
  32. <a-card>
  33. <a-form :form="form" :labelCol="BaseTool.Constant.labelCol" :wrapperCol="BaseTool.Constant.wrapperCol">
  34. <a-row>
  35. <VueDraggable v-model="components" :animation="150" group="people" style="min-height:600px">
  36. <MComponent class="hover" v-for="item in components" :key="item.id" :config="config" :detail="item" @select="handleSelect" @selectInfo="handleInfoSelect" />
  37. </VueDraggable>
  38. </a-row>
  39. </a-form>
  40. </a-card>
  41. </a-col>
  42. <a-col :span="4">
  43. <Detail :config="config" ref="detail" @delete="handleDelete" @addForm="addForm" />
  44. </a-col>
  45. <SelectInfo ref="selectInfo" @selected="handleInfoSelected" />
  46. </a-row>
  47. </template>
  48. <script>
  49. import { VueDraggable } from 'vue-draggable-plus'
  50. import Detail from './modules/Detail.vue'
  51. import MComponent from './modules/Component.vue'
  52. import SelectInfo from './modules/SelectInfo'
  53. import { getCustomRelation } from '@/api/custom/relation'
  54. import { componentBaseList, componenHidetList } from './modules/components'
  55. export default {
  56. name: 'Test1',
  57. components: {
  58. VueDraggable,
  59. Detail,
  60. MComponent,
  61. SelectInfo,
  62. },
  63. data() {
  64. return {
  65. form: this.$form.createForm(this),
  66. componentBaseList,
  67. componenHidetList,
  68. components: [],
  69. num: 1,
  70. detail: {},
  71. config: {
  72. layout: 2,
  73. },
  74. }
  75. },
  76. provide() {
  77. return {
  78. getFormList: () => {
  79. return this.components
  80. },
  81. }
  82. },
  83. watch: {
  84. components: {
  85. deep: true,
  86. handler(val) {
  87. this.num++
  88. },
  89. },
  90. },
  91. created() {},
  92. mounted() {
  93. // this.handleSelect({}, this.config)
  94. },
  95. methods: {
  96. base(record, params = {}) {
  97. this.components = record.components
  98. this.config = record.config
  99. this.num = record.num
  100. if (this.components.length == 0) {
  101. getCustomRelation(params).then((res) => {
  102. const datas = JSON.parse(res.data.json)
  103. const components = datas.forEach((item) => {
  104. const newVal = [...componentBaseList, ...componenHidetList].find(
  105. (component) => item.type === component.type
  106. )
  107. const component = {
  108. ...newVal,
  109. value: item.englishName,
  110. id: String(+new Date()),
  111. label: item.chineseName,
  112. isDelete: false,
  113. }
  114. console.log(component)
  115. this.components.push(component)
  116. })
  117. })
  118. }
  119. },
  120. onClone(element) {
  121. // 生成随机id
  122. const val = {
  123. ...JSON.parse(JSON.stringify(element)),
  124. value: `${element.value}${this.num}`,
  125. id: String(+new Date()),
  126. }
  127. this.handleSelect(val)
  128. return val
  129. },
  130. update(val) {
  131. console.log(val)
  132. },
  133. addForm(val) {
  134. val.forEach((item) => {
  135. this.components.push({
  136. id: item.bind,
  137. name: '单行文本',
  138. type: 'input',
  139. value: item.bind,
  140. dependentId: false,
  141. required: true,
  142. label: item.columnComment,
  143. attrs: {
  144. placeholder: '请输入',
  145. disabled: true,
  146. },
  147. })
  148. })
  149. },
  150. handleDelete(val) {
  151. this.components = this.components.filter((v) => v.id !== val.id)
  152. },
  153. handleSubmit() {
  154. const {
  155. form: { validateFieldsAndScroll },
  156. } = this
  157. this.confirmLoading = true
  158. validateFieldsAndScroll((errors, values) => {
  159. console.log(values)
  160. if (errors) {
  161. this.confirmLoading = false
  162. }
  163. })
  164. },
  165. handleSelect(item) {
  166. this.$refs.detail.base(item, this.config)
  167. },
  168. handleInfoSelect(item) {
  169. this.$refs.selectInfo.base(item)
  170. },
  171. handleInfoSelected(keys, rows, detail) {
  172. const {
  173. form: { setFieldsValue },
  174. } = this
  175. if (detail.attrs.selectType === 'radio') {
  176. const data = rows[0]
  177. const value = {}
  178. detail.attrs.connect.forEach((item) => {
  179. value[item.bind] = data[item.columnName]
  180. })
  181. this.$nextTick(() => {
  182. setFieldsValue(value)
  183. })
  184. } else {
  185. this.$nextTick(() => {
  186. setFieldsValue({
  187. [detail.attrs.connect[0].bind]: keys,
  188. })
  189. })
  190. }
  191. },
  192. },
  193. }
  194. </script>
  195. <style lang="less" scoped>
  196. .type {
  197. border: 1px solid #ccc;
  198. padding: 5px;
  199. margin: 5px;
  200. border-radius: 5px;
  201. font-size: 12px;
  202. }
  203. </style>