mirror of
https://gitee.com/java110/WechatOwnerService.git
synced 2026-02-24 05:46:04 +08:00
优化我的页面
This commit is contained in:
parent
e6f9f3a6ed
commit
992ca1e406
@ -24,10 +24,39 @@ const getHeaders = function () {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取位置
|
||||
* add by wuxw 2019-12-28
|
||||
*/
|
||||
const getLocation = function(){
|
||||
return wx.getStorageSync('location');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
* add by wuxw 2019-12-28
|
||||
*/
|
||||
const getUserInfo = function(){
|
||||
let _userInfo = wx.getStorageSync(constant.mapping.USER_INFO);
|
||||
return JSON.parse(_userInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录标记
|
||||
* add by wuxw 2019-12-28
|
||||
*/
|
||||
const getLoginFlag = function(){
|
||||
let _loginFlag = wx.getStorageSync(constant.mapping.LOGIN_FLAG)
|
||||
return _loginFlag;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
constant: constant,
|
||||
util: util,
|
||||
factory:factory,
|
||||
getHeaders: getHeaders
|
||||
getHeaders: getHeaders,
|
||||
getLocation: getLocation,
|
||||
getUserInfo: getUserInfo,
|
||||
getLoginFlag: getLoginFlag
|
||||
};
|
||||
@ -18,23 +18,14 @@ class LoginFactory {
|
||||
}
|
||||
|
||||
// 检查本地 storage 中是否有登录态标识
|
||||
checkLoginStatus() {
|
||||
checkLoginStatus(callback = () => { }) {
|
||||
let loginFlag = wx.getStorageSync(constant.mapping.LOGIN_FLAG);
|
||||
if (loginFlag) {
|
||||
// 检查 session_key 是否过期
|
||||
wx.checkSession({
|
||||
// session_key 有效(为过期)
|
||||
success: function () {
|
||||
// 直接从Storage中获取用户信息
|
||||
let userStorageInfo = wx.getStorageSync('userInfo');
|
||||
console.log('用户信息', userStorageInfo);
|
||||
if (userStorageInfo) {
|
||||
//that.globalData.userInfo = JSON.parse(userStorageInfo);
|
||||
} else {
|
||||
coreUtil.showInfo('缓存信息缺失');
|
||||
console.error('登录成功后将用户信息存在Storage的userStorageInfo字段中,该字段丢失');
|
||||
}
|
||||
|
||||
callback();
|
||||
},
|
||||
// session_key 过期
|
||||
fail: function () {
|
||||
@ -44,7 +35,7 @@ class LoginFactory {
|
||||
});
|
||||
} else {
|
||||
// 无登录态
|
||||
this.doLogin();
|
||||
this.doLogin(callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -13,9 +13,9 @@
|
||||
</view>
|
||||
</view>
|
||||
<swiper class="categoryList" indicator-dots="true" indicator-color="rgba(228,228,228,1)" indicator-active-color="#FECA49">
|
||||
<block wx:for="{{categoryList}}" wx:key="">
|
||||
<block wx:for="{{categoryList}}" wx:key="index">
|
||||
<swiper-item>
|
||||
<block wx:for="{{item}}" wx:key="">
|
||||
<block wx:for="{{item}}" wx:key="index">
|
||||
<!-- <navigator url="{{item.href}}"> -->
|
||||
<view class="category-info">
|
||||
<navigator url="{{item.href}}">
|
||||
@ -30,7 +30,7 @@
|
||||
</swiper>
|
||||
|
||||
<swiper class="ad-swiper" indicator-dots="true" indicator-color="rgba(228,228,228,1)" indicator-active-color="#FECA49" autoplay='true' interval='5000' duration='1000' circular='true'>
|
||||
<block wx:for="{{ad}}" wx:key="">
|
||||
<block wx:for="{{ad}}" wx:key="index">
|
||||
<swiper-item>
|
||||
<image src="{{item.imageUrl}}"></image>
|
||||
</swiper-item>
|
||||
@ -42,7 +42,7 @@
|
||||
<text class="iconfont icongengduo1 gd"></text>
|
||||
</view>
|
||||
<view class="noticesList">
|
||||
<block wx:for="{{notices}}" wx:key="">
|
||||
<block wx:for="{{notices}}" wx:key="index">
|
||||
<navigator url="/pages/menu/menu">
|
||||
<view class="noticesList-list">
|
||||
<view class="notices-info">
|
||||
|
||||
@ -1,100 +1,23 @@
|
||||
/** index.js **/
|
||||
|
||||
const context = require('../../context/Java110Context.js');
|
||||
const factory = context.factory;
|
||||
//获取app实例
|
||||
const app = getApp();
|
||||
|
||||
Page({
|
||||
data: {
|
||||
userInfo: {}, // 用户信息
|
||||
hasLogin: wx.getStorageSync('loginFlag')
|
||||
hasLogin: context.getLoginFlag()
|
||||
? true
|
||||
: false // 是否登录,根据后台返回的skey判断
|
||||
},
|
||||
|
||||
// 检查本地 storage 中是否有skey登录态标识
|
||||
checkLoginStatus: function() {
|
||||
|
||||
let that = this;
|
||||
|
||||
let loginFlag = wx.getStorageSync('loginFlag');
|
||||
|
||||
if (loginFlag) {
|
||||
// 检查 session_key 是否过期
|
||||
wx.checkSession({
|
||||
// session_key 有效(未过期)
|
||||
success: function() {
|
||||
// 获取用户头像/昵称等信息
|
||||
that.getUserInfo();
|
||||
},
|
||||
|
||||
// session_key 已过期
|
||||
fail: function() {
|
||||
that.setData({
|
||||
hasLogin: false
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
that.setData({
|
||||
hasLogin: false
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 执行登录操作
|
||||
*/
|
||||
doLogin: function() {
|
||||
let that = this;
|
||||
wx.showLoading({
|
||||
title: '登录中...',
|
||||
mask: true
|
||||
});
|
||||
app.doLogin(that.getUserInfo);
|
||||
},
|
||||
/**
|
||||
* 获取用户昵称,头像等信息
|
||||
* @param {*} e
|
||||
*/
|
||||
onGotUserInfo: function (e) {
|
||||
console.log(e.detail.userInfo);
|
||||
console.log(e.detail.rawData)
|
||||
|
||||
// TODO 调用api更新
|
||||
},
|
||||
/**
|
||||
* 跳转已购书籍页面
|
||||
*/
|
||||
goMyBooks: function() {
|
||||
wx.navigateTo({
|
||||
url: '../myBooks/myBooks'
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 从 globalData 中获取 userInfo
|
||||
*/
|
||||
getUserInfo: function() {
|
||||
let that = this;
|
||||
|
||||
let userInfo = app.globalData.userInfo;
|
||||
|
||||
console.info('userInfo is:', userInfo);
|
||||
|
||||
if (userInfo) {
|
||||
that.setData({
|
||||
hasLogin: true,
|
||||
userInfo: userInfo
|
||||
});
|
||||
wx.hideLoading();
|
||||
} else {
|
||||
console.log('globalData中userInfo为空');
|
||||
}
|
||||
},
|
||||
|
||||
onLoad: function() {
|
||||
this.checkLoginStatus();
|
||||
let _that = this;
|
||||
factory.login.checkLoginStatus(function(){
|
||||
_that.setData({
|
||||
userInfo: context.getUserInfo()
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
onShow: function() {
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
<view class="userinfo">
|
||||
|
||||
<block wx:if="{{!userInfo.nickName}}">
|
||||
<block wx:if="{{!userInfo.userName}}">
|
||||
<image class="userinfo-avatar" src="../../images/login.png" background-size="cover" ></image>
|
||||
<button class="userinfo-nickname" open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="onGotUserInfo">点击获取昵称</button>
|
||||
</block>
|
||||
@ -33,12 +33,12 @@
|
||||
<view class="tab-arrow"></view>
|
||||
</view>
|
||||
|
||||
<view class="tab-item" hover-class="tab-item-hover" catchtap="goMyBooks">
|
||||
<!-- <view class="tab-item" hover-class="tab-item-hover" catchtap="goMyBooks">
|
||||
<view>
|
||||
<image src="../../images/bought.png" mode="aspectFit" class="tab-icon"></image>
|
||||
<text class="tab-text">已购</text>
|
||||
</view>
|
||||
|
||||
<view class="tab-arrow"></view>
|
||||
</view>
|
||||
</view> -->
|
||||
</view>
|
||||
|
||||
@ -11,10 +11,11 @@
|
||||
}
|
||||
|
||||
.userinfo-avatar {
|
||||
width: 128rpx;
|
||||
height: 128rpx;
|
||||
margin: 20rpx;
|
||||
border-radius: 50%;
|
||||
display:block;
|
||||
overflow:hidden;
|
||||
border-radius: 50%;
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
}
|
||||
|
||||
.userinfo-nickname {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user