App.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. var jpushModule = uni.requireNativePlugin("JG-JPush");
  107. jpushModule.setLoggerEnable(true);
  108. // 初始化函数
  109. jpushModule.initJPushService();
  110. jpushModule.addConnectEventListener(result=>{
  111. let connectEnable = result.connectEnable
  112. // console.log("jpush连接", connectEnable)
  113. })
  114. jpushModule.getRegistrationID(result => {
  115. // console.log("注册ID.....",result)
  116. this.registerID = result.registerID;
  117. if(getToken()){
  118. var params={
  119. jgId:this.registerID,
  120. }
  121. updateUserProfile(params).then(res=>{
  122. if(res.code==200){
  123. console.log(res,9)
  124. }
  125. })
  126. }
  127. })
  128. jpushModule.isPushStopped(result=>{
  129. let code = result.code
  130. console.log('连接状态回调',result)
  131. });
  132. // 设置别名
  133. jpushModule.setAlias({
  134. 'alias' : 'coder',
  135. 'sequence': 1
  136. })
  137. jpushModule.addNotificationListener(result=>{
  138. let notificationEventType = result.notificationEventType
  139. let messageID = result.messageID
  140. let title = result.title
  141. let content = result.content
  142. let extras = result.extras
  143. console.log('通知事件回调',result)
  144. // 推送一个本地通知
  145. jpushModule.addLocalNotification({
  146. messageID,
  147. title,
  148. content,
  149. extras
  150. })
  151. })
  152. jpushModule.addNotificationListener(result => {
  153. if (result.notificationEventType == "notificationOpened") {
  154. //点击窗口通知栏推送的消息 跳转指定页面
  155. // uni.reLaunch({
  156. // url:'/pages/index/index'
  157. // })
  158. this.$tab.navigateTo("/pages/index/notice?type=dbtz")
  159. // uni.reLaunch({
  160. // url:'/pages/index/notice?type=dbtz'
  161. // })
  162. }
  163. });
  164. },
  165. // 初始化应用
  166. initApp() {
  167. // 初始化应用配置
  168. this.initConfig()
  169. // 检查用户登录状态
  170. //#ifdef H5
  171. this.checkLogin()
  172. //#endif
  173. },
  174. initConfig() {
  175. this.globalData.config = config
  176. },
  177. checkLogin() {
  178. // if (!getToken()) {
  179. // this.$tab.reLaunch('/pages/login')
  180. // }
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss">
  186. @import '@/static/scss/index.scss';
  187. @import "@/static/style.css";
  188. </style>