simple_admin

package module
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2020 License: MIT Imports: 27 Imported by: 0

README

中文

about simple_admin

First time , very thanks for iris framework and developer to helps~

Now talk something , this library just resolve a small and simple problem :

Xorm or gorm Why not provide a simple or small struct model visible dashboard

My trust 99% golang uses people need this

Wait long time not has , start with me , but i time and ability is small and limited !

So I'm just use i familiar technology :

  • iris
  • xorm
  • casbin -> rbac
  • react -> ant.design

Hope to help everyone !

preview

welcome dashBoard dataList guest userManage

use

Install

go get https://github.com/23233/simple_admin

Examples -> https://github.com/23233/simple_admin/tree/master/_examples


Ready -> Defined you struct

type TestModelA struct {
	Id   uint64 `xorm:"autoincr pk unique" json:"id"`
	Name string `xorm:"varchar(20)"`
}

type TestModelB struct {
	Id   uint64 `xorm:"autoincr pk unique" json:"id"`
	Desc string `xorm:"varchar(60)"`
}

Ready -> Defined you xorm engine


Engine, err = xorm.NewEngine("mysql", dbUrl)

Ready -> Defined iris application

app := iris.New()

Go -> Register simple_admin

modelList := []interface{}{new(TestModelA), new(TestModelB)}

_, err := simple_admin.New(simple_admin.Config{
    Engine:    engine,
    App:       app,
    ModelList: modelList,
    Name:      "app name",
    RunSync:   true, // this is xorm sync2
    Prefix:    "/admin", // path prefix like app.Prefix("/admin")
})

Go -> Run you app open browser http://127.0.0.1:8080/admin Yes god job

app.Listen(":8080")

warning

  • first, now don't support xorm deleted tag delete use Unscoped methods!
  • the best you do not use custom usermodel , admin isolation is good!

model custom tags (sp) now support

example: sp("key:value") sp("key(value)") sp("key('value')")
  • autogen -> mark columns is code auto generate not handle
sp("autogen")
  • lineTo -> if custom action , default value use this define for select row
sp("lineTo(Id)")
  • fk -> foreign key , support one to tone and many to one , if use multiple is many to one , just only support id columns , must be have id field !!!
sp("fk('ComplexModelC')") 
sp("fk('ComplexModelC') multiple")
  • tag -> front show whats ? now support custom tag , default show text , options: img
sp:"tag(img)"

event support

  • SpInsertBefore
  • SpInsertAfter
  • SpUpdateBefore
  • SpUpdateAfter
  • SpDeleteBefore()
  • SpDeleteAfter()

custom action

  • func name must use SpAction , just like SpAction() SpAction123() is ok , must return simple_admin.CustomAction struct !

todo features

  • [] full test
  • [] gorm support
  • [] gin support
  • dashboard
  • simple event monitor
  • add spider visit monitor options enable!
  • custom action
  • [] fine permission manage
  • [] support micro frontend , use qiankun
  • [] beat more features

Documentation

Overview

