加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.js 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
小帅丶 提交于 2023-12-12 09:17 . :sparkles:3.0.0beta版本代码提交
import {
colorUI
} from './config/ColorUI'
import {
colorUISdk
} from './config/mp-sdk'
var api = require('utils/api.js');
App({
colorUI,
colorUISdk,
onLaunch() {
var that = this;
that.xsShare()
wx.getStorage({
key: 'userLogin',
success: function(res) {
that.globalData.openid = res.data.openid,
that.globalData.account_code = api.account_code
that.globalData.userId = res.data.userId
},
fail:function(res){
// 登录
wx.login({
success: res => {
//发送 res.code 到后台换取 openId, sessionKey, unionId
wx.request({
url: api.wxlogin_url,
data: {
code: res.code,
account_code: api.account_code
},
success: function (res) {
that.globalData.openid = res.data.data.openid,
that.globalData.account_code = api.account_code
that.globalData.userId = res.data.data.userId
wx.setStorage({
key: 'userLogin',
data: res.data.data,
})
},
})
}
})
}
})
},
onShow() {
},
xsShare: function () {
wx.onAppRoute(function () {
let pages = getCurrentPages(),
views = pages[pages.length - 1],
data;
if (views) {
data = views.data;
if (!data.isOverShare) {
data.isOverShare = true;
views.onShareAppMessage = function () {
return {
title: '有趣~ 好玩~ AI科技狠活',
path: '/pages/index/index'
}
}
}
}
})
},
globalData: {
canIUse:false,
openid: null,
userId: null,
account_code: null,
session_key:null,
userInfo:null,
}
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化