123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <script>
- import {
- mapMutations,
- } from 'vuex';
- export default {
- methods: {
- ...mapMutations(['setOpenid','login','showDialog'])
- },
-
- onLaunch: function() {
- // 用户登录
- console.log(this.$store)
- let that = this;
- let sessionId = uni.getStorageSync('sessionId');// 用户sessinid
- console.log(sessionId)
- if(sessionId != '') {
- uni.checkSession({
- success(){
- console.log("登录未过期")
- that.setOpenid("22222");
- },
-
- fail(){
- console.log("jjjj")
- // 登录过期 重新登录
- uni.login({
- provider: 'weixin',
- success: function(res) {
- // 获取code
- that.setOpenid("22222");
- that.login();
- // 获取sessionId
- uni.request({
- url: '',
- data: {
-
- },
- success: (res) => {
- //this.setOpenid("dddd")
-
- }
- })
- },
- fail: function(res) {
-
- }
- })
- }
- })
- }else {
- uni.login({
- provider: 'weixin',
- success: function(res) {
- // 获取code
- that.setOpenid("22222");
- that.login();
- // 获取sessionId
- uni.request({
- url: '',
- data: {
-
- },
- success: (res) => {
- //this.setOpenid("dddd")
-
- }
- })
- },
- fail: function(res) {
-
- }
- })
- };
- // 用户授全
- uni.getSetting({
- success(res) {
- if (res.authSetting['scope.userInfo']) {
- console.log("已授权=====")
- console.log(uni.getStorageSync('sessionId'));
- // 已经授权,可以直接调用 getUserInfo 获取头像昵称
- uni.getUserInfo({
- success(res) {
- that.login(res.userInfo);
- // uni.setStorage({//缓存用户登陆状态
- // key: 'userInfo',
- // data: res.userInfo
- // })
- },
- fail(res) {
- console.log("获取用户信息失败", res)
- }
- })
- } else {
- console.log("触发授权")
- uni.showModal({
- title: '提示',
- content: '请前往授权',
- success: function (res) {
- if (res.confirm) {
- that.showDialog(true)
- } else if (res.cancel) {
- uni.showToast({
- title: '授权失败不能正常使用',
- duration: 2000
- });
- }
- }
- });
- // console.log("未授权=====")
- // that.showSettingToast("请授权")
- }
- }
- })
- },
- onShow: function() {
- console.log('App Show')
- },
- onHide: function() {
- console.log('App Hide')
- }
- }
- </script>
- <style>
- /*每个页面公共css */
- </style>
|