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

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