business-tool.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var businessType = require('business-type.js')
  2. var _debug = false
  3. function isDebug() {
  4. return _debug
  5. }
  6. function debugLog(e) {
  7. if (_debug) {
  8. console.log(e)
  9. }
  10. }
  11. function action(f, t) {
  12. var after = t || 500
  13. return function () {
  14. var app = getApp()
  15. if (app.globalData.isClicked) {
  16. return
  17. }
  18. app.globalData.isClicked = true
  19. f.apply(this, arguments)
  20. setTimeout(function () {
  21. app.globalData.isClicked = false
  22. }, after)
  23. }
  24. }
  25. function showFailTips(err, p) {
  26. if (err.code == businessType.NetworkErrorCode.netwrokMiss) {
  27. wx.showToast({
  28. title: err.msg,
  29. icon: 'none'
  30. })
  31. } else if (err.code == businessType.NetworkErrorCode.connectErrorMessage) {
  32. wx.showToast({
  33. title: err.msg,
  34. icon: 'none'
  35. })
  36. } else if (p) {
  37. wx.showToast({
  38. title: p,
  39. icon: 'none'
  40. })
  41. }
  42. }
  43. module.exports = {
  44. debugLog: debugLog,
  45. action: action,
  46. showFailTips: showFailTips,
  47. isDebug: isDebug
  48. }