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.Base + 'user-login', method: 'POST', dataType: 'json', data: { username: username, password: password, }, header: { 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest' } }) .then(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) } }) }) }