├── effect.png ├── README.md └── components └── modal-view ├── modal-view.wxml ├── modal-view.wxss └── modal-view.js /effect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iRobin520/WeApp-ModalView/HEAD/effect.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WeApp-ModalView 2 | 微信小程序自定义模态弹窗,完全根据传入的数据值动态生成各种类型的组件, 无需修改任何模版或样式的的代码,只需添加相应的js字段即可。 3 | 4 | 先上效果图: 5 | ![image](https://github.com/iRobin520/WeApp-ModalView/raw/master/effect.png) 6 | 7 | 示列代码:
8 | 在wxml文件中加入代码:
9 | < import src="../../../../components/modal-view/modal-view.wxml" / >
10 | < template is="modalView" data="{{ ...__modalView__ }}" / >
11 | 12 | 在js文件中加入代码:
13 | import { ModalView } from '../../../../components/modal-view/modal-view' 14 | 15 | 在onLoad事件中加入: 16 | new ModalView 17 | 18 | 在你自己定义的事件中加入:
19 | this.modalView.showModal({
20 |   title: '申请退货',
21 |   confirmation: true,
22 |   confirmationText: '确定要申请退货吗?',
23 |   inputFields: [{
24 |    fieldName: 'reason',
25 |    fieldType: 'Picker',
26 |    fieldPlaceHolder: '选择退货原因',
27 |    fieldDatasource: reasons,
28 |    isRequired: true,
29 |   },
30 |   {
31 |    fieldName: 'test',
32 |    fieldType: 'Text',
33 |    fieldPlaceHolder: '请填写测试信息',
34 |    isRequired: false,
35 |   },
36 |   {
37 |    fieldName: 'descriptions',
38 |    fieldType: 'Textarea',
39 |    fieldPlaceHolder: '请填写退货描述',
40 |    isRequired: false,
41 |   }],
42 |   confirm: function (res) {
43 |    console.log(res)
44 |    //用户按确定按钮以后会回到这里,并且对输入的表单数据会带回
45 |   }
46 | })
47 | -------------------------------------------------------------------------------- /components/modal-view/modal-view.wxml: -------------------------------------------------------------------------------- 1 |