add score

This commit is contained in:
Firesieht 2022-08-27 12:17:39 +03:00
parent 12900998c8
commit 0a3bf71358
7 changed files with 126 additions and 115 deletions

View File

@ -6,15 +6,15 @@ import 'antd/dist/antd.css';
interface ErrorViewerIE{
errText:string;
paragraph: string[];
paragraph: [number, string][];
variants?: string[];
num: number;
correct:boolean
correct:boolean;
}
export const ErrorViewer : React.FC<ErrorViewerIE> = (props) =>{
const [open, setOpen] = useState(false)
console.log(props.paragraph)
return(
<div className={styles.viewer}>
@ -41,8 +41,9 @@ export const ErrorViewer : React.FC<ErrorViewerIE> = (props) =>{
{
props.paragraph.map(
(value, index)=><div className={styles.paragraph}>
<div>{index+1}</div>
<div className={styles.paragraph}>{value}</div>
<div><strong>{index+1}</strong></div>
<div className={styles.paragraph}>{value[0]}</div>
<div><strong>Score:{value[1]}</strong></div>
</div>
)
}

View File

@ -2,6 +2,7 @@ import React, { useState } from "react";
import { Button, message, Upload } from "antd"
import Icon, { UploadOutlined } from '@ant-design/icons';
import 'antd/dist/antd.css';
import { host } from "../../pages/api/consts";
interface FileUploaderIE{
@ -12,7 +13,7 @@ export const FileUploader:React.FC<FileUploaderIE> = (data) =>{
const props = {
name: 'file',
action: 'http://192.168.9.152:8000/api/docx/',
action: host + '/api/site/docx/',
headers: {
authorization: 'authorization-text',
},

89
pages/files.tsx Normal file
View File

@ -0,0 +1,89 @@
import type { NextPage } from 'next'
import Head from 'next/head'
import { ErrorViewer } from '../Components/ErrorViewer'
import { FileUploader } from '../Components/FileUploader'
import { Header } from '../Components/header'
import styles from '../styles/Home.module.css'
import 'antd/dist/antd.css';
import { ItemSelect, SelectItemIE } from '../Components/ItemSelect'
import { useState } from 'react'
import { get } from './api/fetch'
import { host } from './api/consts'
import { PulseLoader } from 'react-spinners'
import axios from 'axios'
const Home: NextPage = () => {
let files = JSON.parse(localStorage.getItem("files") as string)
const [file, setFile] = useState(files[0].uuid)
const [data,setData] = useState("")
let i = 1;
let cards = new Array<JSX.Element>()
const getData = () =>{
if (data == ""){
axios.get(host+"/api/site/docx/" + file).then(res => {
setData(res.data)
})
}
}
const onFileChange = (newFile:any) =>{
setData("")
axios.get(host+"/api/site/docx/" + newFile).then(res => {
setData(res.data)
})
setFile(newFile)
}
setTimeout(getData, 2000);
if (data != ""){
for(var name in data as any) {
cards.push(
<ErrorViewer
num={i}
paragraph={(data as any)[name][0]==undefined? [["Выявлено отсутсвие данного модуля"]]:(data as any)[name]}
errText={name}
correct={(data as any)[name][0]==undefined? false:true}
></ErrorViewer>
)
i++
}
}
let select = new Array<SelectItemIE>()
files.forEach((value : any) => {
select.push(
{
name: value.file.slice(48, value.uuid.lenght),
value: value.uuid
} as SelectItemIE
)
});
return (
<div className={styles.container}>
<Head>
<title>Загрузите файл</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}>
<Header></Header>
<div className={styles.selector}>
<ItemSelect
onChange={(val)=>onFileChange(val as any)}
items={select}
></ItemSelect>
</div>
<div className={styles.pagination}>
{data == ""? <PulseLoader color={"#13377D"}></PulseLoader>:cards}
</div>
</main>
</div>
)
}
export default Home

View File

@ -20,12 +20,13 @@ const History: NextPage = () => {
const [data, setData] = useState("")
let router = useRouter()
if (data == ""){
axios.get(host+"/api/docx").then(res => {
axios.get(host+"/api/site/docx/").then(res => {
setData(res.data)
})
}
if (data != ""){
(data as any).forEach((value:any) => {
localStorage.setItem(value.uuid, value.file)
files.push(
<div className={styles.fileCard} onClick={()=>router.push("/view/" + value.uuid)}>
{value.file.slice(48, value.file.lenght)}

View File

@ -7,83 +7,36 @@ import styles from '../styles/Home.module.css'
import 'antd/dist/antd.css';
import { ItemSelect, SelectItemIE } from '../Components/ItemSelect'
import { useState } from 'react'
import { get } from './api/fetch'
import { host } from './api/consts'
import { PulseLoader } from 'react-spinners'
import axios from 'axios'
import { useRouter } from 'next/router'
const Home: NextPage = () => {
const Upload: NextPage = () => {
const [files, setFiles] = useState(new Array())
let router = useRouter()
let files = JSON.parse(localStorage.getItem("files") as string)
const [file, setFile] = useState(files[0].uuid)
const [data,setData] = useState("")
let i = 1;
let cards = new Array<JSX.Element>()
const getData = () =>{
if (data == ""){
axios.get(host+"/api/docx/" + file).then(res => {
setData(res.data)
})
}
const onNext = () =>{
localStorage.setItem("files", JSON.stringify(files))
router.push("/files")
}
const onFileChange = (newFile:any) =>{
setData("")
axios.get(host+"/api/docx/" + newFile).then(res => {
setData(res.data)
})
setFile(newFile)
}
setTimeout(getData, 2000);
if (data != ""){
for(var name in data as any) {
cards.push(
<ErrorViewer
num={i}
paragraph={(data as any)[name][0]==undefined? ["Выявлено отсутсвие данного модуля"]:(data as any)[name]}
errText={name}
correct={(data as any)[name][0]==undefined? false:true}
></ErrorViewer>
)
i++
}
}
let select = new Array<SelectItemIE>()
files.forEach((value : any) => {
select.push(
{
name: value.file.slice(48, value.uuid.lenght),
value: value.uuid
} as SelectItemIE
)
});
return (
<div className={styles.container}>
<Head>
<title>Загрузите файл</title>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}>
<Header></Header>
<div className={styles.upload}>
<FileUploader onResponse={(file)=>setFiles([...files, file])}></FileUploader>
<div className={styles.btn} onClick={()=>onNext()}>Далее</div>
</div>
<div className={styles.selector}>
<ItemSelect
onChange={(val)=>onFileChange(val as any)}
items={select}
></ItemSelect>
</div>
<div className={styles.pagination}>
{data == ""? <PulseLoader color={"#13377D"}></PulseLoader>:cards}
</div>
</main>
</div>
)
}
export default Home
export default Upload

View File

@ -1,42 +0,0 @@
import type { NextPage } from 'next'
import Head from 'next/head'
import { ErrorViewer } from '../Components/ErrorViewer'
import { FileUploader } from '../Components/FileUploader'
import { Header } from '../Components/header'
import styles from '../styles/Home.module.css'
import 'antd/dist/antd.css';
import { ItemSelect, SelectItemIE } from '../Components/ItemSelect'
import { useState } from 'react'
import { useRouter } from 'next/router'
const Upload: NextPage = () => {
const [files, setFiles] = useState(new Array())
let router = useRouter()
const onNext = () =>{
localStorage.setItem("files", JSON.stringify(files))
router.push("/")
}
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}>
<Header></Header>
<div className={styles.upload}>
<FileUploader onResponse={(file)=>setFiles([...files, file])}></FileUploader>
<div className={styles.btn} onClick={()=>onNext()}>Далее</div>
</div>
</main>
</div>
)
}
export default Upload

View File

@ -24,7 +24,7 @@ const View: NextPage = () => {
const getData = () =>{
if (data == ""){
axios.get(host+"/api/docx/" + uuid).then(res => {
axios.get(host+"/api/site/docx/" + uuid).then(res => {
setData(res.data)
})
}
@ -35,7 +35,7 @@ const View: NextPage = () => {
cards.push(
<ErrorViewer
num={i}
paragraph={(data as any)[name][0]==undefined? ["Выявлено отсутсвие данного модуля"]:(data as any)[name]}
paragraph={(data as any)[name][0]==undefined? [["Выявлено отсутсвие данного модуля"]]:(data as any)[name]}
errText={name}
correct={(data as any)[name][0]==undefined? false:true}
></ErrorViewer>
@ -56,6 +56,14 @@ const View: NextPage = () => {
<Header></Header>
<div className={styles.uploader}>
<div>
<div onClick={()=>router.back()}>
<img style={{transform:"rotate(90deg)", cursor:"pointer"}}src="/images/arrow.svg"></img>
</div>
<div>
{localStorage.getItem(uuid)?.slice(48,localStorage.getItem(uuid)?.length)}
</div>
</div>
{data == ""? <PulseLoader color={"#13377D"}></PulseLoader>:cards}
</div>
</main>