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

216 lines
4.6 KiB

5 years ago
  1. <template>
  2. <view>
  3. <view :style="{marginBottom: spreadOut ? headHeight + 'px' : '0px'}">
  4. <view :class="{head: true, 'border-b': boderBottom}" :style="{height: headHeight + 'px', background: bgColor}">
  5. <block v-if="diy">
  6. <view class="diy-head" :style="{'top': headHeight - 38 + 'px'}">
  7. <slot></slot>
  8. </view>
  9. </block>
  10. <block v-else>
  11. <view class="head-nav" :style="{'top': headHeight - 40 + 'px'}" v-if="showIcon">
  12. <text class="lf-iconfont icon-daifukuan font-40size" @click="clickDropOut"></text>
  13. <text class="lf-iconfont icon-sousuo font-40size" @click="clickHome"></text>
  14. </view>
  15. <view class="title-box" :style="{'margin': headHeight - 36 + 'px auto 0'}" @click="goSearch()">
  16. <view v-if="search" class="search-father">
  17. <u-icon name="search" class="search-icon" style="color: #777;"></u-icon>
  18. <input class="search" placeholder-style="color: #777" placeholder="搜你想要的" confirm-type="search" v-model="value" @confirm="onSearch"/>
  19. </view>
  20. <text class="font-30size" :style="{color: titleColor}" v-else>{{ title }}</text>
  21. </view>
  22. </block>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. props: {
  30. title: {
  31. type: String, // 标题
  32. default: ''
  33. },
  34. showIcon: {
  35. type: Boolean, // 是否显示左侧操作菜单
  36. default: false
  37. },
  38. bgColor: {
  39. type: String, // head背景颜色
  40. default: '#f8f8f8'
  41. },
  42. titleColor: {
  43. type: String, // 标题字体颜色
  44. default: '#1d1d1d'
  45. },
  46. spreadOut: {
  47. type: Boolean, // 内容是否自动撑开,该组件悬浮了,原有的dom不再占用位置,如果需要占用值为true
  48. default: true
  49. },
  50. search: {
  51. type: Boolean, // 是否显示搜索输入框
  52. default: false
  53. },
  54. diy: {
  55. type: Boolean, // 自定义内容,开启后title,showIcon,search均都不生效
  56. default: false
  57. },
  58. backInquiry: {
  59. type: Boolean, // 点击返回按钮后是否弹出询问弹窗,showIcon为true时生效
  60. default: false
  61. },
  62. boderBottom: {
  63. type: Boolean, // 是否显示底部边框线
  64. default: false
  65. }
  66. },
  67. data() {
  68. return {
  69. headHeight: 66, // 头部导航高度
  70. value: ''
  71. };
  72. },
  73. created(){
  74. this.getSystemInfo();
  75. },
  76. methods: {
  77. goSearch() {
  78. console.log(1)
  79. uni.redirectTo({
  80. url: '/pages/search/search'
  81. })
  82. },
  83. // 获取手机高度
  84. getSystemInfo(){
  85. let result = uni.getSystemInfoSync();
  86. this.headHeight = result.statusBarHeight + 46;
  87. this.$emit('changeHeight', this.headHeight);
  88. },
  89. // 监听返回
  90. clickDropOut(event){
  91. if(this.backInquiry){
  92. uni.showModal({
  93. title: '温馨提示',
  94. content: '确定离开此页面吗?',
  95. success: result => {
  96. if(result.confirm){
  97. this.$back();
  98. }
  99. }
  100. })
  101. }else{
  102. this.$back();
  103. }
  104. },
  105. $back(){
  106. // #ifdef H5
  107. let pages = getCurrentPages();
  108. if(pages.length <= 1){
  109. uni.redirectTo({
  110. url: '/pages/index/index/index'
  111. })
  112. return;
  113. }
  114. // #endif
  115. uni.navigateBack();
  116. },
  117. // 监听回到首页
  118. clickHome(){
  119. uni.reLaunch({
  120. url: '/pages/index/index/index'
  121. })
  122. },
  123. // 搜索
  124. onSearch(event){
  125. this.$emit('search', event.detail.value);
  126. }
  127. }
  128. }
  129. </script>
  130. <style scoped lang="scss">
  131. .search-father {
  132. display: flex;
  133. position: relative;
  134. }
  135. .font-40size{
  136. font-size: 40rpx;
  137. }
  138. .font-30size{
  139. font-size: 30rpx;
  140. }
  141. .border-b{
  142. border-bottom: 1rpx solid #e5e5e5;
  143. }
  144. .head{
  145. width: 100vw;
  146. position: fixed;
  147. top: 0;
  148. left: 0;
  149. z-index: 99999;
  150. transition: all .2;
  151. }
  152. .head .head-nav{
  153. position: absolute;
  154. left: 2vw;
  155. cursor: pointer;
  156. width: 130rpx;
  157. background-color: #FFFFFF;
  158. border: 1rpx solid #dcd3d5;
  159. border-radius: 30rpx;
  160. height: 60rpx;
  161. box-sizing: border-box;
  162. display: flex;
  163. justify-content: space-between;
  164. align-items: center;
  165. padding: 0 12rpx;
  166. }
  167. .head .head-nav::after{
  168. position: absolute;
  169. content: '';
  170. width: 2rpx;
  171. height: 40rpx;
  172. background-color: #f7f7f7;
  173. left: 50%;
  174. top: calc(50% - 20rpx);
  175. }
  176. .title-box{
  177. max-width: 49%;
  178. height: 50rpx;
  179. text-align: center;
  180. overflow: hidden;
  181. white-space: nowrap;
  182. text-overflow: ellipsis;
  183. }
  184. .search{
  185. width: 344rpx;
  186. height: 50rpx;
  187. background-color: rgba(255,255,255,0.5);
  188. color: #777;
  189. border-radius: 30rpx;
  190. margin: 0 auto;
  191. text-align: left;
  192. box-sizing: border-box;
  193. padding: 0 50rpx;
  194. font-size: 26rpx;
  195. }
  196. /deep/.input-placeholder{
  197. color: #777;
  198. font-size: 40rpx!important;
  199. }
  200. .search-icon {
  201. position: absolute;
  202. left: 24rpx;
  203. top: 12rpx;
  204. }
  205. .diy-head{
  206. position: absolute;
  207. left: 2vw;
  208. max-width: 70%;
  209. height: 50rpx;
  210. display: flex;
  211. }
  212. </style>