4 Star 2 Fork 0

DianaAkko / vue3+vite+element-plus+pinia

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MulanPSL-2.0

该模板是根据PanJiaChen大佬的vue-element-admin模板来修改的vue3+vite+element-plus+pinia版本,有需要可以去研究一下。

当前框架仓库:https://gitee.com/DianaYako/vue3-vite-element-plus-pinia

如果有与vue-element-admin模板功能差异、BUG、任何框架、模板上的BUG,欢迎与相关人员联系进行修复、填充,或者在相关仓库提issue。

开始

运行及打包

  • 安装依赖:npm install OR npm i
  • 运行 - 开发环境:npm run dev - 对应变量文件:.env.development
  • 运行 - 生产环境:npm run pro - 对应变量文件:.env.production
  • 运行 - 测试环境:npm run test - 对应变量文件:.env.test
  • 打包 - 生产环境:npm run build【一般用来部署到最终环境并且是可生产版本】 - 对应变量文件:.env.production
  • 打包 - 测试环境:npm run buildTest【一般用来部署到测试服务器进行线上测试】 - 对应变量文件:.env.test

框架说明

框架配置【/src/global/setting.ts】

如果想要修改一些配置,例如隐藏tags-view、左上角logo、面包屑导航等,可以进入该文件进行配置,该文件内有注释解释各个配置项的功能。

路由【Routes】相关规则(主要是写法)

{
  path: string // 必填 不用说
  name: string // 必填 一定要填写 不然很多功能会出现问题,并且保持唯一 (注:父子路由之间,父级路由也必须填写路由【因为面包屑算法识别以及规范】)
  component: Component // 必填
  // ...等其他路由信息
  // 框架衍生其他信息
  meta: {
    // 设置为 true 时,该路由不会出现在侧边栏导航,比如login、文章详情页等。
    hidden: boolean // 默认 false
    
    // 当你一个路由下面的 children 声明的路由大于1个时,自动会变成嵌套的模式--如组件页面
    // 只有一个时,会将那个子路由当做根路由显示在侧边栏--如引导页面
    // 若你想不管路由下面的 children 声明的个数都显示你的根路由
    // 你可以设置 alwaysShow: true,这样它就会忽略之前定义的规则,一直显示根路由
    alwaysShow: boolean // 默认 false 或者 undefined
    
    title: string // 设置该路由在侧边栏和面包屑中展示的名字
    icon: string // 设置该路由的图标,支持 svg-class,也支持 el-icon-x element-ui 的 icon
    keepAlive: boolean, // 如果设置为true 则会对当前页面进行缓存
    noCache: boolean // 如果设置为true,则不会被 <keep-alive> 缓存(默认 false)(用于tags-view)
    breadcrumb: boolean //  如果设置为false,则不会在breadcrumb面包屑中显示(默认 true)
    affix: boolean // 如果设置为true,它则会固定在tags-view中(默认 false)
  
    // 当路由设置了该属性,则会高亮相对应的侧边栏。
    // 这在某些场景非常有用,比如:一个文章的列表页路由为:/article/list
    // 点击文章进入文章详情页,这时候路由为/article/1,但你想在侧边栏高亮文章列表的路由,就可以进行如下设置
    activeMenu: string

    // 针对性缓存 -- 字符串数组(字符串为路由name)
    // 在该数组内写入所要针对页面进行缓存的路由name
    // 例子;A页面跳转B页面(name:BPAGE),A页面路由的meta.cacheToNames为['BPAGE']即可,这时A->B->A两次跳转后A页面的内容为缓存过的,不会变动,A->C->A会重新渲染,不进行缓存
    // 注意:如果按照上述例子,假如A页面name为APAGE,需要在A页面的script标签内写入name,例如:<script setup lang="ts" name="APAGE">
    cacheToNames: Array<string>
  }
}

