Selaa lähdekoodia

be 更新后端API

master
Chunxian Zhang 2 vuotta sitten
vanhempi
commit
4bc0d59c63
6 muutettua tiedostoa jossa 166 lisäystä ja 40 poistoa
  1. +0
    -0
      appTime/AppTime-Realease/data.db-journal
  2. +95
    -16
      lazy-timer-be/app.py
  3. +46
    -2
      lazy-timer-fe/package-lock.json
  4. +1
    -0
      lazy-timer-fe/package.json
  5. +17
    -16
      lazy-timer-fe/src/data/dummy.js
  6. +7
    -6
      lazy-timer-fe/src/pages/Ecommerce.jsx

+ 0
- 0
appTime/AppTime-Realease/data.db-journal Näytä tiedosto


+ 95
- 16
lazy-timer-be/app.py Näytä tiedosto

@ -1,23 +1,102 @@
# python对多文件编程及其不友好, 白写了这么多文件到处报错, 最后还是要写在一个文件里解决了
import os
import sys
from datetime import datetime # 处理时间
from flask import Flask
from markupsafe import escape # 字符串转义处理
from flask_cors import CORS, cross_origin
from flask_sqlalchemy import SQLAlchemy
# SQLite windows适配
WIN = sys.platform.startswith('win')
if WIN:
prefix = 'sqlite:///'
else:
prefix = 'sqlite:////'
app = Flask(__name__)
db = SQLAlchemy(app) # 初始化拓展, 传入程序实例 app
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
prefix = "sqlite:///"
path = '../appTime/AppTime-Realease/data.db'
app.config['SQLALCHEMY_DATABASE_URI'] = prefix + path
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
# 在扩展类实例化前加载配置
db = SQLAlchemy(app)
# 数据库模型
class App(db.Model):
id = db.Column(db.Integer, primary_key=True) # App id
process = db.Column(db.Text) # appName
text = db.Column(db.Text) # app窗口名称
tagId = db.Column(db.Integer, unique=True) # 标签id
class Period(db.Model):
timeStart = db.Column(db.DateTime, primary_key=True) # 开始时间
timeEnd = db.Column(db.DateTime) # 结束时间
winId = db.Column(db.Integer) # 活动id
class Tag(db.Model):
id = db.Column(db.Integer, primary_key=True) # 标签id
text = db.Column(db.Text) # 标签文本
class Win(db.Model):
id = db.Column(db.Integer, primary_key=True) # 活动id
appId = db.Column(db.Integer) # App id
text = db.Column(db.Text, nullable=True) # 活动窗口名称
tagId = db.Column(db.Integer, nullable=True) # 标签id
# 后端API
# 获取每日屏幕使用总时间
@app.route('/getDayScreenUseTime', methods=['GET'])
@cross_origin()
def getDayScreenUseTime():
datetimeStr = '2022-09-05'
struct_time = datetime.strptime(datetimeStr, "%Y-%m-%d").date() # 获取请求日期, struct_time数据类型为dateTime
activityTimeList = Period.query.all()
selectedTimeList = [] # 选中的对应今天日期的时间李彪
for time in activityTimeList:
if time.timeStart.date() == struct_time:
selectedTimeList.append(time)
timeAmount = 0
for time in selectedTimeList:
time_diff = time.timeEnd - time.timeStart
timeAmount = timeAmount + time_diff.total_seconds()
timeAmount = int(timeAmount)
m, s = divmod(timeAmount, 60)
h, m = divmod(m, 60)
return '{:d}小时{:02d}分{:02d}秒'.format(h, m, s)
# 获取每日第一次屏幕使用时刻
@app.route('/getFirstScreenTime', methods=['GET'])
@cross_origin()
def getFirstScreenTime():
datetimeStr = '2022-09-05'
struct_time = datetime.strptime(datetimeStr, "%Y-%m-%d").date() # 获取请求日期, struct_time数据类型为dateTime
activityTimeList = Period.query.all()
selectedTimeList = [] # 选中的对应今天日期的时间李彪
for time in activityTimeList:
if time.timeStart.date() == struct_time:
selectedTimeList.append(time)
break;
firstScreenTime = selectedTimeList[0].timeStart.strftime('%H点%M分%S秒')
return firstScreenTime
# 获取每日最后一次屏幕使用时刻
@app.route('/getLastScreenTime', methods=['GET'])
@cross_origin()
def getLastScreenTime():
datetimeStr = '2022-09-05'
struct_time = datetime.strptime(datetimeStr, "%Y-%m-%d").date() # 获取请求日期, struct_time数据类型为dateTime
activityTimeList = Period.query.all()
selectedTimeList = [] # 选中的对应今天日期的时间李彪
for time in activityTimeList:
if time.timeStart.date() == struct_time:
selectedTimeList.append(time)
@app.route('/')
def hello():
return 'Welcome to My Watchlist!'
lastScreenTime = selectedTimeList[-1].timeEnd.strftime('%H点%M分%S秒')
return lastScreenTime
@app.route('/user/<name>')
def user_page(name):
return f'User: {escape(name)}'
# 持续时间

