system-set.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view class="system-set">
  3. <custom-nav ref="ltm" :title="title" />
  4. <view class="content">
  5. <navigator class="app-item" url="../problem-feedback/problem-feedback">
  6. <text>问题反馈</text>
  7. <text class="cuIcon-right"></text>
  8. </navigator>
  9. <navigator class="app-item" url="../user-agreement/user-agreement">
  10. <text>用户协议</text>
  11. <text class="cuIcon-right"></text>
  12. </navigator>
  13. <view class="app-item item-space" @tap="checkoutNew">
  14. <text>检查更新</text>
  15. <text class="cuIcon-refresh"></text>
  16. </view>
  17. <view class="app-item" @tap="clearStorage">
  18. <text>清除缓存</text>
  19. <text class="cuIcon-right"></text>
  20. </view>
  21. <navigator class="app-item" url="../about-us/about-us">
  22. <text>关于我们</text>
  23. <text class="cuIcon-right"></text>
  24. </navigator>
  25. <view class="big-btn" @tap="logout">退出登录</view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import { _API_AppUpdata } from '@/apis/app.js'
  31. export default {
  32. data() {
  33. return {
  34. title: '系统设置'
  35. }
  36. },
  37. computed: {
  38. screenWidth() { return this.$store.state.device.screenWidth }, // 屏幕宽
  39. screenHeight() { return this.$store.state.device.screenHeight }, // 屏幕高
  40. },
  41. methods: {
  42. checkoutNew() { // 点击检查更新
  43. if (uni.UPDATING) {
  44. this.$refs.ltm.toast('新版本正在下载中:' + uni.UPDATAPROGRESS + '%')
  45. } else {
  46. this.$refs.ltm.loading()
  47. _API_AppUpdata().then(res => { // 获取更新链接
  48. if (res.data.version !== this.$store.state.app.version) { // 有新版本 /////////////////////////////
  49. const position = this.getNativeObjPosition(560/681)
  50. const pn = this.getNativeObjPosition(560/681)
  51. Object.keys(pn).forEach(key => pn[key] = Number(pn[key].split('px')[0]))
  52. const UPDATA = new plus.nativeObj.View('auth', // 定义升级弹窗
  53. { top:'0px', left:'0px', height:'100%', width:'100%', backgroundColor: "rgba(0, 0 , 0, 0.6)" },
  54. [
  55. { tag:'img', id:'authImg', src: '/static/icon/appupdata.png', position },
  56. { tag:'font', id:'font1', text:'版本号:' + res.data.version,
  57. textStyles:{ size: '18px', align: 'left', whiteSpace: 'normal', verticalAlign: 'top' },
  58. position:{ top: pn.top+pn.height/2-18+'px', left: pn.left+20+'px', width: '100%', height: '36px' },
  59. },
  60. {
  61. tag:'font',
  62. id:'font2',
  63. text:res.data.message,
  64. textStyles:{ size: '16px', align: 'left', whiteSpace: 'normal', verticalAlign: 'top', overflow: 'ellipsis' },
  65. position:{ top: pn.top+pn.height/2+14 + 'px', left: pn.left+30+ 'px', width: pn.width-60 + 'px', height: pn.height/4 + 'px' },
  66. },
  67. ],
  68. )
  69. UPDATA.addEventListener('click', e => { // 点击弹窗升级app
  70. if (this.isClickInArea(e, 560/681)) { // 如果点击图片区
  71. UPDATA.close() // 关闭弹窗
  72. this.$refs.ltm.modal('提示', ['新版本将在后台下载', '下载成功后会提示您安装'], 'noCancle').then(() => { // 提示后台下载
  73. uni.UPDATING = true // 标记 app 正在下载状态 为 true
  74. uni.UNIPROGRESS = 0 // 设置 app 下载进度为 0
  75. const downloadTask = _API_DownLoadNewVersion(res.data.url) // 发送请求
  76. downloadTask.onProgressUpdate((e) => uni.UNIPROGRESS = e.progress ) // 更新进度
  77. downloadTask.then(({ tempFilePath }) => { // app 下载成功后弹窗通知
  78. uni.UPDATING = false // 标记 app 正在下载状态 为 false
  79. uni.$emit('UPDATAAPP', tempFilePath) // 通知弹窗弹出
  80. } )
  81. })
  82. } else { // 如果点击背景区
  83. UPDATA.close()
  84. }
  85. })
  86. UPDATA.show() // 弹出升级弹窗
  87. } else {
  88. this.$refs.ltm.toast('已是最新版本')
  89. }
  90. })
  91. }
  92. },
  93. getNativeObjPosition(as) {
  94. const width = this.screenWidth * 0.8
  95. const height = width / as
  96. const top = (this.screenHeight - height) / 2
  97. const left = (this.screenWidth - width) / 2
  98. return {
  99. width: Math.floor(width) + 'px',
  100. height: Math.floor(height) + 'px',
  101. top: Math.floor(top) + 'px',
  102. left: Math.floor(left) + 'px'
  103. }
  104. },
  105. isClickInArea(e, as) { // 只有点击图片区域才返回 true
  106. let p = this.getNativeObjPosition(as)
  107. Object.keys(p).forEach(key => p[key] = Number(p[key].split('px')[0]))
  108. if ((e.pageX >= p.left) && (e.pageX <= (p.left + p.width)) && (e.pageY >= p.top) && (e.pageY <= (p.top + p.height))) {
  109. return true
  110. }
  111. },
  112. clearStorage() { // 点击清除缓存
  113. this.$refs.ltm.modal('提示', ['确定清除已经缓存的数据?']).then(() => {
  114. this.$store.commit('message/clearStorage')
  115. this.$refs.ltm.toast('清除成功')
  116. }).catch(() => {
  117. this.$refs.ltm.toast('取消清除')
  118. })
  119. },
  120. logout() { // 点击退出登录
  121. this.$store.commit('app/LOGOUT')
  122. uni.reLaunch({ url: '../login-reg/login-reg' })
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss">
  128. .system-set {
  129. @include page();
  130. }
  131. </style>