Authored by QC-L

修复首页在清除缓存的情况下失效的 bug --- review by 黄敬囿

... ... @@ -63,7 +63,7 @@ export const setOpenId = (id) => {
export const setSessionkey = (sessionKey) => {
sessionKey = !sessionKey ? user.getYHStorageSync('session_key', 'app') : sessionKey;
console.log(sessionKey);
return {
sessionKey,
type: globalData.SESSIONKEY
... ...
... ... @@ -8,6 +8,8 @@ import * as globalData from './actions/globalData';
import udid from './utils/udid';
import './app.scss'
import event from './utils/event';
import { loginAction } from './libs/login/login.js'
import getPrivateKey from './libs/request/getPrivateKey.js'
const store = createStore();
... ... @@ -82,7 +84,7 @@ class App extends Component {
}
};
componentWillMount () {
componentWillMount () {
let {setSystemInfo, wechatLogin, setSessionkey} = this.props;
// 获取系统信息
... ... @@ -104,7 +106,7 @@ class App extends Component {
this.props.setWxUnionId();
// this.props.getUnionTypeWithUid(this.props.globalData.userInfo.uid); // 有赚
},
fail: () => {
async fail: () => {
console.log('登录已经过期')
//登录态过期
Taro.setStorage({key: 'WXThird_session', data: ''});
... ...
import { Component } from '@tarojs/taro';
import Taro, { Component } from '@tarojs/taro';
import { View } from '@tarojs/components';
import { common as commonModel } from '../../models';
import Focus from '../resource-focus';
import HotSeries from '../resource-hot-series';
import Category from '../resource-category';
import './index.scss';
import getPrivateKey from '../../libs/request/getPrivateKey.js'
export default class Resources extends Component {
constructor(props) {
... ... @@ -14,7 +15,9 @@ export default class Resources extends Component {
};
}
componentDidMount() {
async componentDidMount() {
const pk = await getPrivateKey();
Taro.setStorage({ key: 'verifyKey', data: pk });
commonModel.resource(this.props.code).then(res => {
if (res && res.code === 200) {
this.setState({
... ...
... ... @@ -11,9 +11,13 @@ export const loginAction = (callBack) => {
// 获取 srd_session
const loginData = data;
handleLoginData(loginData);
callBack(null, data);
if (callBack) {
callBack(null, data);
}
}).catch((error) => {
callBack(error);
if (callBack) {
callBack(error);
}
});
}
},
... ... @@ -65,7 +69,7 @@ export const decodeUnionId = (srd_session, result) => {
} else {
union_id = globalData.union_id;
}
console.log('+++++++++++++++', union_id);
if (!union_id) {
throw new Error('union_id is null');
}
... ... @@ -158,7 +162,7 @@ export const getUserInfo = (e) => {
if (error) return;
decodeUnionId(loginData.srd_session, e).then(data => {
wechatUserIsBind(data.union_id, data.userInfo).then(message => {
console.log(message);
if (message.code === 10003) {
event.emit('user-login-success');
setTimeout(() => {
... ... @@ -252,18 +256,13 @@ export const getPhoneNumber = (e) => {
export const getLoginButtonType = () => {
const globalData = getGlobalData();
console.log(globalData);
if (globalData && globalData.userInfo && globalData.userInfo.uid) {
return ''; // 已经是登录状态,合法用户
}
console.log(globalData);
let isUnionID = globalData.userInfo && globalData.userInfo.union_id;// 如果有unionID情况
let isPhoneNumber = isUnionID ? !(globalData.userInfo && globalData.userInfo.uid) : false; // 如果有unionID且没有uid,可以获取手机号自动绑定登录
console.log(isUnionID);
console.log(isPhoneNumber);
console.log(globalData.userInfo.uid);
console.log(globalData.userInfo.union_id);
if (!isUnionID) {
event.emit('change-login-status', {
text: '微信登录',
... ...
... ... @@ -5,6 +5,7 @@ import {Resources} from '../../components';
import {classify as classifyModel} from '../../models';
import {getImgUrl} from '../../utils';
import './index.scss';
import getPrivateKey from '../../libs/request/getPrivateKey.js'
export default class Classify extends Component {
constructor() {
... ... @@ -20,7 +21,9 @@ export default class Classify extends Component {
navigationBarTitleText: '分类'
}
componentDidMount () {
async componentDidMount () {
const pk = await getPrivateKey();
Taro.setStorage({ key: 'verifyKey', data: pk });
classifyModel.getBrandList().then(ret => {
if (ret && ret.code === 200) {
this.setState({
... ...
... ... @@ -7,6 +7,7 @@ import {common as commonModel} from '../../models';
import './index.scss';
import { connect } from '@tarojs/redux';
import { loginAction, decodeUnionId, wechatUserIsBind } from '../../libs/login/login.js'
import getPrivateKey from '../../libs/request/getPrivateKey.js'
@connect(({ filterMenu }) => ({
... ... @@ -42,74 +43,77 @@ export default class Index extends Component {
navigationBarTitleText: 'UFO'
};
componentDidMount() {
let obj = {
page: {},
productList: {},
stopLoading: {}
};
// 初始化数据
this.state.tabs.map(item => {
let type = item.type;
obj.page[type] = 1;
obj.productList[type] = [];
obj.stopLoading[type] = false;
});
this.setState(obj, () => {
this.getProductData();
});
}
componentWillReceiveProps (nextProps) {
let curType = nextProps.filterMenu.curType;
let {productList} = this.state;
if (productList[curType].length === 0) {
this.getProductData(nextProps.filterMenu);
}
componentDidMount() {
let obj = {
page: {},
productList: {},
stopLoading: {}
};
// 初始化数据
this.state.tabs.map(item => {
let type = item.type;
obj.page[type] = 1;
obj.productList[type] = [];
obj.stopLoading[type] = false;
});
this.setState(obj, () => {
this.getProductData();
});
}
componentWillReceiveProps(nextProps) {
let curType = nextProps.filterMenu.curType;
let { productList } = this.state;
if (productList[curType].length === 0) {
this.getProductData(nextProps.filterMenu);
}
getProductData(obj) {
let {filterMenu} = this.props;
let {page, productList, stopLoading} = this.state;
obj = obj || filterMenu;
let type = obj.curType;
commonModel.search({
limit: 10,
type: type,
page: page[type]
}).then(ret => {
if (ret && ret.code === 200) {
let list = ret.data && ret.data.product_list || [];
if (list.length === 0) {
this.setState({
stopLoading: Object.assign(stopLoading, {[type]: true})
});
} else {
this.setState({
productList: Object.assign(productList, {[type]: [...productList[type], ...list]})
});
}
}
})
}
onScrollToLower() {
let {filterMenu} = this.props;
let {page} = this.state;
let type = filterMenu.curType;
if (!this.state.stopLoading[type]) {
this.setState({page: Object.assign(page, {[type]: page[type] + 1})}, () => {
this.getProductData();
});
}
async getProductData(obj) {
let { filterMenu } = this.props;
let { page, productList, stopLoading } = this.state;
obj = obj || filterMenu;
let type = obj.curType;
const pk = await getPrivateKey();
Taro.setStorage({ key: 'verifyKey', data: pk });
commonModel.search({
limit: 10,
type: type,
page: page[type]
}).then(ret => {
console.log(ret);
if (ret && ret.code === 200) {
let list = ret.data && ret.data.product_list || [];
if (list.length === 0) {
this.setState({
stopLoading: Object.assign(stopLoading, { [type]: true })
});
} else {
this.setState({
productList: Object.assign(productList, { [type]: [...productList[type], ...list] })
});
}
}
}
})
}
onScrollToLower() {
let { filterMenu } = this.props;
let { page } = this.state;
let type = filterMenu.curType;
if (!this.state.stopLoading[type]) {
this.setState({ page: Object.assign(page, { [type]: page[type] + 1 }) }, () => {
this.getProductData();
});
}
}
// gotoNative() {
// Taro.navigateTo({
... ...
... ... @@ -16,7 +16,6 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(options);
let that = this;
event.on('user-login-success', () => {
// 返回上一页
... ... @@ -66,7 +65,6 @@ Page({
*/
onShow: function () {
const buttonType = getLoginButtonType();
console.log('buttonType: ', buttonType);
this.setData({
loginButtonType: buttonType
});
... ...
... ... @@ -123,11 +123,9 @@ const api = {
return resultData;
} else {
console.error('api statusCode:', result.statusCode);
return result && result.data || {};
}
}).catch(err => {
console.error(err);
return {};
});
},
... ...