index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="角色名称" prop="name">
  12. <el-input
  13. v-model="queryParams.name"
  14. placeholder="请输入角色名称"
  15. clearable
  16. @keyup.enter="handleQuery"
  17. class="!w-240px"
  18. />
  19. </el-form-item>
  20. <el-form-item label="角色类别" prop="category">
  21. <el-input
  22. v-model="queryParams.category"
  23. placeholder="请输入角色类别"
  24. clearable
  25. @keyup.enter="handleQuery"
  26. class="!w-240px"
  27. />
  28. </el-form-item>
  29. <el-form-item label="是否公开" prop="publicStatus">
  30. <el-select
  31. v-model="queryParams.publicStatus"
  32. placeholder="请选择是否公开"
  33. clearable
  34. class="!w-240px"
  35. >
  36. <el-option
  37. v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
  38. :key="dict.value"
  39. :label="dict.label"
  40. :value="dict.value"
  41. />
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item>
  45. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  46. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  47. <el-button
  48. type="primary"
  49. plain
  50. @click="openForm('create')"
  51. v-hasPermi="['ai:chat-role:create']"
  52. >
  53. <Icon icon="ep:plus" class="mr-5px" /> 新增
  54. </el-button>
  55. </el-form-item>
  56. </el-form>
  57. </ContentWrap>
  58. <!-- 列表 -->
  59. <ContentWrap>
  60. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  61. <el-table-column label="角色名称" align="center" prop="name" />
  62. <el-table-column label="绑定模型" align="center" prop="modelName" />
  63. <el-table-column label="角色头像" align="center" prop="avatar">
  64. <template #default="scope">
  65. <el-image :src="scope?.row.avatar" class="w-32px h-32px" />
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="角色类别" align="center" prop="category" />
  69. <el-table-column label="角色描述" align="center" prop="description" />
  70. <el-table-column label="角色欢迎语" align="center" prop="welcomeMessage" />
  71. <el-table-column label="角色上下文" align="center" prop="systemMessage" />
  72. <el-table-column label="是否公开" align="center" prop="publicStatus">
  73. <template #default="scope">
  74. <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.publicStatus" />
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="状态" align="center" prop="status">
  78. <template #default="scope">
  79. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="角色排序" align="center" prop="sort" />
  83. <el-table-column label="操作" align="center">
  84. <template #default="scope">
  85. <el-button
  86. link
  87. type="primary"
  88. @click="openForm('update', scope.row.id)"
  89. v-hasPermi="['ai:chat-role:update']"
  90. >
  91. 编辑
  92. </el-button>
  93. <el-button
  94. link
  95. type="danger"
  96. @click="handleDelete(scope.row.id)"
  97. v-hasPermi="['ai:chat-role:delete']"
  98. >
  99. 删除
  100. </el-button>
  101. </template>
  102. </el-table-column>
  103. </el-table>
  104. <!-- 分页 -->
  105. <Pagination
  106. :total="total"
  107. v-model:page="queryParams.pageNo"
  108. v-model:limit="queryParams.pageSize"
  109. @pagination="getList"
  110. />
  111. </ContentWrap>
  112. <!-- 表单弹窗:添加/修改 -->
  113. <ChatRoleForm ref="formRef" @success="getList" />
  114. </template>
  115. <script setup lang="ts">
  116. import { getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
  117. import { ChatRoleApi, ChatRoleVO } from '@/api/ai/model/chatRole'
  118. import ChatRoleForm from './ChatRoleForm.vue'
  119. /** AI 聊天角色 列表 */
  120. defineOptions({ name: 'AiChatRole' })
  121. const message = useMessage() // 消息弹窗
  122. const { t } = useI18n() // 国际化
  123. const loading = ref(true) // 列表的加载中
  124. const list = ref<ChatRoleVO[]>([]) // 列表的数据
  125. const total = ref(0) // 列表的总页数
  126. const queryParams = reactive({
  127. pageNo: 1,
  128. pageSize: 10,
  129. name: undefined,
  130. category: undefined,
  131. publicStatus: true
  132. })
  133. const queryFormRef = ref() // 搜索的表单
  134. /** 查询列表 */
  135. const getList = async () => {
  136. loading.value = true
  137. try {
  138. const data = await ChatRoleApi.getChatRolePage(queryParams)
  139. list.value = data.list
  140. total.value = data.total
  141. } finally {
  142. loading.value = false
  143. }
  144. }
  145. /** 搜索按钮操作 */
  146. const handleQuery = () => {
  147. queryParams.pageNo = 1
  148. getList()
  149. }
  150. /** 重置按钮操作 */
  151. const resetQuery = () => {
  152. queryFormRef.value.resetFields()
  153. handleQuery()
  154. }
  155. /** 添加/修改操作 */
  156. const formRef = ref()
  157. const openForm = (type: string, id?: number) => {
  158. formRef.value.open(type, id)
  159. }
  160. /** 删除按钮操作 */
  161. const handleDelete = async (id: number) => {
  162. try {
  163. // 删除的二次确认
  164. await message.delConfirm()
  165. // 发起删除
  166. await ChatRoleApi.deleteChatRole(id)
  167. message.success(t('common.delSuccess'))
  168. // 刷新列表
  169. await getList()
  170. } catch {}
  171. }
  172. /** 初始化 **/
  173. onMounted(() => {
  174. getList()
  175. })
  176. </script>