You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
let loadingService = true; //等待层状态
|
|
|
|
import {
|
|
|
|
devDomain,
|
|
|
|
prdDomain
|
|
|
|
} from "../config/config.js";
|
|
|
|
import store from "../store/index.js";
|
|
|
|
const api = {
|
|
|
|
|
|
|
|
loginModalState: true,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 成功提示
|
|
|
|
*/
|
|
|
|
success: (msg) => {
|
|
|
|
|
|
|
|
return new Promise((relove, reject) => {
|
|
|
|
uni.showToast({
|
|
|
|
title: msg,
|
|
|
|
icon: "success"
|
|
|
|
})
|
|
|
|
setTimeout(() => {
|
|
|
|
relove();
|
|
|
|
}, 1500)
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 失败提示
|
|
|
|
*/
|
|
|
|
error: (msg) => {
|
|
|
|
|
|
|
|
return new Promise((relove, reject) => {
|
|
|
|
|
|
|
|
uni.showToast({
|
|
|
|
title: msg,
|
|
|
|
icon: "none",
|
|
|
|
duration: 2500
|
|
|
|
})
|
|
|
|
setTimeout(() => {
|
|
|
|
relove();
|
|
|
|
}, 2500)
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 等待层
|
|
|
|
*/
|
|
|
|
showWaiting: () => {
|
|
|
|
|
|
|
|
loadingService = true;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
|
|
if (loadingService) {
|
|
|
|
uni.showLoading({
|
|
|
|
title: '加载中',
|
|
|
|
mask: true
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 200)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 关闭等待层
|
|
|
|
*/
|
|
|
|
closeWaiting: () => {
|
|
|
|
|
|
|
|
loadingService = false;
|
|
|
|
uni.hideLoading();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 确认对话框
|
|
|
|
* @param {Object} contents
|
|
|
|
* @param {Object} callback
|
|
|
|
*/
|
|
|
|
confirm: (contents) => {
|
|
|
|
|
|
|
|
return new Promise((relove, reject) => {
|
|
|
|
|
|
|
|
uni.showModal({
|
|
|
|
title: '提示',
|
|
|
|
content: contents,
|
|
|
|
success: function(res) {
|
|
|
|
if (res.confirm) {
|
|
|
|
relove();
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取当前域名
|
|
|
|
*/
|
|
|
|
getDomain() {
|
|
|
|
|
|
|
|
return process.env.NODE_ENV === 'development' ? devDomain : prdDomain;
|
|
|
|
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 跳转
|
|
|
|
* @param {Object} url
|
|
|
|
* @param {Object} params
|
|
|
|
*/
|
|
|
|
toUrl(url, params = null) {
|
|
|
|
if (params) {
|
|
|
|
let paramsArr = [];
|
|
|
|
Object.keys(params).forEach(key => {
|
|
|
|
paramsArr.push(`${key}=${params[key]}`);
|
|
|
|
})
|
|
|
|
url += "?" + paramsArr.join("&");
|
|
|
|
}
|
|
|
|
|
|
|
|
uni.navigateTo({
|
|
|
|
url: url
|
|
|
|
})
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 退出登录
|
|
|
|
*/
|
|
|
|
logout() {
|
|
|
|
|
|
|
|
uni.reLaunch({
|
|
|
|
url: "/pages/login/login"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
export default api;
|