Kevin Jiang před 2 roky
rodič
revize
7c702dfd39

+ 10 - 0
src/client/test.client.ts

@@ -0,0 +1,10 @@
+import httpClient from "@/services/httpClient";
+import type { Response } from "@/types/response.types";
+import * as urlHelper from "@/libs/url.lib"
+
+const _url = urlHelper.withPrefix("/gw/user/test")
+
+export async function test1(text: string) {
+  const resp = await httpClient.post<Response<string>>(_url("1"), { text });
+  return resp.data.data;
+}

+ 5 - 0
src/services/test.service.ts

@@ -0,0 +1,5 @@
+import * as testClient from "@/client/test.client";
+
+export async function test1(text: string) {
+  return testClient.test1(text)
+}

+ 20 - 5
src/views/report/components/ChapterEditor.vue

@@ -1,11 +1,13 @@
 <!-- 章节编辑器 -->
 
 <script setup lang="ts">
-import { ref, watch, type PropType } from 'vue';
+import { computed, ref, watch, type PropType } from 'vue';
 import { EditOutlined, DownOutlined } from '@ant-design/icons-vue';
 import type { Chapter } from '@/types/report.types';
 import ContentEditor from "../components/ContentEditor.vue";
 import ReferenceDraw from "../components/reference/ReferenceDraw.vue";
+import { useRoute } from 'vue-router';
+import * as testService from "@/services/test.service"
 
 const props = defineProps({
   reportKeywords: {
@@ -23,6 +25,10 @@ const props = defineProps({
   }
 });
 
+const route = useRoute()
+
+const isAI = computed(() => route.query.ai)
+
 const titleEditor = ref<HTMLInputElement | null>(null);
 
 const titleEditing = ref(false);
@@ -34,7 +40,7 @@ const keywordsEditor = ref<HTMLInputElement | null>(null);
 const keywordsEditing = ref(false);
 
 const repetitiveWarning = ref(false);
- 
+
 const fullTitle = ref('');
 // 参考文献抽屉组件ref
 const referenceDraw = ref<InstanceType<typeof ReferenceDraw> | null>(null);
@@ -132,10 +138,19 @@ function notifyRepetitiveWarning(data: boolean){
   repetitiveWarning.value = data;
 }
 
+function test1() {
+  const prompt = `根据章节标题和关键词续写章节内容:\n` +
+            `章节标题:${props.data.title}\n关键词:${props.data.keywords}\n续写`
+  testService.test1(prompt).then((resp) => {
+    onContentChange(resp)
+  }).catch((err) => {
+    console.log('err', err)
+  })
+}
+
 defineExpose({
-  notifyRepetitiveWarning 
+  notifyRepetitiveWarning
 })
-
 </script>
 
 <template>
@@ -202,7 +217,7 @@ defineExpose({
     <div class="chapter-button-group" v-if="contentEditorVisible">
       <a-space>
         <a-button @click="searchReference">查找参考文献</a-button>
-        <a-button disabled>自动生成(二期)</a-button>
+        <a-button :disabled="!isAI" @click="test1">自动生成(二期)</a-button>
       </a-space>
     </div>
   </div>