mini-form-render 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,135 +1,140 @@
1
- <template>
2
- <view class="mini-form-container">
3
- <view wx:for="{{scheme.properties}}" wx:key="key">
4
- <view class="mini-form-item {{index !== scheme.properties.length - 1 ? 'retina-border-bottom' : ''}}">
5
- <basic-picker wx:if="{{item.widget === 'picker'}}" item="{{item}}" wx:model="{{formRes[item.key]}}"/>
6
- <basic-input wx:else item="{{item}}" wx:model="{{formRes[item.key]}}"/>
7
- </view>
8
- </view>
9
- <!--<button bindtap="handleTap">提交</button>-->
10
- </view>
11
- </template>
12
-
13
- <script>
14
- import { toPureObject, createComponent } from '@mpxjs/core'
15
-
16
- createComponent({
17
- props: {
18
- scheme: {
19
- type: Object
20
- }
21
- },
22
- data: {
23
- formRes: {}
24
- },
25
- methods: {
26
- parseScheme(scheme) {
27
- this.formRes = {}
28
- const properties = scheme.properties || []
29
- properties.forEach(item => {
30
- const key = item.key
31
- this.$set(this.formRes, key)
32
- })
33
- }
34
- // handleTap() {
35
- // console.log('formRes', this.formRes)
36
- // }
37
- },
38
- watch: {
39
- scheme: {
40
- handler(scheme) {
41
- this.parseScheme(scheme)
42
- },
43
- immediate: true
44
- },
45
- formRes: {
46
- handler(newVal) {
47
- const formResult = toPureObject(newVal)
48
- // console.log('trigger form change event:', formResult)
49
- this.triggerEvent('formchange', formResult)
50
- },
51
- deep: true
52
- }
53
- }
54
- })
55
- </script>
56
-
57
- <style lang="stylus">
58
- .mini-form-container
59
- .mini-form-item
60
- padding 24rpx 0
61
-
62
- .form-item-title
63
- font-size 30rpx
64
- width 200rpx
65
- color #333
66
-
67
- // 边框默认颜色
68
- $defaultBorderColor = rgba(0, 0, 0, 0.18)
69
-
70
- // retina 边框函数基础声明,不包含 border 部分,主要用于在 retina-border 函数里继承
71
- .retina-border-basic
72
- position: relative
73
- &::before
74
- content: ''
75
- position: absolute
76
- width: 100%
77
- height: 100%
78
- top: 0
79
- left:0
80
- transform-origin: left top
81
- box-sizing: border-box
82
- pointer-events: none
83
- @media
84
- (-webkit-min-device-pixel-ratio 2),
85
- (min-resolution 2dppx)
86
- &::before
87
- width: 200%
88
- height: 200%
89
- transform: scale(.5)
90
- @media
91
- (-webkit-min-device-pixel-ratio 3),
92
- (min-resolution 3dppx)
93
- &::before
94
- width: 300%
95
- height: 300%
96
- transform: scale(1 / 3)
97
-
98
- // 设置圆角(如果圆角大于0,则添加圆角的代码)
99
- retina-border-radius(borderRadius)
100
- if unit(borderRadius, px) > 0
101
- border-radius: borderRadius
102
- @media
103
- (-webkit-min-device-pixel-ratio 2),
104
- (min-resolution 2dppx)
105
- &::before
106
- border-radius: unit(borderRadius, px) * 2
107
- @media
108
- (-webkit-min-device-pixel-ratio 3),
109
- (min-resolution 3dppx)
110
- &::before
111
- border-radius: unit(borderRadius, px) * 3
112
-
113
- // retina 边框函数声明
114
- retina-border(borderWidth = 1px, borderStyle = solid, borderColor = $defaultBorderColor, borderRadius = 0)
115
- @extends .retina-border-basic
116
- retina-border-radius(borderRadius)
117
- &::before
118
- border-width: borderWidth
119
- border-style: borderStyle
120
- border-color: borderColor
121
-
122
- // 下边框
123
- .retina-border-bottom
124
- retina-border(0 0 1px)
125
- </style>
126
-
127
- <script type="application/json">
128
- {
129
- "component": true,
130
- "usingComponents": {
131
- "basic-input": "./basic-input",
132
- "basic-picker": "./basic-picker"
133
- }
134
- }
135
- </script>
1
+ <template>
2
+ <view class="mini-form-container">
3
+ <view wx:for="{{scheme.properties}}" wx:key="key">
4
+ <view class="mini-form-item {{index !== scheme.properties.length - 1 ? 'retina-border-bottom' : ''}}">
5
+ <basic-picker wx:if="{{item.widget === 'picker'}}" item="{{item}}" wx:model="{{formRes[item.key]}}"/>
6
+ <basic-input wx:else item="{{item}}" wx:model="{{formRes[item.key]}}"/>
7
+ </view>
8
+ </view>
9
+ <!--<button bindtap="handleTap">提交</button>-->
10
+ </view>
11
+ </template>
12
+
13
+ <script>
14
+ import { toPureObject, createComponent } from '@mpxjs/core'
15
+
16
+ createComponent({
17
+ props: {
18
+ scheme: {
19
+ type: Object
20
+ }
21
+ },
22
+ data: {
23
+ formRes: {}
24
+ },
25
+ methods: {
26
+ parseScheme(scheme) {
27
+ const oldFormRes = this.formRes
28
+ this.formRes = {}
29
+ const properties = scheme.properties || []
30
+ properties.forEach(item => {
31
+ const key = item.key
32
+ this.$set(this.formRes, key, oldFormRes[key])
33
+ })
34
+ }
35
+ // handleTap() {
36
+ // console.log('formRes', this.formRes)
37
+ // }
38
+ },
39
+ watch: {
40
+ scheme: {
41
+ handler(scheme) {
42
+ this.parseScheme(scheme)
43
+ },
44
+ immediate: true
45
+ },
46
+ formRes: {
47
+ handler(newVal) {
48
+ const formResult = toPureObject(newVal)
49
+ // console.log('trigger form change event:', formResult)
50
+ this.triggerEvent('formchange', formResult)
51
+ },
52
+ deep: true
53
+ }
54
+ }
55
+ })
56
+ </script>
57
+
58
+ <style lang="stylus">
59
+ .mini-form-container
60
+ .mini-form-item
61
+ padding 24rpx 0
62
+
63
+ .form-item-title
64
+ font-size 30rpx
65
+ width 200rpx
66
+ color #333
67
+
68
+ @media(prefers-color-scheme: dark)
69
+ .form-item-title
70
+ color hsla(0, 0%, 100%, .8)
71
+
72
+ // 边框默认颜色
73
+ $defaultBorderColor = rgba(0, 0, 0, 0.18)
74
+
75
+ // retina 边框函数基础声明,不包含 border 部分,主要用于在 retina-border 函数里继承
76
+ .retina-border-basic
77
+ position: relative
78
+ &::before
79
+ content: ''
80
+ position: absolute
81
+ width: 100%
82
+ height: 100%
83
+ top: 0
84
+ left:0
85
+ transform-origin: left top
86
+ box-sizing: border-box
87
+ pointer-events: none
88
+ @media
89
+ (-webkit-min-device-pixel-ratio 2),
90
+ (min-resolution 2dppx)
91
+ &::before
92
+ width: 200%
93
+ height: 200%
94
+ transform: scale(.5)
95
+ @media
96
+ (-webkit-min-device-pixel-ratio 3),
97
+ (min-resolution 3dppx)
98
+ &::before
99
+ width: 300%
100
+ height: 300%
101
+ transform: scale(1 / 3)
102
+
103
+ // 设置圆角(如果圆角大于0,则添加圆角的代码)
104
+ retina-border-radius(borderRadius)
105
+ if unit(borderRadius, px) > 0
106
+ border-radius: borderRadius
107
+ @media
108
+ (-webkit-min-device-pixel-ratio 2),
109
+ (min-resolution 2dppx)
110
+ &::before
111
+ border-radius: unit(borderRadius, px) * 2
112
+ @media
113
+ (-webkit-min-device-pixel-ratio 3),
114
+ (min-resolution 3dppx)
115
+ &::before
116
+ border-radius: unit(borderRadius, px) * 3
117
+
118
+ // retina 边框函数声明
119
+ retina-border(borderWidth = 1px, borderStyle = solid, borderColor = $defaultBorderColor, borderRadius = 0)
120
+ @extends .retina-border-basic
121
+ retina-border-radius(borderRadius)
122
+ &::before
123
+ border-width: borderWidth
124
+ border-style: borderStyle
125
+ border-color: borderColor
126
+
127
+ // 下边框
128
+ .retina-border-bottom
129
+ retina-border(0 0 1px)
130
+ </style>
131
+
132
+ <script type="application/json">
133
+ {
134
+ "component": true,
135
+ "usingComponents": {
136
+ "basic-input": "./basic-input",
137
+ "basic-picker": "./basic-picker"
138
+ }
139
+ }
140
+ </script>
@@ -1,47 +1,47 @@
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">本地scheme渲染表单测试</view>
7
- <form-render class="form-render-container" scheme="{{formScheme}}" />
8
- </view>
9
- </view>
10
- </template>
11
-
12
- <script>
13
- import { createPage } from '@mpxjs/core'
14
- import formScheme from '../test/scheme1'
15
-
16
- createPage({
17
- data: {
18
- formScheme
19
- },
20
- onLoad() {
21
- console.log('onLoad')
22
- }
23
- })
24
- </script>
25
-
26
- <style lang="stylus">
27
- page
28
- background-color #f5f5f5
29
-
30
- .form-demo-container
31
- background #fff
32
- margin 24rpx
33
- border-radius 16rpx
34
- padding 24rpx
35
-
36
- .form-render-container {
37
- margin-top 24rpx
38
- }
39
- </style>
40
-
41
- <script type="application/json">
42
- {
43
- "usingComponents": {
44
- "form-render": "../components/form"
45
- }
46
- }
47
- </script>
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">本地scheme渲染表单测试</view>
7
+ <form-render class="form-render-container" scheme="{{formScheme}}" />
8
+ </view>
9
+ </view>
10
+ </template>
11
+
12
+ <script>
13
+ import { createPage } from '@mpxjs/core'
14
+ import formScheme from '../test/scheme1'
15
+
16
+ createPage({
17
+ data: {
18
+ formScheme
19
+ },
20
+ onLoad() {
21
+ console.log('onLoad')
22
+ }
23
+ })
24
+ </script>
25
+
26
+ <style lang="stylus">
27
+ page
28
+ background-color #f5f5f5
29
+
30
+ .form-demo-container
31
+ background #fff
32
+ margin 24rpx
33
+ border-radius 16rpx
34
+ padding 24rpx
35
+
36
+ .form-render-container {
37
+ margin-top 24rpx
38
+ }
39
+ </style>
40
+
41
+ <script type="application/json">
42
+ {
43
+ "usingComponents": {
44
+ "form-render": "../components/form"
45
+ }
46
+ }
47
+ </script>
@@ -1,48 +1,51 @@
1
- <template>
2
- <view class="form-demo-index">
3
- <view style="content: ''; overflow: hidden;"></view>
4
-
5
- <view class="demo-index">
6
- <view bindtap="handleJump('render')">跳转去本地表单渲染测试页</view>
7
- <view bindtap="handleJump('server')">跳转去服务端协议渲染测试</view>
8
- </view>
9
- </view>
10
- </template>
11
-
12
- <script>
13
- import mpx, { createPage } from '@mpxjs/core'
14
-
15
- createPage({
16
- onLoad() {
17
- console.log('onLoad')
18
- },
19
- methods: {
20
- handleJump(action) {
21
- if (action === 'render') {
22
- mpx.navigateTo({ url: '/pages/form-render' })
23
- } else if (action === 'server') {
24
- mpx.navigateTo({ url: '/pages/server-scheme' })
25
- }
26
- }
27
- }
28
- })
29
- </script>
30
-
31
- <style lang="stylus">
32
- page {
33
- background-color: #f5f5f5;
34
- }
35
-
36
- .form-container {
37
- background: #fff;
38
- margin: 24rpx;
39
- border-radius: 16rpx;
40
- padding: 24rpx;
41
- }
42
- </style>
43
-
44
- <script type="application/json">
45
- {
46
- "usingComponents": {}
47
- }
48
- </script>
1
+ <template>
2
+ <view class="form-demo-index">
3
+ <view style="content: ''; overflow: hidden;"></view>
4
+
5
+ <view class="demo-index">
6
+ <view bindtap="handleJump('render')">跳转去本地表单渲染测试页</view>
7
+ <view bindtap="handleJump('logic')">跳转去本地逻辑渲染测试页</view>
8
+ <view bindtap="handleJump('server')">跳转去服务端协议渲染测试</view>
9
+ </view>
10
+ </view>
11
+ </template>
12
+
13
+ <script>
14
+ import mpx, { createPage } from '@mpxjs/core'
15
+
16
+ createPage({
17
+ onLoad() {
18
+ console.log('onLoad')
19
+ },
20
+ methods: {
21
+ handleJump(action) {
22
+ if (action === 'render') {
23
+ mpx.navigateTo({ url: '/pages/form-render' })
24
+ } else if (action === 'logic') {
25
+ mpx.navigateTo({ url: '/pages/js-logic-render' })
26
+ } else if (action === 'server') {
27
+ mpx.navigateTo({ url: '/pages/server-scheme' })
28
+ }
29
+ }
30
+ }
31
+ })
32
+ </script>
33
+
34
+ <style lang="stylus">
35
+ page {
36
+ background-color: #f5f5f5;
37
+ }
38
+
39
+ .form-container {
40
+ background: #fff;
41
+ margin: 24rpx;
42
+ border-radius: 16rpx;
43
+ padding: 24rpx;
44
+ }
45
+ </style>
46
+
47
+ <script type="application/json">
48
+ {
49
+ "usingComponents": {}
50
+ }
51
+ </script>
@@ -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>