index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div class="container">
  3. <template v-if="userFormDataState">
  4. <div class="head-title">
  5. <span> {{ route.meta.title }} </span>
  6. <div class="form-row">
  7. <a-input
  8. v-model="formData.username"
  9. style="margin: 0 0.6rem"
  10. placeholder="请输入用户名称"
  11. />
  12. <a-button
  13. type="primary"
  14. style="margin: 0 0.6rem"
  15. @click="intData"
  16. >
  17. <template #icon>
  18. <icon-search />
  19. </template>
  20. 查询
  21. </a-button>
  22. <a-button type="primary" @click="evReturnAdd">新增账号</a-button>
  23. </div>
  24. </div>
  25. <a-table :data="dataSource" :columns="columns" :scroll="{ x: 'auto' }" >
  26. <template #roleList="{ record }">
  27. <a-tag v-for="item in record.roleList" :key="item.id" style="margin:0 0 2px 4px;">{{ item.name }}</a-tag>
  28. </template>
  29. <template #state="{ record }">
  30. <a-popconfirm
  31. :content="`确认要${record.state === '1'? '禁用' : '开启'}${record.username}用户吗?`"
  32. ok-text="确定"
  33. cancel-text="取消"
  34. @ok="evSwitchStatus(record)"
  35. >
  36. <div>
  37. <a-switch v-model="record.state" style="pointer-events: none" checked-value="1" unchecked-value="0" />
  38. </div>
  39. </a-popconfirm>
  40. </template>
  41. <template #id="{ record }">
  42. <a class="a-link" href="javascript:;" style="margin-right: 1rem" @click="evEdit(record)">编辑</a>
  43. <a-popconfirm content="确认删除该信息?" ok-text="确定" cancel-text="取消" @ok="evDelete(record.id)">
  44. <a href="javascript:;" class="a-link">删除</a>
  45. </a-popconfirm>
  46. </template>
  47. </a-table>
  48. </template>
  49. <!-- <svg-icon icon="menu-bangong1" ></svg-icon> -->
  50. <userFormData
  51. v-else
  52. :data="userManagementAddData"
  53. @return-main="evReturnMain"
  54. />
  55. </div>
  56. </template>
  57. <script setup>
  58. import { onMounted, ref, h } from "vue";
  59. import { useRoute } from "vue-router";
  60. import { columns } from "./config";
  61. import userFormData from "./form.vue";
  62. import { Message, Notification } from '@arco-design/web-vue'
  63. import { userList, deleteUserItem, systemFindRoleList, updateUserState } from '@/api/path/system.api'
  64. const route = useRoute();
  65. const formData = ref({
  66. username: ''
  67. });
  68. // const editState = ref(false);
  69. const userManagementAddData = ref({})
  70. const userFormDataState = ref(true);
  71. const dataSource = ref([]);
  72. const pagination = ref({
  73. total: 0,
  74. pageSize: 10,
  75. current: 1,
  76. })
  77. const evReturnMain = (state = true) => {
  78. intData()
  79. userFormDataState.value = state
  80. }
  81. const evReturnAdd = () => {
  82. userFormDataState.value = false;
  83. userManagementAddData.value = {}
  84. evReturnMain(false);
  85. };
  86. const evEdit = (e) => {
  87. userManagementAddData.value = e
  88. userManagementAddData.value.passwordState = true
  89. userFormDataState.value = true
  90. evReturnMain(false)
  91. }
  92. const evSwitchStatus = async (e) =>{
  93. await updateUserState({
  94. id:e.id,
  95. state: e.state == 1 ? 0 : 1,
  96. })
  97. Message.success({
  98. content: '操作成功',
  99. duration: 2000,
  100. })
  101. intData()
  102. }
  103. const intData = async () => {
  104. // const { username } = formData.value
  105. const param = {
  106. current: pagination.value.current,
  107. size: pagination.value.pageSize,
  108. ...formData.value
  109. }
  110. const { data:roleList } = await systemFindRoleList({})
  111. const { data } = await userList(param)
  112. dataSource.value = data.records.map(item =>{
  113. item.roleList = roleList.filter(cItem =>{
  114. return item.roleIds.includes(cItem.id)
  115. })
  116. return item
  117. })
  118. pagination.value.total = data.total
  119. }
  120. const evDelete = async (id) =>{
  121. await deleteUserItem({id})
  122. intData()
  123. }
  124. onMounted(() => {
  125. intData()
  126. })
  127. </script>
  128. <style scoped lang="less">
  129. .container {
  130. .head-title {
  131. display: flex;
  132. justify-content: space-between;
  133. }
  134. .form-row {
  135. display: flex;
  136. }
  137. }
  138. </style>