feat: 添加管理员用户封禁和解封功能,优化用户管理体验
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { createAuthClient } from 'better-auth/client';
|
import { createAuthClient } from 'better-auth/client';
|
||||||
import { twoFactorClient, usernameClient } from 'better-auth/client/plugins';
|
import { adminClient, twoFactorClient, usernameClient } from 'better-auth/client/plugins';
|
||||||
import { getToken } from '@/store/modules/auth/shared';
|
import { getToken } from '@/store/modules/auth/shared';
|
||||||
import { request } from '../request';
|
import { request } from '../request';
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ export const authClient = createAuthClient({
|
|||||||
token: () => getToken()
|
token: () => getToken()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: [usernameClient(), twoFactorClient()]
|
plugins: [usernameClient(), twoFactorClient(), adminClient()]
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { h, useTemplateRef } from 'vue';
|
import { h, useTemplateRef } from 'vue';
|
||||||
import { useDialog } from 'naive-ui';
|
import { useDialog, useMessage } from 'naive-ui';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { client, safeClient } from '@/service/api';
|
import { authClient, client, safeClient } from '@/service/api';
|
||||||
import type { TableBaseColumns, TableFetchData, TableFilterColumns, TableInst } from '@/components/table';
|
import type { TableBaseColumns, TableFetchData, TableFilterColumns, TableInst } from '@/components/table';
|
||||||
import UserSelect from '@/components/common/user-select.vue';
|
import UserSelect from '@/components/common/user-select.vue';
|
||||||
import Wallet from './components/wallet.vue';
|
import Wallet from './components/wallet.vue';
|
||||||
@@ -14,7 +14,7 @@ import Kyc from './components/kyc.vue';
|
|||||||
import Ledger from './components/ledger.vue';
|
import Ledger from './components/ledger.vue';
|
||||||
|
|
||||||
const dialog = useDialog();
|
const dialog = useDialog();
|
||||||
|
const message = useMessage();
|
||||||
const tableInst = useTemplateRef<TableInst>('tableInst');
|
const tableInst = useTemplateRef<TableInst>('tableInst');
|
||||||
|
|
||||||
const fetchData: TableFetchData = ({ pagination, filter }) => {
|
const fetchData: TableFetchData = ({ pagination, filter }) => {
|
||||||
@@ -164,6 +164,42 @@ const columns: TableBaseColumns = [
|
|||||||
content: () => h(Ledger, { userId: row.id })
|
content: () => h(Ledger, { userId: row.id })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
contentText: row.banned === false ? '封禁' : '解封',
|
||||||
|
size: 'small',
|
||||||
|
type: row.banned === false ? 'error' : 'success',
|
||||||
|
ghost: true,
|
||||||
|
onClick: () => {
|
||||||
|
dialog.warning({
|
||||||
|
title: row.banned === false ? '封禁用户' : '解封用户',
|
||||||
|
content:
|
||||||
|
row.banned === false
|
||||||
|
? '确认解封该用户吗?解封后用户将恢复正常使用。'
|
||||||
|
: '确认封禁该用户吗?封禁后用户将无法登录和使用相关服务。',
|
||||||
|
positiveText: '确认',
|
||||||
|
negativeText: '取消',
|
||||||
|
onPositiveClick: async () => {
|
||||||
|
if (row.banned === true) {
|
||||||
|
await safeClient(() =>
|
||||||
|
authClient.admin.unbanUser({
|
||||||
|
userId: row.id
|
||||||
|
})
|
||||||
|
);
|
||||||
|
message.success('该用户已被成功解封。');
|
||||||
|
tableInst.value?.reload();
|
||||||
|
} else {
|
||||||
|
await safeClient(() =>
|
||||||
|
authClient.admin.banUser({
|
||||||
|
userId: row.id
|
||||||
|
})
|
||||||
|
);
|
||||||
|
message.success('该用户已被成功封禁。');
|
||||||
|
tableInst.value?.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user