App.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <script>
  2. import utils from './common/utils.js'
  3. import config from './config.js'
  4. export default {
  5. onLaunch: function(e) {
  6. // 隐私政策
  7. // #ifdef APP-PLUS
  8. this.isFirstEnter();
  9. // #endif
  10. console.log('App Launch');
  11. //#ifdef MP-WEIXIN
  12. //检查更新
  13. this.updateManager();
  14. //#endif
  15. // #ifdef APP-PLUS
  16. plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
  17. uni.request({
  18. url: config.app_url + '/index.php/api/index/update',
  19. data: {
  20. version: widgetInfo.version,
  21. name: widgetInfo.name,
  22. app_id: config.app_id,
  23. platform: uni.getSystemInfoSync().platform
  24. },
  25. success: (result) => {
  26. console.log(result);
  27. var data = result.data.data.result;
  28. if (data.update && data.wgtUrl) {
  29. uni.downloadFile({
  30. url: data.wgtUrl,
  31. success: (downloadResult) => {
  32. if (downloadResult.statusCode === 200) {
  33. plus.runtime.install(downloadResult
  34. .tempFilePath, {
  35. force: true
  36. },
  37. function() {
  38. console.log('install success...');
  39. plus.nativeUI.alert(
  40. "已更新至最新版本,确定后将重启应用",
  41. function() {
  42. plus.runtime.restart();
  43. }, "更新提示", "确定");
  44. },
  45. function(e) {
  46. console.error('install fail...');
  47. });
  48. }
  49. }
  50. });
  51. }
  52. if (data.update && data.pkgUrl) {
  53. plus.nativeUI.confirm("有新版本更新,请点击确认更新到最新版本,以免影响使用", function(e) {
  54. if (e.index == 0) {
  55. plus.runtime.openURL(data.pkgUrl);
  56. }
  57. }, {
  58. "title": "更新提示",
  59. "buttons": ["确定", "取消"],
  60. "verticalAlign": "center"
  61. });
  62. }
  63. },
  64. error: (error) => {
  65. console.log('----------------error');
  66. console.log(error);
  67. }
  68. });
  69. });
  70. // #endif
  71. //应用启动参数
  72. this.onStartupScene(e.query);
  73. // #ifndef APP-PLUS
  74. this.getTabBarLinks();
  75. //#endif
  76. },
  77. onShow: function() {
  78. //console.log('App Show')
  79. },
  80. onHide: function() {
  81. //console.log('App Hide')
  82. },
  83. methods: {
  84. isFirstEnter() {
  85. var firstEnter = uni.getStorageSync('firstEnter'); //同步获取缓存中是否有首次进入字段
  86. let self = this;
  87. uni.getSystemInfo({
  88. success(data) {
  89. console.log('firstEnter='+ firstEnter);
  90. // 如果是ios并且没有firstEnter缓存则弹出模态框
  91. if (data.platform == 'ios' && !firstEnter) {
  92. console.log('---------------');
  93. uni.navigateTo({
  94. url: '/pages/privacy/privacy'
  95. })
  96. }
  97. }
  98. })
  99. },
  100. updateManager: function() {
  101. const updateManager = uni.getUpdateManager();
  102. updateManager.onCheckForUpdate(function(res) {
  103. // 请求完新版本信息的回调
  104. if (res.hasUpdate) {
  105. updateManager.onUpdateReady(function(res2) {
  106. uni.showModal({
  107. title: '更新提示',
  108. content: '新版本已经准备好,即将重启应用',
  109. showCancel: false,
  110. success(res2) {
  111. if (res2.confirm) {
  112. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  113. updateManager.applyUpdate();
  114. }
  115. }
  116. });
  117. });
  118. }
  119. });
  120. updateManager.onUpdateFailed(function(res) {
  121. // 新的版本下载失败
  122. uni.showModal({
  123. title: '更新提示',
  124. content: '检查到有新版本,但下载失败,请检查网络设置',
  125. showCancel: false
  126. });
  127. });
  128. },
  129. /**
  130. * 小程序启动场景
  131. */
  132. onStartupScene(query) {
  133. // 获取场景值
  134. let scene = utils.getSceneData(query);
  135. // 记录推荐人id
  136. let refereeId = query.referee_id;
  137. if (refereeId > 0) {
  138. if (!uni.getStorageSync('referee_id')) {
  139. uni.setStorageSync('referee_id', refereeId);
  140. }
  141. }
  142. // 记录分销人id
  143. let uid = scene.uid;
  144. if (uid > 0) {
  145. uni.setStorageSync('referee_id', uid);
  146. }
  147. // 邀请有礼id
  148. let invitation_id = query.invitation_id;
  149. if (invitation_id > 0) {
  150. uni.setStorageSync('invitation_id', invitation_id);
  151. }
  152. let invitid = scene.invitid;
  153. if (invitid > 0) {
  154. uni.setStorageSync('invitation_id', invitid);
  155. }
  156. // 如果是h5,设置app_id
  157. // #ifdef H5
  158. let appId = query.app_id;
  159. if (appId > 0) {
  160. uni.setStorageSync('app_id', appId);
  161. }
  162. if (uni.getStorageSync('app_id')) {
  163. this.config.app_id = uni.getStorageSync('app_id');
  164. }
  165. // #endif
  166. },
  167. getTabBarLinks() {
  168. uni.request({
  169. url: this.config.app_url + '/index.php/api/index/nav',
  170. data: {
  171. app_id: this.config.app_id
  172. },
  173. success: (result) => {
  174. let vars = result.data.data.vars;
  175. uni.setStorageSync('TabBar', vars);
  176. uni.setTabBarStyle({
  177. color: vars.no_color,
  178. selectedColor: vars.color,
  179. })
  180. vars.menus.forEach((item, index) => {
  181. uni.setTabBarItem({
  182. index: index,
  183. text: item.text,
  184. iconPath: item.iconPath,
  185. selectedIconPath: item.selectedIconPath
  186. })
  187. })
  188. }
  189. });
  190. }
  191. }
  192. }
  193. </script>
  194. <style>
  195. @import './common/iconfont.css';
  196. @import './common/myIcon.css';
  197. /*每个页面公共css */
  198. @import './common/style.css';
  199. </style>