登陆重构

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
syntax = "proto3"; syntax = "proto3";
option go_package = "data/"; option go_package = "pb/";
message info{ message info{
Basicinfo basicinfo = 1; Basicinfo basicinfo = 1;
@ -12,8 +12,9 @@ message info{
// //
message Basicinfo{ message Basicinfo{
string model = 1; // string model = 1; //
string sn = 2; // SN string id = 2; // id
string first_time = 3; // 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"; syntax = "proto3";
option go_package = "data/"; option go_package = "pb/";
message user{ message user{
string name = 1; string name = 1;
string password = 2; string password = 2;
fixed64 timestamp = 3; string new_password = 3;
} }
message token{ message token{
string name = 1; string name = 1;
string token = 2; int64 expires_time = 2;
fixed64 timestamp = 3; string value = 3;
fixed64 expiration_time = 4;
}
message passwd{
string name = 1;
string old_password = 2;
string new_password = 3;
string new_password2 = 4;
} }

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 axios from "axios";
import md5 from "js-md5"; import {
import { Base64 } from "js-base64"; ElMessage
import { ElMessage } from "element-plus"; } from "element-plus";
import router from "@/router/index"; import router from "@/router/index";
import { localGet } from "./index"; import {
localSet,
localGet,
localRemove
} from "./index";
import config from "~/config"; import config from "~/config";
import { token,response } from '../proto/data/pd'; import {
import { localRemove, pathMap } from "@/utils"; 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; axios.defaults.withCredentials = true;
// headers // headers
axios.defaults.headers["X-Requested-With"] = "XMLHttpRequest"; axios.defaults.headers["X-Requested-With"] = "XMLHttpRequest";
axios.defaults.headers = getNeedToken(); axios.interceptors.request.use(
(req) => {
req.headers["cdcm"] = localGet("token");
function getNeedToken() { return req;
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.response.use( axios.interceptors.response.use(
(res) => { (res) => {
const token = res.headers["token"]
// token
if (typeof (token) != "undefined") {
localSet("token", token);
}
const ret = response.decode(new Uint8Array(res.data));
// token // token
const ret = response.decode(new Uint8Array(res)); if (ret.code === 2003) {
if(ret.code ===40100 || ret.code ===40101) {
localRemove("token"); localRemove("token");
ElMessage.closeAll(); ElMessage.closeAll();
ElMessage.error(ret.msg || "Token过期请重新登录"); ElMessage.error(ret.msg + "[" + new TextDecoder().decode(res.data) + "]" || "Token异常,请重新登录");
router.push({ path: "/login" }); router.push({
path: "/login"
});
return Promise.reject(ret); return Promise.reject(ret);
} }
return res.data; return ret
}, },
(error) => { (error) => {
ElMessage.closeAll(); ElMessage.closeAll();
ElMessage.error(error || "401 Unauthorized"); ElMessage.error(error);
router.push({ path: "/login" }); router.push({
path: "/login"
});
return Promise.reject(error); return Promise.reject(error);
} }
); );
// post // post
export function postJsonRequest(url, params) { export function postPBRequest(url, params, actionNum) {
return axios({ return axios({
method: "post", method: "post",
url: url, url: url,
data: params, data: params,
responseType: 'arraybuffer', responseType: 'arraybuffer',
headers: { 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> <script>
import { onMounted, reactive, ref, toRefs, nextTick } from "vue"; 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 { ElMessage } from "element-plus";
import * as echarts from "echarts"; import * as echarts from "echarts";
import { user, token, response, info } from '../proto/data/pd'; import { user, token, response, info } from '../proto/data/pd';
@ -92,19 +92,19 @@ export default {
getSys(); getSys();
}); });
const getSys = async () => { const getSys = async () => {
const res = await infoApi.getSys(); // const res = await infoApi.getSys();
// // //
const ret = response.decode(new Uint8Array(res)); // const ret = response.decode(new Uint8Array(res));
console.log(ret) // console.log(ret)
if (ret.code == 0) { // if (ret.code == 0) {
// // //
state.deviceData = info.decode(ret.data); // state.deviceData = info.decode(ret.data);
console.log(44, state.deviceData); // console.log(44, state.deviceData);
nextTick(() => { // nextTick(() => {
drawEchart(); // drawEchart();
}); // });
} // }
}; };

View File

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

View File

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