135 lines
3.1 KiB
JavaScript
135 lines
3.1 KiB
JavaScript
const navigation = require('../../utils/navigation')
|
|
|
|
Component({
|
|
options: {
|
|
multipleSlots: true,
|
|
},
|
|
properties: {
|
|
extClass: {
|
|
type: String,
|
|
value: '',
|
|
},
|
|
title: {
|
|
type: String,
|
|
value: '',
|
|
},
|
|
background: {
|
|
type: String,
|
|
value: '',
|
|
},
|
|
color: {
|
|
type: String,
|
|
value: '',
|
|
},
|
|
back: {
|
|
type: Boolean,
|
|
value: true,
|
|
},
|
|
showBack: {
|
|
type: Boolean,
|
|
value: true,
|
|
},
|
|
isTabPage: {
|
|
type: Boolean,
|
|
value: false,
|
|
},
|
|
fallbackPath: {
|
|
type: String,
|
|
value: '/pages/home/index',
|
|
},
|
|
loading: {
|
|
type: Boolean,
|
|
value: false,
|
|
},
|
|
homeButton: {
|
|
type: Boolean,
|
|
value: false,
|
|
},
|
|
animated: {
|
|
type: Boolean,
|
|
value: true,
|
|
},
|
|
show: {
|
|
type: Boolean,
|
|
value: true,
|
|
observer(show) {
|
|
this._showChange(show)
|
|
},
|
|
},
|
|
delta: {
|
|
type: Number,
|
|
value: 1,
|
|
},
|
|
safeAreaMode: {
|
|
type: String,
|
|
value: 'solid',
|
|
},
|
|
},
|
|
observers: {
|
|
'back, showBack, isTabPage': function () {
|
|
this.updateResolvedBack()
|
|
},
|
|
},
|
|
data: {
|
|
displayStyle: '',
|
|
resolvedShowBack: false,
|
|
},
|
|
lifetimes: {
|
|
attached() {
|
|
const rect = wx.getMenuButtonBoundingClientRect()
|
|
const deviceInfo = (typeof wx.getDeviceInfo === 'function' ? wx.getDeviceInfo() : wx.getSystemInfoSync()) || {}
|
|
const windowInfo = (typeof wx.getWindowInfo === 'function' ? wx.getWindowInfo() : wx.getSystemInfoSync()) || {}
|
|
const platform = deviceInfo.platform
|
|
const isAndroid = platform === 'android'
|
|
const isDevtools = platform === 'devtools'
|
|
const safeArea = windowInfo.safeArea || {}
|
|
const top = safeArea.top || 0
|
|
const windowWidth = windowInfo.windowWidth || deviceInfo.windowWidth || 375
|
|
|
|
this.setData({
|
|
ios: !isAndroid,
|
|
innerPaddingRight: `padding-right: ${windowWidth - rect.left}px`,
|
|
leftWidth: `width: ${windowWidth - rect.left}px`,
|
|
safeAreaTop: isDevtools || isAndroid ? `height: calc(var(--height) + ${top}px); padding-top: ${top}px` : '',
|
|
})
|
|
this.updateResolvedBack()
|
|
},
|
|
},
|
|
methods: {
|
|
updateResolvedBack() {
|
|
const resolvedShowBack = !this.data.isTabPage && Boolean(this.data.showBack && this.data.back)
|
|
this.setData({
|
|
resolvedShowBack,
|
|
})
|
|
},
|
|
_showChange(show) {
|
|
const animated = this.data.animated
|
|
let displayStyle = ''
|
|
if (animated) {
|
|
displayStyle = `opacity: ${show ? '1' : '0'};transition:opacity 0.3s;`
|
|
} else {
|
|
displayStyle = `display: ${show ? '' : 'none'}`
|
|
}
|
|
this.setData({
|
|
displayStyle,
|
|
})
|
|
},
|
|
back() {
|
|
const pages = getCurrentPages()
|
|
if (this.data.delta && pages.length > this.data.delta) {
|
|
wx.navigateBack({
|
|
delta: this.data.delta,
|
|
})
|
|
return
|
|
}
|
|
|
|
navigation.goBack(this.data.fallbackPath || '/pages/home/index')
|
|
},
|
|
home() {
|
|
wx.switchTab({
|
|
url: '/pages/home/index',
|
|
})
|
|
},
|
|
},
|
|
})
|