userList.vue 9.7 KB

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