Skip to content

Commit

Permalink
fix: update cli template resolve preview error
Browse files Browse the repository at this point in the history
  • Loading branch information
hexqi committed Jan 2, 2025
1 parent 6110591 commit efd0123
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 24 deletions.
19 changes: 11 additions & 8 deletions packages/engine-cli/template/designer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_THEME=light vite build --mode prod"
},
"dependencies": {
"vue": "^3.4.21",
"@opentiny/tiny-engine": "^2.0.0-alpha.5",
"@opentiny/tiny-engine-theme-dark": "^2.0.0-alpha.5",
"@opentiny/tiny-engine-theme-light": "^2.0.0-alpha.5",
"@opentiny/tiny-engine": "^2.1.0",
"@opentiny/tiny-engine-theme-dark": "^2.1.0",
"@opentiny/tiny-engine-theme-light": "^2.1.0",
"@opentiny/tiny-engine-utils": "^2.1.0",
"@opentiny/vue": "~3.14.0",
"@opentiny/vue-icon": "~3.14.0",
"@opentiny/vue-design-smb": "~3.14.0",
"@opentiny/vue-icon": "~3.14.0",
"@opentiny/vue-locale": "~3.14.0",
"@opentiny/vue-renderless": "~3.14.0",
"@opentiny/vue-theme": "~3.14.0"
"@opentiny/vue-theme": "~3.14.0",
"@vueuse/core": "^9.6.0",
"vue": "^3.4.21"
},
"devDependencies": {
"@opentiny/tiny-engine-vite-config": "^2.0.0-alpha.5",
"@opentiny/tiny-engine-mock": "^2.0.0-alpha.5",
"@opentiny/tiny-engine-mock": "^2.1.0",
"@opentiny/tiny-engine-vite-config": "^2.1.0",
"@vitejs/plugin-vue": "^5.1.2",
"cross-env": "^7.0.3",
"concurrently": "^8.2.0",
Expand Down
109 changes: 108 additions & 1 deletion packages/engine-cli/template/designer/public/mock/bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -4828,6 +4828,113 @@
}
}
},
{
"icon": "row",
"name": {
"zh_CN": "row"
},
"component": "TinyLayout",
"description": "定义 Layout 的行配置信息",
"docUrl": "",
"screenshot": "",
"tags": "",
"keywords": "",
"devMode": "proCode",
"npm": {
"package": "@opentiny/vue",
"exportName": "Layout",
"version": "3.14.0",
"destructuring": true,
"script": "https://unpkg.com/@opentiny/vue@~3.14/runtime/tiny-vue.mjs",
"css": "https://unpkg.com/@opentiny/vue-theme@~3.14/index.css"
},
"group": "component",
"priority": 5,
"schema": {
"properties": [
{
"label": {
"zh_CN": "基础信息"
},
"description": {
"zh_CN": "基础信息"
},
"content": [
{
"property": "cols",
"label": {
"text": {
"zh_CN": "总栅格数"
}
},
"cols": 12,
"widget": {
"component": "ButtonGroupConfigurator",
"props": {
"options": [
{
"label": "12",
"value": 12
},
{
"label": "24",
"value": 24
}
]
}
},
"description": {
"zh_CN": "选择总栅格数"
},
"labelPosition": "none"
},
{
"property": "tag",
"label": {
"text": {
"zh_CN": "layout渲染的标签"
}
},
"required": false,
"readOnly": false,
"disabled": false,
"cols": 12,
"widget": {
"component": "InputConfigurator",
"props": {}
},
"description": {
"zh_CN": "定义Layout元素渲染后的标签,默认为 div"
}
}
]
}
]
},
"configure": {
"loop": true,
"condition": true,
"styles": true,
"isContainer": true,
"isModal": false,
"nestingRule": {
"childWhitelist": ["TinyRow", "TinyCol"],
"parentWhitelist": "",
"descendantBlacklist": "",
"ancestorWhitelist": ""
},
"isNullNode": false,
"isLayout": false,
"rootSelector": "",
"shortcuts": {
"properties": ["disabled"]
},
"contextMenu": {
"actions": ["create symbol"],
"disable": ["copy", "remove"]
}
}
},
{
"icon": "form",
"name": {
Expand Down Expand Up @@ -9613,7 +9720,7 @@
"required": true,
"readOnly": false,
"disabled": false,
"onChange": "this.delProp('data')",
"onChange": "function () { this.delProp('data') } ",
"cols": 12,
"widget": {
"component": "CodeConfigurator",
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-cli/template/designer/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { HttpService } from './src/composable'
export default {
root: {
id: 'engine.root',
metas: [HttpService, GenerateCodeService, GlobalService]
metas: [HttpService, GenerateCodeService, GlobalService] // GlobalService 依赖 HttpService,HttpService需要在前面处理
},
config: engineConfig,
layout: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<template>
<div v-if="visible" class="tiny-popup__wrapper">
<div class="tiny-sso__box">
<div class="tiny-sso__body">
<iframe :src="url" class="tiny-sso__body-iframe" frameBorder="0" scrolling="no"></iframe>
</div>
</div>
</div>
</template>

<script>
import { ref } from 'vue'
export default {
setup() {
const visible = ref(false)
const url = ref('')
const openLogin = (procession, newUrl) => {
visible.value = true
url.value = newUrl
return new Promise((resolve, reject) => {
procession.mePromise.resolve = resolve
procession.mePromise.reject = reject
})
}
const closeLogin = () => {
visible.value = false
}
return {
openLogin,
closeLogin,
visible,
url
}
}
}
</script>

<style scoped lang="less">
.tiny-popup__wrapper {
z-index: 9999;
background: rgba(0, 0, 0, 0.5);
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: auto;
margin: 0;
.tiny-sso__box {
position: absolute;
background: #fff;
border: 1px solid transparent;
box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.2);
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
.tiny-sso__body {
text-align: initial;
padding: 20px;
color: #5a5e66;
line-height: 32px;
font-size: 14px;
.tiny-sso__body-iframe {
width: 450px;
height: 450px;
overflow: hidden;
//兼容edge
@supports (-ms-ime-align: auto) {
height: 460px;
}
}
}
}
}
</style>
125 changes: 112 additions & 13 deletions packages/engine-cli/template/designer/src/composable/http/index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,135 @@
import { createApp } from 'vue'
import { HttpService } from '@opentiny/tiny-engine'
import { useBroadcastChannel } from '@vueuse/core'
import { constants } from '@opentiny/tiny-engine-utils'
import Login from './Login.vue'

const LOGIN_EXPIRED_CODE = 401
const { BROADCAST_CHANNEL } = constants

const { post: globalNotify } = useBroadcastChannel({ name: BROADCAST_CHANNEL.Notify })

const procession = {
promiseLogin: null,
mePromise: {}
}
let loginVM = null

const showError = (url, message) => {
globalNotify({
type: 'error',
title: '接口报错',
message: `报错接口: ${url} \n报错信息: ${message ?? ''}`
})
}

const preRequest = (config) => {
const isDevelopEnv = import.meta.env.MODE?.includes('dev')

if (isDevelopEnv && config.url.match(/\/generate\//)) {
config.baseURL = ''
}

const isVsCodeEnv = window.vscodeBridge

if (isVsCodeEnv) {
config.baseURL = ''
}

return config
}

const preResponse = (res) => {
if (res.data?.error) {
showError(res.config?.url, res?.data?.error?.message)

return Promise.reject(res.data.error)
}

return res.data?.data
}

const openLogin = () => {
if (!window.lowcode) {
const loginDom = document.createElement('div')
document.body.appendChild(loginDom)
loginVM = createApp(Login).mount(loginDom)

window.lowcode = {
platformCenter: {
Session: {
rebuiltCallback: function () {
loginVM.closeLogin()

procession.mePromise.resolve('login ok')
procession.promiseLogin = null
procession.mePromise = {}
}
}
}
}
}

return new Promise((resolve, reject) => {
if (!procession.promiseLogin) {
procession.promiseLogin = loginVM.openLogin(procession, '/api/rebuildSession')
procession.promiseLogin.then((response) => {
HttpService.apis.request(response.config).then(resolve, reject)
})
}
})
}

const errorResponse = (error) => {
return Promise.reject(error.message)
// 用户信息失效时,弹窗提示登录
const { response } = error

if (response?.status === LOGIN_EXPIRED_CODE) {
// vscode 插件环境弹出输入框提示登录
if (window.vscodeBridge) {
return Promise.resolve(true)
}

// 浏览器环境弹出小窗登录
if (response?.headers['x-login-url']) {
return openLogin()
}
}

showError(error.config?.url, error?.message)

return response?.data.error ? Promise.reject(response.data.error) : Promise.reject(error.message)
}

const getConfig = (env = import.meta.env) => {
const baseURL = env.VITE_ORIGIN
// 仅在本地开发时,启用 withCredentials
const dev = env.MODE?.includes('dev')
// 获取租户 id
const getTenant = () => new URLSearchParams(location.search).get('tenant')

return {
baseURL: env.VITE_ORIGIN,
baseURL,
withCredentials: dev,
headers: {
'x-lowcode-mode': env.MODE
...(dev && { 'x-lowcode-mode': 'develop' }),
'x-lowcode-org': getTenant()
}
}
}

const options = {
axiosConfig: getConfig(),
enableMock: false,
mockData: {},
interceptors: {
request: [preRequest],
response: [[preResponse, errorResponse]]
const customizeHttpService = () => {
const options = {
axiosConfig: getConfig(),
interceptors: {
request: [preRequest],
response: [[preResponse, errorResponse]]
}
}
}

HttpService.apis.setOptions(options)
HttpService.apis.setOptions(options)

return HttpService
}

export default HttpService
export default customizeHttpService()
Loading

0 comments on commit efd0123

Please sign in to comment.