微信小程序批量收集formid

首先我们封装成一个组件起来,收集用户每一次点击的formid

组件的wxml的部分

<!--components/formId/formId.wxml-->
<form report-submit="{{true}}" catchsubmit="submitFormId" class='form'>
    <button form-type="submit" class='form-btn'></button>
</form>

组件的wxss的部分

/* components/formId/formId.wxss */
/* 让button铺满整个屏幕 */
.form-btn{
	position:absolute;
	display: inline-block;
	top:0;
	left:0;
	right:0;
	bottom:0;
	opacity:0;
}

组件的js部分

// pages/com/conpant.js
// 后台的接口
import { saveMiniForm } from '../../api/publictool';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
  },

  /**
   * 组件的初始数据
   */
  data: {},

  /**
   * 组件的方法列表
   */
  methods: {
    // 发formid给后台
    submitFormId(e) {
      // 判断是不是在编辑器上
      if (e.detail.formId != 'formid the formId is a mock one') {
        saveMiniForm({uid:wx.getStorageSync('userinfo').uid,formid:e.detail.formId})
      }
    }
  }
})

//那么我们开始使用

这里的类名pr是相对定位position: relative这样的话点击自己处理的事件就不会触发到formid的事件;

<view>
    <formId></formId>
    <view bindtap="toChildPagex" form-type="submit" class="pr">点击不会触发Fromid事件</view>
</view>

猜你喜欢

转载自blog.csdn.net/Hgh_1997/article/details/97141572