田源
2025-03-05 f6b61a485501f326debe52d77ea65d87fb34b37f
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
<template>
    <el-dialog
      title="服务更新jar包导入"
      :visible.sync="dialogVisible"
      append-to-body
    >
      <Divider text="更新提示" left="30px"></Divider>
      <ul>
        <li>
          1.上传jar文件时请确定jar文件名称正确,打好的jar包,<span style="font-weight: bold;color: red;">请勿随便更改jar文件名和文件后缀名</span>。
        </li>
        <li>
          2.上传多个文件时请压缩成<span style="font-weight: bold;color: red;">.zip</span>再上传。
        </li>
        <li>
          3.上传成功之后会自动重启指定服务,并且该界面中会暂时无法查询到该服务信息,请稍等1~2分钟再查看验证该服务是否更新成功。
        </li>
      </ul>
      <Divider text="文件,选择文件后会自动上传" left="30px"></Divider>
      <el-upload
        ref="uploadFiles"
        action="/api/ubcs-deploy/deploy/importUpdateServiceJar"
        :on-success="onSuccess"
        :multiple="true"
        :on-error="onError"
        :headers="uploadHeaders"
        :show-file-list="false"
        :before-upload="beforeUpload"
        :on-change="uploadChange"
        :directory="true"
        :data="{'serverName':serverName}"
        name="files"
        class="upload-demo">
        <el-button size="small" type="primary" style="margin: 15px 10px 15px 35px" @click="handleAddFolder('file')">浏览文件</el-button>
        <!-- <el-button size="small" type="primary" @click="handleAddFolder('dir')">浏览文件夹</el-button> -->
      </el-upload>
      <template #footer>
        <el-button size="small" @click="dialogVisible = false">关闭</el-button>
      </template>
    </el-dialog>
  </template>
  
<script>
import {downloadErrorFile} from '@/api/template/templateAttr'
import {getToken} from "@/util/auth";
import func from "@/util/func";
export default {
  name: "uploadServiceJarDialog",
  props: {
      visible: {
        type: Boolean,
        default: false,
      },
      serverName: {
        type: String,
        default: false,
      },
  },
  data(){
      return{
      flga:true,
      pageLoading: null,
      downloadLoading: false,
      }
  },
  watch:{
      visible:{
        handler(newval,oldval){
            // console.log('newval',newval)
        }
      }
  },
  computed:{
      uploadHeaders() {
        return {
            "Blade-Auth": "bearer " + getToken(),
        };
      },
      dialogVisible: {
        get() {
            return this.visible;
        },
        set(val) {
            this.$emit("update:visible", val);
        },
      },
  },
  methods:{
      //文件上传前
      async beforeUpload(file) {
        // console.log(file);
        // console.log(this.serviceName);
        this.pageLoading = this.$loading({
            lock: true,
            text: "文件上传中",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
        });
        return true;
      },
      // 文件上传成功
      onSuccess(resbonse){
        if (Object.keys(resbonse.data).length === 0) {
            this.$message.success( "更新包导入成功!");
            this.dialogVisible = false;
            return;
        }
        if (resbonse.data.fileOid) {
            const fileName = resbonse.data.filePath.split("/").pop();
            this.$message.error("请下载错误信息文件进行查看!");
            downloadErrorFile({ uuid: resbonse.data.fileOid }).then((res) => {
            func.downloadFileByBlobHandler(res);
            });
        }
      },
      //文件上传失败
      onError(res){
        this.pageLoading.close();
      },
      //文件状态改变
      uploadChange(file){
        if (file.status === "success" || file.status === "error") {
            this.pageLoading.close();
        }
      },
      // 点击文件夹路径上传按钮
      // handleAddFolder (type) {
      //   if(type==='file'){
      //     this.$nextTick(() => {
      //       this.$refs.uploadFiles.$children[0].$refs.input.webkitdirectory = false;
      //     })
      //   }else{
      //     this.$nextTick(() => {
      //       this.$refs.uploadFiles.$children[0].$refs.input.webkitdirectory = true;
      //     })
      //   }
      // },
 
  }
}
</script>
  
<style scoped lang="scss">
ul {
  color: rgb(188, 188, 188);
  margin: 20px 0 20px 0;
  padding: 0 0 0 30px;
  list-style: none;
  li {
    margin-bottom: 5px;
    font-size: 13px;
  }
}
</style>