userList.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <a-card size="small" :bordered="false">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <div ref="tableSearch" class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  6. <a-row :gutter="15">
  7. <a-col :md="6" :sm="24">
  8. <a-form-item label="用户名称">
  9. <a-input allowClear v-model.trim="queryParam.name" placeholder="请输入用户名称"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="6" :sm="24">
  13. <a-form-item label="手机号码">
  14. <a-input allowClear v-model.trim="queryParam.phone" placeholder="请输入手机号码"/>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="6" :sm="24">
  18. <a-form-item label="状态">
  19. <v-select code="ENABLE_FLAG" v-model="queryParam.loginFlag" allowClear placeholder="请选择状态"></v-select>
  20. </a-form-item>
  21. </a-col>
  22. <a-col :md="4" :sm="24">
  23. <a-button type="primary" @click="$refs.table.refresh(true)" style="margin-right: 10px;">查询</a-button>
  24. <a-button type="" @click="reset" id="roleList-reset">重置</a-button>
  25. </a-col>
  26. </a-row>
  27. </a-form>
  28. </div>
  29. <div class="table-operator">
  30. <a-button type="primary" v-if="$hasPermissions('B_power_user_add')" class="button-error" @click="openModal">新增</a-button>
  31. </div>
  32. <s-table
  33. class="sTable fixPagination"
  34. ref="table"
  35. size="small"
  36. :style="{ height: tableHeight+84.5+'px' }"
  37. rowKey="id"
  38. :columns="columns"
  39. :data="loadData"
  40. :scroll="{ y: tableHeight }"
  41. style="word-break: break-all;"
  42. :defaultLoadData="false"
  43. bordered
  44. >
  45. <span slot="status" slot-scope="text, record">
  46. <!-- 超级管理员不可删除不可编辑不可启禁用 -->
  47. <a-switch v-if="record.superAdmin!=1 && $hasPermissions('B_power_user_enable')" checkedChildren="启用" unCheckedChildren="禁用" v-model="record.loginFlag" @change="changeFlagHandle(text, record)"/>
  48. <span v-else>{{ record.loginFlag==1?'已启用':'已禁用' }}</span>
  49. </span>
  50. <span slot="action" slot-scope="text, record">
  51. <a-button
  52. size="small"
  53. type="link"
  54. class="button-info"
  55. v-if="record.superAdmin!=1 &&$hasPermissions('B_power_user_edit')"
  56. @click="handleEdit(record)"
  57. >
  58. 编辑
  59. </a-button>
  60. <a-button
  61. size="small"
  62. type="link"
  63. class="button-info"
  64. v-if="record.loginFlag==1 && record.superAdmin!=1 &&$hasPermissions('B_power_user_resetPsd')"
  65. @click="resetPassword(record)"
  66. >
  67. 重置密码
  68. </a-button>
  69. <a-button
  70. size="small"
  71. type="link"
  72. class="button-error"
  73. v-if="record.loginFlag==0 && record.superAdmin!=1 &&$hasPermissions('B_power_user_del')"
  74. @click="delect(record)"
  75. >
  76. 删除
  77. </a-button>
  78. </span>
  79. </s-table>
  80. </a-spin>
  81. <userModal :visible="showModal" @refresh="$refs.table.refresh(true)" :nowData="itemData" @close="closeModal"></userModal>
  82. </a-card>
  83. </template>
  84. <script>
  85. import { commonMixin } from '@/utils/mixin'
  86. import { STable, VSelect } from '@/components'
  87. import userModal from './userModal.vue'
  88. import { resetPSD, updateEnableStatus, getPowerUserList, delectUserPower } from '@/api/power-user.js'
  89. export default {
  90. name: 'PowerUserList',
  91. mixins: [commonMixin],
  92. components: {
  93. STable, VSelect, userModal
  94. },
  95. data () {
  96. return {
  97. spinning: false,
  98. tableHeight: 0,
  99. // 查询参数
  100. queryParam: {
  101. name: '',
  102. phone: '',
  103. loginFlag: undefined
  104. },
  105. showModal: false,
  106. openUdModal: false,
  107. itemData: null, // 编辑行数据
  108. // 表头
  109. columns: [
  110. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  111. { title: '创建时间', dataIndex: 'createDate', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  112. { title: '用户名称', dataIndex: 'name', align: 'center', width: '23%', customRender: function (text) { return text || '--' }, ellipsis: true },
  113. { title: '手机号码', dataIndex: 'phone', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  114. { title: '用户账号', dataIndex: 'loginName', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  115. { title: '所属分区', dataIndex: 'allSubareaName', width: '8%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  116. { title: '角色', dataIndex: 'roleNames', width: '23%', align: 'center', customRender: function (text) { return text || '--' } },
  117. { title: '状态', width: '6%', align: 'center', scopedSlots: { customRender: 'status' } },
  118. { title: '操作', width: '10%', align: 'center', scopedSlots: { customRender: 'action' } }
  119. ],
  120. // 加载数据方法 必须为 Promise 对象
  121. loadData: parameter => {
  122. this.spinning = true
  123. return getPowerUserList(Object.assign(parameter, this.queryParam)).then(res => {
  124. let data
  125. if (res.status == 200) {
  126. data = res.data
  127. const no = (data.pageNo - 1) * data.pageSize
  128. for (let i = 0; i < data.list.length; i++) {
  129. const _item = data.list[i]
  130. _item.no = no + i + 1
  131. _item.loginFlag = _item.loginFlag + '' === '1'
  132. }
  133. }
  134. this.spinning = false
  135. return data
  136. })
  137. },
  138. optionAlertShow: false
  139. }
  140. },
  141. methods: {
  142. // 新增
  143. openModal () {
  144. this.showModal = true
  145. this.itemData = null
  146. },
  147. closeModal () {
  148. this.showModal = false
  149. this.itemData = null
  150. },
  151. // 重置
  152. reset () {
  153. this.queryParam.name = ''
  154. this.queryParam.phone = ''
  155. this.queryParam.loginFlag = undefined
  156. this.$refs.table.refresh(true)
  157. },
  158. // 重置密码
  159. resetPassword (row) {
  160. const _this = this
  161. this.$confirm({
  162. title: '提示',
  163. content: '确认重置密码吗?',
  164. centered: true,
  165. onOk () {
  166. _this.spinning = true
  167. resetPSD({
  168. id: row.id
  169. }).then(res => {
  170. if (res.status == 200) {
  171. _this.$message.success(res.message)
  172. _this.$refs.table.refresh()
  173. _this.spinning = false
  174. } else {
  175. _this.spinning = false
  176. }
  177. })
  178. }
  179. })
  180. },
  181. // 删除
  182. delect (row) {
  183. const _this = this
  184. this.$confirm({
  185. title: '警告',
  186. content: '删除后无法恢复,确认删除?',
  187. centered: true,
  188. onOk () {
  189. _this.spinning = true
  190. delectUserPower({
  191. id: row.id
  192. }).then(res => {
  193. if (res.status == 200) {
  194. _this.$message.success(res.message)
  195. _this.$refs.table.refresh()
  196. _this.spinning = false
  197. } else {
  198. _this.$message.error(res.message)
  199. _this.spinning = false
  200. }
  201. })
  202. }
  203. })
  204. },
  205. handleEdit (row) {
  206. this.showModal = true
  207. this.itemData = row
  208. },
  209. // 修改状态
  210. changeFlagHandle (text, record) {
  211. const _data = {
  212. id: record.id,
  213. flag: record.loginFlag ? '1' : '0'
  214. }
  215. this.spinning = true
  216. updateEnableStatus(_data).then(res => {
  217. if (res.status == 200) {
  218. this.$message.success(res.message)
  219. this.$refs.table.refresh()
  220. this.spinning = false
  221. } else {
  222. this.$refs.table.refresh()
  223. this.spinning = false
  224. }
  225. })
  226. },
  227. pageInit () {
  228. const _this = this
  229. this.$nextTick(() => { // 页面渲染完成后的回调
  230. _this.setTableH()
  231. })
  232. },
  233. setTableH () {
  234. const tableSearchH = this.$refs.tableSearch.offsetHeight
  235. this.tableHeight = window.innerHeight - tableSearchH - 245
  236. }
  237. },
  238. watch: {
  239. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  240. this.setTableH()
  241. }
  242. },
  243. mounted () {
  244. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  245. this.pageInit()
  246. this.reset()
  247. }
  248. },
  249. activated () {
  250. // 如果是新页签打开,则重置当前页面
  251. if (this.$store.state.app.isNewTab) {
  252. this.pageInit()
  253. this.reset()
  254. }
  255. // 仅刷新列表,不重置页面
  256. if (this.$store.state.app.updateList) {
  257. this.pageInit()
  258. this.$refs.table.refresh()
  259. }
  260. }
  261. }
  262. </script>