layer层、modal模拟窗 单独测试页面

本文介绍如何利用Layer和Bootstrap框架实现不同类型的弹窗效果,包括提示层、页面层、iframe层、loading层和tips层,以及使用Bootstrap创建modal模态框的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

layer_test.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>开始使用layer——单独的测试页面</title>
  <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
</head>
<body>
	<input type="button" value="弹出一个提示层" id="test2">
  
  <script src="static/js/jquery-1.10.1.min.js"></script> <!-- 你必须先引入jQuery1.8或以上版本 -->
  <script src="static/layer-v3.1.1/layer/layer.js"></script> 
  <script> 
  //弹出一个提示层
  $('#test1').on('click', function(){
    layer.msg('hello');
  });
  
  //弹出一个页面层
  $('#test2').on('click', function(){
    layer.open({
      type: 1,
      area: ['600px', '360px'],
      shadeClose: true, //点击遮罩关闭
      content: '\<\div style="padding:20px;">自定义内容\<\/div>'
    });
  });
  
  //弹出一个iframe层
  $('#parentIframe').on('click', function(){
    layer.open({
      type: 2,
      title: 'iframe父子操作',
      maxmin: true,
      shadeClose: true, //点击遮罩关闭层
      area : ['800px' , '520px'],
      content: 'test/iframe.html'
    });
  });
 
  //弹出一个loading层
  $('#test4').on('click', function(){
    var ii = layer.load();
    //此处用setTimeout演示ajax的回调
    setTimeout(function(){
      layer.close(ii);
    }, 1000);
  });
  
  //弹出一个tips层
  $('#test5').on('click', function(){
    layer.tips('Hello tips!', '#test5');
  });
  </script>
</body>
</html>

bootstrap_model_test.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>开始使用Bootstrap创建modal模态框——单独的测试页面</title>
  <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link href="static/bootstrap-3.3.5-dist/css/bootstrap.css" rel="stylesheet" />
</head>
<body>	
	<div class="container">
	    <h2>使用Bootstrap创建modal模态框</h2>
	    <div id="example" class="modal hide fade in" style="display: none; ">
	        <div class="modal-header">
	            <a class="close" data-dismiss="modal">×</a>
	            <h3>这是一个模态框标题</h3>
	        </div>
	        <div class="modal-body">
	            <h4>模态框中的文本</h4>
	            <p>你可以在这添加一些文本。</p>
	        </div>
	        <div class="modal-footer">
	            <a href="#" class="btn btn-success">唤醒活动</a>
	            <a href="#" class="btn" data-dismiss="modal">关闭</a>
	        </div>
	    </div>
	   <!-- 这里是自动绑定的事件 -->
	    <p><a data-toggle="modal" href="#example" class="btn btn-primary btn-large">发动演示模态框</a></p>
	</div>	
	<input type="button" id="test" value="示模态框">
	
  <script src="static/js/jquery-1.10.1.min.js"></script><!-- 你必须先引入jQuery1.8或以上版本 -->
  <script src="static/bootstrap-3.3.5-dist/js/bootstrap.js"></script>
  <script>
  //手动执行
  $("#test").click(function(){
	  //example和<div id="example"对应
	  $('#example').modal('show');
  });
  </script>
