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

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