index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <!-- chat 角色仓库 -->
  2. <template>
  3. <el-container class="role-container">
  4. <ChatRoleForm ref="formRef" @success="handlerAddRoleSuccess" />
  5. <Header title="角色仓库"/>
  6. <el-main class="role-main">
  7. <div class="search-container">
  8. <!-- 搜索按钮 -->
  9. <el-input
  10. v-model="search"
  11. class="search-input"
  12. size="default"
  13. placeholder="请输入搜索的内容"
  14. :suffix-icon="Search"
  15. @change="getActiveTabsRole"
  16. />
  17. <el-button type="primary" @click="handlerAddRole" style="margin-left: 20px;">
  18. <el-icon><User /></el-icon>
  19. 添加角色
  20. </el-button>
  21. </div>
  22. <!-- tabs -->
  23. <el-tabs v-model="activeRole" class="tabs" @tab-click="handleTabsClick">
  24. <el-tab-pane class="role-pane" label="我的角色" name="my-role">
  25. <RoleList :role-list="myRoleList" @onDelete="handlerCardDelete" @onEdit="handlerCardEdit" @onUse="handlerCardUse" style="margin-top: 20px;" />
  26. </el-tab-pane>
  27. <el-tab-pane label="公共角色" name="public-role">
  28. <RoleCategoryList :category-list="categoryList" :active="activeCategory" @onCategoryClick="handlerCategoryClick" />
  29. <RoleList :role-list="publicRoleList" @onDelete="handlerCardDelete" @onEdit="handlerCardEdit" style="margin-top: 20px;" />
  30. </el-tab-pane>
  31. </el-tabs>
  32. </el-main>
  33. </el-container>
  34. </template>
  35. <!-- setup -->
  36. <script setup lang="ts">
  37. import {ref} from "vue";
  38. import Header from '@/views/ai/chat/components/Header.vue'
  39. import RoleList from './RoleList.vue'
  40. import ChatRoleForm from '@/views/ai/model/chatRole/ChatRoleForm.vue'
  41. import RoleCategoryList from './RoleCategoryList.vue'
  42. import {ChatRoleApi, ChatRolePageReqVO, ChatRoleVO} from '@/api/ai/model/chatRole'
  43. import {ChatConversationApi, ChatConversationVO} from '@/api/ai/chat/conversation'
  44. import {TabsPaneContext} from "element-plus";
  45. import {Search, User} from "@element-plus/icons-vue";
  46. // 获取路由
  47. const router = useRouter()
  48. // 属性定义
  49. const activeRole = ref<string>('my-role') // 选中的角色
  50. const loadding = ref<boolean>(true) // 加载中
  51. const search = ref<string>('') // 加载中
  52. const myPageNo = ref<number>(1) // my 分页下标
  53. const myPageSize = ref<number>(50) // my 分页大小
  54. const myRoleList = ref<ChatRoleVO[]>([]) // my 分页大小
  55. const publicPageNo = ref<number>(1) // public 分页下标
  56. const publicPageSize = ref<number>(50) // public 分页大小
  57. const publicRoleList = ref<ChatRoleVO[]>([]) // public 分页大小
  58. const activeCategory = ref<string>('') // 选择中的分类
  59. const categoryList = ref<string[]>([]) // 角色分类类别
  60. /** 添加/修改操作 */
  61. const formRef = ref()
  62. // tabs 点击
  63. const handleTabsClick = async (tab: TabsPaneContext) => {
  64. // 设置切换状态
  65. const activeTabs = tab.paneName + ''
  66. activeRole.value = activeTabs;
  67. // 切换的时候重新加载数据
  68. await getActiveTabsRole()
  69. }
  70. // 获取 my role
  71. const getMyRole = async () => {
  72. const params:ChatRolePageReqVO = {
  73. pageNo: myPageNo.value,
  74. pageSize: myPageSize.value,
  75. category: activeCategory.value,
  76. name: search.value,
  77. publicStatus: false
  78. }
  79. const { total, list } = await ChatRoleApi.getMyPage(params)
  80. myRoleList.value = list
  81. }
  82. // 获取 public role
  83. const getPublicRole = async () => {
  84. const params:ChatRolePageReqVO = {
  85. pageNo: publicPageNo.value,
  86. pageSize: publicPageSize.value,
  87. category: activeCategory.value,
  88. name: search.value,
  89. publicStatus: true
  90. }
  91. const { total, list } = await ChatRoleApi.getMyPage(params)
  92. publicRoleList.value = list
  93. }
  94. // 获取选中的 tabs 角色
  95. const getActiveTabsRole = async () => {
  96. if (activeRole.value === 'my-role') {
  97. await getMyRole()
  98. } else {
  99. await getPublicRole()
  100. }
  101. }
  102. // 获取角色分类列表
  103. const getRoleCategoryList = async () => {
  104. categoryList.value = await ChatRoleApi.getCategoryList()
  105. }
  106. // 处理分类点击
  107. const handlerCategoryClick = async (category: string) => {
  108. if (activeCategory.value === category) {
  109. activeCategory.value = ''
  110. } else {
  111. activeCategory.value = category
  112. }
  113. await getActiveTabsRole()
  114. }
  115. // 添加角色
  116. const handlerAddRole = async () => {
  117. formRef.value.open('my-create', null, '添加角色')
  118. }
  119. // card 删除
  120. const handlerCardDelete = async (role) => {
  121. await ChatRoleApi.deleteMy(role.id)
  122. // 刷新数据
  123. await getActiveTabsRole()
  124. }
  125. // card 编辑
  126. const handlerCardEdit = async (role) => {
  127. formRef.value.open('my-update', role.id, '编辑角色')
  128. }
  129. // card 使用
  130. const handlerCardUse = async (role) => {
  131. const data : ChatConversationVO = {
  132. roleId: role.id
  133. } as unknown as ChatConversationVO
  134. // 创建对话
  135. const conversation = await ChatConversationApi.createChatConversationMy(data)
  136. // 调整页面
  137. router.push({
  138. path: `/ai/chat/index`,
  139. query: {
  140. conversationId: conversation,
  141. }
  142. })
  143. }
  144. // 添加角色成功
  145. const handlerAddRoleSuccess = async (e) => {
  146. console.log(e)
  147. // 刷新数据
  148. await getActiveTabsRole()
  149. }
  150. //
  151. onMounted( async () => {
  152. // 获取分类
  153. await getRoleCategoryList()
  154. // 获取 role 数据
  155. await getActiveTabsRole()
  156. })
  157. </script>
  158. <!-- 样式 -->
  159. <style scoped lang="scss">
  160. // 跟容器
  161. .role-container {
  162. position: absolute;
  163. margin: 0;
  164. padding: 0;
  165. width: 100%;
  166. height: 100%;
  167. left: 0;
  168. right: 0;
  169. top: 0;
  170. bottom: 0;
  171. background-color: #ffffff;
  172. display: flex;
  173. flex-direction: column;
  174. .role-main {
  175. position: relative;
  176. .search-container {
  177. //position: absolute;
  178. //right: 20px;
  179. //top: 10px;
  180. //z-index: 100;
  181. }
  182. .search-input {
  183. width: 240px;
  184. }
  185. .tabs {
  186. position: relative;
  187. }
  188. .role-pane {
  189. display: flex;
  190. flex-direction: column;
  191. }
  192. }
  193. }
  194. </style>