Code generated for package simple_admin by go-bindata DO NOT EDIT. (@generated) sources: simple_admin_templates/external_chartAddEdit.chunk.css simple_admin_templates/external_chartAddEdit.js simple_admin_templates/p__404.js simple_admin_templates/p__Welcome.chunk.css simple_admin_templates/p__Welcome.js simple_admin_templates/p__account__changePassword.chunk.css simple_admin_templates/p__account__changePassword.js simple_admin_templates/p__dashboard__add.chunk.css simple_admin_templates/p__dashboard__add.js simple_admin_templates/p__dashboard__edit.chunk.css simple_admin_templates/p__dashboard__edit.js simple_admin_templates/p__dashboard__index.chunk.css simple_admin_templates/p__dashboard__index.js simple_admin_templates/p__dataShow.chunk.css simple_admin_templates/p__dataShow.js simple_admin_templates/p__dataShow__single.chunk.css simple_admin_templates/p__dataShow__single.js simple_admin_templates/p__layout__SecurityLayout.chunk.css simple_admin_templates/p__layout__SecurityLayout.js simple_admin_templates/p__userManage__index.chunk.css simple_admin_templates/p__userManage__index.js simple_admin_templates/p__user__login__index.chunk.css simple_admin_templates/p__user__login__index.js simple_admin_templates/simple_admin.html simple_admin_templates/umi.css simple_admin_templates/umi.js simple_admin_templates/vendors~external_chartAddEdit.chunk.css simple_admin_templates/vendors~external_chartAddEdit.js simple_admin_templates/vendors~external_chartAddEdit~p__Welcome~p__account__changePassword~p__dashboard__index~p__dataShow~~28b62020.chunk.css simple_admin_templates/vendors~external_chartAddEdit~p__Welcome~p__account__changePassword~p__dashboard__index~p__dataShow~~28b62020.js simple_admin_templates/vendors~external_chartAddEdit~p__user__login__index.chunk.css simple_admin_templates/vendors~external_chartAddEdit~p__user__login__index.js simple_admin_templates/vendors~p__404.chunk.css simple_admin_templates/vendors~p__404.js simple_admin_templates/vendors~p__404~p__Welcome~p__account__changePassword~p__dashboard__add~p__dashboard__edit~p__dashboa~837a9f08.chunk.css simple_admin_templates/vendors~p__404~p__Welcome~p__account__changePassword~p__dashboard__add~p__dashboard__edit~p__dashboa~837a9f08.js simple_admin_templates/vendors~p__Welcome~p__account__changePassword~p__dashboard__add~p__dashboard__edit~p__dashboard__ind~5b4479c7.chunk.css simple_admin_templates/vendors~p__Welcome~p__account__changePassword~p__dashboard__add~p__dashboard__edit~p__dashboard__ind~5b4479c7.js simple_admin_templates/vendors~p__Welcome~p__account__changePassword~p__dashboard__add~p__dashboard__edit~p__dashboard__ind~f7f871a1.chunk.css simple_admin_templates/vendors~p__Welcome~p__account__changePassword~p__dashboard__add~p__dashboard__edit~p__dashboard__ind~f7f871a1.js

Index

Constants

This section is empty.

Variables

View Source
var (
	NowSpAdmin    *SpAdmin
	SvKey         = sv.GlobalContextKey
	DefaultPrefix = "/SP_PREFIX"
)
View Source
var CustomJwt = jwt.New(jwt.Config{
	ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) {
		return MySecret, nil
	},
	Expiration:    true,
	SigningMethod: jwt.SigningMethodHS256,
})

自定义JWT 使用办法 中间层 handler.CustomJwt.Serve, handler.TokenToUserUidMiddleware,user handler

View Source
var MySecret = []byte("8657684ae02840ead423e0d781a7a0c5")

Functions

func AddDashBoard added in v1.4.8

func AddDashBoard(ctx iris.Context)

新增图表

func AddDashBoardScreen added in v1.4.8

func AddDashBoardScreen(ctx iris.Context)

func AddRouterData

func AddRouterData(ctx iris.Context)

新增数据

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetFile added in v1.3.1

func AssetFile() http.FileSystem

AssetFile return a http.FileSystem instance that data backend by asset

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func ChangeUserPassword

func ChangeUserPassword(ctx iris.Context)

变更用户密码

func ChangeUserRoles

func ChangeUserRoles(ctx iris.Context)

变更用户群组

func Configuration

func Configuration(ctx iris.Context)

获取配置信息

func DashBoardIsSelfMiddleware added in v1.4.8

func DashBoardIsSelfMiddleware(ctx iris.Context)

数据可视化必须本人操作Middleware

func DashBoardSourceGet added in v1.4.8

func DashBoardSourceGet(ctx iris.Context)

获取图表数据源

func DeleteBoardScreen added in v1.4.8

func DeleteBoardScreen(ctx iris.Context)

func DeleteDashBoard added in v1.4.8

func DeleteDashBoard(ctx iris.Context)

删除图表

func EditDashBoard added in v1.4.9

func EditDashBoard(ctx iris.Context)

编辑图表

func EditDashBoardPosition added in v1.4.9

func EditDashBoardPosition(ctx iris.Context)

更新图表位置

func EditRouterData

func EditRouterData(ctx iris.Context)

修改数据 -> 全量更新

func GenJwtToken

func GenJwtToken(userUid, userName string) string

生成token

func GetCurrentUser

func GetCurrentUser(ctx iris.Context)

获取当前用户

func GetDashBoard added in v1.4.8

func GetDashBoard(ctx iris.Context)

数据图表

