mirror of
https://github.com/Powerful-517/yys-editor.git
synced 2025-06-09 09:35:23 +00:00
调整字体栏编辑效果,增加LocalStorage缓存
This commit is contained in:
parent
b951e0ea5e
commit
78c4b2a2c1
@ -36,7 +36,7 @@
|
|||||||
<el-button type="danger" icon="Delete" circle @click="removeGroup(groupIndex)"></el-button>
|
<el-button type="danger" icon="Delete" circle @click="removeGroup(groupIndex)"></el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<QuillEditor ref="shortDescriptionEditor" contentType="html" theme="snow" :toolbar="toolbarOptions"/>
|
<QuillEditor ref="shortDescriptionEditor" v-model:content="group.shortDescription" contentType="html" theme="snow" :toolbar="toolbarOptions"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="group-body">
|
<div class="group-body">
|
||||||
<draggable :list="group.groupInfo" item-key="name" class="body-content">
|
<draggable :list="group.groupInfo" item-key="name" class="body-content">
|
||||||
@ -180,20 +180,20 @@ registerSizes()
|
|||||||
|
|
||||||
// 工具栏配置
|
// 工具栏配置
|
||||||
const toolbarOptions = ref([
|
const toolbarOptions = ref([
|
||||||
['bold', 'italic', 'underline', 'strike'],
|
|
||||||
// ['blockquote', 'code-block'],
|
|
||||||
[{ header: 1 }, { header: 2 }],
|
|
||||||
[{ list: 'ordered' }, { list: 'bullet' }, {'list': 'check'}],
|
|
||||||
[{ script: 'sub' }, { script: 'super' }],
|
|
||||||
[{ indent: '-1' }, { indent: '+1' }],
|
|
||||||
[{ direction: 'rtl' }],
|
|
||||||
[{ color: [] }, { background: [] }],
|
|
||||||
// [{ header: [1, 2, 3, 4, 5, 6, false] }],
|
|
||||||
[{ size: ['12px', '14px', '16px', '18px', '21px', '29px', '32px', '34px'] }],
|
|
||||||
[{ font: ['SimSun', 'SimHei', 'KaiTi', 'FangSong', 'Microsoft YaHei', 'PingFang SC'] }],
|
[{ font: ['SimSun', 'SimHei', 'KaiTi', 'FangSong', 'Microsoft YaHei', 'PingFang SC'] }],
|
||||||
|
[{ header: 1 }, { header: 2 }],
|
||||||
|
[{ size: ['12px', '14px', '16px', '18px', '21px', '29px', '32px', '34px'] }],
|
||||||
|
['bold', 'italic', 'underline', 'strike'],
|
||||||
|
[{ color: [] }, { background: [] }],
|
||||||
|
// ['blockquote', 'code-block'],
|
||||||
|
[ { list: 'bullet' }, { list: 'ordered' }, {'list': 'check'}],
|
||||||
|
|
||||||
|
[{ indent: '-1' }, { indent: '+1' }],
|
||||||
[{ align: [] }],
|
[{ align: [] }],
|
||||||
|
[{ direction: 'rtl' }],
|
||||||
|
// [{ header: [1, 2, 3, 4, 5, 6, false] }],
|
||||||
// ['link', 'image', 'video'],
|
// ['link', 'image', 'video'],
|
||||||
['clean']
|
// ['clean']
|
||||||
] as const)
|
] as const)
|
||||||
|
|
||||||
// 定义方法
|
// 定义方法
|
||||||
|
@ -16,6 +16,7 @@ import zh from './locales/zh.json'
|
|||||||
import ja from './locales/ja.json'
|
import ja from './locales/ja.json'
|
||||||
|
|
||||||
import { createPinia } from 'pinia' // 导入 Pinia
|
import { createPinia } from 'pinia' // 导入 Pinia
|
||||||
|
import {useFilesStore} from "@/ts/files";
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
|
|
||||||
@ -60,3 +61,7 @@ app.use(pinia) // 使用 Pinia
|
|||||||
.use(ElementPlus)
|
.use(ElementPlus)
|
||||||
.use(Vue3DraggableResizable)
|
.use(Vue3DraggableResizable)
|
||||||
.mount('#app')
|
.mount('#app')
|
||||||
|
|
||||||
|
const filesStore = useFilesStore();
|
||||||
|
filesStore.setupAutoSave();
|
||||||
|
filesStore.initializeWithPrompt();
|
@ -3,6 +3,19 @@ import {ElMessageBox} from "element-plus";
|
|||||||
import {useGlobalMessage} from "./useGlobalMessage";
|
import {useGlobalMessage} from "./useGlobalMessage";
|
||||||
|
|
||||||
const { showMessage } = useGlobalMessage();
|
const { showMessage } = useGlobalMessage();
|
||||||
|
|
||||||
|
function saveStateToLocalStorage(state) {
|
||||||
|
localStorage.setItem('filesStore', JSON.stringify(state));
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearLocalStorage() {
|
||||||
|
localStorage.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadStateFromLocalStorage() {
|
||||||
|
return JSON.parse(localStorage.getItem('filesStore'));
|
||||||
|
}
|
||||||
|
|
||||||
export const useFilesStore = defineStore('files', {
|
export const useFilesStore = defineStore('files', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
fileList: [
|
fileList: [
|
||||||
@ -194,6 +207,32 @@ export const useFilesStore = defineStore('files', {
|
|||||||
visibleFiles: (state) => state.fileList.filter(file => file.visible),
|
visibleFiles: (state) => state.fileList.filter(file => file.visible),
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
initializeWithPrompt() {
|
||||||
|
const savedState = loadStateFromLocalStorage();
|
||||||
|
if (savedState) {
|
||||||
|
ElMessageBox.confirm(
|
||||||
|
'检测到有未保存的旧数据,是否恢复?',
|
||||||
|
'提示',
|
||||||
|
{
|
||||||
|
confirmButtonText: '恢复',
|
||||||
|
cancelButtonText: '不恢复',
|
||||||
|
type: 'warning',
|
||||||
|
}
|
||||||
|
).then(() => {
|
||||||
|
this.fileList = savedState.fileList || [];
|
||||||
|
this.activeFile = savedState.activeFile || "1";
|
||||||
|
showMessage('success', '数据已恢复');
|
||||||
|
}).catch(() => {
|
||||||
|
clearLocalStorage();
|
||||||
|
showMessage('info', '选择了不恢复旧数据');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setupAutoSave() {
|
||||||
|
setInterval(() => {
|
||||||
|
saveStateToLocalStorage(this.$state);
|
||||||
|
}, 30000); // 设置间隔时间为30秒
|
||||||
|
},
|
||||||
addFile(file) {
|
addFile(file) {
|
||||||
this.fileList.push({...file, visible: true});
|
this.fileList.push({...file, visible: true});
|
||||||
this.activeFile = file.name;
|
this.activeFile = file.name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user