app.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //app.js
  2. import WxAuthor from './utils/WxAuthor'
  3. App({
  4. onLaunch: function() {
  5. let self = this;
  6. // 登录
  7. new WxAuthor(self)
  8. const dirs = ['addAddress','address','myhome','confirmOrder','confirmVOrder',
  9. 'order_tabs','orderPaySn','person','postageDetail','postageManage','shopCart'];
  10. let pages = new Set()
  11. dirs.forEach(dir => {
  12. let page = `/pages/${dir}/${dir}`
  13. pages.add(page)
  14. });
  15. this.globalData.authPages = pages
  16. },
  17. globalData: {
  18. userId: {
  19. openid: '',
  20. unionid: ''
  21. },
  22. userInfo: null,
  23. defaultAddress: null,
  24. fcodeErr: '',
  25. backLogin: false,
  26. arrayTree: [],
  27. fromSource: '',
  28. channel: '欧耶商城',
  29. record: null,
  30. card_type: '',
  31. authPages: null
  32. },
  33. setFromSource(fromSource) {
  34. this.globalData.fromSource = fromSource
  35. },
  36. checkDefaultAddress(address) {
  37. this.globalData.defaultAddress = address
  38. },
  39. clearAddress() {
  40. this.globalData.defaultAddress = null
  41. },
  42. setArrayTree(tree) {
  43. this.globalData.arrayTree = tree
  44. },
  45. setCardType(card_type) {
  46. this.globalData.card_type = card_type
  47. },
  48. showToast(title, icon, duration){
  49. wx.showToast({
  50. icon: icon || 'none',
  51. title,
  52. duration: 2000 || duration
  53. })
  54. },
  55. trim(str) {
  56. str = str.replace(/\s+/g, "")
  57. return str
  58. },
  59. checkCurrentRecord(record) {
  60. this.globalData.record = record
  61. },
  62. clearRecord() {
  63. this.globalData.record = null
  64. },
  65. navigateto(page)
  66. {
  67. this.globalData.authPages.forEach(prefix => {
  68. if(page.indexOf(prefix) == 0) {
  69. if(!this.globalData.userInfo) {
  70. wx.navigateTo({
  71. url: '/pages/auth/auth',
  72. })
  73. return;
  74. }
  75. }
  76. });
  77. wx.navigateTo({
  78. url: page,
  79. })
  80. }
  81. })