func GetDashBoardScreen added in v1.4.8

func GetDashBoardScreen(ctx iris.Context)

数据可视化屏幕

func GetMapValues

func GetMapValues(a map[string]string) []string

func GetRouterCustomAction added in v1.0.8

func GetRouterCustomAction(ctx iris.Context)

获取单个表的自定义操作

func GetRouterData

func GetRouterData(ctx iris.Context)

获取表数据

func GetRouterFields

func GetRouterFields(ctx iris.Context)

获取单个表的列信息

func GetRouterSingleData

func GetRouterSingleData(ctx iris.Context)

获取表单条数据

func GetRouters

func GetRouters(ctx iris.Context)

获取所有表名

func GetSingleDashBoard added in v1.4.9

func GetSingleDashBoard(ctx iris.Context)

单个图表

func Index

func Index(ctx iris.Context)

首页

func IsNum

func IsNum(s string) bool

func Login

func Login(ctx iris.Context)

登录

func MsgLog

func MsgLog(msg string) error

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func PolicyRequireAdminMiddleware

func PolicyRequireAdminMiddleware(ctx iris.Context)

必须admin权限middleware

func PolicyValidMiddleware

func PolicyValidMiddleware(ctx iris.Context)

权限Middleware

func RandStringBytes

func RandStringBytes(n int) string

func Reg

func Reg(ctx iris.Context)

注册

func RemoveRouterData

func RemoveRouterData(ctx iris.Context)

删除数据 -> 可以批量

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func SearchRouterData added in v1.2.6

func SearchRouterData(ctx iris.Context)

搜索表数据

func SpiderVisitHistoryMiddleware added in v1.2.7

func SpiderVisitHistoryMiddleware(ctx iris.Context)

爬虫监听Middleware

func StringsContains

func StringsContains(a []string, x string) bool

func TokenToUserUidMiddleware

func TokenToUserUidMiddleware(ctx iris.Context)

登录token存储信息 记录到上下文中

Types

type Config

type Config struct {
	Name      string            // 后台显示名称
	Engine    *xorm.Engine      // xorm engine实例
	App       *iris.Application // iris实例
	ModelList []interface{}     // 模型列表

	UserModel                  interface{}    // 用户模型
	RunSync                    bool           // 是否进行sync
	PageSize                   int            // 每页条数
	AbridgeName                string         // tag的解析名称
	Prefix                     string         // 前缀
	InitAdminUserName          string         // 初始管理员用户名 若存在则跳过
	InitAdminPassword          string         // 初始管理员密码
	UserModelSpecialUniqueName string         // 用户模型唯一名
	CustomActions              []CustomAction // 自定义action列表
	EnableSpiderWatch          bool           // 开启爬虫监听
	SpiderMatchList            []string       // 爬虫ua匹配列表
	SpiderSkipList             []string       // 爬虫匹配忽略
	// contains filtered or unexported fields
}

type ConfigResp added in v1.0.2

type ConfigResp struct {
	Name          string `json:"name"`
	Prefix        string `json:"prefix"`
	UserModelName string `json:"user_model_name"`
}

type CustomAction added in v1.0.8

type CustomAction struct {
	Name    string      `json:"name"`    // action display name
	Methods string      `json:"methods"` // request run methods
	Valid   interface{} `json:"valid"`   // request valid struct
	Path    string      `json:"path"`    // request path
	Scope   interface{} `json:"scope"`   // show where
	Func    func(ctx iris.Context)
	// contains filtered or unexported fields
}

自定义action

type CustomActionResp added in v1.0.8

type CustomActionResp struct {
	Name    string       `json:"name"`    // action display name
	Methods string       `json:"methods"` // request run methods
	Fields  []structInfo `json:"fields"`  // request valid struct
	Path    string       `json:"path"`    // request path
}

type DashBoard added in v1.4.8

type DashBoard struct {
	Id         uint64 `xorm:"autoincr pk unique" json:"id"`
	ScreenId   uint64 `sp:"fk('DashBoardScreen') index" comment:"屏幕ID" json:"screen_id" `
	Name       string `xorm:"varchar(45) notnull" comment:"名称" json:"name"`
	ChartType  string `xorm:"varchar(40) notnull" comment:"图表类型" json:"chart_type"`
	DataSource string `xorm:"text notnull" comment:"数据源" json:"data_source"`
	Extra      string `xorm:"text" comment:"附加信息" json:"extra"`
	Config     string `xorm:"text notnull" comment:"配置" json:"config"`
}

