UserList.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <div class="content-container">
  3. <el-row class="tool-bar">
  4. <el-col :span="6" class="left">
  5. <div class="content-title">
  6. {{ title }}
  7. </div>
  8. </el-col>
  9. <el-col :span="16" class="right">
  10. <el-input v-model="conditions.keywords" class="search-input m-right-15" placeholder="请输入内容">
  11. <el-button slot="append" icon="el-icon-search" @click="getData()" />
  12. </el-input>
  13. <el-button type="primary" @click="handleAddUser">新增用户</el-button>
  14. </el-col>
  15. </el-row>
  16. <el-row class="content-body">
  17. <el-table v-loading="listLoading" class="page-table" :data="dataList" height="calc(100vh - 240px)">
  18. <el-table-column type="index" align="center" label="序号" width="70" />
  19. <el-table-column align="center" header-align="center" label="头像" width="50">
  20. <template v-slot="{row}">
  21. <el-avatar :size="30" :src="row.accountAvatar" />
  22. </template>
  23. </el-table-column>
  24. <el-table-column align="center" width="100" label="账号">
  25. <template v-slot="{row}">
  26. <span>{{ row.accountName }}</span>
  27. </template>
  28. </el-table-column>
  29. <el-table-column align="center" width="100" label="姓名">
  30. <template v-slot="{row}">
  31. <span>{{ row.accountRealName }}</span>
  32. </template>
  33. </el-table-column>
  34. <el-table-column align="center" width="100" label="工号">
  35. <template v-slot="{row}">
  36. <span>{{ row.accountStaffNo }}</span>
  37. </template>
  38. </el-table-column>
  39. <el-table-column align="center" width="120" label="联系方式">
  40. <template v-slot="{row}">
  41. <span>{{ row.accountPhone }}</span>
  42. </template>
  43. </el-table-column>
  44. <el-table-column align="center" label="所在部门">
  45. <template v-slot="{row}">
  46. <span>{{ row.groupName }}</span>
  47. </template>
  48. </el-table-column>
  49. <!-- <el-table-column align="center" width="100" label="岗位">
  50. <template v-slot="{row}">
  51. <span>{{ row.positionName }}</span>
  52. </template>
  53. </el-table-column> -->
  54. <el-table-column align="center" label="状态" width="140">
  55. <template v-slot="{row}">
  56. <div v-if="row.isFixed !== 1">
  57. <el-switch
  58. v-model="row.status"
  59. active-text="正常"
  60. inactive-text="锁定"
  61. :active-value="1"
  62. :inactive-value="2"
  63. @change="(status)=>handlerChangeUserStatus(status, row)"
  64. />
  65. </div>
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="操作" header-align="center" align="center" width="210">
  69. <template v-slot="{row}">
  70. <el-button size="mini" @click="handleEditUser(row)">修改</el-button>
  71. <el-button v-if="row.isFixed !== 1" size="mini" type="danger" @click="handleDeleteUser(row)">删除</el-button>
  72. <el-dropdown v-if="row.isFixed !== 1" class="el-dropdown-link" @command="(command)=>handlerCommand(command, row)">
  73. <el-button size="mini" type="primary">
  74. 更多<i class="el-icon-arrow-down el-icon--right" />
  75. </el-button>
  76. <el-dropdown-menu slot="dropdown">
  77. <template v-if="row.grantGroupId > 0">
  78. <el-dropdown-item command="editGrantGroup">编辑授权</el-dropdown-item>
  79. <el-dropdown-item command="delGrantGroup">解除授权</el-dropdown-item>
  80. </template>
  81. <template v-else>
  82. <el-dropdown-item command="addGrantGroup">添加授权</el-dropdown-item>
  83. </template>
  84. <el-dropdown-item command="resetPwd">重置密码</el-dropdown-item>
  85. <el-dropdown-item command="handlePermit">权限配置</el-dropdown-item>
  86. </el-dropdown-menu>
  87. </el-dropdown>
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. <div class="pagination-container">
  92. <pagination v-show="total>0" :total="total" :page.sync="conditions.page" :limit.sync="conditions.limit" @pagination="getData" />
  93. </div>
  94. </el-row>
  95. <user ref="AddUser" @formSuccess="getData" />
  96. <user ref="EditUser" title="编辑用户" @formSuccess="getData" />
  97. <grant-group ref="AddGrantGroup" title="添加授权" @formSuccess="getData" />
  98. <grant-group ref="EditGrantGroup" title="变更授权" @formSuccess="getData" />
  99. <account-permit ref="AccountPermit" title="权限配置" />
  100. </div>
  101. </template>
  102. <script>
  103. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  104. import AccountPermit from '@/views/system/permit/account'
  105. import GrantGroup from './GrantGroup.vue'
  106. import User from './User.vue'
  107. import { deleteUserById, getUserByPage, resetPassword, updateUserStatus } from '@/api/system/userApi'
  108. import { mapGetters } from 'vuex'
  109. export default {
  110. name: 'UserList',
  111. components: { Pagination, User, GrantGroup, AccountPermit },
  112. props: { },
  113. data() {
  114. return {
  115. title: '用户管理',
  116. dataList: [],
  117. total: 0,
  118. listLoading: false,
  119. conditions: {
  120. page: 1,
  121. limit: 10,
  122. keyword: '',
  123. groupId: null,
  124. groupName: ''
  125. }
  126. }
  127. },
  128. computed: {
  129. ...mapGetters([
  130. 'userData'
  131. ])
  132. },
  133. mounted() {
  134. },
  135. methods: {
  136. // Change User "Status"
  137. handlerChangeUserStatus(status, data) {
  138. updateUserStatus(data.accountId, status).then((resp) => {
  139. const { code, msg } = resp
  140. if (code === 0) {
  141. this.$message.success(msg)
  142. } else {
  143. this.$message.error(msg)
  144. }
  145. }).catch((error) => {
  146. console.log(error)
  147. })
  148. },
  149. // Command Handling
  150. handlerCommand(command, data) {
  151. switch (command) {
  152. case 'addGrantGroup':
  153. this.$refs['AddGrantGroup'].showAddModel(data.accountId)
  154. break
  155. case 'editGrantGroup':
  156. this.$refs['EditGrantGroup'].showEditModel(data.accountId)
  157. break
  158. case 'delGrantGroup':
  159. this.handleDelGrantGroup(data)
  160. break
  161. case 'resetPwd':
  162. this.handleResetPassword(data)
  163. break
  164. case 'handlePermit':
  165. this.handlePermit(data)
  166. break
  167. }
  168. },
  169. // Load Data
  170. loadData(groupId, groupName) {
  171. this.conditions.groupId = groupId
  172. this.conditions.groupName = groupName
  173. this.getData()
  174. },
  175. // Fetch User Data
  176. getData() {
  177. this.listLoading = true
  178. getUserByPage(this.conditions).then((resp) => {
  179. this.listLoading = false
  180. const { code, data, total, msg } = resp
  181. if (code === 0) {
  182. this.total = total
  183. this.dataList = data
  184. } else {
  185. this.$message.error(msg)
  186. }
  187. }).catch((error) => {
  188. console.log(error)
  189. })
  190. },
  191. // Click "Add"
  192. handleAddUser() {
  193. const groupId = this.conditions.groupId
  194. const groupName = this.conditions.groupName
  195. this.$refs['AddUser'].showAddModel(groupId, groupName)
  196. },
  197. // Click "Edit"
  198. handleEditUser(data) {
  199. const groupId = data.groupId
  200. const accountId = data.accountId
  201. this.$refs['EditUser'].showEditModel(groupId, accountId)
  202. },
  203. // Click "Reset Password"
  204. handleResetPassword(data) {
  205. this.$confirm('温馨提示:系统默认重置密码为 888888', '提示', {
  206. confirmButtonText: '确定',
  207. cancelButtonText: '取消',
  208. type: 'warning'
  209. }).then(() => {
  210. resetPassword(data.accountId).then((resp) => {
  211. const { code, msg } = resp
  212. if (code === 0) {
  213. this.$message.success(msg)
  214. } else {
  215. this.$message.error(msg)
  216. }
  217. })
  218. }).catch(() => {
  219. this.$message.info('已取消重置')
  220. })
  221. },
  222. // 权限管理
  223. handlePermit(data) {
  224. const { accountId, positionId } = data
  225. this.$refs['AccountPermit'].showModel(accountId, positionId)
  226. },
  227. // Click "Delete" User
  228. handleDeleteUser(data) {
  229. this.$confirm('此操作将永久删除该账号, 是否继续?', '提示', {
  230. confirmButtonText: '确定',
  231. cancelButtonText: '取消',
  232. type: 'warning'
  233. }).then(() => {
  234. deleteUserById(data.accountId).then((resp) => {
  235. const { code, msg } = resp
  236. if (code === 0) {
  237. this.getData()
  238. this.$message.success(msg)
  239. } else {
  240. this.$message.error(msg)
  241. }
  242. })
  243. }).catch(() => {
  244. this.$message.info('已取消操作')
  245. })
  246. }
  247. }
  248. }
  249. </script>
  250. <style scoped>
  251. .content-container {
  252. margin: 10px 10px 10px 0 ;
  253. }
  254. </style>