未验证 提交 62678966 编写于 作者: G Grant 提交者: GitHub

Merge pull request #2 from piexlmax/master

update
......@@ -7,9 +7,15 @@ import (
)
type Config struct {
Admin Admin
MysqlAdmin MysqlAdmin
Qiniu Qiniu
CasbinConfig CasbinConfig
}
type Admin struct {
type CasbinConfig struct {
ModelPath string // casbin model地址配置
}
type MysqlAdmin struct { // mysql admin 数据库配置
Username string
Password string
Path string
......@@ -17,12 +23,17 @@ type Admin struct {
Config string
}
var Dbconfig Config
type Qiniu struct { // 七牛 密钥配置
AccessKey string
SecretKey string
}
var GinVueAdminconfig Config
func init() {
v := viper.New()
v.SetConfigName("config") // 设置配置文件名 (不带后缀)
v.AddConfigPath("./static/dbconfig/") // 第一个搜索路径
v.AddConfigPath("./static/config/") // 第一个搜索路径
v.SetConfigType("json")
err := v.ReadInConfig() // 搜索路径,并读取配置数据
if err != nil {
......@@ -32,7 +43,7 @@ func init() {
v.OnConfigChange(func(e fsnotify.Event) {
fmt.Println("Config file changed:", e.Name)
})
if err := v.Unmarshal(&Dbconfig); err != nil {
if err := v.Unmarshal(&GinVueAdminconfig); err != nil {
fmt.Println(err)
}
}
......@@ -3,14 +3,15 @@ package servers
import (
"context"
"fmt"
"gin-vue-admin/config"
"github.com/qiniu/api.v7/auth/qbox"
"github.com/qiniu/api.v7/storage"
"mime/multipart"
"time"
)
var accessKey string = "25j8dYBZ2wuiy0yhwShytjZDTX662b8xiFguwxzZ" // 你在七牛云的accessKey 这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
var secretKey string = "pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY" // 你在七牛云的secretKey 这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
var accessKey string = config.GinVueAdminconfig.Qiniu.AccessKey // 你在七牛云的accessKey 这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
var secretKey string = config.GinVueAdminconfig.Qiniu.SecretKey // 你在七牛云的secretKey 这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
// 接收两个参数 一个文件流 一个 bucket 你的七牛云标准空间的名字
func Upload(file *multipart.FileHeader, bucket string, urlPath string) (err error, path string, key string) {
......
此差异已折叠。
......@@ -10,7 +10,7 @@ import (
var DEFAULTDB *gorm.DB
//初始化数据库并产生数据库全局变量
func InitMysql(admin config.Admin) *gorm.DB {
func InitMysql(admin config.MysqlAdmin) *gorm.DB {
if db, err := gorm.Open("mysql", admin.Username+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname+"?"+admin.Config); err != nil {
log.Printf("DEFAULTDB数据库启动异常%S", err)
} else {
......
......@@ -21,7 +21,7 @@ import (
func main() {
qmlog.InitLog() // 初始化日志
db := qmsql.InitMysql(config.Dbconfig.Admin) // 链接初始化数据库
db := qmsql.InitMysql(config.GinVueAdminconfig.MysqlAdmin) // 链接初始化数据库
registTable.RegistTable(db) //注册数据库表
defer qmsql.DEFAULTDB.Close() // 程序结束前关闭数据库链接
Router := initRouter.InitRouter() //注册路由
......
......@@ -12,6 +12,8 @@ type SysAuthority struct {
gorm.Model
AuthorityId string `json:"authorityId" gorm:"not null;unique"`
AuthorityName string `json:"authorityName"`
ParentId string `json:"parentId"`
Children []SysAuthority `json:"children"`
}
// 创建角色
......@@ -23,9 +25,14 @@ func (a *SysAuthority) CreateAuthority() (err error, authority *SysAuthority) {
// 删除角色
func (a *SysAuthority) DeleteAuthority() (err error) {
err = qmsql.DEFAULTDB.Where("authority_id = ?", a.AuthorityId).Find(&SysUser{}).Error
if err != nil {
err = qmsql.DEFAULTDB.Where("parentId = ?", a.AuthorityId).Find(&SysAuthority{}).Error
if err != nil {
err = qmsql.DEFAULTDB.Where("authority_id = ?", a.AuthorityId).First(a).Unscoped().Delete(a).Error
new(CasbinModel).clearCasbin(0, a.AuthorityId)
} else {
err = errors.New("此角色存在子角色不允许删除")
}
} else {
err = errors.New("此角色有用户正在使用禁止删除")
}
......@@ -40,7 +47,22 @@ func (a *SysAuthority) GetInfoList(info modelInterface.PageInfo) (err error, lis
return
} else {
var authority []SysAuthority
err = db.Find(&authority).Error
err = db.Where("parent_id = 0").Find(&authority).Error
if len(authority) > 0 {
for k, _ := range authority {
err = findChildrenAuthority(&authority[k])
}
}
return err, authority, total
}
}
func findChildrenAuthority(authority *SysAuthority) (err error) {
err = qmsql.DEFAULTDB.Where("parent_id = ?", authority.AuthorityId).Find(&authority.Children).Error
if len(authority.Children) > 0 {
for k, _ := range authority.Children {
err = findChildrenAuthority(&authority.Children[k])
}
}
return err
}
......@@ -2,6 +2,7 @@ package sysModel
import (
"errors"
"gin-vue-admin/config"
"gin-vue-admin/init/qmsql"
"github.com/casbin/casbin"
gormadapter "github.com/casbin/gorm-adapter"
......@@ -83,7 +84,7 @@ func ParamsMatchFunc(args ...interface{}) (interface{}, error) {
//持久化到数据库 引入自定义规则
func Casbin() *casbin.Enforcer {
a := gormadapter.NewAdapterByDB(qmsql.DEFAULTDB)
e := casbin.NewEnforcer("./static/rbacmodel/rbac_model.conf", a)
e := casbin.NewEnforcer(config.GinVueAdminconfig.CasbinConfig.ModelPath, a)
e.AddFunction("ParamsMatch", ParamsMatchFunc)
e.LoadPolicy()
return e
......
{
"admin": {
"mysqlAdmin": {
"username": "root",
"password": "Aa@6447985",
"path": "127.0.0.1:3306",
"dbname": "qmplus",
"config": "charset=utf8&parseTime=True&loc=Local"
},
"qiniu": {
"accessKey":"25j8dYBZ2wuiy0yhwShytjZDTX662b8xiFguwxzZ",
"secretKey": "pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY"
},
"casbinConfig":{
"modelPath":"./static/rbacmodel/rbac_model.conf"
}
}
\ No newline at end of file
import axios from 'axios'; // 引入axios
import { Message } from 'element-ui';
import { Message, Loading } from 'element-ui';
import { store } from '@/store/index'
const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API,
timeout: 99999
})
let acitveAxios = 0
let loadingInstance
let timer
const showLoading = () => {
acitveAxios++
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
if (acitveAxios > 0) {
loadingInstance = Loading.service({ fullscreen: true })
}
}, 400);
}
//http request 拦截器
const closeLoading = () => {
acitveAxios--
if (acitveAxios <= 0) {
clearTimeout(timer)
loadingInstance && loadingInstance.close()
}
}
//http request 拦截器
service.interceptors.request.use(
config => {
showLoading()
const token = store.getters['user/token']
config.data = JSON.stringify(config.data);
config.headers = {
......@@ -19,6 +40,7 @@ service.interceptors.request.use(
return config;
},
error => {
closeLoading()
Message({
showClose: true,
message: error,
......@@ -32,6 +54,7 @@ service.interceptors.request.use(
//http response 拦截器
service.interceptors.response.use(
response => {
closeLoading()
if (response.data.success) {
return response.data
} else {
......@@ -47,6 +70,7 @@ service.interceptors.response.use(
}
},
error => {
closeLoading()
Message({
showClose: true,
message: error,
......
<template>
<div>
<div v-loading.fullscreen.lock="fullscreenLoading">
<el-upload
:action="`${path}/fileUploadAndDownload/upload`"
:before-upload="checkFile"
......@@ -64,6 +64,7 @@ export default {
mixins: [infoList],
data() {
return {
fullscreenLoading:false,
listApi: getFileList,
listKey: 'list',
path: path,
......@@ -121,14 +122,17 @@ export default {
})
},
checkFile(file) {
this.fullscreenLoading = true
const isJPG = file.type === 'image/jpeg'
const isPng = file.type === 'image/png'
const isLt2M = file.size / 1024 / 1024 < 2
if (!isJPG && !isPng) {
this.$message.error('上传头像图片只能是 JPG或png 格式!')
this.fullscreenLoading = false
}
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 2MB!')
this.fullscreenLoading = false
}
return (isPng || isJPG) && isLt2M
},
......@@ -140,12 +144,15 @@ export default {
if (res.success) {
this.getTableData()
}
this.fullscreenLoading = false
},
uploadError() {
this.$message({
type: 'error',
message: '上传失败'
})
this.fullscreenLoading = false
},
downloadFile(row) {
downloadImage(row.url, row.name)
......
<template>
<div class="authority">
<div class="button-box clearflex">
<el-button @click="addAuthority" type="primary">新增角色</el-button>
<el-button @click="addAuthority('0')" type="primary">新增角色</el-button>
</div>
<el-table :data="tableData" border stripe>
<el-table
:data="tableData"
style="width: 100%"
row-key="ID"
border
stripe
:tree-props="{children: 'children', hasChildren: 'hasChildren'}">
<el-table-column label="id" min-width="180" prop="ID"></el-table-column>
<el-table-column label="角色id" min-width="180" prop="authorityId"></el-table-column>
<el-table-column label="角色名称" min-width="180" prop="authorityName"></el-table-column>
......@@ -11,23 +17,17 @@
<template slot-scope="scope">
<el-button @click="opdendrawer(scope.row)" size="small" type="text">设置权限</el-button>
<el-button @click="deleteAuth(scope.row)" size="small" type="text">删除角色</el-button>
<el-button @click="addAuthority(scope.row.authorityId)" size="small" type="text">新增子角色</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
:current-page="page"
:page-size="pageSize"
:page-sizes="[10, 30, 50, 100]"
:style="{float:'right',padding:'20px'}"
:total="total"
@current-change="handleCurrentChange"
@size-change="handleSizeChange"
layout="total, sizes, prev, pager, next, jumper"
></el-pagination>
<!-- 新增角色弹窗 -->
<el-dialog :visible.sync="dialogFormVisible" title="新增角色">
<el-form :model="form">
<el-form-item label="父级角色ID">
<el-input autocomplete="off" disabled v-model="form.parentId"></el-input>
</el-form-item>
<el-form-item label="角色ID">
<el-input autocomplete="off" v-model="form.authorityId"></el-input>
</el-form-item>
......@@ -81,7 +81,8 @@ export default {
apiDialogFlag: false,
form: {
authorityId: '',
authorityName: ''
authorityName: '',
parentId:'0'
}
}
},
......@@ -146,9 +147,13 @@ export default {
this.dialogFormVisible = false
},
// 增加角色
addAuthority() {
addAuthority(parentId) {
this.form.parentId = parentId
this.dialogFormVisible = true
}
},
created(){
this.pageSize = 999
}
}
</script>
......
......@@ -108,8 +108,8 @@ swag init
项目文件夹下面会有 doc文件夹出现
这时候登录 localhost:8888/swagger/index.html
就可以看到 swagger文档啦
## 个人博客
http://www.henrongyi.top,内有前端框架教学视频,GOLANG基础入门视频正在筹备中。
## 团队博客
https://blog.henrongyi.top,内有前端框架教学视频,GOLANG基础入门视频正在筹备中。
如果觉得项目对您有所帮助可以添加我的个人微信:shouzi_1994,欢迎您提出宝贵的需求。
## 最后
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册