mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-05-10 04:29:07 +08:00
fix(playground): 预览检查是否保存
This commit is contained in:
parent
2f8f81afb3
commit
f9ae10bc9d
@ -27,11 +27,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, ref, toRaw } from 'vue';
|
import { defineComponent, ref, toRaw } from 'vue';
|
||||||
import { Coin, Connection, Document, FolderOpened, SwitchButton, Tickets } from '@element-plus/icons';
|
import { Coin, Connection, Document, FolderOpened, SwitchButton, Tickets } from '@element-plus/icons';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||||
import serialize from 'serialize-javascript';
|
import serialize from 'serialize-javascript';
|
||||||
|
|
||||||
import type { MenuBarData, MoveableOptions, TMagicEditor } from '@tmagic/editor';
|
import type { MenuBarData, MoveableOptions, TMagicEditor } from '@tmagic/editor';
|
||||||
import { NodeType } from '@tmagic/schema';
|
import { Id, NodeType } from '@tmagic/schema';
|
||||||
import StageCore from '@tmagic/stage';
|
import StageCore from '@tmagic/stage';
|
||||||
import { asyncLoadJs } from '@tmagic/utils';
|
import { asyncLoadJs } from '@tmagic/utils';
|
||||||
|
|
||||||
@ -50,6 +50,18 @@ export default defineComponent({
|
|||||||
const propsValues = ref<Record<string, any>>({});
|
const propsValues = ref<Record<string, any>>({});
|
||||||
const propsConfigs = ref<Record<string, any>>({});
|
const propsConfigs = ref<Record<string, any>>({});
|
||||||
const eventMethodList = ref<Record<string, any>>({});
|
const eventMethodList = ref<Record<string, any>>({});
|
||||||
|
|
||||||
|
const save = () => {
|
||||||
|
localStorage.setItem(
|
||||||
|
'magicUiConfig',
|
||||||
|
serialize(toRaw(value.value), {
|
||||||
|
space: 2,
|
||||||
|
unsafe: true,
|
||||||
|
}).replace(/"(\w+)":\s/g, '$1: '),
|
||||||
|
);
|
||||||
|
editor.value?.editorService.resetModifiedNodeId();
|
||||||
|
};
|
||||||
|
|
||||||
const menu: MenuBarData = {
|
const menu: MenuBarData = {
|
||||||
left: [
|
left: [
|
||||||
{
|
{
|
||||||
@ -63,7 +75,20 @@ export default defineComponent({
|
|||||||
type: 'button',
|
type: 'button',
|
||||||
text: '预览',
|
text: '预览',
|
||||||
icon: Connection,
|
icon: Connection,
|
||||||
handler: () => {
|
handler: async () => {
|
||||||
|
if (editor.value && editor.value.editorService.get<Map<Id, Id>>('modifiedNodeIds').size > 0) {
|
||||||
|
try {
|
||||||
|
await ElMessageBox.confirm('有修改未保存,是否先保存再预览', '提示', {
|
||||||
|
confirmButtonText: '保存并预览',
|
||||||
|
cancelButtonText: '预览',
|
||||||
|
type: 'warning',
|
||||||
|
});
|
||||||
|
save();
|
||||||
|
ElMessage.success('保存成功');
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
previewVisible.value = true;
|
previewVisible.value = true;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -71,15 +96,8 @@ export default defineComponent({
|
|||||||
type: 'button',
|
type: 'button',
|
||||||
text: '保存',
|
text: '保存',
|
||||||
icon: Coin,
|
icon: Coin,
|
||||||
handler: (service) => {
|
handler: () => {
|
||||||
localStorage.setItem(
|
save();
|
||||||
'magicUiConfig',
|
|
||||||
serialize(toRaw(value.value), {
|
|
||||||
space: 2,
|
|
||||||
unsafe: true,
|
|
||||||
}).replace(/"(\w+)":\s/g, '$1: '),
|
|
||||||
);
|
|
||||||
service?.editorService.resetModifiedNodeId();
|
|
||||||
ElMessage.success('保存成功');
|
ElMessage.success('保存成功');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -103,6 +121,8 @@ export default defineComponent({
|
|||||||
eventMethodList.value = (globalThis as any).magicPresetEvents;
|
eventMethodList.value = (globalThis as any).magicPresetEvents;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
save();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
RUNTIME_PATH,
|
RUNTIME_PATH,
|
||||||
|
|
||||||
@ -169,6 +189,9 @@ export default defineComponent({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
html {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
#app {
|
#app {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user