Go Wails Docker图形界面管理工具 (4)

1. 前言

接上篇,本次添加Docker日志查看功能

2. 效果图

在这里插入图片描述在这里插入图片描述

3. 代码

直接调用官方库

app.go

func (a *App) Log(ID string) (string, error) {
	reader, err := Cli.ContainerLogs(context.Background(), ID, types.ContainerLogsOptions{ShowStdout: true, ShowStderr: true})
	if err != nil {
		return "", err
	}
	b, err := ioutil.ReadAll(reader)
	if err != nil {
		return "", err
	}
	return string(b), nil
}

LogView.vue

<template>
    <a-spin :spinning="spinning">
        <div>
            <div class="table-operations">
                <a-button @click="handleRefresh">刷新容器</a-button>
            </div>
            <a-table row-key="ID" :columns="columns" :data-source="data" :scroll="{ x: 'max-content' }">
                <template #bodyCell="{ column, record }">
                    <template v-if="column.dataIndex === 'Names'">
                        <a-tag v-for="name in record.Names" color="geekblue">{{ name.substring(1) }}</a-tag>
                    </template>
                    <template v-else-if="column.dataIndex === 'State'">
                        <a-tag :color="record.State == 'running' ? 'green' : 'volcano'">{{ record.State }}</a-tag>
                    </template>
                    <template v-else-if="column.dataIndex === 'Ops'">
                        <a-button type="primary" @click="handleLog(record)">查看日志</a-button>
                    </template>
                </template>
            </a-table>
        </div>
        <a-drawer size="large" :title="drawerModel.title" :placement="right" :closable="false" v-model:visible="drawerModel.visible">
            <a-textarea :value="drawerModel.content"  autosize="true" readOnly />
        </a-drawer>
    </a-spin>
</template>
<script setup>
import { onBeforeMount, reactive, ref } from 'vue';
import { ContainerList, Log } from "../../wailsjs/go/main/App";
import { message } from "ant-design-vue";

onBeforeMount(() => handleRefresh());

const spinning = ref(false);
const drawerModel = reactive({
    title: "",
    content: "",
    visible: false
});

const columns = [{
    title: 'ID',
    dataIndex: 'ID',
    fixed: 'left',
}, {
    title: 'NAMES',
    dataIndex: 'Names',
    fixed: 'left',
}, {
    title: 'STATE',
    dataIndex: 'State',
    fixed: 'left',
}, {
    title: '操作',
    dataIndex: 'Ops',
},];

const data = ref([]);

const handleRefresh = () => {
    ContainerList()
        .then((containers) => {
            data.value = containers;
        })
        .catch(e => message.error(e));
};

const handleLog = (record) => {
    spinning.value = true;
    Log(record.ID)
        .then((log) => {
            drawerModel.title = `容器 - ${record.Names[0]} 日志`;
            drawerModel.content = log;
            drawerModel.visible = true;
        })
        .catch(e => message.error(e))
        .finally(() => { spinning.value = false; });
};

</script>

<style scoped>
.table-operations {
    margin-bottom: 16px;
}

.table-operations>button {
    margin-right: 8px;
}
</style>

项目地址 https://github.com/LeoBest2/my-docker-gui

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Wails是一个用于构建跨平台桌面应用程序的开发工具包,它结合了Go语言和Web前端技术。通过使用Wails,您可以使用Go语言编写后端逻辑,并使用Web前端技术(如HTML、CSS和JavaScript)构建用户界面。 以下是使用Wails + Go的一些基本步骤: 1. 安装Wails CLI:您可以使用以下命令安装Wails CLI环境检测工具: ```shell go install github.com/wailsapp/wails/v2/cmd/wails@latest ``` 2. 创建新的Wails项目:使用以下命令创建一个新的Wails项目: ```shell wails init <project_name> ``` 这将在当前目录下创建一个新的Wails项目。 3. 编写Go后端代码:在Wails项目的`main.go`文件中,您可以编写Go语言的后端逻辑。您可以使用Go的强大功能来处理数据、执行计算等。 4. 构建前端界面:在Wails项目的`frontend`目录中,您可以使用Web前端技术(如HTML、CSS和JavaScript)构建用户界面。您可以使用任何您熟悉的前端框架或库,例如ant-design-vue。 5. 运行应用程序:使用以下命令在开发模式下运行应用程序: ```shell wails serve ``` 这将启动Wails开发服务器,并在浏览器中打开应用程序。 6. 打包应用程序:一旦您完成了应用程序的开发,您可以使用以下命令将其打包为可执行文件: ```shell wails build ``` 这将根据您的操作系统生成相应的可执行文件。 请注意,以上步骤只是Wails + Go的基本示例。您可以根据自己的需求和喜好进行更多的定制和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值