WidgetInline.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div
  3. class="widget-inline widget-view"
  4. :class="{
  5. active: selectWidget.key && selectWidget.key == element.key,
  6. 'is_hidden': element.options.hidden
  7. }"
  8. @click.stop="handleSelectWidget(index)"
  9. :size="element.options.size"
  10. @mouseover.stop="handleMouseover"
  11. @mouseout="handleMouseout"
  12. ref="widgetInline"
  13. >
  14. <div class="widget-inline-content">
  15. <draggable
  16. v-model="element.list"
  17. v-bind="{group:{name: 'people', put: handlePut}, ghostClass: 'ghost',animation: 200, handle: '.drag-widget'}"
  18. :no-transition-on-drag="true"
  19. @add="handleWidgetInlineAdd($event, element)"
  20. @update="handleWidgetInlineUpdate"
  21. @start="setDragging(true)"
  22. @end="setDragging(false)"
  23. class="widget-inline-list"
  24. :class="{
  25. [element.options && element.options.customClass]: element.options.customClass ? true : false
  26. }"
  27. :style="{
  28. display: element.options.flex ? 'flex' : 'block',
  29. 'flex-direction': 'row',
  30. 'flex-wrap': 'wrap',
  31. 'justify-content': element.options.flexJustify || 'normal',
  32. 'align-items': element.options.flexAlign || 'normal'
  33. }"
  34. >
  35. <template v-for="(item, index) in element.list" v-if="item && item.key">
  36. <widget-form-item
  37. :key="item.key"
  38. :element="item"
  39. :select.sync="selectWidget"
  40. :index="index" :data="element"
  41. @select-change="handleSelectChange($event, element)"
  42. :form-key="formKey"
  43. :style="{'margin-right': element.options.spaceSize+'px'}"
  44. >
  45. </widget-form-item>
  46. </template>
  47. </draggable>
  48. </div>
  49. <div class="widget-view-action widget-inline-action" v-if="selectWidget.key == element.key">
  50. <i class="fm-iconfont icon-icon_clone" @click.stop="handleInlineClone(index)" :title="$t('fm.tooltip.clone')"></i>
  51. <i class="fm-iconfont icon-trash" @click.stop="handleWidgetDelete(index)" :title="$t('fm.tooltip.trash')"></i>
  52. </div>
  53. <div class="widget-view-drag widget-inline-drag" v-if="selectWidget.key == element.key">
  54. <i class="fm-iconfont icon-drag drag-widget"></i>
  55. </div>
  56. <div class="widget-view-model " :style="{'color': element.options.dataBind ? '' : '#666'}">
  57. <span>{{element.model}}</span>
  58. </div>
  59. <div class="widget-view-type ">
  60. <span>{{element.type ? this.$t('fm.components.fields.' + element.type) : ''}}</span>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. import WidgetFormItem from './WidgetFormItem'
  66. import Draggable from 'vuedraggable'
  67. import _ from 'lodash'
  68. import { CloneLayout } from '../util/layout-clone.js'
  69. import { EventBus } from '../util/event-bus.js'
  70. import { addClass, removeClass } from '../util'
  71. export default {
  72. name: 'widget-inline',
  73. components: {
  74. Draggable,
  75. WidgetFormItem
  76. },
  77. props: ['element', 'select', 'index', 'data', 'platform', 'formKey', 'subform'],
  78. inject: ['setDragging', 'getDragging'],
  79. data () {
  80. return {
  81. selectWidget: this.select || {}
  82. }
  83. },
  84. methods: {
  85. handleMouseover (e) {
  86. !this.getDragging() && addClass(this.$refs['widgetInline'], 'is-hover')
  87. },
  88. handleMouseout (e) {
  89. removeClass(this.$refs['widgetInline'], 'is-hover')
  90. },
  91. handleSelectWidget (index) {
  92. this.selectWidget = this.data.list[index]
  93. },
  94. handlePut (a, b, c) {
  95. if (c.className.split(' ').indexOf('widget-col') >=0 ||
  96. c.className.split(' ').indexOf('widget-table') >= 0 ||
  97. c.className.split(' ').indexOf('widget-tab') >= 0 ||
  98. c.className.split(' ').indexOf('widget-inline') >= 0 ||
  99. c.className.split(' ').indexOf('widget-report') >=0 ||
  100. c.className.split(' ').indexOf('widget-dialog') >= 0 ||
  101. c.className.split(' ').indexOf('widget-card') >= 0 ||
  102. c.className.split(' ').indexOf('no-put') >= 0 ||
  103. c.children[0].className.split(' ').indexOf('no-put') >= 0) {
  104. return false
  105. }
  106. return true
  107. },
  108. handleWidgetInlineAdd ($event, table) {
  109. const newIndex = $event.newIndex
  110. const key = Math.random().toString(36).slice(-8)
  111. this.$set(table.list, newIndex, _.cloneDeep(table.list[newIndex]))
  112. this.$set(table.list, newIndex, {
  113. ...table.list[newIndex],
  114. options: {
  115. ...table.list[newIndex].options,
  116. remoteFunc: table.list[newIndex].options.remoteFunc || 'func_'+key,
  117. remoteOption: table.list[newIndex].options.remoteOption || 'option_'+key,
  118. subform: this.subform ? true : false,
  119. tableColumn: false
  120. },
  121. key: table.list[newIndex].key ? table.list[newIndex].key : key,
  122. model: table.list[newIndex].model ? table.list[newIndex].model : table.list[newIndex].type + '_' + key,
  123. rules: table.list[newIndex].rules ? [...table.list[newIndex].rules] : []
  124. })
  125. this.selectWidget = table.list[newIndex]
  126. this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
  127. },
  128. handleInlineClone (index) {
  129. let cloneData = _.cloneDeep(this.data.list[index])
  130. this.data.list.splice(index + 1, 0, CloneLayout(cloneData))
  131. this.$nextTick(() => {
  132. this.selectWidget = this.data.list[index + 1]
  133. this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
  134. })
  135. },
  136. handleWidgetDelete (index) {
  137. if (this.data.list.length == 1) {
  138. this.$emit('select-change', -1)
  139. } else {
  140. if (this.data.list.length - 1 == index) {
  141. this.$emit('select-change', index - 1)
  142. } else {
  143. this.$emit('select-change', index)
  144. }
  145. }
  146. this.data.list.splice(index, 1)
  147. setTimeout(() => {
  148. EventBus.$emit('on-history-add-' + this.formKey)
  149. }, 20)
  150. },
  151. handleWidgetInlineUpdate () {
  152. this.$nextTick(() => { EventBus.$emit('on-history-add-' + this.formKey) })
  153. },
  154. handleSelectChange (index, item) {
  155. setTimeout(() => {
  156. index >=0 ? (this.selectWidget = item.list[index]) : (this.selectWidget = this.data.list[this.index])
  157. })
  158. }
  159. },
  160. watch: {
  161. select (val) {
  162. this.selectWidget = val
  163. },
  164. selectWidget: {
  165. deep: false,
  166. handler (val) {
  167. this.$emit('update:select', val)
  168. }
  169. },
  170. }
  171. }
  172. </script>