nc-update.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view>
  3. <uni-popup ref="updatePopup" type="center" :maskClick="false" v-if="versionInfo">
  4. <view class="update-wrap">
  5. <view class="head"><image :src="$util.img('public/uniapp/cashier/update_header.png')"></image></view>
  6. <view class="body">
  7. <view class="version-no">版本号:{{ versionInfo.version }}</view>
  8. <view class="title">更新内容</view>
  9. <view class="desc common-scrollbar">{{ versionInfo.update_desc }}</view>
  10. <button type="default" class="primary-btn" @click="update">立即更新</button>
  11. <view class="giveup-update" @click="giveupUpdate" v-if="!versionInfo.is_force_upgrade">以后再说</view>
  12. </view>
  13. </view>
  14. </uni-popup>
  15. </view>
  16. </template>
  17. <script>
  18. /**
  19. * app版本更新
  20. */
  21. export default {
  22. data() {
  23. return {
  24. versionInfo: null
  25. };
  26. },
  27. created() {
  28. // wifi模式下才检测升级
  29. if (plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_WIFI) {
  30. this.checkUpdate();
  31. }
  32. },
  33. methods: {
  34. /**
  35. * 检测是否有新版本
  36. */
  37. checkUpdate() {
  38. this.$api.sendRequest({
  39. url: '/cashier/storeapi/appversion/checkupdate',
  40. data: {
  41. app_key: this.$config.app.app_key,
  42. version: this.$config.app.version_no,
  43. platform: uni.getSystemInfoSync().platform
  44. },
  45. success: res => {
  46. if (res.code == 0 && res.data) {
  47. this.versionInfo = res.data;
  48. if (!uni.getStorageSync('version_' + this.versionInfo.version_no)) {
  49. this.$refs.updatePopup.open();
  50. }
  51. }
  52. }
  53. });
  54. },
  55. /**
  56. * 确认更新
  57. */
  58. update() {
  59. let systemInfo = uni.getSystemInfoSync();
  60. if (systemInfo.platform == 'android') {
  61. uni.showLoading({});
  62. uni.downloadFile({
  63. url: this.$util.img(this.versionInfo.package_path),
  64. success: data => {
  65. uni.hideLoading();
  66. if (data.statusCode === 200) {
  67. plus.runtime.install(
  68. data.tempFilePath,
  69. {
  70. force: false
  71. },
  72. function() {
  73. plus.runtime.restart();
  74. }
  75. );
  76. }
  77. },
  78. fail: res => {
  79. this.$util.showToast({ title: '安装包下载失败' });
  80. uni.hideLoading();
  81. }
  82. });
  83. } else if (systemInfo.platform == 'ios') {
  84. plus.runtime.launchApplication({ action: this.versionInfo.package_path }, e => {
  85. this.$util.showToast({ title: e.message });
  86. this.$refs.updatePopup.close();
  87. });
  88. }
  89. },
  90. /**
  91. * 放弃本次更新
  92. */
  93. giveupUpdate() {
  94. uni.setStorageSync('version_' + this.versionInfo.version_no, 1);
  95. this.$refs.updatePopup.close();
  96. }
  97. }
  98. };
  99. </script>
  100. <style lang="scss">
  101. .update-wrap {
  102. width: 3rem;
  103. .head {
  104. height: 0.98rem;
  105. image {
  106. width: 3rem;
  107. height: 0.98rem;
  108. }
  109. }
  110. .body {
  111. padding: 0.2rem 0.3rem;
  112. background: #fff;
  113. .version-no {
  114. margin-bottom: 0.15rem;
  115. }
  116. .desc {
  117. max-height: 1rem;
  118. }
  119. .title {
  120. font-size: 0.16rem;
  121. font-weight: 700;
  122. margin-bottom: 0.15rem;
  123. }
  124. .primary-btn {
  125. margin-top: 0.15rem;
  126. }
  127. .giveup-update {
  128. margin-top: 0.15rem;
  129. text-align: center;
  130. line-height: 1;
  131. }
  132. }
  133. }
  134. /deep/ .uni-popup {
  135. z-index: 1010;
  136. }
  137. </style>