add pywebview demo

This commit is contained in:
murmur 2024-07-03 22:09:45 +08:00
parent b1e4383afe
commit 27bbd133be
7 changed files with 54147 additions and 0 deletions

View 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)

View 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"
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View 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>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long