mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-07-02 08:40:26 +08:00
finish filelist analyze
This commit is contained in:
@@ -6,7 +6,7 @@ VITE_PUBLIC_PATH = /
|
|||||||
|
|
||||||
# Cross-domain proxy, you can configure multiple
|
# Cross-domain proxy, you can configure multiple
|
||||||
# Please note that no line breaks
|
# 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"]]
|
# VITE_PROXY=[["/api","https://vvbin.cn/test"]]
|
||||||
|
|
||||||
# Delete console
|
# Delete console
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { resultError, resultSuccess, getRequestToken, requestParams } from '../_
|
|||||||
|
|
||||||
const deletedIDs: number[] = []
|
const deletedIDs: number[] = []
|
||||||
|
|
||||||
|
const analyzingIDs: { id: number; per: number }[] = []
|
||||||
|
|
||||||
function createFileList() {
|
function createFileList() {
|
||||||
const lst: any[] = []
|
const lst: any[] = []
|
||||||
for (let i = 100; i > 0; i--) {
|
for (let i = 100; i > 0; i--) {
|
||||||
@@ -48,6 +50,21 @@ export default [
|
|||||||
if (!token) return resultError('Invalid token')
|
if (!token) return resultError('Invalid token')
|
||||||
const id = request.query.id
|
const id = request.query.id
|
||||||
if (!id || id < 0) return resultError('Invalid 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({
|
return resultSuccess({
|
||||||
percent: 100,
|
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[]
|
] as MockMethod[]
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { defHttp } from '/@/utils/http/axios'
|
import { defHttp } from '/@/utils/http/axios'
|
||||||
import { getFileListModel, FilePercent, DelFile } from './model/fileListModel'
|
import { getFileListModel, FilePercent, DelFile, AnalyzeFile } from './model/fileListModel'
|
||||||
|
|
||||||
enum Api {
|
enum Api {
|
||||||
GetFileList = '/getFileList',
|
GetFileList = '/getFileList',
|
||||||
GetFilePercent = '/getFilePercent',
|
GetFilePercent = '/getFilePercent',
|
||||||
DelFile = '/delFile',
|
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) => {
|
export const delFile = (id: number) => {
|
||||||
return defHttp.get<DelFile>({ url: Api.DelFile, params: { id: id } })
|
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 } })
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,3 +21,7 @@ export interface FilePercent {
|
|||||||
export interface DelFile {
|
export interface DelFile {
|
||||||
msg: string
|
msg: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AnalyzeFile {
|
||||||
|
msg: string
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,15 +2,18 @@ import { reactive } from 'vue'
|
|||||||
import { getFileList, getFilePercent } from '/@/api/page'
|
import { getFileList, getFilePercent } from '/@/api/page'
|
||||||
import { getFileListModel } from '/@/api/page/model/fileListModel'
|
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 () => {
|
return async () => {
|
||||||
const p = await getFilePercent(arr[i].id)
|
const p = await getFilePercent(item.id)
|
||||||
arr[i].percent = p.percent
|
if (p.percent) {
|
||||||
if (p.percent < 100) {
|
item.percent = p.percent
|
||||||
setTimeout(refreshFilePercent(arr, i), 1000)
|
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))
|
else lst = reactive(cardList._cardList.slice((cardList._cardList.length / pageSize) * pageSize))
|
||||||
for (let i = 0; i < lst.length; i++) {
|
for (let i = 0; i < lst.length; i++) {
|
||||||
if (!lst[i].hassettimeout && lst[i].percent > 0 && lst[i].percent < 100) {
|
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
|
lst[i].hassettimeout = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
color="warning"
|
color="warning"
|
||||||
v-if="hasPermission([RoleEnum.SUPER, RoleEnum.FILE_MANAGER])"
|
v-if="hasPermission([RoleEnum.SUPER, RoleEnum.FILE_MANAGER])"
|
||||||
:disabled="item.percent != 0"
|
:disabled="item.percent != 0"
|
||||||
|
@click="analyzeFile(item)"
|
||||||
>
|
>
|
||||||
解析
|
解析
|
||||||
</a-button>
|
</a-button>
|
||||||
@@ -94,7 +95,14 @@
|
|||||||
import { defineComponent } from 'vue'
|
import { defineComponent } from 'vue'
|
||||||
import { Icon } from '/@/components/Icon'
|
import { Icon } from '/@/components/Icon'
|
||||||
import { BasicUpload } from '/@/components/Upload'
|
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 { PageWrapper } from '/@/components/Page'
|
||||||
import { useMessage } from '/@/hooks/web/useMessage'
|
import { useMessage } from '/@/hooks/web/useMessage'
|
||||||
import { usePermission } from '/@/hooks/web/usePermission'
|
import { usePermission } from '/@/hooks/web/usePermission'
|
||||||
@@ -102,7 +110,7 @@
|
|||||||
import { List } from 'ant-design-vue'
|
import { List } from 'ant-design-vue'
|
||||||
import { uploadApi } from '/@/api/sys/upload'
|
import { uploadApi } from '/@/api/sys/upload'
|
||||||
import { useI18n } from '/@/hooks/web/useI18n'
|
import { useI18n } from '/@/hooks/web/useI18n'
|
||||||
import { delFile } from '/@/api/page'
|
import { delFile, analyzeFile } from '/@/api/page'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const { createMessage } = useMessage()
|
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({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
BasicUpload,
|
BasicUpload,
|
||||||
@@ -152,6 +175,7 @@
|
|||||||
prefixCls: 'list-basic',
|
prefixCls: 'list-basic',
|
||||||
getListOfPage,
|
getListOfPage,
|
||||||
deleteFile,
|
deleteFile,
|
||||||
|
analyzeFile: analFile,
|
||||||
cardList,
|
cardList,
|
||||||
pagination,
|
pagination,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user