相关例子(列举一些常见的)

  • 文章列表页、新增修改页、详情页。【层级模式,就是在详情页等子页时,面包屑导航会有上级导航】
    {
      path: '/article',
      component: Layout,
      redirect: '/article',
      name: 'Article',
      meta: { title: '文章列表' },
      children: [
        {
          path: '',
          name: 'ArticleList',
          component: () => import('@/views/article/index.vue'),
          meta: { title: '文章列表' },
        },
        {
          path: 'createOrUpdate',
          name: 'ArticleCreateOrUpdate',
          component: () => import('@/views/article/childs/create-or-update/index.vue'),
          meta: { title: '新增/修改文章', hidden: true },
        },
        {
          path: 'detail',
          name: 'ArticleDetail',
          component: () => import('@/views/article/childs/detail/index.vue'),
          meta: { title: '文章详情', hidden: true },
        }
      ]
    }
  • 列表页、新增修改页、详情页。【平级模式,就是在详情页等子页时,面包屑导航不会有上级导航】
    {
      path: '/article',
      component: Layout,
      redirect: '/article/list',
      name: 'Article',
      meta: { title: '文章列表', icon: 'Search' },
      children: [
        {
          path: 'list',
          name: 'ArticleList',
          component: () => import('@/views/article/index.vue'),
          meta: { title: '文章列表' },
        },
        {
          path: 'detail',
          name: 'ArticleDetail',
          component: () => import('@/views/article/childs/detail/index.vue'),
          meta: { title: '文章详情', hidden: true },
        }
      ]
    }
  • 多级导航
    {
      path: '/muti',
      component: Layout,
      redirect: '/muti/',
      meta: { title: '多级导航', icon: 'User' },
      children: [
        {
          path: 'article-list',
          name: 'Article',
          children: [
            {
              path: '',
              name: 'ArticleList',
              component: () => import('@/views/article/index.vue'),
              meta: { title: '文章列表' },
            },
            {
              path: 'createOrUpdate',
              name: 'ArticleCreateOrUpdate',
              component: () => import('@/views/article/childs/create-or-update/index.vue'),
              meta: { title: '新增/修改文章', hidden: true },
            },
            {
              path: 'detail',
              name: 'ArticleDetail',
              component: () => import('@/views/article/childs/detail/index.vue'),
              meta: { title: '文章详情', hidden: true },
            }
          ]
        },
        {
          path: 'audit',
          name: 'Audio',
          meta: { title: '审核列表' },
          children: [
            {
              path: '',
              name: 'AuditList',
              component: () => import('@/views/audit/index.vue'),
              meta: { title: '审核列表' },
            },
            {
              path: 'detail',
              name: 'AuditDetail',
              component: () => import('@/views/audit/childs/detail/index.vue'),
              meta: { title: '审核详情', hidden: true },
            }
          ]
        },
        {
          path: 'user',
          name: 'User',
          meta: { title: '用户管理' },
          children: [
            {
              path: 'user-school',
              name: 'UserSchool',
              meta: { title: '学校用户' },
              children: [
                {
                  path: 'user-school-teacher',
                  name: 'UserSchoolTeacher',
                  meta: { title: '教师列表' },
                  component: () => import('@/views/user/childs/school/childs/teacher/index.vue')
                },
                {
                  path: 'user-school-student',
                  name: 'UserSchoolStudent',
                  meta: { title: '学生列表' },
                  component: () => import('@/views/user/childs/school/childs/student/index.vue')
                }
              ]
            }
          ]
        }
      ],
    }

路由权限相关

1、根据路由id动态渲染

前端写路由的地方每个路由的meta参数中加一个id的唯一路由标识符,

前端用token来请求当前用户可以访问的页面的id(数组或者是树结构都可以),

然后前端在第一次进页面的时候进行获取一次这个id数组,然后进行通过这个id数组来判断要显示的路由目录,

路由的id不在这个id数组中的就是不显示(或者是直接不添加这个路由)

