12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- // const baseUrl = 'http://81.70.84.72:30046'
- // const baseUrl = 'http://172.18.0.24:30046'
- const baseUrl = 'http://39.100.230.190:30046'
- // 文件上传地址
- 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']= 'kH9Hjdl/kDju1I678v+35Wbf5u0HrveaZsxbhtW8xK8='
- }
- 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.status === '50000') {
- uni.showToast({
- title: res.data.message,
- duration: 2000,
- icon: 'none',
- position: 'top'
- });
- } else {
- resolve(res.data)
- }
- uni.hideLoading()
- },
- fail: (error) => {
- console.log(error, '错误');
- uni.showToast({
- title: error.errMsg,
- duration: 20000,
- icon: 'none',
- position: 'top'
- });
- 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);
- }
- });
- })
- }
|