widgetInline.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import _ from 'lodash'
  2. import { CloneLayout } from '../util/layout-clone.js'
  3. import { EventBus } from '../util/event-bus.js'
  4. import { addClass, removeClass } from '../util'
  5. export const widgetInlineMixin = {
  6. props: ['element', 'select', 'index', 'data', 'platform', 'formKey', 'subform'],
  7. emits: ['select-change', 'update:select'],
  8. inject: ['setDragging', 'getDragging'],
  9. data () {
  10. return {
  11. selectWidget: this.select || {}
  12. }
  13. },
  14. methods: {
  15. handleMouseover (e) {
  16. !this.getDragging() && addClass(this.$refs['widgetInline'], 'is-hover')
  17. },
  18. handleMouseout (e) {
  19. removeClass(this.$refs['widgetInline'], 'is-hover')
  20. },
  21. handleSelectWidget (index) {
  22. this.selectWidget = this.data.list[index]
  23. },
  24. handlePut (a, b, c) {
  25. if (c.className.split(' ').indexOf('widget-col') >=0 ||
  26. c.className.split(' ').indexOf('widget-table') >= 0 ||
  27. c.className.split(' ').indexOf('widget-tab') >= 0 ||
  28. c.className.split(' ').indexOf('widget-inline') >= 0 ||
  29. c.className.split(' ').indexOf('widget-report') >=0 ||
  30. c.className.split(' ').indexOf('widget-dialog') >= 0 ||
  31. c.className.split(' ').indexOf('widget-card') >= 0 ||
  32. c.className.split(' ').indexOf('no-put') >= 0 ||
  33. c.children[0].className.split(' ').indexOf('no-put') >= 0) {
  34. return false
  35. }
  36. return true
  37. },
  38. handleWidgetInlineAdd ($event, table) {
  39. const newIndex = $event.newIndex
  40. const key = Math.random().toString(36).slice(-8)
  41. table.list[newIndex] = _.cloneDeep(table.list[newIndex])
  42. table.list[newIndex] = {
  43. ...table.list[newIndex],
  44. options: {
  45. ...table.list[newIndex].options,
  46. remoteFunc: table.list[newIndex].options.remoteFunc || 'func_'+key,
  47. remoteOption: table.list[newIndex].options.remoteOption || 'option_'+key,
  48. subform: this.subform ? true : false,
  49. tableColumn: false
  50. },
  51. key: table.list[newIndex].key ? table.list[newIndex].key : key,
  52. model: table.list[newIndex].model ? table.list[newIndex].model : table.list[newIndex].type + '_' + key,
  53. rules: table.list[newIndex].rules ? [...table.list[newIndex].rules] : []
  54. }
  55. this.$nextTick(() => {
  56. this.selectWidget = table.list[newIndex]
  57. EventBus.$emit('on-history-add-' + this.formKey)
  58. })
  59. },
  60. handleInlineClone (index) {
  61. let cloneData = _.cloneDeep(this.data.list[index])
  62. this.data.list.splice(index + 1, 0, CloneLayout(cloneData))
  63. this.$nextTick(() => {
  64. this.selectWidget = this.data.list[index + 1]
  65. this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
  66. })
  67. },
  68. handleWidgetDelete (index) {
  69. if (this.data.list.length == 1) {
  70. this.$emit('select-change', -1)
  71. } else {
  72. if (this.data.list.length - 1 == index) {
  73. this.$emit('select-change', index - 1)
  74. } else {
  75. this.$emit('select-change', index)
  76. }
  77. }
  78. this.data.list.splice(index, 1)
  79. setTimeout(() => {
  80. EventBus.$emit('on-history-add-' + this.formKey)
  81. }, 20)
  82. },
  83. handleWidgetInlineUpdate () {
  84. this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
  85. },
  86. handleSelectChange (index, item) {
  87. setTimeout(() => {
  88. index >=0 ? (this.selectWidget = item.list[index]) : (this.selectWidget = this.data.list[this.index])
  89. })
  90. }
  91. },
  92. watch: {
  93. select (val) {
  94. this.selectWidget = val
  95. },
  96. selectWidget (val) {
  97. this.$emit('update:select', val)
  98. }
  99. }
  100. }