添加模板生成代码
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Common.Helper;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Template.Abstract
|
||||||
|
{
|
||||||
|
public abstract class AbstractTemplateProvider : ITemplateProvider
|
||||||
|
{
|
||||||
|
public string BuildPath { get; set; }
|
||||||
|
public string TemplatePath { get; set; }
|
||||||
|
public string BakPath { get; set; }
|
||||||
|
private Dictionary<string, string> TemplateDic { get; set; }
|
||||||
|
|
||||||
|
public void Bak() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Build()
|
||||||
|
{
|
||||||
|
var templateData = GetTemplateData();
|
||||||
|
foreach (var ky in TemplateDic)
|
||||||
|
{
|
||||||
|
templateData = templateData.Replace(ky.Key, ky.Value);
|
||||||
|
}
|
||||||
|
File.WriteAllText(BuildPath, templateData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected virtual string GetTemplateData()
|
||||||
|
{
|
||||||
|
return File.ReadAllText(TemplatePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void AddTemplateDic(string oldStr, string newStr)
|
||||||
|
{
|
||||||
|
TemplateDic=new Dictionary<string, string>();
|
||||||
|
TemplateDic.Add(oldStr, newStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Template.Abstract
|
||||||
|
{
|
||||||
|
public interface ITemplateProvider
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 构建生成路径
|
||||||
|
/// </summary>
|
||||||
|
string BuildPath { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 模板文件路径
|
||||||
|
/// </summary>
|
||||||
|
string TemplatePath { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 备份文件路径
|
||||||
|
/// </summary>
|
||||||
|
string BakPath { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 开始构建
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
void Build();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生成备份
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
void Bak();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
490
Yi.Framework.Net6/Yi.Framework.Template/FileHelper.cs
Normal file
490
Yi.Framework.Net6/Yi.Framework.Template/FileHelper.cs
Normal file
@@ -0,0 +1,490 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Common.Helper
|
||||||
|
{
|
||||||
|
public class FileHelper : IDisposable
|
||||||
|
{
|
||||||
|
|
||||||
|
private bool _alreadyDispose = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region 构造函数
|
||||||
|
public FileHelper()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// TODO: 在此处添加构造函数逻辑
|
||||||
|
//
|
||||||
|
}
|
||||||
|
~FileHelper()
|
||||||
|
{
|
||||||
|
Dispose(); ;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
if (_alreadyDispose) return;
|
||||||
|
_alreadyDispose = true;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IDisposable 成员
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 取得文件后缀名
|
||||||
|
/****************************************
|
||||||
|
* 函数名称:GetPostfixStr
|
||||||
|
* 功能说明:取得文件后缀名
|
||||||
|
* 参 数:filename:文件名称
|
||||||
|
* 调用示列:
|
||||||
|
* string filename = "aaa.aspx";
|
||||||
|
* string s = EC.FileObj.GetPostfixStr(filename);
|
||||||
|
*****************************************/
|
||||||
|
/// <summary>
|
||||||
|
/// 取后缀名
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">文件名</param>
|
||||||
|
/// <returns>.gif|.html格式</returns>
|
||||||
|
public static string GetPostfixStr(string filename)
|
||||||
|
{
|
||||||
|
int start = filename.LastIndexOf(".");
|
||||||
|
int length = filename.Length;
|
||||||
|
string postfix = filename.Substring(start, length - start);
|
||||||
|
return postfix;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 根据文件大小获取指定前缀的可用文件名
|
||||||
|
/// <summary>
|
||||||
|
/// 根据文件大小获取指定前缀的可用文件名
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">文件夹</param>
|
||||||
|
/// <param name="prefix">文件前缀</param>
|
||||||
|
/// <param name="size">文件大小(1m)</param>
|
||||||
|
/// <param name="ext">文件后缀(.log)</param>
|
||||||
|
/// <returns>可用文件名</returns>
|
||||||
|
//public static string GetAvailableFileWithPrefixOrderSize(string folderPath, string prefix, int size = 1 * 1024 * 1024, string ext = ".log")
|
||||||
|
//{
|
||||||
|
// var allFiles = new DirectoryInfo(folderPath);
|
||||||
|
// var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(prefix.ToLower()) && fi.Extension.ToLower() == ext.ToLower() && fi.Length < size).OrderByDescending(d=>d.Name).ToList();
|
||||||
|
|
||||||
|
// if (selectFiles.Count > 0)
|
||||||
|
// {
|
||||||
|
// return selectFiles.FirstOrDefault().FullName;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return Path.Combine(folderPath, $@"{prefix}_{DateTime.Now.DateToTimeStamp()}.log");
|
||||||
|
//}
|
||||||
|
//public static string GetAvailableFileNameWithPrefixOrderSize(string _contentRoot, string prefix, int size = 1 * 1024 * 1024, string ext = ".log")
|
||||||
|
//{
|
||||||
|
// var folderPath = Path.Combine(_contentRoot, "Log");
|
||||||
|
// if (!Directory.Exists(folderPath))
|
||||||
|
// {
|
||||||
|
// Directory.CreateDirectory(folderPath);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var allFiles = new DirectoryInfo(folderPath);
|
||||||
|
// var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(prefix.ToLower()) && fi.Extension.ToLower() == ext.ToLower() && fi.Length < size).OrderByDescending(d => d.Name).ToList();
|
||||||
|
|
||||||
|
// if (selectFiles.Count > 0)
|
||||||
|
// {
|
||||||
|
// return selectFiles.FirstOrDefault().Name.Replace(".log","");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return $@"{prefix}_{DateTime.Now.DateToTimeStamp()}";
|
||||||
|
//}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 写文件
|
||||||
|
/****************************************
|
||||||
|
* 函数名称:WriteFile
|
||||||
|
* 功能说明:写文件,会覆盖掉以前的内容
|
||||||
|
* 参 数:Path:文件路径,Strings:文本内容
|
||||||
|
* 调用示列:
|
||||||
|
* string Path = Server.MapPath("Default2.aspx");
|
||||||
|
* string Strings = "这是我写的内容啊";
|
||||||
|
* EC.FileObj.WriteFile(Path,Strings);
|
||||||
|
*****************************************/
|
||||||
|
/// <summary>
|
||||||
|
/// 写文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Path">文件路径</param>
|
||||||
|
/// <param name="Strings">文件内容</param>
|
||||||
|
public static void WriteFile(string Path, string Strings)
|
||||||
|
{
|
||||||
|
if (!File.Exists(Path))
|
||||||
|
{
|
||||||
|
FileStream f = File.Create(Path);
|
||||||
|
f.Close();
|
||||||
|
}
|
||||||
|
StreamWriter f2 = new StreamWriter(Path, false, System.Text.Encoding.GetEncoding("gb2312"));
|
||||||
|
f2.Write(Strings);
|
||||||
|
f2.Close();
|
||||||
|
f2.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 写文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Path">文件路径</param>
|
||||||
|
/// <param name="Strings">文件内容</param>
|
||||||
|
/// <param name="encode">编码格式</param>
|
||||||
|
public static void WriteFile(string Path, string Strings, Encoding encode)
|
||||||
|
{
|
||||||
|
if (!File.Exists(Path))
|
||||||
|
{
|
||||||
|
FileStream f = File.Create(Path);
|
||||||
|
f.Close();
|
||||||
|
}
|
||||||
|
StreamWriter f2 = new StreamWriter(Path, false, encode);
|
||||||
|
f2.Write(Strings);
|
||||||
|
f2.Close();
|
||||||
|
f2.Dispose();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 读文件
|
||||||
|
/****************************************
|
||||||
|
* 函数名称:ReadFile
|
||||||
|
* 功能说明:读取文本内容
|
||||||
|
* 参 数:Path:文件路径
|
||||||
|
* 调用示列:
|
||||||
|
* string Path = Server.MapPath("Default2.aspx");
|
||||||
|
* string s = EC.FileObj.ReadFile(Path);
|
||||||
|
*****************************************/
|
||||||
|
/// <summary>
|
||||||
|
/// 读文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Path">文件路径</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string ReadFile(string Path)
|
||||||
|
{
|
||||||
|
string s = "";
|
||||||
|
if (!File.Exists(Path))
|
||||||
|
s = "不存在相应的目录";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
StreamReader f2 = new StreamReader(Path, System.Text.Encoding.GetEncoding("gb2312"));
|
||||||
|
s = f2.ReadToEnd();
|
||||||
|
f2.Close();
|
||||||
|
f2.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 读文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Path">文件路径</param>
|
||||||
|
/// <param name="encode">编码格式</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string ReadFile(string Path, Encoding encode)
|
||||||
|
{
|
||||||
|
string s = "";
|
||||||
|
if (!File.Exists(Path))
|
||||||
|
s = "不存在相应的目录";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
StreamReader f2 = new StreamReader(Path, encode);
|
||||||
|
s = f2.ReadToEnd();
|
||||||
|
f2.Close();
|
||||||
|
f2.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 追加文件
|
||||||
|
/****************************************
|
||||||
|
* 函数名称:FileAdd
|
||||||
|
* 功能说明:追加文件内容
|
||||||
|
* 参 数:Path:文件路径,strings:内容
|
||||||
|
* 调用示列:
|
||||||
|
* string Path = Server.MapPath("Default2.aspx");
|
||||||
|
* string Strings = "新追加内容";
|
||||||
|
* EC.FileObj.FileAdd(Path, Strings);
|
||||||
|
*****************************************/
|
||||||
|
/// <summary>
|
||||||
|
/// 追加文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Path">文件路径</param>
|
||||||
|
/// <param name="strings">内容</param>
|
||||||
|
public static void FileAdd(string Path, string strings)
|
||||||
|
{
|
||||||
|
StreamWriter sw = File.AppendText(Path);
|
||||||
|
sw.Write(strings);
|
||||||
|
sw.Flush();
|
||||||
|
sw.Close();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 拷贝文件
|
||||||
|
/****************************************
|
||||||
|
* 函数名称:FileCoppy
|
||||||
|
* 功能说明:拷贝文件
|
||||||
|
* 参 数:OrignFile:原始文件,NewFile:新文件路径
|
||||||
|
* 调用示列:
|
||||||
|
* string orignFile = Server.MapPath("Default2.aspx");
|
||||||
|
* string NewFile = Server.MapPath("Default3.aspx");
|
||||||
|
* EC.FileObj.FileCoppy(OrignFile, NewFile);
|
||||||
|
*****************************************/
|
||||||
|
/// <summary>
|
||||||
|
/// 拷贝文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="OrignFile">原始文件</param>
|
||||||
|
/// <param name="NewFile">新文件路径</param>
|
||||||
|
public static void FileCoppy(string orignFile, string NewFile)
|
||||||
|
{
|
||||||
|
File.Copy(orignFile, NewFile, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 删除文件
|
||||||
|
/****************************************
|
||||||
|
* 函数名称:FileDel
|
||||||
|
* 功能说明:删除文件
|
||||||
|
* 参 数:Path:文件路径
|
||||||
|
* 调用示列:
|
||||||
|
* string Path = Server.MapPath("Default3.aspx");
|
||||||
|
* EC.FileObj.FileDel(Path);
|
||||||
|
*****************************************/
|
||||||
|
/// <summary>
|
||||||
|
/// 删除文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Path">路径</param>
|
||||||
|
public static void FileDel(string Path)
|
||||||
|
{
|
||||||
|
File.Delete(Path);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 移动文件
|
||||||
|
/****************************************
|
||||||
|
* 函数名称:FileMove
|
||||||
|
* 功能说明:移动文件
|
||||||
|
* 参 数:OrignFile:原始路径,NewFile:新文件路径
|
||||||
|
* 调用示列:
|
||||||
|
* string orignFile = Server.MapPath("../说明.txt");
|
||||||
|
* string NewFile = Server.MapPath("http://www.cnblogs.com/说明.txt");
|
||||||
|
* EC.FileObj.FileMove(OrignFile, NewFile);
|
||||||
|
*****************************************/
|
||||||
|
/// <summary>
|
||||||
|
/// 移动文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="OrignFile">原始路径</param>
|
||||||
|
/// <param name="NewFile">新路径</param>
|
||||||
|
public static void FileMove(string orignFile, string NewFile)
|
||||||
|
{
|
||||||
|
File.Move(orignFile, NewFile);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 在当前目录下创建目录
|
||||||
|
/****************************************
|
||||||
|
* 函数名称:FolderCreate
|
||||||
|
* 功能说明:在当前目录下创建目录
|
||||||
|
* 参 数:OrignFolder:当前目录,NewFloder:新目录
|
||||||
|
* 调用示列:
|
||||||
|
* string orignFolder = Server.MapPath("test/");
|
||||||
|
* string NewFloder = "new";
|
||||||
|
* EC.FileObj.FolderCreate(OrignFolder, NewFloder);
|
||||||
|
*****************************************/
|
||||||
|
/// <summary>
|
||||||
|
/// 在当前目录下创建目录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="OrignFolder">当前目录</param>
|
||||||
|
/// <param name="NewFloder">新目录</param>
|
||||||
|
public static void FolderCreate(string orignFolder, string NewFloder)
|
||||||
|
{
|
||||||
|
Directory.SetCurrentDirectory(orignFolder);
|
||||||
|
Directory.CreateDirectory(NewFloder);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 递归删除文件夹目录及文件
|
||||||
|
/****************************************
|
||||||
|
* 函数名称:DeleteFolder
|
||||||
|
* 功能说明:递归删除文件夹目录及文件
|
||||||
|
* 参 数:dir:文件夹路径
|
||||||
|
* 调用示列:
|
||||||
|
* string dir = Server.MapPath("test/");
|
||||||
|
* EC.FileObj.DeleteFolder(dir);
|
||||||
|
*****************************************/
|
||||||
|
/// <summary>
|
||||||
|
/// 递归删除文件夹目录及文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dir"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static void DeleteFolder(string dir)
|
||||||
|
{
|
||||||
|
if (Directory.Exists(dir)) //如果存在这个文件夹删除之
|
||||||
|
{
|
||||||
|
foreach (string d in Directory.GetFileSystemEntries(dir))
|
||||||
|
{
|
||||||
|
if (File.Exists(d))
|
||||||
|
File.Delete(d); //直接删除其中的文件
|
||||||
|
else
|
||||||
|
DeleteFolder(d); //递归删除子文件夹
|
||||||
|
}
|
||||||
|
Directory.Delete(dir); //删除已空文件夹
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 将指定文件夹下面的所有内容copy到目标文件夹下面 果目标文件夹为只读属性就会报错。
|
||||||
|
/****************************************
|
||||||
|
* 函数名称:CopyDir
|
||||||
|
* 功能说明:将指定文件夹下面的所有内容copy到目标文件夹下面 果目标文件夹为只读属性就会报错。
|
||||||
|
* 参 数:srcPath:原始路径,aimPath:目标文件夹
|
||||||
|
* 调用示列:
|
||||||
|
* string srcPath = Server.MapPath("test/");
|
||||||
|
* string aimPath = Server.MapPath("test1/");
|
||||||
|
* EC.FileObj.CopyDir(srcPath,aimPath);
|
||||||
|
*****************************************/
|
||||||
|
/// <summary>
|
||||||
|
/// 指定文件夹下面的所有内容copy到目标文件夹下面
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="srcPath">原始路径</param>
|
||||||
|
/// <param name="aimPath">目标文件夹</param>
|
||||||
|
public static void CopyDir(string srcPath, string aimPath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 检查目标目录是否以目录分割字符结束如果不是则添加之
|
||||||
|
if (aimPath[aimPath.Length - 1] != Path.DirectorySeparatorChar)
|
||||||
|
aimPath += Path.DirectorySeparatorChar;
|
||||||
|
// 判断目标目录是否存在如果不存在则新建之
|
||||||
|
if (!Directory.Exists(aimPath))
|
||||||
|
Directory.CreateDirectory(aimPath);
|
||||||
|
// 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
|
||||||
|
//如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法
|
||||||
|
//string[] fileList = Directory.GetFiles(srcPath);
|
||||||
|
string[] fileList = Directory.GetFileSystemEntries(srcPath);
|
||||||
|
//遍历所有的文件和目录
|
||||||
|
foreach (string file in fileList)
|
||||||
|
{
|
||||||
|
//先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
|
||||||
|
|
||||||
|
if (Directory.Exists(file))
|
||||||
|
CopyDir(file, aimPath + Path.GetFileName(file));
|
||||||
|
//否则直接Copy文件
|
||||||
|
else
|
||||||
|
File.Copy(file, aimPath + Path.GetFileName(file), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ee)
|
||||||
|
{
|
||||||
|
throw new Exception(ee.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取目录下全部文件名
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
/// <param name="pattern"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static List<string> GetAllFileNames(string path, string pattern = "*")
|
||||||
|
{
|
||||||
|
List<FileInfo> folder = new DirectoryInfo(path).GetFiles(pattern).ToList();
|
||||||
|
|
||||||
|
return folder.Select(x => x.Name).ToList();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 文件内容替换
|
||||||
|
/// </summary>
|
||||||
|
public static string FileContentReplace(string path, string oldStr, string newStr)
|
||||||
|
{
|
||||||
|
var content = File.ReadAllText(path);
|
||||||
|
|
||||||
|
if (content.Contains(oldStr))
|
||||||
|
{
|
||||||
|
File.Delete(path);
|
||||||
|
File.WriteAllText(path, content.Replace(oldStr, newStr));
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 文件名称
|
||||||
|
/// </summary>
|
||||||
|
public static string FileNameReplace(string path, string oldStr, string newStr)
|
||||||
|
{
|
||||||
|
string fileName = Path.GetFileName(path);
|
||||||
|
if (!fileName.Contains(oldStr))
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? directoryName = Path.GetDirectoryName(path);
|
||||||
|
string newFileName = fileName.Replace(oldStr, newStr);
|
||||||
|
string newPath = Path.Combine(directoryName ?? "", newFileName);
|
||||||
|
File.Move(path, newPath);
|
||||||
|
|
||||||
|
return newPath;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 目录名替换
|
||||||
|
/// </summary>
|
||||||
|
public static string DirectoryNameReplace(string path, string oldStr, string newStr)
|
||||||
|
{
|
||||||
|
string fileName = Path.GetFileName(path);
|
||||||
|
if (!fileName.Contains(oldStr))
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? directoryName = Path.GetDirectoryName(path);
|
||||||
|
string newFileName = fileName.Replace(oldStr, newStr);
|
||||||
|
string newPath = Path.Combine(directoryName ?? "", newFileName);
|
||||||
|
Directory.Move(path, newPath);
|
||||||
|
return newPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 全部信息递归替换
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dirPath"></param>
|
||||||
|
/// <param name="oldStr"></param>
|
||||||
|
/// <param name="newStr"></param>
|
||||||
|
public static void AllInfoReplace(string dirPath, string oldStr, string newStr)
|
||||||
|
{
|
||||||
|
var path = DirectoryNameReplace(dirPath, oldStr, newStr);
|
||||||
|
var dirInfo = new DirectoryInfo(path);
|
||||||
|
var files = dirInfo.GetFiles();
|
||||||
|
var dirs = dirInfo.GetDirectories();
|
||||||
|
if (files.Length > 0)
|
||||||
|
{
|
||||||
|
foreach (var f in files)
|
||||||
|
{
|
||||||
|
FileContentReplace(f.FullName, oldStr, newStr);
|
||||||
|
FileNameReplace(f.FullName, oldStr, newStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dirs.Length > 0)
|
||||||
|
{
|
||||||
|
foreach (var d in dirs)
|
||||||
|
{
|
||||||
|
AllInfoReplace(d.FullName, oldStr, newStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Yi.Framework.Net6/Yi.Framework.Template/Program.cs
Normal file
14
Yi.Framework.Net6/Yi.Framework.Template/Program.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using Yi.Framework.Template;
|
||||||
|
using Yi.Framework.Template.Provider;
|
||||||
|
|
||||||
|
TemplateFactory templateFactory = new();
|
||||||
|
|
||||||
|
//选择需要生成的模板提供者
|
||||||
|
templateFactory.CreateTemplateProviders((option) =>
|
||||||
|
{
|
||||||
|
option.Add(new ServceTemplateProvider());
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
//开始构建模板
|
||||||
|
templateFactory.BuildTemplate();
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Template.Abstract;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Template.Provider
|
||||||
|
{
|
||||||
|
public class ServceTemplateProvider : AbstractTemplateProvider
|
||||||
|
{
|
||||||
|
public ServceTemplateProvider()
|
||||||
|
{
|
||||||
|
BuildPath = "E:\\Yi\\Yi.Framework.Net6\\Yi.Framework.Template\\Code\\ServiceNewTemplate.txt";
|
||||||
|
TemplatePath = "E:\\Yi\\Yi.Framework.Net6\\Yi.Framework.Template\\Template\\ServiceTemplate.txt";
|
||||||
|
AddTemplateDic("Yi.Framework", "Yi.TTT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Common.Models;
|
||||||
|
using Yi.Framework.DtoModel.ERP.Supplier;
|
||||||
|
using Yi.Framework.Interface.ERP;
|
||||||
|
using Yi.Framework.Model.ERP.Entitys;
|
||||||
|
using Yi.Framework.Repository;
|
||||||
|
using Yi.Framework.Service.Base.Crud;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Service.ERP
|
||||||
|
{
|
||||||
|
public class SupplierService : CrudAppService<SupplierEntity, SupplierGetListOutput, long, SupplierCreateUpdateInput>, ISupplierService
|
||||||
|
{
|
||||||
|
public SupplierService(IRepository<SupplierEntity> repository, IMapper mapper) : base(repository, mapper)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public async Task<PageModel<List<SupplierGetListOutput>>> PageListAsync(SupplierCreateUpdateInput input, PageParModel page)
|
||||||
|
{
|
||||||
|
RefAsync<int> totalNumber = 0;
|
||||||
|
var data = await Repository._DbQueryable
|
||||||
|
.WhereIF(input.Code is not null,u=>u.Code.Contains(input.Code))
|
||||||
|
.WhereIF(input.Name is not null, u => u.Name.Contains(input.Name))
|
||||||
|
.ToPageListAsync(page.PageNum, page.PageSize, totalNumber);
|
||||||
|
return new PageModel<List<SupplierGetListOutput>> { Total = totalNumber.Value, Data = await MapToGetListOutputDtosAsync(data) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
Yi.Framework.Net6/Yi.Framework.Template/TemplateFactory.cs
Normal file
38
Yi.Framework.Net6/Yi.Framework.Template/TemplateFactory.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Template.Abstract;
|
||||||
|
using Yi.Framework.Template.Provider;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Template
|
||||||
|
{
|
||||||
|
public class TemplateFactory
|
||||||
|
{
|
||||||
|
private List<ITemplateProvider> _templateProviders;
|
||||||
|
|
||||||
|
public void CreateTemplateProviders(Action<List<ITemplateProvider>> action)
|
||||||
|
{
|
||||||
|
_templateProviders=new List<ITemplateProvider>();
|
||||||
|
action(_templateProviders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BuildTemplate()
|
||||||
|
{
|
||||||
|
foreach (var provider in _templateProviders)
|
||||||
|
{
|
||||||
|
provider.Build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BakTemplate()
|
||||||
|
{
|
||||||
|
foreach (var provider in _templateProviders)
|
||||||
|
{
|
||||||
|
provider.Bak();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,47 +4,16 @@
|
|||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="vue3-ruoyi\view.vue">
|
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>view.tt</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Include="vue3-ruoyi\view.cs">
|
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>view.tt</DependentUpon>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Update="vue3-ruoyi\view.tt">
|
|
||||||
<LastGenOutput>view.vue</LastGenOutput>
|
|
||||||
<Generator>TextTemplatingFileGenerator</Generator>
|
|
||||||
</None>
|
|
||||||
<None Update="vue3-ruoyi\api.tt">
|
|
||||||
<Generator>TextTemplatingFileGenerator</Generator>
|
|
||||||
<LastGenOutput>api.js</LastGenOutput>
|
|
||||||
</None>
|
|
||||||
<None Update="vue3-ruoyi\api.js">
|
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>api.tt</DependentUpon>
|
|
||||||
</None>
|
|
||||||
<None Update="vue3-ruoyi\view.vue">
|
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>view.tt</DependentUpon>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Template\" />
|
||||||
|
<Folder Include="Code\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
import request from '@/utils/request'
|
|
||||||
|
|
||||||
// 分页查询
|
|
||||||
export function listData(query) {
|
|
||||||
return request({
|
|
||||||
url: '/article/pageList',
|
|
||||||
method: 'get',
|
|
||||||
params: query
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// id查询
|
|
||||||
export function getData(code) {
|
|
||||||
return request({
|
|
||||||
url: '/article/getById/' + code,
|
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 新增
|
|
||||||
export function addData(data) {
|
|
||||||
return request({
|
|
||||||
url: '/article/add',
|
|
||||||
method: 'post',
|
|
||||||
data: data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改
|
|
||||||
export function updateData(data) {
|
|
||||||
return request({
|
|
||||||
url: '/article/update',
|
|
||||||
method: 'put',
|
|
||||||
data: data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除
|
|
||||||
export function delData(code) {
|
|
||||||
return request({
|
|
||||||
url: '/article/delList',
|
|
||||||
method: 'delete',
|
|
||||||
data:"string"==typeof(code)?[code]:code
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
<#@ template debug="false" hostspecific="false" language="C#" #>
|
|
||||||
<#@ assembly name="System.Core" #>
|
|
||||||
<#@ import namespace="System.Linq" #>
|
|
||||||
<#@ import namespace="System.Text" #>
|
|
||||||
<#@ import namespace="System.Collections.Generic" #>
|
|
||||||
<#@ output extension=".js" #>
|
|
||||||
<#
|
|
||||||
var entityName="article";
|
|
||||||
#>
|
|
||||||
import request from '@/utils/request'
|
|
||||||
|
|
||||||
// 分页查询
|
|
||||||
export function listData(query) {
|
|
||||||
return request({
|
|
||||||
url: '/<#= entityName #>/pageList',
|
|
||||||
method: 'get',
|
|
||||||
params: query
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// id查询
|
|
||||||
export function getData(code) {
|
|
||||||
return request({
|
|
||||||
url: '/<#= entityName #>/getById/' + code,
|
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 新增
|
|
||||||
export function addData(data) {
|
|
||||||
return request({
|
|
||||||
url: '/<#= entityName #>/add',
|
|
||||||
method: 'post',
|
|
||||||
data: data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改
|
|
||||||
export function updateData(data) {
|
|
||||||
return request({
|
|
||||||
url: '/<#= entityName #>/update',
|
|
||||||
method: 'put',
|
|
||||||
data: data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除
|
|
||||||
export function delData(code) {
|
|
||||||
return request({
|
|
||||||
url: '/<#= entityName #>/delList',
|
|
||||||
method: 'delete',
|
|
||||||
data:"string"==typeof(code)?[code]:code
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,315 +0,0 @@
|
|||||||
<#@ template debug="false" hostspecific="false" language="C#" #>
|
|
||||||
<#@ assembly name="System.Core" #>
|
|
||||||
<#@ import namespace="System.Linq" #>
|
|
||||||
<#@ import namespace="System.Text" #>
|
|
||||||
<#@ import namespace="System.Collections.Generic" #>
|
|
||||||
<#@ output extension=".vue" #>
|
|
||||||
<#
|
|
||||||
var entityName="article";
|
|
||||||
var path="/business/articleApi";
|
|
||||||
var entityRemark="文章";
|
|
||||||
var perCode="business:article";
|
|
||||||
var dataDic=new Dictionary<string,string>(){
|
|
||||||
{"title","文章标题"},
|
|
||||||
};
|
|
||||||
var isStart=false;
|
|
||||||
#>
|
|
||||||
//
|
|
||||||
<#if(isStart){
|
|
||||||
|
|
||||||
#>
|
|
||||||
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="app-container">
|
|
||||||
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
|
|
||||||
<# foreach(var dic in dataDic) { #>
|
|
||||||
<el-form-item label="<#=dic.Value#>" prop="<#=dic.Key#>">
|
|
||||||
<el-input
|
|
||||||
v-model="queryParams.<#=dic.Key#>"
|
|
||||||
placeholder="请输入<#=dic.Value#>"
|
|
||||||
clearable
|
|
||||||
style="width: 240px"
|
|
||||||
@keyup.enter="handleQuery"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<#} #>
|
|
||||||
|
|
||||||
|
|
||||||
<el-form-item label="状态" prop="isDeleted">
|
|
||||||
<el-select
|
|
||||||
v-model="queryParams.isDeleted"
|
|
||||||
placeholder="状态"
|
|
||||||
clearable
|
|
||||||
style="width: 240px"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="dict in sys_normal_disable"
|
|
||||||
:key="dict.value"
|
|
||||||
:label="dict.label"
|
|
||||||
:value="dict.value"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="创建时间" style="width: 308px">
|
|
||||||
<el-date-picker
|
|
||||||
v-model="dateRange"
|
|
||||||
value-format="YYYY-MM-DD"
|
|
||||||
type="daterange"
|
|
||||||
range-separator="-"
|
|
||||||
start-placeholder="开始日期"
|
|
||||||
end-placeholder="结束日期"
|
|
||||||
></el-date-picker>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item>
|
|
||||||
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
|
||||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
|
|
||||||
<el-row :gutter="10" class="mb8">
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
|
||||||
type="primary"
|
|
||||||
plain
|
|
||||||
icon="Plus"
|
|
||||||
@click="handleAdd"
|
|
||||||
v-hasPermi="['<#=perCode#>:add']"
|
|
||||||
>新增</el-button>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
|
||||||
type="success"
|
|
||||||
plain
|
|
||||||
icon="Edit"
|
|
||||||
:disabled="single"
|
|
||||||
@click="handleUpdate"
|
|
||||||
v-hasPermi="['<#=perCode#>:edit']"
|
|
||||||
>修改</el-button>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
|
||||||
type="danger"
|
|
||||||
plain
|
|
||||||
icon="Delete"
|
|
||||||
:disabled="multiple"
|
|
||||||
@click="handleDelete"
|
|
||||||
v-hasPermi="['<#=perCode#>:remove']"
|
|
||||||
>删除</el-button>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
|
||||||
type="warning"
|
|
||||||
plain
|
|
||||||
icon="Download"
|
|
||||||
@click="handleExport"
|
|
||||||
v-hasPermi="['<#=perCode#>:export']"
|
|
||||||
>导出</el-button>
|
|
||||||
</el-col>
|
|
||||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
|
||||||
</el-row>
|
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="<#=entityName#>List" @selection-change="handleSelectionChange">
|
|
||||||
<el-table-column type="selection" width="55" align="center" />
|
|
||||||
<el-table-column label="编号" align="center" prop="id" />
|
|
||||||
|
|
||||||
<# foreach(var dic in dataDic) { #>
|
|
||||||
<el-table-column label="<#=dic.Value#>" align="center" prop="<#=dic.Key#>" :show-overflow-tooltip="true"/>
|
|
||||||
<# }#>
|
|
||||||
|
|
||||||
<el-table-column label="状态" align="center" prop="isDeleted">
|
|
||||||
<template #default="scope">
|
|
||||||
<dict-tag :options="sys_normal_disable" :value="scope.row.isDeleted" />
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
|
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
|
||||||
<template #default="scope">
|
|
||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
|
||||||
<template #default="scope">
|
|
||||||
<el-button
|
|
||||||
type="text"
|
|
||||||
icon="Edit"
|
|
||||||
@click="handleUpdate(scope.row)"
|
|
||||||
v-hasPermi="['<#=perCode#>:edit']"
|
|
||||||
>修改</el-button>
|
|
||||||
<el-button
|
|
||||||
type="text"
|
|
||||||
icon="Delete"
|
|
||||||
@click="handleDelete(scope.row)"
|
|
||||||
v-hasPermi="['<#=perCode#>:remove']"
|
|
||||||
>删除</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
|
|
||||||
<pagination
|
|
||||||
v-show="total > 0"
|
|
||||||
:total="total"
|
|
||||||
v-model:page="queryParams.pageNum"
|
|
||||||
v-model:limit="queryParams.pageSize"
|
|
||||||
@pagination="getList"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
|
|
||||||
<el-form ref="dataRef" :model="form" :rules="rules" label-width="80px">
|
|
||||||
<# foreach(var dic in dataDic) { #>
|
|
||||||
<el-form-item label="<#=dic.Value#>" prop="<#=dic.Key#>">
|
|
||||||
<el-input v-model="form.<#=dic.Key#>" placeholder="请输入<#=dic.Value#>" />
|
|
||||||
</el-form-item>
|
|
||||||
<# } #>
|
|
||||||
<el-form-item label="状态" prop="isDeleted">
|
|
||||||
<el-radio-group v-model="form.isDeleted">
|
|
||||||
<el-radio v-for="dict in sys_normal_disable" :key="dict.value" :label="JSON.parse(dict.value)">{{dict.label}}</el-radio>
|
|
||||||
</el-radio-group>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="备注" prop="remark">
|
|
||||||
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
<template #footer>
|
|
||||||
<div class="dialog-footer">
|
|
||||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
|
||||||
<el-button @click="cancel">取 消</el-button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</el-dialog>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { listData, getData, delData, addData, updateData } from "@/api<#=path#>";
|
|
||||||
|
|
||||||
const { proxy } = getCurrentInstance();
|
|
||||||
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
|
|
||||||
|
|
||||||
const <#=entityName#>List = ref([]);
|
|
||||||
const open = ref(false);
|
|
||||||
const loading = ref(true);
|
|
||||||
const showSearch = ref(true);
|
|
||||||
const ids = ref([]);
|
|
||||||
const single = ref(true);
|
|
||||||
const multiple = ref(true);
|
|
||||||
const total = ref(0);
|
|
||||||
const title = ref("");
|
|
||||||
const dateRange = ref([]);
|
|
||||||
|
|
||||||
const data = reactive({
|
|
||||||
form: {},
|
|
||||||
queryParams: {
|
|
||||||
pageNum: 1,
|
|
||||||
pageSize: 10,
|
|
||||||
<# foreach(var dic in dataDic) { #>
|
|
||||||
<#=dic.Key#>: undefined,
|
|
||||||
<# }#>
|
|
||||||
isDeleted: undefined
|
|
||||||
},
|
|
||||||
rules: {
|
|
||||||
<# foreach(var dic in dataDic) { #>
|
|
||||||
<#=dic.Key#>: [{ required: true, message: "<#=dic.Value#>不能为空", trigger: "blur" }],
|
|
||||||
<# }#>
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const { queryParams, form, rules } = toRefs(data);
|
|
||||||
|
|
||||||
/** 查询列表 */
|
|
||||||
function getList() {
|
|
||||||
loading.value = true;
|
|
||||||
listData(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
|
|
||||||
<#=entityName#>List.value = response.data.data;
|
|
||||||
total.value = response.data.total;
|
|
||||||
loading.value = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/** 取消按钮 */
|
|
||||||
function cancel() {
|
|
||||||
open.value = false;
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
/** 表单重置 */
|
|
||||||
function reset() {
|
|
||||||
form.value = {
|
|
||||||
id: undefined,
|
|
||||||
<# foreach(var dic in dataDic) { #>
|
|
||||||
<#=dic.Key#>: undefined,
|
|
||||||
<# }#>
|
|
||||||
isDeleted: false,
|
|
||||||
remark: undefined
|
|
||||||
};
|
|
||||||
proxy.resetForm("dataRef");
|
|
||||||
}
|
|
||||||
/** 搜索按钮操作 */
|
|
||||||
function handleQuery() {
|
|
||||||
queryParams.value.pageNum = 1;
|
|
||||||
getList();
|
|
||||||
}
|
|
||||||
/** 重置按钮操作 */
|
|
||||||
function resetQuery() {
|
|
||||||
dateRange.value = [];
|
|
||||||
proxy.resetForm("queryRef");
|
|
||||||
handleQuery();
|
|
||||||
}
|
|
||||||
/** 新增按钮操作 */
|
|
||||||
function handleAdd() {
|
|
||||||
reset();
|
|
||||||
open.value = true;
|
|
||||||
title.value = "添加<#=entityRemark#>";
|
|
||||||
}
|
|
||||||
/** 多选框选中数据 */
|
|
||||||
function handleSelectionChange(selection) {
|
|
||||||
ids.value = selection.map(item => item.id);
|
|
||||||
single.value = selection.length != 1;
|
|
||||||
multiple.value = !selection.length;
|
|
||||||
}
|
|
||||||
/** 修改按钮操作 */
|
|
||||||
function handleUpdate(row) {
|
|
||||||
reset();
|
|
||||||
const id = row.id || ids.value;
|
|
||||||
getData(id).then(response => {
|
|
||||||
form.value = response.data;
|
|
||||||
open.value = true;
|
|
||||||
title.value = "修改<#=entityRemark#>类型";
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/** 提交按钮 */
|
|
||||||
function submitForm() {
|
|
||||||
proxy.$refs["dataRef"].validate(valid => {
|
|
||||||
if (valid) {
|
|
||||||
if (form.value.id != undefined) {
|
|
||||||
updateData(form.value).then(response => {
|
|
||||||
proxy.$modal.msgSuccess("修改成功");
|
|
||||||
open.value = false;
|
|
||||||
getList();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
addData(form.value).then(response => {
|
|
||||||
proxy.$modal.msgSuccess("新增成功");
|
|
||||||
open.value = false;
|
|
||||||
getList();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/** 删除按钮操作 */
|
|
||||||
function handleDelete(row) {
|
|
||||||
const delIds = row.id || ids.value;
|
|
||||||
proxy.$modal.confirm('是否确认删除字典编号为"' + delIds + '"的数据项?').then(function() {
|
|
||||||
return delData(delIds);
|
|
||||||
}).then(() => {
|
|
||||||
getList();
|
|
||||||
proxy.$modal.msgSuccess("删除成功");
|
|
||||||
}).catch(() => {});
|
|
||||||
}
|
|
||||||
/** 导出按钮操作 */
|
|
||||||
function handleExport() {
|
|
||||||
|
|
||||||
}
|
|
||||||
getList();
|
|
||||||
</script>
|
|
||||||
<#}
|
|
||||||
#>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
//
|
|
||||||
Reference in New Issue
Block a user