Commit becf339b authored by 郭志伟's avatar 郭志伟

fix: 分享问题

parent 9c46aca9
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
* @Description: weixin-js-sdk * @Description: weixin-js-sdk
* @LastEditors: gzw * @LastEditors: gzw
* @Date: 20120-08-30 18:40:11 * @Date: 20120-08-30 18:40:11
* @LastEditTime: 2020-09-01 19:06:07 * @LastEditTime: 2020-09-01 19:27:35
*/ */
import cfg from "@/config/index"; import cfg from "@/config/index";
import { getwxAuth } from "@/api/user"; import { getwxAuth } from "@/api/user";
import wx from "weixin-js-sdk"; import wx from "weixin-js-sdk";
import { isWeixinBrower } from "@/service/validation"; import { isWeixinBrower } from "@/service/validation";
import { parseSearch } from "@/service/utils";
import localStorage from "@/service/localStorage"; import localStorage from "@/service/localStorage";
/** /**
...@@ -22,7 +23,7 @@ export async function setShare({ ...@@ -22,7 +23,7 @@ export async function setShare({
// console.log(title, desc, link, imgUrl); // console.log(title, desc, link, imgUrl);
const res = await getwxAuth({ const res = await getwxAuth({
appId: cfg.wxAppId, appId: cfg.wxAppId,
url: window.location.href url: link
}); });
const { appId, timestamp, nonceStr, signature } = res; const { appId, timestamp, nonceStr, signature } = res;
wx.config({ wx.config({
...@@ -69,10 +70,10 @@ export async function setShare({ ...@@ -69,10 +70,10 @@ export async function setShare({
*/ */
export function checkOpenId() { export function checkOpenId() {
const openId = localStorage.get("openId"); const openId = localStorage.get("openId");
const _param = parseSearch(window.location.href);
const local = window.location.href; const local = window.location.href;
console.log(!openId, isWeixinBrower); console.log(!openId, isWeixinBrower);
if (!openId && isWeixinBrower) { if (!openId && isWeixinBrower && !_param.code) {
alert("无openid");
var nextPage = document.createElement("a"); var nextPage = document.createElement("a");
nextPage.setAttribute( nextPage.setAttribute(
"href", "href",
...@@ -83,8 +84,5 @@ export function checkOpenId() { ...@@ -83,8 +84,5 @@ export function checkOpenId() {
"&response_type=code&scope=snsapi_base&state=1#wechat_redirect" "&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
); );
nextPage.click(); nextPage.click();
return false;
} else {
return true;
} }
} }
...@@ -223,7 +223,7 @@ export default { ...@@ -223,7 +223,7 @@ export default {
} }
}, },
created() { created() {
!checkOpenId(); checkOpenId();
}, },
mounted() { mounted() {
this.updateRemain(); this.updateRemain();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment