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

@mmstudio/an000034

v1.0.202004171635

Published

获取用户角色菜单

Downloads

5

Readme

获取用户角色菜单

redis

考虑到可多实例部署情况,需要用到redis数据库用来存储用户session

postgres

用户数据存储到postgres数据库中,其json字段更便于存储可扩展的用户信息

用户表

表结构

角色表

字段名|字段类型|字段描述 ---|---|--- id|text|角色ID name|text|角色名称

菜单表

字段名|字段类型|字段描述 ---|---|--- id|text|菜单ID name|text|菜单名称 parent|text|父级菜单ID priority|smallint|显示优先级 url|text|页面地址 authcode|smallint|用户控制码,每一位表示页面上一个功能(通常为按钮)是否可用,比如0b01表示第一个功能可用,0b11表示第一和第二个功能可用,而0b10表示第二个功能可用,第一个功能不可用

角色菜单关联表

字段名|字段类型|字段描述 ---|---|--- roleid|text|角色ID role.id menuid|text|菜单ID menu.id

用户角色关联表

字段名|字段类型|字段描述 ---|---|--- userid|text|用户ID user.id roleid|text|角色ID role.id

建表语句

DROP TABLE IF EXISTS role;
CREATE TABLE role
(
	id text NOT NULL,
	name text NOT NULL,
	PRIMARY KEY (id)
)
WITH (oids = false);

COMMENT ON TABLE role IS '角色表';
COMMENT ON COLUMN role.name IS '角色名称';

DROP TABLE IF EXISTS menu;
CREATE TABLE menu
(
	id text NOT NULL,
	name text NOT NULL,
	parent text,
	priority smallint,
	url text,
	authcode smallint,
	PRIMARY KEY (id)
)
WITH (oids = false);

COMMENT ON TABLE menu IS '菜单表';
COMMENT ON COLUMN menu.id IS '菜单ID';
COMMENT ON COLUMN menu.name IS '菜单名称';
COMMENT ON COLUMN menu.parent IS '父级菜单ID';
COMMENT ON COLUMN menu.priority IS '显示优先级';
COMMENT ON COLUMN menu.url IS '页面地址';
COMMENT ON COLUMN menu.authcode IS '用户控制码,每一位表示页面上一个功能(通常为按钮)是否可用,比如0b01表示第一个功能可用,0b11表示第一和第二个功能可用,而0b10表示第二个功能可用,第一个功能不可用';

DROP TABLE IF EXISTS rolemenu;
CREATE TABLE rolemenu
(
	roleid text NOT NULL,
	menuid text NOT NULL,
	CONSTRAINT pk_rolemenu PRIMARY KEY (roleid, menuid)
)
WITH (oids = false);

COMMENT ON TABLE rolemenu IS '角色菜单关联表';
COMMENT ON COLUMN rolemenu.roleid IS '角色ID role.id';
COMMENT ON COLUMN rolemenu.menuid IS '菜单ID menu.id';

DROP TABLE IF EXISTS userole;
CREATE TABLE userole
(
	userid text NOT NULL,
	roleid text NOT NULL,
	CONSTRAINT pk_userole PRIMARY KEY (userid, roleid)
)
WITH (oids = false);

COMMENT ON TABLE userole IS '用户角色关联表';
COMMENT ON COLUMN userole.userid IS '用户ID user.id';
COMMENT ON COLUMN userole.roleid IS '角色ID role.id';

完整的配置文件

{
	"redis": {
		"url": "redis://127.0.0.1:6379",
		"expiration": 20000
	},
	"dbs": {
		"sys": {
			"type": "postgres",
			"source": "postgres://mmstudio:[email protected]:5432/mmstudio"
		}
	}
}

docker-file

docker-compose安置

version: '3.7'

services:
  redis:
    image: redis
    container_name: redis
    ports:
      - 6379:6379
    # networks:
    #   - app

  postgres:
    image: postgres
    container_name: postgres
    volumes:
      - /home/taoqf/data/postgre:/var/lib/postgresql/data
    restart: always
    environment:
      POSTGRES_DB: mmstudio
      POSTGRES_USER: mmstudio
      POSTGRES_PASSWORD: Mmstudio123
    ports:
      - 5432:5432
  adminer:
    container_name: adminer
    image: adminer
    restart: always
    ports:
      - 8080:8080