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

159 lines
5.2 KiB

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