lsc 2 months ago
parent
commit
fb5f23b8a9
2 changed files with 179 additions and 6 deletions
  1. BIN
      src/assets/icon/u_op.png
  2. 179 6
      src/components/courseDetail.vue

BIN
src/assets/icon/u_op.png


+ 179 - 6
src/components/courseDetail.vue

@@ -204,8 +204,11 @@
         </div>
         </div>
         <div class="student_body">
         <div class="student_body">
           <div class="sLeft" v-if="courseDetail.brief">
           <div class="sLeft" v-if="courseDetail.brief">
-            <div class="courseT">课程详情</div>
-            <div class="courseTd vditor-reset" v-html="MarkdownT(courseDetail.brief)"></div>
+            <div class="courseT">
+              <span>课程详情</span>
+              <div class="r_pub_button_op" v-if="(courseDetail.state == 6 || courseDetail.state == 5) && courseDetail.userid == userid" @click="aiChatContent">优化</div> 
+            </div>
+            <div v-loading="elLoading" element-loading-text="小可正在努力生成中,请稍等..." ref="chatDialog" class="courseTd vditor-reset" v-html="brief"></div>
           </div>
           </div>
           <div :class="courseDetail.brief != '' ? 'rightTd' : 'noBRight'">
           <div :class="courseDetail.brief != '' ? 'rightTd' : 'noBRight'">
             <div v-if="tType == 1 || tType == 4" class="checkBox">
             <div v-if="tType == 1 || tType == 4" class="checkBox">
@@ -213,13 +216,15 @@
                 >阶段选择
                 >阶段选择
                 <div v-show="false">
                 <div v-show="false">
                   {{
                   {{
-                    courseDetail.state == 1
+                    courseDetail.state == 1 
                       ? "阶段模式"
                       ? "阶段模式"
                       : courseDetail.state == 2
                       : courseDetail.state == 2
                       ? "任务模式"
                       ? "任务模式"
                       : courseDetail.state == 3
                       : courseDetail.state == 3
-                      ? "极简模式"
-                      : "AI模式"
+                      ? "极简模式" 
+                      : courseDetail.state == 4 || courseDetail.state == 5 
+                      ? "AI模式"
+                      : "上课模式"
                   }}
                   }}
                 </div></span
                 </div></span
               >
               >
@@ -247,7 +252,7 @@
                 <div class="jdAndTask">
                 <div class="jdAndTask">
                   <div>第{{ index + 1 }}阶段</div>
                   <div>第{{ index + 1 }}阶段</div>
                   <div
                   <div
-                    v-if="courseDetail.state == 2 || courseDetail.state == 3 || courseDetail.state == 4 || courseDetail.state == 5"
+                    v-if="courseDetail.state == 2 || courseDetail.state == 3 || courseDetail.state == 4 || courseDetail.state == 5 || courseDetail.state == 6"
                   >
                   >
                     任务查看
                     任务查看
                   </div>
                   </div>
@@ -1091,6 +1096,8 @@ import FileSaver from "file-saver";
 import scoreZong from './scoreZong/get.vue'
 import scoreZong from './scoreZong/get.vue'
 
 
 import MarkdownIt from "markdown-it";
 import MarkdownIt from "markdown-it";
+import { v4 as uuidv4 } from "uuid";
+
 
 
 var OpenCC = require("opencc-js");
 var OpenCC = require("opencc-js");
 let converter = OpenCC.Converter({
 let converter = OpenCC.Converter({
@@ -1187,6 +1194,12 @@ export default {
       dialogVisibleQR: false,
       dialogVisibleQR: false,
       checkStage: 0,
       checkStage: 0,
       tools: JSON.parse(converter(JSON.stringify(tools))),
       tools: JSON.parse(converter(JSON.stringify(tools))),
+      brief: '',
+      sbrief: '',
+      setting: {},
+      elLoading: false,
+      eltLoading: false,
+      languageSetting: 0,
     };
     };
   },
   },
   computed: {
   computed: {
@@ -1435,6 +1448,8 @@ export default {
 								window.parent.postMessage({ tools: "openCourseEUpdate",cid:this.id }, "*");
 								window.parent.postMessage({ tools: "openCourseEUpdate",cid:this.id }, "*");
 							}else if(this.courseDetail.state == 4 || this.courseDetail.state == 5){
 							}else if(this.courseDetail.state == 4 || this.courseDetail.state == 5){
 								window.parent.postMessage({ tools: "openCourseAiUpdate",cid:this.id }, "*");
 								window.parent.postMessage({ tools: "openCourseAiUpdate",cid:this.id }, "*");
+              }else if(this.courseDetail.state == 6){
+								window.parent.postMessage({ tools: "openCourseAiUpdate2",cid:this.id }, "*");
               }
               }
 
 
 						})
 						})
@@ -1725,6 +1740,20 @@ export default {
       loading.close();
       loading.close();
       // this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
       // this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
       this.courseDetail = res.data[0][0];
       this.courseDetail = res.data[0][0];
+      if(res.data[0][0].setting){
+        try {
+          this.languageSetting = (JSON.parse(res.data[0][0].setting).languageSetting || JSON.parse(res.data[0][0].setting).languageSetting == 0) ? JSON.parse(res.data[0][0].setting).languageSetting : 0;
+          this.sbrief = JSON.parse(res.data[0][0].setting).sbrief ? JSON.parse(res.data[0][0].setting).sbrief : '';
+          this.setting = JSON.parse(res.data[0][0].setting)
+        }catch(error){
+          console.error(error)
+        }
+      }
+      this.brief = this.sbrief ? this.sbrief : this.MarkdownT(this.courseDetail.brief)
+      
+      if(this.brief && !this.sbrief && (this.courseDetail.state == 6 || this.courseDetail.state == 5) && this.courseDetail.userid == this.userid){
+        this.aiChatContent()
+      }
       this.isFollow = res.data[0][0].follow;
       this.isFollow = res.data[0][0].follow;
       this.followC = res.data[0][0].followC
       this.followC = res.data[0][0].followC
         ? res.data[0][0].followC.split("-")[0]
         ? res.data[0][0].followC.split("-")[0]
@@ -2245,6 +2274,124 @@ export default {
         });
         });
       });
       });
     },
     },