注:如果有父子目录,且父路由只有一个子路由,那么给予子路由id来判断即可,权限判断会判断当前目录下是否有有效菜单,没有则不显示。

相关写法

{
  path: '/muti',
  component: Layout,
  redirect: '/muti/',
  meta: { title: '多级导航', icon: 'User' },
  children: [
    {
      path: 'article-list',
      name: 'Article',
      children: [
        {
          path: '',
          name: 'ArticleList',
          component: () => import('@/views/article/index.vue'),
          meta: { title: '文章列表', id: 1 },
        },
        {
          path: 'createOrUpdate',
          name: 'ArticleCreateOrUpdate',
          component: () => import('@/views/article/childs/create-or-update/index.vue'),
          meta: { title: '新增/修改文章', hidden: true, id: 2 },
        },
        {
          path: 'detail',
          name: 'ArticleDetail',
          component: () => import('@/views/article/childs/detail/index.vue'),
          meta: { title: '文章详情', hidden: true, id: 3 },
        }
      ]
    },
    {
      path: 'audit',
      name: 'Audio',
      meta: { title: '审核列表' },
      children: [
        {
          path: '',
          name: 'AuditList',
          component: () => import('@/views/audit/index.vue'),
          meta: { title: '审核列表', id: 1 },
        },
        {
          path: 'detail',
          name: 'AuditDetail',
          component: () => import('@/views/audit/childs/detail/index.vue'),
          meta: { title: '审核详情', hidden: true, id: 2 },
        }
      ]
    }
  ],
}

上方实例,如果没有审核列表和文章列表的权限,那么整个多级导航的菜单则都不显示。

2、根据角色动态渲染

这个简单点说,就是给每个路由的meta中添加一个role属性,然后再获取登录用户信息时,会有一个当前登录人的角色信息,然后再动态添加路由时根据两者进行判断是否有权限即可。

木兰宽松许可证, 第2版 木兰宽松许可证, 第2版 2020年1月 http://license.coscl.org.cn/MulanPSL2 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: 0. 定义 “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 “法人实体”是指提交贡献的机构及其“关联实体”。 “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 1. 授予版权许可 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 2. 授予专利许可 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 3. 无商标许可 “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 4. 分发限制 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 5. 免责声明与责任限制 “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 6. 语言 “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 条款结束 如何将木兰宽松许可证,第2版,应用到您的软件 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; 3, 请将如下声明文本放入每个源文件的头部注释中。 Copyright (c) [Year] [name of copyright holder] [Software Name] is licensed under Mulan PSL v2. You can use this software according to the terms and conditions of the Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2 THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v2 for more details. Mulan Permissive Software License,Version 2 Mulan Permissive Software License,Version 2 (Mulan PSL v2) January 2020 http://license.coscl.org.cn/MulanPSL2 Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: 0. Definition Software means the program and related documents which are licensed under this License and comprise all Contribution(s). Contribution means the copyrightable work licensed by a particular Contributor under this License. Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. Legal Entity means the entity making a Contribution and all its Affiliates. Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. 1. Grant of Copyright License Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. 2. Grant of Patent License Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. 3. No Trademark License No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4. 4. Distribution Restriction You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. 5. Disclaimer of Warranty and Limitation of Liability THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 6. Language THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. END OF THE TERMS AND CONDITIONS How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; iii Attach the statement to the appropriate annotated syntax at the beginning of each source file. Copyright (c) [Year] [name of copyright holder] [Software Name] is licensed under Mulan PSL v2. You can use this software according to the terms and conditions of the Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2 THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v2 for more details.

简介

Vue3 Element Admin 展开 收起
MulanPSL-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/diana-akko/vue3-vite-element-plus-pinia.git
git@gitee.com:diana-akko/vue3-vite-element-plus-pinia.git
diana-akko
vue3-vite-element-plus-pinia
vue3+vite+element-plus+pinia
master

搜索帮助