Skip to content

Commit

Permalink
ref: 修复表单支持去重
Browse files Browse the repository at this point in the history
  • Loading branch information
lltx authored Jul 14, 2024
1 parent d59d398 commit a00aef4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion common/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function putObj(obj?: Object) {
* 字段名: [
* {
* validator: (rule, value, callback) => {
* validateExist(rule, value, callback, form.id !== '');
* validateExist(rule, value, callback, form.${pk.attrName} !== '');
* },
* trigger: 'blur',
* },
Expand Down
19 changes: 13 additions & 6 deletions multiple/主子表单.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" @click="onSubmit" :disabled="loading">确认</el-button>
<el-button @click="visible = false">取 消</el-button>
<el-button type="primary" @click="onSubmit" :disabled="loading">确 认</el-button>
</span>
</template>
</el-drawer>
Expand All @@ -134,7 +134,7 @@
import { useDict } from '/@/hooks/dict';
import { rule } from '/@/utils/validate';
import { useMessage } from "/@/hooks/message";
import { getObj, addObj, putObj, delChildObj } from '/@/api/${moduleName}/${functionName}'
import { getObj, addObj, putObj, delChildObj, validateExist } from '/@/api/${moduleName}/${functionName}'
const scFormTable = defineAsyncComponent(() => import('/@/components/FormTable/index.vue'));
const emit = defineEmits(['refresh']);
Expand Down Expand Up @@ -181,12 +181,19 @@ const childTemp = reactive({
// 定义校验规则
const dataRules = ref({
#foreach($field in $formList)
#if($field.formRequired == '1' && $field.formValidator)
#if($field.formRequired == '1' && $field.formValidator == 'duplicate')
${field.attrName}: [{required: true, message: '${field.fieldComment}不能为空', trigger: 'blur'}, {
validator: (rule: any, value: any, callback: any) => {
validateExist(rule, value, callback, form.${pk.attrName} !== '');
},
trigger: 'blur',
}],
#elseif($field.formRequired == '1' && $field.formValidator)
${field.attrName}: [{required: true, message: '${field.fieldComment}不能为空', trigger: 'blur'}, { validator: rule.${field.formValidator}, trigger: 'blur' }],
#elseif($field.formRequired == '1')
${field.attrName}: [{required: true, message: '${field.fieldComment}不能为空', trigger: 'blur'}],
${field.attrName}: [{required: true, message: '${field.fieldComment}不能为空', trigger: 'blur'}],
#elseif($field.formValidator)
${field.attrName}: [{ validator: rule.${field.formValidator}, trigger: 'blur' }],
${field.attrName}: [{ validator: rule.${field.formValidator}, trigger: 'blur' }],
#end
#end
})
Expand Down
19 changes: 13 additions & 6 deletions single/表单.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" @click="onSubmit" :disabled="loading">确认</el-button>
<el-button @click="visible = false">取 消</el-button>
<el-button type="primary" @click="onSubmit" :disabled="loading">确 认</el-button>
</span>
</template>
</el-dialog>
Expand All @@ -112,7 +112,7 @@
<script setup lang="ts" name="${ClassName}Dialog">
import { useDict } from '/@/hooks/dict';
import { useMessage } from "/@/hooks/message";
import { getObj, addObj, putObj } from '/@/api/${moduleName}/${functionName}'
import { getObj, addObj, putObj, validateExist } from '/@/api/${moduleName}/${functionName}'
import { rule } from '/@/utils/validate';
const emit = defineEmits(['refresh']);
Expand Down Expand Up @@ -150,12 +150,19 @@ const form = reactive({
// 定义校验规则
const dataRules = ref({
#foreach($field in $formList)
#if($field.formRequired == '1' && $field.formValidator)
#if($field.formRequired == '1' && $field.formValidator == 'duplicate')
${field.attrName}: [{required: true, message: '${field.fieldComment}不能为空', trigger: 'blur'}, {
validator: (rule: any, value: any, callback: any) => {
validateExist(rule, value, callback, form.${pk.attrName} !== '');
},
trigger: 'blur',
}],
#elseif($field.formRequired == '1' && $field.formValidator)
${field.attrName}: [{required: true, message: '${field.fieldComment}不能为空', trigger: 'blur'}, { validator: rule.${field.formValidator}, trigger: 'blur' }],
#elseif($field.formRequired == '1')
${field.attrName}: [{required: true, message: '${field.fieldComment}不能为空', trigger: 'blur'}],
${field.attrName}: [{required: true, message: '${field.fieldComment}不能为空', trigger: 'blur'}],
#elseif($field.formValidator)
${field.attrName}: [{ validator: rule.${field.formValidator}, trigger: 'blur' }],
${field.attrName}: [{ validator: rule.${field.formValidator}, trigger: 'blur' }],
#end
#end
})
Expand Down

0 comments on commit a00aef4

Please sign in to comment.