12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import BaseStore from '@src/stores/base';
- import { generateUUID } from '@src/services/Tools';
- import { WechatH5AppId } from '../../Constant';
- export default class CommonStore extends BaseStore {
-
- sendSms(area, mobile) {
- return this.apiPost('/common/sms/valid', { area, mobile });
- }
-
- upload(file) {
- return this.apiForm('/common/upload/image', { file });
- }
- readyWechatBridge(callback) {
- if (typeof WeixinJSBridge === 'object' && typeof WeixinJSBridge.invoke === 'function') {
- callback();
- } else if (document.addEventListener) {
- document.addEventListener('WeixinJSBridgeReady', callback, false);
- } else if (document.attachEvent) {
- document.attachEvent('WeixinJSBridgeReady', callback);
- document.attachEvent('onWeixinJSBridgeReady', callback);
- }
- }
- readyWechat(url, list) {
- return this.apiGet('/common/wechat/ticket').then(ticket => {
- const time = new Date().getTime() / 1000;
- const nonce = generateUUID(6, 10);
- const p = `jsapi_ticket=${ticket}&noncestr=${nonce}×tamp=${time}&url=${url.split('#')[0]}`;
- const a = list.map(row => row);
- a.push('checkJsApi');
- wx.config({
- debug: false,
- appid: WechatH5AppId,
- timestamp: time,
- nonceStr: nonce,
- signature: sha1(p),
- jsApiList: a,
- });
- return new Promise((resolve, reject) => {
- wx.ready(() => {
- resolve(wx);
- });
- wx.error((err) => {
- reject(err);
- });
- });
- });
- }
- }
- export const Common = new CommonStore({ key: 'common' });
|