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

初步引入regex

This commit is contained in:
源文雨
2023-04-17 23:31:35 +08:00
parent e2a8cdf5b3
commit f65874cf52
3 changed files with 166 additions and 2 deletions

View File

@@ -4,6 +4,8 @@ import (
"reflect"
"regexp"
"strconv"
sql "github.com/FloatTech/sqlite"
)
// Regex stores user's config of splitting docx file
@@ -73,10 +75,16 @@ func (u *UserDatabase) GetUserRegex(id int) (*Regex, error) {
if !user.IsFileManager() {
return nil, ErrInvalidRole
}
reg := newRegex()
u.mu.RLock()
_ = u.db.Find(UserTableRegex, &reg, "WHERE ID="+strconv.Itoa(id))
reg, _ := sql.Find[Regex](&u.db, UserTableRegex, "WHERE ID="+strconv.Itoa(id))
u.mu.RUnlock()
reg.ID = *user.ID
rf := reflect.ValueOf(reg)
defaultrf := reflect.ValueOf(newRegex())
for i := 0; i < rf.NumField(); i++ {
if rf.Field(i).IsZero() {
rf.Field(i).Set(defaultrf.Field(i))
}
}
return &reg, nil
}

View File

@@ -0,0 +1,87 @@
import { FormSchema } from '/@/components/Form'
const colProps = {
span: 8,
}
export const schemas: FormSchema[] = [
{
field: 'title',
component: 'Input',
colProps,
label: '标题',
helpMessage: '目标的服务对象',
componentProps: {
placeholder: '请描述你服务的客户,内部客户直接 @姓名/工号',
},
},
{
field: 'class',
component: 'Input',
colProps,
label: '客户',
helpMessage: '目标的服务对象',
componentProps: {
placeholder: '请描述你服务的客户,内部客户直接 @姓名/工号',
},
},
{
field: 'opencl',
component: 'Input',
colProps,
label: '客户',
helpMessage: '目标的服务对象',
componentProps: {
placeholder: '请描述你服务的客户,内部客户直接 @姓名/工号',
},
},
{
field: 'date',
component: 'Input',
colProps,
label: '客户',
helpMessage: '目标的服务对象',
componentProps: {
placeholder: '请描述你服务的客户,内部客户直接 @姓名/工号',
},
},
{
field: 'time',
component: 'Input',
colProps,
label: '客户',
helpMessage: '目标的服务对象',
componentProps: {
placeholder: '请描述你服务的客户,内部客户直接 @姓名/工号',
},
},
{
field: 'rate',
component: 'Input',
colProps,
label: '客户',
helpMessage: '目标的服务对象',
componentProps: {
placeholder: '请描述你服务的客户,内部客户直接 @姓名/工号',
},
},
{
field: 'major',
component: 'Input',
colProps,
label: '客户',
helpMessage: '目标的服务对象',
componentProps: {
placeholder: '请描述你服务的客户,内部客户直接 @姓名/工号',
},
},
{
field: 'sub',
component: 'Input',
colProps,
label: '客户',
helpMessage: '目标的服务对象',
componentProps: {
placeholder: '请描述你服务的客户,内部客户直接 @姓名/工号',
},
},
]

View File

@@ -0,0 +1,69 @@
<template>
<PageWrapper
title="基础表单"
contentBackground
content=" 表单页用于向用户收集或验证信息,基础表单常见于数据项较少的表单场景。"
contentClass="p-4"
>
<BasicForm @register="register" />
</PageWrapper>
</template>
<script lang="ts">
import { BasicForm, useForm } from '/@/components/Form'
import { defineComponent } from 'vue'
import { schemas } from './data'
import { useMessage } from '/@/hooks/web/useMessage'
import { PageWrapper } from '/@/components/Page'
export default defineComponent({
name: 'FormBasicPage',
components: { BasicForm, PageWrapper },
setup() {
const { createMessage } = useMessage()
const [register, { validate, setProps }] = useForm({
labelCol: {
span: 8,
},
wrapperCol: {
span: 15,
},
schemas: schemas,
actionColOptions: {
offset: 8,
span: 23,
},
submitButtonOptions: {
text: '提交',
},
submitFunc: customSubmitFunc,
})
async function customSubmitFunc() {
try {
await validate()
setProps({
submitButtonOptions: {
loading: true,
},
})
setTimeout(() => {
setProps({
submitButtonOptions: {
loading: false,
},
})
createMessage.success('提交成功!')
}, 2000)
} catch (error) {}
}
return { register }
},
})
</script>
<style lang="less" scoped>
.form-wrap {
padding: 24px;
background-color: @component-background;
}
</style>