list.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <BodyPanlHeader>
  3. <a-button type="primary" @click="addMaterial()">新建备注</a-button>
  4. <div>
  5. <a-input-search
  6. v-model:value="filterName"
  7. style="width: 280px"
  8. placeholder="请输入笔记名称"
  9. @search="updateMaterials"
  10. />
  11. </div>
  12. </BodyPanlHeader>
  13. <BodyPanlBody>
  14. <a-table
  15. :data-source="materials"
  16. :columns="materialColumns"
  17. :pagination="pagination"
  18. >
  19. <template #bodyCell="{ column }">
  20. <template v-if="column.key === 'action'">
  21. <div class="table-actions">
  22. <a>查看</a>
  23. </div>
  24. </template>
  25. </template>
  26. </a-table>
  27. </BodyPanlBody>
  28. </template>
  29. <script lang="ts" setup>
  30. import EditMember from './edit.vue'
  31. import { ref, reactive, computed } from 'vue'
  32. import { BodyPanlHeader, BodyPanlBody } from '@/layout/panl'
  33. import { useRealtime } from '@/hook'
  34. import { router } from '@/router'
  35. import { renderModal } from '@/helper'
  36. import { materialColumns as baseColumns } from './columns'
  37. import {
  38. fetchMembers,
  39. checkMemberUserName,
  40. addMember,
  41. updateMember
  42. } from '@/api'
  43. import type { Member } from '@/api'
  44. const materialColumns = [
  45. ...baseColumns,
  46. {
  47. title: '操作',
  48. dataIndex: 'action',
  49. key: 'action'
  50. }
  51. ]
  52. const filterName = ref('')
  53. const projectId = computed(() => Number(router.currentRoute.value.params.id))
  54. const pagination = reactive({
  55. current: 1,
  56. total: 0,
  57. pageSize: 12,
  58. onChange: (current: number) => {
  59. pagination.current = current
  60. updateMaterials()
  61. }
  62. })
  63. const [materials, updateMaterials] = useRealtime(async () => {
  64. const result = await fetchMembers({
  65. userName: filterName.value,
  66. projectId: projectId.value,
  67. pageNum: pagination.current,
  68. pageSize: pagination.pageSize
  69. })
  70. pagination.total = result.total
  71. return result.list
  72. }, [])
  73. const addMaterial = () => {
  74. renderModal(EditMember, {
  75. async onSave(member) {
  76. if (member.teamId) {
  77. await updateMember(member as Member)
  78. } else {
  79. await checkMemberUserName(member.userName)
  80. await addMember(projectId.value, member)
  81. }
  82. await updateMaterials()
  83. }
  84. })
  85. }
  86. </script>