时空网前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
5.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <script>
  2. export default {
  3. globalData: {
  4. },
  5. onLaunch: function() {
  6. // this.login(); // 校验登录态 TODO 等待与后端对接
  7. },
  8. onShow: function() {
  9. // #ifdef MP-WEIXIN
  10. this.getUpdateWexin(); // 小程序更新检查
  11. // #endif
  12. },
  13. onHide: function() {
  14. console.log('App Hide')
  15. },
  16. methods: {
  17. // 接口code换取用户信息
  18. userCode(code){
  19. this.$http('', { code }).then(res => {
  20. console.log("获得用户信息", res);
  21. })
  22. },
  23. // 登录
  24. login(){
  25. this.checkSession().then(code => {
  26. this.userCode(code);
  27. }).catch(err => {
  28. uni.login({
  29. complete: result => {
  30. if(result.errMsg == 'login:ok'){
  31. let code = result.code;
  32. uni.setStorageSync('login_token', code);
  33. this.userCode(code);
  34. }
  35. }
  36. })
  37. });
  38. },
  39. // 校验登录态是否过期,如果没有过期还要判断本地有没有token
  40. checkSession(){
  41. return new Promise((resolve, reject) => {
  42. uni.checkSession({
  43. complete: result => {
  44. if(result.errMsg == 'checkSession:ok'){ // 处于登录状态 session未过期
  45. let login_token = uni.getStorageSync();
  46. if(login_token){
  47. resolve(login_token);
  48. }else{
  49. reject(); // 本地没有token,重新调取登录
  50. }
  51. }else{ // session已过期,需要重新登录
  52. reject();
  53. }
  54. }
  55. })
  56. });
  57. },
  58. // 小程序版本更新检查
  59. getUpdateWexin(){
  60. const updateManager = uni.getUpdateManager(); // 获取版本更新管理器对象
  61. updateManager.onCheckForUpdate(function(res) {
  62. // 请求完新版本信息的回调
  63. if (res.hasUpdate) {
  64. updateManager.onUpdateReady(function(res2) {
  65. uni.showModal({
  66. title: '更新提示',
  67. content: '发现新版本,是否重启应用?',
  68. confirmColor: '#FE9903',
  69. showCancel: false,
  70. success(res2) {
  71. if (res2.confirm) {
  72. // 新的版本已经下载好,调用applyUpdate应用新版本并重启
  73. updateManager.applyUpdate();
  74. }
  75. }
  76. });
  77. });
  78. }
  79. });
  80. updateManager.onUpdateFailed(function(res) {
  81. // 新的版本下载失败
  82. uni.showModal({
  83. title: '提示',
  84. content: '检查到有新版本,但下载失败,请检查网络设置',
  85. confirmColor: '#FE9903',
  86. success(res) {
  87. if (res.confirm) {
  88. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  89. updateManager.applyUpdate();
  90. }
  91. }
  92. });
  93. });
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss">
  99. @import "uview-ui/index.scss";
  100. @import './colorui/main.css';
  101. @import './colorui/icon.css';
  102. @import "@/colorui/animation.css";
  103. @import '@/common/styles/common.css';
  104. /*每个页面公共css */
  105. //底部按钮
  106. .btn-bottom {
  107. position: fixed;
  108. left: 0;
  109. bottom: 0;
  110. width: 100%;
  111. z-index: 1;
  112. }
  113. // loading加载
  114. .loading-more {
  115. align-items: center;
  116. justify-content: center;
  117. padding-top: 10px;
  118. padding-bottom: 10px;
  119. text-align: center;
  120. font-size: 28rpx;
  121. color: #999;
  122. }
  123. .loading-more-text::before {
  124. content: '';
  125. width: 20px;
  126. height: 20px;
  127. display: inline-block;
  128. vertical-align: middle;
  129. -webkit-animation: weuiLoading 1s steps(12, end) infinite;
  130. animation: weuiLoading 1s steps(12, end) infinite;
  131. background-repeat: no-repeat;
  132. background-image: url("data:image/svg+xml;charset=utf8, %3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 100 100'%3E%3Cpath fill='none' d='M0 0h100v100H0z'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23E9E9E9' rx='5' ry='5' transform='translate(0 -30)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23989697' rx='5' ry='5' transform='rotate(30 105.98 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%239B999A' rx='5' ry='5' transform='rotate(60 75.98 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23A3A1A2' rx='5' ry='5' transform='rotate(90 65 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23ABA9AA' rx='5' ry='5' transform='rotate(120 58.66 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23B2B2B2' rx='5' ry='5' transform='rotate(150 54.02 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23BAB8B9' rx='5' ry='5' transform='rotate(180 50 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23C2C0C1' rx='5' ry='5' transform='rotate(-150 45.98 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23CBCBCB' rx='5' ry='5' transform='rotate(-120 41.34 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23D2D2D2' rx='5' ry='5' transform='rotate(-90 35 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23DADADA' rx='5' ry='5' transform='rotate(-60 24.02 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23E2E2E2' rx='5' ry='5' transform='rotate(-30 -5.98 65)'/%3E%3C/svg%3E");
  133. background-size: 100%;
  134. }
  135. @-webkit-keyframes weuiLoading {
  136. 0% {
  137. transform: rotate3d(0, 0, 1, 0deg);
  138. }
  139. 100% {
  140. transform: rotate3d(0, 0, 1, 360deg);
  141. }
  142. }
  143. @keyframes weuiLoading {
  144. 0% {
  145. transform: rotate3d(0, 0, 1, 0deg);
  146. }
  147. 100% {
  148. transform: rotate3d(0, 0, 1, 360deg);
  149. }
  150. }
  151. </style>