You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.1 KiB

7 days ago
  1. <script setup lang="ts">
  2. import { delUser, userList } from 'apis/user'
  3. import Edit from 'components/user/Edit/index.vue'
  4. import { ElMessageBox } from 'element-plus'
  5. import { FtMessage } from 'libs/message'
  6. import { cloneDeep } from 'lodash'
  7. import { useSystemStore } from 'stores/systemStore'
  8. import { useTemplateRef } from 'vue'
  9. const systemStore = useSystemStore()
  10. const btnList = systemStore.systemStatus.currentUser?.fixedUser === 'ENABLE'
  11. ? [
  12. {
  13. name: '新增',
  14. type: 'primary',
  15. serverUrl: 'add',
  16. serverCondition: 0,
  17. },
  18. {
  19. name: '编辑',
  20. type: 'primary',
  21. serverUrl: 'edit',
  22. serverCondition: 1,
  23. },
  24. {
  25. name: '删除',
  26. type: 'danger',
  27. serverUrl: 'del',
  28. serverCondition: 2,
  29. },
  30. ]
  31. : []
  32. const columns = [
  33. {
  34. type: 'selection',
  35. selectable: (row: any) => {
  36. return (row.fixedUser !== 'ENABLE') || row.username === systemStore.systemStatus.currentUser?.username
  37. },
  38. },
  39. {
  40. title: '账号',
  41. key: 'username',
  42. },
  43. {
  44. title: '用户名',
  45. key: 'nickname',
  46. },
  47. ]
  48. const tableRef = useTemplateRef('tableRef')
  49. const del = async (selectedRows: any) => {
  50. const ids = selectedRows.map((item: any) => item.id)
  51. await ElMessageBox.confirm('确定删除当前选中的行?', '消息', {
  52. confirmButtonText: '确认',
  53. cancelButtonText: '取消',
  54. type: 'warning',
  55. })
  56. await delUser(ids)
  57. FtMessage.success('删除成功')
  58. tableRef.value?.initData()
  59. }
  60. const addVisible = ref(false)
  61. const currentData = ref({})
  62. const addHandle = () => {
  63. currentData.value = {}
  64. addVisible.value = true
  65. }
  66. const editHandle = (data: any) => {
  67. currentData.value = cloneDeep(data[0])
  68. console.log(currentData.value)
  69. addVisible.value = true
  70. }
  71. </script>
  72. <template lang="pug">
  73. div
  74. FtTable(ref="tableRef", has-header, has-page, :columns="columns", :btn-list="btnList", :get-data-fn="userList", @add="addHandle", @edit="editHandle", @del="del")
  75. Edit(v-if="addVisible", :data="currentData", @ok="addVisible = false;tableRef?.initData()", @cancel="addVisible = false")
  76. </template>