Browse Source

✨ feat: 增加用户封禁功能

Pchen0 1 month ago
parent
commit
7018b97736
2 changed files with 75 additions and 2 deletions
  1. 9 0
      src/api/user.js
  2. 66 2
      src/pages/admin/user/userList.vue

+ 9 - 0
src/api/user.js

@@ -8,6 +8,7 @@ const api = {
   GetRepos: '/User/GetRepos',
   AdminUserList: '/Admin/User/GetUserList',
   AdminSetSendCountAutoApprove: '/Admin/User/SetSendCountAutoApprove',
+  AdminSetUserBan: '/Admin/User/SetUserBan',
   AdminChangeLepaoCount: '/Admin/User/ChangeLepaoCount',
   AdminGetReqLog: '/Admin/User/GetReqLog',
   AdminGetReqLogDetail: '/Admin/User/GetReqLogDetail'
@@ -53,6 +54,14 @@ export function adminSetSendCountAutoApprove(parameter) {
   })
 }
 
+export function adminSetUserBan(parameter) {
+  return request({
+    url: api.AdminSetUserBan,
+    method: 'post',
+    data: parameter
+  })
+}
+
 export function BindEmail(parameter) {
   return request({
     url: api.BindEmail,

+ 66 - 2
src/pages/admin/user/userList.vue

@@ -106,6 +106,18 @@
                         @change="(checked) => onSendCountAutoApproveChange(record, checked)"
                     />
                 </template>
+                <template #is_banned_status="{ record }">
+                    <a-tag v-if="isBanned(record)" color="red">已封禁</a-tag>
+                    <a-tag v-else color="green">正常</a-tag>
+                </template>
+                <template #is_banned="{ record }">
+                    <a-switch
+                        :model-value="isBanned(record)"
+                        :loading="banLoadingUuid === record.uuid"
+                        checked-color="rgb(var(--red-6))"
+                        @change="(checked) => onBanChange(record, checked)"
+                    />
+                </template>
                 <template #optional="{ record }">
                     <a-button @click="changeCount(record)">更改次数</a-button>
                 </template>
@@ -132,8 +144,8 @@
 
 <script setup>
 import { ref, reactive, onMounted } from 'vue'
-import { adminGetUserList, adminChangeLepaoCount, adminSetSendCountAutoApprove } from '@/api/user'
-import { Notification, Message } from '@arco-design/web-vue'
+import { adminGetUserList, adminChangeLepaoCount, adminSetSendCountAutoApprove, adminSetUserBan } from '@/api/user'
+import { Notification, Message, Modal } from '@arco-design/web-vue'
 
 const visible = ref(false)
 const ok_loading = ref(false)
@@ -159,8 +171,10 @@ const pagination = reactive({
 const loading = ref(false)
 const data = ref([])
 const whitelistLoadingUuid = ref('')
+const banLoadingUuid = ref('')
 
 const isSendCountAutoApprove = (record) => Number(record?.send_count_auto_approve) === 1
+const isBanned = (record) => Number(record?.is_banned) === 1
 
 const onSendCountAutoApproveChange = async (record, checked) => {
     if (!record?.uuid || whitelistLoadingUuid.value) return
@@ -190,6 +204,48 @@ const onSendCountAutoApproveChange = async (record, checked) => {
     }
 }
 
+const setUserBan = async (record, next) => {
+    banLoadingUuid.value = record.uuid
+    try {
+        const res = await adminSetUserBan({
+            userid: record.uuid,
+            is_banned: next
+        })
+        if (!res || res.code !== 0) {
+            Notification.error({
+                title: '操作失败',
+                content: res?.msg ?? '请稍后再试'
+            })
+            return
+        }
+        record.is_banned = next
+        Message.success(next ? '已封禁该用户' : '已解除封禁')
+    } catch (error) {
+        Notification.error({
+            title: '操作失败',
+            content: error.message || '请稍后再试'
+        })
+    } finally {
+        banLoadingUuid.value = ''
+    }
+}
+
+const onBanChange = async (record, checked) => {
+    if (!record?.uuid || banLoadingUuid.value) return
+    const next = checked === true ? 1 : 0
+    if (next === 1) {
+        Modal.confirm({
+            title: '确认封禁',
+            content: `确定封禁用户「${record.username || record.uuid}」?封禁后该用户将立即下线且无法登录。`,
+            onOk: async () => {
+                await setUserBan(record, next)
+            }
+        })
+        return
+    }
+    await setUserBan(record, 0)
+}
+
 const columns = [
 
     {
@@ -235,6 +291,14 @@ const columns = [
         title: '赠送免审',
         slotName: 'send_count_auto_approve',
         width: 110,
+    }, {
+        title: '账号状态',
+        slotName: 'is_banned_status',
+        width: 100,
+    }, {
+        title: '封禁',
+        slotName: 'is_banned',
+        width: 80,
     }, {
         title: '操作',
         slotName: 'optional',