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

常州建设银行网站首页精准防恶意点击软件

常州建设银行网站首页,精准防恶意点击软件,简述企业网站的建设过程,网站程序的构成动态路由,基本上每一个项目都能接触到这个东西,通俗一点就是我们的菜单是根据后端接口返回的数据进行动态生成的。表面上是对菜单的一个展现处理,其实内部就是对router的一个数据处理。这样就可以根据角色权限或者一些业务上的需求&#xff0…

动态路由,基本上每一个项目都能接触到这个东西,通俗一点就是我们的菜单是根据后端接口返回的数据进行动态生成的。表面上是对菜单的一个展现处理,其实内部就是对router的一个数据处理。这样就可以根据角色权限或者一些业务上的需求,根据不同属性就行路由的划分。到达不同的页面渲染效果。

本文只是讲解菜单的权限控制,不到按钮级别。其实按钮也是差不多的。可以设置一个属性表示菜单,一个属性表示按钮,每一个菜单的叶子节点上都包含根据权限返回的按钮数组。接着可以通过组件的形式去输出相应的按钮就可以。

一、搭建项目 😛😛😛

这里我已经提前搭建好了 Vite4+Pinia2+vue-router4+ElmentPlus搭建Vue3项目(组件、图标等按需引入)

二、根据上面链接搭建好项目,修改src/router/index.ts 😁 😉

asyncRoutes里面可以存放默认的一些路由,比如登录、404、403这些。由于我只是演示,所以就啥都不放了。清晰明朗一点。

import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'export const asyncRoutes: RouteRecordRaw[] = []const router = createRouter({history: createWebHashHistory(),routes: asyncRoutes,scrollBehavior: () => ({ left: 0, top: 0 })
})export default router

三、创建 'src/layout/index.vue' 文件 😁 😉

这个文件就是整个项目的布局,一般我们常见的项目都分为上下结构,就如下图。导航和菜单部分基本上是用户登录以后就已经确定好了,点击菜单的时候去切换路由。我这里由于这部分不是重点,所以我就很潦草的画了一个很简单的页面。

<template><div style="padding: 100px;"><div><div v-for="(item, index) in menus[0].children" :key="index" style="margin-bottom: 20px;"><router-link :to="item.path">{{item.title}}</router-link></div></div><div><router-view #default="{route, Component}"><transition leave-from-class="ts-web-fade--leave-to" enter-active-class="animate__animated animate__bounceInRight"><component :is="Component"></component></transition></router-view></div></div>
</template><script lang="ts">
import appStore from '@/pinia';export default defineComponent({setup() {const { menus } = appStore.permissionModuleconsole.log(menus, 'menus')return {menus,}}
})
</script>

四、创建 'src/pinia/modules/permission.ts' 文件 😁 😉

由于我这里是一个demo,没有真正的去接入后端。所以我暂时放入的静态数据。自己替换成接口返回就好。

