App.vue 5.3 KB

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