68ce24908619a078fbeec109d9381629a993e83a.svn-base 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <a-modal
  3. :width="1000"
  4. :title="title"
  5. :visible="innerVisible"
  6. @cancel="handleCancel"
  7. cancelText="关闭"
  8. :okButtonProps="{style:{display:'none'}}"
  9. >
  10. <a-alert type="info" showIcon style="margin-bottom: 16px;">
  11. <template slot="message">
  12. <span>已选择</span>
  13. <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
  14. <span>项</span>
  15. <template v-if="selectedRowKeys.length>0">
  16. <a-divider type="vertical"/>
  17. <a @click="handleClearSelection">清空选择</a>
  18. <a-divider type="vertical"/>
  19. <a @click="handleRevertBatch">批量还原</a>
  20. <a-divider type="vertical"/>
  21. <a @click="handleDeleteBatch">批量删除</a>
  22. </template>
  23. </template>
  24. </a-alert>
  25. <a-table
  26. ref="table"
  27. rowKey="id"
  28. size="middle"
  29. bordered
  30. :columns="columns"
  31. :loading="loading"
  32. :dataSource="dataSource"
  33. :pagination="false"
  34. :rowSelection="{selectedRowKeys, onChange: handleTableSelectChange}"
  35. >
  36. <!-- 显示头像 -->
  37. <template slot="avatarslot" slot-scope="text, record, index">
  38. <div class="anty-img-wrap">
  39. <a-avatar shape="square" :src="url.getAvatar(record.avatar)" icon="user"/>
  40. </div>
  41. </template>
  42. <span slot="action" slot-scope="text, record">
  43. <a @click="handleRevert([record.id])"><a-icon type="redo"/> 还原用户</a>
  44. <a-divider type="vertical"/>
  45. <a @click="handleDelete([record.id])"><a-icon type="delete"/> 彻底删除</a>
  46. </span>
  47. </a-table>
  48. </a-modal>
  49. </template>
  50. <script>
  51. import { putAction,deleteAction,getFileAccessHttpUrl } from "@/api/manage"
  52. // 高度封装的请求,请务必使用 superRequest.call(this,{}) 的方式调用
  53. function superRequest(options) {
  54. this.loading = !!options.loading
  55. options.promise.then(res => {
  56. if (res.success && typeof options.success === 'function') {
  57. options.success(res)
  58. } else {
  59. throw new Error(res.message)
  60. }
  61. }).catch(e => {
  62. console.error('查询已删除的用户失败:', e)
  63. this.$message.warning('查询已删除的用户失败:' + (e.message || e))
  64. }).finally(() => {
  65. this.loading = false
  66. })
  67. }
  68. export default {
  69. name: 'UserRecycleBinModal',
  70. props: {
  71. visible: {
  72. type: Boolean,
  73. default: false
  74. },
  75. },
  76. data() {
  77. return {
  78. title: '用户回收站',
  79. loading: false,
  80. innerVisible: false,
  81. selectedRowKeys: [],
  82. dataSource: [],
  83. columns: [
  84. { title: '#', align: 'center', key: 'rowIndex', width: 80, customRender: (t, r, i) => i + 1 },
  85. { title: '账号', align: 'center', dataIndex: 'username' },
  86. { title: '姓名', align: 'center', dataIndex: 'realname', },
  87. { title: '头像', align: 'center', dataIndex: 'avatar', scopedSlots: { customRender: 'avatarslot' } },
  88. { title: '部门', align: 'center', dataIndex: 'orgCode' },
  89. { title: '操作', align: 'center', dataIndex: 'action', width: 200, scopedSlots: { customRender: 'action' } }
  90. ],
  91. url: {
  92. getAvatar: (path) => getFileAccessHttpUrl(`${path}`),
  93. // 回收站操作,get = 获取列表;put = 取回;delete = 彻底删除
  94. recycleBin: '/sys/user/recycleBin',
  95. putRecycleBin: '/sys/user/putRecycleBin',
  96. deleteRecycleBin: '/sys/user/deleteRecycleBin',
  97. },
  98. }
  99. },
  100. watch: {
  101. visible: {
  102. immediate: true,
  103. handler(val) {
  104. if (val) {
  105. this.loadData()
  106. }
  107. this.innerVisible = val
  108. }
  109. },
  110. innerVisible(val) {
  111. this.$emit('update:visible', val)
  112. },
  113. },
  114. methods: {
  115. loadData() {
  116. superRequest.call(this, {
  117. loading: true,
  118. promise: this.$http.get(this.url.recycleBin),
  119. success: res => this.dataSource = res.result
  120. })
  121. },
  122. handleOk() {
  123. this.loadData()
  124. this.$emit('ok')
  125. },
  126. handleCancel() {
  127. this.innerVisible = false
  128. },
  129. // 还原用户
  130. handleRevert(userIds) {
  131. this.$confirm({
  132. title: '恢复用户',
  133. content: `您确定要恢复这 ${userIds.length} 个用户吗?`,
  134. centered: true,
  135. onOk: () => {
  136. putAction(this.url.putRecycleBin,{userIds:userIds.join(',')}).then((res)=>{
  137. if(res.success){
  138. this.handleOk()
  139. this.handleClearSelection()
  140. this.$message.success(`还原 ${userIds.length} 个用户成功!`)
  141. }
  142. })
  143. }
  144. })
  145. },
  146. // 彻底删除用户
  147. handleDelete(userIds) {
  148. this.$confirm({
  149. title: '彻底删除用户',
  150. content: (<div>
  151. <p>您确定要彻底删除这 {userIds.length} 个用户吗?</p>
  152. <p style="color:red;">注意:彻底删除后将无法恢复,请谨慎操作!</p>
  153. </div>),
  154. centered: true,
  155. onOk: () => {
  156. var that = this;
  157. deleteAction(that.url.deleteRecycleBin, {userIds: userIds.join(',')}).then((res) => {
  158. if (res.success) {
  159. this.loadData()
  160. this.handleClearSelection()
  161. this.$message.success(`彻底删除 ${userIds.length} 个用户成功!`)
  162. } else {
  163. that.$message.warning(res.message);
  164. }
  165. });
  166. },
  167. })
  168. },
  169. handleRevertBatch() {
  170. this.handleRevert(this.selectedRowKeys)
  171. },
  172. handleDeleteBatch() {
  173. this.handleDelete(this.selectedRowKeys)
  174. },
  175. handleClearSelection() {
  176. this.handleTableSelectChange([], [])
  177. },
  178. handleTableSelectChange(selectedRowKeys, selectionRows) {
  179. this.selectedRowKeys = selectedRowKeys
  180. this.selectionRows = selectionRows
  181. },
  182. }
  183. }
  184. </script>
  185. <style lang="less" scoped></style>