</body>
</html>
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; using System; using System.Collections.Generic; using System.Linq; namespace BeamPlugin { public class BeamCommands { // 梁信息存储类 private class BeamInfo { public string Name { get; set; } public string Size { get; set; } public double? Elevation { get; set; } // 标高值(单位:米) } // 主命令:识别并标注梁 (缩写为 BD) [CommandMethod("BD")] public void BeamDimensioning() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction tr = db.TransactionManager.StartTransaction()) { try { // 1. 点选识别集中标注和原位标注 var beamDict = new Dictionary<ObjectId, BeamInfo>(); IdentifyBeams(ed, tr, beamDict); // 2. 框选识别所有梁并标注 PromptSelectionResult selRes = ed.GetSelection(); if (selRes.Status == PromptStatus.OK) { SelectionSet selSet = selRes.Value; ProcessBeams(tr, selSet, beamDict); } // 3. 清理不需要的图 CleanupLayers(db); // 传递Database对象 tr.Commit(); } catch (System.Exception ex) // 明确指定System.Exception { ed.WriteMessage($"\n错误: {ex.Message}"); } } } // 识别梁信息 private void IdentifyBeams(Editor ed, Transaction tr, Dictionary<ObjectId, BeamInfo> beamDict) { // 点选集中标注(假设为文字实体) PromptEntityOptions opt = new PromptEntityOptions("\n选择梁集中标注: "); opt.SetRejectMessage("\n请选择文字对象"); opt.AddAllowedClass(typeof(DBText), false); PromptEntityResult res = ed.GetEntity(opt); if (res.Status == PromptStatus.OK) { DBText dimText = tr.GetObject(res.ObjectId, OpenMode.ForRead) as DBText; BeamInfo info = ParseBeamText(dimText.TextString); beamDict.Add(dimText.OwnerId, info); // 关联到梁实体 } // 点选原位标注(类似逻辑) opt.Message = "\n选择梁原位标注: "; res = ed.GetEntity(opt); if (res.Status == PromptStatus.OK) { DBText dimText = tr.GetObject(res.ObjectId, OpenMode.ForRead) as DBText; BeamInfo info = ParseBeamText(dimText.TextString); beamDict.Add(dimText.OwnerId, info); } } // 解析梁文本信息 private BeamInfo ParseBeamText(string text) { var info = new BeamInfo(); // 示例解析逻辑 if (text.Contains(";")) { string[] parts = text.Split(';'); info.Name = parts[0].Trim(); if (parts.Length > 1 && double.TryParse(parts[1], out double elev)) info.Elevation = elev; } else { info.Name = text; } // 从名称中提取尺寸(示例:2-Lg22(6) 600x800) if (info.Name.Contains(" ")) { string[] nameParts = info.Name.Split(' '); info.Name = nameParts[0]; if (nameParts.Length > 1 && nameParts[1].Contains('x')) { info.Size = nameParts[1]; } } return info; } // 处理梁并标注 private void ProcessBeams(Transaction tr, SelectionSet selSet, Dictionary<ObjectId, BeamInfo> beamDict) { BlockTable bt = (BlockTable)tr.GetObject(tr.Database.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); foreach (SelectedObject selObj in selSet) { if (selObj != null) { Entity ent = tr.GetObject(selObj.ObjectId, OpenMode.ForRead) as Entity; if (ent != null && ent is Polyline && ent.Layer == "梁") // 假设梁在"梁"图 { Polyline beam = ent as Polyline; BeamInfo info = FindBeamInfo(beam, beamDict); if (info != null) { // 创建梁标注 DBText label = CreateBeamLabel(beam, info); btr.AppendEntity(label); tr.AddNewlyCreatedDBObject(label, true); } } } } } // 查找梁信息(支持同名匹配) private BeamInfo FindBeamInfo(Polyline beam, Dictionary<ObjectId, BeamInfo> beamDict) { // 1. 尝试直接获取 if (beamDict.TryGetValue(beam.ObjectId, out BeamInfo directInfo)) return directInfo; // 2. 通过同名匹配 string beamName = GetBeamName(beam); if (!string.IsNullOrEmpty(beamName)) { return beamDict.Values.FirstOrDefault(v => v.Name.StartsWith(beamName)); } return null; } // 获取梁名称(从未标注梁中提取) private string GetBeamName(Polyline beam) { // 实际项目中应根据图/扩展数据等获取 // 示例:从图名提取(图格式为"梁-名称") return beam.Layer.Contains('-') ? beam.Layer.Split('-').Last() : beam.Layer; } // 获取梁中点坐标 (修复GetPointAtDist参数问题) private Point3d GetBeamMidPoint(Polyline beam) { double halfLength = beam.Length / 2; return beam.GetPointAtDist(halfLength); } // 估算文字宽度 private double EstimateTextWidth(string text, double height) { // 近似计算:每个字符宽度=高度的0.7倍 return text.Length * height * 0.7; } // 创建梁标注文字 private DBText CreateBeamLabel(Polyline beam, BeamInfo info) { Point3d midPoint = GetBeamMidPoint(beam); double textHeight = 150; // 标注高度 DBText label = new DBText { Position = midPoint, TextString = FormatLabelText(info, beam.Length), Height = textHeight, Layer = "梁标注", AlignmentPoint = midPoint, Justify = AttachmentPoint.MiddleCenter }; // 自动调整文字大小 double textWidth = EstimateTextWidth(label.TextString, textHeight); if (textWidth > beam.Length * 0.8) // 超过梁长的80% { label.Height = textHeight * (beam.Length * 0.8 / textWidth); } return label; } // 格式化标注文本 private string FormatLabelText(BeamInfo info, double beamLength) { string label = info.Name; if (!string.IsNullOrEmpty(info.Size)) label += " " + info.Size; if (info.Elevation.HasValue) { label += $";{info.Elevation.Value.ToString(info.Elevation.Value < 0 ? "0.00" : "0")}"; } return label; } // 清理图 private void CleanupLayers(Database db) { using (Transaction tr = db.TransactionManager.StartTransaction()) { LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); // 要保留的图 string[] keepLayers = { "轴网", "轴号", "梁", "墙", "柱", "尺寸标注", "填充" }; foreach (ObjectId layerId in lt) { LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(layerId, OpenMode.ForRead); if (!keepLayers.Contains(ltr.Name)) { // 删除非保留图上的所有实体 DeleteEntitiesOnLayer(tr, db, ltr.Name); } } tr.Commit(); } } // 删除指定图上的所有实体 (修复遍历问题) private void DeleteEntitiesOnLayer(Transaction tr, Database db, string layerName) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); // 使用安全方式遍历 ObjectIdCollection idsToErase = new ObjectIdCollection(); foreach (ObjectId id in btr) { Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity; if (ent != null && ent.Layer == layerName) { idsToErase.Add(id); } } // 单独执行删除 foreach (ObjectId id in idsToErase) { Entity ent = tr.GetObject(id, OpenMode.ForWrite) as Entity; if (ent != null && !ent.IsErased) { ent.Erase(); } } } // 统计梁截面命令 (缩写为 BS) [CommandMethod("BS")] public void BeamStatistics() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; PromptSelectionResult selRes = ed.GetSelection(); if (selRes.Status != PromptStatus.OK) return; using (Transaction tr = db.TransactionManager.StartTransaction()) { try { // 统计梁截面尺寸 var sizeStats = new Dictionary<string, int>(); foreach (SelectedObject selObj in selRes.Value) { Entity ent = tr.GetObject(selObj.ObjectId, OpenMode.ForRead) as Entity; if (ent is Polyline && ent.Layer == "梁") { // 从梁标注中提取尺寸 string beamSize = ExtractBeamSize(ent); if (!string.IsNullOrEmpty(beamSize)) { if (sizeStats.ContainsKey(beamSize)) { sizeStats[beamSize]++; } else { sizeStats[beamSize] = 1; } } } } // 生成统计表格 GenerateStatisticsTable(ed, tr, sizeStats); tr.Commit(); } catch (System.Exception ex) { ed.WriteMessage($"\n错误: {ex.Message}"); } } } private string ExtractBeamSize(Entity ent) { // 实际实现从梁实体或标注中提取尺寸 // 这里返回模拟数据 return "600x800"; } private void GenerateStatisticsTable(Editor ed, Transaction tr, Dictionary<string, int> sizeStats) { // 创建统计表格 ed.WriteMessage("\n梁截面尺寸统计:"); foreach (var kvp in sizeStats.OrderBy(x => x.Key)) { ed.WriteMessage($"\n尺寸 {kvp.Key}: {kvp.Value} 根"); } } } } S1061“Transaction”未包含”Database”的定义,并且找不到可接受第一个“Transaction”类型参数的可访问扩展方法”Database”(是否缺少using 指令或程序集引用?
最新发布
07-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值