|
|
|
@ -251,7 +251,7 @@ class RefineDoc extends Plugin {
|
|
|
|
|
init() {
|
|
|
|
|
// console.log('Translation initialized!');
|
|
|
|
|
|
|
|
|
|
this.editor.ui.componentFactory.add('translate', (locale) => {
|
|
|
|
|
this.editor.ui.componentFactory.add('RefineDoc', (locale) => {
|
|
|
|
|
const dropdownView = createDropdown(locale);
|
|
|
|
|
dropdownView.buttonView.set({
|
|
|
|
|
label: '智能助手',
|
|
|
|
@ -435,6 +435,91 @@ class AiFormat extends Plugin {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 智能识别发送消息
|
|
|
|
|
function sendRecMsg(type) {
|
|
|
|
|
const selection = window.getSelection();
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
var src = '';
|
|
|
|
|
if (type === 'pic_recognition') {
|
|
|
|
|
const range = selection.getRangeAt(0);
|
|
|
|
|
const imageElements = range.commonAncestorContainer.parentNode.querySelectorAll('img');
|
|
|
|
|
if (imageElements.length > 0) {
|
|
|
|
|
const selectedImage = imageElements[0];
|
|
|
|
|
src = selectedImage.getAttribute('src');
|
|
|
|
|
const prefix = "data:image/png;base64,";
|
|
|
|
|
if (src.startsWith(prefix)) {
|
|
|
|
|
src = src.substring(prefix.length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (src.trim() === '') return;
|
|
|
|
|
formData.append('pic', src);
|
|
|
|
|
}
|
|
|
|
|
else if (type === 'voc_recognition') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const requestOptions= {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: formData
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const store = window.store;
|
|
|
|
|
const res = {oldContent:'', newContent:'...'};
|
|
|
|
|
store.commit('setCurrentTag', type);
|
|
|
|
|
store.commit('addContentToTag', {tag:type, newContent:res});
|
|
|
|
|
const index = store.getters.getCurrentindex;
|
|
|
|
|
emitter.emit('show-ai-recg-sidebar', type);
|
|
|
|
|
|
|
|
|
|
fetch('/web_api/admin/ai_recognition/' + type, requestOptions)
|
|
|
|
|
.then(response => {
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error("请求出错");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据返回的数据格式进行相应处理,这里假设返回的数据是JSON格式,所以使用response.json()解析
|
|
|
|
|
return response.json();
|
|
|
|
|
})
|
|
|
|
|
.then(data => {
|
|
|
|
|
|
|
|
|
|
// console.log("useStore", store);
|
|
|
|
|
const newRes = {oldContent:'', newContent:data.data.words};
|
|
|
|
|
store.commit('changeContentForTag', {tag:type, index:index, newContent:newRes});
|
|
|
|
|
emitter.emit('show-ai-recg-sidebar', type);
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error("POST请求出错:", error);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PicRecog extends Plugin {
|
|
|
|
|
init() {
|
|
|
|
|
// console.log('Translation initialized!');
|
|
|
|
|
|
|
|
|
|
this.editor.ui.componentFactory.add('PicRecog', () => {
|
|
|
|
|
const button = new ButtonView();
|
|
|
|
|
|
|
|
|
|
button.set({
|
|
|
|
|
label: '图片识别',
|
|
|
|
|
withText: true
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Execute a callback function when the button is clicked
|
|
|
|
|
button.on('execute', () => {
|
|
|
|
|
sendRecMsg('pic_recognition');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return button;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 配置CKEditor5
|
|
|
|
|
function setConfig() {
|
|
|
|
|
// 获取用户的样式配置
|
|
|
|
@ -469,7 +554,7 @@ function setConfig() {
|
|
|
|
|
'numberedList',
|
|
|
|
|
'outdent',
|
|
|
|
|
'indent',
|
|
|
|
|
'|', 'ExportToWord', 'ExportToPDF', 'translate', 'SideBar', 'SaveButton','AiFormat'
|
|
|
|
|
'|', 'ExportToWord', 'ExportToPDF', 'RefineDoc', 'SideBar', 'SaveButton','AiFormat'
|
|
|
|
|
],
|
|
|
|
|
shouldNotGroupWhenFull: true
|
|
|
|
|
},
|
|
|
|
@ -543,7 +628,7 @@ function setConfig() {
|
|
|
|
|
TodoList,
|
|
|
|
|
Underline,
|
|
|
|
|
Undo,
|
|
|
|
|
Export2Word, RefineDoc, Export2PDF, ToggleSideBar, SaveButton, AiFormat
|
|
|
|
|
Export2Word, RefineDoc, Export2PDF, ToggleSideBar, SaveButton, AiFormat, PicRecog
|
|
|
|
|
],
|
|
|
|
|
balloonToolbar: ['bold', 'italic', '|', 'link', 'insertImage', '|', 'bulletedList', 'numberedList','|','AiFormat'],
|
|
|
|
|
//自定义设置字体
|
|
|
|
@ -622,7 +707,9 @@ function setConfig() {
|
|
|
|
|
'imageStyle:wrapText',
|
|
|
|
|
'imageStyle:breakText',
|
|
|
|
|
'|',
|
|
|
|
|
'resizeImage'
|
|
|
|
|
'resizeImage',
|
|
|
|
|
'|',
|
|
|
|
|
'PicRecog'
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
initialData:
|
|
|
|
@ -681,4 +768,4 @@ function setConfig() {
|
|
|
|
|
}
|
|
|
|
|
const emitter = new mitt();
|
|
|
|
|
export default emitter;
|
|
|
|
|
export {Export2Word, Export2PDF, RefineDoc, ToggleSideBar, setConfig};
|
|
|
|
|
export {Export2Word, Export2PDF, RefineDoc, ToggleSideBar, PicRecog, setConfig};
|
|
|
|
|