widgetColItem.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import _ from 'lodash'
  2. import { CloneLayout } from '../util/layout-clone.js'
  3. import { EventBus } from '../util/event-bus.js'
  4. import { generateKeyToTD, generateKeyToTH, generateKeyToCol, fixDraggbleList, addClass, removeClass } from '../util'
  5. export const widgetColItemMixin = {
  6. props: ['element', 'select', 'index', 'data', 'platform', 'formKey', 'subform'],
  7. emits: ['select-change', 'update:select'],
  8. inject: ['getDragging', 'setDragging'],
  9. data () {
  10. return {
  11. selectWidget: this.select || {},
  12. selectIndex: -1
  13. }
  14. },
  15. methods: {
  16. handleMouseover (e) {
  17. !this.getDragging() && addClass(this.$refs['widgetCol'], 'is-hover')
  18. },
  19. handleMouseout (e) {
  20. removeClass(this.$refs['widgetCol'], 'is-hover')
  21. },
  22. handleMouseoverCol (i) {
  23. !this.getDragging() && addClass(this.$refs['widgetColItem'][i].$el, 'is-hover')
  24. },
  25. handleMouseoutCol (i) {
  26. removeClass(this.$refs['widgetColItem'][i].$el, 'is-hover')
  27. },
  28. handlePut (a, b, c) {
  29. if (c.className.split(' ').indexOf('widget-dialog') >=0 || c.className.split(' ').indexOf('dialog-put') >= 0 || c.children[0].className.split(' ').indexOf('dialog-put') >= 0) {
  30. return false
  31. }
  32. return true
  33. },
  34. getColSpan (options) {
  35. if (this.platform == 'pc') {
  36. return options && options.md
  37. }
  38. if (this.platform == 'pad') {
  39. return options && options.sm
  40. }
  41. if (this.platform == 'mobile') {
  42. return options && options.xs
  43. }
  44. },
  45. handleSelectWidget (index) {
  46. this.$emit('update:select', this.data.list[index])
  47. },
  48. handleSelectItemWidget (i) {
  49. this.$emit('update:select', this.data.list[this.index].columns[i])
  50. this.selectIndex = i
  51. },
  52. handleWidgetDelete (index) {
  53. if (this.data.list.length == 1) {
  54. this.$emit('select-change', -1)
  55. } else {
  56. if (this.data.list.length - 1 == index) {
  57. this.$emit('select-change', index - 1)
  58. } else {
  59. this.$emit('select-change', index)
  60. }
  61. }
  62. this.data.list.splice(index, 1)
  63. setTimeout(() => {
  64. EventBus.$emit('on-history-add-' + this.formKey)
  65. }, 20)
  66. },
  67. handleColItemDelete (index, i) {
  68. this.data.list[index].columns.splice(i, 1)
  69. if (i == 0) {
  70. this.$emit('update:select', this.data.list[index].columns[0])
  71. } else {
  72. this.$emit('update:select', this.data.list[index].columns[i - 1])
  73. }
  74. setTimeout(() => {
  75. EventBus.$emit('on-history-add-' + this.formKey)
  76. }, 20)
  77. },
  78. handleAddCol (index) {
  79. this.data.list[index].columns.push({
  80. type: 'col',
  81. options: {
  82. span: 12,
  83. offset: 0,
  84. push: 0,
  85. pull: 0,
  86. xs: 24,
  87. sm: 12,
  88. md: 12,
  89. lg: 12,
  90. xl: 12,
  91. customClass: ''
  92. },
  93. list: [],
  94. key: Math.random().toString(36).slice(-8)
  95. })
  96. this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
  97. },
  98. handleColClone (index) {
  99. let cloneData = _.cloneDeep(this.data.list[index])
  100. this.data.list.splice(index + 1, 0, CloneLayout(cloneData))
  101. this.$nextTick(() => {
  102. this.data.list[index + 1]
  103. this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
  104. })
  105. },
  106. handleColItemClone (index, i) {
  107. let cloneData = _.cloneDeep(this.data.list[index].columns[i])
  108. this.data.list[index].columns.splice(i + 1, 0, CloneLayout(cloneData))
  109. this.$nextTick(() => {
  110. this.$emit('update:select', this.data.list[index].columns[i + 1])
  111. this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
  112. })
  113. },
  114. handleWidgetColUpdate (evt) {
  115. this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
  116. },
  117. handleWidgetColAdd ($event, row, colIndex) {
  118. const newIndex = $event.newIndex
  119. fixDraggbleList(row.columns[colIndex].list, newIndex)
  120. row.columns[colIndex].list[newIndex] = _.cloneDeep(row.columns[colIndex].list[newIndex])
  121. const key = Math.random().toString(36).slice(-8)
  122. row.columns[colIndex].list[newIndex] = {
  123. ...row.columns[colIndex].list[newIndex],
  124. options: {
  125. ...row.columns[colIndex].list[newIndex].options,
  126. remoteFunc: row.columns[colIndex].list[newIndex].options.remoteFunc || 'func_'+key,
  127. remoteOption: row.columns[colIndex].list[newIndex].options.remoteOption || 'option_'+key,
  128. tableColumn: false,
  129. subform: this.subform ? true : false
  130. },
  131. novalid: {
  132. ...row.columns[colIndex].list[newIndex].novalid,
  133. },
  134. key: row.columns[colIndex].list[newIndex].key ? row.columns[colIndex].list[newIndex].key : key,
  135. model: row.columns[colIndex].list[newIndex].model ? row.columns[colIndex].list[newIndex].model : row.columns[colIndex].list[newIndex].type + '_' + key,
  136. rules: row.columns[colIndex].list[newIndex].rules ? [...row.columns[colIndex].list[newIndex].rules] : []
  137. }
  138. if (row.columns[colIndex].list[newIndex].type == 'report') {
  139. row.columns[colIndex].list[newIndex].rows = generateKeyToTD(row.columns[colIndex].list[newIndex].rows)
  140. row.columns[colIndex].list[newIndex].headerRow = generateKeyToTH(row.columns[colIndex].list[newIndex].headerRow)
  141. }
  142. if (row.columns[colIndex].list[newIndex].type == 'grid') {
  143. row.columns[colIndex].list[newIndex].columns = generateKeyToCol(row.columns[colIndex].list[newIndex].columns)
  144. }
  145. setTimeout(() => {
  146. this.selectWidget = row.columns[colIndex].list[newIndex]
  147. EventBus.$emit('on-history-add-' + this.formKey)
  148. }, 50)
  149. },
  150. handleSelectChange (index, item) {
  151. setTimeout(() => {
  152. index >=0 ? (
  153. this.$emit('update:select', item.list[index])
  154. ) : (
  155. this.$emit('update:select', {})
  156. )
  157. })
  158. }
  159. },
  160. watch: {
  161. select (val) {
  162. this.selectWidget = val
  163. },
  164. selectWidget (val) {
  165. this.$emit('update:select', val)
  166. }
  167. }
  168. }