海南旅游项目 前端仓库
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.

163 lines
5.7 KiB

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