Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let sessionResponse: {
data: {
openid: string;
session_key: string;
};
};
try {
sessionResponse = await Taro.request({
method: 'POST',
url: `${envConfig.WECHAT_HOST}/oauth/wechat/session`,
data: loginResponse,
});
if (sessionResponse && sessionResponse.data) {
Taro.setStorageSync('openId', sessionResponse.data.openid);
Taro.setStorageSync('sessionKey', sessionResponse.data.session_key);
}
} catch (e) {
console.log(e);
setLoginLoading(false);
await Taro.showToast({ title: '获取 Key 失败' });
return;
}
console.log('sessionResponse', sessionResponse);
//
// ------------------------------------
let userInfoResponse: {
encryptedData: string;
data: {
openid: string;
session_key: string;
};
};
try {
sessionResponse = await Taro.request({
method: 'POST',
url: `${envConfig.WECHAT_HOST}/oauth/wechat/session`,
data: loginResponse,
});
if (sessionResponse && sessionResponse.data) {
Taro.setStorageSync('openId', sessionResponse.data.openid);
Taro.setStorageSync('sessionKey', sessionResponse.data.session_key);
}
} catch (e) {
console.log(e);
setLoginLoading(false);
await Taro.showToast({ title: '获取 Key 失败' });
return;
}
console.log('sessionResponse', sessionResponse);
//
// ------------------------------------
let userInfoResponse: {
encryptedData: string;
iv: string;
success(res) {
if (res.confirm) {
Taro.setStorageSync('Authorization', '')
Taro.setStorageSync('userInfo', null)
Taro.navigateBack()
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
Taro.startPullDownRefresh().then((result) => {
const {isPullRefresh} = this.state
console.log('onPullDownRefresh',result)
Taro.setStorageSync('IS_LATEST_DATA_REFRESH',true);
Taro.eventCenter.trigger('LATEST_DATA_REFRESH',isPullRefresh)
this.setState({
isPullRefresh: false
},()=>{
Taro.stopPullDownRefresh();
})
}).catch((failResullt) => {
console.log('failResullt', failResullt);
Taro.startPullDownRefresh().then((result) => {
const {isPullRefresh} = this.state
console.log('onPullDownRefresh',result)
Taro.setStorageSync('IS_LATEST_DATA_REFRESH',true);
Taro.eventCenter.trigger('LATEST_DATA_REFRESH',isPullRefresh)
this.setState({
isPullRefresh: false
},()=>{
Taro.stopPullDownRefresh();
})
}).catch((failResullt) => {
console.log('failResullt', failResullt);
success: function (res) {
Taro.hideLoading()
Taro.setStorageSync('resultImg', res.tempFilePath)
},
fail: function (res) {
}).then((res) => {
const { code } = res.data
let tip = '登录成功'
if (code !== 200) {
tip = res.data.msg || '登录失败'
}
this.setState({
showLoading: false,
showTip: true,
tip
})
if (code === 200) {
Taro.setStorageSync('userInfo', res.data)
Taro.setStorageSync('userId', res.data.account.id)
Taro.navigateTo({
url: '/pages/index/index'
})
}
})
}
save(state, { payload }) {
Taro.setStorageSync('items', [...state.items, ...payload.items]);
return { ...state, ...payload };
},
deleteClothes(state, { payload }) {
}).then(res => {
if (res.statusCode == 200) {
let data = res.data.data.data.data;
Taro.setStorageSync("cities", data);
}
});
}
*login(_, { call, put, select }) {
const { code, mobile } = yield select(state => state.login);
const res = yield call(login.login, { code, mobile });
if (res.status == 'ok') {
const userInfo = {
access_token: res.data.access_token,
invitation_code: res.data.invitation_code,
mobile: res.data.mobile,
nickname: res.data.nickname,
new_user: res.data.new_user,
is_has_buy_card: res.data.is_has_buy_card,
erroMessage: '',
};
Taro.setStorageSync('user_info', userInfo);
Taro.setStorageSync('access_token', res.data.access_token);
yield put({
type: 'common/save',
payload: {
access_token: res.data.access_token,
invitation_code: res.data.invitation_code,
mobile: res.data.mobile,
nickname: res.data.nickname,
new_user: res.data.new_user,
is_has_buy_card: res.data.is_has_buy_card,
erroMessage: '',
code: '',
},
});
yield put({