123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- import Vue from 'vue'
- //const BASE_URL = 'https://ymt.prpiano.com/api'
- //const BASE_URL = 'https://ht.test.prpiano.com/api'
- //xw
- //const BASE_URL = 'http://10.0.52.100:82'
- //dh
- var BASE_URL
- var BASE_URL2
- //lb
- //const BASE_URL = 'http://10.0.126.219:82'
- if (process.env.NODE_ENV === 'development') {
- //线上 https://bytesailing.cn/api/storage/cloudApi
- BASE_URL = 'http://36.134.91.96:10001/api'
- BASE_URL2 = 'http://36.134.91.96:10001/api'
- } else {
- //线上
- BASE_URL = 'http://36.134.91.96:10001/api'
- BASE_URL2 = 'http://36.134.91.96:10001/api'
- }
- /**
- * 封装get方法
- * @param url
- * @param data
- * @returns {Promise}
- */
- export function get(url, req = {}) {
- return new Promise((resolve, reject) => {
- if (this.$storage.getStorageSync('token')) {
- var hander = {
- 'Blade-Auth': 'bearer ' + this.$storage.getStorageSync('token'),
- 'Authorization':'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
- 'Content-Type':'application/json;charset=UTF-8',
- }
- } else {
- var hander = {}
- }
- uni.request({
- url: BASE_URL + url,
- data: req,
- method: 'GET',
- header: hander,
- success: (res) => {
- resolve(res.data);
- },
- fail: (err) => {
- return Promise.reject(err);
- }
- });
- })
- }
- /**
- * 封装post请求
- * @param url
- * @param data
- * @returns {Promise}
- */
- var urlList = []
- export function post(url, req = {}, headers) {
- var httpUrl
- if(url.indexOf('/cloudApi') == -1){
- httpUrl = BASE_URL
- }else{
- httpUrl = BASE_URL2
- }
- if(urlList.indexOf(url) == -1 || url == '/wx/inventory/selectFabricWTypeDetails' || '/wx/inventory/selectInkEW'){
- urlList.push(url)
- setTimeout(()=>{
- urlList.splice(urlList.indexOf(url),1)
- },500)
- }else{
- return Promise.reject('请勿频繁提交');
- }
- return new Promise((resolve, reject) => {
- if (this.$storage.getStorageSync('token')) {
-
- var hander = {
- 'Blade-Auth': 'bearer ' + this.$storage.getStorageSync('token'),
- 'Authorization':'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
- 'Content-Type':'application/json;charset=UTF-8',
- }
- } else {
- var hander = {}
- }
- if(headers) hander = headers
- uni.request({
- url: httpUrl + url,
- data: req,
- method: 'POST',
- header: hander,
- success: (res) => {
- console.log(res)
- if (res.data.code == 401) {
- uni.showToast({
- icon: "error",
- title: '前往登录',
- duration: 2000
- });
- Vue.prototype.$token = null
- uni.redirectTo({
- url: "/pages/user/login"
- })
- } else if (res.data.code == 500) {
- uni.showToast({
- icon: "error",
- title: res.data.msg,
- duration: 2000
- });
-
- } else if(res.data.code == 200){
- resolve(res.data);
- } else if(!res.data.code){
- uni.showToast({
- icon: "error",
- title: '服务器错误',
- duration: 2000
- });
- } else {
- uni.showToast({
- icon: "error",
- title: res.data.msg,
- duration: 2000
- });
- }
- },
- fail: (err) => {
- uni.showToast({
- icon: "error",
- title: '服务器错误',
- duration: 2000
- });
- return Promise.reject(err);
- }
- });
- })
- }
- export default {
- post,
- get
- }
|