123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import platform from '@/utils/platform.js'
- import config from '@/config'
- import getEnv from "@/utils/env"
- import {
- getUrlParamsNormal
- } from '@/utils/utils.js'
- import {
- getUserInfo,login
- } from '@/apis/user.js'
- // import {
- // logout
- // } from '@/apis/information.js'
- // const apisFilter = (station, data) => {
- // return new Promise(resolve => {
- // if (station === '1') {
- // getOpenIdAndLogin(data).then((res) => {
- // resolve(res)
- // })
- // } else {
- // getOpenId(data).then((res) => {
- // resolve(res)
- // })
- // }
- // })
- // }
- if (platform() === 'H5') {
- // const getWxQuery = (name) => {
- // return new URL(window.location.href).searchParams.get(name + '')
- // }
- let openIdSt = ''
- let station = getUrlParamsNormal('stationType') || uni.getStorageSync('stationType')
- // if (getEnv() === 'test') {
- // const opId = getUrlParamsNormal('wxOpenid') || uni.getStorageSync('wxOpenid')
- // uni.setStorageSync('wxOpenid', opId)
- // if (station) {
- // uni.setStorageSync('stationType', station)
- // }
- // openIdSt = opId || uni.getStorageSync('wxOpenid')
- // } else {
- // openIdSt = uni.getStorageSync('wxOpenid')
- // if (station) {
- // uni.setStorageSync('stationType', station)
- // }
- // }
- // console.log(openIdSt,'openIdSt');
- // if (!openIdSt) {
- // const code = getWxQuery('code')
- // console.log(code,'code');
- // if (code) {
- // getUserInfo(station, {
- // // code: code
- // }).then(res => {
- // let ress = res.data
- // uni.setStorageSync('wxOpenid', ress.wxOpenid)
- // const userInfo = uni.getStorageSync('userInfo')
- const token = uni.getStorageSync('accessToken')
- setTimeout(() => {
- if (token) { // 登录成功 后更新用户信息
- uni.setStorageSync('accessToken', token)
- // uni.setStorageSync('tokenType', token.tokenType)
- // uni.setStorageSync('userInfo', ress)
- }
- if (!token) { // 未登录过
- const channel = getUrlParamsNormal('channel')
- if (channel === 'qrcode') { // 扫码进入的页面
- uni.redirectTo({
- url: '/pages/gallery/index'
- })
- } else { // 进入登录
- uni.redirectTo({
- url: '/pages/login/index'
- })
- }
- }
- },100)
-
- // })
- // } else {
- // uni.setStorageSync('indexHref', window.location.href)
- // if (getEnv() !== 'mock') {
- // console.log(22);
- // const state = 'retail'
- // const redirect_uri = encodeURIComponent(window.location.href)
- // const appid = config.appid
- // const scope = 'snsapi_userinfo'
- // 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`
- // }
- // }
- // } else {
- // uni.setStorageSync('indexHref', window.location.href)
- // const userInfo = uni.getStorageSync('userInfo')
- // if ((userInfo.type === 0 && station === '0') || (userInfo.type !== 0 && station === '1')) { // 站点切团长
- // logout().then(() => {
- // uni.removeStorageSync('accessToken')
- // uni.removeStorageSync('tokenType')
- // uni.removeStorageSync('userInfo')
- // uni.navigateTo({
- // url: '/pages/login/index'
- // })
- // })
- // }
- // }
- }
|