123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- import http from './http.js'
- export default {
- // 请求方法
- requestEn(url, data = {}, methods) {
- return new Promise((resolve, reject) => {
- uni.request({
- url: http.webUrl + url,
- method: methods ? methods : 'GET',
- data: data,
- success: res => {
- if (res.data.code === 200) {
- resolve(res.data.data === undefined ? null : res.data.data)
- } else if (res.data.code === 403 ||res.data.code === 401 ) {
- uni.showToast({
- title: 'Token超时,请重新登录',
- icon: 'none'
- })
- if (uni.getStorageSync('token')) {
- uni.removeStorage({
- key: 'token',
- success: () => {
- uni.navigateTo({
- url: '/pages/login/login'
- })
- }
- })
- } else {
- uni.navigateTo({
- url: '/pages/login/login'
- })
- }
- } else {
- uni.showToast({
- title: res.data.msg ? res.data.msg : '系统异常',
- icon: 'none'
- })
- }
- },
- fail: () => {
- uni.showToast({
- title: '网络异常',
- icon: 'none'
- })
- }
- })
- })
- },
- // 请求方法
- requestFn(url, data = {}, methods) {
- return new Promise((resolve, reject) => {
- console.log(http.webUrl + url +'---'+ uni.getStorageSync('token'))
- uni.request({
- url: http.webUrl + url,
- method: methods ? methods : 'GET',
- data: data,
- header: {
- "WxAuthorization": `wxBearer ${uni.getStorageSync('token') ? uni.getStorageSync('token') : ''}`,
- "userType":'MOdBILE'
- },
- success: res => {
- console.log(res)
-
- if (res.data.code === 200) {
- resolve(res.data.data === undefined ? null : res.data.data)
- } else if (res.data.code === 403 ||res.data.code === 401 ) {
- uni.showToast({
- title: 'Token超时,请重新登录',
- icon: 'none'
- })
- if (uni.getStorageSync('token')) {
- uni.removeStorage({
- key: 'token',
- success: () => {
- uni.navigateTo({
- url: '/pages/login/login'
- })
- }
- })
- } else {
- uni.navigateTo({
- url: '/pages/login/login'
- })
- }
- } else {
- uni.showToast({
- title: res.data.msg ? res.data.msg : '系统异常',
- icon: 'none'
- })
- }
- },
- fail: () => {
- uni.showToast({
- title: '网络异常',
- icon: 'none'
- })
- }
- })
- })
- },
- requestLo(url, data = {}, methods) {
- return new Promise((resolve, reject) => {
- console.log(http.webUrl + url)
- uni.request({
- url: http.webUrl + url,
- method: methods ? methods : 'GET',
- data: data,
- header: {
- "userType":'MOBILE'
- },
- success: res => {
- console.log(res)
- if (res.data.code === 200 || res.data.code === 500) {
- resolve(res.data === undefined ? null : res.data)
- } else if (res.data.code === 403) {
- uni.showToast({
- title: res.data.msg ? res.data.msg : 'Token超时,请重新登录',
- icon: 'none'
- })
- if (uni.getStorageSync('token')) {
- uni.removeStorage({
- key: 'token',
- success: () => {
- uni.navigateTo({
- url: '/pages/login/login'
- })
- }
- })
- } else {
- uni.navigateTo({
- url: '/pages/login/login'
- })
- }
- } else {
- uni.showToast({
- title: res.data.msg ? res.data.msg : '系统异常',
- icon: 'none'
- })
- }
- },
- fail: () => {
- uni.showToast({
- title: '网络异常',
- icon: 'none'
- })
- }
- })
- })
- }
- }
|