当前位置: 首页 > news >正文

徐州市中心做网站的公司招聘企业网站设计素材

徐州市中心做网站的公司招聘,企业网站设计素材,怎么做网站站长视频,wordpress子站点打不开1.动态获取权限并根据获取权限转换成相对应的router 根据请求获取菜单数据,对菜单数据进行转换,分别进行下面几步: /*** 组件地址前加斜杠处理*/ export function addSlashToRouteComponent(routeList: AppRouteRecordRaw[]) {routeList.fo…

1.动态获取权限并根据获取权限转换成相对应的router

根据请求获取菜单数据,对菜单数据进行转换,分别进行下面几步:

/*** 组件地址前加斜杠处理*/
export function addSlashToRouteComponent(routeList: AppRouteRecordRaw[]) {routeList.forEach((route) => {const component = route.component as string;if (component) {const layoutFound = LayoutMap.get(component);if (!layoutFound) {route.component = component.startsWith("/") ? component : `/${component}`;}}route.children && addSlashToRouteComponent(route.children);});return routeList;
}

利用import函数+通配符,引入匹配的所有vue页面,如下:

const LayoutMap = new Map<string, () => Promise<typeof import("*.vue")>>();

以及const dynamicViewsModules = import.meta.glob("../../views/**/*.{vue,tsx}");

该map会生成一个以页面路径为key的,带有@import动态引入的方法为值的对象,这是可以通过处理key字符串,通过获取的菜单列表匹配对应的path,最终的component 就等于dynamicViewsModules[path]

function dynamicImport(dynamicViewsModules: Record<string, () => Promise<Recordable>>, component: string) {const keys = Object.keys(dynamicViewsModules);const matchKeys = keys.filter((key) => {const k = key.replace("../../views", "");const startFlag = component.startsWith("/");const endFlag = component.endsWith(".vue") || component.endsWith(".tsx");const startIndex = startFlag ? 0 : 1;const lastIndex = endFlag ? k.length : k.lastIndexOf(".");return k.substring(startIndex, lastIndex) === component;});if (matchKeys?.length === 1) {const matchKey = matchKeys[0];return dynamicViewsModules[matchKey];} else if (matchKeys?.length > 1) {console.log("Please do not create `.vue` and `.TSX` files with the same file name in the same hierarchical directory under the views folder. This will cause dynamic introduction failure");return;}
}

处理后最终返回的数据就是生成router树状结构 

2.动态添加路由addRoute

const menuRecordRoutes: RouteRecordRaw[] = Object.entries(menuRoutes).map(([, config]) => config).sort((a: any, b: any) => a.order - b.order) as RouteRecordRaw[];
menuRecordRoutes.forEach((route) => {router.addRoute(route);});

这里有个值得注意的地方如果是该菜单列表下有多个子菜单需要将子菜单也添加进去,如:

menuRecordRoutes.forEach((route) => {router.addRoute(route);if (route?.children?.length) {route.children.forEach((child) => {child.name = route.name?.toString() + "-" + child.name?.toString();if (route.name) {router.addRoute(route.name, child);}});}});

上图中后面一个router.addRoute是针对每个子菜单进行router添加,并且这里还有一个坑:

如果不同的菜单下的子菜单的name属性是一样的话 这里可能会把前面一个添加的子菜单给覆盖了,因为router中的name 属性是唯一的,所以这里对子菜单的name做了一个拼接:将父菜单名称和子菜单名称拼接到一起作为子菜单的新名称。另外这个name属性非常重要,如果name属性中含有特殊符号(如:name=detail@id),页面中如果使用了类似这样的页面跳转:router.push({ name: "detail", params: { id: row.id } }); 则会导致路由不匹配的问题

3.自定义指令控制按钮显隐 

//main.ts中引用
const app = createApp(App);
// 全局注册 自定义指令(directive)
setupDirective(app);
import type { App } from "vue";import { hasPerm } from "./permission";// 全局注册 directive
export function setupDirective(app: App<Element>) {// 使 v-hasPerm 在所有组件中都可用app.directive("hasPerm", hasPerm);
}
//自定义指令的自定义方法
export const hasPerm: Directive = {mounted(el: HTMLElement, binding: DirectiveBinding) {// 「超级管理员」拥有所有的按钮权限const { authList } = useUserStoreHook();const { value } = binding;let result = false;if (authList.length && value) {if (Array.isArray(value)) {result = value.every((ele) => authList.includes(ele));} else {result = authList.includes(value);}}if (!result) {el.parentNode && el.parentNode.removeChild(el);}return result;},
};

页面中使用

<el-button v-hasPerm="['xxx']" :icon="Delete" size="small" text type="primary">删 除</el-button>

至此,动态菜单和按钮权限功能完成 

http://www.ds6.com.cn/news/121118.html

相关文章:

  • 页面兼容性测试网站搜索引擎营销的方法不包括
  • 成品短视频软件源码优化网络的软件
  • 富阳建设局网站首页短视频推广公司
  • 网站建设相关的优化服务平台
  • 宜春网站制作公司软文广告经典案例短的
  • 深圳企业网站建设费用明细福州seo
  • 高清做 视频在线观看网站电商网站前端页面内容编写
  • 装修公司全屋整装谷歌aso优化
  • 清爽网站什么是引流推广
  • 辽宁建设工程信息网 招标文件福州seo关键字推广
  • 在线客服系统网站源码如何做谷歌seo推广
  • 自己免费做网站(四)百度推广登陆
  • 做网站创业需要注册公司吗凤山网站seo
  • 网络运维工程师简历怎么写南京seo外包平台
  • 公司的官方网站的作用公司主页网站设计
  • 营销型网站建设服务长春网站优化体验
  • 网站自动化开发百度网络优化推广公司
  • 有什么自学网站建设的网站百度查找相似图片
  • 网站建设与软件开发哪个好赚钱百度网络推广
  • 沈阳做网站客户多吗能打开各种网站的浏览器下载
  • wordpress主题申请软著吗seo技巧
  • 自己做本地视频网站百度知识营销
  • 河北邢台专业做网站手机网页设计制作网站
  • 东营网站建设培训关键词排名关键词快速排名
  • smluntan论坛wordpress潍坊seo按天收费
  • 易语言 网站开发亚马逊关键词优化怎么做
  • 女的男的做那个视频网站seo建站工具
  • 谁有学做网站论坛账号宁波seo外包推广公司
  • 关于政府网站建设工作讲话今天刚刚发生的新闻最新新闻
  • 布吉做棋牌网站建设找哪家效益快软文营销写作技巧