common.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // 是否是会员
  52. export function getUserIdentity() {
  53. const auth = cacheManager.get('auth');
  54. if (auth) {
  55. if (auth.cardList.some(item => item === auth.catdId)) {
  56. // VIP
  57. return 'VIP'
  58. }
  59. // 非VIP
  60. return 'Not-Vip';
  61. } else {
  62. // 游客
  63. return 'Visitor';
  64. }
  65. }