登陆重构

main
wangqiujuan0808 2024-04-09 09:08:15 +08:00
parent 239939373a
commit 2c5212574e
23 changed files with 10967 additions and 8568 deletions

View File

@ -1,142 +1,142 @@
import {
getRequest,
postJsonRequest,
deleteRequest,
putRequest,
} from "@/utils/axios";
const infoApi = {
//
getSys(params) {
return getRequest("/info", params);
},
//
getNet(params) {
return getRequest("/net", params);
},
saveNet(params) {
return putRequest("/net", params);
},
reboot() {
return postJsonRequest("/reboot",);
},
//
getTc(params) {
return getRequest('/tc', params)
},
//
getSupport(params) {
return getRequest('/tc/support', params)
},
//
getFree(params) {
return getRequest('/com/free', params)
},
//
getTxSupport(params) {
return getRequest('/tx/support', params)
},
// import {
// getRequest,
// postJsonRequest,
// deleteRequest,
// putRequest,
// } from "@/utils/axios";
// const infoApi = {
// //
// getSys(params) {
// return getRequest("/info", params);
// },
// //
// getNet(params) {
// return getRequest("/net", params);
// },
// saveNet(params) {
// return putRequest("/net", params);
// },
// reboot() {
// return postJsonRequest("/reboot",);
// },
// //
// getTc(params) {
// return getRequest('/tc', params)
// },
// //
// getSupport(params) {
// return getRequest('/tc/support', params)
// },
// //
// getFree(params) {
// return getRequest('/com/free', params)
// },
// //
// getTxSupport(params) {
// return getRequest('/tx/support', params)
// },
// api/com
getCom(params) {
return getRequest('/com', params)
},
// // api/com
// getCom(params) {
// return getRequest('/com', params)
// },
saveTx(params) {
return postJsonRequest("/tx", params);
},
editTx(params) {
return putRequest("/tx", params);
},
//
stopTc(params) {
return putRequest("/tc", params);
},
//
delTc(params) {
return deleteRequest("/tc", params);
},
//
getMb(params) {
return getRequest('/tx/mb/list', params)
},
//
addMb(params) {
return postJsonRequest('/tx/mb', params)
},
//
editMb(params) {
return putRequest('/tx/mb', params)
},
//
delMb(params) {
return deleteRequest('/tx/mb', params)
},
//
addP(params) {
return putRequest('/tx/mb', params)
},
// saveTx(params) {
// return postJsonRequest("/tx", params);
// },
// editTx(params) {
// return putRequest("/tx", params);
// },
// //
// stopTc(params) {
// return putRequest("/tc", params);
// },
// //
// delTc(params) {
// return deleteRequest("/tc", params);
// },
// //
// getMb(params) {
// return getRequest('/tx/mb/list', params)
// },
// //
// addMb(params) {
// return postJsonRequest('/tx/mb', params)
// },
// //
// editMb(params) {
// return putRequest('/tx/mb', params)
// },
// //
// delMb(params) {
// return deleteRequest('/tx/mb', params)
// },
// //
// addP(params) {
// return putRequest('/tx/mb', params)
// },
//
getP(params) {
return postJsonRequest('/tx/mb/info', params)
},
//
getSet(params) {
return postJsonRequest('/tx/info', params)
},
//
addSet(params) {
return putRequest('/tx/device', params)
},
//
getTx(params) {
return getRequest('/tx/list', params)
},
//
saveTx(params) {
return postJsonRequest("/tx", params);
},
// //
// getP(params) {
// return postJsonRequest('/tx/mb/info', params)
// },
// //
// getSet(params) {
// return postJsonRequest('/tx/info', params)
// },
// //
// addSet(params) {
// return putRequest('/tx/device', params)
// },
// //
// getTx(params) {
// return getRequest('/tx/list', params)
// },
// //
// saveTx(params) {
// return postJsonRequest("/tx", params);
// },
// ,
changeStatus(params) {
return postJsonRequest(`/tx/${params.url}/${params.name}`, params);
},
// // ,
// changeStatus(params) {
// return postJsonRequest(`/tx/${params.url}/${params.name}`, params);
// },
//
delTx(params) {
return deleteRequest(`/tx`, params);
},
//
getSc(params) {
return getRequest('/sb/list', params)
},
//
getQuDong(params) {
return getRequest('/sb/support', params)
},
//
saveTx(params) {
return postJsonRequest("/sb", params);
},
//
updateTx(params) {
return putRequest('/sb', params);
},
//
stopSc(params) {
return putRequest("/sc", params);
},
//
delSc(params) {
return deleteRequest("/sb", params);
},
//
getRules(params) {
return getRequest('/rule', params);
},
//
postRules(params) {
return postJsonRequest('/rule', params)
},
};
export default infoApi;
// //
// delTx(params) {
// return deleteRequest(`/tx`, params);
// },
// //
// getSc(params) {
// return getRequest('/sb/list', params)
// },
// //
// getQuDong(params) {
// return getRequest('/sb/support', params)
// },
// //
// saveTx(params) {
// return postJsonRequest("/sb", params);
// },
// //
// updateTx(params) {
// return putRequest('/sb', params);
// },
// //
// stopSc(params) {
// return putRequest("/sc", params);
// },
// //
// delSc(params) {
// return deleteRequest("/sb", params);
// },
// //
// getRules(params) {
// return getRequest('/rule', params);
// },
// //
// postRules(params) {
// return postJsonRequest('/rule', params)
// },
// };
// export default infoApi;

