This commit is contained in:
zdg 2024-12-18 15:59:51 +08:00
commit 6fa0aa6e5f
9 changed files with 447 additions and 221 deletions

View File

@ -10,11 +10,10 @@ export const createChart = ({ headers, data }) => {
}) })
} }
// 大模型对话 // 大模型对话
export const sendChart = ({ headers, data }) => { export const sendChart = (data) => {
return request({ return request({
url: '/qf/sendTalk', url: '/qf/sendTalk',
method: 'post', method: 'post',
headers,
data, data,
}) })
} }

View File

@ -30,7 +30,7 @@
</div> </div>
</el-scrollbar> </el-scrollbar>
<div class="file-list"> <div class="file-list">
<el-dropdown @command="changeFile"> <el-dropdown @command="changeFile" v-if="type == 3">
<span class="el-dropdown-link"> <span class="el-dropdown-link">
{{ curFile.fileName }} {{ curFile.fileName }}
<i class="iconfont icon-xiangxia"></i> <i class="iconfont icon-xiangxia"></i>
@ -54,7 +54,7 @@
</template> </template>
<script setup> <script setup>
import { ref, reactive, onMounted, onUnmounted, watch } from 'vue' import { ref, reactive, onMounted, onUnmounted } from 'vue'
import { completion, docList } from '@/api/mode/index' import { completion, docList } from '@/api/mode/index'
import { sessionStore } from '@/utils/store' import { sessionStore } from '@/utils/store'
import { dataSetJson } from '@/utils/comm.js' import { dataSetJson } from '@/utils/comm.js'
@ -71,7 +71,7 @@ const props = defineProps({
item: { item: {
type: Object, type: Object,
default: () => { default: () => {
return { name: '11' } return { name: '' }
} }
}, },
type: { type: {
@ -125,19 +125,6 @@ const saveAdjust = (item) =>{
emitter.emit('onSaveAdjust', item.msg) emitter.emit('onSaveAdjust', item.msg)
} }
const modeType = ref('课标')
watch(() => props.type, (newVal) => {
if (newVal == 1){
modeType.value = '课标'
}
if (newVal == 2){
modeType.value = '教材'
}
if (newVal == 2){
modeType.value = '考试'
}
}, { immediate: false })
const curFile = reactive({}) const curFile = reactive({})
const dataset_id = ref('') const dataset_id = ref('')
@ -160,11 +147,12 @@ const changeFile = (val) =>{
params.document_ids = val.docId params.document_ids = val.docId
} }
const modeType = ref('')
onMounted(() => { onMounted(() => {
let data = sessionStore.get('subject.curNode') let data = sessionStore.get('subject.curNode')
Object.assign(curNode, data); Object.assign(curNode, data);
modeType.value = props.type == 1 ? '课标' : props.type == 2 ? '教材' : '考试'
let jsonKey = `${modeType.value}-${data.edustage}-${data.edusubject}` let jsonKey = `${modeType.value}-${data.edustage}-${data.edusubject}`
params.dataset_id = dataSetJson[jsonKey] params.dataset_id = dataSetJson[jsonKey]
if(props.type == 3){ if(props.type == 3){

View File

@ -14,7 +14,10 @@
</el-dropdown-menu> </el-dropdown-menu>
</template> </template>
</el-dropdown> </el-dropdown>
<div> <div class="flex">
<el-select v-model="curMode" placeholder="Select" class="mr-4 w-30">
<el-option v-for="item in modeOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<el-button type="danger" link :disabled="!(templateList.length)" @click="removeItem(curTemplate, false)"> <el-button type="danger" link :disabled="!(templateList.length)" @click="removeItem(curTemplate, false)">
删除 删除
</el-button> </el-button>
@ -52,7 +55,8 @@
<i class="iconfont icon-ai"></i> <i class="iconfont icon-ai"></i>
</div> </div>
<div class="item-answer"> <div class="item-answer">
<TypingEffect v-if="isStarted[index]" :text="item.answer" :delay="10" :aiShow="item.aiShow" @complete="handleCompleteText($event,index)" @updateScroll="scrollToBottom($event,index)" /> <TypingEffect v-if="isStarted[index]" :text="item.answer" :delay="10" :aiShow="item.aiShow"
@complete="handleCompleteText($event, index)" @updateScroll="scrollToBottom($event, index)" />
</div> </div>
</div> </div>
<div class="ai-btn" v-if="item.answer"> <div class="ai-btn" v-if="item.answer">
@ -86,6 +90,7 @@
import { ref, reactive, onMounted, onUnmounted, nextTick } from 'vue' import { ref, reactive, onMounted, onUnmounted, nextTick } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { tempSave, completion, modelList, removeChildTemp, tempResult, editTempResult } from '@/api/mode/index' import { tempSave, completion, modelList, removeChildTemp, tempResult, editTempResult } from '@/api/mode/index'
import { createChart, sendChart } from '@/api/ai/index'
import { sessionStore } from '@/utils/store' import { sessionStore } from '@/utils/store'
import keywordDialog from './keyword-dialog.vue'; import keywordDialog from './keyword-dialog.vue';
import AdjustDialog from './adjust-dialog.vue' import AdjustDialog from './adjust-dialog.vue'
@ -94,10 +99,23 @@ import TypingEffect from '@/components/typing-effect/index.vue'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import emitter from '@/utils/mitt'; import emitter from '@/utils/mitt';
import { dataSetJson } from '@/utils/comm.js' import { dataSetJson } from '@/utils/comm.js'
import { cloneDeep } from 'lodash'
const props = defineProps(['type']) const props = defineProps(['type'])
const { user } = useUserStore() const { user } = useUserStore()
const curMode = ref(1)
const modeOptions = ref([
{
label: '教学大模型',
value: 1
},
{
label: '知识库模型',
value: 2
}
])
/*****************提示词相关****************/ /*****************提示词相关****************/
/** /**
@ -122,7 +140,7 @@ const editKeyWord = (item, val) => {
Object.assign(editItem, item) Object.assign(editItem, item)
editItem.isAdd = val editItem.isAdd = val
isWordDialog.value = true isWordDialog.value = true
} }
/*******************模板相关**********************/ /*******************模板相关**********************/
@ -139,9 +157,9 @@ const curTemplate = reactive({ name: '', id: '' })
const templateList = ref([]) const templateList = ref([])
const childTempList = ref([]) const childTempList = ref([])
const getTemplateList = () => { const getTemplateList = () => {
modelList({ createUser: user.userId, model: props.type, type: 1, pageNum: 1, pageSize: 10000, ex1: curNode.edustage, ex2: curNode.edusubject }).then(res => { modelList({ createUser: user.userId, model: props.type, type: 1, pageNum: 1, pageSize: 10000, ex1: curNode.edustage, ex2: curNode.edusubject }).then(res => {
templateList.value = res.rows templateList.value = res.rows
if(res.rows.length > 0){ if (res.rows.length > 0) {
Object.assign(curTemplate, res.rows[0]); Object.assign(curTemplate, res.rows[0]);
getChildTemplate() getChildTemplate()
} }
@ -151,7 +169,7 @@ const getChildTemplate = () => {
tempLoading.value = true tempLoading.value = true
modelList({ model: props.type, type: 2, parentId: curTemplate.id, ex1: curNode.edustage, ex2: curNode.edusubject }).then(res => { modelList({ model: props.type, type: 2, parentId: curTemplate.id, ex1: curNode.edustage, ex2: curNode.edusubject }).then(res => {
childTempList.value = res.rows childTempList.value = res.rows
if(childTempList.value.length){ if (childTempList.value.length) {
childTempList.value.forEach(item => item.answer = '') childTempList.value.forEach(item => item.answer = '')
} }
getTempResult() getTempResult()
@ -173,28 +191,28 @@ const getTempResult = () => {
} }
}) })
}) })
if(rows.length > 0){ if (rows.length > 0) {
isStarted.value = new Array(rows.length).fill(true) isStarted.value = new Array(rows.length).fill(true)
} }
}) })
} }
const scrollToBottom = (height,index) =>{ const scrollToBottom = (height, index) => {
if (listRef.value) { if (listRef.value) {
let sum = 0 let sum = 0
let listDom = listRef.value.children let listDom = listRef.value.children
if(index == 0){ if (index == 0) {
// 220 // 220
let screenHeight = window.innerHeight - 220 let screenHeight = window.innerHeight - 220
if(height > screenHeight){ if (height > screenHeight) {
listRef.value.scrollTop = (height - screenHeight + 50) listRef.value.scrollTop = (height - screenHeight + 50)
} }
} }
else{ else {
for(let i = 0; i < index; i++){ for (let i = 0; i < index; i++) {
sum += listDom[i].clientHeight sum += listDom[i].clientHeight
} }
listRef.value.scrollTop = sum + height listRef.value.scrollTop = sum + height
@ -252,7 +270,6 @@ const removeItem = async (item, isChild) => {
} }
} }
// Ai // Ai
const curIndex = ref(-1) const curIndex = ref(-1)
const isAdjust = ref(false) const isAdjust = ref(false)
@ -277,6 +294,7 @@ const params = reactive(
dataset_id: '' dataset_id: ''
} }
) )
const prompt = ref('')
// //
const isAgain = ref(false) const isAgain = ref(false)
@ -285,10 +303,10 @@ const againResult = async (index, item) => {
isStarted.value[index] = false isStarted.value[index] = false
childTempList.value[index].answer = '' childTempList.value[index].answer = ''
if(index == 0){ if (index == 0) {
listRef.value.scrollTop = 0 listRef.value.scrollTop = 0
}else{ } else {
scrollToBottom(50, index) scrollToBottom(50, index)
} }
@ -296,8 +314,28 @@ const againResult = async (index, item) => {
await nextTick() await nextTick()
childTempList.value[index].loading = true childTempList.value[index].loading = true
item.aiShow = true item.aiShow = true
params.prompt = `按照${item.prompt}的要求,针对${curNode.edustage}${curNode.edusubject}${modeType.value}${curNode.itemtitle}进行教学分析`
const { data } = await completion(params) let str = cloneDeep(prompt.value)
str = str.replace('{模板标题}',item.name)
str = str.replace('{模板内容}',item.prompt)
params.prompt = str
params.template = item.prompt
let data = null;
//
if (mode.value == 1) {
const res = await sendChart({
content: params.prompt,
conversationId: conversation_id.value,
stream: false
})
data = res.data
} else {
//
const res = await completion(params)
data = res.data
}
childTempList.value[index].answer = getResult(data.answer); childTempList.value[index].answer = getResult(data.answer);
isStarted.value[index] = true isStarted.value[index] = true
@ -305,13 +343,14 @@ const againResult = async (index, item) => {
childTempList.value[index].loading = false childTempList.value[index].loading = false
} }
} }
// //
const getCompletion = async () => { const getCompletion = async () => {
isStarted.value = new Array(childTempList.length).fill(false) isStarted.value = new Array(childTempList.length).fill(false)
isStarted.value[0] = true isStarted.value[0] = true
childTempList.value.forEach(item =>{ childTempList.value.forEach(item => {
if(item.answer){ if (item.answer) {
item.answer = '' item.answer = ''
} }
}) })
@ -320,8 +359,27 @@ const getCompletion = async () => {
try { try {
item.loading = true item.loading = true
item.aiShow = true item.aiShow = true
params.prompt = `按照${item.prompt}的要求,针对${curNode.edustage}${curNode.edusubject}${modeType.value}${curNode.itemtitle}进行教学分析` let str = cloneDeep(prompt.value)
const { data } = await completion(params) str = str.replace('{模板标题}',item.name)
str = str.replace('{模板内容}',item.prompt)
params.prompt = str
params.template = item.prompt
//
let data = null
if (curMode.value == 1) {
const res = await sendChart({
content: params.prompt,
conversationId: conversation_id.value,
stream: false
})
data = res.data
}
//
else {
const res = await completion(params)
data = res.data
}
item.answer = getResult(data.answer) item.answer = getResult(data.answer)
onSaveTemp(item) onSaveTemp(item)
} finally { } finally {
@ -330,14 +388,14 @@ const getCompletion = async () => {
} }
} }
const handleCompleteText = async (answer, index) =>{ const handleCompleteText = async (answer, index) => {
if (index < childTempList.value.length - 1) { if (index < childTempList.value.length - 1) {
isStarted.value[index + 1] = true; // isStarted.value[index + 1] = true; //
} }
if(isAgain.value){ if (isAgain.value) {
try{ try {
await editTempResult({ id: childTempList.value[index].resultId, content: answer }) await editTempResult({ id: childTempList.value[index].resultId, content: answer })
}finally{ } finally {
isAgain.value = false isAgain.value = false
} }
} }
@ -386,6 +444,30 @@ emitter.on('onGetMain', () => {
}) })
//
const conversation_id = ref('')
const getChartId = () => {
createChart({ app_id: '712ff0df-ed6b-470f-bf87-8cfbaf757be5' }).then(res => {
localStorage.setItem("conversation_id", res.data.conversation_id);
conversation_id.value = res.data.conversation_id;
})
}
// prompt
const getPrompt = async () => {
const { rows } = await modelList({ model: 5 })
let str = rows.find(item => item.name.indexOf(modeType.value) != -1).prompt
str = str.replace('{学段}', curNode.edustage)
str = str.replace('{学科}', curNode.edusubject)
let bookV = curNode.roottitle.split('-')[1] + '版本'
str = str.replace('{教材版本}', bookV)
str = str.replace('{课程名称}', `${curNode.itemtitle}`)
if(modeType.value == '课标'){
str = str.replace('{课标名称}', `${curNode.edustage}${curNode.edusubject}课标`)
}
prompt.value = str
}
const curNode = reactive({}) const curNode = reactive({})
const modeType = ref('') const modeType = ref('')
onMounted(() => { onMounted(() => {
@ -396,6 +478,15 @@ onMounted(() => {
getTemplateList() getTemplateList()
let jsonKey = `${modeType.value}-${data.edustage}-${data.edusubject}` let jsonKey = `${modeType.value}-${data.edustage}-${data.edusubject}`
params.dataset_id = dataSetJson[jsonKey] params.dataset_id = dataSetJson[jsonKey]
// ID
conversation_id.value = localStorage.getItem('conversation_id')
if (!conversation_id.value) {
getChartId();
}
// prompt
getPrompt()
}) })
// //

View File

@ -83,7 +83,7 @@ export const constantRoutes = [
path: 'questionUpload', path: 'questionUpload',
component: () => import('@/views/classTask/newClassTaskAssign/questionUpload/index.vue'), component: () => import('@/views/classTask/newClassTaskAssign/questionUpload/index.vue'),
name: 'questionUpload', name: 'questionUpload',
meta: { title: '习题上传' } meta: { title: '习题上传', showBread: true }
}, },
{ {
path: 'aiKolors', path: 'aiKolors',

View File

@ -5,6 +5,7 @@ import { JYApiListCT, JYApiListOriginYear, JYApiListSO} from "@/utils/examQuesti
const useClassTaskStore = defineStore('classTask',{ const useClassTaskStore = defineStore('classTask',{
state: () => ({ state: () => ({
isOpenQuestUploadView: false, // 是否打开习题上传的页面
classListIds: [], classListIds: [],
entpCourseWorkTypeList: [ entpCourseWorkTypeList: [
{value: 0, label: "不限"}, {value: 0, label: "不限"},

View File

@ -149,10 +149,14 @@ import { useGetHomework } from '@/hooks/useGetHomework'
import { sessionStore } from '@/utils/store' import { sessionStore } from '@/utils/store'
import { useRouter, useRoute } from 'vue-router' import { useRouter, useRoute } from 'vue-router'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import useClassTaskStore from '@/store/modules/classTask'
const userStore = useUserStore().user const userStore = useUserStore().user
const route = useRoute(); const route = useRoute();
const router = useRouter() const router = useRouter()
const { proxy } = getCurrentInstance() const { proxy } = getCurrentInstance()
const useClassTaskStores = useClassTaskStore();
const props = defineProps({ const props = defineProps({
currentCourse: Object, currentCourse: Object,
}) })
@ -189,6 +193,7 @@ const boardLoading = ref(false);
const fileLoading = ref(false); // loading const fileLoading = ref(false); // loading
onMounted(() => { onMounted(() => {
console.log("----onMounted-------")
currentRow.value = {id:0}; currentRow.value = {id:0};
if(propsQueryCourseObj){ if(propsQueryCourseObj){
if(JSON.parse(propsQueryCourseObj)){ if(JSON.parse(propsQueryCourseObj)){
@ -216,7 +221,28 @@ onMounted(() => {
} }
} }
initHomeWork(); initHomeWork();
isInToMyQuestion(); //
}) })
//
const isInToMyQuestion = () => {
console.log('isOpenQuestUploadView',useClassTaskStores.isOpenQuestUploadView);
if(useClassTaskStores.isOpenQuestUploadView){
useClassTaskStores.isOpenQuestUploadView = false;
currentRow.value = {id:1}; //
activeAptTab.value = "个人题库";
//
classWorkForm.id = 0;
classWorkForm.uniquekey = ""; //
classWorkForm.worktype = "习题训练"; //
classWorkForm.title = ""; //
classWorkForm.quizlist = []; //
classWorkForm.chooseWorkLists = []; // list
classWorkForm.fileHomeworkList = []; //
classWorkForm.whiteboardObj = ""; // -
classWorkForm.question = ""; // -
}
}
watch(() => props.currentCourse, (newVal, oldVal) => { watch(() => props.currentCourse, (newVal, oldVal) => {
if(newVal){ if(newVal){
courseObj.textbookId = newVal.textbookId // courseObj.textbookId = newVal.textbookId //

View File

@ -74,7 +74,7 @@
<script setup> <script setup>
import "vue-cropper/dist/index.css"; import "vue-cropper/dist/index.css";
import { VueCropper } from "vue-cropper"; import { VueCropper } from "vue-cropper";
import { onMounted, ref,watch, reactive, getCurrentInstance,nextTick } from 'vue' import { onMounted, ref,watch, reactive, getCurrentInstance,nextTick, onUnmounted } from 'vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
@ -88,6 +88,8 @@ import { useRouter, useRoute } from 'vue-router'
import { ocrImg2ExamByManualUpl, ocrImg2ItemByManualUpl } from "@/views/classTask/newClassTaskAssign/questionUpload/ocrImg2ExamQues"; import { ocrImg2ExamByManualUpl, ocrImg2ItemByManualUpl } from "@/views/classTask/newClassTaskAssign/questionUpload/ocrImg2ExamQues";
import QuesItem from "@/views/classTask/newClassTaskAssign/questionUpload/quesItem/index.vue"; import QuesItem from "@/views/classTask/newClassTaskAssign/questionUpload/quesItem/index.vue";
import useClassTaskStore from '@/store/modules/classTask'
// const Remote = require('@electron/remote') // const Remote = require('@electron/remote')
// const fs = require('fs'); // const fs = require('fs');
@ -96,7 +98,9 @@ import useUserStore from '@/store/modules/user'
const userStore = useUserStore().user const userStore = useUserStore().user
const route = useRoute(); const route = useRoute();
const router = useRouter() const router = useRouter()
const { proxy } = getCurrentInstance() const { proxy } = getCurrentInstance();
const useClassTaskStores = useClassTaskStore();
const props = defineProps({ const props = defineProps({
}) })
@ -151,6 +155,7 @@ const cropOption = reactive({
onMounted(() => { onMounted(() => {
useClassTaskStores.isOpenQuestUploadView = true; //
console.log('propsQueryCourseObj', JSON.parse(propsQueryCourseObj)); console.log('propsQueryCourseObj', JSON.parse(propsQueryCourseObj));
if(propsQueryCourseObj&&JSON.parse(propsQueryCourseObj)){ if(propsQueryCourseObj&&JSON.parse(propsQueryCourseObj)){
courseObj.textbookId = JSON.parse(propsQueryCourseObj).bookObj // courseObj.textbookId = JSON.parse(propsQueryCourseObj).bookObj //
@ -161,7 +166,13 @@ onMounted(() => {
} }
initHomeWork(); initHomeWork();
}) })
onUnmounted(()=>{
// 1s isOpenQuestUploadView
setTimeout(()=>{
useClassTaskStores.isOpenQuestUploadView = false; //
console.log('onUnmounted 习题上传');
}, 1000)
})
/** /**
* 获取 entpcourseid 获取作业列表 * 获取 entpcourseid 获取作业列表

View File

@ -1,6 +1,7 @@
import { ElMessageBox, ElMessage } from "element-plus"; import { ElMessageBox, ElMessage } from "element-plus";
import qs from "qs"; import qs from "qs";
import axios from 'axios' import axios from 'axios'
import request from '@/utils/request'
import { pyOCRAPI } from "@/api/education/entpcoursework"; import { pyOCRAPI } from "@/api/education/entpcoursework";
@ -9,13 +10,20 @@ const baidubceConfig = {
// Header // Header
'Content-Type': "application/x-www-form-urlencoded", 'Content-Type': "application/x-www-form-urlencoded",
// 格式 // 格式
'Accept' : 'application/json', 'Accept': 'application/json',
// id(临时测试) // id(临时测试)
'client_id': "U0DrGBE6X92IXgV6cJMNON8F", 'client_id': "U0DrGBE6X92IXgV6cJMNON8F",
// 密钥(临时测试) // 密钥(临时测试)
'client_secret': 'oWb0M0YWMmZPMQIhIUkJX99ddr7h61qf', 'client_secret': 'oWb0M0YWMmZPMQIhIUkJX99ddr7h61qf',
}; };
export function getOcrContent(data) {
return request({
url: '/ocr/exam',
method: 'post',
data: data
})
}
/** /**
@ -34,8 +42,8 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
let regex = null; let regex = null;
// 识别内容拼接 // 识别内容拼接
let ocrTxt = '' let ocrTxt = ''
if(isLocalTest) { if (isLocalTest) {
// 临时本地测试json格式跟百度ocr一致 // 临时本地测试json格式跟百度ocr一致
const response = await fetch('/cropImgTest/single.json'); const response = await fetch('/cropImgTest/single.json');
const resOcr = await response.json(); const resOcr = await response.json();
@ -59,7 +67,7 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
} }
else { else {
const tmp = await ocrImg2Json(imgBase64); const tmp = await ocrImg2Json(imgBase64);
if(!tmp?.data) { if (!tmp?.data) {
return examItem; return examItem;
} }
ocrJson = tmp.data.results; ocrJson = tmp.data.results;
@ -69,12 +77,12 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
}); });
} }
if(ocrJson == '') { if (ocrJson == '') {
ElMessage.error('[人工录入-单项]识别的图片为空, 识别失败, 请检查重试!'); ElMessage.error('[人工录入-单项]识别的图片为空, 识别失败, 请检查重试!');
return examItem; return examItem;
} }
if(ocrTxt == '') { if (ocrTxt == '') {
ElMessage.error('[人工录入-单项]识别内容拼接失败, 请检查重试!'); ElMessage.error('[人工录入-单项]识别内容拼接失败, 请检查重试!');
return examItem; return examItem;
} }
@ -87,7 +95,7 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
ocrTxt = ocrTxt.replace(regex, '').replace(/<br \/>/g, ''); ocrTxt = ocrTxt.replace(regex, '').replace(/<br \/>/g, '');
examItem = ocrTxt; examItem = ocrTxt;
} }
else if (curItem === 'workdesc') { else if (curItem === 'workdesc') {
// 该类型下无需[判断题]和[主观题]处理 // 该类型下无需[判断题]和[主观题]处理
if (examType.includes('复合题')) { if (examType.includes('复合题')) {
// 因[题目+选项]分离正则匹配需要, 故需开头手动拼一个<br /> // 因[题目+选项]分离正则匹配需要, 故需开头手动拼一个<br />
@ -96,13 +104,13 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
worktype: '单选题', worktype: '单选题',
params: [], params: [],
} }
mutiParams.arrWorkDesc.forEach( item => { mutiParams.arrWorkDesc.forEach(item => {
const obj = { const obj = {
title: item.title, title: item.title,
workanswer: '', workanswer: '',
checkAnswer: [], checkAnswer: [],
type: item.type, type: item.type,
options: item.options.map(element => {return {text: element.replace(/<br \/>/g, '')}}), options: item.options.map(element => { return { text: element.replace(/<br \/>/g, '') } }),
} }
examItem.params.push(obj); examItem.params.push(obj);
}); });
@ -114,7 +122,7 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
// 先判断是否存在选项标识, 且存在2个及以上(A.---1.---(1)---1) // 先判断是否存在选项标识, 且存在2个及以上(A.---1.---(1)---1)
regex = /\s*[A-H][..。]/g; regex = /\s*[A-H][..。]/g;
const matches = ocrTxt.match(regex); const matches = ocrTxt.match(regex);
if (matches==null || matches.length < 2){ if (matches == null || matches.length < 2) {
ElMessage.error('[人工录入-单项]识别[选项]失败, 请检查重试!'); ElMessage.error('[人工录入-单项]识别[选项]失败, 请检查重试!');
return examItem; return examItem;
} }
@ -138,7 +146,7 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
examItem.push(obj); examItem.push(obj);
return examItem; return examItem;
} }
} }
else if (curItem === 'workanswer') { else if (curItem === 'workanswer') {
// 该类型下只做[主观题]和[复合题]的处理 // 该类型下只做[主观题]和[复合题]的处理
@ -163,8 +171,8 @@ export const ocrImg2ExamByManualUpl = async (isLocalTest = false, imgBase64 = ''
let ocrJson = ''; let ocrJson = '';
// 识别内容拼接 // 识别内容拼接
let ocrTxt = ''; let ocrTxt = '';
if(isLocalTest) { if (isLocalTest) {
// 临时本地测试json格式跟百度ocr一致 // 临时本地测试json格式跟百度ocr一致
const response = await fetch('/cropImgTest/single.json'); const response = await fetch('/cropImgTest/single.json');
const resOcr = await response.json(); const resOcr = await response.json();
@ -173,7 +181,7 @@ export const ocrImg2ExamByManualUpl = async (isLocalTest = false, imgBase64 = ''
ocrJson.forEach(ele => { ocrJson.forEach(ele => {
ocrTxt += `${ele.words.word}<br />`; ocrTxt += `${ele.words.word}<br />`;
}); });
//-------------------------------------------------------------- //--------------------------------------------------------------
// 备用ocr识别服务 python的一个识别服务 // 备用ocr识别服务 python的一个识别服务
// const response = await ocrImgPyJson(imgBase64); // const response = await ocrImgPyJson(imgBase64);
@ -186,7 +194,7 @@ export const ocrImg2ExamByManualUpl = async (isLocalTest = false, imgBase64 = ''
// }); // });
} else { } else {
const tmp = await ocrImg2Json(imgBase64); const tmp = await ocrImg2Json(imgBase64);
if(!tmp?.data) { if (!tmp?.data) {
return examQues; return examQues;
} }
ocrJson = tmp.data.results; ocrJson = tmp.data.results;
@ -195,20 +203,20 @@ export const ocrImg2ExamByManualUpl = async (isLocalTest = false, imgBase64 = ''
}); });
} }
if(ocrJson == '') { if (ocrJson == '') {
ElMessage.error('[人工录入-整题]图片识别内容为空, 识别失败, 请重试!'); ElMessage.error('[人工录入-整题]图片识别内容为空, 识别失败, 请重试!');
return examQues; return examQues;
} }
if(ocrTxt == '') {
if (ocrTxt == '') {
ElMessage.error('[人工录入-整题]识别内容拼接失败, 请重试!'); ElMessage.error('[人工录入-整题]识别内容拼接失败, 请重试!');
return examQues; return examQues;
} }
// 识别内容转为试题结构 // 识别内容转为试题结构
examQues = assembleExam(ocrTxt); examQues = assembleExam(ocrTxt);
if(examQues.err != '') { if (examQues.err != '') {
ElMessage.error(`[人工录入-整题]${examQues.err}, 请重试!`); ElMessage.error(`[人工录入-整题]${examQues.err}, 请重试!`);
examQues = {}; examQues = {};
} }
@ -226,30 +234,36 @@ const ocrImg2Json = async (urlBase64) => {
ElMessage.error("未检测到截图图片, 请截取图片后再识别"); ElMessage.error("未检测到截图图片, 请截取图片后再识别");
return null; return null;
} }
const resToken = await bdyAPI_getToken();
if (resToken.status !== 200) {
ElMessage.error("百度智能云用户标识有误");
return null;
}
const token = resToken.data?.access_token;
let base64Code = urlBase64.split(",")[1]; let base64Code = urlBase64.split(",")[1];
const query = { const resOcr = await getOcrContent({ base64Code: base64Code });
image: base64Code, //图片地址(base64) if (resOcr.code !== 200) {
line_probability: false, //是否返回每行识别结果的置信度。默认为false ElMessage.error("图片识别错误");
disp_line_poly: false, //是否返回每行的四角点坐标。默认为false
words_type: 'handprint_mix', //文字类型。 默认:印刷文字识别 = handwring_only手写文字识别 = handprint_mix 手写印刷混排识别
layout_analysis: false, //是否分析文档版面包括layout图、表、标题、段落、目录attribute栏、页眉、页脚、页码、脚注的分析输出
recg_long_division: false, //是否检测并识别手写竖式
recg_formula: true, //控制是否检测并识别公式默认为false
}
const resOcr = await bdyAPI_getOcrContent(token, base64Code, query);
if (resOcr.status !== 200) {
ElMessage.error("百度智能云图片识别错误");
return null; return null;
} }
// const resToken = await bdyAPI_getToken();
// if (resToken.status !== 200) {
// ElMessage.error("百度智能云用户标识有误");
// return null;
// }
// const token = resToken.data?.access_token;
// let base64Code = urlBase64.split(",")[1];
// const query = {
// image: base64Code, //图片地址(base64)
// line_probability: false, //是否返回每行识别结果的置信度。默认为false
// disp_line_poly: false, //是否返回每行的四角点坐标。默认为false
// words_type: 'handprint_mix', //文字类型。 默认:印刷文字识别 = handwring_only手写文字识别 = handprint_mix 手写印刷混排识别
// layout_analysis: false, //是否分析文档版面包括layout图、表、标题、段落、目录attribute栏、页眉、页脚、页码、脚注的分析输出
// recg_long_division: false, //是否检测并识别手写竖式
// recg_formula: true, //控制是否检测并识别公式默认为false
// }
// const resOcr = await bdyAPI_getOcrContent(token, base64Code, query);
// if (resOcr.status !== 200) {
// ElMessage.error("百度智能云图片识别错误");
// return null;
// }
return resOcr; return resOcr;
} }
@ -264,7 +278,7 @@ const ocrImgPyJson = async (urlBase64) => {
ElMessage.error("未检测到截图图片, 请截取图片后再识别"); ElMessage.error("未检测到截图图片, 请截取图片后再识别");
return null; return null;
} }
const resOcr = await pyOCRAPI(urlBase64); const resOcr = await pyOCRAPI(urlBase64);
if (resOcr.status !== 200) { if (resOcr.status !== 200) {
ElMessage.error("图片识别错误"); ElMessage.error("图片识别错误");
@ -351,7 +365,7 @@ const assembleExam = (eachSub) => {
let regex = null; let regex = null;
let titleAndWorkDesc = '', let titleAndWorkDesc = '',
answer = ''; answer = '';
// 获取[题源] - 格式化 // 获取[题源] - 格式化
@ -361,7 +375,7 @@ const assembleExam = (eachSub) => {
subObj.worktag = workTag[0].replace(/^\d*[..。]/g, ''); subObj.worktag = workTag[0].replace(/^\d*[..。]/g, '');
subObj.worktag = subObj.worktag.replace('(', '').replace(')', ''); subObj.worktag = subObj.worktag.replace('(', '').replace(')', '');
} }
// 去掉开头的序号和题源 // 去掉开头的序号和题源
eachSub = eachSub.replace(regex, ''); eachSub = eachSub.replace(regex, '');
// 先判断是否存在答案 // 先判断是否存在答案
@ -370,7 +384,7 @@ const assembleExam = (eachSub) => {
if (!hasAnswer) { if (!hasAnswer) {
// 不存在答案, 仅处理[题干+选项] // 不存在答案, 仅处理[题干+选项]
titleAndWorkDesc = eachSub; titleAndWorkDesc = eachSub;
}else { } else {
// 存在答案, 需处理[题干+选项]和[答案+解析] // 存在答案, 需处理[题干+选项]和[答案+解析]
regex = /(<br \/>?\s*[【\[].*?[】\]])/g; regex = /(<br \/>?\s*[【\[].*?[】\]])/g;
let tmpList = eachSub.split(regex); let tmpList = eachSub.split(regex);
@ -386,10 +400,10 @@ const assembleExam = (eachSub) => {
// 第二部分[分析-答案] 处理 // 第二部分[分析-答案] 处理
let answerAndAnswer = {}; let answerAndAnswer = {};
// 将第二部分的内容做key-value绑定 - 键为【分析】、【讨论】、【方法】等. 值为随之分隔的内容 // 将第二部分的内容做key-value绑定 - 键为【分析】、【讨论】、【方法】等. 值为随之分隔的内容
for (let i=1; i<tmpList.length-1; i=i+2){ for (let i = 1; i < tmpList.length - 1; i = i + 2) {
let key = tmpList[i]; let key = tmpList[i];
key = key.replace(/<br \/>|【|】|\[|\]/g, ''); key = key.replace(/<br \/>|【|】|\[|\]/g, '');
let value = tmpList[i+1]; let value = tmpList[i + 1];
value = value.replace(/^<br \/>+|<br \/>+$/g, ''); value = value.replace(/^<br \/>+|<br \/>+$/g, '');
answerAndAnswer[key] = value; answerAndAnswer[key] = value;
} }
@ -430,12 +444,12 @@ const assembleExam = (eachSub) => {
// [答案] - 初步初始化 --- 根据答案判断试题大分类: 复合题(实际为大题) 或 其他基础题型(单选,多选,填空,判断) // [答案] - 初步初始化 --- 根据答案判断试题大分类: 复合题(实际为大题) 或 其他基础题型(单选,多选,填空,判断)
answer = answerAndAnswer['答案'].trim(); answer = answerAndAnswer['答案'].trim();
if(!answer) { if (!answer) {
answer = answerAndAnswer['答案及评分参考'].trim(); answer = answerAndAnswer['答案及评分参考'].trim();
answer = answer.replace(/^\d+[\u4e00-\u9fa5][..。]\s*<br \/>/, ''); // 去掉 - 有些开头会有[xx分。] answer = answer.replace(/^\d+[\u4e00-\u9fa5][..。]\s*<br \/>/, ''); // 去掉 - 有些开头会有[xx分。]
} }
// 将多余的空格替换为固定的4个空格 // 将多余的空格替换为固定的4个空格
answer = answer.replaceAll("\\s{3,}"," "); answer = answer.replaceAll("\\s{3,}", " ");
if (answer == null | answer == '') { if (answer == null | answer == '') {
subObj.err = '题目缺少[答案]'; subObj.err = '题目缺少[答案]';
return subObj; return subObj;
@ -455,7 +469,7 @@ const assembleExam = (eachSub) => {
let answerFind = regex.test(answer); let answerFind = regex.test(answer);
regex = /(\d+[..。]|\(\d+\)|\d+)/; regex = /(\d+[..。]|\(\d+\)|\d+)/;
let titleFind = regex.test(titleAndWorkDesc); let titleFind = regex.test(titleAndWorkDesc);
if(titleFind && answerFind){ if (titleFind && answerFind) {
/** /**
* [复合题] - 处理逻辑 * [复合题] - 处理逻辑
*/ */
@ -471,7 +485,7 @@ const assembleExam = (eachSub) => {
if (tmpExam) { if (tmpExam) {
// 错误信息 // 错误信息
if(tmpExam.errMsg !== '') { if (tmpExam.errMsg !== '') {
subObj.err = tmpExam.err; subObj.err = tmpExam.err;
return subObj; return subObj;
} }
@ -484,7 +498,7 @@ const assembleExam = (eachSub) => {
subObj.workanswer = JSON.stringify(tmpExam.arrWorkAnswer); subObj.workanswer = JSON.stringify(tmpExam.arrWorkAnswer);
} }
} }
return subObj; return subObj;
} }
@ -508,7 +522,7 @@ const processExamSingle = function (titleAndWorkDesc, answer) {
let matcher = null; let matcher = null;
/** [判断题]的处理逻辑, resp: -1-未找到 0-*为对应匹配的index */ /** [判断题]的处理逻辑, resp: -1-未找到 0-*为对应匹配的index */
let judgedStatus = answer!=='' ? containsExactMatch(answer) : -1; let judgedStatus = answer !== '' ? containsExactMatch(answer) : -1;
/** 其他基础题型(单选,多选,填空,判断)的处理逻辑 */ /** 其他基础题型(单选,多选,填空,判断)的处理逻辑 */
// 先去掉开头的试题序号 // 先去掉开头的试题序号
@ -524,7 +538,7 @@ const processExamSingle = function (titleAndWorkDesc, answer) {
answer = answer.replace("<br />", "").trim(); answer = answer.replace("<br />", "").trim();
// [题型] - 格式化 - 根据答案字符个数区分[单选]或[多选] // [题型] - 格式化 - 根据答案字符个数区分[单选]或[多选]
examSingle.workType = answer==='' ? '单选题' : answer.length == 1 ? "单选题" : "多选题"; examSingle.workType = answer === '' ? '单选题' : answer.length == 1 ? "单选题" : "多选题";
// 切分题干+选项 // 切分题干+选项
regex = /<br \/>*\s*[A-H][..。]/g; regex = /<br \/>*\s*[A-H][..。]/g;
@ -535,12 +549,12 @@ const processExamSingle = function (titleAndWorkDesc, answer) {
// [选项]-处理 --- ['ABC123','ABC123'] // [选项]-处理 --- ['ABC123','ABC123']
for (let i = 1; i < tmpSplit.length; i++) { for (let i = 1; i < tmpSplit.length; i++) {
let option = tmpSplit[i].replace("<br />", "").trim(); let option = tmpSplit[i].replace("<br />", "").trim();
//option = option.replace("_", ""); //option = option.replace("_", "");
// [选项] - 格式化 // [选项] - 格式化
examSingle.arrWorkDesc.push(option); examSingle.arrWorkDesc.push(option);
} }
// [题目答案] --- ['0'] | ['0','1'] // [题目答案] --- ['0'] | ['0','1']
if (answer !== '') { if (answer !== '') {
// 答案为空时, 置空后直接返回 // 答案为空时, 置空后直接返回
@ -570,7 +584,7 @@ const processExamSingle = function (titleAndWorkDesc, answer) {
examSingle.arrWorkAnswer = answer.split(" "); examSingle.arrWorkAnswer = answer.split(" ");
} }
} }
else if( judgedStatus != -1 ) { else if (judgedStatus != -1) {
/** /**
* 判断题 * 判断题
*/ */
@ -635,48 +649,48 @@ const processExamMulti = function (titleAndWorkDesc, answer) {
// 先确定当前是以什么形式的小题序号来切分 --- 需要全部独立判断, 避免出现复合题中, 每小题内还包含小题的情况--- 1.回答以下问题 (1)***** (2)****** // 先确定当前是以什么形式的小题序号来切分 --- 需要全部独立判断, 避免出现复合题中, 每小题内还包含小题的情况--- 1.回答以下问题 (1)***** (2)******
let cliceSucc = false; let cliceSucc = false;
let arrAnswer = [] let arrAnswer = []
if(!cliceSucc){ if (!cliceSucc) {
regex = /<br \/>\s*\d+[..。]\s*/; regex = /<br \/>\s*\d+[..。]\s*/;
if (regex.test(titleAndWorkDesc)) { if (regex.test(titleAndWorkDesc)) {
// 再次以答案中的序号同步匹配一次 // 再次以答案中的序号同步匹配一次
regex = /^\s*\d+[..。]\s*/; regex = /^\s*\d+[..。]\s*/;
if(answer === '' || regex.test(answer)){ if (answer === '' || regex.test(answer)) {
regex = /<br \/>\s*\d+[..。]\s*/g; regex = /<br \/>\s*\d+[..。]\s*/g;
tmpSplit = titleAndWorkDesc.split(regex); tmpSplit = titleAndWorkDesc.split(regex);
if (answer !== '') { if (answer !== '') {
// 存在答案时, 再校验 // 存在答案时, 再校验
regex = /^\s*\d+[..。]\s*|<br \/>\s*\d+[..。]\s*|\s+\d+[..。]\s*/g; regex = /^\s*\d+[..。]\s*|<br \/>\s*\d+[..。]\s*|\s+\d+[..。]\s*/g;
arrAnswer = answer.split(regex); arrAnswer = answer.split(regex);
} }
cliceSucc = true; cliceSucc = true;
} }
} }
} }
if (!cliceSucc){ if (!cliceSucc) {
regex = /<br \/>\s*\d+\s*/; regex = /<br \/>\s*\d+\s*/;
if (regex.test(titleAndWorkDesc)) { if (regex.test(titleAndWorkDesc)) {
// 再次以答案中的序号同步匹配一次 // 再次以答案中的序号同步匹配一次
regex = /\s*\d+\s*/; regex = /\s*\d+\s*/;
if(answer === '' || regex.test(answer)){ if (answer === '' || regex.test(answer)) {
regex = /<br \/>\s*\d+\s*/g; regex = /<br \/>\s*\d+\s*/g;
tmpSplit = titleAndWorkDesc.split(regex); tmpSplit = titleAndWorkDesc.split(regex);
if (answer !== '') { if (answer !== '') {
// 存在答案时, 再校验 // 存在答案时, 再校验
regex = /^\s*\d+\s*|<br \/>\s*\d+\s*|\s+\d+\s*/g; regex = /^\s*\d+\s*|<br \/>\s*\d+\s*|\s+\d+\s*/g;
arrAnswer = answer.split(regex); arrAnswer = answer.split(regex);
} }
cliceSucc = true; cliceSucc = true;
} }
} }
} }
if (!cliceSucc){ if (!cliceSucc) {
regex = /<br \/>\s*\(\d+\)\s*/; regex = /<br \/>\s*\(\d+\)\s*/;
if (regex.test(titleAndWorkDesc)) { if (regex.test(titleAndWorkDesc)) {
// 再次以答案中的序号同步匹配一次 // 再次以答案中的序号同步匹配一次
regex = /^\s*\(\d+\)\s*/; regex = /^\s*\(\d+\)\s*/;
if(answer === '' || regex.test(answer)){ if (answer === '' || regex.test(answer)) {
regex = /<br \/>\s*\(\d+\)\s*/g; regex = /<br \/>\s*\(\d+\)\s*/g;
tmpSplit = titleAndWorkDesc.split(regex); tmpSplit = titleAndWorkDesc.split(regex);
if (answer !== '') { if (answer !== '') {
@ -689,19 +703,19 @@ const processExamMulti = function (titleAndWorkDesc, answer) {
} }
} }
} }
if (!cliceSucc){ if (!cliceSucc) {
examMulti.errMsg = '[复合题]小题与答案序号[不匹配]'; examMulti.errMsg = '[复合题]小题与答案序号[不匹配]';
return examMulti; return examMulti;
} }
if (tmpSplit.length < 2){ if (tmpSplit.length < 2) {
examMulti.errMsg = '[复合题]题干与小题[切分失败]'; examMulti.errMsg = '[复合题]题干与小题[切分失败]';
return examMulti; return examMulti;
} }
if (answer !== '' && arrAnswer.length < 2){ if (answer !== '' && arrAnswer.length < 2) {
examMulti.errMsg = '[复合题]答案切分小题失败'; examMulti.errMsg = '[复合题]答案切分小题失败';
return examMulti; return examMulti;
} }
if (answer !== '' && tmpSplit.length != arrAnswer.length){ if (answer !== '' && tmpSplit.length != arrAnswer.length) {
examMulti.errMsg = '[复合题]小题个数与答案个数[不一致]'; examMulti.errMsg = '[复合题]小题个数与答案个数[不一致]';
return examMulti; return examMulti;
} }
@ -710,13 +724,13 @@ const processExamMulti = function (titleAndWorkDesc, answer) {
examMulti.title = tmpSplit[0].trim(); examMulti.title = tmpSplit[0].trim();
// [选项]+[答案] - 逻辑处理 // [选项]+[答案] - 逻辑处理
for (let i=1; i<tmpSplit.length; i++){ for (let i = 1; i < tmpSplit.length; i++) {
const tmp = tmpSplit[i].trim(); const tmp = tmpSplit[i].trim();
// 因arrAnswer[0]对应为分隔出来的首位空数组, 故这里也可直接使用i=1作为下标获取答案 // 因arrAnswer[0]对应为分隔出来的首位空数组, 故这里也可直接使用i=1作为下标获取答案
const tmpAnswer = answer === '' ? '' : arrAnswer[i].trim(); const tmpAnswer = answer === '' ? '' : arrAnswer[i].trim();
// 单题处理 // 单题处理
const tmpExam = processExamSingle(tmp, tmpAnswer); const tmpExam = processExamSingle(tmp, tmpAnswer);
if(tmpExam.errMsg !== ''){ if (tmpExam.errMsg !== '') {
examMulti.errMsg = '[复合题]小题解析失败'; examMulti.errMsg = '[复合题]小题解析失败';
return examMulti; return examMulti;
} }
@ -768,10 +782,10 @@ const containsExactMatch = function (answer) {
answer = answer.replace("_____", ""); answer = answer.replace("_____", "");
let index = 0; let index = 0;
for (let item of EXAM_JUDGED_DICTIONARY) { for (let item of EXAM_JUDGED_DICTIONARY) {
if (answer === item) { if (answer === item) {
return index; return index;
} }
index++; index++;
} }
return -1; return -1;
} }

View File

@ -10,6 +10,9 @@
</el-button> </el-button>
</div> </div>
<div class="header-right"> <div class="header-right">
<el-select v-model="curMode" placeholder="Select" class="mr-4 w-30">
<el-option v-for="item in modeOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<el-button type="primary" :disabled="!(resultList.length)" @click="getCompletion">一键研读</el-button> <el-button type="primary" :disabled="!(resultList.length)" @click="getCompletion">一键研读</el-button>
<el-button type="primary">生成大纲</el-button> <el-button type="primary">生成大纲</el-button>
<el-button type="danger" @click="pptDialog = true">生成PPT</el-button> <el-button type="danger" @click="pptDialog = true">生成PPT</el-button>
@ -21,21 +24,22 @@
<div class="item-top flex"> <div class="item-top flex">
<span>{{ item.name }}</span> <span>{{ item.name }}</span>
<el-popover placement="bottom-end" trigger="hover" popper-class="template-custom-popover"> <el-popover placement="bottom-end" trigger="hover" popper-class="template-custom-popover">
<template #reference> <template #reference>
<el-button link type="primary"> <el-button link type="primary">
<i class="iconfont icon-shenglvehao"></i></el-button> <i class="iconfont icon-shenglvehao"></i></el-button>
</template> </template>
<template #default> <template #default>
<el-button type="primary" link @click="editKeyWord(item, false)">编辑</el-button> <el-button type="primary" link @click="editKeyWord(item, false)">编辑</el-button>
<el-button type="primary" link @click="removeItem(item, true)">移除</el-button> <el-button type="primary" link @click="removeItem(item, true)">移除</el-button>
</template> </template>
</el-popover> </el-popover>
</div> </div>
<div class="item-bom"> <div class="item-bom">
<div class="item-prompt">{{ item.prompt }}</div> <div class="item-prompt">{{ item.prompt }}</div>
<div class="item-answer" v-if="item.answer"> <div class="item-answer" v-if="item.answer">
<div class="answer-text"> <div class="answer-text">
<TypingEffect v-if="isStarted[index]" :text="item.answer" :delay="10" :aiShow="item.aiShow" @complete="handleCompleteText($event,index)" @updateScroll="scrollToBottom($event,index)" /> <TypingEffect v-if="isStarted[index]" :text="item.answer" :delay="10" :aiShow="item.aiShow"
@complete="handleCompleteText($event, index)" @updateScroll="scrollToBottom($event, index)" />
</div> </div>
<div class="item-btn flex"> <div class="item-btn flex">
<el-button type="primary" link @click="againResult(index, item)"> <el-button type="primary" link @click="againResult(index, item)">
@ -59,10 +63,10 @@
</div> </div>
<EditDialog v-model="isEdit" :item="curItem" /> <EditDialog v-model="isEdit" :item="curItem" />
<AdjustDialog v-model="isAdjust" :item="curItem" /> <AdjustDialog v-model="isAdjust" :item="curItem" />
<PptDialog @add-success="addAiPPT" :dataList="resultList" v-model="pptDialog"/> <PptDialog @add-success="addAiPPT" :dataList="resultList" v-model="pptDialog" />
<progress-dialog v-model:visible="pgDialog.visible" v-bind="pgDialog" /> <progress-dialog v-model:visible="pgDialog.visible" v-bind="pgDialog" />
<!--添加编辑提示词--> <!--添加编辑提示词-->
<keywordDialog v-model="isWordDialog" :item="curItem" /> <keywordDialog v-model="isWordDialog" :item="curItem" />
</template> </template>
<script setup> <script setup>
@ -73,15 +77,17 @@ import emitter from '@/utils/mitt'
import EditDialog from './edit-dialog.vue' import EditDialog from './edit-dialog.vue'
import AdjustDialog from './adjust-dialog.vue' import AdjustDialog from './adjust-dialog.vue'
import progressDialog from './progress-dialog.vue' import progressDialog from './progress-dialog.vue'
import { completion, tempResult, tempSave, removeChildTemp, editTempResult } from '@/api/mode/index.js' import { completion, tempResult, tempSave, removeChildTemp, editTempResult, modelList } from '@/api/mode/index.js'
import { createChart, sendChart } from '@/api/ai/index'
// import { dataSetJson } from '@/utils/comm.js' // import { dataSetJson } from '@/utils/comm.js'
import * as commUtils from '@/utils/comm.js' import * as commUtils from '@/utils/comm.js'
import PptDialog from '@/views/prepare/container/pptist-dialog.vue' import PptDialog from '@/views/prepare/container/pptist-dialog.vue'
import keywordDialog from './keyword-dialog.vue' import keywordDialog from './keyword-dialog.vue'
import TypingEffect from '@/components/typing-effect/index.vue' import TypingEffect from '@/components/typing-effect/index.vue'
import { cloneDeep } from 'lodash'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import {PPTXFileToJson} from '@/AixPPTist/src/hooks/useImport' // pptjson import { PPTXFileToJson } from '@/AixPPTist/src/hooks/useImport' // pptjson
import * as API_entpcourse from '@/api/education/entpcourse' // api import * as API_entpcourse from '@/api/education/entpcourse' // api
import * as API_entpcoursefile from '@/api/education/entpcoursefile' // api import * as API_entpcoursefile from '@/api/education/entpcoursefile' // api
import * as Api_server from '@/api/apiService' // api import * as Api_server from '@/api/apiService' // api
@ -100,7 +106,7 @@ const pgDialog = reactive({ // 弹窗-进度条
width: 300, width: 300,
showClose: false, showClose: false,
draggable: true, draggable: true,
beforeClose: done => {}, // - beforeClose: done => { }, // -
pg: { // - pg: { // -
percentage: 0, // percentage: 0, //
color: [ color: [
@ -110,6 +116,19 @@ const pgDialog = reactive({ // 弹窗-进度条
] ]
} }
}) })
const curMode = ref(1)
const modeOptions = ref([
{
label: '教学大模型',
value: 1
},
{
label: '知识库模型',
value: 2
}
])
emitter.on('changeMode', (item) => { emitter.on('changeMode', (item) => {
resultList.value = item.child resultList.value = item.child
getTempResult(item.id) getTempResult(item.id)
@ -121,8 +140,8 @@ const getCompletion = async () => {
isStarted.value = new Array(resultList.length).fill(false) isStarted.value = new Array(resultList.length).fill(false)
isStarted.value[0] = true isStarted.value[0] = true
resultList.value.forEach(item =>{ resultList.value.forEach(item => {
if(item.answer){ if (item.answer) {
item.answer = '' item.answer = ''
} }
}) })
@ -131,8 +150,28 @@ const getCompletion = async () => {
try { try {
item.loading = true item.loading = true
item.aiShow = true item.aiShow = true
params.prompt = `按照${item.prompt}的要求,针对${curNode.edustage}${curNode.edusubject}${curNode.itemtitle}进行教学分析`
const { data } = await completion(params) let str = cloneDeep(prompt.value)
str = str.replace(/{模板名称}/g, item.name)
params.prompt = str
params.template = item.prompt
//
let data = null
if (curMode.value == 1) {
const res = await sendChart({
content: params.prompt,
conversationId: conversation_id.value,
stream: false
})
data = res.data
}
//
else {
const res = await completion(params)
data = res.data
}
item.answer = getResult(data.answer) item.answer = getResult(data.answer)
onSaveTemp(item) onSaveTemp(item)
} finally { } finally {
@ -141,14 +180,14 @@ const getCompletion = async () => {
} }
} }
const handleCompleteText = async (answer, index) =>{ const handleCompleteText = async (answer, index) => {
if (index < resultList.value.length - 1) { if (index < resultList.value.length - 1) {
isStarted.value[index + 1] = true; // isStarted.value[index + 1] = true; //
} }
if(isAgain.value){ if (isAgain.value) {
try{ try {
await editTempResult({ id: resultList.value[index].resultId, content: answer }) await editTempResult({ id: resultList.value[index].resultId, content: answer })
}finally{ } finally {
isAgain.value = false isAgain.value = false
} }
} }
@ -176,7 +215,7 @@ const editKeyWord = (item, val) => {
Object.assign(curItem, item) Object.assign(curItem, item)
curItem.isAdd = val curItem.isAdd = val
isWordDialog.value = true isWordDialog.value = true
} }
@ -230,30 +269,30 @@ const getTempResult = (id) => {
}) })
}) })
} }
}) })
} }
const scrollToBottom = (height,index) =>{ const scrollToBottom = (height, index) => {
if (listRef.value) { if (listRef.value) {
let sum = 0 let sum = 0
let listDom = listRef.value.children let listDom = listRef.value.children
if(index == 0){ if (index == 0) {
// 220 // 220
let screenHeight = window.innerHeight - 220 let screenHeight = window.innerHeight - 220
if(height > screenHeight){ if (height > screenHeight) {
listRef.value.scrollTop = (height - screenHeight + 50) listRef.value.scrollTop = (height - screenHeight + 50)
}
}
else {
for (let i = 0; i < index; i++) {
sum += listDom[i].clientHeight
}
listRef.value.scrollTop = sum + height
} }
} }
else{
for(let i = 0; i < index; i++){
sum += listDom[i].clientHeight
}
listRef.value.scrollTop = sum + height
}
}
} }
// ### ** // ### **
@ -265,11 +304,14 @@ let getResult = (str) => {
const params = reactive( const params = reactive(
{ {
prompt: '', prompt: '',
dataset_id: '' dataset_id: '',
template: ''
} }
) )
const prompt = ref('')
const addAiPPT = async(res) => {
const addAiPPT = async (res) => {
let node = courseObj.node let node = courseObj.node
pptDialog.value = false; pptDialog.value = false;
if (!node) return msgUtils.msgWarning('请选择章节?') if (!node) return msgUtils.msgWarning('请选择章节?')
@ -284,14 +326,14 @@ const addAiPPT = async(res) => {
} else courseObj.entp = resEnpt?.rows?.[0] || null } else courseObj.entp = resEnpt?.rows?.[0] || null
// PPT json // PPT json
fetch(res.url) fetch(res.url)
.then(res => res.arrayBuffer()) .then(res => res.arrayBuffer())
.then(async buffer => { .then(async buffer => {
const resPptJson = await PPTXFileToJson(buffer) const resPptJson = await PPTXFileToJson(buffer)
const { def, slides, ...content } = resPptJson const { def, slides, ...content } = resPptJson
// || 线 // || 线
let completed = 0 let completed = 0
const total = slides.length const total = slides.length
for( let o of slides ) { for (let o of slides) {
completed++ completed++
await toRousrceUrl(o) await toRousrceUrl(o)
// //
@ -300,14 +342,14 @@ const addAiPPT = async(res) => {
pgDialog.pg.percentage = 0 pgDialog.pg.percentage = 0
pgDialog.visible = false pgDialog.visible = false
// ppt- // ppt-
const p_params = {parentContent: JSON.stringify(content)} const p_params = { parentContent: JSON.stringify(content) }
const parentid = await HTTP_SERVER_API('addEntpcoursefile', p_params) const parentid = await HTTP_SERVER_API('addEntpcoursefile', p_params)
if (!!parentid??null) { // if (!!parentid ?? null) { //
// -Smarttalk // -Smarttalk
HTTP_SERVER_API('addSmarttalk',{fileId: parentid}) HTTP_SERVER_API('addSmarttalk', { fileId: parentid })
if (slides.length > 0) { if (slides.length > 0) {
const resSlides = slides.map(({id, ...slide}) => JSON.stringify(slide)) const resSlides = slides.map(({ id, ...slide }) => JSON.stringify(slide))
const params = {parentid, filetype: 'slide', title: '', slides: resSlides } const params = { parentid, filetype: 'slide', title: '', slides: resSlides }
const res_3 = await HTTP_SERVER_API('batchAddNew', params) const res_3 = await HTTP_SERVER_API('batchAddNew', params)
if (res_3 && res_3.code == 200) { if (res_3 && res_3.code == 200) {
msgUtils.msgSuccess('生成PPT课件成功') msgUtils.msgSuccess('生成PPT课件成功')
@ -332,10 +374,10 @@ const againResult = async (index, item) => {
isAgain.value = true isAgain.value = true
isStarted.value[index] = false isStarted.value[index] = false
resultList.value[index].answer = '' resultList.value[index].answer = ''
if(index == 0){ if (index == 0) {
listRef.value.scrollTop = 0 listRef.value.scrollTop = 0
}else{ } else {
scrollToBottom(50, index) scrollToBottom(50, index)
} }
@ -343,8 +385,27 @@ const againResult = async (index, item) => {
await nextTick() await nextTick()
resultList.value[index].loading = true resultList.value[index].loading = true
item.aiShow = true item.aiShow = true
params.prompt = `按照${item.prompt}的要求,针对${curNode.edustage}${curNode.edusubject}课标对${curNode.itemtitle}进行教学分析`
const { data } = await completion(params) let str = cloneDeep(prompt.value)
str = str.replace(/{模板名称}/g, item.name)
params.prompt = str
params.template = item.prompt
let data = null;
//
if (mode.value == 1) {
const res = await sendChart({
content: params.prompt,
conversationId: conversation_id.value,
stream: false
})
data = res.data
} else {
//
const res = await completion(params)
data = res.data
}
resultList.value[index].answer = getResult(data.answer) resultList.value[index].answer = getResult(data.answer)
isStarted.value[index] = true isStarted.value[index] = true
} finally { } finally {
@ -386,12 +447,12 @@ const HTTP_SERVER_API = (type, params = {}) => {
fileFlag: 'aippt', fileFlag: 'aippt',
fileShowName: node.itemtitle + '.aippt', fileShowName: node.itemtitle + '.aippt',
textbookId: node.rootid, textbookId: node.rootid,
levelFirstId: node.parentid||node.id, levelFirstId: node.parentid || node.id,
levelSecondId: node.parentid && node.id, levelSecondId: node.parentid && node.id,
fileSource: '个人', fileSource: '个人',
fileRoot: '备课' fileRoot: '备课'
} }
return API_smarttalk.creatAPT({...def, ...params}) return API_smarttalk.creatAPT({ ...def, ...params })
} }
case 'addEntpcourse': { // case 'addEntpcourse': { //
const node = courseObj.node || {} const node = courseObj.node || {}
@ -428,7 +489,7 @@ const HTTP_SERVER_API = (type, params = {}) => {
case 'getCourseList': { // case 'getCourseList': { //
return API_entpcourse.listEntpcourse(params) return API_entpcourse.listEntpcourse(params)
} }
case 'getCourseFileList':{ // case 'getCourseFileList': { //
return API_entpcoursefile.listEntpcoursefileNew(params) return API_entpcoursefile.listEntpcoursefileNew(params)
} }
} }
@ -455,7 +516,7 @@ const getDefParams = (params) => {
return Object.assign(def, params) return Object.assign(def, params)
} }
// || 线 // || 线
const toRousrceUrl = async(o) => { const toRousrceUrl = async (o) => {
if (!!o.src) { // src if (!!o.src) { // src
const isBase64 = /^data:image\/(\w+);base64,/.test(o.src) const isBase64 = /^data:image\/(\w+);base64,/.test(o.src)
const isBlobUrl = /^blob:/.test(o.src) const isBlobUrl = /^blob:/.test(o.src)
@ -469,35 +530,56 @@ const toRousrceUrl = async(o) => {
const formData = new FormData() const formData = new FormData()
formData.append('file', file) formData.append('file', file)
const res = await Api_server.Other.uploadFile(formData) const res = await Api_server.Other.uploadFile(formData)
if (res && res.code == 200){ if (res && res.code == 200) {
const url = res?.url const url = res?.url
url &&(o.src = url) url && (o.src = url)
} }
} else if (isBlobUrl) { // } else if (isBlobUrl) { //
const res = await fetch(o.src) const res = await fetch(o.src)
const blob = await res.blob() const blob = await res.blob()
const fileName = o.type=='video'? Date.now() + '.mp4':Date.now() + '.mp3' const fileName = o.type == 'video' ? Date.now() + '.mp4' : Date.now() + '.mp3'
const file = commUtils.blobToFile(blob, fileName) const file = commUtils.blobToFile(blob, fileName)
// o.src = fileName // o.src = fileName
// console.log('file', file) // console.log('file', file)
const formData = new FormData() const formData = new FormData()
formData.append('file', file) formData.append('file', file)
const ress = await Api_server.Other.uploadFile(formData) const ress = await Api_server.Other.uploadFile(formData)
if (ress && ress.code == 200){ if (ress && ress.code == 200) {
const url = ress?.url const url = ress?.url
url &&(o.src = url) url && (o.src = url)
} }
} }
} }
if (o?.background?.image) await toRousrceUrl(o.background.image) if (o?.background?.image) await toRousrceUrl(o.background.image)
if(o?.elements){ if (o?.elements) {
for (let element of o.elements) { for (let element of o.elements) {
await toRousrceUrl(element); await toRousrceUrl(element);
} }
} }
} }
// ======== zdg end ============ // ======== zdg end ============
//
const conversation_id = ref('')
const getChartId = () => {
createChart({ app_id: '712ff0df-ed6b-470f-bf87-8cfbaf757be5' }).then(res => {
localStorage.setItem("conversation_id", res.data.conversation_id);
conversation_id.value = res.data.conversation_id;
})
}
// prompt
const getPrompt = async () => {
const { rows } = await modelList({ model: 5 })
let str = rows.find(item => item.name.indexOf('框架设计') != -1).prompt
str = str.replace('{学段}', curNode.edustage)
str = str.replace('{学科}', curNode.edusubject)
let bookV = curNode.roottitle.split('-')[1] + '版本'
str = str.replace('{教材版本}', bookV)
str = str.replace('{课程名称}', `${curNode.itemtitle}`)
prompt.value = str
}
const curNode = reactive({}) const curNode = reactive({})
onMounted(() => { onMounted(() => {
let data = sessionStore.get('subject.curNode') let data = sessionStore.get('subject.curNode')
@ -506,6 +588,15 @@ onMounted(() => {
let jsonKey = `课标-${data.edustage}-${data.edusubject}` let jsonKey = `课标-${data.edustage}-${data.edusubject}`
params.dataset_id = commUtils.dataSetJson[jsonKey] params.dataset_id = commUtils.dataSetJson[jsonKey]
// ID
conversation_id.value = localStorage.getItem('conversation_id')
if (!conversation_id.value) {
getChartId();
}
// prompt
getPrompt()
}) })
@ -548,7 +639,8 @@ onUnmounted(() => {
position: relative; position: relative;
padding-left: 15px; padding-left: 15px;
box-sizing: border-box; box-sizing: border-box;
&::after{
&::after {
content: ''; content: '';
width: 15px; width: 15px;
height: 15px; height: 15px;
@ -558,7 +650,8 @@ onUnmounted(() => {
left: -8px; left: -8px;
top: 5px; top: 5px;
} }
&::before{
&::before {
content: ''; content: '';
width: 2px; width: 2px;
height: 100%; height: 100%;
@ -567,17 +660,20 @@ onUnmounted(() => {
left: -1px; left: -1px;
top: 5px; top: 5px;
} }
&:last-child{
&::before{ &:last-child {
&::before {
content: ''; content: '';
width: 0 width: 0
} }
} }
.item-top { .item-top {
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
margin-bottom: 5px; margin-bottom: 5px;
.icon-shenglvehao{
.icon-shenglvehao {
font-weight: bold font-weight: bold
} }
} }