ZZJ
2022-06-01 f3bf27d9bc7c8c6484be4f37edcc57df5490ecbe
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<template>
  <div class="sys-pkg right-main">
    <div class="top-title">
      <p>系统安装包管理</p>
    </div>
    <div class="control-bar">
      <div class="line-one">
        <div class="screening" @click="addPkg">
          <!-- <label></label> -->
          <!-- <i class="el-icon-circle-plus-outline" ></i> -->
          <span class="add-btn">系统安装包</span>
        </div>
       
      </div>
    </div>
    <div class="table-area">
      <el-table
        id="multipleTable"
        ref="multipleTable"
        tooltip-effect="dark"
        :data="dataList"
        :fit="true"
        :default-sort="{ prop: 'createTime', order: 'descending' }"
        v-loading="loading"
        element-loading-text="上传中"
        element-loading-spinner="el-icon-loading"
      >
        <el-table-column label="序号" width="68">
          <template slot-scope="scope">{{ scope.$index + 1 + (page - 1) * size }}</template>
        </el-table-column>
        <el-table-column label="系统安装包名称" min-width="100px">
          <template slot-scope="scope">
            <span>{{ scope.row.version }}</span>
          </template>
        </el-table-column>
        <el-table-column label="基础安装包" min-width="200px" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.$index != dataList.length - 1">{{ scope.row.intro }}</span>
            <el-input
              type="textarea"
              size="small"
              :rows="2"
              v-if="isAdding && scope.$index == dataList.length - 1"
              placeholder=""
              v-model="addBody.intro"
            >
            </el-input>
          </template>
        </el-table-column>
        <el-table-column prop="upload_time" label="版本类型" min-width="150px" sortable></el-table-column>
 
        <el-table-column prop="devName" label="创建时间" show-overflow-tooltip></el-table-column>
        <el-table-column label="文件大小" min-width="250">
          <template slot-scope="scope">
            <div class="pkg-wrap" v-if="scope.row.fileName || scope.row.local_filename">
              <div class="pkg-show">
                <span>{{ scope.row.local_filename || scope.row.fileName }}</span>
              </div>
              <i
                v-if="scope.$index !== dataList.length - 1"
                class="el-icon-download"
                @click="downloadPkg(scope.row)"
              ></i>
            </div>
 
            <el-upload
              style="float: left; margin-right: 10px"
              action
              :disabled="scope.$index == dataList.length - 1 && !addBody.version && !addBody.intro"
              v-if="scope.row.isEditting && !scope.row.local_filename"
              :http-request="uploadPkg"
              :show-file-list="false"
            >
              <div
                class="up-btn"
                @click="checkUpload(scope.$index)"
                v-if="scope.row.isEditting && !scope.row.local_filename"
              >
                {{ "上传系统安装包" }}
              </div>
            </el-upload>
 
            <el-button
              style="float: left"
              v-if="scope.$index !== dataList.length - 1 && scope.row.isEditting"
              type="primary"
              @click="dataList[scope.$index].isEditting = false"
              plain
              >取消</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="安装包信息" min-width="250">
          <template slot-scope="scope">
            <div class="pkg-wrap" v-if="scope.row.fileName || scope.row.local_filename">
              <div class="pkg-show">
                <span>{{ scope.row.local_filename || scope.row.fileName }}</span>
                <!-- <span
                  class="icon iconfont"
                  style="cursor: pointer"
                  @click="reUpload(scope.$index)"
                  >&#xe61a;</span
                > -->
              </div>
              <i
                v-if="scope.$index !== dataList.length - 1"
                class="el-icon-download"
                @click="downloadPkg(scope.row)"
              ></i>
            </div>
 
            <el-upload
              style="float: left; margin-right: 10px"
              action
              :disabled="scope.$index == dataList.length - 1 && !addBody.version && !addBody.intro"
              v-if="scope.row.isEditting && !scope.row.local_filename"
              :http-request="uploadPkg"
              :show-file-list="false"
            >
              <!-- scope.row.isEditting ? "重新上传" :  -->
              <div
                class="up-btn"
                @click="checkUpload(scope.$index)"
                v-if="scope.row.isEditting && !scope.row.local_filename"
              >
                {{ "上传系统安装包" }}
              </div>
            </el-upload>
 
            <el-button
              style="float: left"
              v-if="scope.$index !== dataList.length - 1 && scope.row.isEditting"
              type="primary"
              @click="dataList[scope.$index].isEditting = false"
              plain
              >取消</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="250">
          <template slot-scope="scope">
            <!-- v-if="
                scope.$index != dataList.length - 1 && !scope.row.isEditting
              " -->
            <span class="icon iconfont del-icon" @click="deletePkg(scope.row.path)">&#xe64f;</span>
            <!-- v-if="scope.row.isEditting && scope.$index == dataList.length - 1" -->
            <span class="icon iconfont cursor-pointer" @click="downloadPkg(scope.$index)">{{ "\ue63f" }}</span>
            
          </template>
        </el-table-column>
      </el-table>
      <div>
        <el-pagination
          @current-change="refresh"
          @size-change="handleSizeChange"
          :current-page="page"
          :page-size="size"
          layout="total, sizes, prev, pager, next, jumper"
          :page-sizes="[5, 10, 15, 20, 25]"
          :total="total"
        ></el-pagination>
      </div>
    </div>
 
  </div>
</template>
 
