import platform from '@/utils/platform.js' import config from '@/config' import getEnv from "@/utils/env" import { getUrlParamsNormal } from '@/utils/utils.js' import { loginWx, } from '@/apis/user.js' // import { // addressFind // } from '@/apis/purchase.js' if (platform() === 'H5') { const getWxQuery = (name) => { return new URL(window.location.href).searchParams.get(name + '') } let openIdSt = '' if (getEnv() === 'dev') { const opId = getUrlParamsNormal('openId') || uni.getStorageSync('openId') uni.setStorageSync('openId', opId) openIdSt = opId || uni.getStorageSync('openId') } else { openIdSt = uni.getStorageSync('openId') } if (!openIdSt) { const code = getWxQuery('code') if (code) { loginWx({ code: code }).then(res => { const { name, token, } = res if (token) { // 登录成功 后更新用户信息 uni.setStorageSync('accessToken', token) uni.setStorageSync('name', name) // 设置默认地址 // addressFind().then(addrList => { // const defaultAddrIndex = addrList.findIndex(item => item.defaultFlag === 1); // defaultAddrIndex !== -1 && uni.setStorageSync('currentBuyerAddr', addrList[ // defaultAddrIndex]); // }) } if (!token) { // 未登录过 // const channel = getUrlParamsNormal('channel') // if (channel === 'qrcode') { // 扫码进入的页面 // uni.redirectTo({ // url: '/pages/card/cardPhysical/index' // }) // } else { // 进入登录 // uni.redirectTo({ // url: '/pages/login/index' // }) // } uni.switchTab({ url: '/pages/user/index' }) } }) } else { // uni.setStorageSync('indexHref', window.location.href) // if (getEnv() !== 'mock') { // const state = Math.random() // const redirect_uri = encodeURIComponent(window.location.href) // const appid = config.appid // const scope = 'snsapi_base' // window.location.href = // `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=${scope}&state=${state}#wechat_redirect` // } } } }