1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- export let api_url = null
- export function get(url, params, success = noop, fail = noop) {
- return http(url, 'GET', params, success, fail)
- }
- export function post(url, params, success = noop, fail = noop) {
- return http(url, 'POST', params, success, fail)
- }
- function noop() {}
- function http(url, method, params, success, fail) {
- // const type = wx.getStorageSync('env') || 'dev' // 测试环境
- const type = wx.getStorageSync('env') || 'ijolijoli' // 正式环境
- switch (type) {
- case 'dev':
- api_url = 'https://test-api-ads.tiantianqutao.com/'
- break
- default:
- api_url = 'https://test-api-ads.tiantianqutao.com/'
- break
- }
- return wx.request({
- url: `${api_url}${url}`,
- method: method,
- data: params,
- header: {
- token: wx.getStorageSync('token') || ''
- },
- success: ({ data, statusCode, header }) => {
- console.log(`==============${url}`, data)
- if (data.code == 200) {
- success(data, header)
- } else if (data.code == 201) {
- wx.showToast({
- title: data.msg,
- icon: 'none'
- })
- fail(data, header)
- } else if (data.code == 400) {
- console.log('登录失败')
- wx.showToast({
- title: data.msg,
- icon: 'none'
- })
- let pages = getCurrentPages()
- if (pages.length == 0) {
- wx.reLaunch({
- url: '/pages/login/login'
- })
- return
- }
- // if (pages[pages.length - 1].route == 'pages/deviceLogin/deviceLogin') {
- // wx.navigateTo({
- // url: '/pages/login/login?prePage=1'
- // })
- // } else {
- // wx.reLaunch({
- // url: '/pages/login/login'
- // })
- // }
- // wx.reLaunch({
- // url: '/pages/login/login',
- // })
- // login()
- }else{
- success(data, header)
- }
- },
- fail() {
- wx.showToast({
- title: '服务器异常 请稍后再试',
- icon: 'none'
- })
- }
- })
- }
- // 清理code
- export function clearWxLoginCode() {
- getApp().loginConfig = {
- code: '',
- codeTime: ''
- }
- }
|