import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
|
import store from '@/store'
|
import * as dd from 'dingtalk-jsapi'
|
import publics from "@/router/module"
|
import scheduledRoute from "@/router/module/scheduledRoute"
|
import materialStorage from "@/router/module/materialStorage"
|
import workOrder from "@/router/module/workOrder"
|
import needToBeDealtWith from '@/router/module/needToBeDealtWith'
|
import productionInspection from '@/router/module/productionInspection'
|
import personal from '@/router/module/personal'
|
import requisition from '@/router/module/requisition'
|
|
const routes: Array<RouteRecordRaw> = [
|
...publics, // 公共路由
|
...scheduledRoute, // 计划模块
|
...workOrder, // 工单模块
|
...needToBeDealtWith, // 待办
|
...productionInspection, // 生产检验
|
...materialStorage, // 仓库
|
...personal, // 个人
|
...requisition // 申请单
|
]
|
|
const router = createRouter({
|
history: createWebHashHistory(),
|
routes
|
})
|
|
router.beforeEach(async (to, from, next) => {
|
if (to.meta.title) {
|
// @ts-ignore
|
document.title = to.meta.title
|
// 判断是否在钉钉内
|
if (dd.env.platform !== 'notInDingTalk') {
|
// 如果是钉钉登录,设置钉钉导航栏标题为router里meta标签里设置的title
|
dd.biz.navigation.setTitle({
|
title: to.meta.title as string,
|
// @ts-ignore
|
onSuccess: (result: any) => {
|
console.log('设置钉钉title成功')
|
},
|
onFail: (err: any) => {
|
console.log('设置钉钉title失败')
|
}
|
})
|
}
|
} else {
|
document.title = '云工厂'
|
}
|
if (to.query.companyId) {
|
store.commit('setCompany', to.query.companyId)
|
next()
|
}
|
await next()
|
})
|
|
export default router;
|