Skip to content

Commit 576f151

Browse files
committed
fix: container can't upload
1 parent 5644f0d commit 576f151

3 files changed

Lines changed: 47 additions & 51 deletions

File tree

src/components/views/ContainerManager.vue

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
:title="$t('message.newContainer')"
2727
:visible.sync="dialogVisible"
2828
width="50%"
29-
v-on:close="closeEdit"
30-
:before-close="handleClose">
29+
v-on:close="closeEdit">
3130
<el-form ref="form" :model="form" label-width="150px" class="genTable" label-position='left'>
3231
<el-form-item :label="$t('message.containerName')">
3332
<el-input v-model="form.containerName"></el-input>
@@ -59,6 +58,7 @@
5958
:file-list = "fileList"
6059
:on-success="onSuccess"
6160
:action="`${requestUrl}/container/jarUpload`"
61+
:headers="headersObj"
6262
multiple>
6363
<i class="el-icon-upload"></i>
6464
<div class="el-upload__text">Drag the file here, or <em>click on Upload</em></div>
@@ -79,6 +79,7 @@
7979

8080
<script>
8181
import baseUrl from '../../main';
82+
import {Message} from "element-ui";
8283
8384
let ws;
8485
export default {
@@ -104,11 +105,17 @@
104105
containerList:[],
105106
logs:[],
106107
requestUrl :"",
107-
fileList: []
108+
fileList: [],
109+
110+
headersObj: {
111+
Power_jwt: undefined,
112+
AppId: undefined
113+
}
108114
}
109115
},
110116
methods: {
111117
onSubmit() {
118+
const that = this
112119
// 接口参数
113120
let data = {
114121
appId:this.appId,
@@ -124,19 +131,18 @@
124131
data.sourceInfo = this.sourceInfo;
125132
data.sourceType = 'FatJar'
126133
}
127-
this.axios.post("container/save",data).then(()=>{
128-
let appId = window.localStorage.getItem("Power_appId");
129-
this.axios.get("/container/list?appId=" + appId).then(res => {
130-
this.$message.info(this.$t('message.success'));
131-
// 恢复默认表单
132-
this.dialogVisible = false;
133-
this.form.containerName = '';
134-
this.gitForm = {};
135-
this.sourceInfo = '';
136-
this.id = '';
137-
// 刷新容器表单
138-
this.containerList = res;
139-
});
134+
this.axios.post("container/save",data).then(res=>{
135+
console.log('container save result:' + JSON.stringify(res))
136+
137+
Message.success("SUCCESS");
138+
// 恢复默认表单
139+
that.dialogVisible = false;
140+
that.form.containerName = '';
141+
that.gitForm = {};
142+
that.sourceInfo = '';
143+
that.id = '';
144+
145+
that.listContainers()
140146
});
141147
},
142148
// 文件上传成功后 修改来源信息
@@ -145,7 +151,7 @@
145151
},
146152
deleteItem(item,index){
147153
let appId = window.localStorage.getItem("Power_appId");
148-
this.flyio.get("/container/delete?containerId="+ item.id+'&appId='+appId).then(res => {
154+
this.axios.get("/container/delete?containerId="+ item.id+'&appId='+appId).then(res => {
149155
console.log(res);
150156
this.containerList.splice(index,1);
151157
this.$message.info(this.$t('message.success'));
@@ -194,7 +200,7 @@
194200
},
195201
listOfItem(item){
196202
let appId = window.localStorage.getItem("Power_appId");
197-
this.flyio.get("/container/listDeployedWorker?containerId="+ item.id+'&appId='+appId).then(res => {
203+
this.axios.get("/container/listDeployedWorker?containerId="+ item.id+'&appId='+appId).then(res => {
198204
if(res.data.data){
199205
this.logs = res.data.data.split('\n');
200206
this.arrangeTitle = this.$t('message.deployedWorkerList');
@@ -215,18 +221,24 @@
215221
}else {
216222
this.requestUrl = baseUrl;
217223
}
218-
}
224+
},
225+
226+
listContainers() {
227+
let appId = window.localStorage.getItem("Power_appId");
228+
this.axios.get("/container/list?appId=" + appId).then(res => {
229+
console.log(res);
230+
if(res.data.success){
231+
this.containerList = res.data.data;
232+
}
233+
});
234+
}
219235
},
220236
mounted() {
221237
this.calculateRequestUrl();
238+
this.listContainers();
222239
223-
let appId = window.localStorage.getItem("Power_appId");
224-
this.flyio.get("/container/list?appId=" + appId).then(res => {
225-
console.log(res);
226-
if(res.data.success){
227-
this.containerList = res.data.data;
228-
}
229-
});
240+
this.headersObj.AppId = window.localStorage.getItem("Power_appId")
241+
this.headersObj.Power_jwt = window.localStorage.getItem("Power_jwt")
230242
}
231243
}
232244
</script>

src/components/views/ContainerTemplate.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
methods: {
4444
onSubmit() {
4545
console.log('submit!');
46-
this.flyio.post("/container/downloadContainerTemplate", this.form
46+
this.axios.post("/container/downloadContainerTemplate", this.form
4747
,{
4848
responseType:'blob'//服务器返回的数据类型
4949
}).then((res)=>{

src/main.js

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import './iconfont.css';
1010

1111
// axios 负责统一拦截处理 ResultDTO,fly 负责处理不需要拦截的请求
1212
import axios from 'axios';
13-
import flyio from 'flyio';
1413
import router from "./router";
1514
import store from "./store";
1615
import common from "./common";
@@ -27,10 +26,6 @@ Vue.prototype.common = common;
2726
Vue.prototype.axios = axios;
2827
axios.defaults.baseURL = baseURL;
2928
axios.defaults.timeout = timeout;
30-
/* ******* fly.io config ******* */
31-
Vue.prototype.flyio = flyio;
32-
flyio.config.baseURL = baseURL;
33-
flyio.config.timeout = timeout;
3429

3530
Vue.config.productionTip = false;
3631

@@ -41,32 +36,14 @@ new Vue({
4136
render: h => h(App),
4237
}).$mount('#app');
4338

44-
//请求发送拦截,没有 appId 要求重新 "登录"
39+
// 请求拦截,全局添加 JWT 和 APPID 信息
4540
axios.interceptors.request.use((request) => {
4641

4742
request.headers['Power_jwt'] = window.localStorage.getItem("Power_jwt");
4843
if (request.headers['AppId'] == null) {
4944
request.headers['AppId'] = window.localStorage.getItem("Power_appId");
5045
}
5146

52-
// let url = request.url;
53-
// let isListAppInfo = url.search("/appInfo/list") !== -1;
54-
// let isAppRegister = url.search("/appInfo/save") !== -1;
55-
// let isAssertAppInfo = url.search("/appInfo/assert") !== -1;
56-
//
57-
// if (isListAppInfo || isAppRegister || isAssertAppInfo) {
58-
// return request;
59-
// }
60-
61-
/*
62-
TODO: 先注释原来的全局 appId 登录拦截逻辑,后续考虑兼容性问题
63-
let appId = store.state.appInfo.id;
64-
if (appId === undefined || appId === null) {
65-
router.push("/");
66-
// remove no appId warn due to too much user report this is a bug...
67-
return Promise.reject();
68-
}
69-
*/
7047
return request;
7148

7249
}, function (error) {
@@ -84,6 +61,13 @@ axios.interceptors.response.use((response) => {
8461
return
8562
}
8663

64+
// 值示例 /user/query
65+
const req_url = response.config.url
66+
if (req_url.startsWith('/container')) {
67+
console.log("skip intercept container's request")
68+
return response
69+
}
70+
8771
if (response.data.success === true) {
8872
return response.data.data;
8973
}

0 commit comments

Comments
 (0)