jiangping
2023-08-11 5c98be0b50b8ca78ed05358cbd434193e75dcd8a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;