Commit 55ec2270 by jianshuqin

优化:组件功能

parent 6123a96d
......@@ -5,6 +5,11 @@ namespace Bailun.DC.Models.Component.DTO
public class FormDTO
{
/// <summary>
/// Id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 编码
/// </summary>
public string Code { get; set; }
......@@ -60,6 +65,11 @@ namespace Bailun.DC.Models.Component.DTO
public bool? IsValidate { get; set; }
/// <summary>
/// 是否可以移动:(默认可以)
/// </summary>
public bool? IsDrag { get; set; }
/// <summary>
/// 保存脚本
/// </summary>
public string SaveScript { get; set; }
......
using System;
using Dapper;
using System;
namespace Bailun.DC.Models.Component.Entity
{
......@@ -105,6 +106,7 @@ namespace Bailun.DC.Models.Component.Entity
/// <summary>
/// 创建时间
/// </summary>
[IgnoreUpdate]
public DateTime gmt_create { get; set; }
/// <summary>
......
using Bailun.DC.Models.Component.DTO;
using Bailun.DC.Models.Component.Entity;
using Dapper;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using System;
using System.Linq;
namespace Bailun.DC.Services.Component
{
......@@ -31,6 +35,7 @@ namespace Bailun.DC.Services.Component
{
dto = new FormDTO
{
Id = entity.id,
Code = entity.code,
Name = entity.name,
Width = entity.width,
......@@ -42,6 +47,7 @@ namespace Bailun.DC.Services.Component
CancelButtonText = entity.cancel_button_text,
Justify = entity.justify,
IsValidate = entity.is_validate,
IsDrag = entity.is_drag,
SaveScript = entity.save_script,
javascript = entity.javascript,
ListFormItem = !string.IsNullOrWhiteSpace(entity.form_item) ? DeserializeCollection<dynamic>(entity.form_item) : null,
......@@ -53,5 +59,167 @@ namespace Bailun.DC.Services.Component
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
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
}
[HttpPost]
public JsonResult Save(TableDTO dto)
public JsonResult Save([FromBody] TableDTO dto)
{
ResultDTO result = default(ResultDTO);
try
......
<el-container class="el-dialog-form">
<el-dialog ref="dialog"
top="15px"
class="el-dialog-form"
el-dialog
append-to-body
......
......@@ -128,17 +128,17 @@
v-on:change="javaScript.call(this,item.onchange,$event)">
</el-upload-form>
<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"
icon="el-icon-plus"
v-bind:size="item.size || 'small'"
v-on:click="$set(item,'value',[]);item.value.push({});">
v-on:click="onClick">
{{"新增"}}
</el-button>
<el-table-control ref="table"
v-else
v-bind:code="item.code"
v-model="item.value"
v-model="item_value"
v-on:show-dialog="showDialog">
</el-table-control>
</template>
......@@ -147,7 +147,7 @@
v-bind:style="item.color ? 'color:' + item.color: ''">{{item.value}}</span>
</template>
<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>
</span>
</script>
......
......@@ -78,6 +78,14 @@
v-bind:key="index"
v-bind:width="column.width || ''"
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>
<template slot-scope="scope">
<el-form-control v-model="scope.row[column.prop]"
......
......@@ -35,11 +35,17 @@
loading: false
},
methods: {
onShowDialog(title, form, code) {
//显示弹窗
onShowDialog: function (title, form, code) {
this.$refs.dialogForm.showDialog(title, form, code);
},
onCloseDialog(title, form, code) {
//关闭弹窗
onCloseDialog: function (title, form, code) {
this.$refs.dialogForm.closeDialog();
},
//查询数据
onSearch: function () {
this.$refs.tableQuery.onSearch();
}
}
})
......@@ -47,6 +53,6 @@
</script>
}
<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>
</div>
......@@ -13,7 +13,9 @@
<el-table-control ref="table"
v-bind:code="code"
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-footer>
<el-pagination background layout="total,sizes,jumper,prev, pager, next"
......
......@@ -51,3 +51,7 @@
.el-dialog-form .el-form-control .el-input-number {
width: 100%;
}
.el-dialog__wrapper.el-dialog-form {
overflow: hidden;
}
......@@ -11,3 +11,7 @@
color: #3a8ee6;
margin: 0px 5px;
}
.el-table-control .el-table__header th.el-table__cell {
padding: 0px;
}
......@@ -91,8 +91,8 @@
} else {
isvalid = true
}
if (isvalid && that.dialog.submitScript) {
that.javaScript.call(that, that.dialog.submitScript, that.form)
if (isvalid && that.dialog.saveScript) {
that.javaScript.call(that, that.dialog.saveScript, that.form)
}
},
//
......
......@@ -15,6 +15,10 @@
//是否禁用
disabled: {
default: null
},
//表单
form: {
default: null
}
},
//双向绑定
......@@ -163,6 +167,12 @@
//弹出窗
showDialog(title, form, code) {
},
//单击事件
onClick: function () {
var that = this;
Vue.set(that, 'item_value', []);
that.item_value.push({});
}
},
template: '#elFormControl'
});
\ No newline at end of file
......@@ -59,6 +59,14 @@
})
}
},
//关闭弹出窗
closeDialog() {
this.$emit("close-dialog")
},
//弹出窗
showDialog(title, form, code) {
this.$emit("show-dialog", title, form, code)
},
//获取表单组件信息
getTable: function () {
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