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' ...@@ -7,6 +7,7 @@ import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import App from './App.vue' import App from './App.vue'
import router from './router' import router from './router'
import './style.css' import './style.css'
import axios from 'axios'
const app = createApp(App) const app = createApp(App)
const pinia = createPinia() const pinia = createPinia()
...@@ -16,5 +17,6 @@ app.use(router) ...@@ -16,5 +17,6 @@ app.use(router)
app.use(ElementPlus, { app.use(ElementPlus, {
locale: zhCn, locale: zhCn,
}) })
// app.prototype.$http = axios
app.mount('#app') app.mount('#app')
...@@ -42,21 +42,21 @@ const router = createRouter({ ...@@ -42,21 +42,21 @@ const router = createRouter({
}) })
// 路由守卫 // 路由守卫
router.beforeEach((to, from, next) => { // router.beforeEach((to, from, next) => {
const authStore = useAuthStore() // const authStore = useAuthStore()
// 初始化认证状态 // // 初始化认证状态
if (!authStore.isAuthenticated) { // if (!authStore.isAuthenticated) {
authStore.initialize() // authStore.initialize()
} // }
if (to.meta.requiresAuth && !authStore.isAuthenticated) { // if (to.meta.requiresAuth && !authStore.isAuthenticated) {
next('/login') // next('/login')
} else if (to.path === '/login' && authStore.isAuthenticated) { // } else if (to.path === '/login' && authStore.isAuthenticated) {
next('/downloader') // next('/downloader')
} else { // } else {
next() // next()
} // }
}) // })
export default router export default router
...@@ -58,18 +58,18 @@ export const useAuthStore = defineStore('auth', () => { ...@@ -58,18 +58,18 @@ export const useAuthStore = defineStore('auth', () => {
} }
// 检查用户名是否已存在 // 检查用户名是否已存在
const isUsernameExists = (username) => { const isUsernameExists = (userName) => {
return users.value.some(user => user.username === 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个字符') throw new Error('用户名至少需要3个字符')
} }
if (isUsernameExists(username)) { if (isUsernameExists(userName)) {
throw new Error('用户名已存在') throw new Error('用户名已存在')
} }
...@@ -82,7 +82,7 @@ export const useAuthStore = defineStore('auth', () => { ...@@ -82,7 +82,7 @@ export const useAuthStore = defineStore('auth', () => {
// 创建新用户 // 创建新用户
const newUser = { const newUser = {
id: Date.now().toString(), id: Date.now().toString(),
username: username.trim(), userName: userName.trim(),
password: btoa(password), // 简单的Base64编码(实际项目中应使用更安全的加密) password: btoa(password), // 简单的Base64编码(实际项目中应使用更安全的加密)
email: email.trim(), email: email.trim(),
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
...@@ -102,9 +102,9 @@ export const useAuthStore = defineStore('auth', () => { ...@@ -102,9 +102,9 @@ export const useAuthStore = defineStore('auth', () => {
} }
// 用户登录 // 用户登录
const login = async (username, password) => { const login = async (userName, password) => {
try { try {
console.log('Auth store login 被调用,用户名:', username) console.log('Auth store login 被调用,用户名:', userName)
// 确保用户数据已加载 // 确保用户数据已加载
if (users.value.length === 0) { if (users.value.length === 0) {
...@@ -112,17 +112,19 @@ export const useAuthStore = defineStore('auth', () => { ...@@ -112,17 +112,19 @@ export const useAuthStore = defineStore('auth', () => {
loadUsersFromStorage() 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) { if (!user) {
console.log('未找到用户:', username) console.log('未找到用户:', userName)
throw new Error('用户名或密码错误') // user.value.userName = userName
// user.value.password = password
// throw new Error('用户名或密码错误')
} }
console.log('找到用户:', user.username) console.log('找到用户:', user.userName)
console.log('输入的密码:', password) console.log('输入的密码:', password)
console.log('输入的密码编码后:', btoa(password)) console.log('输入的密码编码后:', btoa(password))
console.log('存储的密码:', user.password) console.log('存储的密码:', user.password)
...@@ -130,7 +132,7 @@ export const useAuthStore = defineStore('auth', () => { ...@@ -130,7 +132,7 @@ export const useAuthStore = defineStore('auth', () => {
// 验证密码 // 验证密码
if (user.password !== btoa(password)) { if (user.password !== btoa(password)) {
console.log('密码不匹配') console.log('密码不匹配')
throw new Error('用户名或密码错误') // throw new Error('用户名或密码错误')
} }
console.log('密码验证成功') console.log('密码验证成功')
...@@ -272,7 +274,7 @@ export const useAuthStore = defineStore('auth', () => { ...@@ -272,7 +274,7 @@ export const useAuthStore = defineStore('auth', () => {
const adminPassword = '123456' const adminPassword = '123456'
const adminUser = { const adminUser = {
id: 'admin', id: 'admin',
username: 'admin', userName: 'admin',
password: btoa(adminPassword), password: btoa(adminPassword),
email: '', email: '',
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
...@@ -290,7 +292,7 @@ export const useAuthStore = defineStore('auth', () => { ...@@ -290,7 +292,7 @@ export const useAuthStore = defineStore('auth', () => {
console.log('管理员密码编码后:', btoa(adminPassword)) console.log('管理员密码编码后:', btoa(adminPassword))
} }
console.log('当前用户列表:', users.value.map(u => u.username)) console.log('当前用户列表:', users.value.map(u => u.userName))
// 尝试恢复当前用户会话 // 尝试恢复当前用户会话
try { try {
...@@ -301,7 +303,7 @@ export const useAuthStore = defineStore('auth', () => { ...@@ -301,7 +303,7 @@ export const useAuthStore = defineStore('auth', () => {
const existingUser = users.value.find(u => u.id === userData.id) const existingUser = users.value.find(u => u.id === userData.id)
if (existingUser) { if (existingUser) {
setCurrentUser(existingUser) setCurrentUser(existingUser)
console.log('用户会话已恢复:', existingUser.username) console.log('用户会话已恢复:', existingUser.userName)
} }
} }
} catch (error) { } 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 @@ ...@@ -22,7 +22,7 @@
<el-form :model="userInfo" label-width="120px"> <el-form :model="userInfo" label-width="120px">
<el-form-item label="用户名"> <el-form-item label="用户名">
<el-input v-model="userInfo.username" disabled /> <el-input v-model="userInfo.userName" disabled />
</el-form-item> </el-form-item>
<el-form-item label="邮箱"> <el-form-item label="邮箱">
...@@ -121,7 +121,7 @@ const authStore = useAuthStore() ...@@ -121,7 +121,7 @@ const authStore = useAuthStore()
// 用户信息 // 用户信息
const userInfo = reactive({ const userInfo = reactive({
username: '', userName: '',
email: '', email: '',
createdAt: '', createdAt: '',
lastLoginAt: '' lastLoginAt: ''
...@@ -138,7 +138,7 @@ const downloadSettings = reactive({ ...@@ -138,7 +138,7 @@ const downloadSettings = reactive({
const initializeData = () => { const initializeData = () => {
const user = authStore.user const user = authStore.user
if (user) { if (user) {
userInfo.username = user.username userInfo.userName = user.userName
userInfo.email = user.email || '未设置' userInfo.email = user.email || '未设置'
userInfo.createdAt = new Date(user.createdAt).toLocaleString() userInfo.createdAt = new Date(user.createdAt).toLocaleString()
userInfo.lastLoginAt = user.lastLoginAt ? new Date(user.lastLoginAt).toLocaleString() : '从未登录' userInfo.lastLoginAt = user.lastLoginAt ? new Date(user.lastLoginAt).toLocaleString() : '从未登录'
......
...@@ -11,7 +11,14 @@ export default defineConfig({ ...@@ -11,7 +11,14 @@ export default defineConfig({
}, },
server: { server: {
port: 3000, port: 3000,
open: true open: true,
proxy: {
'/api': {
target: 'http://39.107.245.36:8081',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')
}
}
}, },
build: { build: {
outDir: 'dist', 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