2024-07-03 14:09:45 +00:00
|
|
|
from flask import Flask, jsonify, render_template,request
|
|
|
|
import json
|
|
|
|
import webview
|
|
|
|
|
2024-07-03 14:18:03 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2024-07-03 14:09:45 +00:00
|
|
|
|
2024-07-03 14:18:03 +00:00
|
|
|
def resource_path(relative_path):
|
|
|
|
""" Get absolute path to resource, works for dev and for PyInstaller """
|
|
|
|
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
return os.path.join(base_path, relative_path)
|
|
|
|
|
|
|
|
app = Flask(__name__, static_folder=resource_path('web'), static_url_path='')
|
2024-07-03 14:09:45 +00:00
|
|
|
|
|
|
|
@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)
|