Forráskód Böngészése

超管强制修改用户密码功能

刘洋 1 éve
szülő
commit
adef27afec

+ 6 - 0
src/api/user.js

@@ -85,6 +85,12 @@ export const updateMyPassword = (data) =>
     data,
     loading: true,
   });
+export const updateUserPassword = (data) =>
+  request({
+    url: '/api/admin/user/update_password',
+    data,
+    loading: true,
+  });
 export const getVerifyCode = (data) =>
   request({
     url: '/api/admin/common/get_verify_code',

+ 2 - 3
src/utils/request.js

@@ -81,8 +81,7 @@ function createService() {
       const err = (text) => {
         Message.error({
           content:
-            error?.config?.url +
-            ' ' +
+            (error?.response?.status == 401 ? error?.config?.url + ' ' : '') +
             (error.response &&
             error.response.data &&
             error.response.data.message
@@ -101,7 +100,7 @@ function createService() {
           case 401:
             err('登录状态已过期或没有权限');
             if (error.response?.data?.message.includes('登录')) {
-              router.push({ name: 'Login' });
+              router.replace({ name: 'Login' });
             }
             break;
           case 403:

+ 8 - 1
src/views/user/auth-manage/role-manage/index.vue

@@ -2,7 +2,12 @@
   <div class="role h-full">
     <div class="flex-1 page-wrap">
       <div class="btn-group">
-        <t-button theme="success" @click="toAddRole({})">新增角色</t-button>
+        <t-button
+          v-perm="'role_BUTTON_Add'"
+          theme="success"
+          @click="toAddRole({})"
+          >新增角色</t-button
+        >
       </div>
       <t-table
         size="small"
@@ -44,6 +49,7 @@ const columns = [
       return (
         <div class="table-operations">
           <t-link
+            v-perm="role_LINK_Update"
             theme="primary"
             hover="color"
             onClick={(e) => {
@@ -54,6 +60,7 @@ const columns = [
             修改
           </t-link>
           <t-link
+            v-perm="role_LINK_Delete"
             theme="danger"
             hover="color"
             onClick={(e) => {

+ 24 - 0
src/views/user/auth-manage/user-manage/index.vue

@@ -39,6 +39,12 @@
       :curRow="curRow"
       @success="addSuccess"
     ></AddUserDialog>
+    <UpdateUserPwdDialog
+      v-model:visible="showUpdateUserPwdDialog"
+      :curRow="curRow"
+      @success="updatePwdSuccess"
+    >
+    </UpdateUserPwdDialog>
   </div>
 </template>
 
@@ -47,9 +53,11 @@ import { ref } from 'vue';
 import { getUserList } from '@/api/user';
 import useFetchTable from '@/hooks/useFetchTable';
 import AddUserDialog from './add-user-dialog.vue';
+import UpdateUserPwdDialog from './update-user-pwd-dialog.vue';
 import { toggleUserStatus } from '@/api/user';
 import { MessagePlugin } from 'tdesign-vue-next';
 const showAddUserDialog = ref(false);
+const showUpdateUserPwdDialog = ref(false);
 const curRow = ref(null);
 const toggleStatus = (row) => {
   toggleUserStatus({ id: row.id, enable: !row.enable }).then(() => {
@@ -72,6 +80,18 @@ const columns = [
     cell: (h, { row }) => {
       return (
         <div class="table-operations">
+          <t-link
+            v-perm="user_LINK_UpdatePwd"
+            theme="primary"
+            hover="color"
+            onClick={(e) => {
+              e.stopPropagation();
+              curRow.value = row;
+              showUpdateUserPwdDialog.value = true;
+            }}
+          >
+            修改密码
+          </t-link>
           <t-link
             v-perm="user_LINK_Update"
             theme="primary"
@@ -115,6 +135,10 @@ const addSuccess = () => {
   MessagePlugin.success('操作成功');
   search();
 };
+const updatePwdSuccess = () => {
+  showUpdateUserPwdDialog.value = false;
+  MessagePlugin.success('操作成功');
+};
 </script>
 
 <style></style>

+ 69 - 0
src/views/user/auth-manage/user-manage/update-user-pwd-dialog.vue

@@ -0,0 +1,69 @@
+<template>
+  <my-dialog
+    :visible="visible"
+    @close="emit('update:visible', false)"
+    :header="'修改用户密码'"
+    :width="500"
+    :closeOnOverlayClick="false"
+  >
+    <t-form ref="formRef" :data="formData" labelWidth="120px" :rules="rules">
+      <t-form-item label="新密码" name="newPassword">
+        <t-input
+          v-model="formData.newPassword"
+          type="password"
+          clearable
+        ></t-input>
+      </t-form-item>
+    </t-form>
+    <template #foot>
+      <t-button theme="default" @click="emit('update:visible', false)"
+        >取消</t-button
+      >
+      <t-button theme="primary" @click="save">保存</t-button>
+    </template>
+  </my-dialog>
+</template>
+<script setup name="AddUserDialog">
+import useClearDialog from '@/hooks/useClearDialog';
+import { ref } from 'vue';
+import { updateUserPassword } from '@/api/user';
+import { getBase64 } from '@/utils/crypto';
+const emit = defineEmits(['update:visible', 'success']);
+const formRef = ref(null);
+const props = defineProps({
+  visible: Boolean,
+  curRow: Object,
+});
+const { formData } = useClearDialog(
+  {
+    newPassword: '',
+  },
+  props,
+  formRef
+);
+const rules = {
+  newPassword: [
+    {
+      required: true,
+      message: '请填写该用户的新密码',
+      type: 'error',
+      trigger: 'blur',
+    },
+  ],
+};
+const updateHandler = () => {
+  updateUserPassword({
+    newPassword: getBase64(formData.getBase64),
+    id: props.curRow.id,
+  }).then(() => {
+    emit('success');
+  });
+};
+const save = () => {
+  formRef.value.validate().then(async (result) => {
+    if (result === true) {
+      updateHandler();
+    }
+  });
+};
+</script>