|
|
|
@ -16,16 +16,16 @@
|
|
|
|
|
</div>
|
|
|
|
|
<el-button type="primary" @click="toggleSidebar()" style="display:none"
|
|
|
|
|
id="toggleSidebarButton">打开/关闭侧边栏</el-button>
|
|
|
|
|
<div class="sidebar" :class="{ 'active': isSidebarOpen }">
|
|
|
|
|
<div class="sidebar" :class="{ 'active': isSidebarOpen }" >
|
|
|
|
|
<!-- 侧边栏内容 -->
|
|
|
|
|
<el-menu class="sidebar-menu" :class="{ 'active': isNavbarOpen }" :collapse="isNavbarOpen">
|
|
|
|
|
<el-sub-menu index="1" class="horizontal-sub-menu">
|
|
|
|
|
<template #title>智能助手</template>
|
|
|
|
|
<el-menu-item index="1-1" @click="showContent('polish')">润色</el-menu-item>
|
|
|
|
|
<el-menu-item index="1-2" @click="showContent('rewrite')">改写</el-menu-item>
|
|
|
|
|
<el-menu-item index="1-3" @click="showContent('summary')">摘要</el-menu-item>
|
|
|
|
|
<el-menu-item index="1-4" @click="showContent('edit')">修改</el-menu-item>
|
|
|
|
|
<el-menu-item index="1-5" @click="showContent('translate')">翻译</el-menu-item>
|
|
|
|
|
<el-menu-item index="1-1" @click="showRefineDOCContent('decoration')">润色</el-menu-item>
|
|
|
|
|
<el-menu-item index="1-2" @click="showRefineDOCContent('extension')">续写</el-menu-item>
|
|
|
|
|
<el-menu-item index="1-3" @click="showRefineDOCContent('summary')">摘要</el-menu-item>
|
|
|
|
|
<el-menu-item index="1-4" @click="showRefineDOCContent('correction')">修改</el-menu-item>
|
|
|
|
|
<el-menu-item index="1-5" @click="showRefineDOCContent('translation')">翻译</el-menu-item>
|
|
|
|
|
</el-sub-menu>
|
|
|
|
|
<el-sub-menu index="2" class="horizontal-sub-menu">
|
|
|
|
|
<template #title>图文转换</template>
|
|
|
|
@ -41,11 +41,19 @@
|
|
|
|
|
<!-- Content Sections -->
|
|
|
|
|
<div v-if="currentContent" class="content-section">
|
|
|
|
|
<!-- Dynamic content based on navigation selection -->
|
|
|
|
|
<div v-if="currentContent === 'polish'">润色内容</div>
|
|
|
|
|
<div v-if="currentContent === 'rewrite'">改写内容</div>
|
|
|
|
|
<div v-if="currentContent === 'summary'">摘要内容</div>
|
|
|
|
|
<div v-if="currentContent === 'edit'">修改内容</div>
|
|
|
|
|
<div v-if="currentContent === 'translate'">翻译内容</div>
|
|
|
|
|
<div v-if="currentContent === 'refine_doc'" id='refine_doc_block'>
|
|
|
|
|
<div class="refine_docs" id="refine_docs">
|
|
|
|
|
<el-button style="margin-left: 10px; width: 40px; height: 40px;" @click="clearRefineDOCContent()"><svg t="1731509926355" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8154" width="20" height="20"><path d="M1011.43552 981.92384l-68.4032-394.40384h23.10144c18.5856 0 33.54624-14.97088 33.54624-33.55648V306.16576c0-18.5856-14.97088-33.55648-33.54624-33.55648H648.6528V37.71392c0-18.5856-14.97088-33.55648-33.55648-33.55648H408.59648c-18.5856 0-33.55648 14.97088-33.55648 33.55648v234.88512H57.5488c-18.5856 0-33.54624 14.97088-33.54624 33.55648v247.79776c0 18.5856 14.97088 33.55648 33.54624 33.55648h23.10144L12.24704 981.9136c-0.38912 1.9456-0.512 3.87072-0.512 5.6832 0 18.5856 14.97088 33.54624 33.55648 33.54624h933.10976c1.93536 0 3.88096-0.12288 5.6832-0.512 18.31936-3.08224 30.57664-20.51072 27.35104-38.7072zM114.33984 362.94656h351.03744V94.50496h92.928v268.4416h351.03744v134.22592H114.33984V362.94656zM718.336 930.816V729.48736c0-5.6832-4.64896-10.33216-10.32192-10.33216h-61.952c-5.67296 0-10.32192 4.64896-10.32192 10.33216V930.816H387.9424V729.48736c0-5.6832-4.64896-10.33216-10.32192-10.33216h-61.952c-5.67296 0-10.32192 4.64896-10.32192 10.33216V930.816H112.78336l58.20416-335.55456h681.5744L910.76608 930.816H718.336z m0 0" fill="#2C2C2C" p-id="8155"></path></svg></el-button>
|
|
|
|
|
<div v-for="(item, index) in currentRefineDocContent" :key="index" class="messages">
|
|
|
|
|
<div class="message">
|
|
|
|
|
<p>{{ item.oldContent }}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="message-answer">
|
|
|
|
|
<pre>{{ item.newContent }}</pre>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-if="currentContent === 'ocr'">OCR内容</div>
|
|
|
|
|
<div v-if="currentContent === 'mindmap'">脑图生成内容</div>
|
|
|
|
|
<div v-if="currentContent === 'manual'">
|
|
|
|
@ -293,7 +301,7 @@ import {
|
|
|
|
|
import 'ckeditor5/ckeditor5.css';
|
|
|
|
|
import '../public/sidebar.css';
|
|
|
|
|
import { ElButton, ElInput, ElSelect, ElOption, ElForm, ElFormItem, ElMenu, ElMenuItem, ElColorPicker, ElSubMenu } from 'element-plus';
|
|
|
|
|
import { setConfig } from '../components/plugins'
|
|
|
|
|
import emitter, { setConfig } from '../components/plugins'
|
|
|
|
|
// import {getUserConfigFromBackend,saveData,getPageContent,getAndApplyUserStyles} from './components/utils';
|
|
|
|
|
import { useStore } from 'vuex';
|
|
|
|
|
import router from '../router/index.js';
|
|
|
|
@ -311,6 +319,7 @@ export default {
|
|
|
|
|
isSidebarOpen: false,// 侧边栏是否打开
|
|
|
|
|
isNavbarOpen: false,// 侧边栏是否打开
|
|
|
|
|
currentContent: '', // 当前侧边栏显示的表单
|
|
|
|
|
currentRefineDocContent: [], //当前侧边栏显示的文档优化的内容
|
|
|
|
|
formData: {
|
|
|
|
|
fontFamily: '',
|
|
|
|
|
color: '',
|
|
|
|
@ -328,10 +337,6 @@ export default {
|
|
|
|
|
previewStyle: {},
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.config = setConfig();
|
|
|
|
|
this.isLayoutReady = true;
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
onReady(editor) {
|
|
|
|
|
Array.from(this.$refs.editorToolbarElement.children).forEach(child => child.remove());
|
|
|
|
@ -341,10 +346,8 @@ export default {
|
|
|
|
|
this.$refs.editorMenuBarElement.appendChild(editor.ui.view.menuBarView.element);
|
|
|
|
|
// 这里向后端获取要打开文件地内容
|
|
|
|
|
const pageContent = this.store.state.user.filecontent;
|
|
|
|
|
// const pageContent = '<h2>Congratulations on setting up CKEditor 5! 🎉</h2>\n<p>\n You\'ve successfully created a CKEditor 5 project. This powerful text editor will enhance your application, enabling rich text editing\n capabilities that are customizable and easy to use.\n</p>\n<h3>What\'s next?</h3>\n<ol>\n <li>\n <strong>Integrate into your app</strong>: time to bring the editing into your application. Take the code you created and add to your\n application.\n </li>\n <li>\n <strong>Explore features:</strong> Experiment with different plugins and toolbar options to discover what works best for your needs.\n </li>\n <li>\n <strong>Customize your editor:</strong> Tailor the editor\'s configuration to match your application\'s style and requirements. Or even\n write your plugin!\n </li>\n</ol>\n<p>\n Keep experimenting, and don\'t hesitate to push the boundaries of what you can achieve with CKEditor 5. Your feedback is invaluable to us\n as we strive to improve and evolve. Happy editing!\n</p>\n<h3>Helpful resources</h3>\n<ul>\n <li>📝 <a href="https://orders.ckeditor.com/trial/premium-features">Trial sign up</a>,</li>\n <li>📕 <a href="https://ckeditor.com/docs/ckeditor5/latest/installation/index.html">Documentation</a>,</li>\n <li>⭐️ <a href="https://github.com/ckeditor/ckeditor5">GitHub</a> (star us if you can!),</li>\n <li>🏠 <a href="https://ckeditor.com">CKEditor Homepage</a>,</li>\n <li>🧑💻 <a href="https://ckeditor.com/ckeditor-5/demo/">CKEditor 5 Demos</a>,</li>\n</ul>\n<h3>Need help?</h3>\n<p>\n See this text, but the editor is not starting up? Check the browser\'s console for clues and guidance. It may be related to an incorrect\n license key if you use premium features or another feature-related requirement. If you cannot make it work, file a GitHub issue, and we\n will help as soon as possible!\n</p>\n';
|
|
|
|
|
// 打开已有文本就将pageContent替换
|
|
|
|
|
// TODO
|
|
|
|
|
editor.setData(pageContent);
|
|
|
|
|
// 将editor保存到window中,便于别的地方使用|官方推荐做法
|
|
|
|
|
window.editor = editor;
|
|
|
|
|
},
|
|
|
|
|
// sidebar
|
|
|
|
@ -357,6 +360,20 @@ export default {
|
|
|
|
|
showContent(formType) {
|
|
|
|
|
this.currentContent = formType;
|
|
|
|
|
},
|
|
|
|
|
// 展示文本优化表单
|
|
|
|
|
showRefineDOCContent(tag){
|
|
|
|
|
this.currentContent = 'refine_doc';
|
|
|
|
|
this.store.commit('setCurrentTag', tag);
|
|
|
|
|
if (this.store.getters.getCurrentContent){
|
|
|
|
|
this.currentRefineDocContent = this.store.getters.getCurrentContent.reduce((acc, current) => [current,...acc], []);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
clearRefineDOCContent(){
|
|
|
|
|
this.store.commit('clearContentsForTag', this.store.getters.getCurrentTag);
|
|
|
|
|
if (this.store.getters.getCurrentContent){
|
|
|
|
|
this.currentRefineDocContent = this.store.getters.getCurrentContent.reduce((acc, current)=> [current,...acc], []);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 保存用户定义样式
|
|
|
|
|
submitForm() {
|
|
|
|
|
const selectedStyles = {};
|
|
|
|
@ -404,7 +421,6 @@ export default {
|
|
|
|
|
messagesDiv.appendChild(messageDiv);
|
|
|
|
|
|
|
|
|
|
if (sender === 'ai') {
|
|
|
|
|
// TODO 从返回文本中提取出css部分
|
|
|
|
|
preElement.textContent = `文心一言:\n` + preElement.textContent;
|
|
|
|
|
messageDiv.style.backgroundColor = '#bdc3c7';
|
|
|
|
|
}
|
|
|
|
@ -421,6 +437,7 @@ export default {
|
|
|
|
|
// 构造聊天历史
|
|
|
|
|
let chatHistory = [];
|
|
|
|
|
const messages = document.getElementById('messages').children;
|
|
|
|
|
// TODO 如果最后一个消息是error 清空messages
|
|
|
|
|
for (let i = 0; i < messages.length; i++) {
|
|
|
|
|
if (i % 4 == 0) {
|
|
|
|
|
chatHistory.push({ Role: 'user', Content: messages[i].textContent });
|
|
|
|
@ -428,6 +445,8 @@ export default {
|
|
|
|
|
const assistantResponse = messages[i].textContent.replaceAll('文心一言:\n', '');
|
|
|
|
|
chatHistory.push({ Role: 'assistant', Content: assistantResponse });
|
|
|
|
|
}
|
|
|
|
|
// i %4 == 2 preview
|
|
|
|
|
// i %4 == 3 button
|
|
|
|
|
}
|
|
|
|
|
console.log(chatHistory);
|
|
|
|
|
|
|
|
|
@ -435,11 +454,8 @@ export default {
|
|
|
|
|
this.displayMessage(messageText, 'user');
|
|
|
|
|
|
|
|
|
|
// 向后端调用API并接受response
|
|
|
|
|
// 根据messages的内容构造聊天历史列表
|
|
|
|
|
// TODO
|
|
|
|
|
// const chat_history = []
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch('http://localhost:14514/admin/ai_layout/style_generate', {
|
|
|
|
|
const response = await fetch('/web_api/admin/ai_layout/style_generate', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
@ -451,7 +467,6 @@ export default {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!response.body) {
|
|
|
|
|
// TODO
|
|
|
|
|
throw new Error('No response body');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -616,6 +631,16 @@ export default {
|
|
|
|
|
return clearButton;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.config = setConfig();
|
|
|
|
|
this.isLayoutReady = true;
|
|
|
|
|
emitter.on('show-refine-doc-sidebar', (id) => {
|
|
|
|
|
this.isSidebarOpen = true;
|
|
|
|
|
this.isNavbarOpen = true;
|
|
|
|
|
this.showRefineDOCContent(id);
|
|
|
|
|
console.log(this.currentContent)
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
components: {
|
|
|
|
|
// 导入组件
|
|
|
|
|
ElButton, ElInput, ElSelect, ElOption, ElForm, ElFormItem, ElMenu, ElMenuItem, ElColorPicker, ElSubMenu
|
|
|
|
@ -624,6 +649,9 @@ export default {
|
|
|
|
|
if (!this.store.state.user.is_login) {
|
|
|
|
|
router.push({ name: 'login' });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
beforeUnmount() {
|
|
|
|
|
emitter.off('show-refine-doc-sidebar');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|