func (*DashBoard) SpAlias added in v1.4.8

func (c *DashBoard) SpAlias() string

type DashBoardAddReq added in v1.4.8

type DashBoardAddReq struct {
	Name       string `json:"name" form:"name" comment:"名称" validate:"required,max=45"`
	DataSource string `json:"data_source" form:"data_source" comment:"数据源配置" validate:"required"`
	Config     string `json:"config" form:"config" comment:"图表配置" validate:"required"`
	ChartType  string `json:"chart_type" form:"chart_type" comment:"图表类型" validate:"required"`
}

数据图表新增

type DashBoardChangePositionReq added in v1.4.9

type DashBoardChangePositionReq struct {
	Extra string `json:"extra" form:"extra" comment:"附加信息" validate:"required"`
}

数据图表位置变更

type DashBoardGetDataItem added in v1.4.8

type DashBoardGetDataItem struct {
	ColName     string `json:"col_name" comment:"列名" validate:"required,max=50"`
	OpType      string `json:"op_type" comment:"操作" validate:"required,max=20"` // = > != < >= <= in (not in) like
	Value       string `json:"value" comment:"值" validate:"required,max=100"`
	Order       uint64 `json:"order" comment:"顺序" validate:"required"` // 以小到大排列
	ConnectType string `json:"connect_type" comment:"连接方式"`            // and or xor not
}

获取数据源内容

type DashBoardGetDataReq added in v1.4.8

type DashBoardGetDataReq struct {
	ColumnOp []DashBoardGetDataItem `json:"column_op"`
	Limit    uint64                 `json:"limit"`
}

获取数据源

type DashBoardScreen added in v1.4.8

type DashBoardScreen struct {
	Id           uint64 `xorm:"autoincr pk unique" json:"id"`
	Name         string `xorm:"varchar(45) notnull" comment:"仪表台名称" json:"name"`
	Priority     uint64 `xorm:"notnull" comment:"优先级" json:"priority"`
	IsDefault    bool   `xorm:"notnull" comment:"默认" json:"is_default"`
	CreateUserId uint64 `xorm:"notnull index" comment:"用户ID" json:"create_user_id"`
}

仪表台模型

func (*DashBoardScreen) SpAlias added in v1.4.8

func (c *DashBoardScreen) SpAlias() string

type DashBoardScreenAddOrEditReq added in v1.4.8

type DashBoardScreenAddOrEditReq struct {
	Id        uint64 `json:"id" form:"name" comment:"id"`
	Name      string `json:"name" form:"name" comment:"名称" validate:"required,max=25"`
	IsDefault bool   `json:"is_default" form:"is_default" comment:"默认"`
}

数据屏幕

type DeleteReq added in v1.0.2

type DeleteReq struct {
	Ids string `json:"ids" form:"ids" comment:"标识符列表" validate:"required,min=1"`
}

type GetAllTableNameResp added in v1.4.3

type GetAllTableNameResp struct {
	Tables  map[string]string `json:"tables"`
	Remarks map[string]string `json:"remarks"`
}

type GetCurrentUserResp added in v1.0.2

type GetCurrentUserResp struct {
	Name   string   `json:"name"`
	Avatar string   `json:"avatar"`
	UserId string   `json:"userid"`
	Roles  []string `json:"roles"`
}

type PagResult

type PagResult struct {
	All      int64               `json:"all"`
	Page     int                 `json:"page"`
	PageSize int                 `json:"page_size"`
	Data     []map[string]string `json:"data"`
}

分页结果

type SearchReq added in v1.2.6

type SearchReq struct {
	Cols       []string `json:"cols" form:"cols" comment:"列信息" validate:"required"` // column map name
	SearchText string   `json:"search_text" form:"search_text" comment:"搜索内容" validate:"max=20" `
	FullMath   bool     `json:"full_math" form:"full_math" comment:"全匹配"`
}

搜索

type SpAdmin

type SpAdmin struct {
	// contains filtered or unexported fields
}

func New

func New(c Config) (*SpAdmin, error)

func (*SpAdmin) Pagination

func (lib *SpAdmin) Pagination(routerName string, page int) (PagResult, error)

