Test1.vue 4.5 KB

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