View File

@ -1,22 +1,16 @@
import {
getRequest,
postJsonRequest,
deleteRequest,
putRequest
postPBRequest,
} from '@/utils/axios';
const myApi = {
//
loginStatus() {
return postPBRequest('/login', null, 1000);
},
login(params = {}) {
return postJsonRequest('/login', params);
return postPBRequest('/login', params, 1001);
},
//
editPass(params) {
return putRequest("/user", params);
},
// 退
logOut() {
return postJsonRequest('/logout');
logout() {
return postPBRequest('/login', null, 1002);
}
}
export default myApi;

View File

@ -51,7 +51,7 @@ import myApi from "@/api/myApi.js";
import { ElMessage, ElMessageBox } from "element-plus";
import { useStore } from "vuex";
import md5 from 'js-md5'
import { passwd, response } from '../proto/data/pd'
import { response } from '../proto/data/pd'
export default {
props: ["dialogVisible"],

View File

@ -46,13 +46,10 @@
<script>
import { onMounted, reactive, toRefs } from "vue";
import { useRouter } from "vue-router";
import { localRemove, pathMap } from "@/utils";
import infoApi from "@/api/infoApi.js";
import { pathMap } from "@/utils";
import EditPass from "@/components/EditPass.vue";
import { ElMessage } from "element-plus";
import { useStore } from "vuex";
import myApi from "@/api/myApi.js";
import { response } from '../proto/data/pd'
export default {
name: "Header",
components: {
@ -94,25 +91,26 @@ export default {
};
const reStart = async () => {
const res = await infoApi.reboot();
if (res.code == 0) {
ElMessage.success(res.msg || "请求成功");
} else {
ElMessage.error(res.msg || "请求失败");
}
// const res = await infoApi.reboot();
// if (res.code == 0) {
// ElMessage.success(res.msg || "");
// } else {
// ElMessage.error(res.msg || "");
// }
};
const logout = async () => {
const res = await myApi.logOut();
const res = await myApi.logout();
console.log("666",res);
//
const ret = response.decode(new Uint8Array(res));
if (ret.code == 0) {
//
console.log(new TextDecoder().decode(ret.data));
localRemove("token");
window.location.reload();
} else {
console.log(ret);
}
// const ret = response.decode(new Uint8Array(res));
// if (ret.code == 0) {
// //
// console.log(new TextDecoder().decode(ret.data));
// localRemove("token");
// window.location.reload();
// } else {
// console.log(ret);
// }
};
const editPass = () => {

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
syntax = "proto3";
option go_package = "data/";
option go_package = "pb/";
message info{
Basicinfo basicinfo = 1;
@ -12,8 +12,9 @@ message info{
//
message Basicinfo{
string model = 1; //
string sn = 2; // SN
string first_time = 3; //
string id = 2; // id
string sn = 3; // SN
string factory = 4; //
}
//

8
src/proto/reponse.proto Normal file
View File

@ -0,0 +1,8 @@
syntax = "proto3";
option go_package = "pb/";
message response{
uint32 code = 1;
bytes data = 2;
string message = 3;
}

View File

@ -1,22 +1,14 @@
syntax = "proto3";
option go_package = "data/";
option go_package = "pb/";
message user{
string name = 1;
string password = 2;
fixed64 timestamp = 3;
string new_password = 3;
}
message token{
string name = 1;
string token = 2;
fixed64 timestamp = 3;
fixed64 expiration_time = 4;
}
message passwd{
string name = 1;
string old_password = 2;
string new_password = 3;
string new_password2 = 4;
int64 expires_time = 2;
string value = 3;
}

10542
src/proto2/data/pd.js Normal file

File diff suppressed because it is too large Load Diff

55
src/proto2/info.proto Normal file
View File

@ -0,0 +1,55 @@
syntax = "proto3";
option go_package = "pb/";
message info{
Basicinfo basicinfo = 1;
Hostinfo hostinfo = 2;
Meminfo meminfo = 3;
repeated Diskinfo diskinfo = 4;
repeated Netinfo netinfo = 5;
}
//
message Basicinfo{
string model = 1; //
string id = 2; // id
string sn = 3; // SN
string factory = 4; //
}
//
message Hostinfo{
int32 cpu = 1; // cpu
string uptime = 2; //
string boottime = 3; //
}
//
message Meminfo{
double total = 1; //
double available = 2; //
double used = 3; //
double used_percent = 4; //
double free = 5; //
double buffers = 6; //
double cached = 7; //
}
//
message Diskinfo{
string name = 1; //
string path = 2; //
double total = 3; //
double free = 4; //
double used = 5; //
double used_percent = 6; //
}
//
message Netinfo{
string name = 1; //
uint64 bytesSent = 2; // number of bytes sent
uint64 bytesRecv = 3; // number of bytes received
uint64 packetsSent = 4; // number of packets sent
uint64 packetsRecv = 5; // number of packets received
}

14
src/proto2/user.proto Normal file
View File

@ -0,0 +1,14 @@
syntax = "proto3";
option go_package = "pb/";
message user{
string name = 1;
string password = 2;
string new_password = 3;
}
message token{
string name = 1;
int64 expires_time = 2;
string value = 3;
}

View File

@ -1,96 +1,69 @@
import axios from "axios";
import md5 from "js-md5";
import { Base64 } from "js-base64";
import { ElMessage } from "element-plus";
import {
ElMessage
} from "element-plus";
import router from "@/router/index";
import { localGet } from "./index";
import {
localSet,
localGet,
localRemove
} from "./index";
import config from "~/config";
import { token,response } from '../proto/data/pd';
import { localRemove, pathMap } from "@/utils";
import {
response
} from '../proto/data/pd';
axios.defaults.baseURL = config[import.meta.env.MODE].baseUrl;
axios.defaults.baseURL = config[
import.meta.env.MODE].baseUrl;
axios.defaults.withCredentials = true;
// headers
axios.defaults.headers["X-Requested-With"] = "XMLHttpRequest";
axios.defaults.headers = getNeedToken();
function getNeedToken() {
const ret_token = localGet("token");
if (ret_token && ret_token.timestamp) {
ret_token.timestamp = new Date().getTime();
const tokenInfo = token.encode(ret_token).finish();
// stringheaderheaderkey"cdcm"
const cdcm = tokenInfo.slice(0, tokenInfo.length).toString()
return { cdcm };
} else {
localRemove("token");
axios.interceptors.request.use(
(req) => {
req.headers["cdcm"] = localGet("token");
return req;
}
);
}
//
axios.interceptors.response.use(
(res) => {
const token = res.headers["token"]
// token
if (typeof (token) != "undefined") {
localSet("token", token);
}
const ret = response.decode(new Uint8Array(res.data));
// token
const ret = response.decode(new Uint8Array(res));
if(ret.code ===40100 || ret.code ===40101) {
if (ret.code === 2003) {
localRemove("token");
ElMessage.closeAll();
ElMessage.error(ret.msg || "Token过期请重新登录");
router.push({ path: "/login" });
ElMessage.error(ret.msg + "[" + new TextDecoder().decode(res.data) + "]" || "Token异常,请重新登录");
router.push({
path: "/login"
});
return Promise.reject(ret);
}
return res.data;
return ret
},
(error) => {
ElMessage.closeAll();
ElMessage.error(error || "401 Unauthorized");
router.push({ path: "/login" });
ElMessage.error(error);
router.push({
path: "/login"
});
return Promise.reject(error);
}
);
// post
export function postJsonRequest(url, params) {
export function postPBRequest(url, params, actionNum) {
return axios({
method: "post",
url: url,
data: params,
responseType: 'arraybuffer',
headers: {
"Content-Type": "application/json",
"action": actionNum,
},
});
}
// get
export function getRequest(url, params) {
return axios({
method: "get",
responseType: 'arraybuffer',
params: {
...params,
},
url: url,
});
}
export function deleteRequest(url, params) {
return axios({
method: "delete",
data: params,
responseType: 'arraybuffer',
url: url,
});
}
export const putRequest = (url, params) => {
return axios({
method: "put",
data: params,
responseType: 'arraybuffer',
url: url,
headers: {
"Content-Type": "application/json",
},
});
};

View File

@ -70,7 +70,7 @@
<script>
import { onMounted, reactive, ref, toRefs, nextTick } from "vue";
import infoApi from "@/api/infoApi.js";
// import infoApi from "@/api/infoApi.js";
import { ElMessage } from "element-plus";
import * as echarts from "echarts";
import { user, token, response, info } from '../proto/data/pd';
@ -92,19 +92,19 @@ export default {
getSys();
});
const getSys = async () => {
const res = await infoApi.getSys();
//
const ret = response.decode(new Uint8Array(res));
console.log(ret)
// const res = await infoApi.getSys();
// //
// const ret = response.decode(new Uint8Array(res));
// console.log(ret)
if (ret.code == 0) {
//
state.deviceData = info.decode(ret.data);
console.log(44, state.deviceData);
nextTick(() => {
drawEchart();
});
}
// if (ret.code == 0) {
// //
// state.deviceData = info.decode(ret.data);
// console.log(44, state.deviceData);
// nextTick(() => {
// drawEchart();
// });
// }
};

View File

@ -76,27 +76,18 @@ export default {
const userInfo = user.encode({
name: state.ruleForm.username,
password: md5(state.ruleForm.password).toUpperCase(),
timestamp: new Date().getTime()
// timestamp: new Date().getTime()
}).finish()
// 2.
const send_userInfo = userInfo.slice(0, userInfo.length);
const res = await myApi.login(send_userInfo);
//
const ret = response.decode(new Uint8Array(res));
console.log(2, ret);
if (ret.code == 0) {
//
const ret_token = token.decode(ret.data);
// token
localSet('token', ret_token);
console.log(222, localGet("token"));
//
// console.log("===",res);
console.log("===",new TextDecoder().decode(res.data));
if (res.code == 0){
const res2 = await myApi.loginStatus();
console.log("===",new TextDecoder().decode(res2.data));
window.location.href = '/';
} else {
console.log(ret);
}
} else {
console.log("error submit!!");

View File

@ -24,10 +24,10 @@ export default ({ mode }) => defineConfig({
server: {
proxy: {
'/api': {
target: 'http://cdcm_test_api.shikicc.com:58909',
// target: 'http://cdcm_test_api.shikicc.com:58909',
// target: 'http://frp.shikicc.com:58951',
// target: 'http://10.10.14.123',
// target: 'https://cdcmapi.shikicc.com',
target: 'https://cdcm_api.shikicc.com',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '/api')
}