diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 2f7acbe..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - // 使用 IntelliSense 了解相关属性。 - // 悬停以查看现有属性的描述。 - // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - - { - "name": "Launch", - "type": "go", - "request": "launch", - "mode": "debug", - "program": "${fileDirname}", - "cwd":"${workspaceFolder}/server", - "remotePath": "", - "port": 2345, - "host": "127.0.0.1", - "env": { - "GOPATH":"E:/gopath" - }, - "showLog": true, - "args":["migrate"] - } - ] -} \ No newline at end of file diff --git a/server/api/v1/user/register.go b/server/api/v1/user/register.go index 8b8b024..ccac00d 100644 --- a/server/api/v1/user/register.go +++ b/server/api/v1/user/register.go @@ -56,6 +56,7 @@ type FetchUserInput struct { ApproveStatus int8 `json:"approve_status" form:"approve_status"` Page int64 `json:"page" form:"page"` PageSize int64 `json:"page_size" form:"page_size"` + Sort int8 `json:"sort" form:"sort" validate:"gte=0,lte=1" description:"结果的顺序。0-ASC,1-DESC"` } type FetchRegistedUserResponse struct { @@ -162,7 +163,13 @@ func FetchUser(ctx *gin.Context, in *FetchUserInput) (*FetchRegistedUserResponse } users := make([]*models.User, 0) if total > 0 { - if err := db.GetDB().Model(&models.User{}).Where("apprv_status = ? ", in.ApproveStatus). + var order string + if in.Sort == 0 { + order = "id asc" + } else { + order = "id desc" + } + if err := db.GetDB().Model(&models.User{}).Where("apprv_status = ? ", in.ApproveStatus).Order(order). Limit(int(in.PageSize)).Offset(int((in.Page - 1) * in.PageSize)).Find(&users).Error; err != nil { return nil, err } diff --git a/server/config/db/db.go b/server/config/db/db.go index d88e2d0..6606eb3 100644 --- a/server/config/db/db.go +++ b/server/config/db/db.go @@ -18,6 +18,7 @@ package db import ( "database/sql" + "fmt" glog "log" "os" "time" @@ -52,15 +53,6 @@ func InitDB(appConfig *config.AppConfig) (err error) { } return nil } - sqlDB, err := sql.Open(appConfig.Db.Driver, appConfig.Db.ConnectionString) - if err != nil { - log.Error("InitDB sql.Open error:" + err.Error()) - return err - } - sqlDB.SetMaxIdleConns(20) - sqlDB.SetMaxOpenConns(50) - sqlDB.SetConnMaxLifetime(5 * time.Second) - newLogger := logger.New( glog.New(os.Stdout, "\r\n", glog.LstdFlags), // io writer logger.Config{ @@ -71,12 +63,30 @@ func InitDB(appConfig *config.AppConfig) (err error) { }, ) - db, err = gorm.Open(mysql.New(mysql.Config{Conn: sqlDB}), - &gorm.Config{Logger: newLogger}) + if appConfig.Db.Driver == "mysql" { + sqlDB, err := sql.Open(appConfig.Db.Driver, appConfig.Db.ConnectionString) + if err != nil { + log.Error("InitDB sql.Open error:" + err.Error()) + return err + } + sqlDB.SetMaxIdleConns(20) + sqlDB.SetMaxOpenConns(50) + sqlDB.SetConnMaxLifetime(5 * time.Second) - if err != nil { - log.Error("InitDB Failed:" + err.Error()) - return err + db, err = gorm.Open(mysql.New(mysql.Config{Conn: sqlDB}), + &gorm.Config{Logger: newLogger}) + if err != nil { + log.Error("InitDB Failed:" + err.Error()) + return err + } + } else if appConfig.Db.Driver == "sqlite" { + db, err = gorm.Open(sqlite.Open(appConfig.Db.ConnectionString), &gorm.Config{Logger: newLogger}) + if err != nil { + log.Error("InitDB Failed:" + err.Error()) + return err + } + } else { + return fmt.Errorf("unknown db driver type %s", appConfig.Db.Driver) } // Set default database charset to utf8mb4 diff --git a/vetur.config.js b/vetur.config.js new file mode 100644 index 0000000..91becd4 --- /dev/null +++ b/vetur.config.js @@ -0,0 +1,8 @@ +module.exports = { + projects: [ + { + root: './web', // root of your vue project (should contain package.json) + package: './package.json', // Relative to root property, don't change this. + } + ] +} diff --git a/web/jsconfig.json b/web/jsconfig.json new file mode 100644 index 0000000..2cabd5a --- /dev/null +++ b/web/jsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@/*": [ + "./src/*" + ] + } + }, + "exclude": [ + "node_modules" + ], + "include": [ + "./src/**/*" + ] +} \ No newline at end of file diff --git a/web/src/api/v1/users.js b/web/src/api/v1/users.js index e8fb24e..159d9de 100644 --- a/web/src/api/v1/users.js +++ b/web/src/api/v1/users.js @@ -5,8 +5,8 @@ export default { register(username, password) { return v1.post('/users/tokens', {'user_name': username, 'password': password}) }, - fetchUser(apprv_status,pageID,pageSize) { - return v1.get('/users/approve_status', {params:{approve_status:apprv_status,page: pageID, page_size: pageSize}}) + fetchUser(apprv_status,pageID,pageSize,sort) { + return v1.get('/users/approve_status', {params:{approve_status:apprv_status,page: pageID, page_size: pageSize, sort: sort}}) }, approveUser(userId) { return v1.post(`/users/approve/${userId}`) diff --git a/web/src/views/dashboard/content/userlist/index.vue b/web/src/views/dashboard/content/userlist/index.vue index 141be3c..5d38aef 100644 --- a/web/src/views/dashboard/content/userlist/index.vue +++ b/web/src/views/dashboard/content/userlist/index.vue @@ -84,12 +84,14 @@ export default { management:{ tableData:[], page_size:12, - page:1 + page:1, + sort: 0, }, approval:{ tableData:[], page_size:12, - page:1 + page:1, + sort: 1, }, capsTooltip: false, loading: false, @@ -135,7 +137,7 @@ export default { this.$confirm(this.$t('dashboard.userlist.approve_user',{name:user.name})).then((res) => { V1UserAPI.approveUser(user.id).then((res) => { this.$message(this.$t('dashboard.userlist.user_approved')); - this.approval.tableData = this.approval.tableData.filter((itm)=>itm.id != user.id) + this.approval.tableData = this.approval.tableData.filter((itm)=>itm.id != user.id) // this.load(); }); }); @@ -150,15 +152,15 @@ export default { }); }, load() { - if(this.activeName == 'management') { - V1UserAPI.fetchUser(this.$appGlobal.constants.USER_APPROV_STATUS_APPROVED,this.management.page,this.management.page_size).then((res) => { + if(this.activeName == 'management') { + V1UserAPI.fetchUser(this.$appGlobal.constants.USER_APPROV_STATUS_APPROVED,this.management.page,this.management.page_size, this.management.sort).then((res) => { let lst = res.list.filter((itm)=>this['management']['tableData'].findIndex((data)=>data.id == itm.id) < 0) this['management']['tableData'].push(...lst); this.management.page += 1 }); } if(this.activeName == 'approval') { - V1UserAPI.fetchUser(this.$appGlobal.constants.USER_APPROVE_STATUS_REGISTED,this.approval.page,this.approval.page_size).then((res) => { + V1UserAPI.fetchUser(this.$appGlobal.constants.USER_APPROVE_STATUS_REGISTED,this.approval.page,this.approval.page_size, this.approval.sort).then((res) => { let lst = res.list.filter((itm)=>this['approval']['tableData'].findIndex((data)=>data.id == itm.id) < 0) this['approval']['tableData'].push(...lst); this.approval.page += 1 @@ -205,8 +207,8 @@ export default { max-height calc(100vh - 240px) overflow:auto &::-webkit-scrollbar { - width: 0px; - background-color: #e5e5e5; + width: 0px; + background-color: #e5e5e5; } } }