|
@@ -1,5 +1,6 @@
|
|
|
// commpents/mobile-frame/mobile-main.js
|
|
|
-const app = getApp()
|
|
|
+const app = getApp();
|
|
|
+import { system } from "../../utils/dict";
|
|
|
Component({
|
|
|
/**
|
|
|
* 组件的属性列表
|
|
@@ -22,24 +23,43 @@ Component({
|
|
|
* 组件的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
- active: '0'
|
|
|
+ // 当前选中菜单
|
|
|
+ active: 0,
|
|
|
+ // 菜单列表
|
|
|
+ menuList: []
|
|
|
},
|
|
|
/**
|
|
|
* 组件的方法列表
|
|
|
*/
|
|
|
methods: {
|
|
|
- // 返回上一级
|
|
|
+ // 跳转
|
|
|
tabPath(e) {
|
|
|
- this.triggerEvent('tabPath', { index: e.detail })
|
|
|
+ const that = this;
|
|
|
+ that.setData({ active: e.detail });
|
|
|
+ let route = that.data.menuList[e.detail];
|
|
|
+ if (route) that.triggerEvent('tabPath', route)
|
|
|
},
|
|
|
search() {
|
|
|
- let pages = getCurrentPages();
|
|
|
- let currentPage = pages[pages.length - 1];
|
|
|
- if (currentPage.route == 'pages/market/index') {
|
|
|
- this.setData({ active: 0 })
|
|
|
- } else {
|
|
|
- this.setData({ active: 1 })
|
|
|
- }
|
|
|
+ const that = this;
|
|
|
+ // 监听用户是否登录
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'token',
|
|
|
+ success: res => {
|
|
|
+ // 获取当前路由地址
|
|
|
+ let pages = getCurrentPages();
|
|
|
+ let currentPage = pages[pages.length - 1];
|
|
|
+ let menu = system.filter((i) => i.type.includes(res.data.type));
|
|
|
+ if (menu) {
|
|
|
+ that.setData({ menuList: menu });
|
|
|
+ let index = menu.findIndex((i) => i.route == currentPage.route);
|
|
|
+ if (index) that.setData({ active: index });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: res => {
|
|
|
+ return wx.redirectTo({ url: '/pages/login/index', })
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
+
|