Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: merge preview entry with index entry #581

Draft
wants to merge 2 commits into
base: refactor/develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions designer-demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue</title>
<title>TinyEngine 低代码引擎可视化设计器</title>
</head>
<body>
<div id="app"></div>
Expand Down
13 changes: 0 additions & 13 deletions designer-demo/preview.html

This file was deleted.

29 changes: 0 additions & 29 deletions designer-demo/src/preview.js

This file was deleted.

5 changes: 2 additions & 3 deletions packages/build/vite-config/src/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ const config = {
plugins: [nodePolyfill({ include: null })], // 使用@rollup/plugin-inject的默认值{include: null}, 即在所有代码中生效
input: {
index: path.resolve(process.cwd(), './index.html'),
canvas: path.resolve(process.cwd(), './canvas.html'),
preview: path.resolve(process.cwd(), './preview.html')
canvas: path.resolve(process.cwd(), './canvas.html')
},
output: {
manualChunks: (id) => {
Expand Down Expand Up @@ -150,7 +149,7 @@ export default defineConfig(({ command = 'serve', mode = 'serve' }, extOptions)
})
const htmlPlugin = (mode) => {
const upgradeHttpsMetaTags = []
const includeHtmls = ['index.html', 'preview.html', 'previewApp.html']
const includeHtmls = ['index.html']

if (mode === 'alpha' || mode === 'prod') {
upgradeHttpsMetaTags.push({
Expand Down
7 changes: 2 additions & 5 deletions packages/controller/js/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
*/

import { constants } from '@opentiny/tiny-engine-utils'
import { isDevelopEnv } from './environments'
import { useResource } from '@opentiny/tiny-engine-entry'
// prefer old unicode hacks for backward compatibility

const { COMPONENT_NAME } = constants

// prefer old unicode hacks for backward compatibility
export const utoa = (string) => btoa(unescape(encodeURIComponent(string)))

export const atou = (base64) => decodeURIComponent(escape(atob(base64)))
Expand All @@ -36,9 +35,7 @@ const open = (params = {}) => {
let openUrl = ''
const hashString = utoa(JSON.stringify(params))

openUrl = isDevelopEnv
? `./preview.html?tenant=${tenant}#${hashString}`
: `${href}/preview?tenant=${tenant}#${hashString}`
openUrl = `${href}/preview?tenant=${tenant}#${hashString}`

const aTag = document.createElement('a')
aTag.href = openUrl
Expand Down
1 change: 0 additions & 1 deletion packages/design-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export { default as Events } from '@opentiny/tiny-engine-setting-events'
export { default as Styles } from '@opentiny/tiny-engine-setting-styles'
export { default as Layout } from '@opentiny/tiny-engine-layout'
export { default as Canvas } from '@opentiny/tiny-engine-canvas'
export { initPreview } from './src/preview/src/main'

export { default as defaultRegistry } from './registry'

Expand Down
16 changes: 15 additions & 1 deletion packages/design-core/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { defineEntry, mergeRegistry } from '@opentiny/tiny-engine-entry'
import App from './App.vue'
import defaultRegistry from '../registry.js'
import { registerConfigurators } from './registerConfigurators'
import { initPreview } from './preview/src/main.js'

const defaultLifeCycles = {
beforeAppCreate: ({ registry }) => {
Expand Down Expand Up @@ -57,7 +58,7 @@ const defaultLifeCycles = {
}
}

export const init = ({ selector = '#app', registry = defaultRegistry, lifeCycles = {}, configurators = [] } = {}) => {
const initMain = ({ selector = '#app', registry = defaultRegistry, lifeCycles = {}, configurators = [] } = {}) => {
const { beforeAppCreate, appCreated, appMounted } = lifeCycles

registerConfigurators(configurators)
Expand All @@ -71,3 +72,16 @@ export const init = ({ selector = '#app', registry = defaultRegistry, lifeCycles
app.mount(selector)
appMounted?.({ app })
}

// 如果后续预览和主设计器的初始化参数差异大,需要拆分配置
export const init = (params) => {
const path = window.location.pathname

// 预览页面
if (path.endsWith('/preview')) {
initPreview(params)
} else {
// 主设计器
initMain(params)
}
}
15 changes: 0 additions & 15 deletions packages/design-core/src/main.js

This file was deleted.

7 changes: 2 additions & 5 deletions packages/design-core/src/preview/src/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ export default {
setup() {
const debugSwitch = injectDebugSwitch()
const _tools = ['breadcrumb', 'lang', 'media']
const [Breadcrumb, ChangeLang, ToolbarMedia] = [
BreadcrumbPlugin.component,
LangPlugin.component,
MediaPlugin.component
]

const [Breadcrumb, ChangeLang, ToolbarMedia] = [BreadcrumbPlugin.entry, LangPlugin.entry, MediaPlugin.entry]

const { setBreadcrumbPage } = useBreadcrumb()
const { pageInfo } = getSearchParams()
Expand Down