From b051f008e007a335948cd8f3b78c1f7629a4d6ac Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期一, 31 八月 2026 13:00:05 +0800
Subject: [PATCH] fix: 菜单高亮间歇性失效根因(el-menu 同路由导航回滚 activeIndex)——default-active 绑定路由+select 后宏任务纠正;feat: 修改密码(用户自改)+ admin 重置他人密码为 123456

---
 traffic-audit-web/src/components/AppHeader.vue |   84 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/traffic-audit-web/src/components/AppHeader.vue b/traffic-audit-web/src/components/AppHeader.vue
index 09eb2bb..aeec948 100644
--- a/traffic-audit-web/src/components/AppHeader.vue
+++ b/traffic-audit-web/src/components/AppHeader.vue
@@ -5,33 +5,107 @@
       <span class="header-user">
         <i class="el-icon-user"></i> {{ username }}
       </span>
+      <el-button type="text" class="header-link" @click="openChangePwd">
+        <i class="el-icon-key"></i> 淇敼瀵嗙爜
+      </el-button>
       <el-button type="text" class="header-logout" @click="logout">
         <i class="el-icon-switch-button"></i> 閫�鍑虹櫥褰�
       </el-button>
     </div>
+
+    <el-dialog title="淇敼瀵嗙爜" :visible.sync="pwdDialogVisible" width="420px" @closed="resetPwdForm">
+      <el-form ref="pwdForm" :model="pwdForm" :rules="pwdRules" label-width="90px">
+        <el-form-item label="鍘熷瘑鐮�" prop="oldPassword">
+          <el-input v-model="pwdForm.oldPassword" type="password" show-password placeholder="璇疯緭鍏ュ師瀵嗙爜"></el-input>
+        </el-form-item>
+        <el-form-item label="鏂板瘑鐮�" prop="newPassword">
+          <el-input v-model="pwdForm.newPassword" type="password" show-password placeholder="鑷冲皯 6 浣�"></el-input>
+        </el-form-item>
+        <el-form-item label="纭鏂板瘑鐮�" prop="confirmPassword">
+          <el-input v-model="pwdForm.confirmPassword" type="password" show-password placeholder="鍐嶆杈撳叆鏂板瘑鐮�"></el-input>
+        </el-form-item>
+      </el-form>
+      <div slot="footer">
+        <el-button @click="pwdDialogVisible = false">鍙栨秷</el-button>
+        <el-button type="primary" :loading="pwdSaving" @click="submitPwd">淇濆瓨</el-button>
+      </div>
+    </el-dialog>
   </el-header>
 </template>
 
 <script>
+import api from '@/api'
+
 export default {
   name: 'AppHeader',
   props: {
     title: { type: String, required: true }
   },
+  data() {
+    return {
+      pwdDialogVisible: false,
+      pwdSaving: false,
+      pwdForm: { oldPassword: '', newPassword: '', confirmPassword: '' },
+      pwdRules: {
+        oldPassword: [{ required: true, message: '璇疯緭鍏ュ師瀵嗙爜', trigger: 'blur' }],
+        newPassword: [
+          { required: true, message: '璇疯緭鍏ユ柊瀵嗙爜', trigger: 'blur' },
+          { min: 6, message: '鏂板瘑鐮侀暱搴︿笉鑳藉皯浜� 6 浣�', trigger: 'blur' }
+        ],
+        confirmPassword: [
+          { required: true, message: '璇峰啀娆¤緭鍏ユ柊瀵嗙爜', trigger: 'blur' },
+          {
+            validator: (rule, value, cb) => (value === this.pwdForm.newPassword ? cb() : cb(new Error('涓ゆ杈撳叆鐨勫瘑鐮佷笉涓�鑷�'))),
+            trigger: 'blur'
+          }
+        ]
+      }
+    }
+  },
   computed: {
     username() {
-      return localStorage.getItem('username') || 'admin'
+      return sessionStorage.getItem('username') || 'admin'
     }
   },
   methods: {
+    openChangePwd() {
+      this.pwdForm = { oldPassword: '', newPassword: '', confirmPassword: '' }
+      this.pwdDialogVisible = true
+      this.$nextTick(() => this.$refs.pwdForm && this.$refs.pwdForm.clearValidate())
+    },
+    resetPwdForm() {
+      this.$refs.pwdForm && this.$refs.pwdForm.clearValidate()
+    },
+    submitPwd() {
+      this.$refs.pwdForm.validate(valid => {
+        if (!valid) return
+        this.pwdSaving = true
+        api.post('/auth/change-password', {
+          oldPassword: this.pwdForm.oldPassword,
+          newPassword: this.pwdForm.newPassword
+        })
+          .then(() => {
+            this.$message.success('瀵嗙爜淇敼鎴愬姛')
+            this.pwdDialogVisible = false
+          })
+          .catch(err => {
+            if (err && err._toast) return
+            const d = err && err.response && err.response.data
+            this.$message.error((d && d.message) || '瀵嗙爜淇敼澶辫触')
+          })
+          .finally(() => { this.pwdSaving = false })
+      })
+    },
     logout() {
       this.$confirm('纭畾閫�鍑虹櫥褰曞悧锛�', '鎻愮ず', {
         confirmButtonText: '閫�鍑�',
         cancelButtonText: '鍙栨秷',
         type: 'warning'
       }).then(() => {
-        localStorage.removeItem('token')
-        localStorage.removeItem('username')
+        sessionStorage.removeItem('token')
+        sessionStorage.removeItem('username')
+        sessionStorage.removeItem('realName')
+        sessionStorage.removeItem('modules')
         this.$message.success('宸查��鍑虹櫥褰�')
         this.$router.push('/login')
       }).catch(() => {})
@@ -60,6 +134,8 @@
   line-height: normal;
 }
 .header-user { opacity: 0.92; }
+.header-link { color: #fff; font-size: 14px; padding: 0; }
+.header-link:hover { color: #ffd04b; }
 .header-logout { color: #fff; font-size: 14px; padding: 0; }
 .header-logout:hover { color: #ffd04b; }
-</style>
\ No newline at end of file
+</style>

--
Gitblit v1.9.1