userList.vue 9.0 KB

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