updata.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <!-- 版本更新弹出框 -->
  3. <u-popup :show="isUpdateShow" mode="center">
  4. <view class="update-box" :class="bnList.url?'':'updateOverHeight'">
  5. <view class="update-text" v-if="bnList.url">
  6. <view class="title-text">
  7. 发现新版本
  8. </view>
  9. <view class="middle-text">
  10. 新版本V{{bnList.version}}
  11. </view>
  12. </view>
  13. <view class="update-text" v-else>
  14. <view class="title-text">
  15. 当前已是最新版本
  16. </view>
  17. <view class="middle-text">
  18. 当前V{{bnList.version}}
  19. </view>
  20. </view>
  21. <view class="percentStyle" v-if="progress">
  22. {{percent}}%
  23. </view>
  24. <view class="progress" v-if="progress">
  25. <u-line-progress height="22rpx" :showText="false" :percentage="percent" activeColor="#2675CE">
  26. </u-line-progress>
  27. </view>
  28. <view class="update-button" v-if="bnList.url">
  29. <u-button shape="circle" color="linear-gradient(to top, #F59A02, #FFD334 )" @tap="getKpi(bnList.url)"
  30. class="add-button width220 boderRadius buttonLang width220">
  31. {{progress?'停止更新':'马上更新'}}
  32. </u-button>
  33. <!-- <u-button @tap="isUpdateShow = false"
  34. class=" add-button boderRadius backWhtie colorYellow width220">暂不更新</u-button> -->
  35. </view>
  36. <view class="update-close" @tap="close">
  37. <u-icon size="66" color="#ffffff" name="close-circle"></u-icon>
  38. </view>
  39. </view>
  40. </u-popup>
  41. </template>
  42. <script>
  43. import {
  44. versionList
  45. } from "@/api/company/my.js"
  46. export default {
  47. name: "updata",
  48. props: {
  49. // 升级框的开关
  50. isUpdateShow: {
  51. type: Boolean,
  52. default: false
  53. },
  54. isLogin: {
  55. type: Boolean,
  56. default: false
  57. }
  58. },
  59. data() {
  60. return {
  61. oldVersion: null,
  62. downloadTask: null,
  63. progress: false,
  64. percent: 0,
  65. bnList: {
  66. version: "",
  67. oldVersion: "",
  68. url: ','
  69. },
  70. userId: null,
  71. versionCode: null
  72. };
  73. },
  74. watch: {
  75. isUpdateShow(newVal) {
  76. if (newVal) {
  77. this.getVersion()
  78. }
  79. },
  80. oldVersion(newVal) {
  81. if (newVal) {
  82. this.getVersionList()
  83. }
  84. }
  85. },
  86. methods: {
  87. // 按钮事件
  88. getKpi(url) {
  89. this.percent = 0
  90. this.progress = !this.progress
  91. // #ifdef APP-PLUS
  92. if (this.progress) {
  93. // 开始下载任务
  94. this.downloadTask = uni.downloadFile({
  95. url,
  96. // 接口调用成功
  97. success: (downloadResult) => {
  98. uni.hideLoading();
  99. if (downloadResult.statusCode === 200) {
  100. plus.runtime.install(downloadResult.tempFilePath, {
  101. force: false
  102. }, function() {
  103. plus.runtime.restart();
  104. }, function(e) {
  105. console.error('install fail...');
  106. });
  107. }
  108. },
  109. // 接口调用失败
  110. fail: (err) => {
  111. // uni.showToast({
  112. // icon: 'none',
  113. // mask: true,
  114. // title: '安装失败,请重新下载',
  115. // });
  116. },
  117. // 接口调用结束
  118. complete: () => {
  119. this.downloadTask.offProgressUpdate(); //取消监听加载进度
  120. }
  121. });
  122. //监听下载进度
  123. this.downloadTask.onProgressUpdate(res => {
  124. // state.percent = res.progress;
  125. this.percent = res.progress
  126. // console.log('下载进度百分比:' + res.progress); // 下载进度百分比
  127. // console.log('已经下载的数据长度:' + res.totalBytesWritten); // 已经下载的数据长度,单位 Bytes
  128. // console.log('预期需要下载的数据总长度:' + res.totalBytesExpectedToWrite); // 预期需要下载的数据总长度,单位 Bytes
  129. })
  130. } else {
  131. // 中断下载
  132. this.downloadTask.abort()
  133. }
  134. // #endif
  135. },
  136. getVersion() {
  137. //#ifdef APP-PLUS
  138. // 获取本地应用资源版本号
  139. plus.runtime.getProperty(plus.runtime.appid, (info) => {
  140. console.log(JSON.stringify(info));
  141. this.oldVersion = info.version
  142. let versionCode = this.oldVersion
  143. let arr = versionCode.split('.')
  144. this.versionCode = arr.join('')
  145. console.log(this.oldVersion);
  146. console.log(this.versionCode);
  147. })
  148. //#endif
  149. },
  150. // 关闭事件
  151. close() {
  152. this.$emit('close', false)
  153. },
  154. getVersionList() {
  155. if (this.isLogin) {
  156. let obj = {}
  157. obj.versionNo = 'admin'
  158. obj.userId = ''
  159. console.log(obj);
  160. versionList(obj).then(res => {
  161. console.log('登录页更新', res);
  162. let versionCode = res.data.versionNo
  163. let arr = versionCode.split('.')
  164. let versionNum = arr.join('')
  165. // versionCode.replace(/./g, '')
  166. console.log('版本数字', versionNum);
  167. if (+versionNum <= +this.versionCode) {
  168. this.bnList.url = ''
  169. this.bnList.version = this.oldVersion
  170. this.$emit('loginShow', false)
  171. } else {
  172. this.bnList.url = res.data.url;
  173. this.bnList.version = res.data.versionNo
  174. console.log(this.bnList);
  175. this.$emit('loginShow', true)
  176. }
  177. })
  178. } else {
  179. let obj = {}
  180. obj.versionNo = this.oldVersion
  181. obj.userId = this.userId
  182. console.log(obj);
  183. versionList(obj).then(res => {
  184. console.log('版本', res);
  185. let versionCode = res.data.versionNo
  186. let arr = versionCode.split('.')
  187. let versionNum = arr.join('')
  188. this.bnList.oldVersion = this.oldVersion;
  189. this.bnList.version = res.data.versionNo
  190. if (+versionNum <= +this.versionCode) {
  191. this.bnList.url = ''
  192. this.bnList.version = this.oldVersion
  193. console.log(this.bnList);
  194. } else {
  195. this.bnList.url = res.data.url;
  196. console.log(this.bnList);
  197. }
  198. console.log(this.bnList);
  199. // this.versionCode = info.versionCode ;
  200. })
  201. }
  202. }
  203. },
  204. mounted() {
  205. this.userId = this.$store.state.user.userId
  206. if (this.isLogin) {
  207. this.getVersion()
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. /deep/.u-popup__content {
  214. border-radius: 18rpx;
  215. }
  216. // 进度条样式
  217. .progress {
  218. margin: 18rpx auto 0;
  219. width: 388rpx;
  220. }
  221. .percentStyle {
  222. width: 100%;
  223. text-align: center;
  224. font-size: 26rpx;
  225. color: #2675CE;
  226. }
  227. .updateOverHeight {
  228. height: 480rpx !important;
  229. }
  230. .update-box {
  231. width: 543rpx;
  232. height: 630rpx;
  233. background: url(../../static/images/home/update.png);
  234. background-size: 100%;
  235. position: relative;
  236. border-radius: 16rpx;
  237. .update-text {
  238. text-align: center;
  239. margin-top: 330rpx;
  240. .title-text {
  241. font-size: 36rpx;
  242. color: #333333;
  243. font-weight: bold;
  244. }
  245. .middle-text {
  246. font-size: 26rpx;
  247. color: rgba(153, 153, 153, 1);
  248. font-weight: 400;
  249. margin-top: 16rpx;
  250. }
  251. }
  252. .update-button {
  253. display: flex;
  254. justify-content: center;
  255. /deep/ uni-button {
  256. margin-top: 47rpx;
  257. // &:nth-child(1) {
  258. // margin-right: 13rpx;
  259. // }
  260. // &:nth-child(2) {
  261. // margin-left: 13rpx;
  262. // }
  263. }
  264. }
  265. .update-close {
  266. position: absolute;
  267. text-align: center;
  268. left: 50%;
  269. transform: translate(-50%);
  270. bottom: -80rpx;
  271. }
  272. }
  273. .width220 {
  274. width: 220rpx;
  275. height: 68rpx !important;
  276. }
  277. .boderRadius {
  278. border-radius: 68rpx !important;
  279. }
  280. </style>