utils.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // 弹窗
  2. function alertError(title) {
  3. document.addEventListener('plusready', function() {
  4. console.log('......')
  5. })
  6. try {
  7. plus.nativeUI.toast(title, {
  8. icon: '/static/common/toast-error.png',
  9. style: 'inline',
  10. verticalAlign: 'top'
  11. });
  12. } catch (e) {
  13. //TODO handle the exception
  14. }
  15. }
  16. //获取get传值的方法
  17. function getQueryString(name) {
  18. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  19. var r = window.location.search.substr(1).match(reg);
  20. if (r != null) return decodeURI(r[2]);
  21. return null;
  22. }
  23. let baseUrl = 'https://aws.okx.com';
  24. // post请求封装
  25. function axiosPost(url, data) {
  26. return new Promise((resolve, reject) => {
  27. axios({
  28. headers: {
  29. "Content-Type": "application/x-www-form-urlencoded",
  30. },
  31. method: 'post',
  32. url: baseUrl + url,
  33. data: data || {}
  34. })
  35. .then(res => {
  36. if (res.data.code == 0) {
  37. resolve(res.data)
  38. } else {
  39. reject()
  40. alertError('请求超时')
  41. }
  42. })
  43. .catch(err => {
  44. alertError('请求超时')
  45. })
  46. })
  47. }
  48. // get请求封装
  49. function axiosGet(url, data) {
  50. return new Promise((resolve, reject) => {
  51. axios({
  52. method: 'get',
  53. url: baseUrl + url,
  54. params: data || {}
  55. })
  56. .then(res => {
  57. // console.log("res: " + JSON.stringify(res.data.data));
  58. if (res.data.code == 0) {
  59. resolve(res.data.data)
  60. } else {
  61. reject()
  62. alertError('请求超时')
  63. }
  64. })
  65. .catch(err => {
  66. alertError('请求超时')
  67. })
  68. })
  69. }