/** * Purpose: navigation supports navigation-bar.js by holding or executing the navigation page or API role. * Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow. */ 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() }, }, /** * Purpose: data supports navigation-bar.js by holding or executing the data page or API role. * Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow. */ data: { /** * Purpose: displayStyle supports navigation-bar.js by holding or executing the display style page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ displayStyle: '', /** * Purpose: resolvedShowBack supports navigation-bar.js by holding or executing the resolved show back page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ resolvedShowBack: false, }, /** * Purpose: lifetimes supports navigation-bar.js by holding or executing the lifetimes page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ 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({ /** * Purpose: ios supports navigation-bar.js by holding or executing the ios page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ ios: !isAndroid, /** * Purpose: innerPaddingRight supports navigation-bar.js by holding or executing the inner padding right page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ innerPaddingRight: `padding-right: ${windowWidth - rect.left}px`, /** * Purpose: leftWidth supports navigation-bar.js by holding or executing the left width page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ leftWidth: `width: ${windowWidth - rect.left}px`, /** * Purpose: safeAreaTop supports navigation-bar.js by holding or executing the safe area top page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ safeAreaTop: isDevtools || isAndroid ? `height: calc(var(--height) + ${top}px); padding-top: ${top}px` : '', }) this.updateResolvedBack() }, }, /** * Purpose: methods supports navigation-bar.js by holding or executing the methods page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ 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({ /** * Purpose: delta supports navigation-bar.js by holding or executing the delta page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ delta: this.data.delta, }) return } navigation.goBack(this.data.fallbackPath || '/pages/home/index') }, home() { wx.switchTab({ /** * Purpose: url supports navigation-bar.js by holding or executing the url page or API role. * Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow. */ url: '/pages/home/index', }) }, }, })