nav.js
1.93 KB
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
// components/nav/nav.js
Component({
/**
* 组件的属性列表
*/
properties: {
backgroundColor: {
type: String,
value: '#ffffff'
},
color: {
type: String,
value: '#000000'
},
hasHome: {
type: Boolean,
value: false
},
back: {
type: String,
value: false
},
place:{
type:Boolean,
value:true
}
},
/**
* 组件的初始数据
*/
data: {
disHome: false,
disBack: false,
},
attached(){
this.init();
},
/**
* 组件的方法列表
*/
methods: {
back(){
this.triggerEvent('NavEvent');
if(this.data.back=='none'){
console.log('back none');
}else{
wx.navigateBack()
}
},
home(){
if (!this.data.disHome) return;
wx.reLaunch({
url: '/pages/customer/index'
})
},
init(){
let disBack = false;
let disHome = false;
let pages = getCurrentPages();
console.log('pages.length', pages[0]);
if (pages.length > 1) {
disBack = true;
} else {
//if (getApp().shareTicket && this.data.hasHome) {
if (this.data.hasHome && pages[0].route != "pages/customer/list") {
disHome = true;
}
}
//导航栏自适应
let systemInfo = wx.getSystemInfoSync();
let reg = /ios/i;
let pt = 20;//导航状态栏上内边距
let h = 44;//导航状态栏高度
if(reg.test(systemInfo.system)){
pt = systemInfo.statusBarHeight;
h = 44;
}else{
pt = systemInfo.statusBarHeight;
h = 48;
}
this.setData({
statusBarHeight: pt,
disHome: disHome,
disBack: disBack,
statusBarHeightFull: pt + h,
titleBarHeight:h,
})
console.log('this.setData', this.data);
// wx.setStorageSync('headerHeight',pt+h);
},
getHeight(){
return this.data.statusBarHeightFull
},
}
})