分页

func (*SpAdmin) Register

func (lib *SpAdmin) Register()

注册视图

func (*SpAdmin) Router

func (lib *SpAdmin) Router(router iris.Party)

在这里注册主路由

func (*SpAdmin) SingleData

func (lib *SpAdmin) SingleData(routerName string, id uint64) ([]map[string]string, error)

单条数据获取

type SpDeleteAfterProcess added in v1.4.3

type SpDeleteAfterProcess interface {
	SpDeleteAfter()
}

删除之后

type SpDeleteBeforeProcess added in v1.4.3

type SpDeleteBeforeProcess interface {
	SpDeleteBefore()
}

删除之前

type SpInsertAfterProcess added in v1.4.3

type SpInsertAfterProcess interface {
	SpInsertAfter()
}

插入之后

type SpInsertBeforeProcess added in v1.4.3

type SpInsertBeforeProcess interface {
	SpInsertBefore()
}

插入之前

type SpTableNameProcess added in v1.4.3

type SpTableNameProcess interface {
	SpAlias() string
}

表别名

type SpUpdateAfterProcess added in v1.4.3

type SpUpdateAfterProcess interface {
	SpUpdateAfter()
}

更新之后

type SpUpdateBeforeProcess added in v1.4.3

type SpUpdateBeforeProcess interface {
	SpUpdateBefore()
}

更新之前

type SpiderHistory added in v1.2.7

type SpiderHistory struct {
	Id         uint64    `xorm:"autoincr pk unique" json:"id"`
	CreateTime time.Time `xorm:"created index" json:"create_time" comment:"创建时间"`
	Ip         string    `xorm:"varchar(15)" json:"ip" comment:"ip地址"`
	Match      string    `xorm:"varchar(40)" json:"match" comment:"爬虫名"`
	Ua         string    `xorm:"varchar(150)" json:"ua" comment:"ua"`
	Page       string    `xorm:"varchar(150)" json:"page" comment:"访问路径"` // 访问路径
}

模型爬虫监听模型

func (*SpiderHistory) SpAlias added in v1.4.7

func (c *SpiderHistory) SpAlias() string

type TableFieldsResp added in v1.0.3

type TableFieldsResp struct {
	Fields        []structInfo    `json:"fields"`
	AutoIncrement string          `json:"autoincr"`
	Updated       string          `json:"updated"`
	Deleted       string          `json:"deleted"`
	Created       map[string]bool `json:"created"`
	Version       string          `json:"version"`
}

type TableInfoList added in v1.3.7

type TableInfoList struct {
	RouterName string          `json:"router_name"`
	RemarkName string          `json:"remark_name"`
	FieldList  TableFieldsResp `json:"field_list"`
	Actions    []CustomAction  `json:"actions"`
}

表信息存储

type UserChangePasswordReq added in v1.0.2

type UserChangePasswordReq struct {
	Id       uint64 `json:"id" comment:"id" validate:"required"`
	UserName string `json:"user_name" comment:"用户名" validate:"required,max=20,min=3"`
	Password string `json:"password" comment:"密码" validate:"required,min=3,max=20"`
}

用户变更密码

type UserChangeRolesReq added in v1.0.2

type UserChangeRolesReq struct {
	Id   uint64 `json:"id" comment:"id" validate:"required"`
	Role string `json:"role" comment:"群组名" validate:"required"`
	Add  bool   `json:"add" comment:"添加"`
}

admin 变更用户群组

type UserLoginReq added in v1.0.2

type UserLoginReq struct {
	UserName string `json:"user_name" comment:"用户名" validate:"required,max=20,min=3"`
	Password string `json:"password" comment:"密码" validate:"required,min=3,max=20"`
}

用户登录

type UserLoginResp added in v1.0.2

type UserLoginResp struct {
	Token    string             `json:"token"`
	UserInfo GetCurrentUserResp `json:"user_info"`
}

type UserModel

type UserModel struct {
	Id       uint64 `xorm:"autoincr pk unique" json:"id"`
	UserName string `xorm:"varchar(60) notnull unique index" comment:"用户名" json:"username"`
	Password string `xorm:"varchar(100) notnull" comment:"密码" json:"password"`
	Salt     string `xorm:"varchar(40) notnull" comment:"加密salt" json:"salt"`
}

默认用户模型

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL