widgetTableItem.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import _ from 'lodash'
  2. import { EventBus } from '../util/event-bus.js'
  3. import { addClass, removeClass } from '../util'
  4. export const widgetTableItemMixin = {
  5. props: ['element', 'select', 'index', 'data', 'platform', 'formKey'],
  6. emits: ['select-change', 'update:select'],
  7. data () {
  8. return {
  9. selectWidget: this.select || {}
  10. }
  11. },
  12. methods: {
  13. handleMouseover (e) {
  14. addClass(this.$refs['widgetTableItem'], 'is-hover')
  15. },
  16. handleMouseout (e) {
  17. removeClass(this.$refs['widgetTableItem'], 'is-hover')
  18. },
  19. handleSelectWidget (index) {
  20. this.$emit('update:select', this.data[index])
  21. },
  22. handleWidgetDelete (index) {
  23. if (this.data.length == 1) {
  24. this.$emit('select-change', -1)
  25. } else {
  26. if (this.data.length - 1 == index) {
  27. this.$emit('select-change', index - 1)
  28. } else {
  29. this.$emit('select-change', index)
  30. }
  31. }
  32. this.$nextTick(() => {
  33. this.data.splice(index, 1)
  34. setTimeout(() => {
  35. EventBus.$emit('on-history-add-' + this.formKey)
  36. }, 20)
  37. })
  38. },
  39. handleWidgetClone (index) {
  40. const key = Math.random().toString(36).slice(-8)
  41. let cloneData = {
  42. ..._.cloneDeep(this.data[index]),
  43. key,
  44. model: this.data[index].type + '_' + key,
  45. }
  46. this.data.splice(index + 1, 0, cloneData)
  47. this.$nextTick(() => {
  48. this.$emit('update:select', this.data[index + 1])
  49. this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
  50. })
  51. },
  52. },
  53. watch: {
  54. select (val) {
  55. this.selectWidget = val
  56. },
  57. selectWidget (val) {
  58. this.$emit('update:select', val)
  59. }
  60. }
  61. }