1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 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={}){
-
- 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);
- }else{
-
- console.log(res)
- if(res.data.error == '1'){
- uni.hideLoading();
- }else{
- resolve(res.data);
- }
- }
- uni.hideLoading();
- });
- });
- },
- get(url="",data={}){
- return this.send({
- url: url,
- data: data
- });
- },
- post(url="",data={}){
- return this.send({
- url: url,
- data: data,
- method: "POST"
- });
- }
- };
|