Skip to content

Commit 65cb092

Browse files
committed
feat: 移除模板设置组件,更新模板处理逻辑以支持字符串类型模板,优化代码结构
1 parent 018ca60 commit 65cb092

4 files changed

Lines changed: 14 additions & 72 deletions

File tree

designer-demo/registry.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { META_SERVICE } from '@opentiny/tiny-engine-meta-register'
1313
// import { META_SERVICE } from '@opentiny/tiny-engine'
1414
import engineConfig from './engine.config'
1515
import { HttpService } from './src/composable'
16-
import templateSetting from './src/template/setting.vue'
1716
import scriptPlugin from './src/plugins/script'
1817
import removedRegistry from './removedRegistry.json'
1918

@@ -22,13 +21,6 @@ export default {
2221
'engine.config': {
2322
...engineConfig
2423
},
25-
'engine.plugins.page': {
26-
overwrite: {
27-
templates: {
28-
PageSetting: templateSetting
29-
}
30-
}
31-
},
3224
...removedRegistry,
3325
// 配置 false 隐藏工具栏清空按钮
3426
// 'engine.toolbars.clean': false,
@@ -39,7 +31,7 @@ export default {
3931
// 换了个id,代表新增模块
4032
'engine.plugins.script': {
4133
...scriptPlugin,
42-
id: 'engine.plugins.script',
34+
id: 'engine.plugins.script'
4335
},
4436
'engine.layout': {
4537
options: {
@@ -65,5 +57,5 @@ export default {
6557
}
6658
}
6759
}
68-
},
60+
}
6961
}

designer-demo/src/template/setting.vue

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

packages/register/src/entryHash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const handleLifeCycles = (id: string, lifeCycles: any) => {
8383

8484
const handleVueTemplate = (id: string, templates: any) => {
8585
Object.entries(templates).forEach(([name, template]) => {
86-
if (typeof template === 'object') {
86+
if (typeof template === 'string') {
8787
const prefix = name && name !== "''" ? `.${name}` : ''
8888
const templateId = `${id}${prefix}`
8989
templateHashMap[templateId] = template

packages/register/src/templateHash.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,23 @@
99
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
1010
*
1111
*/
12+
import { compile } from 'vue/dist/vue.esm-bundler.js'
1213
import { templateHashMap } from './entryHash'
1314

15+
const generateTemplate = (template: string) => {
16+
const templateString = template.trim()
17+
if (templateString.startsWith('<template>') && templateString.endsWith('</template>')) {
18+
return templateString.slice(10, -11)
19+
}
20+
return templateString
21+
}
22+
1423
export const useCompile = ({ component, metaData }: any) => {
1524
// 此处compile会缓存template对应的render函数,并且render函数一个纯函数(用到的所有变量都来自参数)
1625
const customTem = templateHashMap[metaData.id]
1726
if (customTem) {
18-
component.render = customTem.render
27+
const template = generateTemplate(customTem)
28+
component.render = compile(template)
1929
}
2030

2131
return component

0 commit comments

Comments
 (0)