weijin 4 лет назад
Родитель
Сommit
accec634b1
1 измененных файлов с 58 добавлено и 9 удалено
  1. 58 9
      pages/admin/userAdmin.vue

+ 58 - 9
pages/admin/userAdmin.vue

@@ -29,15 +29,24 @@
       <el-table-column
         prop="state"
         label="状态"
-        width="100">
+        width="80">
+      </el-table-column>
+      <el-table-column
+        fixed="right"
+        label="封号"
+        width="50">
+        <template slot-scope="scope">
+          <el-button @click="block(scope.row)" type="text" size="small" v-if="scope.row.valid">封禁</el-button>
+          <el-button @click="unblock(scope.row)" type="text" size="small" v-else>解封</el-button>
+        </template>
       </el-table-column>
       <el-table-column
         fixed="right"
         label="操作"
         width="100">
         <template slot-scope="scope">
-          <el-button @click="block(scope.row)" type="text" size="small" v-if="scope.row.isValid">封禁</el-button>
-          <el-button @click="unblock(scope.row)" type="text" size="small" v-else>解封</el-button>
+          <el-button @click="setSEEC(scope.row)" type="text" size="small" v-if="scope.row.role==='STUDENT'">设为开发人员</el-button>
+          <el-button @click="setStudent(scope.row)" type="text" size="small" v-else-if="scope.row.role==='SEEC'">恢复为普通用户</el-button>
         </template>
       </el-table-column>
     </el-table>
@@ -60,11 +69,11 @@ export default {
   },
   methods: {
     getUsers () {
-      this.$api.$get('/admin/users').then((res) => {
+      this.$api.$get('/admin/getUsers').then((res) => {
         console.log('users', res.data)
         if (res.code === 0) {
           for (const item of res.data) {
-            if (item.isValid) {
+            if (item.valid) {
               item.state = '正常'
             } else {
               item.state = '封禁中'
@@ -84,14 +93,14 @@ export default {
       })
     },
     block (row) {
-      this.$api.$put('/admin/user', { id: row.id, isValid: false }).then((res) => {
+      this.$api.$post('/admin/updateUserValid', { id: row.id, valid: false }).then((res) => {
         if (res.code === 0) {
           this.$message({
             showClose: true,
             message: '已封禁用户' + row.name,
             type: 'success'
           })
-          row.isValid = false
+          row.valid = false
           row.state = '封禁中'
         } else {
           this.$message({
@@ -106,14 +115,14 @@ export default {
       })
     },
     unblock (row) {
-      this.$api.$put('/admin/user', { id: row.id, isValid: true }).then((res) => {
+      this.$api.$post('/admin/updateUserValid', { id: row.id, valid: true }).then((res) => {
         if (res.code === 0) {
           this.$message({
             showClose: true,
             message: '已解封用户' + row.name,
             type: 'success'
           })
-          row.isValid = true
+          row.valid = true
           row.state = '正常'
         } else {
           this.$message({
@@ -126,6 +135,46 @@ export default {
       ).catch((e) => {
         console.log(e)
       })
+    },
+    setSEEC (row) {
+      this.$api.$post('/admin/updateUserRole', { id: row.id, role: 'SEEC' }).then((res) => {
+        if (res.code === 0) {
+          this.$message({
+            showClose: true,
+            message: row.name + '已设置为开发人员',
+            type: 'success'
+          })
+          row.role = 'SEEC'
+        } else {
+          this.$message({
+            showClose: true,
+            message: res.message,
+            type: 'error'
+          })
+        }
+      }).catch((e) => {
+        console.log(e)
+      })
+    },
+    setStudent (row) {
+      this.$api.$post('/admin/updateUserRole', { id: row.id, role: 'STUDENT' }).then((res) => {
+        if (res.code === 0) {
+          this.$message({
+            showClose: true,
+            message: row.name + '已恢复为普通用户',
+            type: 'success'
+          })
+          row.role = 'STUDENT'
+        } else {
+          this.$message({
+            showClose: true,
+            message: res.message,
+            type: 'error'
+          })
+        }
+      }).catch((e) => {
+        console.log(e)
+      })
     }
   }
 }