1.10.1 • Published 6 months ago

@vrx-arco/app v1.10.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@vrx-arco/app

npm version npm downloads bundle size license

集成 vue-router, pinia

快速完成对动态路由的支持

安装

# ✨ Auto-detect
npx nypm install @vrx-arco/app

# npm
npm install @vrx-arco/app

# yarn
yarn add @vrx-arco/app

# pnpm
pnpm install @vrx-arco/app

# bun
bun install @vrx-arco/app

# deno
deno install @vrx-arco/app

创建

import { Notification } from '@arco-design/web-vue'
import { createVrxArcoApp } from '@vrx-arco/app' 
import App from './App.vue'
import { basicRoutes, dynamicRoutes } from '@/router'
import { usePageStore } from '@/pinia'
import { getPermission } from '@/api'

createVrxArcoApp({
  // 根组件
  rootComponent: App,
  // 渲染根节点
  rootContainer: '#app',
  // 路由配置
  router: {
    // 静态路由部分
    routes: basicRoutes,
    // 动态路由部分
    dynamicRoutes,
    // 根据从远程获取的权限,筛选每个路由
    filterDynamicRoutes: (route, permission) => {
      return permission.includes(route.name)
    },
    // 页面未找到 路由
    pageNotFound: {
      name: 'page404',
      component: () => import('@/views/page/404.vue'),
      meta: {
        title: ''
      },
    },
    // 登陆过期重定向路由 name
    loginExpiredRedirect: 'login',
    // 未登陆时 路由通过 name 白名单
    whiteList: ['login', 'register']
  },
  // 路由遍历前后,添加加载状态控制
  loading: (value: boolean) => {
    const page = usePageStore()
    page.setLoading(value)
  },
  authentication: {
    /**
     * 从远程获取权限
     */
    getPermission: async () => {
      const permission = await getPermission()
      return permission
    },
    /**
     * 用于自定义局部鉴权
     */
    checkPermission: (permission, data) => {
      return true
    },
    /**
     * 判断是否已登陆
     */
    isLogin: () => !!localStorage.getItem('token'),
    // 登陆过期回调
    // 从远程获取权限报错,也会触发该方法
    onLoginExpired: () => {
      Notification.error({
        title: '提示',
        content: '请重新登陆'
      })
    },
  },
})

局部鉴权用组件

<script lang="ts" setup>
import { Permission } from '@vrx-arco/app'
import { Button, Switch } from '@arco-design/web-vue'
</script>

<template>

  <!--  data 传递给 authentication.checkPermission 用作鉴权-->
  <!--  当鉴权失败时,责销毁默认插槽内的组件-->
  <Permission data="user:add:edit">
    <Button>编辑</Button>
  </Permission>

  <!--  data 传递给 authentication.checkPermission 用作鉴权-->
  <!--  当鉴权失败时,hasPermission为 false,可自行处理组件无权限表现 -->
  <Permission data="user:add:del" :destroyOnNoPermission="false">
    <template #default="{hasPermission}">
      <Button :disabled="!hasPermission">删除</Button>
    </template>
  </Permission>

  <!--  data 传递给 authentication.checkPermission 用作鉴权-->
  <!--  当鉴权失败时,使用 noPermission插槽,自行处理无权限组件渲染 -->
  <Permission data="user:add:del">
    <template #default>
      <Switch />
    </template>
    <template #noPermission>
      是
    </template>
  </Permission>
</template>

贡献者

Published under the MIT license. Made by @Colourlessglow and community 💛


🤖 auto updated with automd

1.10.1

6 months ago

1.10.0

6 months ago

1.9.1

7 months ago

1.9.0

7 months ago

1.8.0

8 months ago

1.7.2

9 months ago

1.7.1

9 months ago

1.7.0

10 months ago

1.6.0

11 months ago

1.5.14

12 months ago

1.5.12

1 year ago

1.5.11

1 year ago

1.5.10

1 year ago

1.5.9

1 year ago

1.5.8

1 year ago

1.5.7

1 year ago

1.5.6

1 year ago

1.5.5

1 year ago

1.5.4

1 year ago

1.5.2

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.2.0

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.3.8

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.0

2 years ago

1.1.2

2 years ago

1.0.0

2 years ago

1.0.0-beta.2

2 years ago

1.0.0-beta.3

2 years ago

1.0.0-beta.4

2 years ago

1.0.0-beta.5

2 years ago

1.0.0-beta.0

2 years ago

1.0.0-beta.1

2 years ago

0.2.7

2 years ago

0.1.41

2 years ago

0.1.42

2 years ago

0.1.43

2 years ago

0.1.44

2 years ago

0.1.45

2 years ago

0.1.46

2 years ago

0.1.47

2 years ago

0.1.48

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.6

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.1.40

2 years ago

0.1.33

2 years ago

0.1.34

2 years ago

0.1.35

2 years ago

0.1.36

2 years ago

0.1.37

2 years ago

0.1.38

2 years ago

0.1.39

2 years ago

0.1.30

3 years ago

0.1.31

3 years ago

0.1.32

3 years ago

0.1.27

3 years ago

0.1.28

3 years ago

0.1.29

3 years ago

0.1.20

3 years ago

0.1.21

3 years ago

0.1.22

3 years ago

0.1.23

3 years ago

0.1.24

3 years ago

0.1.25

3 years ago

0.1.26

3 years ago

0.1.19

3 years ago

0.1.18

3 years ago

0.1.17

3 years ago

0.1.16

3 years ago

0.1.15

3 years ago

0.1.14

3 years ago

0.1.13

3 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago