views

1. 视图及HttpRequest 和HttpResponse

Django中的视图主要用来接受Web请求,并做出响应。
视图的本质就是一个Python中的函数
视图的响应分为两大类
1)以Json数据形式返回 (JsonResponse)
2)以网页的形式返回
2.1)重定向到另一个网页 (HttpResponseRedirect)
2.2)错误视图(40X,50X) ( HttpResponseNotFound, HttpResponseForbidden,HttpResponseNotAllowed等)
视图响应过程: 浏览器输入 ->  django获取信息并去掉ip:端口,剩下路径 -> urls 路由匹配 - > 视图响应 -> 回馈到浏览器
视图参数:
1) 一个HttpRequest的实例,一般命名为request
2) 通过url正则表达式传递过来的参数
位置:通常在应用下的views.py中定义
错误视图:
1) 404视图 (页面没找到)
2) 400视图 (客户操作错误)
3) 500视图(服务器内部错误)
自定义错误视图
在工程的templates文件夹下创建对应的错误文件
在文件中定义自己的错误样式
注意需要在关闭Debug的情况下才可以
没有关闭Debug的情况下会在界面中直接显示log

1.1 HttpRequest

服务器在接收到Http请求后,会根据报文创建HttpRequest对象
视图中的第一个参数就是HttpRequest对象
Django框架接收到http请求之后会将http请求包装为HttpRequest对象,之后传递给视图。

HttpRequest和HttpResponse属性和方法的详细说明点击打开链接

常用属性和方法:
属性: path 请求的完整路径
method 请求的方法,常用GET,POST
encoding 编码方式,常用utf-8
GET 类似字典的参数,包含了get的所有参数
POST 类似字典的参数,包含了post所有参数
FILES 类似字典的参数,包含了上传的文件
COOKIES 字典,包含了所有COOKIE
session 类似字典,表示会话
方法: is_ajax() 判断是否是ajax(),通常用在移动端和JS中
QueryDict
类似字典的数据结构。与字典的区别,可以存在相同的键。
QueryDict中数据获取方式
dict['uname'] 或 dict.get('uname)
获取指定key对应的所有值
dict.getlist('uname')

1.2 HttpResponse

服务器返回给客户端的数据
HttpResponse由程序猿自己创建:
1)不使用模板,直接调用HttpResponse(),返回HttpResponse对象。
2)调用模板,进行渲染。
2.1) 先load模板,再渲染
2.2) 直接使用render一步到位
render(request,template_name[,context])
request 请求体对象
template_name 模板路径
context 字典参数,用来填坑

属性: content 返回的内容
charset 编码格式
status_code 响应状态码(200,3xx,404,5xx)
方法
init 初始化内容
write(xxx) 直接写出文本 
flush() 冲刷缓冲区
set_cookie(key,value='xxx',max_age=None,expries=None)
delete_cookie(key) 删除cookie,上面那个是设置
HttpResponse子类
HttpResponseRedirect
响应重定向:可以实现服务器内部跳转
return HttpResponseRedict('/grade/2017')
使用的时候推荐使用反向解析
JsonResponse
返回Json数据的请求,通常用在异步请求上
JsonResponse(dict)
也可以使用__init__(self,data)设置数据
Content-type是application/json

2. Cookies 和Session

2.1 Cookies

理论上,一个用户的所有请求操作都应该属于同一个会话,而另一个用户的所有请求操作则应该属于另一个会话,二者不能混淆. 而Web应用程序是使用HTTP协议传输数据的。HTTP协议是无状态的协议。一旦数据交换完毕,客户端与服务器端的连接就会关闭,再次交换数据需要建立新的连接。这就意味着服务器无法从连接上跟踪会话。要跟踪该会话,必须引入一种机制。
Cookie就是这样的一种机制。它可以弥补HTTP协议无状态的不足。在Session出现之前,基本上所有的网站都采用Cookie来跟踪会话。
Cookie实际上是一小段的文本信息。客户端请求服务器,如果服务器需要记录该用户状态,就使用response向客户端浏览器颁发一个Cookie。客户端浏览器会把Cookie保存起来。当浏览器再请求该网站时,浏览器把请求的网址连同该Cookie一同提交给服务器。服务器检查该Cookie,以此来辨认用户状态。服务器还可以根据需要修改Cookie的内容。
cookie本身由服务器生成,通过Response将cookie写到浏览器上,下一次访问,浏览器会根据不同的规则携带cookie过来。
注意:cookie不能跨浏览器
设置cookie:
response.set_cookie(key,value[,max_age=None,expries=None)]
max_age: 整数 单位为秒,指定cookie过期时间
expries   : 整数,指定过期时间,还支持datetime或timedelta,可以指定一个具体日期时间
max_age和expries两个选一个指定
过期时间的几个关键时间
max_age 设置为 0 浏览器关闭失效
设置为None永不过期
expires=timedelta(days=10) 10天后过期
获取cookie:
request.COOKIES.get('username')
删除cookie:
response.delete_cookie('username')
cookie存储到客户端
优点:
       数据存在在客户端,减轻服务器端的压力,提高网站的性能。
 缺点:
       安全性不高:在客户端机很容易被查看或破解用户会话信息

