app.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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,true)
  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. fMinistart: false,
  19. userId: {
  20. openid: '',
  21. unionid: '',
  22. timeStamp:0
  23. },
  24. userInfo: null,
  25. defaultAddress: null,
  26. fcodeErr: '',
  27. backLogin: false,
  28. arrayTree: [],
  29. fromSource: '',
  30. channel: '欧耶商城',
  31. record: null,
  32. card_type: '',
  33. authPages: null,
  34. mWxAuthor:null,
  35. member_id:0,
  36. hasmobile: false,
  37. relay_id:0
  38. },
  39. setFromSource(fromSource) {
  40. this.globalData.fromSource = fromSource
  41. },
  42. checkDefaultAddress(address) {
  43. this.globalData.defaultAddress = address
  44. },
  45. clearAddress() {
  46. this.globalData.defaultAddress = null
  47. },
  48. setArrayTree(tree) {
  49. this.globalData.arrayTree = tree
  50. },
  51. setCardType(card_type) {
  52. this.globalData.card_type = card_type
  53. },
  54. showToast(title, icon, duration){
  55. wx.showToast({
  56. icon: icon || 'none',
  57. title,
  58. duration: 2000 || duration
  59. })
  60. },
  61. trim(str) {
  62. str = str.replace(/\s+/g, "")
  63. return str
  64. },
  65. checkCurrentRecord(record) {
  66. this.globalData.record = record
  67. },
  68. clearRecord() {
  69. this.globalData.record = null
  70. },
  71. navigateto(page)
  72. {
  73. if (!this.globalData.userInfo)
  74. {
  75. this.globalData.authPages.forEach(prefix => {
  76. if (page.indexOf(prefix) == 0) {
  77. wx.navigateTo({
  78. url: '/pages/auth/auth',
  79. })
  80. return;
  81. }
  82. });
  83. }
  84. wx.navigateTo({
  85. url: page,
  86. })
  87. },
  88. switchtab(page) {
  89. if (!this.globalData.userInfo) {
  90. this.globalData.authPages.forEach(prefix => {
  91. if(page.indexOf(prefix) == 0) {
  92. wx.navigateTo({
  93. url: '/pages/auth/auth',
  94. })
  95. return;
  96. }
  97. });
  98. }
  99. wx.switchTab({
  100. url: page,
  101. })
  102. },
  103. getValueByKey(key = '', data = []){
  104. if(!data.length) return {}
  105. return data.filter(val => val.card_type === key)[0] || {}
  106. },
  107. relogin() {
  108. this.mWxAuthor.init(true);
  109. },
  110. cardShareInfo() {
  111. console.log('index onShareAppMessage')
  112. let userid = this.globalData.member_id
  113. let imageUrl = '/image/xyzshare.png'
  114. let share_path = `/pages/index/index?relay_id=${userid}`
  115. console.log('share path:', share_path)
  116. return {
  117. title: '移动、联通、电信、中石油、中石化,首充95折,即刻到账',
  118. path: share_path,
  119. imageUrl: imageUrl,
  120. }
  121. },
  122. isNullObject(obj) {
  123. return (Object.keys(obj).length === 0);
  124. }
  125. })