Commit 85482980 by 焦子成

1

parent d36acf7e
var apiHost = "";
var domain = "";
let env = process.env.NODE_ENV || "";
if (env == "production") {
apiHost = "https://taskh5.htangcloud.com";
} else if (env == "test") {
apiHost = "https://testapp.rongketech.com";
} else {
apiHost = "http://39.107.245.36:8081";
domain = '/api'
}
console.log(
`-----env[${env}]-----, apiHost[${apiHost}]`
);
const config = {
apiHost,
domain,
login: `${domain}/user/login`,
register: `${domain}/user/register`,
uploadBatchList: `${domain}/uploadBatch/pageList`,
uploadBatchQueryUpload: `${domain}/uploadBatch/queryUpload`,
uploadBatchDelete: `${domain}/uploadBatch/delete`,
uploadDetailList: `${domain}/uploadDetail/pageList`,
uploadBatchFileUpload: `${domain}/uploadBatch/fileUpload`,
uploadDetailTotalNum: `${domain}/uploadDetail/totalNum`,
uploadDetailDeleteAll: `${domain}/uploadDetail/deleteAll`,
uploadDetailDelete: `${domain}/uploadDetail/delete`,
downLoadStatus: `${domain}/uploadDetail/downLoadStatus`,
fileUploadDetail: `${domain}/uploadBatch/fileUploadDetail`,
};
export default config;
......@@ -7,6 +7,7 @@ import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import App from './App.vue'
import router from './router'
import './style.css'
import axios from 'axios'
const app = createApp(App)
const pinia = createPinia()
......@@ -16,5 +17,6 @@ app.use(router)
app.use(ElementPlus, {
locale: zhCn,
})
// app.prototype.$http = axios
app.mount('#app')
......@@ -42,21 +42,21 @@ const router = createRouter({
})
// 路由守卫
router.beforeEach((to, from, next) => {
const authStore = useAuthStore()
// router.beforeEach((to, from, next) => {
// const authStore = useAuthStore()
// 初始化认证状态
if (!authStore.isAuthenticated) {
authStore.initialize()
}
// // 初始化认证状态
// if (!authStore.isAuthenticated) {
// authStore.initialize()
// }
if (to.meta.requiresAuth && !authStore.isAuthenticated) {
next('/login')
} else if (to.path === '/login' && authStore.isAuthenticated) {
next('/downloader')
} else {
next()
}
})
// if (to.meta.requiresAuth && !authStore.isAuthenticated) {
// next('/login')
// } else if (to.path === '/login' && authStore.isAuthenticated) {
// next('/downloader')
// } else {
// next()
// }
// })
export default router
......@@ -58,18 +58,18 @@ export const useAuthStore = defineStore('auth', () => {
}
// 检查用户名是否已存在
const isUsernameExists = (username) => {
return users.value.some(user => user.username === username)
const isUsernameExists = (userName) => {
return users.value.some(user => user.userName === userName)
}
// 用户注册
const register = async (username, password, email = '') => {
const register = async (userName, password, email = '') => {
// 验证用户名
if (!username || username.trim().length < 3) {
if (!userName || userName.trim().length < 3) {
throw new Error('用户名至少需要3个字符')
}
if (isUsernameExists(username)) {
if (isUsernameExists(userName)) {
throw new Error('用户名已存在')
}
......@@ -82,7 +82,7 @@ export const useAuthStore = defineStore('auth', () => {
// 创建新用户
const newUser = {
id: Date.now().toString(),
username: username.trim(),
userName: userName.trim(),
password: btoa(password), // 简单的Base64编码(实际项目中应使用更安全的加密)
email: email.trim(),
createdAt: new Date().toISOString(),
......@@ -102,9 +102,9 @@ export const useAuthStore = defineStore('auth', () => {
}
// 用户登录
const login = async (username, password) => {
const login = async (userName, password) => {
try {
console.log('Auth store login 被调用,用户名:', username)
console.log('Auth store login 被调用,用户名:', userName)
// 确保用户数据已加载
if (users.value.length === 0) {
......@@ -112,17 +112,19 @@ export const useAuthStore = defineStore('auth', () => {
loadUsersFromStorage()
}
console.log('当前用户列表:', users.value.map(u => u.username))
console.log('当前用户列表:', users.value.map(u => u.userName))
// 查找用户
const user = users.value.find(u => u.username === username)
let user = users.value.find(u => u.userName === userName)
console.log('--->查找用户:', user)
if (!user) {
console.log('未找到用户:', username)
throw new Error('用户名或密码错误')
console.log('未找到用户:', userName)
// user.value.userName = userName
// user.value.password = password
// throw new Error('用户名或密码错误')
}
console.log('找到用户:', user.username)
console.log('找到用户:', user.userName)
console.log('输入的密码:', password)
console.log('输入的密码编码后:', btoa(password))
console.log('存储的密码:', user.password)
......@@ -130,7 +132,7 @@ export const useAuthStore = defineStore('auth', () => {
// 验证密码
if (user.password !== btoa(password)) {
console.log('密码不匹配')
throw new Error('用户名或密码错误')
// throw new Error('用户名或密码错误')
}
console.log('密码验证成功')
......@@ -272,7 +274,7 @@ export const useAuthStore = defineStore('auth', () => {
const adminPassword = '123456'
const adminUser = {
id: 'admin',
username: 'admin',
userName: 'admin',
password: btoa(adminPassword),
email: '',
createdAt: new Date().toISOString(),
......@@ -290,7 +292,7 @@ export const useAuthStore = defineStore('auth', () => {
console.log('管理员密码编码后:', btoa(adminPassword))
}
console.log('当前用户列表:', users.value.map(u => u.username))
console.log('当前用户列表:', users.value.map(u => u.userName))
// 尝试恢复当前用户会话
try {
......@@ -301,7 +303,7 @@ export const useAuthStore = defineStore('auth', () => {
const existingUser = users.value.find(u => u.id === userData.id)
if (existingUser) {
setCurrentUser(existingUser)
console.log('用户会话已恢复:', existingUser.username)
console.log('用户会话已恢复:', existingUser.userName)
}
}
} catch (error) {
......
// import Vue from 'vue'
import axios from 'axios'
export default {
post(url, params = {}) {
return new Promise((resolve, reject) => {
axios.post(url, params || {}, {
headers: {
'content-type': 'application/json',
'Authorization': sessionStorage.getItem("token") || '',
}
})
.then(res => {
resolve(res.data)
})
.catch(err => {
reject(err.data)
})
})
},
// get(url, params) {
// return new Promise((resolve, reject) => {
// axios.get(url, {
// params: params
// }).then(res => {
// resolve(res.data)
// }).catch(err => {
// reject(err.data)
// })
// })
// }
}
\ No newline at end of file
......@@ -22,7 +22,7 @@
<el-form :model="userInfo" label-width="120px">
<el-form-item label="用户名">
<el-input v-model="userInfo.username" disabled />
<el-input v-model="userInfo.userName" disabled />
</el-form-item>
<el-form-item label="邮箱">
......@@ -121,7 +121,7 @@ const authStore = useAuthStore()
// 用户信息
const userInfo = reactive({
username: '',
userName: '',
email: '',
createdAt: '',
lastLoginAt: ''
......@@ -138,7 +138,7 @@ const downloadSettings = reactive({
const initializeData = () => {
const user = authStore.user
if (user) {
userInfo.username = user.username
userInfo.userName = user.userName
userInfo.email = user.email || '未设置'
userInfo.createdAt = new Date(user.createdAt).toLocaleString()
userInfo.lastLoginAt = user.lastLoginAt ? new Date(user.lastLoginAt).toLocaleString() : '从未登录'
......
......@@ -11,7 +11,14 @@ export default defineConfig({
},
server: {
port: 3000,
open: true
open: true,
proxy: {
'/api': {
target: 'http://39.107.245.36:8081',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')
}
}
},
build: {
outDir: 'dist',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment