123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <script>
- export default {
- globalData: {
- winHeight: "",
- is_auth: '',
- baseUrl: 'http://admin.l4j.cn/api', //线上地址
- product: '',
- code_no: '',
- code: '',
- latitude: '',
- longitude: '',
- subscribe: '',
- },
- onLaunch: function(e) {
- let that = this
-
- let code_no = e.query.no
- let code = e.query.code
- let code_num = e.query.state
- uni.setStorageSync('code_no', e.query.no)
- let location_url = window.location.href
- let skip_url = 'http://l4j.cn/pages/statistics'
- let skip_url1 = `http://l4j.cn/pages/statistics?code=${code}&state=state`
- //登陆方法线上需要谢在下方else位置
- if (location_url !== skip_url && location_url !== skip_url1) {
- let token = uni.getStorageSync('token')
- if (token) return
- if (!e.query.code) {
- that.globalData.code_no = e.query.no
- //线上解开此处
- window.location.replace(
- `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx22dc4d8cbc0a192d&redirect_uri=http://l4j.cn&response_type=code&scope=snsapi_base&state=${code_no}#wechat_redirect`
- )
- return
- } else {
- // 此处写登陆方法
- uni.showLoading({
- mask: true
- })
- uni.request({
- url: that.globalData.baseUrl + '/auth/wechat-login',
- method: 'POST',
- header: {
- 'content-type': 'application/json',
- 'Accept': 'application/json',
- },
- data: {
- code: e.query.code,
- //code: 'mead',
- appId: 'wx22dc4d8cbc0a192d',
- },
- success(res) {
- console.log(res, 'huoqutoken')
- if (res.data.message == "授权失败") {
- console.log(code_num, '红包码')
- uni.showModal({
- title: '提示',
- content: '授权失败是否重试',
- confirmText: '重试',
- showCancel: false,
- success: (res) => {
- if (res.confirm) {
- window.location.replace('http://l4j.cn/?no=' +
- code_num)
- }
- }
- })
- } else {
- uni.setStorageSync('token', res.data.data.token),
- uni.setStorageSync('is_auth', res.data.data.is_auth),
- uni.setStorageSync('subscribe', res.data.data.subscribe)
- that.globalData.subscribe = res.data.data.subscribe
- // uni.hideLoading()
- }
- },
- catch: (err => {
- uni.showToast({
- title: '授权失败',
- icon: 'none'
- })
- })
- })
- }
- } else {
- return;
- }
- uni.getSystemInfo({
- success(res) {
- console.log(res, '系统信息')
- that.globalData.winHeight = res.windowHeight
- console.log(that.globalData.winHeight, '系统信息')
- }
- })
- },
- onShow: function() {
- console.log('App Show')
- },
- onHide: function() {
- console.log('App Hide')
- },
- methods: {
- request(api, params, method) {
- var that = this;
- return new Promise((resolve, reject) => {
- uni.request({
- url: that.globalData.baseUrl + api,
- data: params,
- header: {
- 'content-type': 'application/json',
- 'Accept': 'application/json',
- 'Authorization': uni.getStorageSync('token'),
- },
- method: method,
- success: (res) => {
- resolve(res.data)
- console.log(res, '请求结果----------------------')
- if (res.statusCode == 450) {
- return;
- }
- if (res.statusCode == 401) {
- uni.clearStorageSync('token')
- location.reload()
- } else if (res.statusCode != 200) {
- if (res.message != undefined) {
- uni.showToast({
- title: res.message,
- icon: 'none',
- duration: 3000,
- mask: true
- })
- } else if (res.data.message != undefined) {
- uni.showToast({
- title: res.data.message,
- icon: 'none',
- duration: 3000,
- mask: true
- })
- }
- }
- if (res.statusCode == 429) {
- uni.showToast({
- title: "操作频繁请稍后再试",
- icon: 'none',
- duration: 3000,
- mask: true
- })
- uni.navigateBack({
- })
- }
- },
- fail: (err) => {
- // console.log('请求失败')
- resolve(err)
- // reject("请求失败")
- }
- })
- })
- },
- }
- }
- </script>
- <style>
- /*每个页面公共css */
- </style>
|