123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- import {
- wechatConfig,
- share,
- getWxconfig
- } from '@/api/wx';
- import {
- getCompany
- } from '@/api/index.js'
- import store from '../store';
- let weixinObj = require('jweixin-module');
- let shareData = '';
- let appId = '';
- export function loginWinxin() {
- let pages, page, path;
- try {
- pages = getCurrentPages();
-
- page = pages[pages.length - 1];
-
- path = page.route;
- } catch (e) {
- console.log(e);
- }
-
- if (path != 'pages/redirect/redirect') {
- setTimeout((e) => {
- weixinObj.ready(() => {
- console.log('weixinObj.ready');
-
- try {
- console.log(shareData);
- console.log(path);
- weixinSq(shareData, path);
- } catch (e) {
- console.log(e);
-
- }
- });
- weixinObj.error((e) => {
- console.log(e);
- })
- }, 10)
- }
- };
- function weixinSq(data, path) {
-
- try {
- let ul = encodeURIComponent(store.state.baseURL + store.state.urlFile + '/#/pages/redirect/redirect');
- console.log(ul, "ul")
-
- let url =
- 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
- appId +
- '&redirect_uri=' +
- ul +
- '&response_type=code&scope=snsapi_userinfo&state=' +
- new Date().getTime() +
- '#wechat_redirect';
- console.log(url, "url")
- window.location.href = url;
- } catch (e) {
- console.log(e);
- }
- };
- export function weixindata(config) {
-
-
- let weixinObj = require('jweixin-module');
-
- store.commit('setWeiChatObj', weixinObj)
- console.log(window.location.href);
- console.log('当前注册url地址', window.location.href);
- getWxconfig({
- url: store.state.baseURL + store.state.urlFile + '/',
- }).then(({
- data
- }) => {
- appId = data.appId;
-
- weixinObj.config({
- debug: false,
- appId: data.appId,
- timestamp: data.timestamp,
- nonceStr: data.nonceStr,
- signature: data.signature,
- jsApiList: data.jsApiList
- });
- weixinObj.ready((e) => {
- console.log('分享数据', shareData);
- if (shareData == '') {
- getCompany().then(({
- data
- }) => {
-
- shareData = {
- title: data.company_name,
- imgUrl: data.wechat_share_image,
- desc: data.share_info,
- }
- shareLoad(config)
- })
-
- } else {
- shareLoad(config)
- }
- })
- })
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- function shareLoad(config) {
- let mess;
- if (config) {
- mess = {
- link: config.link,
- imgUrl: config.imgUrl,
- desc: config.desc,
- title: config.title,
- success: config.success,
- fail: config.fail || function(e) {
- console.log(e);
- }
- }
- } else {
-
-
- let url = window.location.href;
- url = url.replace(/[\?,&]{0,1}from=singlemessage/g, '');
- mess = {
- title: store.state.baseName,
- link: url,
- imgUrl: store.state.baseURL + '/index/static/img/002.png',
- desc: store.state.shareDesc,
- success: function() {},
- fail: function(e) {
- console.log(e);
- }
- }
- }
-
-
-
- weixinObj.onMenuShareAppMessage(mess);
-
-
- weixinObj.onMenuShareTimeline(mess);
- }
- export function weixinhideMenu(config) {
- console.log(config)
- weixinObj.ready((e) => {
- weixinObj.hideMenuItems({
- menuList: config,
- });
- })
- }
- export default {
- weixinObj,
- shareData,
- appId
- }
|