-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.ui
335 lines (311 loc) · 8.5 KB
/
app.ui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<template>
<ui-view id="ui-app">
<ui-slide-menu width="280" threshold="30" touch="{{ pageConfig.touchSlideMenu }}" ui:model="showSlideMenu">
<ui-view slot="menu" class="menu">
<ui-text block="" style="color:#fff;margin:10px">侧滑菜单</ui-text>
</ui-view>
<ui-view slot="panel">
<!-- 通用导航栏 -->
<ui-nav-bar ui:if="pageConfig" ui:show="navigationBarVisible" style="{{ navStyle }}">
<ui-row>
<ui-col width="80">
<span class="back" bindtap="handleBack" ui:show="{{showBack}}">
<ui-icon type="arrow-left" font-size="24"></ui-icon>返回
</span>
<span class="back" ui:show="{{!showBack}}" bindtap="handleNavIconTap">
<ui-icon type="list" color="#2B333B" size="16"></ui-icon>
</span>
</ui-col>
<ui-col width="{{WIN_WIDTH-160}}" align="center" content-direction="row" class="nav-bar-center">
<ui-view class="nav-bar-center-loading" style="display: none;"></ui-view>
<span class="nav-bar-center-text">{{ $t(winConfig.navigationBarTitleText) }}</span>
</ui-col>
<ui-col width="80">
</ui-col>
</ui-row>
</ui-nav-bar>
<!-- 页面路由 -->
<router-view class="router-view">
</router-view>
<!-- 底部标签栏 -->
<ui-tab-bar bindbeforechange="handleTabBeforeChange" bindchange="handleTabChange" ui:if="isTabBar" ui:model="tabIndex" style="{{ tabBarStyle }}" id="{{ tabBar.id }}" group-id="{{ tabBar.groupId }}" icon-size="{{ tabBar.iconSize }}" font-size="{{ tabBar.fontSize }}" position="{{ tabBar.position }}" list="{{ tabBarList }}" paths="{{ tabBar.paths }}" background-color="{{ tabBar.backgroundColor }}" border-color="{{ tabBar.borderColor }}" color="{{ tabBar.color }}" selected-color="{{ tabBar.selectedColor }}">
</ui-tab-bar>
</ui-view>
</ui-slide-menu>
</ui-view>
</template>
<script>
export default {
config: {
pages: [
'pages/greenHand',
'pages/allProducts',
'pages/user',
'pages/coffers'
],
theme: {
'theme-color': '#3399ff'
},
window: {
scrollType: 'div',
navigationBarBackgroundColor: '#ffffff',
navigationBarTextStyle: 'black',
navigationBarBorderColor: 'rgba(231, 231, 231, 0.6)'
},
tabBar: {
color: '#7a7e83',
selectedColor: '#39f',
borderColor: 'rgba(231, 231, 231, 0.6)',
backgroundColor: '#fff',
list: [{
pagePath: 'pages/greenHand',
iconPath: 'images/index.png',
selectedIconPath: 'images/index2.png',
text: '首页'
},
{
pagePath: 'pages/allProducts',
iconPath: 'images/quanbu.png',
selectedIconPath: 'images/quanbu2.png',
text: '全部产品'
},
{
pagePath: 'pages/user',
iconPath: 'images/user.png',
selectedIconPath: 'images/user2.png',
text: '我的'
}
]
}
},
data() {
return {
//全局变量
globalData: {},
WIN_WIDTH: ui.WIN_WIDTH,
tabIndex: 0,
tabBarList: [],
navStyle: {},
tabBar: {},
tabBarHeight: 56,
headerHeight: ui.DEFAULT_HEADER_HEIGHT,
paths: [],
barHeight: ui.STATUS_BAR_HEIGHT,
showSlideMenu: false
}
},
computed: {
// 控制通用导航栏是否显示
navigationBarVisible() {
return this.winConfig.navigationStyle !== 'custom'
},
// 控制通用导航栏是否显示返回按钮(首页不显示,其他页显示)
showBack() {
let homePath = this.paths[0]
if (this.tabBar && this.tabBar.paths) {
return this.tabBar.paths.indexOf(homePath) < 0
} else {
return homePath !== this.$route.path
}
}, // 通用导航栏应用app.json和page.json的设置
winConfig() {
let window = this.$router.options.window
let config = { ...window,
...this.pageConfig
}
let color = config.navigationBarTextStyle || 'white'
let scrollType = document.body.getAttribute('scroll-type')
this.navStyle = {
backgroundColor: config.navigationBarBackgroundColor,
color: color,
borderBottom: `1px solid ${config.navigationBarBorderColor}`,
backgroundImage: config.navigationBarBackgroundGradient,
position: scrollType === 'body' ? 'fixed' : 'absolute'
}
if (this.navStyle.backgroundColor) {
this.navStyle.backgroundImage = 'none'
}
if (config.navigationBarBorderColor) {
this.navStyle.borderBottom = `1px solid ${
config.navigationBarBorderColor
}`
} else {
this.navStyle.borderBottom = '0'
}
return config
},
// 控制底部标签栏是否显示
isTabBar() {
return this.tabBarList && this.tabBarList.length > 0
},
// 设置底部标签栏样式
tabBarStyle() {
let style = {}
if (this.navigationBarVisible && this.tabBar.position === 'top') {
style.top = this.headerHeight + 'px'
}
let scrollType = document.body.getAttribute('scroll-type')
style.position = scrollType === 'body' ? 'fixed' : 'absolute'
return style
},
bottom() {
return this.isTabBar ? `${this.tabBarHeight}px` : 0
},
// 底部标签栏应用app.json和page.json的设置
pageConfig() {
if (this.isTabBar) {
return this.tabBarList[this.tabIndex].pageConfig
} else {
return this.$route.meta.pageConfig || window.__$uiPageConfig
}
}
},
watch: {
'$route.path' (path) {
this.handleIosGesture()
this.initTab()
this.initBodyStyle()
}
},
// 初始化
created() {
this.initTab()
this.initPaths()
this.$nextTick(() => {
this.handleIosGesture()
})
},
methods: {
handleNavIconTap() {
this.showSlideMenu = !this.showSlideMenu
},
// 初始化底部标签栏
initTab() {
this.tabBar = this.getTabBar()
this.tabBarList = this.tabBar.list
if (this.tabBar.paths) {
this.tabIndex = this.tabBar.paths.indexOf(this.$route.path)
}
},
// 初始化路由
initPaths() {
let routes = this.$router.options.routes
this.paths = routes.map(item => {
return item.path
})
},
initBodyStyle() {
if (this.winConfig && this.winConfig.backgroundColor) {
document.body.style.backgroundColor = this.winConfig.backgroundColor
}
},
// iOS是否禁用侧滑退出
handleIosGesture() {
if (ui.IS_IOS) {
ui.setPagePopGesture &&
ui.setPagePopGesture({
openPagePopGesture: !this.pageConfig.disableIosGesture
})
}
},
// tabBar示例用到,底部标签栏切换前事件处理
handleTabBeforeChange({
id,
index,
next
}) {
next()
},
// tabBar示例用到,底部标签栏切换后事件处理
handleTabChange({
id,
index
}) {},
// 回退处理
handleBack() {
ui.navigateBack()
},
getTabBar() {
let tabBars = [
this.$router.options.tabBar,
...this.$router.options.pageTabBars
]
for (let i = 0; i < tabBars.length; i++) {
if (
tabBars[i].paths &&
tabBars[i].paths.indexOf(this.$route.path) > -1
) {
return tabBars[i]
}
}
return {}
}
},
mounted() {}
}
</script>
<style lang="less">
@import './static/css/animate.css';
@import './static/css/loading.less';
@import './static/font/iconfont.css';
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Helvetica Neue', Helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', SimSun, sans-serif;
-webkit-touch-callout: none;
}
html,
body {
font-size: 12px;
}
#ui-app {
width: 100%;
height: 100%;
}
.touchui-hover {
background-color: #eee !important;
}
.iphonex-bottom {
height: env(safe-area-inset-bottom);
background-color: #fff;
width: 100%;
}
.ui-nav-bar {
top: 0;
left: 0;
width: 100%;
.nav-bar-left,
.nav-bar-right {
position: relative;
width: 66px;
text-align: center;
}
.back {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
i {
margin-left: 10px;
}
}
.nav-bar-center-text {
.mix-text-overflow();
}
}
.ui-tab-bar {
&.div-scroll {
position: absolute;
}
&.body-scroll {
position: fixed;
}
}
.router-view {
width: 100%;
}
</style>