Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 1 | // import React, { useEffect, useState } from 'react'; |
| 2 | // import { getExperience, updateExperience, checkUpgrade, upgradeUserLevel } from '../../api/level'; |
| 3 | // import LevelCard from '../../components/LevelCard'; |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 4 | |
Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 5 | // const user_id = 1; // 实际项目中请从用户上下文获取 |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 6 | |
Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 7 | // const LevelPage = () => { |
| 8 | // const [levelInfo, setLevelInfo] = useState(null); |
| 9 | // const [upgradeStatus, setUpgradeStatus] = useState(null); |
| 10 | // const [message, setMessage] = useState(''); |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 11 | |
Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 12 | // const fetchExperience = async () => { |
| 13 | // try { |
| 14 | // const res = await getExperience(user_id); |
| 15 | // setLevelInfo(res.data); |
| 16 | // } catch (error) { |
| 17 | // console.error(error); |
| 18 | // } |
| 19 | // }; |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 20 | |
Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 21 | // const handleUpdate = async () => { |
| 22 | // try { |
| 23 | // const res = await updateExperience({ user_id, experience: 50, source: '签到' }); |
| 24 | // setMessage(res.data.message || '经验更新成功'); |
| 25 | // fetchExperience(); |
| 26 | // } catch (error) { |
| 27 | // console.error(error); |
| 28 | // } |
| 29 | // }; |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 30 | |
Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 31 | // const handleCheckUpgrade = async () => { |
| 32 | // try { |
| 33 | // const res = await checkUpgrade(user_id); |
| 34 | // setUpgradeStatus(res.data); |
| 35 | // } catch (error) { |
| 36 | // console.error(error); |
| 37 | // } |
| 38 | // }; |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 39 | |
Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 40 | // const handleUpgrade = async () => { |
| 41 | // try { |
| 42 | // const res = await upgradeUserLevel({ user_id, can_upgrade: true }); |
| 43 | // setMessage(res.data.message || '升级成功'); |
| 44 | // fetchExperience(); |
| 45 | // } catch (error) { |
| 46 | // setMessage(error.response?.data?.message || '升级失败'); |
| 47 | // } |
| 48 | // }; |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 49 | |
Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 50 | // useEffect(() => { |
| 51 | // fetchExperience(); |
| 52 | // }, []); |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 53 | |
Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 54 | // return ( |
| 55 | // <div className="max-w-xl mx-auto p-4"> |
| 56 | // <h1 className="text-2xl font-bold mb-4">我的等级</h1> |
| 57 | // {levelInfo && ( |
| 58 | // <LevelCard |
| 59 | // level={levelInfo.level} |
| 60 | // current={levelInfo.current_experience} |
| 61 | // next={levelInfo.next_level_experience} |
| 62 | // /> |
| 63 | // )} |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 64 | |
Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 65 | // <div className="space-x-2 mb-4"> |
| 66 | // <button |
| 67 | // onClick={handleUpdate} |
| 68 | // className="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700" |
| 69 | // > |
| 70 | // 模拟签到加经验 |
| 71 | // </button> |
| 72 | // <button |
| 73 | // onClick={handleCheckUpgrade} |
| 74 | // className="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700" |
| 75 | // > |
| 76 | // 检查是否可升级 |
| 77 | // </button> |
| 78 | // </div> |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 79 | |
Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 80 | // {upgradeStatus && ( |
| 81 | // <div className="mb-4"> |
| 82 | // {upgradeStatus.can_upgrade ? ( |
| 83 | // <button |
| 84 | // onClick={handleUpgrade} |
| 85 | // className="px-4 py-2 bg-purple-600 text-white rounded hover:bg-purple-700" |
| 86 | // > |
| 87 | // 升级到下一级 |
| 88 | // </button> |
| 89 | // ) : ( |
| 90 | // <p className="text-gray-700">当前还不能升级。</p> |
| 91 | // )} |
| 92 | // </div> |
| 93 | // )} |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 94 | |
Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 95 | // {message && <div className="text-sm text-green-700 mt-2">{message}</div>} |
| 96 | // </div> |
| 97 | // ); |
| 98 | // }; |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 99 | |
Krishya | 73cd882 | 2025-06-07 15:48:41 +0800 | [diff] [blame] | 100 | // export default LevelPage; |