1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- // const baseUrl = 'http://39.100.230.190:30046'
- const baseUrl = 'http://172.18.0.24:30046'
- // const baseUrl = 'http://172.18.1.227:30046'
- // 文件上传地址
- const fileUrl = 'http://172.18.0.24:30045'
- // const fileUrl = 'http://39.100.230.190:30045'
- // import { showLoading,hideLoading } from './loading.js'
- // 方式请求
- export function request(method, url, data = {},header={},token=false) {
- return new Promise((resolve, reject) => {
-
- // header['content-type']='application/x-www-form-urlencoded;charset=UTF-8'
-
- const t = uni.getStorageSync('token')
- if(t){
- // header['Authorization']='Bearer '+ t
- header['Authorization']= t
- } else {
- header['Authorization']= ''
- }
- uni.showLoading()
- uni.request({
- url: baseUrl + url,
- method: method.toUpperCase(),
- data: data,
- dataType: 'json',
- header,
- success: (res) => {
- if(res.data.status === '40401' || res.data.status === '40415' || res.data.message === '未获得认证信息,请重新登陆') {
- uni.hideLoading()
- uni.showToast({
- title: res.data.message,
- duration: 2000,
- icon: 'none',
- position: 'top'
- });
-
- setTimeout(()=>{
- uni.navigateTo({
- url: '/pages/login/login'
- })
- },1000)
- } else {
- uni.hideLoading()
- resolve(res.data)
- }
- },
- fail: (error) => {
- uni.showToast({
- title: error.errMsg,
- duration: 20000,
- icon: 'none',
- position: 'top'
- });
- setTimeout(()=>{
- uni.navigateTo({
- url: '/pages/login/login'
- })
- },1000)
- reject(error)
- }
- });
- })
- }
- //上传图片
- export function upload_img(url, imageSrc) {
- return new Promise((resolve, reject) => {
- uni.uploadFile({
- url: fileUrl + url,
- filePath: imageSrc,
- name: 'file',
- header: {
- 'Authorization': uni.getStorageSync('token')
- },
- success: (res) => {
- res = JSON.parse(res.data);
- resolve(res);
- },
- fail: (err) => {
- reject(err);
- }
- });
- })
- }
|