金诚优选前端代码
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.9 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-fanhui font-43size" @click="clickDropOut"></text>
  13. <text class="lf-iconfont icon-shouye font-30size" @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. backDiy: {
  67. type: Boolean, // 点击返回按钮后是否执行自定义方法,优先级低于backInquiry
  68. default: false
  69. },
  70. backCallback: {
  71. type: Function // 返回执行的自定义方法
  72. },
  73. boderBottom: {
  74. type: Boolean, // 是否显示底部边框线
  75. default: false
  76. }
  77. },
  78. data() {
  79. return {
  80. headHeight: 66, // 头部导航高度
  81. value: ''
  82. };
  83. },
  84. created(){
  85. this.getSystemInfo();
  86. },
  87. methods: {
  88. // 获取手机高度
  89. getSystemInfo(){
  90. let result = uni.getSystemInfoSync();
  91. this.headHeight = result.statusBarHeight + 46;
  92. this.$emit('changeHeight', this.headHeight);
  93. },
  94. // 监听返回
  95. clickDropOut(event){
  96. if(this.backInquiry){
  97. uni.showModal({
  98. title: '温馨提示',
  99. content: '确定离开此页面吗?',
  100. success: result => {
  101. if(result.confirm){
  102. this.$back();
  103. }
  104. }
  105. })
  106. }else{
  107. if(this.backDiy){
  108. this.$emit('backCallback');
  109. }else{
  110. this.$back();
  111. }
  112. }
  113. },
  114. $back(){
  115. let pages = getCurrentPages();
  116. if(pages.length <= 1){
  117. uni.redirectTo({
  118. url: '/pages/index/index/index'
  119. })
  120. return;
  121. }
  122. uni.navigateBack();
  123. },
  124. // 监听回到首页
  125. clickHome(){
  126. uni.reLaunch({
  127. url: '/pages/index/index/index'
  128. })
  129. },
  130. // 搜索
  131. onSearch(event){
  132. this.$emit('search', event.detail.value);
  133. },
  134. searchClick(){
  135. this.$url('/pages/shop/search');
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. .font-40size{
  142. font-size: 40rpx;
  143. }
  144. .font-30size{
  145. font-size: 30rpx;
  146. }
  147. .border-b{
  148. border-bottom: 1rpx solid #e5e5e5;
  149. }
  150. .head{
  151. width: 100vw;
  152. position: fixed;
  153. top: 0;
  154. left: 0;
  155. z-index: 99999;
  156. transition: all .2s;
  157. }
  158. .head .head-nav{
  159. position: absolute;
  160. left: 2vw;
  161. cursor: pointer;
  162. width: 130rpx;
  163. background-color: #FFFFFF;
  164. border: 1rpx solid #dcd3d5;
  165. border-radius: 30rpx;
  166. height: 60rpx;
  167. box-sizing: border-box;
  168. display: flex;
  169. justify-content: space-between;
  170. align-items: center;
  171. // padding: 0 12rpx;
  172. }
  173. .head .head-nav>text{
  174. display: inline-block;
  175. width: 50%;
  176. height: 100%;
  177. line-height: 57rpx;
  178. }
  179. .head .head-nav>text:nth-child(1){
  180. padding-left: 12rpx;
  181. }
  182. .head .head-nav>text:nth-child(2){
  183. text-align: right;
  184. padding-right: 12rpx;
  185. }
  186. .head .head-nav::after{
  187. position: absolute;
  188. content: '';
  189. width: 2rpx;
  190. height: 40rpx;
  191. background-color: #f7f7f7;
  192. left: 50%;
  193. top: calc(50% - 20rpx);
  194. }
  195. .title-box{
  196. max-width: 49%;
  197. height: 50rpx;
  198. text-align: center;
  199. overflow: hidden;
  200. white-space: nowrap;
  201. text-overflow: ellipsis;
  202. }
  203. .search{
  204. width: 228rpx;
  205. height: 50rpx;
  206. margin: 0 auto;
  207. text-align: left;
  208. font-size: 24rpx;
  209. /* background-color: #f0f0f0;
  210. color: #9a9a9a;
  211. border-radius: 30rpx;
  212. box-sizing: border-box;
  213. padding: 0 20rpx; */
  214. }
  215. .diy-head{
  216. position: absolute;
  217. left: 2vw;
  218. max-width: 70%;
  219. height: 50rpx;
  220. display: flex;
  221. }
  222. </style>