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.
143 lines
1.9 KiB
143 lines
1.9 KiB
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;
|
|
|