fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
     <div :class="['menuTabs',isOpen?'isOpen':'']">
        <span
          :class="['tabName',activeId === item.id?'activeTab':'']"
          v-for="(item, index) in diyList"
          :key="item.id"
          @click="handleClick(item,index)"
        >
         <img class="tabImg" :src="srcUrlArr[index]">
         <span v-show="item.title">{{index ? `${index}-${item.title}` : item.title}}</span>
         <span v-show="!item.title">{{index>=0 && useSceneMap[item.type]? `${index}-${useSceneMap[item.type]}` : `${index}-热区`}}</span>
        </span>
        <span class="icon-btn">
          <i v-if="!isOpen" @click="tabUpDown(1)" class="el-icon-arrow-down"></i>
          <i v-else @click="tabUpDown(2)" class="el-icon-arrow-up"></i>
        </span>
       <el-dialog :visible.sync="dialogVisible" :title="title" width="400px" :close-on-click-modal="false" :modal-append-to-body="false" v-if="dialogVisible">
          <el-form ref="form" size="mini" @submit.native.prevent :model="form">
            <el-form-item prop="title" :rules="titleRules">
              <el-input v-model="form.title" @keyup.enter.native="submit" placeholder="请输入标题名称"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button size="mini" @click="submit" type="primary">确定</el-button>
            <el-button size="mini" @click="dialogVisible = false">取消</el-button>
          </div>
       </el-dialog>
     </div>
</template>
 
<script>
import { mapState } from 'vuex'
export default {
  props: ['useSceneMap', 'useSceneArray'],
  data () {
    return {
      tabIndex: 1,
      isOpen: false,
      clickTimes: 0,
      dialogVisible: false,
      title: null,
      form: { title: null },
      titleRules: [
        { required: true, message: '请输入标题名称', trigger: 'change' },
        { max: 6, message: '标题名称最多只能输入 6 个字' }
      ],
      clickData: null
    }
  },
  computed: {
    ...mapState(['diyList', 'mousedown']),
    hotAreaTabs () {
      return this.diyList
    },
    activeId () {
      this.$emit('get-tab', this.mousedown.activeId)
      return this.mousedown.activeId
    },
    srcUrlArr () {
      const srcUrlArr = []
      this.diyList.forEach(item => {
        this.useSceneArray.forEach(i => {
          if (i.value === item.type) {
            srcUrlArr.push(require('../../../../assets/img/' + i.src))
          }
        })
        if (item.type === 'basicSet') {
          srcUrlArr.push(require('../../../../assets/img/basicSet.png'))
        }
        if (!item.type) {
          srcUrlArr.push('')
        }
      })
      return srcUrlArr
    }
  },
  created () {
    const arr = this.hotAreaTabs.filter((v) => {
      return v.id === this.activeId
    })
    arr.length && this.$emit('get-tab', arr[0].type)
  },
  methods: {
    /**
     * 修改diy热区名字
     */
    submit () {
      this.$refs.form.validate().then(res => {
        if (this.diyList.find(v => {
          return this.clickData.id !== v.id && v.title === this.form.title
        })) {
          this.$message({
            type: 'info',
            message: `${this.form.title}已存在`
          })
          return
        }
        this.$set(this.clickData, 'title', this.form.title)
        this.dialogVisible = false
      })
    },
    handleClick (val, index) {
      const _this = this
      _this.clickTimes++
      if (_this.clickTimes === 2) {
        _this.clickTimes = 0
        if (val.type !== 'basicSet') {
          _this.dialogVisible = true
          _this.title = val.title ? `修改 ${index}-${val.title}` : `修改 ${index}-${this.useSceneMap[val.type]}`
          _this.clickData = val
          _this.form.title = val.title ? val.title : this.useSceneMap[val.type]
        }
      }
      setTimeout(function () {
        if (_this.clickTimes === 1) {
          // 单击事件
          _this.clickTimes = 0
          val.isActive = true
          _this.mousedown.activeId = val.id
          _this.$emit('get-tab', val.id)
        }
      }, 300)
      // document.body.scrollTop = document.getElementById('main-container').scrollTop = 0
    },
    /**
     * 表格收起展开
     */
    tabUpDown (val) {
      this.isOpen = val === 1
    }
  }
}
</script>
 
<style scoped lang="scss">
.menuTabs {
  // background-color: #f5f7fa;
  border-bottom: 4px solid #fafafa;
  // box-shadow:2px 2px 5px rgba(0,0,0,0.2);
  height: 82px;
  overflow: hidden;
  position: relative;
  .tabName{
    height: 40px;
    display: inline-block;
    padding: 20px 30px;
    line-height: 40px;
    border: 1px solid transparent;
    color: #333333;
    cursor: pointer;
    font-weight: 400;
    .tabImg{
      display: block;
      margin: 0 auto;
    }
  }
  .activeTab{
    color: #d70012;
    // background-color: #fff;
    // border-left-color: #dcdfe6;
    // border-right-color: #dcdfe6;
  }
  .icon-btn{
    position: absolute;
    top: 30%;
    right: 10px;
    i{
      cursor: pointer;
    }
  }
}
.isOpen{
  height: auto;
}
</style>