yangg 10 сар өмнө
parent
commit
7f6f436518

+ 0 - 0
src/views/document/com/components/sourceAi/index.scss


+ 216 - 0
src/views/document/com/components/sourceAi/index.vue

@@ -0,0 +1,216 @@
+<template>
+  <div class="com-formual">
+    <el-form>
+      <el-form-item>
+        <el-select
+          v-model="tableCode"
+          placeholder="请选择模型"
+          @change="onChangeTab"
+          size="large"
+          style="width: 100%"
+        >
+          <el-option label="测试模型" :value="0"></el-option>
+          <!-- <el-option
+                        v-for="(item,index) in tableList"
+                        :key="item.id"
+                        :label="item.name"
+                        :value="index"
+                      /> -->
+        </el-select>
+      </el-form-item>
+      <el-form-item>
+        <el-input v-model="dataIntro" v-if="showSearch" @keyup.enter="retrieval"
+          ><!-- v-model="dataForm.intro" -->
+          <el-button
+            slot="append"
+            icon="el-icon-search"
+            @click="retrieval"
+          ></el-button
+        ></el-input>
+      </el-form-item>
+      <el-form-item style="min-height: 200px" v-if="fileLoadStatus" v-loading="loading">
+        <div>当前回答内容:{{ textInfo }}</div>
+        <div class="dialog-footer" style="display: flex; justify-content: flex-end;">
+          <el-button  type="primary" @click="onConfirm"> 确认选择 </el-button>
+        </div>
+      </el-form-item>
+    </el-form>
+
+    <!-- <el-dialog
+                :visible.sync="showConfirm"
+                title="数据确认"
+                width="500"
+                align-center
+                :append-to-body="true"
+              >
+                <div>当前工作表:{{position.sheet}} </div>
+                <div>当前取值:{{position.value}}</div>
+                <template #footer>
+                  <div class="dialog-footer">
+                    <el-button @click="showConfirm = false">关闭</el-button>
+                    <el-button type="primary" @click="onConfirm">
+                      确认选择
+                    </el-button>
+                  </div>
+                </template>
+              </el-dialog> -->
+  </div>
+</template>
+  
+  <script>
+import { searchSourceData, deleteSourceData } from "@/api/sourceData";
+/* import { search } from "core-js/fn/symbol"; */
+import LuckyExcel from "luckyexcel"; //引入LuckyExcel
+import axios from "axios";
+export default {
+  name: "SourceAi",
+  emits: ["onPicked"],
+
+  components: {},
+  data() {
+    return {
+      tableCode: "",
+      tableList: [],
+      showConfirm: false,
+      fileLoadStatus: false,
+      showSearch: false,
+      position: {
+        tb: "",
+        c: 0,
+        r: 0,
+        sheet: "",
+        value: "",
+      },
+      dataIntro: "",
+      textInfo: "",
+      loading: false, // 增加 loading 状态
+      searchResult:{}
+    };
+  },
+  mounted() {
+    this.initTableList();
+  },
+  methods: {
+    /* ai检索 */
+    async retrieval() {
+        this.fileLoadStatus = true;
+        this.loading = true; // 开始加载动画
+      try {
+        const response = await axios.post(
+          "http://58.246.234.210:7860/api/v1/run/3f84a841-cefd-44b3-9555-568cc3b6c2d2?stream=false",
+          {
+            input_value: this.dataIntro,
+            output_type: "chat",
+            input_type: "chat",
+            tweaks: {
+              "ChatInput-em6qC": {},
+              "ParseData-yO3YQ": {},
+              "Prompt-Wj75b": {},
+              "ChatOutput-zy9na": {},
+              "SplitText-O1knk": {},
+              "File-4j6Zd": {},
+              "OllamaEmbeddings-xbYXX": {},
+              "Chroma-OIejP": {},
+              "OllamaModel-04mEO": {},
+              "OllamaEmbeddings-UGvLP": {},
+              "Chroma-HzukO": {},
+            },
+          },
+          {
+            headers: {
+              "Content-Type": "application/json",
+            },
+          }
+        );
+
+        if (response.status === 200) {
+          
+          // 假设返回的数据在 response.data.outputs[0].outputs[0].results.message.data.text 中
+          this.textInfo =
+            response.data.outputs[0].outputs[0].results.message.data.text;
+            // 将搜索词和生成的内容存储在 searchResult 对象中
+          this.searchResult = {
+            searchTerm: this.dataIntro,
+            result: this.textInfo,
+          };
+        }
+      } catch (error) {
+        console.error("Error during retrieval:", error);
+        this.$message.error("检索失败,请稍后重试");
+      } finally {
+        this.loading = false; // 结束加载动画
+      }
+    },
+
+    onConfirm(e) {
+      /*       this.showConfirm = false; */
+      this.$emit("onPicked", this.searchResult);
+    },
+
+    onChangeTab(e) {
+      let _this = this;
+      /*      let item = _this.tableList[e]; */
+      _this.showSearch = true;
+
+      /*  item.sourceData = JSON.parse(item.source_data);
+
+      _this.position.tb = item.code; */
+      /*      _this.$nextTick(() => {
+        luckysheet.destroy();
+        luckysheet.create({
+          container: "luckysheet", //dom id
+          data: item.sourceData.exportJson.sheets, //excel数据
+          lang: "zh",
+          showinfobar: false, // 是否显示顶部信息栏
+          showstatisticBar: false, // 是否显示底部计数栏
+          sheetBottomConfig: false, // sheet页下方的添加行按钮和回到顶部按钮配置
+          allowEdit: false, // 是否允许前台编辑
+          enableAddRow: false, // 是否允许增加行
+          enableAddCol: false, // 是否允许增加列
+          sheetFormulaBar: false, // 是否显示公式栏
+          enableAddBackTop: false, // 返回头部按钮
+          showsheetbar: true, // 是否显示底部sheet页按钮
+          enableAddRow: false, //允许添加行
+          // 自定义配置底部sheet页按钮
+          showsheetbarConfig: {
+            add: false,
+            menu: false,
+          },
+          hook: {
+            cellMousedown: function (cell, position, sheetFile, ctx) {
+              _this.position.sheet = sheetFile.name;
+
+              _this.position.r = position.r;
+              _this.position.c = position.c;
+
+              if (cell.v) {
+                _this.position.value = cell.v;
+              } else {
+                _this.position.value = "";
+                cell.ct.s.map((res) => {
+                  _this.position.value += res.v;
+                });
+              }
+              _this.showConfirm = true;
+            },
+            cellUpdated: function (r, c, oldValue, newValue, isRefresh) {
+            },
+          },
+        });
+      }); */
+    },
+    initTableList() {
+      let _this = this;
+      searchSourceData({ page: 1, pageSize: 999, status: 5 }).then((res) => {
+        if (res.status != 200) return;
+        _this.tableList = res.data.dataList;
+      });
+    },
+  },
+};
+</script>
+  
+  <style lang="scss">
+@import "./index.scss";
+</style>
+  

