Commit 55ec2270 by jianshuqin

优化:组件功能

parent 6123a96d
...@@ -5,6 +5,11 @@ namespace Bailun.DC.Models.Component.DTO ...@@ -5,6 +5,11 @@ namespace Bailun.DC.Models.Component.DTO
public class FormDTO public class FormDTO
{ {
/// <summary> /// <summary>
/// Id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 编码 /// 编码
/// </summary> /// </summary>
public string Code { get; set; } public string Code { get; set; }
...@@ -60,6 +65,11 @@ namespace Bailun.DC.Models.Component.DTO ...@@ -60,6 +65,11 @@ namespace Bailun.DC.Models.Component.DTO
public bool? IsValidate { get; set; } public bool? IsValidate { get; set; }
/// <summary> /// <summary>
/// 是否可以移动:(默认可以)
/// </summary>
public bool? IsDrag { get; set; }
/// <summary>
/// 保存脚本 /// 保存脚本
/// </summary> /// </summary>
public string SaveScript { get; set; } public string SaveScript { get; set; }
......
using System; using Dapper;
using System;
namespace Bailun.DC.Models.Component.Entity namespace Bailun.DC.Models.Component.Entity
{ {
...@@ -105,6 +106,7 @@ namespace Bailun.DC.Models.Component.Entity ...@@ -105,6 +106,7 @@ namespace Bailun.DC.Models.Component.Entity
/// <summary> /// <summary>
/// 创建时间 /// 创建时间
/// </summary> /// </summary>
[IgnoreUpdate]
public DateTime gmt_create { get; set; } public DateTime gmt_create { get; set; }
/// <summary> /// <summary>
......
using Bailun.DC.Models.Component.DTO; using Bailun.DC.Models.Component.DTO;
using Bailun.DC.Models.Component.Entity; using Bailun.DC.Models.Component.Entity;
using Dapper; using Dapper;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using System;
using System.Linq;
namespace Bailun.DC.Services.Component namespace Bailun.DC.Services.Component
{ {
...@@ -31,6 +35,7 @@ namespace Bailun.DC.Services.Component ...@@ -31,6 +35,7 @@ namespace Bailun.DC.Services.Component
{ {
dto = new FormDTO dto = new FormDTO
{ {
Id = entity.id,
Code = entity.code, Code = entity.code,
Name = entity.name, Name = entity.name,
Width = entity.width, Width = entity.width,
...@@ -42,6 +47,7 @@ namespace Bailun.DC.Services.Component ...@@ -42,6 +47,7 @@ namespace Bailun.DC.Services.Component
CancelButtonText = entity.cancel_button_text, CancelButtonText = entity.cancel_button_text,
Justify = entity.justify, Justify = entity.justify,
IsValidate = entity.is_validate, IsValidate = entity.is_validate,
IsDrag = entity.is_drag,
SaveScript = entity.save_script, SaveScript = entity.save_script,
javascript = entity.javascript, javascript = entity.javascript,
ListFormItem = !string.IsNullOrWhiteSpace(entity.form_item) ? DeserializeCollection<dynamic>(entity.form_item) : null, ListFormItem = !string.IsNullOrWhiteSpace(entity.form_item) ? DeserializeCollection<dynamic>(entity.form_item) : null,
...@@ -53,5 +59,167 @@ namespace Bailun.DC.Services.Component ...@@ -53,5 +59,167 @@ namespace Bailun.DC.Services.Component
return dto; return dto;
} }
/// <summary>
/// 保存报表组件
/// </summary>
/// <param name="dto">报表组件对象</param>
/// <returns>保存结果</returns>
public ResultDTO Save(FormDTO dto)
{
ResultDTO result = this.BeforeSave(dto);
if (result.Result)
{
dc_component_form entity = new dc_component_form()
{
id = dto.Id,
code = dto.Code,
name = dto.Name,
width = dto.Width,
label_width = dto.LabelWidth,
is_show_border = dto.IsShowBorder,
is_show_save_button = dto.IsShowSaveButton,
save_button_text = dto.SaveButtonText,
is_show_cancel_button = dto.IsShowCancelButton,
cancel_button_text = dto.CancelButtonText,
justify = dto.Justify,
is_validate = dto.IsValidate,
is_drag = dto.IsDrag,
save_script = dto.SaveScript,
javascript = dto.javascript,
gmt_create = DateTime.Now,
gmt_modified = DateTime.Now,
form_item = dto.ListFormItem?.Count() > 0 ? JsonConvert.SerializeObject(dto.ListFormItem) : null,
controls = dto.ListControl?.Count() > 0 ? JsonConvert.SerializeObject(dto.ListControl) : null,
javascript_src = dto.ListJavascriptSrc?.Where(l => !string.IsNullOrWhiteSpace(l)).Count() > 0 ? JsonConvert.SerializeObject(dto.ListJavascriptSrc) : null
};
using (var db = DB)
{
//开启事务
MySqlTransaction transaction = db.BeginTransaction();
try
{
int? resultCount = entity.id > 0 ? db.Update(entity) : db.Insert(entity);
if (resultCount == 0)
{
throw new Exception("保存失败");
}
else
{
//提交事务
transaction.Commit();
result.Message = "保存成功";
}
}
catch (Exception ex)
{
//回滚事务
transaction.Rollback();
result.Message = ex.Message;
result.Result = false;
}
}
}
return result;
}
/// <summary>
/// 保存报表组件
/// </summary>
/// <param name="id">ID</param>
/// <param name="is_delete">是否删除</param>
/// <returns>保存结果</returns>
public ResultDTO Save(int[] id, bool is_delete)
{
ResultDTO result = this.BeforeSave(id);
if (result.Result)
{
string sql = "update dc_component_form set is_delete = @is_delete, gmt_modified = @gmt_modified where id in @id";
using (var db = DB)
{
//开启事务
MySqlTransaction transaction = db.BeginTransaction();
try
{
int resultCount = db.Execute(sql, new { id = id, is_delete = is_delete, gmt_modified = DateTime.Now });
if (resultCount == 0)
{
throw new Exception("保存失败");
}
else
{
//提交事务
transaction.Commit();
result.Message = "保存成功";
}
}
catch (Exception ex)
{
//回滚事务
transaction.Rollback();
result.Message = ex.Message;
result.Result = false;
}
}
}
return result;
}
/// <summary>
/// 保存报表组件
/// </summary>
/// <param name="dto">报表组件对象</param>
/// <returns>保存结果</returns>
private ResultDTO BeforeSave(FormDTO dto)
{
ResultDTO result = new ResultDTO();
if (dto == null)
{
result.Message = "参数有误";
}
else if (string.IsNullOrWhiteSpace(dto.Code))
{
result.Message = "编码不能为空";
}
else if (string.IsNullOrWhiteSpace(dto.Name))
{
result.Message = "名称不能为空";
}
else if (string.IsNullOrWhiteSpace(dto.Name))
{
result.Message = "名称不能为空";
}
else
{
result.Result = true;
}
return result;
}
/// <summary>
/// 保存报表组件
/// </summary>
/// <param name="id">ID</param>
/// <returns>保存结果</returns>
private ResultDTO BeforeSave(int[] id)
{
ResultDTO result = new ResultDTO();
if (id == null || id.Length == 0 || id.Contains(0))
{
result.Message = "ID不能为空";
}
else
{
result.Result = true;
}
return result;
}
} }
} }
...@@ -25,5 +25,55 @@ namespace Bailun.DC.Web.Areas.Component.Controllers ...@@ -25,5 +25,55 @@ namespace Bailun.DC.Web.Areas.Component.Controllers
return Json(result); return Json(result);
} }
[HttpPost]
public JsonResult Save([FromBody]FormDTO dto)
{
ResultDTO result = default(ResultDTO);
try
{
result = new FormService().Save(dto);
}
catch (Exception ex)
{
result = new ResultDTO() { Message = ex.Message };
}
return Json(result);
}
[HttpPost]
public JsonResult Enable(int[] id)
{
ResultDTO result = default(ResultDTO);
try
{
result = new FormService().Save(id, true);
}
catch (Exception ex)
{
result = new ResultDTO() { Message = ex.Message };
}
return Json(result);
}
[HttpPost]
public JsonResult Disable(int[] id)
{
ResultDTO result = default(ResultDTO);
try
{
result = new FormService().Save(id, false);
}
catch (Exception ex)
{
result = new ResultDTO() { Message = ex.Message };
}
return Json(result);
}
} }
} }
...@@ -87,7 +87,7 @@ namespace Bailun.DC.Web.Areas.Component.Controllers ...@@ -87,7 +87,7 @@ namespace Bailun.DC.Web.Areas.Component.Controllers
} }
[HttpPost] [HttpPost]
public JsonResult Save(TableDTO dto) public JsonResult Save([FromBody] TableDTO dto)
{ {
ResultDTO result = default(ResultDTO); ResultDTO result = default(ResultDTO);
try try
......
<el-container class="el-dialog-form"> <el-container class="el-dialog-form">
<el-dialog ref="dialog" <el-dialog ref="dialog"
top="15px"
class="el-dialog-form" class="el-dialog-form"
el-dialog el-dialog
append-to-body append-to-body
......
...@@ -128,17 +128,17 @@ ...@@ -128,17 +128,17 @@
v-on:change="javaScript.call(this,item.onchange,$event)"> v-on:change="javaScript.call(this,item.onchange,$event)">
</el-upload-form> </el-upload-form>
<template v-else-if="item.type == 'table' && item.code"> <template v-else-if="item.type == 'table' && item.code">
<el-button v-if="!item.value || !item.value.length" <el-button v-if="!item_value || !item_value.length"
type="success" type="success"
icon="el-icon-plus" icon="el-icon-plus"
v-bind:size="item.size || 'small'" v-bind:size="item.size || 'small'"
v-on:click="$set(item,'value',[]);item.value.push({});"> v-on:click="onClick">
{{"新增"}} {{"新增"}}
</el-button> </el-button>
<el-table-control ref="table" <el-table-control ref="table"
v-else v-else
v-bind:code="item.code" v-bind:code="item.code"
v-model="item.value" v-model="item_value"
v-on:show-dialog="showDialog"> v-on:show-dialog="showDialog">
</el-table-control> </el-table-control>
</template> </template>
...@@ -147,7 +147,7 @@ ...@@ -147,7 +147,7 @@
v-bind:style="item.color ? 'color:' + item.color: ''">{{item.value}}</span> v-bind:style="item.color ? 'color:' + item.color: ''">{{item.value}}</span>
</template> </template>
<template v-else-if="item_value != null"> <template v-else-if="item_value != null">
{{ item.format ? (item_value.constructor === Boolean ? (item_value ? '是' : '否') :(new Date(item_value).format(item.format))) : item_value}} {{ item.format ? (item_value.constructor === Boolean || item_value == 1 || item_value == 0 ? (item_value ? '是' : '否') :(new Date(item_value).format(item.format))) : item_value}}
</template> </template>
</span> </span>
</script> </script>
......
...@@ -78,6 +78,14 @@ ...@@ -78,6 +78,14 @@
v-bind:key="index" v-bind:key="index"
v-bind:width="column.width || ''" v-bind:width="column.width || ''"
v-bind:min-width="!column.width && ((column.name || ' ').length * 15 + 45)"> v-bind:min-width="!column.width && ((column.name || ' ').length * 15 + 45)">
<template slot-scope="scope">
<el-form-control v-model="scope.row[column.prop]"
v-bind:item="column"
v-bind:scope="scope"
v-on:click="javaScript.call(scope,column.click,scope)"
v-on:change="javaScript.call(scope,column.change,scope)">
</el-form-control>
</template>
</el-table-column> </el-table-column>
<template slot-scope="scope"> <template slot-scope="scope">
<el-form-control v-model="scope.row[column.prop]" <el-form-control v-model="scope.row[column.prop]"
......
...@@ -35,11 +35,17 @@ ...@@ -35,11 +35,17 @@
loading: false loading: false
}, },
methods: { methods: {
onShowDialog(title, form, code) { //显示弹窗
onShowDialog: function (title, form, code) {
this.$refs.dialogForm.showDialog(title, form, code); this.$refs.dialogForm.showDialog(title, form, code);
}, },
onCloseDialog(title, form, code) { //关闭弹窗
onCloseDialog: function (title, form, code) {
this.$refs.dialogForm.closeDialog(); this.$refs.dialogForm.closeDialog();
},
//查询数据
onSearch: function () {
this.$refs.tableQuery.onSearch();
} }
} }
}) })
...@@ -47,6 +53,6 @@ ...@@ -47,6 +53,6 @@
</script> </script>
} }
<div id="app" v-cloak> <div id="app" v-cloak>
<el-table-query v-bind:code="code" v-on:show-dialog="onShowDialog" v-on:close-dialog="onCloseDialog"></el-table-query> <el-table-query v-bind:code="code" ref="tableQuery" v-on:show-dialog="onShowDialog" v-on:close-dialog="onCloseDialog"></el-table-query>
<el-dialog-form v-bind:code="code" ref="dialogForm"></el-dialog-form> <el-dialog-form v-bind:code="code" ref="dialogForm"></el-dialog-form>
</div> </div>
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
<el-table-control ref="table" <el-table-control ref="table"
v-bind:code="code" v-bind:code="code"
v-bind:filterParams="filterParams" v-bind:filterParams="filterParams"
v-on:init="onInit"></el-table-control> v-on:init="onInit"
v-on:show-dialog="showDialog"
v-on:close-dialog="closeDialog"></el-table-control>
</el-main> </el-main>
<el-footer> <el-footer>
<el-pagination background layout="total,sizes,jumper,prev, pager, next" <el-pagination background layout="total,sizes,jumper,prev, pager, next"
......
...@@ -51,3 +51,7 @@ ...@@ -51,3 +51,7 @@
.el-dialog-form .el-form-control .el-input-number { .el-dialog-form .el-form-control .el-input-number {
width: 100%; width: 100%;
} }
.el-dialog__wrapper.el-dialog-form {
overflow: hidden;
}
...@@ -11,3 +11,7 @@ ...@@ -11,3 +11,7 @@
color: #3a8ee6; color: #3a8ee6;
margin: 0px 5px; margin: 0px 5px;
} }
.el-table-control .el-table__header th.el-table__cell {
padding: 0px;
}
...@@ -91,8 +91,8 @@ ...@@ -91,8 +91,8 @@
} else { } else {
isvalid = true isvalid = true
} }
if (isvalid && that.dialog.submitScript) { if (isvalid && that.dialog.saveScript) {
that.javaScript.call(that, that.dialog.submitScript, that.form) that.javaScript.call(that, that.dialog.saveScript, that.form)
} }
}, },
// //
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
//是否禁用 //是否禁用
disabled: { disabled: {
default: null default: null
},
//表单
form: {
default: null
} }
}, },
//双向绑定 //双向绑定
...@@ -163,6 +167,12 @@ ...@@ -163,6 +167,12 @@
//弹出窗 //弹出窗
showDialog(title, form, code) { showDialog(title, form, code) {
}, },
//单击事件
onClick: function () {
var that = this;
Vue.set(that, 'item_value', []);
that.item_value.push({});
}
}, },
template: '#elFormControl' template: '#elFormControl'
}); });
\ No newline at end of file
...@@ -59,6 +59,14 @@ ...@@ -59,6 +59,14 @@
}) })
} }
}, },
//关闭弹出窗
closeDialog() {
this.$emit("close-dialog")
},
//弹出窗
showDialog(title, form, code) {
this.$emit("show-dialog", title, form, code)
},
//获取表单组件信息 //获取表单组件信息
getTable: function () { getTable: function () {
var that = this; var that = this;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment