parent
7c166b0393
commit
5cfe9eb906
@ -0,0 +1,50 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
// import "validate/validate.proto";
|
||||
import "google/api/annotations.proto";
|
||||
import "google/protobuf/empty.proto";
|
||||
|
||||
package api.v1;
|
||||
|
||||
option go_package = "moredoc/api/v1;v1";
|
||||
option java_multiple_files = true;
|
||||
option java_package = "api.v1";
|
||||
|
||||
message Config {
|
||||
int64 id = 1;
|
||||
string label = 2;
|
||||
string name = 3;
|
||||
string value = 4;
|
||||
string placeholder = 5;
|
||||
string input_type = 6;
|
||||
string category = 7;
|
||||
int32 sort = 8;
|
||||
string options = 9;
|
||||
google.protobuf.Timestamp created_at = 10 [ (gogoproto.stdtime) = true ];
|
||||
google.protobuf.Timestamp updated_at = 11 [ (gogoproto.stdtime) = true ];
|
||||
}
|
||||
|
||||
message ListConfigRequest {
|
||||
repeated string category = 1;
|
||||
}
|
||||
|
||||
message Configs { repeated Config config = 1; }
|
||||
|
||||
service ConfigAPI {
|
||||
// UpdateConfig 更新配置
|
||||
rpc UpdateConfig(Configs) returns (google.protobuf.Empty) {
|
||||
option (google.api.http) = {
|
||||
put : '/api/v1/config',
|
||||
body : '*',
|
||||
};
|
||||
}
|
||||
|
||||
// ListConfig 查询配置项
|
||||
rpc ListConfig(ListConfigRequest) returns (Configs) {
|
||||
option (google.api.http) = {
|
||||
get : '/api/v1/config/list',
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
pb "moredoc/api/v1"
|
||||
"moredoc/middleware/auth"
|
||||
"moredoc/model"
|
||||
"moredoc/util"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
type ConfigAPIService struct {
|
||||
pb.UnimplementedConfigAPIServer
|
||||
dbModel *model.DBModel
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewConfigAPIService(dbModel *model.DBModel, logger *zap.Logger) (service *ConfigAPIService) {
|
||||
return &ConfigAPIService{dbModel: dbModel, logger: logger.Named("ConfigAPIService")}
|
||||
}
|
||||
|
||||
func (s *ConfigAPIService) checkPermission(ctx context.Context) (userClaims *auth.UserClaims, err error) {
|
||||
return checkGRPCPermission(s.dbModel, ctx)
|
||||
}
|
||||
|
||||
// UpdateConfig 更新配置
|
||||
func (s *ConfigAPIService) UpdateConfig(ctx context.Context, req *pb.Configs) (*emptypb.Empty, error) {
|
||||
_, err := s.checkPermission(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var cfgs []*model.Config
|
||||
err = util.CopyStruct(req.Config, &cfgs)
|
||||
if err != nil {
|
||||
s.logger.Error("util.CopyStruct", zap.Any("req", req), zap.Any("cfgs", cfgs), zap.Error(err))
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
err = s.dbModel.UpdateConfigs(cfgs, "value")
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
// ListConfig 查询配置
|
||||
func (s *ConfigAPIService) ListConfig(ctx context.Context, req *pb.ListConfigRequest) (*pb.Configs, error) {
|
||||
_, err := s.checkPermission(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
opt := &model.OptionGetConfigList{
|
||||
QueryIn: map[string][]interface{}{
|
||||
"category": util.Slice2Interface(req.Category),
|
||||
},
|
||||
}
|
||||
|
||||
configs, err := s.dbModel.GetConfigList(opt)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
var pbConfigs []*pb.Config
|
||||
util.CopyStruct(&configs, &pbConfigs)
|
||||
|
||||
s.logger.Debug("ListConfig", zap.Any("req", req), zap.Any("configs", configs), zap.Any("pbConfigs", pbConfigs))
|
||||
|
||||
return &pb.Configs{Config: pbConfigs}, nil
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
import service from '~/utils/request'
|
||||
|
||||
export const updateConfig = (data) => {
|
||||
return service({
|
||||
url: '/api/v1/config',
|
||||
method: 'put',
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
export const listConfig = (params) => {
|
||||
return service({
|
||||
url: '/api/v1/config/list',
|
||||
method: 'get',
|
||||
params,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,69 @@
|
||||
<template>
|
||||
<div>{{ $route.name }}</div>
|
||||
<el-card shadow="never">
|
||||
<el-tabs v-model="activeName" type="card" @tab-click="handleClick">
|
||||
<el-tab-pane
|
||||
v-for="item in categories"
|
||||
:key="'category-' + item.value"
|
||||
:label="item.label"
|
||||
:name="item.value"
|
||||
>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<FormConfig :init-configs="configs" />
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listConfig } from '~/api/config'
|
||||
import FormConfig from '~/components/FormConfig.vue'
|
||||
export default {
|
||||
components: { FormConfig },
|
||||
layout: 'admin',
|
||||
created() {},
|
||||
data() {
|
||||
return {
|
||||
activeName: 'system',
|
||||
configs: [],
|
||||
categories: [
|
||||
{
|
||||
label: '系统配置',
|
||||
value: 'system',
|
||||
},
|
||||
// {
|
||||
// label: '用户配置',
|
||||
// value: 'user',
|
||||
// },
|
||||
// {
|
||||
// label: '邮箱配置',
|
||||
// value: 'email',
|
||||
// },
|
||||
{
|
||||
label: '验证码配置',
|
||||
value: 'captcha',
|
||||
},
|
||||
{
|
||||
label: '安全配置',
|
||||
value: 'security',
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.loadConfig()
|
||||
},
|
||||
methods: {
|
||||
handleClick(tab) {
|
||||
this.activeName = tab.name
|
||||
this.loadConfig()
|
||||
},
|
||||
async loadConfig() {
|
||||
const res = await listConfig({ category: [this.activeName] })
|
||||
if (res.status === 200) {
|
||||
this.configs = res.data.config || []
|
||||
} else {
|
||||
this.configs = []
|
||||
this.$message.error(res.data.message)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in new issue