mini-form-render 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/app.mpx +1 -0
- package/src/components/form.mpx +2 -1
- package/src/pages/index.mpx +3 -0
- package/src/pages/js-logic-render.mpx +59 -0
- package/src/test/paint-form.js +43 -0
package/package.json
CHANGED
package/src/app.mpx
CHANGED
package/src/components/form.mpx
CHANGED
@@ -24,11 +24,12 @@ createComponent({
|
|
24
24
|
},
|
25
25
|
methods: {
|
26
26
|
parseScheme(scheme) {
|
27
|
+
const oldFormRes = this.formRes
|
27
28
|
this.formRes = {}
|
28
29
|
const properties = scheme.properties || []
|
29
30
|
properties.forEach(item => {
|
30
31
|
const key = item.key
|
31
|
-
this.$set(this.formRes, key)
|
32
|
+
this.$set(this.formRes, key, oldFormRes[key])
|
32
33
|
})
|
33
34
|
}
|
34
35
|
// handleTap() {
|
package/src/pages/index.mpx
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
<view class="demo-index">
|
6
6
|
<view bindtap="handleJump('render')">跳转去本地表单渲染测试页</view>
|
7
|
+
<view bindtap="handleJump('logic')">跳转去本地逻辑渲染测试页</view>
|
7
8
|
<view bindtap="handleJump('server')">跳转去服务端协议渲染测试</view>
|
8
9
|
</view>
|
9
10
|
</view>
|
@@ -20,6 +21,8 @@ createPage({
|
|
20
21
|
handleJump(action) {
|
21
22
|
if (action === 'render') {
|
22
23
|
mpx.navigateTo({ url: '/pages/form-render' })
|
24
|
+
} else if (action === 'logic') {
|
25
|
+
mpx.navigateTo({ url: '/pages/js-logic-render' })
|
23
26
|
} else if (action === 'server') {
|
24
27
|
mpx.navigateTo({ url: '/pages/server-scheme' })
|
25
28
|
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
<template>
|
2
|
+
<view class="form-demo-page">
|
3
|
+
<view style="content: ''; overflow: hidden;"></view>
|
4
|
+
|
5
|
+
<view class="form-demo-container">
|
6
|
+
<view class="form-title">JS逻辑控制scheme渲染表单测试</view>
|
7
|
+
<mini-form-render
|
8
|
+
class="form-render-container"
|
9
|
+
scheme="{{formScheme}}"
|
10
|
+
bindformchange="handleFormChange"
|
11
|
+
/>
|
12
|
+
</view>
|
13
|
+
</view>
|
14
|
+
</template>
|
15
|
+
|
16
|
+
<script>
|
17
|
+
import { createPage } from '@mpxjs/core'
|
18
|
+
import getFormScheme from '../test/paint-form'
|
19
|
+
|
20
|
+
createPage({
|
21
|
+
data: {
|
22
|
+
formScheme: getFormScheme({})
|
23
|
+
},
|
24
|
+
onLoad() {
|
25
|
+
console.log('onLoad')
|
26
|
+
},
|
27
|
+
methods: {
|
28
|
+
handleFormChange(e) {
|
29
|
+
const formResult = e.detail
|
30
|
+
console.log('form changed: ', formResult)
|
31
|
+
this.formScheme = getFormScheme(formResult)
|
32
|
+
this.formResult = formResult
|
33
|
+
}
|
34
|
+
}
|
35
|
+
})
|
36
|
+
</script>
|
37
|
+
|
38
|
+
<style lang="stylus">
|
39
|
+
page
|
40
|
+
background-color #f5f5f5
|
41
|
+
|
42
|
+
.form-demo-container
|
43
|
+
background #fff
|
44
|
+
margin 24rpx
|
45
|
+
border-radius 16rpx
|
46
|
+
padding 24rpx
|
47
|
+
|
48
|
+
.form-render-container {
|
49
|
+
margin-top 24rpx
|
50
|
+
}
|
51
|
+
</style>
|
52
|
+
|
53
|
+
<script type="application/json">
|
54
|
+
{
|
55
|
+
"usingComponents": {
|
56
|
+
"mini-form-render": "../components/form"
|
57
|
+
}
|
58
|
+
}
|
59
|
+
</script>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
const getFormScheme = (formRes) => {
|
2
|
+
const baseScheme = {
|
3
|
+
properties: [model]
|
4
|
+
}
|
5
|
+
|
6
|
+
baseScheme.properties.push(formRes.model !== '二次元' ? templateDream : templateAnything)
|
7
|
+
|
8
|
+
const formScheme = baseScheme
|
9
|
+
|
10
|
+
return formScheme
|
11
|
+
}
|
12
|
+
|
13
|
+
const model = {
|
14
|
+
key: 'model',
|
15
|
+
type: 'string',
|
16
|
+
title: '模型选择',
|
17
|
+
widget: 'picker',
|
18
|
+
customData: {
|
19
|
+
pickerArr: ['绘梦', '二次元']
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
const templateDream = {
|
24
|
+
key: 'template',
|
25
|
+
type: 'string',
|
26
|
+
title: '模板选择',
|
27
|
+
widget: 'picker',
|
28
|
+
customData: {
|
29
|
+
pickerArr: ['油画', '风景', '水彩']
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
const templateAnything = {
|
34
|
+
key: 'template',
|
35
|
+
type: 'string',
|
36
|
+
title: '模板选择',
|
37
|
+
widget: 'picker',
|
38
|
+
customData: {
|
39
|
+
pickerArr: ['幻想', '动漫']
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
export default getFormScheme
|