widgetFormItem.js 1.7 KB

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