App.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <script>
  2. import config from './config'
  3. import store from '@/store'
  4. import { getToken } from '@/utils/auth'
  5. import {updateUserProfile,findVersion} from "@/api/system/user.js"
  6. const baseUrl = config.baseUrl
  7. export default {
  8. data(){
  9. return{
  10. platform:'Android'
  11. }
  12. },
  13. onLaunch: function() {
  14. // #ifdef APP
  15. this.onlineWgt(); //版本更新
  16. // var url=baseUrl;
  17. // if(url.indexOf('https://lyyy.qs163.cn')!=-1){
  18. // }else{
  19. // }
  20. // #endif
  21. },
  22. methods: {
  23. //热更新
  24. // this.getJGtuifn()
  25. // 在线跟新
  26. onlineWgt() {
  27. let that = this;
  28. plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
  29. that.comparisonVersionNo(widgetInfo.versionCode);
  30. });
  31. // that.comparisonVersionNo()
  32. },
  33. comparisonVersionNo(versionCode) {
  34. let that = this;
  35. // console.log("aaaaaaa===versionCode", versionCode);
  36. const parmas = {
  37. model: that.platform
  38. }
  39. findVersion(parmas).then(res => {
  40. console.log(res)
  41. if (res.code == "200") {
  42. let versionNos = res.data.code;
  43. // console.log(versionNos,'versionNos')
  44. let filePath = res.data.path;
  45. if (Number(versionNos) > Number(versionCode)) { //服务器返回1更新,0则不更新
  46. uni.showModal({
  47. title: '提示',
  48. content: '发现新版本,是否升级',
  49. success: function(res) {
  50. // console.log(widgetInfo.version);
  51. if (res.confirm) {
  52. console.log('用户点击确定');
  53. that.getProperty(filePath);
  54. } else if (res.cancel) {
  55. console.log('用户点击取消');
  56. }
  57. }
  58. });
  59. }
  60. }
  61. }).catch(error=>{
  62. uni.hideLoading()
  63. console.log(error)
  64. })
  65. },
  66. getProperty(getProperty) {
  67. // console.log("bbbbbbbbb----------->", getProperty)
  68. let that = this;
  69. // console.log(baseUrl + getProperty)
  70. // 在线升级app/热更新
  71. that.showwri = true;
  72. const downloadTask = uni.downloadFile({ //下载文件
  73. url: baseUrl + getProperty,
  74. success: (downloadResult) => {
  75. // console.log(downloadResult);
  76. if (downloadResult.statusCode == 200) {
  77. // 更新升级
  78. plus.runtime.install(downloadResult.tempFilePath, {
  79. force: true
  80. }, function() {
  81. // console.log('install success...');
  82. that.showwri = false;
  83. plus.nativeUI.alert("应用资源更新完成!", function() {
  84. plus.runtime.restart();
  85. });
  86. }, function(e) {
  87. that.showwri = false;
  88. plus.nativeUI.alert("更新失败,请稍后再试");
  89. });
  90. }
  91. }
  92. });
  93. downloadTask.onProgressUpdate((res) => { //下载文件的进度
  94. that.totalBytesWritten = res.totalBytesWritten; //当前下载大小
  95. that.progress = res.progress; //当前下载比例
  96. that.totalBytesExpectedToWrite = res.totalBytesExpectedToWrite; //
  97. });
  98. },
  99. // 极光推送
  100. getJGtuifn(){
  101. //#ifdef APP-PLUS
  102. var jpushModule = uni.requireNativePlugin("JG-JPush");
  103. jpushModule.setLoggerEnable(true);
  104. // 初始化函数
  105. jpushModule.initJPushService();
  106. jpushModule.addConnectEventListener(result=>{
  107. let connectEnable = result.connectEnable
  108. // console.log("jpush连接", connectEnable)
  109. })
  110. jpushModule.getRegistrationID(result => {
  111. // console.log("注册ID.....",result)
  112. this.registerID = result.registerID;
  113. if(getToken()){
  114. var params={
  115. jgId:this.registerID,
  116. }
  117. updateUserProfile(params).then(res=>{
  118. if(rtes.code==200){
  119. console.log(res,9)
  120. }
  121. })
  122. }
  123. })
  124. jpushModule.isPushStopped(result=>{
  125. let code = result.code
  126. console.log('连接状态回调',result)
  127. });
  128. // 设置别名
  129. jpushModule.setAlias({
  130. 'alias' : 'coder',
  131. 'sequence': 1
  132. })
  133. jpushModule.addNotificationListener(result=>{
  134. let notificationEventType = result.notificationEventType
  135. let messageID = result.messageID
  136. let title = result.title
  137. let content = result.content
  138. let extras = result.extras
  139. console.log('通知事件回调',result)
  140. // 推送一个本地通知
  141. jpushModule.addLocalNotification({
  142. messageID,
  143. title,
  144. content,
  145. extras
  146. })
  147. })
  148. jpushModule.addNotificationListener(result => {
  149. console.log(result)
  150. if (result.notificationEventType == "notificationOpened") {
  151. //点击窗口通知栏推送的消息 跳转指定页面
  152. uni.reLaunch({
  153. url:'/pages/login'
  154. })
  155. }
  156. });
  157. //#endif
  158. },
  159. // 初始化应用
  160. initApp() {
  161. // 初始化应用配置
  162. this.initConfig()
  163. // 检查用户登录状态
  164. //#ifdef H5
  165. this.checkLogin()
  166. //#endif
  167. },
  168. initConfig() {
  169. this.globalData.config = config
  170. },
  171. checkLogin() {
  172. // if (!getToken()) {
  173. // this.$tab.reLaunch('/pages/login')
  174. // }
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss">
  180. @import '@/static/scss/index.scss';
  181. @import "@/static/style.css";
  182. </style>