App.vue 5.2 KB

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