获取进程列表

This commit is contained in:
Shikong 2023-07-17 10:05:45 +08:00
parent 4fa5e7e34d
commit 3000dc13fc
6 changed files with 83 additions and 22 deletions

View File

@ -11,8 +11,6 @@ declare module 'vue' {
ElButton: typeof import('element-plus/es')['ElButton'] ElButton: typeof import('element-plus/es')['ElButton']
ElCol: typeof import('element-plus/es')['ElCol'] ElCol: typeof import('element-plus/es')['ElCol']
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider'] ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
ElInput: typeof import('element-plus/es')['ElInput']
ElPagination: typeof import('element-plus/es')['ElPagination']
ElProgress: typeof import('element-plus/es')['ElProgress'] ElProgress: typeof import('element-plus/es')['ElProgress']
ElRow: typeof import('element-plus/es')['ElRow'] ElRow: typeof import('element-plus/es')['ElRow']
ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] ElScrollbar: typeof import('element-plus/es')['ElScrollbar']

View File

@ -92,11 +92,6 @@ const generateData = (
} }
) )
}) })
const table = reactive({
columns: generateColumns(10),
data: generateData(generateColumns(10),20)
})
</script> </script>
<template> <template>
@ -114,11 +109,8 @@ const table = reactive({
</el-col> </el-col>
</el-row> </el-row>
<div class="result w-full text-center" id="result">Please enter your name below 👇</div>
<div class="input-box w-full text-center" id="input"> <el-button class="btn" @click="sendNotify()">通知</el-button>
<el-input v-model="controller.input" type="text" autocomplete="off"></el-input>
<el-button class="btn" @click="sendNotify()">通知</el-button>
</div>
<el-button @click="getAllEnv()">获取所有环境变量</el-button> <el-button @click="getAllEnv()">获取所有环境变量</el-button>
<div> <div>
@ -127,15 +119,6 @@ const table = reactive({
</div> </div>
<el-button @click="switchLocale()">切换 locale</el-button> <el-button @click="switchLocale()">切换 locale</el-button>
<div style="height: 50vh">
<el-auto-resizer>
<template #default="{ height, width}">
<el-table-v2 mb-1 :height="height" :width="width" :data="table.data" :columns="table.columns" fixed/>
</template>
</el-auto-resizer>
</div>
<el-pagination :total="100" />
<el-button @click="addTab()">添加tab</el-button> <el-button @click="addTab()">添加tab</el-button>
<el-button @click="router.push('/environment')">环境变量</el-button> <el-button @click="router.push('/environment')">环境变量</el-button>

View File

@ -319,3 +319,47 @@ export namespace process {
} }
export namespace system {
export class ProcessDTO {
pid: number;
name: string;
parent?: process.Process;
status: string;
createTime: number;
static createFrom(source: any = {}) {
return new ProcessDTO(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.pid = source["pid"];
this.name = source["name"];
this.parent = this.convertValues(source["parent"], process.Process);
this.status = source["status"];
this.createTime = source["createTime"];
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
}

View File

@ -4,8 +4,8 @@ import {cpu} from '../models';
import {disk} from '../models'; import {disk} from '../models';
import {net} from '../models'; import {net} from '../models';
import {process} from '../models'; import {process} from '../models';
import {mem} from '../models';
import {system} from '../models'; import {system} from '../models';
import {mem} from '../models';
export function GetAllProcessPid():Promise<Array<number>>; export function GetAllProcessPid():Promise<Array<number>>;
@ -25,6 +25,8 @@ export function GetNetWorkConnection():Promise<Array<net.ConnectionStat>>;
export function GetProcessInfo(arg1:number):Promise<process.Process>; export function GetProcessInfo(arg1:number):Promise<process.Process>;
export function GetProcesses():Promise<Array<system.ProcessDTO>>;
export function GetSwapMemory():Promise<mem.SwapMemoryStat>; export function GetSwapMemory():Promise<mem.SwapMemoryStat>;
export function GetVirtualMemory():Promise<mem.VirtualMemoryStat>; export function GetVirtualMemory():Promise<mem.VirtualMemoryStat>;

View File

@ -38,6 +38,10 @@ export function GetProcessInfo(arg1) {
return window['go']['system']['InfoUtils']['GetProcessInfo'](arg1); return window['go']['system']['InfoUtils']['GetProcessInfo'](arg1);
} }
export function GetProcesses() {
return window['go']['system']['InfoUtils']['GetProcesses']();
}
export function GetSwapMemory() { export function GetSwapMemory() {
return window['go']['system']['InfoUtils']['GetSwapMemory'](); return window['go']['system']['InfoUtils']['GetSwapMemory']();
} }

View File

@ -11,3 +11,33 @@ func (i *InfoUtils) GetProcessInfo(pid int32) *process.Process {
info, _ := process.NewProcess(pid) info, _ := process.NewProcess(pid)
return info return info
} }
type ProcessDTO struct {
Pid int32 `json:"pid"`
Name string `json:"name"`
Parent *process.Process `json:"parent"`
Status string `json:"status"`
CreateTime int64 `json:"createTime"`
}
func (i *InfoUtils) GetProcesses() []*ProcessDTO {
info, _ := process.Processes()
dto := make([]*ProcessDTO, 0)
for _, i := range info {
d := &ProcessDTO{
Pid: i.Pid,
Name: "",
Parent: nil,
Status: "",
CreateTime: 0,
}
d.Name, _ = i.Name()
d.Parent, _ = i.Parent()
d.CreateTime, _ = i.CreateTime()
d.Status, _ = i.Status()
dto = append(dto, d)
}
return dto
}