A:增加并验证“资料库”删除和修改
This commit is contained in:
1 parent
b1ee8d916a
commit
e1227343e9
3 files changed
+48
-34
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
export type LibraryTable = {
|
||||||
|
created_at: string
|
||||||
|
id: number
|
||||||
|
img_path: string
|
||||||
|
is_enable: boolean
|
||||||
|
updated_at: string
|
||||||
|
}
|
||||||
@@ -72,7 +72,16 @@ class HttpClient {
|
|||||||
// 请求拦截器
|
// 请求拦截器
|
||||||
this.axiosInstance.interceptors.request.use(
|
this.axiosInstance.interceptors.request.use(
|
||||||
(config: InternalAxiosRequestConfig) => {
|
(config: InternalAxiosRequestConfig) => {
|
||||||
console.group("请求链接: "+config.url);
|
console.group(
|
||||||
|
'请求链接: ' +
|
||||||
|
config.url +
|
||||||
|
' ' +
|
||||||
|
config.method?.toUpperCase() +
|
||||||
|
' params: ' +
|
||||||
|
JSON.stringify(config.params) +
|
||||||
|
', data: ' +
|
||||||
|
JSON.stringify(config.data),
|
||||||
|
)
|
||||||
// 防止重复请求
|
// 防止重复请求
|
||||||
this.addPending(config)
|
this.addPending(config)
|
||||||
|
|
||||||
@@ -109,7 +118,7 @@ class HttpClient {
|
|||||||
// 统一处理响应数据
|
// 统一处理响应数据
|
||||||
const { data } = response
|
const { data } = response
|
||||||
|
|
||||||
console.groupEnd();
|
console.groupEnd()
|
||||||
if (data.success || data.code === 200) {
|
if (data.success || data.code === 200) {
|
||||||
return response
|
return response
|
||||||
} else {
|
} else {
|
||||||
@@ -125,7 +134,7 @@ class HttpClient {
|
|||||||
|
|
||||||
// 统一错误处理
|
// 统一错误处理
|
||||||
this.handleError(error)
|
this.handleError(error)
|
||||||
console.groupEnd();
|
console.groupEnd()
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
import { httpClient } from '@/utils/http.ts'
|
import { httpClient } from '@/utils/http.ts'
|
||||||
import { CloseOutline, FolderOutline, CheckmarkCircle, EllipseOutline } from '@vicons/ionicons5'
|
import { CloseOutline, FolderOutline, CheckmarkCircle, EllipseOutline } from '@vicons/ionicons5'
|
||||||
import { onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import { NSpace, NInput, NButton, NIcon, NTag, NCard, NEmpty, useMessage } from 'naive-ui'
|
import { NSpace, NInput, NButton, NIcon, NTag, NCard, NEmpty, useMessage } from 'naive-ui'
|
||||||
|
import type { LibraryTable } from '@/model/libraryTable.ts'
|
||||||
|
|
||||||
// 消息提示
|
// 消息提示
|
||||||
const message = useMessage()
|
const message = useMessage()
|
||||||
@@ -17,10 +18,7 @@ interface LibraryPath {
|
|||||||
enabled: boolean
|
enabled: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const libraryPaths = ref<LibraryPath[]>([
|
const libraryPaths = ref<LibraryPath[]>([])
|
||||||
{ id: '1', path: 'C:\\Users\\Documents\\教师资料', enabled: true },
|
|
||||||
{ id: '2', path: 'D:\\程序员学习资料', enabled: true }
|
|
||||||
])
|
|
||||||
|
|
||||||
// 选择文件夹
|
// 选择文件夹
|
||||||
const selectFolder = async () => {
|
const selectFolder = async () => {
|
||||||
@@ -48,7 +46,7 @@ const addPath = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否已存在
|
// 检查是否已存在
|
||||||
if (libraryPaths.value.some(item => item.path === inputPath.value)) {
|
if (libraryPaths.value.some((item) => item.path === inputPath.value)) {
|
||||||
message.warning('该路径已存在')
|
message.warning('该路径已存在')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -56,14 +54,14 @@ const addPath = async () => {
|
|||||||
try {
|
try {
|
||||||
// 发送到后端
|
// 发送到后端
|
||||||
const response = await httpClient.post('/v1/library', {
|
const response = await httpClient.post('/v1/library', {
|
||||||
path: inputPath.value
|
path: inputPath.value,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 添加到列表
|
// 添加到列表
|
||||||
libraryPaths.value.push({
|
libraryPaths.value.push({
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
path: inputPath.value,
|
path: inputPath.value,
|
||||||
enabled: true
|
enabled: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 清空输入
|
// 清空输入
|
||||||
@@ -80,8 +78,9 @@ const toggleEnabled = async (item: LibraryPath) => {
|
|||||||
item.enabled = !item.enabled
|
item.enabled = !item.enabled
|
||||||
|
|
||||||
// 发送到后端
|
// 发送到后端
|
||||||
await httpClient.put(`/api/library/${item.id}`, {
|
await httpClient.put(`/v1/library`, {
|
||||||
enabled: item.enabled
|
path: encodeURIComponent(item.path),
|
||||||
|
enabled: item.enabled,
|
||||||
})
|
})
|
||||||
|
|
||||||
message.success(item.enabled ? '已启用' : '已禁用')
|
message.success(item.enabled ? '已启用' : '已禁用')
|
||||||
@@ -95,11 +94,14 @@ const toggleEnabled = async (item: LibraryPath) => {
|
|||||||
// 删除路径
|
// 删除路径
|
||||||
const removePath = async (item: LibraryPath) => {
|
const removePath = async (item: LibraryPath) => {
|
||||||
try {
|
try {
|
||||||
|
console.log(item.path)
|
||||||
// 发送到后端
|
// 发送到后端
|
||||||
await httpClient.delete(`/api/library/${item.id}`)
|
await httpClient.delete(`/v1/library`, {
|
||||||
|
path: encodeURIComponent(item.path),
|
||||||
|
})
|
||||||
|
|
||||||
// 从列表中移除
|
// 从列表中移除
|
||||||
const index = libraryPaths.value.findIndex(p => p.id === item.id)
|
const index = libraryPaths.value.findIndex((p) => p.id === item.id)
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
libraryPaths.value.splice(index, 1)
|
libraryPaths.value.splice(index, 1)
|
||||||
}
|
}
|
||||||
@@ -112,8 +114,9 @@ const removePath = async (item: LibraryPath) => {
|
|||||||
|
|
||||||
// 开始任务
|
// 开始任务
|
||||||
const startTask = async () => {
|
const startTask = async () => {
|
||||||
const enabledPaths = libraryPaths.value.filter(item => item.enabled)
|
const enabledPaths = libraryPaths.value.filter((item) => item.enabled)
|
||||||
|
message.error('创建任务失败')
|
||||||
|
return
|
||||||
if (enabledPaths.length === 0) {
|
if (enabledPaths.length === 0) {
|
||||||
message.warning('请至少选择一个启用的路径')
|
message.warning('请至少选择一个启用的路径')
|
||||||
return
|
return
|
||||||
@@ -121,7 +124,7 @@ const startTask = async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await httpClient.post('/api/task/create', {
|
const response = await httpClient.post('/api/task/create', {
|
||||||
paths: enabledPaths.map(item => item.path)
|
paths: enabledPaths.map((item) => item.path),
|
||||||
})
|
})
|
||||||
|
|
||||||
message.success('任务已创建,正在处理中...')
|
message.success('任务已创建,正在处理中...')
|
||||||
@@ -131,8 +134,15 @@ const startTask = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
httpClient.get("v1/library").then((res) => {
|
httpClient.get('v1/library').then((res) => {
|
||||||
console.log(res);
|
const data = res.data as LibraryTable[]
|
||||||
|
data.forEach((item) => {
|
||||||
|
libraryPaths.value.push({
|
||||||
|
id: item.id.toString(),
|
||||||
|
path: item.img_path,
|
||||||
|
enabled: item.is_enable,
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -153,22 +163,10 @@ onMounted(() => {
|
|||||||
<n-icon :component="FolderOutline" />
|
<n-icon :component="FolderOutline" />
|
||||||
</template>
|
</template>
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
<n-button
|
<n-button type="tertiary" size="small" @click="selectFolder"> 选择文件夹</n-button>
|
||||||
type="tertiary"
|
|
||||||
size="small"
|
|
||||||
@click="selectFolder"
|
|
||||||
>
|
|
||||||
选择文件夹
|
|
||||||
</n-button>
|
|
||||||
</template>
|
</template>
|
||||||
</n-input>
|
</n-input>
|
||||||
<n-button
|
<n-button type="primary" size="large" @click="addPath"> 添加</n-button>
|
||||||
type="primary"
|
|
||||||
size="large"
|
|
||||||
@click="addPath"
|
|
||||||
>
|
|
||||||
添加
|
|
||||||
</n-button>
|
|
||||||
</n-space>
|
</n-space>
|
||||||
</n-card>
|
</n-card>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user