common.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import cacheManager from "./cacheManager.js"
  2. /**
  3. * 显示消息提示框
  4. * @param content 提示的标题
  5. */
  6. export function toast(content) {
  7. uni.showToast({
  8. icon: 'none',
  9. title: content
  10. })
  11. }
  12. /**
  13. * 显示模态弹窗
  14. * @param content 提示的标题
  15. */
  16. export function showConfirm(content) {
  17. return new Promise((resolve, reject) => {
  18. uni.showModal({
  19. title: '提示',
  20. content: content,
  21. cancelText: '取消',
  22. confirmText: '确定',
  23. success: function(res) {
  24. resolve(res)
  25. }
  26. })
  27. })
  28. }
  29. /**
  30. * 参数处理
  31. * @param params 参数
  32. */
  33. export function tansParams(params) {
  34. let result = ''
  35. // FIXME 拼接参数
  36. return result
  37. }
  38. /**
  39. * @summary 获取请求异常与正常返回
  40. * @param {Object} promise
  41. */
  42. export function catchError(promise) {
  43. return new Promise((resolve,reject) => {
  44. promise.then(data => {
  45. resolve([undefined, data.data])
  46. }).catch(err => {
  47. reject([err])
  48. })
  49. })
  50. }
  51. export function debounce(func, wait) {
  52. let timeout;
  53. return function(...args) {
  54. // 清除之前的定时器
  55. clearTimeout(timeout);
  56. // 设置新的定时器
  57. timeout = setTimeout(() => {
  58. func.apply(this, args);
  59. }, wait);
  60. };
  61. }