util.js 859 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* 常用工具函数 */
  2. export const msg = (title, duration=1500, mask=true, icon='none')=>{
  3. //统一提示方便全局修改
  4. if(Boolean(title) === false){return;}
  5. uni.showToast({
  6. title,
  7. duration,
  8. mask,
  9. icon
  10. });
  11. }
  12. export const modal = (title,content,confirmText,cancelText,showCancel=false,callBack) =>{
  13. uni.showModal({
  14. title,
  15. content,
  16. confirmText,
  17. cancelText,
  18. confirmColor:'#E15616',
  19. showCancel,
  20. success: function (res) {
  21. if (res.confirm) {
  22. callBack()
  23. }
  24. }
  25. });
  26. }
  27. export const json = type=>{
  28. //模拟异步请求数据
  29. return new Promise(resolve=>{
  30. setTimeout(()=>{
  31. // console.log(resolve+'======='+type);
  32. resolve(Json[type]);
  33. }, 500)
  34. })
  35. }
  36. export const prePage = ()=>{
  37. let pages = getCurrentPages();
  38. let prePage = pages[pages.length - 2];
  39. // #ifdef H5
  40. return prePage;
  41. // #endif
  42. return prePage.$vm;
  43. }