userList.vue 9.2 KB

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