App.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <script>
  2. import config from './config'
  3. import store from '@/store'
  4. import { getToken } from '@/utils/auth'
  5. // const jpushModule = uni.requireNativePlugin('JG-JPush')
  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. // this.platform=uni.getSystemInfoSync().platform;
  16. // console.log(this.platform,1)
  17. this.initApp()
  18. // #ifdef APP
  19. var url=baseUrl;
  20. if(url.indexOf('https://qszs.qs163.cn')!=-1){
  21. this.getJGtuifn()
  22. this.onlineWgt(); //版本更新
  23. }else{
  24. }
  25. // #endif
  26. // console.log(jpushModule)
  27. },
  28. methods: {
  29. //热更新
  30. // 在线跟新
  31. onlineWgt() {
  32. let that = this;
  33. plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
  34. that.$store.dispatch('SetwgtFn',widgetInfo.version).then(()=>{
  35. })
  36. that.comparisonVersionNo(widgetInfo.versionCode);
  37. });
  38. // that.comparisonVersionNo()
  39. },
  40. comparisonVersionNo(versionCode) {
  41. let that = this;
  42. // console.log("aaaaaaa===versionCode", versionCode);
  43. const parmas = {
  44. model: that.platform
  45. }
  46. findVersion(parmas).then(res => {
  47. if (res.code == "200") {
  48. let versionNos = res.data.code;
  49. console.log(versionNos,'versionNos')
  50. // console.log(res.data.path);
  51. let filePath = res.data.path;
  52. if (versionNos != versionCode) { //服务器返回1更新,0则不更新
  53. uni.showModal({
  54. title: '提示',
  55. content: '发现新版本,是否升级',
  56. success: function(res) {
  57. // console.log(widgetInfo.version);
  58. if (res.confirm) {
  59. console.log('用户点击确定');
  60. that.getProperty(filePath);
  61. } else if (res.cancel) {
  62. console.log('用户点击取消');
  63. }
  64. }
  65. });
  66. }
  67. }
  68. }).catch(error=>{
  69. uni.hideLoading()
  70. console.log(error)
  71. })
  72. },
  73. getProperty(getProperty) {
  74. // console.log("bbbbbbbbb----------->", getProperty)
  75. let that = this;
  76. // 在线升级app/热更新
  77. that.showwri = true;
  78. const downloadTask = uni.downloadFile({ //下载文件
  79. url: baseUrl + getProperty,
  80. success: (downloadResult) => {
  81. // console.log(downloadResult);
  82. if (downloadResult.statusCode == 200) {
  83. // 更新升级
  84. plus.runtime.install(downloadResult.tempFilePath, {
  85. force: true
  86. }, function() {
  87. // console.log('install success...');
  88. that.showwri = false;
  89. plus.nativeUI.alert("应用资源更新完成!", function() {
  90. plus.runtime.restart();
  91. });
  92. }, function(e) {
  93. that.showwri = false;
  94. plus.nativeUI.alert("更新失败,请稍后再试");
  95. });
  96. }
  97. }
  98. });
  99. downloadTask.onProgressUpdate((res) => { //下载文件的进度
  100. that.totalBytesWritten = res.totalBytesWritten; //当前下载大小
  101. that.progress = res.progress; //当前下载比例
  102. that.totalBytesExpectedToWrite = res.totalBytesExpectedToWrite; //
  103. });
  104. },
  105. // 极光推送
  106. getJGtuifn(){
  107. //#ifdef APP-PLUS
  108. var jpushModule = uni.requireNativePlugin("JG-JPush");
  109. jpushModule.setLoggerEnable(true);
  110. // 初始化函数
  111. jpushModule.initJPushService();
  112. jpushModule.addConnectEventListener(result=>{
  113. let connectEnable = result.connectEnable
  114. // console.log("jpush连接", connectEnable)
  115. })
  116. jpushModule.getRegistrationID(result => {
  117. // console.log("注册ID.....",result)
  118. this.registerID = result.registerID;
  119. if(getToken()){
  120. var params={
  121. jgId:this.registerID,
  122. }
  123. updateUserProfile(params).then(res=>{
  124. if(rtes.code==200){
  125. console.log(res,9)
  126. }
  127. })
  128. }
  129. })
  130. jpushModule.isPushStopped(result=>{
  131. let code = result.code
  132. console.log('连接状态回调',result)
  133. });
  134. // 设置别名
  135. jpushModule.setAlias({
  136. 'alias' : 'coder',
  137. 'sequence': 1
  138. })
  139. jpushModule.addNotificationListener(result=>{
  140. let notificationEventType = result.notificationEventType
  141. let messageID = result.messageID
  142. let title = result.title
  143. let content = result.content
  144. let extras = result.extras
  145. console.log('通知事件回调',result)
  146. // 推送一个本地通知
  147. jpushModule.addLocalNotification({
  148. messageID,
  149. title,
  150. content,
  151. extras
  152. })
  153. })
  154. jpushModule.addNotificationListener(result => {
  155. console.log(result)
  156. if (result.notificationEventType == "notificationOpened") {
  157. //点击窗口通知栏推送的消息 跳转指定页面
  158. uni.reLaunch({
  159. url:'/pages/login'
  160. })
  161. }
  162. });
  163. //#endif
  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. page{background-color: #ffffff;}
  187. @import '@/static/scss/index.scss';
  188. @import "@/static/style.css";
  189. .uni-tabbar .uni-tabbar__label{
  190. font-size: 32rpx !important;
  191. }
  192. // tab图标
  193. .uni-tabbar .uni-tabbar__icon {
  194. width: 50rpx !important;
  195. height: 50rpx !important;
  196. }
  197. /* #ifdef APP */
  198. /deep/ .uni-picker-container .uni-picker-header{background-color: #FA5F03;}
  199. /* #endif */
  200. // .inform /deep/ .uni-input-input{text-align: right;font-size: 32rpx;color: #343434;}
  201. // .inform /deep/ .uni-easyinput__placeholder-class{text-align: right;font-size: 32rpx !important;color: #808080;}
  202. </style>