UNPKG

bmfe-mina-template

Version:

BM 小程序模板

62 lines (53 loc) 1.66 kB
import _assign from 'lodash/assign'; import _isObject from 'lodash/isObject'; import GlobalContext from './globalContext'; import { path, getConfig } from '../config/index'; var MAXLENGTH = 0, TYPE = 'wechatMina', ISPROD = path.indexOf('wechat.benmu-health.com') !== -1, BEACONURL = 'https://metatron.benmu-health.com/recorder/recordList.do?app=fe&business=beacon'; /* type: '' // 非必传 业务名称 page: '' // 非必传 默认为空 name: '' // 必传 事件 ID extra_a: '' // 非必传 openId extra_b: '' // 非必传 登录信息 extra_c: '' // 非必传 卡号 extra_d: '' // 非必传 时间戳 extra_e: '' // 非必传 时间戳 extra_f: '' // 非必传 时间戳 extra_g: '' // 非必传 时间戳 extra_h: '' // 非必传 时间戳 */ export default function Beacon(name, page, extra){ if(!name){ return; } if(_isObject(page)){ page = ''; extra = page; } var data = {}, _openid = getConfig('openid'), _sendData = GlobalContext.get('beaconCache'); if(!_sendData){ _sendData = []; } data['type'] = TYPE; data['page'] = page || ''; data['name'] = name; data['extra_a'] = _openid || ''; data['extra_d'] = +new Date(); _assign(data, extra); _sendData.push(data); if(_sendData.length > MAXLENGTH){ wx.request({ method: 'post', url: BEACONURL, timeout: 5000, data: _sendData }); _sendData = []; } GlobalContext.set('beaconCache', _sendData); }