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

155 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. wxlogin: () => {}
  5. },
  6. onLaunch: function() {
  7. this.disableConsole();
  8. this.getUserInfo();
  9. },
  10. onShow: function() {
  11. // #ifdef MP-WEIXIN
  12. this.getUpdateWexin(); // 小程序更新检查
  13. // #endif
  14. },
  15. onHide: function() {
  16. console.log('App Hide')
  17. },
  18. methods: {
  19. // 获取用户信息
  20. getUserInfo(){
  21. this.globalData.wxlogin = this.wxlogin;
  22. // 检查用户是否点击的退出登录按钮
  23. // let quit_login_state = uni.getStorageSync('quit_login_state');
  24. // if(quit_login_state){
  25. // return;
  26. // }
  27. // 去缓存判断有无用户信息
  28. let userinfo = uni.getStorageSync('userinfo');
  29. if(userinfo && userinfo.id){
  30. return;
  31. }
  32. this.globalData.wxlogin();
  33. },
  34. wxlogin(){
  35. return new Promise((resolve, rejecj) => {
  36. uni.login({
  37. complete: result => {
  38. if(result.errMsg == 'login:ok'){
  39. let code = result.code;
  40. this.$http(this.API.API_WXLOGIN, { code }).then(res => {
  41. console.log("获得用户信息", res);
  42. uni.setStorageSync('userinfo', res.data);
  43. resolve(res.data);
  44. })
  45. }
  46. }
  47. })
  48. })
  49. },
  50. // 小程序版本更新检查
  51. getUpdateWexin(){
  52. const updateManager = uni.getUpdateManager(); // 获取版本更新管理器对象
  53. updateManager.onCheckForUpdate(function(res) {
  54. // 请求完新版本信息的回调
  55. if (res.hasUpdate) {
  56. updateManager.onUpdateReady(function(res2) {
  57. uni.showModal({
  58. title: '更新提示',
  59. content: '发现新版本,是否重启应用?',
  60. confirmColor: '#FE9903',
  61. showCancel: false,
  62. success(res2) {
  63. if (res2.confirm) {
  64. // 新的版本已经下载好,调用applyUpdate应用新版本并重启
  65. updateManager.applyUpdate();
  66. }
  67. }
  68. });
  69. });
  70. }
  71. });
  72. updateManager.onUpdateFailed(function(res) {
  73. // 新的版本下载失败
  74. uni.showModal({
  75. title: '提示',
  76. content: '检查到有新版本,但下载失败,请检查网络设置',
  77. confirmColor: '#FE9903',
  78. success(res) {
  79. if (res.confirm) {
  80. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  81. updateManager.applyUpdate();
  82. }
  83. }
  84. });
  85. });
  86. },
  87. // 判断正式服屏蔽console输出
  88. disableConsole(){
  89. if(this.API.DEV == 'prod'){
  90. console.log = () => {};
  91. }
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="scss">
  97. @import "uview-ui/index.scss";
  98. @import './colorui/main.css';
  99. @import './colorui/icon.css';
  100. @import "@/colorui/animation.css";
  101. @import '@/common/styles/common.css';
  102. @import "@/common/styles/iconfont.css";
  103. /*每个页面公共css */
  104. //底部按钮
  105. .btn-bottom {
  106. position: fixed;
  107. left: 0;
  108. bottom: 0;
  109. width: 100%;
  110. z-index: 1;
  111. }
  112. // loading加载
  113. .loading-more {
  114. align-items: center;
  115. justify-content: center;
  116. padding-top: 10px;
  117. padding-bottom: 10px;
  118. text-align: center;
  119. font-size: 28rpx;
  120. color: #999;
  121. }
  122. .loading-more-text::before {
  123. content: '';
  124. width: 20px;
  125. height: 20px;
  126. display: inline-block;
  127. vertical-align: middle;
  128. -webkit-animation: weuiLoading 1s steps(12, end) infinite;
  129. animation: weuiLoading 1s steps(12, end) infinite;
  130. background-repeat: no-repeat;
  131. 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");
  132. background-size: 100%;
  133. }
  134. @-webkit-keyframes weuiLoading {
  135. 0% {
  136. transform: rotate3d(0, 0, 1, 0deg);
  137. }
  138. 100% {
  139. transform: rotate3d(0, 0, 1, 360deg);
  140. }
  141. }
  142. @keyframes weuiLoading {
  143. 0% {
  144. transform: rotate3d(0, 0, 1, 0deg);
  145. }
  146. 100% {
  147. transform: rotate3d(0, 0, 1, 360deg);
  148. }
  149. }
  150. </style>