diff --git a/activitylink/src/api/manage/login.js b/activitylink/src/api/manage/login.js index 8173ccd..ac3f391 100644 --- a/activitylink/src/api/manage/login.js +++ b/activitylink/src/api/manage/login.js @@ -12,4 +12,12 @@ export function adminlogin(data) { method: 'post', data }) +} + +export function adminlogout(data) { + return request({ + url: '/admin/user/logout', // 替换为你的实际接口地址 + method: 'post', + data + }) } \ No newline at end of file diff --git a/activitylink/src/utils/auth.js b/activitylink/src/utils/auth.js new file mode 100644 index 0000000..d582848 --- /dev/null +++ b/activitylink/src/utils/auth.js @@ -0,0 +1,13 @@ +const TOKEN_KEY = 'token' + +export function setToken(token) { + localStorage.setItem(TOKEN_KEY, token) +} + +export function getToken() { + return localStorage.getItem(TOKEN_KEY) +} + +export function removeToken() { + localStorage.removeItem(TOKEN_KEY) +} \ No newline at end of file diff --git a/activitylink/src/utils/request.js b/activitylink/src/utils/request.js index c0fa594..78b95ee 100644 --- a/activitylink/src/utils/request.js +++ b/activitylink/src/utils/request.js @@ -1,22 +1,29 @@ import axios from 'axios' import { ElMessage } from 'element-plus' - +import { getToken } from '@/utils/auth' // 创建基础实例 const service = axios.create({ baseURL: import.meta.env.VITE_APP_BASE_API, timeout: 10000 }) -// 请求拦截器(简化版) -service.interceptors.request.use(config => { - // 添加token逻辑(如果存在) - const token = localStorage.getItem('token') - if (token) { - config.headers['Authorization'] = 'Bearer ' + token +// 请求拦截器 +service.interceptors.request.use( + (config) => { + const token = getToken() + if (token) { + // 在请求头中添加 token,通常为 Bearer 模式 + config.headers['token'] = `${token}` + } + return config + }, + (error) => { + // 请求错误处理 + console.error('请求错误:', error) + return Promise.reject(error) } - return config -}) +) // 响应拦截器(简化版) service.interceptors.response.use( diff --git a/activitylink/src/views/homePage.vue b/activitylink/src/views/homePage.vue index 1724649..68a0a80 100644 --- a/activitylink/src/views/homePage.vue +++ b/activitylink/src/views/homePage.vue @@ -24,6 +24,7 @@ import { ref } from "vue"; import { useRouter } from "vue-router"; import { ElMessage } from 'element-plus' import { adminlogin } from '@/api/manage/login' +// import { setToken } from '@/api/utils/auth' const router = useRouter(); const username = ref(""); const password = ref(""); @@ -37,7 +38,7 @@ const loginHandler = async () => { // router.push('/zhongchou/mainimg') if (response.code === 200 ) { const token = response.data.token - // console.log(token) + console.log(token) localStorage.setItem('token', token) ElMessage.success('登录成功,欢迎您使用本系统') router.push('/zhongchou/mainimg') diff --git a/activitylink/src/views/zhongchou/activity/detail/index.vue b/activitylink/src/views/zhongchou/activity/detail/index.vue index c740a70..d69669e 100644 --- a/activitylink/src/views/zhongchou/activity/detail/index.vue +++ b/activitylink/src/views/zhongchou/activity/detail/index.vue @@ -49,7 +49,7 @@ - + @@ -88,6 +88,10 @@ const marketOneLabel = ref('') const marketTwoLabel = ref('') const marketList = ref([]) +const formatJoinTime = (row, column, cellValue) => { + if (!cellValue) return '--' + return cellValue.replace('T', ' ') +} // 获取市场列表 const fetchMarketList = async () => { try { diff --git a/activitylink/src/views/zhongchou/index.vue b/activitylink/src/views/zhongchou/index.vue index bde9f5c..c58431f 100644 --- a/activitylink/src/views/zhongchou/index.vue +++ b/activitylink/src/views/zhongchou/index.vue @@ -10,6 +10,7 @@ import { HelpFilled } from '@element-plus/icons-vue' import { ElMessageBox, ElMessage } from 'element-plus'; +import { adminlogout } from '@/api/manage/login' import { useRouter } from 'vue-router' const router = useRouter() const handleOpen = (key, keyPath) => { @@ -26,10 +27,24 @@ const handleLogout = () => { type: 'warning' }).then(() => { // 点击确定,跳转到登录页 - router.push('/homePage'); + const response = adminlogout( + { + token: localStorage.getItem('token') + } + ) + if(response.code === 200) + { + router.push('/homePage'); + localStorage.removeItem('token'); + ElMessage.success('退出成功') + } + else { + ElMessage.error('退出失败') + } }).catch(() => { // 点击取消,不做任何操作 ElMessage.info('已取消退出'); + router.back(); }); }; @@ -80,7 +95,7 @@ const handleLogout = () => { 用户管理 - + 退出登录 diff --git a/activitylink/src/views/zhongchou/user/index.vue b/activitylink/src/views/zhongchou/user/index.vue index 915b144..46a2857 100644 --- a/activitylink/src/views/zhongchou/user/index.vue +++ b/activitylink/src/views/zhongchou/user/index.vue @@ -11,7 +11,7 @@ @@ -33,9 +33,25 @@ + + + + + + + 您确定删除该用户吗? + + + + + + + + + + + + + + + @@ -68,12 +110,89 @@ username: "", jwcode: "" }) - - + const addForm = ref( + { + username: '', + jwcode: '', + } + ); + const deleteConfirmVisible = ref(false) // 表格数据 const tableData = ref([]) const total = ref(0) + const centerDialogVisible = ref(false); + const addusershow = () => { + centerDialogVisible.value = true; +}; + +// 根据什么删除在定 +const openDeleteDialog = (row) => { + // activityToDelete.value = row.id + deleteConfirmVisible.value = true +} +// 确定删除 +const confirmDelete = async () => { + // if (!activityToDelete.value) { + // ElMessage.warning('未获取到活动ID') + // return + // } + + // try { + // const response = await deleteActivityById({activityId: activityToDelete.value}) + + // if (response.code === 200) { + // ElMessage.success('活动删除成功') + // fetchActivityList() // 刷新活动列表 + // } else { + // ElMessage.error(response.message || '删除失败') + // } + // } catch (error) { + // console.error('删除活动失败:', error) + // ElMessage.error('请求失败,请重试') + // } finally { + // deleteConfirmVisible.value = false + // activityToDelete.value = null + // } + console.log("删除用户") + fetchWinList() + deleteConfirmVisible.value = false +} + +const addUser = () => { + console.log("添加用户") + centerDialogVisible.value = false; +}; + + const JwUser = ref({ + username: '', + jwcode: '', + }) + + const validateJwcode = (rule, value, callback) => { + const isNumber = /^\d*$/.test(value); + if (!isNumber) { + callback(new Error('只能输入数字')); + } else { + callback(); + } +}; + + const rules = { + username: [ + { required: true, message: '请输入用户名称', trigger: 'blur' } + ], + jwcode: [ + { required: true, message: '请输入精网号', trigger: 'blur' }, + { validator: validateJwcode, trigger: 'blur' } + ] +} + +// 输入精网号处理 +const handleJwcodeInput = (value) => { + searchParams.value.jwcode = value.replace(/\D/g, '') +} + const handleSizeChange = (val) => { searchParams.value.pageSize = val @@ -85,6 +204,12 @@ searchParams.value.pageNum = val fetchWinList() } + + const cancel = () => { + centerDialogVisible.value = false; + addForm.value.resetFields(); +}; + // 获取中奖列表 const fetchWinList = async () => { try { @@ -127,7 +252,6 @@ pageNum: 1, pageSize: 10, username: '', - gradeId: '', jwcode: '' } @@ -139,10 +263,6 @@ fetchWinList() } - // 精网号输入处理 - const handleJingwangIdInput = (value) => { - searchParams.value.jwcode = value.replace(/\D/g, '') - } // 页面加载时获取数据 onMounted(() => {