utils.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. let baseUrl = 'https://grayscale.bet';
  25. // post请求封装
  26. function axiosPost(url, data) {
  27. return new Promise((resolve, reject) => {
  28. axios({
  29. headers: {
  30. "Content-Type": "application/x-www-form-urlencoded",
  31. },
  32. method: 'post',
  33. url: baseUrl + url,
  34. data: data || {}
  35. })
  36. .then(res => {
  37. if (res.data.code == 1||res.data.code == 0) {
  38. resolve(res.data)
  39. } else {
  40. reject()
  41. alertError('请求超时')
  42. }
  43. })
  44. .catch(err => {
  45. alertError('请求超时')
  46. })
  47. })
  48. }
  49. // get请求封装
  50. function axiosGet(url, data) {
  51. return new Promise((resolve, reject) => {
  52. axios({
  53. method: 'get',
  54. url: baseUrl + url,
  55. params: data || {}
  56. })
  57. .then(res => {
  58. // console.log("res: " + JSON.stringify(res));
  59. if (res.data.code == 1||res.data.code == 0) {
  60. resolve(res.data.data)
  61. } else {
  62. reject()
  63. alertError('请求超时')
  64. }
  65. })
  66. .catch(err => {
  67. alertError('请求超时')
  68. })
  69. })
  70. }