userList.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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="{ x: 1350, 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="showModal = false"></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: 70, align: 'center' },
  110. { title: '创建时间', dataIndex: 'createDate', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  111. { title: '用户名称', dataIndex: 'name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  112. { title: '手机号码', dataIndex: 'phone', width: 150, align: 'center', customRender: function (text) { return text || '--' } },
  113. { title: '用户账号', dataIndex: 'loginName', width: 150, align: 'center', customRender: function (text) { return text || '--' } },
  114. { title: '所属分区', dataIndex: 'allSubareaName', width: 150, align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  115. { title: '角色', dataIndex: 'roleNames', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
  116. { title: '状态', width: 100, align: 'center', scopedSlots: { customRender: 'status' }, fixed: 'right' },
  117. { title: '操作', width: 160, align: 'center', scopedSlots: { customRender: 'action' }, fixed: 'right' }
  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. // 重置
  143. reset () {
  144. this.queryParam.name = ''
  145. this.queryParam.phone = ''
  146. this.queryParam.loginFlag = undefined
  147. this.$refs.table.refresh(true)
  148. },
  149. // 分区设置
  150. handleSetting (row) {
  151. this.openUdModal = true
  152. this.$refs.UpdateArea.setData(row)
  153. },
  154. // 重置密码
  155. resetPassword (row) {
  156. const _this = this
  157. this.$confirm({
  158. title: '提示',
  159. content: '确认重置密码吗?',
  160. centered: true,
  161. onOk () {
  162. _this.spinning = true
  163. resetPSD({
  164. id: row.id
  165. }).then(res => {
  166. if (res.status == 200) {
  167. _this.$message.success(res.message)
  168. _this.$refs.table.refresh()
  169. _this.spinning = false
  170. } else {
  171. _this.spinning = false
  172. }
  173. })
  174. }
  175. })
  176. },
  177. // 删除
  178. delect (row) {
  179. const _this = this
  180. this.$confirm({
  181. title: '警告',
  182. content: '删除后无法恢复,确认删除?',
  183. centered: true,
  184. onOk () {
  185. _this.spinning = true
  186. delectUserPower({
  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.$message.error(res.message)
  195. _this.spinning = false
  196. }
  197. })
  198. }
  199. })
  200. },
  201. handleEdit (row) {
  202. this.showModal = true
  203. this.itemData = row
  204. },
  205. // 修改状态
  206. changeFlagHandle (text, record) {
  207. const _data = {
  208. id: record.id,
  209. flag: record.loginFlag ? '1' : '0'
  210. }
  211. this.spinning = true
  212. updateEnableStatus(_data).then(res => {
  213. if (res.status == 200) {
  214. this.$message.success(res.message)
  215. this.$refs.table.refresh()
  216. this.spinning = false
  217. } else {
  218. this.$refs.table.refresh()
  219. this.spinning = false
  220. }
  221. })
  222. },
  223. pageInit () {
  224. const _this = this
  225. this.$nextTick(() => { // 页面渲染完成后的回调
  226. _this.setTableH()
  227. })
  228. },
  229. setTableH () {
  230. const tableSearchH = this.$refs.tableSearch.offsetHeight
  231. this.tableHeight = window.innerHeight - tableSearchH - 235
  232. }
  233. },
  234. mounted () {
  235. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  236. this.pageInit()
  237. this.reset()
  238. }
  239. },
  240. activated () {
  241. // 如果是新页签打开,则重置当前页面
  242. if (this.$store.state.app.isNewTab) {
  243. this.pageInit()
  244. this.reset()
  245. }
  246. }
  247. }
  248. </script>