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

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