Skip to content

Commit efd0123

Browse files
committed
fix: update cli template resolve preview error
1 parent 6110591 commit efd0123

File tree

6 files changed

+317
-24
lines changed

6 files changed

+317
-24
lines changed

packages/engine-cli/template/designer/package.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@
1111
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_THEME=light vite build --mode prod"
1212
},
1313
"dependencies": {
14-
"vue": "^3.4.21",
15-
"@opentiny/tiny-engine": "^2.0.0-alpha.5",
16-
"@opentiny/tiny-engine-theme-dark": "^2.0.0-alpha.5",
17-
"@opentiny/tiny-engine-theme-light": "^2.0.0-alpha.5",
14+
"@opentiny/tiny-engine": "^2.1.0",
15+
"@opentiny/tiny-engine-theme-dark": "^2.1.0",
16+
"@opentiny/tiny-engine-theme-light": "^2.1.0",
17+
"@opentiny/tiny-engine-utils": "^2.1.0",
1818
"@opentiny/vue": "~3.14.0",
19-
"@opentiny/vue-icon": "~3.14.0",
2019
"@opentiny/vue-design-smb": "~3.14.0",
20+
"@opentiny/vue-icon": "~3.14.0",
21+
"@opentiny/vue-locale": "~3.14.0",
2122
"@opentiny/vue-renderless": "~3.14.0",
22-
"@opentiny/vue-theme": "~3.14.0"
23+
"@opentiny/vue-theme": "~3.14.0",
24+
"@vueuse/core": "^9.6.0",
25+
"vue": "^3.4.21"
2326
},
2427
"devDependencies": {
25-
"@opentiny/tiny-engine-vite-config": "^2.0.0-alpha.5",
26-
"@opentiny/tiny-engine-mock": "^2.0.0-alpha.5",
28+
"@opentiny/tiny-engine-mock": "^2.1.0",
29+
"@opentiny/tiny-engine-vite-config": "^2.1.0",
2730
"@vitejs/plugin-vue": "^5.1.2",
2831
"cross-env": "^7.0.3",
2932
"concurrently": "^8.2.0",

packages/engine-cli/template/designer/public/mock/bundle.json

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4828,6 +4828,113 @@
48284828
}
48294829
}
48304830
},
4831+
{
4832+
"icon": "row",
4833+
"name": {
4834+
"zh_CN": "row"
4835+
},
4836+
"component": "TinyLayout",
4837+
"description": "定义 Layout 的行配置信息",
4838+
"docUrl": "",
4839+
"screenshot": "",
4840+
"tags": "",
4841+
"keywords": "",
4842+
"devMode": "proCode",
4843+
"npm": {
4844+
"package": "@opentiny/vue",
4845+
"exportName": "Layout",
4846+
"version": "3.14.0",
4847+
"destructuring": true,
4848+
"script": "https://unpkg.com/@opentiny/vue@~3.14/runtime/tiny-vue.mjs",
4849+
"css": "https://unpkg.com/@opentiny/vue-theme@~3.14/index.css"
4850+
},
4851+
"group": "component",
4852+
"priority": 5,
4853+
"schema": {
4854+
"properties": [
4855+
{
4856+
"label": {
4857+
"zh_CN": "基础信息"
4858+
},
4859+
"description": {
4860+
"zh_CN": "基础信息"
4861+
},
4862+
"content": [
4863+
{
4864+
"property": "cols",
4865+
"label": {
4866+
"text": {
4867+
"zh_CN": "总栅格数"
4868+
}
4869+
},
4870+
"cols": 12,
4871+
"widget": {
4872+
"component": "ButtonGroupConfigurator",
4873+
"props": {
4874+
"options": [
4875+
{
4876+
"label": "12",
4877+
"value": 12
4878+
},
4879+
{
4880+
"label": "24",
4881+
"value": 24
4882+
}
4883+
]
4884+
}
4885+
},
4886+
"description": {
4887+
"zh_CN": "选择总栅格数"
4888+
},
4889+
"labelPosition": "none"
4890+
},
4891+
{
4892+
"property": "tag",
4893+
"label": {
4894+
"text": {
4895+
"zh_CN": "layout渲染的标签"
4896+
}
4897+
},
4898+
"required": false,
4899+
"readOnly": false,
4900+
"disabled": false,
4901+
"cols": 12,
4902+
"widget": {
4903+
"component": "InputConfigurator",
4904+
"props": {}
4905+
},
4906+
"description": {
4907+
"zh_CN": "定义Layout元素渲染后的标签,默认为 div"
4908+
}
4909+
}
4910+
]
4911+
}
4912+
]
4913+
},
4914+
"configure": {
4915+
"loop": true,
4916+
"condition": true,
4917+
"styles": true,
4918+
"isContainer": true,
4919+
"isModal": false,
4920+
"nestingRule": {
4921+
"childWhitelist": ["TinyRow", "TinyCol"],
4922+
"parentWhitelist": "",
4923+
"descendantBlacklist": "",
4924+
"ancestorWhitelist": ""
4925+
},
4926+
"isNullNode": false,
4927+
"isLayout": false,
4928+
"rootSelector": "",
4929+
"shortcuts": {
4930+
"properties": ["disabled"]
4931+
},
4932+
"contextMenu": {
4933+
"actions": ["create symbol"],
4934+
"disable": ["copy", "remove"]
4935+
}
4936+
}
4937+
},
48314938
{
48324939
"icon": "form",
48334940
"name": {
@@ -9613,7 +9720,7 @@
96139720
"required": true,
96149721
"readOnly": false,
96159722
"disabled": false,
9616-
"onChange": "this.delProp('data')",
9723+
"onChange": "function () { this.delProp('data') } ",
96179724
"cols": 12,
96189725
"widget": {
96199726
"component": "CodeConfigurator",

packages/engine-cli/template/designer/registry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { HttpService } from './src/composable'
5050
export default {
5151
root: {
5252
id: 'engine.root',
53-
metas: [HttpService, GenerateCodeService, GlobalService]
53+
metas: [HttpService, GenerateCodeService, GlobalService] // GlobalService 依赖 HttpService,HttpService需要在前面处理
5454
},
5555
config: engineConfig,
5656
layout: {
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<template>
2+
<div v-if="visible" class="tiny-popup__wrapper">
3+
<div class="tiny-sso__box">
4+
<div class="tiny-sso__body">
5+
<iframe :src="url" class="tiny-sso__body-iframe" frameBorder="0" scrolling="no"></iframe>
6+
</div>
7+
</div>
8+
</div>
9+
</template>
10+
11+
<script>
12+
import { ref } from 'vue'
13+
14+
export default {
15+
setup() {
16+
const visible = ref(false)
17+
const url = ref('')
18+
19+
const openLogin = (procession, newUrl) => {
20+
visible.value = true
21+
url.value = newUrl
22+
23+
return new Promise((resolve, reject) => {
24+
procession.mePromise.resolve = resolve
25+
procession.mePromise.reject = reject
26+
})
27+
}
28+
29+
const closeLogin = () => {
30+
visible.value = false
31+
}
32+
33+
return {
34+
openLogin,
35+
closeLogin,
36+
visible,
37+
url
38+
}
39+
}
40+
}
41+
</script>
42+
43+
<style scoped lang="less">
44+
.tiny-popup__wrapper {
45+
z-index: 9999;
46+
background: rgba(0, 0, 0, 0.5);
47+
position: fixed;
48+
top: 0;
49+
right: 0;
50+
bottom: 0;
51+
left: 0;
52+
overflow: auto;
53+
margin: 0;
54+
55+
.tiny-sso__box {
56+
position: absolute;
57+
background: #fff;
58+
border: 1px solid transparent;
59+
box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.2);
60+
left: 50%;
61+
top: 50%;
62+
transform: translate(-50%, -50%);
63+
64+
.tiny-sso__body {
65+
text-align: initial;
66+
padding: 20px;
67+
color: #5a5e66;
68+
line-height: 32px;
69+
font-size: 14px;
70+
71+
.tiny-sso__body-iframe {
72+
width: 450px;
73+
height: 450px;
74+
overflow: hidden;
75+
//兼容edge
76+
@supports (-ms-ime-align: auto) {
77+
height: 460px;
78+
}
79+
}
80+
}
81+
}
82+
}
83+
</style>
Lines changed: 112 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,135 @@
1+
import { createApp } from 'vue'
12
import { HttpService } from '@opentiny/tiny-engine'
3+
import { useBroadcastChannel } from '@vueuse/core'
4+
import { constants } from '@opentiny/tiny-engine-utils'
5+
import Login from './Login.vue'
6+
7+
const LOGIN_EXPIRED_CODE = 401
8+
const { BROADCAST_CHANNEL } = constants
9+
10+
const { post: globalNotify } = useBroadcastChannel({ name: BROADCAST_CHANNEL.Notify })
11+
12+
const procession = {
13+
promiseLogin: null,
14+
mePromise: {}
15+
}
16+
let loginVM = null
17+
18+
const showError = (url, message) => {
19+
globalNotify({
20+
type: 'error',
21+
title: '接口报错',
22+
message: `报错接口: ${url} \n报错信息: ${message ?? ''}`
23+
})
24+
}
225

326
const preRequest = (config) => {
27+
const isDevelopEnv = import.meta.env.MODE?.includes('dev')
28+
29+
if (isDevelopEnv && config.url.match(/\/generate\//)) {
30+
config.baseURL = ''
31+
}
32+
33+
const isVsCodeEnv = window.vscodeBridge
34+
35+
if (isVsCodeEnv) {
36+
config.baseURL = ''
37+
}
38+
439
return config
540
}
641

742
const preResponse = (res) => {
43+
if (res.data?.error) {
44+
showError(res.config?.url, res?.data?.error?.message)
45+
46+
return Promise.reject(res.data.error)
47+
}
48+
849
return res.data?.data
950
}
1051

52+
const openLogin = () => {
53+
if (!window.lowcode) {
54+
const loginDom = document.createElement('div')
55+
document.body.appendChild(loginDom)
56+
loginVM = createApp(Login).mount(loginDom)
57+
58+
window.lowcode = {
59+
platformCenter: {
60+
Session: {
61+
rebuiltCallback: function () {
62+
loginVM.closeLogin()
63+
64+
procession.mePromise.resolve('login ok')
65+
procession.promiseLogin = null
66+
procession.mePromise = {}
67+
}
68+
}
69+
}
70+
}
71+
}
72+
73+
return new Promise((resolve, reject) => {
74+
if (!procession.promiseLogin) {
75+
procession.promiseLogin = loginVM.openLogin(procession, '/api/rebuildSession')
76+
procession.promiseLogin.then((response) => {
77+
HttpService.apis.request(response.config).then(resolve, reject)
78+
})
79+
}
80+
})
81+
}
82+
1183
const errorResponse = (error) => {
12-
return Promise.reject(error.message)
84+
// 用户信息失效时,弹窗提示登录
85+
const { response } = error
86+
87+
if (response?.status === LOGIN_EXPIRED_CODE) {
88+
// vscode 插件环境弹出输入框提示登录
89+
if (window.vscodeBridge) {
90+
return Promise.resolve(true)
91+
}
92+
93+
// 浏览器环境弹出小窗登录
94+
if (response?.headers['x-login-url']) {
95+
return openLogin()
96+
}
97+
}
98+
99+
showError(error.config?.url, error?.message)
100+
101+
return response?.data.error ? Promise.reject(response.data.error) : Promise.reject(error.message)
13102
}
14103

15104
const getConfig = (env = import.meta.env) => {
105+
const baseURL = env.VITE_ORIGIN
106+
// 仅在本地开发时,启用 withCredentials
107+
const dev = env.MODE?.includes('dev')
108+
// 获取租户 id
109+
const getTenant = () => new URLSearchParams(location.search).get('tenant')
110+
16111
return {
17-
baseURL: env.VITE_ORIGIN,
112+
baseURL,
113+
withCredentials: dev,
18114
headers: {
19-
'x-lowcode-mode': env.MODE
115+
...(dev && { 'x-lowcode-mode': 'develop' }),
116+
'x-lowcode-org': getTenant()
20117
}
21118
}
22119
}
23120

24-
const options = {
25-
axiosConfig: getConfig(),
26-
enableMock: false,
27-
mockData: {},
28-
interceptors: {
29-
request: [preRequest],
30-
response: [[preResponse, errorResponse]]
121+
const customizeHttpService = () => {
122+
const options = {
123+
axiosConfig: getConfig(),
124+
interceptors: {
125+
request: [preRequest],
126+
response: [[preResponse, errorResponse]]
127+
}
31128
}
32-
}
33129

34-
HttpService.apis.setOptions(options)
130+
HttpService.apis.setOptions(options)
131+
132+
return HttpService
133+
}
35134

36-
export default HttpService
135+
export default customizeHttpService()

0 commit comments

Comments
 (0)