Skip to content

Commit

Permalink
UI optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Moujuruo committed Jun 28, 2024
1 parent cd624b9 commit 6a110fc
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 60 deletions.
Binary file modified Ai_work.db
Binary file not shown.
29 changes: 27 additions & 2 deletions backend/run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,40 @@ def deleteReservation():
for member_id in member_ids:
if int(member_id[0]) != int(user_id):
result2 = Team.insertMeetingRoomReservation(room_id, member_id[0], user_id, start_time, end_time, date, subject, team_id, 1)
print(result2)
# print(result2)
activity_name = "会议 - " + room_name + " - " + subject
result3 = DBUtil.deleteActivityByActivityName(activity_name, date)
print(result3)

if result == False:
return jsonify({'code': 1, 'message': '删除会议室预约失败', 'status': 500 })
return jsonify({'code': 0, 'message': '删除会议室预约成功', 'status': 200 }), 200


# getReservationInfo
@app.route(apiPrefix + 'getReservationInfo', methods=['POST'])
def getReservationInfo():
data = request.get_json()
user_id = data.get('userID')
reservations = Team.getMeetingRoomReservation(user_id)
if reservations is None:
return jsonify({'code': 1, 'message': '获取会议室预约列表失败', 'status': 500 })
# room_id, room_name, user_id, reserve_user_id, reserve_user_name, start_time, end_time, date, subject, team_id, team_name, type
keys = ['id', 'room_id', 'room_name', 'user_id', 'reserve_user_id', 'reserve_user_name', 'start_time', 'end_time', 'date', 'subject', 'team_id', 'team_name', 'type']
reservations_list = [dict(zip(keys, reservation)) for reservation in reservations]
return jsonify({'code': 0, 'message': '获取会议室预约列表成功', 'status': 200, 'data': reservations_list}), 200

# acceptReservation
@app.route(apiPrefix + 'acceptReservation', methods=['POST'])
def acceptReservation():
data = request.get_json()
user_id = data.get('userID')
reservation_id = data.get('reservation_id')
type = data.get('type')
result = Team.deleteMeetingRoomReservation(reservation_id, user_id, type)
if result == False:
return jsonify({'code': 1, 'message': '已读失败', 'status': 500 })
return jsonify({'code': 0, 'message': '已读成功', 'status': 200 }), 200


