user接口修改并测试

This commit is contained in:
Ran_Chen
2025-04-01 10:59:35 +08:00
parent a345d41e9e
commit 5998fc3edd
7 changed files with 84 additions and 72 deletions
+3 -2
View File
@@ -105,11 +105,12 @@ function httpHandlerError(info, callBack) {
/** 请求成功,退出该函数 可以根据项目需求来判断是否请求成功。这里判断的是status为200的时候是成功 */ /** 请求成功,退出该函数 可以根据项目需求来判断是否请求成功。这里判断的是status为200的时候是成功 */
let networkError = false let networkError = false
if (info.status === 200) { if (info.status === 200) {
if (info.data.code === 'success' || info.data.code === 0 || info.data.code === undefined) { if (info.data.code === 'success' || info.data.code === 0 || info.data.code === undefined) {
return networkError return networkError
}else if (info.data.code === 401) { }else if (info.data.code === 401) {
goToPage(Constant.PAGE.LOGIN, true) console.log('触发 401,清除 Token 并跳转登录页');
store.commit('clearAuth');
window.location.href = '/login';
return true return true
} else { } else {
showDanger(info.data.msg) showDanger(info.data.msg)
+2 -2
View File
@@ -138,8 +138,8 @@ export default {
.url(`${getServiceUrl()}/api/v1/user/change-password`) .url(`${getServiceUrl()}/api/v1/user/change-password`)
.method('PUT') .method('PUT')
.data({ .data({
old_password: oldPassword, password: oldPassword,
new_password: newPassword, newPassword: newPassword,
}) })
.success((res) => { .success((res) => {
RequestService.clearRequestTime(); RequestService.clearRequestTime();

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

@@ -1,57 +1,63 @@
<template> <template>
<el-dialog :visible.sync="visible" width="400px" center> <form>
<div <el-dialog :visible.sync="value" width="400px" center>
style="margin: 0 10px 10px;display: flex;align-items: center;gap: 10px;font-weight: 700;font-size: 20px;text-align: left;color: #3d4566;">
<div <div
style="width: 40px;height: 40px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;"> style="margin: 0 10px 10px;display: flex;align-items: center;gap: 10px;font-weight: 700;font-size: 20px;text-align: left;color: #3d4566;">
<img src="@/assets/login/shield.png" alt="" style="width: 19px;height: 23px; filter: brightness(0) invert(1);" /> <div
style="width: 40px;height: 40px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;">
<img src="@/assets/login/shield.png" alt="" style="width: 19px;height: 23px; filter: brightness(0) invert(1);" />
</div>
修改密码
</div> </div>
修改密码 <div style="height: 1px;background: #e8f0ff;"/>
</div> <div style="margin: 22px 15px;">
<div style="height: 1px;background: #e8f0ff;"/> <div style="font-weight: 400;font-size: 14px;text-align: left;color: #3d4566;">
<div style="margin: 22px 15px;"> <div style="color: red;display: inline-block;">*</div>
<div style="font-weight: 400;font-size: 14px;text-align: left;color: #3d4566;"> 旧密码
<div style="color: red;display: inline-block;">*</div> </div>
旧密码 <div class="input-46" style="margin-top: 12px;">
<el-input placeholder="请输入旧密码" v-model="oldPassword" type="password" show-password/>
</div>
<div style="font-weight: 400;font-size: 14px;text-align: left;color: #3d4566;margin-top: 12px;">
<div style="color: red;display: inline-block;">*</div>
新密码
</div>
<div class="input-46" style="margin-top: 12px;">
<el-input placeholder="请输入新密码" v-model="newPassword" type="password" show-password/>
</div>
<div style="font-weight: 400;font-size: 14px;text-align: left;color: #3d4566;margin-top: 12px;">
<div style="color: red;display: inline-block;">*</div>
确认新密码
</div>
<div class="input-46" style="margin-top: 12px;">
<el-input placeholder="请再次输入新密码" v-model="confirmNewPassword" type="password" show-password/>
</div>
</div> </div>
<div class="input-46" style="margin-top: 12px;"> <div style="display: flex;margin: 15px 15px;gap: 7px;">
<el-input placeholder="请输入旧密码" v-model="oldPassword" type="password" show-password/> <div class="dialog-btn" @click="confirm">
确定
</div>
<div class="dialog-btn"
style="background: #e6ebff;border: 1px solid #adbdff;color: #5778ff;"
@click="cancel">
取消
</div>
</div> </div>
<div style="font-weight: 400;font-size: 14px;text-align: left;color: #3d4566;margin-top: 12px;"> </el-dialog>
<div style="color: red;display: inline-block;">*</div> </form>
新密码
</div>
<div class="input-46" style="margin-top: 12px;">
<el-input placeholder="请输入新密码" v-model="newPassword" type="password" show-password/>
</div>
<div style="font-weight: 400;font-size: 14px;text-align: left;color: #3d4566;margin-top: 12px;">
<div style="color: red;display: inline-block;">*</div>
确认新密码
</div>
<div class="input-46" style="margin-top: 12px;">
<el-input placeholder="请再次输入新密码" v-model="confirmNewPassword" type="password" show-password/>
</div>
</div>
<div style="display: flex;margin: 15px 15px;gap: 7px;">
<div class="dialog-btn" @click="confirm">
确定
</div>
<div class="dialog-btn"
style="background: #e6ebff;border: 1px solid #adbdff;color: #5778ff;"
@click="cancel">
取消
</div>
</div>
</el-dialog>
</template> </template>
<script> <script>
import userApi from '@/apis/module/user'; import userApi from '@/apis/module/user';
import { mapActions } from 'vuex';
export default { export default {
name: 'ChangePasswordDialog', name: 'ChangePasswordDialog',
props: { props: {
visible: {type: Boolean, required: true} value: {
type: Boolean,
required: true
}
}, },
data() { data() {
return { return {
@@ -61,6 +67,7 @@ export default {
} }
}, },
methods: { methods: {
...mapActions(['logout']), // 引入Vuex的logout action
confirm() { confirm() {
if (!this.oldPassword.trim() || !this.newPassword.trim() || !this.confirmNewPassword.trim()) { if (!this.oldPassword.trim() || !this.newPassword.trim() || !this.confirmNewPassword.trim()) {
this.$message.error('请填写所有字段'); this.$message.error('请填写所有字段');
@@ -75,22 +82,24 @@ export default {
return; return;
} }
// 直接调用修改密码接口 // 修改后的接口调用
userApi.changePassword(this.oldPassword, this.newPassword, (res) => { userApi.changePassword(this.oldPassword, this.newPassword, (res) => {
if (res.code === 0) { if (res.data.code === 0) {
this.$message.error(res.msg || '密码修改失败'); this.$message.success('密码修改成功,请重新登录');
} else { this.logout().then(() => {
this.$message.success('密码修改成功'); this.$router.push('/login');
this.$emit('confirm', res); this.$emit('update:visible', false);
this.$emit('update:visible', false); });
this.resetForm(); }else{
this.$message.error(res.data.msg || '密码修改失败');
} }
}, (err) => { }, (err) => {
this.$message.error(err.msg || '密码修改失败'); this.$message.error(err.msg || '密码修改失败');
}); });
this.$emit('input', false);
}, },
cancel() { cancel() {
this.$emit('update:visible', false); this.$emit('input', false);
this.resetForm(); this.resetForm();
}, },
resetForm() { resetForm() {
@@ -10,7 +10,7 @@
<!-- 中间导航菜单 --> <!-- 中间导航菜单 -->
<div class="header-center"> <div class="header-center">
<div class="equipment-management" :class="{ 'active-tab': $route.path === '/home' }" @click="goHome"> <div class="equipment-management" :class="{ 'active-tab': $route.path === '/home' }" @click="goHome">
<img alt="" src="@/assets/header/roboot.png" :style="{ filter: $route.path === '/home' ? 'brightness(0) invert(1)' : 'None' }"/> <img alt="" src="@/assets/header/robot.png" :style="{ filter: $route.path === '/home' ? 'brightness(0) invert(1)' : 'None' }"/>
智能体管理 智能体管理
</div> </div>
<div class="equipment-management" :class="{ 'active-tab': $route.path === '/user-management' }" @click="goUserManagement"> <div class="equipment-management" :class="{ 'active-tab': $route.path === '/user-management' }" @click="goUserManagement">
@@ -27,7 +27,7 @@
<div class="header-right"> <div class="header-right">
<div class="search-container"> <div class="search-container">
<el-input <el-input
v-model="serach" v-model="search"
placeholder="输入名称搜索.." placeholder="输入名称搜索.."
class="custom-search-input" class="custom-search-input"
@keyup.enter.native="handleSearch" @keyup.enter.native="handleSearch"
@@ -38,7 +38,7 @@
<img alt="" src="@/assets/home/avatar.png" class="avatar-img"/> <img alt="" src="@/assets/home/avatar.png" class="avatar-img"/>
<el-dropdown trigger="click" class="user-dropdown"> <el-dropdown trigger="click" class="user-dropdown">
<span class="el-dropdown-link"> <span class="el-dropdown-link">
{{ userInfo.mobile || '加载中...' }}<i class="el-icon-arrow-down el-icon--right"></i> {{ userInfo.username || '加载中...' }}<i class="el-icon-arrow-down el-icon--right"></i>
</span> </span>
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">
<el-dropdown-item icon="el-icon-plus" @click.native="">个人中心</el-dropdown-item> <el-dropdown-item icon="el-icon-plus" @click.native="">个人中心</el-dropdown-item>
@@ -50,7 +50,7 @@
</div> </div>
<!-- 修改密码弹窗 --> <!-- 修改密码弹窗 -->
<ChangePasswordDialog :visible.sync="isChangePasswordDialogVisible"/> <ChangePasswordDialog v-model="isChangePasswordDialogVisible"/>
</el-header> </el-header>
</template> </template>
@@ -68,7 +68,7 @@ export default {
props: ['devices'], // 接收父组件设备列表 props: ['devices'], // 接收父组件设备列表
data() { data() {
return { return {
serach: '', search: '',
userInfo: { userInfo: {
username: '', username: '',
mobile: '' mobile: ''
@@ -99,7 +99,7 @@ export default {
// 处理搜索 // 处理搜索
handleSearch() { handleSearch() {
const searchValue = this.serach.trim(); const searchValue = this.search.trim();
let filteredDevices; let filteredDevices;
if (!searchValue) { if (!searchValue) {
+1 -1
View File
@@ -39,7 +39,7 @@ export default new Vuex.Store({
logout({ commit }) { logout({ commit }) {
return new Promise((resolve) => { return new Promise((resolve) => {
commit('clearAuth') commit('clearAuth')
resolve() window.location.href = '/login';
}) })
} }
}, },
+13 -11
View File
@@ -9,7 +9,7 @@
</div> </div>
</el-header> </el-header>
<el-main style="position: relative;"> <el-main style="position: relative;">
<div class="login-box"> <div class="login-box" @keyup.enter="login">
<div <div
style="display: flex;align-items: center;gap: 20px;margin-bottom: 39px;padding: 0 30px;"> style="display: flex;align-items: center;gap: 20px;margin-bottom: 39px;padding: 0 30px;">
<img alt="" src="@/assets/login/hi.png" style="width: 34px;height: 34px;"/> <img alt="" src="@/assets/login/hi.png" style="width: 34px;height: 34px;"/>
@@ -87,8 +87,11 @@ export default {
}, },
methods: { methods: {
fetchCaptcha() { fetchCaptcha() {
console.log(this.$store.getters.getToken)
if (this.$store.getters.getToken) { if (this.$store.getters.getToken) {
goToPage('/home') if (this.$route.path !== '/home'){
this.$router.push('/home')
}
} else { } else {
this.captchaUuid = getUUID(); this.captchaUuid = getUUID();
@@ -96,10 +99,8 @@ export default {
if (res.status === 200) { if (res.status === 200) {
const blob = new Blob([res.data], {type: res.data.type}); const blob = new Blob([res.data], {type: res.data.type});
this.captchaUrl = URL.createObjectURL(blob); this.captchaUrl = URL.createObjectURL(blob);
} else { } else {
console.error('验证码加载异常:', error); showDanger('验证码加载失败,点击刷新');
showDanger('验证码加载失败,点击刷新')
} }
}); });
} }
@@ -130,12 +131,13 @@ export default {
this.form.captchaId = this.captchaUuid this.form.captchaId = this.captchaUuid
Api.user.login(this.form, ({data}) => { Api.user.login(this.form, ({data}) => {
console.log(data) if (data.code === 0) {
showSuccess('登成功!') showSuccess('登成功!');
// 将令牌存储到 Vuex 中 this.$store.commit('setToken', JSON.stringify(data.data));
this.$store.commit('setToken', JSON.stringify(data.data)) goToPage('/home');
} else {
goToPage('/home') showDanger(data.msg || '登录失败');
}
}) })
// 重新获取验证码 // 重新获取验证码