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

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