update 校验重复接口调整
This commit is contained in:
@@ -137,10 +137,11 @@ yarn run lint
|
||||
重复校验效果:
|
||||

|
||||
|
||||
1.引入排重接口,代码如下:
|
||||
1.引入排重接口,以及获取混淆code方法,代码如下:
|
||||
|
||||
```
|
||||
import { duplicateCheck } from '@/api/api'
|
||||
import { getConfusionCode } from '@/utils/util'
|
||||
```
|
||||
2.找到编码必填校验规则的前端代码,代码如下:
|
||||
|
||||
@@ -155,10 +156,11 @@ code: {
|
||||
},
|
||||
```
|
||||
3.找到rules里validator对应的方法在哪里,然后使用第一步中引入的排重校验接口.
|
||||
以用户online表单编码为示例,其中四个必传的参数有:
|
||||
以用户online表单编码为示例,其中三个必传的参数有:
|
||||
|
||||
```
|
||||
{tableName:表名,fieldName:字段名,fieldVal:字段值,dataId:表的主键},
|
||||
{confusionCode:混淆code,fieldVal:字段值,dataId:表的主键,
|
||||
encrypt:是否数据库中加密(不加密不传该参数)},
|
||||
```
|
||||
具体使用代码如下:
|
||||
|
||||
@@ -168,9 +170,10 @@ code: {
|
||||
if(!pattern.test(value)){
|
||||
callback('编码必须以字母开头,可包含数字、下划线、横杠');
|
||||
} else {
|
||||
var confusionCode = getConfusionCode('tableName', 'fieldName')
|
||||
var params = {
|
||||
tableName: "onl_cgreport_head",
|
||||
fieldName: "code",
|
||||
// encrypt: 1, // 数据库中是加密的信息,就要传该参数,否则不传
|
||||
confusionCode,
|
||||
fieldVal: value,
|
||||
dataId: this.model.id
|
||||
};
|
||||
|
||||
+49
-2
@@ -343,9 +343,14 @@ export function jsExpand (options = {}) {
|
||||
* @param dataId 数据ID,可空
|
||||
* @param callback
|
||||
*/
|
||||
export function validateDuplicateValue (tableName, fieldName, fieldVal, dataId, callback) {
|
||||
export function validateDuplicateValue (isEncrypt, tableName, fieldName, fieldVal, dataId, callback) {
|
||||
if (fieldVal) {
|
||||
const params = { tableName, fieldName, fieldVal, dataId }
|
||||
const confusionCode = getConfusionCode(tableName, fieldName)
|
||||
const params = { confusionCode, fieldVal, dataId }
|
||||
// 是否数据库中存储的加密信息
|
||||
if (isEncrypt) {
|
||||
params.encrypt = 1
|
||||
}
|
||||
api.duplicateCheck(params).then(res => {
|
||||
res.success ? callback() : callback(res.message)
|
||||
}).catch(err => {
|
||||
@@ -622,3 +627,45 @@ export function urlToParams (url) {
|
||||
})
|
||||
return paramsObj
|
||||
}
|
||||
|
||||
/**
|
||||
* 重复校验:表名和字段名获取混淆code
|
||||
* @param tableName
|
||||
* @param fieldName
|
||||
* @return {string}
|
||||
*/
|
||||
export function getConfusionCode (tableName, fieldName) {
|
||||
// map对象对应数据库中 sys_confusion 表
|
||||
const map = {
|
||||
sys_user: {
|
||||
username: 'sys_username',
|
||||
phone: 'user_phone',
|
||||
email: 'user_email'
|
||||
},
|
||||
sys_role: {
|
||||
role_code: 'sys_rolecode'
|
||||
},
|
||||
sys_dict: {
|
||||
dict_code: 'sys_dictcode'
|
||||
},
|
||||
sys_depart: {
|
||||
depart_name: 'depart_name'
|
||||
},
|
||||
sys_check_rule: {
|
||||
rule_code: 'check_rule_code'
|
||||
},
|
||||
sys_data_source: {
|
||||
code: 'data_source_code'
|
||||
},
|
||||
sys_fill_rule: {
|
||||
rule_code: 'fill_rule_code'
|
||||
},
|
||||
sys_sms_template: {
|
||||
template_code: 'sms_template_code'
|
||||
}
|
||||
}
|
||||
if (map[tableName] && map[tableName][fieldName]) {
|
||||
return map[tableName][fieldName]
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
import { httpAction } from '@/api/manage'
|
||||
import pick from 'lodash.pick'
|
||||
import { duplicateCheck } from '@/api/api'
|
||||
import { getConfusionCode } from '@/utils/util'
|
||||
|
||||
export default {
|
||||
name: 'SysMessageTemplateModal',
|
||||
@@ -184,9 +185,11 @@ export default {
|
||||
})
|
||||
},
|
||||
validateTemplateCode (rule, value, callback) {
|
||||
const confusionCode = getConfusionCode('sys_sms_template', 'template_code')
|
||||
const params = {
|
||||
tableName: 'sys_sms_template',
|
||||
fieldName: 'template_code',
|
||||
// tableName: 'sys_sms_template',
|
||||
// fieldName: 'template_code',
|
||||
confusionCode,
|
||||
fieldVal: value,
|
||||
dataId: this.model.id
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
<script>
|
||||
import { addRole, editRole, duplicateCheck } from '@/api/api'
|
||||
import { getConfusionCode } from '@/utils/util'
|
||||
|
||||
export default {
|
||||
name: 'RoleModal',
|
||||
@@ -113,9 +114,11 @@ export default {
|
||||
if (/[\u4E00-\u9FA5]/g.test(value)) {
|
||||
callback(new Error(this.$t('roleManage.roleCodeNotChinese')))
|
||||
} else {
|
||||
const confusionCode = getConfusionCode('sys_role', 'role_code')
|
||||
const params = {
|
||||
tableName: 'sys_role',
|
||||
fieldName: 'role_code',
|
||||
// tableName: 'sys_role',
|
||||
// fieldName: 'role_code',
|
||||
confusionCode,
|
||||
fieldVal: value,
|
||||
dataId: this.model.id
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ export default {
|
||||
ruleName: [{ required: true, message: '请输入规则名称!' }],
|
||||
ruleCode: [
|
||||
{ required: true, message: '请输入规则Code!' },
|
||||
{ validator: (rule, value, callback) => validateDuplicateValue('sys_check_rule', 'rule_code', value, this.model.id, callback) }
|
||||
{ validator: (rule, value, callback) => validateDuplicateValue(false, 'sys_check_rule', 'rule_code', value, this.model.id, callback) }
|
||||
]
|
||||
},
|
||||
tabs: {
|
||||
|
||||
@@ -107,7 +107,7 @@ export default {
|
||||
if (!pattern.test(value)) {
|
||||
callback(new Error('编码必须以字母开头,可包含数字、下划线、横杠'))
|
||||
} else {
|
||||
validateDuplicateValue('sys_data_source', 'code', value, this.model.id, callback)
|
||||
validateDuplicateValue(false, 'sys_data_source', 'code', value, this.model.id, callback)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export default {
|
||||
ruleName: [{ required: true, message: '规则名称不能为空' }],
|
||||
ruleCode: [
|
||||
{ required: true, message: '规则Code不能为空' },
|
||||
{ validator: (rule, value, callback) => validateDuplicateValue('sys_fill_rule', 'rule_code', value, this.model.id, callback) }
|
||||
{ validator: (rule, value, callback) => validateDuplicateValue(false, 'sys_fill_rule', 'rule_code', value, this.model.id, callback) }
|
||||
],
|
||||
ruleClass: [{ required: true, message: '规则实现类不能为空' }],
|
||||
ruleParams: [{
|
||||
@@ -68,7 +68,7 @@ export default {
|
||||
info = '请输入JSON字符串'
|
||||
callback(info)
|
||||
}
|
||||
} catch {
|
||||
} catch (err) {
|
||||
info = '请输入JSON字符串'
|
||||
callback(info)
|
||||
}
|
||||
|
||||
@@ -175,6 +175,7 @@ import { disabledAuthFilter } from '@/utils/authFilter'
|
||||
import { getRSAPublicKey } from '@/utils/encryption.js'
|
||||
import { JSEncrypt } from 'jsencrypt'
|
||||
import JMultiSelectTag from '../../../components/dict/JMultiSelectTag'
|
||||
import { getConfusionCode } from '@/utils/util'
|
||||
|
||||
export default {
|
||||
name: 'UserModal',
|
||||
@@ -200,7 +201,7 @@ export default {
|
||||
pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,./]).{8,}$/,
|
||||
message: this.$t('user.passwordConsists')
|
||||
},
|
||||
{ validator: this.validateToNextPassword, trigger: 'change' }],
|
||||
{ validator: this.validateToNextPassword, trigger: 'change' }],
|
||||
confirmpassword: [{ required: true, message: this.$t('user.reenterLoginPassword') },
|
||||
{ validator: this.compareToFirstPassword }],
|
||||
realname: [{ required: true, message: this.$t('pleaseEnter') + this.$t('user.userName') }],
|
||||
@@ -436,9 +437,11 @@ export default {
|
||||
callback()
|
||||
} else {
|
||||
if (new RegExp(/^1[345789][0-9]\d{8}$/).test(value)) {
|
||||
const confusionCode = getConfusionCode('sys_user', 'phone')
|
||||
const params = {
|
||||
tableName: 'sys_user',
|
||||
fieldName: 'phone',
|
||||
// tableName: 'sys_user',
|
||||
// fieldName: 'phone',
|
||||
confusionCode,
|
||||
fieldVal: value,
|
||||
dataId: this.userId
|
||||
}
|
||||
@@ -459,9 +462,11 @@ export default {
|
||||
callback()
|
||||
} else {
|
||||
if (new RegExp(/^\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/).test(value)) {
|
||||
const confusionCode = getConfusionCode('sys_user', 'email')
|
||||
const params = {
|
||||
tableName: 'sys_user',
|
||||
fieldName: 'email',
|
||||
// tableName: 'sys_user',
|
||||
// fieldName: 'email',
|
||||
confusionCode,
|
||||
fieldVal: value,
|
||||
dataId: this.userId
|
||||
}
|
||||
@@ -479,9 +484,11 @@ export default {
|
||||
}
|
||||
},
|
||||
validateUsername (rule, value, callback) {
|
||||
const confusionCode = getConfusionCode('sys_user', 'username')
|
||||
const params = {
|
||||
tableName: 'sys_user',
|
||||
fieldName: 'username',
|
||||
// tableName: 'sys_user',
|
||||
// fieldName: 'username',
|
||||
confusionCode,
|
||||
fieldVal: value,
|
||||
dataId: this.userId
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
import JDictSelectTag from '../../../../components/dict/JDictSelectTag'
|
||||
import { addDict, duplicateCheck, editDict } from '../../../../api/api'
|
||||
import { IsReadOnlyEnums } from '../../../../enums/commonEnums'
|
||||
import { getConfusionCode } from '@/utils/util'
|
||||
|
||||
export default {
|
||||
name: 'TagContentModal',
|
||||
@@ -168,10 +169,12 @@ export default {
|
||||
}
|
||||
},
|
||||
validateDictCode (rule, value, callback) {
|
||||
const confusionCode = getConfusionCode('sys_dict', 'dict_code')
|
||||
// 重复校验
|
||||
const params = {
|
||||
tableName: 'sys_dict',
|
||||
fieldName: 'dict_code',
|
||||
// tableName: 'sys_dict',
|
||||
// fieldName: 'dict_code',
|
||||
confusionCode,
|
||||
fieldVal: value,
|
||||
dataId: this.model.id
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user