2.2 Session

服务器端会话技术,依赖于cookie.
django中启用SESSION
settings中
INSTALLED_APPS:
'django.contrib.sessions'
MIDDLEWARE:
'django.contrib.sessions.middleware.SessionMiddleware'
基本操作
设置Sessions值
     request.session['session_name'] ="admin"
获取Sessions值
get(key,default=None) 根据键获取会话的值
 session_name = request.session["session_name"]
删除Sessions值
  del request.session["session_name"]
clear() 清楚所有会话
flush() 删除当前的会话数据并删除会话的cookie
session.session_key获取session的key
数据存储到数据库中会进行编码,使用的是Base64
每个HttpRequest对象都有一个session属性,也是一个类字典对象.

3. 静态文件和媒体文件

媒体文件:用户上传的文件,叫做media
静态文件:css,js,image等 叫做static

3.1 在django中使用静态文件

1)首先确保django.contrib.staticfiles在 INSTALLED_APPS中
2)在settings中定义 STATIC_URL
STATIC_URL = '/static/'
3)在模板中使用load标签去加载静态文件
{% load static %}
<img src="{% static "my_app/example.jpg" %}" alt="My image"/>
4)在你app的static目录中存放静态文件,比如: my_app/static/my_app/example.jpg.
如果有别的静态资源文件,不在app下的static目录下,可以通过STATICFILES_DIRS来指定额外的静态文件搜索目录。
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    '/var/www/static/',
]

3.2 在django中使用媒体文件

1)在settings中配置 MEDIA_URL和 MEDIA_ROOT
MEDIA_URL= '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
2) 在url中配置:
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
    # ... the rest of your URLconf goes here ...
]+static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)


3. 文件上传

        文件上传要求form表单存在enctype="multipart/form-data"属性,并且提交方法是post。
<form enctype="multipart/form-data" action="/uploadFile/" method="post">  
         <input type="file" name="myfile" />  
 <br/>  
<input type="submit" value="upload"/>  
</form>
最简单的文件上传:
def upload_file(request):  
if request.method == "POST":    # 请求方法为POST时,进行处理  
        myFile =request.FILES.get("myfile", None)    # 获取上传的文件,如果没有文件,则默认为None  
        if not myFile:  
            return HttpResponse("no files for upload!")  
        destination = open(os.path.join("E:\\upload",myFile.name),'wb+')    # 打开特定的文件进行二进制的写操作  
        for chunk in myFile.chunks():      # 分块写入文件  
            destination.write(chunk)  
        destination.close()  
        return HttpResponse("upload over!") 


