fix: update API endpoint for user login and adjust authentication logic in App component; modify rating display in MediaItem component

This commit is contained in:
ethan.chen
2025-06-13 14:32:34 +08:00
parent 35e0df26fe
commit 3c346021e3
4 changed files with 10 additions and 9 deletions

View File

@@ -120,12 +120,15 @@
try { try {
// 保存认证信息 // 保存认证信息
const auth = btoa(`${username}:${password}`); const auth = btoa(`${username}:${password}`);
localStorage.setItem('auth', auth);
// 使用验证接口验证登录 // 使用验证接口验证登录
const response = await request.get<ApiResponse<{username: string}>>('/auth/verify'); const response = await request.post<ApiResponse<{token: string}>>('/user/login', {
username,
password
});
if (response.data.code === 0) { if (response.data.code === 200) {
localStorage.setItem('auth', response.data.data.token);
isAuthenticated = true; isAuthenticated = true;
error = ''; error = '';
// 获取初始数据 // 获取初始数据

View File

@@ -41,7 +41,7 @@
<div class="space-y-2 text-sm text-gray-600 flex justify-between"> <div class="space-y-2 text-sm text-gray-600 flex justify-between">
<p class="flex items-center gap-2"> <p class="flex items-center gap-2">
<span class="text-gray-500">评分:</span> <span class="text-gray-500">评分:</span>
<span class="flex items-center gap-1">{@html StarRating(media.rating ?? 0)}</span> <span class="flex items-center gap-1">{@html StarRating((media.rating ?? 0) / 2)}</span>
</p> </p>
<p class="flex items-center gap-2"> <p class="flex items-center gap-2">
<span class="text-gray-500">日期:</span> <span class="text-gray-500">日期:</span>

View File

@@ -1,16 +1,14 @@
/* /*
* @Date: 2025-05-26 17:39:36 * @Date: 2025-05-26 17:39:36
* @LastEditors: 陈子健 * @LastEditors: 陈子健
* @LastEditTime: 2025-05-29 11:03:14 * @LastEditTime: 2025-06-13 14:32:26
* @FilePath: /my-score/frontend/src/lib/utils.ts * @FilePath: /my-score/frontend/src/lib/utils.ts
*/ */
export const StarRating = (rating: number, maxStars: number = 5) => { export const StarRating = (rating: number, maxStars: number = 5) => {
const stars = []; const stars = [];
for (let i = 1; i <= maxStars; i++) { for (let i = 1; i <= maxStars; i++) {
const fill = i <= Math.floor(rating) ? '#FFD700' : 'white'; const fill = i <= Math.floor(rating) ? '#FFD700' : 'white';
const isHalfStar = i - 0.5 <= rating && rating < i; const isHalfStar = i - 0.5 <= rating && rating < i;
if (isHalfStar) { if (isHalfStar) {
console.log('isHalfStar', isHalfStar); console.log('isHalfStar', isHalfStar);
stars.push(` stars.push(`

View File

@@ -1,7 +1,7 @@
/* /*
* @Date: 2025-05-20 17:59:45 * @Date: 2025-05-20 17:59:45
* @LastEditors: 陈子健 * @LastEditors: 陈子健
* @LastEditTime: 2025-05-20 18:04:34 * @LastEditTime: 2025-06-13 14:07:41
* @FilePath: /my-score/frontend/vite.config.ts * @FilePath: /my-score/frontend/vite.config.ts
*/ */
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
@@ -13,7 +13,7 @@ export default defineConfig({
server: { server: {
proxy: { proxy: {
'/api': { '/api': {
target: 'http://127.0.0.1:5000', target: 'http://127.0.0.1:8000',
changeOrigin: true, changeOrigin: true,
secure: false secure: false
} }