+ 36 - 6
src/views/document/com/menus.vue

@@ -29,6 +29,10 @@
       <el-dialog  :visible.sync="showSourceData" append-to-body v-el-drag-dialog  width="300" custom-class="prod-verify" title="选择源数据">
           <sourceData  @onPicked="onPickedTab"></sourceData>
       </el-dialog>
+      <!-- 插入ai -->
+      <el-dialog  :visible.sync="showSourceAi" append-to-body v-el-drag-dialog  width="300" custom-class="prod-verify" title="选择AI">
+          <sourceAi  @onPicked="onPickedAi"></sourceAi>
+      </el-dialog>
 
 
 
@@ -38,6 +42,7 @@
 <script>
   import Formula from "./components/Formula";
   import sourceData from "./components/SourceData";
+  import sourceAi from "./components/sourceAi/index.vue";
   import Variable from "./components/Variable"
   import elDragDialog from '@/directive/el-drag-dialog'
 
@@ -45,7 +50,7 @@
     name:"menus",
     emits:["onEvents"],
     components:{
-      Formula,Variable,sourceData
+      Formula,Variable,sourceData,sourceAi
     },
     directives: { elDragDialog },
     data(){
@@ -53,6 +58,7 @@
         showFormula:false,
         showVariable:false,
         showSourceData:false,
+        showSourceAi:false,
         type:null,
         insertTitle:'插入变量',
         menus:[
@@ -101,11 +107,21 @@
                 name:"目录",
                 icon:"subject",
               },
-              // {
-              //   key:"pager",
-              //   name:"分页",
-              //   icon:"insertPage",
-              // },
+              /* {
+                key:"pager",
+                name:"分页",
+                icon:"insertPage",
+              }, */
+              {
+                key:"ai",
+                name:"AI模块",
+                icon:"insertAuth",
+              },
+              /* {
+                key:"aiEs",
+                name:"AI随笔",
+                icon:"insertAuth",
+              }, */
             ]
           },
           // {
