From 0ce2087152c8f0bcc78d9f79d4843eba5824de7f Mon Sep 17 00:00:00 2001 From: hengji2023 Date: Sun, 15 Jan 2023 18:18:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=AF=86=E7=A0=81=E5=92=8C=E4=B8=AA=E4=BA=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UI2.0/package.json | 1 + UI2.0/src/js/login.js | 5 +- UI2.0/src/js/personal.js | 79 ++++++++++++++++++++++++++++++- UI2.0/src/js/userlayout.js | 3 ++ UI2.0/src/js/utils/utils.js | 6 +++ UI2.0/src/layouts/UserLayout.vue | 2 +- UI2.0/src/pages/Control-panel.vue | 4 +- UI2.0/src/pages/Personal.vue | 24 +++++++--- UI2.0/src/store/index.js | 15 +++--- UI2.0/src/store/user/userInfo.js | 37 +++++++++++++++ 10 files changed, 156 insertions(+), 20 deletions(-) create mode 100644 UI2.0/src/store/user/userInfo.js diff --git a/UI2.0/package.json b/UI2.0/package.json index 2dbf6c2..ecbf641 100644 --- a/UI2.0/package.json +++ b/UI2.0/package.json @@ -21,6 +21,7 @@ "vue": "^3.0.0", "vue-router": "^4.0.0", "vuex": "^4.0.1", + "vuex-persistedstate": "^4.1.0", "xterm": "^4.19.0" }, "devDependencies": { diff --git a/UI2.0/src/js/login.js b/UI2.0/src/js/login.js index 13ed9f6..601660e 100644 --- a/UI2.0/src/js/login.js +++ b/UI2.0/src/js/login.js @@ -23,7 +23,10 @@ export default defineComponent({ .then(res => { res = JSON.parse(res) if (res.login) { - this.$store.commit("changeUserName", res.user_name) + this.$store.commit("setUserInfo", { + name: res.user_name, + userId: res.user_id, + }) this.$router.push({ path: "/user", }); diff --git a/UI2.0/src/js/personal.js b/UI2.0/src/js/personal.js index 612d7c2..a5ecbef 100644 --- a/UI2.0/src/js/personal.js +++ b/UI2.0/src/js/personal.js @@ -1,7 +1,23 @@ import { defineComponent } from "vue"; +import axios from "./utils/AxiosConfig"; +import base64Encode from './utils/utils' export default defineComponent({ name: "PageIndex", + data() { + return{ + basicInfo: { + name: "", + description: "" + }, + password: { + hint: "", + oldPassword: "", + newPassword: "", + renewPassword: "" + } + } + }, methods: { popWin() { document.getElementById("light").style.display = "block"; @@ -19,8 +35,69 @@ export default defineComponent({ document.getElementById("card-password").style.display = "none"; document.getElementById("fade").style.display = "none"; }, + changeBasicInfo(){ + if(this.basicInfo.name == this.$store.state.User.userInfo.name && + this.basicInfo.description == this.$store.state.User.userInfo.description) { + this.closeWin() + }else{ + this.$store.commit("setUserInfo", { + userId: this.$store.state.User.userInfo.userId, + name: this.basicInfo.name, + description: this.basicInfo.description + }) + axios("/v1/UI/user/changeBasicInfo", { + userId: this.$store.state.User.userInfo.userId, + name: this.basicInfo.name, + description: this.basicInfo.description, + }, "post").then(res => { + res = JSON.parse(res) + if(!res.success) { + console.log("修改失败") + } else { + console.log("修改成功") + } + }).catch(err => { + console.log(err) + }) + } + }, + changePwd() { + if(this.password.oldPassword == "" || this.password.newPassword == "" || this.password.renewPassword == ""){ + this.password.hint = "上述参数必须填写完整" + return + } + if(this.password.newPassword != this.password.renewPassword) { + this.password.hint = "两次输入的新密码不同" + return + } + if(this.password.newPassword == this.password.oldPassword) { + this.password.hint = "新密码不能和旧密码一致" + return + } + console.log(base64Encode(this.password.oldPassword)) + axios("/v1/UI/user/changePasswd", { + userId: this.$store.state.User.userInfo.userId, + password: base64Encode(this.password.oldPassword), + newPasswd: base64Encode(this.password.newPassword) + }, "post").then(res => { + res = JSON.parse(res) + if(!res.oldMatch) { + this.password.hint = "旧密码错误,请重新输入" + this.password.oldPassword = "" + this.password.newPassword = "" + this.password.renewPassword = "" + return + }else{ + this.password.hint = "密码修改成功,下次登陆生效" + } + }).catch(err => { + console.log(err) + }) + }, }, + mounted() { - + this.basicInfo.name = this.$store.state.User.userInfo.name + this.basicInfo.description = this.$store.state.User.userInfo.description }, }); \ No newline at end of file diff --git a/UI2.0/src/js/userlayout.js b/UI2.0/src/js/userlayout.js index 7742971..6836724 100644 --- a/UI2.0/src/js/userlayout.js +++ b/UI2.0/src/js/userlayout.js @@ -58,6 +58,9 @@ export default defineComponent({ document.getElementById("search-input").style.display = "block"; }, }, + mounted() { + this.$store.dispatch("getUserInfoFromBackend") + }, setup() { return { diff --git a/UI2.0/src/js/utils/utils.js b/UI2.0/src/js/utils/utils.js index 7aa92a9..12d2be6 100644 --- a/UI2.0/src/js/utils/utils.js +++ b/UI2.0/src/js/utils/utils.js @@ -1,5 +1,11 @@ +import CryptoJS from "crypto-js"; + export function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min) + min); +} + +export default function base64Encode(pwd) { + return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(pwd)); } \ No newline at end of file diff --git a/UI2.0/src/layouts/UserLayout.vue b/UI2.0/src/layouts/UserLayout.vue index f57d98e..7297988 100644 --- a/UI2.0/src/layouts/UserLayout.vue +++ b/UI2.0/src/layouts/UserLayout.vue @@ -55,7 +55,7 @@ padding: 0px; padding-right: 32px; " - :label="$store.state.user.name" + :label="$store.state.User.userInfo.name" dropdown-icon="expand_more" > diff --git a/UI2.0/src/pages/Control-panel.vue b/UI2.0/src/pages/Control-panel.vue index 67afb96..e54730e 100644 --- a/UI2.0/src/pages/Control-panel.vue +++ b/UI2.0/src/pages/Control-panel.vue @@ -5,10 +5,10 @@
- 嗨,{{$store.state.user.name}}愿您事事顺心,快乐相随! + 嗨,{{$store.state.User.userInfo.name}}愿您事事顺心,快乐相随!
- 长风破浪会有时,直挂云帆济沧海 + {{$store.state.User.userInfo.description}}
diff --git a/UI2.0/src/pages/Personal.vue b/UI2.0/src/pages/Personal.vue index add010f..01ab33e 100644 --- a/UI2.0/src/pages/Personal.vue +++ b/UI2.0/src/pages/Personal.vue @@ -23,10 +23,10 @@ margin-top: 16px; " > - {{$store.state.user.name}} + {{$store.state.User.userInfo.name}}
- 长风破浪会有时,直挂云帆济沧海 + {{$store.state.User.userInfo.description}}
@@ -128,6 +128,7 @@
昵称: 签名: