From 3de63514e769ac64da604a3e7e3262b33e653884 Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期一, 16 六月 2025 13:55:29 +0800
Subject: [PATCH] feat(eims): 新增修改密码功能并优化用户初始密码设置- 在 SocialAuthStrategy 中使用 BCrypt 对用户初始密码进行加密- 在 eims-ui-mobile 中添加修改密码页面和相关功能 - 更新用户服务以支持修改密码操作 - 调整页面路由以包含新功能

---
 eims-ui-mobile/src/pages/my/password.vue                                            |  132 ++++++++++++++++++++++++++++++++++++++++++++
 eims-ui-mobile/src/service/app/user.ts                                              |   11 +++
 eims-ui-mobile/src/pages/maint/maint-st.vue                                         |    2 
 eims-ui-mobile/src/pages.json                                                       |    9 +++
 eims-ui-mobile/src/pages/my/index.vue                                               |    7 ++
 eims/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java |    3 
 6 files changed, 162 insertions(+), 2 deletions(-)

diff --git a/eims-ui-mobile/src/pages.json b/eims-ui-mobile/src/pages.json
index dd4e52f..b5a08ca 100644
--- a/eims-ui-mobile/src/pages.json
+++ b/eims-ui-mobile/src/pages.json
@@ -165,6 +165,15 @@
       }
     },
     {
+      "path": "pages/my/password",
+      "type": "page",
+      "layout": "default",
+      "needLogin": true,
+      "style": {
+        "navigationBarTitleText": "淇敼瀵嗙爜"
+      }
+    },
+    {
       "path": "pages/repair/repair-add",
       "type": "page",
       "layout": "default",
diff --git a/eims-ui-mobile/src/pages/maint/maint-st.vue b/eims-ui-mobile/src/pages/maint/maint-st.vue
index c58daa8..836d79d 100644
--- a/eims-ui-mobile/src/pages/maint/maint-st.vue
+++ b/eims-ui-mobile/src/pages/maint/maint-st.vue
@@ -138,7 +138,7 @@
 // 鍘熸湁鐘舵��
 const status = ref<string>('0') // 榛樿涓哄緟淇濆吇鐘舵��
 const equName = ref<string>('-1')
-const filterDate = ref<string>('1')
+const filterDate = ref<string>('0')
 
 const filterDateList = ref<Record<string, any>[]>([
   { label: '鎵�鏈夋暟鎹�', value: '0' },
diff --git a/eims-ui-mobile/src/pages/my/index.vue b/eims-ui-mobile/src/pages/my/index.vue
index 41c97d5..63ce1b7 100644
--- a/eims-ui-mobile/src/pages/my/index.vue
+++ b/eims-ui-mobile/src/pages/my/index.vue
@@ -16,6 +16,7 @@
       <wd-cell title="浜哄憳绠$悊" icon="usergroup" is-link  custom-icon-class="icon-color-base" @click="handleInfo" />
     </wd-cell-group>
     <wd-cell-group border class="mt-2">
+      <wd-cell title="淇敼瀵嗙爜" icon="keywords" is-link  custom-icon-class="icon-color-base" @click="handlePwd" />
       <wd-cell title="閫�鍑虹櫥褰�" icon="login" is-link  custom-icon-class="icon-color-base" @click="handleLogout" />
     </wd-cell-group>
   </view>
@@ -60,6 +61,12 @@
     icon: 'none',
   })
 }
+
+function handlePwd() {
+  uni.navigateTo({
+    url: '/pages/my/password'
+  })
+}
 </script>
 
 <style lang="scss" scoped>
