1
0
mirror of https://github.com/fumiama/paper-manager.git synced 2026-06-08 17:40:23 +08:00

finish filelist analyze

This commit is contained in:
源文雨
2023-03-15 22:36:41 +08:00
parent feca597c14
commit 6c823457b9
6 changed files with 84 additions and 13 deletions

View File

@@ -6,7 +6,7 @@ VITE_PUBLIC_PATH = /
# Cross-domain proxy, you can configure multiple
# Please note that no line breaks
VITE_PROXY = [["/basic-api","http://localhost:3000"],["/upload","http://localhost:3300/upload"]]
VITE_PROXY = [["/basic-api","http://localhost:3000"],["/upload","http://localhost:3000/upload"]]
# VITE_PROXY=[["/api","https://vvbin.cn/test"]]
# Delete console

View File

@@ -3,6 +3,8 @@ import { resultError, resultSuccess, getRequestToken, requestParams } from '../_
const deletedIDs: number[] = []
const analyzingIDs: { id: number; per: number }[] = []
function createFileList() {
const lst: any[] = []
for (let i = 100; i > 0; i--) {
@@ -48,6 +50,21 @@ export default [
if (!token) return resultError('Invalid token')
const id = request.query.id
if (!id || id < 0) return resultError('Invalid id')
let p = 0
analyzingIDs.map((value: { id: number; per: number }, index: number) => {
if (!p && value.id == id) {
value.per += 10
if (value.per >= 100) {
analyzingIDs.splice(index, 1)
p = 100
}
p = value.per
}
})
if (p > 0)
return resultSuccess({
percent: p,
})
return resultSuccess({
percent: 100,
})
@@ -68,4 +85,19 @@ export default [
})
},
},
{
url: '/basic-api/analyzeFile',
timeout: 1000,
method: 'get',
response: (request: requestParams) => {
const token = getRequestToken(request)
if (!token) return resultError('Invalid token')
const id = Number(request.query.id)
if (!id || id < 0) return resultError('Invalid id')
analyzingIDs.push({ id: id, per: 1 })
return resultSuccess({
msg: '正在分析' + id + ', 请耐心等待...',
})
},
},
] as MockMethod[]

View File

@@ -1,10 +1,11 @@
import { defHttp } from '/@/utils/http/axios'
import { getFileListModel, FilePercent, DelFile } from './model/fileListModel'
import { getFileListModel, FilePercent, DelFile, AnalyzeFile } from './model/fileListModel'
enum Api {
GetFileList = '/getFileList',
GetFilePercent = '/getFilePercent',
DelFile = '/delFile',
AnalyzeFile = '/analyzeFile',
}
/**
@@ -22,8 +23,15 @@ export const getFilePercent = (id: number) => {
}
/**
* @description: Get file percant
* @description: Get file percent
*/
export const delFile = (id: number) => {
return defHttp.get<DelFile>({ url: Api.DelFile, params: { id: id } })
}
/**
* @description: Analyze file
*/
export const analyzeFile = (id: number) => {
return defHttp.get<AnalyzeFile>({ url: Api.AnalyzeFile, params: { id: id } })
}

View File

@@ -21,3 +21,7 @@ export interface FilePercent {
export interface DelFile {
msg: string
}
export interface AnalyzeFile {
msg: string
}

View File

@@ -2,15 +2,18 @@ import { reactive } from 'vue'
import { getFileList, getFilePercent } from '/@/api/page'
import { getFileListModel } from '/@/api/page/model/fileListModel'
const random = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1) + min)
export const random = (min: number, max: number) =>
Math.floor(Math.random() * (max - min + 1) + min)
export function refreshFilePercent(arr: any[], i: number) {
export function refreshFilePercent(item: any) {
return async () => {
const p = await getFilePercent(arr[i].id)
arr[i].percent = p.percent
if (p.percent < 100) {
setTimeout(refreshFilePercent(arr, i), 1000)
}
const p = await getFilePercent(item.id)
if (p.percent) {
item.percent = p.percent
if (p.percent < 100) {
setTimeout(refreshFilePercent(item), 1000)
}
} else item.hassettimeout = false
}
}
@@ -22,7 +25,7 @@ export function getListOfPage(pageSize: number, page: number): any[] {
else lst = reactive(cardList._cardList.slice((cardList._cardList.length / pageSize) * pageSize))
for (let i = 0; i < lst.length; i++) {
if (!lst[i].hassettimeout && lst[i].percent > 0 && lst[i].percent < 100) {
setTimeout(refreshFilePercent(lst, i), 1000 + random(0, 1000))
setTimeout(refreshFilePercent(lst[i]), 1000 + random(0, 1000))
lst[i].hassettimeout = true
}
}

View File

@@ -47,6 +47,7 @@
color="warning"
v-if="hasPermission([RoleEnum.SUPER, RoleEnum.FILE_MANAGER])"
:disabled="item.percent != 0"
@click="analyzeFile(item)"
>
解析
</a-button>
@@ -94,7 +95,14 @@
import { defineComponent } from 'vue'
import { Icon } from '/@/components/Icon'
import { BasicUpload } from '/@/components/Upload'
import { cardList, getListOfPage, deleteFileByID, pagination } from './data'
import {
cardList,
getListOfPage,
deleteFileByID,
pagination,
refreshFilePercent,
random,
} from './data'
import { PageWrapper } from '/@/components/Page'
import { useMessage } from '/@/hooks/web/useMessage'
import { usePermission } from '/@/hooks/web/usePermission'
@@ -102,7 +110,7 @@
import { List } from 'ant-design-vue'
import { uploadApi } from '/@/api/sys/upload'
import { useI18n } from '/@/hooks/web/useI18n'
import { delFile } from '/@/api/page'
import { delFile, analyzeFile } from '/@/api/page'
const { t } = useI18n()
const { createMessage } = useMessage()
@@ -126,6 +134,21 @@
}
}
async function analFile(item: any) {
try {
const msg = await analyzeFile(item.id)
if (msg) {
createMessage.success(msg.msg)
if (!item.hassettimeout && item.percent == 0) {
setTimeout(refreshFilePercent(item), 1000 + random(0, 1000))
item.hassettimeout = true
}
}
} catch (error) {
createMessage.error((error as unknown as Error).message)
}
}
export default defineComponent({
components: {
BasicUpload,
@@ -152,6 +175,7 @@
prefixCls: 'list-basic',
getListOfPage,
deleteFile,
analyzeFile: analFile,
cardList,
pagination,
}