mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-04 23:40:24 +08:00
初步完成step1前端设计
This commit is contained in:
32
backend/generate.go
Normal file
32
backend/generate.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/fumiama/paper-manager/backend/global"
|
||||
)
|
||||
|
||||
func init() {
|
||||
apimap["/api/genFile"] = &apihandler{"POST", func(w http.ResponseWriter, r *http.Request) {
|
||||
user := usertokens.Get(r.Header.Get("Authorization"))
|
||||
if user == nil {
|
||||
writeresult(w, codeError, nil, errInvalidToken.Error(), typeError)
|
||||
return
|
||||
}
|
||||
conf := global.GenerateConfig{}
|
||||
defer r.Body.Close()
|
||||
err := json.NewDecoder(r.Body).Decode(&conf)
|
||||
if err != nil {
|
||||
writeresult(w, codeError, nil, err.Error(), typeError)
|
||||
return
|
||||
}
|
||||
docf, err := global.FileDB.GenerateFile(&conf)
|
||||
if err != nil {
|
||||
writeresult(w, codeError, nil, err.Error(), typeError)
|
||||
return
|
||||
}
|
||||
_, _ = io.Copy(w, docf)
|
||||
}}
|
||||
}
|
||||
@@ -235,7 +235,7 @@ func (f *FileDatabase) AddFile(lstid int, reg *Regex, istemp bool, progress func
|
||||
m := md5.Sum(sb.Bytes())
|
||||
que := &Question{
|
||||
ID: int64(binary.LittleEndian.Uint64(m[:8])),
|
||||
FileID: file.ID,
|
||||
ListID: *lst.ID,
|
||||
Major: majorq.Name,
|
||||
Plain: base14.BytesToString(sb.Bytes()),
|
||||
Images: func() []byte {
|
||||
|
||||
@@ -2,6 +2,7 @@ package global
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
sql "github.com/FloatTech/sqlite"
|
||||
@@ -77,7 +78,26 @@ func (f *FileDatabase) GenerateFile(config *GenerateConfig) (*docx.Docx, error)
|
||||
if rate > config.RateLimit {
|
||||
return nil, ErrRateLimitExceeded
|
||||
}
|
||||
// TODO: 写入question到docf
|
||||
for i, q := range ques {
|
||||
lst, err := sql.Find[List](&f.db, FileTableFile, "WHERE ID="+strconv.Itoa(q.ListID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
quesfile, err := os.Open(q.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
stat, err := quesfile.Stat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
docq, err := docx.Parse(quesfile, stat.Size())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
docf.AddParagraph().AddText(strconv.Itoa(i+1) + ". (" + lst.Desc + ")")
|
||||
docf.AppendFile(docq)
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
return docf, nil
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ func (f *FileDatabase) DelQuestion(id int64, istemp bool) error {
|
||||
|
||||
type Question struct {
|
||||
ID int64 // ID is the first 8 bytes of the Plain's md5
|
||||
FileID int64 // FileID is fk to File(ID)
|
||||
ListID int // ListID is fk to List(ID)
|
||||
Major string // Major is sub's major name
|
||||
Path string // Path is the question's docx position
|
||||
Plain string // Plain is the plain text of the question (like markdown format)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"container/heap"
|
||||
"encoding/json"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/fumiama/paper-manager/backend/global"
|
||||
@@ -95,3 +96,22 @@ func parseFileQuestions(qb []byte, istemp bool) ([]question, []duplication, floa
|
||||
|
||||
return qs, ds, sum / float64(cnt), nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
apimap["/api/getMajors"] = &apihandler{"GET", func(w http.ResponseWriter, r *http.Request) {
|
||||
user := usertokens.Get(r.Header.Get("Authorization"))
|
||||
if user == nil {
|
||||
writeresult(w, codeError, nil, errInvalidToken.Error(), typeError)
|
||||
return
|
||||
}
|
||||
majs := global.FileDB.GetMajors()
|
||||
type majret struct {
|
||||
Name string
|
||||
}
|
||||
majrets := make([]majret, len(majs))
|
||||
for i, s := range majs {
|
||||
majrets[i].Name = s
|
||||
}
|
||||
writeresult(w, codeSuccess, &majrets, messageOk, typeSuccess)
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ enum Api {
|
||||
AnalyzeFile = '/analyzeFile',
|
||||
DlFile = '/dlFile',
|
||||
GetFileStatus = '/getFileStatus',
|
||||
GetMajors = '/getMajors',
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,3 +74,10 @@ export const getFileBlob = (url: string) => {
|
||||
export const getFileStatus = (id: number) => {
|
||||
return defHttp.get<FileStatus>({ url: Api.GetFileStatus, params: { id: id } })
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Get majors
|
||||
*/
|
||||
export const getMajors = () => {
|
||||
return defHttp.get<string[]>({ url: Api.GetMajors })
|
||||
}
|
||||
|
||||
@@ -1,48 +1,82 @@
|
||||
<template>
|
||||
<div class="step1">
|
||||
<div class="step1-form">
|
||||
<BasicForm @register="register">
|
||||
<template #fac="{ model, field }">
|
||||
<a-input-group compact>
|
||||
<a-select v-model:value="model['pay']" class="pay-select">
|
||||
<a-select-option value="zfb"> 支付宝 </a-select-option>
|
||||
<a-select-option value="yl"> 银联 </a-select-option>
|
||||
</a-select>
|
||||
<a-input class="pay-input" v-model:value="model[field]" />
|
||||
</a-input-group>
|
||||
<BasicTable @register="registerTable">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'action'">
|
||||
<TableAction :actions="createActions(record, column)" />
|
||||
</template>
|
||||
</template>
|
||||
</BasicForm>
|
||||
</BasicTable>
|
||||
<a-button block type="dashed" class="mt-5" @click="handleAdd"> 新增大题 </a-button>
|
||||
<a-divider />
|
||||
<BasicForm @register="register" />
|
||||
</div>
|
||||
<a-divider />
|
||||
<h3>说明</h3>
|
||||
<h4>转账到支付宝账户</h4>
|
||||
<p>
|
||||
如果需要,这里可以放一些关于产品的常见问题说明。如果需要,这里可以放一些关于产品的常见问题说明。如果需要,这里可以放一些关于产品的常见问题说明。
|
||||
</p>
|
||||
|
||||
<h4>转账到银行卡</h4>
|
||||
<p>
|
||||
如果需要,这里可以放一些关于产品的常见问题说明。如果需要,这里可以放一些关于产品的常见问题说明。如果需要,这里可以放一些关于产品的常见问题说明。
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue'
|
||||
import { BasicForm, useForm } from '/@/components/Form'
|
||||
import { getMajors } from '/@/api/page'
|
||||
import {
|
||||
BasicTable,
|
||||
useTable,
|
||||
TableAction,
|
||||
BasicColumn,
|
||||
ActionItem,
|
||||
EditRecordRow,
|
||||
} from '/@/components/Table'
|
||||
import { step1Schemas } from './data'
|
||||
|
||||
import { Select, Input, Divider } from 'ant-design-vue'
|
||||
import { useMessage } from '/@/hooks/web/useMessage'
|
||||
|
||||
const columns: BasicColumn[] = [
|
||||
{
|
||||
title: '大题',
|
||||
dataIndex: 'major',
|
||||
editRow: true,
|
||||
editComponent: 'ApiSelect',
|
||||
editComponentProps: {
|
||||
api: getMajors,
|
||||
resultField: 'Name',
|
||||
labelField: 'Name',
|
||||
valueField: 'Name',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '数量',
|
||||
dataIndex: 'count',
|
||||
editRow: true,
|
||||
editComponent: 'InputNumber',
|
||||
width: 120,
|
||||
},
|
||||
]
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
BasicForm,
|
||||
BasicTable,
|
||||
TableAction,
|
||||
[Select.name]: Select,
|
||||
ASelectOption: Select.Option,
|
||||
[Input.name]: Input,
|
||||
[Input.Group.name]: Input.Group,
|
||||
[Divider.name]: Divider,
|
||||
},
|
||||
emits: ['next'],
|
||||
setup(_, { emit }) {
|
||||
const [registerTable, { getDataSource }] = useTable({
|
||||
columns: columns,
|
||||
showIndexColumn: false,
|
||||
actionColumn: {
|
||||
width: 100,
|
||||
title: '操作',
|
||||
dataIndex: 'action',
|
||||
// slots: { customRender: 'action' },
|
||||
},
|
||||
scroll: { y: '100%' },
|
||||
pagination: false,
|
||||
})
|
||||
|
||||
const [register, { validate }] = useForm({
|
||||
labelWidth: 100,
|
||||
schemas: step1Schemas,
|
||||
@@ -56,6 +90,8 @@
|
||||
submitFunc: customSubmitFunc,
|
||||
})
|
||||
|
||||
const { createMessage } = useMessage()
|
||||
|
||||
async function customSubmitFunc() {
|
||||
try {
|
||||
const values = await validate()
|
||||
@@ -63,14 +99,91 @@
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
return { register }
|
||||
function handleEdit(record: EditRecordRow) {
|
||||
record.onEdit?.(true)
|
||||
}
|
||||
|
||||
function handleCancel(record: EditRecordRow) {
|
||||
record.onEdit?.(false)
|
||||
if (record.isNew) {
|
||||
const data = getDataSource()
|
||||
const index = data.findIndex((item) => item.key === record.key)
|
||||
data.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
||||
function handleDelete(record: EditRecordRow) {
|
||||
record.onEdit?.(false)
|
||||
if (record.isNew) {
|
||||
const data = getDataSource()
|
||||
const index = data.findIndex((item) => item.key === record.key)
|
||||
data.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
||||
function handleSave(record: EditRecordRow) {
|
||||
record.onEdit?.(false, true)
|
||||
}
|
||||
|
||||
function handleAdd() {
|
||||
const data = getDataSource()
|
||||
if (data.length >= 10) {
|
||||
createMessage.warn('最大只支持10项!')
|
||||
return
|
||||
}
|
||||
const addRow: EditRecordRow = {
|
||||
major: '',
|
||||
count: 1,
|
||||
editable: true,
|
||||
isNew: true,
|
||||
key: `${Date.now()}`,
|
||||
}
|
||||
data.push(addRow)
|
||||
}
|
||||
|
||||
function createActions(record: EditRecordRow, column: BasicColumn): ActionItem[] {
|
||||
if (!record.editable) {
|
||||
return [
|
||||
{
|
||||
label: '编辑',
|
||||
onClick: handleEdit.bind(null, record),
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
onClick: handleDelete.bind(null, record, column),
|
||||
},
|
||||
]
|
||||
}
|
||||
return [
|
||||
{
|
||||
label: '保存',
|
||||
onClick: handleSave.bind(null, record, column),
|
||||
},
|
||||
{
|
||||
label: '取消',
|
||||
popConfirm: {
|
||||
title: '是否取消编辑',
|
||||
confirm: handleCancel.bind(null, record, column),
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
return {
|
||||
register,
|
||||
registerTable,
|
||||
handleEdit,
|
||||
createActions,
|
||||
handleAdd,
|
||||
getDataSource,
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
.step1 {
|
||||
&-form {
|
||||
width: 450px;
|
||||
width: 600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,64 +2,120 @@ import { FormSchema } from '/@/components/Form'
|
||||
|
||||
export const step1Schemas: FormSchema[] = [
|
||||
{
|
||||
field: 'account',
|
||||
component: 'Select',
|
||||
label: '付款账户',
|
||||
field: 'RateLimit',
|
||||
component: 'Slider',
|
||||
label: '重复率上限',
|
||||
required: true,
|
||||
defaultValue: '1',
|
||||
componentProps: {
|
||||
min: 0,
|
||||
max: 100,
|
||||
range: true,
|
||||
marks: {
|
||||
0: '0%',
|
||||
50: '50%',
|
||||
100: '100%',
|
||||
},
|
||||
},
|
||||
colProps: {
|
||||
span: 24,
|
||||
},
|
||||
},
|
||||
{
|
||||
field: '[YearStart, YearEnd]',
|
||||
component: 'RangePicker',
|
||||
label: '起止年份',
|
||||
required: false,
|
||||
componentProps: {
|
||||
format: 'YYYY',
|
||||
placeholder: ['起始年份', '结束年份'],
|
||||
showTime: { format: 'YYYY' },
|
||||
},
|
||||
colProps: {
|
||||
span: 12,
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'AB',
|
||||
component: 'RadioGroup',
|
||||
label: '试卷类别',
|
||||
componentProps: {
|
||||
options: [
|
||||
{
|
||||
label: 'anncwb@126.com',
|
||||
value: '1',
|
||||
label: 'A',
|
||||
value: 'A',
|
||||
},
|
||||
{
|
||||
label: 'B',
|
||||
value: 'B',
|
||||
},
|
||||
],
|
||||
},
|
||||
colProps: {
|
||||
span: 24,
|
||||
span: 12,
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'fac',
|
||||
component: 'InputGroup',
|
||||
label: '收款账户',
|
||||
required: true,
|
||||
defaultValue: 'test@example.com',
|
||||
slot: 'fac',
|
||||
colProps: {
|
||||
span: 24,
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'pay',
|
||||
component: 'Input',
|
||||
label: '',
|
||||
defaultValue: 'zfb',
|
||||
show: false,
|
||||
},
|
||||
{
|
||||
field: 'payeeName',
|
||||
component: 'Input',
|
||||
label: '收款人姓名',
|
||||
defaultValue: 'Vben',
|
||||
required: true,
|
||||
colProps: {
|
||||
span: 24,
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'money',
|
||||
component: 'Input',
|
||||
label: '转账金额',
|
||||
defaultValue: '500',
|
||||
required: true,
|
||||
renderComponentContent: () => {
|
||||
return {
|
||||
prefix: () => '¥',
|
||||
}
|
||||
field: 'MiddleFinal',
|
||||
component: 'RadioGroup',
|
||||
label: '考试阶段',
|
||||
componentProps: {
|
||||
options: [
|
||||
{
|
||||
label: '期中',
|
||||
value: '中',
|
||||
},
|
||||
{
|
||||
label: '期末',
|
||||
value: '末',
|
||||
},
|
||||
],
|
||||
},
|
||||
colProps: {
|
||||
span: 24,
|
||||
span: 12,
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'FirstSecond',
|
||||
component: 'RadioGroup',
|
||||
label: '考试学期',
|
||||
componentProps: {
|
||||
options: [
|
||||
{
|
||||
label: '第1学期',
|
||||
value: '1',
|
||||
},
|
||||
{
|
||||
label: '第2学期',
|
||||
value: '2',
|
||||
},
|
||||
],
|
||||
},
|
||||
colProps: {
|
||||
span: 12,
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'OpenClose',
|
||||
component: 'RadioGroup',
|
||||
label: '考试类型',
|
||||
componentProps: {
|
||||
options: [
|
||||
{
|
||||
label: '开卷',
|
||||
value: '开卷',
|
||||
},
|
||||
{
|
||||
label: '一页纸开卷',
|
||||
value: '一页纸开卷',
|
||||
},
|
||||
{
|
||||
label: '闭卷',
|
||||
value: '闭卷',
|
||||
},
|
||||
],
|
||||
},
|
||||
colProps: {
|
||||
span: 20,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
2
go.mod
2
go.mod
@@ -8,7 +8,7 @@ require (
|
||||
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e
|
||||
github.com/corona10/goimagehash v1.1.0
|
||||
github.com/fumiama/go-base16384 v1.6.4
|
||||
github.com/fumiama/go-docx v0.0.0-20230330141738-34f53a967c03
|
||||
github.com/fumiama/go-docx v0.0.0-20230423112805-050781fdde57
|
||||
github.com/fumiama/imgsz v0.0.2
|
||||
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
|
||||
4
go.sum
4
go.sum
@@ -13,8 +13,8 @@ github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b h1:Zt3pFQditAdWTHCO
|
||||
github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/fumiama/go-base16384 v1.6.4 h1:rYDRwD/th2cG4U7QLokpzmST1cCxZGXtHmolOUePt5o=
|
||||
github.com/fumiama/go-base16384 v1.6.4/go.mod h1:OEn+947GV5gsbTAnyuUW/SrfxJYUdYupSIQXOuGOcXM=
|
||||
github.com/fumiama/go-docx v0.0.0-20230330141738-34f53a967c03 h1:gQ9cMYk9QhTXh5sx74RwuNoDzJqVLYfOBsl/0rMMDns=
|
||||
github.com/fumiama/go-docx v0.0.0-20230330141738-34f53a967c03/go.mod h1:ssRF0IaB1hCcKIObp3FkZOsjTcAHpgii70JelNb4H8M=
|
||||
github.com/fumiama/go-docx v0.0.0-20230423112805-050781fdde57 h1:9ihi8RbNyKHf1gThoeRyD2SYdbPLkLiql9N+kzljoWY=
|
||||
github.com/fumiama/go-docx v0.0.0-20230423112805-050781fdde57/go.mod h1:ssRF0IaB1hCcKIObp3FkZOsjTcAHpgii70JelNb4H8M=
|
||||
github.com/fumiama/imgsz v0.0.2 h1:fAkC0FnIscdKOXwAxlyw3EUba5NzxZdSxGaq3Uyfxak=
|
||||
github.com/fumiama/imgsz v0.0.2/go.mod h1:dR71mI3I2O5u6+PCpd47M9TZptzP+39tRBcbdIkoqM4=
|
||||
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565 h1:sQuR2+N5HurnvsZhiKdEg+Ig354TaqgCQRxd/0KgIOQ=
|
||||
|
||||
Reference in New Issue
Block a user