Skip to content

Commit 0649011

Browse files
committed
feat: add JsonPreview component
1 parent a812685 commit 0649011

File tree

14 files changed

+89
-266
lines changed

14 files changed

+89
-266
lines changed

CHANGELOG.zh_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- 新增图形编辑器示例
66
- 新增代码编辑器(包含 Json 编辑器)
7+
- 新增 `JsonPreview`Json 数据查看组件
78

89
### ⚡ Performance Improvements
910

build/generate/generateModifyVars.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ export function generateModifyVars(dark = false) {
3232
'font-size-base': '14px', // Main font size
3333
'border-radius-base': '2px', // Component/float fillet
3434
'link-color': primary, // Link color
35-
'content-background': '#fafafa', // Link color
35+
'app-content-background': '#fafafa', // Link color
3636
};
3737
}

build/vite/plugin/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function configThemePlugin(isBuild: boolean): Plugin[] {
5353
'border-color-base': '#303030',
5454
// 'border-color-split': '#30363d',
5555
'item-active-bg': '#111b26',
56-
'content-background': '#ffffff0a', // Link color
56+
'app-content-background': 'rgb(255 255 255 / 4%)',
5757
},
5858
}),
5959
];

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@iconify/iconify": "^2.0.0-rc.6",
3636
"@logicflow/core": "^0.3.0",
3737
"@logicflow/extension": "^0.3.0",
38-
"@vueuse/core": "^4.8.1",
38+
"@vueuse/core": "^4.8.2",
3939
"@zxcvbn-ts/core": "^0.3.0",
4040
"ant-design-vue": "^2.1.2",
4141
"axios": "^0.21.1",
@@ -120,7 +120,7 @@
120120
"vite-plugin-style-import": "^0.9.2",
121121
"vite-plugin-svg-icons": "^0.4.3",
122122
"vite-plugin-theme": "^0.7.1",
123-
"vite-plugin-windicss": "0.14.5",
123+
"vite-plugin-windicss": "0.14.6",
124124
"vue-eslint-parser": "^7.6.0",
125125
"vue-tsc": "^0.0.24"
126126
},

src/components/CodeEditor/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import type { App } from 'vue';
22
import codeEditor from './src/CodeEditor.vue';
3+
import jsonPreview from './src/json-preview/JsonPreview.vue';
34

45
export const CodeEditor = Object.assign(codeEditor, {
56
install(app: App) {
67
app.component(codeEditor.name, codeEditor);
78
},
89
});
10+
11+
export const JsonPreview = Object.assign(jsonPreview, {
12+
install(app: App) {
13+
app.component(jsonPreview.name, jsonPreview);
14+
},
15+
});

