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

224 lines
4.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <template>
  2. <view>
  3. <view :style="{marginBottom: spreadOut ? headHeight + 'px' : '0px', '--diycolor': inputColor, '--diytextcolor': textColor}">
  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. inputColor: {
  67. type: String, // 标题字体颜色
  68. default: 'rgba(255,255,255,0.5)'
  69. },
  70. textColor: {
  71. type: String, // 标题字体颜色
  72. default: '#777'
  73. }
  74. },
  75. data() {
  76. return {
  77. headHeight: 66, // 头部导航高度
  78. value: ''
  79. };
  80. },
  81. created(){
  82. this.getSystemInfo();
  83. },
  84. methods: {
  85. goSearch() {
  86. console.log(1)
  87. uni.redirectTo({
  88. url: '/pages/search/search'
  89. })
  90. },
  91. // 获取手机高度
  92. getSystemInfo(){
  93. let result = uni.getSystemInfoSync();
  94. this.headHeight = result.statusBarHeight + 46;
  95. this.$emit('changeHeight', this.headHeight);
  96. },
  97. // 监听返回
  98. clickDropOut(event){
  99. if(this.backInquiry){
  100. uni.showModal({
  101. title: '温馨提示',
  102. content: '确定离开此页面吗?',
  103. success: result => {
  104. if(result.confirm){
  105. this.$back();
  106. }
  107. }
  108. })
  109. }else{
  110. this.$back();
  111. }
  112. },
  113. $back(){
  114. // #ifdef H5
  115. let pages = getCurrentPages();
  116. if(pages.length <= 1){
  117. uni.redirectTo({
  118. url: '/pages/index/index/index'
  119. })
  120. return;
  121. }
  122. // #endif
  123. uni.navigateBack();
  124. },
  125. // 监听回到首页
  126. clickHome(){
  127. uni.reLaunch({
  128. url: '/pages/index/index/index'
  129. })
  130. },
  131. // 搜索
  132. onSearch(event){
  133. this.$emit('search', event.detail.value);
  134. }
  135. }
  136. }
  137. </script>
  138. <style scoped lang="scss">
  139. .search-father {
  140. display: flex;
  141. position: relative;
  142. }
  143. .font-40size{
  144. font-size: 40rpx;
  145. }
  146. .font-30size{
  147. font-size: 30rpx;
  148. }
  149. .border-b{
  150. border-bottom: 1rpx solid #e5e5e5;
  151. }
  152. .head{
  153. width: 100vw;
  154. position: fixed;
  155. top: 0;
  156. left: 0;
  157. z-index: 99999;
  158. transition: all .2;
  159. }
  160. .head .head-nav{
  161. position: absolute;
  162. left: 2vw;
  163. cursor: pointer;
  164. width: 130rpx;
  165. background-color: #FFFFFF;
  166. border: 1rpx solid #dcd3d5;
  167. border-radius: 30rpx;
  168. height: 60rpx;
  169. box-sizing: border-box;
  170. display: flex;
  171. justify-content: space-between;
  172. align-items: center;
  173. padding: 0 12rpx;
  174. }
  175. .head .head-nav::after{
  176. position: absolute;
  177. content: '';
  178. width: 2rpx;
  179. height: 40rpx;
  180. background-color: #f7f7f7;
  181. left: 50%;
  182. top: calc(50% - 20rpx);
  183. }
  184. .title-box{
  185. max-width: 49%;
  186. height: 50rpx;
  187. text-align: center;
  188. overflow: hidden;
  189. white-space: nowrap;
  190. text-overflow: ellipsis;
  191. }
  192. .search{
  193. width: 344rpx;
  194. height: 50rpx;
  195. background-color: var(--diycolor);
  196. color: #777;
  197. border-radius: 30rpx;
  198. margin: 0 auto;
  199. text-align: left;
  200. box-sizing: border-box;
  201. padding: 0 50rpx;
  202. font-size: 26rpx;
  203. }
  204. /deep/.input-placeholder{
  205. color: var(--diytextcolor);
  206. font-size: 40rpx!important;
  207. }
  208. .search-icon {
  209. position: absolute;
  210. left: 24rpx;
  211. top: 12rpx;
  212. }
  213. .diy-head{
  214. position: absolute;
  215. left: 2vw;
  216. max-width: 70%;
  217. height: 50rpx;
  218. display: flex;
  219. }
  220. </style>