Ben Lin
2024-06-18 ebbd788fbb2c0b45d4473798efc57eec8ba74a25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<template>
  <div :class="prefixCls">
    <draggable
      tag="ul"
      :model-value="list"
      v-bind="{
        group: { name: 'form-draggable', pull: 'clone', put: false },
        sort: false,
        clone: cloneItem,
        animation: 180,
        ghostClass: 'moving',
      }"
      item-key="type"
      @start="handleStart($event, list)"
      @add="handleAdd"
    >
      <template #item="{ element, index }">
        <li
          class="bs-box text-ellipsis"
          @dragstart="$emit('add-attrs', list, index)"
          @click="$emit('handle-list-push', element)"
        >
          <!-- <svg v-if="element.icon.indexOf('icon-') > -1" class="icon" aria-hidden="true">
            <use :xlink:href="`#${element.icon}`" />
          </svg> -->
          <Icon :icon="element.icon" />
          {{ element.label }}</li
        ></template
      >
    </draggable>
  </div>
</template>
<script lang="ts">
  import { defineComponent, reactive, PropType } from 'vue';
  import { IVFormComponent } from '../../../typings/v-form-component';
  import draggable from 'vuedraggable';
  import Icon from '@/components/Icon/Icon.vue';
  import { useDesign } from '@/hooks/web/useDesign';
 
  export default defineComponent({
    name: 'CollapseItem',
    components: { draggable, Icon },
    props: {
      list: {
        type: [Array] as PropType<IVFormComponent[]>,
        default: () => [],
      },
      handleListPush: {
        type: Function,
        default: null,
      },
    },
    setup(props, { emit }) {
      const { prefixCls } = useDesign('form-design-collapse-item');
 
      const state = reactive({});
      const handleStart = (e: any, list1: IVFormComponent[]) => {
        emit('start', list1[e.oldIndex].component);
      };
      const handleAdd = (e: any) => {
        console.log(e);
      };
      // https://github.com/SortableJS/vue.draggable.next
      // https://github.com/SortableJS/vue.draggable.next/blob/master/example/components/custom-clone.vue
      const cloneItem = (one) => {
        return props.handleListPush(one);
      };
      return { prefixCls, state, handleStart, handleAdd, cloneItem };
    },
  });
</script>
 
<style lang="less" scoped>
  @prefix-cls: ~'@{namespace}-form-design-collapse-item';
 
  @import url('../styles/variable.less');
 
  .@{prefix-cls} {
    ul {
      display: flex;
      flex-wrap: wrap;
      margin-bottom: 0;
      padding: 5px;
      list-style: none;
      // background: #efefef;
 
      li {
        width: calc(50% - 6px);
        height: 36px;
        margin: 2.7px;
        padding: 8px 12px;
        transition: all 0.3s;
        border: 1px solid @border-color;
        border-radius: 3px;
        line-height: 20px;
        cursor: move;
 
        &:hover {
          position: relative;
          border: 1px solid @primary-color;
          // z-index: 1;
          box-shadow: 0 2px 6px @primary-color;
          color: @primary-color;
        }
      }
    }
 
    svg {
      display: inline !important;
    }
  }
</style>