123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 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() {
- return new Promise((resolve) => {
- if (typeof WeixinJSBridge === 'object' && typeof WeixinJSBridge.invoke === 'function') {
- resolve();
- } else if (document.addEventListener) {
- document.addEventListener('WeixinJSBridgeReady', resolve, false);
- } else if (document.attachEvent) {
- document.attachEvent('WeixinJSBridgeReady', resolve);
- document.attachEvent('onWeixinJSBridgeReady', resolve);
- }
- });
- }
- readyWechat(url, list) {
- return this.apiGet('/common/wechat/ticket').then(ticket => {
- const time = parseInt(new Date().getTime() / 1000, 10);
- 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' });
|