userList.vue 9.7 KB

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