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

jv-account

v4.0.0

Published

jv帐号系统

Downloads

2

Readme

JV内部帐号系统

Single Page Application Isomorphic Example for Egg + Vue, Front-End and Node of The Application are Written in TypeScript.

Document

QuickStart

  • Development Mode
$ npm run dev
  • Publish Mode
npm run tsc
npm run build
npm start

Features

分层

后台分为 Model(数据类) Bll(业务逻辑层) Dal(DB层) 网上的三层介绍https://wenku.baidu.com/view/888e9be8f8c75fbfc77db29c.html

ORM

DB访问我们采用 typeorm https://github.com/typeorm/typeorm

Model

model跟DB中的表一对一关联,无需我们手工创建和修改表,只要修改model。如果数据库用户有权限typeorm会帮我们维护表结构。 示例:

'use strict';

import {Entity, BaseEntity, PrimaryGeneratedColumn, Column} from "typeorm";

@Entity('t_article')
export default class Article extends BaseEntity {
  @PrimaryGeneratedColumn({
    name: 'Fid',
    type: 'int',
    comment: '自增唯一健'
  })
  public id?: number;

  @Column({
    name: 'Ftitle',
    type: 'varchar',
    length: 32
  })
  public title?: string;
  
  @Column({
    name: 'Fcreate_time',
    type: 'datetime'
  })
  public createTime?: string;

  @Column({
    name: 'Fmodify_time',
    type: 'timestamp'
  })
  public modifyTime?: string;
}

数据库访问层

数据库访问也是全部放在了service/dal目录。 如果业务场景不需要特殊的DB访问逻辑,那么它的逻辑层service只需继承dal/base.ts即可。

逻辑层

逻辑层全放在service/bll目录下, 继承service/dal/base就可以拥有基础的数据库操作接口。如果需要特殊DB访问逻辑的,请在dal中创建独立的DB访问service并继承BaseService

Controller

我们把controller封装成了一个统一的入口,不需要重复配置router。 例如,我们在controller下创建一个admin.ts:


import { Context } from 'egg';
import Article from '../model/article';

export default class AdminController {
  public async list(ctx: Context) {
    return await ctx.service.bll.article.getAll();
  }
}

不需要做任何配置,我们就可以通过http://fmp.oa.com/framework/api/admin/list 访问到这个接口。

如果需要在controller中使用多级目录,则在访问url中用/表示,如:/api/my/admin/list, 表示在controller/my目录下的admin controller中的list方法。

返回数据

你只需要在你的接口中,直接return {} 任意你想返回的数据结构。api会把它赋给最终结果的data属性下。 例如:

public async add(ctx: Context) {
    return {"name": "my"};
  }

最终调用者拿到的是

{
  ret: 0,
  msg: "",
  data: {
    "name": "my"
  }
}

如果你想自已定义返回的结果,你也可以返回IApiResult结构。底层会原样返回。

/**
 * api 返回数据标准结构
 */
declare interface IApiResult {
  ret: number,
  msg: string,
  data?: any
}

抛出异常

基础apicatch异常,然后按同上的返回方式返回retmsg。这里的ret统一定义为10001。 如果controller方想自定义异常信息,你可以直接抛出IApiResult结构信息。

throw {ret: 10086, msg: "我是自定义错误"};

服务鉴权

服务鉴权主要提供一个简单的拒绝非法请求功能,基于ts的decorator实现。 服务端在config中需要配置一个accessKey, 需要调用当前服务的必须知道这个服务的key并用通用方法计算出来。

// 中间件access配置
  // 用来请求鉴权  只需要针对/api/ 这类的service请求
  // 计算方法 md5(accessKey + ',' + timestamp)
  config.access = {
    enabled: true, // false 表示不启用鉴权
    accessKey: 'lct.framework' // 用来计算token的当前系统唯一key
  }

可以用配置enabled来启用关闭,每个系统自已可以配置唯一的accessKey来识别请求。

当一个接口需要使用鉴权时,只需加上装饰器即可。


import { Context } from 'egg';
import decorators from "../lib/decorator";

export default class AdminController {

  @decorators.checkApiToken(true) // 标记需要校验token
  public async list(ctx: Context) {
    return await ctx.service.bll.article.getAll();
  }
}

TypeScript

  • https://github.com/kaorun343/vue-property-decorator
  • https://github.com/ktsn/vuex-class

License

MIT