app-nav-bar.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <view class="app-nav-bar">
  3. <view v-if="hasHeight" class="hidden-height" :style="[hiddenHeight()]"></view>
  4. <view
  5. :class="{ 'app-navbar--fixed': fixed, 'app-navbar--shadow': shadow,'app-navbar--border': border, 'app-navbar--content':true}">
  6. <view :style="[ordinaryStyle()]" class="app-navbar__bar cross-center">
  7. <view class="dir-left-nowrap app-navbar__box">
  8. <view class="app-navbar__back cross-center box-grow-0" @click="onClickBack" v-if="pagesLength > 1">
  9. <view class="icon-back"></view>
  10. </view>
  11. <view
  12. :class="{'main-center app-navbar__right-center': position === 'center' && xStyle== 1, 'right__back': pagesLength > 1}"
  13. class="box-grow-1 dir-left-nowrap app-navbar__right">
  14. <view v-if="showLeftIcon">
  15. <template v-if="xStyle==5">
  16. <view class="main-left cross-center hxj-area" :style="{color:color}" @click="leftClick">
  17. <view class="tt t-omit" style="width:110rpx ;overflow: hidden;text-overflow:clip">{{selectedProperties.name?selectedProperties.name:'绑定楼盘'}}</view>
  18. <image src="https://t17.9026.com/web/statics/image/index/arrow-down.png" mode=""></image>
  19. </view>
  20. </template>
  21. <template v-else>
  22. <app-jump-button form :open_type="link.openType"
  23. :url="link.url"
  24. :params="link.params">
  25. <view class="cross-center box-grow-0 left-icon">
  26. <image :style="[hw_style]" :src="leftIcon"></image>
  27. </view>
  28. </app-jump-button>
  29. </template>
  30. </view>
  31. <view v-if="showTitle" class="cross-center box-grow-0 title">
  32. <app-jump-button v-if="hasJump" form :open_type="link.openType"
  33. :url="link.url"
  34. :params="link.params">
  35. <view class="t-omit" :style="[maxWidth()]">{{ title }}</view>
  36. </app-jump-button>
  37. <view v-else class="t-omit" :style="[maxWidth()]">{{ title }}</view>
  38. </view>
  39. <view v-if="showLink" class="cross-center box-grow-0 link">
  40. <view class="link-search" @click="navGoodsSearch"
  41. :style="{color: placeholderColor}">
  42. <view class="link-box cross-center main-between">
  43. <view class="search-placeholder t-omit">{{ placeholder }}</view>
  44. <view class="search-icon"></view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import {mapState} from "vuex";
  56. export default {
  57. name: 'app-nav-bar',
  58. data() {
  59. return {
  60. hw_style: {},
  61. }
  62. },
  63. watch: {
  64. 'leftIcon'(newValue, oldValue) {
  65. this.doSomething();
  66. }
  67. },
  68. props: {
  69. fixed: {
  70. type: [Boolean, String],
  71. default: true
  72. },
  73. shadow: {
  74. type: [String, Boolean],
  75. default: false
  76. },
  77. hasHeight: {
  78. type: Boolean,
  79. default: true,
  80. },
  81. border: {
  82. type: [String, Boolean],
  83. default: false
  84. },
  85. backgroundColor: {
  86. type: String,
  87. default: "#FFFFFF"
  88. },
  89. backgroundImage:{
  90. type:String,
  91. default:''
  92. },
  93. leftIcon: {
  94. type: String,
  95. default: ""
  96. },
  97. link: {
  98. type: [Object,Array]
  99. },
  100. title: {
  101. type: String,
  102. default: ""
  103. },
  104. xStyle: {
  105. type: [Number, String],
  106. default: 1
  107. },
  108. hasMallSetting: {
  109. type: [Number, String],
  110. default: 1
  111. },
  112. color: {
  113. type: String,
  114. default: "#000000"
  115. },
  116. position: {
  117. type: String,
  118. default: "center"
  119. },
  120. placeholder: {
  121. type: String,
  122. default: "搜索"
  123. },
  124. placeholderColor: {
  125. type: String,
  126. default: "#666666"
  127. }
  128. },
  129. computed: {
  130. ...mapState({
  131. statusBarHeight: state => state.gConfig.systemInfo.statusBarHeight,
  132. mBarHeight: state => state.gConfig.mBarHeight,
  133. appImg: state => state.mallConfig.__wxapp_img.mall,
  134. mallNavbar: state => state.mallConfig.navbar,
  135. selectedProperties: state => state.user.selectedProperties
  136. }),
  137. maxWidth() {
  138. return () => {
  139. let xstyle = parseInt(this.xStyle);
  140. let width = 0;
  141. switch (xstyle) {
  142. case 1:
  143. if (this.position === 'center') {
  144. width = uni.upx2px(360);
  145. } else {
  146. width = uni.upx2px(500);
  147. }
  148. break;
  149. case 2:
  150. width = uni.upx2px(400);
  151. break;
  152. case 4:
  153. width = uni.upx2px(200);
  154. break;
  155. default:
  156. break;
  157. }
  158. if (width && this.pagesLength > 1) {
  159. width -= uni.upx2px(42);
  160. }
  161. return Object.assign({}, {
  162. 'max-width': width + 'px',
  163. });
  164. }
  165. },
  166. hiddenHeight() {
  167. return () => {
  168. let barHeight;
  169. // #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO
  170. barHeight = this.statusBarHeight;
  171. // #endif
  172. barHeight = barHeight || 0;
  173. let height = barHeight + this.mBarHeight;
  174. this.$emit('headHeight', height);
  175. return {
  176. height: height + 'px',
  177. }
  178. }
  179. },
  180. ordinaryStyle() {
  181. return () => {
  182. let color = '';
  183. let backgroundColor = '';
  184. let backgroundImage=''
  185. if (this.hasMallSetting == 1) {
  186. color = this.mallNavbar.top_text_color;
  187. backgroundColor = this.mallNavbar.top_background_color;
  188. } else {
  189. color = this.color;
  190. backgroundColor = this.backgroundColor;
  191. backgroundImage =this.backgroundImage
  192. }
  193. let barHeight;
  194. // #ifdef MP
  195. barHeight = this.statusBarHeight;
  196. // #endif
  197. barHeight = barHeight || 0;
  198. color = color || '#000000';
  199. backgroundColor = backgroundColor || '#FFFFFF';
  200. return Object.assign({}, {
  201. color, backgroundColor,backgroundImage,'background-size': '100% 386rpx',
  202. height: (barHeight + this.mBarHeight) + 'px',
  203. paddingTop: barHeight + 'px',
  204. })
  205. }
  206. },
  207. hasJump() {
  208. return [2, 4].indexOf(parseInt(this.xStyle)) !== -1
  209. },
  210. showLeftIcon() {
  211. return [2, 3,5].indexOf(parseInt(this.xStyle)) !== -1 && this.leftIcon
  212. },
  213. showTitle() {
  214. return [1, 2, 4].indexOf(parseInt(this.xStyle)) !== -1 && this.title
  215. },
  216. showLink() {
  217. return [3, 4].indexOf(parseInt(this.xStyle)) !== -1 && this.link
  218. },
  219. pagesLength() {
  220. return getCurrentPages().length;
  221. },
  222. },
  223. mounted() {
  224. this.doSomething();
  225. },
  226. methods: {
  227. doSomething() {
  228. const maxHeight = 54;
  229. const maxWidth = 100;
  230. const self = this;
  231. uni.getImageInfo({
  232. src: self.leftIcon,
  233. success: function (res) {
  234. let {height, width} = res;
  235. if (height <= maxHeight && width <= maxWidth) {
  236. // height = height;
  237. // width = width;
  238. }
  239. if (height <= maxHeight && width >= maxWidth) {
  240. height = height / (width / maxWidth);
  241. width = maxWidth;
  242. }
  243. if (height >= maxHeight && width <= maxWidth) {
  244. height = maxHeight;
  245. width = width / (height / maxHeight);
  246. }
  247. if (height > maxHeight && width >= maxWidth) {
  248. if (maxWidth / maxHeight > width / height) {
  249. width = width / (height / maxHeight);
  250. height = maxHeight;
  251. } else {
  252. height = height / (width / maxWidth);
  253. width = maxWidth;
  254. }
  255. }
  256. self.hw_style = {
  257. height: uni.upx2px(height) + 'px',
  258. width: uni.upx2px(width) + 'px',
  259. };
  260. }
  261. })
  262. },
  263. navGoodsSearch() {
  264. uni.navigateTo({
  265. url: '/pages/search/search',
  266. })
  267. },
  268. onClickBack() {
  269. uni.navigateBack({
  270. delta: 1
  271. })
  272. },
  273. leftClick(){
  274. this.$emit('leftClick')
  275. }
  276. },
  277. }
  278. </script>
  279. <style lang="scss" scoped>
  280. .hxj-area{
  281. width:194rpx;
  282. height: 50rpx;
  283. font-size: 28rpx;
  284. font-weight: 500;
  285. color: #ebe4e1;
  286. // border:1px solid rgba($color: #000, $alpha: 0.22);
  287. background-color: rgba($color: #000, $alpha: 0.22);
  288. border-radius:25px;
  289. display: flex;
  290. align-items: center;
  291. padding: 0 20rpx;
  292. box-sizing: border-box;
  293. justify-content:space-between; ;
  294. .tt{
  295. max-width: 240rpx;
  296. }
  297. image{
  298. width: 24rpx;
  299. height: 20rpx;
  300. margin-left: 6rpx;
  301. }
  302. }
  303. /* #ifdef H5 */
  304. $bar-height: 0;
  305. /* #endif */
  306. /* #ifdef MP */
  307. $bar-height: 20px;
  308. /* #endif */
  309. $app-height: 44px + $bar-height;
  310. $app-bg-color: #FFFFFF;
  311. .app-nav-bar {
  312. .hidden-height {
  313. height: $app-height;
  314. }
  315. .app-navbar--fixed {
  316. position: fixed;
  317. z-index: 9998;
  318. top: 0;
  319. }
  320. .app-navbar--shadow {
  321. box-shadow: 0 1px 6px #ccc;
  322. }
  323. .app-navbar--border {
  324. border-bottom-width: #{1rpx};
  325. border-bottom-style: solid;
  326. border-bottom-color: $app-bg-color;
  327. }
  328. .app-navbar--content {
  329. width: 100vw;
  330. // background-color: $app-bg-color;
  331. overflow: hidden;
  332. }
  333. }
  334. .app-navbar__bar {
  335. height: $app-height;
  336. padding-top: $bar-height;
  337. .app-navbar__box {
  338. position: relative;
  339. width: 100%;
  340. .app-navbar__back {
  341. padding-left: #{26rpx};
  342. .icon-back {
  343. background-image: url("https://shop.9026.com/web/statics/image/mall/static/icon/h5-back-2.png");
  344. // background-image: url("https://t17.9026.com/web/statics/image/index/back.png");
  345. background-repeat: no-repeat;
  346. background-size: 100% 100%;
  347. height: #{30rpx};
  348. width: #{20rpx};
  349. // height: #{27rpx};
  350. // width: #{16rpx};
  351. // height: #{33rpx};
  352. // width: #{33rpx};
  353. display: block;
  354. }
  355. }
  356. .app-navbar__right {
  357. > view {
  358. padding-left: #{26rpx};
  359. }
  360. .left-icon image {
  361. max-height: #{54rpx};
  362. max-width: #{100rpx};
  363. height: 0;
  364. width: 0;
  365. display: block;
  366. }
  367. .title {
  368. font-size: #{32rpx};
  369. font-weight: bold;
  370. > view {
  371. max-width: 50vw;
  372. }
  373. }
  374. .link-search {
  375. width: #{298rpx};
  376. height: #{55rpx};
  377. background-color: #FFFFFF;
  378. border-radius: #{40rpx};
  379. position: relative;
  380. .link-box {
  381. position: absolute;
  382. top: 0;
  383. left: 0;
  384. font-size: #{22rpx};
  385. height: #{55rpx};
  386. padding: 0 #{24rpx};
  387. width: 100%;
  388. border: 1upx solid #e2e2e2;
  389. border-radius: #{40rpx};
  390. .search-placeholder {
  391. max-width: #{218rpx};
  392. }
  393. .search-icon {
  394. background-image: url("https://shop.9026.com/web/statics/image/mall/static/icon/icon-search.png");
  395. background-repeat: no-repeat;
  396. background-size: 100% 100%;
  397. height: #{26rpx};
  398. width: #{26rpx};
  399. }
  400. }
  401. }
  402. }
  403. .app-navbar__right-center {
  404. margin-right: 0;
  405. .title {
  406. padding-left: 0;
  407. }
  408. }
  409. .app-navbar__right-center.right__back {
  410. margin-right: calc(#{26rpx} + #{16rpx});
  411. }
  412. }
  413. }
  414. </style>