Browse Source

字段校验

master_hella_20240701
zhaoyiran 7 months ago
parent
commit
5132f01f82
  1. 2
      src/components/BasicForm/src/BasicForm.vue
  2. 54
      src/views/qms/aql/aql.data.ts
  3. 42
      src/views/qms/aql/index.vue

2
src/components/BasicForm/src/BasicForm.vue

@ -658,7 +658,7 @@ const inpuFocus = (headerItem, row, index) => {
* @param cur 改变后值 * @param cur 改变后值
*/ */
const onChange = (field, cur) => { const onChange = (field, cur) => {
emit('onChange', field, cur) emit('onChange', field, cur, formRef)
} }
/** /**

54
src/views/qms/aql/aql.data.ts

@ -1,6 +1,7 @@
import type { CrudSchema } from '@/hooks/web/useCrudSchemas' import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import {getSamplingScheme} from "@/api/qms/aql"; import {getSamplingScheme} from "@/api/qms/aql";
import {validateNum} from "@/utils/validator";
// 表单校验 // 表单校验
export const AqlRules = reactive({ export const AqlRules = reactive({
@ -8,7 +9,58 @@ export const AqlRules = reactive({
inspectionQualification: [required], inspectionQualification: [required],
sampleCharacterCode: [required], sampleCharacterCode: [required],
sampleSize: [required], sampleSize: [required],
// available: [required], a0separator010: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r0separator010: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a0separator015: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r0separator015: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a0separator025: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r0separator025: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a0separator040: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r0separator040: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a0separator065: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r0separator065: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a0separator10: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r0separator10: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a0separator15: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r0separator15: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a0separator25: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r0separator25: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a0separator40: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r0separator40: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a0separator65: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r0separator65: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a1separator0: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r1separator0: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a1separator5: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r1separator5: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a2separator5: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r2separator5: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a4separator0: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r4separator0: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a6separator5: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r6separator5: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a10: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r10: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a15: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r15: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a25: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r25: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a40: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r40: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a65: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r65: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a100: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r100: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a150: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r150: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a250: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r250: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a400: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r400: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a650: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r650: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
a1000: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
r1000: [{ validator:validateNum, message: '请输入整数', trigger: 'blur'}],
}) })
const samplingSchemeList = await getSamplingScheme() const samplingSchemeList = await getSamplingScheme()
export const Aql = useCrudSchemas(reactive<CrudSchema[]>([ export const Aql = useCrudSchemas(reactive<CrudSchema[]>([

42
src/views/qms/aql/index.vue

@ -48,6 +48,7 @@
:apiCreate="AqlApi.createAql" :apiCreate="AqlApi.createAql"
@searchTableSuccess="searchTableSuccess" @searchTableSuccess="searchTableSuccess"
:isBusiness="false" :isBusiness="false"
@onChange="onChange"
/> />
<!-- 详情 --> <!-- 详情 -->
@ -235,6 +236,47 @@ const searchFormClick = (searchData) => {
getList() // getList() //
} }
const onChange = async (field, value, formRef) => {
// "a"
if (field.startsWith("a") || field.startsWith("r")) {
// "a"
const suffix = field.slice(1);
// "r"
const correspondingField = field.startsWith("a") ? "r" + suffix : "a" + suffix ;
console.log(correspondingField)
// "r"
if (value) {
// "r"
Aql.allSchemas.formSchema.forEach(item => {
if (item.field === correspondingField) {
const setV = {};
if(correspondingField.startsWith("r")){
setV[correspondingField] = parseInt(value) + 1;
}else {
setV[correspondingField] = parseInt(value) - 1;
}
item.componentProps.disabled = true;
// 使 Vue nextTick DOM
nextTick(() => {
formRef.value.setValues(setV);
});
}
});
}else{
Aql.allSchemas.formSchema.forEach(item => {
if (item.field === correspondingField || item.field === field) {
item.componentProps.disabled = false;
const setV = {};
setV[correspondingField] = ''
nextTick(() => {
formRef.value.setValues(setV);
});
}
});
}
}
};
/** 初始化 **/ /** 初始化 **/
onMounted(async () => { onMounted(async () => {
getList() getList()

Loading…
Cancel
Save