123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import {
- wechatConfig,
- share
- } from '@/api/wx';
- import store from '../store';
- let weixinObj = require('jweixin-module');
- let shareData = '';
- let appId = '';
- export function loginWinxin() {
- console.log("222")
- 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') {
- weixinObj.ready(() => {
- console.log('2');
-
- try {
- console.log(shareData);
- weixinSq(shareData, path);
- } catch (e) {
- console.log(e);
-
- }
- });
- }
- };
- function weixinSq(data, path) {
-
- try {
- let ul = encodeURIComponent(store.state.baseURL + store.state.urlFile + '/#/pages/redirect/redirect');
-
- 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';
- window.location.href = url;
- } catch (e) {
- console.log(e);
-
- }
- };
- export function weixindata(config) {
-
- wechatConfig({
- url: window.location.href
- })
- .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) => {
-
- if (shareData == ''&&!config) {
- share({}).then(({
- data
- }) => {
- shareData = data.data
- shareLoad(config)
- });
- } else {
-
- shareLoad(config)
- }
- })
- })
- .catch(e => {
- console.log(e);
- });
- }
- 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
- }
- } else {
- mess = {
- title: shareData.title,
-
- imgUrl: shareData.img,
- desc: shareData.synopsis,
- success: function() {
-
-
-
-
-
-
-
-
-
-
- }
- }
- }
-
-
- weixinObj.updateAppMessageShareData(mess);
-
- weixinObj.updateTimelineShareData(mess)
- }
- export default {
- weixinObj,
- shareData,
- appId
- }
|