util.js 1.2 KB

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