Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加代码自动生成模块中,可以指定生成的字段 html UI宽度 的特性 #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public class GenTableColumn extends BaseEntity
/** 排序 */
private Integer sort;

/**
* UI宽度,单位:px
*/
private Integer width;

public void setColumnId(Long columnId)
{
this.columnId = columnId;
Expand Down Expand Up @@ -328,6 +333,14 @@ public boolean isSuperColumn()
return isSuperColumn(this.javaField);
}

public Integer getWidth() {
return width;
}

public void setWidth(Integer width) {
this.width = width;
}

public static boolean isSuperColumn(String javaField)
{
return StringUtils.equalsAnyIgnoreCase(javaField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.generator.mapper.GenTableColumnMapper">

<resultMap type="GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id" />
<result property="tableId" column="table_id" />
Expand All @@ -23,28 +23,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="htmlType" column="html_type" />
<result property="dictType" column="dict_type" />
<result property="sort" column="sort" />
<result property="width" column="width" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>

<sql id="selectGenTableColumnVo">
select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column
select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, width, create_by, create_time, update_by, update_time from gen_table_column
</sql>

<select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
<include refid="selectGenTableColumnVo"/>
where table_id = #{tableId}
order by sort
</select>

<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
order by ordinal_position
</select>

<insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
insert into gen_table_column (
<if test="tableId != null and tableId != ''">table_id,</if>
Expand All @@ -64,6 +65,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="htmlType != null and htmlType != ''">html_type,</if>
<if test="dictType != null and dictType != ''">dict_type,</if>
<if test="sort != null">sort,</if>
<if test="width != null">width,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
Expand All @@ -84,11 +86,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="htmlType != null and htmlType != ''">#{htmlType},</if>
<if test="dictType != null and dictType != ''">#{dictType},</if>
<if test="sort != null">#{sort},</if>
<if test="width != null">#{width},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>

<update id="updateGenTableColumn" parameterType="GenTableColumn">
update gen_table_column
<set>
Expand All @@ -104,21 +107,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
html_type = #{htmlType},
dict_type = #{dictType},
sort = #{sort},
width = #{width},
update_by = #{updateBy},
update_time = sysdate()
</set>
where column_id = #{columnId}
</update>

<delete id="deleteGenTableColumnByIds" parameterType="Long">
delete from gen_table_column where table_id in
delete from gen_table_column where table_id in
<foreach collection="array" item="tableId" open="(" separator="," close=")">
#{tableId}
</foreach>
</delete>

<delete id="deleteGenTableColumns">
delete from gen_table_column where column_id in
delete from gen_table_column where column_id in
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item.columnId}
</foreach>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="htmlType" column="html_type" />
<result property="dictType" column="dict_type" />
<result property="sort" column="sort" />
<result property="createBy" column="create_by" />
<result property="width" column="width" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
Expand Down Expand Up @@ -100,23 +101,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort, c.width
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
where t.table_id = #{tableId} order by c.sort
</select>

<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort, c.width
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
where t.table_name = #{tableName} order by c.sort
</select>

<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort, c.width
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
order by c.sort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,15 @@ <h4 class="form-header h4">其他信息</h4>
cellStyle: function(value, row, index) {
return { css: { "cursor": "default" } };
}
},
{
field: 'width',
title: 'UI宽度',
width: "5%",
formatter: function (value, row, index) {
var html = $.common.sprintf("<input class='form-control' type='text' name='columns[%s].width' value='%s'>", index, value);
return html;
}
}]
};
$.table.init(options);
Expand Down
60 changes: 46 additions & 14 deletions ruoyi-generator/src/main/resources/vm/html/list.html.vm
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,55 @@
#end
#if($column.htmlType == "input")
<li>
<label>${comment}:</label>
<input type="text" name="${column.javaField}"/>
#if($column.width && $column.width>0)
<label>${comment}:</label>
<input style="width:${column.width}px;" type="text" name="${column.javaField}"/>
#else
<label>${comment}:</label>
<input type="text" name="${column.javaField}"/>
#end
</li>
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
<li>
<label>${comment}:</label>
<select name="${column.javaField}" th:with="type=${@dict.getType('${dictType}')}">
<option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
#if($column.width && $column.width>0)
<label>${comment}:</label>
<select style="width:${column.width}px;" name="${column.javaField}" th:with="type=${@dict.getType('${dictType}')}">
<option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
#else
<label>${comment}:</label>
<select name="${column.javaField}" th:with="type=${@dict.getType('${dictType}')}">
<option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
#end
</li>
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
<li>
<label>${comment}:</label>
<select name="${column.javaField}">
<option value="">所有</option>
<option value="-1">代码生成请选择字典属性</option>
</select>
#if($column.width && $column.width>0)
<label>${comment}:</label>
<select style="width:${column.width}px;" name="${column.javaField}">
<option value="">所有</option>
<option value="-1">代码生成请选择字典属性</option>
</select>
#else
<label>${comment}:</label>
<select name="${column.javaField}">
<option value="">所有</option>
<option value="-1">代码生成请选择字典属性</option>
</select>
#end
</li>
#elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
<li>
<label>${comment}:</label>
<input type="text" class="time-input" placeholder="请选择${comment}" name="${column.javaField}"/>
#if($column.width && $column.width>0)
<label>${comment}:</label>
<input style="width:${column.width}px;" type="text" class="time-input" placeholder="请选择${comment}" name="${column.javaField}"/>
#else
<label>${comment}:</label>
<input type="text" class="time-input" placeholder="请选择${comment}" name="${column.javaField}"/>
#end
</li>
#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
<li class="select-time">
Expand Down Expand Up @@ -125,13 +151,19 @@
{
field: '${javaField}',
title: '${comment}',
#if($column.width && $column.width >0)
width: $column.width,
#end
formatter: function(value, row, index) {
return $.table.selectDictLabel#if($column.htmlType == "checkbox")s#end(${javaField}Datas, value);
}
},
#elseif($column.list && "" != $javaField)
{
field: '${javaField}',
#if($column.width && $column.width >0)
width: $column.width,
#end
title: '${comment}'
},
#end
Expand Down
1 change: 1 addition & 0 deletions sql/ry_20240228_addition_feature.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table gen_table_column add width smallint unsigned default null comment 'UI宽度,单位:px' after sort;