cf-wx-app/src/util/standardLogin.js
2019-03-06 14:16:09 +08:00

61 lines
1.8 KiB
JavaScript

import Taro from '@tarojs/taro'
import URL from '../serviceAPI.config'
const setUserInfoToStorage = () => {
Taro.request({
url: URL.ShopWxStore,
header: {
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
}
})
.then(res => {
if (res.data.err_msg === 'success') {
Taro.setStorageSync('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone })
} else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
duration: 1500
})
}
})
}
export default function standardLogin(username, password) {
return new Promise((resolve,reject)=>{
Taro.request({
url: URL.StandardLogin,
method: 'POST',
dataType: 'json',
data: {
username: username,
password: password,
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
console.log('普通登录',res)
if (res.data.err_code === 0) {
Taro.showToast({
title: '登入成功',
icon: 'success',
duration: 1000
})
Taro.setStorageSync('session_id', res.data.session_id)
Taro.setStorageSync('shopInfo', res.data.shop_info)
Taro.setStorageSync('userInfo', res.data.user_info)
Taro.setStorageSync('accountInfo', { username: username, password: password })
setUserInfoToStorage()
resolve('success')
} else {
reject(res)
}
})
})
}