<script>
import {
  getSysPakages,
  downloadSysPkg,
  uploadSysPkg,
  delSysPkg
} from "../api/product"
export default {
  data() {
    return {
      page: 1,
      addBody: {
        version: "",
        intro: ""
      },
      // addRule: {
      //   stopHours: "",
      //   runHours: "",
      //   recordKeep: "",
      //   cannel: "",
      //   camera: "",
      //   trial_year: ""
      // },
      loading: false,
      isAdding: false,
      // dialogVisible: false,
      // errText: "生成产品密钥失败,请求码格式不正确。",
      size: 10,
      // codeText: "",
      // radio3: "1 年",
      // orderInfo: {
      //   id: "",
      //   chanelNum: 0,
      //   authNum: "",
      //   serviceTime: "",
      //   deviceNum: 0,
      //   activeNum: 0
      // },
      filename: "",
      total: 0,
      dataList: [],
      arch: "amd64",
      uploadIndex: null
    }
  },
  mounted() {
    this.fetchPkgList()
  },
  methods: {
    
    checkUpload(i) {
      if (i === this.dataList.length - 1 && !this.addBody.version && !this.addBody.intro) {
        this.$message.warning("请先填写版本号和版本描述")
      } else {
        this.uploadIndex = i
      }
    },
    reUpload(index) {
      this.$set(this.dataList[index], "isEditting", true)
    },
  
    uploadPkg(params) {
      this.filename = ""
      let param = new FormData()
      param.append("archive", params.file)
      param.append("arch", this.arch)
      param.append("version", this.addBody.version)
      param.append("intro", this.addBody.intro)
      this.loading = true
      let that = this
      uploadSysPkg(param)
        .then((res) => {
          that.loading = false
          that.$notify.success("上传成功")
          that.$set(that.dataList[that.uploadIndex], "local_filename", params.file.name)
          that.$set(that.dataList[that.uploadIndex], "path", res.info.path)
        })
        .catch((err) => {
          this.loading = false
          if (err && err.status == 401) {
            return
          }
          this.$notify.error("上传的安装包不符合要求")
        })
    },
    fetchPkgList() {
      getSysPakages({ page: this.page, size: this.size }).then((res) => {
        this.dataList = res.data.list
        this.dataList = [
          {
            sysName: "SmartAIOS 正式版",
            baseName: "X86-稳定版-1.0.0",
            version: "内测版",
            createTime: "2019-11-7 17:37:34",
            large: "5.44GB",
            info: "实时监控、统计查询、摄像机配置、数据栈管理"
          }
        ]
        this.total = res.data.total
        this.dataList.forEach((x) => {
          this.$set(x, "isEditting", false)
          this.$set(x, "local_filename", "")
        })
        // this.dataList.push({});
      })
    },
    addPkg() {
      this.isAdding = true
      this.$set(this.dataList[this.dataList.length - 1], "isEditting", true)
    },
    downloadPkg({ path, fileName }) {
      this.$confirm("确定下载该安装包吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true
      }).then(() => {
        downloadSysPkg({ filename: path })
          .then((res) => {
            const blob = new Blob([res], { type: "application/zip" })
            const url = window.URL.createObjectURL(blob)
            const link = document.createElement("a") // 创建a标签
            link.href = url
            link.download = fileName // 设置下载的文件名
            document.body.appendChild(link)
            link.click() //执行下载
            document.body.removeChild(link) //释放标签
          })
          .catch((err) => {
            console.log(err)
          })
      })
    },
    handleSizeChange(size) {
      this.size = size
    },
    refresh(page) {
      this.page = page
    },
    deletePkg(path) {
      this.$confirm("确定删除该安装包吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true
      }).then(() => {
        delSysPkg({ path })
          .then((res) => {
            this.$notify.success("删除成功")
            this.fetchPkgList()
          })
          .catch((err) => {
            if (err && err.status == 401) {
              return
            }
            this.$notify.error("删除失败")
          })
      })
    }
  }
}
</script>
 
<style lang="scss">
.right-main .control-bar .line-one {
  display: flex;
  align-items: center;
  min-height: 40px;
}
.right-main .control-bar .right-fixed {
  top: 16px;
}
.screening {
  font-size: 16px;
  cursor: pointer;
  // color: rgba(72, 118, 209, 1);
  // .el-icon-circle-plus-outline {
  //   font-size: 16px;
  //   margin-right: 3px;
  // }
}
.dial-bar {
  font-size: 15px;
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  .label-name {
    font-size: 15px;
    font-weight: 600;
    width: 120px;
    // background-color: antiquewhite;
  }
}
.pkg-wrap {
  display: flex;
  align-items: center;
  .el-icon-download {
    font-size: 22px;
    // font-weight: 600;
    color: rgba(119, 152, 255, 1);
    cursor: pointer;
  }
}
.pkg-show {
  background: #f2f2f2;
  width: 70%;
  padding: 5px 15px;
  border-radius: 5px;
  margin-right: 10px;
  display: flex;
  justify-content: space-between;
}
.del-icon {
  color: #ea1e24;
  font-size: 19px !important;
  // font-weight: 600;
  cursor: pointer;
  line-height: 23px;
  height: 23px;
}
.up-btn {
  background-color: #ea1e24;
  color: #f6f6f6;
  padding: 5px 10px;
}
.sys-pkg {
  .el-dialog__headerbtn .el-dialog__close {
    color: darkgray;
  }
}
</style>