111
jihongshun
8 天以前 0c741cdda7ef9935a20d3090dfea97e1ce8ae754
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
<template>
  <el-row class="bar">
    <el-row class="topTab">
      <el-col :span="12" :class="currentTab === 1 ? 'focusTab':''">
        <div @click="currentTab = 0">组件</div>
      </el-col>
      <el-col :span="12" :class="currentTab === 0 ? 'focusTab':''">
        <div @click="currentTab = 1">图层</div>
      </el-col>
    </el-row>
    <div style="height: 45px;"></div>
    <div v-show="currentTab === 0" v-for="group in options" :key="group.name">
      <div style="line-height: 45px;cursor: pointer;box-shadow: 0 1px 2px #2B3340;" @click="group.opened = !group.opened">
        <div style="display: inline-block;text-indent: 1em;width: 170px;">{{group.name}}</div>
        <div style="display: inline-block;">
          <i :class="group.opened ? 'el-icon-arrow-down':'el-icon-arrow-right'"></i>
        </div>
      </div>
      <el-row :gutter="2" v-show="group.opened">
        <el-col :span="12" v-for="(item,index) in group.children" :key="item.name+index">
          <div draggable="true" :config="JSON.stringify(item)" @dragstart="dragStart"
               style="background-color: #3F4B5F;height: 70px;text-align: center;margin-top: 2px;">
            <div style="line-height: 40px;">
              <embed v-if="item.icon" style="width: 20px;" :src="require('@/assets/icon/'+item.icon+'.svg')" type="image/svg+xml" />
              <i v-else style="font-size: 20px;" class="el-icon-question"></i>
            </div>
            <div style="font-size: 13px">{{ item.name }}</div>
          </div>
        </el-col>
      </el-row>
    </div>
    <div v-show="currentTab === 1">
      <div v-show="selectedComponents.length === 0" style="text-align: center;line-height: 50px;">
        无图层
      </div>
      <el-row v-for="(item,index) in selectedComponents" :key="item.keyId" class="selectedItem"
              :style="{background: currentCptIndex === index ? '#3F4B5F':'#353f50'}">
        <el-col :span="4" style="text-align: center"><i :class="item.icon"/></el-col>
        <el-col :span="15" @click.native="showConfigBar($event,item,index)">{{item.cptTitle}}</el-col>
        <el-col :span="5" style="text-align: center">
          <i class="el-icon-copy-document" @click="copyCpt(item)"/>
          <i style="margin-left: 4px;" class="el-icon-delete" @click="delCpt(item,index)"/>
        </el-col>
      </el-row>
    </div>
  </el-row>
</template>
 
<script>
import options from '@/components/options'
 
export default {
  name: "componentBar",
  data() {
    return {
      options,
      cptGroupKeys:[],
      currentTab:0//0组件,1图层
    }
  },
  props:{
    selectedComponents:Array,
    currentCptIndex:Number
  },
  methods: {
    dragStart(e) {
      let copyDom = e.currentTarget.cloneNode(true);
      this.$emit('dragStart', copyDom);
    },
    showConfigBar(e,item,index){
      this.$emit('showConfigBar', e, item, index);
    },
    copyCpt(item){
      this.$emit('copyCpt', item);
    },
    delCpt(item,index){
      this.$emit('delCpt', item, index);
    }
  },
}
</script>
 
<style scoped>
.bar{position:relative;width:100%;height:100%;background: #353f50;color: #fff;overflow-x:hidden;overflow-y: auto}
.el-collapse-item__*{background: #353f50}
.topTab{width:200px;height: 45px;text-align: center;line-height: 45px;cursor: pointer;
  position: fixed;z-index: 7;background: #353f50;box-shadow: 0 1px 3px #2b3340;}
.focusTab{background: #3F4B5F}
.selectedItem{line-height: 45px;cursor: pointer;box-shadow: 0 1px 3px #2b3340 inset;}
</style>