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

189 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: 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. <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. bgColor: {
  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. let pages = getCurrentPages();
  98. if(pages.length <= 1){
  99. uni.redirectTo({
  100. url: '/pages/index/index/index'
  101. })
  102. return;
  103. }
  104. uni.navigateBack();
  105. },
  106. // 监听回到首页
  107. clickHome(){
  108. uni.reLaunch({
  109. url: '/pages/index/index/index'
  110. })
  111. },
  112. // 搜索
  113. onSearch(event){
  114. this.$emit('search', event.detail.value);
  115. }
  116. }
  117. }
  118. </script>
  119. <style scoped>
  120. .font-40size{
  121. font-size: 40rpx;
  122. }
  123. .font-30size{
  124. font-size: 30rpx;
  125. }
  126. .border-b{
  127. border-bottom: 1rpx solid #e5e5e5;
  128. }
  129. .head{
  130. width: 100vw;
  131. position: fixed;
  132. top: 0;
  133. left: 0;
  134. z-index: 99999;
  135. transition: all .2;
  136. }
  137. .head .head-nav{
  138. position: absolute;
  139. left: 2vw;
  140. cursor: pointer;
  141. width: 130rpx;
  142. background-color: #FFFFFF;
  143. border: 1rpx solid #dcd3d5;
  144. border-radius: 30rpx;
  145. height: 60rpx;
  146. box-sizing: border-box;
  147. display: flex;
  148. justify-content: space-between;
  149. align-items: center;
  150. padding: 0 12rpx;
  151. }
  152. .head .head-nav::after{
  153. position: absolute;
  154. content: '';
  155. width: 2rpx;
  156. height: 40rpx;
  157. background-color: #f7f7f7;
  158. left: 50%;
  159. top: calc(50% - 20rpx);
  160. }
  161. .title-box{
  162. max-width: 49%;
  163. height: 50rpx;
  164. text-align: center;
  165. overflow: hidden;
  166. white-space: nowrap;
  167. text-overflow: ellipsis;
  168. }
  169. .search{
  170. width: 280rpx;
  171. height: 50rpx;
  172. background-color: #f0f0f0;
  173. color: #9a9a9a;
  174. border-radius: 30rpx;
  175. margin: 0 auto;
  176. text-align: left;
  177. box-sizing: border-box;
  178. padding: 0 20rpx;
  179. }
  180. .diy-head{
  181. position: absolute;
  182. left: 2vw;
  183. max-width: 70%;
  184. height: 50rpx;
  185. display: flex;
  186. }
  187. </style>