3328350766
6 天以前 761eb03d6b3bebd0b197179564c84d89d3d12a0d
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<template>
  <div
    v-loading="loading || innerLoading"
    class="template-list-wrap"
  >
    <div
      v-if="hasCreate"
      class="template-item"
      @click="addNew"
    >
      <div
        class="iconfont-div"
      >
        <i class="iconfont el-icon-plus" />
      </div>
      <div
        class="name"
      >
        从空白新建
      </div>
    </div>
    <div
      v-for="template in templateList"
      :key="template.id"
      class="template-item template-choose-item"
    >
      <div
        class="thumbnail"
      >
        <el-image
          :ref="'img' + template.id"
          :src="template.thumbnail"
          :preview-src-list="[template.thumbnail]"
        />
 
        <span class="template-list-item-actions">
          <i
            class="el-icon-zoom-in"
            @click="preview(template.id)"
          />
          <i
            class="el-icon-edit-outline"
            @click="useIt(template.id)"
          />
        </span>
      </div>
      <div class="name">
        {{ template.name }}
      </div>
    </div>
    <el-empty
      v-if="!templateList.length && !hasCreate"
      description="暂无模板"
    />
  </div>
</template>
 
<script>
export default {
  name: 'TemplateList',
  model: {
    prop: 'value',
    event: 'change'
  },
  props: {
    loading: {
      type: Boolean,
      default: false
    },
    hasCreate: {
      type: Boolean,
      default: false
    },
    value: {
      type: String,
      default: ''
    },
    pageInfo: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      innerLoading: false,
      templateList: [],
      type: null, // 类型
      isInDesign: false // 是否在设计页面
    }
  },
  methods: {
    init (type, isInDesign) {
      this.isInDesign = isInDesign
      this.type = type
      this.getTemplateList(type)
    },
    // 得到模板列表
    getTemplateList (type) {
      this.type = type
      this.$dataRoomAxios.get('/visual/bigScreen/template/list', {
        type
      }).then((list) => {
        this.templateList = list
      })
    },
    // 从空白新建
    addNew () {
      this.$emit('addNew')
    },
    // 预览
    preview (id) {
      // 触发el-image的点击事件
      this.$refs['img' + id][0].showViewer = true
    },
    // 使用它作为模版
    useIt (id) {
      if (this.hasCreate) {
        this.$emit('useIt', id)
      } else {
        this.$confirm('使用该模板将会覆盖当前页面的所有内容,是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          customClass: 'bs-el-message-box'
        }).then(() => {
          const className = this.type === 'com.sxlinks.modules.system.dto.visual.DataRoomPageDTO'
          this.innerLoading = true
          this.$dataRoomAxios.post(`/bigScreen/${this.type}/design/get/template`, {
            pageTemplateId: id,
            name: this.pageInfo.name,
            code: this.pageInfo.code,
            id: this.pageInfo.id,
            className
          }).then(res => {
            this.$emit('replaceItByTemplate', res)
          }).finally(() => {
            this.innerLoading = false
          })
        })
      }
    }
  }
}
</script>
 
<style lang="scss" scoped>
.template-list-wrap {
   display: grid;
  // 不固定列
  grid-template-columns: repeat(auto-fill, 140px);
  grid-gap: 20px;
  justify-content: center;
 
  .template-item {
    cursor: pointer;
    margin-right: 20px;
 
    .iconfont-div {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 140px;
      width: 140px;
      border: 1px solid #e5e5e5;
      color: #999999;
 
      .iconfont {
        font-size: 40px;
      }
    }
 
    .thumbnail {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 140px;
      width: 140px;
      background: #f2f2f2;
      position: relative;
 
      .template-list-item-actions {
        position: absolute;
        width: 100%;
        height: 100%;
        left: 0;
        top: 0;
        cursor: default;
        text-align: center;
        color: #fff;
        opacity: 0;
        font-size: 20px;
        background-color: rgba(0,0,0,.5);
        transition: opacity .3s;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
 
        i {
          margin: 0 10px;
        }
      }
      &:hover {
        .template-list-item-actions {
          opacity: 1;
        }
      }
    }
 
    .thumbnail img {
      width: 100%;
    }
 
    .name {
      margin-top: 10px;
      text-align: center;
    }
  }
 
  // 移动上去显示遮罩层预览和使用
 
  .template-choose-item {
 
  }
}
 
</style>