app.js 2.8 KB

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