作者 dong

智能助手配置,bug修正

@@ -59,6 +59,11 @@ export const columns: BasicColumn[] = [ @@ -59,6 +59,11 @@ export const columns: BasicColumn[] = [
59 }, 59 },
60 }, 60 },
61 { 61 {
  62 + title: '按钮名称',
  63 + align: 'center',
  64 + dataIndex: 'buttonName',
  65 + },
  66 + {
62 title: 'code', 67 title: 'code',
63 align: 'center', 68 align: 'center',
64 dataIndex: 'code', 69 dataIndex: 'code',
@@ -82,7 +87,7 @@ export const searchFormSchema: FormSchema[] = [ @@ -82,7 +87,7 @@ export const searchFormSchema: FormSchema[] = [
82 // 新增知识库选择字段 87 // 新增知识库选择字段
83 { 88 {
84 label: '模型名称', 89 label: '模型名称',
85 - field: 'name', // 注意:这里使用knowledgeId作为字段名 90 + field: 'modelId', // 注意:这里使用knowledgeId作为字段名
86 component: 'ApiSelect', 91 component: 'ApiSelect',
87 componentProps: { 92 componentProps: {
88 api: listmodelid, 93 api: listmodelid,
@@ -148,13 +153,13 @@ export const searchFormSchema: FormSchema[] = [ @@ -148,13 +153,13 @@ export const searchFormSchema: FormSchema[] = [
148 export const formSchema: FormSchema[] = [ 153 export const formSchema: FormSchema[] = [
149 { 154 {
150 label: '模型名称', 155 label: '模型名称',
151 - field: 'name', // 注意:这里使用knowledgeId作为字段名 156 + field: 'name',
152 component: 'Input', 157 component: 'Input',
153 required: true, 158 required: true,
154 componentProps: { 159 componentProps: {
155 - api: listmodelid, // 使用知识库接口  
156 - labelField: 'name', // 显示知识库名称  
157 - valueField: 'id', // 提交知识库ID 160 + api: listmodelid,
  161 + labelField: 'name',
  162 + valueField: 'id',
158 showSearch: true, 163 showSearch: true,
159 readonly: true, 164 readonly: true,
160 filterOption: (input: string, option: any) => { 165 filterOption: (input: string, option: any) => {
@@ -225,7 +225,7 @@ @@ -225,7 +225,7 @@
225 showSaveButton: true, 225 showSaveButton: true,
226 operationType: 'knowledge', // 指定操作类型 226 operationType: 'knowledge', // 指定操作类型
227 onConfirm: async (record) => { 227 onConfirm: async (record) => {
228 - console.log("执行知识库确认回调"); 228 + console.log('执行知识库确认回调');
229 try { 229 try {
230 await defHttp.post({ url: '/airaglog/airagLog/saveToEmbeddingLibrary', params: record }); 230 await defHttp.post({ url: '/airaglog/airagLog/saveToEmbeddingLibrary', params: record });
231 // 刷新列表 231 // 刷新列表
@@ -31,10 +31,9 @@ @@ -31,10 +31,9 @@
31 const emit = defineEmits(['register', 'success']); 31 const emit = defineEmits(['register', 'success']);
32 const isUpdate = ref(true); 32 const isUpdate = ref(true);
33 const isDetail = ref(false); 33 const isDetail = ref(false);
34 - const showSaveButton = ref(true);  
35 let customOnConfirm = ref<Function | null>(null); 34 let customOnConfirm = ref<Function | null>(null);
36 //表单配置 35 //表单配置
37 - const [registerForm, { setProps, resetFields, setFieldsValue, validate, scrollToField }] = useForm({ 36 + const [registerForm, { setProps, resetFields, setFieldsValue, validate, scrollToField, updateSchema }] = useForm({
38 labelWidth: 150, 37 labelWidth: 150,
39 schemas: formSchema, 38 schemas: formSchema,
40 showActionButtonGroup: false, 39 showActionButtonGroup: false,
@@ -42,7 +41,7 @@ @@ -42,7 +41,7 @@
42 }); 41 });
43 //表单赋值 42 //表单赋值
44 const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { 43 const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
45 - console.log("模态框打开,操作类型:", data?.operationType); 44 + console.log('模态框打开,操作类型:', data?.operationType);
46 //重置表单 45 //重置表单
47 await resetFields(); 46 await resetFields();
48 setModalProps({ confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter }); 47 setModalProps({ confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter });
@@ -51,6 +50,18 @@ @@ -51,6 +50,18 @@
51 customOnConfirm.value = data?.onConfirm || null; 50 customOnConfirm.value = data?.onConfirm || null;
52 isUpdate.value = !!data?.isUpdate; 51 isUpdate.value = !!data?.isUpdate;
53 isDetail.value = !!data?.showFooter; 52 isDetail.value = !!data?.showFooter;
  53 +
  54 + if (operationType.value === 'knowledge') {
  55 + updateSchema({
  56 + field: 'question',
  57 + show: false,
  58 + });
  59 + } else {
  60 + updateSchema({
  61 + field: 'question',
  62 + show: true,
  63 + });
  64 + }
54 if (unref(isUpdate)) { 65 if (unref(isUpdate)) {
55 //表单赋值 66 //表单赋值
56 await setFieldsValue({ 67 await setFieldsValue({
  1 +<template>
  2 + <a-card title="智能助手配置" class="config-card">
  3 + <a-form :model="formState" layout="vertical">
  4 + <!-- 向量模型 -->
  5 + <a-form-item label="向量模型" class="form-item">
  6 + <a-select
  7 + v-model:value="formState.embeddingId"
  8 + placeholder="请选择向量模型"
  9 + :options="options.embeddingOptions"
  10 + show-search
  11 + option-filter-prop="label"
  12 + />
  13 + </a-form-item>
  14 +
  15 + <!-- 大语言模型 -->
  16 + <a-form-item label="大语言模型" class="form-item">
  17 + <a-select
  18 + v-model:value="formState.llmId"
  19 + placeholder="请选择大语言模型"
  20 + :options="options.llmOptions"
  21 + show-search
  22 + option-filter-prop="label"
  23 + />
  24 + </a-form-item>
  25 +
  26 + <!-- 知识库 -->
  27 + <a-form-item label="知识库" class="form-item">
  28 + <a-select
  29 + v-model:value="formState.knowledgeId"
  30 + placeholder="请选择知识库"
  31 + :options="options.knowledgeOptions"
  32 + show-search
  33 + option-filter-prop="label"
  34 + />
  35 + </a-form-item>
  36 +
  37 + <!-- 按钮(多选) -->
  38 + <a-form-item label="功能按钮" class="form-item">
  39 + <a-select
  40 + v-model:value="formState.buttonIds"
  41 + mode="multiple"
  42 + placeholder="请选择按钮"
  43 + :options="options.buttonOptions"
  44 + show-search
  45 + option-filter-prop="label"
  46 + :max-tag-count="6"
  47 + :max="5"
  48 + />
  49 + <div class="hint">最多可选择5个按钮</div>
  50 + </a-form-item>
  51 +
  52 + <!-- 提示词 -->
  53 + <a-form-item label="提示词" class="form-item">
  54 + <a-textarea
  55 + v-model:value="formState.prompt"
  56 + placeholder="请输入提示词,例如:你是一个专业的AI助手..."
  57 + :rows="4"
  58 + :maxlength="500"
  59 + show-count
  60 + />
  61 + </a-form-item>
  62 +
  63 + <!-- 操作按钮 -->
  64 + <a-form-item class="action-buttons">
  65 + <a-space>
  66 + <a-button @click="resetForm">
  67 + <template #icon><UndoOutlined /></template>
  68 + 重置
  69 + </a-button>
  70 + <a-button type="primary" @click="saveConfigData" :loading="saving">
  71 + <template #icon><SaveOutlined /></template>
  72 + 保存配置
  73 + </a-button>
  74 + </a-space>
  75 + </a-form-item>
  76 + </a-form>
  77 + </a-card>
  78 +</template>
  79 +
  80 +<script lang="ts" setup>
  81 + import { reactive, ref, onMounted } from 'vue';
  82 + import { getConfigData, saveConfig } from './Chatsetting.api';
  83 + import { message } from 'ant-design-vue';
  84 + import { SaveOutlined, UndoOutlined } from '@ant-design/icons-vue';
  85 +
  86 + // 表单数据结构
  87 + const formState = reactive({
  88 + id: '',
  89 + embeddingId: undefined,
  90 + llmId: undefined,
  91 + knowledgeId: undefined,
  92 + buttonIds: [],
  93 + prompt: '',
  94 + });
  95 +
  96 + // 选项数据
  97 + const options = reactive({
  98 + embeddingOptions: [],
  99 + llmOptions: [],
  100 + knowledgeOptions: [],
  101 + buttonOptions: [],
  102 + });
  103 +
  104 + const saving = ref(false);
  105 +
  106 + // 加载配置数据
  107 + const loadConfig = async () => {
  108 + try {
  109 + const res = await getConfigData();
  110 +
  111 + if (res.success) {
  112 + const data = res.result;
  113 +
  114 + // 填充表单
  115 + Object.keys(formState).forEach((key) => {
  116 + if (data.airagChatsettingConfig[key] !== undefined) {
  117 + formState[key] = data.airagChatsettingConfig[key];
  118 + console.log('shuju' + formState[key]);
  119 + }
  120 + });
  121 +
  122 + // 填充选项
  123 + options.embeddingOptions = data.embeddingOptions || [];
  124 + console.log('向量' + options.embeddingOptions);
  125 + options.llmOptions = data.llmOptions || [];
  126 + options.knowledgeOptions = data.knowledgeOptions || [];
  127 + options.buttonOptions = data.buttonOptions || [];
  128 + }
  129 + } catch (error) {
  130 + console.error('配置加载失败', error);
  131 + message.error('配置加载失败');
  132 + }
  133 + };
  134 +
  135 + // 保存配置
  136 + const saveConfigData = async () => {
  137 + const params = {
  138 + ...formState,
  139 + id: formState.id || '',
  140 + buttonIds: formState.buttonIds.filter((id) => id && id !== 'undefined'),
  141 + };
  142 + if (formState.buttonIds.length > 5) {
  143 + message.error('最多只能选择五个按钮');
  144 + return;
  145 + }
  146 + saving.value = true;
  147 + try {
  148 + const res = await saveConfig(params);
  149 + console.log(res.success);
  150 + if (res.success) {
  151 + message.success('配置保存成功');
  152 + loadConfig(); // 重新加载最新数据
  153 + } else {
  154 + message.error('保存失败: ' + res.message);
  155 + }
  156 + } catch (error) {
  157 + console.error('保存失败', error);
  158 + message.error('保存失败');
  159 + } finally {
  160 + saving.value = false;
  161 + }
  162 + };
  163 +
  164 + // 重置表单
  165 + const resetForm = () => {
  166 + loadConfig();
  167 + };
  168 +
  169 + // 初始化加载
  170 + onMounted(() => {
  171 + loadConfig();
  172 + });
  173 +</script>
  174 +
  175 +<style lang="less" scoped>
  176 + .config-card {
  177 + max-width: 800px;
  178 + margin: 20px auto;
  179 + box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  180 +
  181 + :deep(.ant-card-head) {
  182 + background-color: #f0f5ff;
  183 + border-bottom: 1px solid #e8e8e8;
  184 + }
  185 + }
  186 +
  187 + .form-item {
  188 + margin-bottom: 24px;
  189 +
  190 + :deep(.ant-form-item-label) {
  191 + font-weight: 500;
  192 + margin-bottom: 8px;
  193 + }
  194 + }
  195 +
  196 + .hint {
  197 + font-size: 12px;
  198 + color: #999;
  199 + margin-top: 4px;
  200 + }
  201 +
  202 + .action-buttons {
  203 + margin-top: 24px;
  204 + text-align: center;
  205 +
  206 + .ant-space {
  207 + justify-content: center;
  208 + }
  209 +
  210 + .ant-btn {
  211 + min-width: 120px;
  212 + }
  213 + }
  214 +</style>
  1 +import { defHttp } from '/@/utils/http/axios';
  2 +
  3 +enum Api {
  4 + getConfigData = '/airagchatsetting/airagChatsetting/getConfigData',
  5 + saveConfig = '/airagchatsetting/airagChatsetting/saveConfig',
  6 +}
  7 +/**
  8 + * 列表接口
  9 + * @param params
  10 + */
  11 +export const getConfigData = () => defHttp.get({ url: Api.getConfigData }, { isTransformResponse: false });
  12 +/**
  13 + * 保存或者更新
  14 + * @param params
  15 + */
  16 +export const saveConfig = (params) => {
  17 + return defHttp.post({ url: Api.saveConfig, params }, { isTransformResponse: false });
  18 +};