group_list.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div id="withdraw">
  3. <!-- <el-select @change="changeSelect" v-model="selectValue" placeholder="请选择">
  4. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  5. </el-select>-->
  6. <div class="table">
  7. <el-table
  8. v-if="tableData.length"
  9. height="100%"
  10. border
  11. style="width: 100%"
  12. :data="tableData"
  13. :row-class-name="tableRowClassName"
  14. >
  15. <el-table-column
  16. v-for="(prop, index) of tableProps"
  17. :key="index"
  18. :prop="prop"
  19. :label="tableHeaders[index]"
  20. >
  21. <template slot-scope="scope">
  22. <el-button
  23. type="text"
  24. v-if="prop === 'nickname'"
  25. @click="clickUID(scope.row)"
  26. >{{scope.row[prop]}}</el-button>
  27. <el-button
  28. v-else-if="prop === 'ctrl' && scope.row['status'] !== '1'"
  29. type="text"
  30. @click="clickSuper(scope.row)"
  31. >超管查看</el-button>
  32. <span v-else>{{scope.row[prop]}}</span>
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. </div>
  37. <el-pagination
  38. @current-change="getTableData"
  39. :current-page.sync="currentPage"
  40. :page-size="pageSize"
  41. layout="total, prev, pager, next"
  42. :total="totalCount"
  43. ></el-pagination>
  44. </div>
  45. </template>
  46. <script>
  47. const tableHeaders = [
  48. "创建者",
  49. "群组ID",
  50. "群组名称",
  51. "管理人员",
  52. "关联工作",
  53. "创建时间",
  54. "最近更新",
  55. "操作",
  56. ]
  57. const tableProps = [
  58. "nickname",
  59. "id",
  60. "name",
  61. "managers",
  62. "jobs",
  63. "create_date",
  64. "update_date",
  65. "ctrl",
  66. ]
  67. export default {
  68. data() {
  69. return {
  70. options: [
  71. {
  72. value: -1,
  73. label: '全部'
  74. },
  75. {
  76. value: 0,
  77. label: '提交'
  78. },
  79. {
  80. value: 1,
  81. label: '成功'
  82. },
  83. {
  84. value: 2,
  85. label: '失败'
  86. },
  87. {
  88. value: 3,
  89. label: '进行中'
  90. },
  91. ],
  92. selectValue: -1,
  93. // 数据总条目
  94. totalCount: 0,
  95. currentPage: 1,
  96. // 列表头显示内容
  97. tableHeaders,
  98. // 列表头字段
  99. tableProps,
  100. // 列表数据
  101. tableData: [],
  102. env: `test`,
  103. isSuper: false,
  104. pageSize: 20,
  105. };
  106. },
  107. computed: {
  108. isTest() {
  109. return this.env === `test`
  110. }
  111. },
  112. mounted() {
  113. this.getTableData()
  114. },
  115. methods: {
  116. changeSelect(status) {
  117. this.getTableData()
  118. },
  119. // 点击超管
  120. async clickSuper(row) {
  121. if(!this.isSuper) {
  122. this.$message({
  123. message: `不是超管, 没有权限`
  124. })
  125. return
  126. }
  127. if(this.isTest) window.open(`https://dev.test.proginn.com/rooter/loginmember?uid=${row.uid}&next=/group/${row.id}`)
  128. else window.open(`https://www.proginn.com/rooter/loginmember?uid=${row.uid}&next=/group/${row.id}`)
  129. },
  130. // 点击用户的 uid
  131. clickUID(row) {
  132. // todo...
  133. if(this.isTest) window.open(`https://dev.test.proginn.com/rooter/user/${row.uid}`)
  134. else window.open(`https://www.proginn.com/rooter/user/${row.uid}`)
  135. },
  136. // 根据状态显示图表样式
  137. tableRowClassName({ row, rowIndex }) {
  138. let className = ""
  139. if(row.status === "1") className = "success-row"
  140. return className
  141. },
  142. // 格式化列表数据
  143. formatTableData(data) {
  144. return data.map(i => ({
  145. ...i,
  146. managers: (i.managers.map(m => {
  147. return m ? m.nickname : ``
  148. })).join(`;`),
  149. jobs: (Object.keys(i.jobs).map(key => {
  150. let j = i.jobs[key]
  151. return j ? `${j.nickname}(${j.id})` : ``
  152. })).join(`;`)
  153. }));
  154. },
  155. // 获取列表数据
  156. async getTableData(page = this.currentPage) {
  157. this.tableData = []
  158. const res = await this.$post("/api/admin/group/list", { page, page_size: 20 })
  159. const data = res.data
  160. this.env = data.current_env
  161. this.isSuper = data.is_super_admin
  162. this.tableData = this.formatTableData(data.list)
  163. this.totalCount = Number(data.total)
  164. this.totalPage = data.totalPage
  165. }
  166. }
  167. };
  168. </script>
  169. <style scoped>
  170. .table {
  171. height: calc(100% - 40px);
  172. }
  173. </style>