Browse Source

Merge branch 'master' of https://github.com/piexlmax/gin-vue-admin

klausY 5 years ago
parent
commit
f2e5d401bd

+ 17 - 6
QMPlusServer/config/config.go

@@ -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.SetConfigName("config")           //  设置配置文件名 (不带后缀)
+	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 - 2
QMPlusServer/controller/servers/upload.go

@@ -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) {

+ 1 - 1
QMPlusServer/init/qmsql/initMysql.go

@@ -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 {

+ 6 - 6
QMPlusServer/main.go

@@ -20,12 +20,12 @@ import (
 // @BasePath /
 
 func main() {
-	qmlog.InitLog()                              // 初始化日志
-	db := qmsql.InitMysql(config.Dbconfig.Admin) // 链接初始化数据库
-	registTable.RegistTable(db)                  //注册数据库表
-	defer qmsql.DEFAULTDB.Close()                // 程序结束前关闭数据库链接
-	Router := initRouter.InitRouter()            //注册路由
-	qmlog.QMLog.Info("服务器开启")                    // 日志测试代码
+	qmlog.InitLog()                                            // 初始化日志
+	db := qmsql.InitMysql(config.GinVueAdminconfig.MysqlAdmin) // 链接初始化数据库
+	registTable.RegistTable(db)                                //注册数据库表
+	defer qmsql.DEFAULTDB.Close()                              // 程序结束前关闭数据库链接
+	Router := initRouter.InitRouter()                          //注册路由
+	qmlog.QMLog.Info("服务器开启")                                  // 日志测试代码
 	//Router.RunTLS(":443","ssl.pem", "ssl.key")  // https支持 需要添加中间件
 	s := &http.Server{
 		Addr:           ":8888",

+ 2 - 1
QMPlusServer/model/sysModel/sys_casbin.go

@@ -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

+ 16 - 0
QMPlusServer/static/config/config.json

@@ -0,0 +1,16 @@
+{
+  "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"
+  }
+}

+ 0 - 9
QMPlusServer/static/dbconfig/config.json

@@ -1,9 +0,0 @@
-{
-  "admin": {
-    "username": "root",
-    "password": "Aa@6447985",
-    "path": "127.0.0.1:3306",
-    "dbname": "qmplus",
-    "config": "charset=utf8&parseTime=True&loc=Local"
-  }
-}

+ 27 - 3
QMPlusVuePage/src/utils/request.js

@@ -1,15 +1,36 @@
 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,

+ 8 - 1
QMPlusVuePage/src/view/example/upload/upload.vue

@@ -1,5 +1,5 @@
 <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)