user.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div>
  3. <t-list ref="list" api="user" select="status" :columns="columns" @dblclick="edit">
  4. <template slot="searchForm" slot-scope="{data}">
  5. <el-form-item>
  6. <el-input placeholder="姓名" size="small" v-model="data.name"/>
  7. </el-form-item>
  8. <el-form-item>
  9. <el-select placeholder="状态" size="small" v-model="data.status">
  10. <el-option label="全部" value="0"></el-option>
  11. <el-option label="正常" value="y"></el-option>
  12. <el-option label="已禁用" value="n"></el-option>
  13. </el-select>
  14. </el-form-item>
  15. </template>
  16. <template slot="bar" slot-scope="{sel, sels}">
  17. <el-button-group>
  18. <t-btn type="add" @click="add"/>
  19. <t-btn type="del" :sels="sels" @click="del"/>
  20. </el-button-group>
  21. <el-button-group>
  22. <t-btn type="enable" :sels="sels" @click="enable"></t-btn>
  23. <t-btn type="disabled" :sels="sels" @click="disabled"></t-btn>
  24. </el-button-group>
  25. <el-button-group>
  26. <el-button type="success" icon="information" size="small" :disabled="!sel" @click="changeAuth(sel)">设置权限</el-button>
  27. <el-button type="info" icon="information" size="small" :disabled="!sel" @click="changePwd(sel)">重置密码</el-button>
  28. </el-button-group>
  29. </template>
  30. </t-list>
  31. <user-edit ref="useredit" @reload="$refs.list.reload()"/>
  32. <user-auth ref="userauth" @reload="$refs.list.reload()"/>
  33. </div>
  34. </template>
  35. <script>
  36. import userEdit from './userEdit'
  37. import userAuth from './userAuth'
  38. export default {
  39. data () {
  40. return {
  41. columns: [
  42. {prop: 'username', label: '账号'},
  43. {prop: 'name', label: '姓名'},
  44. {prop: 'tel', label: '电话'},
  45. {prop: 'age', label: '年龄'},
  46. {prop: 'sex', label: '性别'},
  47. {prop: 'login_time', label: '登陆时间'},
  48. {prop: 'login_ip', label: '登陆ip'},
  49. {label: '状态', doHtml ({row}) {
  50. if (row.status == 'y') {
  51. return '<span class="el-tag el-tag--success">正常</span>'
  52. }
  53. return '<span class="el-tag el-tag--danger">已禁用</span>'
  54. }}
  55. ]
  56. }
  57. },
  58. methods: {
  59. add () {
  60. this.userEdit.show('新增')
  61. },
  62. del (ids) {
  63. this.$confirm('此操作将删除选中的 '+ids.length+' 个用户, 是否继续?', '提示', {
  64. type: 'warning',
  65. confirmButtonText: '确定',
  66. cancelButtonText: '取消'
  67. }).then(() => {
  68. this.$http.delete('user/' + ids.join('_')).then(() => {
  69. this.list.reload()
  70. }, err => {})
  71. }, err => {})
  72. },
  73. edit (r) {
  74. this.$http.get('user/' + r.id).then(data => {
  75. this.userEdit.show('修改', data)
  76. }, err => {})
  77. },
  78. enable (ids) {
  79. this.$http.put('user/enable/' + ids.join('_')).then(() => {
  80. this.list.reload()
  81. })
  82. },
  83. disabled (ids) {
  84. this.$http.put('user/disabled/' + ids.join('_')).then(() => {
  85. this.list.reload()
  86. })
  87. },
  88. changePwd (r) {
  89. this.$prompt('请输入新密码', '修改密码', {
  90. confirmButtonText: '确定',
  91. cancelButtonText: '取消'
  92. }).then(({value}) => {
  93. this.$http.put('user/' + r.id, {password: value}).then(() => {
  94. this.list.reload()
  95. }, err => {})
  96. }, err => {})
  97. },
  98. changeAuth (r) {
  99. this.$http.get('user/auth/' + r.id).then(data => {
  100. this.userAuth.show(r.id, data)
  101. }, err => {})
  102. }
  103. },
  104. mounted () {
  105. this.userEdit = this.$refs.useredit
  106. this.userAuth = this.$refs.userauth
  107. this.list = this.$refs.list
  108. },
  109. components: {userEdit, userAuth}
  110. }
  111. </script>