+ 46
- 2
lazy-timer-fe/package-lock.json Näytä tiedosto

@ -1,11 +1,11 @@
{
"name": "project_syncfusion_dashboard",
"name": "lazy-timer-fe",
"version": "0.1.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "project_syncfusion_dashboard",
"name": "lazy-timer-fe",
"version": "0.1.0",
"dependencies": {
"@syncfusion/ej2": "^19.4.48",
@ -18,6 +18,7 @@
"@syncfusion/ej2-react-popups": "^19.4.52",
"@syncfusion/ej2-react-richtexteditor": "^19.4.50",
"@syncfusion/ej2-react-schedule": "^19.4.50",
"axios": "^0.27.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-icons": "^4.3.1",
@ -4896,6 +4897,28 @@
"node": ">=4"
}
},
"node_modules/axios": {
"version": "0.27.2",
"resolved": "https://registry.npmmirror.com/axios/-/axios-0.27.2.tgz",
"integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==",
"dependencies": {
"follow-redirects": "^1.14.9",
"form-data": "^4.0.0"
}
},
"node_modules/axios/node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmmirror.com/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/axobject-query": {
"version": "2.2.0",
"resolved": "https://registry.npmmirror.com/axobject-query/-/axobject-query-2.2.0.tgz",
@ -19693,6 +19716,27 @@
"resolved": "https://registry.npmmirror.com/axe-core/-/axe-core-4.4.3.tgz",
"integrity": "sha512-32+ub6kkdhhWick/UjvEwRchgoetXqTK14INLqbGm5U2TzBkBNF3nQtLYm8ovxSkQWArjEQvftCKryjZaATu3w=="
},
"axios": {
"version": "0.27.2",
"resolved": "https://registry.npmmirror.com/axios/-/axios-0.27.2.tgz",
"integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==",
"requires": {
"follow-redirects": "^1.14.9",
"form-data": "^4.0.0"
},
"dependencies": {
"form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmmirror.com/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
}
}
},
"axobject-query": {
"version": "2.2.0",
"resolved": "https://registry.npmmirror.com/axobject-query/-/axobject-query-2.2.0.tgz",

+ 1
- 0
lazy-timer-fe/package.json Näytä tiedosto

@ -13,6 +13,7 @@
"@syncfusion/ej2-react-popups": "^19.4.52",
"@syncfusion/ej2-react-richtexteditor": "^19.4.50",
"@syncfusion/ej2-react-schedule": "^19.4.50",
"axios": "^0.27.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-icons": "^4.3.1",

+ 17
- 16
lazy-timer-fe/src/data/dummy.js Näytä tiedosto

@ -1,11 +1,12 @@
import React from 'react';
import { AiOutlineCalendar, AiOutlineShoppingCart, AiOutlineAreaChart, AiOutlineBarChart, AiOutlineStock } from 'react-icons/ai';
import { FiShoppingBag, FiEdit, FiPieChart, FiBarChart, FiCreditCard, FiStar, FiShoppingCart } from 'react-icons/fi';
import { BsKanban, BsBarChart, BsBoxSeam, BsCurrencyDollar, BsShield, BsChatLeft } from 'react-icons/bs';
import { BsKanban, BsBarChart, BsCurrencyDollar, BsShield, BsChatLeft, BsFillLaptopFill } from 'react-icons/bs';
import { FaSortAmountDown } from 'react-icons/fa'
import { BiColorFill } from 'react-icons/bi';
import { IoMdContacts } from 'react-icons/io';
import { RiContactsLine, RiStockLine } from 'react-icons/ri';
import { MdOutlineSupervisorAccount } from 'react-icons/md';
import { MdWbSunny, MdBedtime } from 'react-icons/md';
import { HiOutlineRefresh } from 'react-icons/hi';
import { TiTick } from 'react-icons/ti';
import { GiLouvrePyramid } from 'react-icons/gi';
@ -630,38 +631,38 @@ export const chatData = [
export const earningData = [
{
icon: <MdOutlineSupervisorAccount />,
amount: '39,354',
icon: <MdWbSunny />,
amount: '这里填写时间',
percentage: '-4%',
title: 'Customers',
title: '第一次屏幕使用',
iconColor: '#03C9D7',
iconBg: '#E5FAFB',
pcColor: 'red-600',
},
{
icon: <BsBoxSeam />,
amount: '4,396',
icon: <MdBedtime />,
amount: '这里填写时间',
percentage: '+23%',
title: 'Products',
title: '最后一次屏幕使用',
iconColor: 'rgb(255, 244, 229)',
iconBg: 'rgb(254, 201, 15)',
pcColor: 'green-600',
iconBg: 'rgb(0,0,0)',
pcColor: 'black-600',
},
{
icon: <FiBarChart />,
amount: '423,39',
icon: <BsFillLaptopFill />,
amount: '这里填写时间',
percentage: '+38%',
title: 'Sales',
title: '今日屏幕使用时间',
iconColor: 'rgb(228, 106, 118)',
iconBg: 'rgb(255, 244, 229)',
pcColor: 'green-600',
},
{
icon: <HiOutlineRefresh />,
amount: '39,354',
icon: <FaSortAmountDown />,
amount: '这里填写时间',
percentage: '-12%',
title: 'Refunds',
title: '总计',
iconColor: 'rgb(0, 194, 146)',
iconBg: 'rgb(235, 250, 242)',
pcColor: 'red-600',

+ 7
- 6
lazy-timer-fe/src/pages/Ecommerce.jsx Näytä tiedosto

@ -1,5 +1,6 @@
import React from 'react';
import { BsCurrencyDollar } from 'react-icons/bs';
import { BsFillLaptopFill } from 'react-icons/bs';
import { AiFillCalendar } from 'react-icons/ai';
import { GoPrimitiveDot } from 'react-icons/go';
import { IoIosMore } from 'react-icons/io';
import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';
@ -25,8 +26,8 @@ const Ecommerce = () => {
<div className="bg-white dark:text-gray-200 dark:bg-secondary-dark-bg h-44 rounded-xl w-full lg:w-80 p-8 pt-9 m-3 bg-hero-pattern bg-no-repeat bg-cover bg-center">
<div className="flex justify-between items-center">
<div>
<p className="font-bold text-gray-400">Earnings</p>
<p className="text-2xl">$63,448.78</p>
<p className="font-bold text-gray-400">日期</p>
<p className="text-2xl">2022年9月5日</p>
</div>
@ -36,7 +37,7 @@ const Ecommerce = () => {
style={{ backgroundColor: currentColor }}
className="text-2xl opacity-0.9 text-white hover:drop-shadow-xl rounded-full p-4"
>
<BsCurrencyDollar />
<AiFillCalendar />
</button>
@ -45,7 +46,7 @@ const Ecommerce = () => {
<Button
color="white"
bgColor={currentColor}
text="Download"
text="选择日期"
borderRadius="10px"
/>
</div>
@ -63,7 +64,7 @@ const Ecommerce = () => {
<p className="mt-3">
<span className="text-lg font-semibold">{item.amount}</span>
<span className={`text-sm text-${item.pcColor} ml-2`}>
{item.percentage}
{/* {item.percentage} */}
</span>
</p>
<p className="text-sm text-gray-400 mt-1">{item.title}</p>

Ladataan…
Peruuta
Tallenna