2024-05-15 16:55:37 +08:00
|
|
|
|
<!-- chat 角色仓库 -->
|
|
|
|
|
<template>
|
|
|
|
|
<el-container class="role-container">
|
2024-05-25 10:54:04 +08:00
|
|
|
|
<ChatRoleForm ref="formRef" @success="handlerAddRoleSuccess" />
|
2024-05-17 15:30:50 +08:00
|
|
|
|
<!-- header -->
|
2024-05-25 10:54:04 +08:00
|
|
|
|
<Header title="角色仓库" style="position: relative" />
|
2024-05-17 15:30:50 +08:00
|
|
|
|
<!-- main -->
|
2024-05-15 16:55:37 +08:00
|
|
|
|
<el-main class="role-main">
|
2024-05-15 23:12:53 +08:00
|
|
|
|
<div class="search-container">
|
2024-05-15 23:11:40 +08:00
|
|
|
|
<!-- 搜索按钮 -->
|
|
|
|
|
<el-input
|
2024-05-17 15:30:50 +08:00
|
|
|
|
:loading="loading"
|
2024-05-15 23:11:40 +08:00
|
|
|
|
v-model="search"
|
|
|
|
|
class="search-input"
|
|
|
|
|
size="default"
|
|
|
|
|
placeholder="请输入搜索的内容"
|
|
|
|
|
:suffix-icon="Search"
|
|
|
|
|
@change="getActiveTabsRole"
|
|
|
|
|
/>
|
2024-05-25 10:54:04 +08:00
|
|
|
|
<el-button
|
|
|
|
|
v-if="activeRole == 'my-role'"
|
|
|
|
|
type="primary"
|
|
|
|
|
@click="handlerAddRole"
|
|
|
|
|
style="margin-left: 20px"
|
|
|
|
|
>
|
|
|
|
|
<!-- TODO @fan:下面两个 icon,可以使用类似 <Icon icon="ep:question-filled" /> 替代哈 -->
|
2024-05-17 15:30:50 +08:00
|
|
|
|
<el-icon>
|
2024-05-25 10:54:04 +08:00
|
|
|
|
<User />
|
2024-05-17 15:30:50 +08:00
|
|
|
|
</el-icon>
|
2024-05-15 23:11:40 +08:00
|
|
|
|
添加角色
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
2024-05-15 18:31:07 +08:00
|
|
|
|
<!-- tabs -->
|
|
|
|
|
<el-tabs v-model="activeRole" class="tabs" @tab-click="handleTabsClick">
|
2024-05-15 18:16:00 +08:00
|
|
|
|
<el-tab-pane class="role-pane" label="我的角色" name="my-role">
|
2024-05-17 15:30:50 +08:00
|
|
|
|
<RoleList
|
|
|
|
|
:loading="loading"
|
|
|
|
|
:role-list="myRoleList"
|
2024-05-21 11:40:15 +08:00
|
|
|
|
:show-more="true"
|
2024-05-17 15:30:50 +08:00
|
|
|
|
@on-delete="handlerCardDelete"
|
|
|
|
|
@on-edit="handlerCardEdit"
|
|
|
|
|
@on-use="handlerCardUse"
|
|
|
|
|
@on-page="handlerCardPage('my')"
|
2024-05-25 10:54:04 +08:00
|
|
|
|
style="margin-top: 20px"
|
|
|
|
|
/>
|
2024-05-15 16:55:37 +08:00
|
|
|
|
</el-tab-pane>
|
|
|
|
|
<el-tab-pane label="公共角色" name="public-role">
|
2024-05-17 15:30:50 +08:00
|
|
|
|
<RoleCategoryList
|
|
|
|
|
class="role-category-list"
|
|
|
|
|
:category-list="categoryList"
|
|
|
|
|
:active="activeCategory"
|
|
|
|
|
@on-category-click="handlerCategoryClick"
|
|
|
|
|
/>
|
|
|
|
|
<RoleList
|
|
|
|
|
:role-list="publicRoleList"
|
|
|
|
|
@on-delete="handlerCardDelete"
|
|
|
|
|
@on-edit="handlerCardEdit"
|
2024-05-21 22:07:56 +08:00
|
|
|
|
@on-use="handlerCardUse"
|
2024-05-17 15:30:50 +08:00
|
|
|
|
@on-page="handlerCardPage('public')"
|
2024-05-25 10:54:04 +08:00
|
|
|
|
style="margin-top: 20px"
|
|
|
|
|
loading
|
|
|
|
|
/>
|
2024-05-15 16:55:37 +08:00
|
|
|
|
</el-tab-pane>
|
|
|
|
|
</el-tabs>
|
|
|
|
|
</el-main>
|
|
|
|
|
</el-container>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2024-05-25 10:54:04 +08:00
|
|
|
|
import { ref } from 'vue'
|
2024-05-15 16:55:37 +08:00
|
|
|
|
import Header from '@/views/ai/chat/components/Header.vue'
|
|
|
|
|
import RoleList from './RoleList.vue'
|
2024-05-15 23:11:40 +08:00
|
|
|
|
import ChatRoleForm from '@/views/ai/model/chatRole/ChatRoleForm.vue'
|
2024-05-15 18:16:00 +08:00
|
|
|
|
import RoleCategoryList from './RoleCategoryList.vue'
|
2024-05-25 10:54:04 +08:00
|
|
|
|
import { ChatRoleApi, ChatRolePageReqVO, ChatRoleVO } from '@/api/ai/model/chatRole'
|
|
|
|
|
import { ChatConversationApi, ChatConversationVO } from '@/api/ai/chat/conversation'
|
|
|
|
|
import { TabsPaneContext } from 'element-plus'
|
|
|
|
|
import { Search, User } from '@element-plus/icons-vue'
|
2024-05-15 16:55:37 +08:00
|
|
|
|
|
2024-05-25 10:54:04 +08:00
|
|
|
|
const router = useRouter() // 路由对象
|
2024-05-15 23:57:41 +08:00
|
|
|
|
|
2024-05-15 16:55:37 +08:00
|
|
|
|
// 属性定义
|
2024-05-17 15:30:50 +08:00
|
|
|
|
const loading = ref<boolean>(false) // 加载中
|
2024-05-25 10:54:04 +08:00
|
|
|
|
const activeRole = ref<string>('my-role') // 选中的角色 TODO @fan:是不是叫 activeTab 会更明确一点哈。选中的角色,会以为是某个角色
|
2024-05-15 18:31:07 +08:00
|
|
|
|
const search = ref<string>('') // 加载中
|
2024-05-25 10:54:04 +08:00
|
|
|
|
// TODO @fan:要不 myPage、pubPage,搞成类似 const queryParams = reactive({ ,分别搞成两个大的参数哈?
|
2024-05-15 16:55:37 +08:00
|
|
|
|
const myPageNo = ref<number>(1) // my 分页下标
|
2024-05-17 15:30:50 +08:00
|
|
|
|
const myPageSize = ref<number>(50) // my 分页大小
|
2024-05-15 16:55:37 +08:00
|
|
|
|
const myRoleList = ref<ChatRoleVO[]>([]) // my 分页大小
|
|
|
|
|
const publicPageNo = ref<number>(1) // public 分页下标
|
2024-05-17 15:30:50 +08:00
|
|
|
|
const publicPageSize = ref<number>(50) // public 分页大小
|
2024-05-15 16:55:37 +08:00
|
|
|
|
const publicRoleList = ref<ChatRoleVO[]>([]) // public 分页大小
|
2024-05-21 18:20:45 +08:00
|
|
|
|
const activeCategory = ref<string>('全部') // 选择中的分类
|
2024-05-15 18:16:00 +08:00
|
|
|
|
const categoryList = ref<string[]>([]) // 角色分类类别
|
2024-05-25 10:54:04 +08:00
|
|
|
|
|
|
|
|
|
/** tabs 点击 */
|
2024-05-15 16:55:37 +08:00
|
|
|
|
const handleTabsClick = async (tab: TabsPaneContext) => {
|
|
|
|
|
// 设置切换状态
|
2024-05-25 10:54:04 +08:00
|
|
|
|
activeRole.value = tab.paneName + ''
|
2024-05-15 16:55:37 +08:00
|
|
|
|
// 切换的时候重新加载数据
|
|
|
|
|
await getActiveTabsRole()
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 10:54:04 +08:00
|
|
|
|
/** 获取 my role 我的角色 */
|
2024-05-17 15:30:50 +08:00
|
|
|
|
const getMyRole = async (append?: boolean) => {
|
|
|
|
|
const params: ChatRolePageReqVO = {
|
2024-05-15 18:31:07 +08:00
|
|
|
|
pageNo: myPageNo.value,
|
|
|
|
|
pageSize: myPageSize.value,
|
|
|
|
|
name: search.value,
|
2024-05-15 16:55:37 +08:00
|
|
|
|
publicStatus: false
|
|
|
|
|
}
|
2024-05-25 10:54:04 +08:00
|
|
|
|
const { total, list } = await ChatRoleApi.getMyPage(params)
|
2024-05-17 15:30:50 +08:00
|
|
|
|
if (append) {
|
|
|
|
|
myRoleList.value.push.apply(myRoleList.value, list)
|
|
|
|
|
} else {
|
|
|
|
|
myRoleList.value = list
|
|
|
|
|
}
|
2024-05-15 16:55:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 10:54:04 +08:00
|
|
|
|
/** 获取 public role 公共角色 */
|
2024-05-17 15:30:50 +08:00
|
|
|
|
const getPublicRole = async (append?: boolean) => {
|
|
|
|
|
const params: ChatRolePageReqVO = {
|
2024-05-15 18:31:07 +08:00
|
|
|
|
pageNo: publicPageNo.value,
|
|
|
|
|
pageSize: publicPageSize.value,
|
2024-05-21 18:20:45 +08:00
|
|
|
|
category: activeCategory.value === '全部' ? '' : activeCategory.value,
|
2024-05-15 18:31:07 +08:00
|
|
|
|
name: search.value,
|
2024-05-15 16:55:37 +08:00
|
|
|
|
publicStatus: true
|
|
|
|
|
}
|
2024-05-25 10:54:04 +08:00
|
|
|
|
const { total, list } = await ChatRoleApi.getMyPage(params)
|
2024-05-17 15:30:50 +08:00
|
|
|
|
if (append) {
|
|
|
|
|
publicRoleList.value.push.apply(publicRoleList.value, list)
|
|
|
|
|
} else {
|
|
|
|
|
publicRoleList.value = list
|
|
|
|
|
}
|
2024-05-15 16:55:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 10:54:04 +08:00
|
|
|
|
/** 获取选中的 tabs 角色 */
|
2024-05-15 18:31:07 +08:00
|
|
|
|
const getActiveTabsRole = async () => {
|
2024-05-15 16:55:37 +08:00
|
|
|
|
if (activeRole.value === 'my-role') {
|
2024-05-17 15:35:13 +08:00
|
|
|
|
myPageNo.value = 1
|
2024-05-15 18:31:07 +08:00
|
|
|
|
await getMyRole()
|
2024-05-15 16:55:37 +08:00
|
|
|
|
} else {
|
2024-05-17 15:35:13 +08:00
|
|
|
|
publicPageNo.value = 1
|
2024-05-15 18:31:07 +08:00
|
|
|
|
await getPublicRole()
|
2024-05-15 16:55:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 10:54:04 +08:00
|
|
|
|
/** 获取角色分类列表 */
|
2024-05-15 18:16:00 +08:00
|
|
|
|
const getRoleCategoryList = async () => {
|
2024-05-21 18:20:45 +08:00
|
|
|
|
const res = await ChatRoleApi.getCategoryList()
|
|
|
|
|
const defaultRole = ['全部']
|
|
|
|
|
categoryList.value = [...defaultRole, ...res]
|
2024-05-15 18:16:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 10:54:04 +08:00
|
|
|
|
/** 处理分类点击 */
|
2024-05-15 18:16:00 +08:00
|
|
|
|
const handlerCategoryClick = async (category: string) => {
|
2024-05-21 18:20:45 +08:00
|
|
|
|
// 切换选择的分类
|
|
|
|
|
activeCategory.value = category
|
|
|
|
|
// 筛选
|
2024-05-15 18:31:07 +08:00
|
|
|
|
await getActiveTabsRole()
|
2024-05-15 18:16:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 10:54:04 +08:00
|
|
|
|
/** 添加/修改操作 */
|
|
|
|
|
const formRef = ref()
|
2024-05-15 23:11:40 +08:00
|
|
|
|
const handlerAddRole = async () => {
|
|
|
|
|
formRef.value.open('my-create', null, '添加角色')
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 10:54:04 +08:00
|
|
|
|
/** 添加角色成功 */
|
|
|
|
|
const handlerAddRoleSuccess = async (e) => {
|
|
|
|
|
// 刷新数据
|
|
|
|
|
await getActiveTabsRole()
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 23:11:40 +08:00
|
|
|
|
// card 删除
|
|
|
|
|
const handlerCardDelete = async (role) => {
|
|
|
|
|
await ChatRoleApi.deleteMy(role.id)
|
|
|
|
|
// 刷新数据
|
|
|
|
|
await getActiveTabsRole()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// card 编辑
|
|
|
|
|
const handlerCardEdit = async (role) => {
|
|
|
|
|
formRef.value.open('my-update', role.id, '编辑角色')
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 10:54:04 +08:00
|
|
|
|
/** card 分页:获取下一页 */
|
2024-05-17 15:30:50 +08:00
|
|
|
|
const handlerCardPage = async (type) => {
|
|
|
|
|
console.log('handlerCardPage', type)
|
|
|
|
|
try {
|
|
|
|
|
loading.value = true
|
|
|
|
|
if (type === 'public') {
|
|
|
|
|
publicPageNo.value++
|
|
|
|
|
await getPublicRole(true)
|
|
|
|
|
} else {
|
|
|
|
|
myPageNo.value++
|
|
|
|
|
await getMyRole(true)
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 10:54:04 +08:00
|
|
|
|
/** 选择 card 角色:新建聊天对话 */
|
2024-05-15 23:57:41 +08:00
|
|
|
|
const handlerCardUse = async (role) => {
|
2024-05-25 10:54:04 +08:00
|
|
|
|
// 1. 创建对话
|
2024-05-17 15:30:50 +08:00
|
|
|
|
const data: ChatConversationVO = {
|
2024-05-15 23:57:41 +08:00
|
|
|
|
roleId: role.id
|
|
|
|
|
} as unknown as ChatConversationVO
|
2024-05-25 10:54:04 +08:00
|
|
|
|
const conversationId = await ChatConversationApi.createChatConversationMy(data)
|
|
|
|
|
// 2. 跳转页面
|
|
|
|
|
// TODO @fan:最好用 name,后续可能会改~~~
|
|
|
|
|
await router.push({
|
2024-05-21 22:07:56 +08:00
|
|
|
|
path: `/ai/chat`,
|
2024-05-16 00:18:29 +08:00
|
|
|
|
query: {
|
2024-05-25 10:54:04 +08:00
|
|
|
|
conversationId: conversationId
|
2024-05-16 00:18:29 +08:00
|
|
|
|
}
|
2024-05-15 23:57:58 +08:00
|
|
|
|
})
|
2024-05-15 23:57:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 10:54:04 +08:00
|
|
|
|
/** 初始化 **/
|
2024-05-17 15:30:50 +08:00
|
|
|
|
onMounted(async () => {
|
2024-05-15 18:16:00 +08:00
|
|
|
|
// 获取分类
|
|
|
|
|
await getRoleCategoryList()
|
2024-05-15 16:55:37 +08:00
|
|
|
|
// 获取 role 数据
|
|
|
|
|
await getActiveTabsRole()
|
|
|
|
|
})
|
2024-05-25 10:54:04 +08:00
|
|
|
|
// TODO @fan:css 是不是可以融合到 scss 里面呀?
|
2024-05-15 16:55:37 +08:00
|
|
|
|
</script>
|
2024-05-17 15:30:50 +08:00
|
|
|
|
<style lang="css">
|
|
|
|
|
.el-tabs__content {
|
|
|
|
|
position: relative;
|
|
|
|
|
height: 100%;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.el-tabs__nav-scroll {
|
|
|
|
|
margin: 10px 20px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
2024-05-15 16:55:37 +08:00
|
|
|
|
<!-- 样式 -->
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
// 跟容器
|
|
|
|
|
.role-container {
|
|
|
|
|
position: absolute;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
2024-05-17 15:30:50 +08:00
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
2024-05-15 16:55:37 +08:00
|
|
|
|
left: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
top: 0;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
background-color: #ffffff;
|
2024-05-17 15:30:50 +08:00
|
|
|
|
overflow: hidden;
|
2024-05-15 16:55:37 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
|
|
|
|
.role-main {
|
2024-05-17 15:30:50 +08:00
|
|
|
|
flex: 1;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
2024-05-21 10:13:30 +08:00
|
|
|
|
position: relative;
|
2024-05-15 18:31:07 +08:00
|
|
|
|
|
2024-05-15 23:11:40 +08:00
|
|
|
|
.search-container {
|
2024-05-17 15:30:50 +08:00
|
|
|
|
margin: 20px 20px 0px 20px;
|
2024-05-21 10:13:30 +08:00
|
|
|
|
position: absolute;
|
|
|
|
|
right: 0;
|
|
|
|
|
top: -5px;
|
|
|
|
|
z-index: 100;
|
2024-05-15 18:31:07 +08:00
|
|
|
|
}
|
2024-05-15 16:55:37 +08:00
|
|
|
|
|
2024-05-15 23:11:40 +08:00
|
|
|
|
.search-input {
|
|
|
|
|
width: 240px;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 18:31:07 +08:00
|
|
|
|
.tabs {
|
|
|
|
|
position: relative;
|
2024-05-17 15:30:50 +08:00
|
|
|
|
height: 100%;
|
|
|
|
|
|
|
|
|
|
.role-category-list {
|
|
|
|
|
margin: 0 27px;
|
|
|
|
|
}
|
2024-05-15 18:31:07 +08:00
|
|
|
|
}
|
2024-05-15 18:16:00 +08:00
|
|
|
|
|
|
|
|
|
.role-pane {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
2024-05-17 15:30:50 +08:00
|
|
|
|
height: 100%;
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
position: relative;
|
2024-05-15 18:16:00 +08:00
|
|
|
|
}
|
2024-05-15 16:55:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|