e63ee924d4
添加独立bar.json
335 lines
7.6 KiB
Plaintext
335 lines
7.6 KiB
Plaintext
//低代码框架 amis
|
|
import win.ui;
|
|
/*DSG{{*/
|
|
var winform = win.form(text="WebView2 - 调用百度低代码前端框架 amis";right=966;bottom=622;border="none";maximize=1;)
|
|
winform.add(
|
|
bk={cls="bk";left=0;top=-1;right=967;bottom=30;bgcolor=10789024;dl=1;dr=1;dt=1;z=1;};
|
|
custom={cls="custom";text="自定义控件";left=0;top=32;right=967;bottom=623;db=1;dl=1;dr=1;dt=1;z=2;};
|
|
|
|
)
|
|
/*}}*/
|
|
|
|
import web.view.7;
|
|
var wb = web.view(winform.custom);
|
|
import web.json
|
|
import console
|
|
|
|
//添加阴影边框
|
|
import win.ui.simpleWindow2
|
|
win.ui.simpleWindow2(winform)
|
|
|
|
//下面的代码实现用鼠标左键按住窗口时 —— 可拖动改变窗口位置
|
|
winform.onMouseDown = function(wParam,lParam){
|
|
winform.hitCaption()
|
|
}
|
|
|
|
|
|
wb.export({
|
|
getAmisJson = function(){
|
|
var cfgstr = string.load("\res\cfg.json")
|
|
var cfgjson = web.json.parse(cfgstr)
|
|
return cfgjson;
|
|
};
|
|
})
|
|
|
|
send = function(t){
|
|
//var p = web.json.
|
|
//console.varDump(t)
|
|
return math.random();
|
|
}
|
|
getTestModule = function(){
|
|
var m= {"自检","EVM","灵敏度","成功率"}
|
|
return m;
|
|
}
|
|
|
|
randdev = function(){
|
|
var lst = {};
|
|
for(i=1;math.random(1,5);1){
|
|
var SN = string.upper(string.random(10,"QWERTYUIOP7894561230"));
|
|
table.push(lst,"USB:" ++ SN)
|
|
table.push(lst,"SER:" ++ SN)
|
|
}
|
|
return lst;
|
|
}
|
|
|
|
getdev = function(){
|
|
var lst = randdev()
|
|
|
|
var json = web.json.stringify(lst);
|
|
json = string.trimleft(json,'[')
|
|
json = string.trimright(json,']')
|
|
return json;
|
|
}
|
|
|
|
condev = function(id){
|
|
console.varDump(id)
|
|
return math.round(math.random());
|
|
}
|
|
closedev = function(id){
|
|
//console.varDump(id)
|
|
return math.round(math.random());
|
|
}
|
|
|
|
|
|
loadModule = function(){
|
|
var str = string.load("\res\m.txt");
|
|
var minfo = {count=0;rows={}};
|
|
for(k,v in string.lines(str,,";")){
|
|
|
|
if(! string.startWith(string.trimleft(k[1]),"//")){//注释行
|
|
//console.varDump(k)
|
|
minfo.count += 1
|
|
table.push(minfo.rows,{id=minfo.count,name = k[1],description = k[2],cfg = web.json.tryParse(k[3])})
|
|
}
|
|
|
|
}
|
|
//console.dumpJson(minfo)
|
|
return minfo;
|
|
|
|
}
|
|
|
|
var ms = loadModule()
|
|
getModuleInfo = function(v){
|
|
|
|
//page/perPage
|
|
|
|
return ms;
|
|
|
|
return loadModule();
|
|
//var lst = string.load("\res\moduleinfo.json")
|
|
|
|
//var json = web.json.stringify(lst);
|
|
//json = string.trimleft(json,'[')
|
|
//json = string.trimright(json,']')
|
|
var json = web.json.parse(lst);
|
|
return json;
|
|
}
|
|
|
|
schema = function(v){
|
|
var s = ms.rows[tonumber(v)].cfg;
|
|
return s;
|
|
}
|
|
|
|
udpSend = function(d){
|
|
console.dumpTable(d)
|
|
}
|
|
|
|
|
|
getStatus = function(){
|
|
//-1:未上电 0:离线 1:在线
|
|
var seed = string.random("Success","Fault","PowerDown")
|
|
return {state={math.random(-1,1),math.random(-1,1),math.random(-1,1)}};
|
|
}
|
|
|
|
loadSchema = function(s){
|
|
var jsonstr = string.load("/res/"++s++".json");
|
|
return web.json.parse(jsonstr);
|
|
}
|
|
|
|
|
|
import wsock.tcp.asynHttpServer;
|
|
var httpServer = wsock.tcp.asynHttpServer();
|
|
|
|
|
|
httpServer.run(
|
|
//此处添加函数
|
|
["/loadSchema"] = function(response,request){
|
|
//console.varDump(request)
|
|
var data = request.get["schema"];//读取表单请求发送的数据,已解析为 aardio 对象
|
|
var rst = loadSchema(data)
|
|
|
|
response.write({
|
|
"status": 0,
|
|
"data": rst
|
|
})
|
|
};
|
|
|
|
["/sendPair"] = function(response,request){
|
|
//console.varDump(request)
|
|
var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象
|
|
var rst = send(data)
|
|
|
|
response.write({
|
|
"status": 0,
|
|
"msg": "发送成功",
|
|
"data": { "id": rst }
|
|
})
|
|
};
|
|
|
|
["/sendData"] = function(response,request){
|
|
//console.dumpTable(request)
|
|
var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象
|
|
var rst = udpSend(data)
|
|
response.write({
|
|
"status": 0,
|
|
"msg": "发送成功",
|
|
"data": { "id": rst }
|
|
})
|
|
};
|
|
|
|
["/sendCfg"] = function(response,request){
|
|
//console.varDump(request)
|
|
var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象
|
|
var rst = send(data)
|
|
response.write({
|
|
"status": 0,
|
|
"msg": "发送成功",
|
|
//"data": { "id": rst }
|
|
})
|
|
};
|
|
|
|
|
|
["/getDevices"] = function(response,request){
|
|
//console.varDump(request)
|
|
var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象
|
|
//var rst = send(data)
|
|
response.write({
|
|
"status": 0,
|
|
//"msg": "发送成功",
|
|
"data": getdev()
|
|
})
|
|
};
|
|
|
|
|
|
["/connectDev"] = function(response,request){
|
|
//console.varDump(request)
|
|
var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象
|
|
var rst = condev(data)
|
|
response.write({
|
|
"status": rst,
|
|
//"msg": "连接成功",
|
|
"msgTimeout": 100,
|
|
"data": {"rst":rst}
|
|
})
|
|
|
|
|
|
};
|
|
|
|
["/closeDev"] = function(response,request){
|
|
//console.varDump(request)
|
|
var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象
|
|
var rst = condev(data)
|
|
response.write({
|
|
"status": rst,
|
|
//"msg": "连接成功",
|
|
"msgTimeout": 100,
|
|
"data": {"rst":rst}
|
|
})
|
|
};
|
|
|
|
["/getTestModule"] = function(response,request){
|
|
//console.varDump(request)
|
|
var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象
|
|
var rst = getTestModule(data)
|
|
response.write({
|
|
"status": 0,
|
|
//"msg": "连接成功",
|
|
//"msgTimeout": 100,
|
|
"data": {"options":rst}
|
|
})
|
|
};
|
|
|
|
["/saveForm"] = function(response,request){
|
|
|
|
var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象
|
|
console.dumpJson(data)
|
|
//var rst = getTestModule(data)
|
|
response.write({
|
|
"status": 0,
|
|
//"msg": "连接成功",
|
|
//"msgTimeout": 100,
|
|
"data": {"options":0}
|
|
})
|
|
};
|
|
|
|
["/saveSubform"] = function(response,request){
|
|
|
|
var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象
|
|
console.dumpJson(data)
|
|
//var rst = getTestModule(data)
|
|
response.write({
|
|
"status": 0,
|
|
//"msg": "连接成功",
|
|
//"msgTimeout": 100,
|
|
"data": {"options":0}
|
|
})
|
|
};
|
|
|
|
|
|
["/getModuleInfo"] = function(response,request){
|
|
|
|
var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象
|
|
//console.dumpJson(data)
|
|
var rst = getModuleInfo(data)
|
|
response.write({
|
|
"status": 0,
|
|
//"msg": "连接成功",
|
|
//"msgTimeout": 100,
|
|
"data": rst
|
|
})
|
|
};
|
|
|
|
["/schema"] = function(response,request,session){
|
|
//var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象
|
|
var data = request.get["cmd"]
|
|
|
|
var rst = schema(data)
|
|
response.write({
|
|
"status": 0,
|
|
//"msg": "连接成功",
|
|
//"msgTimeout": 100,
|
|
"data": rst
|
|
})
|
|
};
|
|
|
|
|
|
|
|
|
|
["/api/getStatus"] = function(response,request,session){
|
|
var data = request.postJson();//读取表单请求发送的数据,已解析为 aardio 对象
|
|
//var data = request.get["cmd"]
|
|
|
|
var rst = getStatus(data)
|
|
|
|
|
|
response.write({
|
|
"status": 0,
|
|
//"msg": "连接成功",
|
|
//"msgTimeout": 100,
|
|
"data": rst
|
|
})
|
|
|
|
};
|
|
|
|
|
|
)
|
|
|
|
//可以支持 aardio 服务端 HTML 模板语法
|
|
var url = httpServer.getUrl("web\index.html"); //参数支持 aardio 工程嵌入资源目录路径
|
|
|
|
//用浏览器组件打开网页试试
|
|
|
|
|
|
|
|
wb.go(url);
|
|
//winform.fullscreen()
|
|
|
|
|
|
|
|
winform.show();
|
|
win.loopMessage();
|
|
|
|
|
|
/*
|
|
<script>
|
|
document.oncontextmenu = function () { return false; };
|
|
document.onkeydown = function () {
|
|
if (window.event && window.event.keyCode == 123) {
|
|
event.keyCode = 0;
|
|
event.returnValue = false;
|
|
return false;
|
|
}
|
|
};
|
|
</script>
|
|
|
|
*/ |