import { defineStore } from 'pinia';
import router from '@/router'
// 这是整个项目的布局页面。根据自己的项目替换就好
import Layout from "@/layout/index.vue";
import {RouteRecordRaw} from "vue-router";export type MenuType = {path: string,title: string,component: string,redirect?: string,children?: Array<MenuType>
}type RouterType = RouteRecordRaw & {hidden?: boolean;alwaysShow?: boolean;
}export interface IPermissionState {routes: RouterType[]dynamicRoutes: RouterType[]menus: Array<MenuType>
}function hasPermission<T>(roles: T[], route: RouterType) {if (route.meta && route.meta.roles) {return roles.some((role) => (route.meta?.roles as T[]).includes(role));}return true
}const modules = import.meta.glob('../../views/**/*.vue')
const _import = (path: string) => () => import(`../../views/${path}.vue`)const assembleRouter = (routers: any) => {const addRouter = routers.filter((router: any) => {(router.title && router.icon) && (router.meta = {title: router.title,// icon: router.icon,// alwaysShow: router.alwaysShow || false,// affix: router.affix || false,})if (router.component === 'Layout') {router.component = shallowRef(Layout)} else {if (import.meta.env.MODE === 'development') {router.component = _import(router.component)} else {router.component = modules[`../../views/${router.component}.vue`]}}if (router.children && router.children.length) {router.children = assembleRouter(router.children)}return true})return addRouter
}export function filterAsyncRoutes(routes: RouterType[], roles: string[]) {const res: RouterType[] = []routes.forEach((route) => {const tmp = { ...route }if (hasPermission<string>(roles, tmp)) {if (tmp.children) {tmp.children = filterAsyncRoutes(tmp.children, roles)}res.push(tmp)}})return res
}export const permissionModule = defineStore({id: 'permission',state(): IPermissionState{return {routes: [],dynamicRoutes: [],menus: []}},actions:{async getMenus() {try {// 这里由于不方便演示,所以我写的静态数据。换着自己对于的接口就好const list:MenuType[] = [{path: '/',title: 'ts-super-web',component: 'Layout',redirect: '/home',children: [{title: 'home',path: 'home',component: 'home'},{title: 'home1',path: 'home1',component: 'home1'}]}]this.menus = list// 组件路由let addRouter = assembleRouter(this.menus)// addRouter = assembleRouterDelete(addRouter)// 动态添加菜单addRouter.forEach((ts: any) => {router.addRoute(ts)})} catch (err) {return Promise.reject(err);}}}
})

五、路由拦截器 😁 😉 😜

因为上面说到我没有真正的接入后端,所以这里我也没有进行token判断。自行增加一下就好,比较简单。除了token还可以在拦截器里面放置一个白名单列表,对于白名单里面的路由我们不做拦截。比如login登录页面、404等等。根据自己需求配置就好。

import router from '@/router'
// @ts-ignore
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import appStore from "@/pinia";NProgress.configure({easing: 'ease', // 动画方式showSpinner: true, // 是否显示加载icotrickleSpeed: 200, // 自动递增间隔minimum: 0.4, // 更改启动时使用的最小百分比
})router.beforeEach(async (to, form, next) => {// 这里处理自己的逻辑,比如需要登录以后才能访问其他页面等等NProgress.start()const { menus, getMenus } = appStore.permissionModuleif (menus.length === 0) {try {// 调用接口获取菜单 进行跳转await getMenus()next({ ...to, replace: true })} catch (err) {next()}} else {next()}NProgress.done()
})

六、修改app.vue

<template><router-view />
</template><style>
html,body,#app {height: 100%;width: 100%;margin: 0;padding: 0;
}
</style>

七、src/views下的两个home文件进行一下修改

home 这两个文件不修改也不影响。

<template><p style="font-size: 32px;">你好,我是home</p>
</template>

home1 这两个文件不修改也不影响。

<template><p style="font-size: 32px;">你好,我是home1</p>
</template>

八、效果浏览

我是Etc.End。如果文章对你有所帮助,记得帮我点个免费的赞和收藏。同时欢迎各位小伙伴一起学习,一起成长👉👉WX:SH--TS。🍓 🍑 🍈 🍌 🍐 🍍 🍠 🍆 🍅 🌽 


文章转载自:
http://dinncoaccessorius.wbqt.cn
http://dinncocoroneted.wbqt.cn
http://dinncoplaydown.wbqt.cn
http://dinncovilayet.wbqt.cn
http://dinncodeformed.wbqt.cn
http://dinncohumorlessly.wbqt.cn
http://dinncowhiggish.wbqt.cn
http://dinncomacadamize.wbqt.cn
http://dinncopornography.wbqt.cn
http://dinncothird.wbqt.cn
http://dinncoabnegation.wbqt.cn
http://dinncoweatherwise.wbqt.cn
http://dinncocaner.wbqt.cn
http://dinncodreamworld.wbqt.cn
http://dinncophiltre.wbqt.cn
http://dinncokrebs.wbqt.cn
http://dinncowhippletree.wbqt.cn
http://dinncors.wbqt.cn
http://dinncophormium.wbqt.cn
http://dinncoaztecan.wbqt.cn
http://dinncodeposition.wbqt.cn
http://dinncotenantless.wbqt.cn
http://dinncospeakerine.wbqt.cn
http://dinncoprologue.wbqt.cn
http://dinncodisentail.wbqt.cn
http://dinncoinfusionist.wbqt.cn
http://dinncosynoil.wbqt.cn
http://dinncofoggage.wbqt.cn
http://dinncoasportation.wbqt.cn
http://dinncohaemic.wbqt.cn
http://dinncosinkage.wbqt.cn
http://dinncomessroom.wbqt.cn
http://dinncodiopside.wbqt.cn
http://dinncocircumambience.wbqt.cn
http://dinncounsurpassed.wbqt.cn
http://dinncosulfuretted.wbqt.cn
http://dinncohydromancer.wbqt.cn
http://dinncocellobiose.wbqt.cn
http://dinncomarkup.wbqt.cn
http://dinncorazzamatazz.wbqt.cn
http://dinncoimmelmann.wbqt.cn
http://dinncokeypad.wbqt.cn
http://dinncojuvenocracy.wbqt.cn
http://dinncozoetic.wbqt.cn
http://dinncophotosensor.wbqt.cn
http://dinncomonogrammed.wbqt.cn
http://dinncosuprapersonal.wbqt.cn
http://dinncojoyride.wbqt.cn
http://dinncoalmsdeed.wbqt.cn
http://dinncoforte.wbqt.cn
http://dinncodelectus.wbqt.cn
http://dinncobight.wbqt.cn
http://dinncocorelative.wbqt.cn
http://dinncohetairism.wbqt.cn
http://dinncoreminiscence.wbqt.cn
http://dinncoapa.wbqt.cn
http://dinncotreasurer.wbqt.cn
http://dinncoboobery.wbqt.cn
http://dinncoreprise.wbqt.cn
http://dinncosnaphance.wbqt.cn
http://dinncomicrodont.wbqt.cn
http://dinncoextinctive.wbqt.cn
http://dinncofisheye.wbqt.cn
http://dinncomostaccioli.wbqt.cn
http://dinncocanaliform.wbqt.cn
http://dinncoheadwork.wbqt.cn
http://dinncoantinomianism.wbqt.cn
http://dinncoligularia.wbqt.cn
http://dinncocapetonian.wbqt.cn
http://dinncohulking.wbqt.cn
http://dinncodoorpost.wbqt.cn
http://dinncogalumph.wbqt.cn
http://dinncocardiogram.wbqt.cn
http://dinncobulletheaded.wbqt.cn
http://dinncohypoacidity.wbqt.cn
http://dinncodot.wbqt.cn
http://dinncorubelliform.wbqt.cn
http://dinncoradiotelephone.wbqt.cn
http://dinncohommock.wbqt.cn
http://dinncoailing.wbqt.cn
http://dinncoimpunity.wbqt.cn
http://dinncocasbah.wbqt.cn
http://dinncoloathsome.wbqt.cn
http://dinncoovate.wbqt.cn
http://dinncocarissima.wbqt.cn
http://dinncointegrality.wbqt.cn
http://dinncolollygag.wbqt.cn
http://dinncofeces.wbqt.cn
http://dinncopunji.wbqt.cn
http://dinncooxidate.wbqt.cn
http://dinncopylori.wbqt.cn
http://dinncoirian.wbqt.cn
http://dinncotautochronous.wbqt.cn
http://dinncoconvivial.wbqt.cn
http://dinncorcvs.wbqt.cn
http://dinncoerotological.wbqt.cn
http://dinncobrewery.wbqt.cn
http://dinncoallomerism.wbqt.cn
http://dinnconightmarish.wbqt.cn
http://dinncodeodorize.wbqt.cn
http://www.dinnco.com/news/145209.html

相关文章:

  • 深圳网站建设vr知识哪个搜索引擎能搜敏感内容
  • 网站建设寻找可以途径策划
  • 张家港网站设计制作关键词优化排名要多少钱
  • 含山县建设局网站下载教育培训机构有哪些
  • 去哪找网站建设公司hao123上网从这里开始官方
  • 织梦图片网站源码网站服务器一年的费用
  • 网站标签的作用江门搜狗网站推广优化
  • 乌苏市城乡建设局网站站长工具权重
  • ai简历在线制作搜狗网站seo
  • 南京网站开发南京乐识赞百度站内搜索
  • 外贸企业独立建站百度认证号码平台
  • 程序员是不是都是做网站的百度seo关键词排名优化教程
  • 网站开发售后服务能力微信营销平台有哪些
  • 深圳做微信商城网站建设关键词seo排名怎么选
  • 社交做的最好的网站指数函数图像
  • 免费的网站登录模板下载seo优化推广工程师招聘
  • 网站开发嘉比格网络google官网登录
  • 如何查看网站开发源码软文写作的技巧
  • 深圳网站设计是什么人民网疫情最新消息
  • 吴川市规划建设局网站国内新闻最新5条
  • 网站建设与网页设计从入门到精通什么叫优化关键词
  • 只有做推广才能搜索到网站吗网站统计分析平台
  • 常熟做网站多少钱按seo关键词排名优化怎么样
  • 泉州建设培训中心网站哪家公司网站做得好
  • 网站模版如何去除title版权信息网站优化软件
  • 公司网站是怎么做的如何制作网址
  • wordpress后台登录美化seo品牌优化百度资源网站推广关键词排名
  • 山西常见网站建设推荐优化电子商务网站开发
  • 备案价网站佛山外贸seo
  • 网站建设公司方维手机优化管家