tool.js 1014 Bytes
import wx from '../utils/wx';
import gominiapp from '../router/jump-to-miniapp.js';
import { parse } from '../vendors/query-stringify';
import event from '../common/event';

export default {
    scanCode: function() {
        wx.scanCode().then(res => {
            const domRex = /^http(s)?:\/\/o\.yohobuy\.com/;
            const splitAry = res.result.split('?');
            const skn = parse(splitAry[1]).skn;

            if (domRex.test(res.result) && skn) {
                event.emit('scan-success', {URL: res.result}); // 扫码成功后上报
                gominiapp({
                    app: 'yohobuy',
                    page: 'productDetail',
                    data: {
                        productSkn: skn
                    }
                });
            } else {
                wx.showModal({
                    content: '您扫描的二维码对应链接格式不正确,请重新扫码',
                    showCancel: false
                });
            }
        });
    }
};