- 将原有的axios直接调用替换为统一的api模块封装 - 新增api.ts文件集中管理所有API接口方法 - 删除旧的axios.ts配置文件 - 统一API响应数据结构处理,将result改为data字段 - 优化HomeView中的Token相关状态管理和数据获取逻辑 - 重构TokenDetailView中信息获取和删除操作的API调用 - 更新TokenManageView中Token列表管理的CRUD操作实现 - 简化组件间的数据传递和状态同步机制
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
const axiosInstance = axios.create({
|
||||||
|
baseURL: import.meta.env.VITE_API_BASE_URL,
|
||||||
|
})
|
||||||
|
|
||||||
|
export default {
|
||||||
|
getTokenList: () =>
|
||||||
|
axiosInstance.get('/api/token'),
|
||||||
|
|
||||||
|
createToken: (params: {
|
||||||
|
token: string
|
||||||
|
dedup_object: string
|
||||||
|
data_format: string
|
||||||
|
notes: string
|
||||||
|
}) =>
|
||||||
|
axiosInstance.post('/api/token', {}, {params}),
|
||||||
|
|
||||||
|
updateToken: (params: {
|
||||||
|
token: string
|
||||||
|
dedup_object?: string
|
||||||
|
data_format?: string
|
||||||
|
notes?: string
|
||||||
|
}) =>
|
||||||
|
axiosInstance.put('/api/token', {}, {params}),
|
||||||
|
|
||||||
|
deleteToken: (params: {
|
||||||
|
token: string
|
||||||
|
}) =>
|
||||||
|
axiosInstance.delete('/api/token', {params}),
|
||||||
|
|
||||||
|
getTokenInfo: (params: {
|
||||||
|
token: string
|
||||||
|
}) =>
|
||||||
|
axiosInstance.get('/api/token/info', {params}),
|
||||||
|
|
||||||
|
deleteTokenInfo: (params: {
|
||||||
|
token: string
|
||||||
|
dedup_bf?: string
|
||||||
|
cache_list?: string
|
||||||
|
both_number?: string
|
||||||
|
}) =>
|
||||||
|
axiosInstance.delete('/api/token/info', {params}),
|
||||||
|
|
||||||
|
uploadData: (params: {
|
||||||
|
data: string
|
||||||
|
token: string
|
||||||
|
}) =>
|
||||||
|
axiosInstance.post('/api/data', {}, {params}),
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
const instance = axios.create({
|
|
||||||
baseURL: import.meta.env.VITE_API_BASE_URL,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default instance;
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {computed, ref} from "vue"
|
import {computed, ref} from "vue"
|
||||||
import axios from "@/axios.ts"
|
import api from "@/api"
|
||||||
import {ElMessage} from 'element-plus'
|
import {ElMessage} from 'element-plus'
|
||||||
import {Upload} from '@element-plus/icons-vue'
|
import {Upload} from '@element-plus/icons-vue'
|
||||||
|
|
||||||
@@ -42,12 +42,7 @@ const handleUpload = async () => {
|
|||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
try {
|
try {
|
||||||
await axios.post('/api/data', {}, {
|
await api.uploadData({data: line, token: props.token || ''})
|
||||||
params: {
|
|
||||||
data: line,
|
|
||||||
token: props.token || ''
|
|
||||||
}
|
|
||||||
})
|
|
||||||
uploadedCount.value++
|
uploadedCount.value++
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
ElMessage.error(error.response?.data?.error || '上传失败')
|
ElMessage.error(error.response?.data?.error || '上传失败')
|
||||||
|
|||||||
+21
-15
@@ -1,14 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {onMounted, onUnmounted, ref} from 'vue'
|
import {onMounted, onUnmounted, ref} from 'vue'
|
||||||
import axios from "@/axios.ts"
|
import api from "@/api"
|
||||||
import {useRoute} from "vue-router"
|
import {useRoute} from "vue-router"
|
||||||
import {ElMessage} from "element-plus"
|
import {ElMessage} from "element-plus"
|
||||||
import {DataAnalysis, Document, Key, Search, Upload, Warning} from '@element-plus/icons-vue'
|
import {DataAnalysis, Document, Key, Search, Upload, Warning} from '@element-plus/icons-vue'
|
||||||
import AddDataDialog from "@/components/AddDataDialog.vue";
|
import AddDataDialog from "@/components/AddDataDialog.vue";
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const token = ref(route.query.token as string || '')
|
const inputToken = ref(route.query.token as string || '')
|
||||||
const input = ref(route.query.token as string || '')
|
|
||||||
const result = ref<any>(null)
|
const result = ref<any>(null)
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const lastUpdate = ref('')
|
const lastUpdate = ref('')
|
||||||
@@ -20,34 +19,41 @@ const updateTime = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fetchInfo = async () => {
|
const fetchInfo = async () => {
|
||||||
if (!input.value) return
|
if (!inputToken.value) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await axios.get('/api/token/info', {
|
const res = await api.getTokenInfo({token: inputToken.value})
|
||||||
params: {token: input.value}
|
result.value = res.data.data
|
||||||
})
|
|
||||||
result.value = res.data.result
|
|
||||||
token.value = input.value
|
|
||||||
updateTime()
|
updateTime()
|
||||||
} catch {
|
} catch {
|
||||||
|
result.value = null
|
||||||
ElMessage({message: 'Token输入错误', type: 'error', duration: 2000})
|
ElMessage({message: 'Token输入错误', type: 'error', duration: 2000})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
await fetchInfo()
|
|
||||||
|
try {
|
||||||
|
const res = await api.getTokenInfo({token: inputToken.value})
|
||||||
|
result.value = res.data.data
|
||||||
|
updateTime()
|
||||||
|
ElMessage({message: '查询成功', type: 'success', duration: 1500})
|
||||||
|
} catch {
|
||||||
|
result.value = null
|
||||||
|
ElMessage({message: 'Token输入错误', type: 'error', duration: 2000})
|
||||||
|
}
|
||||||
|
|
||||||
loading.value = false
|
loading.value = false
|
||||||
ElMessage({message: '查询成功', type: 'success', duration: 1500})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputChange = () => {
|
const inputChange = () => {
|
||||||
if (input.value) fetchInfo()
|
if (inputToken.value) fetchInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
let timer: number
|
let timer: number
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (token.value) fetchInfo()
|
fetchInfo()
|
||||||
timer = window.setInterval(fetchInfo, 5000)
|
timer = window.setInterval(fetchInfo, 5000)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -73,7 +79,7 @@ const statCards = [
|
|||||||
|
|
||||||
<div class="search-box">
|
<div class="search-box">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="input"
|
v-model="inputToken"
|
||||||
placeholder="输入 Token"
|
placeholder="输入 Token"
|
||||||
clearable
|
clearable
|
||||||
size="large"
|
size="large"
|
||||||
@@ -99,7 +105,7 @@ const statCards = [
|
|||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AddDataDialog v-model="showAddDataDialog" :token="token"/>
|
<AddDataDialog v-model="showAddDataDialog" :token="inputToken"/>
|
||||||
|
|
||||||
<div v-if="result" class="result-section">
|
<div v-if="result" class="result-section">
|
||||||
<div class="result-header">
|
<div class="result-header">
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {onMounted, onUnmounted, ref, watch} from 'vue'
|
import {onMounted, onUnmounted, ref, watch} from 'vue'
|
||||||
import {useCounterStore} from "@/stores/counter.ts"
|
import {useCounterStore} from "@/stores/counter.ts"
|
||||||
import axios from "@/axios.ts"
|
import api from "@/api"
|
||||||
import {ElMessage, ElMessageBox} from 'element-plus'
|
import {ElMessage, ElMessageBox} from 'element-plus'
|
||||||
import {DataAnalysis, Delete, Document, InfoFilled, Key, Refresh, Search, Warning} from '@element-plus/icons-vue'
|
import {DataAnalysis, Delete, Document, InfoFilled, Key, Refresh, Search, Warning} from '@element-plus/icons-vue'
|
||||||
|
|
||||||
@@ -23,22 +23,18 @@ const isLoading = ref(false)
|
|||||||
const fetchInfo = async () => {
|
const fetchInfo = async () => {
|
||||||
if (!value.value) return
|
if (!value.value) return
|
||||||
|
|
||||||
const res = await axios.get('/api/token/info', {
|
const res = await api.getTokenInfo({token: value.value})
|
||||||
params: {
|
|
||||||
token: value.value
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
result.value = res.data.result
|
result.value = res.data.data
|
||||||
lastUpdate.value = new Date().toLocaleTimeString()
|
lastUpdate.value = new Date().toLocaleTimeString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchTokens = async () => {
|
const fetchTokens = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.get('/api/token')
|
const res = await api.getTokenList()
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
options.value = res.data.result?.map((item: any) => item.token) || []
|
options.value = res.data.data?.map((item: any) => item.token) || []
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch tokens:', error)
|
console.error('Failed to fetch tokens:', error)
|
||||||
@@ -58,12 +54,7 @@ const deleteDedup = () => {
|
|||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
}).then(async () => {
|
}).then(async () => {
|
||||||
await axios.delete('/api/token/info', {
|
await api.deleteTokenInfo({token: value.value, dedup_bf: "all"})
|
||||||
params: {
|
|
||||||
token: value.value,
|
|
||||||
dedup_bf: "all"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
ElMessage({message: '删除成功', type: 'success'})
|
ElMessage({message: '删除成功', type: 'success'})
|
||||||
await fetchInfo()
|
await fetchInfo()
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
@@ -76,12 +67,7 @@ const deleteRedis = () => {
|
|||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
}).then(async () => {
|
}).then(async () => {
|
||||||
await axios.delete('/api/token/info', {
|
await api.deleteTokenInfo({token: value.value, cache_list: "all"})
|
||||||
params: {
|
|
||||||
token: value.value,
|
|
||||||
cache_list: "all"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
ElMessage({message: '删除成功', type: 'success'})
|
ElMessage({message: '删除成功', type: 'success'})
|
||||||
await fetchInfo()
|
await fetchInfo()
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
@@ -91,12 +77,7 @@ const deleteRedis = () => {
|
|||||||
const deleteSpecifyDedup = async () => {
|
const deleteSpecifyDedup = async () => {
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
|
|
||||||
await axios.delete('/api/token/info', {
|
await api.deleteTokenInfo({token: value.value, dedup_bf: inputSpecifyDedup.value})
|
||||||
params: {
|
|
||||||
token: value.value,
|
|
||||||
dedup_bf: inputSpecifyDedup.value
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
ElMessage({message: '删除成功', type: 'success'})
|
ElMessage({message: '删除成功', type: 'success'})
|
||||||
@@ -109,12 +90,7 @@ const deleteSpecifyDedup = async () => {
|
|||||||
const deleteSpecifyRaw = async () => {
|
const deleteSpecifyRaw = async () => {
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
|
|
||||||
await axios.delete('/api/token/info', {
|
await api.deleteTokenInfo({token: value.value, cache_list: inputSpecifyRaw.value})
|
||||||
params: {
|
|
||||||
token: value.value,
|
|
||||||
cache_list: inputSpecifyRaw.value
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
ElMessage({message: '删除成功', type: 'success'})
|
ElMessage({message: '删除成功', type: 'success'})
|
||||||
@@ -127,12 +103,7 @@ const deleteSpecifyRaw = async () => {
|
|||||||
const deleteSpecifyData = async () => {
|
const deleteSpecifyData = async () => {
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
|
|
||||||
await axios.delete('/api/token/info', {
|
await api.deleteTokenInfo({token: value.value, both_number: inputSpecifyData.value})
|
||||||
params: {
|
|
||||||
token: value.value,
|
|
||||||
both_number: inputSpecifyData.value
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
ElMessage({message: '删除成功', type: 'success'})
|
ElMessage({message: '删除成功', type: 'success'})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {onMounted, ref} from "vue"
|
import {onMounted, ref} from "vue"
|
||||||
import axios from "@/axios.ts"
|
import api from "@/api"
|
||||||
import {ElMessage} from 'element-plus'
|
import {ElMessage} from 'element-plus'
|
||||||
import {useCounterStore} from "@/stores/counter.ts"
|
import {useCounterStore} from "@/stores/counter.ts"
|
||||||
import {useRouter} from "vue-router"
|
import {useRouter} from "vue-router"
|
||||||
@@ -42,8 +42,8 @@ const dataFormatOptions = [
|
|||||||
const fetchTokens = async () => {
|
const fetchTokens = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await axios.get("/api/token")
|
const res = await api.getTokenList()
|
||||||
tableData.value = res.data.result || []
|
tableData.value = res.data.data || []
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
@@ -74,13 +74,11 @@ const addToken = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await axios.post('/api/token', {}, {
|
await api.createToken({
|
||||||
params: {
|
token: input.value,
|
||||||
token: input.value,
|
dedup_object: value.value,
|
||||||
dedup_object: value.value,
|
data_format: dataFormat.value,
|
||||||
data_format: dataFormat.value,
|
notes: inputNotes.value,
|
||||||
notes: inputNotes.value,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
ElMessage({message: '添加成功', type: 'success'})
|
ElMessage({message: '添加成功', type: 'success'})
|
||||||
input.value = ''
|
input.value = ''
|
||||||
@@ -123,13 +121,11 @@ const dialogDataADDVisible = (row: any) => {
|
|||||||
|
|
||||||
const updateDedupObject = async () => {
|
const updateDedupObject = async () => {
|
||||||
try {
|
try {
|
||||||
await axios.put('/api/token', {}, {
|
await api.updateToken({
|
||||||
params: {
|
token: rowOut.value.token,
|
||||||
token: rowOut.value.token,
|
dedup_object: value.value,
|
||||||
dedup_object: value.value,
|
data_format: rowOut.value.data_format,
|
||||||
data_format: rowOut.value.data_format,
|
notes: rowOut.value.notes,
|
||||||
notes: rowOut.value.notes,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
ElMessage({message: '更新成功', type: 'success'})
|
ElMessage({message: '更新成功', type: 'success'})
|
||||||
dedupObjectVisible.value = false
|
dedupObjectVisible.value = false
|
||||||
@@ -141,13 +137,11 @@ const updateDedupObject = async () => {
|
|||||||
|
|
||||||
const updateDataFormat = async () => {
|
const updateDataFormat = async () => {
|
||||||
try {
|
try {
|
||||||
await axios.put('/api/token', {}, {
|
await api.updateToken({
|
||||||
params: {
|
token: rowOut.value.token,
|
||||||
token: rowOut.value.token,
|
dedup_object: rowOut.value.dedup_object,
|
||||||
dedup_object: rowOut.value.dedup_object,
|
data_format: dataFormat.value,
|
||||||
data_format: dataFormat.value,
|
notes: rowOut.value.notes,
|
||||||
notes: rowOut.value.notes,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
ElMessage({message: '更新成功', type: 'success'})
|
ElMessage({message: '更新成功', type: 'success'})
|
||||||
dataFormatVisible.value = false
|
dataFormatVisible.value = false
|
||||||
@@ -159,13 +153,11 @@ const updateDataFormat = async () => {
|
|||||||
|
|
||||||
const updateNotes = async () => {
|
const updateNotes = async () => {
|
||||||
try {
|
try {
|
||||||
await axios.put('/api/token', {}, {
|
await api.updateToken({
|
||||||
params: {
|
token: rowOut.value.token,
|
||||||
token: rowOut.value.token,
|
dedup_object: rowOut.value.dedup_object,
|
||||||
dedup_object: rowOut.value.dedup_object,
|
data_format: rowOut.value.data_format,
|
||||||
data_format: rowOut.value.data_format,
|
notes: inputNotes.value,
|
||||||
notes: inputNotes.value
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
ElMessage({message: '更新成功', type: 'success'})
|
ElMessage({message: '更新成功', type: 'success'})
|
||||||
inputNotesVisible.value = false
|
inputNotesVisible.value = false
|
||||||
@@ -177,9 +169,7 @@ const updateNotes = async () => {
|
|||||||
|
|
||||||
const deleteToken = async (row: any) => {
|
const deleteToken = async (row: any) => {
|
||||||
try {
|
try {
|
||||||
await axios.delete('/api/token', {
|
await api.deleteToken({token: row.token})
|
||||||
params: {token: row.token}
|
|
||||||
})
|
|
||||||
ElMessage({message: '删除成功', type: 'success'})
|
ElMessage({message: '删除成功', type: 'success'})
|
||||||
fetchTokens()
|
fetchTokens()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
Reference in New Issue
Block a user