From a669588ec5a31c0af8b276989ad4cab07487cd6a Mon Sep 17 00:00:00 2001 From: lihuilin Date: Thu, 3 Jul 2025 11:55:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/request.js | 2 +- src/views/login.vue | 22 ++++++++++------------ src/views/workspace/index.vue | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/util/request.js b/src/util/request.js index 541b9f3..ed1eebf 100644 --- a/src/util/request.js +++ b/src/util/request.js @@ -19,7 +19,7 @@ service.interceptors.request.use(config => { } else { config.data = { token }; } - // config.headers.Authorization = `${token}` + config.headers.token = `${token}` } return config }, error => { diff --git a/src/views/login.vue b/src/views/login.vue index f6ed862..04a0a55 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -6,27 +6,25 @@ import request from '@/util/http' import { useRouter } from 'vue-router' import { VscGlobe } from 'vue-icons-plus/vsc' +const router = useRouter() // 获取路由实例 //获取当前浏览器地址 var url = window.location.href //上传服务器时打开注释并注释掉下一行 -var machineId = null +var machineId1 = ref(null) // 获取machineId function getMachineId() { var parts = url.split('machineId=') if (parts.length > 1) { - machineId = parts[1].split('&')[0] // 进一步截取 & 之前的字符串 + machineId1 = parts[1].split('&')[0] // 进一步截取 & 之前的字符串 } - // machineId = decodeURIComponent(machineId); //如果machineId需要前端转码可以打开注释 - console.log('机器码获取到了吗:', machineId) - if (machineId) { + // machineId1 = decodeURIComponent(machineId1); //如果machineId需要前端转码可以打开注释 + console.log('机器码获取到了吗:', machineId1) + form.value.machineId = machineId1 + if (machineId1) { // 将 machineId 存储到本地存储中 - localStorage.setItem('machineId', machineId) + localStorage.setItem('machineId', machineId1) } } - -const router = useRouter() // 获取路由实例 -let formData = new FormData() - -const form = ref({ account: '', password: '', token: '', machineId: machineId }) +const form = ref({ account: '', password: '', token: '', machineId: machineId1.value }) //调用方法 const login = async function () { try { @@ -34,7 +32,7 @@ const login = async function () { url: '/admin/login', data: form.value }) - console.log('看看传给后端的参数', form) + console.log('看看传给后端的参数', form.value) if (result.code == 200) { localStorage.setItem('token', result.msg) // localStorage.setItem('permission', result.data.permission) diff --git a/src/views/workspace/index.vue b/src/views/workspace/index.vue index 55e378c..9423cd7 100644 --- a/src/views/workspace/index.vue +++ b/src/views/workspace/index.vue @@ -145,7 +145,8 @@ const selectedType = ref('all') const tableData = ref([]) const chartRef = ref(null) let chartInstance = null - +// 用户信息 +const adminData = ref({}) // 卡片数据相关 const currentGold = ref(0) const dailyChange = ref(0) @@ -507,7 +508,15 @@ const handleDateRangeChange = () => { timeRange.value = 'custom' loadChart() } - +const getAdminData = async function () { + try { + const result = await API({ url: '/admin/userinfo', data: {} }) + adminData.value = result + console.log('用户信息', adminData.value) + } catch (error) { + console.log('请求失败', error) + } +} // 加载图表数据 const loadChart = () => { getChartData() @@ -530,6 +539,7 @@ const getCardData = async () => { } onMounted(async () => { + await getAdminData() await getCardData() await getMarkets() handleTimeRangeChange() // 初始化时间范围