version.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view>
  3. <view class="" style="width: 100%;height: 30rpx;background-color: #f7f7f7;">
  4. </view>
  5. <!-- <view class="gengxin_box" @click="update">
  6. <image src="../../static/image/pilianggengxin.png" mode="" class="gengxin"></image>
  7. <view class="gengxin_box_dian" v-if="newversion">
  8. </view>
  9. </view> -->
  10. <u-collapse>
  11. <u-collapse-item :title="item.app_version" name="Docs guide" v-for="(item,index) in versionlist"
  12. :key="item.app_version">
  13. <text class="u-collapse-content" v-for="items,indexs in item.app_message"
  14. :key="indexs">{{indexs+1+'、'}}{{items}}</text>
  15. </u-collapse-item>
  16. </u-collapse>
  17. <u-modal title="升级中请勿随意操作" :show-confirm-button="false" :show="showA" :content="contentA">
  18. <!-- <view class="upgradeBox"> -->
  19. <u-line-progress active-color="#19be6b" :percentage="percentNum" height="8"></u-line-progress>
  20. <!-- </view> -->
  21. </u-modal>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. current_version: plus.runtime.version,
  29. newversion: false,
  30. versionlist: [],
  31. showA: false,
  32. contentA: "",
  33. percentNum: 0,
  34. app_url:""
  35. }
  36. },
  37. watch: {
  38. showA(newName, oldName) {
  39. if(newName){
  40. const webView = this.$scope.$getAppWebview()
  41. webView.setStyle({
  42. titleNView: {
  43. autoBackButton: false
  44. }
  45. })
  46. }else{
  47. const webView = this.$scope.$getAppWebview()
  48. webView.setStyle({
  49. titleNView: {
  50. autoBackButton: true
  51. }
  52. })
  53. }
  54. },
  55. videoData(news, old) {
  56. console.log('触发了2222222222222222222222')
  57. console.log(news)
  58. uni.switchTab({
  59. url: '../response/index'
  60. })
  61. // if (news) {
  62. // }
  63. },
  64. },
  65. computed: {
  66. // 视频消息
  67. videoData() {
  68. return this.$store.state.video
  69. },
  70. },
  71. onNavigationBarButtonTap(e) {
  72. uni.$u.toast('更新中请勿操作')
  73. if (this.showA) {
  74. uni.$u.toast('更新中请勿操作')
  75. } else {
  76. this.update()
  77. }
  78. },
  79. onBackPress(options) {
  80. if (this.showA) {
  81. uni.$u.toast('更新中请勿操作')
  82. return true;
  83. 0
  84. }
  85. },
  86. methods: {
  87. async getversions() {
  88. const res = await this.$myRequest({
  89. url: '/api/api_gateway?method=app.my.get_app_history',
  90. data: {
  91. current_version: this.current_version
  92. }
  93. })
  94. // console.log(this.baseUrl)
  95. if (res.new_app.app_version) {
  96. this.app_url = res.new_app.app_url
  97. var news = res.new_app.app_version.match(/\d+/g).join("")
  98. var old = this.current_version.match(/\d+/g).join("")
  99. if (news > old) {
  100. this.newversion = true
  101. } else {
  102. this.newversion = false
  103. }
  104. }
  105. this.versionlist = res.version_list
  106. },
  107. update() {
  108. if (this.newversion) {
  109. uni.showModal({
  110. title: '检测到有新版本,是否更新?',
  111. content: '建议更新,不更新可能会出现部分数据无法获取!',
  112. confirmText: "更新",
  113. cancelText: "不更新",
  114. success: (res) => {
  115. if (res.confirm) {
  116. console.log('用户点击确定');
  117. this.showA = true
  118. this.upgrade()
  119. } else if (res.cancel) {
  120. // plus.runtime.quit();
  121. console.log('用户点击取消');
  122. }
  123. }
  124. })
  125. } else {
  126. uni.showToast({
  127. title: "当前版本已是最新版本",
  128. icon: "none"
  129. })
  130. }
  131. },
  132. upgrade() {
  133. //标准版
  134. // this.appName = "big_data"
  135. var url = this.baseUrl + this.app_url
  136. console.log(url)
  137. const downloadTask = uni.downloadFile({
  138. url: url, //仅为示例,并非真实的资源
  139. success: (res) => {
  140. console.log(res)
  141. if (res.statusCode === 200) {
  142. console.log('下载成功');
  143. console.log('安装包下载成功,即将安装:' + JSON.stringify(res, null, 4));
  144. plus.runtime.openFile(res.tempFilePath);
  145. this.showA = false
  146. }
  147. },
  148. fail: (err) => {
  149. console.log(err)
  150. },
  151. complete: (com) => {
  152. console.log(com)
  153. }
  154. });
  155. downloadTask.onProgressUpdate((res) => {
  156. this.percentNum = res.progress
  157. if (res.progress == 100) {
  158. console.log('下载完成了')
  159. plus.runtime.quit();
  160. }
  161. });
  162. }
  163. },
  164. onLoad() {
  165. this.getversions()
  166. }
  167. }
  168. </script>
  169. <style lang="less" scoped>
  170. .gengxin_box {
  171. width: 54rpx;
  172. height: 54rpx;
  173. position: absolute;
  174. top: -70rpx;
  175. right: 10rpx;
  176. z-index: 9999;
  177. display: flex;
  178. .gengxin {
  179. width: 44rpx;
  180. height: 44rpx;
  181. }
  182. .gengxin_box_dian {
  183. width: 10rpx;
  184. height: 10rpx;
  185. background-color: red;
  186. border-radius: 50%;
  187. margin: 0 5rpx;
  188. }
  189. }
  190. </style>