12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import config from "@/config";
- import storage from "./storage";
- export default {
- console(options){
- if(config.debug){
-
-
-
-
-
-
-
- }
- },
- domain(){
- return config.uni_app_web_api_url.replace("api","");
- },
- send(options={}){
-
- if(options.data.serviceId!=3021){
- uni.showLoading({
- title: '加载中'
- });
- }
-
- options.url = config.uni_app_web_api_url + '' + options.url;
-
- options.method = options.method || "GET";
-
-
- let users = storage.getJson("users");
- if(users != null){
-
- options.header = { "user_token" : users.user_token,"user_id" : users.user_id };
-
-
-
- }
-
- console.log(options);
-
-
- return new Promise((resolve, reject) =>{
- uni.request(options).then(data=>{
- var [error, res] = data;
- if(error != null){
- reject(error);
- uni.hideLoading();
- }else{
-
- console.log(res)
- if(res.data.code == '-1'){
-
-
-
-
-
-
-
-
-
-
- uni.hideLoading();
- }else{
- resolve(res.data);
- uni.hideLoading();
- }
- uni.hideLoading();
- }
- }).catch(data =>{
- uni.showToast({
- icon: 'none',
- title: "服务器错误",
- duration: 5000
- });
- uni.hideLoading();
- });
- });
- },
- get(url="",data={}){
- return this.send({
- url: url,
- data: data
- });
- },
- post(url="",data={}){
- return this.send({
- url: url,
- data: data,
- method: "POST"
- });
- }
- };
|