123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- import { Toast, Notify } from 'vant'
- import Clipboard from "clipboard";
- import { getWxToken, openError } from "@/utils/auth";
- import { getCache } from '@/utils/auth'
- import { getWxConfigInfo } from '../api'
- import router from '@/router'
- import wx from "weixin-js-sdk";
- //判断环境/登录状态
- export function isWxEnv(type, data) {
- return new Promise((resolve, reject) => {
- if (isWeChatMobile()) {
- if (getWxToken() && localStorage.getItem('wx_user_info')) {
- Toast("微信环境已授权");
- resolve()
- } else {
- Toast.fail("微信环境未授权");
- reject(1)
- doWeixinLogin(type, data);
- }
- } else {
- Toast.fail("请在手机微信中打开浏览");
- reject(2)
- // if (getWxToken() && localStorage.getItem('wx_user_info')) {
- // resolve()
- // } else {
- // Toast.fail("请在手机微信中打开浏览");
- // reject(2)
- // }
- }
- })
- }
- export function isWeChat() {
- var ua = navigator.userAgent.toLowerCase();
- return /micromessenger/.test(ua);
- }
- export function isWeChatPC() {
- var ua = navigator.userAgent.toLowerCase();
- // 你可以根据PC版微信浏览器的特性来添加更多的判断条件
- // 例如,某些PC版微信浏览器可能包含特定的关键字或版本信息
- return /micromessenger/.test(ua) && /windows/.test(ua) && !/mobile/.test(ua);
- }
- export function isWeChatMobile() {
- var ua = navigator.userAgent.toLowerCase();
- return /micromessenger/.test(ua) && /mobile/.test(ua);
- }
- // if (isWeChat()) {
- // if (isWeChatPC()) {
- // console.log('这是PC版微信');
- // } else if (isWeChatMobile()) {
- // console.log('这是手机版微信');
- // } else {
- // console.log('无法确定是PC版还是手机版微信');
- // }
- // } else {
- // console.log('这不是微信浏览器');
- // }
- //请求微信授权
- export function doWeixinLogin(type, data) {
- // let defaultUrl = 'https://3g954g5149.picp.vip/wx/mp/auth/wx65f4dde5ec7c31e7?marketing=1'
- // let dealerUrl = 'https://3g954g5149.picp.vip/wx/mp/auth/wx65f4dde5ec7c31e7?marketing=2&pid='
- // let timinalUrl = 'https://3g954g5149.picp.vip/wx/mp/auth/wx65f4dde5ec7c31e7?marketing=3&expendCode='
- let defaultUrl = `${process.env.BASE_API}/wx/mp/auth/wx65f4dde5ec7c31e7?marketing=1`
- let dealerUrl = `${process.env.BASE_API}/wx/mp/auth/wx65f4dde5ec7c31e7?marketing=2&pid=`
- let timinalUrl = `${process.env.BASE_API}/wx/mp/auth/wx65f4dde5ec7c31e7?marketing=3&expendCode=`
- if (getCache("isAndroid")) {
- if (type == 'pid' && data) {
- window.open(`${dealerUrl}${data}`)
- } else if (type == 'code' && data) {
- window.open(`${timinalUrl}${data}`)
- } else {
- window.open(`${defaultUrl}`)
- }
- } else {
- if (type == 'pid' && data) {
- window.location.href = `${dealerUrl}${data}`;
- } else if (type == 'code' && data) {
- window.location.href = `${timinalUrl}${data}`;
- } else {
- window.location.href = `${defaultUrl}`;
- }
- }
- }
- //复制(event必须为点击元素)
- export function copyLink(event) {
- let that = this;
- //这里是复制目标的类名
- let clipboard = new Clipboard(event, {
- text: function (trigger) {
- return trigger.getAttribute("aria-label");
- }
- });
- clipboard.on("success", function (e) {
- e.clearSelection(); //清除选中的文字的选择状态
- that.$toast.success("复制成功~");
- });
- clipboard.on("error", function (e) {
- console.error(e);
- });
- }
- export function setWxConfig(shareInfo) {
- let info
- if(shareInfo){
- info = shareInfo
- }else{
- info = {
- title:'功道云知识平台',// 分享标题
- desc:'听完觉得确实不错,忍不住要推荐~',// 分享描述
- link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
- imgUrl: 'https://oa.g107.com/m/static/images/logo.png', // 分享图标
- }
- }
- console.log(info)
- let data = {
- url:window.location.href
- }
- getWxConfigInfo(data).then(config => {
- wx.config({
- appId: config.appId,
- timestamp: config.timestamp,
- nonceStr: config.nonceStr,
- signature: config.signature,
- jsApiList: ['updateAppMessageShareData','updateTimelineShareData']
- })
- wx.ready(() => {
- wx.updateAppMessageShareData({
- title: info.title, // 分享标题
- desc: info.desc, // 分享描述
- link: info.link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
- imgUrl: info.imgUrl, // 分享图标
- success: function () {
- // 设置成功
- console.log("分享成功");
- },
- });
- wx.updateTimelineShareData({
- title: info.title, // 分享标题
- link: info.link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
- imgUrl: info.imgUrl, // 分享图标
- success: function () {
- // 设置成功
- console.log("分享成功");
- },
- });
- });
- }).catch(err=>{
- console.log(err)
- })
- }
|