src/components/FlowChart/src/DataDialog.vue renamed to src/components/CodeEditor/src/json-preview/JsonPreview.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import 'vue-json-pretty/lib/styles.css';
88
import { defineComponent } from 'vue';
99
export default defineComponent({
10-
name: 'DataDialog',
10+
name: 'JsonPreview',
1111
components: {
1212
VueJsonPretty,
1313
},

src/components/FlowChart/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import type { App } from 'vue';
2-
import dataDialog from './src/DataDialog.vue';
32
import flowChart from './src/index.vue';
43

54
export const FlowChart = Object.assign(flowChart, {
65
install(app: App) {
76
app.component(flowChart.name, flowChart);
87
},
98
});
10-
11-
export const DataDialog = Object.assign(dataDialog, {
12-
install(app: App) {
13-
app.component(dataDialog.name, dataDialog);
14-
},
15-
});

src/components/FlowChart/src/FlowChartToolbar.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
props: {
3131
prefixCls: String,
3232
},
33+
emits: ['view-data'],
3334
setup(_, { emit }) {
3435
const toolbarItemList = ref<ToolbarConfig[]>([
3536
{
@@ -112,7 +113,7 @@
112113
lf.getSnapshot();
113114
break;
114115
case ToolbarTypeEnum.VIEW_DATA:
115-
emit('catData');
116+
emit('view-data');
116117
break;
117118
}
118119
};
@@ -131,12 +132,17 @@
131132
},
132133
});
133134
</script>
134-
<style lang="less" scoped>
135+
<style lang="less">
135136
@prefix-cls: ~'@{namespace}-flow-chart-toolbar';
136137
138+
html[data-theme='dark'] {
139+
.lf-dnd {
140+
background: #080808;
141+
}
142+
}
137143
.@{prefix-cls} {
138144
height: 36px;
139-
background: @content-background;
145+
background-color: @app-content-background;
140146
border-bottom: 1px solid @border-color-base;
141147
142148
.disabeld {

src/components/FlowChart/src/index.css

Lines changed: 0 additions & 216 deletions
This file was deleted.

src/components/FlowChart/src/index.vue

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<template>
22
<div class="h-full" :class="prefixCls">
3-
<FlowChartToolbar :prefixCls="prefixCls" v-if="toolbar" />
3+
<FlowChartToolbar :prefixCls="prefixCls" v-if="toolbar" @view-data="handlePreview" />
44
<div ref="lfElRef" class="h-full"></div>
5+
<BasicModal @register="register" title="流程数据" width="50%">
6+
<JsonPreview :data="graphData" />
7+
</BasicModal>
58
</div>
69
</template>
710
<script lang="ts">
@@ -14,15 +17,18 @@
1417
import { Snapshot, BpmnElement, Menu, DndPanel } from '@logicflow/extension';
1518
1619
import { useDesign } from '/@/hooks/web/useDesign';
20+
import { useAppStore } from '/@/store/modules/app';
1721
import { createFlowChartContext } from './useFlowContext';
1822
1923
import { toLogicFlowData } from './adpterForTurbo';
24+
import { useModal, BasicModal } from '/@/components/Modal';
25+
import { JsonPreview } from '/@/components/CodeEditor';
2026
2127
import '@logicflow/core/dist/style/index.css';
22-
import './index.css';
28+
import '@logicflow/extension/lib/style/index.css';
2329
export default defineComponent({
2430
name: 'FlowChart',
25-
components: { FlowChartToolbar },
31+
components: { BasicModal, FlowChartToolbar, JsonPreview },
2632
props: {
2733
flowOptions: {
2834
type: Object as PropType<Definition>,
@@ -41,10 +47,13 @@
4147
},
4248
setup(props) {
4349
const lfElRef = ref<ElRef>(null);
50+
const graphData = ref<Recordable>({});
4451
4552
const lfInstance = ref<Nullable<LogicFlow>>(null);
4653
4754
const { prefixCls } = useDesign('flow-chart');
55+
const appStore = useAppStore();
56+
const [register, { openModal }] = useModal();
4857
createFlowChartContext({
4958
logicFlow: (lfInstance as unknown) as LogicFlow,
5059
});
@@ -55,7 +64,7 @@
5564
const defaultOptions: Partial<Definition> = {
5665
grid: true,
5766
background: {
58-
color: '#f7f9ff',
67+
color: appStore.getDarkMode === 'light' ? '#f7f9ff' : '#151515',
5968
},
6069
keyboard: {
6170
enabled: true,
@@ -73,12 +82,20 @@
7382
);
7483
7584
watch(
76-
() => props.flowOptions,
85+
() => appStore.getDarkMode,
86+
() => {
87+
init();
88+
}
89+
);
90+
91+
watch(
92+
() => unref(getFlowOptions),
7793
(options) => {
7894
unref(lfInstance)?.updateEditConfig(options);
7995
}
8096
);
8197
98+
let isInit = false;
8299
// init logicFlow
83100
async function init() {
84101
await nextTick();
@@ -87,14 +104,17 @@
87104
if (!lfEl) {
88105
return;
89106
}
107+
if (!isInit) {
108+
// Canvas configuration
109+
LogicFlow.use(Snapshot);
110+
// Use the bpmn plug-in to introduce bpmn elements, which can be used after conversion in turbo
111+
LogicFlow.use(BpmnElement);
112+
// Start the right-click menu
113+
LogicFlow.use(Menu);
114+
LogicFlow.use(DndPanel);
115+
isInit = true;
116+
}
90117
91-
// Canvas configuration
92-
LogicFlow.use(Snapshot);
93-
// Use the bpmn plug-in to introduce bpmn elements, which can be used after conversion in turbo
94-
LogicFlow.use(BpmnElement);
95-
// Start the right-click menu
96-
LogicFlow.use(Menu);
97-
LogicFlow.use(DndPanel);
98118
lfInstance.value = new LogicFlow({
99119
...unref(getFlowOptions),
100120
container: lfEl,
@@ -113,11 +133,24 @@
113133
lf.render(lFData);
114134
}
115135
136+
function handlePreview() {
137+
const lf = unref(lfInstance);
138+
if (!lf) {
139+
return;
140+
}
141+
graphData.value = unref(lf).getGraphData();
142+
143+
openModal();
144+
}
145+
116146
onMounted(init);
117147
118148
return {
149+
register,
119150
prefixCls,
120151
lfElRef,
152+
handlePreview,
153+
graphData,
121154
};
122155
},
123156
});

0 commit comments

Comments
 (0)