team.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div class="team">
  3. <div class="head">
  4. <div class="left">
  5. <p>{{lang.title}}</p>
  6. <p>{{lang.title2}}<span>{{count}}</span>{{lang.title3}}</p>
  7. </div>
  8. <div class="right">
  9. <el-button type="primary" size="small" style="margin-left: 10px" @click="showAdd = true">{{lang.add}}</el-button>
  10. </div>
  11. </div>
  12. <el-table class="table" border :data="list" size="small" v-loading="loading">
  13. <el-table-column prop="id" label="ID" width="100"></el-table-column>
  14. <el-table-column :label="lang.table.nick">
  15. <template slot-scope="scope">
  16. <img :src="scope.row.avatar">
  17. <span>{{scope.row.user_name}}</span>
  18. </template>
  19. </el-table-column>
  20. <el-table-column prop="create_time" :label="lang.table.regTime"></el-table-column>
  21. <el-table-column prop="last_time" :label="lang.table.lastTime"></el-table-column>
  22. <el-table-column prop="role" :label="lang.table.role" width="160"></el-table-column>
  23. <el-table-column prop="statusText" :label="lang.table.status" width="160"></el-table-column>
  24. <el-table-column :label="lang.table.dost" width="160">
  25. <template slot-scope="scope">
  26. <el-tooltip v-if="scope.row.status == 1" class="item" effect="dark" :content="lang.tips9" placement="top">
  27. <el-button type="text" icon="el-icon-unlock" @click="off(scope.row.id, 0)"></el-button>
  28. </el-tooltip>
  29. <el-tooltip v-if="scope.row.status == 0" class="item" effect="dark" :content="lang.tips10" placement="top">
  30. <el-button type="text" icon="el-icon-lock" @click="off(scope.row.id, 1)"></el-button>
  31. </el-tooltip>
  32. <el-tooltip class="item" effect="dark" :content="lang.tips8" placement="top">
  33. <el-button type="text" icon="el-icon-delete" style="margin-left: 20px" @click="del(scope.row.id)"></el-button>
  34. </el-tooltip>
  35. </template>
  36. </el-table-column>
  37. </el-table>
  38. <div class="pagelist">
  39. <el-pagination background :page-size="50" layout="prev, pager, next" :total="count"></el-pagination>
  40. </div>
  41. <el-dialog :title="lang.tips11" append-to-body :visible.sync="showAdd" width="500px" :show-close="false" :before-close="() => {}">
  42. <el-form :model="addForm" label-width="80px" size="small">
  43. <el-form-item :label="lang.tips12">
  44. <el-input v-model="addForm.name" :placeholder="lang.tips13" style="width: 360px"></el-input>
  45. </el-form-item>
  46. <el-form-item :label="lang.tips14">
  47. <el-select v-model="addForm.role" :placeholder="lang.tips15" style="width: 360px">
  48. <el-option :label="lang.tips16" value="2"></el-option>
  49. <el-option :label="lang.tips17" value="1"></el-option>
  50. <el-option :label="lang.tips18" value="0"></el-option>
  51. </el-select>
  52. </el-form-item>
  53. </el-form>
  54. <span slot="footer" class="dialog-footer">
  55. <el-button size="small" @click="cancelAdd">{{lang.tips19}}</el-button>
  56. <el-button size="small" type="primary" @click="add">{{lang.tips20}}</el-button>
  57. </span>
  58. </el-dialog>
  59. </div>
  60. </template>
  61. <script>
  62. import timer from '../tools/timer';
  63. import global from '../tools/global';
  64. export default {
  65. name: 'team',
  66. data (){
  67. return {
  68. key: '',
  69. list: [],
  70. count: 0,
  71. page: 1,
  72. loading: false,
  73. showAdd: false,
  74. addForm: {
  75. name: '',
  76. role: '2'
  77. }
  78. }
  79. },
  80. created (){
  81. this.lang = this.$lang('team');
  82. },
  83. mounted (){
  84. this.getlist();
  85. },
  86. methods: {
  87. // 获取数据列表
  88. getlist (page = 0){
  89. if(page > 0){
  90. this.page = page;
  91. }
  92. this.loading = true;
  93. this.$ajax.get(`/user/list/?page=${this.page}`).then(result => {
  94. console.log(result)
  95. const role = this.lang.role;
  96. this.count = Number(result.count);
  97. this.list = result.list.map(item => {
  98. item.id = Number(item.id) + 1000000;
  99. item.last_time = timer.time('y-m-d h:i:s', item.last_time * 1000);
  100. item.create_time = timer.time('y-m-d h:i:s', item.create_time * 1000);
  101. item.statusText = item.status == 0 ? this.lang.status1 : this.lang.status2;
  102. item.role = role[item.role];
  103. item.avatar = `${global.host}${item.avatar}`;
  104. return item;
  105. })
  106. this.loading = false;
  107. })
  108. },
  109. // 锁定/解锁账户
  110. off (id, status){
  111. this.$ajax.get(`/user/off/?id=${id - 1000000}&status=${status}`).then(result => {
  112. this.$message.success(this.lang.tips1);
  113. this.getlist();
  114. })
  115. },
  116. // 取消添加账户
  117. cancelAdd (){
  118. this.showAdd = false;
  119. this.addForm = {
  120. name: '',
  121. role: '2'
  122. }
  123. },
  124. // 删除
  125. del (id){
  126. this.$confirm(this.lang.tips2, this.lang.tips3, {
  127. confirmButtonText: this.lang.tips5,
  128. cancelButtonText: this.lang.tips4,
  129. type: 'warning'
  130. }).then(() => {
  131. this.$ajax.get(`/user/del/?id=${id - 1000000}`).then(result => {
  132. this.$message.success(this.lang.tips6);
  133. this.getlist(1);
  134. })
  135. }).catch(() => {});
  136. },
  137. // 添加账户
  138. add (){
  139. if(this.addForm.name == ''){
  140. this.$message.warning(this.lang.tips7);
  141. return;
  142. }
  143. this.$ajax.post('/user/add', {
  144. username: this.addForm.name,
  145. role: Number(this.addForm.role)
  146. }).then(result => {
  147. this.showAdd = false;
  148. this.addForm = {
  149. name: '',
  150. role: '2'
  151. }
  152. })
  153. this.getlist(1);
  154. }
  155. }
  156. }
  157. </script>
  158. <style lang="less" scoped>
  159. @import url('../tools/common.less');
  160. .team{
  161. width: calc(100% - 60px);
  162. height: calc(100% - 60px);
  163. padding: 30px;
  164. background: #ffffff;
  165. .head{
  166. display: flex;
  167. justify-content: space-between;
  168. align-items: flex-end;
  169. .left{
  170. p:first-child{
  171. font-size: 18px;
  172. }
  173. p:last-child{
  174. font-size: 14px;
  175. margin-top: 8px;
  176. color: #999999;
  177. span{
  178. color: @color;
  179. }
  180. }
  181. }
  182. .right{
  183. display: flex;
  184. justify-content: flex-end;
  185. align-items: center;
  186. }
  187. }
  188. .table{
  189. width: 100%;
  190. max-height: calc(100% - 160px);
  191. margin-top: 50px;
  192. img{
  193. width: 38px;
  194. height: 38px;
  195. vertical-align: middle;
  196. border-radius: 50%;
  197. margin-right: 10px;
  198. }
  199. }
  200. .pagelist{
  201. text-align: center;
  202. margin-top: 20px;
  203. }
  204. }
  205. </style>