Skip to content

Commit

Permalink
fix: deDuplicated BuiltinComponentsMap (#1073)
Browse files Browse the repository at this point in the history
  • Loading branch information
chilingling authored Feb 6, 2025
1 parent 6d7303f commit 15b6a9c
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/vue-generator/src/plugins/parseSchemaPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function parseSchema() {
const { pageSchema } = schema
const pagesMap = {}
const resPageTree = []

schema.componentsMap = [...schema.componentsMap, ...BUILTIN_COMPONENTS_MAP]

for (const componentItem of pageSchema) {
Expand Down
21 changes: 18 additions & 3 deletions packages/vue-generator/src/utils/generateImportStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,31 @@ export function generateImportStatement(config) {

export function generateImportByPkgName(config) {
const { pkgName, imports } = config

const seen = new Set()
const importStatements = imports
.filter(({ destructuring }) => destructuring)
.map(({ componentName, exportName }) => {
if (componentName === exportName) {
return componentName
if (!seen.has(componentName)) {
seen.add(componentName)

return componentName
}

return ''
}

const alias = `${exportName} as ${componentName}`

if (!seen.has(alias)) {
seen.add(alias)

return alias
}

return `${exportName} as ${componentName}`
return ''
})
.filter((item) => Boolean(item))

// 默认导出如果存在,应该只有一个
let defaultImports = imports.find(({ destructuring }) => !destructuring)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"module": "dist/index.js",
"dependencies": {
"@opentiny/tiny-engine-i18n-host": "^1.0.0",
"@opentiny/vue": "latest",
"@opentiny/vue-icon": "latest",
"@opentiny/vue": "0.1.16",
"@opentiny/vue-icon": "0.1.16",
"axios": "latest",
"axios-mock-adapter": "^1.19.0",
"vue": "^3.3.9",
"vue-i18n": "^9.2.0-beta.3",
"vue-router": "^4.2.5",
"pinia": "^2.1.7"
"pinia": "^2.1.7",
"@opentiny/tiny-engine-builtin-component": "^2.0.0"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.1.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { createRouter, createWebHashHistory } from 'vue-router'
const routes = [
{ path: '/', redirect: '/demopage' },
{ path: '/demopage', component: () => import('@/views/DemoPage.vue') },
{ path: '/createVm', component: () => import('@/views/createVm.vue') }
{
name: '5bhD7p5FUsUOTFRN',
path: 'demopage',
component: () => import('@/views/DemoPage.vue'),
children: []
},
{
name: 'NTJ4MjvqoVj8OVsc',
path: 'createVm',
component: () => import('@/views/createVm.vue'),
children: []
},
{
name: '1737797330916',
path: 'testCanvasRowCol',
component: () => import('@/views/testCanvasRowCol.vue'),
children: []
}
]

export default createRouter({
history: createWebHashHistory(),
routes
routes: [{ path: '/', children: routes }]
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<template>
<div>
<canvas-row-col-container rowGap="20px">
<canvas-row rowGap="20px" colGap="20px">
<canvas-col rowGap="20px" colGap="20px" :grow="true" :shrink="true" widthType="auto"></canvas-col>
<canvas-col rowGap="20px" colGap="20px" :grow="true" :shrink="true" widthType="auto"></canvas-col
></canvas-row>
<canvas-row rowGap="20px" colGap="20px">
<canvas-col rowGap="20px" colGap="20px" :grow="true" :shrink="true" widthType="auto">
<canvas-row rowGap="20px" colGap="20px">
<canvas-col rowGap="20px" colGap="20px" :grow="true" :shrink="true" widthType="auto"></canvas-col
></canvas-row>
<canvas-row rowGap="20px" colGap="20px">
<canvas-col rowGap="20px" colGap="20px" :grow="true" :shrink="true" widthType="auto"></canvas-col
></canvas-row>
<canvas-row rowGap="20px" colGap="20px">
<canvas-col
rowGap="20px"
colGap="20px"
:grow="true"
:shrink="true"
widthType="auto"
></canvas-col></canvas-row
></canvas-col>
<canvas-col rowGap="20px" colGap="20px" :grow="true" :shrink="true" widthType="auto"></canvas-col></canvas-row
></canvas-row-col-container>
</div>
</template>

<script setup>
import { CanvasRow, CanvasCol, CanvasRowColContainer } from '@opentiny/tiny-engine-builtin-component'
import * as vue from 'vue'
import { defineProps, defineEmits } from 'vue'
import { I18nInjectionKey } from 'vue-i18n'
const props = defineProps({})
const emit = defineEmits([])
const { t, lowcodeWrap, stores } = vue.inject(I18nInjectionKey).lowcode()
const wrap = lowcodeWrap(props, { emit })
wrap({ stores })
const state = vue.reactive({ dataDisk: [1, 2, 3] })
wrap({ state })
</script>
<style scoped>
body {
background-color: #eef0f5;
margin-bottom: 80px;
}
</style>
172 changes: 172 additions & 0 deletions packages/vue-generator/test/testcases/generator/mockData.js
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,178 @@ export const appSchemaDemo01 = {
isHome: false,
_id: 'NTJ4MjvqoVj8OVsc'
}
},
{
state: {
dataDisk: [1, 2, 3]
},
methods: {},
componentName: 'Page',
css: 'body {\r\n background-color:#eef0f5 ;\r\n margin-bottom: 80px;\r\n}',
props: {},
children: [
{
componentName: 'CanvasRowColContainer',
props: {
rowGap: '20px'
},
children: [
{
componentName: 'CanvasRow',
props: {
rowGap: '20px',
colGap: '20px'
},
children: [
{
componentName: 'CanvasCol',
props: {
rowGap: '20px',
colGap: '20px',
grow: true,
shrink: true,
widthType: 'auto'
},
id: '4514b344'
},
{
componentName: 'CanvasCol',
props: {
rowGap: '20px',
colGap: '20px',
grow: true,
shrink: true,
widthType: 'auto'
},
children: [],
id: '3664a254'
}
],
id: '63553246'
},
{
componentName: 'CanvasRow',
props: {
rowGap: '20px',
colGap: '20px'
},
children: [
{
componentName: 'CanvasCol',
props: {
rowGap: '20px',
colGap: '20px',
grow: true,
shrink: true,
widthType: 'auto'
},
id: '2c13444f',
children: [
{
componentName: 'CanvasRow',
props: {
rowGap: '20px',
colGap: '20px'
},
children: [
{
componentName: 'CanvasCol',
props: {
rowGap: '20px',
colGap: '20px',
grow: true,
shrink: true,
widthType: 'auto'
},
children: [],
id: '24256327'
}
],
id: '56453426'
},
{
componentName: 'CanvasRow',
props: {
rowGap: '20px',
colGap: '20px'
},
children: [
{
componentName: 'CanvasCol',
props: {
rowGap: '20px',
colGap: '20px',
grow: true,
shrink: true,
widthType: 'auto'
},
id: '5451f224'
}
],
id: '26364626'
},
{
componentName: 'CanvasRow',
props: {
rowGap: '20px',
colGap: '20px'
},
children: [
{
componentName: 'CanvasCol',
props: {
rowGap: '20px',
colGap: '20px',
grow: true,
shrink: true,
widthType: 'auto'
},
children: [],
id: '26232436'
}
],
id: '52555445'
}
]
},
{
componentName: 'CanvasCol',
props: {
rowGap: '20px',
colGap: '20px',
grow: true,
shrink: true,
widthType: 'auto'
},
children: [],
id: '53553563'
}
],
id: '53b5fe13'
}
],
id: '25452c43'
}
],
fileName: 'testCanvasRowCol',
meta: {
name: 'testCanvasRowCol',
id: 1737797330916,
app: '918',
router: 'testCanvasRowCol',
tenant: 1,
isBody: false,
parentId: '0',
group: 'staticPages',
depth: 0,
isPage: true,
isDefault: false,
occupier: {
id: 86,
username: '开发者'
},
isHome: false
}
}
],
componentsMap: [
Expand Down

0 comments on commit 15b6a9c

Please sign in to comment.