Przeglądaj źródła

update: 增加重置密码功能

xyh 2 lat temu
rodzic
commit
db82bbc470

+ 2 - 0
src/locales/common.ts

@@ -7,6 +7,7 @@ export default {
       filter: '筛选',
     },
     confirm: '确定',
+    cancel: '取消',
     tableTool: {
       add: '新增',
       refresh: '刷新',
@@ -42,6 +43,7 @@ export default {
       filter: '筛选',
     },
     confirm: '确定',
+    cancel: '取消',
     tableTool: {
       add: '新增',
       refresh: '刷新',

+ 6 - 0
src/locales/user.ts

@@ -14,6 +14,9 @@ export default {
         '请选择角色',
       ],
     },
+    tableOperation: ['重置密码'],
+    resetTips: '重置密码会将密码修改为123456',
+    resetSuccess: '重置成功',
   },
   ko: {
     label: '用户',
@@ -30,5 +33,8 @@ export default {
         '请选择角色',
       ],
     },
+    tableOperation: ['重置密码'],
+    resetTips: '重置密码会将密码修改为123456',
+    resetSuccess: '重置成功',
   },
 };

+ 1 - 1
src/models/response/menu.ts

@@ -6,7 +6,7 @@ export type MenuListData = {
   /** 韩语名称 */
   koreanName: string;
   /** 父级id */
-  pid: string;
+  pId: string;
   /** 菜单 */
   url: string;
   /** 排序 */

+ 5 - 5
src/pages/home/menu/hooks.tsx

@@ -17,7 +17,7 @@ export function useMenu() {
       koreanName: '첫 페이지',
       id: '-1',
       img: 'HomeMenuIcon',
-      pid: '0',
+      pId: '0',
       url: '/main',
       orderBy: '',
       modifyTime: '',
@@ -42,11 +42,11 @@ export function useMenu() {
     key: string,
     item: typeof menuOptions[0],
   ) {
-    const {label, pid, url, koLabel} = item;
+    const {label, pId, url, koLabel} = item;
 
     tabStore.dispatch({
       type: 'ADD',
-      payload: {label, key, url, pid, koLabel},
+      payload: {label, key, url, pid: pId, koLabel},
     });
   }
 
@@ -55,11 +55,11 @@ export function useMenu() {
     // 页面初始页面不一定是首页需要判断是否需要增加tab
     const idx = basicMenu.findIndex(val => val.url === route.path);
     if (idx < 0) return;
-    const {name, pid, url, id, koreanName} = basicMenu[idx];
+    const {name, pId, url, id, koreanName} = basicMenu[idx];
 
     tabStore.dispatch({
       type: 'ADD',
-      payload: {label: name, key: id, url, pid, koLabel: koreanName},
+      payload: {label: name, key: id, url, pid: pId, koLabel: koreanName},
     });
   });
 

+ 56 - 4
src/pages/user/table/hooks.ts

@@ -1,4 +1,4 @@
-import {delUser, getUserList} from '@apis';
+import {delUser, getUserList, resetPassword} from '@apis';
 import {
   useFetchTableList,
   useTableDeleteEvent,
@@ -6,11 +6,12 @@ import {
 } from '@hooks';
 import {filterSymbol, pageSymbol, searchSymbol} from '../state';
 import {useI18n} from 'vue-i18n';
-import {computed, h} from 'vue';
-import {type DataTableColumn, NSpace} from 'naive-ui';
+import {computed, h, ref} from 'vue';
+import {type DataTableColumn, NSpace, useMessage, useDialog} from 'naive-ui';
 import {UserListData} from '@models';
-import {TABLE_CELL_WIDTH} from '@utils';
+import {TABLE_CELL_WIDTH, lightVariable} from '@utils';
 import {LDTableButton} from '@components';
+import {useMutation} from '@tanstack/vue-query';
 
 export function useTableData() {
   return useFetchTableList({
@@ -21,18 +22,58 @@ export function useTableData() {
   });
 }
 
+function useResePassword() {
+  const message = useMessage();
+  const {t} = useI18n();
+  const resetId = ref('');
+
+  const {mutate} = useMutation({
+    mutationFn: resetPassword,
+    onSuccess({msg}) {
+      msg === '200' && message.success(t('user.resetSuccess'));
+    },
+    onSettled() {
+      resetId.value = '';
+    },
+  });
+
+  const dialog = useDialog();
+  function onReset(id: string) {
+    return function() {
+      dialog.info({
+        title: t('user.tableOperation[0]'),
+        content: t('user.resetTips'),
+        positiveText: t('common.confirm'),
+        negativeText: t('common.cancel'),
+        positiveButtonProps: {
+          color: lightVariable.primaryColor,
+        },
+        onPositiveClick() {
+          mutate(id);
+          resetId.value = id;
+        },
+      });
+    };
+  }
+
+  return [resetId, onReset] as const;
+}
+
 export function useColumns(refetch: () => void) {
   const {t} = useI18n();
   const [
     {visible, editId},
     {onEdit, onAdd},
   ] = useTableModalEvent();
+
   const [deleteId, onDelete] = useTableDeleteEvent(
     delUser,
     refetch,
     {label: t('user.label')},
   );
 
+  const [resetId, onReset] = useResePassword();
+
   const columns = computed<DataTableColumn<UserListData>[]>(function() {
     return [
       {
@@ -67,6 +108,7 @@ export function useColumns(refetch: () => void) {
         fixed: 'right',
         render({id}) {
           const isDeleteing = String(id) === deleteId.value;
+          const isReseting = String(id) === resetId.value;
 
           return h(
             NSpace,
@@ -81,6 +123,16 @@ export function useColumns(refetch: () => void) {
                   text: t('common.tableTool.buttonGroup.edit'),
                 },
               ),
+              h(
+                h(LDTableButton),
+                {
+                  isDelete: false,
+                  disabled: isDeleteing || isReseting,
+                  loading: isReseting,
+                  onClick: onReset(String(id)),
+                  text: t('user.tableOperation[0]'),
+                },
+              ),
               h(
                 h(LDTableButton),
                 {

+ 8 - 8
src/utils/format-menu/index.tsx

@@ -7,7 +7,7 @@ export type MenuList = {
   koLabel: string,
   key: string,
   icon?: () => VNodeChild,
-  pid: string,
+  pId: string,
   url: string,
   children?: MenuList[],
 };
@@ -16,19 +16,19 @@ export function formatMenu(menus: MenuListData[]) {
   const result: MenuList[] = [];
   const tempArea = new Map<string, MenuList[]>();
 
-  menus.forEach(function({name, id, img, pid, url, koreanName}) {
+  menus.forEach(function({name, id, img, pId, url, koreanName}) {
     const temp: MenuList = {
       label: name,
       koLabel: koreanName,
       key: id,
-      pid,
+      pId,
       url,
     };
 
     img && (temp.icon = renderMenuIcon(img));
 
     // 判断是否有pid 如果pid不为0说明为二级菜单
-    if (pid === '0') {
+    if (pId === '0') {
       // 判断临时区域有没有对应的二级菜单
       const children = tempArea.get(id);
 
@@ -38,16 +38,16 @@ export function formatMenu(menus: MenuListData[]) {
     } else {
       // 如果能在数组中能找到父级菜单直接插入到children中
       // 如果找不到放到临时区域等待父组件挂载
-      const idx = result.findIndex(val => val.key === pid);
+      const idx = result.findIndex(val => val.key === pId);
 
       if (idx >= 0) {
         result[idx].children
           ? result[idx].children!.push(temp)
           : result[idx].children = [temp];
       } else {
-        tempArea.has(pid)
-          ? tempArea.get(pid)!.push(temp)
-          : tempArea.set(pid, [temp]);
+        tempArea.has(pId)
+          ? tempArea.get(pId)!.push(temp)
+          : tempArea.set(pId, [temp]);
       }
     }
   });