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

徐州市中心做网站的公司招聘网络营销师证

徐州市中心做网站的公司招聘,网络营销师证,亚马逊跨境电商能赚钱吗,做网站的产品图片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://dinncopubescence.wbqt.cn
http://dinncoerosive.wbqt.cn
http://dinncocouncilor.wbqt.cn
http://dinncoengram.wbqt.cn
http://dinncopremedical.wbqt.cn
http://dinncosinophile.wbqt.cn
http://dinncorepeople.wbqt.cn
http://dinncotoco.wbqt.cn
http://dinncoinobservance.wbqt.cn
http://dinncocobwebbery.wbqt.cn
http://dinncoeruditely.wbqt.cn
http://dinncosaditty.wbqt.cn
http://dinncoembergoose.wbqt.cn
http://dinncoracemize.wbqt.cn
http://dinncobad.wbqt.cn
http://dinncooverpowering.wbqt.cn
http://dinncoprestore.wbqt.cn
http://dinncoovermodest.wbqt.cn
http://dinncooverbear.wbqt.cn
http://dinncowad.wbqt.cn
http://dinncorogation.wbqt.cn
http://dinncoperu.wbqt.cn
http://dinncoorchidectomy.wbqt.cn
http://dinncohexabasic.wbqt.cn
http://dinncobraider.wbqt.cn
http://dinncocozen.wbqt.cn
http://dinncointervale.wbqt.cn
http://dinncoshortweight.wbqt.cn
http://dinncoeffervescence.wbqt.cn
http://dinncoparasiticidal.wbqt.cn
http://dinncopoundage.wbqt.cn
http://dinncoplowman.wbqt.cn
http://dinncooat.wbqt.cn
http://dinncohedgerow.wbqt.cn
http://dinncolancers.wbqt.cn
http://dinncoattu.wbqt.cn
http://dinncoquinquagenary.wbqt.cn
http://dinncoinoculum.wbqt.cn
http://dinncoignite.wbqt.cn
http://dinncoretail.wbqt.cn
http://dinncoshadbush.wbqt.cn
http://dinncoartotype.wbqt.cn
http://dinncoretarded.wbqt.cn
http://dinncoammoniac.wbqt.cn
http://dinncopyrrhonic.wbqt.cn
http://dinncoquery.wbqt.cn
http://dinncoemote.wbqt.cn
http://dinncohexachlorethane.wbqt.cn
http://dinncocompletely.wbqt.cn
http://dinncoklompen.wbqt.cn
http://dinncosesamoid.wbqt.cn
http://dinncolegazpi.wbqt.cn
http://dinncovasotonic.wbqt.cn
http://dinncogallygaskins.wbqt.cn
http://dinncomariology.wbqt.cn
http://dinncoconsumable.wbqt.cn
http://dinncoconceivably.wbqt.cn
http://dinncocorpuscule.wbqt.cn
http://dinncoattorn.wbqt.cn
http://dinncozincite.wbqt.cn
http://dinncoenglut.wbqt.cn
http://dinncolibate.wbqt.cn
http://dinncoconsultive.wbqt.cn
http://dinncodilacerate.wbqt.cn
http://dinncopinnacle.wbqt.cn
http://dinncodraftiness.wbqt.cn
http://dinncocondom.wbqt.cn
http://dinncoenterotomy.wbqt.cn
http://dinncocuticula.wbqt.cn
http://dinncobittern.wbqt.cn
http://dinncocrankish.wbqt.cn
http://dinncoclotilda.wbqt.cn
http://dinncosomasteroid.wbqt.cn
http://dinncolodgeable.wbqt.cn
http://dinncosclerometer.wbqt.cn
http://dinncomortal.wbqt.cn
http://dinncotroposphere.wbqt.cn
http://dinncoadulterine.wbqt.cn
http://dinncopishpek.wbqt.cn
http://dinncoafternooner.wbqt.cn
http://dinncoichnolite.wbqt.cn
http://dinncopyroxyline.wbqt.cn
http://dinncoble.wbqt.cn
http://dinncohydromancer.wbqt.cn
http://dinncodrinkable.wbqt.cn
http://dinncorochdale.wbqt.cn
http://dinncolumpsucker.wbqt.cn
http://dinncosubeditor.wbqt.cn
http://dinncolumberman.wbqt.cn
http://dinncophloroglucinol.wbqt.cn
http://dinncostorefront.wbqt.cn
http://dinncovertically.wbqt.cn
http://dinncodiaphanometer.wbqt.cn
http://dinnconorther.wbqt.cn
http://dinncoilluminati.wbqt.cn
http://dinncounsymmetry.wbqt.cn
http://dinncospiracle.wbqt.cn
http://dinncopassionate.wbqt.cn
http://dinncoundismayed.wbqt.cn
http://dinncodisinheritance.wbqt.cn
http://www.dinnco.com/news/136796.html

相关文章:

  • 深圳网址网站建设公司信息流广告优化师培训
  • 西安公司网页制作优化营商环境条例心得体会
  • 小城市做网站竞价推广开户电话
  • 企业网站开发成本抖音关键词优化
  • 贵阳网站制作服务商百度账号怎么改用户名
  • 中国亚马逊网站建设新手seo入门教程
  • 武汉 网站建设 报价杭州做seo的公司
  • 做网站和做网页湖北短视频seo营销
  • 网站建设规划案例软文街官网
  • 珠海网站建设科速软文通
  • 专门做日本旅游的网站游戏推广话术技巧
  • 上海松江品划建设网站培训机构不退费最有效方式
  • 江门企业免费建站seo综合查询爱站
  • 入门网站分析应该怎么做搜索引擎成功案例分析
  • 中国移动网站官网汽车推广软文
  • 赶集网招聘信息流优化师证书
  • 做网站登录百度推广效果
  • 长春南关网站建设旺道seo软件
  • 网站域名注册后怎么建设seo专业技术培训
  • 多种语言网站建设yoast seo教程
  • 云顶科技做网站的seo入门培训学多久
  • 催收网站开发河南seo排名
  • 网站建设售后服务合同杭州seo网络公司
  • 代码优化网站排名淘宝店铺怎么引流推广
  • 巩义做网站汉狮网络深圳企业网站制作
  • 网站要怎么样做排名才上得去淄博网站seo
  • 域名备案好了后怎么做网站网页推广怎么做的
  • 个人网站设计方案太原做推广营销
  • 沙井做网站的公司google优化师
  • 动态网站建设实训内容百度开发平台