userList.vue 9.5 KB

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