aardio - wsock.tcp.simpleHttpServer 访问数据库例程

go 复制代码
import win.ui;
/*DSG{{*/
var winform = win.form(text="远程屏幕控制服务器";right=500;bottom=320)
winform.add(
edit={cls="edit";left=20;top=20;right=480;bottom=280;edge=1;multiline=1;readonly=1;vscroll=1;z=1}
)
/*}}*/
winform.show()
thread.invoke(function(winform){
    import win.ui;    
    import wsock.tcp.simpleHttpServer;
    import inet.adapter;
    // 获取本机局域网IP地址
    var localIp = wsock.getLocalIp();
    // 启动 HTTP 服务端
    var server = wsock.tcp.simpleHttpServer("0.0.0.0", 8081);
    // 在界面上显示服务器信息
    winform.edit.print(`
     📱 访问地址:
        本地访问: http://127.0.0.1:8081;
        局域网访问: http://` + localIp + `:8081
     📋 功能说明:
        🔴 演示远程sqlite表格的读取
    `)
    winform.show()
 
    // 在后台线程中运行服务器
    server.run(
        function(response, request){
            response.write(`
<!DOCTYPE html>
<html>
<head>
     <meta charset="UTF-8">
     <title>表格演示</title>
     <style>
         /* 表格整体样式 */
         table {
             width: 80%;
             margin: 30px auto;
             border-collapse: collapse; /* 合并边框 */
             font-family: "Microsoft YaHei", sans-serif;
             box-shadow: 0 2px 10px rgba(0,0,0,0.1); /* 轻微阴影 */
             border-radius: 8px;
             overflow: hidden;
         }

         /* 表头样式 */
         th {
             background-color: #409EFF;
             color: white;
             padding: 14px;
             text-align: center;
             font-weight: bold;
         }

         /* 单元格样式 */
         td {
             padding: 12px;
             text-align: center;
             border-bottom: 1px solid #eee;
         }

         /* 隔行变色 */
         tr:nth-child(even) {
             background-color: #f8f9fa;
         }

         /* 鼠标悬浮效果 */
         tr:hover {
             background-color: #e3f2fd;
             transition: 0.2s;
         }
     </style>
</head>
<body>
     <table>
         <tr>
             <th>标题</th>
             <th>长度</th>
             <th>年份</th>
             <th>描述</th>
         </tr>
`)
import sqlite
var db = sqlite("/test.db");
for title,length,year,starring in db.each("SELECT * FROM film") {
response.write(..string.format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",title,length,year,starring));
}
db.close();
response.write(`</table>
</body>
</html>
`);
        }
    );
            
    // 窗口关闭时停止服务器
    winform.onClose = function(hwnd) {
        server.stop();
    }
    
    // 线程驻留
    while(true){
        thread.delay(1);
    }
    
},winform);

win.loopMessage();
相关推荐
木心术12 小时前
OpenClaw数据库自动化部署与网站接口调通全流程指南
运维·数据库·自动化
枕布响丸辣2 小时前
MySQL 主从复制与 MyCat 分库分表实战详解
数据库·mysql
eRTE XFUN2 小时前
Redis 设置密码(配置文件、docker容器、命令行3种场景)
数据库·redis·docker
Lhan.zzZ2 小时前
Qt开发踩坑:QList越界问题导致程序崩溃
数据库·c++·qt
8Qi82 小时前
Redis哨兵模式(Sentinel)深度解析
java·数据库·redis·分布式·缓存·sentinel
数据库小组2 小时前
从业务库到实时分析库,NineData 构建 MySQL 到 SelectDB 同步链路
数据库·mysql·数据库管理工具·数据同步·ninedata·数据库迁移·selectdb
CDN3602 小时前
CDN HTTPS 证书配置失败?SSL 部署与域名绑定常见问题
数据库·https·ssl
Chengbei112 小时前
一次比较简单的360加固APP脱壳渗透
网络·数据库·web安全·网络安全·系统安全·网络攻击模型·安全架构
寒秋花开曾相惜2 小时前
(学习笔记)3.9 异质的数据结构(3.9.1 结构)
c语言·网络·数据结构·数据库·笔记·学习