您的位置:首页 > Web前端 > JavaScript

基于Extjs的web表单设计器 第二节——表单控件设计

2015-01-23 22:16 459 查看
  这一节介绍表单设计器的常用控件的设计。

  在前面两章节的附图中我已经给出了表单控件的两大分类:区域控件、常用控件。这里对每个分类以及分类所包含的控件的作用进行一一的介绍,因为它们很重要,是表单设计器的基本元素,更是核心组成部门。

  一、区域控件,它主要包含三个类型的控件:卡片区域、表格区域、混合区域。这三个控件是我们的其他控件的容器或者叫包装器,相当于VS里面的各种Panel。它们很重要,每种区域控件的作用都不一样,能够包含的控件类型也不大一样,它们三个区域相互配合使用,可以为我们的表单提供强大的支持,各种复杂的表单都可以设计出来。除了容器作用之外,其实它们还对应着表单在数据库后台的存储结构,可能是一张表。

    1. 卡片区域控件——它其实就是我们前面说的主表或者卡片表,它里面的控件一般都是多列横向布局。它可以包含除了所有区域控件之外的其他常用控件。这个区域控件一般所有的表单都会有。

    2. 表格区域控件——就是我们前面说的明细表(表格类型的容器),它里面的控件一般都会有多行数据。它也是可以包含除了所有区域控件之外的其他常用控件。该区域控件也是很常用的,一般也会出现在很多表单里面。

    3. 混合区域控件——我们不常用,但是非常最重要的一个控件。它的存在使我们设计出非常复杂的表单。该区域只能包含卡片区域、表格区域以及它自身类型的容器控件,其他常用的控件是不能拖放到该区域的。

  二、常用控件,该分组的控件是表单的最基本元素,这些控件的组合使用实现了表单所需要的功能。主要包含常用的日期、文本、多文本(可接受换行符,适合显示较多文本数据)、数字、金额、下拉树、单选、复选等控件。这里面应用最多和比较复杂的就是下拉树控件。说它复杂是因为单据的一些复杂的数据源都得靠它来实现(具体怎么实现每个控件的取数我们在后面的章节会详细介绍)。其他的这些控件对开发人员来说就不必在具体介绍了,通过名称我们就基本知道它的作用。

  通过上面的介绍我们大致知道了组成表单的控件的分类及每种控件的用法。这里介绍一下控件数据源的设计,控件列表分组我们可以直接在页面代码里面定义如下的ext 代码,给予每种控件一个类型的标注(如TreeStore 中的Model中定义的type字段,就是用来标记每种控件的类型)。

<ext:TreePanel ID="controlRegion" Title="表单控件" runat="server" Region="West" RootVisible="false"
Width="200" Split="true" Collapsible="true" Collapsed="false">
<Store>
<ext:TreeStore ID="TreeStore1" runat="server">
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="type" />
</Fields>
</ext:Model>
</Model>
</ext:TreeStore>
</Store>
<Root>
<ext:Node NodeID="Root" Text="控件" Expanded="true">
<Children>
<ext:Node NodeID="type1" Text="区域控件" Expanded="true" AllowDrag="false">
<Children>
<ext:Node Leaf="true" Text="卡片区域">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="Card" Mode="Value" />
</CustomAttributes>
</ext:Node>
<ext:Node Leaf="true" Text="表格区域">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="Table" Mode="Value" />
</CustomAttributes>
</ext:Node>
<ext:Node Leaf="true" Text="混合区域">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="Mixed" Mode="Value" />
</CustomAttributes>
</ext:Node>
</Children>
</ext:Node>
<ext:Node NodeID="type0" Text="常用控件" Expanded="true" AllowDrag="false">
<Children>
<ext:Node Leaf="true" Text="文本">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="TextField" Mode="Value" />
</CustomAttributes>
</ext:Node>
<ext:Node Leaf="true" Text="多文本">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="TextArea" Mode="Value" />
</CustomAttributes>
</ext:Node>
<ext:Node Leaf="true" Text="按钮" Icon="Button">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="Button" Mode="Value" />
</CustomAttributes>
</ext:Node>
<ext:Node Leaf="true" Text="复选框" Icon="CheckError">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="CheckBox" Mode="Value" />
</CustomAttributes>
</ext:Node>
<ext:Node Leaf="true" Text="单选框">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="Radio" Mode="Value" />
</CustomAttributes>
</ext:Node>
<ext:Node Leaf="true" Text="数字">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="NumberField" Mode="Value" />
</CustomAttributes>
</ext:Node>
<ext:Node Leaf="true" Text="金额">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="MoneyField" Mode="Value" />
</CustomAttributes>
</ext:Node>
<ext:Node Leaf="true" Text="日期">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="DateField" Mode="Value" />
</CustomAttributes>
</ext:Node>
<ext:Node Leaf="true" Text="下拉">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="ComboBox" Mode="Value" />
</CustomAttributes>
</ext:Node>
<ext:Node Leaf="true" Text="下拉树">
<CustomAttributes>
<ext:ConfigItem Name="type" Value="NetDropDown" Mode="Value" />
</CustomAttributes>
</ext:Node>
</Children>
</ext:Node>
</Children>
</ext:Node>
</Root>
</ext:TreePanel>


但是为了方便扩展,我们通常需要一个描述控件分组和控件本身信息的Xml文件,通过取数接口加载到界面上,这样后期维护的时候只需要修改该文件就可以了。

在上面的代码中,我分别为每种控件第一个了类型,比如:卡片区域 type=Card,表格区域 type=Table,文本控件 type=TextField,金额控件 type=MoneyField等等。这里定义的内容会和我们后台代码定义的控件枚举类型匹配,为了方便我们把后台定义的控件类型也就定义为和这里一样的名称。

/// <summary>
/// 表单分组块的类型
/// </summary>
public enum GroupType
{
/// <summary>
/// 卡片 (主表)
/// </summary>
Card = 0,
/// <summary>
/// 明细表格
/// </summary>
Table,
/// <summary>
/// 混合区域
/// </summary>
Mixed,
}


区域分组控件
到这里我们基本定义和归纳了表单的容器控件和常用控件,下一节我介绍表单控件的拖放设计。

    

                         
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: