schangxiang@126.com
2025-09-10 3d43ffa3152110b7823f9fa6320c08a6ae02358a
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
<template>
  <div :class="{active: selectWidget && selectWidget.key == element.key}" class="button-item" @click.stop="handleSelectWidget(index)">
    <div v-if="element.type=='button'" class="btn">
      <el-button :key="index" v-bind="element.options">{{ element.label }}</el-button>
    </div>
    <div v-else-if="element.type=='button-dropdown'" class="btn">
      <el-dropdown :key="index" v-bind="element.options">
        <el-button v-bind="element.options">
          {{ element.label }}
          <i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item v-for="(item, itemIndex) in element.options.options" :key="itemIndex">{{ item.label }}</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <div class="tool">
      <el-button circle plain type="danger" title="删除" size="mini" @click.stop="handleWidgetDelete(index)">
        <i class="el-icon-yrt-shanchu2"></i>
      </el-button>
      <el-button circle plain type="primary" title="复制" size="mini" @click.stop="handleWidgetClone(index)">
        <i class="el-icon-yrt-fuzhi4"></i>
      </el-button>
    </div>
  </div>
</template>
 
<script>
export default {
  components: {},
  props: {
    element: {
      type: Object,
      default: () => {
        return {};
      }
    },
    select: {
      type: Object,
      default: () => {
        return {};
      }
    },
    index: {
      type: Number,
      default: null
    },
    buttons: {
      type: Array,
      default: () => {
        return [];
      }
    },
    configType: {
      type: String,
      default: null
    }
  },
  data() {
    return {};
  },
  computed: {
    selectWidget: {
      get: function() {
        return this.select;
      },
      set: function(val) {
        this.$emit("update:select", val);
      }
    }
  },
  watch: {
    select(val) {
      this.selectWidget = val;
    }
  },
  methods: {
    handleSelectWidget(index) {
      this.selectWidget = this.buttons[index];
      this.$emit("update:configType", "WidgetConfig");
    },
    handleWidgetDelete(index) {
      if (this.buttons.length - 1 === index) {
        if (index === 0) {
          this.selectWidget = {};
        } else {
          this.selectWidget = this.buttons[index - 1];
        }
      } else {
        this.selectWidget = this.buttons[index + 1];
      }
 
      this.$nextTick(() => {
        this.buttons.splice(index, 1);
      });
    },
    handleWidgetClone(index) {
      const cloneData = {
        ...this.buttons[index],
        key: Date.parse(new Date()) + "_" + Math.ceil(Math.random() * 99999)
      };
 
      this.buttons.splice(index, 0, cloneData);
 
      this.$nextTick(() => {
        this.selectWidget = this.buttons[index + 1];
      });
    }
  }
};
</script>