index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view>
  3. <!-- index.wxml -->
  4. <van-icon name="arrow-left" color="#333333" size="26" class="huitui" v-if="showBack" :style="'top:' + customCenter + 'px'" @tap.native="goback" />
  5. <view class="header_wrap" :style="'height:' + setBgHeight + 'px;background:' + bgColor" v-if="showHeader">
  6. <view class="bg">
  7. <view class="bg_xinxi" :style="'top:' + customCenter + 'px'">
  8. <!-- <van-icon name="arrow-left" color="#333333" size="26" class="huitui" wx:if="{{ showBack }}" bind:tap="goback"/> -->
  9. <text class="sub_title">{{ pageTitle }}</text>
  10. </view>
  11. </view>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. const app = getApp();
  17. export default {
  18. data() {
  19. return {
  20. // 这里是一些组件内部数据
  21. customCenter: app.globalData.customCenter,
  22. setBgHeight: app.globalData.setBgHeight
  23. };
  24. },
  25. props: {
  26. showBack: {
  27. type: Boolean,
  28. default: false // 此小程序,多用非自定义的(为了个别页面方便用一下)
  29. },
  30. showHeader: {
  31. type: Boolean,
  32. default: true
  33. },
  34. pageTitle: {
  35. type: String,
  36. default: ''
  37. },
  38. bgColor: {
  39. type: String,
  40. default: '#ffffff'
  41. }
  42. },
  43. methods: {
  44. // 这里是一些自定义方法
  45. // 回到首页
  46. gohome() {
  47. uni.reLaunch({
  48. url: '/pages/index/index'
  49. });
  50. },
  51. // 返回上一页
  52. goback() {
  53. // 页面栈
  54. // 获取当前页面是否为支付成功页
  55. // let pages = getCurrentPages();
  56. // let currentPage = pages[pages.length -1];
  57. // let url = currentPage.route;
  58. // console.log('当前地址',url);
  59. uni.navigateBack({
  60. delta: 1,
  61. // 返回的页面数,如果 delta 大于现有页面数,则返回到首页。
  62. success: function (res) {
  63. // console.log('返回成功====',res)
  64. },
  65. fail: function (res) {
  66. // 页面栈无页面,跳到首页
  67. if (res.errMsg == 'navigateBack:fail cannot navigate back at first page.') {
  68. uni.switchTab({
  69. url: '/pages/index/index'
  70. });
  71. }
  72. }
  73. }); // 支付页回退到商品页
  74. // if(url == 'pages/pay-success/index'){
  75. // wx.reLaunch({
  76. // url: '/pages/goods/index'
  77. // });
  78. // }else{
  79. // wx.navigateBack({
  80. // delta:1, // 返回的页面数,如果 delta 大于现有页面数,则返回到首页。
  81. // success: function(res){
  82. // // console.log('返回成功====',res)
  83. // },
  84. // fail: function(res){
  85. // // 页面栈无页面,跳到首页
  86. // if(res.errMsg == 'navigateBack:fail cannot navigate back at first page.'){
  87. // wx.switchTab({
  88. // url: '/pages/index/index'
  89. // })
  90. // }
  91. // }
  92. // });
  93. // }
  94. }
  95. }
  96. };
  97. </script>
  98. <style>
  99. .header_wrap {
  100. background: #fff;
  101. position: fixed;
  102. top: 0rpx;
  103. left: 0rpx;
  104. z-index: 100;
  105. }
  106. .huitui {
  107. position: fixed;
  108. left: 30rpx;
  109. transform: translateY(-50%);
  110. z-index: 101;
  111. }
  112. .bg .tu {
  113. position: absolute;
  114. top: 0rpx;
  115. left: 0rpx;
  116. }
  117. .bg_xinxi {
  118. display: flex;
  119. align-items: center;
  120. justify-content: center;
  121. width: 750rpx;
  122. padding-left: 30rpx;
  123. position: absolute;
  124. left: 0;
  125. transform: translateY(-50%);
  126. position: relative;
  127. }
  128. .logo_tu {
  129. width: 216rpx;
  130. height: 56rpx;
  131. position: absolute;
  132. left: 30rpx;
  133. }
  134. .sub_title {
  135. font-size: 30rpx;
  136. color: #333;
  137. }
  138. /* 背景上的圆 */
  139. .square_1 {
  140. width: 150rpx;
  141. height: 150rpx;
  142. background: rgba(255, 255, 255, 0.1);
  143. border-radius: 50%;
  144. position: absolute;
  145. top: -30rpx;
  146. left: -20rpx;
  147. }
  148. .square_2 {
  149. width: 100rpx;
  150. height: 100rpx;
  151. background: rgba(255, 255, 255, 0.1);
  152. border-radius: 50%;
  153. position: absolute;
  154. top: 40rpx;
  155. right: -30rpx;
  156. }
  157. </style>