app.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //app.js
  2. import WxAuthor from './utils/WxAuthor'
  3. App({
  4. onLaunch: function() {
  5. let self = this;
  6. // 登录
  7. this.mWxAuthor = 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. mWxAuthor:null
  33. },
  34. setFromSource(fromSource) {
  35. this.globalData.fromSource = fromSource
  36. },
  37. checkDefaultAddress(address) {
  38. this.globalData.defaultAddress = address
  39. },
  40. clearAddress() {
  41. this.globalData.defaultAddress = null
  42. },
  43. setArrayTree(tree) {
  44. this.globalData.arrayTree = tree
  45. },
  46. setCardType(card_type) {
  47. this.globalData.card_type = card_type
  48. },
  49. showToast(title, icon, duration){
  50. wx.showToast({
  51. icon: icon || 'none',
  52. title,
  53. duration: 2000 || duration
  54. })
  55. },
  56. trim(str) {
  57. str = str.replace(/\s+/g, "")
  58. return str
  59. },
  60. checkCurrentRecord(record) {
  61. this.globalData.record = record
  62. },
  63. clearRecord() {
  64. this.globalData.record = null
  65. },
  66. navigateto(page)
  67. {
  68. this.globalData.authPages.forEach(prefix => {
  69. if(page.indexOf(prefix) == 0) {
  70. if(!this.globalData.userInfo) {
  71. wx.navigateTo({
  72. url: '/pages/auth/auth',
  73. })
  74. return;
  75. }
  76. }
  77. });
  78. wx.navigateTo({
  79. url: page,
  80. })
  81. },
  82. switchtab(page) {
  83. this.globalData.authPages.forEach(prefix => {
  84. if(page.indexOf(prefix) == 0) {
  85. if(!this.globalData.userInfo) {
  86. wx.navigateTo({
  87. url: '/pages/auth/auth',
  88. })
  89. return;
  90. }
  91. }
  92. });
  93. wx.switchTab({
  94. url: page,
  95. })
  96. },
  97. getValueByKey(key = '', data = []){
  98. if(!data.length) return {}
  99. return data.filter(val => val.card_type === key)[0] || {}
  100. },
  101. relogin() {
  102. this.mWxAuthor.init();
  103. }
  104. })