时空网前端
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.

158 lines
5.2 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. return console.log("code", code);
  20. this.$http('', { code }).then(res => {
  21. console.log("获得用户信息", res);
  22. })
  23. },
  24. // 登录
  25. login(){
  26. this.checkSession().then(code => {
  27. this.userCode(code);
  28. }).catch(err => {
  29. uni.login({
  30. complete: result => {
  31. if(result.errMsg == 'login:ok'){
  32. let code = result.code;
  33. uni.setStorageSync('login_token', code);
  34. this.userCode(code);
  35. }
  36. }
  37. })
  38. });
  39. },
  40. // 校验登录态是否过期,如果没有过期还要判断本地有没有token
  41. checkSession(){
  42. return new Promise((resolve, reject) => {
  43. uni.checkSession({
  44. complete: result => {
  45. if(result.errMsg == 'checkSession:ok'){ // 处于登录状态 session未过期
  46. let login_token = uni.getStorageSync('login_token');
  47. if(login_token){
  48. resolve(login_token);
  49. }else{
  50. reject(); // 本地没有token,重新调取登录
  51. }
  52. }else{ // session已过期,需要重新登录
  53. reject();
  54. }
  55. }
  56. })
  57. });
  58. },
  59. // 小程序版本更新检查
  60. getUpdateWexin(){
  61. const updateManager = uni.getUpdateManager(); // 获取版本更新管理器对象
  62. updateManager.onCheckForUpdate(function(res) {
  63. // 请求完新版本信息的回调
  64. if (res.hasUpdate) {
  65. updateManager.onUpdateReady(function(res2) {
  66. uni.showModal({
  67. title: '更新提示',
  68. content: '发现新版本,是否重启应用?',
  69. confirmColor: '#FE9903',
  70. showCancel: false,
  71. success(res2) {
  72. if (res2.confirm) {
  73. // 新的版本已经下载好,调用applyUpdate应用新版本并重启
  74. updateManager.applyUpdate();
  75. }
  76. }
  77. });
  78. });
  79. }
  80. });
  81. updateManager.onUpdateFailed(function(res) {
  82. // 新的版本下载失败
  83. uni.showModal({
  84. title: '提示',
  85. content: '检查到有新版本,但下载失败,请检查网络设置',
  86. confirmColor: '#FE9903',
  87. success(res) {
  88. if (res.confirm) {
  89. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  90. updateManager.applyUpdate();
  91. }
  92. }
  93. });
  94. });
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="scss">
  100. @import "uview-ui/index.scss";
  101. @import './colorui/main.css';
  102. @import './colorui/icon.css';
  103. @import "@/colorui/animation.css";
  104. @import '@/common/styles/common.css';
  105. /*每个页面公共css */
  106. //底部按钮
  107. .btn-bottom {
  108. position: fixed;
  109. left: 0;
  110. bottom: 0;
  111. width: 100%;
  112. z-index: 1;
  113. }
  114. // loading加载
  115. .loading-more {
  116. align-items: center;
  117. justify-content: center;
  118. padding-top: 10px;
  119. padding-bottom: 10px;
  120. text-align: center;
  121. font-size: 28rpx;
  122. color: #999;
  123. }
  124. .loading-more-text::before {
  125. content: '';
  126. width: 20px;
  127. height: 20px;
  128. display: inline-block;
  129. vertical-align: middle;
  130. -webkit-animation: weuiLoading 1s steps(12, end) infinite;
  131. animation: weuiLoading 1s steps(12, end) infinite;
  132. background-repeat: no-repeat;
  133. 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");
  134. background-size: 100%;
  135. }
  136. @-webkit-keyframes weuiLoading {
  137. 0% {
  138. transform: rotate3d(0, 0, 1, 0deg);
  139. }
  140. 100% {
  141. transform: rotate3d(0, 0, 1, 360deg);
  142. }
  143. }
  144. @keyframes weuiLoading {
  145. 0% {
  146. transform: rotate3d(0, 0, 1, 0deg);
  147. }
  148. 100% {
  149. transform: rotate3d(0, 0, 1, 360deg);
  150. }
  151. }
  152. </style>