| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import config from "./url.js"
- import store from '@/store/index.js';
- export const myRequest = (options) => {
- let BASE_URL = config.baseUrl
- console.log(BASE_URL, options.url)
- var session_key = ""
- session_key = uni.getStorageSync('session_key')
- let url = options.url
- let data = options.data || {}
- if (!url.includes('sysmenage.usermanager.user_login') && !url.includes('pest.pests.insect_discern')) {
- data.token = session_key
- if (!session_key) {
- console.log('session_key',session_key)
- return Promise.reject('请重新登录');
- }
- }
- console.log(data, '---------- my request')
- return new Promise((resolve, reject) => {
- uni.request({
- url: BASE_URL + options.url,
- method: options.method || 'POST',
- header: {
- "Content-Type": "application/x-www-form-urlencoded",
- },
- data: data,
- success: (res) => {
- console.log(res)
- if (res.data.message != "") {
- console.log(111)
- uni.showToast({
- title: res.data.message || '请求接口失败',
- icon: "none"
- })
- if (res.data.errorCode == 403) {
- if (!store.state.isInLoginPage) {
- uni.setStorageSync('session_key', '')
- setTimeout(() => {
- uni.reLaunch({
- url: "/pages/login/login"
- })
- }, 2000)
- }
- }
- }
- resolve(res.data.data)
- },
- fail: (err) => {
- uni.showToast({
- title: '请求接口失败'
- })
- reject(err)
- }
- })
- })
- }
|