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

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