diff --git a/eims-ui-mobile/src/pages/my/password.vue b/eims-ui-mobile/src/pages/my/password.vue
new file mode 100644
index 0000000..499a649
--- /dev/null
+++ b/eims-ui-mobile/src/pages/my/password.vue
@@ -0,0 +1,132 @@
+<route lang="json5" type="page">
+{
+  layout: 'default',
+  needLogin: true,
+  "style": {
+    "navigationBarTitleText": "淇敼瀵嗙爜"
+  }
+}
+</route>
+
+<template>
+  <view class="container">
+    <wd-form ref="formRef" :model="form">
+      <wd-cell-group custom-class="cell-group" border>
+        <wd-input
+          label="鏃у瘑鐮�"
+          label-width="100px"
+          clearable
+          show-word-limit
+          prop="oldPassword"
+          show-password
+          v-model="form.oldPassword"
+          placeholder="璇疯緭鍏ユ棫瀵嗙爜"
+          :rules="[{ required: true, message: '鏃у瘑鐮佷笉鑳戒负绌�' }]"
+        />
+        <wd-input
+          label="鏂板瘑鐮�"
+          label-width="100px"
+          clearable
+          show-word-limit
+          prop="newPassword"
+          show-password
+          v-model="form.newPassword"
+          placeholder="璇疯緭鍏ユ柊瀵嗙爜"
+          :rules="[
+            { required: true, message: '鏂板瘑鐮佷笉鑳戒负绌�' },
+            { validator: validatePassword },
+          ]"
+        />
+        <wd-input
+          label="纭鏂板瘑鐮�"
+          label-width="100px"
+          clearable
+          show-word-limit
+          prop="confirmNewPassword"
+          show-password
+          v-model="form.confirmNewPassword"
+          placeholder="璇峰啀娆¤緭鍏ユ柊瀵嗙爜"
+          :rules="[
+            { required: true, message: '纭鏂板瘑鐮佷笉鑳戒负绌�' },
+            { validator: validatePassword },
+            {
+              validator: (value) => value === form.newPassword,
+              message: '涓ゆ杈撳叆鐨勫瘑鐮佷笉涓�鑷�'
+            }
+          ]"
+        />
+      </wd-cell-group>
+      <view class="footer">
+        <wd-button type="primary" class="mt-6" size="large" block @click="submit">鎻愪氦</wd-button>
+      </view>
+    </wd-form>
+  </view>
+</template>
+
+<script lang="ts" setup>
+import { ref, reactive } from 'vue'
+import { updatePassword } from '@/service/app/user'
+import { useUserStore, useAccessStore, useSystemConfigStore } from '@/store'
+
+
+const userStore = useUserStore()
+const accessStore = useAccessStore()
+const configStore = useSystemConfigStore()
+
+const form = reactive({
+  oldPassword: '',
+  newPassword: '',
+  confirmNewPassword: ''
+})
+const formRef = ref()
+
+const validatePassword = (value) => {
+  if (value.length < 6) {
+    return Promise.reject('瀵嗙爜闀垮害涓嶈兘灏戜簬6浣�')
+  }
+  if (value.length > 20) {
+    return Promise.reject('瀵嗙爜闀垮害涓嶈兘瓒呰繃20浣�')
+  }
+  return Promise.resolve()
+}
+
+const submit = () => {
+
+  formRef.value.validate().then(({ valid, errors }) => {
+    if (valid) {
+      updatePassword(form.oldPassword, form.newPassword)
+        .then((response) => {
+          if (response.code === 200) {
+            uni.showToast({
+              title: '淇敼瀵嗙爜鎴愬姛',
+              icon: 'success',
+            })
+            userStore.clearUserInfo()
+            accessStore.clearAccessInfo()
+            configStore.clearConfigInfo()
+            uni.reLaunch({
+              url: '/pages/login/index',
+            })
+          } else {
+            uni.showToast({
+              title: response.msg || '淇敼瀵嗙爜澶辫触',
+              icon: 'error',
+            })
+          }
+        })
+        .catch((error) => {
+          uni.showToast({
+            title: error.msg || '淇敼瀵嗙爜澶辫触',
+            icon: 'error',
+          })
+        })
+    }
+  })
+}
+</script>
+
+<style lang="scss" scoped>
+.footer {
+  margin: 20px;
+}
+</style>
diff --git a/eims-ui-mobile/src/service/app/user.ts b/eims-ui-mobile/src/service/app/user.ts
index 2474272..c02287b 100644
--- a/eims-ui-mobile/src/service/app/user.ts
+++ b/eims-ui-mobile/src/service/app/user.ts
@@ -148,3 +148,14 @@
     ...(options || {}),
   });
 }
+
+/** 淇敼瀵嗙爜 POST /system/user/profile/updatePwd */
+export async function updatePassword(oldPassword: string, newPassword: string) {
+  return request<unknown>('/system/user/profile/updatePwd', {
+    method: 'PUT',
+    data: {
+      oldPassword,
+      newPassword,
+    },
+  });
+}
diff --git a/eims/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java b/eims/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java
index ef2caf8..547f53e 100644
--- a/eims/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java
+++ b/eims/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java
@@ -1,5 +1,6 @@
 package org.dromara.web.service.impl;
 
+import cn.dev33.satoken.secure.BCrypt;
 import cn.dev33.satoken.stp.SaLoginModel;
 import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.collection.CollUtil;
@@ -90,7 +91,7 @@
                 newUser.setUserName(authUserData.getUsername());
                 newUser.setEmail(authUserData.getEmail());
                 newUser.setNickName(authUserData.getNickname());
-                newUser.setPassword("Initial123@"); // 鍒濆瀵嗙爜闇�绗﹀悎瀹夊叏绛栫暐
+                newUser.setPassword(BCrypt.hashpw("123456")); // 鍒濆瀵嗙爜闇�绗﹀悎瀹夊叏绛栫暐
                 newUser.setStatus("0");
 
                 userMapper.insert(newUser); // 鍋囪瀛樺湪鎻掑叆鏂规硶

--
Gitblit v1.9.3