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 Long id;
private String code; // private String code;
private String name; private String name;
} }

View File

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

View File

@ -164,76 +164,6 @@ public class SysRoleExample {
return (Criteria) this; 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() { public Criteria andNameIsNull() {
addCriterion("`name` is null"); addCriterion("`name` is null");
return (Criteria) this; return (Criteria) this;

View File

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

View File

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

View File

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

View File

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

View File

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