version.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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: "",
  29. newversion: false,
  30. versionlist: [],
  31. showA: false,
  32. contentA: "",
  33. percentNum: 0,
  34. }
  35. },
  36. watch: {
  37. showA(newName, oldName) {
  38. if(newName){
  39. const webView = this.$scope.$getAppWebview()
  40. webView.setStyle({
  41. titleNView: {
  42. autoBackButton: false
  43. }
  44. })
  45. }else{
  46. const webView = this.$scope.$getAppWebview()
  47. webView.setStyle({
  48. titleNView: {
  49. autoBackButton: true
  50. }
  51. })
  52. }
  53. }
  54. },
  55. onNavigationBarButtonTap(e) {
  56. uni.$u.toast('更新中请勿操作')
  57. if (this.showA) {
  58. uni.$u.toast('更新中请勿操作')
  59. } else {
  60. this.update()
  61. }
  62. },
  63. onBackPress(options) {
  64. if (this.showA) {
  65. uni.$u.toast('更新中请勿操作')
  66. return true;
  67. 0
  68. }
  69. },
  70. methods: {
  71. async getversions() {
  72. const res = await this.$myRequest({
  73. url: '/api/api_gateway?method=app.my.get_app_history',
  74. data: {
  75. current_version: this.current_version
  76. }
  77. })
  78. if (res.new_app.app_version) {
  79. var news = res.new_app.app_version.match(/\d+/g).join("")
  80. var old = this.current_version.match(/\d+/g).join("")
  81. if (news > old) {
  82. this.newversion = true
  83. } else {
  84. this.newversion = false
  85. }
  86. }
  87. this.versionlist = res.version_list
  88. },
  89. update() {
  90. if (this.newversion) {
  91. uni.showModal({
  92. title: '检测到有新版本,是否更新?',
  93. content: '建议更新,不更新可能会出现部分数据无法获取!',
  94. confirmText: "更新",
  95. cancelText: "不更新",
  96. success: (res) => {
  97. if (res.confirm) {
  98. console.log('用户点击确定');
  99. this.showA = true
  100. this.upgrade()
  101. } else if (res.cancel) {
  102. // plus.runtime.quit();
  103. console.log('用户点击取消');
  104. }
  105. }
  106. })
  107. } else {
  108. uni.showToast({
  109. title: "当前版本已是最新版本",
  110. icon: "none"
  111. })
  112. }
  113. },
  114. upgrade() {
  115. //标准版
  116. // this.appName = "big_data"
  117. var url = "http://hnyfwlw.com/app/big_data.apk"
  118. console.log(url)
  119. const downloadTask = uni.downloadFile({
  120. url: url, //仅为示例,并非真实的资源
  121. success: (res) => {
  122. console.log(res)
  123. if (res.statusCode === 200) {
  124. console.log('下载成功');
  125. console.log('安装包下载成功,即将安装:' + JSON.stringify(res, null, 4));
  126. plus.runtime.openFile(res.tempFilePath);
  127. this.showA = false
  128. }
  129. },
  130. fail: (err) => {
  131. console.log(err)
  132. },
  133. complete: (com) => {
  134. console.log(com)
  135. }
  136. });
  137. downloadTask.onProgressUpdate((res) => {
  138. this.percentNum = res.progress
  139. if (res.progress == 100) {
  140. console.log('下载完成了')
  141. plus.runtime.quit();
  142. }
  143. });
  144. }
  145. },
  146. onLoad(option) {
  147. console.log(option)
  148. this.current_version = option.id
  149. this.getversions()
  150. }
  151. }
  152. </script>
  153. <style lang="less" scoped>
  154. .gengxin_box {
  155. width: 54rpx;
  156. height: 54rpx;
  157. position: absolute;
  158. top: -70rpx;
  159. right: 10rpx;
  160. z-index: 9999;
  161. display: flex;
  162. .gengxin {
  163. width: 44rpx;
  164. height: 44rpx;
  165. }
  166. .gengxin_box_dian {
  167. width: 10rpx;
  168. height: 10rpx;
  169. background-color: red;
  170. border-radius: 50%;
  171. margin: 0 5rpx;
  172. }
  173. }
  174. </style>