金诚优选前端代码
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.

200 lines
4.4 KiB

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