提交 | 用户 | 时间
|
314507
|
1 |
<template> |
H |
2 |
<div class="navigation-bar" :style="bgStyle"> |
|
3 |
<div class="h-full w-full flex items-center"> |
|
4 |
<div v-for="(cell, cellIndex) in cellList" :key="cellIndex" :style="getCellStyle(cell)"> |
|
5 |
<span v-if="cell.type === 'text'">{{ cell.text }}</span> |
|
6 |
<img v-else-if="cell.type === 'image'" :src="cell.imgUrl" alt="" class="h-full w-full" /> |
|
7 |
<SearchBar v-else :property="getSearchProp" /> |
|
8 |
</div> |
|
9 |
</div> |
|
10 |
<img |
|
11 |
v-if="property._local?.previewMp" |
|
12 |
src="@/assets/imgs/diy/app-nav-bar-mp.png" |
|
13 |
alt="" |
|
14 |
class="h-30px w-86px" |
|
15 |
/> |
|
16 |
</div> |
|
17 |
</template> |
|
18 |
<script setup lang="ts"> |
|
19 |
import { NavigationBarCellProperty, NavigationBarProperty } from './config' |
|
20 |
import SearchBar from '@/components/DiyEditor/components/mobile/SearchBar/index.vue' |
|
21 |
import { StyleValue } from 'vue' |
|
22 |
import { SearchProperty } from '@/components/DiyEditor/components/mobile/SearchBar/config' |
|
23 |
|
|
24 |
/** 页面顶部导航栏 */ |
|
25 |
defineOptions({ name: 'NavigationBar' }) |
|
26 |
|
|
27 |
const props = defineProps<{ property: NavigationBarProperty }>() |
|
28 |
|
|
29 |
// 背景 |
|
30 |
const bgStyle = computed(() => { |
|
31 |
const background = |
|
32 |
props.property.bgType === 'img' && props.property.bgImg |
|
33 |
? `url(${props.property.bgImg}) no-repeat top center / 100% 100%` |
|
34 |
: props.property.bgColor |
|
35 |
return { background } |
|
36 |
}) |
|
37 |
// 单元格列表 |
|
38 |
const cellList = computed(() => |
|
39 |
props.property._local?.previewMp ? props.property.mpCells : props.property.otherCells |
|
40 |
) |
|
41 |
// 单元格宽度 |
|
42 |
const cellWidth = computed(() => { |
|
43 |
return props.property._local?.previewMp ? (375 - 80 - 86) / 6 : (375 - 90) / 8 |
|
44 |
}) |
|
45 |
// 获得单元格样式 |
|
46 |
const getCellStyle = (cell: NavigationBarCellProperty) => { |
|
47 |
return { |
|
48 |
width: cell.width * cellWidth.value + (cell.width - 1) * 10 + 'px', |
|
49 |
left: cell.left * cellWidth.value + (cell.left + 1) * 10 + 'px', |
|
50 |
position: 'absolute' |
|
51 |
} as StyleValue |
|
52 |
} |
|
53 |
// 获得搜索框属性 |
|
54 |
const getSearchProp = (cell: NavigationBarCellProperty) => { |
|
55 |
return { |
|
56 |
height: 30, |
|
57 |
showScan: false, |
|
58 |
placeholder: cell.placeholder, |
|
59 |
borderRadius: cell.borderRadius |
|
60 |
} as SearchProperty |
|
61 |
} |
|
62 |
</script> |
|
63 |
<style lang="scss" scoped> |
|
64 |
.navigation-bar { |
|
65 |
display: flex; |
|
66 |
height: 50px; |
|
67 |
background: #fff; |
|
68 |
justify-content: space-between; |
|
69 |
align-items: center; |
|
70 |
padding: 0 6px; |
|
71 |
|
|
72 |
/* 左边 */ |
|
73 |
.left { |
|
74 |
margin-left: 8px; |
|
75 |
} |
|
76 |
|
|
77 |
.center { |
|
78 |
font-size: 14px; |
|
79 |
line-height: 35px; |
|
80 |
color: #333; |
|
81 |
text-align: center; |
|
82 |
flex: 1; |
|
83 |
} |
|
84 |
|
|
85 |
/* 右边 */ |
|
86 |
.right { |
|
87 |
margin-right: 8px; |
|
88 |
} |
|
89 |
} |
|
90 |
</style> |