userList.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. for (let i = 0; i < data.list.length; i++) {
  119. const _item = data.list[i]
  120. _item.no = no + i + 1
  121. _item.loginFlag = _item.loginFlag + '' === '1'
  122. }
  123. }
  124. this.spinning = false
  125. return data
  126. })
  127. },
  128. optionAlertShow: false,
  129. showSyncModal: false // 同步账号编辑弹框
  130. }
  131. },
  132. methods: {
  133. // 新增
  134. openModal () {
  135. this.itemData = null
  136. this.showModal = true
  137. },
  138. // 关闭弹框
  139. handleUserCancel () {
  140. this.showModal = false
  141. this.itemData = null
  142. },
  143. // 重置
  144. reset () {
  145. this.queryParam.name = ''
  146. this.queryParam.phone = ''
  147. this.queryParam.loginFlag = undefined
  148. this.$refs.table.refresh(true)
  149. },
  150. // 重置密码
  151. resetPassword (row) {
  152. const _this = this
  153. this.$confirm({
  154. title: '提示',
  155. content: '确认重置密码吗?',
  156. centered: true,
  157. onOk () {
  158. _this.spinning = true
  159. resetPSD({
  160. id: row.id
  161. }).then(res => {
  162. if (res.status == 200) {
  163. _this.$message.success(res.message)
  164. _this.$refs.table.refresh()
  165. _this.spinning = false
  166. } else {
  167. _this.spinning = false
  168. }
  169. })
  170. }
  171. })
  172. },
  173. // 删除
  174. delect (row) {
  175. const _this = this
  176. this.$confirm({
  177. title: '警告',
  178. content: '删除后无法恢复,确认删除?',
  179. centered: true,
  180. onOk () {
  181. _this.spinning = true
  182. delectUserPower({
  183. id: row.id
  184. }).then(res => {
  185. if (res.status == 200) {
  186. _this.$message.success(res.message)
  187. _this.$refs.table.refresh()
  188. _this.spinning = false
  189. } else {
  190. _this.$message.error(res.message)
  191. _this.spinning = false
  192. }
  193. })
  194. }
  195. })
  196. },
  197. handleEdit (row) {
  198. this.itemData = row
  199. if (row.ownerOrgFlag == 1) { // 自建
  200. this.showModal = true
  201. } else { // 同步过来的,非自建
  202. this.showSyncModal = true
  203. }
  204. },
  205. // 关闭弹框 同步账号
  206. handleCancel () {
  207. this.itemData = null
  208. this.showSyncModal = false
  209. },
  210. // 修改状态
  211. changeFlagHandle (text, record) {
  212. const _data = {
  213. id: record.id,
  214. flag: record.loginFlag ? '1' : '0'
  215. }
  216. this.spinning = true
  217. updateEnableStatus(_data).then(res => {
  218. if (res.status == 200) {
  219. this.$message.success(res.message)
  220. this.$refs.table.refresh()
  221. this.spinning = false
  222. } else {
  223. this.$refs.table.refresh()
  224. this.spinning = false
  225. }
  226. })
  227. },
  228. pageInit () {
  229. const _this = this
  230. this.$nextTick(() => { // 页面渲染完成后的回调
  231. _this.setTableH()
  232. })
  233. },
  234. setTableH () {
  235. const tableSearchH = this.$refs.tableSearch.offsetHeight
  236. this.tableHeight = window.innerHeight - tableSearchH - 235
  237. }
  238. },
  239. watch: {
  240. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  241. this.setTableH()
  242. }
  243. },
  244. mounted () {
  245. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  246. this.pageInit()
  247. this.reset()
  248. }
  249. },
  250. activated () {
  251. // 如果是新页签打开,则重置当前页面
  252. if (this.$store.state.app.isNewTab) {
  253. this.pageInit()
  254. this.reset()
  255. }
  256. }
  257. }
  258. </script>