@@ -140,6 +156,17 @@
     },
 
     methods:{
+      /* 插入ai */
+      onPickedAi(e){
+        let _this=this;
+        let item={
+            type:"insert",
+            key:'ai',
+            content:e,
+        }
+        this.$emit("onEvents",item);
+        this.showSourceAi=false;
+      },
       //选取公式
 
       onPickedTab(e){
@@ -173,6 +200,7 @@
         this.showVariable=false;
       },
       onClickMenus(e){
+        console.log(e);
           e.type="insert";
           if(e.key=="formual"){
               this.showFormula=true;
@@ -187,6 +215,8 @@
               this.insertTitle="插入常量";
             }
             this.showVariable=true;
+          }else if(e.key=="ai"){
+            this.showSourceAi=true
           }else{
               this.$emit("onEvents",e);
           }

+ 101 - 3
src/views/document/create.vue

@@ -106,7 +106,7 @@
         <div class="menus-box">
           <menus @onEvents="onInsert"></menus>
         </div>
-        <div class="editor-box" ref="tabHtml">
+        <div class="editor-box" ref="tabHtml" v-loading="loading">
           <editor
             :coms="coms"
             :comIndex="comIndex"
@@ -225,6 +225,7 @@ import ViewForm from "./com/view";
 import elDragDialog from "@/directive/el-drag-dialog";
 import draggable from "vuedraggable";
 import htmlDocx from "html-docx-js/dist/html-docx";
+import axios from "axios";
 // import htmlDocx from "htmlDocx";
 export default {
   name: "create",
@@ -274,6 +275,7 @@ export default {
       },
       userInfo: null,
       articleId: 0,
+      loading: false, // 增加 loading 状态
     };
   },
   watch: {
@@ -309,6 +311,72 @@ export default {
   },
 
   methods: {
+    /* 更新检索内容 */
+    /* async uptadeSearch() {
+      this.coms.forEach((item) => {
+        item.attrs.forEach((el) => {
+          if (el.type === "ai") {
+            // 在这里执行下一步操作
+            await this.retrieval(el);
+          }
+        });
+      });
+    }, */
+    async uptadeSearch() {
+      for (const item of this.coms) {
+        for (const el of item.attrs) {
+          if (el.type === "ai") {
+            await this.retrieval(el);
+          }
+        }
+      }
+    },
+    /* 初始化检索 */
+    async retrieval(el) {
+      this.loading = true; // 开始加载动画
+      try {
+        const response = await axios.post(
+          "http://58.246.234.210:7860/api/v1/run/3f84a841-cefd-44b3-9555-568cc3b6c2d2?stream=false",
+          {
+            input_value: el.search,
+            output_type: "chat",
+            input_type: "chat",
+            tweaks: {
+              "ChatInput-em6qC": {},
+              "ParseData-yO3YQ": {},
+              "Prompt-Wj75b": {},
+              "ChatOutput-zy9na": {},
+              "SplitText-O1knk": {},
+              "File-4j6Zd": {},
+              "OllamaEmbeddings-xbYXX": {},
+              "Chroma-OIejP": {},
+              "OllamaModel-04mEO": {},
+              "OllamaEmbeddings-UGvLP": {},
+              "Chroma-HzukO": {},
+            },
+          },
+          {
+            headers: {
+              "Content-Type": "application/json",
+            },
+          }
+        );
+
+        if (response.status === 200) {
+          // 假设返回的数据在 response.data.outputs[0].outputs[0].results.message.data.text 中
+          const resultText =
+            response.data.outputs[0].outputs[0].results.message.data.text;
+          // 将搜索词和生成的内容存储在 searchResult 对象中
+          el.content = resultText; // 重新赋值给原数组的对应 content
+         
+        }
+      } catch (error) {
+        console.error("Error during retrieval:", error);
+        this.$message.error("检索失败,请稍后重试");
+      } finally {
+        this.loading = false; // 结束加载动画
+      }
+    },
     loadTemplateInfo(e) {
       let _this = this;
       let par = {
@@ -393,6 +461,7 @@ export default {
         projects: e.projects,
       };
       _this.coms = JSON.parse(e.data);
+      this.uptadeSearch();
     },
     onRemove(index) {
       this.coms.splice(index, 1);
@@ -494,9 +563,38 @@ export default {
         case "addNew": //插入新记录
           _this.insertNew(e);
           break;
+        case "ai": //插入ai
+          _this.insertAI(e);
+          break;
       }
     },
+    /* 插入ai */
+    insertAI(e) {
+      let _this = this;
+      if (_this.comIndex < 0) {
+        _this.$alert("请选择插入图层");
+        return false;
+      }
+      let com = _this.coms[_this.comIndex];
 
+      let data = {
+        type: "ai",
+        id: "ai" + (com.attrs.length + 1),
+        dataId: "",
+        name: "AI",
+        intro: "插入AI",
+        content: e.content.result,
+        search: e.content.searchTerm,
+      };
+      com.attrs.push(data);
+      console.log(com.attrs);
+      if (com.type == "TextArea") {
+        //如果是图文,更新内容
+        _this.insertCmd = {
+          content: "{{" + data.id + "}}",
+        };
+      }
+    },
     insertProductAttr() {
       if (this.docAttr.linkProduct.length <= 0) {
         this.$alert("请选择文档关联商品信息");
@@ -685,14 +783,14 @@ export default {
         }
       }
     },
-    //插入原数据
+    //插入原数据
     insertSourceData(e) {
+      debugger;
       let _this = this;
       if (_this.comIndex < 0) {
         _this.$alert("请选择插入图层");
         return false;
       }
-
       let com = _this.coms[_this.comIndex];
       let data = {
         type: "sourceData",