前后端登录注册连接成功
Change-Id: Ib5f9282fe7217b3363e542ce5c4e1c0d32619dcb
diff --git a/src/App.vue b/src/App.vue
index cfa631b..787103e 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,36 +1,36 @@
-<template>
- <div id="app">
- <router-view />
- </div>
-</template>
-
-<script>
-export default {
- name: 'App'
-}
-</script>
-
-<style>
-#app {
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- margin: 0;
- padding: 0;
- height: 100vh;
- width: 100%;
-}
-
-* {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
-}
-
-body {
- margin: 0;
- padding: 0;
- height: 100vh;
- overflow-x: hidden;
-}
-</style>
+<template>
+ <div id="app">
+ <router-view />
+ </div>
+</template>
+
+<script>
+export default {
+ name: 'App'
+}
+</script>
+
+<style>
+#app {
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+ margin: 0;
+ padding: 0;
+ height: 100vh;
+ width: 100%;
+}
+
+* {
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+}
+
+body {
+ margin: 0;
+ padding: 0;
+ height: 100vh;
+ overflow-x: hidden;
+}
+</style>
diff --git a/src/api/auth.js b/src/api/auth.js
new file mode 100644
index 0000000..a3c672a
--- /dev/null
+++ b/src/api/auth.js
@@ -0,0 +1,62 @@
+import request from './request'
+
+export const authApi = {
+ /**
+ * 用户登录
+ */
+ async login(loginData) {
+ console.log('📤 发送登录数据:', loginData)
+
+ const requestData = {
+ user: loginData.user,
+ password: loginData.password
+ }
+
+ return request({
+ url: '/api/auth/login', // 需要 /api 前缀
+ method: 'post',
+ data: requestData
+ })
+ },
+
+ /**
+ * 用户注册
+ */
+ async register(registerData) {
+ console.log('📤 发送注册数据:', registerData)
+
+ const requestData = {
+ username: registerData.username,
+ email: registerData.email,
+ password: registerData.password
+ }
+
+ return request({
+ url: '/api/auth/register', // 需要 /api 前缀
+ method: 'post',
+ data: requestData
+ })
+ },
+
+ /**
+ * 用户登出
+ */
+ logout() {
+ return request({
+ url: '/api/auth/logout', // 需要 /api 前缀
+ method: 'post'
+ })
+ },
+
+ /**
+ * 获取登录状态
+ */
+ getStatus() {
+ return request({
+ url: '/api/auth/status', // 需要 /api 前缀
+ method: 'get'
+ })
+ }
+}
+
+export default authApi
\ No newline at end of file
diff --git a/src/api/index.js b/src/api/index.js
new file mode 100644
index 0000000..6a72540
--- /dev/null
+++ b/src/api/index.js
@@ -0,0 +1,219 @@
+export { authApi } from './auth'
+export { userApi } from './user'
+
+// 默认导出request实例,方便其他地方使用
+export { default as request } from './request'
+
+// ===========================================
+
+// src/store/modules/auth.js - 认证状态管理
+import { authApi } from '@/api/auth'
+import { ElMessage } from 'element-plus'
+
+const state = {
+ // 登录状态
+ isLoggedIn: false,
+ // 用户信息
+ userInfo: null,
+ // Token信息
+ token: null,
+ // 登录加载状态
+ loginLoading: false
+}
+
+const getters = {
+ // 是否已登录
+ isAuthenticated: state => state.isLoggedIn,
+ // 获取用户信息
+ userInfo: state => state.userInfo,
+ // 获取用户名
+ username: state => state.userInfo?.user?.username || '',
+ // 获取用户头像
+ avatar: state => state.userInfo?.user?.avatar || '',
+ // 获取用户组信息
+ userGroup: state => state.userInfo?.user?.group || null,
+ // 登录加载状态
+ loginLoading: state => state.loginLoading
+}
+
+const mutations = {
+ // 设置登录状态
+ SET_LOGIN_STATUS(state, status) {
+ state.isLoggedIn = status
+ },
+
+ // 设置用户信息
+ SET_USER_INFO(state, userInfo) {
+ state.userInfo = userInfo
+ },
+
+ // 设置Token
+ SET_TOKEN(state, token) {
+ state.token = token
+ },
+
+ // 设置登录加载状态
+ SET_LOGIN_LOADING(state, loading) {
+ state.loginLoading = loading
+ },
+
+ // 清除用户数据
+ CLEAR_USER_DATA(state) {
+ state.isLoggedIn = false
+ state.userInfo = null
+ state.token = null
+ state.loginLoading = false
+ }
+}
+
+const actions = {
+ // 用户登录
+ async login({ commit }, loginData) {
+ try {
+ commit('SET_LOGIN_LOADING', true)
+
+ const response = await authApi.login(loginData)
+
+ if (response) {
+ // 保存Token
+ const tokenInfo = response.token
+ if (tokenInfo && tokenInfo.tokenValue) {
+ localStorage.setItem('token', tokenInfo.tokenValue)
+ localStorage.setItem('tokenInfo', JSON.stringify(tokenInfo))
+ commit('SET_TOKEN', tokenInfo)
+ }
+
+ // 保存用户信息
+ localStorage.setItem('userInfo', JSON.stringify(response))
+ localStorage.setItem('isLoggedIn', 'true')
+
+ commit('SET_USER_INFO', response)
+ commit('SET_LOGIN_STATUS', true)
+
+ ElMessage.success('登录成功!')
+ return response
+ }
+ } catch (error) {
+ console.error('登录失败:', error)
+ throw error
+ } finally {
+ commit('SET_LOGIN_LOADING', false)
+ }
+ },
+
+ // 用户注册
+ async register({ commit }, registerData) {
+ try {
+ commit('SET_LOGIN_LOADING', true)
+
+ const response = await authApi.register(registerData)
+
+ if (response) {
+ // 注册成功后自动登录
+ const tokenInfo = response.token
+ if (tokenInfo && tokenInfo.tokenValue) {
+ localStorage.setItem('token', tokenInfo.tokenValue)
+ localStorage.setItem('tokenInfo', JSON.stringify(tokenInfo))
+ commit('SET_TOKEN', tokenInfo)
+ }
+
+ localStorage.setItem('userInfo', JSON.stringify(response))
+ localStorage.setItem('isLoggedIn', 'true')
+
+ commit('SET_USER_INFO', response)
+ commit('SET_LOGIN_STATUS', true)
+
+ ElMessage.success('注册成功!')
+ return response
+ }
+ } catch (error) {
+ console.error('注册失败:', error)
+ throw error
+ } finally {
+ commit('SET_LOGIN_LOADING', false)
+ }
+ },
+
+ // 用户登出
+ async logout({ commit }) {
+ try {
+ await authApi.logout()
+ } catch (error) {
+ console.error('登出请求失败:', error)
+ // 即使登出请求失败,也要清除本地数据
+ } finally {
+ // 清除本地存储
+ localStorage.removeItem('token')
+ localStorage.removeItem('tokenInfo')
+ localStorage.removeItem('userInfo')
+ localStorage.removeItem('isLoggedIn')
+
+ // 清除状态
+ commit('CLEAR_USER_DATA')
+
+ ElMessage.success('已退出登录')
+ }
+ },
+
+ // 检查登录状态
+ async checkLoginStatus({ commit }) {
+ try {
+ const response = await authApi.getStatus()
+
+ if (response && response.isLoggedIn && response.user) {
+ // 更新用户信息
+ localStorage.setItem('userInfo', JSON.stringify(response.user))
+ localStorage.setItem('isLoggedIn', 'true')
+
+ commit('SET_USER_INFO', response.user)
+ commit('SET_LOGIN_STATUS', true)
+
+ return true
+ } else {
+ // 登录状态无效,清除本地数据
+ commit('CLEAR_USER_DATA')
+ localStorage.removeItem('token')
+ localStorage.removeItem('tokenInfo')
+ localStorage.removeItem('userInfo')
+ localStorage.removeItem('isLoggedIn')
+
+ return false
+ }
+ } catch (error) {
+ console.error('检查登录状态失败:', error)
+ commit('CLEAR_USER_DATA')
+ return false
+ }
+ },
+
+ // 从本地存储恢复登录状态
+ restoreLoginState({ commit }) {
+ const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true'
+ const userInfo = localStorage.getItem('userInfo')
+ const tokenInfo = localStorage.getItem('tokenInfo')
+
+ if (isLoggedIn && userInfo) {
+ try {
+ const parsedUserInfo = JSON.parse(userInfo)
+ const parsedTokenInfo = tokenInfo ? JSON.parse(tokenInfo) : null
+
+ commit('SET_USER_INFO', parsedUserInfo)
+ commit('SET_TOKEN', parsedTokenInfo)
+ commit('SET_LOGIN_STATUS', true)
+
+ console.log('✅ 已从本地存储恢复登录状态')
+ } catch (error) {
+ console.error('❌ 恢复登录状态失败:', error)
+ commit('CLEAR_USER_DATA')
+ }
+ }
+ }
+}
+
+export default {
+ namespaced: true,
+ state,
+ getters,
+ mutations,
+ actions
+}
\ No newline at end of file
diff --git a/src/api/request.js b/src/api/request.js
new file mode 100644
index 0000000..dd5aade
--- /dev/null
+++ b/src/api/request.js
@@ -0,0 +1,76 @@
+import axios from 'axios'
+import { ElMessage } from 'element-plus'
+import router from '@/router'
+
+const request = axios.create({
+ // 关键:不要设置baseURL,或者设置为空字符串
+ // 这样请求会发送到当前域名(8080),然后被代理转发到8081
+ baseURL: '',
+ timeout: 10000,
+ headers: {
+ 'Content-Type': 'application/json'
+ }
+})
+
+request.interceptors.request.use(
+ config => {
+ const token = localStorage.getItem('token')
+ if (token) {
+ config.headers.Authorization = `Bearer ${token}`
+ }
+
+ console.log('🚀 发送请求:', config.method?.toUpperCase(), config.url)
+ console.log('📤 请求数据:', config.data)
+
+ return config
+ },
+ error => {
+ console.error('❌ 请求错误:', error)
+ return Promise.reject(error)
+ }
+)
+
+request.interceptors.response.use(
+ response => {
+ console.log('✅ 响应成功:', response.status, response.data)
+ return response.data
+ },
+ error => {
+ console.error('❌ 响应错误:', error)
+
+ if (error.response) {
+ const { status, data } = error.response
+
+ switch (status) {
+ case 401:
+ localStorage.removeItem('token')
+ localStorage.removeItem('isLoggedIn')
+ localStorage.removeItem('userInfo')
+ ElMessage.error('登录已过期,请重新登录')
+ router.push('/login')
+ break
+ case 403:
+ ElMessage.error('权限不足')
+ break
+ case 404:
+ ElMessage.error('API接口不存在')
+ console.error('❌ 请求的URL:', error.config.url)
+ break
+ case 500:
+ ElMessage.error('服务器内部错误')
+ break
+ default:
+ const errorMessage = data?.message || `请求失败 (${status})`
+ ElMessage.error(errorMessage)
+ }
+ } else if (error.request) {
+ ElMessage.error('无法连接到服务器,请检查网络')
+ } else {
+ ElMessage.error('请求配置错误')
+ }
+
+ return Promise.reject(error)
+ }
+)
+
+export default request
\ No newline at end of file
diff --git a/src/api/user.js b/src/api/user.js
new file mode 100644
index 0000000..2cfb40c
--- /dev/null
+++ b/src/api/user.js
@@ -0,0 +1,115 @@
+import request from './request'
+
+export const userApi = {
+ /**
+ * 获取当前用户信息
+ * @returns {Promise<Object>} 用户信息
+ */
+ getCurrentUser() {
+ return request({
+ url: '/user/profile',
+ method: 'get'
+ })
+ },
+
+ /**
+ * 更新用户资料
+ * @param {Object} profileData - 用户资料数据
+ * @returns {Promise<Object>} 更新响应
+ */
+ updateProfile(profileData) {
+ return request({
+ url: '/user/profile',
+ method: 'put',
+ data: profileData
+ })
+ },
+
+ /**
+ * 修改密码
+ * @param {Object} passwordData - 密码数据
+ * @param {string} passwordData.currentPassword - 当前密码
+ * @param {string} passwordData.newPassword - 新密码
+ * @returns {Promise<Object>} 修改响应
+ */
+ changePassword(passwordData) {
+ return request({
+ url: '/user/password',
+ method: 'put',
+ data: passwordData
+ })
+ },
+
+ /**
+ * 上传头像
+ * @param {FormData} formData - 包含头像文件的FormData
+ * @returns {Promise<Object>} 上传响应
+ */
+ uploadAvatar(formData) {
+ return request({
+ url: '/user/avatar',
+ method: 'post',
+ data: formData,
+ headers: {
+ 'Content-Type': 'multipart/form-data'
+ }
+ })
+ },
+
+ /**
+ * 获取用户统计信息
+ * @returns {Promise<Object>} 统计信息
+ */
+ getUserStats() {
+ return request({
+ url: '/user/stats',
+ method: 'get'
+ })
+ },
+
+ /**
+ * 获取用户活动记录
+ * @param {Object} params - 查询参数
+ * @param {string} params.type - 活动类型
+ * @param {number} params.page - 页码
+ * @param {number} params.size - 每页大小
+ * @returns {Promise<Object>} 活动记录
+ */
+ getUserActivities(params = {}) {
+ return request({
+ url: '/user/activities',
+ method: 'get',
+ params
+ })
+ },
+
+ /**
+ * 获取用户上传的种子
+ * @param {Object} params - 查询参数
+ * @param {number} params.page - 页码
+ * @param {number} params.size - 每页大小
+ * @returns {Promise<Object>} 种子列表
+ */
+ getUserTorrents(params = {}) {
+ return request({
+ url: '/user/torrents',
+ method: 'get',
+ params
+ })
+ },
+
+ /**
+ * 获取登录历史
+ * @param {Object} params - 查询参数
+ * @param {number} params.page - 页码
+ * @param {number} params.size - 每页大小
+ * @returns {Promise<Object>} 登录历史
+ */
+ getLoginHistory(params = {}) {
+ return request({
+ url: '/user/login-history',
+ method: 'get',
+ params
+ })
+ }
+}
diff --git a/src/assets/styles/global.css b/src/assets/styles/global.css
index 2627700..733af3f 100644
--- a/src/assets/styles/global.css
+++ b/src/assets/styles/global.css
@@ -1,60 +1,60 @@
-/* 全局样式文件 */
-:root {
- --primary-color: #667eea;
- --primary-dark: #5a6fd8;
- --secondary-color: #764ba2;
- --success-color: #67c23a;
- --warning-color: #e6a23c;
- --danger-color: #f56c6c;
- --info-color: #909399;
-
- --text-primary: #303133;
- --text-regular: #606266;
- --text-secondary: #909399;
- --text-placeholder: #c0c4cc;
-
- --border-color: #dcdfe6;
- --bg-color: #f5f7fa;
-}
-
-/* 滚动条美化 */
-::-webkit-scrollbar {
- width: 6px;
- height: 6px;
-}
-
-::-webkit-scrollbar-track {
- background: #f1f1f1;
- border-radius: 3px;
-}
-
-::-webkit-scrollbar-thumb {
- background: #c1c1c1;
- border-radius: 3px;
-}
-
-::-webkit-scrollbar-thumb:hover {
- background: #a1a1a1;
-}
-
-/* 通用动画 */
-.fade-enter-active,
-.fade-leave-active {
- transition: opacity 0.3s ease;
-}
-
-.fade-enter-from,
-.fade-leave-to {
- opacity: 0;
-}
-
-/* 通用工具类 */
-.text-center {
- text-align: center;
-}
-
-.flex-center {
- display: flex;
- align-items: center;
- justify-content: center;
-}
+/* 全局样式文件 */
+:root {
+ --primary-color: #667eea;
+ --primary-dark: #5a6fd8;
+ --secondary-color: #764ba2;
+ --success-color: #67c23a;
+ --warning-color: #e6a23c;
+ --danger-color: #f56c6c;
+ --info-color: #909399;
+
+ --text-primary: #303133;
+ --text-regular: #606266;
+ --text-secondary: #909399;
+ --text-placeholder: #c0c4cc;
+
+ --border-color: #dcdfe6;
+ --bg-color: #f5f7fa;
+}
+
+/* 滚动条美化 */
+::-webkit-scrollbar {
+ width: 6px;
+ height: 6px;
+}
+
+::-webkit-scrollbar-track {
+ background: #f1f1f1;
+ border-radius: 3px;
+}
+
+::-webkit-scrollbar-thumb {
+ background: #c1c1c1;
+ border-radius: 3px;
+}
+
+::-webkit-scrollbar-thumb:hover {
+ background: #a1a1a1;
+}
+
+/* 通用动画 */
+.fade-enter-active,
+.fade-leave-active {
+ transition: opacity 0.3s ease;
+}
+
+.fade-enter-from,
+.fade-leave-to {
+ opacity: 0;
+}
+
+/* 通用工具类 */
+.text-center {
+ text-align: center;
+}
+
+.flex-center {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+}
diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue
index b9f3c7d..48d8769 100644
--- a/src/components/HelloWorld.vue
+++ b/src/components/HelloWorld.vue
@@ -1,59 +1,59 @@
-<template>
- <div class="hello">
- <h1>{{ msg }}</h1>
- <p>
- For a guide and recipes on how to configure / customize this project,<br>
- check out the
- <a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
- </p>
- <h3>Installed CLI Plugins</h3>
- <ul>
- <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
- <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-router" target="_blank" rel="noopener">router</a></li>
- <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-vuex" target="_blank" rel="noopener">vuex</a></li>
- </ul>
- <h3>Essential Links</h3>
- <ul>
- <li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
- <li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
- <li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
- <li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
- <li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
- </ul>
- <h3>Ecosystem</h3>
- <ul>
- <li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
- <li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
- <li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
- <li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
- <li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
- </ul>
- </div>
-</template>
-
-<script>
-export default {
- name: 'HelloWorld',
- props: {
- msg: String
- }
-}
-</script>
-
-<!-- Add "scoped" attribute to limit CSS to this component only -->
-<style scoped>
-h3 {
- margin: 40px 0 0;
-}
-ul {
- list-style-type: none;
- padding: 0;
-}
-li {
- display: inline-block;
- margin: 0 10px;
-}
-a {
- color: #42b983;
-}
-</style>
+<template>
+ <div class="hello">
+ <h1>{{ msg }}</h1>
+ <p>
+ For a guide and recipes on how to configure / customize this project,<br>
+ check out the
+ <a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
+ </p>
+ <h3>Installed CLI Plugins</h3>
+ <ul>
+ <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
+ <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-router" target="_blank" rel="noopener">router</a></li>
+ <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-vuex" target="_blank" rel="noopener">vuex</a></li>
+ </ul>
+ <h3>Essential Links</h3>
+ <ul>
+ <li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
+ <li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
+ <li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
+ <li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
+ <li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
+ </ul>
+ <h3>Ecosystem</h3>
+ <ul>
+ <li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
+ <li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
+ <li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
+ <li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
+ <li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
+ </ul>
+ </div>
+</template>
+
+<script>
+export default {
+ name: 'HelloWorld',
+ props: {
+ msg: String
+ }
+}
+</script>
+
+<!-- Add "scoped" attribute to limit CSS to this component only -->
+<style scoped>
+h3 {
+ margin: 40px 0 0;
+}
+ul {
+ list-style-type: none;
+ padding: 0;
+}
+li {
+ display: inline-block;
+ margin: 0 10px;
+}
+a {
+ color: #42b983;
+}
+</style>
diff --git a/src/main.js b/src/main.js
index 4aac723..1f1b08f 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,22 +1,27 @@
-import { createApp } from 'vue'
-import App from './App.vue'
-import router from './router'
-
-// 引入Element Plus
-import ElementPlus from 'element-plus'
-import 'element-plus/dist/index.css'
-import * as ElementPlusIconsVue from '@element-plus/icons-vue'
-
-// 全局样式
-import './assets/styles/global.css'
-
-const app = createApp(App)
-
-// 注册所有Element Plus图标
-for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
- app.component(key, component)
-}
-
-app.use(ElementPlus)
-app.use(router)
+import { createApp } from 'vue'
+import App from './App.vue'
+import router from './router'
+import store from './store'
+
+// 引入Element Plus
+import ElementPlus from 'element-plus'
+import 'element-plus/dist/index.css'
+import * as ElementPlusIconsVue from '@element-plus/icons-vue'
+
+const app = createApp(App)
+
+// 注册所有Element Plus图标
+for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
+ app.component(key, component)
+}
+
+app.use(ElementPlus)
+app.use(store) // 确保这行存在且在 router 之前
+app.use(router)
+
+// 应用启动时恢复登录状态
+if (store && store.dispatch) {
+ store.dispatch('auth/restoreLoginState')
+}
+
app.mount('#app')
\ No newline at end of file
diff --git a/src/router/index.js b/src/router/index.js
index 1beac1f..9bf3278 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -1,151 +1,165 @@
-import { createRouter, createWebHistory } from 'vue-router'
-import { ElMessage } from 'element-plus'
-
-// 路由组件
-import LoginView from '@/views/auth/LoginView.vue'
-import RegisterView from '@/views/auth/RegisterView.vue'
-import HomeView from '@/views/HomeView.vue'
-
-const routes = [
- {
- path: '/',
- redirect: '/login'
- },
- {
- path: '/login',
- name: 'Login',
- component: LoginView,
- meta: {
- title: 'PT Tracker - 登录',
- requiresGuest: true
- }
- },
- {
- path: '/register',
- name: 'Register',
- component: RegisterView,
- meta: {
- title: 'PT Tracker - 注册',
- requiresGuest: true
- }
- },
- {
- path: '/home',
- name: 'Home',
- component: HomeView,
- meta: {
- title: 'PT Tracker - 首页',
- requiresAuth: true
- }
- },
- {
- path: '/:pathMatch(.*)*',
- redirect: '/login'
- },
- {
- path: '/torrents',
- name: 'Torrents',
- component: () => import('@/views/torrent/TorrentsView.vue'),
- meta: {
- title: 'PT Tracker - 种子浏览',
- requiresAuth: true
- }
-},
-{
- path: '/upload',
- name: 'Upload',
- component: () => import('@/views/torrent/UploadView.vue'),
- meta: {
- title: 'PT Tracker - 上传种子',
- requiresAuth: true
- }
-},
-{
- path: '/torrent/:id',
- name: 'TorrentDetail',
- component: () => import('@/views/torrent/TorrentDetailView.vue'),
- meta: {
- title: 'PT Tracker - 种子详情',
- requiresAuth: true
- }
-},
-{
- path: '/forum',
- name: 'Forum',
- component: () => import('@/views/forum/ForumView.vue'),
- meta: {
- title: 'PT Tracker - 论坛',
- requiresAuth: true
- }
-},
-{
- path: '/forum/section/:id',
- name: 'ForumSection',
- component: () => import('@/views/forum/ForumSectionView.vue'),
- meta: {
- title: 'PT Tracker - 版块',
- requiresAuth: true
- }
-},
-{
- path: '/forum/topic/:id',
- name: 'ForumTopic',
- component: () => import('@/views/forum/ForumTopicView.vue'),
- meta: {
- title: 'PT Tracker - 主题详情',
- requiresAuth: true
- }
-},
-// {
-// path: '/forum/topics',
-// name: 'ForumTopics',
-// component: () => impor@/views/forum/ForumTopicView.vue'),
-// meta: {
-// title: 'PT Tracker - 所有主题',
-// requiresAuth: true
-// }
-// },
-{
- path: '/profile',
- name: 'Profile',
- component: () => import('@/views/auth/ProfileView.vue'),
- meta: {
- title: 'PT Tracker - 个人资料',
- requiresAuth: true
- }
-}]
-
-const router = createRouter({
- history: createWebHistory(),
- routes
-})
-
-// 路由守卫
-router.beforeEach((to, from, next) => {
- // 设置页面标题
- if (to.meta.title) {
- document.title = to.meta.title
- }
-
- // 检查登录状态
- const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true'
-
- console.log(`路由跳转: ${from.path} -> ${to.path}, 登录状态: ${isLoggedIn}`)
-
- // 需要登录但未登录
- if (to.meta.requiresAuth && !isLoggedIn) {
- ElMessage.warning('请先登录')
- next('/login')
- return
- }
-
- // 已登录但访问登录/注册页
- if (to.meta.requiresGuest && isLoggedIn) {
- next('/home')
- return
- }
-
- next()
-})
-
-export default router
+import { createRouter, createWebHistory } from 'vue-router'
+import { ElMessage } from 'element-plus'
+import store from '@/store'
+
+// 路由组件
+import LoginView from '@/views/auth/LoginView.vue'
+import RegisterView from '@/views/auth/RegisterView.vue'
+import HomeView from '@/views/HomeView.vue'
+
+const routes = [
+ {
+ path: '/',
+ redirect: '/login'
+ },
+ {
+ path: '/login',
+ name: 'Login',
+ component: LoginView,
+ meta: {
+ title: 'PT Tracker - 登录',
+ requiresGuest: true
+ }
+ },
+ {
+ path: '/register',
+ name: 'Register',
+ component: RegisterView,
+ meta: {
+ title: 'PT Tracker - 注册',
+ requiresGuest: true
+ }
+ },
+ {
+ path: '/home',
+ name: 'Home',
+ component: HomeView,
+ meta: {
+ title: 'PT Tracker - 首页',
+ requiresAuth: true
+ }
+ },
+ {
+ path: '/profile',
+ name: 'Profile',
+ component: () => import('@/views/auth/ProfileView.vue'),
+ meta: {
+ title: 'PT Tracker - 个人资料',
+ requiresAuth: true
+ }
+ },
+ // 种子相关路由
+ {
+ path: '/torrents',
+ name: 'Torrents',
+ component: () => import('@/views/torrent/TorrentsView.vue'),
+ meta: {
+ title: 'PT Tracker - 种子浏览',
+ requiresAuth: true
+ }
+ },
+ {
+ path: '/upload',
+ name: 'Upload',
+ component: () => import('@/views/torrent/UploadView.vue'),
+ meta: {
+ title: 'PT Tracker - 上传种子',
+ requiresAuth: true
+ }
+ },
+ {
+ path: '/torrent/:id',
+ name: 'TorrentDetail',
+ component: () => import('@/views/torrent/TorrentDetailView.vue'),
+ meta: {
+ title: 'PT Tracker - 种子详情',
+ requiresAuth: true
+ }
+ },
+ // 论坛相关路由
+ {
+ path: '/forum',
+ name: 'Forum',
+ component: () => import('@/views/forum/ForumView.vue'),
+ meta: {
+ title: 'PT Tracker - 论坛',
+ requiresAuth: true
+ }
+ },
+ {
+ path: '/forum/section/:id',
+ name: 'ForumSection',
+ component: () => import('@/views/forum/ForumSectionView.vue'),
+ meta: {
+ title: 'PT Tracker - 版块',
+ requiresAuth: true
+ }
+ },
+ {
+ path: '/forum/topic/:id',
+ name: 'ForumTopic',
+ component: () => import('@/views/forum/ForumTopicView.vue'),
+ meta: {
+ title: 'PT Tracker - 主题详情',
+ requiresAuth: true
+ }
+ },
+ // 404页面
+ {
+ path: '/:pathMatch(.*)*',
+ redirect: '/login'
+ }
+]
+
+const router = createRouter({
+ history: createWebHistory(),
+ routes
+})
+
+// 更新路由守卫
+router.beforeEach(async (to, from, next) => {
+ // 设置页面标题
+ if (to.meta.title) {
+ document.title = to.meta.title
+ }
+
+ console.log(`路由跳转: ${from.path} -> ${to.path}`)
+
+ // 恢复登录状态(仅在应用启动时执行一次)
+ if (!store.state.auth.isLoggedIn && localStorage.getItem('isLoggedIn') === 'true') {
+ store.dispatch('auth/restoreLoginState')
+ }
+
+ const isLoggedIn = store.getters['auth/isAuthenticated']
+
+ // 需要登录但未登录
+ if (to.meta.requiresAuth && !isLoggedIn) {
+ // 尝试检查服务器端的登录状态
+ try {
+ const isValid = await store.dispatch('auth/checkLoginStatus')
+ if (isValid) {
+ // 服务器确认已登录,继续跳转
+ next()
+ } else {
+ // 服务器确认未登录,跳转到登录页
+ ElMessage.warning('请先登录')
+ next('/login')
+ }
+ } catch (error) {
+ // 检查失败,跳转到登录页
+ ElMessage.warning('请先登录')
+ next('/login')
+ }
+ return
+ }
+
+ // 已登录但访问登录/注册页
+ if (to.meta.requiresGuest && isLoggedIn) {
+ next('/home')
+ return
+ }
+
+ next()
+})
+
+export default router
\ No newline at end of file
diff --git a/src/store/index.js b/src/store/index.js
index 7f5b89c..d252e96 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -1,14 +1,20 @@
-import { createStore } from 'vuex'
-
-export default createStore({
- state: {
- },
- getters: {
- },
- mutations: {
- },
- actions: {
- },
- modules: {
- }
-})
+import { createStore } from 'vuex'
+import auth from './modules/auth'
+
+export default createStore({
+ state: {
+ // 可以为空
+ },
+ getters: {
+ // 可以为空,因为 auth 模块有自己的 getters
+ },
+ mutations: {
+ // 可以为空
+ },
+ actions: {
+ // 可以为空
+ },
+ modules: {
+ auth
+ }
+})
\ No newline at end of file
diff --git a/src/store/modules/auth.js b/src/store/modules/auth.js
new file mode 100644
index 0000000..69efc6b
--- /dev/null
+++ b/src/store/modules/auth.js
@@ -0,0 +1,210 @@
+import { authApi } from '@/api/auth'
+import { ElMessage } from 'element-plus'
+
+const state = {
+ // 登录状态
+ isLoggedIn: false,
+ // 用户信息
+ userInfo: null,
+ // Token信息
+ token: null,
+ // 登录加载状态
+ loginLoading: false
+}
+
+const getters = {
+ // 是否已登录
+ isAuthenticated: state => state.isLoggedIn,
+ // 获取用户信息
+ userInfo: state => state.userInfo,
+ // 获取用户名
+ username: state => state.userInfo?.user?.username || '',
+ // 获取用户头像
+ avatar: state => state.userInfo?.user?.avatar || '',
+ // 获取用户组信息
+ userGroup: state => state.userInfo?.user?.group || null,
+ // 登录加载状态
+ loginLoading: state => state.loginLoading
+}
+
+const mutations = {
+ // 设置登录状态
+ SET_LOGIN_STATUS(state, status) {
+ state.isLoggedIn = status
+ },
+
+ // 设置用户信息
+ SET_USER_INFO(state, userInfo) {
+ state.userInfo = userInfo
+ },
+
+ // 设置Token
+ SET_TOKEN(state, token) {
+ state.token = token
+ },
+
+ // 设置登录加载状态
+ SET_LOGIN_LOADING(state, loading) {
+ state.loginLoading = loading
+ },
+
+ // 清除用户数据
+ CLEAR_USER_DATA(state) {
+ state.isLoggedIn = false
+ state.userInfo = null
+ state.token = null
+ state.loginLoading = false
+ }
+}
+
+const actions = {
+ // 用户登录
+ async login({ commit }, loginData) {
+ try {
+ commit('SET_LOGIN_LOADING', true)
+
+ const response = await authApi.login(loginData)
+
+ if (response) {
+ // 保存Token
+ const tokenInfo = response.token
+ if (tokenInfo && tokenInfo.tokenValue) {
+ localStorage.setItem('token', tokenInfo.tokenValue)
+ localStorage.setItem('tokenInfo', JSON.stringify(tokenInfo))
+ commit('SET_TOKEN', tokenInfo)
+ }
+
+ // 保存用户信息
+ localStorage.setItem('userInfo', JSON.stringify(response))
+ localStorage.setItem('isLoggedIn', 'true')
+
+ commit('SET_USER_INFO', response)
+ commit('SET_LOGIN_STATUS', true)
+
+ ElMessage.success('登录成功!')
+ return response
+ }
+ } catch (error) {
+ console.error('登录失败:', error)
+ throw error
+ } finally {
+ commit('SET_LOGIN_LOADING', false)
+ }
+ },
+
+ // 用户注册
+ async register({ commit }, registerData) {
+ try {
+ commit('SET_LOGIN_LOADING', true)
+
+ const response = await authApi.register(registerData)
+
+ if (response) {
+ // 注册成功后自动登录
+ const tokenInfo = response.token
+ if (tokenInfo && tokenInfo.tokenValue) {
+ localStorage.setItem('token', tokenInfo.tokenValue)
+ localStorage.setItem('tokenInfo', JSON.stringify(tokenInfo))
+ commit('SET_TOKEN', tokenInfo)
+ }
+
+ localStorage.setItem('userInfo', JSON.stringify(response))
+ localStorage.setItem('isLoggedIn', 'true')
+
+ commit('SET_USER_INFO', response)
+ commit('SET_LOGIN_STATUS', true)
+
+ ElMessage.success('注册成功!')
+ return response
+ }
+ } catch (error) {
+ console.error('注册失败:', error)
+ throw error
+ } finally {
+ commit('SET_LOGIN_LOADING', false)
+ }
+ },
+
+ // 用户登出
+ async logout({ commit }) {
+ try {
+ await authApi.logout()
+ } catch (error) {
+ console.error('登出请求失败:', error)
+ // 即使登出请求失败,也要清除本地数据
+ } finally {
+ // 清除本地存储
+ localStorage.removeItem('token')
+ localStorage.removeItem('tokenInfo')
+ localStorage.removeItem('userInfo')
+ localStorage.removeItem('isLoggedIn')
+
+ // 清除状态
+ commit('CLEAR_USER_DATA')
+
+ ElMessage.success('已退出登录')
+ }
+ },
+
+ // 检查登录状态
+ async checkLoginStatus({ commit }) {
+ try {
+ const response = await authApi.getStatus()
+
+ if (response && response.isLoggedIn && response.user) {
+ // 更新用户信息
+ localStorage.setItem('userInfo', JSON.stringify(response.user))
+ localStorage.setItem('isLoggedIn', 'true')
+
+ commit('SET_USER_INFO', response.user)
+ commit('SET_LOGIN_STATUS', true)
+
+ return true
+ } else {
+ // 登录状态无效,清除本地数据
+ commit('CLEAR_USER_DATA')
+ localStorage.removeItem('token')
+ localStorage.removeItem('tokenInfo')
+ localStorage.removeItem('userInfo')
+ localStorage.removeItem('isLoggedIn')
+
+ return false
+ }
+ } catch (error) {
+ console.error('检查登录状态失败:', error)
+ commit('CLEAR_USER_DATA')
+ return false
+ }
+ },
+
+ // 从本地存储恢复登录状态
+ restoreLoginState({ commit }) {
+ const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true'
+ const userInfo = localStorage.getItem('userInfo')
+ const tokenInfo = localStorage.getItem('tokenInfo')
+
+ if (isLoggedIn && userInfo) {
+ try {
+ const parsedUserInfo = JSON.parse(userInfo)
+ const parsedTokenInfo = tokenInfo ? JSON.parse(tokenInfo) : null
+
+ commit('SET_USER_INFO', parsedUserInfo)
+ commit('SET_TOKEN', parsedTokenInfo)
+ commit('SET_LOGIN_STATUS', true)
+
+ console.log('✅ 已从本地存储恢复登录状态')
+ } catch (error) {
+ console.error('❌ 恢复登录状态失败:', error)
+ commit('CLEAR_USER_DATA')
+ }
+ }
+ }
+}
+
+export default {
+ namespaced: true,
+ state,
+ getters,
+ mutations,
+ actions
+}
\ No newline at end of file
diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue
index c4e0ec7..7a728b1 100644
--- a/src/views/HomeView.vue
+++ b/src/views/HomeView.vue
@@ -1,777 +1,665 @@
-<template>
- <div class="home-page">
- <div class="home-container">
- <!-- 用户信息和导航 -->
- <header class="site-header">
- <div class="header-content">
- <div class="logo-section">
- <h2 class="site-logo">🚀 PT Tracker</h2>
- </div>
- <div class="user-section">
- <div class="user-stats">
- <div class="stat-item">
- <span class="stat-label">上传:</span>
- <span class="stat-value">{{ userStats.uploaded }}</span>
- </div>
- <div class="stat-item">
- <span class="stat-label">下载:</span>
- <span class="stat-value">{{ userStats.downloaded }}</span>
- </div>
- <div class="stat-item">
- <span class="stat-label">分享率:</span>
- <span class="stat-value ratio" :class="getRatioClass(userStats.ratio)">
- {{ userStats.ratio }}
- </span>
- </div>
- </div>
- <div class="user-info">
- <el-avatar :size="40" :icon="UserFilled" />
- <span class="username">{{ userInfo.username }}</span>
- <el-dropdown @command="handleUserCommand">
- <el-icon class="dropdown-icon"><ArrowDown /></el-icon>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item command="profile">个人资料</el-dropdown-item>
- <el-dropdown-item command="settings">设置</el-dropdown-item>
- <el-dropdown-item command="logout" divided>退出登录</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- </div>
- </div>
- </div>
- </header>
-
- <!-- 主要内容区域 -->
- <main class="main-content">
- <!-- 统计概览 -->
- <section class="stats-overview">
- <div class="stats-grid">
- <div class="stat-card">
- <div class="stat-icon">
- <el-icon size="32" color="#67c23a"><Download /></el-icon>
- </div>
- <div class="stat-info">
- <h3>{{ siteStats.totalTorrents }}</h3>
- <p>种子总数</p>
- </div>
- </div>
- <div class="stat-card">
- <div class="stat-icon">
- <el-icon size="32" color="#409eff"><User /></el-icon>
- </div>
- <div class="stat-info">
- <h3>{{ siteStats.totalUsers }}</h3>
- <p>注册用户</p>
- </div>
- </div>
- <div class="stat-card">
- <div class="stat-icon">
- <el-icon size="32" color="#f56c6c"><Upload /></el-icon>
- </div>
- <div class="stat-info">
- <h3>{{ siteStats.totalSize }}</h3>
- <p>数据总量</p>
- </div>
- </div>
- </div>
- </section>
-
- <!-- 快速操作 -->
- <section class="quick-actions">
- <h2 class="section-title">快速操作</h2>
- <div class="action-grid">
- <div class="action-card" @click="navigateTo('/torrents')">
- <el-icon size="48" color="#409eff"><Search /></el-icon>
- <h3>浏览种子</h3>
- <p>搜索和浏览所有可用的种子资源</p>
- </div>
- <div class="action-card" @click="navigateTo('/upload')">
- <el-icon size="48" color="#67c23a"><Upload /></el-icon>
- <h3>上传资源</h3>
- <p>分享你的资源,为社区做贡献</p>
- </div>
- <div class="action-card" @click="navigateTo('/forum')">
- <el-icon size="48" color="#e6a23c"><ChatDotRound /></el-icon>
- <h3>论坛交流</h3>
- <p>与其他用户交流讨论</p>
- </div>
- <div class="action-card" @click="navigateTo('/rankings')">
- <el-icon size="48" color="#f56c6c"><TrophyBase /></el-icon>
- <h3>排行榜</h3>
- <p>查看用户和资源排行</p>
- </div>
- </div>
- </section>
-
- <!-- 最新种子 -->
- <section class="latest-torrents">
- <div class="section-header">
- <h2 class="section-title">最新种子</h2>
- <el-button type="primary" text @click="navigateTo('/torrents')">
- 查看更多 <el-icon><ArrowRight /></el-icon>
- </el-button>
- </div>
- <div class="torrents-list">
- <div
- v-for="torrent in latestTorrents"
- :key="torrent.id"
- class="torrent-item"
- @click="navigateTo(`/torrent/${torrent.id}`)"
- >
- <div class="torrent-info">
- <div class="torrent-category">
- <el-tag :type="getCategoryType(torrent.category)" size="small">
- {{ torrent.category }}
- </el-tag>
- </div>
- <h4 class="torrent-title">{{ torrent.title }}</h4>
- <div class="torrent-meta">
- <span class="meta-item">
- <el-icon><User /></el-icon>
- {{ torrent.uploader }}
- </span>
- <span class="meta-item">
- <el-icon><Clock /></el-icon>
- {{ formatTime(torrent.uploadTime) }}
- </span>
- <span class="meta-item">
- <el-icon><Coin /></el-icon>
- {{ torrent.size }}
- </span>
- </div>
- </div>
- <div class="torrent-stats">
- <div class="stat-group">
- <span class="stat-number seeders">{{ torrent.seeders }}</span>
- <span class="stat-label">做种</span>
- </div>
- <div class="stat-group">
- <span class="stat-number leechers">{{ torrent.leechers }}</span>
- <span class="stat-label">下载</span>
- </div>
- <div class="stat-group">
- <span class="stat-number">{{ torrent.downloads }}</span>
- <span class="stat-label">完成</span>
- </div>
- </div>
- </div>
- </div>
- </section>
-
- <!-- 个人活动 -->
- <section class="user-activity">
- <h2 class="section-title">我的活动</h2>
- <div class="activity-grid">
- <div class="activity-card">
- <h3>我的种子</h3>
- <div class="activity-stats">
- <div class="activity-item">
- <span class="activity-label">正在做种:</span>
- <span class="activity-value">{{ userActivity.seeding }}</span>
- </div>
- <div class="activity-item">
- <span class="activity-label">正在下载:</span>
- <span class="activity-value">{{ userActivity.downloading }}</span>
- </div>
- <div class="activity-item">
- <span class="activity-label">已上传:</span>
- <span class="activity-value">{{ userActivity.uploaded }}</span>
- </div>
- </div>
- <el-button type="primary" size="small" @click="navigateTo('/my-torrents')">
- 查看详情
- </el-button>
- </div>
-
- <div class="activity-card">
- <h3>邀请管理</h3>
- <div class="activity-stats">
- <div class="activity-item">
- <span class="activity-label">可用邀请:</span>
- <span class="activity-value">{{ userActivity.invitations }}</span>
- </div>
- <div class="activity-item">
- <span class="activity-label">已邀请:</span>
- <span class="activity-value">{{ userActivity.invited }}</span>
- </div>
- </div>
- <el-button type="success" size="small" @click="navigateTo('/invitations')">
- 管理邀请
- </el-button>
- </div>
- </div>
- </section>
- </main>
- </div>
- </div>
-</template>
-
-<script>
-import { ref, onMounted } from 'vue'
-import { useRouter } from 'vue-router'
-import { ElMessage, ElMessageBox } from 'element-plus'
-import {
- UserFilled,
- ArrowDown,
- Download,
- Upload,
- ChatDotRound,
- Search,
- User,
- Connection,
- TrophyBase,
- ArrowRight,
- Clock,
- Coin
-} from '@element-plus/icons-vue'
-
-export default {
- name: 'HomeView',
- components: {
- UserFilled,
- ArrowDown
- },
- setup() {
- const router = useRouter()
-
- const userInfo = ref({
- username: '',
- loginTime: ''
- })
-
- const userStats = ref({
- uploaded: '128.5 GB',
- downloaded: '45.2 GB',
- ratio: '2.84'
- })
-
- const siteStats = ref({
- totalTorrents: '12,458',
- totalUsers: '8,924',
- onlineUsers: '342',
- totalSize: '45.2 TB'
- })
-
- const userActivity = ref({
- seeding: 15,
- downloading: 3,
- uploaded: 8,
- invitations: 5,
- invited: 12
- })
-
- const latestTorrents = ref([
- {
- id: 1,
- title: '[4K蓝光原盘] 阿凡达:水之道 Avatar: The Way of Water (2022)',
- category: '电影',
- uploader: 'MovieMaster',
- uploadTime: '2025-06-03T10:30:00',
- size: '85.6 GB',
- seeders: 128,
- leechers: 45,
- downloads: 892
- },
- {
- id: 2,
- title: '[FLAC] Taylor Swift - Midnights (Deluxe Edition) [2022]',
- category: '音乐',
- uploader: 'MusicLover',
- uploadTime: '2025-06-03T09:15:00',
- size: '1.2 GB',
- seeders: 67,
- leechers: 12,
- downloads: 456
- },
- {
- id: 3,
- title: '[合集] Adobe Creative Suite 2025 完整版',
- category: '软件',
- uploader: 'TechGuru',
- uploadTime: '2025-06-03T08:45:00',
- size: '12.8 GB',
- seeders: 234,
- leechers: 89,
- downloads: 1205
- }
- ])
-
- onMounted(() => {
- userInfo.value = {
- username: localStorage.getItem('username') || '用户',
- loginTime: localStorage.getItem('loginTime') || ''
- }
-
- // 模拟获取用户数据
- fetchUserData()
- })
-
- const fetchUserData = () => {
- // 这里应该是API调用,现在使用模拟数据
- console.log('获取用户数据...')
- }
-
- const formatTime = (timeString) => {
- if (!timeString) return ''
- const date = new Date(timeString)
- const now = new Date()
- const diff = now - date
- const hours = Math.floor(diff / (1000 * 60 * 60))
-
- if (hours < 1) return '刚刚'
- if (hours < 24) return `${hours}小时前`
- const days = Math.floor(hours / 24)
- return `${days}天前`
- }
-
- const getRatioClass = (ratio) => {
- const r = parseFloat(ratio)
- if (r >= 2) return 'excellent'
- if (r >= 1) return 'good'
- return 'warning'
- }
-
- const getCategoryType = (category) => {
- const types = {
- '电影': 'primary',
- '音乐': 'success',
- '软件': 'warning',
- '游戏': 'danger',
- '电视剧': 'info'
- }
- return types[category] || 'default'
- }
-
- const navigateTo = (path) => {
- router.push(path)
- }
-
- const handleUserCommand = async (command) => {
- switch (command) {
- case 'profile':
- navigateTo('/profile')
- break
- case 'settings':
- navigateTo('/settings')
- break
- case 'logout':
- await handleLogout()
- break
- }
- }
-
- const handleLogout = async () => {
- try {
- await ElMessageBox.confirm(
- '确定要退出登录吗?',
- '提示',
- {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }
- )
-
- localStorage.removeItem('isLoggedIn')
- localStorage.removeItem('username')
- localStorage.removeItem('loginTime')
- localStorage.removeItem('rememberLogin')
-
- ElMessage.success('已安全退出')
- router.push('/login')
-
- } catch {
- // 用户取消退出
- }
- }
-
- return {
- userInfo,
- userStats,
- siteStats,
- userActivity,
- latestTorrents,
- formatTime,
- getRatioClass,
- getCategoryType,
- navigateTo,
- handleUserCommand,
- handleLogout,
- Download,
- Upload,
- ChatDotRound,
- Search,
- User,
- Connection,
- TrophyBase,
- ArrowRight,
- Clock,
- Coin
- }
- }
-}
-</script>
-
-<style lang="scss" scoped>
-.home-page {
- min-height: 100vh;
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- padding: 0;
-}
-
-.home-container {
- max-width: 1200px;
- margin: 0 auto;
- background: #fff;
- min-height: 100vh;
-}
-
-// 网站头部
-.site-header {
- background: #fff;
- box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
- position: sticky;
- top: 0;
- z-index: 100;
-
- .header-content {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 16px 24px;
-
- .logo-section {
- .site-logo {
- margin: 0;
- font-size: 24px;
- font-weight: bold;
- color: #667eea;
- }
- }
-
- .user-section {
- display: flex;
- align-items: center;
- gap: 24px;
-
- .user-stats {
- display: flex;
- gap: 16px;
-
- .stat-item {
- font-size: 14px;
-
- .stat-label {
- color: #909399;
- margin-right: 4px;
- }
-
- .stat-value {
- font-weight: 600;
- color: #2c3e50;
-
- &.ratio {
- &.excellent { color: #67c23a; }
- &.good { color: #e6a23c; }
- &.warning { color: #f56c6c; }
- }
- }
- }
- }
-
- .user-info {
- display: flex;
- align-items: center;
- gap: 8px;
- cursor: pointer;
-
- .username {
- font-weight: 500;
- color: #2c3e50;
- }
-
- .dropdown-icon {
- color: #909399;
- transition: transform 0.3s ease;
-
- &:hover {
- transform: rotate(180deg);
- }
- }
- }
- }
- }
-}
-
-// 主要内容
-.main-content {
- padding: 24px;
-}
-
-.section-title {
- font-size: 20px;
- font-weight: 600;
- color: #2c3e50;
- margin-bottom: 16px;
-}
-
-.section-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 16px;
-}
-
-// 统计概览
-.stats-overview {
- margin-bottom: 32px;
-
- .stats-grid {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
- gap: 16px;
-
- .stat-card {
- background: #fff;
- border-radius: 12px;
- padding: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
- border: 1px solid #f0f0f0;
- display: flex;
- align-items: center;
- gap: 16px;
- transition: all 0.3s ease;
-
- &:hover {
- transform: translateY(-2px);
- box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
- }
-
- .stat-info {
- h3 {
- font-size: 24px;
- font-weight: bold;
- color: #2c3e50;
- margin: 0 0 4px 0;
- }
-
- p {
- font-size: 14px;
- color: #909399;
- margin: 0;
- }
- }
- }
- }
-}
-
-// 快速操作
-.quick-actions {
- margin-bottom: 32px;
-
- .action-grid {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
- gap: 20px;
-
- .action-card {
- background: #fff;
- border-radius: 12px;
- padding: 32px 24px;
- text-align: center;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
- border: 1px solid #f0f0f0;
- cursor: pointer;
- transition: all 0.3s ease;
-
- &:hover {
- transform: translateY(-4px);
- box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
- }
-
- h3 {
- font-size: 18px;
- font-weight: 600;
- color: #2c3e50;
- margin: 16px 0 8px 0;
- }
-
- p {
- font-size: 14px;
- color: #7f8c8d;
- line-height: 1.5;
- margin: 0;
- }
- }
- }
-}
-
-// 最新种子
-.latest-torrents {
- margin-bottom: 32px;
-
- .torrents-list {
- background: #fff;
- border-radius: 12px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
- border: 1px solid #f0f0f0;
- overflow: hidden;
-
- .torrent-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 20px 24px;
- border-bottom: 1px solid #f5f5f5;
- cursor: pointer;
- transition: background-color 0.3s ease;
-
- &:hover {
- background-color: #f8f9fa;
- }
-
- &:last-child {
- border-bottom: none;
- }
-
- .torrent-info {
- flex: 1;
-
- .torrent-category {
- margin-bottom: 8px;
- }
-
- .torrent-title {
- font-size: 16px;
- font-weight: 500;
- color: #2c3e50;
- margin: 0 0 8px 0;
- line-height: 1.4;
- }
-
- .torrent-meta {
- display: flex;
- gap: 16px;
-
- .meta-item {
- display: flex;
- align-items: center;
- gap: 4px;
- font-size: 12px;
- color: #909399;
-
- .el-icon {
- font-size: 12px;
- }
- }
- }
- }
-
- .torrent-stats {
- display: flex;
- gap: 24px;
-
- .stat-group {
- text-align: center;
-
- .stat-number {
- display: block;
- font-size: 16px;
- font-weight: 600;
-
- &.seeders { color: #67c23a; }
- &.leechers { color: #f56c6c; }
- }
-
- .stat-label {
- font-size: 12px;
- color: #909399;
- }
- }
- }
- }
- }
-}
-
-// 用户活动
-.user-activity {
- .activity-grid {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
- gap: 20px;
-
- .activity-card {
- background: #fff;
- border-radius: 12px;
- padding: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
- border: 1px solid #f0f0f0;
-
- h3 {
- font-size: 18px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 16px 0;
- }
-
- .activity-stats {
- margin-bottom: 16px;
-
- .activity-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 8px 0;
-
- .activity-label {
- font-size: 14px;
- color: #7f8c8d;
- }
-
- .activity-value {
- font-size: 14px;
- font-weight: 600;
- color: #2c3e50;
- }
- }
- }
- }
- }
-}
-
-// 响应式设计
-@media (max-width: 768px) {
- .header-content {
- flex-direction: column;
- gap: 16px;
-
- .user-stats {
- flex-direction: column;
- gap: 8px;
- text-align: center;
- }
- }
-
- .main-content {
- padding: 16px;
- }
-
- .stats-grid,
- .action-grid,
- .activity-grid {
- grid-template-columns: 1fr;
- }
-
- .torrent-item {
- flex-direction: column;
- align-items: flex-start;
- gap: 16px;
-
- .torrent-stats {
- width: 100%;
- justify-content: space-around;
- }
- }
-}
+<template>
+ <div class="home-page">
+ <!-- 导航栏 -->
+ <div class="navbar">
+ <router-link to="/home" class="navbar-brand">PT Tracker</router-link>
+ <div class="navbar-nav">
+ <router-link to="/home" class="navbar-item">首页</router-link>
+ <router-link to="/torrents" class="navbar-item">种子</router-link>
+ <router-link to="/forum" class="navbar-item">论坛</router-link>
+ <el-dropdown @command="handleUserCommand">
+ <span class="navbar-user">
+ <el-avatar :size="32" :src="userAvatar">
+ {{ username.charAt(0).toUpperCase() }}
+ </el-avatar>
+ <span class="username">{{ username }}</span>
+ <el-icon><ArrowDown /></el-icon>
+ </span>
+ <template #dropdown>
+ <el-dropdown-menu>
+ <el-dropdown-item command="profile">
+ <el-icon><User /></el-icon>
+ 个人资料
+ </el-dropdown-item>
+ <el-dropdown-item command="settings">
+ <el-icon><Setting /></el-icon>
+ 设置
+ </el-dropdown-item>
+ <el-dropdown-item divided command="logout">
+ <el-icon><SwitchButton /></el-icon>
+ 退出登录
+ </el-dropdown-item>
+ </el-dropdown-menu>
+ </template>
+ </el-dropdown>
+ </div>
+ </div>
+
+ <!-- 主内容区 -->
+ <div class="main-content">
+ <!-- 欢迎卡片 -->
+ <div class="welcome-card">
+ <div class="welcome-header">
+ <h1>欢迎回来,{{ username }}!</h1>
+ <p>当前时间:{{ currentTime }}</p>
+ </div>
+
+ <!-- 用户统计概览 -->
+ <div class="stats-overview" v-if="userInfo">
+ <div class="stat-item">
+ <div class="stat-icon upload">
+ <el-icon size="24"><Upload /></el-icon>
+ </div>
+ <div class="stat-content">
+ <h3>{{ formatBytes(userInfo.user.uploaded) }}</h3>
+ <p>总上传</p>
+ </div>
+ </div>
+
+ <div class="stat-item">
+ <div class="stat-icon download">
+ <el-icon size="24"><Download /></el-icon>
+ </div>
+ <div class="stat-content">
+ <h3>{{ formatBytes(userInfo.user.downloaded) }}</h3>
+ <p>总下载</p>
+ </div>
+ </div>
+
+ <div class="stat-item">
+ <div class="stat-icon ratio">
+ <el-icon size="24"><TrendCharts /></el-icon>
+ </div>
+ <div class="stat-content">
+ <h3>{{ calculateRatio(userInfo.user.uploaded, userInfo.user.downloaded) }}</h3>
+ <p>分享率</p>
+ </div>
+ </div>
+
+ <div class="stat-item">
+ <div class="stat-icon points">
+ <el-icon size="24"><Star /></el-icon>
+ </div>
+ <div class="stat-content">
+ <h3>{{ userInfo.user.karma || '0' }}</h3>
+ <p>积分</p>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- 功能快捷入口 -->
+ <div class="quick-actions">
+ <h2>快捷操作</h2>
+ <div class="actions-grid">
+ <div class="action-card" @click="$router.push('/upload')">
+ <el-icon size="32" color="#67c23a"><Upload /></el-icon>
+ <h3>上传种子</h3>
+ <p>分享你的资源</p>
+ </div>
+
+ <div class="action-card" @click="$router.push('/torrents')">
+ <el-icon size="32" color="#409eff"><Search /></el-icon>
+ <h3>浏览种子</h3>
+ <p>发现新内容</p>
+ </div>
+
+ <div class="action-card" @click="$router.push('/forum')">
+ <el-icon size="32" color="#e6a23c"><ChatDotRound /></el-icon>
+ <h3>社区论坛</h3>
+ <p>交流讨论</p>
+ </div>
+
+ <div class="action-card" @click="$router.push('/profile')">
+ <el-icon size="32" color="#f56c6c"><User /></el-icon>
+ <h3>个人中心</h3>
+ <p>管理账户</p>
+ </div>
+ </div>
+ </div>
+
+ <!-- API连接状态测试 -->
+ <div class="api-status-card">
+ <h2>API连接状态</h2>
+ <div class="status-items">
+ <div class="status-item">
+ <el-icon :color="loginStatusColor"><CircleCheck /></el-icon>
+ <span>登录状态:{{ loginStatusText }}</span>
+ <el-button size="small" @click="checkLoginStatus">检查状态</el-button>
+ </div>
+
+ <div class="status-item">
+ <el-icon :color="userInfoStatusColor"><User /></el-icon>
+ <span>用户信息:{{ userInfoStatusText }}</span>
+ <el-button size="small" @click="refreshUserInfo">刷新信息</el-button>
+ </div>
+ </div>
+
+ <!-- 用户详细信息展示 -->
+ <div class="user-details" v-if="userInfo">
+ <h3>用户详细信息</h3>
+ <div class="details-grid">
+ <div class="detail-item">
+ <label>用户ID:</label>
+ <span>{{ userInfo.user.id }}</span>
+ </div>
+ <div class="detail-item">
+ <label>用户名:</label>
+ <span>{{ userInfo.user.username }}</span>
+ </div>
+ <div class="detail-item">
+ <label>邮箱:</label>
+ <span>{{ userInfo.user.email }}</span>
+ </div>
+ <div class="detail-item">
+ <label>用户组:</label>
+ <span>{{ userInfo.user.group?.displayName || '未知' }}</span>
+ </div>
+ <div class="detail-item">
+ <label>注册时间:</label>
+ <span>{{ formatDate(userInfo.user.createdAt) }}</span>
+ </div>
+ <div class="detail-item">
+ <label>个性签名:</label>
+ <span>{{ userInfo.user.signature || '这个用户很懒,还没有个性签名' }}</span>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script>
+import { ref, computed, onMounted, onUnmounted } from 'vue'
+import { useRouter } from 'vue-router'
+import { useStore } from 'vuex'
+import { ElMessage, ElMessageBox } from 'element-plus'
+import {
+ ArrowDown,
+ User,
+ Setting,
+ SwitchButton,
+ Upload,
+ Download,
+ TrendCharts,
+ Star,
+ Search,
+ ChatDotRound,
+ CircleCheck
+} from '@element-plus/icons-vue'
+
+export default {
+ name: 'HomeView',
+ components: {
+ ArrowDown,
+ User,
+ Setting,
+ SwitchButton,
+ Upload,
+ Download,
+ TrendCharts,
+ Star,
+ Search,
+ ChatDotRound,
+ CircleCheck
+ },
+ setup() {
+ const router = useRouter()
+ const store = useStore()
+
+ const currentTime = ref('')
+ const timeInterval = ref(null)
+
+ // 从store获取用户信息
+ const userInfo = computed(() => store.getters['auth/userInfo'])
+ const username = computed(() => store.getters['auth/username'])
+ const userAvatar = computed(() => store.getters['auth/avatar'])
+ const isAuthenticated = computed(() => store.getters['auth/isAuthenticated'])
+
+ // API状态
+ const loginStatusColor = computed(() => isAuthenticated.value ? '#67c23a' : '#f56c6c')
+ const loginStatusText = computed(() => isAuthenticated.value ? '已登录' : '未登录')
+
+ const userInfoStatusColor = computed(() => userInfo.value ? '#67c23a' : '#f56c6c')
+ const userInfoStatusText = computed(() => userInfo.value ? '已获取' : '未获取')
+
+ // 更新当前时间
+ const updateCurrentTime = () => {
+ currentTime.value = new Date().toLocaleString('zh-CN')
+ }
+
+ // 格式化字节数
+ const formatBytes = (bytes) => {
+ if (!bytes || bytes === 0) return '0 B'
+
+ const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
+ const i = Math.floor(Math.log(bytes) / Math.log(1024))
+ const size = (bytes / Math.pow(1024, i)).toFixed(2)
+
+ return `${size} ${sizes[i]}`
+ }
+
+ // 计算分享率
+ const calculateRatio = (uploaded, downloaded) => {
+ if (!uploaded || !downloaded || downloaded === 0) {
+ return uploaded > 0 ? '∞' : '0.00'
+ }
+ return (uploaded / downloaded).toFixed(2)
+ }
+
+ // 格式化日期
+ const formatDate = (timestamp) => {
+ if (!timestamp) return '未知'
+ return new Date(timestamp).toLocaleDateString('zh-CN')
+ }
+
+ // 检查登录状态
+ const checkLoginStatus = async () => {
+ try {
+ await store.dispatch('auth/checkLoginStatus')
+ ElMessage.success('登录状态检查完成')
+ } catch (error) {
+ console.error('检查登录状态失败:', error)
+ ElMessage.error('检查登录状态失败')
+ }
+ }
+
+ // 刷新用户信息
+ const refreshUserInfo = async () => {
+ try {
+ await store.dispatch('auth/checkLoginStatus')
+ ElMessage.success('用户信息刷新成功')
+ } catch (error) {
+ console.error('刷新用户信息失败:', error)
+ ElMessage.error('刷新用户信息失败')
+ }
+ }
+
+ // 处理用户菜单命令
+ const handleUserCommand = async (command) => {
+ switch (command) {
+ case 'profile':
+ router.push('/profile')
+ break
+ case 'settings':
+ ElMessage.info('设置功能开发中...')
+ break
+ case 'logout':
+ try {
+ await ElMessageBox.confirm('确定要退出登录吗?', '提示', {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ })
+
+ await store.dispatch('auth/logout')
+ router.push('/login')
+ } catch (error) {
+ // 用户取消操作
+ if (error !== 'cancel') {
+ console.error('退出登录失败:', error)
+ }
+ }
+ break
+ }
+ }
+
+ onMounted(() => {
+ // 开始时间更新
+ updateCurrentTime()
+ timeInterval.value = setInterval(updateCurrentTime, 1000)
+
+ // 检查登录状态
+ if (!isAuthenticated.value) {
+ checkLoginStatus()
+ }
+ })
+
+ onUnmounted(() => {
+ // 清理定时器
+ if (timeInterval.value) {
+ clearInterval(timeInterval.value)
+ }
+ })
+
+ return {
+ currentTime,
+ userInfo,
+ username,
+ userAvatar,
+ isAuthenticated,
+ loginStatusColor,
+ loginStatusText,
+ userInfoStatusColor,
+ userInfoStatusText,
+ formatBytes,
+ calculateRatio,
+ formatDate,
+ checkLoginStatus,
+ refreshUserInfo,
+ handleUserCommand
+ }
+ }
+}
+</script>
+
+<style lang="scss" scoped>
+.home-page {
+ min-height: 100vh;
+ background: #f5f5f5;
+}
+
+.navbar {
+ background: #fff;
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
+ height: 60px;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 0 24px;
+ position: sticky;
+ top: 0;
+ z-index: 1000;
+}
+
+.navbar-brand {
+ font-size: 20px;
+ font-weight: 700;
+ color: #409eff;
+ text-decoration: none;
+}
+
+.navbar-nav {
+ display: flex;
+ align-items: center;
+ gap: 24px;
+}
+
+.navbar-item {
+ color: #606266;
+ text-decoration: none;
+ font-weight: 500;
+ transition: color 0.3s;
+
+ &:hover {
+ color: #409eff;
+ }
+}
+
+.navbar-user {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ cursor: pointer;
+ padding: 8px;
+ border-radius: 6px;
+ transition: background-color 0.3s;
+
+ &:hover {
+ background-color: #f5f7fa;
+ }
+
+ .username {
+ font-weight: 500;
+ color: #303133;
+ }
+}
+
+.main-content {
+ max-width: 1200px;
+ margin: 0 auto;
+ padding: 24px;
+}
+
+.welcome-card {
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
+ color: white;
+ border-radius: 12px;
+ padding: 32px;
+ margin-bottom: 24px;
+
+ .welcome-header {
+ text-align: center;
+ margin-bottom: 24px;
+
+ h1 {
+ font-size: 28px;
+ margin-bottom: 8px;
+ }
+
+ p {
+ opacity: 0.9;
+ font-size: 14px;
+ }
+ }
+
+ .stats-overview {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
+ gap: 16px;
+
+ .stat-item {
+ background: rgba(255, 255, 255, 0.1);
+ backdrop-filter: blur(10px);
+ border-radius: 8px;
+ padding: 20px;
+ display: flex;
+ align-items: center;
+ gap: 16px;
+
+ .stat-icon {
+ width: 48px;
+ height: 48px;
+ border-radius: 50%;
+ background: rgba(255, 255, 255, 0.2);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ }
+
+ .stat-content {
+ h3 {
+ font-size: 20px;
+ font-weight: 600;
+ margin: 0 0 4px 0;
+ }
+
+ p {
+ font-size: 14px;
+ opacity: 0.8;
+ margin: 0;
+ }
+ }
+ }
+ }
+}
+
+.quick-actions {
+ background: #fff;
+ border-radius: 12px;
+ padding: 24px;
+ margin-bottom: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ h2 {
+ font-size: 20px;
+ color: #303133;
+ margin: 0 0 20px 0;
+ }
+
+ .actions-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
+ gap: 16px;
+
+ .action-card {
+ background: #f8f9fa;
+ border-radius: 8px;
+ padding: 24px;
+ text-align: center;
+ cursor: pointer;
+ transition: all 0.3s;
+ border: 2px solid transparent;
+
+ &:hover {
+ transform: translateY(-2px);
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
+ border-color: #409eff;
+ }
+
+ h3 {
+ font-size: 16px;
+ color: #303133;
+ margin: 12px 0 8px 0;
+ }
+
+ p {
+ font-size: 14px;
+ color: #909399;
+ margin: 0;
+ }
+ }
+ }
+}
+
+.api-status-card {
+ background: #fff;
+ border-radius: 12px;
+ padding: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ h2 {
+ font-size: 20px;
+ color: #303133;
+ margin: 0 0 20px 0;
+ }
+
+ .status-items {
+ margin-bottom: 24px;
+
+ .status-item {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ padding: 12px 0;
+ border-bottom: 1px solid #ebeef5;
+
+ &:last-child {
+ border-bottom: none;
+ }
+
+ span {
+ flex: 1;
+ font-size: 14px;
+ color: #606266;
+ }
+ }
+ }
+
+ .user-details {
+ border-top: 1px solid #ebeef5;
+ padding-top: 20px;
+
+ h3 {
+ font-size: 16px;
+ color: #303133;
+ margin: 0 0 16px 0;
+ }
+
+ .details-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
+ gap: 12px;
+
+ .detail-item {
+ display: flex;
+ align-items: center;
+ padding: 8px 0;
+
+ label {
+ font-weight: 500;
+ color: #909399;
+ min-width: 80px;
+ font-size: 14px;
+ }
+
+ span {
+ color: #606266;
+ font-size: 14px;
+ }
+ }
+ }
+ }
+}
+
+@media (max-width: 768px) {
+ .navbar {
+ padding: 0 16px;
+
+ .navbar-nav {
+ gap: 16px;
+ }
+
+ .navbar-user .username {
+ display: none;
+ }
+ }
+
+ .main-content {
+ padding: 16px;
+ }
+
+ .welcome-card {
+ padding: 24px 16px;
+
+ .welcome-header h1 {
+ font-size: 24px;
+ }
+
+ .stats-overview {
+ grid-template-columns: repeat(2, 1fr);
+ gap: 12px;
+
+ .stat-item {
+ padding: 16px;
+
+ .stat-content h3 {
+ font-size: 16px;
+ }
+ }
+ }
+ }
+
+ .actions-grid {
+ grid-template-columns: repeat(2, 1fr);
+ gap: 12px;
+
+ .action-card {
+ padding: 16px;
+
+ h3 {
+ font-size: 14px;
+ }
+
+ p {
+ font-size: 12px;
+ }
+ }
+ }
+
+ .details-grid {
+ grid-template-columns: 1fr;
+ }
+}
+
+@media (max-width: 480px) {
+ .stats-overview {
+ grid-template-columns: 1fr;
+ }
+
+ .actions-grid {
+ grid-template-columns: 1fr;
+ }
+}
</style>
\ No newline at end of file
diff --git a/src/views/auth/LoginView.vue b/src/views/auth/LoginView.vue
index fb85c70..8ab8577 100644
--- a/src/views/auth/LoginView.vue
+++ b/src/views/auth/LoginView.vue
@@ -1,343 +1,183 @@
-<template>
- <div class="login-page">
- <!-- 背景装饰 -->
- <div class="bg-decoration">
- <div class="shape shape-1"></div>
- <div class="shape shape-2"></div>
- <div class="shape shape-3"></div>
- </div>
-
- <!-- 登录表单容器 -->
- <div class="login-container">
- <div class="login-card">
- <!-- 头部信息 -->
- <div class="login-header">
- <div class="logo">
- <el-icon size="48" color="#667eea"><Operation /></el-icon>
- </div>
- <h1 class="title">PT Tracker</h1>
- <p class="subtitle">私有种子分享社区</p>
- </div>
-
- <!-- 登录表单 -->
- <el-form
- ref="loginFormRef"
- :model="loginForm"
- :rules="loginRules"
- class="login-form"
- size="large"
- >
- <el-form-item prop="username">
- <el-input
- v-model="loginForm.username"
- placeholder="请输入用户名或邮箱"
- clearable
- :prefix-icon="User"
- />
- </el-form-item>
-
- <el-form-item prop="password">
- <el-input
- v-model="loginForm.password"
- type="password"
- placeholder="请输入密码"
- show-password
- :prefix-icon="Lock"
- @keyup.enter="handleLogin"
- />
- </el-form-item>
-
- <el-form-item>
- <div class="login-options">
- <el-checkbox v-model="rememberMe">记住登录</el-checkbox>
- <el-link type="primary" :underline="false">忘记密码?</el-link>
- </div>
- </el-form-item>
-
- <el-form-item>
- <el-button
- type="primary"
- :loading="loading"
- style="width: 100%"
- @click="handleLogin"
- >
- <span v-if="!loading">登录</span>
- <span v-else>登录中...</span>
- </el-button>
- </el-form-item>
- </el-form>
-
- <!-- 底部链接 -->
- <div class="login-footer">
- <span class="footer-text">还没有账号?</span>
- <el-link
- type="primary"
- :underline="false"
- @click="$router.push('/register')"
- >
- 立即注册
- </el-link>
- </div>
- </div>
- </div>
- </div>
-</template>
-
-<script>
-import { ref, reactive } from 'vue'
-import { useRouter } from 'vue-router'
-import { ElMessage } from 'element-plus'
-import { User, Lock, Operation } from '@element-plus/icons-vue'
-
-export default {
- name: 'LoginView',
- components: {
- Operation
- },
- setup() {
- const router = useRouter()
- const loginFormRef = ref()
- const loading = ref(false)
- const rememberMe = ref(false)
-
- // 表单数据
- const loginForm = reactive({
- username: '',
- password: ''
- })
-
- // 验证规则
- const loginRules = {
- username: [
- { required: true, message: '请输入用户名或邮箱', trigger: 'blur' },
- { min: 3, message: '用户名至少3个字符', trigger: 'blur' }
- ],
- password: [
- { required: true, message: '请输入密码', trigger: 'blur' },
- { min: 6, message: '密码至少6个字符', trigger: 'blur' }
- ]
- }
-
- // 登录处理
- const handleLogin = async () => {
- try {
- // 表单验证
- const valid = await loginFormRef.value.validate()
- if (!valid) return
-
- loading.value = true
-
- // 模拟登录API请求
- await new Promise(resolve => setTimeout(resolve, 1000))
-
- // 简单的登录验证(实际项目中应该调用后端API)
- if (loginForm.username === 'admin' && loginForm.password === '123456') {
- // 登录成功
- localStorage.setItem('isLoggedIn', 'true')
- localStorage.setItem('username', loginForm.username)
- localStorage.setItem('loginTime', new Date().toISOString())
-
- if (rememberMe.value) {
- localStorage.setItem('rememberLogin', 'true')
- }
-
- ElMessage.success('登录成功!欢迎回来')
- router.push('/home')
- } else {
- ElMessage.error('用户名或密码错误,请重试')
- }
-
- } catch (error) {
- console.error('登录失败:', error)
- ElMessage.error('登录失败,请稍后重试')
- } finally {
- loading.value = false
- }
- }
-
- return {
- loginFormRef,
- loginForm,
- loginRules,
- loading,
- rememberMe,
- handleLogin,
- User,
- Lock
- }
- }
-}
-</script>
-
-<style lang="scss" scoped>
-.login-page {
- min-height: 100vh;
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- position: relative;
- overflow: hidden;
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 20px;
-}
-
-// 背景装饰
-.bg-decoration {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- overflow: hidden;
- z-index: 1;
-
- .shape {
- position: absolute;
- border-radius: 50%;
- background: rgba(255, 255, 255, 0.1);
- animation: float 6s ease-in-out infinite;
-
- &.shape-1 {
- width: 200px;
- height: 200px;
- top: 10%;
- left: 10%;
- animation-delay: 0s;
- }
-
- &.shape-2 {
- width: 150px;
- height: 150px;
- top: 60%;
- right: 10%;
- animation-delay: -2s;
- }
-
- &.shape-3 {
- width: 100px;
- height: 100px;
- bottom: 20%;
- left: 20%;
- animation-delay: -4s;
- }
- }
-}
-
-@keyframes float {
- 0%, 100% {
- transform: translateY(0px) rotate(0deg);
- }
- 50% {
- transform: translateY(-20px) rotate(180deg);
- }
-}
-
-// 登录容器
-.login-container {
- position: relative;
- z-index: 10;
- width: 100%;
- max-width: 420px;
-}
-
-.login-card {
- background: rgba(255, 255, 255, 0.95);
- backdrop-filter: blur(10px);
- border-radius: 16px;
- padding: 40px;
- box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
- border: 1px solid rgba(255, 255, 255, 0.2);
-
- .login-header {
- text-align: center;
- margin-bottom: 32px;
-
- .logo {
- margin-bottom: 16px;
- }
-
- .title {
- font-size: 32px;
- font-weight: 700;
- color: #2c3e50;
- margin-bottom: 8px;
- letter-spacing: -0.5px;
- }
-
- .subtitle {
- font-size: 15px;
- color: #7f8c8d;
- margin: 0;
- font-weight: 400;
- }
- }
-
- .login-form {
- .el-form-item {
- margin-bottom: 24px;
-
- &:last-child {
- margin-bottom: 0;
- }
- }
-
- .login-options {
- display: flex;
- justify-content: space-between;
- align-items: center;
- width: 100%;
-
- .el-checkbox {
- :deep(.el-checkbox__label) {
- font-size: 14px;
- color: #606266;
- }
- }
-
- .el-link {
- font-size: 14px;
- }
- }
-
- .el-button {
- font-size: 16px;
- font-weight: 500;
- height: 48px;
- border-radius: 8px;
- }
- }
-
- .login-footer {
- text-align: center;
- margin-top: 24px;
- padding-top: 24px;
- border-top: 1px solid #ebeef5;
-
- .footer-text {
- color: #909399;
- font-size: 14px;
- margin-right: 8px;
- }
-
- .el-link {
- font-size: 14px;
- font-weight: 500;
- }
- }
-}
-
-// 响应式设计
-@media (max-width: 768px) {
- .login-page {
- padding: 16px;
- }
-
- .login-card {
- padding: 32px 24px;
-
- .login-header .title {
- font-size: 28px;
- }
- }
-}
-</style>
+<template>
+ <div class="login-page">
+ <!-- 背景装饰 -->
+ <div class="bg-decoration">
+ <div class="shape shape-1"></div>
+ <div class="shape shape-2"></div>
+ <div class="shape shape-3"></div>
+ </div>
+
+ <!-- 登录表单容器 -->
+ <div class="login-container">
+ <div class="login-card">
+ <!-- 头部信息 -->
+ <div class="login-header">
+ <div class="logo">
+ <el-icon size="48" color="#667eea"><Operation /></el-icon>
+ </div>
+ <h1 class="title">PT Tracker</h1>
+ <p class="subtitle">私有种子分享社区</p>
+ </div>
+
+ <!-- 登录表单 -->
+ <el-form
+ ref="loginFormRef"
+ :model="loginForm"
+ :rules="loginRules"
+ class="login-form"
+ size="large"
+ >
+ <el-form-item prop="user">
+ <el-input
+ v-model="loginForm.user"
+ placeholder="请输入用户名或邮箱"
+ clearable
+ :prefix-icon="User"
+ @keyup.enter="handleLogin"
+ />
+ </el-form-item>
+
+ <el-form-item prop="password">
+ <el-input
+ v-model="loginForm.password"
+ type="password"
+ placeholder="请输入密码"
+ show-password
+ :prefix-icon="Lock"
+ @keyup.enter="handleLogin"
+ />
+ </el-form-item>
+
+ <el-form-item>
+ <div class="login-options">
+ <el-checkbox v-model="rememberMe">记住登录</el-checkbox>
+ <el-link type="primary" :underline="false">忘记密码?</el-link>
+ </div>
+ </el-form-item>
+
+ <el-form-item>
+ <el-button
+ type="primary"
+ :loading="loginLoading"
+ style="width: 100%"
+ @click="handleLogin"
+ >
+ <span v-if="!loginLoading">登录</span>
+ <span v-else>登录中...</span>
+ </el-button>
+ </el-form-item>
+ </el-form>
+
+ <!-- 底部链接 -->
+ <div class="login-footer">
+ <span class="footer-text">还没有账号?</span>
+ <el-link
+ type="primary"
+ :underline="false"
+ @click="$router.push('/register')"
+ >
+ 立即注册
+ </el-link>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script>
+import { ref, reactive, computed } from 'vue'
+import { useRouter } from 'vue-router'
+import { useStore } from 'vuex'
+import { ElMessage } from 'element-plus'
+import { User, Lock, Operation } from '@element-plus/icons-vue'
+
+export default {
+ name: 'LoginView',
+ components: {
+ Operation
+ },
+ setup() {
+ const router = useRouter()
+ const store = useStore()
+ const loginFormRef = ref()
+ const rememberMe = ref(false)
+
+ // 安全地从store获取登录加载状态,添加防护检查
+ const loginLoading = computed(() => {
+ try {
+ return store?.getters?.['auth/loginLoading'] || false
+ } catch (error) {
+ console.warn('获取 loginLoading 状态失败:', error)
+ return false
+ }
+ })
+
+ // 表单数据
+ const loginForm = reactive({
+ user: '',
+ password: ''
+ })
+
+ // 验证规则
+ const loginRules = {
+ user: [
+ { required: true, message: '请输入用户名或邮箱', trigger: 'blur' },
+ { min: 3, message: '用户名至少3个字符', trigger: 'blur' }
+ ],
+ password: [
+ { required: true, message: '请输入密码', trigger: 'blur' },
+ { min: 6, message: '密码至少6个字符', trigger: 'blur' }
+ ]
+ }
+
+ // 登录处理
+ const handleLogin = async () => {
+ try {
+ // 表单验证
+ if (!loginFormRef.value) {
+ ElMessage.error('表单未准备就绪')
+ return
+ }
+
+ const valid = await loginFormRef.value.validate()
+ if (!valid) return
+
+ // 检查 store 是否可用
+ if (!store) {
+ ElMessage.error('系统初始化失败,请刷新页面重试')
+ return
+ }
+
+ // 调用store的登录action
+ await store.dispatch('auth/login', {
+ user: loginForm.user,
+ password: loginForm.password
+ })
+
+ // 如果选择记住登录,设置localStorage标记
+ if (rememberMe.value) {
+ localStorage.setItem('rememberLogin', 'true')
+ }
+
+ // 登录成功,跳转到首页
+ router.push('/home')
+
+ } catch (error) {
+ console.error('登录失败:', error)
+ ElMessage.error(error.message || '登录失败,请重试')
+ }
+ }
+
+ return {
+ loginFormRef,
+ loginForm,
+ loginRules,
+ loginLoading,
+ rememberMe,
+ handleLogin,
+ User,
+ Lock
+ }
+ }
+}
+</script>
\ No newline at end of file
diff --git a/src/views/auth/ProfileView.vue b/src/views/auth/ProfileView.vue
index e1e2544..5d11acc 100644
--- a/src/views/auth/ProfileView.vue
+++ b/src/views/auth/ProfileView.vue
@@ -1,1343 +1,1343 @@
-<template>
- <div class="profile-page">
- <div class="page-container">
- <!-- 个人信息卡片 -->
- <div class="profile-header">
- <div class="user-avatar-section">
- <div class="avatar-container">
- <el-avatar :size="120" :src="userProfile.avatar">
- {{ userProfile.username.charAt(0).toUpperCase() }}
- </el-avatar>
- <el-button
- type="primary"
- size="small"
- class="change-avatar-btn"
- @click="showAvatarDialog = true"
- >
- 更换头像
- </el-button>
- </div>
-
- <div class="user-basic-info">
- <h1 class="username">{{ userProfile.username }}</h1>
- <div class="user-title">
- <el-tag :type="getUserTitleType(userProfile.userLevel)" size="large">
- {{ userProfile.userTitle }}
- </el-tag>
- </div>
- <div class="join-info">
- <el-icon><Calendar /></el-icon>
- <span>加入时间:{{ formatDate(userProfile.joinDate) }}</span>
- </div>
- <div class="last-login">
- <el-icon><Clock /></el-icon>
- <span>最后登录:{{ formatTime(userProfile.lastLogin) }}</span>
- </div>
- </div>
- </div>
-
- <div class="user-stats-overview">
- <div class="stats-grid">
- <div class="stat-card">
- <div class="stat-icon upload">
- <el-icon size="32"><Upload /></el-icon>
- </div>
- <div class="stat-info">
- <h3>{{ userProfile.stats.uploaded }}</h3>
- <p>上传量</p>
- </div>
- </div>
-
- <div class="stat-card">
- <div class="stat-icon download">
- <el-icon size="32"><Download /></el-icon>
- </div>
- <div class="stat-info">
- <h3>{{ userProfile.stats.downloaded }}</h3>
- <p>下载量</p>
- </div>
- </div>
-
- <div class="stat-card">
- <div class="stat-icon ratio" :class="getRatioClass(userProfile.stats.ratio)">
- <el-icon size="32"><TrendCharts /></el-icon>
- </div>
- <div class="stat-info">
- <h3>{{ userProfile.stats.ratio }}</h3>
- <p>分享率</p>
- </div>
- </div>
-
- <div class="stat-card">
- <div class="stat-icon points">
- <el-icon size="32"><Star /></el-icon>
- </div>
- <div class="stat-info">
- <h3>{{ userProfile.stats.points }}</h3>
- <p>积分</p>
- </div>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 详细信息选项卡 -->
- <div class="profile-content">
- <el-tabs v-model="activeTab" type="border-card">
- <!-- 个人信息 -->
- <el-tab-pane label="个人信息" name="info">
- <div class="info-section">
- <el-form
- ref="profileFormRef"
- :model="editProfile"
- :rules="profileRules"
- label-width="120px"
- size="large"
- >
- <div class="form-section">
- <h3>基本信息</h3>
- <el-form-item label="用户名">
- <el-input v-model="editProfile.username" disabled>
- <template #suffix>
- <el-tooltip content="用户名不可修改">
- <el-icon><QuestionFilled /></el-icon>
- </el-tooltip>
- </template>
- </el-input>
- </el-form-item>
-
- <el-form-item label="邮箱地址" prop="email">
- <el-input v-model="editProfile.email" type="email" />
- </el-form-item>
-
- <el-form-item label="真实姓名" prop="realName">
- <el-input v-model="editProfile.realName" placeholder="可选填写" />
- </el-form-item>
-
- <el-form-item label="所在地区">
- <el-cascader
- v-model="editProfile.location"
- :options="locationOptions"
- placeholder="请选择地区"
- clearable
- />
- </el-form-item>
- </div>
-
- <div class="form-section">
- <h3>个人介绍</h3>
- <el-form-item label="个人签名">
- <el-input
- v-model="editProfile.signature"
- type="textarea"
- :rows="3"
- maxlength="200"
- show-word-limit
- placeholder="介绍一下自己吧..."
- />
- </el-form-item>
-
- <el-form-item label="个人网站">
- <el-input v-model="editProfile.website" placeholder="https://" />
- </el-form-item>
-
- <el-form-item label="兴趣爱好">
- <div class="interests-input">
- <el-tag
- v-for="interest in editProfile.interests"
- :key="interest"
- closable
- @close="removeInterest(interest)"
- class="interest-tag"
- >
- {{ interest }}
- </el-tag>
- <el-input
- v-if="interestInputVisible"
- ref="interestInputRef"
- v-model="interestInputValue"
- size="small"
- @keyup.enter="addInterest"
- @blur="addInterest"
- style="width: 120px;"
- />
- <el-button
- v-else
- size="small"
- @click="showInterestInput"
- >
- + 添加兴趣
- </el-button>
- </div>
- </el-form-item>
- </div>
-
- <div class="form-section">
- <h3>隐私设置</h3>
- <el-form-item label="邮箱公开">
- <el-switch v-model="editProfile.emailPublic" />
- <span class="setting-tip">是否在个人资料中显示邮箱</span>
- </el-form-item>
-
- <el-form-item label="统计公开">
- <el-switch v-model="editProfile.statsPublic" />
- <span class="setting-tip">是否公开上传下载统计</span>
- </el-form-item>
-
- <el-form-item label="活动记录">
- <el-switch v-model="editProfile.activityPublic" />
- <span class="setting-tip">是否公开活动记录</span>
- </el-form-item>
- </div>
-
- <div class="form-actions">
- <el-button @click="resetProfile">重置</el-button>
- <el-button type="primary" @click="saveProfile" :loading="saving">
- 保存修改
- </el-button>
- </div>
- </el-form>
- </div>
- </el-tab-pane>
-
- <!-- 数据统计 -->
- <el-tab-pane label="数据统计" name="stats">
- <div class="stats-section">
- <div class="stats-overview">
- <div class="overview-grid">
- <div class="overview-card">
- <h3>上传统计</h3>
- <div class="stat-details">
- <div class="detail-item">
- <span class="label">总上传量:</span>
- <span class="value">{{ userProfile.detailedStats.totalUploaded }}</span>
- </div>
- <div class="detail-item">
- <span class="label">上传种子:</span>
- <span class="value">{{ userProfile.detailedStats.uploadedTorrents }} 个</span>
- </div>
- <div class="detail-item">
- <span class="label">平均大小:</span>
- <span class="value">{{ userProfile.detailedStats.avgUploadSize }}</span>
- </div>
- </div>
- </div>
-
- <div class="overview-card">
- <h3>下载统计</h3>
- <div class="stat-details">
- <div class="detail-item">
- <span class="label">总下载量:</span>
- <span class="value">{{ userProfile.detailedStats.totalDownloaded }}</span>
- </div>
- <div class="detail-item">
- <span class="label">下载种子:</span>
- <span class="value">{{ userProfile.detailedStats.downloadedTorrents }} 个</span>
- </div>
- <div class="detail-item">
- <span class="label">完成种子:</span>
- <span class="value">{{ userProfile.detailedStats.completedTorrents }} 个</span>
- </div>
- </div>
- </div>
-
- <div class="overview-card">
- <h3>做种统计</h3>
- <div class="stat-details">
- <div class="detail-item">
- <span class="label">正在做种:</span>
- <span class="value">{{ userProfile.detailedStats.seeding }} 个</span>
- </div>
- <div class="detail-item">
- <span class="label">做种时间:</span>
- <span class="value">{{ userProfile.detailedStats.seedingTime }}</span>
- </div>
- <div class="detail-item">
- <span class="label">做种排名:</span>
- <span class="value">第 {{ userProfile.detailedStats.seedingRank }} 名</span>
- </div>
- </div>
- </div>
-
- <div class="overview-card">
- <h3>积分记录</h3>
- <div class="stat-details">
- <div class="detail-item">
- <span class="label">当前积分:</span>
- <span class="value">{{ userProfile.stats.points }}</span>
- </div>
- <div class="detail-item">
- <span class="label">累计获得:</span>
- <span class="value">{{ userProfile.detailedStats.totalEarnedPoints }}</span>
- </div>
- <div class="detail-item">
- <span class="label">累计消费:</span>
- <span class="value">{{ userProfile.detailedStats.totalSpentPoints }}</span>
- </div>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 数据图表 -->
- <div class="charts-section">
- <div class="chart-card">
- <h3>上传下载趋势</h3>
- <div class="chart-placeholder">
- <el-icon size="48" color="#e4e7ed"><TrendCharts /></el-icon>
- <p>图表功能开发中...</p>
- </div>
- </div>
- </div>
- </div>
- </el-tab-pane>
-
- <!-- 我的种子 -->
- <el-tab-pane label="我的种子" name="torrents">
- <div class="torrents-section">
- <div class="section-header">
- <h3>我上传的种子</h3>
- <el-button type="primary" :icon="Upload" @click="$router.push('/upload')">
- 上传新种子
- </el-button>
- </div>
-
- <el-table :data="userTorrents" stripe>
- <el-table-column label="种子名称" min-width="300">
- <template #default="{ row }">
- <div class="torrent-info">
- <el-tag :type="getCategoryType(row.category)" size="small">
- {{ getCategoryName(row.category) }}
- </el-tag>
- <span class="torrent-title">{{ row.title }}</span>
- </div>
- </template>
- </el-table-column>
-
- <el-table-column label="大小" prop="size" width="100" />
- <el-table-column label="做种" prop="seeders" width="80" align="center" />
- <el-table-column label="下载" prop="leechers" width="80" align="center" />
- <el-table-column label="完成" prop="downloads" width="80" align="center" />
- <el-table-column label="上传时间" width="120">
- <template #default="{ row }">
- {{ formatDate(row.uploadTime) }}
- </template>
- </el-table-column>
-
- <el-table-column label="操作" width="120" align="center">
- <template #default="{ row }">
- <el-button
- type="primary"
- size="small"
- @click="$router.push(`/torrent/${row.id}`)"
- >
- 查看
- </el-button>
- </template>
- </el-table-column>
- </el-table>
-
- <div class="pagination-wrapper">
- <el-pagination
- v-model:current-page="torrentsPage"
- :page-size="10"
- :total="userTorrents.length"
- layout="prev, pager, next"
- small
- />
- </div>
- </div>
- </el-tab-pane>
-
- <!-- 活动记录 -->
- <el-tab-pane label="活动记录" name="activity">
- <div class="activity-section">
- <div class="activity-filters">
- <el-select v-model="activityFilter" placeholder="活动类型">
- <el-option label="全部活动" value="" />
- <el-option label="上传种子" value="upload" />
- <el-option label="下载种子" value="download" />
- <el-option label="论坛发帖" value="post" />
- <el-option label="积分变动" value="points" />
- </el-select>
- </div>
-
- <div class="activity-timeline">
- <el-timeline>
- <el-timeline-item
- v-for="activity in filteredActivities"
- :key="activity.id"
- :timestamp="formatTime(activity.time)"
- :type="getActivityType(activity.type)"
- >
- <div class="activity-content">
- <div class="activity-header">
- <el-icon>
- <component :is="getActivityIcon(activity.type)" />
- </el-icon>
- <span class="activity-title">{{ activity.title }}</span>
- </div>
- <div class="activity-description">{{ activity.description }}</div>
- </div>
- </el-timeline-item>
- </el-timeline>
- </div>
- </div>
- </el-tab-pane>
-
- <!-- 安全设置 -->
- <el-tab-pane label="安全设置" name="security">
- <div class="security-section">
- <div class="security-card">
- <h3>修改密码</h3>
- <el-form
- ref="passwordFormRef"
- :model="passwordForm"
- :rules="passwordRules"
- label-width="120px"
- >
- <el-form-item label="当前密码" prop="currentPassword">
- <el-input
- v-model="passwordForm.currentPassword"
- type="password"
- show-password
- placeholder="请输入当前密码"
- />
- </el-form-item>
-
- <el-form-item label="新密码" prop="newPassword">
- <el-input
- v-model="passwordForm.newPassword"
- type="password"
- show-password
- placeholder="请输入新密码"
- />
- </el-form-item>
-
- <el-form-item label="确认密码" prop="confirmPassword">
- <el-input
- v-model="passwordForm.confirmPassword"
- type="password"
- show-password
- placeholder="请再次输入新密码"
- />
- </el-form-item>
-
- <el-form-item>
- <el-button type="primary" @click="changePassword" :loading="changingPassword">
- 修改密码
- </el-button>
- </el-form-item>
- </el-form>
- </div>
-
- <div class="security-card">
- <h3>登录记录</h3>
- <el-table :data="loginHistory" stripe>
- <el-table-column label="登录时间" width="180">
- <template #default="{ row }">
- {{ formatDateTime(row.time) }}
- </template>
- </el-table-column>
- <el-table-column label="IP地址" prop="ip" width="150" />
- <el-table-column label="设备信息" prop="device" />
- <el-table-column label="登录结果" width="100">
- <template #default="{ row }">
- <el-tag :type="row.success ? 'success' : 'danger'" size="small">
- {{ row.success ? '成功' : '失败' }}
- </el-tag>
- </template>
- </el-table-column>
- </el-table>
- </div>
- </div>
- </el-tab-pane>
- </el-tabs>
- </div>
- </div>
-
- <!-- 更换头像对话框 -->
- <el-dialog v-model="showAvatarDialog" title="更换头像" width="400px">
- <div class="avatar-upload">
- <el-upload
- ref="avatarUploadRef"
- :auto-upload="false"
- :limit="1"
- accept="image/*"
- :on-change="handleAvatarChange"
- list-type="picture-card"
- class="avatar-uploader"
- >
- <el-icon><Plus /></el-icon>
- </el-upload>
- <div class="upload-tips">
- <p>支持 JPG、PNG 格式</p>
- <p>建议尺寸 200x200 像素</p>
- <p>文件大小不超过 2MB</p>
- </div>
- </div>
-
- <template #footer>
- <el-button @click="showAvatarDialog = false">取消</el-button>
- <el-button type="primary" @click="uploadAvatar" :loading="uploadingAvatar">
- 上传头像
- </el-button>
- </template>
- </el-dialog>
- </div>
-</template>
-
-<script>
-import { ref, reactive, computed, onMounted, nextTick } from 'vue'
-import { useRouter } from 'vue-router'
-import { ElMessage } from 'element-plus'
-import {
- Calendar,
- Clock,
- Upload,
- Download,
- TrendCharts,
- Star,
- QuestionFilled,
- Plus,
- ChatDotRound,
- Flag,
- Coin
-} from '@element-plus/icons-vue'
-
-export default {
- name: 'ProfileView',
- setup() {
- const router = useRouter()
- const profileFormRef = ref(null)
- const passwordFormRef = ref(null)
- const avatarUploadRef = ref(null)
- const interestInputRef = ref(null)
-
- const activeTab = ref('info')
- const showAvatarDialog = ref(false)
- const saving = ref(false)
- const changingPassword = ref(false)
- const uploadingAvatar = ref(false)
- const interestInputVisible = ref(false)
- const interestInputValue = ref('')
- const activityFilter = ref('')
- const torrentsPage = ref(1)
-
- const userProfile = ref({
- username: 'MovieExpert',
- email: 'movieexpert@example.com',
- realName: '',
- avatar: '',
- userLevel: 5,
- userTitle: '资深会员',
- joinDate: '2023-01-15T10:00:00',
- lastLogin: '2025-06-03T14:30:00',
- location: ['北京市', '朝阳区'],
- signature: '热爱电影,分享快乐!',
- website: 'https://movieblog.com',
- interests: ['电影', '音乐', '科技', '摄影'],
- emailPublic: false,
- statsPublic: true,
- activityPublic: true,
- stats: {
- uploaded: '256.8 GB',
- downloaded: '89.6 GB',
- ratio: '2.87',
- points: '15,680'
- },
- detailedStats: {
- totalUploaded: '256.8 GB',
- uploadedTorrents: 45,
- avgUploadSize: '5.7 GB',
- totalDownloaded: '89.6 GB',
- downloadedTorrents: 123,
- completedTorrents: 118,
- seeding: 32,
- seedingTime: '1,245 小时',
- seedingRank: 86,
- totalEarnedPoints: '28,940',
- totalSpentPoints: '13,260'
- }
- })
-
- const editProfile = reactive({
- username: '',
- email: '',
- realName: '',
- location: [],
- signature: '',
- website: '',
- interests: [],
- emailPublic: false,
- statsPublic: true,
- activityPublic: true
- })
-
- const passwordForm = reactive({
- currentPassword: '',
- newPassword: '',
- confirmPassword: ''
- })
-
- const profileRules = {
- email: [
- { required: true, message: '请输入邮箱地址', trigger: 'blur' },
- { type: 'email', message: '请输入正确的邮箱格式', trigger: 'blur' }
- ]
- }
-
- const passwordRules = {
- currentPassword: [
- { required: true, message: '请输入当前密码', trigger: 'blur' }
- ],
- newPassword: [
- { required: true, message: '请输入新密码', trigger: 'blur' },
- { min: 6, message: '密码长度至少6个字符', trigger: 'blur' }
- ],
- confirmPassword: [
- { required: true, message: '请确认新密码', trigger: 'blur' },
- {
- validator: (rule, value, callback) => {
- if (value !== passwordForm.newPassword) {
- callback(new Error('两次输入的密码不一致'))
- } else {
- callback()
- }
- },
- trigger: 'blur'
- }
- ]
- }
-
- const locationOptions = [
- {
- value: '北京市',
- label: '北京市',
- children: [
- { value: '朝阳区', label: '朝阳区' },
- { value: '海淀区', label: '海淀区' },
- { value: '丰台区', label: '丰台区' }
- ]
- },
- {
- value: '上海市',
- label: '上海市',
- children: [
- { value: '浦东新区', label: '浦东新区' },
- { value: '黄浦区', label: '黄浦区' },
- { value: '静安区', label: '静安区' }
- ]
- }
- ]
-
- const userTorrents = ref([
- {
- id: 1,
- title: '[4K蓝光原盘] 阿凡达:水之道',
- category: 'movie',
- size: '85.6 GB',
- seeders: 45,
- leechers: 12,
- downloads: 234,
- uploadTime: '2025-05-15T10:00:00'
- },
- {
- id: 2,
- title: '[FLAC] 古典音乐合集',
- category: 'music',
- size: '2.3 GB',
- seeders: 23,
- leechers: 5,
- downloads: 89,
- uploadTime: '2025-04-20T15:30:00'
- }
- ])
-
- const activities = ref([
- {
- id: 1,
- type: 'upload',
- title: '上传种子',
- description: '上传了《阿凡达:水之道》4K蓝光原盘',
- time: '2025-06-03T10:30:00'
- },
- {
- id: 2,
- type: 'download',
- title: '下载种子',
- description: '下载了《星际穿越》IMAX版本',
- time: '2025-06-02T14:20:00'
- },
- {
- id: 3,
- type: 'post',
- title: '发布主题',
- description: '在电影讨论区发布了新主题',
- time: '2025-06-01T16:45:00'
- },
- {
- id: 4,
- type: 'points',
- title: '积分变动',
- description: '做种奖励获得 +50 积分',
- time: '2025-05-31T09:15:00'
- }
- ])
-
- const loginHistory = ref([
- {
- time: '2025-06-03T14:30:00',
- ip: '192.168.1.100',
- device: 'Windows 11 / Chrome 120',
- success: true
- },
- {
- time: '2025-06-02T09:15:00',
- ip: '192.168.1.100',
- device: 'Windows 11 / Chrome 120',
- success: true
- },
- {
- time: '2025-06-01T22:30:00',
- ip: '192.168.1.100',
- device: 'Android / Chrome Mobile',
- success: true
- }
- ])
-
- const filteredActivities = computed(() => {
- if (!activityFilter.value) return activities.value
- return activities.value.filter(activity => activity.type === activityFilter.value)
- })
-
- onMounted(() => {
- loadUserProfile()
- })
-
- const loadUserProfile = () => {
- // 加载用户资料到编辑表单
- Object.assign(editProfile, {
- username: userProfile.value.username,
- email: userProfile.value.email,
- realName: userProfile.value.realName,
- location: userProfile.value.location,
- signature: userProfile.value.signature,
- website: userProfile.value.website,
- interests: [...userProfile.value.interests],
- emailPublic: userProfile.value.emailPublic,
- statsPublic: userProfile.value.statsPublic,
- activityPublic: userProfile.value.activityPublic
- })
- }
-
- const formatDate = (dateString) => {
- const date = new Date(dateString)
- return date.toLocaleDateString('zh-CN')
- }
-
- const formatTime = (timeString) => {
- const date = new Date(timeString)
- const now = new Date()
- const diff = now - date
- const hours = Math.floor(diff / (1000 * 60 * 60))
-
- if (hours < 1) return '刚刚'
- if (hours < 24) return `${hours}小时前`
- const days = Math.floor(hours / 24)
- if (days < 7) return `${days}天前`
-
- return date.toLocaleDateString('zh-CN')
- }
-
- const formatDateTime = (dateString) => {
- const date = new Date(dateString)
- return date.toLocaleString('zh-CN')
- }
-
- const getUserTitleType = (level) => {
- if (level >= 8) return 'danger' // 管理员
- if (level >= 6) return 'warning' // 资深会员
- if (level >= 4) return 'success' // 正式会员
- if (level >= 2) return 'info' // 初级会员
- return 'default' // 新手
- }
-
- const getRatioClass = (ratio) => {
- const r = parseFloat(ratio)
- if (r >= 2) return 'excellent'
- if (r >= 1) return 'good'
- return 'warning'
- }
-
- const getCategoryType = (category) => {
- const types = {
- 'movie': 'primary',
- 'tv': 'info',
- 'music': 'success',
- 'software': 'warning',
- 'game': 'danger'
- }
- return types[category] || 'default'
- }
-
- const getCategoryName = (category) => {
- const names = {
- 'movie': '电影',
- 'tv': '电视剧',
- 'music': '音乐',
- 'software': '软件',
- 'game': '游戏'
- }
- return names[category] || category
- }
-
- const getActivityType = (type) => {
- const types = {
- 'upload': 'success',
- 'download': 'primary',
- 'post': 'warning',
- 'points': 'info'
- }
- return types[type] || 'primary'
- }
-
- const getActivityIcon = (type) => {
- const icons = {
- 'upload': 'Upload',
- 'download': 'Download',
- 'post': 'ChatDotRound',
- 'points': 'Coin'
- }
- return icons[type] || 'Star'
- }
-
- const showInterestInput = () => {
- interestInputVisible.value = true
- nextTick(() => {
- interestInputRef.value?.focus()
- })
- }
-
- const addInterest = () => {
- const interest = interestInputValue.value.trim()
- if (interest && !editProfile.interests.includes(interest)) {
- editProfile.interests.push(interest)
- }
- interestInputVisible.value = false
- interestInputValue.value = ''
- }
-
- const removeInterest = (interest) => {
- const index = editProfile.interests.indexOf(interest)
- if (index > -1) {
- editProfile.interests.splice(index, 1)
- }
- }
-
- const saveProfile = async () => {
- try {
- await profileFormRef.value?.validate()
-
- saving.value = true
-
- // 模拟保存过程
- await new Promise(resolve => setTimeout(resolve, 1500))
-
- // 更新用户资料
- Object.assign(userProfile.value, editProfile)
-
- ElMessage.success('个人资料保存成功')
-
- } catch (error) {
- console.error('表单验证失败:', error)
- } finally {
- saving.value = false
- }
- }
-
- const resetProfile = () => {
- loadUserProfile()
- ElMessage.info('已重置为原始数据')
- }
-
- const changePassword = async () => {
- try {
- await passwordFormRef.value?.validate()
-
- changingPassword.value = true
-
- // 模拟密码修改过程
- await new Promise(resolve => setTimeout(resolve, 1500))
-
- // 重置表单
- passwordFormRef.value?.resetFields()
- Object.assign(passwordForm, {
- currentPassword: '',
- newPassword: '',
- confirmPassword: ''
- })
-
- ElMessage.success('密码修改成功')
-
- } catch (error) {
- console.error('表单验证失败:', error)
- } finally {
- changingPassword.value = false
- }
- }
-
- const handleAvatarChange = (file) => {
- const isImage = file.raw.type.startsWith('image/')
- const isLt2M = file.raw.size / 1024 / 1024 < 2
-
- if (!isImage) {
- ElMessage.error('只能上传图片文件!')
- return false
- }
- if (!isLt2M) {
- ElMessage.error('图片大小不能超过 2MB!')
- return false
- }
-
- return true
- }
-
- const uploadAvatar = async () => {
- const files = avatarUploadRef.value?.uploadFiles
- if (!files || files.length === 0) {
- ElMessage.warning('请选择头像文件')
- return
- }
-
- uploadingAvatar.value = true
- try {
- // 模拟上传过程
- await new Promise(resolve => setTimeout(resolve, 2000))
-
- // 更新头像URL
- userProfile.value.avatar = URL.createObjectURL(files[0].raw)
-
- ElMessage.success('头像上传成功')
- showAvatarDialog.value = false
- avatarUploadRef.value?.clearFiles()
-
- } catch (error) {
- ElMessage.error('头像上传失败')
- } finally {
- uploadingAvatar.value = false
- }
- }
-
- return {
- activeTab,
- showAvatarDialog,
- saving,
- changingPassword,
- uploadingAvatar,
- interestInputVisible,
- interestInputValue,
- activityFilter,
- torrentsPage,
- userProfile,
- editProfile,
- passwordForm,
- profileRules,
- passwordRules,
- locationOptions,
- userTorrents,
- filteredActivities,
- loginHistory,
- profileFormRef,
- passwordFormRef,
- avatarUploadRef,
- interestInputRef,
- formatDate,
- formatTime,
- formatDateTime,
- getUserTitleType,
- getRatioClass,
- getCategoryType,
- getCategoryName,
- getActivityType,
- getActivityIcon,
- showInterestInput,
- addInterest,
- removeInterest,
- saveProfile,
- resetProfile,
- changePassword,
- handleAvatarChange,
- uploadAvatar,
- Calendar,
- Clock,
- Upload,
- Download,
- TrendCharts,
- Star,
- QuestionFilled,
- Plus,
- ChatDotRound,
- Flag,
- Coin
- }
- }
-}
-</script>
-
-<style lang="scss" scoped>
-.profile-page {
- max-width: 1200px;
- margin: 0 auto;
- padding: 24px;
- background: #f5f5f5;
- min-height: 100vh;
-}
-
-.profile-header {
- background: #fff;
- border-radius: 12px;
- padding: 32px;
- margin-bottom: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- display: grid;
- grid-template-columns: 1fr 1fr;
- gap: 32px;
-
- .user-avatar-section {
- display: flex;
- gap: 24px;
-
- .avatar-container {
- text-align: center;
-
- .change-avatar-btn {
- margin-top: 12px;
- }
- }
-
- .user-basic-info {
- flex: 1;
-
- .username {
- font-size: 28px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 12px 0;
- }
-
- .user-title {
- margin-bottom: 16px;
- }
-
- .join-info, .last-login {
- display: flex;
- align-items: center;
- gap: 8px;
- font-size: 14px;
- color: #7f8c8d;
- margin-bottom: 8px;
- }
- }
- }
-
- .user-stats-overview {
- .stats-grid {
- display: grid;
- grid-template-columns: repeat(2, 1fr);
- gap: 16px;
-
- .stat-card {
- background: #f8f9fa;
- border-radius: 8px;
- padding: 20px;
- display: flex;
- align-items: center;
- gap: 16px;
-
- .stat-icon {
- width: 48px;
- height: 48px;
- border-radius: 50%;
- display: flex;
- align-items: center;
- justify-content: center;
-
- &.upload { background: rgba(103, 194, 58, 0.1); color: #67c23a; }
- &.download { background: rgba(64, 158, 255, 0.1); color: #409eff; }
- &.ratio {
- &.excellent { background: rgba(103, 194, 58, 0.1); color: #67c23a; }
- &.good { background: rgba(230, 162, 60, 0.1); color: #e6a23c; }
- &.warning { background: rgba(245, 108, 108, 0.1); color: #f56c6c; }
- }
- &.points { background: rgba(245, 108, 108, 0.1); color: #f56c6c; }
- }
-
- .stat-info {
- h3 {
- font-size: 20px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 4px 0;
- }
-
- p {
- font-size: 14px;
- color: #7f8c8d;
- margin: 0;
- }
- }
- }
- }
- }
-}
-
-.profile-content {
- background: #fff;
- border-radius: 12px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- :deep(.el-tabs__content) {
- padding: 24px;
- }
-}
-
-.info-section {
- .form-section {
- margin-bottom: 32px;
-
- h3 {
- font-size: 18px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 20px 0;
- padding-bottom: 8px;
- border-bottom: 2px solid #f0f0f0;
- }
- }
-
- .interests-input {
- display: flex;
- flex-wrap: wrap;
- gap: 8px;
- align-items: center;
-
- .interest-tag {
- margin: 0;
- }
- }
-
- .setting-tip {
- margin-left: 12px;
- font-size: 12px;
- color: #909399;
- }
-
- .form-actions {
- text-align: center;
- margin-top: 32px;
-
- .el-button {
- margin: 0 8px;
- min-width: 100px;
- }
- }
-}
-
-.stats-section {
- .stats-overview {
- margin-bottom: 32px;
-
- .overview-grid {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
- gap: 20px;
-
- .overview-card {
- background: #f8f9fa;
- border-radius: 8px;
- padding: 24px;
-
- h3 {
- font-size: 16px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 16px 0;
- }
-
- .stat-details {
- .detail-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 12px;
-
- .label {
- font-size: 14px;
- color: #7f8c8d;
- }
-
- .value {
- font-size: 14px;
- font-weight: 600;
- color: #2c3e50;
- }
- }
- }
- }
- }
- }
-
- .charts-section {
- .chart-card {
- background: #f8f9fa;
- border-radius: 8px;
- padding: 24px;
-
- h3 {
- font-size: 16px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 20px 0;
- }
-
- .chart-placeholder {
- text-align: center;
- padding: 60px 0;
- color: #909399;
-
- p {
- margin: 12px 0 0 0;
- }
- }
- }
- }
-}
-
-.torrents-section {
- .section-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20px;
-
- h3 {
- font-size: 18px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0;
- }
- }
-
- .torrent-info {
- display: flex;
- align-items: center;
- gap: 12px;
-
- .torrent-title {
- font-weight: 500;
- }
- }
-
- .pagination-wrapper {
- margin-top: 16px;
- text-align: center;
- }
-}
-
-.activity-section {
- .activity-filters {
- margin-bottom: 24px;
-
- .el-select {
- width: 150px;
- }
- }
-
- .activity-timeline {
- .activity-content {
- .activity-header {
- display: flex;
- align-items: center;
- gap: 8px;
- margin-bottom: 8px;
-
- .activity-title {
- font-weight: 600;
- color: #2c3e50;
- }
- }
-
- .activity-description {
- font-size: 14px;
- color: #7f8c8d;
- line-height: 1.5;
- }
- }
- }
-}
-
-.security-section {
- .security-card {
- background: #f8f9fa;
- border-radius: 8px;
- padding: 24px;
- margin-bottom: 24px;
-
- h3 {
- font-size: 18px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 20px 0;
- }
- }
-}
-
-.avatar-upload {
- text-align: center;
-
- .avatar-uploader {
- margin-bottom: 16px;
- }
-
- .upload-tips {
- font-size: 12px;
- color: #909399;
-
- p {
- margin: 4px 0;
- }
- }
-}
-
-@media (max-width: 768px) {
- .profile-page {
- padding: 16px;
- }
-
- .profile-header {
- grid-template-columns: 1fr;
- gap: 24px;
-
- .user-avatar-section {
- flex-direction: column;
- text-align: center;
- }
-
- .user-stats-overview .stats-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .stats-overview .overview-grid {
- grid-template-columns: 1fr;
- }
-
- .torrents-section .section-header {
- flex-direction: column;
- gap: 16px;
- align-items: flex-start;
- }
-}
+<template>
+ <div class="profile-page">
+ <div class="page-container">
+ <!-- 个人信息卡片 -->
+ <div class="profile-header">
+ <div class="user-avatar-section">
+ <div class="avatar-container">
+ <el-avatar :size="120" :src="userProfile.avatar">
+ {{ userProfile.username.charAt(0).toUpperCase() }}
+ </el-avatar>
+ <el-button
+ type="primary"
+ size="small"
+ class="change-avatar-btn"
+ @click="showAvatarDialog = true"
+ >
+ 更换头像
+ </el-button>
+ </div>
+
+ <div class="user-basic-info">
+ <h1 class="username">{{ userProfile.username }}</h1>
+ <div class="user-title">
+ <el-tag :type="getUserTitleType(userProfile.userLevel)" size="large">
+ {{ userProfile.userTitle }}
+ </el-tag>
+ </div>
+ <div class="join-info">
+ <el-icon><Calendar /></el-icon>
+ <span>加入时间:{{ formatDate(userProfile.joinDate) }}</span>
+ </div>
+ <div class="last-login">
+ <el-icon><Clock /></el-icon>
+ <span>最后登录:{{ formatTime(userProfile.lastLogin) }}</span>
+ </div>
+ </div>
+ </div>
+
+ <div class="user-stats-overview">
+ <div class="stats-grid">
+ <div class="stat-card">
+ <div class="stat-icon upload">
+ <el-icon size="32"><Upload /></el-icon>
+ </div>
+ <div class="stat-info">
+ <h3>{{ userProfile.stats.uploaded }}</h3>
+ <p>上传量</p>
+ </div>
+ </div>
+
+ <div class="stat-card">
+ <div class="stat-icon download">
+ <el-icon size="32"><Download /></el-icon>
+ </div>
+ <div class="stat-info">
+ <h3>{{ userProfile.stats.downloaded }}</h3>
+ <p>下载量</p>
+ </div>
+ </div>
+
+ <div class="stat-card">
+ <div class="stat-icon ratio" :class="getRatioClass(userProfile.stats.ratio)">
+ <el-icon size="32"><TrendCharts /></el-icon>
+ </div>
+ <div class="stat-info">
+ <h3>{{ userProfile.stats.ratio }}</h3>
+ <p>分享率</p>
+ </div>
+ </div>
+
+ <div class="stat-card">
+ <div class="stat-icon points">
+ <el-icon size="32"><Star /></el-icon>
+ </div>
+ <div class="stat-info">
+ <h3>{{ userProfile.stats.points }}</h3>
+ <p>积分</p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- 详细信息选项卡 -->
+ <div class="profile-content">
+ <el-tabs v-model="activeTab" type="border-card">
+ <!-- 个人信息 -->
+ <el-tab-pane label="个人信息" name="info">
+ <div class="info-section">
+ <el-form
+ ref="profileFormRef"
+ :model="editProfile"
+ :rules="profileRules"
+ label-width="120px"
+ size="large"
+ >
+ <div class="form-section">
+ <h3>基本信息</h3>
+ <el-form-item label="用户名">
+ <el-input v-model="editProfile.username" disabled>
+ <template #suffix>
+ <el-tooltip content="用户名不可修改">
+ <el-icon><QuestionFilled /></el-icon>
+ </el-tooltip>
+ </template>
+ </el-input>
+ </el-form-item>
+
+ <el-form-item label="邮箱地址" prop="email">
+ <el-input v-model="editProfile.email" type="email" />
+ </el-form-item>
+
+ <el-form-item label="真实姓名" prop="realName">
+ <el-input v-model="editProfile.realName" placeholder="可选填写" />
+ </el-form-item>
+
+ <el-form-item label="所在地区">
+ <el-cascader
+ v-model="editProfile.location"
+ :options="locationOptions"
+ placeholder="请选择地区"
+ clearable
+ />
+ </el-form-item>
+ </div>
+
+ <div class="form-section">
+ <h3>个人介绍</h3>
+ <el-form-item label="个人签名">
+ <el-input
+ v-model="editProfile.signature"
+ type="textarea"
+ :rows="3"
+ maxlength="200"
+ show-word-limit
+ placeholder="介绍一下自己吧..."
+ />
+ </el-form-item>
+
+ <el-form-item label="个人网站">
+ <el-input v-model="editProfile.website" placeholder="https://" />
+ </el-form-item>
+
+ <el-form-item label="兴趣爱好">
+ <div class="interests-input">
+ <el-tag
+ v-for="interest in editProfile.interests"
+ :key="interest"
+ closable
+ @close="removeInterest(interest)"
+ class="interest-tag"
+ >
+ {{ interest }}
+ </el-tag>
+ <el-input
+ v-if="interestInputVisible"
+ ref="interestInputRef"
+ v-model="interestInputValue"
+ size="small"
+ @keyup.enter="addInterest"
+ @blur="addInterest"
+ style="width: 120px;"
+ />
+ <el-button
+ v-else
+ size="small"
+ @click="showInterestInput"
+ >
+ + 添加兴趣
+ </el-button>
+ </div>
+ </el-form-item>
+ </div>
+
+ <div class="form-section">
+ <h3>隐私设置</h3>
+ <el-form-item label="邮箱公开">
+ <el-switch v-model="editProfile.emailPublic" />
+ <span class="setting-tip">是否在个人资料中显示邮箱</span>
+ </el-form-item>
+
+ <el-form-item label="统计公开">
+ <el-switch v-model="editProfile.statsPublic" />
+ <span class="setting-tip">是否公开上传下载统计</span>
+ </el-form-item>
+
+ <el-form-item label="活动记录">
+ <el-switch v-model="editProfile.activityPublic" />
+ <span class="setting-tip">是否公开活动记录</span>
+ </el-form-item>
+ </div>
+
+ <div class="form-actions">
+ <el-button @click="resetProfile">重置</el-button>
+ <el-button type="primary" @click="saveProfile" :loading="saving">
+ 保存修改
+ </el-button>
+ </div>
+ </el-form>
+ </div>
+ </el-tab-pane>
+
+ <!-- 数据统计 -->
+ <el-tab-pane label="数据统计" name="stats">
+ <div class="stats-section">
+ <div class="stats-overview">
+ <div class="overview-grid">
+ <div class="overview-card">
+ <h3>上传统计</h3>
+ <div class="stat-details">
+ <div class="detail-item">
+ <span class="label">总上传量:</span>
+ <span class="value">{{ userProfile.detailedStats.totalUploaded }}</span>
+ </div>
+ <div class="detail-item">
+ <span class="label">上传种子:</span>
+ <span class="value">{{ userProfile.detailedStats.uploadedTorrents }} 个</span>
+ </div>
+ <div class="detail-item">
+ <span class="label">平均大小:</span>
+ <span class="value">{{ userProfile.detailedStats.avgUploadSize }}</span>
+ </div>
+ </div>
+ </div>
+
+ <div class="overview-card">
+ <h3>下载统计</h3>
+ <div class="stat-details">
+ <div class="detail-item">
+ <span class="label">总下载量:</span>
+ <span class="value">{{ userProfile.detailedStats.totalDownloaded }}</span>
+ </div>
+ <div class="detail-item">
+ <span class="label">下载种子:</span>
+ <span class="value">{{ userProfile.detailedStats.downloadedTorrents }} 个</span>
+ </div>
+ <div class="detail-item">
+ <span class="label">完成种子:</span>
+ <span class="value">{{ userProfile.detailedStats.completedTorrents }} 个</span>
+ </div>
+ </div>
+ </div>
+
+ <div class="overview-card">
+ <h3>做种统计</h3>
+ <div class="stat-details">
+ <div class="detail-item">
+ <span class="label">正在做种:</span>
+ <span class="value">{{ userProfile.detailedStats.seeding }} 个</span>
+ </div>
+ <div class="detail-item">
+ <span class="label">做种时间:</span>
+ <span class="value">{{ userProfile.detailedStats.seedingTime }}</span>
+ </div>
+ <div class="detail-item">
+ <span class="label">做种排名:</span>
+ <span class="value">第 {{ userProfile.detailedStats.seedingRank }} 名</span>
+ </div>
+ </div>
+ </div>
+
+ <div class="overview-card">
+ <h3>积分记录</h3>
+ <div class="stat-details">
+ <div class="detail-item">
+ <span class="label">当前积分:</span>
+ <span class="value">{{ userProfile.stats.points }}</span>
+ </div>
+ <div class="detail-item">
+ <span class="label">累计获得:</span>
+ <span class="value">{{ userProfile.detailedStats.totalEarnedPoints }}</span>
+ </div>
+ <div class="detail-item">
+ <span class="label">累计消费:</span>
+ <span class="value">{{ userProfile.detailedStats.totalSpentPoints }}</span>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- 数据图表 -->
+ <div class="charts-section">
+ <div class="chart-card">
+ <h3>上传下载趋势</h3>
+ <div class="chart-placeholder">
+ <el-icon size="48" color="#e4e7ed"><TrendCharts /></el-icon>
+ <p>图表功能开发中...</p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </el-tab-pane>
+
+ <!-- 我的种子 -->
+ <el-tab-pane label="我的种子" name="torrents">
+ <div class="torrents-section">
+ <div class="section-header">
+ <h3>我上传的种子</h3>
+ <el-button type="primary" :icon="Upload" @click="$router.push('/upload')">
+ 上传新种子
+ </el-button>
+ </div>
+
+ <el-table :data="userTorrents" stripe>
+ <el-table-column label="种子名称" min-width="300">
+ <template #default="{ row }">
+ <div class="torrent-info">
+ <el-tag :type="getCategoryType(row.category)" size="small">
+ {{ getCategoryName(row.category) }}
+ </el-tag>
+ <span class="torrent-title">{{ row.title }}</span>
+ </div>
+ </template>
+ </el-table-column>
+
+ <el-table-column label="大小" prop="size" width="100" />
+ <el-table-column label="做种" prop="seeders" width="80" align="center" />
+ <el-table-column label="下载" prop="leechers" width="80" align="center" />
+ <el-table-column label="完成" prop="downloads" width="80" align="center" />
+ <el-table-column label="上传时间" width="120">
+ <template #default="{ row }">
+ {{ formatDate(row.uploadTime) }}
+ </template>
+ </el-table-column>
+
+ <el-table-column label="操作" width="120" align="center">
+ <template #default="{ row }">
+ <el-button
+ type="primary"
+ size="small"
+ @click="$router.push(`/torrent/${row.id}`)"
+ >
+ 查看
+ </el-button>
+ </template>
+ </el-table-column>
+ </el-table>
+
+ <div class="pagination-wrapper">
+ <el-pagination
+ v-model:current-page="torrentsPage"
+ :page-size="10"
+ :total="userTorrents.length"
+ layout="prev, pager, next"
+ small
+ />
+ </div>
+ </div>
+ </el-tab-pane>
+
+ <!-- 活动记录 -->
+ <el-tab-pane label="活动记录" name="activity">
+ <div class="activity-section">
+ <div class="activity-filters">
+ <el-select v-model="activityFilter" placeholder="活动类型">
+ <el-option label="全部活动" value="" />
+ <el-option label="上传种子" value="upload" />
+ <el-option label="下载种子" value="download" />
+ <el-option label="论坛发帖" value="post" />
+ <el-option label="积分变动" value="points" />
+ </el-select>
+ </div>
+
+ <div class="activity-timeline">
+ <el-timeline>
+ <el-timeline-item
+ v-for="activity in filteredActivities"
+ :key="activity.id"
+ :timestamp="formatTime(activity.time)"
+ :type="getActivityType(activity.type)"
+ >
+ <div class="activity-content">
+ <div class="activity-header">
+ <el-icon>
+ <component :is="getActivityIcon(activity.type)" />
+ </el-icon>
+ <span class="activity-title">{{ activity.title }}</span>
+ </div>
+ <div class="activity-description">{{ activity.description }}</div>
+ </div>
+ </el-timeline-item>
+ </el-timeline>
+ </div>
+ </div>
+ </el-tab-pane>
+
+ <!-- 安全设置 -->
+ <el-tab-pane label="安全设置" name="security">
+ <div class="security-section">
+ <div class="security-card">
+ <h3>修改密码</h3>
+ <el-form
+ ref="passwordFormRef"
+ :model="passwordForm"
+ :rules="passwordRules"
+ label-width="120px"
+ >
+ <el-form-item label="当前密码" prop="currentPassword">
+ <el-input
+ v-model="passwordForm.currentPassword"
+ type="password"
+ show-password
+ placeholder="请输入当前密码"
+ />
+ </el-form-item>
+
+ <el-form-item label="新密码" prop="newPassword">
+ <el-input
+ v-model="passwordForm.newPassword"
+ type="password"
+ show-password
+ placeholder="请输入新密码"
+ />
+ </el-form-item>
+
+ <el-form-item label="确认密码" prop="confirmPassword">
+ <el-input
+ v-model="passwordForm.confirmPassword"
+ type="password"
+ show-password
+ placeholder="请再次输入新密码"
+ />
+ </el-form-item>
+
+ <el-form-item>
+ <el-button type="primary" @click="changePassword" :loading="changingPassword">
+ 修改密码
+ </el-button>
+ </el-form-item>
+ </el-form>
+ </div>
+
+ <div class="security-card">
+ <h3>登录记录</h3>
+ <el-table :data="loginHistory" stripe>
+ <el-table-column label="登录时间" width="180">
+ <template #default="{ row }">
+ {{ formatDateTime(row.time) }}
+ </template>
+ </el-table-column>
+ <el-table-column label="IP地址" prop="ip" width="150" />
+ <el-table-column label="设备信息" prop="device" />
+ <el-table-column label="登录结果" width="100">
+ <template #default="{ row }">
+ <el-tag :type="row.success ? 'success' : 'danger'" size="small">
+ {{ row.success ? '成功' : '失败' }}
+ </el-tag>
+ </template>
+ </el-table-column>
+ </el-table>
+ </div>
+ </div>
+ </el-tab-pane>
+ </el-tabs>
+ </div>
+ </div>
+
+ <!-- 更换头像对话框 -->
+ <el-dialog v-model="showAvatarDialog" title="更换头像" width="400px">
+ <div class="avatar-upload">
+ <el-upload
+ ref="avatarUploadRef"
+ :auto-upload="false"
+ :limit="1"
+ accept="image/*"
+ :on-change="handleAvatarChange"
+ list-type="picture-card"
+ class="avatar-uploader"
+ >
+ <el-icon><Plus /></el-icon>
+ </el-upload>
+ <div class="upload-tips">
+ <p>支持 JPG、PNG 格式</p>
+ <p>建议尺寸 200x200 像素</p>
+ <p>文件大小不超过 2MB</p>
+ </div>
+ </div>
+
+ <template #footer>
+ <el-button @click="showAvatarDialog = false">取消</el-button>
+ <el-button type="primary" @click="uploadAvatar" :loading="uploadingAvatar">
+ 上传头像
+ </el-button>
+ </template>
+ </el-dialog>
+ </div>
+</template>
+
+<script>
+import { ref, reactive, computed, onMounted, nextTick } from 'vue'
+import { useRouter } from 'vue-router'
+import { ElMessage } from 'element-plus'
+import {
+ Calendar,
+ Clock,
+ Upload,
+ Download,
+ TrendCharts,
+ Star,
+ QuestionFilled,
+ Plus,
+ ChatDotRound,
+ Flag,
+ Coin
+} from '@element-plus/icons-vue'
+
+export default {
+ name: 'ProfileView',
+ setup() {
+ const router = useRouter()
+ const profileFormRef = ref(null)
+ const passwordFormRef = ref(null)
+ const avatarUploadRef = ref(null)
+ const interestInputRef = ref(null)
+
+ const activeTab = ref('info')
+ const showAvatarDialog = ref(false)
+ const saving = ref(false)
+ const changingPassword = ref(false)
+ const uploadingAvatar = ref(false)
+ const interestInputVisible = ref(false)
+ const interestInputValue = ref('')
+ const activityFilter = ref('')
+ const torrentsPage = ref(1)
+
+ const userProfile = ref({
+ username: 'MovieExpert',
+ email: 'movieexpert@example.com',
+ realName: '',
+ avatar: '',
+ userLevel: 5,
+ userTitle: '资深会员',
+ joinDate: '2023-01-15T10:00:00',
+ lastLogin: '2025-06-03T14:30:00',
+ location: ['北京市', '朝阳区'],
+ signature: '热爱电影,分享快乐!',
+ website: 'https://movieblog.com',
+ interests: ['电影', '音乐', '科技', '摄影'],
+ emailPublic: false,
+ statsPublic: true,
+ activityPublic: true,
+ stats: {
+ uploaded: '256.8 GB',
+ downloaded: '89.6 GB',
+ ratio: '2.87',
+ points: '15,680'
+ },
+ detailedStats: {
+ totalUploaded: '256.8 GB',
+ uploadedTorrents: 45,
+ avgUploadSize: '5.7 GB',
+ totalDownloaded: '89.6 GB',
+ downloadedTorrents: 123,
+ completedTorrents: 118,
+ seeding: 32,
+ seedingTime: '1,245 小时',
+ seedingRank: 86,
+ totalEarnedPoints: '28,940',
+ totalSpentPoints: '13,260'
+ }
+ })
+
+ const editProfile = reactive({
+ username: '',
+ email: '',
+ realName: '',
+ location: [],
+ signature: '',
+ website: '',
+ interests: [],
+ emailPublic: false,
+ statsPublic: true,
+ activityPublic: true
+ })
+
+ const passwordForm = reactive({
+ currentPassword: '',
+ newPassword: '',
+ confirmPassword: ''
+ })
+
+ const profileRules = {
+ email: [
+ { required: true, message: '请输入邮箱地址', trigger: 'blur' },
+ { type: 'email', message: '请输入正确的邮箱格式', trigger: 'blur' }
+ ]
+ }
+
+ const passwordRules = {
+ currentPassword: [
+ { required: true, message: '请输入当前密码', trigger: 'blur' }
+ ],
+ newPassword: [
+ { required: true, message: '请输入新密码', trigger: 'blur' },
+ { min: 6, message: '密码长度至少6个字符', trigger: 'blur' }
+ ],
+ confirmPassword: [
+ { required: true, message: '请确认新密码', trigger: 'blur' },
+ {
+ validator: (rule, value, callback) => {
+ if (value !== passwordForm.newPassword) {
+ callback(new Error('两次输入的密码不一致'))
+ } else {
+ callback()
+ }
+ },
+ trigger: 'blur'
+ }
+ ]
+ }
+
+ const locationOptions = [
+ {
+ value: '北京市',
+ label: '北京市',
+ children: [
+ { value: '朝阳区', label: '朝阳区' },
+ { value: '海淀区', label: '海淀区' },
+ { value: '丰台区', label: '丰台区' }
+ ]
+ },
+ {
+ value: '上海市',
+ label: '上海市',
+ children: [
+ { value: '浦东新区', label: '浦东新区' },
+ { value: '黄浦区', label: '黄浦区' },
+ { value: '静安区', label: '静安区' }
+ ]
+ }
+ ]
+
+ const userTorrents = ref([
+ {
+ id: 1,
+ title: '[4K蓝光原盘] 阿凡达:水之道',
+ category: 'movie',
+ size: '85.6 GB',
+ seeders: 45,
+ leechers: 12,
+ downloads: 234,
+ uploadTime: '2025-05-15T10:00:00'
+ },
+ {
+ id: 2,
+ title: '[FLAC] 古典音乐合集',
+ category: 'music',
+ size: '2.3 GB',
+ seeders: 23,
+ leechers: 5,
+ downloads: 89,
+ uploadTime: '2025-04-20T15:30:00'
+ }
+ ])
+
+ const activities = ref([
+ {
+ id: 1,
+ type: 'upload',
+ title: '上传种子',
+ description: '上传了《阿凡达:水之道》4K蓝光原盘',
+ time: '2025-06-03T10:30:00'
+ },
+ {
+ id: 2,
+ type: 'download',
+ title: '下载种子',
+ description: '下载了《星际穿越》IMAX版本',
+ time: '2025-06-02T14:20:00'
+ },
+ {
+ id: 3,
+ type: 'post',
+ title: '发布主题',
+ description: '在电影讨论区发布了新主题',
+ time: '2025-06-01T16:45:00'
+ },
+ {
+ id: 4,
+ type: 'points',
+ title: '积分变动',
+ description: '做种奖励获得 +50 积分',
+ time: '2025-05-31T09:15:00'
+ }
+ ])
+
+ const loginHistory = ref([
+ {
+ time: '2025-06-03T14:30:00',
+ ip: '192.168.1.100',
+ device: 'Windows 11 / Chrome 120',
+ success: true
+ },
+ {
+ time: '2025-06-02T09:15:00',
+ ip: '192.168.1.100',
+ device: 'Windows 11 / Chrome 120',
+ success: true
+ },
+ {
+ time: '2025-06-01T22:30:00',
+ ip: '192.168.1.100',
+ device: 'Android / Chrome Mobile',
+ success: true
+ }
+ ])
+
+ const filteredActivities = computed(() => {
+ if (!activityFilter.value) return activities.value
+ return activities.value.filter(activity => activity.type === activityFilter.value)
+ })
+
+ onMounted(() => {
+ loadUserProfile()
+ })
+
+ const loadUserProfile = () => {
+ // 加载用户资料到编辑表单
+ Object.assign(editProfile, {
+ username: userProfile.value.username,
+ email: userProfile.value.email,
+ realName: userProfile.value.realName,
+ location: userProfile.value.location,
+ signature: userProfile.value.signature,
+ website: userProfile.value.website,
+ interests: [...userProfile.value.interests],
+ emailPublic: userProfile.value.emailPublic,
+ statsPublic: userProfile.value.statsPublic,
+ activityPublic: userProfile.value.activityPublic
+ })
+ }
+
+ const formatDate = (dateString) => {
+ const date = new Date(dateString)
+ return date.toLocaleDateString('zh-CN')
+ }
+
+ const formatTime = (timeString) => {
+ const date = new Date(timeString)
+ const now = new Date()
+ const diff = now - date
+ const hours = Math.floor(diff / (1000 * 60 * 60))
+
+ if (hours < 1) return '刚刚'
+ if (hours < 24) return `${hours}小时前`
+ const days = Math.floor(hours / 24)
+ if (days < 7) return `${days}天前`
+
+ return date.toLocaleDateString('zh-CN')
+ }
+
+ const formatDateTime = (dateString) => {
+ const date = new Date(dateString)
+ return date.toLocaleString('zh-CN')
+ }
+
+ const getUserTitleType = (level) => {
+ if (level >= 8) return 'danger' // 管理员
+ if (level >= 6) return 'warning' // 资深会员
+ if (level >= 4) return 'success' // 正式会员
+ if (level >= 2) return 'info' // 初级会员
+ return 'default' // 新手
+ }
+
+ const getRatioClass = (ratio) => {
+ const r = parseFloat(ratio)
+ if (r >= 2) return 'excellent'
+ if (r >= 1) return 'good'
+ return 'warning'
+ }
+
+ const getCategoryType = (category) => {
+ const types = {
+ 'movie': 'primary',
+ 'tv': 'info',
+ 'music': 'success',
+ 'software': 'warning',
+ 'game': 'danger'
+ }
+ return types[category] || 'default'
+ }
+
+ const getCategoryName = (category) => {
+ const names = {
+ 'movie': '电影',
+ 'tv': '电视剧',
+ 'music': '音乐',
+ 'software': '软件',
+ 'game': '游戏'
+ }
+ return names[category] || category
+ }
+
+ const getActivityType = (type) => {
+ const types = {
+ 'upload': 'success',
+ 'download': 'primary',
+ 'post': 'warning',
+ 'points': 'info'
+ }
+ return types[type] || 'primary'
+ }
+
+ const getActivityIcon = (type) => {
+ const icons = {
+ 'upload': 'Upload',
+ 'download': 'Download',
+ 'post': 'ChatDotRound',
+ 'points': 'Coin'
+ }
+ return icons[type] || 'Star'
+ }
+
+ const showInterestInput = () => {
+ interestInputVisible.value = true
+ nextTick(() => {
+ interestInputRef.value?.focus()
+ })
+ }
+
+ const addInterest = () => {
+ const interest = interestInputValue.value.trim()
+ if (interest && !editProfile.interests.includes(interest)) {
+ editProfile.interests.push(interest)
+ }
+ interestInputVisible.value = false
+ interestInputValue.value = ''
+ }
+
+ const removeInterest = (interest) => {
+ const index = editProfile.interests.indexOf(interest)
+ if (index > -1) {
+ editProfile.interests.splice(index, 1)
+ }
+ }
+
+ const saveProfile = async () => {
+ try {
+ await profileFormRef.value?.validate()
+
+ saving.value = true
+
+ // 模拟保存过程
+ await new Promise(resolve => setTimeout(resolve, 1500))
+
+ // 更新用户资料
+ Object.assign(userProfile.value, editProfile)
+
+ ElMessage.success('个人资料保存成功')
+
+ } catch (error) {
+ console.error('表单验证失败:', error)
+ } finally {
+ saving.value = false
+ }
+ }
+
+ const resetProfile = () => {
+ loadUserProfile()
+ ElMessage.info('已重置为原始数据')
+ }
+
+ const changePassword = async () => {
+ try {
+ await passwordFormRef.value?.validate()
+
+ changingPassword.value = true
+
+ // 模拟密码修改过程
+ await new Promise(resolve => setTimeout(resolve, 1500))
+
+ // 重置表单
+ passwordFormRef.value?.resetFields()
+ Object.assign(passwordForm, {
+ currentPassword: '',
+ newPassword: '',
+ confirmPassword: ''
+ })
+
+ ElMessage.success('密码修改成功')
+
+ } catch (error) {
+ console.error('表单验证失败:', error)
+ } finally {
+ changingPassword.value = false
+ }
+ }
+
+ const handleAvatarChange = (file) => {
+ const isImage = file.raw.type.startsWith('image/')
+ const isLt2M = file.raw.size / 1024 / 1024 < 2
+
+ if (!isImage) {
+ ElMessage.error('只能上传图片文件!')
+ return false
+ }
+ if (!isLt2M) {
+ ElMessage.error('图片大小不能超过 2MB!')
+ return false
+ }
+
+ return true
+ }
+
+ const uploadAvatar = async () => {
+ const files = avatarUploadRef.value?.uploadFiles
+ if (!files || files.length === 0) {
+ ElMessage.warning('请选择头像文件')
+ return
+ }
+
+ uploadingAvatar.value = true
+ try {
+ // 模拟上传过程
+ await new Promise(resolve => setTimeout(resolve, 2000))
+
+ // 更新头像URL
+ userProfile.value.avatar = URL.createObjectURL(files[0].raw)
+
+ ElMessage.success('头像上传成功')
+ showAvatarDialog.value = false
+ avatarUploadRef.value?.clearFiles()
+
+ } catch (error) {
+ ElMessage.error('头像上传失败')
+ } finally {
+ uploadingAvatar.value = false
+ }
+ }
+
+ return {
+ activeTab,
+ showAvatarDialog,
+ saving,
+ changingPassword,
+ uploadingAvatar,
+ interestInputVisible,
+ interestInputValue,
+ activityFilter,
+ torrentsPage,
+ userProfile,
+ editProfile,
+ passwordForm,
+ profileRules,
+ passwordRules,
+ locationOptions,
+ userTorrents,
+ filteredActivities,
+ loginHistory,
+ profileFormRef,
+ passwordFormRef,
+ avatarUploadRef,
+ interestInputRef,
+ formatDate,
+ formatTime,
+ formatDateTime,
+ getUserTitleType,
+ getRatioClass,
+ getCategoryType,
+ getCategoryName,
+ getActivityType,
+ getActivityIcon,
+ showInterestInput,
+ addInterest,
+ removeInterest,
+ saveProfile,
+ resetProfile,
+ changePassword,
+ handleAvatarChange,
+ uploadAvatar,
+ Calendar,
+ Clock,
+ Upload,
+ Download,
+ TrendCharts,
+ Star,
+ QuestionFilled,
+ Plus,
+ ChatDotRound,
+ Flag,
+ Coin
+ }
+ }
+}
+</script>
+
+<style lang="scss" scoped>
+.profile-page {
+ max-width: 1200px;
+ margin: 0 auto;
+ padding: 24px;
+ background: #f5f5f5;
+ min-height: 100vh;
+}
+
+.profile-header {
+ background: #fff;
+ border-radius: 12px;
+ padding: 32px;
+ margin-bottom: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ display: grid;
+ grid-template-columns: 1fr 1fr;
+ gap: 32px;
+
+ .user-avatar-section {
+ display: flex;
+ gap: 24px;
+
+ .avatar-container {
+ text-align: center;
+
+ .change-avatar-btn {
+ margin-top: 12px;
+ }
+ }
+
+ .user-basic-info {
+ flex: 1;
+
+ .username {
+ font-size: 28px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 12px 0;
+ }
+
+ .user-title {
+ margin-bottom: 16px;
+ }
+
+ .join-info, .last-login {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ font-size: 14px;
+ color: #7f8c8d;
+ margin-bottom: 8px;
+ }
+ }
+ }
+
+ .user-stats-overview {
+ .stats-grid {
+ display: grid;
+ grid-template-columns: repeat(2, 1fr);
+ gap: 16px;
+
+ .stat-card {
+ background: #f8f9fa;
+ border-radius: 8px;
+ padding: 20px;
+ display: flex;
+ align-items: center;
+ gap: 16px;
+
+ .stat-icon {
+ width: 48px;
+ height: 48px;
+ border-radius: 50%;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+
+ &.upload { background: rgba(103, 194, 58, 0.1); color: #67c23a; }
+ &.download { background: rgba(64, 158, 255, 0.1); color: #409eff; }
+ &.ratio {
+ &.excellent { background: rgba(103, 194, 58, 0.1); color: #67c23a; }
+ &.good { background: rgba(230, 162, 60, 0.1); color: #e6a23c; }
+ &.warning { background: rgba(245, 108, 108, 0.1); color: #f56c6c; }
+ }
+ &.points { background: rgba(245, 108, 108, 0.1); color: #f56c6c; }
+ }
+
+ .stat-info {
+ h3 {
+ font-size: 20px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 4px 0;
+ }
+
+ p {
+ font-size: 14px;
+ color: #7f8c8d;
+ margin: 0;
+ }
+ }
+ }
+ }
+ }
+}
+
+.profile-content {
+ background: #fff;
+ border-radius: 12px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ :deep(.el-tabs__content) {
+ padding: 24px;
+ }
+}
+
+.info-section {
+ .form-section {
+ margin-bottom: 32px;
+
+ h3 {
+ font-size: 18px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 20px 0;
+ padding-bottom: 8px;
+ border-bottom: 2px solid #f0f0f0;
+ }
+ }
+
+ .interests-input {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 8px;
+ align-items: center;
+
+ .interest-tag {
+ margin: 0;
+ }
+ }
+
+ .setting-tip {
+ margin-left: 12px;
+ font-size: 12px;
+ color: #909399;
+ }
+
+ .form-actions {
+ text-align: center;
+ margin-top: 32px;
+
+ .el-button {
+ margin: 0 8px;
+ min-width: 100px;
+ }
+ }
+}
+
+.stats-section {
+ .stats-overview {
+ margin-bottom: 32px;
+
+ .overview-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
+ gap: 20px;
+
+ .overview-card {
+ background: #f8f9fa;
+ border-radius: 8px;
+ padding: 24px;
+
+ h3 {
+ font-size: 16px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 16px 0;
+ }
+
+ .stat-details {
+ .detail-item {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 12px;
+
+ .label {
+ font-size: 14px;
+ color: #7f8c8d;
+ }
+
+ .value {
+ font-size: 14px;
+ font-weight: 600;
+ color: #2c3e50;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ .charts-section {
+ .chart-card {
+ background: #f8f9fa;
+ border-radius: 8px;
+ padding: 24px;
+
+ h3 {
+ font-size: 16px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 20px 0;
+ }
+
+ .chart-placeholder {
+ text-align: center;
+ padding: 60px 0;
+ color: #909399;
+
+ p {
+ margin: 12px 0 0 0;
+ }
+ }
+ }
+ }
+}
+
+.torrents-section {
+ .section-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 20px;
+
+ h3 {
+ font-size: 18px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0;
+ }
+ }
+
+ .torrent-info {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+
+ .torrent-title {
+ font-weight: 500;
+ }
+ }
+
+ .pagination-wrapper {
+ margin-top: 16px;
+ text-align: center;
+ }
+}
+
+.activity-section {
+ .activity-filters {
+ margin-bottom: 24px;
+
+ .el-select {
+ width: 150px;
+ }
+ }
+
+ .activity-timeline {
+ .activity-content {
+ .activity-header {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ margin-bottom: 8px;
+
+ .activity-title {
+ font-weight: 600;
+ color: #2c3e50;
+ }
+ }
+
+ .activity-description {
+ font-size: 14px;
+ color: #7f8c8d;
+ line-height: 1.5;
+ }
+ }
+ }
+}
+
+.security-section {
+ .security-card {
+ background: #f8f9fa;
+ border-radius: 8px;
+ padding: 24px;
+ margin-bottom: 24px;
+
+ h3 {
+ font-size: 18px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 20px 0;
+ }
+ }
+}
+
+.avatar-upload {
+ text-align: center;
+
+ .avatar-uploader {
+ margin-bottom: 16px;
+ }
+
+ .upload-tips {
+ font-size: 12px;
+ color: #909399;
+
+ p {
+ margin: 4px 0;
+ }
+ }
+}
+
+@media (max-width: 768px) {
+ .profile-page {
+ padding: 16px;
+ }
+
+ .profile-header {
+ grid-template-columns: 1fr;
+ gap: 24px;
+
+ .user-avatar-section {
+ flex-direction: column;
+ text-align: center;
+ }
+
+ .user-stats-overview .stats-grid {
+ grid-template-columns: 1fr;
+ }
+ }
+
+ .stats-overview .overview-grid {
+ grid-template-columns: 1fr;
+ }
+
+ .torrents-section .section-header {
+ flex-direction: column;
+ gap: 16px;
+ align-items: flex-start;
+ }
+}
</style>
\ No newline at end of file
diff --git a/src/views/auth/RegisterView.vue b/src/views/auth/RegisterView.vue
index ad3461d..67a262f 100644
--- a/src/views/auth/RegisterView.vue
+++ b/src/views/auth/RegisterView.vue
@@ -1,375 +1,207 @@
-<template>
- <div class="register-page">
- <!-- 背景装饰 -->
- <div class="bg-decoration">
- <div class="shape shape-1"></div>
- <div class="shape shape-2"></div>
- <div class="shape shape-3"></div>
- </div>
-
- <!-- 注册表单容器 -->
- <div class="register-container">
- <div class="register-card">
- <!-- 头部信息 -->
- <div class="register-header">
- <div class="logo">
- <el-icon size="48" color="#a8edea"><UserFilled /></el-icon>
- </div>
- <h1 class="title">加入 PT Tracker</h1>
- <p class="subtitle">开始你的资源分享之旅</p>
- </div>
-
- <!-- 注册表单 -->
- <el-form
- ref="registerFormRef"
- :model="registerForm"
- :rules="registerRules"
- class="register-form"
- size="large"
- >
- <el-form-item prop="username">
- <el-input
- v-model="registerForm.username"
- placeholder="请输入用户名"
- clearable
- :prefix-icon="User"
- />
- </el-form-item>
-
- <el-form-item prop="email">
- <el-input
- v-model="registerForm.email"
- placeholder="请输入邮箱地址"
- clearable
- :prefix-icon="Message"
- />
- </el-form-item>
-
- <el-form-item prop="password">
- <el-input
- v-model="registerForm.password"
- type="password"
- placeholder="请输入密码"
- show-password
- :prefix-icon="Lock"
- />
- </el-form-item>
-
- <el-form-item prop="confirmPassword">
- <el-input
- v-model="registerForm.confirmPassword"
- type="password"
- placeholder="请确认密码"
- show-password
- :prefix-icon="Lock"
- />
- </el-form-item>
-
- <el-form-item prop="agreement">
- <el-checkbox v-model="registerForm.agreement">
- 我已阅读并同意
- <el-link type="primary" :underline="false">《用户协议》</el-link>
- 和
- <el-link type="primary" :underline="false">《隐私政策》</el-link>
- </el-checkbox>
- </el-form-item>
-
- <el-form-item>
- <el-button
- type="primary"
- :loading="loading"
- style="width: 100%"
- @click="handleRegister"
- >
- <span v-if="!loading">注册</span>
- <span v-else>注册中...</span>
- </el-button>
- </el-form-item>
- </el-form>
-
- <!-- 底部链接 -->
- <div class="register-footer">
- <span class="footer-text">已有账号?</span>
- <el-link
- type="primary"
- :underline="false"
- @click="$router.push('/login')"
- >
- 立即登录
- </el-link>
- </div>
- </div>
- </div>
- </div>
-</template>
-
-<script>
-import { ref, reactive } from 'vue'
-import { useRouter } from 'vue-router'
-import { ElMessage } from 'element-plus'
-import { User, Lock, Message, UserFilled } from '@element-plus/icons-vue'
-
-export default {
- name: 'RegisterView',
- components: {
- UserFilled
- },
- setup() {
- const router = useRouter()
- const registerFormRef = ref()
- const loading = ref(false)
-
- // 表单数据
- const registerForm = reactive({
- username: '',
- email: '',
- password: '',
- confirmPassword: '',
- agreement: false
- })
-
- // 自定义验证规则
- const validateConfirmPassword = (rule, value, callback) => {
- if (value === '') {
- callback(new Error('请再次输入密码'))
- } else if (value !== registerForm.password) {
- callback(new Error('两次输入密码不一致'))
- } else {
- callback()
- }
- }
-
- const validateAgreement = (rule, value, callback) => {
- if (!value) {
- callback(new Error('请先同意用户协议和隐私政策'))
- } else {
- callback()
- }
- }
-
- // 验证规则
- const registerRules = {
- username: [
- { required: true, message: '请输入用户名', trigger: 'blur' },
- { min: 3, max: 20, message: '用户名长度在3到20个字符', trigger: 'blur' },
- { pattern: /^[a-zA-Z0-9_]+$/, message: '用户名只能包含字母、数字和下划线', trigger: 'blur' }
- ],
- email: [
- { required: true, message: '请输入邮箱地址', trigger: 'blur' },
- { type: 'email', message: '请输入正确的邮箱格式', trigger: 'blur' }
- ],
- password: [
- { required: true, message: '请输入密码', trigger: 'blur' },
- { min: 6, max: 20, message: '密码长度在6到20个字符', trigger: 'blur' },
- { pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?&]/, message: '密码必须包含大小写字母和数字', trigger: 'blur' }
- ],
- confirmPassword: [
- { required: true, validator: validateConfirmPassword, trigger: 'blur' }
- ],
- agreement: [
- { required: true, validator: validateAgreement, trigger: 'change' }
- ]
- }
-
- // 注册处理
- const handleRegister = async () => {
- try {
- // 表单验证
- const valid = await registerFormRef.value.validate()
- if (!valid) return
-
- loading.value = true
-
- // 模拟注册API请求
- await new Promise(resolve => setTimeout(resolve, 1500))
-
- // 模拟注册成功
- ElMessage.success('注册成功!请登录您的账号')
-
- // 跳转到登录页
- router.push('/login')
-
- } catch (error) {
- console.error('注册失败:', error)
- ElMessage.error('注册失败,请稍后重试')
- } finally {
- loading.value = false
- }
- }
-
- return {
- registerFormRef,
- registerForm,
- registerRules,
- loading,
- handleRegister,
- User,
- Lock,
- Message
- }
- }
-}
-</script>
-
-<style lang="scss" scoped>
-.register-page {
- min-height: 100vh;
- background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
- position: relative;
- overflow: hidden;
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 20px;
-}
-
-// 背景装饰(与登录页相同的动画效果)
-.bg-decoration {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- overflow: hidden;
- z-index: 1;
-
- .shape {
- position: absolute;
- border-radius: 50%;
- background: rgba(255, 255, 255, 0.15);
- animation: float 8s ease-in-out infinite;
-
- &.shape-1 {
- width: 180px;
- height: 180px;
- top: 15%;
- left: 15%;
- animation-delay: 0s;
- }
-
- &.shape-2 {
- width: 120px;
- height: 120px;
- top: 50%;
- right: 15%;
- animation-delay: -3s;
- }
-
- &.shape-3 {
- width: 90px;
- height: 90px;
- bottom: 25%;
- left: 25%;
- animation-delay: -6s;
- }
- }
-}
-
-@keyframes float {
- 0%, 100% {
- transform: translateY(0px) rotate(0deg);
- }
- 50% {
- transform: translateY(-15px) rotate(180deg);
- }
-}
-
-// 注册容器
-.register-container {
- position: relative;
- z-index: 10;
- width: 100%;
- max-width: 420px;
-}
-
-.register-card {
- background: rgba(255, 255, 255, 0.95);
- backdrop-filter: blur(10px);
- border-radius: 16px;
- padding: 40px;
- box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
- border: 1px solid rgba(255, 255, 255, 0.2);
-
- .register-header {
- text-align: center;
- margin-bottom: 32px;
-
- .logo {
- margin-bottom: 16px;
- }
-
- .title {
- font-size: 32px;
- font-weight: 700;
- color: #2c3e50;
- margin-bottom: 8px;
- letter-spacing: -0.5px;
- }
-
- .subtitle {
- font-size: 15px;
- color: #7f8c8d;
- margin: 0;
- font-weight: 400;
- }
- }
-
- .register-form {
- .el-form-item {
- margin-bottom: 20px;
-
- &:last-child {
- margin-bottom: 0;
- }
- }
-
- .el-checkbox {
- :deep(.el-checkbox__label) {
- font-size: 14px;
- color: #606266;
- line-height: 1.5;
- }
- }
-
- .el-button {
- font-size: 16px;
- font-weight: 500;
- height: 48px;
- border-radius: 8px;
- }
- }
-
- .register-footer {
- text-align: center;
- margin-top: 24px;
- padding-top: 24px;
- border-top: 1px solid #ebeef5;
-
- .footer-text {
- color: #909399;
- font-size: 14px;
- margin-right: 8px;
- }
-
- .el-link {
- font-size: 14px;
- font-weight: 500;
- }
- }
-}
-
-// 响应式设计
-@media (max-width: 768px) {
- .register-page {
- padding: 16px;
- }
-
- .register-card {
- padding: 32px 24px;
-
- .register-header .title {
- font-size: 28px;
- }
- }
-}
-</style>
\ No newline at end of file
+<template>
+ <div class="register-page">
+ <div class="bg-decoration">
+ <div class="shape shape-1"></div>
+ <div class="shape shape-2"></div>
+ <div class="shape shape-3"></div>
+ </div>
+
+ <div class="register-container">
+ <div class="register-card">
+ <div class="register-header">
+ <div class="logo">
+ <el-icon size="48" color="#a8edea"><UserFilled /></el-icon>
+ </div>
+ <h1 class="title">加入 PT Tracker</h1>
+ <p class="subtitle">开始你的资源分享之旅</p>
+ </div>
+
+ <!-- 注册表单 -->
+ <el-form
+ ref="registerFormRef"
+ :model="registerForm"
+ :rules="registerRules"
+ class="register-form"
+ size="large"
+ >
+ <el-form-item prop="username">
+ <el-input
+ v-model="registerForm.username"
+ placeholder="请输入用户名"
+ clearable
+ :prefix-icon="User"
+ />
+ </el-form-item>
+
+ <el-form-item prop="email">
+ <el-input
+ v-model="registerForm.email"
+ placeholder="请输入邮箱地址"
+ clearable
+ :prefix-icon="Message"
+ />
+ </el-form-item>
+
+ <el-form-item prop="password">
+ <el-input
+ v-model="registerForm.password"
+ type="password"
+ placeholder="请输入密码"
+ show-password
+ :prefix-icon="Lock"
+ />
+ </el-form-item>
+
+ <el-form-item prop="confirmPassword">
+ <el-input
+ v-model="registerForm.confirmPassword"
+ type="password"
+ placeholder="请确认密码"
+ show-password
+ :prefix-icon="Lock"
+ />
+ </el-form-item>
+
+ <el-form-item prop="agreement">
+ <el-checkbox v-model="registerForm.agreement">
+ 我已阅读并同意
+ <el-link type="primary" :underline="false">《用户协议》</el-link>
+ 和
+ <el-link type="primary" :underline="false">《隐私政策》</el-link>
+ </el-checkbox>
+ </el-form-item>
+
+ <el-form-item>
+ <el-button
+ type="primary"
+ :loading="registerLoading"
+ style="width: 100%"
+ @click="handleRegister"
+ >
+ <span v-if="!registerLoading">注册</span>
+ <span v-else>注册中...</span>
+ </el-button>
+ </el-form-item>
+ </el-form>
+
+ <div class="register-footer">
+ <span class="footer-text">已有账号?</span>
+ <el-link
+ type="primary"
+ :underline="false"
+ @click="$router.push('/login')"
+ >
+ 立即登录
+ </el-link>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script>
+import { ref, reactive, computed } from 'vue'
+import { useRouter } from 'vue-router'
+import { useStore } from 'vuex'
+import { User, Lock, Message, UserFilled } from '@element-plus/icons-vue'
+
+export default {
+ name: 'RegisterView',
+ components: {
+ UserFilled
+ },
+ setup() {
+ const router = useRouter()
+ const store = useStore()
+ const registerFormRef = ref()
+
+ // 从store获取登录加载状态(注册和登录共用同一个loading状态)
+ const registerLoading = computed(() => store.getters['auth/loginLoading'])
+
+ // 表单数据
+ const registerForm = reactive({
+ username: '',
+ email: '',
+ password: '',
+ confirmPassword: '',
+ agreement: false
+ })
+
+ // 自定义验证规则
+ const validateConfirmPassword = (rule, value, callback) => {
+ if (value === '') {
+ callback(new Error('请再次输入密码'))
+ } else if (value !== registerForm.password) {
+ callback(new Error('两次输入密码不一致'))
+ } else {
+ callback()
+ }
+ }
+
+ const validateAgreement = (rule, value, callback) => {
+ if (!value) {
+ callback(new Error('请先同意用户协议和隐私政策'))
+ } else {
+ callback()
+ }
+ }
+
+ // 验证规则
+ const registerRules = {
+ username: [
+ { required: true, message: '请输入用户名', trigger: 'blur' },
+ { min: 3, max: 20, message: '用户名长度在3到20个字符', trigger: 'blur' },
+ { pattern: /^[a-zA-Z0-9_]+$/, message: '用户名只能包含字母、数字和下划线', trigger: 'blur' }
+ ],
+ email: [
+ { required: true, message: '请输入邮箱地址', trigger: 'blur' },
+ { type: 'email', message: '请输入正确的邮箱格式', trigger: 'blur' }
+ ],
+ password: [
+ { required: true, message: '请输入密码', trigger: 'blur' },
+ { min: 6, max: 20, message: '密码长度在6到20个字符', trigger: 'blur' }
+ ],
+ confirmPassword: [
+ { required: true, validator: validateConfirmPassword, trigger: 'blur' }
+ ],
+ agreement: [
+ { required: true, validator: validateAgreement, trigger: 'change' }
+ ]
+ }
+
+ // 注册处理
+ const handleRegister = async () => {
+ try {
+ // 表单验证
+ const valid = await registerFormRef.value.validate()
+ if (!valid) return
+
+ // 调用store的注册action
+ await store.dispatch('auth/register', {
+ username: registerForm.username,
+ email: registerForm.email,
+ password: registerForm.password
+ })
+
+ // 注册成功,跳转到首页
+ router.push('/home')
+
+ } catch (error) {
+ console.error('注册失败:', error)
+ // 错误信息已经在store中通过ElMessage显示了
+ }
+ }
+
+ return {
+ registerFormRef,
+ registerForm,
+ registerRules,
+ registerLoading,
+ handleRegister,
+ User,
+ Lock,
+ Message
+ }
+ }
+}
+</script>
\ No newline at end of file
diff --git a/src/views/forum/ForumSectionView.vue b/src/views/forum/ForumSectionView.vue
index a8e7306..d0b42ec 100644
--- a/src/views/forum/ForumSectionView.vue
+++ b/src/views/forum/ForumSectionView.vue
@@ -1,1008 +1,1008 @@
-<template>
- <div class="section-page">
- <div class="page-container">
- <!-- 面包屑导航 -->
- <div class="breadcrumb">
- <el-breadcrumb separator="/">
- <el-breadcrumb-item :to="{ path: '/forum' }">论坛首页</el-breadcrumb-item>
- <el-breadcrumb-item>{{ sectionInfo.name }}</el-breadcrumb-item>
- </el-breadcrumb>
- </div>
-
- <!-- 版块信息 -->
- <div class="section-header">
- <div class="section-info">
- <div class="section-icon">
- <el-icon size="48" :color="sectionInfo.color">
- <component :is="sectionInfo.icon" />
- </el-icon>
- </div>
- <div class="section-details">
- <h1 class="section-name">{{ sectionInfo.name }}</h1>
- <p class="section-description">{{ sectionInfo.description }}</p>
- <div class="section-stats">
- <div class="stat-item">
- <el-icon><ChatDotRound /></el-icon>
- <span>{{ sectionInfo.topics }} 主题</span>
- </div>
- <div class="stat-item">
- <el-icon><Comment /></el-icon>
- <span>{{ sectionInfo.replies }} 回复</span>
- </div>
- <div class="stat-item">
- <el-icon><User /></el-icon>
- <span>{{ sectionInfo.members }} 成员</span>
- </div>
- </div>
- </div>
- </div>
-
- <div class="section-actions">
- <el-button type="primary" :icon="Edit" @click="showNewTopicDialog = true">
- 发布新主题
- </el-button>
- </div>
- </div>
-
- <!-- 筛选和搜索 -->
- <div class="filter-section">
- <div class="filter-left">
- <el-input
- v-model="searchQuery"
- placeholder="搜索主题..."
- :prefix-icon="Search"
- @keyup.enter="handleSearch"
- clearable
- style="width: 300px;"
- />
- <el-button type="primary" @click="handleSearch">搜索</el-button>
- </div>
-
- <div class="filter-right">
- <el-select v-model="sortBy" placeholder="排序方式" @change="handleFilter">
- <el-option label="最新回复" value="last_reply" />
- <el-option label="发布时间" value="create_time" />
- <el-option label="回复数量" value="replies" />
- <el-option label="浏览次数" value="views" />
- </el-select>
-
- <el-select v-model="filterType" placeholder="主题类型" @change="handleFilter">
- <el-option label="全部主题" value="" />
- <el-option label="置顶主题" value="pinned" />
- <el-option label="热门主题" value="hot" />
- <el-option label="精华主题" value="featured" />
- </el-select>
- </div>
- </div>
-
- <!-- 置顶主题 -->
- <div v-if="pinnedTopics.length > 0" class="pinned-topics">
- <h3 class="section-title">置顶主题</h3>
- <div class="topics-list">
- <div
- v-for="topic in pinnedTopics"
- :key="topic.id"
- class="topic-item pinned"
- @click="navigateToTopic(topic.id)"
- >
- <div class="topic-status">
- <el-icon class="pin-icon"><Top /></el-icon>
- </div>
-
- <div class="topic-content">
- <div class="topic-header">
- <h4 class="topic-title">{{ topic.title }}</h4>
- <div class="topic-tags">
- <el-tag type="warning" size="small">置顶</el-tag>
- <el-tag v-if="topic.hot" type="danger" size="small">热门</el-tag>
- <el-tag v-if="topic.featured" type="success" size="small">精华</el-tag>
- </div>
- </div>
-
- <div class="topic-meta">
- <div class="author-info">
- <el-avatar :size="24">{{ topic.author.charAt(0) }}</el-avatar>
- <span class="author-name">{{ topic.author }}</span>
- <span class="create-time">{{ formatTime(topic.createTime) }}</span>
- </div>
-
- <div class="topic-stats">
- <span class="stat-item">
- <el-icon><View /></el-icon>
- {{ topic.views }}
- </span>
- <span class="stat-item">
- <el-icon><Comment /></el-icon>
- {{ topic.replies }}
- </span>
- </div>
- </div>
- </div>
-
- <div class="last-reply">
- <div v-if="topic.lastReply" class="reply-info">
- <div class="reply-author">{{ topic.lastReply.author }}</div>
- <div class="reply-time">{{ formatTime(topic.lastReply.time) }}</div>
- </div>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 普通主题列表 -->
- <div class="normal-topics">
- <div class="section-header">
- <h3 class="section-title">主题列表</h3>
- <div class="results-info">
- 共 {{ totalTopics }} 个主题
- </div>
- </div>
-
- <div class="topics-list" v-loading="loading">
- <div
- v-for="topic in topics"
- :key="topic.id"
- class="topic-item"
- @click="navigateToTopic(topic.id)"
- >
- <div class="topic-status">
- <el-icon v-if="topic.hasNewReplies" class="new-icon" color="#f56c6c">
- <ChatDotRound />
- </el-icon>
- <el-icon v-else class="normal-icon" color="#909399">
- <ChatLineRound />
- </el-icon>
- </div>
-
- <div class="topic-content">
- <div class="topic-header">
- <h4 class="topic-title">{{ topic.title }}</h4>
- <div class="topic-tags">
- <el-tag v-if="topic.hot" type="danger" size="small">热门</el-tag>
- <el-tag v-if="topic.featured" type="success" size="small">精华</el-tag>
- <el-tag v-if="topic.closed" type="info" size="small">已关闭</el-tag>
- </div>
- </div>
-
- <div class="topic-meta">
- <div class="author-info">
- <el-avatar :size="24">{{ topic.author.charAt(0) }}</el-avatar>
- <span class="author-name">{{ topic.author }}</span>
- <span class="create-time">{{ formatTime(topic.createTime) }}</span>
- </div>
-
- <div class="topic-stats">
- <span class="stat-item">
- <el-icon><View /></el-icon>
- {{ topic.views }}
- </span>
- <span class="stat-item">
- <el-icon><Comment /></el-icon>
- {{ topic.replies }}
- </span>
- </div>
- </div>
- </div>
-
- <div class="last-reply">
- <div v-if="topic.lastReply" class="reply-info">
- <div class="reply-author">{{ topic.lastReply.author }}</div>
- <div class="reply-time">{{ formatTime(topic.lastReply.time) }}</div>
- </div>
- <div v-else class="no-reply">暂无回复</div>
- </div>
- </div>
-
- <div v-if="topics.length === 0 && !loading" class="no-topics">
- 暂无主题,快来发布第一个主题吧!
- </div>
- </div>
-
- <!-- 分页 -->
- <div class="pagination-wrapper">
- <el-pagination
- v-model:current-page="currentPage"
- v-model:page-size="pageSize"
- :page-sizes="[20, 50, 100]"
- :total="totalTopics"
- layout="total, sizes, prev, pager, next, jumper"
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- />
- </div>
- </div>
- </div>
-
- <!-- 发布新主题对话框 -->
- <el-dialog
- v-model="showNewTopicDialog"
- title="发布新主题"
- width="600px"
- :before-close="handleCloseDialog"
- >
- <el-form
- ref="topicFormRef"
- :model="newTopic"
- :rules="topicRules"
- label-width="80px"
- >
- <el-form-item label="主题标题" prop="title">
- <el-input
- v-model="newTopic.title"
- placeholder="请输入主题标题"
- maxlength="100"
- show-word-limit
- />
- </el-form-item>
-
- <el-form-item label="主题标签">
- <div class="tags-input">
- <el-tag
- v-for="tag in newTopic.tags"
- :key="tag"
- closable
- @close="removeTopicTag(tag)"
- >
- {{ tag }}
- </el-tag>
- <el-input
- v-if="tagInputVisible"
- ref="tagInputRef"
- v-model="tagInputValue"
- size="small"
- @keyup.enter="addTopicTag"
- @blur="addTopicTag"
- style="width: 100px;"
- />
- <el-button
- v-else
- size="small"
- @click="showTagInput"
- >
- + 添加标签
- </el-button>
- </div>
- </el-form-item>
-
- <el-form-item label="主题内容" prop="content">
- <el-input
- v-model="newTopic.content"
- type="textarea"
- :rows="8"
- placeholder="请输入主题内容..."
- maxlength="5000"
- show-word-limit
- />
- </el-form-item>
-
- <el-form-item label="主题选项">
- <el-checkbox-group v-model="newTopic.options">
- <el-checkbox label="hot">申请热门</el-checkbox>
- <el-checkbox label="featured">申请精华</el-checkbox>
- </el-checkbox-group>
- </el-form-item>
- </el-form>
-
- <template #footer>
- <el-button @click="handleCloseDialog">取消</el-button>
- <el-button type="primary" @click="submitNewTopic" :loading="submitting">
- 发布主题
- </el-button>
- </template>
- </el-dialog>
- </div>
-</template>
-
-<script>
-import { ref, reactive, onMounted, nextTick } from 'vue'
-import { useRoute, useRouter } from 'vue-router'
-import { ElMessage, ElMessageBox } from 'element-plus'
-import {
- Edit,
- Search,
- ChatDotRound,
- Comment,
- User,
- View,
- Top,
- ChatLineRound,
- Film,
- Headphones,
- Monitor,
- GamePad,
- Bell,
- QuestionFilled
-} from '@element-plus/icons-vue'
-
-export default {
- name: 'ForumSectionView',
- setup() {
- const route = useRoute()
- const router = useRouter()
- const topicFormRef = ref(null)
- const tagInputRef = ref(null)
-
- const loading = ref(false)
- const showNewTopicDialog = ref(false)
- const submitting = ref(false)
- const tagInputVisible = ref(false)
- const tagInputValue = ref('')
-
- const searchQuery = ref('')
- const sortBy = ref('last_reply')
- const filterType = ref('')
- const currentPage = ref(1)
- const pageSize = ref(20)
- const totalTopics = ref(0)
-
- const sectionInfo = ref({
- id: 1,
- name: '电影讨论',
- description: '分享和讨论电影资源,交流观影心得',
- icon: 'Film',
- color: '#409eff',
- topics: 3256,
- replies: 18934,
- members: 1234
- })
-
- const newTopic = reactive({
- title: '',
- content: '',
- tags: [],
- options: []
- })
-
- const topicRules = {
- title: [
- { required: true, message: '请输入标题', trigger: 'blur' },
- { min: 5, max: 100, message: '标题长度在 5 到 100 个字符', trigger: 'blur' }
- ],
- content: [
- { required: true, message: '请输入内容', trigger: 'blur' },
- { min: 10, max: 5000, message: '内容长度在 10 到 5000 个字符', trigger: 'blur' }
- ]
- }
-
- const pinnedTopics = ref([
- {
- id: 1,
- title: '【公告】本版块发帖规则和注意事项',
- author: 'Admin',
- createTime: '2025-05-01T10:00:00',
- views: 5678,
- replies: 23,
- hot: false,
- featured: true,
- lastReply: {
- author: 'User123',
- time: '2025-06-02T15:30:00'
- }
- }
- ])
-
- const topics = ref([
- {
- id: 2,
- title: '2024年度最佳科幻电影推荐榜单',
- author: 'SciFiFan',
- createTime: '2025-06-03T10:30:00',
- views: 1234,
- replies: 45,
- hot: true,
- featured: false,
- closed: false,
- hasNewReplies: true,
- lastReply: {
- author: 'MovieLover',
- time: '2025-06-03T14:25:00'
- }
- },
- {
- id: 3,
- title: '阿凡达2:水之道 观影感受分享',
- author: 'Avatar2Fan',
- createTime: '2025-06-02T16:45:00',
- views: 892,
- replies: 67,
- hot: false,
- featured: true,
- closed: false,
- hasNewReplies: false,
- lastReply: {
- author: 'CinemaExpert',
- time: '2025-06-03T12:10:00'
- }
- },
- {
- id: 4,
- title: '求推荐几部好看的悬疑电影',
- author: 'SuspenseLover',
- createTime: '2025-06-01T09:20:00',
- views: 456,
- replies: 23,
- hot: false,
- featured: false,
- closed: false,
- hasNewReplies: true,
- lastReply: {
- author: 'ThrillerFan',
- time: '2025-06-03T11:45:00'
- }
- }
- ])
-
- onMounted(() => {
- const sectionId = route.params.id
- fetchSectionData(sectionId)
- })
-
- const fetchSectionData = async (id) => {
- loading.value = true
- try {
- // 模拟API调用
- console.log('获取版块数据:', id)
-
- // 根据版块ID设置不同的版块信息
- const sections = {
- 1: { name: '电影讨论', description: '分享和讨论电影资源,交流观影心得', icon: 'Film', color: '#409eff' },
- 2: { name: '音乐分享', description: '音乐资源分享,音乐制作技术交流', icon: 'Headphones', color: '#67c23a' },
- 3: { name: '软件技术', description: '软件资源分享,技术问题讨论', icon: 'Monitor', color: '#e6a23c' },
- 4: { name: '游戏天地', description: '游戏资源分享,游戏攻略讨论', icon: 'GamePad', color: '#f56c6c' },
- 5: { name: '站务公告', description: '网站公告,规则说明,意见建议', icon: 'Bell', color: '#909399' },
- 6: { name: '新手求助', description: '新手问题解答,使用教程分享', icon: 'QuestionFilled', color: '#606266' }
- }
-
- const sectionData = sections[id] || sections[1]
- sectionInfo.value = {
- id: parseInt(id),
- ...sectionData,
- topics: 3256,
- replies: 18934,
- members: 1234
- }
-
- totalTopics.value = 156
-
- } catch (error) {
- ElMessage.error('获取版块数据失败')
- } finally {
- loading.value = false
- }
- }
-
- const formatTime = (timeString) => {
- const date = new Date(timeString)
- const now = new Date()
- const diff = now - date
- const hours = Math.floor(diff / (1000 * 60 * 60))
-
- if (hours < 1) return '刚刚'
- if (hours < 24) return `${hours}小时前`
- const days = Math.floor(hours / 24)
- if (days < 7) return `${days}天前`
-
- return date.toLocaleDateString('zh-CN', {
- month: '2-digit',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit'
- })
- }
-
- const navigateToTopic = (topicId) => {
- router.push(`/forum/topic/${topicId}`)
- }
-
- const handleSearch = () => {
- currentPage.value = 1
- fetchTopics()
- }
-
- const handleFilter = () => {
- currentPage.value = 1
- fetchTopics()
- }
-
- const fetchTopics = async () => {
- loading.value = true
- try {
- // 模拟API调用
- await new Promise(resolve => setTimeout(resolve, 500))
- console.log('获取主题列表:', { searchQuery: searchQuery.value, sortBy: sortBy.value, filterType: filterType.value })
- } catch (error) {
- ElMessage.error('获取主题列表失败')
- } finally {
- loading.value = false
- }
- }
-
- const handleSizeChange = (size) => {
- pageSize.value = size
- currentPage.value = 1
- fetchTopics()
- }
-
- const handleCurrentChange = (page) => {
- currentPage.value = page
- fetchTopics()
- }
-
- const showTagInput = () => {
- tagInputVisible.value = true
- nextTick(() => {
- tagInputRef.value?.focus()
- })
- }
-
- const addTopicTag = () => {
- const tag = tagInputValue.value.trim()
- if (tag && !newTopic.tags.includes(tag)) {
- newTopic.tags.push(tag)
- }
- tagInputVisible.value = false
- tagInputValue.value = ''
- }
-
- const removeTopicTag = (tag) => {
- const index = newTopic.tags.indexOf(tag)
- if (index > -1) {
- newTopic.tags.splice(index, 1)
- }
- }
-
- const handleCloseDialog = () => {
- if (newTopic.title || newTopic.content) {
- ElMessageBox.confirm(
- '确定要关闭吗?未保存的内容将会丢失。',
- '提示',
- {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }
- ).then(() => {
- resetForm()
- showNewTopicDialog.value = false
- }).catch(() => {
- // 用户取消
- })
- } else {
- resetForm()
- showNewTopicDialog.value = false
- }
- }
-
- const submitNewTopic = async () => {
- try {
- await topicFormRef.value?.validate()
-
- submitting.value = true
-
- // 模拟提交过程
- await new Promise(resolve => setTimeout(resolve, 1500))
-
- ElMessage.success('主题发布成功!')
- resetForm()
- showNewTopicDialog.value = false
-
- // 刷新主题列表
- fetchTopics()
-
- } catch (error) {
- console.error('表单验证失败:', error)
- } finally {
- submitting.value = false
- }
- }
-
- const resetForm = () => {
- topicFormRef.value?.resetFields()
- newTopic.title = ''
- newTopic.content = ''
- newTopic.tags = []
- newTopic.options = []
- }
-
- return {
- loading,
- showNewTopicDialog,
- submitting,
- tagInputVisible,
- tagInputValue,
- searchQuery,
- sortBy,
- filterType,
- currentPage,
- pageSize,
- totalTopics,
- sectionInfo,
- pinnedTopics,
- topics,
- newTopic,
- topicRules,
- topicFormRef,
- tagInputRef,
- formatTime,
- navigateToTopic,
- handleSearch,
- handleFilter,
- handleSizeChange,
- handleCurrentChange,
- showTagInput,
- addTopicTag,
- removeTopicTag,
- handleCloseDialog,
- submitNewTopic,
- Edit,
- Search,
- ChatDotRound,
- Comment,
- User,
- View,
- Top,
- ChatLineRound,
- Film,
- Headphones,
- Monitor,
- GamePad,
- Bell,
- QuestionFilled
- }
- }
-}
-</script>
-
-<style lang="scss" scoped>
-.section-page {
- max-width: 1200px;
- margin: 0 auto;
- padding: 24px;
- background: #f5f5f5;
- min-height: 100vh;
-}
-
-.breadcrumb {
- margin-bottom: 16px;
-}
-
-.section-header {
- background: #fff;
- border-radius: 12px;
- padding: 32px;
- margin-bottom: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- display: flex;
- justify-content: space-between;
- align-items: center;
- gap: 24px;
-
- .section-info {
- display: flex;
- align-items: center;
- gap: 20px;
- flex: 1;
-
- .section-details {
- .section-name {
- font-size: 28px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 8px 0;
- }
-
- .section-description {
- font-size: 16px;
- color: #7f8c8d;
- margin: 0 0 16px 0;
- }
-
- .section-stats {
- display: flex;
- gap: 24px;
-
- .stat-item {
- display: flex;
- align-items: center;
- gap: 8px;
- font-size: 14px;
- color: #606266;
- }
- }
- }
- }
-
- .section-actions {
- flex-shrink: 0;
- }
-}
-
-.filter-section {
- background: #fff;
- border-radius: 12px;
- padding: 20px 24px;
- margin-bottom: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- display: flex;
- justify-content: space-between;
- align-items: center;
- gap: 20px;
-
- .filter-left {
- display: flex;
- align-items: center;
- gap: 12px;
- }
-
- .filter-right {
- display: flex;
- align-items: center;
- gap: 12px;
-
- .el-select {
- width: 120px;
- }
- }
-}
-
-.pinned-topics, .normal-topics {
- background: #fff;
- border-radius: 12px;
- padding: 24px;
- margin-bottom: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- .section-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20px;
- background: none;
- padding: 0;
- box-shadow: none;
-
- .section-title {
- font-size: 18px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0;
- }
-
- .results-info {
- font-size: 14px;
- color: #909399;
- }
- }
-}
-
-.topics-list {
- .topic-item {
- display: flex;
- align-items: center;
- gap: 16px;
- padding: 16px;
- border: 1px solid #f0f0f0;
- border-radius: 8px;
- margin-bottom: 12px;
- cursor: pointer;
- transition: all 0.3s ease;
-
- &:hover {
- background: #f8f9fa;
- border-color: #409eff;
- transform: translateX(2px);
- }
-
- &.pinned {
- background: linear-gradient(90deg, #fff7e6 0%, #fff 100%);
- border-color: #e6a23c;
- }
-
- .topic-status {
- width: 32px;
- text-align: center;
-
- .pin-icon {
- color: #e6a23c;
- }
-
- .new-icon {
- animation: pulse 2s infinite;
- }
- }
-
- .topic-content {
- flex: 1;
-
- .topic-header {
- display: flex;
- align-items: center;
- gap: 12px;
- margin-bottom: 8px;
-
- .topic-title {
- font-size: 16px;
- font-weight: 500;
- color: #2c3e50;
- margin: 0;
- flex: 1;
-
- &:hover {
- color: #409eff;
- }
- }
-
- .topic-tags {
- .el-tag {
- margin-left: 4px;
- }
- }
- }
-
- .topic-meta {
- display: flex;
- justify-content: space-between;
- align-items: center;
-
- .author-info {
- display: flex;
- align-items: center;
- gap: 8px;
-
- .author-name {
- font-size: 14px;
- font-weight: 500;
- color: #606266;
- }
-
- .create-time {
- font-size: 12px;
- color: #909399;
- }
- }
-
- .topic-stats {
- display: flex;
- gap: 16px;
-
- .stat-item {
- display: flex;
- align-items: center;
- gap: 4px;
- font-size: 12px;
- color: #909399;
- }
- }
- }
- }
-
- .last-reply {
- width: 150px;
- text-align: right;
-
- .reply-info {
- .reply-author {
- font-size: 14px;
- font-weight: 500;
- color: #606266;
- margin-bottom: 4px;
- }
-
- .reply-time {
- font-size: 12px;
- color: #909399;
- }
- }
-
- .no-reply {
- font-size: 12px;
- color: #c0c4cc;
- }
- }
- }
-
- .no-topics {
- text-align: center;
- color: #909399;
- padding: 60px 0;
- font-size: 16px;
- }
-}
-
-.pagination-wrapper {
- margin-top: 24px;
- text-align: center;
-}
-
-.tags-input {
- display: flex;
- flex-wrap: wrap;
- gap: 8px;
- align-items: center;
-
- .el-tag {
- margin: 0;
- }
-}
-
-@keyframes pulse {
- 0% {
- transform: scale(1);
- }
- 50% {
- transform: scale(1.1);
- }
- 100% {
- transform: scale(1);
- }
-}
-
-@media (max-width: 768px) {
- .section-page {
- padding: 16px;
- }
-
- .section-header {
- flex-direction: column;
- align-items: flex-start;
- gap: 16px;
-
- .section-info {
- flex-direction: column;
- text-align: center;
-
- .section-stats {
- justify-content: center;
- }
- }
-
- .section-actions {
- width: 100%;
- text-align: center;
- }
- }
-
- .filter-section {
- flex-direction: column;
- gap: 16px;
-
- .filter-left, .filter-right {
- width: 100%;
- justify-content: center;
- }
-
- .filter-right {
- .el-select {
- width: 140px;
- }
- }
- }
-
- .topic-item {
- flex-direction: column;
- align-items: flex-start;
- gap: 12px;
-
- .topic-status {
- align-self: flex-start;
- }
-
- .topic-content {
- width: 100%;
-
- .topic-meta {
- flex-direction: column;
- align-items: flex-start;
- gap: 8px;
- }
- }
-
- .last-reply {
- width: 100%;
- text-align: left;
- }
- }
-}
+<template>
+ <div class="section-page">
+ <div class="page-container">
+ <!-- 面包屑导航 -->
+ <div class="breadcrumb">
+ <el-breadcrumb separator="/">
+ <el-breadcrumb-item :to="{ path: '/forum' }">论坛首页</el-breadcrumb-item>
+ <el-breadcrumb-item>{{ sectionInfo.name }}</el-breadcrumb-item>
+ </el-breadcrumb>
+ </div>
+
+ <!-- 版块信息 -->
+ <div class="section-header">
+ <div class="section-info">
+ <div class="section-icon">
+ <el-icon size="48" :color="sectionInfo.color">
+ <component :is="sectionInfo.icon" />
+ </el-icon>
+ </div>
+ <div class="section-details">
+ <h1 class="section-name">{{ sectionInfo.name }}</h1>
+ <p class="section-description">{{ sectionInfo.description }}</p>
+ <div class="section-stats">
+ <div class="stat-item">
+ <el-icon><ChatDotRound /></el-icon>
+ <span>{{ sectionInfo.topics }} 主题</span>
+ </div>
+ <div class="stat-item">
+ <el-icon><Comment /></el-icon>
+ <span>{{ sectionInfo.replies }} 回复</span>
+ </div>
+ <div class="stat-item">
+ <el-icon><User /></el-icon>
+ <span>{{ sectionInfo.members }} 成员</span>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="section-actions">
+ <el-button type="primary" :icon="Edit" @click="showNewTopicDialog = true">
+ 发布新主题
+ </el-button>
+ </div>
+ </div>
+
+ <!-- 筛选和搜索 -->
+ <div class="filter-section">
+ <div class="filter-left">
+ <el-input
+ v-model="searchQuery"
+ placeholder="搜索主题..."
+ :prefix-icon="Search"
+ @keyup.enter="handleSearch"
+ clearable
+ style="width: 300px;"
+ />
+ <el-button type="primary" @click="handleSearch">搜索</el-button>
+ </div>
+
+ <div class="filter-right">
+ <el-select v-model="sortBy" placeholder="排序方式" @change="handleFilter">
+ <el-option label="最新回复" value="last_reply" />
+ <el-option label="发布时间" value="create_time" />
+ <el-option label="回复数量" value="replies" />
+ <el-option label="浏览次数" value="views" />
+ </el-select>
+
+ <el-select v-model="filterType" placeholder="主题类型" @change="handleFilter">
+ <el-option label="全部主题" value="" />
+ <el-option label="置顶主题" value="pinned" />
+ <el-option label="热门主题" value="hot" />
+ <el-option label="精华主题" value="featured" />
+ </el-select>
+ </div>
+ </div>
+
+ <!-- 置顶主题 -->
+ <div v-if="pinnedTopics.length > 0" class="pinned-topics">
+ <h3 class="section-title">置顶主题</h3>
+ <div class="topics-list">
+ <div
+ v-for="topic in pinnedTopics"
+ :key="topic.id"
+ class="topic-item pinned"
+ @click="navigateToTopic(topic.id)"
+ >
+ <div class="topic-status">
+ <el-icon class="pin-icon"><Top /></el-icon>
+ </div>
+
+ <div class="topic-content">
+ <div class="topic-header">
+ <h4 class="topic-title">{{ topic.title }}</h4>
+ <div class="topic-tags">
+ <el-tag type="warning" size="small">置顶</el-tag>
+ <el-tag v-if="topic.hot" type="danger" size="small">热门</el-tag>
+ <el-tag v-if="topic.featured" type="success" size="small">精华</el-tag>
+ </div>
+ </div>
+
+ <div class="topic-meta">
+ <div class="author-info">
+ <el-avatar :size="24">{{ topic.author.charAt(0) }}</el-avatar>
+ <span class="author-name">{{ topic.author }}</span>
+ <span class="create-time">{{ formatTime(topic.createTime) }}</span>
+ </div>
+
+ <div class="topic-stats">
+ <span class="stat-item">
+ <el-icon><View /></el-icon>
+ {{ topic.views }}
+ </span>
+ <span class="stat-item">
+ <el-icon><Comment /></el-icon>
+ {{ topic.replies }}
+ </span>
+ </div>
+ </div>
+ </div>
+
+ <div class="last-reply">
+ <div v-if="topic.lastReply" class="reply-info">
+ <div class="reply-author">{{ topic.lastReply.author }}</div>
+ <div class="reply-time">{{ formatTime(topic.lastReply.time) }}</div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- 普通主题列表 -->
+ <div class="normal-topics">
+ <div class="section-header">
+ <h3 class="section-title">主题列表</h3>
+ <div class="results-info">
+ 共 {{ totalTopics }} 个主题
+ </div>
+ </div>
+
+ <div class="topics-list" v-loading="loading">
+ <div
+ v-for="topic in topics"
+ :key="topic.id"
+ class="topic-item"
+ @click="navigateToTopic(topic.id)"
+ >
+ <div class="topic-status">
+ <el-icon v-if="topic.hasNewReplies" class="new-icon" color="#f56c6c">
+ <ChatDotRound />
+ </el-icon>
+ <el-icon v-else class="normal-icon" color="#909399">
+ <ChatLineRound />
+ </el-icon>
+ </div>
+
+ <div class="topic-content">
+ <div class="topic-header">
+ <h4 class="topic-title">{{ topic.title }}</h4>
+ <div class="topic-tags">
+ <el-tag v-if="topic.hot" type="danger" size="small">热门</el-tag>
+ <el-tag v-if="topic.featured" type="success" size="small">精华</el-tag>
+ <el-tag v-if="topic.closed" type="info" size="small">已关闭</el-tag>
+ </div>
+ </div>
+
+ <div class="topic-meta">
+ <div class="author-info">
+ <el-avatar :size="24">{{ topic.author.charAt(0) }}</el-avatar>
+ <span class="author-name">{{ topic.author }}</span>
+ <span class="create-time">{{ formatTime(topic.createTime) }}</span>
+ </div>
+
+ <div class="topic-stats">
+ <span class="stat-item">
+ <el-icon><View /></el-icon>
+ {{ topic.views }}
+ </span>
+ <span class="stat-item">
+ <el-icon><Comment /></el-icon>
+ {{ topic.replies }}
+ </span>
+ </div>
+ </div>
+ </div>
+
+ <div class="last-reply">
+ <div v-if="topic.lastReply" class="reply-info">
+ <div class="reply-author">{{ topic.lastReply.author }}</div>
+ <div class="reply-time">{{ formatTime(topic.lastReply.time) }}</div>
+ </div>
+ <div v-else class="no-reply">暂无回复</div>
+ </div>
+ </div>
+
+ <div v-if="topics.length === 0 && !loading" class="no-topics">
+ 暂无主题,快来发布第一个主题吧!
+ </div>
+ </div>
+
+ <!-- 分页 -->
+ <div class="pagination-wrapper">
+ <el-pagination
+ v-model:current-page="currentPage"
+ v-model:page-size="pageSize"
+ :page-sizes="[20, 50, 100]"
+ :total="totalTopics"
+ layout="total, sizes, prev, pager, next, jumper"
+ @size-change="handleSizeChange"
+ @current-change="handleCurrentChange"
+ />
+ </div>
+ </div>
+ </div>
+
+ <!-- 发布新主题对话框 -->
+ <el-dialog
+ v-model="showNewTopicDialog"
+ title="发布新主题"
+ width="600px"
+ :before-close="handleCloseDialog"
+ >
+ <el-form
+ ref="topicFormRef"
+ :model="newTopic"
+ :rules="topicRules"
+ label-width="80px"
+ >
+ <el-form-item label="主题标题" prop="title">
+ <el-input
+ v-model="newTopic.title"
+ placeholder="请输入主题标题"
+ maxlength="100"
+ show-word-limit
+ />
+ </el-form-item>
+
+ <el-form-item label="主题标签">
+ <div class="tags-input">
+ <el-tag
+ v-for="tag in newTopic.tags"
+ :key="tag"
+ closable
+ @close="removeTopicTag(tag)"
+ >
+ {{ tag }}
+ </el-tag>
+ <el-input
+ v-if="tagInputVisible"
+ ref="tagInputRef"
+ v-model="tagInputValue"
+ size="small"
+ @keyup.enter="addTopicTag"
+ @blur="addTopicTag"
+ style="width: 100px;"
+ />
+ <el-button
+ v-else
+ size="small"
+ @click="showTagInput"
+ >
+ + 添加标签
+ </el-button>
+ </div>
+ </el-form-item>
+
+ <el-form-item label="主题内容" prop="content">
+ <el-input
+ v-model="newTopic.content"
+ type="textarea"
+ :rows="8"
+ placeholder="请输入主题内容..."
+ maxlength="5000"
+ show-word-limit
+ />
+ </el-form-item>
+
+ <el-form-item label="主题选项">
+ <el-checkbox-group v-model="newTopic.options">
+ <el-checkbox label="hot">申请热门</el-checkbox>
+ <el-checkbox label="featured">申请精华</el-checkbox>
+ </el-checkbox-group>
+ </el-form-item>
+ </el-form>
+
+ <template #footer>
+ <el-button @click="handleCloseDialog">取消</el-button>
+ <el-button type="primary" @click="submitNewTopic" :loading="submitting">
+ 发布主题
+ </el-button>
+ </template>
+ </el-dialog>
+ </div>
+</template>
+
+<script>
+import { ref, reactive, onMounted, nextTick } from 'vue'
+import { useRoute, useRouter } from 'vue-router'
+import { ElMessage, ElMessageBox } from 'element-plus'
+import {
+ Edit,
+ Search,
+ ChatDotRound,
+ Comment,
+ User,
+ View,
+ Top,
+ ChatLineRound,
+ Film,
+ Headphones,
+ Monitor,
+ GamePad,
+ Bell,
+ QuestionFilled
+} from '@element-plus/icons-vue'
+
+export default {
+ name: 'ForumSectionView',
+ setup() {
+ const route = useRoute()
+ const router = useRouter()
+ const topicFormRef = ref(null)
+ const tagInputRef = ref(null)
+
+ const loading = ref(false)
+ const showNewTopicDialog = ref(false)
+ const submitting = ref(false)
+ const tagInputVisible = ref(false)
+ const tagInputValue = ref('')
+
+ const searchQuery = ref('')
+ const sortBy = ref('last_reply')
+ const filterType = ref('')
+ const currentPage = ref(1)
+ const pageSize = ref(20)
+ const totalTopics = ref(0)
+
+ const sectionInfo = ref({
+ id: 1,
+ name: '电影讨论',
+ description: '分享和讨论电影资源,交流观影心得',
+ icon: 'Film',
+ color: '#409eff',
+ topics: 3256,
+ replies: 18934,
+ members: 1234
+ })
+
+ const newTopic = reactive({
+ title: '',
+ content: '',
+ tags: [],
+ options: []
+ })
+
+ const topicRules = {
+ title: [
+ { required: true, message: '请输入标题', trigger: 'blur' },
+ { min: 5, max: 100, message: '标题长度在 5 到 100 个字符', trigger: 'blur' }
+ ],
+ content: [
+ { required: true, message: '请输入内容', trigger: 'blur' },
+ { min: 10, max: 5000, message: '内容长度在 10 到 5000 个字符', trigger: 'blur' }
+ ]
+ }
+
+ const pinnedTopics = ref([
+ {
+ id: 1,
+ title: '【公告】本版块发帖规则和注意事项',
+ author: 'Admin',
+ createTime: '2025-05-01T10:00:00',
+ views: 5678,
+ replies: 23,
+ hot: false,
+ featured: true,
+ lastReply: {
+ author: 'User123',
+ time: '2025-06-02T15:30:00'
+ }
+ }
+ ])
+
+ const topics = ref([
+ {
+ id: 2,
+ title: '2024年度最佳科幻电影推荐榜单',
+ author: 'SciFiFan',
+ createTime: '2025-06-03T10:30:00',
+ views: 1234,
+ replies: 45,
+ hot: true,
+ featured: false,
+ closed: false,
+ hasNewReplies: true,
+ lastReply: {
+ author: 'MovieLover',
+ time: '2025-06-03T14:25:00'
+ }
+ },
+ {
+ id: 3,
+ title: '阿凡达2:水之道 观影感受分享',
+ author: 'Avatar2Fan',
+ createTime: '2025-06-02T16:45:00',
+ views: 892,
+ replies: 67,
+ hot: false,
+ featured: true,
+ closed: false,
+ hasNewReplies: false,
+ lastReply: {
+ author: 'CinemaExpert',
+ time: '2025-06-03T12:10:00'
+ }
+ },
+ {
+ id: 4,
+ title: '求推荐几部好看的悬疑电影',
+ author: 'SuspenseLover',
+ createTime: '2025-06-01T09:20:00',
+ views: 456,
+ replies: 23,
+ hot: false,
+ featured: false,
+ closed: false,
+ hasNewReplies: true,
+ lastReply: {
+ author: 'ThrillerFan',
+ time: '2025-06-03T11:45:00'
+ }
+ }
+ ])
+
+ onMounted(() => {
+ const sectionId = route.params.id
+ fetchSectionData(sectionId)
+ })
+
+ const fetchSectionData = async (id) => {
+ loading.value = true
+ try {
+ // 模拟API调用
+ console.log('获取版块数据:', id)
+
+ // 根据版块ID设置不同的版块信息
+ const sections = {
+ 1: { name: '电影讨论', description: '分享和讨论电影资源,交流观影心得', icon: 'Film', color: '#409eff' },
+ 2: { name: '音乐分享', description: '音乐资源分享,音乐制作技术交流', icon: 'Headphones', color: '#67c23a' },
+ 3: { name: '软件技术', description: '软件资源分享,技术问题讨论', icon: 'Monitor', color: '#e6a23c' },
+ 4: { name: '游戏天地', description: '游戏资源分享,游戏攻略讨论', icon: 'GamePad', color: '#f56c6c' },
+ 5: { name: '站务公告', description: '网站公告,规则说明,意见建议', icon: 'Bell', color: '#909399' },
+ 6: { name: '新手求助', description: '新手问题解答,使用教程分享', icon: 'QuestionFilled', color: '#606266' }
+ }
+
+ const sectionData = sections[id] || sections[1]
+ sectionInfo.value = {
+ id: parseInt(id),
+ ...sectionData,
+ topics: 3256,
+ replies: 18934,
+ members: 1234
+ }
+
+ totalTopics.value = 156
+
+ } catch (error) {
+ ElMessage.error('获取版块数据失败')
+ } finally {
+ loading.value = false
+ }
+ }
+
+ const formatTime = (timeString) => {
+ const date = new Date(timeString)
+ const now = new Date()
+ const diff = now - date
+ const hours = Math.floor(diff / (1000 * 60 * 60))
+
+ if (hours < 1) return '刚刚'
+ if (hours < 24) return `${hours}小时前`
+ const days = Math.floor(hours / 24)
+ if (days < 7) return `${days}天前`
+
+ return date.toLocaleDateString('zh-CN', {
+ month: '2-digit',
+ day: '2-digit',
+ hour: '2-digit',
+ minute: '2-digit'
+ })
+ }
+
+ const navigateToTopic = (topicId) => {
+ router.push(`/forum/topic/${topicId}`)
+ }
+
+ const handleSearch = () => {
+ currentPage.value = 1
+ fetchTopics()
+ }
+
+ const handleFilter = () => {
+ currentPage.value = 1
+ fetchTopics()
+ }
+
+ const fetchTopics = async () => {
+ loading.value = true
+ try {
+ // 模拟API调用
+ await new Promise(resolve => setTimeout(resolve, 500))
+ console.log('获取主题列表:', { searchQuery: searchQuery.value, sortBy: sortBy.value, filterType: filterType.value })
+ } catch (error) {
+ ElMessage.error('获取主题列表失败')
+ } finally {
+ loading.value = false
+ }
+ }
+
+ const handleSizeChange = (size) => {
+ pageSize.value = size
+ currentPage.value = 1
+ fetchTopics()
+ }
+
+ const handleCurrentChange = (page) => {
+ currentPage.value = page
+ fetchTopics()
+ }
+
+ const showTagInput = () => {
+ tagInputVisible.value = true
+ nextTick(() => {
+ tagInputRef.value?.focus()
+ })
+ }
+
+ const addTopicTag = () => {
+ const tag = tagInputValue.value.trim()
+ if (tag && !newTopic.tags.includes(tag)) {
+ newTopic.tags.push(tag)
+ }
+ tagInputVisible.value = false
+ tagInputValue.value = ''
+ }
+
+ const removeTopicTag = (tag) => {
+ const index = newTopic.tags.indexOf(tag)
+ if (index > -1) {
+ newTopic.tags.splice(index, 1)
+ }
+ }
+
+ const handleCloseDialog = () => {
+ if (newTopic.title || newTopic.content) {
+ ElMessageBox.confirm(
+ '确定要关闭吗?未保存的内容将会丢失。',
+ '提示',
+ {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }
+ ).then(() => {
+ resetForm()
+ showNewTopicDialog.value = false
+ }).catch(() => {
+ // 用户取消
+ })
+ } else {
+ resetForm()
+ showNewTopicDialog.value = false
+ }
+ }
+
+ const submitNewTopic = async () => {
+ try {
+ await topicFormRef.value?.validate()
+
+ submitting.value = true
+
+ // 模拟提交过程
+ await new Promise(resolve => setTimeout(resolve, 1500))
+
+ ElMessage.success('主题发布成功!')
+ resetForm()
+ showNewTopicDialog.value = false
+
+ // 刷新主题列表
+ fetchTopics()
+
+ } catch (error) {
+ console.error('表单验证失败:', error)
+ } finally {
+ submitting.value = false
+ }
+ }
+
+ const resetForm = () => {
+ topicFormRef.value?.resetFields()
+ newTopic.title = ''
+ newTopic.content = ''
+ newTopic.tags = []
+ newTopic.options = []
+ }
+
+ return {
+ loading,
+ showNewTopicDialog,
+ submitting,
+ tagInputVisible,
+ tagInputValue,
+ searchQuery,
+ sortBy,
+ filterType,
+ currentPage,
+ pageSize,
+ totalTopics,
+ sectionInfo,
+ pinnedTopics,
+ topics,
+ newTopic,
+ topicRules,
+ topicFormRef,
+ tagInputRef,
+ formatTime,
+ navigateToTopic,
+ handleSearch,
+ handleFilter,
+ handleSizeChange,
+ handleCurrentChange,
+ showTagInput,
+ addTopicTag,
+ removeTopicTag,
+ handleCloseDialog,
+ submitNewTopic,
+ Edit,
+ Search,
+ ChatDotRound,
+ Comment,
+ User,
+ View,
+ Top,
+ ChatLineRound,
+ Film,
+ Headphones,
+ Monitor,
+ GamePad,
+ Bell,
+ QuestionFilled
+ }
+ }
+}
+</script>
+
+<style lang="scss" scoped>
+.section-page {
+ max-width: 1200px;
+ margin: 0 auto;
+ padding: 24px;
+ background: #f5f5f5;
+ min-height: 100vh;
+}
+
+.breadcrumb {
+ margin-bottom: 16px;
+}
+
+.section-header {
+ background: #fff;
+ border-radius: 12px;
+ padding: 32px;
+ margin-bottom: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ gap: 24px;
+
+ .section-info {
+ display: flex;
+ align-items: center;
+ gap: 20px;
+ flex: 1;
+
+ .section-details {
+ .section-name {
+ font-size: 28px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 8px 0;
+ }
+
+ .section-description {
+ font-size: 16px;
+ color: #7f8c8d;
+ margin: 0 0 16px 0;
+ }
+
+ .section-stats {
+ display: flex;
+ gap: 24px;
+
+ .stat-item {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ font-size: 14px;
+ color: #606266;
+ }
+ }
+ }
+ }
+
+ .section-actions {
+ flex-shrink: 0;
+ }
+}
+
+.filter-section {
+ background: #fff;
+ border-radius: 12px;
+ padding: 20px 24px;
+ margin-bottom: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ gap: 20px;
+
+ .filter-left {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ }
+
+ .filter-right {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+
+ .el-select {
+ width: 120px;
+ }
+ }
+}
+
+.pinned-topics, .normal-topics {
+ background: #fff;
+ border-radius: 12px;
+ padding: 24px;
+ margin-bottom: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ .section-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 20px;
+ background: none;
+ padding: 0;
+ box-shadow: none;
+
+ .section-title {
+ font-size: 18px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0;
+ }
+
+ .results-info {
+ font-size: 14px;
+ color: #909399;
+ }
+ }
+}
+
+.topics-list {
+ .topic-item {
+ display: flex;
+ align-items: center;
+ gap: 16px;
+ padding: 16px;
+ border: 1px solid #f0f0f0;
+ border-radius: 8px;
+ margin-bottom: 12px;
+ cursor: pointer;
+ transition: all 0.3s ease;
+
+ &:hover {
+ background: #f8f9fa;
+ border-color: #409eff;
+ transform: translateX(2px);
+ }
+
+ &.pinned {
+ background: linear-gradient(90deg, #fff7e6 0%, #fff 100%);
+ border-color: #e6a23c;
+ }
+
+ .topic-status {
+ width: 32px;
+ text-align: center;
+
+ .pin-icon {
+ color: #e6a23c;
+ }
+
+ .new-icon {
+ animation: pulse 2s infinite;
+ }
+ }
+
+ .topic-content {
+ flex: 1;
+
+ .topic-header {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ margin-bottom: 8px;
+
+ .topic-title {
+ font-size: 16px;
+ font-weight: 500;
+ color: #2c3e50;
+ margin: 0;
+ flex: 1;
+
+ &:hover {
+ color: #409eff;
+ }
+ }
+
+ .topic-tags {
+ .el-tag {
+ margin-left: 4px;
+ }
+ }
+ }
+
+ .topic-meta {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ .author-info {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+
+ .author-name {
+ font-size: 14px;
+ font-weight: 500;
+ color: #606266;
+ }
+
+ .create-time {
+ font-size: 12px;
+ color: #909399;
+ }
+ }
+
+ .topic-stats {
+ display: flex;
+ gap: 16px;
+
+ .stat-item {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ font-size: 12px;
+ color: #909399;
+ }
+ }
+ }
+ }
+
+ .last-reply {
+ width: 150px;
+ text-align: right;
+
+ .reply-info {
+ .reply-author {
+ font-size: 14px;
+ font-weight: 500;
+ color: #606266;
+ margin-bottom: 4px;
+ }
+
+ .reply-time {
+ font-size: 12px;
+ color: #909399;
+ }
+ }
+
+ .no-reply {
+ font-size: 12px;
+ color: #c0c4cc;
+ }
+ }
+ }
+
+ .no-topics {
+ text-align: center;
+ color: #909399;
+ padding: 60px 0;
+ font-size: 16px;
+ }
+}
+
+.pagination-wrapper {
+ margin-top: 24px;
+ text-align: center;
+}
+
+.tags-input {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 8px;
+ align-items: center;
+
+ .el-tag {
+ margin: 0;
+ }
+}
+
+@keyframes pulse {
+ 0% {
+ transform: scale(1);
+ }
+ 50% {
+ transform: scale(1.1);
+ }
+ 100% {
+ transform: scale(1);
+ }
+}
+
+@media (max-width: 768px) {
+ .section-page {
+ padding: 16px;
+ }
+
+ .section-header {
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 16px;
+
+ .section-info {
+ flex-direction: column;
+ text-align: center;
+
+ .section-stats {
+ justify-content: center;
+ }
+ }
+
+ .section-actions {
+ width: 100%;
+ text-align: center;
+ }
+ }
+
+ .filter-section {
+ flex-direction: column;
+ gap: 16px;
+
+ .filter-left, .filter-right {
+ width: 100%;
+ justify-content: center;
+ }
+
+ .filter-right {
+ .el-select {
+ width: 140px;
+ }
+ }
+ }
+
+ .topic-item {
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 12px;
+
+ .topic-status {
+ align-self: flex-start;
+ }
+
+ .topic-content {
+ width: 100%;
+
+ .topic-meta {
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 8px;
+ }
+ }
+
+ .last-reply {
+ width: 100%;
+ text-align: left;
+ }
+ }
+}
</style>
\ No newline at end of file
diff --git a/src/views/forum/ForumTopicView.vue b/src/views/forum/ForumTopicView.vue
index 027083f..e65b297 100644
--- a/src/views/forum/ForumTopicView.vue
+++ b/src/views/forum/ForumTopicView.vue
@@ -1,933 +1,933 @@
-<template>
- <div class="topic-detail-page">
- <div class="page-container">
- <!-- 面包屑导航 -->
- <div class="breadcrumb">
- <el-breadcrumb separator="/">
- <el-breadcrumb-item :to="{ path: '/forum' }">论坛首页</el-breadcrumb-item>
- <el-breadcrumb-item :to="{ path: `/forum/section/${topic.sectionId}` }">
- {{ topic.sectionName }}
- </el-breadcrumb-item>
- <el-breadcrumb-item>{{ topic.title }}</el-breadcrumb-item>
- </el-breadcrumb>
- </div>
-
- <!-- 主题信息 -->
- <div class="topic-header">
- <div class="topic-info">
- <div class="topic-title-row">
- <h1 class="topic-title">{{ topic.title }}</h1>
- <div class="topic-status">
- <el-tag v-if="topic.pinned" type="warning" size="small">置顶</el-tag>
- <el-tag v-if="topic.hot" type="danger" size="small">热门</el-tag>
- <el-tag v-if="topic.closed" type="info" size="small">已关闭</el-tag>
- </div>
- </div>
-
- <div class="topic-tags">
- <el-tag
- v-for="tag in topic.tags"
- :key="tag"
- size="small"
- type="info"
- effect="plain"
- >
- {{ tag }}
- </el-tag>
- </div>
-
- <div class="topic-meta">
- <div class="author-info">
- <el-avatar :size="32">{{ topic.author.charAt(0) }}</el-avatar>
- <div class="author-details">
- <span class="author-name">{{ topic.author }}</span>
- <span class="post-time">发表于 {{ formatDateTime(topic.createTime) }}</span>
- </div>
- </div>
-
- <div class="topic-stats">
- <div class="stat-item">
- <el-icon><View /></el-icon>
- <span>{{ topic.views }} 浏览</span>
- </div>
- <div class="stat-item">
- <el-icon><Comment /></el-icon>
- <span>{{ topic.replies }} 回复</span>
- </div>
- </div>
- </div>
- </div>
-
- <div class="topic-actions">
- <el-button
- v-if="!topic.closed"
- type="primary"
- :icon="Edit"
- @click="showReplyDialog = true"
- >
- 回复主题
- </el-button>
- <el-dropdown @command="handleTopicAction">
- <el-button :icon="More">
- 更多 <el-icon class="el-icon--right"><ArrowDown /></el-icon>
- </el-button>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item command="favorite">
- {{ isFavorited ? '取消收藏' : '收藏主题' }}
- </el-dropdown-item>
- <el-dropdown-item command="share">分享主题</el-dropdown-item>
- <el-dropdown-item command="report" divided>举报主题</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- </div>
- </div>
-
- <!-- 主题内容和回复列表 -->
- <div class="posts-container">
- <!-- 主楼 -->
- <div class="post-item main-post">
- <div class="post-header">
- <div class="floor-number">#1</div>
- <div class="post-author">
- <el-avatar :size="48">{{ topic.author.charAt(0) }}</el-avatar>
- <div class="author-info">
- <span class="author-name">{{ topic.author }}</span>
- <span class="author-title">{{ topic.authorTitle || '会员' }}</span>
- <div class="author-stats">
- <span>帖子: {{ topic.authorPosts || 0 }}</span>
- <span>声望: {{ topic.authorReputation || 0 }}</span>
- </div>
- </div>
- </div>
- <div class="post-time">
- {{ formatDateTime(topic.createTime) }}
- </div>
- </div>
-
- <div class="post-content">
- <div class="content-text" v-html="formatContent(topic.content)"></div>
- </div>
-
- <div class="post-actions">
- <el-button type="text" size="small" @click="likePost(topic.id)">
- <el-icon><Like /></el-icon>
- {{ topic.likes || 0 }}
- </el-button>
- <el-button type="text" size="small" @click="quotePost(topic)">
- <el-icon><ChatDotRound /></el-icon>
- 引用
- </el-button>
- <el-button type="text" size="small" @click="reportPost(topic.id)">
- <el-icon><Flag /></el-icon>
- 举报
- </el-button>
- </div>
- </div>
-
- <!-- 回复列表 -->
- <div
- v-for="(reply, index) in replies"
- :key="reply.id"
- class="post-item reply-post"
- >
- <div class="post-header">
- <div class="floor-number">#{{ index + 2 }}</div>
- <div class="post-author">
- <el-avatar :size="48">{{ reply.author.charAt(0) }}</el-avatar>
- <div class="author-info">
- <span class="author-name">{{ reply.author }}</span>
- <span class="author-title">{{ reply.authorTitle || '会员' }}</span>
- <div class="author-stats">
- <span>帖子: {{ reply.authorPosts || 0 }}</span>
- <span>声望: {{ reply.authorReputation || 0 }}</span>
- </div>
- </div>
- </div>
- <div class="post-time">
- {{ formatDateTime(reply.createTime) }}
- </div>
- </div>
-
- <div class="post-content">
- <div v-if="reply.quotedPost" class="quoted-content">
- <div class="quote-header">
- <el-icon><ChatDotRound /></el-icon>
- <span>{{ reply.quotedPost.author }} 发表于 {{ formatDateTime(reply.quotedPost.time) }}</span>
- </div>
- <div class="quote-text">{{ reply.quotedPost.content }}</div>
- </div>
- <div class="content-text" v-html="formatContent(reply.content)"></div>
- </div>
-
- <div class="post-actions">
- <el-button type="text" size="small" @click="likePost(reply.id)">
- <el-icon><Like /></el-icon>
- {{ reply.likes || 0 }}
- </el-button>
- <el-button type="text" size="small" @click="quotePost(reply)">
- <el-icon><ChatDotRound /></el-icon>
- 引用
- </el-button>
- <el-button type="text" size="small" @click="reportPost(reply.id)">
- <el-icon><Flag /></el-icon>
- 举报
- </el-button>
- </div>
- </div>
- </div>
-
- <!-- 分页 -->
- <div class="pagination-wrapper">
- <el-pagination
- v-model:current-page="currentPage"
- v-model:page-size="pageSize"
- :page-sizes="[10, 20, 50]"
- :total="totalReplies"
- layout="total, sizes, prev, pager, next, jumper"
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- />
- </div>
-
- <!-- 快速回复 -->
- <div v-if="!topic.closed" class="quick-reply">
- <h3>快速回复</h3>
- <el-input
- v-model="quickReplyContent"
- type="textarea"
- :rows="4"
- placeholder="输入你的回复..."
- maxlength="2000"
- show-word-limit
- />
- <div class="quick-reply-actions">
- <el-button @click="clearQuickReply">清空</el-button>
- <el-button type="primary" @click="submitQuickReply" :loading="submittingReply">
- 发表回复
- </el-button>
- </div>
- </div>
- </div>
-
- <!-- 回复对话框 -->
- <el-dialog
- v-model="showReplyDialog"
- title="回复主题"
- width="700px"
- :before-close="handleCloseReplyDialog"
- >
- <el-form
- ref="replyFormRef"
- :model="replyForm"
- :rules="replyRules"
- label-width="80px"
- >
- <el-form-item v-if="quotedContent" label="引用内容">
- <div class="quoted-preview">
- <div class="quote-header">
- <span>{{ quotedContent.author }}</span>
- </div>
- <div class="quote-content">{{ quotedContent.content }}</div>
- <el-button type="text" size="small" @click="clearQuote">
- 清除引用
- </el-button>
- </div>
- </el-form-item>
-
- <el-form-item label="回复内容" prop="content">
- <el-input
- v-model="replyForm.content"
- type="textarea"
- :rows="8"
- placeholder="请输入回复内容..."
- maxlength="5000"
- show-word-limit
- />
- </el-form-item>
- </el-form>
-
- <template #footer>
- <el-button @click="handleCloseReplyDialog">取消</el-button>
- <el-button type="primary" @click="submitReply" :loading="submittingReply">
- 发表回复
- </el-button>
- </template>
- </el-dialog>
- </div>
-</template>
-
-<script>
-import { ref, reactive, onMounted } from 'vue'
-import { useRoute, useRouter } from 'vue-router'
-import { ElMessage, ElMessageBox } from 'element-plus'
-import {
- Edit,
- More,
- View,
- Comment,
- Like,
- ChatDotRound,
- Flag,
- ArrowDown
-} from '@element-plus/icons-vue'
-
-export default {
- name: 'ForumTopicView',
- setup() {
- const route = useRoute()
- const router = useRouter()
- const replyFormRef = ref(null)
-
- const showReplyDialog = ref(false)
- const submittingReply = ref(false)
- const isFavorited = ref(false)
- const currentPage = ref(1)
- const pageSize = ref(20)
- const totalReplies = ref(0)
- const quickReplyContent = ref('')
- const quotedContent = ref(null)
-
- const topic = ref({
- id: 1,
- title: '2024年度最佳PT站点推荐与对比分析',
- sectionId: 1,
- sectionName: '站务讨论',
- author: 'PTExpert',
- authorTitle: '资深会员',
- authorPosts: 1256,
- authorReputation: 2890,
- createTime: '2025-06-01T10:30:00',
- content: `
- <p>大家好,作为一个使用PT站点多年的老用户,我想和大家分享一下2024年各大PT站点的使用体验和对比分析。</p>
-
- <h3>评测标准</h3>
- <ul>
- <li>资源丰富度:种子数量、更新速度、稀有资源</li>
- <li>用户体验:界面设计、功能完善度、响应速度</li>
- <li>社区氛围:用户活跃度、互帮互助程度</li>
- <li>规则友好性:考核难度、分享率要求、保种要求</li>
- </ul>
-
- <h3>推荐站点</h3>
- <p>经过综合评测,以下几个站点值得推荐:</p>
- <ol>
- <li><strong>站点A</strong>:资源最全,更新最快,适合影视爱好者</li>
- <li><strong>站点B</strong>:音乐资源丰富,无损居多,音质发烧友首选</li>
- <li><strong>站点C</strong>:软件资源全面,更新及时,开发者必备</li>
- </ol>
-
- <p>具体的详细评测报告我会在后续回复中逐一介绍,欢迎大家讨论和补充!</p>
- `,
- views: 2856,
- replies: 147,
- likes: 89,
- tags: ['PT站点', '推荐', '对比'],
- pinned: true,
- hot: true,
- closed: false
- })
-
- const replies = ref([
- {
- id: 2,
- author: 'MovieLover88',
- authorTitle: '影视达人',
- authorPosts: 567,
- authorReputation: 1234,
- createTime: '2025-06-01T11:15:00',
- content: '感谢楼主的详细分析!特别期待站点A的详细评测,最近正在寻找好的影视资源站点。',
- likes: 12
- },
- {
- id: 3,
- author: 'TechGuru',
- authorTitle: '技术专家',
- authorPosts: 890,
- authorReputation: 2156,
- createTime: '2025-06-01T12:30:00',
- content: '站点C确实不错,软件资源很全面。不过楼主能不能也评测一下游戏类的PT站点?',
- likes: 8,
- quotedPost: {
- author: 'PTExpert',
- time: '2025-06-01T10:30:00',
- content: '站点C:软件资源全面,更新及时,开发者必备'
- }
- }
- ])
-
- const replyForm = reactive({
- content: ''
- })
-
- const replyRules = {
- content: [
- { required: true, message: '请输入回复内容', trigger: 'blur' },
- { min: 5, max: 5000, message: '内容长度在 5 到 5000 个字符', trigger: 'blur' }
- ]
- }
-
- onMounted(() => {
- const topicId = route.params.id
- fetchTopicDetail(topicId)
- })
-
- const fetchTopicDetail = async (id) => {
- try {
- console.log('获取主题详情:', id)
- totalReplies.value = 147
- } catch (error) {
- ElMessage.error('获取主题详情失败')
- router.back()
- }
- }
-
- const formatDateTime = (dateString) => {
- const date = new Date(dateString)
- return date.toLocaleString('zh-CN', {
- year: 'numeric',
- month: '2-digit',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit'
- })
- }
-
- const formatContent = (content) => {
- return content.replace(/\n/g, '<br>')
- }
-
- const handleTopicAction = (command) => {
- switch (command) {
- case 'favorite':
- isFavorited.value = !isFavorited.value
- ElMessage.success(isFavorited.value ? '已收藏' : '已取消收藏')
- break
- case 'share':
- navigator.clipboard.writeText(window.location.href)
- ElMessage.success('链接已复制到剪贴板')
- break
- case 'report':
- reportPost(topic.value.id)
- break
- }
- }
-
- const likePost = (postId) => {
- if (postId === topic.value.id) {
- topic.value.likes = (topic.value.likes || 0) + 1
- } else {
- const reply = replies.value.find(r => r.id === postId)
- if (reply) {
- reply.likes = (reply.likes || 0) + 1
- }
- }
- ElMessage.success('点赞成功')
- }
-
- const quotePost = (post) => {
- quotedContent.value = {
- author: post.author,
- content: post.content.replace(/<[^>]*>/g, '').substring(0, 100) + '...',
- time: post.createTime
- }
- showReplyDialog.value = true
- }
-
- const reportPost = async (postId) => {
- try {
- await ElMessageBox.prompt('请说明举报原因', '举报内容', {
- confirmButtonText: '提交举报',
- cancelButtonText: '取消',
- inputType: 'textarea',
- inputPlaceholder: '请详细说明举报原因...'
- })
-
- ElMessage.success('举报已提交,我们会尽快处理')
- } catch {
- // 用户取消
- }
- }
-
- const clearQuote = () => {
- quotedContent.value = null
- }
-
- const handleCloseReplyDialog = () => {
- if (replyForm.content) {
- ElMessageBox.confirm(
- '确定要关闭吗?未保存的内容将会丢失。',
- '提示',
- {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }
- ).then(() => {
- resetReplyForm()
- showReplyDialog.value = false
- }).catch(() => {
- // 用户取消
- })
- } else {
- resetReplyForm()
- showReplyDialog.value = false
- }
- }
-
- const submitReply = async () => {
- try {
- await replyFormRef.value?.validate()
-
- submittingReply.value = true
-
- await new Promise(resolve => setTimeout(resolve, 1500))
-
- const newReply = {
- id: Date.now(),
- author: localStorage.getItem('username') || '用户',
- authorTitle: '会员',
- authorPosts: 0,
- authorReputation: 0,
- createTime: new Date().toISOString(),
- content: replyForm.content,
- likes: 0,
- quotedPost: quotedContent.value
- }
-
- replies.value.push(newReply)
- topic.value.replies += 1
-
- ElMessage.success('回复发表成功!')
- resetReplyForm()
- showReplyDialog.value = false
-
- } catch (error) {
- console.error('表单验证失败:', error)
- } finally {
- submittingReply.value = false
- }
- }
-
- const submitQuickReply = async () => {
- if (!quickReplyContent.value.trim()) {
- ElMessage.warning('请输入回复内容')
- return
- }
-
- submittingReply.value = true
- try {
- await new Promise(resolve => setTimeout(resolve, 1000))
-
- const newReply = {
- id: Date.now(),
- author: localStorage.getItem('username') || '用户',
- authorTitle: '会员',
- authorPosts: 0,
- authorReputation: 0,
- createTime: new Date().toISOString(),
- content: quickReplyContent.value,
- likes: 0
- }
-
- replies.value.push(newReply)
- topic.value.replies += 1
- quickReplyContent.value = ''
-
- ElMessage.success('回复发表成功!')
- } catch (error) {
- ElMessage.error('发表回复失败')
- } finally {
- submittingReply.value = false
- }
- }
-
- const clearQuickReply = () => {
- quickReplyContent.value = ''
- }
-
- const resetReplyForm = () => {
- replyFormRef.value?.resetFields()
- replyForm.content = ''
- quotedContent.value = null
- }
-
- const handleSizeChange = (size) => {
- pageSize.value = size
- currentPage.value = 1
- }
-
- const handleCurrentChange = (page) => {
- currentPage.value = page
- }
-
- return {
- showReplyDialog,
- submittingReply,
- isFavorited,
- currentPage,
- pageSize,
- totalReplies,
- quickReplyContent,
- quotedContent,
- topic,
- replies,
- replyForm,
- replyRules,
- replyFormRef,
- formatDateTime,
- formatContent,
- handleTopicAction,
- likePost,
- quotePost,
- reportPost,
- clearQuote,
- handleCloseReplyDialog,
- submitReply,
- submitQuickReply,
- clearQuickReply,
- handleSizeChange,
- handleCurrentChange,
- Edit,
- More,
- View,
- Comment,
- Like,
- ChatDotRound,
- Flag,
- ArrowDown
- }
- }
-}
-</script>
-
-<style lang="scss" scoped>
-.topic-detail-page {
- max-width: 1000px;
- margin: 0 auto;
- padding: 24px;
- background: #f5f5f5;
- min-height: 100vh;
-}
-
-.breadcrumb {
- margin-bottom: 16px;
-}
-
-.topic-header {
- background: #fff;
- border-radius: 12px;
- padding: 24px;
- margin-bottom: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- display: flex;
- justify-content: space-between;
- align-items: flex-start;
- gap: 24px;
-
- .topic-info {
- flex: 1;
-
- .topic-title-row {
- display: flex;
- align-items: center;
- gap: 12px;
- margin-bottom: 12px;
-
- .topic-title {
- font-size: 24px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0;
- flex: 1;
- }
-
- .topic-status {
- .el-tag {
- margin-left: 8px;
- }
- }
- }
-
- .topic-tags {
- margin-bottom: 16px;
-
- .el-tag {
- margin-right: 8px;
- }
- }
-
- .topic-meta {
- display: flex;
- justify-content: space-between;
- align-items: center;
-
- .author-info {
- display: flex;
- align-items: center;
- gap: 12px;
-
- .author-details {
- .author-name {
- display: block;
- font-weight: 600;
- color: #2c3e50;
- font-size: 14px;
- }
-
- .post-time {
- display: block;
- font-size: 12px;
- color: #909399;
- }
- }
- }
-
- .topic-stats {
- display: flex;
- gap: 16px;
-
- .stat-item {
- display: flex;
- align-items: center;
- gap: 4px;
- font-size: 14px;
- color: #7f8c8d;
- }
- }
- }
- }
-
- .topic-actions {
- display: flex;
- gap: 12px;
- flex-shrink: 0;
- }
-}
-
-.posts-container {
- .post-item {
- background: #fff;
- border-radius: 12px;
- margin-bottom: 16px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
- overflow: hidden;
-
- &.main-post {
- border-left: 4px solid #409eff;
- }
-
- .post-header {
- background: #f8f9fa;
- padding: 16px 24px;
- display: flex;
- align-items: center;
- gap: 16px;
- border-bottom: 1px solid #f0f0f0;
-
- .floor-number {
- background: #409eff;
- color: white;
- padding: 4px 8px;
- border-radius: 4px;
- font-size: 12px;
- font-weight: 600;
- min-width: 32px;
- text-align: center;
- }
-
- .post-author {
- display: flex;
- align-items: center;
- gap: 12px;
- flex: 1;
-
- .author-info {
- .author-name {
- display: block;
- font-weight: 600;
- color: #2c3e50;
- font-size: 14px;
- }
-
- .author-title {
- display: block;
- font-size: 12px;
- color: #67c23a;
- margin-bottom: 4px;
- }
-
- .author-stats {
- font-size: 11px;
- color: #909399;
-
- span {
- margin-right: 12px;
- }
- }
- }
- }
-
- .post-time {
- font-size: 12px;
- color: #909399;
- }
- }
-
- .post-content {
- padding: 24px;
-
- .quoted-content {
- background: #f5f7fa;
- border-left: 4px solid #e4e7ed;
- padding: 12px 16px;
- margin-bottom: 16px;
- border-radius: 0 4px 4px 0;
-
- .quote-header {
- display: flex;
- align-items: center;
- gap: 8px;
- font-size: 12px;
- color: #909399;
- margin-bottom: 8px;
- }
-
- .quote-text {
- font-size: 14px;
- color: #606266;
- line-height: 1.5;
- }
- }
-
- .content-text {
- line-height: 1.6;
- color: #2c3e50;
-
- :deep(h3) {
- color: #2c3e50;
- font-size: 18px;
- font-weight: 600;
- margin: 20px 0 12px 0;
- }
-
- :deep(p) {
- margin-bottom: 12px;
- }
-
- :deep(ul), :deep(ol) {
- margin: 12px 0;
- padding-left: 20px;
-
- li {
- margin-bottom: 8px;
- }
- }
- }
- }
-
- .post-actions {
- padding: 12px 24px;
- border-top: 1px solid #f0f0f0;
- background: #fafafa;
-
- .el-button {
- margin-right: 16px;
-
- .el-icon {
- margin-right: 4px;
- }
- }
- }
- }
-}
-
-.pagination-wrapper {
- text-align: center;
- margin: 24px 0;
-}
-
-.quick-reply {
- background: #fff;
- border-radius: 12px;
- padding: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- h3 {
- font-size: 18px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 16px 0;
- }
-
- .quick-reply-actions {
- margin-top: 12px;
- text-align: right;
-
- .el-button {
- margin-left: 12px;
- }
- }
-}
-
-.quoted-preview {
- background: #f5f7fa;
- border: 1px solid #e4e7ed;
- border-radius: 4px;
- padding: 12px;
-
- .quote-header {
- font-size: 12px;
- color: #909399;
- margin-bottom: 8px;
- }
-
- .quote-content {
- font-size: 14px;
- color: #606266;
- margin-bottom: 8px;
- line-height: 1.5;
- }
-}
-
-@media (max-width: 768px) {
- .topic-detail-page {
- padding: 16px;
- }
-
- .topic-header {
- flex-direction: column;
- align-items: flex-start;
-
- .topic-actions {
- width: 100%;
- justify-content: flex-end;
- }
- }
-
- .post-header {
- flex-direction: column;
- align-items: flex-start;
- gap: 12px;
-
- .floor-number {
- align-self: flex-start;
- }
- }
-
- .post-content {
- padding: 16px;
- }
-
- .post-actions {
- padding: 12px 16px;
-
- .el-button {
- margin-right: 8px;
- margin-bottom: 8px;
- }
- }
-}
+<template>
+ <div class="topic-detail-page">
+ <div class="page-container">
+ <!-- 面包屑导航 -->
+ <div class="breadcrumb">
+ <el-breadcrumb separator="/">
+ <el-breadcrumb-item :to="{ path: '/forum' }">论坛首页</el-breadcrumb-item>
+ <el-breadcrumb-item :to="{ path: `/forum/section/${topic.sectionId}` }">
+ {{ topic.sectionName }}
+ </el-breadcrumb-item>
+ <el-breadcrumb-item>{{ topic.title }}</el-breadcrumb-item>
+ </el-breadcrumb>
+ </div>
+
+ <!-- 主题信息 -->
+ <div class="topic-header">
+ <div class="topic-info">
+ <div class="topic-title-row">
+ <h1 class="topic-title">{{ topic.title }}</h1>
+ <div class="topic-status">
+ <el-tag v-if="topic.pinned" type="warning" size="small">置顶</el-tag>
+ <el-tag v-if="topic.hot" type="danger" size="small">热门</el-tag>
+ <el-tag v-if="topic.closed" type="info" size="small">已关闭</el-tag>
+ </div>
+ </div>
+
+ <div class="topic-tags">
+ <el-tag
+ v-for="tag in topic.tags"
+ :key="tag"
+ size="small"
+ type="info"
+ effect="plain"
+ >
+ {{ tag }}
+ </el-tag>
+ </div>
+
+ <div class="topic-meta">
+ <div class="author-info">
+ <el-avatar :size="32">{{ topic.author.charAt(0) }}</el-avatar>
+ <div class="author-details">
+ <span class="author-name">{{ topic.author }}</span>
+ <span class="post-time">发表于 {{ formatDateTime(topic.createTime) }}</span>
+ </div>
+ </div>
+
+ <div class="topic-stats">
+ <div class="stat-item">
+ <el-icon><View /></el-icon>
+ <span>{{ topic.views }} 浏览</span>
+ </div>
+ <div class="stat-item">
+ <el-icon><Comment /></el-icon>
+ <span>{{ topic.replies }} 回复</span>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="topic-actions">
+ <el-button
+ v-if="!topic.closed"
+ type="primary"
+ :icon="Edit"
+ @click="showReplyDialog = true"
+ >
+ 回复主题
+ </el-button>
+ <el-dropdown @command="handleTopicAction">
+ <el-button :icon="More">
+ 更多 <el-icon class="el-icon--right"><ArrowDown /></el-icon>
+ </el-button>
+ <template #dropdown>
+ <el-dropdown-menu>
+ <el-dropdown-item command="favorite">
+ {{ isFavorited ? '取消收藏' : '收藏主题' }}
+ </el-dropdown-item>
+ <el-dropdown-item command="share">分享主题</el-dropdown-item>
+ <el-dropdown-item command="report" divided>举报主题</el-dropdown-item>
+ </el-dropdown-menu>
+ </template>
+ </el-dropdown>
+ </div>
+ </div>
+
+ <!-- 主题内容和回复列表 -->
+ <div class="posts-container">
+ <!-- 主楼 -->
+ <div class="post-item main-post">
+ <div class="post-header">
+ <div class="floor-number">#1</div>
+ <div class="post-author">
+ <el-avatar :size="48">{{ topic.author.charAt(0) }}</el-avatar>
+ <div class="author-info">
+ <span class="author-name">{{ topic.author }}</span>
+ <span class="author-title">{{ topic.authorTitle || '会员' }}</span>
+ <div class="author-stats">
+ <span>帖子: {{ topic.authorPosts || 0 }}</span>
+ <span>声望: {{ topic.authorReputation || 0 }}</span>
+ </div>
+ </div>
+ </div>
+ <div class="post-time">
+ {{ formatDateTime(topic.createTime) }}
+ </div>
+ </div>
+
+ <div class="post-content">
+ <div class="content-text" v-html="formatContent(topic.content)"></div>
+ </div>
+
+ <div class="post-actions">
+ <el-button type="text" size="small" @click="likePost(topic.id)">
+ <el-icon><Like /></el-icon>
+ {{ topic.likes || 0 }}
+ </el-button>
+ <el-button type="text" size="small" @click="quotePost(topic)">
+ <el-icon><ChatDotRound /></el-icon>
+ 引用
+ </el-button>
+ <el-button type="text" size="small" @click="reportPost(topic.id)">
+ <el-icon><Flag /></el-icon>
+ 举报
+ </el-button>
+ </div>
+ </div>
+
+ <!-- 回复列表 -->
+ <div
+ v-for="(reply, index) in replies"
+ :key="reply.id"
+ class="post-item reply-post"
+ >
+ <div class="post-header">
+ <div class="floor-number">#{{ index + 2 }}</div>
+ <div class="post-author">
+ <el-avatar :size="48">{{ reply.author.charAt(0) }}</el-avatar>
+ <div class="author-info">
+ <span class="author-name">{{ reply.author }}</span>
+ <span class="author-title">{{ reply.authorTitle || '会员' }}</span>
+ <div class="author-stats">
+ <span>帖子: {{ reply.authorPosts || 0 }}</span>
+ <span>声望: {{ reply.authorReputation || 0 }}</span>
+ </div>
+ </div>
+ </div>
+ <div class="post-time">
+ {{ formatDateTime(reply.createTime) }}
+ </div>
+ </div>
+
+ <div class="post-content">
+ <div v-if="reply.quotedPost" class="quoted-content">
+ <div class="quote-header">
+ <el-icon><ChatDotRound /></el-icon>
+ <span>{{ reply.quotedPost.author }} 发表于 {{ formatDateTime(reply.quotedPost.time) }}</span>
+ </div>
+ <div class="quote-text">{{ reply.quotedPost.content }}</div>
+ </div>
+ <div class="content-text" v-html="formatContent(reply.content)"></div>
+ </div>
+
+ <div class="post-actions">
+ <el-button type="text" size="small" @click="likePost(reply.id)">
+ <el-icon><Like /></el-icon>
+ {{ reply.likes || 0 }}
+ </el-button>
+ <el-button type="text" size="small" @click="quotePost(reply)">
+ <el-icon><ChatDotRound /></el-icon>
+ 引用
+ </el-button>
+ <el-button type="text" size="small" @click="reportPost(reply.id)">
+ <el-icon><Flag /></el-icon>
+ 举报
+ </el-button>
+ </div>
+ </div>
+ </div>
+
+ <!-- 分页 -->
+ <div class="pagination-wrapper">
+ <el-pagination
+ v-model:current-page="currentPage"
+ v-model:page-size="pageSize"
+ :page-sizes="[10, 20, 50]"
+ :total="totalReplies"
+ layout="total, sizes, prev, pager, next, jumper"
+ @size-change="handleSizeChange"
+ @current-change="handleCurrentChange"
+ />
+ </div>
+
+ <!-- 快速回复 -->
+ <div v-if="!topic.closed" class="quick-reply">
+ <h3>快速回复</h3>
+ <el-input
+ v-model="quickReplyContent"
+ type="textarea"
+ :rows="4"
+ placeholder="输入你的回复..."
+ maxlength="2000"
+ show-word-limit
+ />
+ <div class="quick-reply-actions">
+ <el-button @click="clearQuickReply">清空</el-button>
+ <el-button type="primary" @click="submitQuickReply" :loading="submittingReply">
+ 发表回复
+ </el-button>
+ </div>
+ </div>
+ </div>
+
+ <!-- 回复对话框 -->
+ <el-dialog
+ v-model="showReplyDialog"
+ title="回复主题"
+ width="700px"
+ :before-close="handleCloseReplyDialog"
+ >
+ <el-form
+ ref="replyFormRef"
+ :model="replyForm"
+ :rules="replyRules"
+ label-width="80px"
+ >
+ <el-form-item v-if="quotedContent" label="引用内容">
+ <div class="quoted-preview">
+ <div class="quote-header">
+ <span>{{ quotedContent.author }}</span>
+ </div>
+ <div class="quote-content">{{ quotedContent.content }}</div>
+ <el-button type="text" size="small" @click="clearQuote">
+ 清除引用
+ </el-button>
+ </div>
+ </el-form-item>
+
+ <el-form-item label="回复内容" prop="content">
+ <el-input
+ v-model="replyForm.content"
+ type="textarea"
+ :rows="8"
+ placeholder="请输入回复内容..."
+ maxlength="5000"
+ show-word-limit
+ />
+ </el-form-item>
+ </el-form>
+
+ <template #footer>
+ <el-button @click="handleCloseReplyDialog">取消</el-button>
+ <el-button type="primary" @click="submitReply" :loading="submittingReply">
+ 发表回复
+ </el-button>
+ </template>
+ </el-dialog>
+ </div>
+</template>
+
+<script>
+import { ref, reactive, onMounted } from 'vue'
+import { useRoute, useRouter } from 'vue-router'
+import { ElMessage, ElMessageBox } from 'element-plus'
+import {
+ Edit,
+ More,
+ View,
+ Comment,
+ Like,
+ ChatDotRound,
+ Flag,
+ ArrowDown
+} from '@element-plus/icons-vue'
+
+export default {
+ name: 'ForumTopicView',
+ setup() {
+ const route = useRoute()
+ const router = useRouter()
+ const replyFormRef = ref(null)
+
+ const showReplyDialog = ref(false)
+ const submittingReply = ref(false)
+ const isFavorited = ref(false)
+ const currentPage = ref(1)
+ const pageSize = ref(20)
+ const totalReplies = ref(0)
+ const quickReplyContent = ref('')
+ const quotedContent = ref(null)
+
+ const topic = ref({
+ id: 1,
+ title: '2024年度最佳PT站点推荐与对比分析',
+ sectionId: 1,
+ sectionName: '站务讨论',
+ author: 'PTExpert',
+ authorTitle: '资深会员',
+ authorPosts: 1256,
+ authorReputation: 2890,
+ createTime: '2025-06-01T10:30:00',
+ content: `
+ <p>大家好,作为一个使用PT站点多年的老用户,我想和大家分享一下2024年各大PT站点的使用体验和对比分析。</p>
+
+ <h3>评测标准</h3>
+ <ul>
+ <li>资源丰富度:种子数量、更新速度、稀有资源</li>
+ <li>用户体验:界面设计、功能完善度、响应速度</li>
+ <li>社区氛围:用户活跃度、互帮互助程度</li>
+ <li>规则友好性:考核难度、分享率要求、保种要求</li>
+ </ul>
+
+ <h3>推荐站点</h3>
+ <p>经过综合评测,以下几个站点值得推荐:</p>
+ <ol>
+ <li><strong>站点A</strong>:资源最全,更新最快,适合影视爱好者</li>
+ <li><strong>站点B</strong>:音乐资源丰富,无损居多,音质发烧友首选</li>
+ <li><strong>站点C</strong>:软件资源全面,更新及时,开发者必备</li>
+ </ol>
+
+ <p>具体的详细评测报告我会在后续回复中逐一介绍,欢迎大家讨论和补充!</p>
+ `,
+ views: 2856,
+ replies: 147,
+ likes: 89,
+ tags: ['PT站点', '推荐', '对比'],
+ pinned: true,
+ hot: true,
+ closed: false
+ })
+
+ const replies = ref([
+ {
+ id: 2,
+ author: 'MovieLover88',
+ authorTitle: '影视达人',
+ authorPosts: 567,
+ authorReputation: 1234,
+ createTime: '2025-06-01T11:15:00',
+ content: '感谢楼主的详细分析!特别期待站点A的详细评测,最近正在寻找好的影视资源站点。',
+ likes: 12
+ },
+ {
+ id: 3,
+ author: 'TechGuru',
+ authorTitle: '技术专家',
+ authorPosts: 890,
+ authorReputation: 2156,
+ createTime: '2025-06-01T12:30:00',
+ content: '站点C确实不错,软件资源很全面。不过楼主能不能也评测一下游戏类的PT站点?',
+ likes: 8,
+ quotedPost: {
+ author: 'PTExpert',
+ time: '2025-06-01T10:30:00',
+ content: '站点C:软件资源全面,更新及时,开发者必备'
+ }
+ }
+ ])
+
+ const replyForm = reactive({
+ content: ''
+ })
+
+ const replyRules = {
+ content: [
+ { required: true, message: '请输入回复内容', trigger: 'blur' },
+ { min: 5, max: 5000, message: '内容长度在 5 到 5000 个字符', trigger: 'blur' }
+ ]
+ }
+
+ onMounted(() => {
+ const topicId = route.params.id
+ fetchTopicDetail(topicId)
+ })
+
+ const fetchTopicDetail = async (id) => {
+ try {
+ console.log('获取主题详情:', id)
+ totalReplies.value = 147
+ } catch (error) {
+ ElMessage.error('获取主题详情失败')
+ router.back()
+ }
+ }
+
+ const formatDateTime = (dateString) => {
+ const date = new Date(dateString)
+ return date.toLocaleString('zh-CN', {
+ year: 'numeric',
+ month: '2-digit',
+ day: '2-digit',
+ hour: '2-digit',
+ minute: '2-digit'
+ })
+ }
+
+ const formatContent = (content) => {
+ return content.replace(/\n/g, '<br>')
+ }
+
+ const handleTopicAction = (command) => {
+ switch (command) {
+ case 'favorite':
+ isFavorited.value = !isFavorited.value
+ ElMessage.success(isFavorited.value ? '已收藏' : '已取消收藏')
+ break
+ case 'share':
+ navigator.clipboard.writeText(window.location.href)
+ ElMessage.success('链接已复制到剪贴板')
+ break
+ case 'report':
+ reportPost(topic.value.id)
+ break
+ }
+ }
+
+ const likePost = (postId) => {
+ if (postId === topic.value.id) {
+ topic.value.likes = (topic.value.likes || 0) + 1
+ } else {
+ const reply = replies.value.find(r => r.id === postId)
+ if (reply) {
+ reply.likes = (reply.likes || 0) + 1
+ }
+ }
+ ElMessage.success('点赞成功')
+ }
+
+ const quotePost = (post) => {
+ quotedContent.value = {
+ author: post.author,
+ content: post.content.replace(/<[^>]*>/g, '').substring(0, 100) + '...',
+ time: post.createTime
+ }
+ showReplyDialog.value = true
+ }
+
+ const reportPost = async (postId) => {
+ try {
+ await ElMessageBox.prompt('请说明举报原因', '举报内容', {
+ confirmButtonText: '提交举报',
+ cancelButtonText: '取消',
+ inputType: 'textarea',
+ inputPlaceholder: '请详细说明举报原因...'
+ })
+
+ ElMessage.success('举报已提交,我们会尽快处理')
+ } catch {
+ // 用户取消
+ }
+ }
+
+ const clearQuote = () => {
+ quotedContent.value = null
+ }
+
+ const handleCloseReplyDialog = () => {
+ if (replyForm.content) {
+ ElMessageBox.confirm(
+ '确定要关闭吗?未保存的内容将会丢失。',
+ '提示',
+ {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }
+ ).then(() => {
+ resetReplyForm()
+ showReplyDialog.value = false
+ }).catch(() => {
+ // 用户取消
+ })
+ } else {
+ resetReplyForm()
+ showReplyDialog.value = false
+ }
+ }
+
+ const submitReply = async () => {
+ try {
+ await replyFormRef.value?.validate()
+
+ submittingReply.value = true
+
+ await new Promise(resolve => setTimeout(resolve, 1500))
+
+ const newReply = {
+ id: Date.now(),
+ author: localStorage.getItem('username') || '用户',
+ authorTitle: '会员',
+ authorPosts: 0,
+ authorReputation: 0,
+ createTime: new Date().toISOString(),
+ content: replyForm.content,
+ likes: 0,
+ quotedPost: quotedContent.value
+ }
+
+ replies.value.push(newReply)
+ topic.value.replies += 1
+
+ ElMessage.success('回复发表成功!')
+ resetReplyForm()
+ showReplyDialog.value = false
+
+ } catch (error) {
+ console.error('表单验证失败:', error)
+ } finally {
+ submittingReply.value = false
+ }
+ }
+
+ const submitQuickReply = async () => {
+ if (!quickReplyContent.value.trim()) {
+ ElMessage.warning('请输入回复内容')
+ return
+ }
+
+ submittingReply.value = true
+ try {
+ await new Promise(resolve => setTimeout(resolve, 1000))
+
+ const newReply = {
+ id: Date.now(),
+ author: localStorage.getItem('username') || '用户',
+ authorTitle: '会员',
+ authorPosts: 0,
+ authorReputation: 0,
+ createTime: new Date().toISOString(),
+ content: quickReplyContent.value,
+ likes: 0
+ }
+
+ replies.value.push(newReply)
+ topic.value.replies += 1
+ quickReplyContent.value = ''
+
+ ElMessage.success('回复发表成功!')
+ } catch (error) {
+ ElMessage.error('发表回复失败')
+ } finally {
+ submittingReply.value = false
+ }
+ }
+
+ const clearQuickReply = () => {
+ quickReplyContent.value = ''
+ }
+
+ const resetReplyForm = () => {
+ replyFormRef.value?.resetFields()
+ replyForm.content = ''
+ quotedContent.value = null
+ }
+
+ const handleSizeChange = (size) => {
+ pageSize.value = size
+ currentPage.value = 1
+ }
+
+ const handleCurrentChange = (page) => {
+ currentPage.value = page
+ }
+
+ return {
+ showReplyDialog,
+ submittingReply,
+ isFavorited,
+ currentPage,
+ pageSize,
+ totalReplies,
+ quickReplyContent,
+ quotedContent,
+ topic,
+ replies,
+ replyForm,
+ replyRules,
+ replyFormRef,
+ formatDateTime,
+ formatContent,
+ handleTopicAction,
+ likePost,
+ quotePost,
+ reportPost,
+ clearQuote,
+ handleCloseReplyDialog,
+ submitReply,
+ submitQuickReply,
+ clearQuickReply,
+ handleSizeChange,
+ handleCurrentChange,
+ Edit,
+ More,
+ View,
+ Comment,
+ Like,
+ ChatDotRound,
+ Flag,
+ ArrowDown
+ }
+ }
+}
+</script>
+
+<style lang="scss" scoped>
+.topic-detail-page {
+ max-width: 1000px;
+ margin: 0 auto;
+ padding: 24px;
+ background: #f5f5f5;
+ min-height: 100vh;
+}
+
+.breadcrumb {
+ margin-bottom: 16px;
+}
+
+.topic-header {
+ background: #fff;
+ border-radius: 12px;
+ padding: 24px;
+ margin-bottom: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ display: flex;
+ justify-content: space-between;
+ align-items: flex-start;
+ gap: 24px;
+
+ .topic-info {
+ flex: 1;
+
+ .topic-title-row {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ margin-bottom: 12px;
+
+ .topic-title {
+ font-size: 24px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0;
+ flex: 1;
+ }
+
+ .topic-status {
+ .el-tag {
+ margin-left: 8px;
+ }
+ }
+ }
+
+ .topic-tags {
+ margin-bottom: 16px;
+
+ .el-tag {
+ margin-right: 8px;
+ }
+ }
+
+ .topic-meta {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ .author-info {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+
+ .author-details {
+ .author-name {
+ display: block;
+ font-weight: 600;
+ color: #2c3e50;
+ font-size: 14px;
+ }
+
+ .post-time {
+ display: block;
+ font-size: 12px;
+ color: #909399;
+ }
+ }
+ }
+
+ .topic-stats {
+ display: flex;
+ gap: 16px;
+
+ .stat-item {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ font-size: 14px;
+ color: #7f8c8d;
+ }
+ }
+ }
+ }
+
+ .topic-actions {
+ display: flex;
+ gap: 12px;
+ flex-shrink: 0;
+ }
+}
+
+.posts-container {
+ .post-item {
+ background: #fff;
+ border-radius: 12px;
+ margin-bottom: 16px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+ overflow: hidden;
+
+ &.main-post {
+ border-left: 4px solid #409eff;
+ }
+
+ .post-header {
+ background: #f8f9fa;
+ padding: 16px 24px;
+ display: flex;
+ align-items: center;
+ gap: 16px;
+ border-bottom: 1px solid #f0f0f0;
+
+ .floor-number {
+ background: #409eff;
+ color: white;
+ padding: 4px 8px;
+ border-radius: 4px;
+ font-size: 12px;
+ font-weight: 600;
+ min-width: 32px;
+ text-align: center;
+ }
+
+ .post-author {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ flex: 1;
+
+ .author-info {
+ .author-name {
+ display: block;
+ font-weight: 600;
+ color: #2c3e50;
+ font-size: 14px;
+ }
+
+ .author-title {
+ display: block;
+ font-size: 12px;
+ color: #67c23a;
+ margin-bottom: 4px;
+ }
+
+ .author-stats {
+ font-size: 11px;
+ color: #909399;
+
+ span {
+ margin-right: 12px;
+ }
+ }
+ }
+ }
+
+ .post-time {
+ font-size: 12px;
+ color: #909399;
+ }
+ }
+
+ .post-content {
+ padding: 24px;
+
+ .quoted-content {
+ background: #f5f7fa;
+ border-left: 4px solid #e4e7ed;
+ padding: 12px 16px;
+ margin-bottom: 16px;
+ border-radius: 0 4px 4px 0;
+
+ .quote-header {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ font-size: 12px;
+ color: #909399;
+ margin-bottom: 8px;
+ }
+
+ .quote-text {
+ font-size: 14px;
+ color: #606266;
+ line-height: 1.5;
+ }
+ }
+
+ .content-text {
+ line-height: 1.6;
+ color: #2c3e50;
+
+ :deep(h3) {
+ color: #2c3e50;
+ font-size: 18px;
+ font-weight: 600;
+ margin: 20px 0 12px 0;
+ }
+
+ :deep(p) {
+ margin-bottom: 12px;
+ }
+
+ :deep(ul), :deep(ol) {
+ margin: 12px 0;
+ padding-left: 20px;
+
+ li {
+ margin-bottom: 8px;
+ }
+ }
+ }
+ }
+
+ .post-actions {
+ padding: 12px 24px;
+ border-top: 1px solid #f0f0f0;
+ background: #fafafa;
+
+ .el-button {
+ margin-right: 16px;
+
+ .el-icon {
+ margin-right: 4px;
+ }
+ }
+ }
+ }
+}
+
+.pagination-wrapper {
+ text-align: center;
+ margin: 24px 0;
+}
+
+.quick-reply {
+ background: #fff;
+ border-radius: 12px;
+ padding: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ h3 {
+ font-size: 18px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 16px 0;
+ }
+
+ .quick-reply-actions {
+ margin-top: 12px;
+ text-align: right;
+
+ .el-button {
+ margin-left: 12px;
+ }
+ }
+}
+
+.quoted-preview {
+ background: #f5f7fa;
+ border: 1px solid #e4e7ed;
+ border-radius: 4px;
+ padding: 12px;
+
+ .quote-header {
+ font-size: 12px;
+ color: #909399;
+ margin-bottom: 8px;
+ }
+
+ .quote-content {
+ font-size: 14px;
+ color: #606266;
+ margin-bottom: 8px;
+ line-height: 1.5;
+ }
+}
+
+@media (max-width: 768px) {
+ .topic-detail-page {
+ padding: 16px;
+ }
+
+ .topic-header {
+ flex-direction: column;
+ align-items: flex-start;
+
+ .topic-actions {
+ width: 100%;
+ justify-content: flex-end;
+ }
+ }
+
+ .post-header {
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 12px;
+
+ .floor-number {
+ align-self: flex-start;
+ }
+ }
+
+ .post-content {
+ padding: 16px;
+ }
+
+ .post-actions {
+ padding: 12px 16px;
+
+ .el-button {
+ margin-right: 8px;
+ margin-bottom: 8px;
+ }
+ }
+}
</style>
\ No newline at end of file
diff --git a/src/views/forum/ForumView.vue b/src/views/forum/ForumView.vue
index e4fa0f9..22345e6 100644
--- a/src/views/forum/ForumView.vue
+++ b/src/views/forum/ForumView.vue
@@ -1,978 +1,978 @@
-<template>
- <div class="forum-page">
- <div class="page-container">
- <!-- 论坛头部 -->
- <div class="forum-header">
- <div class="header-content">
- <h1>社区论坛</h1>
- <p class="header-description">与其他用户交流讨论,分享经验心得</p>
- <div class="header-actions">
- <el-button type="primary" :icon="Edit" @click="showNewTopicDialog = true">
- 发布新帖
- </el-button>
- </div>
- </div>
- </div>
-
- <!-- 论坛统计 -->
- <div class="forum-stats">
- <div class="stats-grid">
- <div class="stat-item">
- <el-icon size="32" color="#409eff"><ChatDotRound /></el-icon>
- <div class="stat-info">
- <h3>{{ forumStats.totalTopics }}</h3>
- <p>主题总数</p>
- </div>
- </div>
- <div class="stat-item">
- <el-icon size="32" color="#67c23a"><Comment /></el-icon>
- <div class="stat-info">
- <h3>{{ forumStats.totalReplies }}</h3>
- <p>回复总数</p>
- </div>
- </div>
- <div class="stat-item">
- <el-icon size="32" color="#e6a23c"><User /></el-icon>
- <div class="stat-info">
- <h3>{{ forumStats.activeUsers }}</h3>
- <p>活跃用户</p>
- </div>
- </div>
- <div class="stat-item">
- <el-icon size="32" color="#f56c6c"><View /></el-icon>
- <div class="stat-info">
- <h3>{{ forumStats.todayPosts }}</h3>
- <p>今日发帖</p>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 版块列表 -->
- <div class="forum-sections">
- <h2 class="section-title">论坛版块</h2>
- <div class="sections-list">
- <div
- v-for="section in forumSections"
- :key="section.id"
- class="section-card"
- @click="navigateToSection(section.id)"
- >
- <div class="section-icon">
- <el-icon size="48" :color="section.color">
- <component :is="section.icon" />
- </el-icon>
- </div>
- <div class="section-info">
- <h3 class="section-name">{{ section.name }}</h3>
- <p class="section-description">{{ section.description }}</p>
- <div class="section-stats">
- <span class="stat">{{ section.topics }} 主题</span>
- <span class="stat">{{ section.replies }} 回复</span>
- </div>
- </div>
- <div class="section-latest">
- <div v-if="section.latestTopic" class="latest-topic">
- <p class="topic-title">{{ section.latestTopic.title }}</p>
- <div class="topic-meta">
- <span class="author">{{ section.latestTopic.author }}</span>
- <span class="time">{{ formatTime(section.latestTopic.time) }}</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 热门主题 -->
- <div class="hot-topics">
- <div class="section-header">
- <h2 class="section-title">热门主题</h2>
- <el-button type="primary" text @click="$router.push('/forum/topics')">
- 查看全部 <el-icon><ArrowRight /></el-icon>
- </el-button>
- </div>
- <div class="topics-list">
- <div
- v-for="topic in hotTopics"
- :key="topic.id"
- class="topic-item"
- @click="navigateToTopic(topic.id)"
- >
- <div class="topic-content">
- <div class="topic-header">
- <h4 class="topic-title">{{ topic.title }}</h4>
- <div class="topic-tags">
- <el-tag
- v-for="tag in topic.tags"
- :key="tag"
- size="small"
- type="info"
- >
- {{ tag }}
- </el-tag>
- </div>
- </div>
- <div class="topic-meta">
- <div class="author-info">
- <el-avatar :size="24">{{ topic.author.charAt(0) }}</el-avatar>
- <span class="author-name">{{ topic.author }}</span>
- </div>
- <div class="topic-stats">
- <span class="stat-item">
- <el-icon><View /></el-icon>
- {{ topic.views }}
- </span>
- <span class="stat-item">
- <el-icon><Comment /></el-icon>
- {{ topic.replies }}
- </span>
- <span class="time">{{ formatTime(topic.lastReply) }}</span>
- </div>
- </div>
- </div>
- <div class="topic-status">
- <el-tag v-if="topic.pinned" type="warning" size="small">置顶</el-tag>
- <el-tag v-if="topic.hot" type="danger" size="small">热门</el-tag>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 最新回复 -->
- <div class="recent-replies">
- <h2 class="section-title">最新回复</h2>
- <div class="replies-list">
- <div
- v-for="reply in recentReplies"
- :key="reply.id"
- class="reply-item"
- @click="navigateToTopic(reply.topicId)"
- >
- <div class="reply-avatar">
- <el-avatar :size="40">{{ reply.author.charAt(0) }}</el-avatar>
- </div>
- <div class="reply-content">
- <div class="reply-header">
- <span class="reply-author">{{ reply.author }}</span>
- <span class="reply-action">回复了主题</span>
- <span class="topic-title">{{ reply.topicTitle }}</span>
- </div>
- <div class="reply-text">{{ reply.content }}</div>
- <div class="reply-time">{{ formatTime(reply.time) }}</div>
- </div>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 发布新帖对话框 -->
- <el-dialog
- v-model="showNewTopicDialog"
- title="发布新主题"
- width="600px"
- :before-close="handleCloseDialog"
- >
- <el-form
- ref="topicFormRef"
- :model="newTopic"
- :rules="topicRules"
- label-width="80px"
- >
- <el-form-item label="版块" prop="sectionId">
- <el-select v-model="newTopic.sectionId" placeholder="选择版块">
- <el-option
- v-for="section in forumSections"
- :key="section.id"
- :label="section.name"
- :value="section.id"
- />
- </el-select>
- </el-form-item>
-
- <el-form-item label="标题" prop="title">
- <el-input
- v-model="newTopic.title"
- placeholder="请输入主题标题"
- maxlength="100"
- show-word-limit
- />
- </el-form-item>
-
- <el-form-item label="标签">
- <div class="tags-input">
- <el-tag
- v-for="tag in newTopic.tags"
- :key="tag"
- closable
- @close="removeTopicTag(tag)"
- >
- {{ tag }}
- </el-tag>
- <el-input
- v-if="tagInputVisible"
- ref="tagInputRef"
- v-model="tagInputValue"
- size="small"
- @keyup.enter="addTopicTag"
- @blur="addTopicTag"
- style="width: 100px;"
- />
- <el-button
- v-else
- size="small"
- @click="showTagInput"
- >
- + 添加标签
- </el-button>
- </div>
- </el-form-item>
-
- <el-form-item label="内容" prop="content">
- <el-input
- v-model="newTopic.content"
- type="textarea"
- :rows="8"
- placeholder="请输入主题内容..."
- maxlength="5000"
- show-word-limit
- />
- </el-form-item>
- </el-form>
-
- <template #footer>
- <el-button @click="handleCloseDialog">取消</el-button>
- <el-button type="primary" @click="submitNewTopic" :loading="submitting">
- 发布主题
- </el-button>
- </template>
- </el-dialog>
- </div>
-</template>
-
-<script>
-import { ref, reactive, onMounted, nextTick } from 'vue'
-import { useRouter } from 'vue-router'
-import { ElMessage, ElMessageBox } from 'element-plus'
-import {
- Edit,
- ChatDotRound,
- Comment,
- User,
- View,
- ArrowRight,
- Film,
- Headphones,
- Monitor,
- GamePad,
- ChatLineRound,
- QuestionFilled,
- Bell
-} from '@element-plus/icons-vue'
-
-export default {
- name: 'ForumView',
- setup() {
- const router = useRouter()
- const topicFormRef = ref(null)
- const tagInputRef = ref(null)
-
- const showNewTopicDialog = ref(false)
- const submitting = ref(false)
- const tagInputVisible = ref(false)
- const tagInputValue = ref('')
-
- const forumStats = reactive({
- totalTopics: '15,268',
- totalReplies: '89,456',
- activeUsers: '2,341',
- todayPosts: '156'
- })
-
- const newTopic = reactive({
- sectionId: '',
- title: '',
- content: '',
- tags: []
- })
-
- const topicRules = {
- sectionId: [
- { required: true, message: '请选择版块', trigger: 'change' }
- ],
- title: [
- { required: true, message: '请输入标题', trigger: 'blur' },
- { min: 5, max: 100, message: '标题长度在 5 到 100 个字符', trigger: 'blur' }
- ],
- content: [
- { required: true, message: '请输入内容', trigger: 'blur' },
- { min: 10, max: 5000, message: '内容长度在 10 到 5000 个字符', trigger: 'blur' }
- ]
- }
-
- const forumSections = ref([
- {
- id: 1,
- name: '电影讨论',
- description: '分享和讨论电影资源,交流观影心得',
- icon: 'Film',
- color: '#409eff',
- topics: 3256,
- replies: 18934,
- latestTopic: {
- title: '2024年最佳科幻电影推荐',
- author: 'MovieFan',
- time: '2025-06-03T14:30:00'
- }
- },
- {
- id: 2,
- name: '音乐分享',
- description: '音乐资源分享,音乐制作技术交流',
- icon: 'Headphones',
- color: '#67c23a',
- topics: 1892,
- replies: 9567,
- latestTopic: {
- title: '无损音乐格式对比分析',
- author: 'AudioExpert',
- time: '2025-06-03T13:45:00'
- }
- },
- {
- id: 3,
- name: '软件技术',
- description: '软件资源分享,技术问题讨论',
- icon: 'Monitor',
- color: '#e6a23c',
- topics: 2134,
- replies: 12456,
- latestTopic: {
- title: 'Adobe 2025 新功能体验分享',
- author: 'TechGuru',
- time: '2025-06-03T12:20:00'
- }
- },
- {
- id: 4,
- name: '游戏天地',
- description: '游戏资源分享,游戏攻略讨论',
- icon: 'GamePad',
- color: '#f56c6c',
- topics: 1567,
- replies: 8234,
- latestTopic: {
- title: '年度游戏大作盘点',
- author: 'GameMaster',
- time: '2025-06-03T11:50:00'
- }
- },
- {
- id: 5,
- name: '站务公告',
- description: '网站公告,规则说明,意见建议',
- icon: 'Bell',
- color: '#909399',
- topics: 234,
- replies: 1567,
- latestTopic: {
- title: '网站维护通知',
- author: 'Admin',
- time: '2025-06-03T10:00:00'
- }
- },
- {
- id: 6,
- name: '新手求助',
- description: '新手问题解答,使用教程分享',
- icon: 'QuestionFilled',
- color: '#606266',
- topics: 456,
- replies: 2890,
- latestTopic: {
- title: '新手如何提高分享率?',
- author: 'Newbie123',
- time: '2025-06-03T09:30:00'
- }
- }
- ])
-
- const hotTopics = ref([
- {
- id: 1,
- title: '2024年度最佳PT站点推荐与对比分析',
- author: 'PTExpert',
- views: 2856,
- replies: 147,
- lastReply: '2025-06-03T14:25:00',
- tags: ['PT站点', '推荐', '对比'],
- pinned: true,
- hot: true
- },
- {
- id: 2,
- title: '如何安全高效地使用BT下载工具',
- author: 'SafeDownloader',
- views: 1932,
- replies: 89,
- lastReply: '2025-06-03T13:50:00',
- tags: ['BT工具', '安全', '教程'],
- hot: true
- },
- {
- id: 3,
- title: '分享率提升技巧与经验总结',
- author: 'SeedMaster',
- views: 1654,
- replies: 76,
- lastReply: '2025-06-03T12:40:00',
- tags: ['分享率', '技巧', '经验']
- }
- ])
-
- const recentReplies = ref([
- {
- id: 1,
- author: 'MovieLover88',
- topicId: 1,
- topicTitle: '阿凡达2观影感受分享',
- content: '画面效果确实震撼,特别是水下的场景...',
- time: '2025-06-03T14:45:00'
- },
- {
- id: 2,
- author: 'TechEnthusiast',
- topicId: 2,
- topicTitle: '最新版Photoshop使用技巧',
- content: '新的AI功能确实很强大,大大提高了工作效率...',
- time: '2025-06-03T14:30:00'
- },
- {
- id: 3,
- author: 'GameFan2024',
- topicId: 3,
- topicTitle: '赛博朋克2077最新更新体验',
- content: '修复了很多bug,现在游戏体验好多了...',
- time: '2025-06-03T14:15:00'
- }
- ])
-
- onMounted(() => {
- // 初始化论坛数据
- })
-
- const formatTime = (timeString) => {
- const date = new Date(timeString)
- const now = new Date()
- const diff = now - date
- const hours = Math.floor(diff / (1000 * 60 * 60))
-
- if (hours < 1) return '刚刚'
- if (hours < 24) return `${hours}小时前`
- const days = Math.floor(hours / 24)
- return `${days}天前`
- }
-
- const navigateToSection = (sectionId) => {
- router.push(`/forum/section/${sectionId}`)
- }
-
- const navigateToTopic = (topicId) => {
- router.push(`/forum/topic/${topicId}`)
- }
-
- const showTagInput = () => {
- tagInputVisible.value = true
- nextTick(() => {
- tagInputRef.value?.focus()
- })
- }
-
- const addTopicTag = () => {
- const tag = tagInputValue.value.trim()
- if (tag && !newTopic.tags.includes(tag)) {
- newTopic.tags.push(tag)
- }
- tagInputVisible.value = false
- tagInputValue.value = ''
- }
-
- const removeTopicTag = (tag) => {
- const index = newTopic.tags.indexOf(tag)
- if (index > -1) {
- newTopic.tags.splice(index, 1)
- }
- }
-
- const handleCloseDialog = () => {
- if (newTopic.title || newTopic.content) {
- ElMessageBox.confirm(
- '确定要关闭吗?未保存的内容将会丢失。',
- '提示',
- {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }
- ).then(() => {
- resetForm()
- showNewTopicDialog.value = false
- }).catch(() => {
- // 用户取消
- })
- } else {
- resetForm()
- showNewTopicDialog.value = false
- }
- }
-
- const submitNewTopic = async () => {
- try {
- await topicFormRef.value?.validate()
-
- submitting.value = true
-
- // 模拟提交过程
- await new Promise(resolve => setTimeout(resolve, 1500))
-
- ElMessage.success('主题发布成功!')
- resetForm()
- showNewTopicDialog.value = false
-
- // 跳转到新创建的主题页面
- router.push('/forum/topic/new')
-
- } catch (error) {
- console.error('表单验证失败:', error)
- } finally {
- submitting.value = false
- }
- }
-
- const resetForm = () => {
- topicFormRef.value?.resetFields()
- newTopic.sectionId = ''
- newTopic.title = ''
- newTopic.content = ''
- newTopic.tags = []
- }
-
- return {
- showNewTopicDialog,
- submitting,
- tagInputVisible,
- tagInputValue,
- topicFormRef,
- tagInputRef,
- forumStats,
- forumSections,
- hotTopics,
- recentReplies,
- newTopic,
- topicRules,
- formatTime,
- navigateToSection,
- navigateToTopic,
- showTagInput,
- addTopicTag,
- removeTopicTag,
- handleCloseDialog,
- submitNewTopic,
- Edit,
- ChatDotRound,
- Comment,
- User,
- View,
- ArrowRight,
- Film,
- Headphones,
- Monitor,
- GamePad,
- Bell,
- QuestionFilled
- }
- }
-}
-</script>
-
-<style lang="scss" scoped>
-.forum-page {
- max-width: 1200px;
- margin: 0 auto;
- padding: 24px;
- background: #f5f5f5;
- min-height: 100vh;
-}
-
-.forum-header {
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- border-radius: 12px;
- padding: 48px 32px;
- margin-bottom: 24px;
- color: white;
- text-align: center;
-
- h1 {
- font-size: 36px;
- font-weight: 600;
- margin: 0 0 12px 0;
- }
-
- .header-description {
- font-size: 18px;
- margin: 0 0 24px 0;
- opacity: 0.9;
- }
-}
-
-.forum-stats {
- background: #fff;
- border-radius: 12px;
- padding: 24px;
- margin-bottom: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- .stats-grid {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
- gap: 24px;
-
- .stat-item {
- display: flex;
- align-items: center;
- gap: 16px;
-
- .stat-info {
- h3 {
- font-size: 24px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 4px 0;
- }
-
- p {
- font-size: 14px;
- color: #7f8c8d;
- margin: 0;
- }
- }
- }
- }
-}
-
-.forum-sections {
- background: #fff;
- border-radius: 12px;
- padding: 24px;
- margin-bottom: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- .section-title {
- font-size: 20px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 20px 0;
- }
-
- .sections-list {
- .section-card {
- display: flex;
- align-items: center;
- gap: 20px;
- padding: 20px;
- border: 1px solid #f0f0f0;
- border-radius: 8px;
- margin-bottom: 12px;
- cursor: pointer;
- transition: all 0.3s ease;
-
- &:hover {
- background: #f8f9fa;
- border-color: #409eff;
- transform: translateX(4px);
- }
-
- .section-info {
- flex: 1;
-
- .section-name {
- font-size: 18px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 8px 0;
- }
-
- .section-description {
- font-size: 14px;
- color: #7f8c8d;
- margin: 0 0 12px 0;
- }
-
- .section-stats {
- display: flex;
- gap: 16px;
-
- .stat {
- font-size: 12px;
- color: #909399;
- }
- }
- }
-
- .section-latest {
- width: 200px;
-
- .latest-topic {
- .topic-title {
- font-size: 14px;
- color: #2c3e50;
- margin: 0 0 8px 0;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- }
-
- .topic-meta {
- font-size: 12px;
- color: #909399;
-
- .author {
- margin-right: 8px;
- }
- }
- }
- }
- }
- }
-}
-
-.hot-topics {
- background: #fff;
- border-radius: 12px;
- padding: 24px;
- margin-bottom: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- .section-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20px;
-
- .section-title {
- font-size: 20px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0;
- }
- }
-
- .topics-list {
- .topic-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 16px;
- border: 1px solid #f0f0f0;
- border-radius: 8px;
- margin-bottom: 12px;
- cursor: pointer;
- transition: all 0.3s ease;
-
- &:hover {
- background: #f8f9fa;
- border-color: #409eff;
- }
-
- .topic-content {
- flex: 1;
-
- .topic-header {
- display: flex;
- align-items: center;
- gap: 12px;
- margin-bottom: 8px;
-
- .topic-title {
- font-size: 16px;
- font-weight: 500;
- color: #2c3e50;
- margin: 0;
- }
-
- .topic-tags {
- .el-tag {
- margin-right: 4px;
- }
- }
- }
-
- .topic-meta {
- display: flex;
- justify-content: space-between;
- align-items: center;
-
- .author-info {
- display: flex;
- align-items: center;
- gap: 8px;
-
- .author-name {
- font-size: 14px;
- color: #7f8c8d;
- }
- }
-
- .topic-stats {
- display: flex;
- align-items: center;
- gap: 16px;
- font-size: 12px;
- color: #909399;
-
- .stat-item {
- display: flex;
- align-items: center;
- gap: 4px;
- }
- }
- }
- }
-
- .topic-status {
- .el-tag {
- margin-left: 8px;
- }
- }
- }
- }
-}
-
-.recent-replies {
- background: #fff;
- border-radius: 12px;
- padding: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- .section-title {
- font-size: 20px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 20px 0;
- }
-
- .replies-list {
- .reply-item {
- display: flex;
- flex-direction: column;
- gap: 12px;
- padding: 16px;
- border: 1px solid #f0f0f0;
- border-radius: 8px;
- margin-bottom: 12px;
- cursor: pointer;
- transition: all 0.3s ease;
-
- &:hover {
- background: #f8f9fa;
- border-color: #409eff;
- }
-
- .reply-content {
- flex: 1;
-
- .reply-header {
- font-size: 14px;
- margin-bottom: 8px;
-
- .reply-author {
- font-weight: 600;
- color: #2c3e50;
- }
-
- .reply-action {
- color: #7f8c8d;
- margin: 0 4px;
- }
-
- .topic-title {
- color: #409eff;
- font-weight: 500;
- }
- }
-
- .reply-text {
- font-size: 14px;
- color: #5a6c7d;
- margin-bottom: 8px;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- }
-
- .reply-time {
- font-size: 12px;
- color: #909399;
- }
- }
- }
- }
-}
-</style>
-
-.tags-input {
- display: flex;
- flex-wrap: wrap;
- gap: 8px;
- align-items: center;
-
- .el-tag {
- margin: 0;
- }
-}
-
-@media (max-width: 768px) {
- .forum-page {
- padding: 16px;
- }
-
- .forum-header {
- padding: 32px 24px;
-
- h1 {
- font-size: 28px;
- }
-
- .header-description {
- font-size: 16px;
- }
- }
-
- .stats-grid {
- grid-template-columns: repeat(2, 1fr);
- }
-
- .section-card {
- flex-direction: column;
- text-align: center;
-
- .section-latest {
- width: 100%;
- margin-top: 16px;
- }
- }
-
- .topic-item {
- flex-direction: column;
- align-items: flex-start;
-
- .topic-status {
- margin-top: 12px;
- align-self: flex-end;
- }
- }
+<template>
+ <div class="forum-page">
+ <div class="page-container">
+ <!-- 论坛头部 -->
+ <div class="forum-header">
+ <div class="header-content">
+ <h1>社区论坛</h1>
+ <p class="header-description">与其他用户交流讨论,分享经验心得</p>
+ <div class="header-actions">
+ <el-button type="primary" :icon="Edit" @click="showNewTopicDialog = true">
+ 发布新帖
+ </el-button>
+ </div>
+ </div>
+ </div>
+
+ <!-- 论坛统计 -->
+ <div class="forum-stats">
+ <div class="stats-grid">
+ <div class="stat-item">
+ <el-icon size="32" color="#409eff"><ChatDotRound /></el-icon>
+ <div class="stat-info">
+ <h3>{{ forumStats.totalTopics }}</h3>
+ <p>主题总数</p>
+ </div>
+ </div>
+ <div class="stat-item">
+ <el-icon size="32" color="#67c23a"><Comment /></el-icon>
+ <div class="stat-info">
+ <h3>{{ forumStats.totalReplies }}</h3>
+ <p>回复总数</p>
+ </div>
+ </div>
+ <div class="stat-item">
+ <el-icon size="32" color="#e6a23c"><User /></el-icon>
+ <div class="stat-info">
+ <h3>{{ forumStats.activeUsers }}</h3>
+ <p>活跃用户</p>
+ </div>
+ </div>
+ <div class="stat-item">
+ <el-icon size="32" color="#f56c6c"><View /></el-icon>
+ <div class="stat-info">
+ <h3>{{ forumStats.todayPosts }}</h3>
+ <p>今日发帖</p>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- 版块列表 -->
+ <div class="forum-sections">
+ <h2 class="section-title">论坛版块</h2>
+ <div class="sections-list">
+ <div
+ v-for="section in forumSections"
+ :key="section.id"
+ class="section-card"
+ @click="navigateToSection(section.id)"
+ >
+ <div class="section-icon">
+ <el-icon size="48" :color="section.color">
+ <component :is="section.icon" />
+ </el-icon>
+ </div>
+ <div class="section-info">
+ <h3 class="section-name">{{ section.name }}</h3>
+ <p class="section-description">{{ section.description }}</p>
+ <div class="section-stats">
+ <span class="stat">{{ section.topics }} 主题</span>
+ <span class="stat">{{ section.replies }} 回复</span>
+ </div>
+ </div>
+ <div class="section-latest">
+ <div v-if="section.latestTopic" class="latest-topic">
+ <p class="topic-title">{{ section.latestTopic.title }}</p>
+ <div class="topic-meta">
+ <span class="author">{{ section.latestTopic.author }}</span>
+ <span class="time">{{ formatTime(section.latestTopic.time) }}</span>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- 热门主题 -->
+ <div class="hot-topics">
+ <div class="section-header">
+ <h2 class="section-title">热门主题</h2>
+ <el-button type="primary" text @click="$router.push('/forum/topics')">
+ 查看全部 <el-icon><ArrowRight /></el-icon>
+ </el-button>
+ </div>
+ <div class="topics-list">
+ <div
+ v-for="topic in hotTopics"
+ :key="topic.id"
+ class="topic-item"
+ @click="navigateToTopic(topic.id)"
+ >
+ <div class="topic-content">
+ <div class="topic-header">
+ <h4 class="topic-title">{{ topic.title }}</h4>
+ <div class="topic-tags">
+ <el-tag
+ v-for="tag in topic.tags"
+ :key="tag"
+ size="small"
+ type="info"
+ >
+ {{ tag }}
+ </el-tag>
+ </div>
+ </div>
+ <div class="topic-meta">
+ <div class="author-info">
+ <el-avatar :size="24">{{ topic.author.charAt(0) }}</el-avatar>
+ <span class="author-name">{{ topic.author }}</span>
+ </div>
+ <div class="topic-stats">
+ <span class="stat-item">
+ <el-icon><View /></el-icon>
+ {{ topic.views }}
+ </span>
+ <span class="stat-item">
+ <el-icon><Comment /></el-icon>
+ {{ topic.replies }}
+ </span>
+ <span class="time">{{ formatTime(topic.lastReply) }}</span>
+ </div>
+ </div>
+ </div>
+ <div class="topic-status">
+ <el-tag v-if="topic.pinned" type="warning" size="small">置顶</el-tag>
+ <el-tag v-if="topic.hot" type="danger" size="small">热门</el-tag>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- 最新回复 -->
+ <div class="recent-replies">
+ <h2 class="section-title">最新回复</h2>
+ <div class="replies-list">
+ <div
+ v-for="reply in recentReplies"
+ :key="reply.id"
+ class="reply-item"
+ @click="navigateToTopic(reply.topicId)"
+ >
+ <div class="reply-avatar">
+ <el-avatar :size="40">{{ reply.author.charAt(0) }}</el-avatar>
+ </div>
+ <div class="reply-content">
+ <div class="reply-header">
+ <span class="reply-author">{{ reply.author }}</span>
+ <span class="reply-action">回复了主题</span>
+ <span class="topic-title">{{ reply.topicTitle }}</span>
+ </div>
+ <div class="reply-text">{{ reply.content }}</div>
+ <div class="reply-time">{{ formatTime(reply.time) }}</div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- 发布新帖对话框 -->
+ <el-dialog
+ v-model="showNewTopicDialog"
+ title="发布新主题"
+ width="600px"
+ :before-close="handleCloseDialog"
+ >
+ <el-form
+ ref="topicFormRef"
+ :model="newTopic"
+ :rules="topicRules"
+ label-width="80px"
+ >
+ <el-form-item label="版块" prop="sectionId">
+ <el-select v-model="newTopic.sectionId" placeholder="选择版块">
+ <el-option
+ v-for="section in forumSections"
+ :key="section.id"
+ :label="section.name"
+ :value="section.id"
+ />
+ </el-select>
+ </el-form-item>
+
+ <el-form-item label="标题" prop="title">
+ <el-input
+ v-model="newTopic.title"
+ placeholder="请输入主题标题"
+ maxlength="100"
+ show-word-limit
+ />
+ </el-form-item>
+
+ <el-form-item label="标签">
+ <div class="tags-input">
+ <el-tag
+ v-for="tag in newTopic.tags"
+ :key="tag"
+ closable
+ @close="removeTopicTag(tag)"
+ >
+ {{ tag }}
+ </el-tag>
+ <el-input
+ v-if="tagInputVisible"
+ ref="tagInputRef"
+ v-model="tagInputValue"
+ size="small"
+ @keyup.enter="addTopicTag"
+ @blur="addTopicTag"
+ style="width: 100px;"
+ />
+ <el-button
+ v-else
+ size="small"
+ @click="showTagInput"
+ >
+ + 添加标签
+ </el-button>
+ </div>
+ </el-form-item>
+
+ <el-form-item label="内容" prop="content">
+ <el-input
+ v-model="newTopic.content"
+ type="textarea"
+ :rows="8"
+ placeholder="请输入主题内容..."
+ maxlength="5000"
+ show-word-limit
+ />
+ </el-form-item>
+ </el-form>
+
+ <template #footer>
+ <el-button @click="handleCloseDialog">取消</el-button>
+ <el-button type="primary" @click="submitNewTopic" :loading="submitting">
+ 发布主题
+ </el-button>
+ </template>
+ </el-dialog>
+ </div>
+</template>
+
+<script>
+import { ref, reactive, onMounted, nextTick } from 'vue'
+import { useRouter } from 'vue-router'
+import { ElMessage, ElMessageBox } from 'element-plus'
+import {
+ Edit,
+ ChatDotRound,
+ Comment,
+ User,
+ View,
+ ArrowRight,
+ Film,
+ Headphones,
+ Monitor,
+ GamePad,
+ ChatLineRound,
+ QuestionFilled,
+ Bell
+} from '@element-plus/icons-vue'
+
+export default {
+ name: 'ForumView',
+ setup() {
+ const router = useRouter()
+ const topicFormRef = ref(null)
+ const tagInputRef = ref(null)
+
+ const showNewTopicDialog = ref(false)
+ const submitting = ref(false)
+ const tagInputVisible = ref(false)
+ const tagInputValue = ref('')
+
+ const forumStats = reactive({
+ totalTopics: '15,268',
+ totalReplies: '89,456',
+ activeUsers: '2,341',
+ todayPosts: '156'
+ })
+
+ const newTopic = reactive({
+ sectionId: '',
+ title: '',
+ content: '',
+ tags: []
+ })
+
+ const topicRules = {
+ sectionId: [
+ { required: true, message: '请选择版块', trigger: 'change' }
+ ],
+ title: [
+ { required: true, message: '请输入标题', trigger: 'blur' },
+ { min: 5, max: 100, message: '标题长度在 5 到 100 个字符', trigger: 'blur' }
+ ],
+ content: [
+ { required: true, message: '请输入内容', trigger: 'blur' },
+ { min: 10, max: 5000, message: '内容长度在 10 到 5000 个字符', trigger: 'blur' }
+ ]
+ }
+
+ const forumSections = ref([
+ {
+ id: 1,
+ name: '电影讨论',
+ description: '分享和讨论电影资源,交流观影心得',
+ icon: 'Film',
+ color: '#409eff',
+ topics: 3256,
+ replies: 18934,
+ latestTopic: {
+ title: '2024年最佳科幻电影推荐',
+ author: 'MovieFan',
+ time: '2025-06-03T14:30:00'
+ }
+ },
+ {
+ id: 2,
+ name: '音乐分享',
+ description: '音乐资源分享,音乐制作技术交流',
+ icon: 'Headphones',
+ color: '#67c23a',
+ topics: 1892,
+ replies: 9567,
+ latestTopic: {
+ title: '无损音乐格式对比分析',
+ author: 'AudioExpert',
+ time: '2025-06-03T13:45:00'
+ }
+ },
+ {
+ id: 3,
+ name: '软件技术',
+ description: '软件资源分享,技术问题讨论',
+ icon: 'Monitor',
+ color: '#e6a23c',
+ topics: 2134,
+ replies: 12456,
+ latestTopic: {
+ title: 'Adobe 2025 新功能体验分享',
+ author: 'TechGuru',
+ time: '2025-06-03T12:20:00'
+ }
+ },
+ {
+ id: 4,
+ name: '游戏天地',
+ description: '游戏资源分享,游戏攻略讨论',
+ icon: 'GamePad',
+ color: '#f56c6c',
+ topics: 1567,
+ replies: 8234,
+ latestTopic: {
+ title: '年度游戏大作盘点',
+ author: 'GameMaster',
+ time: '2025-06-03T11:50:00'
+ }
+ },
+ {
+ id: 5,
+ name: '站务公告',
+ description: '网站公告,规则说明,意见建议',
+ icon: 'Bell',
+ color: '#909399',
+ topics: 234,
+ replies: 1567,
+ latestTopic: {
+ title: '网站维护通知',
+ author: 'Admin',
+ time: '2025-06-03T10:00:00'
+ }
+ },
+ {
+ id: 6,
+ name: '新手求助',
+ description: '新手问题解答,使用教程分享',
+ icon: 'QuestionFilled',
+ color: '#606266',
+ topics: 456,
+ replies: 2890,
+ latestTopic: {
+ title: '新手如何提高分享率?',
+ author: 'Newbie123',
+ time: '2025-06-03T09:30:00'
+ }
+ }
+ ])
+
+ const hotTopics = ref([
+ {
+ id: 1,
+ title: '2024年度最佳PT站点推荐与对比分析',
+ author: 'PTExpert',
+ views: 2856,
+ replies: 147,
+ lastReply: '2025-06-03T14:25:00',
+ tags: ['PT站点', '推荐', '对比'],
+ pinned: true,
+ hot: true
+ },
+ {
+ id: 2,
+ title: '如何安全高效地使用BT下载工具',
+ author: 'SafeDownloader',
+ views: 1932,
+ replies: 89,
+ lastReply: '2025-06-03T13:50:00',
+ tags: ['BT工具', '安全', '教程'],
+ hot: true
+ },
+ {
+ id: 3,
+ title: '分享率提升技巧与经验总结',
+ author: 'SeedMaster',
+ views: 1654,
+ replies: 76,
+ lastReply: '2025-06-03T12:40:00',
+ tags: ['分享率', '技巧', '经验']
+ }
+ ])
+
+ const recentReplies = ref([
+ {
+ id: 1,
+ author: 'MovieLover88',
+ topicId: 1,
+ topicTitle: '阿凡达2观影感受分享',
+ content: '画面效果确实震撼,特别是水下的场景...',
+ time: '2025-06-03T14:45:00'
+ },
+ {
+ id: 2,
+ author: 'TechEnthusiast',
+ topicId: 2,
+ topicTitle: '最新版Photoshop使用技巧',
+ content: '新的AI功能确实很强大,大大提高了工作效率...',
+ time: '2025-06-03T14:30:00'
+ },
+ {
+ id: 3,
+ author: 'GameFan2024',
+ topicId: 3,
+ topicTitle: '赛博朋克2077最新更新体验',
+ content: '修复了很多bug,现在游戏体验好多了...',
+ time: '2025-06-03T14:15:00'
+ }
+ ])
+
+ onMounted(() => {
+ // 初始化论坛数据
+ })
+
+ const formatTime = (timeString) => {
+ const date = new Date(timeString)
+ const now = new Date()
+ const diff = now - date
+ const hours = Math.floor(diff / (1000 * 60 * 60))
+
+ if (hours < 1) return '刚刚'
+ if (hours < 24) return `${hours}小时前`
+ const days = Math.floor(hours / 24)
+ return `${days}天前`
+ }
+
+ const navigateToSection = (sectionId) => {
+ router.push(`/forum/section/${sectionId}`)
+ }
+
+ const navigateToTopic = (topicId) => {
+ router.push(`/forum/topic/${topicId}`)
+ }
+
+ const showTagInput = () => {
+ tagInputVisible.value = true
+ nextTick(() => {
+ tagInputRef.value?.focus()
+ })
+ }
+
+ const addTopicTag = () => {
+ const tag = tagInputValue.value.trim()
+ if (tag && !newTopic.tags.includes(tag)) {
+ newTopic.tags.push(tag)
+ }
+ tagInputVisible.value = false
+ tagInputValue.value = ''
+ }
+
+ const removeTopicTag = (tag) => {
+ const index = newTopic.tags.indexOf(tag)
+ if (index > -1) {
+ newTopic.tags.splice(index, 1)
+ }
+ }
+
+ const handleCloseDialog = () => {
+ if (newTopic.title || newTopic.content) {
+ ElMessageBox.confirm(
+ '确定要关闭吗?未保存的内容将会丢失。',
+ '提示',
+ {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }
+ ).then(() => {
+ resetForm()
+ showNewTopicDialog.value = false
+ }).catch(() => {
+ // 用户取消
+ })
+ } else {
+ resetForm()
+ showNewTopicDialog.value = false
+ }
+ }
+
+ const submitNewTopic = async () => {
+ try {
+ await topicFormRef.value?.validate()
+
+ submitting.value = true
+
+ // 模拟提交过程
+ await new Promise(resolve => setTimeout(resolve, 1500))
+
+ ElMessage.success('主题发布成功!')
+ resetForm()
+ showNewTopicDialog.value = false
+
+ // 跳转到新创建的主题页面
+ router.push('/forum/topic/new')
+
+ } catch (error) {
+ console.error('表单验证失败:', error)
+ } finally {
+ submitting.value = false
+ }
+ }
+
+ const resetForm = () => {
+ topicFormRef.value?.resetFields()
+ newTopic.sectionId = ''
+ newTopic.title = ''
+ newTopic.content = ''
+ newTopic.tags = []
+ }
+
+ return {
+ showNewTopicDialog,
+ submitting,
+ tagInputVisible,
+ tagInputValue,
+ topicFormRef,
+ tagInputRef,
+ forumStats,
+ forumSections,
+ hotTopics,
+ recentReplies,
+ newTopic,
+ topicRules,
+ formatTime,
+ navigateToSection,
+ navigateToTopic,
+ showTagInput,
+ addTopicTag,
+ removeTopicTag,
+ handleCloseDialog,
+ submitNewTopic,
+ Edit,
+ ChatDotRound,
+ Comment,
+ User,
+ View,
+ ArrowRight,
+ Film,
+ Headphones,
+ Monitor,
+ GamePad,
+ Bell,
+ QuestionFilled
+ }
+ }
+}
+</script>
+
+<style lang="scss" scoped>
+.forum-page {
+ max-width: 1200px;
+ margin: 0 auto;
+ padding: 24px;
+ background: #f5f5f5;
+ min-height: 100vh;
+}
+
+.forum-header {
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
+ border-radius: 12px;
+ padding: 48px 32px;
+ margin-bottom: 24px;
+ color: white;
+ text-align: center;
+
+ h1 {
+ font-size: 36px;
+ font-weight: 600;
+ margin: 0 0 12px 0;
+ }
+
+ .header-description {
+ font-size: 18px;
+ margin: 0 0 24px 0;
+ opacity: 0.9;
+ }
+}
+
+.forum-stats {
+ background: #fff;
+ border-radius: 12px;
+ padding: 24px;
+ margin-bottom: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ .stats-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
+ gap: 24px;
+
+ .stat-item {
+ display: flex;
+ align-items: center;
+ gap: 16px;
+
+ .stat-info {
+ h3 {
+ font-size: 24px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 4px 0;
+ }
+
+ p {
+ font-size: 14px;
+ color: #7f8c8d;
+ margin: 0;
+ }
+ }
+ }
+ }
+}
+
+.forum-sections {
+ background: #fff;
+ border-radius: 12px;
+ padding: 24px;
+ margin-bottom: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ .section-title {
+ font-size: 20px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 20px 0;
+ }
+
+ .sections-list {
+ .section-card {
+ display: flex;
+ align-items: center;
+ gap: 20px;
+ padding: 20px;
+ border: 1px solid #f0f0f0;
+ border-radius: 8px;
+ margin-bottom: 12px;
+ cursor: pointer;
+ transition: all 0.3s ease;
+
+ &:hover {
+ background: #f8f9fa;
+ border-color: #409eff;
+ transform: translateX(4px);
+ }
+
+ .section-info {
+ flex: 1;
+
+ .section-name {
+ font-size: 18px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 8px 0;
+ }
+
+ .section-description {
+ font-size: 14px;
+ color: #7f8c8d;
+ margin: 0 0 12px 0;
+ }
+
+ .section-stats {
+ display: flex;
+ gap: 16px;
+
+ .stat {
+ font-size: 12px;
+ color: #909399;
+ }
+ }
+ }
+
+ .section-latest {
+ width: 200px;
+
+ .latest-topic {
+ .topic-title {
+ font-size: 14px;
+ color: #2c3e50;
+ margin: 0 0 8px 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+ }
+
+ .topic-meta {
+ font-size: 12px;
+ color: #909399;
+
+ .author {
+ margin-right: 8px;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+.hot-topics {
+ background: #fff;
+ border-radius: 12px;
+ padding: 24px;
+ margin-bottom: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ .section-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 20px;
+
+ .section-title {
+ font-size: 20px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0;
+ }
+ }
+
+ .topics-list {
+ .topic-item {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 16px;
+ border: 1px solid #f0f0f0;
+ border-radius: 8px;
+ margin-bottom: 12px;
+ cursor: pointer;
+ transition: all 0.3s ease;
+
+ &:hover {
+ background: #f8f9fa;
+ border-color: #409eff;
+ }
+
+ .topic-content {
+ flex: 1;
+
+ .topic-header {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ margin-bottom: 8px;
+
+ .topic-title {
+ font-size: 16px;
+ font-weight: 500;
+ color: #2c3e50;
+ margin: 0;
+ }
+
+ .topic-tags {
+ .el-tag {
+ margin-right: 4px;
+ }
+ }
+ }
+
+ .topic-meta {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ .author-info {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+
+ .author-name {
+ font-size: 14px;
+ color: #7f8c8d;
+ }
+ }
+
+ .topic-stats {
+ display: flex;
+ align-items: center;
+ gap: 16px;
+ font-size: 12px;
+ color: #909399;
+
+ .stat-item {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ }
+ }
+ }
+ }
+
+ .topic-status {
+ .el-tag {
+ margin-left: 8px;
+ }
+ }
+ }
+ }
+}
+
+.recent-replies {
+ background: #fff;
+ border-radius: 12px;
+ padding: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ .section-title {
+ font-size: 20px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 20px 0;
+ }
+
+ .replies-list {
+ .reply-item {
+ display: flex;
+ flex-direction: column;
+ gap: 12px;
+ padding: 16px;
+ border: 1px solid #f0f0f0;
+ border-radius: 8px;
+ margin-bottom: 12px;
+ cursor: pointer;
+ transition: all 0.3s ease;
+
+ &:hover {
+ background: #f8f9fa;
+ border-color: #409eff;
+ }
+
+ .reply-content {
+ flex: 1;
+
+ .reply-header {
+ font-size: 14px;
+ margin-bottom: 8px;
+
+ .reply-author {
+ font-weight: 600;
+ color: #2c3e50;
+ }
+
+ .reply-action {
+ color: #7f8c8d;
+ margin: 0 4px;
+ }
+
+ .topic-title {
+ color: #409eff;
+ font-weight: 500;
+ }
+ }
+
+ .reply-text {
+ font-size: 14px;
+ color: #5a6c7d;
+ margin-bottom: 8px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+ }
+
+ .reply-time {
+ font-size: 12px;
+ color: #909399;
+ }
+ }
+ }
+ }
+}
+</style>
+
+.tags-input {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 8px;
+ align-items: center;
+
+ .el-tag {
+ margin: 0;
+ }
+}
+
+@media (max-width: 768px) {
+ .forum-page {
+ padding: 16px;
+ }
+
+ .forum-header {
+ padding: 32px 24px;
+
+ h1 {
+ font-size: 28px;
+ }
+
+ .header-description {
+ font-size: 16px;
+ }
+ }
+
+ .stats-grid {
+ grid-template-columns: repeat(2, 1fr);
+ }
+
+ .section-card {
+ flex-direction: column;
+ text-align: center;
+
+ .section-latest {
+ width: 100%;
+ margin-top: 16px;
+ }
+ }
+
+ .topic-item {
+ flex-direction: column;
+ align-items: flex-start;
+
+ .topic-status {
+ margin-top: 12px;
+ align-self: flex-end;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/views/torrent/TorrentDetailView.vue b/src/views/torrent/TorrentDetailView.vue
index 941ebd1..c8ee498 100644
--- a/src/views/torrent/TorrentDetailView.vue
+++ b/src/views/torrent/TorrentDetailView.vue
@@ -1,862 +1,862 @@
-<template>
- <div class="torrent-detail-page">
- <div class="page-container">
- <!-- 返回按钮 -->
- <div class="back-button">
- <el-button :icon="ArrowLeft" @click="$router.back()">
- 返回列表
- </el-button>
- </div>
-
- <!-- 种子基本信息 -->
- <div class="torrent-header">
- <div class="header-content">
- <div class="torrent-cover">
- <el-image
- :src="torrentInfo.coverImage || '/default-cover.jpg'"
- :alt="torrentInfo.title"
- fit="cover"
- class="cover-image"
- >
- <template #error>
- <div class="image-placeholder">
- <el-icon size="48"><Picture /></el-icon>
- <span>暂无封面</span>
- </div>
- </template>
- </el-image>
- </div>
-
- <div class="torrent-info">
- <div class="category-tag">
- <el-tag :type="getCategoryType(torrentInfo.category)" size="large">
- {{ getCategoryName(torrentInfo.category) }}
- </el-tag>
- <el-tag v-if="torrentInfo.subcategory" type="info" size="small">
- {{ torrentInfo.subcategory }}
- </el-tag>
- </div>
-
- <h1 class="torrent-title">{{ torrentInfo.title }}</h1>
-
- <div class="torrent-tags">
- <el-tag
- v-for="tag in torrentInfo.tags"
- :key="tag"
- size="small"
- effect="plain"
- >
- {{ tag }}
- </el-tag>
- </div>
-
- <div class="torrent-meta">
- <div class="meta-item">
- <el-icon><User /></el-icon>
- <span>上传者:{{ torrentInfo.uploader }}</span>
- </div>
- <div class="meta-item">
- <el-icon><Clock /></el-icon>
- <span>上传时间:{{ formatDateTime(torrentInfo.uploadTime) }}</span>
- </div>
- <div class="meta-item">
- <el-icon><Document /></el-icon>
- <span>文件大小:{{ torrentInfo.size }}</span>
- </div>
- <div class="meta-item">
- <el-icon><Files /></el-icon>
- <span>文件数量:{{ torrentInfo.fileCount }} 个</span>
- </div>
- </div>
-
- <div class="torrent-stats">
- <div class="stat-item seeders">
- <span class="stat-number">{{ torrentInfo.seeders }}</span>
- <span class="stat-label">做种</span>
- </div>
- <div class="stat-item leechers">
- <span class="stat-number">{{ torrentInfo.leechers }}</span>
- <span class="stat-label">下载</span>
- </div>
- <div class="stat-item downloads">
- <span class="stat-number">{{ torrentInfo.downloads }}</span>
- <span class="stat-label">完成</span>
- </div>
- </div>
-
- <div class="action-buttons">
- <el-button
- type="primary"
- size="large"
- :icon="Download"
- @click="handleDownload"
- :loading="downloading"
- >
- {{ downloading ? '准备中...' : '下载种子' }}
- </el-button>
- <el-button
- type="success"
- size="large"
- :icon="Star"
- @click="handleFavorite"
- >
- {{ isFavorited ? '已收藏' : '收藏' }}
- </el-button>
- <el-button
- type="warning"
- size="large"
- :icon="Flag"
- @click="handleReport"
- >
- 举报
- </el-button>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 详细信息选项卡 -->
- <div class="detail-tabs">
- <el-tabs v-model="activeTab" type="border-card">
- <!-- 种子描述 -->
- <el-tab-pane label="详细描述" name="description">
- <div class="description-content">
- <div v-if="torrentInfo.description" v-html="formatDescription(torrentInfo.description)"></div>
- <div v-else class="no-description">暂无详细描述</div>
- </div>
- </el-tab-pane>
-
- <!-- 文件列表 -->
- <el-tab-pane label="文件列表" name="files" lazy>
- <div class="files-list">
- <el-table :data="torrentInfo.files" stripe>
- <el-table-column label="文件名" prop="name" min-width="400">
- <template #default="{ row }">
- <div class="file-name">
- <el-icon v-if="row.type === 'folder'"><Folder /></el-icon>
- <el-icon v-else><Document /></el-icon>
- <span>{{ row.name }}</span>
- </div>
- </template>
- </el-table-column>
- <el-table-column label="大小" prop="size" width="120" align="right" />
- <el-table-column label="路径" prop="path" min-width="300" />
- </el-table>
- </div>
- </el-tab-pane>
-
- <!-- 用户活动 -->
- <el-tab-pane label="用户活动" name="activity">
- <div class="activity-section">
- <div class="activity-stats">
- <div class="stats-grid">
- <div class="stat-card">
- <h3>做种用户</h3>
- <p class="stat-number">{{ torrentInfo.seeders }}</p>
- </div>
- <div class="stat-card">
- <h3>下载用户</h3>
- <p class="stat-number">{{ torrentInfo.leechers }}</p>
- </div>
- <div class="stat-card">
- <h3>完成用户</h3>
- <p class="stat-number">{{ torrentInfo.downloads }}</p>
- </div>
- </div>
- </div>
-
- <div class="user-lists">
- <el-tabs v-model="activityTab" type="card">
- <el-tab-pane label="做种用户" name="seeders">
- <el-table :data="seedersList" max-height="400">
- <el-table-column label="用户" prop="username" />
- <el-table-column label="上传量" prop="uploaded" />
- <el-table-column label="下载量" prop="downloaded" />
- <el-table-column label="分享率" prop="ratio" />
- <el-table-column label="做种时间" prop="seedTime" />
- </el-table>
- </el-tab-pane>
-
- <el-tab-pane label="下载用户" name="leechers">
- <el-table :data="leechersList" max-height="400">
- <el-table-column label="用户" prop="username" />
- <el-table-column label="进度" prop="progress">
- <template #default="{ row }">
- <el-progress :percentage="row.progress" :stroke-width="6" />
- </template>
- </el-table-column>
- <el-table-column label="下载速度" prop="downloadSpeed" />
- <el-table-column label="剩余时间" prop="eta" />
- </el-table>
- </el-tab-pane>
- </el-tabs>
- </div>
- </div>
- </el-tab-pane>
-
- <!-- 评论区 -->
- <el-tab-pane label="评论" name="comments">
- <div class="comments-section">
- <!-- 发表评论 -->
- <div class="comment-form">
- <el-input
- v-model="newComment"
- type="textarea"
- :rows="4"
- placeholder="发表你的评论..."
- maxlength="500"
- show-word-limit
- />
- <div class="comment-actions">
- <el-button type="primary" @click="submitComment" :loading="submittingComment">
- 发表评论
- </el-button>
- </div>
- </div>
-
- <!-- 评论列表 -->
- <div class="comments-list">
- <div
- v-for="comment in comments"
- :key="comment.id"
- class="comment-item"
- >
- <div class="comment-avatar">
- <el-avatar :size="40">{{ comment.username.charAt(0) }}</el-avatar>
- </div>
- <div class="comment-content">
- <div class="comment-header">
- <span class="comment-username">{{ comment.username }}</span>
- <span class="comment-time">{{ formatDateTime(comment.time) }}</span>
- </div>
- <div class="comment-text">{{ comment.content }}</div>
- <div class="comment-actions">
- <el-button type="text" size="small" @click="likeComment(comment.id)">
- <el-icon><Like /></el-icon>
- {{ comment.likes || 0 }}
- </el-button>
- <el-button type="text" size="small" @click="replyComment(comment.id)">
- 回复
- </el-button>
- </div>
- </div>
- </div>
-
- <div v-if="comments.length === 0" class="no-comments">
- 暂无评论,快来发表第一条评论吧!
- </div>
- </div>
- </div>
- </el-tab-pane>
- </el-tabs>
- </div>
- </div>
- </div>
-</template>
-
-<script>
-import { ref, onMounted } from 'vue'
-import { useRoute, useRouter } from 'vue-router'
-import { ElMessage, ElMessageBox } from 'element-plus'
-import {
- ArrowLeft,
- Download,
- Star,
- Flag,
- User,
- Clock,
- Document,
- Files,
- Picture,
- Folder,
- Like
-} from '@element-plus/icons-vue'
-
-export default {
- name: 'TorrentDetailView',
- setup() {
- const route = useRoute()
- const router = useRouter()
-
- const activeTab = ref('description')
- const activityTab = ref('seeders')
- const downloading = ref(false)
- const isFavorited = ref(false)
- const submittingComment = ref(false)
- const newComment = ref('')
-
- const torrentInfo = ref({
- id: 1,
- title: '[4K蓝光原盘] 阿凡达:水之道 Avatar: The Way of Water (2022)',
- category: 'movie',
- subcategory: '科幻片',
- uploader: 'MovieMaster',
- uploadTime: '2025-06-03T10:30:00',
- size: '85.6 GB',
- fileCount: 125,
- seeders: 128,
- leechers: 45,
- downloads: 892,
- coverImage: 'https://example.com/avatar2-cover.jpg',
- tags: ['4K', '蓝光原盘', '科幻', '詹姆斯·卡梅隆'],
- description: `
- <h3>影片信息</h3>
- <p><strong>片名:</strong>阿凡达:水之道 / Avatar: The Way of Water</p>
- <p><strong>年份:</strong>2022</p>
- <p><strong>导演:</strong>詹姆斯·卡梅隆</p>
- <p><strong>主演:</strong>萨姆·沃辛顿 / 佐伊·索尔达娜 / 西格妮·韦弗</p>
- <p><strong>类型:</strong>科幻 / 动作 / 冒险</p>
- <p><strong>制片国家/地区:</strong>美国</p>
- <p><strong>语言:</strong>英语</p>
- <p><strong>上映日期:</strong>2022-12-16</p>
- <p><strong>片长:</strong>192分钟</p>
-
- <h3>影片简介</h3>
- <p>杰克·萨利和奈蒂莉组建了家庭,他们的孩子也逐渐成长。当危险威胁到他们时,杰克和奈蒂莉必须为彼此而战,为家庭而战,为生存而战。</p>
-
- <h3>技术规格</h3>
- <ul>
- <li>视频:4K UHD 2160p / HEVC / HDR10</li>
- <li>音频:Dolby Atmos TrueHD 7.1 / DTS-HD MA 7.1</li>
- <li>字幕:中文 / 英文</li>
- <li>片源:4K UHD 蓝光原盘</li>
- </ul>
-
- <h3>下载说明</h3>
- <p>本资源为4K蓝光原盘,保持了最高的画质和音质。建议使用支持4K播放的设备观看。</p>
- `,
- files: [
- { name: 'BDMV', type: 'folder', size: '85.6 GB', path: '/' },
- { name: 'CERTIFICATE', type: 'folder', size: '2.1 MB', path: '/' },
- { name: 'Avatar.The.Way.of.Water.2022.2160p.UHD.Blu-ray.x265.HDR.Atmos-DETAIL.mkv', type: 'file', size: '32.8 GB', path: '/BDMV/STREAM/' },
- { name: 'Avatar.The.Way.of.Water.2022.Extras.mkv', type: 'file', size: '12.4 GB', path: '/BDMV/STREAM/' }
- ]
- })
-
- const seedersList = ref([
- { username: 'SeedMaster', uploaded: '2.5 TB', downloaded: '850 GB', ratio: '3.02', seedTime: '15天' },
- { username: 'MovieFan88', uploaded: '1.8 TB', downloaded: '1.2 TB', ratio: '1.50', seedTime: '8天' },
- { username: 'CinemaLover', uploaded: '3.2 TB', downloaded: '900 GB', ratio: '3.56', seedTime: '22天' }
- ])
-
- const leechersList = ref([
- { username: 'NewUser123', progress: 65, downloadSpeed: '15.2 MB/s', eta: '2小时15分' },
- { username: 'MovieSeeker', progress: 23, downloadSpeed: '8.7 MB/s', eta: '8小时32分' },
- { username: 'FilmCollector', progress: 89, downloadSpeed: '22.1 MB/s', eta: '45分钟' }
- ])
-
- const comments = ref([
- {
- id: 1,
- username: 'MovieReviewer',
- content: '画质非常棒!4K HDR效果惊艳,水下场景美不胜收。感谢分享!',
- time: '2025-06-03T12:00:00',
- likes: 15
- },
- {
- id: 2,
- username: 'CinemaExpert',
- content: '音效也很棒,Dolby Atmos的环绕效果让人身临其境。推荐大家下载!',
- time: '2025-06-03T11:30:00',
- likes: 8
- }
- ])
-
- onMounted(() => {
- const torrentId = route.params.id
- fetchTorrentDetail(torrentId)
- })
-
- const fetchTorrentDetail = async (id) => {
- try {
- // 模拟API调用
- console.log('获取种子详情:', id)
- // 这里应该调用真实的API
- } catch (error) {
- ElMessage.error('获取种子详情失败')
- router.back()
- }
- }
-
- const formatDateTime = (dateString) => {
- const date = new Date(dateString)
- return date.toLocaleString('zh-CN', {
- year: 'numeric',
- month: '2-digit',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit'
- })
- }
-
- const formatDescription = (description) => {
- // 简单的HTML清理,实际项目中应该使用专门的库
- return description.replace(/\n/g, '<br>')
- }
-
- const getCategoryType = (category) => {
- const types = {
- 'movie': 'primary',
- 'tv': 'info',
- 'music': 'success',
- 'software': 'warning',
- 'game': 'danger'
- }
- return types[category] || 'default'
- }
-
- const getCategoryName = (category) => {
- const names = {
- 'movie': '电影',
- 'tv': '电视剧',
- 'music': '音乐',
- 'software': '软件',
- 'game': '游戏'
- }
- return names[category] || category
- }
-
- const handleDownload = async () => {
- downloading.value = true
- try {
- // 模拟下载准备过程
- await new Promise(resolve => setTimeout(resolve, 1500))
-
- // 实际项目中这里应该下载.torrent文件
- const link = document.createElement('a')
- link.href = '#' // 实际的种子文件下载链接
- link.download = `${torrentInfo.value.title}.torrent`
- link.click()
-
- ElMessage.success('种子文件下载完成')
- } catch (error) {
- ElMessage.error('下载失败,请稍后重试')
- } finally {
- downloading.value = false
- }
- }
-
- const handleFavorite = () => {
- isFavorited.value = !isFavorited.value
- ElMessage.success(isFavorited.value ? '已添加到收藏' : '已取消收藏')
- }
-
- const handleReport = async () => {
- try {
- await ElMessageBox.prompt('请说明举报原因', '举报内容', {
- confirmButtonText: '提交举报',
- cancelButtonText: '取消',
- inputType: 'textarea',
- inputPlaceholder: '请详细说明举报原因...'
- })
-
- ElMessage.success('举报已提交,我们会尽快处理')
- } catch {
- // 用户取消
- }
- }
-
- const submitComment = async () => {
- if (!newComment.value.trim()) {
- ElMessage.warning('请输入评论内容')
- return
- }
-
- submittingComment.value = true
- try {
- // 模拟提交评论
- await new Promise(resolve => setTimeout(resolve, 1000))
-
- const comment = {
- id: Date.now(),
- username: localStorage.getItem('username') || '用户',
- content: newComment.value,
- time: new Date().toISOString(),
- likes: 0
- }
-
- comments.value.unshift(comment)
- newComment.value = ''
-
- ElMessage.success('评论发表成功')
- } catch (error) {
- ElMessage.error('发表评论失败')
- } finally {
- submittingComment.value = false
- }
- }
-
- const likeComment = (commentId) => {
- const comment = comments.value.find(c => c.id === commentId)
- if (comment) {
- comment.likes = (comment.likes || 0) + 1
- ElMessage.success('点赞成功')
- }
- }
-
- const replyComment = (commentId) => {
- // 实现回复功能
- ElMessage.info('回复功能开发中...')
- }
-
- return {
- activeTab,
- activityTab,
- downloading,
- isFavorited,
- submittingComment,
- newComment,
- torrentInfo,
- seedersList,
- leechersList,
- comments,
- formatDateTime,
- formatDescription,
- getCategoryType,
- getCategoryName,
- handleDownload,
- handleFavorite,
- handleReport,
- submitComment,
- likeComment,
- replyComment,
- ArrowLeft,
- Download,
- Star,
- Flag,
- User,
- Clock,
- Document,
- Files,
- Picture,
- Folder,
- Like
- }
- }
-}
-</script>
-
-<style lang="scss" scoped>
-.torrent-detail-page {
- max-width: 1200px;
- margin: 0 auto;
- padding: 24px;
- background: #f5f5f5;
- min-height: 100vh;
-}
-
-.back-button {
- margin-bottom: 16px;
-}
-
-.torrent-header {
- background: #fff;
- border-radius: 12px;
- padding: 32px;
- margin-bottom: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- .header-content {
- display: flex;
- gap: 32px;
-
- .torrent-cover {
- flex-shrink: 0;
-
- .cover-image {
- width: 200px;
- height: 280px;
- border-radius: 8px;
- object-fit: cover;
- }
-
- .image-placeholder {
- width: 200px;
- height: 280px;
- background: #f5f5f5;
- border-radius: 8px;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- color: #999;
-
- span {
- margin-top: 8px;
- font-size: 14px;
- }
- }
- }
-
- .torrent-info {
- flex: 1;
-
- .category-tag {
- margin-bottom: 16px;
-
- .el-tag {
- margin-right: 8px;
- }
- }
-
- .torrent-title {
- font-size: 28px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 16px 0;
- line-height: 1.3;
- }
-
- .torrent-tags {
- margin-bottom: 20px;
-
- .el-tag {
- margin: 0 8px 8px 0;
- }
- }
-
- .torrent-meta {
- margin-bottom: 20px;
-
- .meta-item {
- display: flex;
- align-items: center;
- gap: 8px;
- margin-bottom: 8px;
- color: #7f8c8d;
- font-size: 14px;
-
- .el-icon {
- color: #909399;
- }
- }
- }
-
- .torrent-stats {
- display: flex;
- gap: 32px;
- margin-bottom: 24px;
-
- .stat-item {
- text-align: center;
-
- .stat-number {
- display: block;
- font-size: 24px;
- font-weight: 600;
- margin-bottom: 4px;
-
- &.seeders { color: #67c23a; }
- &.leechers { color: #f56c6c; }
- &.downloads { color: #409eff; }
- }
-
- .stat-label {
- font-size: 14px;
- color: #909399;
- }
- }
- }
-
- .action-buttons {
- display: flex;
- gap: 12px;
- flex-wrap: wrap;
- }
- }
- }
-}
-
-.detail-tabs {
- background: #fff;
- border-radius: 12px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- :deep(.el-tabs__content) {
- padding: 24px;
- }
-
- .description-content {
- line-height: 1.6;
-
- :deep(h3) {
- color: #2c3e50;
- font-size: 18px;
- font-weight: 600;
- margin: 24px 0 12px 0;
-
- &:first-child {
- margin-top: 0;
- }
- }
-
- :deep(p) {
- margin-bottom: 12px;
- color: #5a6c7d;
- }
-
- :deep(ul) {
- margin: 12px 0;
- padding-left: 20px;
-
- li {
- margin-bottom: 8px;
- color: #5a6c7d;
- }
- }
-
- .no-description {
- text-align: center;
- color: #909399;
- padding: 40px 0;
- }
- }
-
- .files-list {
- .file-name {
- display: flex;
- align-items: center;
- gap: 8px;
-
- .el-icon {
- color: #909399;
- }
- }
- }
-
- .activity-section {
- .activity-stats {
- margin-bottom: 24px;
-
- .stats-grid {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
- gap: 16px;
-
- .stat-card {
- background: #f8f9fa;
- padding: 20px;
- border-radius: 8px;
- text-align: center;
-
- h3 {
- font-size: 14px;
- color: #909399;
- margin: 0 0 8px 0;
- }
-
- .stat-number {
- font-size: 24px;
- font-weight: 600;
- color: #2c3e50;
- }
- }
- }
- }
- }
-
- .comments-section {
- .comment-form {
- margin-bottom: 32px;
-
- .comment-actions {
- margin-top: 12px;
- text-align: right;
- }
- }
-
- .comments-list {
- .comment-item {
- display: flex;
- gap: 16px;
- margin-bottom: 24px;
- padding-bottom: 24px;
- border-bottom: 1px solid #f0f0f0;
-
- &:last-child {
- border-bottom: none;
- margin-bottom: 0;
- padding-bottom: 0;
- }
-
- .comment-content {
- flex: 1;
-
- .comment-header {
- display: flex;
- align-items: center;
- gap: 12px;
- margin-bottom: 8px;
-
- .comment-username {
- font-weight: 600;
- color: #2c3e50;
- }
-
- .comment-time {
- font-size: 12px;
- color: #909399;
- }
- }
-
- .comment-text {
- color: #5a6c7d;
- line-height: 1.5;
- margin-bottom: 12px;
- }
-
- .comment-actions {
- .el-button {
- padding: 0;
- margin-right: 16px;
-
- .el-icon {
- margin-right: 4px;
- }
- }
- }
- }
- }
-
- .no-comments {
- text-align: center;
- color: #909399;
- padding: 40px 0;
- }
- }
- }
-}
-
-// 响应式设计
-@media (max-width: 768px) {
- .torrent-detail-page {
- padding: 16px;
- }
-
- .torrent-header .header-content {
- flex-direction: column;
- text-align: center;
-
- .torrent-cover {
- align-self: center;
- }
-
- .torrent-stats {
- justify-content: center;
- }
-
- .action-buttons {
- justify-content: center;
- }
- }
-
- .activity-section .stats-grid {
- grid-template-columns: 1fr;
- }
-
- .comment-item {
- flex-direction: column;
- gap: 12px;
- }
-}
+<template>
+ <div class="torrent-detail-page">
+ <div class="page-container">
+ <!-- 返回按钮 -->
+ <div class="back-button">
+ <el-button :icon="ArrowLeft" @click="$router.back()">
+ 返回列表
+ </el-button>
+ </div>
+
+ <!-- 种子基本信息 -->
+ <div class="torrent-header">
+ <div class="header-content">
+ <div class="torrent-cover">
+ <el-image
+ :src="torrentInfo.coverImage || '/default-cover.jpg'"
+ :alt="torrentInfo.title"
+ fit="cover"
+ class="cover-image"
+ >
+ <template #error>
+ <div class="image-placeholder">
+ <el-icon size="48"><Picture /></el-icon>
+ <span>暂无封面</span>
+ </div>
+ </template>
+ </el-image>
+ </div>
+
+ <div class="torrent-info">
+ <div class="category-tag">
+ <el-tag :type="getCategoryType(torrentInfo.category)" size="large">
+ {{ getCategoryName(torrentInfo.category) }}
+ </el-tag>
+ <el-tag v-if="torrentInfo.subcategory" type="info" size="small">
+ {{ torrentInfo.subcategory }}
+ </el-tag>
+ </div>
+
+ <h1 class="torrent-title">{{ torrentInfo.title }}</h1>
+
+ <div class="torrent-tags">
+ <el-tag
+ v-for="tag in torrentInfo.tags"
+ :key="tag"
+ size="small"
+ effect="plain"
+ >
+ {{ tag }}
+ </el-tag>
+ </div>
+
+ <div class="torrent-meta">
+ <div class="meta-item">
+ <el-icon><User /></el-icon>
+ <span>上传者:{{ torrentInfo.uploader }}</span>
+ </div>
+ <div class="meta-item">
+ <el-icon><Clock /></el-icon>
+ <span>上传时间:{{ formatDateTime(torrentInfo.uploadTime) }}</span>
+ </div>
+ <div class="meta-item">
+ <el-icon><Document /></el-icon>
+ <span>文件大小:{{ torrentInfo.size }}</span>
+ </div>
+ <div class="meta-item">
+ <el-icon><Files /></el-icon>
+ <span>文件数量:{{ torrentInfo.fileCount }} 个</span>
+ </div>
+ </div>
+
+ <div class="torrent-stats">
+ <div class="stat-item seeders">
+ <span class="stat-number">{{ torrentInfo.seeders }}</span>
+ <span class="stat-label">做种</span>
+ </div>
+ <div class="stat-item leechers">
+ <span class="stat-number">{{ torrentInfo.leechers }}</span>
+ <span class="stat-label">下载</span>
+ </div>
+ <div class="stat-item downloads">
+ <span class="stat-number">{{ torrentInfo.downloads }}</span>
+ <span class="stat-label">完成</span>
+ </div>
+ </div>
+
+ <div class="action-buttons">
+ <el-button
+ type="primary"
+ size="large"
+ :icon="Download"
+ @click="handleDownload"
+ :loading="downloading"
+ >
+ {{ downloading ? '准备中...' : '下载种子' }}
+ </el-button>
+ <el-button
+ type="success"
+ size="large"
+ :icon="Star"
+ @click="handleFavorite"
+ >
+ {{ isFavorited ? '已收藏' : '收藏' }}
+ </el-button>
+ <el-button
+ type="warning"
+ size="large"
+ :icon="Flag"
+ @click="handleReport"
+ >
+ 举报
+ </el-button>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- 详细信息选项卡 -->
+ <div class="detail-tabs">
+ <el-tabs v-model="activeTab" type="border-card">
+ <!-- 种子描述 -->
+ <el-tab-pane label="详细描述" name="description">
+ <div class="description-content">
+ <div v-if="torrentInfo.description" v-html="formatDescription(torrentInfo.description)"></div>
+ <div v-else class="no-description">暂无详细描述</div>
+ </div>
+ </el-tab-pane>
+
+ <!-- 文件列表 -->
+ <el-tab-pane label="文件列表" name="files" lazy>
+ <div class="files-list">
+ <el-table :data="torrentInfo.files" stripe>
+ <el-table-column label="文件名" prop="name" min-width="400">
+ <template #default="{ row }">
+ <div class="file-name">
+ <el-icon v-if="row.type === 'folder'"><Folder /></el-icon>
+ <el-icon v-else><Document /></el-icon>
+ <span>{{ row.name }}</span>
+ </div>
+ </template>
+ </el-table-column>
+ <el-table-column label="大小" prop="size" width="120" align="right" />
+ <el-table-column label="路径" prop="path" min-width="300" />
+ </el-table>
+ </div>
+ </el-tab-pane>
+
+ <!-- 用户活动 -->
+ <el-tab-pane label="用户活动" name="activity">
+ <div class="activity-section">
+ <div class="activity-stats">
+ <div class="stats-grid">
+ <div class="stat-card">
+ <h3>做种用户</h3>
+ <p class="stat-number">{{ torrentInfo.seeders }}</p>
+ </div>
+ <div class="stat-card">
+ <h3>下载用户</h3>
+ <p class="stat-number">{{ torrentInfo.leechers }}</p>
+ </div>
+ <div class="stat-card">
+ <h3>完成用户</h3>
+ <p class="stat-number">{{ torrentInfo.downloads }}</p>
+ </div>
+ </div>
+ </div>
+
+ <div class="user-lists">
+ <el-tabs v-model="activityTab" type="card">
+ <el-tab-pane label="做种用户" name="seeders">
+ <el-table :data="seedersList" max-height="400">
+ <el-table-column label="用户" prop="username" />
+ <el-table-column label="上传量" prop="uploaded" />
+ <el-table-column label="下载量" prop="downloaded" />
+ <el-table-column label="分享率" prop="ratio" />
+ <el-table-column label="做种时间" prop="seedTime" />
+ </el-table>
+ </el-tab-pane>
+
+ <el-tab-pane label="下载用户" name="leechers">
+ <el-table :data="leechersList" max-height="400">
+ <el-table-column label="用户" prop="username" />
+ <el-table-column label="进度" prop="progress">
+ <template #default="{ row }">
+ <el-progress :percentage="row.progress" :stroke-width="6" />
+ </template>
+ </el-table-column>
+ <el-table-column label="下载速度" prop="downloadSpeed" />
+ <el-table-column label="剩余时间" prop="eta" />
+ </el-table>
+ </el-tab-pane>
+ </el-tabs>
+ </div>
+ </div>
+ </el-tab-pane>
+
+ <!-- 评论区 -->
+ <el-tab-pane label="评论" name="comments">
+ <div class="comments-section">
+ <!-- 发表评论 -->
+ <div class="comment-form">
+ <el-input
+ v-model="newComment"
+ type="textarea"
+ :rows="4"
+ placeholder="发表你的评论..."
+ maxlength="500"
+ show-word-limit
+ />
+ <div class="comment-actions">
+ <el-button type="primary" @click="submitComment" :loading="submittingComment">
+ 发表评论
+ </el-button>
+ </div>
+ </div>
+
+ <!-- 评论列表 -->
+ <div class="comments-list">
+ <div
+ v-for="comment in comments"
+ :key="comment.id"
+ class="comment-item"
+ >
+ <div class="comment-avatar">
+ <el-avatar :size="40">{{ comment.username.charAt(0) }}</el-avatar>
+ </div>
+ <div class="comment-content">
+ <div class="comment-header">
+ <span class="comment-username">{{ comment.username }}</span>
+ <span class="comment-time">{{ formatDateTime(comment.time) }}</span>
+ </div>
+ <div class="comment-text">{{ comment.content }}</div>
+ <div class="comment-actions">
+ <el-button type="text" size="small" @click="likeComment(comment.id)">
+ <el-icon><Like /></el-icon>
+ {{ comment.likes || 0 }}
+ </el-button>
+ <el-button type="text" size="small" @click="replyComment(comment.id)">
+ 回复
+ </el-button>
+ </div>
+ </div>
+ </div>
+
+ <div v-if="comments.length === 0" class="no-comments">
+ 暂无评论,快来发表第一条评论吧!
+ </div>
+ </div>
+ </div>
+ </el-tab-pane>
+ </el-tabs>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script>
+import { ref, onMounted } from 'vue'
+import { useRoute, useRouter } from 'vue-router'
+import { ElMessage, ElMessageBox } from 'element-plus'
+import {
+ ArrowLeft,
+ Download,
+ Star,
+ Flag,
+ User,
+ Clock,
+ Document,
+ Files,
+ Picture,
+ Folder,
+ Like
+} from '@element-plus/icons-vue'
+
+export default {
+ name: 'TorrentDetailView',
+ setup() {
+ const route = useRoute()
+ const router = useRouter()
+
+ const activeTab = ref('description')
+ const activityTab = ref('seeders')
+ const downloading = ref(false)
+ const isFavorited = ref(false)
+ const submittingComment = ref(false)
+ const newComment = ref('')
+
+ const torrentInfo = ref({
+ id: 1,
+ title: '[4K蓝光原盘] 阿凡达:水之道 Avatar: The Way of Water (2022)',
+ category: 'movie',
+ subcategory: '科幻片',
+ uploader: 'MovieMaster',
+ uploadTime: '2025-06-03T10:30:00',
+ size: '85.6 GB',
+ fileCount: 125,
+ seeders: 128,
+ leechers: 45,
+ downloads: 892,
+ coverImage: 'https://example.com/avatar2-cover.jpg',
+ tags: ['4K', '蓝光原盘', '科幻', '詹姆斯·卡梅隆'],
+ description: `
+ <h3>影片信息</h3>
+ <p><strong>片名:</strong>阿凡达:水之道 / Avatar: The Way of Water</p>
+ <p><strong>年份:</strong>2022</p>
+ <p><strong>导演:</strong>詹姆斯·卡梅隆</p>
+ <p><strong>主演:</strong>萨姆·沃辛顿 / 佐伊·索尔达娜 / 西格妮·韦弗</p>
+ <p><strong>类型:</strong>科幻 / 动作 / 冒险</p>
+ <p><strong>制片国家/地区:</strong>美国</p>
+ <p><strong>语言:</strong>英语</p>
+ <p><strong>上映日期:</strong>2022-12-16</p>
+ <p><strong>片长:</strong>192分钟</p>
+
+ <h3>影片简介</h3>
+ <p>杰克·萨利和奈蒂莉组建了家庭,他们的孩子也逐渐成长。当危险威胁到他们时,杰克和奈蒂莉必须为彼此而战,为家庭而战,为生存而战。</p>
+
+ <h3>技术规格</h3>
+ <ul>
+ <li>视频:4K UHD 2160p / HEVC / HDR10</li>
+ <li>音频:Dolby Atmos TrueHD 7.1 / DTS-HD MA 7.1</li>
+ <li>字幕:中文 / 英文</li>
+ <li>片源:4K UHD 蓝光原盘</li>
+ </ul>
+
+ <h3>下载说明</h3>
+ <p>本资源为4K蓝光原盘,保持了最高的画质和音质。建议使用支持4K播放的设备观看。</p>
+ `,
+ files: [
+ { name: 'BDMV', type: 'folder', size: '85.6 GB', path: '/' },
+ { name: 'CERTIFICATE', type: 'folder', size: '2.1 MB', path: '/' },
+ { name: 'Avatar.The.Way.of.Water.2022.2160p.UHD.Blu-ray.x265.HDR.Atmos-DETAIL.mkv', type: 'file', size: '32.8 GB', path: '/BDMV/STREAM/' },
+ { name: 'Avatar.The.Way.of.Water.2022.Extras.mkv', type: 'file', size: '12.4 GB', path: '/BDMV/STREAM/' }
+ ]
+ })
+
+ const seedersList = ref([
+ { username: 'SeedMaster', uploaded: '2.5 TB', downloaded: '850 GB', ratio: '3.02', seedTime: '15天' },
+ { username: 'MovieFan88', uploaded: '1.8 TB', downloaded: '1.2 TB', ratio: '1.50', seedTime: '8天' },
+ { username: 'CinemaLover', uploaded: '3.2 TB', downloaded: '900 GB', ratio: '3.56', seedTime: '22天' }
+ ])
+
+ const leechersList = ref([
+ { username: 'NewUser123', progress: 65, downloadSpeed: '15.2 MB/s', eta: '2小时15分' },
+ { username: 'MovieSeeker', progress: 23, downloadSpeed: '8.7 MB/s', eta: '8小时32分' },
+ { username: 'FilmCollector', progress: 89, downloadSpeed: '22.1 MB/s', eta: '45分钟' }
+ ])
+
+ const comments = ref([
+ {
+ id: 1,
+ username: 'MovieReviewer',
+ content: '画质非常棒!4K HDR效果惊艳,水下场景美不胜收。感谢分享!',
+ time: '2025-06-03T12:00:00',
+ likes: 15
+ },
+ {
+ id: 2,
+ username: 'CinemaExpert',
+ content: '音效也很棒,Dolby Atmos的环绕效果让人身临其境。推荐大家下载!',
+ time: '2025-06-03T11:30:00',
+ likes: 8
+ }
+ ])
+
+ onMounted(() => {
+ const torrentId = route.params.id
+ fetchTorrentDetail(torrentId)
+ })
+
+ const fetchTorrentDetail = async (id) => {
+ try {
+ // 模拟API调用
+ console.log('获取种子详情:', id)
+ // 这里应该调用真实的API
+ } catch (error) {
+ ElMessage.error('获取种子详情失败')
+ router.back()
+ }
+ }
+
+ const formatDateTime = (dateString) => {
+ const date = new Date(dateString)
+ return date.toLocaleString('zh-CN', {
+ year: 'numeric',
+ month: '2-digit',
+ day: '2-digit',
+ hour: '2-digit',
+ minute: '2-digit'
+ })
+ }
+
+ const formatDescription = (description) => {
+ // 简单的HTML清理,实际项目中应该使用专门的库
+ return description.replace(/\n/g, '<br>')
+ }
+
+ const getCategoryType = (category) => {
+ const types = {
+ 'movie': 'primary',
+ 'tv': 'info',
+ 'music': 'success',
+ 'software': 'warning',
+ 'game': 'danger'
+ }
+ return types[category] || 'default'
+ }
+
+ const getCategoryName = (category) => {
+ const names = {
+ 'movie': '电影',
+ 'tv': '电视剧',
+ 'music': '音乐',
+ 'software': '软件',
+ 'game': '游戏'
+ }
+ return names[category] || category
+ }
+
+ const handleDownload = async () => {
+ downloading.value = true
+ try {
+ // 模拟下载准备过程
+ await new Promise(resolve => setTimeout(resolve, 1500))
+
+ // 实际项目中这里应该下载.torrent文件
+ const link = document.createElement('a')
+ link.href = '#' // 实际的种子文件下载链接
+ link.download = `${torrentInfo.value.title}.torrent`
+ link.click()
+
+ ElMessage.success('种子文件下载完成')
+ } catch (error) {
+ ElMessage.error('下载失败,请稍后重试')
+ } finally {
+ downloading.value = false
+ }
+ }
+
+ const handleFavorite = () => {
+ isFavorited.value = !isFavorited.value
+ ElMessage.success(isFavorited.value ? '已添加到收藏' : '已取消收藏')
+ }
+
+ const handleReport = async () => {
+ try {
+ await ElMessageBox.prompt('请说明举报原因', '举报内容', {
+ confirmButtonText: '提交举报',
+ cancelButtonText: '取消',
+ inputType: 'textarea',
+ inputPlaceholder: '请详细说明举报原因...'
+ })
+
+ ElMessage.success('举报已提交,我们会尽快处理')
+ } catch {
+ // 用户取消
+ }
+ }
+
+ const submitComment = async () => {
+ if (!newComment.value.trim()) {
+ ElMessage.warning('请输入评论内容')
+ return
+ }
+
+ submittingComment.value = true
+ try {
+ // 模拟提交评论
+ await new Promise(resolve => setTimeout(resolve, 1000))
+
+ const comment = {
+ id: Date.now(),
+ username: localStorage.getItem('username') || '用户',
+ content: newComment.value,
+ time: new Date().toISOString(),
+ likes: 0
+ }
+
+ comments.value.unshift(comment)
+ newComment.value = ''
+
+ ElMessage.success('评论发表成功')
+ } catch (error) {
+ ElMessage.error('发表评论失败')
+ } finally {
+ submittingComment.value = false
+ }
+ }
+
+ const likeComment = (commentId) => {
+ const comment = comments.value.find(c => c.id === commentId)
+ if (comment) {
+ comment.likes = (comment.likes || 0) + 1
+ ElMessage.success('点赞成功')
+ }
+ }
+
+ const replyComment = (commentId) => {
+ // 实现回复功能
+ ElMessage.info('回复功能开发中...')
+ }
+
+ return {
+ activeTab,
+ activityTab,
+ downloading,
+ isFavorited,
+ submittingComment,
+ newComment,
+ torrentInfo,
+ seedersList,
+ leechersList,
+ comments,
+ formatDateTime,
+ formatDescription,
+ getCategoryType,
+ getCategoryName,
+ handleDownload,
+ handleFavorite,
+ handleReport,
+ submitComment,
+ likeComment,
+ replyComment,
+ ArrowLeft,
+ Download,
+ Star,
+ Flag,
+ User,
+ Clock,
+ Document,
+ Files,
+ Picture,
+ Folder,
+ Like
+ }
+ }
+}
+</script>
+
+<style lang="scss" scoped>
+.torrent-detail-page {
+ max-width: 1200px;
+ margin: 0 auto;
+ padding: 24px;
+ background: #f5f5f5;
+ min-height: 100vh;
+}
+
+.back-button {
+ margin-bottom: 16px;
+}
+
+.torrent-header {
+ background: #fff;
+ border-radius: 12px;
+ padding: 32px;
+ margin-bottom: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ .header-content {
+ display: flex;
+ gap: 32px;
+
+ .torrent-cover {
+ flex-shrink: 0;
+
+ .cover-image {
+ width: 200px;
+ height: 280px;
+ border-radius: 8px;
+ object-fit: cover;
+ }
+
+ .image-placeholder {
+ width: 200px;
+ height: 280px;
+ background: #f5f5f5;
+ border-radius: 8px;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ color: #999;
+
+ span {
+ margin-top: 8px;
+ font-size: 14px;
+ }
+ }
+ }
+
+ .torrent-info {
+ flex: 1;
+
+ .category-tag {
+ margin-bottom: 16px;
+
+ .el-tag {
+ margin-right: 8px;
+ }
+ }
+
+ .torrent-title {
+ font-size: 28px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 16px 0;
+ line-height: 1.3;
+ }
+
+ .torrent-tags {
+ margin-bottom: 20px;
+
+ .el-tag {
+ margin: 0 8px 8px 0;
+ }
+ }
+
+ .torrent-meta {
+ margin-bottom: 20px;
+
+ .meta-item {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ margin-bottom: 8px;
+ color: #7f8c8d;
+ font-size: 14px;
+
+ .el-icon {
+ color: #909399;
+ }
+ }
+ }
+
+ .torrent-stats {
+ display: flex;
+ gap: 32px;
+ margin-bottom: 24px;
+
+ .stat-item {
+ text-align: center;
+
+ .stat-number {
+ display: block;
+ font-size: 24px;
+ font-weight: 600;
+ margin-bottom: 4px;
+
+ &.seeders { color: #67c23a; }
+ &.leechers { color: #f56c6c; }
+ &.downloads { color: #409eff; }
+ }
+
+ .stat-label {
+ font-size: 14px;
+ color: #909399;
+ }
+ }
+ }
+
+ .action-buttons {
+ display: flex;
+ gap: 12px;
+ flex-wrap: wrap;
+ }
+ }
+ }
+}
+
+.detail-tabs {
+ background: #fff;
+ border-radius: 12px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ :deep(.el-tabs__content) {
+ padding: 24px;
+ }
+
+ .description-content {
+ line-height: 1.6;
+
+ :deep(h3) {
+ color: #2c3e50;
+ font-size: 18px;
+ font-weight: 600;
+ margin: 24px 0 12px 0;
+
+ &:first-child {
+ margin-top: 0;
+ }
+ }
+
+ :deep(p) {
+ margin-bottom: 12px;
+ color: #5a6c7d;
+ }
+
+ :deep(ul) {
+ margin: 12px 0;
+ padding-left: 20px;
+
+ li {
+ margin-bottom: 8px;
+ color: #5a6c7d;
+ }
+ }
+
+ .no-description {
+ text-align: center;
+ color: #909399;
+ padding: 40px 0;
+ }
+ }
+
+ .files-list {
+ .file-name {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+
+ .el-icon {
+ color: #909399;
+ }
+ }
+ }
+
+ .activity-section {
+ .activity-stats {
+ margin-bottom: 24px;
+
+ .stats-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
+ gap: 16px;
+
+ .stat-card {
+ background: #f8f9fa;
+ padding: 20px;
+ border-radius: 8px;
+ text-align: center;
+
+ h3 {
+ font-size: 14px;
+ color: #909399;
+ margin: 0 0 8px 0;
+ }
+
+ .stat-number {
+ font-size: 24px;
+ font-weight: 600;
+ color: #2c3e50;
+ }
+ }
+ }
+ }
+ }
+
+ .comments-section {
+ .comment-form {
+ margin-bottom: 32px;
+
+ .comment-actions {
+ margin-top: 12px;
+ text-align: right;
+ }
+ }
+
+ .comments-list {
+ .comment-item {
+ display: flex;
+ gap: 16px;
+ margin-bottom: 24px;
+ padding-bottom: 24px;
+ border-bottom: 1px solid #f0f0f0;
+
+ &:last-child {
+ border-bottom: none;
+ margin-bottom: 0;
+ padding-bottom: 0;
+ }
+
+ .comment-content {
+ flex: 1;
+
+ .comment-header {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ margin-bottom: 8px;
+
+ .comment-username {
+ font-weight: 600;
+ color: #2c3e50;
+ }
+
+ .comment-time {
+ font-size: 12px;
+ color: #909399;
+ }
+ }
+
+ .comment-text {
+ color: #5a6c7d;
+ line-height: 1.5;
+ margin-bottom: 12px;
+ }
+
+ .comment-actions {
+ .el-button {
+ padding: 0;
+ margin-right: 16px;
+
+ .el-icon {
+ margin-right: 4px;
+ }
+ }
+ }
+ }
+ }
+
+ .no-comments {
+ text-align: center;
+ color: #909399;
+ padding: 40px 0;
+ }
+ }
+ }
+}
+
+// 响应式设计
+@media (max-width: 768px) {
+ .torrent-detail-page {
+ padding: 16px;
+ }
+
+ .torrent-header .header-content {
+ flex-direction: column;
+ text-align: center;
+
+ .torrent-cover {
+ align-self: center;
+ }
+
+ .torrent-stats {
+ justify-content: center;
+ }
+
+ .action-buttons {
+ justify-content: center;
+ }
+ }
+
+ .activity-section .stats-grid {
+ grid-template-columns: 1fr;
+ }
+
+ .comment-item {
+ flex-direction: column;
+ gap: 12px;
+ }
+}
</style>
\ No newline at end of file
diff --git a/src/views/torrent/TorrentsView.vue b/src/views/torrent/TorrentsView.vue
index f3231da..1ae9f4b 100644
--- a/src/views/torrent/TorrentsView.vue
+++ b/src/views/torrent/TorrentsView.vue
@@ -1,479 +1,479 @@
-<template>
- <div class="torrents-page">
- <div class="page-header">
- <h1>种子资源</h1>
- <div class="header-actions">
- <el-button type="primary" :icon="Upload" @click="$router.push('/upload')">
- 上传种子
- </el-button>
- </div>
- </div>
-
- <!-- 搜索和筛选 -->
- <div class="search-section">
- <div class="search-bar">
- <el-input
- v-model="searchQuery"
- placeholder="搜索种子..."
- :prefix-icon="Search"
- size="large"
- @keyup.enter="handleSearch"
- clearable
- />
- <el-button type="primary" size="large" @click="handleSearch">
- 搜索
- </el-button>
- </div>
-
- <div class="filters">
- <el-select v-model="selectedCategory" placeholder="分类" @change="handleFilter">
- <el-option label="全部" value="" />
- <el-option label="电影" value="movie" />
- <el-option label="电视剧" value="tv" />
- <el-option label="音乐" value="music" />
- <el-option label="软件" value="software" />
- <el-option label="游戏" value="game" />
- </el-select>
-
- <el-select v-model="sortBy" placeholder="排序方式" @change="handleFilter">
- <el-option label="上传时间" value="upload_time" />
- <el-option label="文件大小" value="size" />
- <el-option label="做种数" value="seeders" />
- <el-option label="下载数" value="leechers" />
- <el-option label="完成数" value="downloads" />
- </el-select>
-
- <el-radio-group v-model="sortOrder" @change="handleFilter">
- <el-radio-button label="desc">降序</el-radio-button>
- <el-radio-button label="asc">升序</el-radio-button>
- </el-radio-group>
- </div>
- </div>
-
- <!-- 种子列表 -->
- <div class="torrents-list">
- <div class="list-header">
- <span class="results-count">共找到 {{ totalCount }} 个种子</span>
- </div>
-
- <el-table
- :data="torrents"
- v-loading="loading"
- @row-click="handleRowClick"
- stripe
- class="torrents-table"
- >
- <el-table-column label="分类" width="80">
- <template #default="{ row }">
- <el-tag :type="getCategoryType(row.category)" size="small">
- {{ getCategoryName(row.category) }}
- </el-tag>
- </template>
- </el-table-column>
-
- <el-table-column label="种子信息" min-width="400">
- <template #default="{ row }">
- <div class="torrent-info">
- <h4 class="torrent-title">{{ row.title }}</h4>
- <div class="torrent-meta">
- <span class="uploader">
- <el-icon><User /></el-icon>
- {{ row.uploader }}
- </span>
- <span class="upload-time">
- <el-icon><Clock /></el-icon>
- {{ formatTime(row.uploadTime) }}
- </span>
- <span class="file-size">
- <el-icon><Document /></el-icon>
- {{ row.size }}
- </span>
- </div>
- </div>
- </template>
- </el-table-column>
-
- <el-table-column label="做种" width="80" align="center">
- <template #default="{ row }">
- <span class="seeders">{{ row.seeders }}</span>
- </template>
- </el-table-column>
-
- <el-table-column label="下载" width="80" align="center">
- <template #default="{ row }">
- <span class="leechers">{{ row.leechers }}</span>
- </template>
- </el-table-column>
-
- <el-table-column label="完成" width="80" align="center">
- <template #default="{ row }">
- <span>{{ row.downloads }}</span>
- </template>
- </el-table-column>
-
- <el-table-column label="操作" width="120" align="center">
- <template #default="{ row }">
- <el-button
- type="primary"
- size="small"
- :icon="Download"
- @click.stop="handleDownload(row)"
- >
- 下载
- </el-button>
- </template>
- </el-table-column>
- </el-table>
-
- <!-- 分页 -->
- <div class="pagination-wrapper">
- <el-pagination
- v-model:current-page="currentPage"
- v-model:page-size="pageSize"
- :page-sizes="[20, 50, 100]"
- :total="totalCount"
- layout="total, sizes, prev, pager, next, jumper"
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- />
- </div>
- </div>
- </div>
-</template>
-
-<script>
-import { ref, onMounted, watch } from 'vue'
-import { useRouter, useRoute } from 'vue-router'
-import { ElMessage } from 'element-plus'
-import {
- Search,
- Upload,
- Download,
- User,
- Clock,
- Document
-} from '@element-plus/icons-vue'
-
-export default {
- name: 'TorrentsView',
- setup() {
- const router = useRouter()
- const route = useRoute()
-
- const loading = ref(false)
- const searchQuery = ref('')
- const selectedCategory = ref('')
- const sortBy = ref('upload_time')
- const sortOrder = ref('desc')
- const currentPage = ref(1)
- const pageSize = ref(20)
- const totalCount = ref(0)
-
- const torrents = ref([
- {
- id: 1,
- title: '[4K蓝光原盘] 阿凡达:水之道 Avatar: The Way of Water (2022)',
- category: 'movie',
- uploader: 'MovieMaster',
- uploadTime: '2025-06-03T10:30:00',
- size: '85.6 GB',
- seeders: 128,
- leechers: 45,
- downloads: 892
- },
- {
- id: 2,
- title: '[FLAC] Taylor Swift - Midnights (Deluxe Edition) [2022]',
- category: 'music',
- uploader: 'MusicLover',
- uploadTime: '2025-06-03T09:15:00',
- size: '1.2 GB',
- seeders: 67,
- leechers: 12,
- downloads: 456
- },
- {
- id: 3,
- title: '[合集] Adobe Creative Suite 2025 完整版',
- category: 'software',
- uploader: 'TechGuru',
- uploadTime: '2025-06-03T08:45:00',
- size: '12.8 GB',
- seeders: 234,
- leechers: 89,
- downloads: 1205
- }
- ])
-
- onMounted(() => {
- // 从URL参数初始化搜索条件
- if (route.query.q) {
- searchQuery.value = route.query.q
- }
- if (route.query.category) {
- selectedCategory.value = route.query.category
- }
-
- fetchTorrents()
- })
-
- const fetchTorrents = async () => {
- loading.value = true
- try {
- // 模拟API调用
- await new Promise(resolve => setTimeout(resolve, 1000))
- totalCount.value = 156
- } catch (error) {
- ElMessage.error('获取种子列表失败')
- } finally {
- loading.value = false
- }
- }
-
- const handleSearch = () => {
- currentPage.value = 1
- updateURL()
- fetchTorrents()
- }
-
- const handleFilter = () => {
- currentPage.value = 1
- updateURL()
- fetchTorrents()
- }
-
- const updateURL = () => {
- const query = {}
- if (searchQuery.value) query.q = searchQuery.value
- if (selectedCategory.value) query.category = selectedCategory.value
- if (sortBy.value !== 'upload_time') query.sort = sortBy.value
- if (sortOrder.value !== 'desc') query.order = sortOrder.value
- if (currentPage.value > 1) query.page = currentPage.value
-
- router.replace({ query })
- }
-
- const handleRowClick = (row) => {
- router.push(`/torrent/${row.id}`)
- }
-
- const handleDownload = (row) => {
- ElMessage.success(`开始下载: ${row.title}`)
- // 这里实现下载逻辑
- }
-
- const handleSizeChange = (size) => {
- pageSize.value = size
- currentPage.value = 1
- fetchTorrents()
- }
-
- const handleCurrentChange = (page) => {
- currentPage.value = page
- updateURL()
- fetchTorrents()
- }
-
- const formatTime = (timeString) => {
- const date = new Date(timeString)
- const now = new Date()
- const diff = now - date
- const hours = Math.floor(diff / (1000 * 60 * 60))
-
- if (hours < 1) return '刚刚'
- if (hours < 24) return `${hours}小时前`
- const days = Math.floor(hours / 24)
- return `${days}天前`
- }
-
- const getCategoryType = (category) => {
- const types = {
- 'movie': 'primary',
- 'tv': 'info',
- 'music': 'success',
- 'software': 'warning',
- 'game': 'danger'
- }
- return types[category] || 'default'
- }
-
- const getCategoryName = (category) => {
- const names = {
- 'movie': '电影',
- 'tv': '电视剧',
- 'music': '音乐',
- 'software': '软件',
- 'game': '游戏'
- }
- return names[category] || category
- }
-
- return {
- loading,
- searchQuery,
- selectedCategory,
- sortBy,
- sortOrder,
- currentPage,
- pageSize,
- totalCount,
- torrents,
- handleSearch,
- handleFilter,
- handleRowClick,
- handleDownload,
- handleSizeChange,
- handleCurrentChange,
- formatTime,
- getCategoryType,
- getCategoryName,
- Search,
- Upload,
- Download,
- User,
- Clock,
- Document
- }
- }
-}
-</script>
-
-<style lang="scss" scoped>
-.torrents-page {
- max-width: 1200px;
- margin: 0 auto;
- padding: 24px;
-}
-
-.page-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 24px;
-
- h1 {
- font-size: 28px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0;
- }
-}
-
-.search-section {
- background: #fff;
- border-radius: 12px;
- padding: 24px;
- margin-bottom: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- .search-bar {
- display: flex;
- gap: 12px;
- margin-bottom: 16px;
-
- .el-input {
- flex: 1;
- }
- }
-
- .filters {
- display: flex;
- gap: 16px;
- flex-wrap: wrap;
- align-items: center;
-
- .el-select {
- width: 120px;
- }
- }
-}
-
-.torrents-list {
- background: #fff;
- border-radius: 12px;
- padding: 24px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- .list-header {
- margin-bottom: 16px;
-
- .results-count {
- font-size: 14px;
- color: #909399;
- }
- }
-
- .torrents-table {
- .torrent-info {
- .torrent-title {
- font-size: 16px;
- font-weight: 500;
- color: #2c3e50;
- margin: 0 0 8px 0;
- line-height: 1.4;
- cursor: pointer;
-
- &:hover {
- color: #409eff;
- }
- }
-
- .torrent-meta {
- display: flex;
- gap: 16px;
- font-size: 12px;
- color: #909399;
-
- span {
- display: flex;
- align-items: center;
- gap: 4px;
- }
- }
- }
-
- .seeders {
- color: #67c23a;
- font-weight: 600;
- }
-
- .leechers {
- color: #f56c6c;
- font-weight: 600;
- }
- }
-
- .pagination-wrapper {
- margin-top: 24px;
- text-align: center;
- }
-}
-
-@media (max-width: 768px) {
- .torrents-page {
- padding: 16px;
- }
-
- .page-header {
- flex-direction: column;
- gap: 16px;
- align-items: flex-start;
- }
-
- .filters {
- flex-direction: column;
- align-items: flex-start;
-
- .el-select {
- width: 100%;
- }
- }
-
- .torrents-table {
- :deep(.el-table__header),
- :deep(.el-table__body) {
- font-size: 12px;
- }
- }
-}
+<template>
+ <div class="torrents-page">
+ <div class="page-header">
+ <h1>种子资源</h1>
+ <div class="header-actions">
+ <el-button type="primary" :icon="Upload" @click="$router.push('/upload')">
+ 上传种子
+ </el-button>
+ </div>
+ </div>
+
+ <!-- 搜索和筛选 -->
+ <div class="search-section">
+ <div class="search-bar">
+ <el-input
+ v-model="searchQuery"
+ placeholder="搜索种子..."
+ :prefix-icon="Search"
+ size="large"
+ @keyup.enter="handleSearch"
+ clearable
+ />
+ <el-button type="primary" size="large" @click="handleSearch">
+ 搜索
+ </el-button>
+ </div>
+
+ <div class="filters">
+ <el-select v-model="selectedCategory" placeholder="分类" @change="handleFilter">
+ <el-option label="全部" value="" />
+ <el-option label="电影" value="movie" />
+ <el-option label="电视剧" value="tv" />
+ <el-option label="音乐" value="music" />
+ <el-option label="软件" value="software" />
+ <el-option label="游戏" value="game" />
+ </el-select>
+
+ <el-select v-model="sortBy" placeholder="排序方式" @change="handleFilter">
+ <el-option label="上传时间" value="upload_time" />
+ <el-option label="文件大小" value="size" />
+ <el-option label="做种数" value="seeders" />
+ <el-option label="下载数" value="leechers" />
+ <el-option label="完成数" value="downloads" />
+ </el-select>
+
+ <el-radio-group v-model="sortOrder" @change="handleFilter">
+ <el-radio-button label="desc">降序</el-radio-button>
+ <el-radio-button label="asc">升序</el-radio-button>
+ </el-radio-group>
+ </div>
+ </div>
+
+ <!-- 种子列表 -->
+ <div class="torrents-list">
+ <div class="list-header">
+ <span class="results-count">共找到 {{ totalCount }} 个种子</span>
+ </div>
+
+ <el-table
+ :data="torrents"
+ v-loading="loading"
+ @row-click="handleRowClick"
+ stripe
+ class="torrents-table"
+ >
+ <el-table-column label="分类" width="80">
+ <template #default="{ row }">
+ <el-tag :type="getCategoryType(row.category)" size="small">
+ {{ getCategoryName(row.category) }}
+ </el-tag>
+ </template>
+ </el-table-column>
+
+ <el-table-column label="种子信息" min-width="400">
+ <template #default="{ row }">
+ <div class="torrent-info">
+ <h4 class="torrent-title">{{ row.title }}</h4>
+ <div class="torrent-meta">
+ <span class="uploader">
+ <el-icon><User /></el-icon>
+ {{ row.uploader }}
+ </span>
+ <span class="upload-time">
+ <el-icon><Clock /></el-icon>
+ {{ formatTime(row.uploadTime) }}
+ </span>
+ <span class="file-size">
+ <el-icon><Document /></el-icon>
+ {{ row.size }}
+ </span>
+ </div>
+ </div>
+ </template>
+ </el-table-column>
+
+ <el-table-column label="做种" width="80" align="center">
+ <template #default="{ row }">
+ <span class="seeders">{{ row.seeders }}</span>
+ </template>
+ </el-table-column>
+
+ <el-table-column label="下载" width="80" align="center">
+ <template #default="{ row }">
+ <span class="leechers">{{ row.leechers }}</span>
+ </template>
+ </el-table-column>
+
+ <el-table-column label="完成" width="80" align="center">
+ <template #default="{ row }">
+ <span>{{ row.downloads }}</span>
+ </template>
+ </el-table-column>
+
+ <el-table-column label="操作" width="120" align="center">
+ <template #default="{ row }">
+ <el-button
+ type="primary"
+ size="small"
+ :icon="Download"
+ @click.stop="handleDownload(row)"
+ >
+ 下载
+ </el-button>
+ </template>
+ </el-table-column>
+ </el-table>
+
+ <!-- 分页 -->
+ <div class="pagination-wrapper">
+ <el-pagination
+ v-model:current-page="currentPage"
+ v-model:page-size="pageSize"
+ :page-sizes="[20, 50, 100]"
+ :total="totalCount"
+ layout="total, sizes, prev, pager, next, jumper"
+ @size-change="handleSizeChange"
+ @current-change="handleCurrentChange"
+ />
+ </div>
+ </div>
+ </div>
+</template>
+
+<script>
+import { ref, onMounted, watch } from 'vue'
+import { useRouter, useRoute } from 'vue-router'
+import { ElMessage } from 'element-plus'
+import {
+ Search,
+ Upload,
+ Download,
+ User,
+ Clock,
+ Document
+} from '@element-plus/icons-vue'
+
+export default {
+ name: 'TorrentsView',
+ setup() {
+ const router = useRouter()
+ const route = useRoute()
+
+ const loading = ref(false)
+ const searchQuery = ref('')
+ const selectedCategory = ref('')
+ const sortBy = ref('upload_time')
+ const sortOrder = ref('desc')
+ const currentPage = ref(1)
+ const pageSize = ref(20)
+ const totalCount = ref(0)
+
+ const torrents = ref([
+ {
+ id: 1,
+ title: '[4K蓝光原盘] 阿凡达:水之道 Avatar: The Way of Water (2022)',
+ category: 'movie',
+ uploader: 'MovieMaster',
+ uploadTime: '2025-06-03T10:30:00',
+ size: '85.6 GB',
+ seeders: 128,
+ leechers: 45,
+ downloads: 892
+ },
+ {
+ id: 2,
+ title: '[FLAC] Taylor Swift - Midnights (Deluxe Edition) [2022]',
+ category: 'music',
+ uploader: 'MusicLover',
+ uploadTime: '2025-06-03T09:15:00',
+ size: '1.2 GB',
+ seeders: 67,
+ leechers: 12,
+ downloads: 456
+ },
+ {
+ id: 3,
+ title: '[合集] Adobe Creative Suite 2025 完整版',
+ category: 'software',
+ uploader: 'TechGuru',
+ uploadTime: '2025-06-03T08:45:00',
+ size: '12.8 GB',
+ seeders: 234,
+ leechers: 89,
+ downloads: 1205
+ }
+ ])
+
+ onMounted(() => {
+ // 从URL参数初始化搜索条件
+ if (route.query.q) {
+ searchQuery.value = route.query.q
+ }
+ if (route.query.category) {
+ selectedCategory.value = route.query.category
+ }
+
+ fetchTorrents()
+ })
+
+ const fetchTorrents = async () => {
+ loading.value = true
+ try {
+ // 模拟API调用
+ await new Promise(resolve => setTimeout(resolve, 1000))
+ totalCount.value = 156
+ } catch (error) {
+ ElMessage.error('获取种子列表失败')
+ } finally {
+ loading.value = false
+ }
+ }
+
+ const handleSearch = () => {
+ currentPage.value = 1
+ updateURL()
+ fetchTorrents()
+ }
+
+ const handleFilter = () => {
+ currentPage.value = 1
+ updateURL()
+ fetchTorrents()
+ }
+
+ const updateURL = () => {
+ const query = {}
+ if (searchQuery.value) query.q = searchQuery.value
+ if (selectedCategory.value) query.category = selectedCategory.value
+ if (sortBy.value !== 'upload_time') query.sort = sortBy.value
+ if (sortOrder.value !== 'desc') query.order = sortOrder.value
+ if (currentPage.value > 1) query.page = currentPage.value
+
+ router.replace({ query })
+ }
+
+ const handleRowClick = (row) => {
+ router.push(`/torrent/${row.id}`)
+ }
+
+ const handleDownload = (row) => {
+ ElMessage.success(`开始下载: ${row.title}`)
+ // 这里实现下载逻辑
+ }
+
+ const handleSizeChange = (size) => {
+ pageSize.value = size
+ currentPage.value = 1
+ fetchTorrents()
+ }
+
+ const handleCurrentChange = (page) => {
+ currentPage.value = page
+ updateURL()
+ fetchTorrents()
+ }
+
+ const formatTime = (timeString) => {
+ const date = new Date(timeString)
+ const now = new Date()
+ const diff = now - date
+ const hours = Math.floor(diff / (1000 * 60 * 60))
+
+ if (hours < 1) return '刚刚'
+ if (hours < 24) return `${hours}小时前`
+ const days = Math.floor(hours / 24)
+ return `${days}天前`
+ }
+
+ const getCategoryType = (category) => {
+ const types = {
+ 'movie': 'primary',
+ 'tv': 'info',
+ 'music': 'success',
+ 'software': 'warning',
+ 'game': 'danger'
+ }
+ return types[category] || 'default'
+ }
+
+ const getCategoryName = (category) => {
+ const names = {
+ 'movie': '电影',
+ 'tv': '电视剧',
+ 'music': '音乐',
+ 'software': '软件',
+ 'game': '游戏'
+ }
+ return names[category] || category
+ }
+
+ return {
+ loading,
+ searchQuery,
+ selectedCategory,
+ sortBy,
+ sortOrder,
+ currentPage,
+ pageSize,
+ totalCount,
+ torrents,
+ handleSearch,
+ handleFilter,
+ handleRowClick,
+ handleDownload,
+ handleSizeChange,
+ handleCurrentChange,
+ formatTime,
+ getCategoryType,
+ getCategoryName,
+ Search,
+ Upload,
+ Download,
+ User,
+ Clock,
+ Document
+ }
+ }
+}
+</script>
+
+<style lang="scss" scoped>
+.torrents-page {
+ max-width: 1200px;
+ margin: 0 auto;
+ padding: 24px;
+}
+
+.page-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 24px;
+
+ h1 {
+ font-size: 28px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0;
+ }
+}
+
+.search-section {
+ background: #fff;
+ border-radius: 12px;
+ padding: 24px;
+ margin-bottom: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ .search-bar {
+ display: flex;
+ gap: 12px;
+ margin-bottom: 16px;
+
+ .el-input {
+ flex: 1;
+ }
+ }
+
+ .filters {
+ display: flex;
+ gap: 16px;
+ flex-wrap: wrap;
+ align-items: center;
+
+ .el-select {
+ width: 120px;
+ }
+ }
+}
+
+.torrents-list {
+ background: #fff;
+ border-radius: 12px;
+ padding: 24px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ .list-header {
+ margin-bottom: 16px;
+
+ .results-count {
+ font-size: 14px;
+ color: #909399;
+ }
+ }
+
+ .torrents-table {
+ .torrent-info {
+ .torrent-title {
+ font-size: 16px;
+ font-weight: 500;
+ color: #2c3e50;
+ margin: 0 0 8px 0;
+ line-height: 1.4;
+ cursor: pointer;
+
+ &:hover {
+ color: #409eff;
+ }
+ }
+
+ .torrent-meta {
+ display: flex;
+ gap: 16px;
+ font-size: 12px;
+ color: #909399;
+
+ span {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ }
+ }
+ }
+
+ .seeders {
+ color: #67c23a;
+ font-weight: 600;
+ }
+
+ .leechers {
+ color: #f56c6c;
+ font-weight: 600;
+ }
+ }
+
+ .pagination-wrapper {
+ margin-top: 24px;
+ text-align: center;
+ }
+}
+
+@media (max-width: 768px) {
+ .torrents-page {
+ padding: 16px;
+ }
+
+ .page-header {
+ flex-direction: column;
+ gap: 16px;
+ align-items: flex-start;
+ }
+
+ .filters {
+ flex-direction: column;
+ align-items: flex-start;
+
+ .el-select {
+ width: 100%;
+ }
+ }
+
+ .torrents-table {
+ :deep(.el-table__header),
+ :deep(.el-table__body) {
+ font-size: 12px;
+ }
+ }
+}
</style>
\ No newline at end of file
diff --git a/src/views/torrent/UploadView.vue b/src/views/torrent/UploadView.vue
index d99b446..80c3660 100644
--- a/src/views/torrent/UploadView.vue
+++ b/src/views/torrent/UploadView.vue
@@ -1,506 +1,506 @@
-<template>
- <div class="upload-page">
- <div class="page-header">
- <h1>上传种子</h1>
- <p class="page-description">分享你的资源,为社区做贡献</p>
- </div>
-
- <div class="upload-form">
- <el-form
- ref="uploadFormRef"
- :model="uploadForm"
- :rules="formRules"
- label-width="120px"
- size="large"
- >
- <!-- 种子文件上传 -->
- <el-form-item label="种子文件" prop="torrentFile" required>
- <el-upload
- ref="torrentUploadRef"
- :auto-upload="false"
- :limit="1"
- accept=".torrent"
- :on-change="handleTorrentChange"
- :on-remove="handleTorrentRemove"
- :before-upload="beforeTorrentUpload"
- drag
- class="torrent-upload"
- >
- <el-icon class="el-icon--upload"><UploadFilled /></el-icon>
- <div class="el-upload__text">
- 将 .torrent 文件拖到此处,或<em>点击上传</em>
- </div>
- <template #tip>
- <div class="el-upload__tip">
- 只能上传 .torrent 文件,且不超过 10MB
- </div>
- </template>
- </el-upload>
- </el-form-item>
-
- <!-- 基本信息 -->
- <el-form-item label="资源标题" prop="title" required>
- <el-input
- v-model="uploadForm.title"
- placeholder="请输入资源标题"
- maxlength="200"
- show-word-limit
- />
- </el-form-item>
-
- <el-form-item label="资源分类" prop="category" required>
- <el-select v-model="uploadForm.category" placeholder="请选择分类">
- <el-option label="电影" value="movie" />
- <el-option label="电视剧" value="tv" />
- <el-option label="音乐" value="music" />
- <el-option label="软件" value="software" />
- <el-option label="游戏" value="game" />
- <el-option label="电子书" value="ebook" />
- <el-option label="其他" value="other" />
- </el-select>
- </el-form-item>
-
- <el-form-item label="子分类" prop="subcategory">
- <el-select v-model="uploadForm.subcategory" placeholder="请选择子分类">
- <el-option
- v-for="sub in getSubcategories(uploadForm.category)"
- :key="sub.value"
- :label="sub.label"
- :value="sub.value"
- />
- </el-select>
- </el-form-item>
-
- <!-- 详细描述 -->
- <el-form-item label="资源描述" prop="description">
- <el-input
- v-model="uploadForm.description"
- type="textarea"
- :rows="6"
- placeholder="请详细描述资源内容,包括格式、质量、语言等信息"
- maxlength="2000"
- show-word-limit
- />
- </el-form-item>
-
- <!-- 标签 -->
- <el-form-item label="标签">
- <div class="tags-input">
- <el-tag
- v-for="tag in uploadForm.tags"
- :key="tag"
- closable
- @close="removeTag(tag)"
- class="tag-item"
- >
- {{ tag }}
- </el-tag>
- <el-input
- v-if="tagInputVisible"
- ref="tagInputRef"
- v-model="tagInputValue"
- size="small"
- @keyup.enter="addTag"
- @blur="addTag"
- class="tag-input"
- />
- <el-button
- v-else
- size="small"
- @click="showTagInput"
- class="add-tag-btn"
- >
- + 添加标签
- </el-button>
- </div>
- </el-form-item>
-
- <!-- 封面图片 -->
- <el-form-item label="封面图片">
- <el-upload
- ref="imageUploadRef"
- :auto-upload="false"
- :limit="1"
- accept="image/*"
- :on-change="handleImageChange"
- :on-remove="handleImageRemove"
- list-type="picture-card"
- class="image-upload"
- >
- <el-icon><Plus /></el-icon>
- <template #tip>
- <div class="el-upload__tip">
- 支持 JPG、PNG 格式,建议尺寸 300x400,不超过 5MB
- </div>
- </template>
- </el-upload>
- </el-form-item>
-
- <!-- 高级选项 -->
- <el-form-item>
- <el-collapse>
- <el-collapse-item title="高级选项" name="advanced">
- <el-form-item label="免费时间">
- <el-select v-model="uploadForm.freeTime" placeholder="选择免费时间">
- <el-option label="永久免费" value="forever" />
- <el-option label="24小时" value="24h" />
- <el-option label="48小时" value="48h" />
- <el-option label="7天" value="7d" />
- <el-option label="30天" value="30d" />
- </el-select>
- </el-form-item>
-
- <el-form-item label="匿名上传">
- <el-switch v-model="uploadForm.anonymous" />
- <span class="form-tip">开启后将不显示上传者信息</span>
- </el-form-item>
-
- <el-form-item label="允许HR">
- <el-switch v-model="uploadForm.allowHR" />
- <span class="form-tip">允许此种子参与HR考核</span>
- </el-form-item>
- </el-collapse-item>
- </el-collapse>
- </el-form-item>
-
- <!-- 提交按钮 -->
- <el-form-item>
- <div class="submit-buttons">
- <el-button @click="resetForm">重置</el-button>
- <el-button type="primary" @click="submitForm" :loading="uploading">
- {{ uploading ? '上传中...' : '提交种子' }}
- </el-button>
- </div>
- </el-form-item>
- </el-form>
- </div>
- </div>
-</template>
-
-<script>
-import { ref, reactive, nextTick } from 'vue'
-import { useRouter } from 'vue-router'
-import { ElMessage } from 'element-plus'
-import {
- UploadFilled,
- Plus
-} from '@element-plus/icons-vue'
-
-export default {
- name: 'UploadView',
- setup() {
- const router = useRouter()
- const uploadFormRef = ref(null)
- const torrentUploadRef = ref(null)
- const imageUploadRef = ref(null)
- const tagInputRef = ref(null)
-
- const uploading = ref(false)
- const tagInputVisible = ref(false)
- const tagInputValue = ref('')
-
- const uploadForm = reactive({
- torrentFile: null,
- title: '',
- category: '',
- subcategory: '',
- description: '',
- tags: [],
- coverImage: null,
- freeTime: '',
- anonymous: false,
- allowHR: true
- })
-
- const formRules = {
- title: [
- { required: true, message: '请输入资源标题', trigger: 'blur' },
- { min: 5, max: 200, message: '标题长度在 5 到 200 个字符', trigger: 'blur' }
- ],
- category: [
- { required: true, message: '请选择资源分类', trigger: 'change' }
- ],
- description: [
- { min: 10, max: 2000, message: '描述长度在 10 到 2000 个字符', trigger: 'blur' }
- ]
- }
-
- const subcategories = {
- movie: [
- { label: '动作片', value: 'action' },
- { label: '喜剧片', value: 'comedy' },
- { label: '科幻片', value: 'scifi' },
- { label: '恐怖片', value: 'horror' },
- { label: '剧情片', value: 'drama' }
- ],
- tv: [
- { label: '美剧', value: 'us' },
- { label: '国产剧', value: 'cn' },
- { label: '日韩剧', value: 'asia' },
- { label: '英剧', value: 'uk' },
- { label: '纪录片', value: 'documentary' }
- ],
- music: [
- { label: '流行音乐', value: 'pop' },
- { label: '古典音乐', value: 'classical' },
- { label: '摇滚音乐', value: 'rock' },
- { label: '电子音乐', value: 'electronic' },
- { label: '其他', value: 'other' }
- ],
- software: [
- { label: '操作系统', value: 'os' },
- { label: '办公软件', value: 'office' },
- { label: '开发工具', value: 'dev' },
- { label: '设计软件', value: 'design' },
- { label: '其他', value: 'other' }
- ],
- game: [
- { label: 'PC游戏', value: 'pc' },
- { label: '主机游戏', value: 'console' },
- { label: '手机游戏', value: 'mobile' },
- { label: '其他', value: 'other' }
- ]
- }
-
- const getSubcategories = (category) => {
- return subcategories[category] || []
- }
-
- const handleTorrentChange = (file) => {
- uploadForm.torrentFile = file.raw
- // 这里可以解析torrent文件获取基本信息
- parseTorrentFile(file.raw)
- }
-
- const handleTorrentRemove = () => {
- uploadForm.torrentFile = null
- }
-
- const beforeTorrentUpload = (file) => {
- const isTorrent = file.type === 'application/x-bittorrent' || file.name.endsWith('.torrent')
- const isLt10M = file.size / 1024 / 1024 < 10
-
- if (!isTorrent) {
- ElMessage.error('只能上传 .torrent 文件!')
- return false
- }
- if (!isLt10M) {
- ElMessage.error('种子文件大小不能超过 10MB!')
- return false
- }
- return true
- }
-
- const parseTorrentFile = (file) => {
- // 这里应该实现torrent文件解析
- // 可以使用 parse-torrent 库
- console.log('解析种子文件:', file.name)
-
- // 模拟解析结果自动填入表单
- if (!uploadForm.title) {
- uploadForm.title = file.name.replace('.torrent', '')
- }
- }
-
- const handleImageChange = (file) => {
- uploadForm.coverImage = file.raw
- }
-
- const handleImageRemove = () => {
- uploadForm.coverImage = null
- }
-
- const showTagInput = () => {
- tagInputVisible.value = true
- nextTick(() => {
- tagInputRef.value?.focus()
- })
- }
-
- const addTag = () => {
- const tag = tagInputValue.value.trim()
- if (tag && !uploadForm.tags.includes(tag)) {
- uploadForm.tags.push(tag)
- }
- tagInputVisible.value = false
- tagInputValue.value = ''
- }
-
- const removeTag = (tag) => {
- const index = uploadForm.tags.indexOf(tag)
- if (index > -1) {
- uploadForm.tags.splice(index, 1)
- }
- }
-
- const submitForm = async () => {
- if (!uploadForm.torrentFile) {
- ElMessage.error('请上传种子文件')
- return
- }
-
- try {
- await uploadFormRef.value?.validate()
-
- uploading.value = true
-
- // 模拟上传过程
- await new Promise(resolve => setTimeout(resolve, 2000))
-
- ElMessage.success('种子上传成功!')
- router.push('/torrents')
-
- } catch (error) {
- console.error('表单验证失败:', error)
- } finally {
- uploading.value = false
- }
- }
-
- const resetForm = () => {
- uploadFormRef.value?.resetFields()
- uploadForm.torrentFile = null
- uploadForm.coverImage = null
- uploadForm.tags = []
- torrentUploadRef.value?.clearFiles()
- imageUploadRef.value?.clearFiles()
- }
-
- return {
- uploadFormRef,
- torrentUploadRef,
- imageUploadRef,
- tagInputRef,
- uploading,
- tagInputVisible,
- tagInputValue,
- uploadForm,
- formRules,
- getSubcategories,
- handleTorrentChange,
- handleTorrentRemove,
- beforeTorrentUpload,
- handleImageChange,
- handleImageRemove,
- showTagInput,
- addTag,
- removeTag,
- submitForm,
- resetForm,
- UploadFilled,
- Plus
- }
- }
-}
-</script>
-
-<style lang="scss" scoped>
-.upload-page {
- max-width: 800px;
- margin: 0 auto;
- padding: 24px;
-}
-
-.page-header {
- text-align: center;
- margin-bottom: 32px;
-
- h1 {
- font-size: 28px;
- font-weight: 600;
- color: #2c3e50;
- margin: 0 0 8px 0;
- }
-
- .page-description {
- font-size: 16px;
- color: #7f8c8d;
- margin: 0;
- }
-}
-
-.upload-form {
- background: #fff;
- border-radius: 12px;
- padding: 32px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
-
- .torrent-upload {
- width: 100%;
-
- :deep(.el-upload-dragger) {
- width: 100%;
- height: 180px;
- border: 2px dashed #d9d9d9;
- border-radius: 8px;
-
- &:hover {
- border-color: #409eff;
- }
- }
- }
-
- .tags-input {
- display: flex;
- flex-wrap: wrap;
- gap: 8px;
- align-items: center;
-
- .tag-item {
- margin: 0;
- }
-
- .tag-input {
- width: 100px;
- }
-
- .add-tag-btn {
- border: 1px dashed #d9d9d9;
- color: #999;
-
- &:hover {
- border-color: #409eff;
- color: #409eff;
- }
- }
- }
-
- .image-upload {
- :deep(.el-upload--picture-card) {
- width: 148px;
- height: 148px;
- }
- }
-
- .form-tip {
- margin-left: 8px;
- font-size: 12px;
- color: #909399;
- }
-
- .submit-buttons {
- display: flex;
- gap: 16px;
- justify-content: center;
- margin-top: 24px;
- }
-}
-
-@media (max-width: 768px) {
- .upload-page {
- padding: 16px;
- }
-
- .upload-form {
- padding: 24px 16px;
- }
-
- .submit-buttons {
- flex-direction: column;
-
- .el-button {
- width: 100%;
- }
- }
-}
+<template>
+ <div class="upload-page">
+ <div class="page-header">
+ <h1>上传种子</h1>
+ <p class="page-description">分享你的资源,为社区做贡献</p>
+ </div>
+
+ <div class="upload-form">
+ <el-form
+ ref="uploadFormRef"
+ :model="uploadForm"
+ :rules="formRules"
+ label-width="120px"
+ size="large"
+ >
+ <!-- 种子文件上传 -->
+ <el-form-item label="种子文件" prop="torrentFile" required>
+ <el-upload
+ ref="torrentUploadRef"
+ :auto-upload="false"
+ :limit="1"
+ accept=".torrent"
+ :on-change="handleTorrentChange"
+ :on-remove="handleTorrentRemove"
+ :before-upload="beforeTorrentUpload"
+ drag
+ class="torrent-upload"
+ >
+ <el-icon class="el-icon--upload"><UploadFilled /></el-icon>
+ <div class="el-upload__text">
+ 将 .torrent 文件拖到此处,或<em>点击上传</em>
+ </div>
+ <template #tip>
+ <div class="el-upload__tip">
+ 只能上传 .torrent 文件,且不超过 10MB
+ </div>
+ </template>
+ </el-upload>
+ </el-form-item>
+
+ <!-- 基本信息 -->
+ <el-form-item label="资源标题" prop="title" required>
+ <el-input
+ v-model="uploadForm.title"
+ placeholder="请输入资源标题"
+ maxlength="200"
+ show-word-limit
+ />
+ </el-form-item>
+
+ <el-form-item label="资源分类" prop="category" required>
+ <el-select v-model="uploadForm.category" placeholder="请选择分类">
+ <el-option label="电影" value="movie" />
+ <el-option label="电视剧" value="tv" />
+ <el-option label="音乐" value="music" />
+ <el-option label="软件" value="software" />
+ <el-option label="游戏" value="game" />
+ <el-option label="电子书" value="ebook" />
+ <el-option label="其他" value="other" />
+ </el-select>
+ </el-form-item>
+
+ <el-form-item label="子分类" prop="subcategory">
+ <el-select v-model="uploadForm.subcategory" placeholder="请选择子分类">
+ <el-option
+ v-for="sub in getSubcategories(uploadForm.category)"
+ :key="sub.value"
+ :label="sub.label"
+ :value="sub.value"
+ />
+ </el-select>
+ </el-form-item>
+
+ <!-- 详细描述 -->
+ <el-form-item label="资源描述" prop="description">
+ <el-input
+ v-model="uploadForm.description"
+ type="textarea"
+ :rows="6"
+ placeholder="请详细描述资源内容,包括格式、质量、语言等信息"
+ maxlength="2000"
+ show-word-limit
+ />
+ </el-form-item>
+
+ <!-- 标签 -->
+ <el-form-item label="标签">
+ <div class="tags-input">
+ <el-tag
+ v-for="tag in uploadForm.tags"
+ :key="tag"
+ closable
+ @close="removeTag(tag)"
+ class="tag-item"
+ >
+ {{ tag }}
+ </el-tag>
+ <el-input
+ v-if="tagInputVisible"
+ ref="tagInputRef"
+ v-model="tagInputValue"
+ size="small"
+ @keyup.enter="addTag"
+ @blur="addTag"
+ class="tag-input"
+ />
+ <el-button
+ v-else
+ size="small"
+ @click="showTagInput"
+ class="add-tag-btn"
+ >
+ + 添加标签
+ </el-button>
+ </div>
+ </el-form-item>
+
+ <!-- 封面图片 -->
+ <el-form-item label="封面图片">
+ <el-upload
+ ref="imageUploadRef"
+ :auto-upload="false"
+ :limit="1"
+ accept="image/*"
+ :on-change="handleImageChange"
+ :on-remove="handleImageRemove"
+ list-type="picture-card"
+ class="image-upload"
+ >
+ <el-icon><Plus /></el-icon>
+ <template #tip>
+ <div class="el-upload__tip">
+ 支持 JPG、PNG 格式,建议尺寸 300x400,不超过 5MB
+ </div>
+ </template>
+ </el-upload>
+ </el-form-item>
+
+ <!-- 高级选项 -->
+ <el-form-item>
+ <el-collapse>
+ <el-collapse-item title="高级选项" name="advanced">
+ <el-form-item label="免费时间">
+ <el-select v-model="uploadForm.freeTime" placeholder="选择免费时间">
+ <el-option label="永久免费" value="forever" />
+ <el-option label="24小时" value="24h" />
+ <el-option label="48小时" value="48h" />
+ <el-option label="7天" value="7d" />
+ <el-option label="30天" value="30d" />
+ </el-select>
+ </el-form-item>
+
+ <el-form-item label="匿名上传">
+ <el-switch v-model="uploadForm.anonymous" />
+ <span class="form-tip">开启后将不显示上传者信息</span>
+ </el-form-item>
+
+ <el-form-item label="允许HR">
+ <el-switch v-model="uploadForm.allowHR" />
+ <span class="form-tip">允许此种子参与HR考核</span>
+ </el-form-item>
+ </el-collapse-item>
+ </el-collapse>
+ </el-form-item>
+
+ <!-- 提交按钮 -->
+ <el-form-item>
+ <div class="submit-buttons">
+ <el-button @click="resetForm">重置</el-button>
+ <el-button type="primary" @click="submitForm" :loading="uploading">
+ {{ uploading ? '上传中...' : '提交种子' }}
+ </el-button>
+ </div>
+ </el-form-item>
+ </el-form>
+ </div>
+ </div>
+</template>
+
+<script>
+import { ref, reactive, nextTick } from 'vue'
+import { useRouter } from 'vue-router'
+import { ElMessage } from 'element-plus'
+import {
+ UploadFilled,
+ Plus
+} from '@element-plus/icons-vue'
+
+export default {
+ name: 'UploadView',
+ setup() {
+ const router = useRouter()
+ const uploadFormRef = ref(null)
+ const torrentUploadRef = ref(null)
+ const imageUploadRef = ref(null)
+ const tagInputRef = ref(null)
+
+ const uploading = ref(false)
+ const tagInputVisible = ref(false)
+ const tagInputValue = ref('')
+
+ const uploadForm = reactive({
+ torrentFile: null,
+ title: '',
+ category: '',
+ subcategory: '',
+ description: '',
+ tags: [],
+ coverImage: null,
+ freeTime: '',
+ anonymous: false,
+ allowHR: true
+ })
+
+ const formRules = {
+ title: [
+ { required: true, message: '请输入资源标题', trigger: 'blur' },
+ { min: 5, max: 200, message: '标题长度在 5 到 200 个字符', trigger: 'blur' }
+ ],
+ category: [
+ { required: true, message: '请选择资源分类', trigger: 'change' }
+ ],
+ description: [
+ { min: 10, max: 2000, message: '描述长度在 10 到 2000 个字符', trigger: 'blur' }
+ ]
+ }
+
+ const subcategories = {
+ movie: [
+ { label: '动作片', value: 'action' },
+ { label: '喜剧片', value: 'comedy' },
+ { label: '科幻片', value: 'scifi' },
+ { label: '恐怖片', value: 'horror' },
+ { label: '剧情片', value: 'drama' }
+ ],
+ tv: [
+ { label: '美剧', value: 'us' },
+ { label: '国产剧', value: 'cn' },
+ { label: '日韩剧', value: 'asia' },
+ { label: '英剧', value: 'uk' },
+ { label: '纪录片', value: 'documentary' }
+ ],
+ music: [
+ { label: '流行音乐', value: 'pop' },
+ { label: '古典音乐', value: 'classical' },
+ { label: '摇滚音乐', value: 'rock' },
+ { label: '电子音乐', value: 'electronic' },
+ { label: '其他', value: 'other' }
+ ],
+ software: [
+ { label: '操作系统', value: 'os' },
+ { label: '办公软件', value: 'office' },
+ { label: '开发工具', value: 'dev' },
+ { label: '设计软件', value: 'design' },
+ { label: '其他', value: 'other' }
+ ],
+ game: [
+ { label: 'PC游戏', value: 'pc' },
+ { label: '主机游戏', value: 'console' },
+ { label: '手机游戏', value: 'mobile' },
+ { label: '其他', value: 'other' }
+ ]
+ }
+
+ const getSubcategories = (category) => {
+ return subcategories[category] || []
+ }
+
+ const handleTorrentChange = (file) => {
+ uploadForm.torrentFile = file.raw
+ // 这里可以解析torrent文件获取基本信息
+ parseTorrentFile(file.raw)
+ }
+
+ const handleTorrentRemove = () => {
+ uploadForm.torrentFile = null
+ }
+
+ const beforeTorrentUpload = (file) => {
+ const isTorrent = file.type === 'application/x-bittorrent' || file.name.endsWith('.torrent')
+ const isLt10M = file.size / 1024 / 1024 < 10
+
+ if (!isTorrent) {
+ ElMessage.error('只能上传 .torrent 文件!')
+ return false
+ }
+ if (!isLt10M) {
+ ElMessage.error('种子文件大小不能超过 10MB!')
+ return false
+ }
+ return true
+ }
+
+ const parseTorrentFile = (file) => {
+ // 这里应该实现torrent文件解析
+ // 可以使用 parse-torrent 库
+ console.log('解析种子文件:', file.name)
+
+ // 模拟解析结果自动填入表单
+ if (!uploadForm.title) {
+ uploadForm.title = file.name.replace('.torrent', '')
+ }
+ }
+
+ const handleImageChange = (file) => {
+ uploadForm.coverImage = file.raw
+ }
+
+ const handleImageRemove = () => {
+ uploadForm.coverImage = null
+ }
+
+ const showTagInput = () => {
+ tagInputVisible.value = true
+ nextTick(() => {
+ tagInputRef.value?.focus()
+ })
+ }
+
+ const addTag = () => {
+ const tag = tagInputValue.value.trim()
+ if (tag && !uploadForm.tags.includes(tag)) {
+ uploadForm.tags.push(tag)
+ }
+ tagInputVisible.value = false
+ tagInputValue.value = ''
+ }
+
+ const removeTag = (tag) => {
+ const index = uploadForm.tags.indexOf(tag)
+ if (index > -1) {
+ uploadForm.tags.splice(index, 1)
+ }
+ }
+
+ const submitForm = async () => {
+ if (!uploadForm.torrentFile) {
+ ElMessage.error('请上传种子文件')
+ return
+ }
+
+ try {
+ await uploadFormRef.value?.validate()
+
+ uploading.value = true
+
+ // 模拟上传过程
+ await new Promise(resolve => setTimeout(resolve, 2000))
+
+ ElMessage.success('种子上传成功!')
+ router.push('/torrents')
+
+ } catch (error) {
+ console.error('表单验证失败:', error)
+ } finally {
+ uploading.value = false
+ }
+ }
+
+ const resetForm = () => {
+ uploadFormRef.value?.resetFields()
+ uploadForm.torrentFile = null
+ uploadForm.coverImage = null
+ uploadForm.tags = []
+ torrentUploadRef.value?.clearFiles()
+ imageUploadRef.value?.clearFiles()
+ }
+
+ return {
+ uploadFormRef,
+ torrentUploadRef,
+ imageUploadRef,
+ tagInputRef,
+ uploading,
+ tagInputVisible,
+ tagInputValue,
+ uploadForm,
+ formRules,
+ getSubcategories,
+ handleTorrentChange,
+ handleTorrentRemove,
+ beforeTorrentUpload,
+ handleImageChange,
+ handleImageRemove,
+ showTagInput,
+ addTag,
+ removeTag,
+ submitForm,
+ resetForm,
+ UploadFilled,
+ Plus
+ }
+ }
+}
+</script>
+
+<style lang="scss" scoped>
+.upload-page {
+ max-width: 800px;
+ margin: 0 auto;
+ padding: 24px;
+}
+
+.page-header {
+ text-align: center;
+ margin-bottom: 32px;
+
+ h1 {
+ font-size: 28px;
+ font-weight: 600;
+ color: #2c3e50;
+ margin: 0 0 8px 0;
+ }
+
+ .page-description {
+ font-size: 16px;
+ color: #7f8c8d;
+ margin: 0;
+ }
+}
+
+.upload-form {
+ background: #fff;
+ border-radius: 12px;
+ padding: 32px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
+
+ .torrent-upload {
+ width: 100%;
+
+ :deep(.el-upload-dragger) {
+ width: 100%;
+ height: 180px;
+ border: 2px dashed #d9d9d9;
+ border-radius: 8px;
+
+ &:hover {
+ border-color: #409eff;
+ }
+ }
+ }
+
+ .tags-input {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 8px;
+ align-items: center;
+
+ .tag-item {
+ margin: 0;
+ }
+
+ .tag-input {
+ width: 100px;
+ }
+
+ .add-tag-btn {
+ border: 1px dashed #d9d9d9;
+ color: #999;
+
+ &:hover {
+ border-color: #409eff;
+ color: #409eff;
+ }
+ }
+ }
+
+ .image-upload {
+ :deep(.el-upload--picture-card) {
+ width: 148px;
+ height: 148px;
+ }
+ }
+
+ .form-tip {
+ margin-left: 8px;
+ font-size: 12px;
+ color: #909399;
+ }
+
+ .submit-buttons {
+ display: flex;
+ gap: 16px;
+ justify-content: center;
+ margin-top: 24px;
+ }
+}
+
+@media (max-width: 768px) {
+ .upload-page {
+ padding: 16px;
+ }
+
+ .upload-form {
+ padding: 24px 16px;
+ }
+
+ .submit-buttons {
+ flex-direction: column;
+
+ .el-button {
+ width: 100%;
+ }
+ }
+}
</style>
\ No newline at end of file