npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cta-template-admin

v1.3.4

Published

基于react18的模板项目,支持路由keepalive,历史访问页签等

Downloads

10

Readme

react + vite 模板项目

Publish Docker Image CI

一个可以实现路由 keepAlive,具有类似浏览器访问页签功能的模板项目。

阿里云在线预览 | vercel online

example

模板下载使用

可以通过 npx 命令安装此项目

npx create-template-app my-app --template admin

一、权限管理

路由权限

  1. src/config/access.ts中,同 umi 使用方式一致,配置对应权限对象。
import { InitialStateType } from "@/core/context/global";

export default function accessFactory(
  initialState: InitialStateType
): Record<string, boolean> {
  // const { accessInfo } = initialState

  return {
    canNav1: false,
  };
}
  1. src/routes/index.tsx中,配置对应的 access key。
...

path: 'brandManage',
name: '品牌管理',
access: 'canNav1', // 对应的key
icon: <BoldOutlined />,
layout: {
	topItemRender: false
},

...

组件权限

src/core/Access中:

  1. Access组件:用于判断返回的 key,是否包含在后端的权限列表中,进而是否渲染传入的children
<Access access="enterprisePrivate-label-batchImport">
  <Button onClick={handleBatchImport}>批量导入</Button>
</Access>
  1. useAccesshook:返回对应的 access key 是否包含在后端返回的权限列表中。
const noticeUpdateAuth = useAccess("notice-update");

二、keepAlive

注意:

  1. 为了稳定起见 keepAlive 仅仅针对路由级别生效。
  2. 默认不会开启 keepAlive
  3. keepAlive 最多缓存的组件数,默认为 10 个,超过最大数量后会直接删除第一个缓存的组件。(可以在 core.ts 中配置 maxLength 来扩大缓存容积)

开启方法:

在路由配置中增加keepAlive:true选项。

{
	path: 'brandRule',
	name: '品牌规则',
	keepAlive: true, // 开启
	element: lazyLoad(lazy(() => import('@/pages/BrandManage/BrandRule')))
},

三、页签功能

默认开启页签功能,如果需要关闭此功能。在core.ts中配置isTab: false

页签支持拖拽,刷新,关闭等操作。

四、环境变量使用

访问: getEnv()

在项目根目录下,配置了三种环境文件.env.development,.env.test,.env.production。分别对应本地、测试、生产三个环境。里面已经配置了相应的环境变量和gateway地址

如需更多配置,直接增加对应的字段即可。为了更加友好的提示,增加对应字段后,在src/typings/vite-env.d.ts中加入新增字段的类型。

interface ImportMetaEnv {
  readonly VITE_NODE_ENV: "development" | "test" | "production";
  readonly VITE_PREFIX_URL: string;
}

五、接口请求

src/core/service中封装了requestrequestLegacy两个请求实例。分别针对gateway接口和之前走nginx代理的接口。

六、开发代理

vite.config.ts中增加自定义代理即可。

...

server: {
	host: '127.0.0.1',
	port: 3000,
	open: true,
	proxy: {
		'/api': {
			target: proxyTarget.api,
			changeOrigin: true
		},
		'/user': {
			target: proxyTarget.nr,
			changeOrigin: true
		}
	}
}
...