lejianwen 1 год назад
Родитель
Сommit
529e67095a
3 измененных файлов с 45 добавлено и 5 удалено
  1. 8 0
      src/api/user_token.js
  2. 20 2
      src/views/user/token.js
  3. 17 3
      src/views/user/token.vue

+ 8 - 0
src/api/user_token.js

@@ -14,3 +14,11 @@ export function remove (data) {
14 14
     data,
15 15
   })
16 16
 }
17
+
18
+export function batchRemove (data) {
19
+  return request({
20
+    url: '/user_token/batchDelete',
21
+    method: 'post',
22
+    data,
23
+  })
24
+}

+ 20 - 2
src/views/user/token.js

@@ -1,5 +1,5 @@
1 1
 import { reactive } from 'vue'
2
-import { list, remove } from '@/api/user_token'
2
+import { batchRemove, list, remove } from '@/api/user_token'
3 3
 import { ElMessage, ElMessageBox } from 'element-plus'
4 4
 import { useRoute } from 'vue-router'
5 5
 import { T } from '@/utils/i18n'
@@ -36,7 +36,7 @@ export function useRepositories () {
36 36
   }
37 37
 
38 38
   const del = async (row) => {
39
-    const cf = await ElMessageBox.confirm(T('Confirm?', {param: T('Logout')}), {
39
+    const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('Logout') }), {
40 40
       confirmButtonText: T('Confirm'),
41 41
       cancelButtonText: T('Cancel'),
42 42
       type: 'warning',
@@ -52,11 +52,29 @@ export function useRepositories () {
52 52
     }
53 53
   }
54 54
 
55
+  const batchDelete = async (ids) => {
56
+    const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('BatchDelete') }), {
57
+      confirmButtonText: T('Confirm'),
58
+      cancelButtonText: T('Cancel'),
59
+      type: 'warning',
60
+    }).catch(_ => false)
61
+    if (!cf) {
62
+      return false
63
+    }
64
+
65
+    const res = await batchRemove({ ids }).catch(_ => false)
66
+    if (res) {
67
+      ElMessage.success(T('OperationSuccess'))
68
+      getList()
69
+    }
70
+  }
71
+
55 72
   return {
56 73
     listRes,
57 74
     listQuery,
58 75
     getList,
59 76
     handlerQuery,
60 77
     del,
78
+    batchDelete,
61 79
   }
62 80
 }

+ 17 - 3
src/views/user/token.vue

@@ -13,12 +13,14 @@
13 13
           </el-select>
14 14
         </el-form-item>
15 15
         <el-form-item>
16
-          <el-button type="primary" @click="handlerQuery">{{ T('Filter')}}</el-button>
16
+          <el-button type="primary" @click="handlerQuery">{{ T('Filter') }}</el-button>
17
+          <el-button type="danger" @click="toBatchDelete">{{ T('BatchDelete') }}</el-button>
17 18
         </el-form-item>
18 19
       </el-form>
19 20
     </el-card>
20 21
     <el-card class="list-body" shadow="hover">
21
-      <el-table :data="listRes.list" v-loading="listRes.loading" border>
22
+      <el-table :data="listRes.list" v-loading="listRes.loading" border @selection-change="handleSelectionChange">
23
+        <el-table-column type="selection" align="center" width="50"/>
22 24
         <el-table-column prop="id" label="id" align="center" width="100"/>
23 25
         <el-table-column :label="T('Owner')" align="center">
24 26
           <template #default="{row}">
@@ -56,7 +58,7 @@
56 58
 </template>
57 59
 
58 60
 <script setup>
59
-  import { onActivated, onMounted, watch } from 'vue'
61
+  import { onActivated, onMounted, ref, watch } from 'vue'
60 62
   import { loadAllUsers } from '@/global'
61 63
   import { useRepositories } from '@/views/user/token.js'
62 64
   import { T } from '@/utils/i18n'
@@ -70,6 +72,7 @@
70 72
     getList,
71 73
     handlerQuery,
72 74
     del,
75
+    batchDelete,
73 76
   } = useRepositories()
74 77
 
75 78
   onMounted(getList)
@@ -85,6 +88,17 @@
85 88
     const now = new Date().getTime()
86 89
     return row.expired_at * 1000 < now
87 90
   }
91
+
92
+  const multipleSelection = ref([])
93
+  const handleSelectionChange = (val) => {
94
+    multipleSelection.value = val
95
+  }
96
+  const toBatchDelete = () => {
97
+    if (multipleSelection.value.length === 0) {
98
+      return
99
+    }
100
+    batchDelete(multipleSelection.value.map(v => v.id))
101
+  }
88 102
 </script>
89 103
 
90 104
 <style scoped lang="scss">