import { createWebHistory, createRouter } from "vue-router"; /* Layout */ import Layout from "@/layout"; import { deepClone, flattenTreeList } from "@/utils"; import BasicRoute from "./routeBasic"; const modules = import.meta.glob("@/views/**"); import emitter from "@/utils/eventBus"; /** * Note: 路由配置项 * * hidden: true // 当设置 true 的时候该路由不会再侧边栏出现 如401,login等页面,或者如一些编辑页面/edit/1 * alwaysShow: true // 当你一个路由下面的 children 声明的路由大于1个时,自动会变成嵌套的模式--如组件页面 * // 只有一个时,会将那个子路由当做根路由显示在侧边栏--如引导页面 * // 若你想不管路由下面的 children 声明的个数都显示你的根路由 * // 你可以设置 alwaysShow: true,这样它就会忽略之前定义的规则,一直显示根路由 * redirect: noRedirect // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击 * name:'router-name' // 设定路由的名字,一定要填写不然使用<keep-alive>时会出现各种问题 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数 * roles: ['admin', 'common'] // 访问路由的角色权限 * permissions: ['a:a:a', 'b:b:b'] // 访问路由的菜单权限 * meta : { noCache: true // 如果设置为true,则不会被 <keep-alive> 缓存(默认 false) title: 'title' // 设置该路由在侧边栏和面包屑中展示的名字 icon: 'svg-name' // 设置该路由的图标,对应路径src/assets/icons/svg breadcrumb: false // 如果设置为false,则不会在breadcrumb面包屑中显示 activeMenu: '/system/user' // 当路由设置了该属性,则会高亮相对应的侧边栏。 } */ // 公共路由 export const constantRoutes = [ { path: "/", redirect: "/myWorkbench", }, { path: "/login", name: "login", component: () => import("@/views/login"), hidden: true, }, { path: "/register", component: () => import("@/views/register"), hidden: true, }, { path: "/:pathMatch(.*)*", component: () => import("@/views/error/404"), hidden: true, }, { path: "/401", component: () => import("@/views/error/401"), hidden: true, }, ]; // 动态路由,基于用户权限动态去加载 export const dynamicRoutes = [ { path: "/search", component: Layout, redirect: "search", meta: { docTitle: "搜索", parentActive: "search", }, children: [ { name: "search", path: "/search", component: () => import("@/views/search"), }, ], }, { path: "/notice", component: Layout, redirect: "/notice", meta: { docTitle: "通知", }, children: [ { name: "notice", path: "/notice", redirect: "/notify", component: () => import("@/views/notice"), children: [ { name: "notify", path: "/notify", title: "通知", meta: { parentActive: "notice", }, component: () => import("@/views/notice/notify"), }, ], }, ], }, { path: "/myWork", component: Layout, redirect: "/dashboard", meta: { docTitle: "工作台", }, children: [ { name: "myWorkbench", path: "/myWorkbench", redirect: "/dashboard", component: () => import("@/views/myWorkbench"), children: [ { name: "dashboard", path: "/dashboard", title: "仪表盘", meta: { parentActive: "myWorkbench", }, component: () => import("@/views/myWorkbench/dashboard"), }, { name: "todoTasks", path: "/todoTasks", title: "待办任务", meta: { parentActive: "myWorkbench", }, component: () => import("@/views/myWorkbench/todoTasks"), }, { name: "reviewCenter", path: "/reviewCenter", title: "流程中心", meta: { parentActive: "myWorkbench", }, component: () => import("@/views/myWorkbench/reviewCenter"), }, ], }, ], }, { path: "/ComponentiInProject", component: Layout, redirect: "ComponentiInProject", children: [ { name: "workItems", path: "/workItems", meta: { parentActive: "ComponentiInProject", }, component: () => import("@/views/workitem"), }, { name: "projectPageSetting", path: "/projectPageSetting/:projectId", meta: { parentActive: "ProjectManagements", }, component: () => import("@/views/pm/pmpm"), props: (route) => ({ projectId: route.params.projectId, }), // redirect: "/projectPageSetting/overview", // 添加默认重定向 children: [ { name: "baseline", path: "baseline", component: () => import("@/views/pm/pmpm/components/baseLine/index.vue"), }, { name: "changeManager", path: "changeManager", title: "变更管理", // redirect: { name: "change-manager-list" }, component: () => import("@/views/changeManager/index.vue"), children: [ { name: "change-manager-list", path: "manager", component: () => import("@/views/changeManager/components/manage.vue"), }, { name: "change-ledger-list", path: "ledger", component: () => import("@/views/changeManager/components/ledger.vue"), }, ] }, { name: "workItem", path: "work-item", component: () => import("@/views/workitem/index.vue"), }, { name: "testManager", path: "test-manager", component: () => import("@/views/pm/pmpm/components/testManager"), redirect: { name: "testOverview" }, children: [ { name: "testOverview", path: "overview", component: () => import( "@/views/pm/pmpm/components/testManager/overview/index" ), }, { name: "testCase", path: "case", component: () => import("@/views/pm/pmpm/components/testManager/case/index"), redirect: { name: "testCaseLibrary" }, children: [ { name: "testCaseLibrary", path: "library", component: () => import( "@/views/pm/pmpm/components/testManager/case/libraryList" ), }, { name: "testCaseList", path: "list/:libraryId", component: () => import( "@/views/pm/pmpm/components/testManager/case/case" ), }, { name: "testCaseList2", path: "list2/:libraryId", component: () => import( "@/views/pm/pmpm/components/testManager/case/caseList/caselist" ), }, ], }, { name: "testPlan", path: "plan", component: () => import("@/views/pm/pmpm/components/testManager/plan/index"), redirect: { name: "planList" }, children: [ { name: "planList", path: "list", component: () => import( "@/views/pm/pmpm/components/testManager/plan/planList" ), }, { name: "planDetail", path: "detail/:planId", component: () => import( "@/views/pm/pmpm/components/testManager/plan/planLibrary" ), }, ], }, { name: "testReport", path: "report", component: () => import( "@/views/pm/pmpm/components/testManager/report/reportList" ), }, ], }, { name: "overview", path: "overview", component: () => import("@/views/pm/pmpm/components/overview/index.vue"), }, { name: "member", path: "member", component: () => import("@/views/pm/pmpm/components/member/index.vue"), }, { name: "communicationDesign", path: "communication-design", component: () => import("@/views/pm/pmpm/components/communicationDesign/index.vue"), }, { name: "checklist", path: "software-inventory", component: () => import("@/views/pm/pmpm/components/softwareInventory/index.vue"), }, { name: "funcSecurity", path: "funcSecurity", redirect: { name: "hara" }, component: () => import("@/views/pm/pmpm/components/funcSecurity/index.vue"), children: [ { name: "hara", path: "hara", component: () => import("@/views/pm/pmpm/components/funcSecurity/component/hara.vue"), }, { name: "func-sec-fault", path: "fault", component: () => import("@/views/pm/pmpm/components/funcSecurity/component/fault.vue"), }, { name: "func-sec-hazard", path: "hazard", component: () => import("@/views/pm/pmpm/components/funcSecurity/component/hazard.vue"), }, { name: "func-sec-scene", path: "scene", component: () => import("@/views/pm/pmpm/components/funcSecurity/component/scene.vue"), }, { name: "func-sec-event", path: "event", component: () => import("@/views/pm/pmpm/components/funcSecurity/component/event.vue"), }, { name: "func-sec-target", path: "target", component: () => import("@/views/pm/pmpm/components/funcSecurity/component/target.vue"), }, ] }, // { // name: "projectPlan", // path: "project-plan", // title: "项目计划", // redirect: { name: "plan-list" }, // component: () => // import("@/views/pm/pmpm/components/projectPlan/index.vue"), // children: [ // { // name: "plan-list", // path: "plan", // component: () => import("@/views/pm/pmpm/components/projectPlan/plan/index.vue"), // }, // { // name: "milestone-list", // path: "milestone", // component: () => import("@/views/pm/pmpm/components/projectPlan/milestone/index.vue"), // }, // ] // }, { name: "bugManager", path: "bugManager", component: () => import("@/views/pm/pmpm/components/bugManager/index.vue"), }, { name: "iteration", path: "iteration", component: () => import("@/views/pm/pmpm/components/iteration/index.vue"), }, { name: "knowledgeBase", path: "knowledge-base", component: () => import("@/views/pm/pmpm/components/pmpmWiki/index.vue"), redirect: { name: 'pmRecently'}, children: [ { name: "pmRecently", path: "recently", title: "最近", icon: "time", meta: { parentActive: "pmWiki", }, component: () => import("@/views/wiki/recently"), }, { name: "pMycollectiton", path: "mycollectiton", title: "我的收藏", icon: "rate", meta: { parentActive: "pmWiki", }, component: () => import("@/views/wiki/mycollectiton"), }, { name: "pmShare", path: "share", title: "与我共享", icon: "redo", meta: { parentActive: "pmWiki", }, component: () => import("@/views/wiki/share"), }, // { // path: "shareManage", // redirect: "/shareManage/:knowledgeGroupId", // children: [ // { // path: "/shareManage/:knowledgeGroupId", // name: "pmShareManage", // component: () => import("@/views/wiki/shareManage"), // meta: { // parentActive: "pmWiki", // topActive: "share" // }, // }, // ], // }, { path: "shareManage/:knowledgeGroupId", name: "pmShareManage", component: () => import("@/views/wiki/shareManage"), meta: { parentActive: "pmWiki", topActive: "pmShare" }, }, { name: "pmPageGroup", path: "pageGroup", title: "知识库", icon: "space", meta: { parentActive: "pmWiki", }, component: () => import("@/views/wiki/pageGroup"), }, { name: "pmInsightOverview", path: "insightOverview", title: "数据统计", icon: "monitor", meta: { parentActive: "pmWiki", }, component: () => import("@/views/wiki/insightOverview"), }, // { // path: "pageGroupManage", // redirect: "pageGroupManage", // children: [ // { // path: "pageGroupManage/:knowledgeGroupId", // name: "pmPageGroupManage", // component: () => import("@/views/wiki/pageGroupManage"), // meta: { // parentActive: "pmWiki", // topActive: "pageGroup" // }, // }, // ], // }, { path: "pageGroupManage/:knowledgeGroupId", name: "pmPageGroupManage", component: () => import("@/views/wiki/pageGroupManage"), meta: { parentActive: "pmWiki", topActive: "pmPageGroup" }, }, // { // path: "archiveManage", // redirect: "archiveManage/:knowledgeGroupId", // children: [ // { // path: "archiveManage/:knowledgeGroupId", // name: "pmArchiveManage", // component: () => import("@/views/wiki/archiveManage"), // meta: { // parentActive: "pmWiki", // topActive: "pageGroup" // }, // }, // ], // }, { path: "archiveManage/:knowledgeGroupId", name: "pmArchiveManage", component: () => import("@/views/wiki/archiveManage"), meta: { parentActive: "pmWiki", topActive: "pmPageGroup" }, }, // { // path: "pageGroupSet", // redirect: "pageGroupSet/:knowledgeGroupId", // children: [ // { // path: "pageGroupSet/:knowledgeGroupId", // name: "pmPageGroupSet", // component: () => import("@/views/wiki/pageGroupSet"), // meta: { // parentActive: "pmWiki", // topActive: "pageGroup" // }, // }, // ], // }, { path: "pageGroupSet/:knowledgeGroupId", name: "pmPageGroupSet", component: () => import("@/views/wiki/pageGroupSet"), meta: { parentActive: "pmWiki", topActive: "pmPageGroup" }, }, // { // path: "wikiHistory", // redirect: "wikiHistory/:knowledgeGroupId", // children: [ // { // path: "wikiHistory/:knowledgeGroupId", // name: "pmSikiHistory", // component: () => import("@/views/wiki/history"), // meta: { // parentActive: "pmWiki", // topActive: "pageGroup" // }, // }, // ], // }, { path: "wikiHistory/:knowledgeGroupId", name: "pmWikiHistory", component: () => import("@/views/wiki/history"), meta: { parentActive: "pmWiki", topActive: "pmPageGroup" }, }, ], }, { name: "projectPlan", path: "project-plan", title: "项目计划", redirect: { name: "plan-list" }, component: () => import("@/views/pm/pmpm/components/projectPlan/index.vue"), children: [ { name: "plan-list", path: "plan", component: () => import("@/views/pm/pmpm/components/projectPlan/plan/index.vue"), }, { name: "milestone-list", path: "milestone", component: () => import("@/views/pm/pmpm/components/projectPlan/milestone/index.vue"), }, ] }, { name: "projectSetting", path: "project-setting", component: () => import("@/views/pm/pmpm/components/setTab.vue"), }, { name: "fileManager", path: "fileManager", title: "文件管理", component: () => import("_f/views/File.vue"), }, { path: "onlyoffice", name: "Onlyoffice", meta: { title: "在线编辑预览", content: { description: "onlyoffice 文档在线编辑预览,支持 Word Excel PowerPoint", }, }, component: () => import("@/views/QWFile/views/OnlyOffice.vue"), }, { name: 'softwareManager', path: 'software-management', title: '软件管理', component: () => import("@/views/pm/pmpm/components/softwareManagement/index.vue"), children: [ // { // name: "software-board", // path: "board", // component: () => import("@/views/pm/pmpm/components/softwareManagement/board"), // }, { name: "software-train", path: "train", component: () => import("@/views/pm/pmpm/components/softwareManagement/train"), }, { name: "software-ecu", path: "ecu", component: () => import("@/views/pm/pmpm/components/softwareManagement/ECUList"), }, { name: "software-ecu-version", path: "ecu-version", component: () => import("@/views/pm/pmpm/components/softwareManagement/ECUVersionList"), }, { name: "software-delivery", path: "delivery", component: () => import("@/views/pm/pmpm/components/softwareManagement/delivery"), }, { name: "software-ecu-base-version-list", path: "ecu-base", component: () => import("@/views/pm/pmpm/components/softwareManagement/ECUBaseVersionList"), }, { name: "software-delivery-list", path: "delivery-list", component: () => import("@/views/pm/pmpm/components/softwareManagement/deliveryList"), }, { name: "efficiency-board", path: "efficiency", component: () => import("@/views/pm/pmpm/components/softwareManagement/efficiency"), }, ] }, { name: "projectTask", path: "task", title: "任务", redirect: { name: "task-list" }, component: () => import("@/views/pm/pmpm/components/taskManagement/index.vue"), children: [ { name: "task-list", path: "list", title: "任务列表", component: () => import("@/views/pm/pmpm/components/taskManagement/list.vue"), }, { name: "task-test", path: "test", title: "任务测试", component: () => import("@/views/pm/pmpm/components/taskManagement/test.vue"), } ] } ], }, ], }, { path: "/wiki", component: Layout, redirect: "/recently", meta: { docTitle: "知识库", }, children: [ { name: "wiki", path: "/wiki", redirect: "/recently", component: () => import("@/views/wiki"), children: [ { name: "recently", path: "/recently", title: "最近", icon: "time", meta: { parentActive: "wiki", }, component: () => import("@/views/wiki/recently"), }, { name: "mycollectiton", path: "/mycollectiton", title: "我的收藏", icon: "rate", meta: { parentActive: "wiki", }, component: () => import("@/views/wiki/mycollectiton"), }, { name: "share", path: "/share", title: "与我共享", icon: "redo", meta: { parentActive: "wiki", }, component: () => import("@/views/wiki/share"), }, { path: "/shareManage", redirect: "/shareManage/:knowledgeGroupId", children: [ { path: "/shareManage/:knowledgeGroupId", name: "shareManage", component: () => import("@/views/wiki/shareManage"), meta: { parentActive: "wiki", topActive: "share", }, }, ], }, { name: "pageGroup", path: "/pageGroup", title: "知识库", icon: "space", meta: { parentActive: "wiki", }, component: () => import("@/views/wiki/pageGroup"), }, { name: "insightOverview", path: "/insightOverview", title: "数据统计", icon: "monitor", meta: { parentActive: "wiki", }, component: () => import("@/views/wiki/insightOverview"), }, { path: "/pageGroupManage", redirect: "pageGroupManage", children: [ { path: "/pageGroupManage/:knowledgeGroupId", name: "pageGroupManage", component: () => import("@/views/wiki/pageGroupManage"), meta: { parentActive: "wiki", topActive: "pageGroup", }, }, ], }, { path: "/archiveManage", redirect: "/archiveManage/:knowledgeGroupId", children: [ { path: "/archiveManage/:knowledgeGroupId", name: "archiveManage", component: () => import("@/views/wiki/archiveManage"), meta: { parentActive: "wiki", topActive: "pageGroup", }, }, ], }, { path: "/pageGroupSet", redirect: "/pageGroupSet/:knowledgeGroupId", children: [ { path: "/pageGroupSet/:knowledgeGroupId", name: "pageGroupSet", component: () => import("@/views/wiki/pageGroupSet"), meta: { parentActive: "wiki", topActive: "pageGroup", }, }, ], }, { path: "/wikiHistory", redirect: "/wikiHistory/:knowledgeGroupId", children: [ { path: "/wikiHistory/:knowledgeGroupId", name: "wikiHistory", component: () => import("@/views/wiki/history"), meta: { parentActive: "wiki", topActive: "pageGroup", }, }, ], }, ], }, ], }, { path: "/rdLibrary", component: Layout, redirect: "/library", meta: { docTitle: "研发库", }, children: [ { name: "rdLibrary", path: "/rdLibrary", redirect: "/library", component: () => import("@/views/RdLibrary/index.vue"), children: [ { name: "library", path: "/library", component: () => import("@/views/RdLibrary/library/index.vue"), }, { name: "libraryContents", path: "/libraryContents", component: () => import("@/views/RdLibrary/library/contents.vue"), }, { name: "demandPoolLadger", path: "/demandPoolLadger", component: () => import("@/views/RdLibrary/components/demandPoolLadger.vue"), }, { name: "librarySettings", path: "/librarySettings", component: () => import("@/views/RdLibrary/library/librarySettings.vue"), }, ] } ], }, { path:"/Architecture", component: Layout, redirect: "/architecture", meta: { docTitle: "架构设计", }, children: [ { name: "architectureDesign", path: "/architectureDesign", component: () => import("@/views/architecture"), } ] }, { path: "/baselineManagements", component: Layout, redirect: "/baselinesManagement", meta: { docTitle: "基线管理", }, children: [ { name: "baselinesManagement", path: "/baselinesManagement", component: () => import("@/views/baselineManagement/index.vue"), } ], }, { path: "/HelpCenters", component: Layout, redirect: "/updateLog", meta: { docTitle: "帮助", }, children: [ { name: "HelpCenters", path: "/HelpCenters", redirect: "/updateLog", component: () => import("@/views/HelpCenters"), children: [ { name: "updateLog", path: "/updateLog", title: "更新日志", meta: { parentActive: "HelpCenters", }, component: () => import("@/views/HelpCenters/updateLog"), }, ], }, ], }, { path: "/configurationCenter", component: Layout, redirect: "/projectGroupMag", meta: { docTitle: "配置", }, children: [ { name: "configurationCenter", path: "/configurationCenter", redirect: "/projectGroupMag", component: () => import("@/views/configurationCenter"), children: [ { name: "MenuManagement", path: "/MenuManagement", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/configurationCenter/MenuManagement"), }, { name: "UserManagement", path: "/UserManagement", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/configurationCenter/UserManagement"), }, { name: "/userGroup", path: "/userGroup", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/ugm"), }, { name: "departManagement", path: "/departManageMent", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/dgm"), }, { name: "RoleManagement", path: "/RoleManagement", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/configurationCenter/RoleManagement"), }, { name: "functionalSafety", path: "/functionalSafety", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/securityConfig/functionalSafety"), }, { name: "WorkitemType", path: "/WorkitemType", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/workitemConfig/workType"), }, { name: "Notification", path: "/WorkitemType/Notification", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/workitemConfig/notification"), }, { name: "jiraSetting", path: "/jiraSetting", component: () => import("@/views/jiraSetting"), meta: { parentActive: "configurationCenter", }, }, { name: "WindowConfig", path: "/WindowConfig", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/workitemConfig/workFrame"), }, { name: "ProcessDesign", path: "/ProcessDesign", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/workitemConfig/workFlow"), }, { name: "ProjectM", path: "/ProjectM", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/proManaConfig/components/projectMag.vue"), }, { name: "projectGroupMag", path: "/projectGroupMag", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/proManaConfig/components/projectGroupMag"), }, { name: "projectAttribute", path: "/projectAttribute", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/proManaConfig/components/projectAttribute"), }, { name: "projectStatus", path: "/projectStatus", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/proManaConfig/components/projectStatus"), }, { name: "projectRole", path: "/projectRole", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/proManaConfig/components/projectRole"), }, { path: "/aclmanager", name: "aclmanager", props: (route) => ({ projectId: route.query.projectId || "-1" }), meta: { parentActive: "configurationCenter", }, component: () => import("@/views/workitemConfig/acl/index.vue"), // children: [{ // name: "aclmanager", // path: "/aclmanager", // component: () => import('@/views/workitemConfig/acl/index.vue') // }] }, { name: "TestPlanAttribute", path: "/TestPlanAttribute", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/TestManagementConfig/TestPlanAttribute"), }, { name: "FileSizeConfig", path: "/FileSizeConfig", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/fileConfig/fileInfoManage"), }, { name: "LoginLogs", path: "/LoginLogs", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/logManagement/loginlogs"), }, { name: "ActionLogs", path: "/ActionLogs", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/logManagement/actionlogs"), }, { name: "InterfaceLogs", path: "/InterfaceLogs", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/logManagement/interfacelogs"), }, { name: "iterationAttribute", path: "/iterationAttribute", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/iterationAttributeConfig/iterationAttribute"), }, { name: "wikiPermissConfig", path: "/wikiPermissConfig", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/wiki/wikiManaConfig/wikiPermissConfig"), }, { name: "wikiPageManage", path: "/wikiPageManage", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/wiki/wikiManaConfig/wikiPageManage"), }, { name: "wikiInfoManage", path: "/wikiInfoManage", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/wiki/wikiManaConfig/wikiInfoManage"), }, { name: "wikiTemplateManage", path: "/wikiTemplateManage", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/wiki/wikiManaConfig/wikiTemplateManage"), }, { name: "templateList", path: "/templateList", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/reviewCenter/templateList"), }, { name: "formFlowEdit", path: "/formFlowEdit", meta: { parentActive: "configurationCenter", }, component: () => import( "@/views/pm/reviewCenter/formFlowEdit/FormProcessDesigner" ), }, { name: "componentManage", path: "/componentManage", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/reviewCenter/componentManage"), }, { name: "dataManage", path: "/dataManage", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/reviewCenter/dataManage"), }, { name: "dataStatistics", path: "/dataStatistics", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/reviewCenter/dataStatistics"), }, { name: "baseLineAttribute", path: "/baseLineAttribute", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/baseLineM/attribute.vue"), }, { name: "baseLineStatus", path: "/baseLineStatus", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/baseLineM/status.vue"), }, { name: "applicableCarType", // 适用车型 path: "/applicableCarType", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/reviewCenter/applicableConfig/applicableCarType"), }, { name: "applicableStage", // 适用阶段 path: "/applicableStage", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/reviewCenter/applicableConfig/applicableStage"), }, { name: "approvalSet", // 审批设置 path: "/approvalSet", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/reviewCenter/approvalSet"), }, { name: "ECUDataSet", // ECU主数据 path: "/ECUDataSet", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/reviewCenter/ECUDataSet"), }, { name: "ECUDataSet", // ECU主数据 path: "/ECUDataSet", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/reviewCenter/ECUDataSet"), }, { name: "ecuConfig", // data dictionary-ecu配置 path: "/ecuConfig", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/dataDictionary/ecu"), }, { name: "systemConfig", // 数据字典-系统配置 path: "/systemConfig", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/dataDictionary/system"), }, { name: "stageConfig", // 数据字典-阶段配置 path: "/stageConfig", meta: { parentActive: "configurationCenter", }, component: () => import("@/views/pm/dataDictionary/stage"), }, ], }, ], }, { path: "/workitem", component: Layout, redirect: "workitem", children: [ { name: "workitem", path: "/workitem", component: () => import("@/views/workitem"), }, ], }, { path: "/pm", component: Layout, redirect: "/projectManagement", meta: { docTitle: "项目", }, children: [ { name: "ProjectManagements", path: "/pm", redirect: "/projectManagement", //重定向的目标路径 component: () => import("@/views/pm/home"), children: [ { name: "ProjectManagements", path: "/projectManagement", title: "项目列表", // meta: { // parentActive: "myWorkbench", // }, component: () => import("@/views/pm/home/conmponents/projectManagement.vue"), }, ], }, ], }, { path: "/fileManagement", component: Layout, redirect: "/File", meta: { docTitle: "文件管理", }, children: [ { name: "File", path: "/File", title: "文件管理", component: () => import("_f/views/File.vue"), }, ], }, { path: "/office", name: "office", meta: { title: "在线编辑预览", content: { description: "onlyoffice 文档在线编辑预览,支持 Word Excel PowerPoint", }, }, component: () => import("@/views/QWFile/views/OnlyOffice.vue"), }, ]; const router = createRouter({ history: createWebHistory(), routes: [...constantRoutes, ...dynamicRoutes], scrollBehavior(to, from, savedPosition) { if (savedPosition) { return savedPosition; } return { top: 0 }; }, }); // 添加路由 export const resetRouter = (params) => { const dashboardRoute = router.options.routes.filter((el) => el?.path.indexOf("/dashboard") > -1) ?? []; const param = [...params, ...BasicRoute, ...dashboardRoute]; router.options.routes = []; router.options.routes.push(...param); // param.forEach((item) => { // router.addRoute(item); // }); }; // 生成路由 export const filterRoute = (rou) => { const permission = []; if (rou && Array.isArray(rou)) { rou.sort((a, b) => a.displayOrder - b.displayOrder); const forFn = (arr, val) => { // eslint-disable-next-line array-callback-return for (let i = 0; i < arr.length; i++) { // 跳过第一层非目录的数据 const item = arr[i]; if (item?.resourceType === 1 && item?.pid === "0") { continue; } item.name = item.routerName; item.path = item.routerAddress; try { // eslint-disable-next-line no-eval item.meta = JSON.parse(item.meta); item.meta.resourceName = item.resourceName; item.meta.resourceCode = item.resourceCode; } catch (e) { console.log(e); } // 处理菜单 if (item.resourceType !== 2) { item.meta.icon = item.icon || ""; item.meta.btncontent = []; if (item.meta.permission) { permission.push(item); } if (item.fileAddress) { item.component = modules[`/src/${item.fileAddress}/index.vue`]; item.componentString = `@/${item.fileAddress}`; } } if (item.resourceType === 2) { permission.push(item); val?.meta?.btncontent?.push({ icon: item.icon, btnName: item.resourceName, btnCode: item.resourceCode, }); if (val.meta?.list) { const child = val?.children?.find( (el) => el.resourceCode === item.resourceCode ); if (child) { child.meta.btncontent = []; child.meta.btncontent.push({ icon: item.icon, btnName: item.resourceName, btnCode: item.resourceCode, }); } } arr.splice(i--, 1); } if (item.children && Array.isArray(item.children)) { if (item.children.length > 0) { item.children.sort((a, b) => a.displayOrder - b.displayOrder); item.redirect = item.children.filter( (el) => el.resourceType === 1 )?.[0]?.routerAddress; forFn(item.children, item); } } } }; forFn(rou); } return { rou, permission }; }; router.beforeEach((to, from) => { // 如果是从 fileManager 页面离开 if (from.path.includes("/fileManager")) { emitter.emit("routeChange", { to, from }); } }); export default router;
最新发布
09-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值