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

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