Skip to content

Commit

Permalink
feat: 标题优化,读配置,更新配置接口逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-zuo committed Mar 16, 2024
1 parent 240d5fc commit a5d1dba
Show file tree
Hide file tree
Showing 6 changed files with 16,012 additions and 15,391 deletions.
3 changes: 2 additions & 1 deletion formily/antd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"@designable/core": "1.0.0-beta.45",
"@designable/formily-setters": "1.0.0-beta.45",
"@designable/formily-transformer": "1.0.0-beta.45",
"@designable/react": "1.0.0-beta.45"
"@designable/react": "1.0.0-beta.45",
"axios": "^1.6.7"
},
"publishConfig": {
"access": "public"
Expand Down
65 changes: 53 additions & 12 deletions formily/antd/playground/service/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,70 @@ import {
transformToTreeNode,
} from '@designable/formily-transformer'
import { message } from 'antd'
import axios from 'axios'

export const saveSchema = (designer: Engine) => {
const isProduction = process.env.NODE_ENV === 'production'

const BASE_URL = isProduction
? 'https://api.formily.top'
: 'http://127.0.0.1:5000'
export const saveSchema = async (designer: Engine, isPublish: boolean) => {
let queryParams = Object.fromEntries(new URLSearchParams(location.search))
let { bid } = queryParams
if (!bid) {
message.warning('url 异常,缺少 id 参数')
return
}
let formilySchema = JSON.stringify(
let formilySchemaConfig = JSON.stringify(
transformToSchema(designer.getCurrentTree())
)
console.log('formily-schema', formilySchema)
localStorage.setItem(
'formily-schema',
JSON.stringify(transformToSchema(designer.getCurrentTree()))
)
console.log('formily-schema', bid, formilySchemaConfig)

try {
const res = await axios.post(`${BASE_URL}/configList/update`, {
bid,
config: formilySchemaConfig,
})
console.log('res', res)
} catch (e) {
console.log(e)
} finally {
// loading = false
}

// if (isPublish) {
// // 发布版本
// } else {
// // 保存到当前版本

// }
// localStorage.setItem(
// 'formily-schema',
// JSON.stringify(transformToSchema(designer.getCurrentTree()))
// )
message.success('Save Success')
}

export const loadInitialSchema = (designer: Engine) => {
// 初始化低代码内容
export const loadInitialSchema = async (designer: Engine) => {
const params = Object.fromEntries(new URLSearchParams(window.location.search))
const { bid } = params
if (!bid) {
return
}
try {
designer.setCurrentTree(
transformToTreeNode(JSON.parse(localStorage.getItem('formily-schema')))
)
} catch {}
const res = await axios.get(`${BASE_URL}/configList/detail/${bid}`)
console.log('res /configList/detail/', res)
if (res.data.code === 0) {
let schemaConfig = res?.data?.data?.config
designer.setCurrentTree(transformToTreeNode(JSON.parse(schemaConfig)))
// localStorage.getItem('formily-schema')
} else {
message.warning(res?.data?.msg || '获取配置异常')
}
} catch (e) {
console.log(e)
} finally {
// loading = false
}
}
10 changes: 5 additions & 5 deletions formily/antd/playground/widgets/ActionsWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react'
import { Space, Button, Radio } from 'antd'
import { GithubOutlined } from '@ant-design/icons'
// import { GithubOutlined } from '@ant-design/icons'
import { useDesigner, TextWidget } from '@designable/react'
import { GlobalRegistry } from '@designable/core'
import { observer } from '@formily/react'
Expand Down Expand Up @@ -38,17 +38,17 @@ export const ActionsWidget = observer(() => {
<GithubOutlined />
Github
</Button> */}
<Button
{/* <Button
onClick={() => {
saveSchema(designer)
saveSchema(designer, false)
}}
>
<TextWidget>Save</TextWidget>
</Button>
</Button> */}
<Button
type="primary"
onClick={() => {
saveSchema(designer)
saveSchema(designer, true)
}}
>
<TextWidget>Publish</TextWidget>
Expand Down
14 changes: 9 additions & 5 deletions formily/antd/playground/widgets/LogoWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ const logo = {
}

export const LogoWidget: React.FC = () => {
const url = logo[useTheme()]
const url = 'http://cdn.zuo11.com/imgs/avatar.jpg'
// logo[useTheme()]
return (
<div style={{ display: 'flex', alignItems: 'center', fontSize: 14 }}>
<img
src={url}
style={{ margin: '12px 8px', height: 18, width: 'auto' }}
/>
<div>
<img
src={url}
style={{ margin: '12px 8px', height: 18, width: 'auto' }}
/>
Formily 低代码设计器
</div>
</div>
)
}
2 changes: 2 additions & 0 deletions packages/react/src/panels/StudioPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ const StudioPanelInternal: React.FC<IStudioPanelProps> = ({
const prefix = usePrefix('main-panel')
const position = usePosition()
const classNameBase = cls('root', position, props.className)
const params = Object.fromEntries(new URLSearchParams(location.search))
if (logo || actions) {
return (
<div {...props} className={cls(`${prefix}-container`, classNameBase)}>
<div className={prefix + '-header'}>
<div className={prefix + '-header-logo'}>{logo}</div>
<div>{params.name}</div>
<div className={prefix + '-header-actions'}>{actions}</div>
</div>
<div className={prefix}>{props.children}</div>
Expand Down
Loading

0 comments on commit a5d1dba

Please sign in to comment.