Merge pull request #21 from maxbad/v2.0

fix 一些使用问题
This commit is contained in:
孟帅 2023-05-08 21:37:00 +08:00 committed by GitHub
commit bbe655a4d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 57 additions and 48 deletions

View File

@ -20,7 +20,7 @@ var (
Description: ``, Description: ``,
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) { Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
flags := parser.GetOptAll() flags := parser.GetOptAll()
g.Log().Debug(ctx, "flags:%+v", flags) g.Log().Debugf(ctx, "flags:%+v", flags)
if len(flags) == 0 { if len(flags) == 0 {
g.Log().Fatal(ctx, "工具参数不能为空") g.Log().Fatal(ctx, "工具参数不能为空")
return return

View File

@ -28,7 +28,7 @@ func (c *cPost) Delete(ctx context.Context, req *post.DeleteReq) (res *post.Dele
} }
err = service.AdminPost().Delete(ctx, in) err = service.AdminPost().Delete(ctx, in)
return res, nil return
} }
// Edit 修改/新增 // Edit 修改/新增

View File

@ -35,7 +35,7 @@ func ScanInstall(m Module) (record *InstallRecord, err error) {
func IsInstall(m Module) bool { func IsInstall(m Module) bool {
record, err := ScanInstall(m) record, err := ScanInstall(m)
if err != nil { if err != nil {
g.Log().Debugf(m.Ctx(), err.Error()) g.Log().Debug(m.Ctx(), err.Error())
return false return false
} }
if record == nil { if record == nil {

View File

@ -37,7 +37,7 @@ func SetAdapter(ctx context.Context) {
if conf == nil { if conf == nil {
conf = new(model.CacheConfig) conf = new(model.CacheConfig)
g.Log().Infof(ctx, "no cache driver is configured. default memory cache is used.") g.Log().Info(ctx, "no cache driver is configured. default memory cache is used.")
} }
switch conf.Adapter { switch conf.Adapter {
@ -45,7 +45,7 @@ func SetAdapter(ctx context.Context) {
adapter = gcache.NewAdapterRedis(g.Redis()) adapter = gcache.NewAdapterRedis(g.Redis())
case "file": case "file":
if conf.FileDir == "" { if conf.FileDir == "" {
g.Log().Fatalf(ctx, "file path must be configured for file caching.") g.Log().Fatal(ctx, "file path must be configured for file caching.")
return return
} }

View File

@ -34,7 +34,7 @@ func Get(ctx context.Context) *model.Context {
func SetUser(ctx context.Context, user *model.Identity) { func SetUser(ctx context.Context, user *model.Identity) {
c := Get(ctx) c := Get(ctx)
if c == nil { if c == nil {
g.Log().Warningf(ctx, "contexts.SetUser, c == nil ") g.Log().Warning(ctx, "contexts.SetUser, c == nil ")
return return
} }
c.User = user c.User = user
@ -44,7 +44,7 @@ func SetUser(ctx context.Context, user *model.Identity) {
func SetResponse(ctx context.Context, response *model.Response) { func SetResponse(ctx context.Context, response *model.Response) {
c := Get(ctx) c := Get(ctx)
if c == nil { if c == nil {
g.Log().Warningf(ctx, "contexts.SetResponse, c == nil ") g.Log().Warning(ctx, "contexts.SetResponse, c == nil ")
return return
} }
c.Response = response c.Response = response
@ -54,7 +54,7 @@ func SetResponse(ctx context.Context, response *model.Response) {
func SetModule(ctx context.Context, module string) { func SetModule(ctx context.Context, module string) {
c := Get(ctx) c := Get(ctx)
if c == nil { if c == nil {
g.Log().Warningf(ctx, "contexts.SetModule, c == nil ") g.Log().Warning(ctx, "contexts.SetModule, c == nil ")
return return
} }
c.Module = module c.Module = module
@ -64,7 +64,7 @@ func SetModule(ctx context.Context, module string) {
func SetTakeUpTime(ctx context.Context, takeUpTime int64) { func SetTakeUpTime(ctx context.Context, takeUpTime int64) {
c := Get(ctx) c := Get(ctx)
if c == nil { if c == nil {
g.Log().Warningf(ctx, "contexts.SetTakeUpTime, c == nil ") g.Log().Warning(ctx, "contexts.SetTakeUpTime, c == nil ")
return return
} }
c.TakeUpTime = takeUpTime c.TakeUpTime = takeUpTime
@ -120,7 +120,7 @@ func GetModule(ctx context.Context) string {
func SetAddonName(ctx context.Context, name string) { func SetAddonName(ctx context.Context, name string) {
c := Get(ctx) c := Get(ctx)
if c == nil { if c == nil {
g.Log().Warningf(ctx, "contexts.SetAddonName, c == nil ") g.Log().Warning(ctx, "contexts.SetAddonName, c == nil ")
return return
} }
Get(ctx).AddonName = name Get(ctx).AddonName = name

View File

@ -109,7 +109,7 @@ func setDefault(field *sysin.GenCodesColumnListModel) {
setDefaultValue(field) setDefaultValue(field)
if field.IsAllowNull == "YES" { if field.IsAllowNull == "NO" {
field.Required = true field.Required = true
} }

View File

@ -56,7 +56,7 @@ func FilterAuthWithField(filterField string) func(m *gdb.Model) *gdb.Model {
} }
if role == nil { if role == nil {
g.Log().Panicf(ctx, "failed to role information roleModel == nil") g.Log().Panic(ctx, "failed to role information roleModel == nil")
} }
sq := g.Model("admin_member").Fields("id") sq := g.Model("admin_member").Fields("id")
@ -77,7 +77,7 @@ func FilterAuthWithField(filterField string) func(m *gdb.Model) *gdb.Model {
case consts.RoleDataSelfAndAllSub: // 自己和全部下级 case consts.RoleDataSelfAndAllSub: // 自己和全部下级
m = m.WhereIn(filterField, GetSelfAndAllSub(co.User.Id)) m = m.WhereIn(filterField, GetSelfAndAllSub(co.User.Id))
default: default:
g.Log().Panicf(ctx, "dataScope is not registered") g.Log().Panic(ctx, "dataScope is not registered")
} }
return m return m

View File

@ -174,7 +174,7 @@ func GetPublicIP(ctx context.Context) (ip string, err error) {
} }
if data == nil { if data == nil {
g.Log().Infof(ctx, "publicIP address Parsing failure, check the network and firewall blocking.") g.Log().Info(ctx, "publicIP address Parsing failure, check the network and firewall blocking.")
return "0.0.0.0", nil return "0.0.0.0", nil
} }
return data.Ip, nil return data.Ip, nil

View File

@ -81,7 +81,7 @@ func init() {
mqProducerInstanceMap = make(map[string]MqProducer) mqProducerInstanceMap = make(map[string]MqProducer)
mqConsumerInstanceMap = make(map[string]MqConsumer) mqConsumerInstanceMap = make(map[string]MqConsumer)
if err := g.Cfg().MustGet(ctx, "queue").Scan(&config); err != nil { if err := g.Cfg().MustGet(ctx, "queue").Scan(&config); err != nil {
g.Log().Warning(ctx, "queue init err:%+v", err) g.Log().Warningf(ctx, "queue init err:%+v", err)
} }
} }

View File

@ -346,6 +346,15 @@ func (s *sAdminMenu) GetMenuList(ctx context.Context, memberId int64) (lists rol
if err != nil { if err != nil {
return role.DynamicRes{}, err return role.DynamicRes{}, err
} }
if len(array) > 0 {
pidList, err := dao.AdminMenu.Ctx(ctx).Fields("pid").WhereIn("id", array).Group("pid").Array()
if err != nil {
return role.DynamicRes{}, err
}
if len(pidList) > 0 {
array = append(pidList, array...)
}
}
mod = mod.Where("id", array) mod = mod.Where("id", array)
} }

View File

@ -16,7 +16,7 @@ func (s *sMiddleware) Blacklist(r *ghttp.Request) {
response.JsonExit(r, gcode.CodeServerBusy.Code(), "请求异常,已被封禁,如有疑问请联系管理员!") response.JsonExit(r, gcode.CodeServerBusy.Code(), "请求异常,已被封禁,如有疑问请联系管理员!")
} }
} else { } else {
g.Log().Infof(r.Context(), "blacklists uninitialized") g.Log().Info(r.Context(), "blacklists uninitialized")
} }
r.Middleware.Next() r.Middleware.Next()

View File

@ -99,7 +99,7 @@ func (s *sSysLog) Export(ctx context.Context, in sysin.LogListInp) (err error) {
// RealWrite 真实写入 // RealWrite 真实写入
func (s *sSysLog) RealWrite(ctx context.Context, commonLog entity.SysLog) (err error) { func (s *sSysLog) RealWrite(ctx context.Context, commonLog entity.SysLog) (err error) {
_, err = dao.SysLog.Ctx(ctx).Data(commonLog).Insert() _, err = dao.SysLog.Ctx(ctx).Data(commonLog).FieldsEx(dao.SysLog.Columns().Id).Insert()
return return
} }

View File

@ -99,7 +99,7 @@ func (s *sSysLoginLog) List(ctx context.Context, in sysin.LoginLogListInp) (list
} }
for _, v := range list { for _, v := range list {
g.DumpWithType(v) //g.DumpWithType(v)
//// 获取省市编码对应的地区名称 //// 获取省市编码对应的地区名称
//region, err := location.ParseRegion(ctx, v.SysLogProvinceId, v.SysLogCityId, 0) //region, err := location.ParseRegion(ctx, v.SysLogProvinceId, v.SysLogCityId, 0)
//if err != nil { //if err != nil {
@ -191,6 +191,6 @@ func (s *sSysLoginLog) Push(ctx context.Context, in sysin.LoginLogPushInp) {
// RealWrite 真实写入 // RealWrite 真实写入
func (s *sSysLoginLog) RealWrite(ctx context.Context, models entity.SysLoginLog) (err error) { func (s *sSysLoginLog) RealWrite(ctx context.Context, models entity.SysLoginLog) (err error) {
_, err = dao.SysLoginLog.Ctx(ctx).Data(models).Insert() _, err = dao.SysLoginLog.Ctx(ctx).Data(models).FieldsEx(dao.SysLoginLog.Columns().Id).Insert()
return return
} }

View File

@ -144,6 +144,6 @@ func (s *sSysServeLog) View(ctx context.Context, in sysin.ServeLogViewInp) (res
// RealWrite 真实写入 // RealWrite 真实写入
func (s *sSysServeLog) RealWrite(ctx context.Context, models entity.SysServeLog) (err error) { func (s *sSysServeLog) RealWrite(ctx context.Context, models entity.SysServeLog) (err error) {
_, err = dao.SysServeLog.Ctx(ctx).Data(models).Insert() _, err = dao.SysServeLog.Ctx(ctx).Data(models).FieldsEx(dao.SysServeLog.Columns().Id).Insert()
return return
} }

View File

@ -291,7 +291,7 @@ func (manager *ClientManager) start() {
} }
} }
case <-manager.closeSignal: case <-manager.closeSignal:
g.Log().Infof(ctxManager, "websocket closeSignal quit..") g.Log().Info(ctxManager, "websocket closeSignal quit..")
return return
} }

View File

@ -33,7 +33,7 @@ type ExportReq struct {
type ExportRes struct{} type ExportRes struct{}
@{end} @{end}
@{ if eq .options.Step.HasView true } @{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
// ViewReq 获取@{.tableComment}指定信息 // ViewReq 获取@{.tableComment}指定信息
type ViewReq struct { type ViewReq struct {
g.Meta `path:"/@{.varName | LcFirst}/view" method:"get" tags:"@{.tableComment}" summary:"获取@{.tableComment}指定信息"` g.Meta `path:"/@{.varName | LcFirst}/view" method:"get" tags:"@{.tableComment}" summary:"获取@{.tableComment}指定信息"`

View File

@ -92,7 +92,7 @@ func (c *c@{.varName}) MaxSort(ctx context.Context, req *@{.varName | ToLower}.M
return return
} }
@{end} @{end}
@{ if eq .options.Step.HasView true } @{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
// View 获取指定@{.tableComment}信息 // View 获取指定@{.tableComment}信息
func (c *c@{.varName}) View(ctx context.Context, req *@{.varName | ToLower}.ViewReq) (res *@{.varName | ToLower}.ViewRes, err error) { func (c *c@{.varName}) View(ctx context.Context, req *@{.varName | ToLower}.ViewReq) (res *@{.varName | ToLower}.ViewRes, err error) {
var in @{.templateGroup}in.@{.varName}ViewInp var in @{.templateGroup}in.@{.varName}ViewInp

View File

@ -44,7 +44,7 @@ func (in *@{.varName}DeleteInp) Filter(ctx context.Context) (err error) {
type @{.varName}DeleteModel struct{} type @{.varName}DeleteModel struct{}
@{end} @{end}
@{ if eq .options.Step.HasView true } @{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
// @{.varName}ViewInp 获取指定@{.tableComment}信息 // @{.varName}ViewInp 获取指定@{.tableComment}信息
type @{.varName}ViewInp struct { type @{.varName}ViewInp struct {
@{.pk.GoName} @{.pk.GoType} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"` @{.pk.GoName} @{.pk.GoType} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"`

View File

@ -125,7 +125,7 @@ func (s *s@{.servFunName}) MaxSort(ctx context.Context, in @{.templateGroup}in.@
return return
} }
@{end} @{end}
@{ if eq .options.Step.HasView true } @{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
// View 获取@{.tableComment}指定信息 // View 获取@{.tableComment}指定信息
func (s *s@{.servFunName}) View(ctx context.Context, in @{.templateGroup}in.@{.varName}ViewInp) (res *@{.templateGroup}in.@{.varName}ViewModel, err error) { func (s *s@{.servFunName}) View(ctx context.Context, in @{.templateGroup}in.@{.varName}ViewInp) (res *@{.templateGroup}in.@{.varName}ViewModel, err error) {
err = s.Model(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Scan(&res) err = s.Model(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Scan(&res)

View File

@ -35,7 +35,7 @@ INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type
SET @listId = LAST_INSERT_ID(); SET @listId = LAST_INSERT_ID();
@{ if eq .options.Step.HasView true } @{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
-- 详情 -- 详情
INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @dirId, '@{.tableComment}详情', '@{.varName | LcFirst}View', 'view/:id?', '', '2', '', '/@{.apiPrefix}/view', '', '/@{.componentPrefix}/view', '0', '@{.varName | LcFirst}Index', '0', '0', '', '0', '1', '0', '2', '', '20', '', '1', @now, @now); INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @dirId, '@{.tableComment}详情', '@{.varName | LcFirst}View', 'view/:id?', '', '2', '', '/@{.apiPrefix}/view', '', '/@{.componentPrefix}/view', '0', '@{.varName | LcFirst}Index', '0', '0', '', '0', '1', '0', '2', '', '20', '', '1', @now, @now);
@{end} @{end}

View File

@ -48,7 +48,7 @@ export function Switch(params) {
}); });
} }
@{end} @{end}
@{ if eq .options.Step.HasView true } @{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
// 获取@{.tableComment}指定详情 // 获取@{.tableComment}指定详情
export function View(params) { export function View(params) {
return http.request({ return http.request({

View File

@ -92,11 +92,11 @@
@{.apiImport} @{.apiImport}
import { State, columns, schemas, options, newState } from './model'; import { State, columns, schemas, options, newState } from './model';
@{.iconsImport} @{.iconsImport}
@{ if eq .options.Step.HasView true } import { useRouter } from 'vue-router';@{end} @{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) } import { useRouter } from 'vue-router';@{end}
import { getOptionLabel } from '@/utils/hotgo'; import { getOptionLabel } from '@/utils/hotgo';
@{ if eq .options.Step.HasEdit true } import Edit from './edit.vue';@{end} @{ if eq .options.Step.HasEdit true } import Edit from './edit.vue';@{end}
const { hasPermission } = usePermission(); const { hasPermission } = usePermission();
@{ if eq .options.Step.HasView true } const router = useRouter();@{end} @{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) } const router = useRouter();@{end}
const actionRef = ref(); const actionRef = ref();
const dialog = useDialog(); const dialog = useDialog();
const message = useMessage(); const message = useMessage();

View File

@ -30,7 +30,7 @@ func IsDNSName(s string) bool {
func IsHTTPS(ctx context.Context) bool { func IsHTTPS(ctx context.Context) bool {
r := ghttp.RequestFromCtx(ctx) r := ghttp.RequestFromCtx(ctx)
if r == nil { if r == nil {
g.Log().Infof(ctx, "IsHTTPS ctx not request") g.Log().Info(ctx, "IsHTTPS ctx not request")
return false return false
} }
var ( var (

View File

@ -38,6 +38,7 @@
"date-fns": "^2.28.0", "date-fns": "^2.28.0",
"echarts": "^5.3.2", "echarts": "^5.3.2",
"element-resize-detector": "^1.2.4", "element-resize-detector": "^1.2.4",
"highlight.js": "^11.8.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"mitt": "^2.1.0", "mitt": "^2.1.0",

View File

@ -118,7 +118,7 @@ export function getChildrenRouter(routerMap: Array<any>) {
* Router * Router
* */ * */
export function isRootRouter(item) { export function isRootRouter(item) {
if (item.meta?.alwaysShow != true && item.children?.length === 1) { if (item.meta?.alwaysShow != true && item.children?.length === 0) {
return true; return true;
} }

View File

@ -99,3 +99,11 @@ export function newState(state: State | null): State {
export const options = ref<Options>({ export const options = ref<Options>({
sys_normal_disable: [], sys_normal_disable: [],
}); });
async function loadOptions() {
options.value = await Dicts({
types: ['sys_normal_disable'],
});
}
await loadOptions();

View File

@ -120,6 +120,7 @@
NIcon, NIcon,
NTag, NTag,
NIconWrapper, NIconWrapper,
NAvatar,
useMessage, useMessage,
NImage, NImage,
useDialog, useDialog,
@ -159,25 +160,13 @@
}); });
} else { } else {
return h( return h(
NIconWrapper, NAvatar,
{ {
size: 48, size: 48,
borderRadius: 8, color: '#2D8CF0',
}, },
{ {
default: () => default: () => h(getIconComponent(row.logo)),
h(
NIcon,
{
size: 36,
style: {
marginTop: '-8px',
},
},
{
default: () => h(getIconComponent(row.logo)),
}
),
} }
); );
} }

View File

@ -10,7 +10,7 @@
{{ view.path }} {{ view.path }}
</n-tag> </n-tag>
<n-scrollbar class="code-scrollbar" trigger="none"> <n-scrollbar class="code-scrollbar" trigger="none">
<n-code :code="view.content" /> <n-code :code="view.content" :hljs="hljs" language="goLang" show-line-numbers />
</n-scrollbar> </n-scrollbar>
</n-tab-pane> </n-tab-pane>
</n-tabs> </n-tabs>
@ -19,6 +19,8 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from 'vue'; import { computed } from 'vue';
import hljs from 'highlight.js/lib/core';
import goLang from 'highlight.js/lib/languages/go';
import { cloneDeep } from 'lodash-es'; import { cloneDeep } from 'lodash-es';
import { import {
CheckmarkCircle, CheckmarkCircle,
@ -27,6 +29,7 @@
HelpCircleOutline, HelpCircleOutline,
RemoveCircleOutline, RemoveCircleOutline,
} from '@vicons/ionicons5'; } from '@vicons/ionicons5';
hljs.registerLanguage('goLang', goLang);
interface Props { interface Props {
previewModel: any; previewModel: any;

View File

@ -15,7 +15,6 @@ export const columns = [
{ {
ghost: true, ghost: true,
strong: true, strong: true,
tertiary: true,
size: 'small', size: 'small',
text: true, text: true,
iconPlacement: 'right', iconPlacement: 'right',