App.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <script>
  2. //app.js
  3. const req = require("./utils/request.js");
  4. // // #ifndef H5
  5. // let livePlayer = requirePlugin('live-player-plugin')
  6. // // #endif
  7. export default {
  8. onLaunch: function(options) {
  9. // this.globalData.appInitData();
  10. this.globalData.InitUpdateManager();
  11. // this.globalData.getChatList();
  12. //
  13. uni.hideTabBar()
  14. },
  15. onShow(options) {
  16. let scene = options.scene;
  17. req.setStorage('scene',scene)
  18. this.globalData.getVideoScene();
  19. // // #ifndef H5
  20. // // 分享卡片/订阅消息/扫码二维码/广告/朋友圈等场景才能调用getShareParams接口获取以下参数
  21. // const sceneList = [1007, 1008, 1014, 1044, 1045, 1046, 1047, 1048, 1049, 1073, 1154, 1155]
  22. // if (sceneList.includes(options.scene)) {
  23. // livePlayer.getShareParams()
  24. // .then(res => {
  25. // // 房间号
  26. // console.log('get room id', res.room_id)
  27. // // 用户openid
  28. // console.log('get openid', res.openid)
  29. // // 分享者openid,分享卡片进入场景才有
  30. // console.log('get share openid', res.share_openid)
  31. // // 开发者在跳转进入直播间页面时,页面路径上携带的自定义参数,这里传回给开发者
  32. // console.log('get custom params', res.custom_params)
  33. // if(res.custom_params){
  34. // req.setStorage('pidCode',res.custom_params.userId)
  35. // }
  36. // }).catch(err => {
  37. // console.log('get share params', err)
  38. // })
  39. // }
  40. // // #endif
  41. },
  42. globalData: {
  43. //获取客服配置
  44. // getChatList() {
  45. // req.getRequest('/api/customer/list', {}, res => {
  46. // req.setStorage('chatService', res);
  47. // });
  48. // },
  49. appInitData() {
  50. var getSysInfo = uni.getSystemInfoSync();
  51. this.isIPhone = getSysInfo.model.indexOf("iPhone") != -1;
  52. this.isIPhoneX = getSysInfo.model.indexOf("iPhone X") != -1 || getSysInfo.model.indexOf("iPhone 11") != -
  53. 1; // 是否为全面屏
  54. this.isFullScreen = getSysInfo.screenHeight / getSysInfo.screenWidth >= 2.1; // iPhoneX底部空白高度为68,全面屏为20
  55. this.bottomBlankHeignt = this.isIPhoneX ? 68 : this.isFullScreen ? 10 : 0;
  56. this.height = getSysInfo.statusBarHeight;
  57. this.screenHeight = getSysInfo.screenHeight;
  58. },
  59. getVideoScene(){
  60. let scene = req.getStorage('scene');
  61. let arr = [1195,1193,1191,1184,1177,1176,1175,1201,1216,10001]
  62. req.setStorage('isVideoScene',false)
  63. arr.some(it=>{
  64. if(it === scene){
  65. req.setStorage('isVideoScene',true)
  66. }
  67. })
  68. console.log('isVideoScene==',req.getStorage('isVideoScene'))
  69. },
  70. InitUpdateManager() {
  71. const updateManager = uni.getUpdateManager();
  72. let that = this;
  73. updateManager.onCheckForUpdate(function(res) {
  74. // 请求完新版本信息的回调
  75. console.log(res.hasUpdate);
  76. });
  77. updateManager.onUpdateReady(function() {
  78. uni.showModal({
  79. title: '更新提示',
  80. content: '新版本已经准备好,是否重启应用?',
  81. success: function(res) {
  82. if (res.confirm) {
  83. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  84. uni.clearStorage({
  85. success() {
  86. updateManager.applyUpdate();
  87. }
  88. });
  89. }
  90. }
  91. });
  92. });
  93. updateManager.onUpdateFailed(function() { // 新版本下载失败
  94. });
  95. },
  96. getCheckSessoin(success) {
  97. // var sessionKey = req.getStorage('SESSION_KEY');
  98. // let that = this;
  99. // wx.checkSession({
  100. // success() {
  101. // if (!sessionKey) {
  102. // that.getSessionKey(success);
  103. // } else {
  104. // success.call(this, sessionKey);
  105. // }
  106. // },
  107. // fail() {
  108. // that.getSessionKey(success);
  109. // }
  110. // })
  111. this.getSessionKey(success);
  112. },
  113. getSessionKey(success) {
  114. let that = this;
  115. uni.login({
  116. success(res) {
  117. req.postRequest('/api/code', {
  118. code: res.code
  119. }, data => {
  120. that.SESSION_KEY = data.session_key;
  121. req.setStorage('SESSION_KEY', data.session_key);
  122. success.call(this, data);
  123. }, true);
  124. }
  125. });
  126. },
  127. userInfo: null,
  128. height: 0,
  129. isredenvelopes:true,
  130. isLayerAd:true,
  131. /**
  132. * 打开新页面
  133. */
  134. openPage(e) {
  135. let url
  136. if (e.indexOf("plugin-private:") != -1) {
  137. url = `${e}`
  138. } else {
  139. url = `/${e}`
  140. }
  141. uni.navigateTo({
  142. // url: `/${e}`
  143. url: url
  144. });
  145. // uni.navigateTo({
  146. // url: `/${e}`
  147. // });
  148. },
  149. /**
  150. *
  151. * 关闭当前页面,跳转到应用内的某个页面。
  152. */
  153. redirectTab(path) {
  154. uni.redirectTo({
  155. url: `/${path}`
  156. });
  157. },
  158. /**
  159. *
  160. * 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
  161. */
  162. switchTab(path) {
  163. uni.switchTab({
  164. url: `/${path}`
  165. });
  166. },
  167. /**
  168. *
  169. * 关闭所有页面,打开到应用内的某个页面
  170. */
  171. reLaunchTo(path) {
  172. uni.reLaunch({
  173. url: `/${path}`
  174. });
  175. },
  176. /**
  177. *
  178. * 保留当前页面,跳转到应用内的某个页面
  179. */
  180. navigateTo(path) {
  181. uni.navigateTo({
  182. url: `/${path}`
  183. });
  184. }
  185. },
  186. methods: {}
  187. };
  188. </script>
  189. <style>
  190. @import "./app.css";
  191. </style>