userList.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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-icon
  52. type="edit"
  53. title="编辑"
  54. v-if="record.superAdmin!=1 &&$hasPermissions('B_power_user_edit')"
  55. :style="{fontSize: '20px',color:' #1890FF',padding:' 0 10px'}"
  56. @click="handleEdit(record)"
  57. />
  58. <a-icon
  59. type="unlock"
  60. title="重置密码"
  61. v-if="record.loginFlag==1 && record.superAdmin!=1 &&$hasPermissions('B_power_user_resetPsd')"
  62. :style="{fontSize: '20px',color:' #ffaa00',padding: '0 10px'}"
  63. @click="resetPassword(record)" />
  64. <a-icon
  65. type="delete"
  66. title="删除"
  67. :style="{fontSize: '20px',color: '#f00',padding: '0 10px'}"
  68. v-if="record.loginFlag==0 && record.superAdmin!=1 &&$hasPermissions('B_power_user_del')"
  69. @click="delect(record)"/>
  70. <a-icon
  71. type="setting"
  72. title="分区设置"
  73. v-if="$hasPermissions('B_power_user_set')"
  74. :style="{fontSize: '20px',color:' #00aa00',padding: '0 10px'}"
  75. @click="handleSetting(record)" />
  76. </span>
  77. </s-table>
  78. </a-spin>
  79. <userModal :visible="showModal" @refresh="$refs.table.refresh(true)" :nowData="itemData" @close="closeModal"></userModal>
  80. <!-- 分区设置 -->
  81. <UpdateArea ref="UpdateArea" :openUdModal="openUdModal" @ok="$refs.table.refresh(true)" @close="openUdModal=false"></UpdateArea>
  82. </a-card>
  83. </template>
  84. <script>
  85. import { STable, VSelect } from '@/components'
  86. import userModal from './userModal.vue'
  87. import { resetPSD, updateEnableStatus, getPowerUserList, delectUserPower } from '@/api/power-user.js'
  88. import UpdateArea from './updateAreal.vue'
  89. export default {
  90. name: 'UserList',
  91. components: {
  92. STable, VSelect, userModal, UpdateArea
  93. },
  94. data () {
  95. return {
  96. spinning: false,
  97. tableHeight: 0,
  98. // 查询参数
  99. queryParam: {
  100. name: '',
  101. phone: '',
  102. loginFlag: undefined
  103. },
  104. showModal: false,
  105. openUdModal: false,
  106. itemData: null, // 编辑行数据
  107. // 表头
  108. columns: [
  109. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  110. { title: '创建时间', dataIndex: 'createDate', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  111. { title: '用户名称', dataIndex: 'name', align: 'center', width: '18%', customRender: function (text) { return text || '--' }, ellipsis: true },
  112. { title: '手机号码', dataIndex: 'phone', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  113. { title: '用户账号', dataIndex: 'loginName', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  114. { title: '所属分区', dataIndex: 'allSubareaName', width: '8%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  115. { title: '角色', dataIndex: 'roleNames', width: '18%', align: 'center', customRender: function (text) { return text || '--' } },
  116. { title: '状态', width: '6%', align: 'center', scopedSlots: { customRender: 'status' } },
  117. { title: '操作', width: '12%', align: 'center', scopedSlots: { customRender: 'action' } }
  118. ],
  119. // 加载数据方法 必须为 Promise 对象
  120. loadData: parameter => {
  121. this.spinning = true
  122. return getPowerUserList(Object.assign(parameter, this.queryParam)).then(res => {
  123. const no = (res.data.pageNo - 1) * res.data.pageSize
  124. for (let i = 0; i < res.data.list.length; i++) {
  125. const _item = res.data.list[i]
  126. _item.no = no + i + 1
  127. _item.loginFlag = _item.loginFlag + '' === '1'
  128. }
  129. this.spinning = false
  130. return res.data
  131. })
  132. },
  133. optionAlertShow: false
  134. }
  135. },
  136. methods: {
  137. // 新增
  138. openModal () {
  139. this.showModal = true
  140. this.itemData = null
  141. },
  142. closeModal () {
  143. this.showModal = false
  144. this.itemData = null
  145. },
  146. // 重置
  147. reset () {
  148. this.queryParam.name = ''
  149. this.queryParam.phone = ''
  150. this.queryParam.loginFlag = undefined
  151. this.$refs.table.refresh(true)
  152. },
  153. // 分区设置
  154. handleSetting (row) {
  155. this.openUdModal = true
  156. this.$refs.UpdateArea.setData(row)
  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 - 235
  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>