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

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