refactor: chat user
This commit is contained in:
parent
f2f6f82240
commit
fef23579ac
@ -19,6 +19,13 @@ const getUserGroupList: (resource: ChatUserResourceParams, loading?: Ref<boolean
|
|||||||
return get(`${prefix.value}/${resource.resource_type}/${resource.resource_id}/user_group`, undefined, loading)
|
return get(`${prefix.value}/${resource.resource_type}/${resource.resource_id}/user_group`, undefined, loading)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改用户组列表授权
|
||||||
|
*/
|
||||||
|
const editUserGroupList: (resource: ChatUserResourceParams, data: { user_group_id: string, is_auth: boolean }[], loading?: Ref<boolean>) => Promise<Result<any>> = (resource, data, loading) => {
|
||||||
|
return put(`${prefix}/${resource.resource_type}/${resource.resource_id}/user_group`, data, undefined, loading)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户组的用户列表
|
* 获取用户组的用户列表
|
||||||
*/
|
*/
|
||||||
@ -50,6 +57,7 @@ const putUserGroupUser: (
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
getUserGroupList,
|
getUserGroupList,
|
||||||
|
editUserGroupList,
|
||||||
getUserGroupUserList,
|
getUserGroupUserList,
|
||||||
putUserGroupUser
|
putUserGroupUser
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,7 +55,7 @@ const postAddMember: (
|
|||||||
*/
|
*/
|
||||||
const postRemoveMember: (
|
const postRemoveMember: (
|
||||||
user_group_id: string,
|
user_group_id: string,
|
||||||
body: string[],
|
body: any,
|
||||||
loading?: Ref<boolean>,
|
loading?: Ref<boolean>,
|
||||||
) => Promise<Result<any>> = (user_group_id, body, loading) => {
|
) => Promise<Result<any>> = (user_group_id, body, loading) => {
|
||||||
return post(`${prefix}/${user_group_id}/remove_member`, body, {}, loading)
|
return post(`${prefix}/${user_group_id}/remove_member`, body, {}, loading)
|
||||||
|
|||||||
@ -40,7 +40,7 @@
|
|||||||
{{ paginationConfig.total }}
|
{{ paginationConfig.total }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<el-button type="primary" @click="handleSave">
|
<el-button type="primary" :disabled="current?.is_auth" @click="handleSave">
|
||||||
{{ t('common.save') }}
|
{{ t('common.save') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
@ -50,12 +50,13 @@
|
|||||||
<el-select class="complex-search__left" v-model="searchType" style="width: 120px">
|
<el-select class="complex-search__left" v-model="searchType" style="width: 120px">
|
||||||
<el-option :label="$t('views.login.loginForm.username.label')" value="name" />
|
<el-option :label="$t('views.login.loginForm.username.label')" value="name" />
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-input v-if="searchType === 'name'" v-model="searchForm.name"
|
<el-input v-if="searchType === 'name'" v-model="searchForm.name" @change="getList"
|
||||||
@change="getList" :placeholder="$t('common.inputPlaceholder')" style="width: 220px" clearable />
|
:placeholder="$t('common.inputPlaceholder')" style="width: 220px" clearable />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex align-center">
|
<div class="flex align-center">
|
||||||
<div class="color-secondary mr-8">{{ $t('views.chatUser.autoAuthorization') }}</div>
|
<div class="color-secondary mr-8">{{ $t('views.chatUser.autoAuthorization') }}</div>
|
||||||
<el-switch size="small" v-model="automaticAuthorization"></el-switch>
|
<el-switch size="small" :model-value="current?.is_auth" @click="changeAuth"
|
||||||
|
:loading="loading"></el-switch>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -82,11 +83,12 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column :width="140" align="center">
|
<el-table-column :width="140" align="center">
|
||||||
<template #header>
|
<template #header>
|
||||||
<el-checkbox :model-value="allChecked" :indeterminate="allIndeterminate" :disabled="disabled"
|
<el-checkbox :model-value="allChecked" :indeterminate="allIndeterminate" :disabled="current?.is_auth"
|
||||||
@change="handleCheckAll">{{ $t('views.chatUser.authorization') }}</el-checkbox>
|
@change="handleCheckAll">{{ $t('views.chatUser.authorization')
|
||||||
|
}}</el-checkbox>
|
||||||
</template>
|
</template>
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-checkbox v-model="row.enable" :indeterminate="row.indeterminate" :disabled="disabled"
|
<el-checkbox v-model="row.is_auth" :indeterminate="row.indeterminate" :disabled="current?.is_auth"
|
||||||
@change="(value: boolean) => handleRowChange(value, row)" />
|
@change="(value: boolean) => handleRowChange(value, row)" />
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
@ -104,12 +106,11 @@ import { t } from '@/locales'
|
|||||||
import type { ChatUserGroupItem, ChatUserResourceParams, ChatUserGroupUserItem } from '@/api/type/workspaceChatUser'
|
import type { ChatUserGroupItem, ChatUserResourceParams, ChatUserGroupUserItem } from '@/api/type/workspaceChatUser'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { ChatUserResourceEnum } from '@/enums/workspaceChatUser'
|
import { ChatUserResourceEnum } from '@/enums/workspaceChatUser'
|
||||||
|
import { MsgSuccess } from '@/utils/message'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const resource: ChatUserResourceParams = { resource_id: route.params.id as string, resource_type: route.meta.resourceType as ChatUserResourceEnum }
|
const resource: ChatUserResourceParams = { resource_id: route.params.id as string, resource_type: route.meta.resourceType as ChatUserResourceEnum }
|
||||||
|
|
||||||
const disabled = computed(() => false) // TODO
|
|
||||||
|
|
||||||
const filterText = ref('')
|
const filterText = ref('')
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const list = ref<ChatUserGroupItem[]>([])
|
const list = ref<ChatUserGroupItem[]>([])
|
||||||
@ -148,13 +149,24 @@ function clickUserGroup(item: ChatUserGroupItem) {
|
|||||||
current.value = item
|
current.value = item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function changeAuth() {
|
||||||
|
const params = [{ user_group_id: current.value?.id as string, is_auth: !current.value?.is_auth }]
|
||||||
|
try {
|
||||||
|
await ChatUserApi.editUserGroupList(resource, params, loading)
|
||||||
|
await getUserGroupList()
|
||||||
|
current.value = { name: current.value?.name as string, id: current.value?.id as string, is_auth: !current.value?.is_auth }
|
||||||
|
getList()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const rightLoading = ref(false)
|
const rightLoading = ref(false)
|
||||||
|
|
||||||
const searchType = ref('name')
|
const searchType = ref('name')
|
||||||
const searchForm = ref<Record<string, any>>({
|
const searchForm = ref<Record<string, any>>({
|
||||||
name: '',
|
name: '',
|
||||||
})
|
})
|
||||||
const automaticAuthorization = ref(false)
|
|
||||||
const paginationConfig = reactive({
|
const paginationConfig = reactive({
|
||||||
current_page: 1,
|
current_page: 1,
|
||||||
page_size: 20,
|
page_size: 20,
|
||||||
@ -205,6 +217,7 @@ async function handleSave() {
|
|||||||
try {
|
try {
|
||||||
const params = tableData.value.map(item => ({ chat_user_id: item.id, is_auth: item.is_auth }))
|
const params = tableData.value.map(item => ({ chat_user_id: item.id, is_auth: item.is_auth }))
|
||||||
await ChatUserApi.putUserGroupUser(resource, current.value?.id as string, params, rightLoading)
|
await ChatUserApi.putUserGroupUser(resource, current.value?.id as string, params, rightLoading)
|
||||||
|
MsgSuccess(t('common.saveSuccess'))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,7 +78,7 @@
|
|||||||
<div class="flex-between mb-16" style="margin-top: 20px;">
|
<div class="flex-between mb-16" style="margin-top: 20px;">
|
||||||
<div>
|
<div>
|
||||||
<el-button type="primary" @click="createUser()">
|
<el-button type="primary" @click="createUser()">
|
||||||
{{ t('views.userManage.createUser') }}
|
{{ t('views.role.member.add') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button :disabled="multipleSelection.length === 0" @click="handleDeleteUser()">
|
<el-button :disabled="multipleSelection.length === 0" @click="handleDeleteUser()">
|
||||||
{{ $t('common.delete') }}
|
{{ $t('common.delete') }}
|
||||||
@ -132,7 +132,7 @@
|
|||||||
</el-card>
|
</el-card>
|
||||||
</ContentContainer>
|
</ContentContainer>
|
||||||
<CreateOrUpdateGroupDialog ref="createOrUpdateGroupDialogRef" @refresh="refresh" />
|
<CreateOrUpdateGroupDialog ref="createOrUpdateGroupDialogRef" @refresh="refresh" />
|
||||||
<CreateGroupUserDialog ref="createGroupUserDialogRef" @refresh="getUserGroupList" />
|
<CreateGroupUserDialog ref="createGroupUserDialogRef" @refresh="getList" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
@ -256,22 +256,22 @@ function createUser() {
|
|||||||
createGroupUserDialogRef.value?.open(current.value?.id);
|
createGroupUserDialogRef.value?.open(current.value?.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const multipleSelection = ref<string[]>([])
|
const multipleSelection = ref<any[]>([])
|
||||||
function handleSelectionChange(val: string[]) {
|
function handleSelectionChange(val: any[]) {
|
||||||
multipleSelection.value = val
|
multipleSelection.value = val
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDeleteUser(item?: ChatUserGroupUserItem) {
|
function handleDeleteUser(item?: ChatUserGroupUserItem) {
|
||||||
MsgConfirm(
|
MsgConfirm(
|
||||||
item ? `${t('views.workspace.member.delete.confirmTitle')}${item.nick_name} ?` : '',
|
item ? `${t('views.workspace.member.delete.confirmTitle')}${item.nick_name} ?` : t('views.chatUser.group.batchDeleteMember', { count: multipleSelection.value.length }),
|
||||||
t('views.chatUser.group.batchDeleteMember', { number: multipleSelection.value.length }),
|
'',
|
||||||
{
|
{
|
||||||
confirmButtonText: t('common.confirm'),
|
confirmButtonText: t('common.confirm'),
|
||||||
confirmButtonClass: 'danger',
|
confirmButtonClass: 'danger',
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
SystemGroupApi.postRemoveMember(current.value?.id as string, item ? [item.id] : multipleSelection.value, loading).then(async () => {
|
SystemGroupApi.postRemoveMember(current.value?.id as string, { group_relation_ids: item ? [item.id] : multipleSelection.value.map(item => (item.id)) }, loading).then(async () => {
|
||||||
MsgSuccess(t('common.deleteSuccess'))
|
MsgSuccess(t('common.deleteSuccess'))
|
||||||
await getList()
|
await getList()
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user