diff --git a/amis-flask-pywebview-demo/app.py b/amis-flask-pywebview-demo/app.py index 0abae64..344f7e4 100644 --- a/amis-flask-pywebview-demo/app.py +++ b/amis-flask-pywebview-demo/app.py @@ -33,6 +33,27 @@ def submit(): return jsonify({"code": 0, "msg": "恭喜,注册成功!"}) + +@app.route('/api/getStatus') +def getStatus(): + #产生三组随机数,随机数在-1 0 1之间 + import random + import time + time.sleep(1) + a = random.randint(-1, 1) + b = random.randint(-1, 1) + c = random.randint(-1, 1) + return jsonify({"code": 0, "data": {'state':[a, b, c]}}) + + +@app.route('/sendData',methods=['POST']) +def sendUPD(): + #print the keys and values of the request + print(request.json) + return jsonify({"code": 0, "msg": "发送指令成功!"}) + + + # 定义锁文件的路径 LOCKFILE = 'app.lock' diff --git a/amis-flask-pywebview-demo/cfg.json b/amis-flask-pywebview-demo/cfg.json index 0edcc9f..84ab3a5 100644 --- a/amis-flask-pywebview-demo/cfg.json +++ b/amis-flask-pywebview-demo/cfg.json @@ -1,23 +1,758 @@ { - "body": { - "api": "/saveForm", - "body": [ - { - "label": "Name", - "name": "name", - "type": "input-text", - "required": true - }, - { - "label": "Email邮箱", - "name": "email", - "type": "input-email", - "required": true - } - ], - "mode": "horizontal", - "type": "form" - }, - "title": "demo测试", - "type": "page" + "asideResizor":false, + "body":[ + { + "id":"u:f439a8330e02", + "inline":false, + "tpl":"初始页面", + "type":"tpl", + "wrapperComponent":"" + }, + { + "columns":[ + { + "body":[], + "id":"u:39c97acec8cc" + }, + { + "body":[ + { + "activeKey":[ + "1" + ], + "body":[ + { + "active":true, + "body":[ + { + "buttons":[ + { + "id":"u:sendButtonText", + "label":"按钮1", + "type":"button", + "onEvent":{ + "click":{ + "actions":[ + { + "actionType":"custom", + "ignoreError":false, + "script":"const buttonText = context.props.label;\ndoAction({\n actionType: \u0027ajax\u0027,\n args: {\n api: {\n url: \u0027/sendData\u0027,\n method: \u0027post\u0027,\n data: {\n buttonLabel: buttonText\n }\n }\n }\n});\n" + } + ] + } + } + }, + { + "id":"u:8eae2c306cc5", + "label":"按钮2", + "type":"button", + "onEvent":{ + "click":{ + "actions":[ + { + "actionType":"custom", + "ignoreError":false, + "script":"const buttonText = context.props.label;\ndoAction({\n actionType: \u0027ajax\u0027,\n args: {\n api: {\n url: \u0027/sendData\u0027,\n method: \u0027post\u0027,\n data: {\n buttonLabel: buttonText\n },\n successMessage: \u0027请求成功\u0027,\n errorMessage: \u0027请求失败\u0027\n }\n }\n});\n" + } + ] + } + } + } + ], + "id":"u:b6649c1b1585", + "label":"按钮工具栏", + "type":"button-toolbar", + "data":{ + "x":"yy" + } + }, + { + "displayMode":"base", + "id":"numberInput", + "keyboard":true, + "kilobitSeparator":true, + "label":"数字输入", + "max":500000, + "min":225000, + "mode":"inline", + "name":"freq", + "placeholder":"225,000到500,000之间", + "required":true, + "size":"full", + "step":12, + "type":"input-number", + "unitOptions":[ + { + "label":"kHz" + } + ], + "value":225000 + }, + { + "block":false, + "disabledOn":"this.freq === undefined || this.freq === \u0027\u0027", + "id":"submitButton", + "label":"提交", + "size":"md", + "type":"button", + "onEvent":{ + "click":{ + "actions":[ + { + "actionType":"ajax", + "ignoreError":false, + "outputVar":"responseResult", + "api":{ + "method":"post", + "url":"/sendData", + "data":{ + "frequency":"${freq}" + } + }, + "messages":{ + "failed":"发送数据失败,请重试", + "success":"数据已成功发送" + } + } + ] + } + } + }, + { + "id":"u:5112d83e3943", + "inline":false, + "label":"单选", + "multiple":false, + "name":"buttonGroupSelect", + "options":[ + { + "label":"选项1", + "value":"a" + }, + { + "label":"选项2", + "value":"b" + } + ], + "type":"button-group-select", + "value":"a" + }, + { + "falseValue":false, + "id":"u:bd2f8c0b2176", + "label":"天通", + "mode":"inline", + "name":"switchTT", + "trueValue":true, + "type":"switch", + "onEvent":{ + "change":{ + "actions":[ + { + "actionType":"custom", + "ignoreError":false, + "script":"const buttonText = context.props.label + (!context.props.value?\u0027开\u0027:\u0027关\u0027);\ndoAction({\n actionType: \u0027ajax\u0027,\n args: {\n api: {\n url: \u0027/sendData\u0027,\n method: \u0027post\u0027,\n data: {\n buttonLabel: buttonText\n },\n successMessage: \u0027请求成功\u0027,\n errorMessage: \u0027请求失败\u0027\n }\n }\n});\n" + } + ], + "weight":0 + } + } + }, + { + "falseValue":false, + "id":"u:bd2f8c0b2176", + "label":"超短波", + "mode":"inline", + "name":"switchCDB", + "trueValue":true, + "type":"switch", + "onEvent":{ + "change":{ + "actions":[ + { + "actionType":"custom", + "ignoreError":false, + "script":"const buttonText = context.props.label + (!context.props.value?\u0027开\u0027:\u0027关\u0027);\ndoAction({\n actionType: \u0027ajax\u0027,\n args: {\n api: {\n url: \u0027/sendData\u0027,\n method: \u0027post\u0027,\n data: {\n buttonLabel: buttonText\n },\n successMessage: \u0027请求成功\u0027,\n errorMessage: \u0027请求失败\u0027\n }\n }\n});\n" + } + ], + "weight":0 + } + } + } + ], + "header":"通用", + "id":"u:53511e674086", + "key":"1", + "type":"collapse" + }, + { + "body":[ + { + "api":"/api/getStatus", + "body":[ + { + "id":"u:18e5f253165a", + "trs":[ + { + "background":"#F7F7F7", + "id":"u:37a706fd866d", + "tds":[ + { + "align":"center", + "id":"u:fddabc45cb59", + "valign":"middle", + "body":{ + "id":"u:19f87144bbea", + "tpl":"模块", + "type":"tpl", + "wrapperComponent":"" + } + }, + { + "align":"center", + "id":"u:6ffa039534e7", + "valign":"middle", + "body":{ + "id":"u:420e9a9f9353", + "tpl":"最后一分钟状态", + "type":"tpl", + "wrapperComponent":"" + } + }, + { + "align":"center", + "id":"u:fe0dab630536", + "valign":"middle", + "body":{ + "id":"u:2dfafcf526f9", + "tpl":"最近一次状态", + "type":"tpl", + "wrapperComponent":"" + } + } + ] + }, + { + "id":"u:42c47c152e5f", + "tds":[ + { + "align":"center", + "id":"u:897aee319eb4", + "valign":"middle", + "body":{ + "id":"u:518882ea6114", + "tpl":"TT", + "type":"tpl", + "wrapperComponent":"" + } + }, + { + "align":"center", + "id":"u:4804d1216011", + "valign":"middle", + "width":"80%", + "body":{ + "name":"items", + "type":"each", + "items":{ + "tpl":"
", + "type":"tpl", + "style":{ + "display":"inline-block", + "marginBottom":"-5px", + "marginRight":"5px" + } + } + } + }, + { + "align":"center", + "id":"u:ba272dd0e407", + "valign":"middle", + "body":{ + "id":"u:20d501a115fc", + "tpl":"
", + "type":"tpl" + } + } + ] + } + ], + "type":"table-view" + } + ], + "interval":1500, + "silentPolling":true, + "type":"service", + "data":{ + "alive":"#00ff00", + "dead":"#ff0000", + "height":"30px", + "items":[ + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + }, + { + "color":[ + "${powerdown}", + "${powerdown}", + "${powerdown}" + ] + } + ], + "maxBarCnt":"60", + "powerdown":"#808080", + "width":"5px" + }, + "onEvent":{ + "fetchInited":{ + "actions":[ + { + "actionType":"custom", + "script":"const colorMap=[context.props.data.powerdown,context.props.data.dead,context.props.data.alive];\n const ncolor = [colorMap[event.data.responseData.state[0]+1],colorMap[event.data.responseData.state[1]+1],colorMap[event.data.responseData.state[2]+1]];\n console.log(event.data.responseData.state,ncolor);\ncontext.props.data.items.push({\u0027color\u0027:ncolor})\nif (context.props.data.items.length > context.props.data.maxBarCnt) {\n context.props.data.items.shift(); // Remove the oldest value\n};" + } + ] + } + } + } + ], + "header":"调试", + "id":"u:4ad528b09137", + "key":"6", + "type":"collapse" + } + ], + "id":"u:8035637b2ce6", + "type":"collapse-group" + } + ], + "id":"u:63b382ec7d2f" + } + ], + "id":"u:a9f37a6134a4", + "type":"grid" + } + ], + "id":"u:ddf6e6d384e7", + "regions":[ + "body" + ], + "title":"Hello world", + "type":"page", + "data":{ + "x":"xx" + }, + "pullRefresh":{ + "disabled":true + } } \ No newline at end of file