feat: 角色删除code字段 表单增加重复验证

This commit is contained in:
fit2cloud-chenyw 2021-04-30 11:05:59 +08:00
parent 54f43559bf
commit e0a6ae7962
8 changed files with 49 additions and 108 deletions

View File

@ -9,7 +9,7 @@ public class CurrentRoleDto implements Serializable {
private Long id;
private String code;
// private String code;
private String name;
}

View File

@ -7,8 +7,6 @@ import lombok.Data;
public class SysRole implements Serializable {
private Long roleId;
private String code;
private String name;
private String description;

View File

@ -164,76 +164,6 @@ public class SysRoleExample {
return (Criteria) this;
}
public Criteria andCodeIsNull() {
addCriterion("code is null");
return (Criteria) this;
}
public Criteria andCodeIsNotNull() {
addCriterion("code is not null");
return (Criteria) this;
}
public Criteria andCodeEqualTo(String value) {
addCriterion("code =", value, "code");
return (Criteria) this;
}
public Criteria andCodeNotEqualTo(String value) {
addCriterion("code <>", value, "code");
return (Criteria) this;
}
public Criteria andCodeGreaterThan(String value) {
addCriterion("code >", value, "code");
return (Criteria) this;
}
public Criteria andCodeGreaterThanOrEqualTo(String value) {
addCriterion("code >=", value, "code");
return (Criteria) this;
}
public Criteria andCodeLessThan(String value) {
addCriterion("code <", value, "code");
return (Criteria) this;
}
public Criteria andCodeLessThanOrEqualTo(String value) {
addCriterion("code <=", value, "code");
return (Criteria) this;
}
public Criteria andCodeLike(String value) {
addCriterion("code like", value, "code");
return (Criteria) this;
}
public Criteria andCodeNotLike(String value) {
addCriterion("code not like", value, "code");
return (Criteria) this;
}
public Criteria andCodeIn(List<String> values) {
addCriterion("code in", values, "code");
return (Criteria) this;
}
public Criteria andCodeNotIn(List<String> values) {
addCriterion("code not in", values, "code");
return (Criteria) this;
}
public Criteria andCodeBetween(String value1, String value2) {
addCriterion("code between", value1, value2, "code");
return (Criteria) this;
}
public Criteria andCodeNotBetween(String value1, String value2) {
addCriterion("code not between", value1, value2, "code");
return (Criteria) this;
}
public Criteria andNameIsNull() {
addCriterion("`name` is null");
return (Criteria) this;

View File

@ -3,7 +3,6 @@
<mapper namespace="io.dataease.base.mapper.SysRoleMapper">
<resultMap id="BaseResultMap" type="io.dataease.base.domain.SysRole">
<id column="role_id" jdbcType="BIGINT" property="roleId" />
<result column="code" jdbcType="VARCHAR" property="code" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
@ -70,7 +69,7 @@
</where>
</sql>
<sql id="Base_Column_List">
role_id, code, `name`, description, create_by, update_by, create_time, update_time
role_id, `name`, description, create_by, update_by, create_time, update_time
</sql>
<select id="selectByExample" parameterType="io.dataease.base.domain.SysRoleExample" resultMap="BaseResultMap">
select
@ -103,12 +102,12 @@
</if>
</delete>
<insert id="insert" parameterType="io.dataease.base.domain.SysRole">
insert into sys_role (role_id, code, `name`,
description, create_by, update_by,
create_time, update_time)
values (#{roleId,jdbcType=BIGINT}, #{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, #{updateBy,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT})
insert into sys_role (role_id, `name`, description,
create_by, update_by, create_time,
update_time)
values (#{roleId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
#{createBy,jdbcType=VARCHAR}, #{updateBy,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" parameterType="io.dataease.base.domain.SysRole">
insert into sys_role
@ -116,9 +115,6 @@
<if test="roleId != null">
role_id,
</if>
<if test="code != null">
code,
</if>
<if test="name != null">
`name`,
</if>
@ -142,9 +138,6 @@
<if test="roleId != null">
#{roleId,jdbcType=BIGINT},
</if>
<if test="code != null">
#{code,jdbcType=VARCHAR},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
@ -177,9 +170,6 @@
<if test="record.roleId != null">
role_id = #{record.roleId,jdbcType=BIGINT},
</if>
<if test="record.code != null">
code = #{record.code,jdbcType=VARCHAR},
</if>
<if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR},
</if>
@ -206,7 +196,6 @@
<update id="updateByExample" parameterType="map">
update sys_role
set role_id = #{record.roleId,jdbcType=BIGINT},
code = #{record.code,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
description = #{record.description,jdbcType=VARCHAR},
create_by = #{record.createBy,jdbcType=VARCHAR},
@ -220,9 +209,6 @@
<update id="updateByPrimaryKeySelective" parameterType="io.dataease.base.domain.SysRole">
update sys_role
<set>
<if test="code != null">
code = #{code,jdbcType=VARCHAR},
</if>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
@ -246,8 +232,7 @@
</update>
<update id="updateByPrimaryKey" parameterType="io.dataease.base.domain.SysRole">
update sys_role
set code = #{code,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
set `name` = #{name,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
create_by = #{createBy,jdbcType=VARCHAR},
update_by = #{updateBy,jdbcType=VARCHAR},

View File

@ -15,7 +15,6 @@
<resultMap id="roleMap" type="io.dataease.auth.api.dto.CurrentRoleDto" >
<id column="role_id" property="id"/>
<result column="code" jdbcType="VARCHAR" property="code"/>
<result column="name" jdbcType="VARCHAR" property="name" />
</resultMap>
@ -29,7 +28,7 @@
</select>
<select id="roleCodes" resultType="String">
select r.code from sys_role r
select r.id from sys_role r
left join sys_users_roles sur on sur.role_id = r.role_id
where sur.user_id = #{userId}
</select>
@ -43,7 +42,7 @@
</select>
<select id="roles" resultMap="roleMap">
select r.role_id, r.code, r.name
select r.role_id, r.name
from sys_role r
left join sys_users_roles sur on sur.role_id = r.role_id
where sur.user_id = #{userId}

View File

@ -67,7 +67,7 @@
<!-- <table tableName="datasource"/>-->
<!-- <table tableName="sys_dict"/>-->
<!-- <table tableName="sys_dict_item"/>-->
<table tableName="dataset_table_field"/>
<table tableName="sys_role"/>
<!-- <table tableName="panel_design"/>-->

View File

@ -5,9 +5,9 @@
<el-input v-model="form.name" />
</el-form-item>
<el-form-item label="角色代码" prop="code">
<!-- <el-form-item label="角色代码" prop="code">
<el-input v-model="form.code" :disabled="formType !== 'add'" />
</el-form-item>
</el-form-item> -->
<el-form-item label="描述信息" prop="description">
<el-input v-model="form.description" type="textarea" />
@ -23,19 +23,22 @@
<script>
import LayoutContent from '@/components/business/LayoutContent'
import { addRole, editRole } from '@/api/system/role'
import { addRole, editRole, allRoles } from '@/api/system/role'
export default {
components: { LayoutContent },
data() {
return {
formType: 'add',
form: {},
rule: {
name: [
{ required: true, message: '请输入名称', trigger: 'blur' }
{ required: true, trigger: 'blur', validator: this.roleValidator }
],
code: [{ required: true, message: '请输入代码', trigger: 'blur' }]
}
},
roles: [],
originName: null
}
},
@ -46,6 +49,7 @@ export default {
} else {
this.create()
}
this.queryAllRoles()
},
methods: {
create() {
@ -54,6 +58,7 @@ export default {
edit(row) {
this.formType = 'modify'
this.form = Object.assign({}, row)
this.originName = row.name
},
reset() {
@ -72,6 +77,30 @@ export default {
}
})
},
queryAllRoles() {
allRoles().then(res => {
this.roles = res.data
})
},
nameRepeat(value) {
if (!this.roles || this.roles.length === 0) {
return false
}
//
if (this.formType === 'modify' && this.originName === value) {
return false
}
return this.roles.some(role => role.name === value)
},
roleValidator(rule, value, callback) {
if (!value || value.length === 0) {
callback(new Error('请输入名称'))
} else if (this.nameRepeat(value)) {
callback(new Error('角色名称已存在'))
} else {
callback()
}
},
backToList() {
this.$router.push({ name: '角色管理' })
}

View File

@ -18,7 +18,7 @@
</template>
<el-table-column prop="name" label="名称" />
<el-table-column prop="code" label="代码" />
<!-- <el-table-column prop="code" label="代码" /> -->
<el-table-column :show-overflow-tooltip="true" prop="createTime" label="创建日期">
<template v-slot:default="scope">
<span>{{ scope.row.createTime | timestampFormatDate }}</span>
@ -61,9 +61,9 @@
<el-input v-model="form.name" style="width: 380px;" />
</el-form-item>
<el-form-item label="角色代码" prop="code">
<!-- <el-form-item label="角色代码" prop="code">
<el-input v-model="form.code" style="width: 380px;" />
</el-form-item>
</el-form-item> -->
<el-form-item label="描述信息" prop="description">
<el-input v-model="form.description" style="width: 380px;" rows="5" type="textarea" />