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
<template>
  <div class="basicSet">
    <p class="basicTip">小贴士:标题栏图片建议尺寸为 750*200 像素,背景图片宽度建议为 750 像素,长度有足够空间</p>
    <div>
      <el-form-item label="标题栏图片:" :required="true">
        <custom-upload-img @handle-success="handleTitleSuccess" @handle-remove="handleTitleRemove"
                           :fileList="fileTitleList">
        </custom-upload-img>
      </el-form-item>
      <el-form-item label="标题栏底色:" :required="true">
        <el-color-picker v-model="titleColor" @change="handleChange"></el-color-picker>
      </el-form-item>
    </div>
    <div>
      <el-form-item label="背景图片:" :required="true">
        <custom-upload-img :limitNumber="28" @handle-success="handleBgSuccess"
                           @handle-remove="handleBgRemove" :fileList="fileBgList"
                           @handle-file-data="handleFileData" :multiple="true" :draggable="true">
        </custom-upload-img>
      </el-form-item>
    </div>
  </div>
</template>
 
<script>
import { mapMutations, mapState } from 'vuex'
export default {
  props: ['form'],
  data () {
    return {
      fileTitleList: [],
      titleColor: null,
      fileBgList: []
    }
  },
  watch: {
    diyListFirst: {
      handler (newValue, oldvalue) {
        this.fileTitleList = newValue.titleImg ? [{ url: newValue.titleImg, id: newValue.id }] : []
        this.titleColor = newValue.titleColor
        newValue.bgImg.forEach(item => {
          this.fileBgList.push(item)
        })
      },
      immediate: true
    }
  },
  computed: {
    ...mapState(['diyList']),
    diyListFirst () {
      return this.diyList[0]
    }
  },
  methods: {
    ...mapMutations(['updateDiylistById']),
    // 数组更新时重新获取数据
    handleFileData (arr) {
      this.updateDiylistById({ id: 'basicSet', update: { bgImg: arr } })
      this.fileBgList = arr
    },
    /**
     * 获取上传成功的图片
     */
    handleTitleSuccess (data) {
      this.updateDiylistById({ id: 'basicSet', update: { titleImg: data.url } })
      this.fileTitleList.push({
        url: data.url
      })
    },
    // 移除文件数组
    removeFile (arr, data) {
      return arr.filter(v => {
        return v.id !== data.id
      })
    },
    /**
     * 移除图片
     */
    handleTitleRemove (data) {
      this.updateDiylistById({ id: 'basicSet', update: { titleImg: '' } })
      this.fileTitleList = []
    },
    /**
     * 获取上传成功的图片
     */
    handleBgSuccess (data) {
      const arr = JSON.parse(JSON.stringify(this.diyList[0].bgImg))
      arr.push({
        id: data.id,
        url: data.url
      })
      this.updateDiylistById({ id: 'basicSet', update: { bgImg: arr } })
      this.fileBgList.push({
        url: data.url,
        id: data.id
      })
    },
    /**
     * 移除图片
     */
    handleBgRemove (data) {
      const arr = JSON.parse(JSON.stringify(this.diyList[0].bgImg))
      this.updateDiylistById({
        id: 'basicSet',
        update: {
          bgImg: this.removeFile(arr, data)
        }
      })
      this.fileBgList = this.removeFile(this.fileBgList, data)
    },
    handleChange (val) {
      this.updateDiylistById({ id: 'basicSet', update: { titleColor: val } })
    }
  }
}
</script>
 
<style lang='scss'>
.basicSet {
}
</style>