public.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const publicFn = {
  2. /**
  3. * Loading转圈圈
  4. * @param {nunber} mask - 不传默认不显示透明蒙层
  5. * @param {string} msg - 提示语 默认值:加载中
  6. */
  7. Loading (mask, msg){
  8. let Mask = mask ? true : false;
  9. let Msg = msg ? msg : "加载中"
  10. wx.showLoading({
  11. title: Msg,
  12. mask: Mask
  13. })
  14. },
  15. /**
  16. * Loading取消转圈圈
  17. */
  18. LoadingOff (){
  19. wx.hideLoading();
  20. },
  21. /**
  22. * Toast提示
  23. * @param {string} msg - 提示内容
  24. * @param {string} icon - icon图标 成功success 加载中loading 无样式none
  25. * @param {number} time - 提示存在时长
  26. */
  27. Toast (msg, icon, time){
  28. let Icon = icon === 1 ? "success" : "none";
  29. wx.showToast({
  30. title: msg,
  31. icon: Icon,
  32. duration: time || 2000
  33. })
  34. },
  35. /**
  36. * 带确认的提示框
  37. * @param {string} msg - 提示内容
  38. */
  39. Alert (msg){
  40. return new Promise((resolve, reject) => {
  41. wx.showModal({
  42. title: '温馨提示',
  43. content: msg,
  44. showCancel:false,
  45. confirmColor:"#007AFF",
  46. success (res) {
  47. // 此弹窗只有确认键,没有取消键,所以只写了resolve没有reject
  48. resolve(res);
  49. }
  50. })
  51. })
  52. },
  53. /**
  54. * 带确认和取消的提示框
  55. * @param {string} msg - 提示内容
  56. */
  57. Confirm (msg){
  58. return new Promise((resolve, reject) => {
  59. wx.showModal({
  60. title: '温馨提示',
  61. content: msg,
  62. cancelColor:"#000000",
  63. confirmColor:"#007AFF",
  64. success (res) {
  65. if (res.confirm) {
  66. resolve(res);
  67. }else if (res.cancel) {
  68. reject(res)
  69. }
  70. }
  71. })
  72. })
  73. },
  74. /**
  75. * 微信登陆 wx.login
  76. */
  77. wxLogin () {
  78. return new Promise((resolve, reject) => {
  79. wx.login({
  80. success (res) {
  81. if (res.code) {
  82. resolve(res.code)
  83. } else {
  84. reject(res.errMsg);
  85. }
  86. }
  87. })
  88. });
  89. }
  90. }
  91. module.exports = publicFn;