Skip to content

Commit f3869aa

Browse files
committed
将 FcDesigner 改成局部注册,减少包大小
1 parent d32537e commit f3869aa

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

src/plugins/formCreate/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717

1818
import formCreate from '@form-create/element-ui'
1919
import install from '@form-create/element-ui/auto-import'
20-
import FcDesigner from '@form-create/designer'
2120

2221
const components = [
2322
ElAside,
@@ -34,14 +33,11 @@ const components = [
3433
ElTabPane
3534
]
3635

36+
// 参考 http://www.form-create.com/v3/element-ui/auto-import.html 文档
3737
export const setupFormCreate = (app: App<Element>) => {
3838
components.forEach((component) => {
3939
app.component(component.name, component)
4040
})
41-
4241
formCreate.use(install)
43-
4442
app.use(formCreate)
45-
46-
app.use(FcDesigner)
4743
}

src/views/bpm/form/editor/index.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<template>
22
<ContentWrap>
33
<!-- 表单设计器 -->
4-
<fc-designer ref="designer" height="780px">
4+
<FcDesigner ref="designer" height="780px">
55
<template #handle>
66
<el-button round size="small" type="primary" @click="handleSave">
77
<Icon class="mr-5px" icon="ep:plus" />
88
保存
99
</el-button>
1010
</template>
11-
</fc-designer>
11+
</FcDesigner>
1212
</ContentWrap>
1313

1414
<!-- 表单保存的弹窗 -->
@@ -42,6 +42,7 @@
4242
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
4343
import { CommonStatusEnum } from '@/utils/constants'
4444
import * as FormApi from '@/api/bpm/form'
45+
import FcDesigner from '@form-create/designer'
4546
import { encodeConf, encodeFields, setConfAndFields } from '@/utils/formCreate'
4647
4748
const { t } = useI18n() // 国际化

src/views/infra/build/index.vue

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<el-col>
55
<div class="mb-2 float-right">
66
<el-button size="small" type="primary" @click="showJson">生成 JSON</el-button>
7-
<el-button size="small" type="success" @click="showOption">生成O ptions</el-button>
7+
<el-button size="small" type="success" @click="showOption">生成 Options</el-button>
88
<el-button size="small" type="danger" @click="showTemplate">生成组件</el-button>
99
</div>
1010
</el-col>
1111
<!-- 表单设计器 -->
1212
<el-col>
13-
<fc-designer ref="designer" height="780px" />
13+
<FcDesigner ref="designer" height="780px" />
1414
</el-col>
1515
</el-row>
1616
</ContentWrap>
@@ -22,18 +22,17 @@
2222
{{ t('common.copy') }}
2323
</el-button>
2424
<el-scrollbar height="580">
25-
<div v-highlight>
26-
<code class="hljs">
27-
{{ formData }}
28-
</code>
25+
<div>
26+
<pre><code class="hljs" v-html="highlightedCode(formData)"></code></pre>
2927
</div>
3028
</el-scrollbar>
3129
</div>
3230
</Dialog>
3331
</template>
3432
<script setup lang="ts" name="InfraBuild">
35-
import formCreate from '@form-create/element-ui'
33+
import FcDesigner from '@form-create/designer'
3634
import { useClipboard } from '@vueuse/core'
35+
import { isString } from '@/utils/is'
3736
const { t } = useI18n() // 国际化
3837
const message = useMessage() // 消息
3938
@@ -109,4 +108,32 @@ const copy = async (text: string) => {
109108
}
110109
}
111110
}
111+
112+
/**
113+
* 代码高亮
114+
*/
115+
import hljs from 'highlight.js' // 导入代码高亮文件
116+
import 'highlight.js/styles/github.css' // 导入代码高亮样式
117+
import xml from 'highlight.js/lib/languages/java'
118+
import json from 'highlight.js/lib/languages/json'
119+
const highlightedCode = (code) => {
120+
// 处理语言和代码
121+
let language = 'json'
122+
if (formType.value === 2) {
123+
language = 'xml'
124+
}
125+
if (!isString(code)) {
126+
code = JSON.stringify(code)
127+
}
128+
// 高亮
129+
const result = hljs.highlight(language, code, true)
130+
return result.value || '&nbsp;'
131+
}
132+
133+
/** 初始化 **/
134+
onMounted(async () => {
135+
// 注册代码高亮的各种语言
136+
hljs.registerLanguage('xml', xml)
137+
hljs.registerLanguage('json', json)
138+
})
112139
</script>

0 commit comments

Comments
 (0)