123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- // index.js
- // 获取应用实例
- const app = getApp()
- const formLayout = {
- fieldId: '101', //对应一级表单层级
- fieldName: '基本信息',
- formInfo: [ //每个层级下面 具体表单元素
- {
- label: '名字',//标题
- type: 'text', //表单类型 text,upload,picker,time
- id: 'input-name-form', //表单id
- placeholder: '输入您的姓名',//设置文本框默认提示
- data: [], //填充表单的数据 例如下拉框
- role: {
- type: 'reg',
- value: '',//正则表达式
- },
- force: true,//是否必输入
- },
- {
- label: '手机号',//标题
- type: 'text', //表单类型 text,upload,picker,time
- id: 'input-id-form', //表单id
- placeholder: '输入您的手机号',//设置文本框默认提示
- data: [], //填充表单的数据 例如下拉框
- role: {
- type: 'reg',
- formatter:(v)=>{
- let reg = /^1[3-9]\d{9}$/
- if (!reg.test(v)) return '手机号输入有误'
- return ''
- }
- },
- force: true,//是否必输入
- },
- {
- label: '性别',//标题
- type: 'picker', //表单类型 text,upload,picker,time
- id: 'input-sex-form', //表单id
- inputValue:'男',
- placeholder: '输入您的姓名',//设置文本框默认提示
- data: [
- { value: 1, label: '男' },
- { value: 2, label: '女' },
- ], //填充表单的数据 例如下拉框
- role: {
- type: 'reg',
- value: '',//正则表达式
- },
- force: false,//是否必输入
- },
- {
- label: '上传',//标题
- type: 'upload', //表单类型 text,upload,picker,time
- id: 'input-sex-form', //表单id
- inputValue:'男',
- placeholder: '输入您的姓名',//设置文本框默认提示
- data: [
- { value: 1, label: '男' },
- { value: 2, label: '女' },
- ], //填充表单的数据 例如下拉框
- role: {
- type: 'reg',
- value: '',//正则表达式
- },
- force: false,//是否必输入
- },
- {
- label: '选择日期',//标题
- type: 'datepicker', //表单类型 text,upload,picker,time
- id: 'input-sex-form', //表单id
- inputValue:(new Date()).toISOString().split('T')[0],
- placeholder: '选择日期',//设置文本框默认提示
- role: {
- type: 'reg',
- value: '',//正则表达式
- },
- force: false,//是否必输入
- },
- ]
- }
- Page({
- data: {
- motto: 'Hello World',
- userInfo: {},
- hasUserInfo: false,
- canIUse: wx.canIUse('button.open-type.getUserInfo'),
- canIUseGetUserProfile: false,
- canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'), // 如需尝试获取用户信息可改为false
- formLayout
- },
- // 事件处理函数
- bindViewTap() {
- wx.navigateTo({
- url: '../logs/logs'
- })
- },
- onLoad() {
- if (wx.getUserProfile) {
- this.setData({
- canIUseGetUserProfile: true
- })
- }
- },
- getUserProfile(e) {
- // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
- wx.getUserProfile({
- desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
- success: (res) => {
- console.log(res)
- this.setData({
- userInfo: res.userInfo,
- hasUserInfo: true
- })
- }
- })
- },
- getUserInfo(e) {
- // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
- console.log(e)
- this.setData({
- userInfo: e.detail.userInfo,
- hasUserInfo: true
- })
- }
- })
|