From 04a557b6e68bc45b4da28ba490b8ed5e87b5435e Mon Sep 17 00:00:00 2001 From: yubaolee Date: Tue, 25 Feb 2025 15:52:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96CodeSmith=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CodeSmith/CSharp/Web/Index.cshtml.cst | 32 ++++---- CodeSmith/CSharp/Web/index.js.cst | 111 ++++++++++++-------------- 2 files changed, 67 insertions(+), 76 deletions(-) diff --git a/CodeSmith/CSharp/Web/Index.cshtml.cst b/CodeSmith/CSharp/Web/Index.cshtml.cst index 94c8e495..ceb6b43c 100644 --- a/CodeSmith/CSharp/Web/Index.cshtml.cst +++ b/CodeSmith/CSharp/Web/Index.cshtml.cst @@ -7,27 +7,22 @@ Description: 列表页面 <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="连接的数据库" %> <%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> - <%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> <%@ Assembly Name="SchemaExplorer" %> <%@ Import Namespace="SchemaExplorer" %> <%@ Assembly Src="Util.cs" %> <%@ Import Namespace="Util" %> - @section header { } -
-
- -
- <%} %> -
@@ -91,8 +90,5 @@ Description="连接的数据库" %>
- - - diff --git a/CodeSmith/CSharp/Web/index.js.cst b/CodeSmith/CSharp/Web/index.js.cst index 7e75f987..66bb566d 100644 --- a/CodeSmith/CSharp/Web/index.js.cst +++ b/CodeSmith/CSharp/Web/index.js.cst @@ -4,6 +4,8 @@ Author: yubaolee --%> <%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %> <%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> +<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" +Description="连接的数据库" %> <%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> <%@ Assembly Name="SchemaExplorer" %> @@ -13,9 +15,10 @@ Author: yubaolee layui.config({ base: "/js/" -}).use(['form', 'vue', 'ztree', 'layer', 'jquery', 'table', 'droptree', 'openauth', 'utils'], function () { +}).use(['form', 'laydate', 'ztree', 'layer', 'jquery', 'table', 'droptree', 'openauth', 'utils'], function () { var form = layui.form, layer = layui.layer, + laydate = layui.laydate, $ = layui.jquery; var table = layui.table; var openauth = layui.openauth; @@ -23,30 +26,49 @@ layui.config({ $("#menus").loadMenus("<%=ModuleName%>"); + <% foreach (ColumnSchema column in this.SourceTable.Columns) { + if(CSharpAlias[column.SystemType.FullName] == "System.DateTime") { %> + laydate.render({ + elem: '#<%=column.Name%>' + }); + <%} }%> + + var initVal = { //初始化的值 + <% foreach (ColumnSchema column in this.SourceTable.Columns) { + if(CSharpAlias[column.SystemType.FullName] == "bool") { %> + <%=column.Name%>: false, + <%}else if(CSharpAlias[column.SystemType.FullName] == "int" ) {%> + <%=column.Name%>: 0, + <%}else if(CSharpAlias[column.SystemType.FullName] == "System.DateTime") {%> + <%=column.Name%>: new Date().toISOString().split('T')[0], + <%} else {%> + <%=column.Name%>: '', + <%} }%> + } //加载表头 $.getJSON('/<%=ModuleName%>s/Load', - { page: 1, limit: 1 }, - function (data) { - var columns = data.columnFields.filter(u => u.IsList ===true).map(function (e) { - return { - field: e.ColumnName, - title: e.Remark - }; - }); - columns.unshift({ - type: 'checkbox', - fixed: 'left' - }); - table.render({ - elem: '#mainList', - page: true, - url: '/<%=ModuleName%>s/Load', - cols: [columns] - , response: { - statusCode: 200 //规定成功的状态码,默认:0 - } - }); + { page: 1, limit: 1 }, + function (data) { + var columns = data.columnFields.filter(u => u.IsList ===true).map(function (e) { + return { + field: e.ColumnName, + title: e.Remark + }; + }); + columns.unshift({ + type: 'checkbox', + fixed: 'left' + }); + table.render({ + elem: '#mainList', + page: true, + url: '/<%=ModuleName%>s/Load', + cols: [columns] + , response: { + statusCode: 200 //规定成功的状态码,默认:0 + } + }); }); @@ -69,9 +91,7 @@ layui.config({ //添加(编辑)对话框 var editDlg = function () { - var vm; - var update = false; //是否为更新 - var show = function (data) { + var show = function (update, data) { var title = update ? "编辑信息" : "添加"; layer.open({ title: title, @@ -79,32 +99,11 @@ layui.config({ type: 1, content: $('#divEdit'), success: function () { - if(vm == undefined){ - vm = new Vue({ - el: "#formEdit", - data(){ - return { - tmp:data //使用一个tmp封装一下,后面可以直接用vm.tmp赋值 - } - }, - watch:{ - tmp(val){ - this.$nextTick(function () { - form.render(); //刷新select等 - layui.droptree("/Applications/GetList", "#AppName", "#AppId", false); - - }) - } - }, - mounted(){ - form.render(); - layui.droptree("/Applications/GetList", "#AppName", "#AppId", false); - - } - }); - }else{ - vm.tmp = Object.assign({}, vm.tmp,data) - } + if(data == undefined){ + form.val("formEdit", initVal); + }else{ + form.val("formEdit", data); + } }, end: mainList }); @@ -125,15 +124,11 @@ layui.config({ }); } return { - add: function () { //弹出添加 - update = false; - show({ - Id: '' - }); + add: function () { //弹出添加 + show(false); }, update: function (data) { //弹出编辑框 - update = true; - show(data); + show(true, data); } }; }();