app.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. var util = require('we7/resource/js/util.js');
  2. var timeQueue = require('lionfish_comshop/utils/timeQueue');
  3. require('lionfish_comshop/utils//mixins.js');
  4. require('/lib/SPage.js')
  5. App({
  6. onLaunch: async function (options) {
  7. let scene = options.scene || '';
  8. this.globalData.scene = scene;
  9. console.log('scene:' + scene);
  10. var userInfo = wx.getStorageSync("userInfo");
  11. this.globalData.userInfo = userInfo;
  12. wx.setStorageSync("isparse_formdata", 0);
  13. var currentCommunity = wx.getStorageSync("community");
  14. this.globalData.hasDefaultCommunity = !!currentCommunity;
  15. this.globalData.community = currentCommunity;
  16. this.globalData.systemInfo = wx.getSystemInfoSync();
  17. var model = this.globalData.systemInfo.model;
  18. this.globalData.isIpx = model.indexOf("iPhone X") > -1 || model.indexOf("unknown<iPhone") > -1;
  19. this.globalData.timer = new timeQueue.default();
  20. // wx.checkSession({
  21. // success: res => {
  22. // },
  23. // fail: (res) => {
  24. // this.getCode();
  25. // }
  26. // })
  27. },
  28. $mixinP:{
  29. onLoad(options){
  30. console.log("options", options)
  31. }
  32. },
  33. onShow: function () {
  34. if(this.globalData.scene!=1154) this.getUpdate();
  35. },
  36. onHide: function () {
  37. },
  38. //加载微擎工具类
  39. util: util,
  40. //用户信息,sessionid是用户是否登录的凭证
  41. userInfo: {
  42. sessionid: null,
  43. },
  44. globalData: {
  45. systemInfo: {},
  46. isIpx: false,
  47. userInfo: {},
  48. canGetGPS: true,
  49. city: {},
  50. community: {},
  51. location: {},
  52. hasDefaultCommunity: true,
  53. historyCommunity: [],
  54. changedCommunity: false,
  55. disUserInfo: {},
  56. changeCity: "",
  57. timer: 0,
  58. formIds: [],
  59. community_id: '',
  60. placeholdeImg: '',
  61. cartNum: 0,
  62. cartNumStamp: 0,
  63. common_header_backgroundimage: '',
  64. appLoadStatus: 1, // 1 正常 0 未登录 2 未选择社区
  65. goodsListCarCount: [],
  66. typeCateId: 0,
  67. navBackUrl: '',
  68. isblack: 0,
  69. skin: {
  70. color: '#ff5344',
  71. subColor: '#ed7b3a',
  72. lighter: '#fff9f4'
  73. },
  74. goods_sale_unit: '件',
  75. scene: '',
  76. indexCateId: ''
  77. },
  78. getCode:function () {
  79. return new Promise(function (resolve, reject) {
  80. console.log(2222)
  81. var app = getApp();
  82. wx.login({
  83. success: function (res) {
  84. if (res.code) {
  85. console.log(res.code);
  86. util.request({
  87. url: 'entry/wxapp/user',
  88. data: {
  89. controller: 'user.applogin',
  90. code: res.code
  91. },
  92. dataType: 'json',
  93. success: function (res) {
  94. resolve(res.data.token);
  95. wx.setStorageSync('token', res.data.token);
  96. }
  97. });
  98. } else {
  99. reject(res.errMsg)
  100. }
  101. }
  102. })
  103. })
  104. },
  105. getUpdate: function(){
  106. if (wx.canIUse("getUpdateManager")) {
  107. const updateManager = wx.getUpdateManager();
  108. updateManager.onCheckForUpdate(function (res) {
  109. res.hasUpdate && (updateManager.onUpdateReady(function () {
  110. wx.showModal({
  111. title: "更新提示",
  112. content: "新版本已经准备好,是否马上重启小程序?",
  113. success: function (t) {
  114. t.confirm && updateManager.applyUpdate();
  115. }
  116. });
  117. }), updateManager.onUpdateFailed(function () {
  118. wx.showModal({
  119. title: "已经有新版本了哟~",
  120. content: "新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~"
  121. });
  122. }));
  123. });
  124. } else wx.showModal({
  125. title: "提示",
  126. content: "当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。"
  127. });
  128. },
  129. getConfig: function() {
  130. var token = wx.getStorageSync('token');
  131. return new Promise((resolve, reject)=>{
  132. util.request({
  133. url: 'entry/wxapp/user',
  134. data: {
  135. controller: 'index.get_firstload_msg',
  136. token,
  137. m: 'lionfish_comshop'
  138. },
  139. method: 'post',
  140. dataType: 'json',
  141. success: function(res) {
  142. if(res.data.code==0) {
  143. let { new_head_id, default_head_info, isparse_formdata } = res.data;
  144. if(!token) isparse_formdata = 0;
  145. wx.setStorageSync('isparse_formdata', isparse_formdata);
  146. if(new_head_id>0&&Object.keys(default_head_info).length) {
  147. wx.setStorageSync('community', default_head_info);
  148. }
  149. resolve(res)
  150. } else {
  151. reject()
  152. }
  153. }
  154. })
  155. })
  156. },
  157. setShareConfig: function(){
  158. wx.showShareMenu({
  159. menus: ['shareAppMessage', 'shareTimeline']
  160. })
  161. },
  162. siteInfo: require('siteinfo.js')
  163. });