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

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