【增加】增加仓库分类

This commit is contained in:
cherishsince 2024-05-15 18:16:00 +08:00
parent 986f50c6da
commit 3e0da37e16
3 changed files with 89 additions and 13 deletions

View File

@ -51,7 +51,12 @@ export const ChatRoleApi = {
},
// 获取 my role
getMyRole: async (params: ChatRolePageReqVO) => {
getMyPage: async (params: ChatRolePageReqVO) => {
return await request.get({ url: `/ai/chat-role/my-page`, params})
},
// 获取角色分类
getCategoryList: async () => {
return await request.get({ url: `/ai/chat-role/category-list`})
}
}

View File

@ -0,0 +1,46 @@
<template>
<div class="category-list">
<div class="category" v-for="category in categoryList" :key="category">
<el-button plain v-if="category !== active" @click="handleCategoryClick(category)">{{ category }}</el-button>
<el-button plain type="primary" v-else @click="handleCategoryClick(category)">{{ category }}</el-button>
</div>
</div>
</template>
<script setup lang="ts">
import {PropType} from "vue";
//
defineProps({
categoryList: {
type: Array as PropType<string[]>,
required: true
},
active: {
type: String,
required: false
}
})
//
const emits = defineEmits(['onCategoryClick'])
//
const handleCategoryClick = async (category) => {
emits('onCategoryClick', category)
}
</script>
<style scoped lang="scss">
.category-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
.category {
display: flex;
flex-direction: row;
margin-right: 20px;
}
}
</style>

View File

@ -4,8 +4,9 @@
<Header title="角色仓库"/>
<el-main class="role-main">
<el-tabs v-model="activeRole" class="demo-tabs" @tab-click="handleTabsClick">
<el-tab-pane label="我的角色" name="my-role">
<RoleList :role-list="myRoleList" />
<el-tab-pane class="role-pane" label="我的角色" name="my-role">
<RoleCategoryList :category-list="categoryList" :active="activeCategory" @onCategoryClick="handlerCategoryClick" />
<RoleList :role-list="myRoleList" style="margin-top: 20px;" />
</el-tab-pane>
<el-tab-pane label="公共角色" name="public-role">
<RoleList :role-list="publicRoleList" />
@ -20,6 +21,7 @@
import {ref} from "vue";
import Header from '@/views/ai/chat/components/Header.vue'
import RoleList from './RoleList.vue'
import RoleCategoryList from './RoleCategoryList.vue'
import {ChatRoleApi, ChatRolePageReqVO, ChatRoleVO} from '@/api/ai/model/chatRole'
import {TabsPaneContext} from "element-plus";
@ -32,6 +34,8 @@ const myRoleList = ref<ChatRoleVO[]>([]) // my 分页大小
const publicPageNo = ref<number>(1) // public
const publicPageSize = ref<number>(50) // public
const publicRoleList = ref<ChatRoleVO[]>([]) // public
const activeCategory = ref<string>('writing') //
const categoryList = ref<string[]>([]) //
// tabs
const handleTabsClick = async (tab: TabsPaneContext) => {
@ -43,41 +47,57 @@ const handleTabsClick = async (tab: TabsPaneContext) => {
}
// my role
const getMyRole = async (pageNo: number, pageSize: number) => {
const getMyRole = async (pageNo: number, pageSize: number, category?: string) => {
const params:ChatRolePageReqVO = {
pageNo,
pageSize,
category,
publicStatus: false
}
const { total, list } = await ChatRoleApi.getMyRole(params)
const { total, list } = await ChatRoleApi.getMyPage(params)
myRoleList.value = list
console.log('myRoleList 获取成功', list)
console.log('myRoleList 获取成功', myRoleList.value)
}
// public role
const getPublicRole = async (pageNo: number, pageSize: number) => {
const getPublicRole = async (pageNo: number, pageSize: number, category?: string) => {
const params:ChatRolePageReqVO = {
pageNo,
pageSize,
category,
publicStatus: true
}
const { total, list } = await ChatRoleApi.getMyRole(params)
console.log(list)
const { total, list } = await ChatRoleApi.getMyPage(params)
publicRoleList.value = list
}
// tabs
const getActiveTabsRole = async () => {
const getActiveTabsRole = async (category?: string) => {
if (activeRole.value === 'my-role') {
await getMyRole(myPageNo.value, myPageSize.value)
await getMyRole(myPageNo.value, myPageSize.value, category)
} else {
await getPublicRole(myPageNo.value, myPageSize.value)
await getPublicRole(publicPageNo.value, publicPageSize.value, category)
}
}
//
const getRoleCategoryList = async () => {
categoryList.value = await ChatRoleApi.getCategoryList()
}
//
const handlerCategoryClick = async (category: string) => {
if (activeCategory.value === category) {
activeCategory.value = ''
} else {
activeCategory.value = category
}
await getActiveTabsRole(activeCategory.value)
}
//
onMounted( async () => {
//
await getRoleCategoryList()
// role
await getActiveTabsRole()
})
@ -103,6 +123,11 @@ onMounted( async () => {
.role-main {
.role-pane {
display: flex;
flex-direction: column;
}
}
}