add pywebview demo
This commit is contained in:
parent
b1e4383afe
commit
27bbd133be
39
amis-flask-pywebview-demo/app.py
Normal file
39
amis-flask-pywebview-demo/app.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
from flask import Flask, jsonify, render_template,request
|
||||||
|
import json
|
||||||
|
import webview
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__, static_folder='web', static_url_path='')
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
return app.send_static_file('index.html')
|
||||||
|
|
||||||
|
@app.route('/api/config')
|
||||||
|
def get_config():
|
||||||
|
with open('cfg.json', 'r', encoding='utf-8') as f:
|
||||||
|
config = json.load(f)
|
||||||
|
return jsonify(config)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/saveForm', methods=['POST'])
|
||||||
|
def submit():
|
||||||
|
username = request.json.get('name')
|
||||||
|
password = request.json.get('email')
|
||||||
|
|
||||||
|
# 执行提交逻辑
|
||||||
|
print(username,password)
|
||||||
|
|
||||||
|
return jsonify({"code": 0, "msg": "恭喜,注册成功!"})
|
||||||
|
|
||||||
|
def start_flask():
|
||||||
|
app.run(debug=True, port=5000, use_reloader=False)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import threading
|
||||||
|
flask_thread = threading.Thread(target=start_flask)
|
||||||
|
flask_thread.daemon = True
|
||||||
|
flask_thread.start()
|
||||||
|
|
||||||
|
webview.create_window("demo","http://127.0.0.1:5000")
|
||||||
|
webview.start(debug=True)
|
23
amis-flask-pywebview-demo/cfg.json
Normal file
23
amis-flask-pywebview-demo/cfg.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
47744
amis-flask-pywebview-demo/web/helper.css
Normal file
47744
amis-flask-pywebview-demo/web/helper.css
Normal file
File diff suppressed because it is too large
Load Diff
2404
amis-flask-pywebview-demo/web/iconfont.css
Normal file
2404
amis-flask-pywebview-demo/web/iconfont.css
Normal file
File diff suppressed because one or more lines are too long
36
amis-flask-pywebview-demo/web/index.html
Normal file
36
amis-flask-pywebview-demo/web/index.html
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>AMIS 示例</title>
|
||||||
|
<link rel="stylesheet" href="sdk.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
|
||||||
|
<script src="sdk.js"></script>
|
||||||
|
<script>
|
||||||
|
async function fetchConfig() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/config');
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Network response was not ok ' + response.statusText);
|
||||||
|
}
|
||||||
|
const config = await response.json();
|
||||||
|
renderAmis(config);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Fetch error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderAmis(config) {
|
||||||
|
let amis = amisRequire('amis/embed');
|
||||||
|
amis.embed('#root', config);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取并渲染配置
|
||||||
|
fetchConfig();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
291
amis-flask-pywebview-demo/web/sdk.css
Normal file
291
amis-flask-pywebview-demo/web/sdk.css
Normal file
File diff suppressed because one or more lines are too long
3610
amis-flask-pywebview-demo/web/sdk.js
Normal file
3610
amis-flask-pywebview-demo/web/sdk.js
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user