@app.route(apiPrefix + 'getUserReservations', methods=['POST'])
def getUserReservations():
Expand Down
24 changes: 24 additions & 0 deletions backend/sqlite_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,30 @@ def insertMeetingRoomReservation(room_id, user_id, reserve_user_id, start_time,
finally:
lock_threading.release()

def getMeetingRoomReservation(user_id):
try:
lock_threading.acquire()
cursor.execute('''SELECT * FROM meeting_room_reservation WHERE user_id = ?''', (user_id,))
return cursor.fetchall()
except sqlite3.Error as e:
print(e)
return False
finally:
lock_threading.release()

def deleteMeetingRoomReservation(reservation_id, user_id, type):
try:
lock_threading.acquire()
print(reservation_id, user_id, type)
cursor.execute('''DELETE FROM meeting_room_reservation WHERE id = ? AND user_id = ? AND type = ?''', (reservation_id, user_id, type))
conn.commit()
return True
except sqlite3.Error as e:
print(e)
return False
finally:
lock_threading.release()


def insertTeam(team_name, captain_id):
try:
Expand Down
189 changes: 156 additions & 33 deletions frontend/src/pages/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ interface inviteinfo {
user_id: number
}

interface reservationinfo {
id: number,
room_id: number,
room_name: string,
reserve_user_id: number,
reserve_user_name: string,
team_id: number,
team_name: string,
date: string,
start_time: string,
end_time: string,
type: number,
}


const MainLayout: React.FC = () => {
Expand All @@ -28,6 +41,7 @@ const MainLayout: React.FC = () => {
const [api, contextHolder] = notification.useNotification();
// let invitations: inviteinfo[] = [];
const [invitations, setInvitations] = useState<inviteinfo[]>([]);
const [reservations, setReservations] = useState<reservationinfo[]>([]);

useEffect(() => {
const avatar = localStorage.getItem('avatarUrl');
Expand All @@ -38,6 +52,7 @@ const MainLayout: React.FC = () => {

useEffect(() => {
checkInvitations();
checkMeetings();
}, []);

const logout = () => {
Expand Down Expand Up @@ -86,6 +101,93 @@ const MainLayout: React.FC = () => {
}
};

// 类似的,展示会议室预定通知,按钮变为已读和忽略,根据type区别,0为通知有会议,1为会议预定取消
const checkMeetings = async () => {
try {
const response = await HttpUtil.post(ApiUtil.API_GET_RESERVATION_INFO, { userID: userID }) as ApiResponse<reservationinfo[]>;
console.log('response:', response);
if (response.status === 200) {
console.log('reservations1:', reservations);

const newreservations = response.data;
setReservations(newreservations);

if (newreservations.length > 0) {
console.log('reservations:', newreservations);
newreservations.forEach((reservation: any) => {
const { id, room_id, room_name, reserve_user_id, reserve_user_name, team_id, team_name, date, start_time, end_time, type } = reservation;
const key = `reservation-${id}`;
if (type === 0)
api.open({
message: '会议室预定通知',
description: `团队 ${team_name}${date} ${start_time} - ${end_time}${room_name} 预定了会议, 请注意查看`,
btn: (
<div>
<Button type='primary' onClick={() => acceptMeeting(id, type, key)}>已读</Button>
<Button onClick={() => {
api.destroy(key);
}} style={{ marginLeft: '8px' }}>忽略</Button>
</div>
),
key,
duration: 10,
showProgress: true,
onClose: () => api.destroy(key),
});
else
api.open({
message: '会议室预定通知',
description: `团队 ${team_name}${date} ${start_time} - ${end_time}${room_name} 取消了会议, 请注意查看`,
btn: (
<div>
<Button type='primary' onClick={() => acceptMeeting(id, type, key)}>已读</Button>
<Button onClick={() => {
api.destroy(key);
}} style={{ marginLeft: '8px' }}>忽略</Button>
</div>
),
key,
duration: 10,
showProgress: true,
onClose: () => api.destroy(key),
});
});
}
} else
console.log('获取会议室预定通知失败');
} catch (error) {
console.error('获取会议室预定通知失败:', error);
}
}

const acceptMeeting = async (reservation_id: number, type: number, notificationKey: string) => {
try {
const response = await HttpUtil.post(ApiUtil.API_ACCEPT_RESERVATION, { reservation_id: reservation_id, userID: userID, type: type}) as ApiResponse<string>;
if (response.status === 200) {
api.success({
message: '已读成功',
description: '已成功标记为已读',
});
if (notificationKey !== '')
api.destroy(notificationKey); // Destroy the notification
setReservations(reservations.filter(reservation => reservation.id !== reservation_id));
} else {
api.error({
message: '已读失败',
description: response.data,
});
}
} catch (error) {
console.error('已读失败:', error);
api.error({
message: '已读失败',
description: '发生未知错误',
});
}
};



const acceptInvitation = async (teamId: number, captainId: number, notificationKey: string) => {
try {
const response = await HttpUtil.post(ApiUtil.API_ACCEPT_INVITATION, { userID: userID, teamID: teamId }) as ApiResponse<string>;
Expand Down Expand Up @@ -290,44 +392,65 @@ const MainLayout: React.FC = () => {
<div style={{ display: "flex", alignItems: "center" }}>
<Dropdown
menu={{
items: invitations.length === 0
items: [
...invitations.length === 0 && reservations.length === 0
? [{ key: 'empty', label: '暂无通知' }]
: invitations.map((invitation) => ({
key: invitation.team_id,
label: (
<div>
团队 {invitation.team_id} 的邀请
<Button
type="link"
onClick={() =>
acceptInvitation(
invitation.team_id,
invitation.captain_id,
''
)
}
>
接受
</Button>
<Button
type="link"
onClick={() =>
rejectInvitation(
invitation.team_id,
invitation.captain_id,
''
)
}
>
拒绝
</Button>
</div>
<div>
团队 {invitation.team_id} 的邀请
<Button
type="link"
onClick={() =>
acceptInvitation(
invitation.team_id,
invitation.captain_id,
''
)
}
>
接受
</Button>
<Button
type="link"
onClick={() =>
rejectInvitation(
invitation.team_id,
invitation.captain_id,
''
)
}
>
拒绝
</Button>
</div>
),
})),
}}
trigger={['click']}
>
<Badge count={invitations.length} offset={[-25, -2]} size='small'>
})),
...reservations.map((reservation: any) => {
const { id, room_id, room_name, reserve_user_id, reserve_user_name, team_id, team_name, date, start_time, end_time, type } = reservation;
const key = `reservation-${id}`;
const message = type === 0 ? '会议室预定通知' : '会议室取消通知';
const description = type === 0
? `团队 ${team_name}${date} ${start_time} - ${end_time}${room_name} 预定了会议, 请注意查看`
: `团队 ${team_name}${date} ${start_time} - ${end_time}${room_name} 取消了会议, 请注意查看`;
return {
key,
label: (
<div>
{message}
<div>{description}</div>
<Button type='primary' onClick={() => acceptMeeting(id, type, key)}>已读</Button>
<Button onClick={() => api.destroy(key)} style={{ marginLeft: '8px' }}>忽略</Button>
</div>
),
};
}),
],
}}
trigger={['click']}
>
<Badge count={invitations.length + reservations.length} offset={[-25, -2]} size='small'>
<BellOutlined
style={{ fontSize: "24px", marginRight: "25px", cursor: "pointer" }}
/>
Expand Down
Loading

0 comments on commit 6a110fc

Please sign in to comment.