+    getLang(){
+      let lang = ''
+      if(this.languageSetting == 0){
+        lang = 'Chinese.'
+      }else if(this.languageSetting == 1){
+        lang = 'Traditional Chinese.'
+      }else if(this.languageSetting == 2){
+        lang = 'English.'
+      }
+      return lang
+    },
+    updateSetting(){
+			let params = [{
+				cid: this.id,
+				setting: JSON.stringify(this.setting)
+			}]
+
+			this.ajax.post(this.$store.state.api+'updateWorksSetting',params).then(res=>{
+				if(res.data==1){
+					console.log('保存操作成功')
+				}else{
+					console.log('保存操作失败')
+				}
+			}).catch(e=>{
+				console.log('保存操作失败')
+				console.log(e)
+			})
+		},
+    aiChatContent() {
+      if(this.elLoading || this.eltLoading){
+        this.$message.error('正在优化中,请稍后')
+        return
+      }
+      this.elLoading = true
+      this.eltLoading = true
+      let _uuid = uuidv4();
+      this.brief = "";
+      let params = {
+        model: "qwen-plus",
+        temperature: 0,
+        max_tokens: 4096,
+        top_p: 1,
+        frequency_penalty: 0,
+        presence_penalty: 0,
+        messages: [
+          {
+            role: "user",
+            content: `Language: ${this.getLang()} 总结以下内容为150字左右的课程简介:${this.courseDetail.brief}`
+          }
+        ],
+        uid: _uuid,
+        mind_map_question: ""
+      }
+
+      this.ajax
+        .post("https://gpt4.cocorobo.cn/chat", params)
+        .then(res => {
+          if (
+            converter(res.data.FunctionResponse.result) ==
+            converter("发送成功")
+          ) {
+          } else {
+            this.$message.warning(res.data.FunctionResponse.result);
+          }
+        })
+        .catch(e => {
+          console.log(e);
+          this.elLoading = false
+          this.eltLoading = false
+        });
+      this.getAiContent(_uuid);
+    },
+    getAiContent(_uid) {
+      this.fasource = new EventSource(
+        `https://gpt4.cocorobo.cn/stream/${_uid}`
+      ); //http://gpt4.cocorobo.cn:8011/stream/     https://gpt4.cocorobo.cn/stream/
+      let _allText = "";
+      let _mdText = "";
+      const md = new MarkdownIt();
+      this.fasource.onmessage = _e => {
+        if (_e.data.replace("'", "").replace("'", "") == "[DONE]") {
+          //对话已经完成
+          _mdText = _mdText.replace("_", "");
+          this.fasource.close();
+          this.fasource = null;
+          this.$nextTick(() => {
+            this.$refs.chatDialog.scrollTop = this.$refs.chatDialog.scrollHeight;
+          });
+          this.brief = _mdText;
+          this.setting.sbrief = _mdText
+          this.eltLoading = false
+          this.$forceUpdate()
+          this.updateSetting();
+          return;
+        } else {
+          //对话还在继续
+          let _text = "";
+          _text = _e.data.replaceAll("'", "");
+          if (_allText == "") {
+            _allText = _text.replace(/^\n+/, ""); //去掉回复消息中偶尔开头就存在的连续换行符
+          } else {
+            _allText += _text;
+          }
+          _mdText = _allText + "_";
+          _mdText = _mdText.replace(/\\n/g, "\n");
+          _mdText = _mdText.replace(/\\/g, "");
+          if (_allText.split("```").length % 2 == 0) _mdText += "\n```\n";
+          //转化返回的回复流数据
+          _mdText = md.render(_mdText);
+          this.brief = _mdText;
+          this.elLoading = false
+          this.$nextTick(() => {
+            this.$refs.chatDialog.scrollTop = this.$refs.chatDialog.scrollHeight;
+          });
+          // 处理流数据
+        }
+      };
+    },
   },
   },
   created() {
   created() {
     // if(this.tType == 1 || this.tType == 4){
     // if(this.tType == 1 || this.tType == 4){
@@ -2703,6 +2850,9 @@ export default {
   border-left: 3px solid #3681fc;
   border-left: 3px solid #3681fc;
   padding-left: 5px;
   padding-left: 5px;
   font-weight: bold;
   font-weight: bold;
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
 }
 }
 
 
 .courseTd {
 .courseTd {
@@ -3295,4 +3445,27 @@ export default {
 	border-color: #1463eb !important;
 	border-color: #1463eb !important;
 }
 }
 
 
+
+.r_pub_button_op{
+  color: #448bff;
+  font-size: 14px;
+  cursor: pointer;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+}
+
+.r_pub_button_op::before {
+  content: "";
+  width: 14px;
+  height: 14px;
+  min-width: 14px;
+  min-height: 14px;
+  background-size: 100% 100%;
+  display: block;
+  margin-right: 7px;
+  background-image: url(../assets/icon/u_op.png);
+}
+
+
 </style>
 </style>