Skip to content

Commit 659c720

Browse files
committed
[feat] 增加前端代码
1 parent 261d43c commit 659c720

File tree

6 files changed

+92
-28
lines changed

6 files changed

+92
-28
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vscode/
2+
.idea/
23

34
# Byte-compiled / optimized / DLL files
45
__pycache__/

index.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
from flask import Flask, render_template, request
1+
from flask import Flask, render_template, request, send_from_directory
22
from os.path import dirname, abspath, join
33
from json import loads, dumps
4-
import random
4+
import os
55
from core import search
6-
import requests
76
import urllib3
87

98
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
109

1110
app = Flask(__name__)
11+
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600 # 缓存时间为1小时
12+
app.config['STATIC_FOLDER'] = os.path.join(
13+
os.path.dirname(os.path.abspath(__file__)), 'static')
1214

13-
14-
@app.route('/')
15-
def home():
16-
return render_template('index.html')
15+
@app.route('/<path:filename>')
16+
def static_files(filename):
17+
return send_from_directory(app.config['STATIC_FOLDER'], filename)
1718

1819

1920
@app.route('/s', methods=['GET'])
@@ -38,4 +39,4 @@ def about():
3839

3940
if __name__ == '__main__':
4041
app.config['JSON_AS_ASCII'] = False
41-
app.run(host='127.0.0.1', port=2333)
42+
app.run(host='127.0.0.1', port=2333)

static/app.css

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
body,
2+
:root,
3+
html {
4+
display: flex;
5+
flex-direction: column;
6+
align-items: center;
7+
justify-content: center;
8+
height: 100%;
9+
margin: 0;
10+
width: 100%;
11+
}
12+
13+
.title {
14+
font-size: 50px;
15+
font-weight: 400;
16+
}
17+
18+
.form {
19+
display: flex;
20+
flex-direction: column;
21+
align-items: center;
22+
width: calc(100% - 30px);
23+
;
24+
max-width: 768px;
25+
margin: 15px;
26+
}
27+
28+
.q-input {
29+
border: none;
30+
border-bottom: 3px solid #38b6ff;
31+
padding: 10px;
32+
outline: none;
33+
width: 100%;
34+
margin: 20px;
35+
box-sizing: border-box;
36+
}
37+
38+
.submit {
39+
outline: none;
40+
border: 0;
41+
background-color: #38b6ff;
42+
color: #fff;
43+
padding: 10px;
44+
margin: 20px;
45+
}

static/app.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function search() {
2+
var search = document.getElementById("search").value;
3+
var searchEngine = document.getElementsByName("SearchE")[0].checked ? "bing" : "google" ;
4+
fetch("/s", {
5+
headers: {
6+
"Content-Type": "application/json"
7+
},
8+
body: JSON.stringify({ search: search, searchEngine: searchEngine })
9+
}).then(response => response.json()).then(data => {
10+
console.log(data);
11+
});
12+
}

static/index.html

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Plug</title>
8+
<link rel="stylesheet" href="/app.css">
9+
<script src="/app.js"></script>
10+
</head>
11+
12+
<body>
13+
<h1 class="title">Plug</h1>
14+
<div class="form">
15+
<input placeholder="Name of the Plugin, Chinese or English" name="q" class="q-input" id="search">
16+
<br>
17+
<span class="select">
18+
<input type="radio" name="SearchE" value="bing" checked> Bing
19+
<input type="radio" name="SearchE" value="google"> Google
20+
</span>
21+
<button type="button" class="submit" onclick="search()">Search</button>
22+
</div>
23+
</body>
24+
25+
</html>

templates/index.html

-20
This file was deleted.

0 commit comments

Comments
 (0)