import C from 'bsl-mp/app/Component'; import Event from 'bsl-mp/typings/event'; import { link } from 'bsl-mp/utils'; import * as Export from './export'; const state = { selected: 0 }; class Instance extends C { constructor() { super(state, { color: String, selectedColor: String, list: Array }); } public externalClasses = ['wrap-cls']; public options = { styleIsolation: 'apply-shared' } private getRoute() { const pages = getCurrentPages(); const currentPage = pages[pages.length - 1]; return currentPage.route; } public ready() { const route = this.getRoute(); for (let i = 0; i < this.properties.list.length; i++) { const item = this.properties.list[i]; if (item.pagePath === route) { this.setData({ selected: i }); break; } } } public bindTap(e: Event.Tap) { const pages = getCurrentPages(); const currentRoute = pages[pages.length - 1].route; const dataset = e.currentTarget.dataset; const targetRoute = dataset.route; const detail = { target: targetRoute, current: currentRoute } as Export.OnTapDetail; if (targetRoute !== this.getRoute()) { link('/' + dataset.route, undefined, { mode: 'reLaunch' }); } this.triggerEvent('click', detail); } } Component(new Instance().init());