mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-29 23:30:43 +08:00
fix name exist check on update
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
import { defineComponent, ref, computed, unref } from 'vue'
|
import { defineComponent, ref, computed, unref } from 'vue'
|
||||||
import { BasicModal, useModalInner } from '/@/components/Modal'
|
import { BasicModal, useModalInner } from '/@/components/Modal'
|
||||||
import { BasicForm, useForm } from '/@/components/Form/index'
|
import { BasicForm, useForm } from '/@/components/Form/index'
|
||||||
import { nameFormSchema } from './account.data'
|
import { isNameExist } from '/@/api/sys/user'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'AccountModal',
|
name: 'AccountModal',
|
||||||
@@ -20,7 +20,81 @@
|
|||||||
const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({
|
const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({
|
||||||
labelWidth: 100,
|
labelWidth: 100,
|
||||||
baseColProps: { span: 24 },
|
baseColProps: { span: 24 },
|
||||||
schemas: nameFormSchema,
|
schemas: [
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
label: '用户名',
|
||||||
|
component: 'Input',
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请输入用户名',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
validator(_, value) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (unref(isUpdate)) {
|
||||||
|
resolve()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
isNameExist(value)
|
||||||
|
.then((v) => {
|
||||||
|
if (!v) resolve()
|
||||||
|
else reject('用户名已存在')
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
reject(err.message || '验证失败')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'pwd',
|
||||||
|
label: '密码',
|
||||||
|
component: 'InputPassword',
|
||||||
|
required: true,
|
||||||
|
ifShow: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '角色',
|
||||||
|
field: 'role',
|
||||||
|
component: 'ApiSelect',
|
||||||
|
componentProps: {
|
||||||
|
api: () => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
roleName: '课程组长',
|
||||||
|
value: 'super',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
roleName: '归档代理',
|
||||||
|
value: 'filemgr',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
roleName: '课程组员',
|
||||||
|
value: 'user',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
labelField: 'roleName',
|
||||||
|
valueField: 'value',
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'nick',
|
||||||
|
label: '昵称',
|
||||||
|
component: 'Input',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '简介',
|
||||||
|
field: 'desc',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
},
|
||||||
|
],
|
||||||
showActionButtonGroup: false,
|
showActionButtonGroup: false,
|
||||||
actionColOptions: {
|
actionColOptions: {
|
||||||
span: 23,
|
span: 23,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { isNameExist } from '/@/api/sys/user'
|
|
||||||
import { BasicColumn } from '/@/components/Table'
|
import { BasicColumn } from '/@/components/Table'
|
||||||
import { FormSchema } from '/@/components/Table'
|
import { FormSchema } from '/@/components/Table'
|
||||||
|
|
||||||
@@ -43,75 +42,3 @@ export const searchFormSchema: FormSchema[] = [
|
|||||||
colProps: { span: 8 },
|
colProps: { span: 8 },
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
export const nameFormSchema: FormSchema[] = [
|
|
||||||
{
|
|
||||||
field: 'name',
|
|
||||||
label: '用户名',
|
|
||||||
component: 'Input',
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '请输入用户名',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
validator(_, value) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
isNameExist(value)
|
|
||||||
.then((v) => {
|
|
||||||
if (!v) resolve()
|
|
||||||
else reject('用户名已存在')
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
reject(err.message || '验证失败')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'pwd',
|
|
||||||
label: '密码',
|
|
||||||
component: 'InputPassword',
|
|
||||||
required: true,
|
|
||||||
ifShow: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '角色',
|
|
||||||
field: 'role',
|
|
||||||
component: 'ApiSelect',
|
|
||||||
componentProps: {
|
|
||||||
api: () => {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
roleName: '课程组长',
|
|
||||||
value: 'super',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
roleName: '归档代理',
|
|
||||||
value: 'filemgr',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
roleName: '课程组员',
|
|
||||||
value: 'user',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
labelField: 'roleName',
|
|
||||||
valueField: 'value',
|
|
||||||
},
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'nick',
|
|
||||||
label: '昵称',
|
|
||||||
component: 'Input',
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '简介',
|
|
||||||
field: 'desc',
|
|
||||||
component: 'InputTextArea',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user