group_list.vue 4.1 KB

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