mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 10:02:46 +00:00
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)
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户组列表授权
|
||||
*/
|
||||
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 {
|
||||
getUserGroupList,
|
||||
editUserGroupList,
|
||||
getUserGroupUserList,
|
||||
putUserGroupUser
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ const postAddMember: (
|
|||
*/
|
||||
const postRemoveMember: (
|
||||
user_group_id: string,
|
||||
body: string[],
|
||||
body: any,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<any>> = (user_group_id, body, loading) => {
|
||||
return post(`${prefix}/${user_group_id}/remove_member`, body, {}, loading)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
{{ paginationConfig.total }}
|
||||
</span>
|
||||
</div>
|
||||
<el-button type="primary" @click="handleSave">
|
||||
<el-button type="primary" :disabled="current?.is_auth" @click="handleSave">
|
||||
{{ t('common.save') }}
|
||||
</el-button>
|
||||
</div>
|
||||
|
|
@ -50,12 +50,13 @@
|
|||
<el-select class="complex-search__left" v-model="searchType" style="width: 120px">
|
||||
<el-option :label="$t('views.login.loginForm.username.label')" value="name" />
|
||||
</el-select>
|
||||
<el-input v-if="searchType === 'name'" v-model="searchForm.name"
|
||||
@change="getList" :placeholder="$t('common.inputPlaceholder')" style="width: 220px" clearable />
|
||||
<el-input v-if="searchType === 'name'" v-model="searchForm.name" @change="getList"
|
||||
:placeholder="$t('common.inputPlaceholder')" style="width: 220px" clearable />
|
||||
</div>
|
||||
<div class="flex align-center">
|
||||
<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>
|
||||
|
||||
|
|
@ -82,11 +83,12 @@
|
|||
</el-table-column>
|
||||
<el-table-column :width="140" align="center">
|
||||
<template #header>
|
||||
<el-checkbox :model-value="allChecked" :indeterminate="allIndeterminate" :disabled="disabled"
|
||||
@change="handleCheckAll">{{ $t('views.chatUser.authorization') }}</el-checkbox>
|
||||
<el-checkbox :model-value="allChecked" :indeterminate="allIndeterminate" :disabled="current?.is_auth"
|
||||
@change="handleCheckAll">{{ $t('views.chatUser.authorization')
|
||||
}}</el-checkbox>
|
||||
</template>
|
||||
<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)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
|
@ -104,12 +106,11 @@ import { t } from '@/locales'
|
|||
import type { ChatUserGroupItem, ChatUserResourceParams, ChatUserGroupUserItem } from '@/api/type/workspaceChatUser'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ChatUserResourceEnum } from '@/enums/workspaceChatUser'
|
||||
import { MsgSuccess } from '@/utils/message'
|
||||
|
||||
const route = useRoute()
|
||||
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 loading = ref(false)
|
||||
const list = ref<ChatUserGroupItem[]>([])
|
||||
|
|
@ -148,13 +149,24 @@ function clickUserGroup(item: ChatUserGroupItem) {
|
|||
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 searchType = ref('name')
|
||||
const searchForm = ref<Record<string, any>>({
|
||||
name: '',
|
||||
})
|
||||
const automaticAuthorization = ref(false)
|
||||
const paginationConfig = reactive({
|
||||
current_page: 1,
|
||||
page_size: 20,
|
||||
|
|
@ -205,6 +217,7 @@ async function handleSave() {
|
|||
try {
|
||||
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)
|
||||
MsgSuccess(t('common.saveSuccess'))
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@
|
|||
<div class="flex-between mb-16" style="margin-top: 20px;">
|
||||
<div>
|
||||
<el-button type="primary" @click="createUser()">
|
||||
{{ t('views.userManage.createUser') }}
|
||||
{{ t('views.role.member.add') }}
|
||||
</el-button>
|
||||
<el-button :disabled="multipleSelection.length === 0" @click="handleDeleteUser()">
|
||||
{{ $t('common.delete') }}
|
||||
|
|
@ -132,7 +132,7 @@
|
|||
</el-card>
|
||||
</ContentContainer>
|
||||
<CreateOrUpdateGroupDialog ref="createOrUpdateGroupDialogRef" @refresh="refresh" />
|
||||
<CreateGroupUserDialog ref="createGroupUserDialogRef" @refresh="getUserGroupList" />
|
||||
<CreateGroupUserDialog ref="createGroupUserDialogRef" @refresh="getList" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
|
|
@ -256,22 +256,22 @@ function createUser() {
|
|||
createGroupUserDialogRef.value?.open(current.value?.id);
|
||||
}
|
||||
|
||||
const multipleSelection = ref<string[]>([])
|
||||
function handleSelectionChange(val: string[]) {
|
||||
const multipleSelection = ref<any[]>([])
|
||||
function handleSelectionChange(val: any[]) {
|
||||
multipleSelection.value = val
|
||||
}
|
||||
|
||||
function handleDeleteUser(item?: ChatUserGroupUserItem) {
|
||||
MsgConfirm(
|
||||
item ? `${t('views.workspace.member.delete.confirmTitle')}${item.nick_name} ?` : '',
|
||||
t('views.chatUser.group.batchDeleteMember', { number: multipleSelection.value.length }),
|
||||
item ? `${t('views.workspace.member.delete.confirmTitle')}${item.nick_name} ?` : t('views.chatUser.group.batchDeleteMember', { count: multipleSelection.value.length }),
|
||||
'',
|
||||
{
|
||||
confirmButtonText: t('common.confirm'),
|
||||
confirmButtonClass: 'danger',
|
||||
},
|
||||
)
|
||||
.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'))
|
||||
await getList()
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue