Skip to content

Commit

Permalink
improve console
Browse files Browse the repository at this point in the history
  • Loading branch information
keengo99 committed Jan 6, 2025
1 parent 0981321 commit 9fe806b
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 173 deletions.
7 changes: 0 additions & 7 deletions console/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@ export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
AButton: typeof import('ant-design-vue/es')['Button']
ATable: typeof import('ant-design-vue/es')['Table']
IconCommunity: typeof import('./src/components/icons/IconCommunity.vue')['default']
IconDocumentation: typeof import('./src/components/icons/IconDocumentation.vue')['default']
IconEcosystem: typeof import('./src/components/icons/IconEcosystem.vue')['default']
IconSupport: typeof import('./src/components/icons/IconSupport.vue')['default']
IconTooling: typeof import('./src/components/icons/IconTooling.vue')['default']
NButton: typeof import('naive-ui')['NButton']
NCollapse: typeof import('naive-ui')['NCollapse']
NCollapseItem: typeof import('naive-ui')['NCollapseItem']
NDivider: typeof import('naive-ui')['NDivider']
NTable: typeof import('naive-ui')['NTable']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
Whm: typeof import('./src/components/Whm.vue')['default']
Expand Down
7 changes: 2 additions & 5 deletions console/src/components/Whm.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<script lang="ts">
export default {
name:"whm",
}
export function whm_get(call_name: string, param?: Record<string, string>): Promise<any> {
export function whm_get(call_name: string, param?: Record<string, any>): Promise<any> {
if (param == null) {
param = {}
}
param["whm_call"] = call_name;
param['format'] = 'json';
return fetch('/core.whm?' + new URLSearchParams(param).toString()).then((res) => res.json());
}
export function whm_post(call_name: string, formData: FormData|Record<string, string>): Promise<any> {
export function whm_post(call_name: string, formData: FormData|Record<string, any>): Promise<any> {
return fetch('/core.whm?' + new URLSearchParams({ "whm_call": call_name, "format": "json" }).toString(),
{
method: 'POST',
Expand Down
3 changes: 2 additions & 1 deletion console/src/views/ConnectionView.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script lang="ts" setup>
import { whm_get } from '@/components/Whm.vue';
import { onMounted, ref } from 'vue';
const connections = ref(<any[]>[]);
function flushConnect() {
fetch('/core.whm?whm_call=connection&format=json').then((res) => res.json()).then((json) => {
whm_get('connection').then((json) => {
connections.value = json.result.c;
});
}
Expand Down
175 changes: 164 additions & 11 deletions console/src/views/acccess/AccessView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,31 @@
import { onMounted, ref } from 'vue';
import TableView from './TableView.vue'
import DefaultAction from './ActionView.vue';
import { whm_get } from '@/components/Whm.vue';
import ModuleView, { type ModuleBase } from './ModuleView.vue';
import ModuleSelectView from './ModuleSelectView.vue';
const props = defineProps<{ access: string, vh?: string }>();
interface TableView {
name: string,
refs: number,
show_chain?: boolean,
};
interface NamedModule extends ModuleBase {
name: string
}
interface NamedModuleList {
acl: NamedModule[],
mark: NamedModule[]
}
interface EditNamedModule {
m?: ModuleBase,
name?: string,
type: number,
edit: boolean
}
const tables = ref(<TableView[] | null>null);
const named_modules = ref(<NamedModuleList | null>null);
function get_whm_url(call_name: string) {
let url: string = '/core.whm?format=json&whm_call=' + call_name + '&access=' + props.access;
if (props.vh) {
Expand All @@ -25,7 +42,23 @@ function flush_table() {
}
});
}
onMounted(flush_table)
function flush_named_module() {
var param: Record<string, any> = { access: props.access, detail: 1 };
if (props.vh) {
param["vh"] = props.vh;
}
whm_get('list_named_module', param).then((json) => {
named_modules.value = json.result;
});
}
function refresh() {
if (cur_tab.value == "access") {
flush_table();
} else {
flush_named_module();
}
}
onMounted(refresh)
function toggle_chain(table: TableView) {
table.show_chain = !table.show_chain;
}
Expand All @@ -45,19 +78,139 @@ function new_table() {
flush_table();
});
}
const cur_tab = ref("access")
const curEditNamedModule = ref(<EditNamedModule | null>null);
function switch_tab(tab: string) {
cur_tab.value = tab;
refresh();
}
function add_named_module(type: number) {
curEditNamedModule.value = { type: type, edit: false };
}
function del_named_module(type: number, m: NamedModule) {
if (!confirm("确定要删除命名模块" + m.name + "吗?")) {
return;
}
}
function edit_named_module(type: number, m: NamedModule) {
let param: Record<string, any> = { access: props.access, name: m.name, type: type }
if (props.vh) {
param["vh"] = props.vh;
}
whm_get('get_named_module', param).then((json) => {
curEditNamedModule.value = { type: type, m: json.result, name: m.name, edit: true };
});
}
function cancel_edit_named_module() {
curEditNamedModule.value = null;
}
</script>
<template>
[<RouterLink to='/named_module'>命名模块</RouterLink>]
<DefaultAction :access=props.access></DefaultAction>
[<a @click="new_table" href=#>新建表</a>]
<div v-if="tables == null">正在加载</div>
<template v-else>
<div v-for="table in tables">
<a href=# @click="toggle_chain(table)">{{ table.name }}</a> 引用:{{ table.refs }}
[<a href=# @click="del_table(table)">删除</a>]
<div v-if="table.show_chain">
<TableView :access=props.access :name=table.name :vh=props.vh />
<div>
[<a href=# @click="switch_tab('access')">控制规则</a>]
[<a href=# @click="switch_tab('named_module')">命名模块</a>]
[<a href=# @click="refresh()">刷新</a>]
</div>
<!-- access list -->
<template v-if="cur_tab == 'access'">
<DefaultAction :access=props.access></DefaultAction>

<div v-if="tables == null">正在加载</div>
<template v-else>
<div v-for="table in tables" class="access_table">
<a href=# @click="toggle_chain(table)">{{ table.name }}</a> 引用:{{ table.refs }}
[<a href=# @click="del_table(table)">删除</a>]
<div v-if="table.show_chain">
<TableView :access=props.access :name=table.name :vh=props.vh />
</div>
</div>
</template>
[<a @click="new_table" href=#>新建表</a>]
</template>
<!-- named_module -->
<template v-else>
<div v-for="(module, index) in [named_modules?.acl, named_modules?.mark]">
{{ index == 0 ? "匹配模块" : "标记模块" }} [<a href=# @click="add_named_module(index)">增加</a>]
<table border="1" cellspacing="0">
<tr>
<th>操作</th>
<th>名称</th>
<th>模块</th>
<th>信息</th>
</tr>
<tr v-for="m in module">
<td><a href=# @click="del_named_module(index, m)">删除</a></td>
<td><a href=# @click="edit_named_module(index, m)">{{ m.name }}</a></td>
<td>{{ m.module }}</td>
<td>{{ m.html }}</td>
</tr>
</table>
<hr>
</div>
<div v-if="curEditNamedModule != null" class="edit_chain">
<form id="form" name="accessaddform" onsubmit="return false;">
<table border="1" cellspacing="0">
<tr>
<td>名称</td>
<td>
<template v-if="!curEditNamedModule.edit">
<input name="module" :value="curEditNamedModule.name"/>
</template>
<template v-else>
{{ curEditNamedModule.name }}
</template>
</td>
</tr>
<tr>
<td>模块</td>
<td>
<template v-if="curEditNamedModule.m">
{{ curEditNamedModule.m.module }}
</template>
<template v-else>
<ModuleSelectView :access="props.access" :type="curEditNamedModule.type"/>
</template>
</td>
</tr>
<tr>
<td>配置</td>
<td>
<template v-if="curEditNamedModule.m">
<input type="hidden" name="begin_sub_form"
:value="(curEditNamedModule.type == 0 ? 'acl_' : 'mark_') + curEditNamedModule.m?.module" />
<ModuleView :module="curEditNamedModule.m" />
<input type="hidden" name="end_sub_form" value='1' />
</template>
</td>
</tr>
<tr>
<td colspan="2">
<button @click="">确定</button>
<button @click="cancel_edit_named_module()">取消</button>
</td>
</tr>
</table>
</form>
</div>
</template>
</template>
<style>
.access_table {
border: 1px solid;
margin: 2px;
padding: 2px;
}
.edit_chain {
border: 1px solid #666;
background: white;
position: fixed;
height: 100%;
left: 300px;
top: 0;
width: 100%;
padding: 0px;
margin: 1px;
z-index: 4300;
}
</style>
7 changes: 6 additions & 1 deletion console/src/views/acccess/ChainView.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import ModuleView, { type Module } from './ModuleView.vue';
import ModuleView, { type ModuleBase } from './ModuleView.vue';
export interface Module extends ModuleBase{
is_or: number,
revers: number,
ref?: string
}
export interface ChainKey {
file: string,
index: number,
Expand Down
28 changes: 28 additions & 0 deletions console/src/views/acccess/ModuleSelectView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script lang="ts" setup>
import { whm_get } from '@/components/Whm.vue';
import { onMounted, ref } from 'vue';
const props = defineProps<{
access:string,
type:number,
}>()
const modules = ref(<string[]|null>null);
function flush_module() {
let param:Record<string,any> = {
access:props.access,
type:props.type
}
whm_get("list_module",param).then((json)=>{
modules.value = json.result.module;
})
}
onMounted(flush_module);
</script>
<template>
<select>
<option>--请选择--</option>
<template v-for="module in modules">
<option value="{{ module }}">{{ module }}</option>
</template>
</select>
</template>
12 changes: 5 additions & 7 deletions console/src/views/acccess/ModuleView.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<script lang="ts" setup>
import { computed, onMounted, ref, watchEffect } from 'vue';
export interface Module {
html: string,
is_or: number,
revers: number,
module?: string,
ref?: string
export interface ModuleBase {
module?: string,
html: string,
}
const props = defineProps<{
module: Module
module: ModuleBase
}>()
const getScripts = computed<string[]>(()=>{
Expand Down
5 changes: 0 additions & 5 deletions console/src/views/acccess/NamedModuleView.vue

This file was deleted.

16 changes: 1 addition & 15 deletions console/src/views/acccess/TableView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,4 @@ onMounted(flushChain);
</div>
[<a href=# @click='appendChain()'>增加</a>]
</template>
</template>
<style>
.edit_chain {
border: 1px solid #666;
background: white;
position: fixed;
height: 100%;
left: 300px;
top: 0;
width: 100%;
padding: 0px;
margin: 1px;
z-index: 4300;
}
</style>
</template>
15 changes: 15 additions & 0 deletions include/KModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ class KModel {
delete this;
}
}
void dump(kgl::serializable* m, bool is_short) {
m->add("revers", revers);
m->add("is_or", is_or);
m->add("module", getName());
if (!named.empty()) {
m->add("ref", named);
}
KStringBuf out;
if (is_short) {
get_display(out);
} else {
get_html(out);
}
m->add("html", out.str());
}
/* 命名模块的名字 */
KString named;
bool revers;
Expand Down
Loading

0 comments on commit 9fe806b

Please sign in to comment.