Skip to content

Commit

Permalink
Merge pull request #66 from delta-mpc/0.8.2-alpha1
Browse files Browse the repository at this point in the history
change users' order to desc in approve users page
  • Loading branch information
mh739025250 authored Mar 9, 2023
2 parents 4f6a6c0 + abb3bcd commit 6f0f67e
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 50 deletions.
25 changes: 0 additions & 25 deletions .vscode/launch.json

This file was deleted.

9 changes: 8 additions & 1 deletion server/api/v1/user/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
38 changes: 24 additions & 14 deletions server/config/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package db

import (
"database/sql"
"fmt"
glog "log"
"os"
"time"
Expand Down Expand Up @@ -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{
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions vetur.config.js
Original file line number Diff line number Diff line change
@@ -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.
}
]
}
16 changes: 16 additions & 0 deletions web/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": [
"./src/*"
]
}
},
"exclude": [
"node_modules"
],
"include": [
"./src/**/*"
]
}
4 changes: 2 additions & 2 deletions web/src/api/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
18 changes: 10 additions & 8 deletions web/src/views/dashboard/content/userlist/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
});
});
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
}
Expand Down

0 comments on commit 6f0f67e

Please sign in to comment.