mini-form-render 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini-form-render",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "mpx-cli-service serve:mp",
package/src/app.mpx CHANGED
@@ -20,6 +20,7 @@ createApp({
20
20
  "pages": [
21
21
  "./pages/index",
22
22
  "./pages/form-render",
23
+ "./pages/js-logic-render",
23
24
  "./pages/server-scheme"
24
25
  ]
25
26
  }
@@ -1,12 +1,16 @@
1
1
  <template>
2
2
  <view class="basic-picker">
3
3
  <view class="^form-item-title">{{item.title}}</view>
4
- <picker wx:model="{{resultIndex}}" wx:model-event="change" range="{{item.customData.pickerArr}}">
4
+ <picker
5
+ wx:model="{{resultIndex}}"
6
+ wx:model-event="change"
7
+ range="{{item.customData.pickerArr}}"
8
+ >
5
9
  <view class="picker-box">
6
10
  <view class="picker-show-title">
7
11
  {{item.customData.pickerArr[resultIndex]}}
8
12
  </view>
9
- <image class="picker-title-arrow" src="../image/caret-right.svg" mode="widthFix"></image>
13
+ <image class="picker-title-arrow" src="https://aipaint.lihuanyu.com/common/caret-right.svg" mode="widthFix"></image>
10
14
  </view>
11
15
  </picker>
12
16
  </view>
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <view class="mini-form-container">
3
- <view wx:for="{{scheme.properties}}">
3
+ <view wx:for="{{scheme.properties}}" wx:key="key">
4
4
  <view class="mini-form-item {{index !== scheme.properties.length - 1 ? 'retina-border-bottom' : ''}}">
5
5
  <basic-picker wx:if="{{item.widget === 'picker'}}" item="{{item}}" wx:model="{{formRes[item.key]}}"/>
6
6
  <basic-input wx:else item="{{item}}" wx:model="{{formRes[item.key]}}"/>
@@ -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() {
@@ -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