PermissionList.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <!-- 操作栏 -->
  3. <el-row justify="end">
  4. <el-button @click="openForm">
  5. <Icon class="mr-5px" icon="fluent:people-team-add-20-filled" /> 添加团队成员
  6. </el-button>
  7. <el-button @click="handleUpdate">
  8. <Icon class="mr-5px" icon="ep:edit" />
  9. 编辑
  10. </el-button>
  11. <el-button @click="handleDelete">
  12. <Icon class="mr-5px" icon="ep:delete" />
  13. 移除
  14. </el-button>
  15. <el-button type="danger" @click="handleQuit"> 退出团队</el-button>
  16. </el-row>
  17. <!-- 列表 -->
  18. <ContentWrap class="mt-10px">
  19. <el-table
  20. v-loading="loading"
  21. :data="list"
  22. :show-overflow-tooltip="true"
  23. :stripe="true"
  24. @selection-change="handleSelectionChange"
  25. >
  26. <el-table-column type="selection" width="55" />
  27. <el-table-column align="center" label="姓名" prop="nickname" />
  28. <el-table-column align="center" label="部门" prop="deptName" />
  29. <el-table-column align="center" label="岗位" prop="postNames" />
  30. <el-table-column align="center" label="权限" prop="level">
  31. <template #default="{ row }">
  32. <dict-tag :type="DICT_TYPE.CRM_PERMISSION_LEVEL" :value="row.level" />
  33. </template>
  34. </el-table-column>
  35. <el-table-column
  36. :formatter="dateFormatter"
  37. align="center"
  38. label="加入时间"
  39. prop="createTime"
  40. />
  41. </el-table>
  42. </ContentWrap>
  43. <!-- 表单弹窗:添加/修改 -->
  44. <CrmPermissionForm ref="formRef" @success="getList" />
  45. </template>
  46. <script lang="ts" setup>
  47. import { dateFormatter } from '@/utils/formatTime'
  48. import { DICT_TYPE } from '@/utils/dict'
  49. import * as PermissionApi from '@/api/crm/permission'
  50. import { PermissionLevelEnum } from '@/api/crm/permission'
  51. import { useUserStoreWithOut } from '@/store/modules/user'
  52. import CrmPermissionForm from './PermissionForm.vue'
  53. defineOptions({ name: 'CrmPermissionList' })
  54. const props = defineProps<{
  55. bizType: number // 业务类型
  56. bizId: number // 业务编号
  57. }>()
  58. const message = useMessage() // 消息
  59. const loading = ref(true) // 列表的加载中
  60. const list = ref<PermissionApi.PermissionVO[]>([]) // 列表的数据
  61. /** 查询列表 */
  62. const getList = async () => {
  63. loading.value = true
  64. try {
  65. list.value = await PermissionApi.getPermissionList({
  66. bizType: props.bizType,
  67. bizId: props.bizId
  68. })
  69. } finally {
  70. loading.value = false
  71. }
  72. }
  73. /** 选中团队成员 */
  74. const multipleSelection = ref<PermissionApi.PermissionVO[]>([]) // 选择的团队成员
  75. const handleSelectionChange = (val: PermissionApi.PermissionVO[]) => {
  76. multipleSelection.value = val
  77. }
  78. /** 添加团队成员 */
  79. const formRef = ref<InstanceType<typeof CrmPermissionForm>>() // 权限表单 Ref
  80. const openForm = () => {
  81. formRef.value?.open('create', props.bizType, props.bizId)
  82. }
  83. /** 编辑团队成员 */
  84. const handleUpdate = () => {
  85. if (multipleSelection.value?.length === 0) {
  86. message.warning('请先选择团队成员后操作!')
  87. return
  88. }
  89. const ids = multipleSelection.value?.map((item) => item.id) as number[]
  90. formRef.value?.open('update', props.bizType, props.bizId, ids)
  91. }
  92. /** 移除团队成员 */
  93. const handleDelete = async () => {
  94. if (multipleSelection.value?.length === 0) {
  95. message.warning('请先选择团队成员后操作!')
  96. return
  97. }
  98. // TODO @puhui999:应该有个提示哈
  99. await message.delConfirm()
  100. const ids = multipleSelection.value?.map((item) => item.id)
  101. await PermissionApi.deletePermissionBatch({
  102. bizType: props.bizType,
  103. bizId: props.bizId,
  104. ids
  105. })
  106. }
  107. /** 退出团队 */
  108. const userStore = useUserStoreWithOut() // 用户信息缓存
  109. const handleQuit = async () => {
  110. const permission = list.value.find(
  111. (item) => item.userId === userStore.getUser.id && item.level === PermissionLevelEnum.OWNER
  112. )
  113. if (permission) {
  114. message.warning('负责人不能退出团队!')
  115. return
  116. }
  117. // TODO @puhui999:应该有个提示哈
  118. const userPermission = list.value.find((item) => item.userId === userStore.getUser.id)
  119. await PermissionApi.deleteSelfPermission(userPermission?.id)
  120. }
  121. /** 监听打开的 bizId + bizType,从而加载最新的列表 */
  122. watch(
  123. () => [props.bizId, props.bizType],
  124. () => {
  125. getList()
  126. },
  127. { immediate: true, deep: true }
  128. )
  129. </script>