123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import dev from "@/env/dev.js"
- import prod from "@/env/prod.js"
- let baseUrl = ''
- if (process.env.NODE_ENV === 'development') {
- baseUrl = dev.baseUrl
- } else {
- baseUrl = prod.baseUrl
- }
- if(baseUrl==""){
- baseUrl="http://yigui.liliju.com";
- }
- export const myRequest = (options) => {
- return new Promise((resolve, reject) => {
- let obj_url = ''
- let obj_method = 'GET'
- let obj_data = {}
- if (options) {
- obj_url = baseUrl + options.url
- obj_method = options.method
- obj_data = options.data
- }
- uni.request({
- url: obj_url,
- method: obj_method,
- header: {
- 'token':uni.getStorageSync("token")
- },
- data: obj_data,
- success: (res) => {
- if(res.data.msg=="登入已过期"){
- uni.redirectTo({
- url:"/pages/login/index"
- })
- }else{
- resolve(res)
- }
-
- },
- fail: (err) => {
- uni.showToast({
- title: "请求接口失败",
- icon: "error"
- })
- reject(err)
- }
- })
- })
- }
|