3.5.2.2 构建View的Template

我们在很多时候需要自定义模型的管理页面,而不是直接使用默认页面,比如字段的展示与隐藏,Action是否在这个页面上出现,搜索条件自定义等等,那么本章节带您一起学习如何自定义View的Template。

自定义View的Template

在使用默认layout的情况下,我们来做几个自定义视图Template,并把文件放到指定目录下。

3.5.2.2 构建View的Template

图3-5-2-14 自定义View的Template

第一个Tabel

Step1 自定义PetTalent的列表

  1. 我们先通过数据库查看默认页面定义,找到base_view表,过滤条件设置为model =\'demo.PetTalent\',我们就看到该模型下对应的所有view,这些是系统根据该模型的ViewAction对应生成的默认视图,找到类型为【表格(type = TABLE)】的记录,查看template字段。

3.5.2.2 构建View的Template

图3-5-2-15 base_view表查看template字段

<view name="tableView" cols="1" type="TABLE" enableSequence="false">
  <template slot="actions" autoFill="true"/>
  <template slot="rowActions" autoFill="true"/>
  <template slot="fields">
    <field invisible="true" data="id" label="ID" readonly="true"/>
    <field data="name" label="达人"/>
    <field data="dataStatus" label="数据状态">
      <options>
        <option name="DRAFT" displayName="草稿" value="DRAFT" state="ACTIVE"/>
        <option name="NOT_ENABLED" displayName="未启用" value="NOT_ENABLED" state="ACTIVE"/>
        <option name="ENABLED" displayName="已启用" value="ENABLED" state="ACTIVE"/>
        <option name="DISABLED" displayName="已禁用" value="DISABLED" state="ACTIVE"/>
      </options>
    </field>
    <field data="createDate" label="创建时间" readonly="true"/>
    <field data="writeDate" label="更新时间" readonly="true"/>
    <field data="createUid" label="创建人id"/>
    <field data="writeUid" label="更新人id"/>
  </template>
  <template slot="search" autoFill="true" cols="4"/>
</view>

图3-5-2-16 base_view表查看template字段

  1. 对比view的template定义与页面差异,从页面上看跟view的定义少了,创建人id和更新人id。因为这两个字段元数据定义里invisible属性。

a. 当XML里面没有配置,则用元数据覆盖了。

b. 当XML里面配置了,则不会用元数据覆盖了。

在下一步中我们只要view的DSL中给这两个字段加上invisible="false"就可以展示出来了

3.5.2.2 构建View的Template

图3-5-2-17 查看列表展示

3.5.2.2 构建View的Template

图3-5-2-18 invisible属性

  1. 新建pet_talent_table.xml文件放到对应的pamirs/views/demo_core/template目录下,内容如下

a. 对比默认视图,在自定义视图时需要额外增加属性model="demo.PetTalent"

b. name设置为"tableView",系统重启后会替换掉base_view表中model为"demo.PetTalent",name为"tableView",type为"TABLE"的数据记录。

ⅰ. name不同的但type相同,且viewAction没有指定时,根据优先级priority进行选择。小伙伴可以尝试修改name="tableView1",并设置priority为1,默认生成的优先级为10,越小越优先。

ccreateUid和writeUid字段,增加invisible="false"的属性定义

<view name="tableView" model="demo.PetTalent" cols="1" type="TABLE" enableSequence="false">
  <template slot="actions" autoFill="true"/>
  <template slot="rowActions" autoFill="true"/>
  <template slot="fields">
    <field invisible="true" data="id" label="ID" readonly="true"/>
    <field data="name" label="达人"/>
    <field data="dataStatus" label="数据状态">
      <options>
        <option name="DRAFT" displayName="草稿" value="DRAFT" state="ACTIVE"/>
        <option name="NOT_ENABLED" displayName="未启用" value="NOT_ENABLED" state="ACTIVE"/>
        <option name="ENABLED" displayName="已启用" value="ENABLED" state="ACTIVE"/>
        <option name="DISABLED" displayName="已禁用" value="DISABLED" state="ACTIVE"/>
      </options>
    </field>
    <field data="createDate" label="创建时间" readonly="true"/>
    <field data="writeDate" label="更新时间" readonly="true"/>
    <field data="createUid" label="创建人id" invisible="false"/>
    <field data="writeUid" label="更新人id" invisible="false"/>
  </template>
  <template slot="search" autoFill="true" cols="4"/>
</view>

图3-5-2-19 增加invisible="false"的属性定义

Step2 重启应用看效果

3.5.2.2 构建View的Template

图3-5-2-20 示例效果

第一个Form

Step1 自定义PetTalent的编辑页

  1. 我们先通过数据库查看默认页面定义,找到base_view表,过滤条件设置为model =\'demo.PetTalent\',我们就看到该模型下对应的所有view,这些是系统根据该模型的ViewAction对应生成的默认视图,找到类型为【表单(type = FORM)】的记录,查看template字段。

  2. 新建一个pet_talent_form.xml文件放在对应的pamirs/views/demo_core/template目录下,把数据状态下拉选项去除一个【草稿】选项

a. 对比默认视图,在自定义视图时需要额外增加属性model="demo.PetTalent" bname设置为"formView1",系统重启后会在base_view表中新增一个model为"demo.PetTalent",name为"formView1",type为"FORM",并设置priority为1 的数据记录。

ⅰ. name不同的但type相同,且viewAction没有指定时,根据优先级priority进行选择,默认生成的优先级为10,越小越优先。所以在此打开新增或编辑页面默认会路由到我们新配置的view上

<view name="formView1" model="demo.PetTalent" cols="2" type="FORM" priority="1">
  <template slot="actions" autoFill="true"/>
  <template slot="fields">
    <pack widget="group" title="基础信息">
      <field invisible="true" data="id" label="ID" readonly="true"/>
      <field data="name" label="达人"/>
      <field data="dataStatus" label="数据状态">
        <options>
          <!-- option name="DRAFT" displayName="草稿" value="DRAFT" state="ACTIVE"/ -->
          <option name="NOT_ENABLED" displayName="未启用" value="NOT_ENABLED" state="ACTIVE"/>
          <option name="ENABLED" displayName="已启用" value="ENABLED" state="ACTIVE"/>
          <option name="DISABLED" displayName="已禁用" value="DISABLED" state="ACTIVE"/>
        </options>
      </field>
      <field invisible="true" data="createDate" label="创建时间" readonly="true"/>
      <field invisible="true" data="writeDate" label="更新时间" readonly="true"/>
      <field data="createUid" label="创建人id"/>
      <field data="writeUid" label="更新人id"/>
    </pack>
  </template>
</view>

图3-5-2-21 自定义PetTalent的编辑页

Step2 重启看效果

3.5.2.2 构建View的Template

图3-5-2-22 示例效果

第一个Detail

Step1 自定义PetTalent的详情页

  1. 我们先通过数据库查看默认页面定义,找到base_view表,过滤条件设置为model =\'demo.PetTalent\',我们就看到该模型下对应的所有view,这些是系统根据该模型的ViewAction对应生成的默认视图,找到类型为【表单(type = DETAIL)】的记录,查看template字段。

  2. 新建一个pet_talent_detail.xml文件放在pamirs-demo-core的pamirs/views/demo_core/template目录下

a. 对比默认视图,在自定义视图时需要额外增加属性model="demo.PetTalent"

b. 把分组的title从【基础信息】改成【基础信息1】

<view name="detailView" cols="2" type="DETAIL" model="demo.PetTalent">
  <template slot="actions" autoFill="true"/>
  <template slot="fields">
    <pack widget="group" title="基础信息1">
      <field invisible="true" data="id" label="ID" readonly="true"/>
      <field data="name" label="达人"/>
      <field data="dataStatus" label="数据状态">
        <options>
          <option name="DRAFT" displayName="草稿" value="DRAFT" state="ACTIVE"/>
          <option name="NOT_ENABLED" displayName="未启用" value="NOT_ENABLED" state="ACTIVE"/>
          <option name="ENABLED" displayName="已启用" value="ENABLED" state="ACTIVE"/>
          <option name="DISABLED" displayName="已禁用" value="DISABLED" state="ACTIVE"/>
        </options>
      </field>
      <field data="createDate" label="创建时间" readonly="true"/>
      <field data="writeDate" label="更新时间" readonly="true"/>
      <field data="createUid" label="创建人id"/>
      <field data="writeUid" label="更新人id"/>
    </pack>
  </template>
</view>

图3-5-2-23 自定义PetTalent的详情页

Step2 重启看效果

3.5.2.2 构建View的Template

图3-5-2-24 示例效果

第一个Search

Step1 自定义PetTalent的列表页的搜索项

修改pet_talent_table.xml文件,默认情况下代表着跟表格的字段自动填充搜索字段,我们搜索条件只保留【数据状态】和【创建时间】

<view name="tableView" model="demo.PetTalent" cols="1" type="TABLE" enableSequence="true" baseLayoutName="">
    <template slot="actions" autoFill="true"/>
    <template slot="rowActions" autoFill="true"/>
    <template slot="fields">
        <field invisible="true" data="id" label="ID" readonly="true"/>
        <field data="name" label="达人"/>
        <field data="dataStatus" label="数据状态">
            <options>
                <option name="DRAFT" displayName="草稿" value="DRAFT" state="ACTIVE"/>
                <option name="NOT_ENABLED" displayName="未启用" value="NOT_ENABLED" state="ACTIVE"/>
                <option name="ENABLED" displayName="已启用" value="ENABLED" state="ACTIVE"/>
                <option name="DISABLED" displayName="已禁用" value="DISABLED" state="ACTIVE"/>
            </options>
        </field>
        <field data="createDate" label="创建时间" readonly="true"/>
        <field data="writeDate" label="更新时间" readonly="true"/>
        <field data="createUid" label="创建人id" invisible="false"/>
        <field data="writeUid" label="更新人id" invisible="false"/>
    </template>
    <template slot="search"  cols="4">
        <field data="dataStatus" label="数据状态">
            <options>
                <option name="DRAFT" displayName="草稿" value="DRAFT" state="ACTIVE"/>
                <option name="NOT_ENABLED" displayName="未启用" value="NOT_ENABLED" state="ACTIVE"/>
                <option name="ENABLED" displayName="已启用" value="ENABLED" state="ACTIVE"/>
                <option name="DISABLED" displayName="已禁用" value="DISABLED" state="ACTIVE"/>
            </options>
        </field>
        <field data="createDate" label="创建时间"/>
    </template>
</view>

图3-5-2-25 自定义PetTalent的列表页的搜索项

Step2 重启看效果

3.5.2.2 构建View的Template

图3-5-2-26 示例效果

其他

search默认查询的是模型的queryPage函数,但我们有时候需要替换调用的函数,下个版本支持。其核心场景为当搜索条件中有非存储字段,如果直接用queryPage函数的rsql拼接就会报错。本版本临时替代方案见4.1.14【Search之非存储字段条件】一文。

Oinone社区 作者:史, 昂原创文章,如若转载,请注明出处:https://doc.oinone.top/oio4/9253.html

访问Oinone官网:https://www.oinone.top获取数式Oinone低代码应用平台体验

(0)
史, 昂的头像史, 昂数式管理员
上一篇 2024年5月23日 am9:25
下一篇 2024年5月23日 am9:27

相关推荐

  • 致Oinone读者

    欢迎来到Oinone生态,我们为您提供了一站式低代码商业支撑平台,数式科技已经用其服务了如中烟、得力、上海电气、中航金网、雾芯科技等多个知名企业,我们的技术实力在商业场景得到了很好的验证。我们希望通过开源Oinone项目,为中国软件行业带来变革,提升整体工程化水平,与广大软件工程师一起为客户创造价值!《Oinone 7天从入门到精通》一书是Oinone开源项目的配套书籍,系统化地介绍了如何基于Oinone开源项目,快速开发高质量的软件系统。此外,如果您开发的项目是用于商业化而非企业自用,我们还为您提供了一种可选的商业化变现途径:申请成为Oinone的合作伙伴,并提交相关产品,详情请访问 www.oinone.top 网站。 书籍纲领 本书的章节安排如下: 第一章至第二章:【揭开面纱,理解Oinone】和【Oinone的技术独特性】。这两个章节可以帮助您更好地理解我们设计Oinone的初衷以及特性的由来。 第三章:面向研发人员的【Oinone的基础入门】。如果您是专业的研发人员,本章可以帮助您快速上手并做出业务系统。只要按着里面的case一步步操作下来就可以。 第四章至第六章:面向研发人员的【Oinone的高级特性】、【Oinone的CDM】、【Oinone的通用能力】。这三篇章节重点介绍了Oinone的高级技术特性、提供的通用数据模型和通用基础能力。它们能够帮助我们更快地进行业务开发,从容应对业务的特殊场景要求,比较适合进阶的研发人员。 第七章:面向非研发人员的【Oinone的设计器们】和【Oinone的低无一体】。如果您并不是专业的研发人员,本章可以帮助您通过使用Oinone的无代码可视化设计器轻松自主解决业务需求,并且当可视化设计器满足不了的时候,您还可以在【Oinone的低无一体】中找到方式,并寻求研发帮助

    Oinone 7天入门到精通 2024年5月23日
    1.7K00
  • 用户中心

    1. 创建用户 进入用户中心应用,在用户列表中点击创建。 填写表单中的必填信息。 若未设置昵称,则右上角头像右侧展示名称。若设置了昵称,则右上角头像右侧展示昵称。 是否激活账号选择是,选择否时用户登录会显示“未找到首页”。 角色分组中,选择创建的用户的角色,默认选择了超级管理员(包含所有权限)。 点击确定,用户创建完成。 用户登录时可用登录账号/邮箱/手机号登录。 2. 用户相关操作 表格页中包含常规的搜索、批量删除功能。 冻结:当将“是否有效”状态为“是”时展示,将用户“是否有效”修改为“否”。 解冻:当将“是否有效”状态为“否”时展示,将用户“是否有效”修改为“是”。 修改:进入用户信息修改页面,“编码、登录账号、注册时间”只读。 重置密码:点击后在弹窗“账号确认”中输入账号,点击重置密码后,展示新密码。

    2024年6月20日
    2.5K00
  • 4.1.19 框架之网关协议-后端占位符

    在我们日常开发中会有碰到一些特殊场景,需要由前端来传一些如“当前用户Id”、“当前用户code”诸如此类只有后端才知道值的参数,那么后端占位符就是来解决类似问题的。如前端传${currentUserId},后端会自动替换为当前用户Id。 Step1 后端定义占位符 我们新建一个UserPlaceHolder继承AbstractPlaceHolderParser,用namespace来定义一个“currentUserId”的占位符,其对应值由value()决定为“PamirsSession.getUserId().toString()”,active要为真才有效,priority为优先级 package pro.shushi.pamirs.demo.core.placeholder; import org.springframework.stereotype.Component; import pro.shushi.pamirs.meta.api.session.PamirsSession; import pro.shushi.pamirs.user.api.AbstractPlaceHolderParser; @Component public class UserPlaceHolder extends AbstractPlaceHolderParser { @Override protected String value() { return PamirsSession.getUserId().toString(); } @Override public Integer priority() { return 10; } @Override public Boolean active() { return Boolean.TRUE; } @Override public String namespace() { return "currentUserId"; } } 图4-1-19-1 后端定义占位符 Step2 前端使用后端占位符 我们经常在o2m和m2m中会设置domain来过滤数据,这里案例就是在field中设置来过滤条件,domain="createUid == $#{currentUserId}",注意这里用的是$#{currentUserId} 而不是${currentUserId},这是前端为了区分真正变量和后端占位符,提交的时候会把#过滤掉提交。修改宠物达人表格视图的Template中search部分 <template slot="search" cols="4"> <field data="name" label="达人"/> <field data="petTalentSex" multi="true" label="达人性别"/> <field data="creater" /> <!– <field data="petShops" label="宠物商店" domain="createUid == ${activeRecord.creater.id}"/>–> <field data="petShops" label="宠物商店" domain="createUid == $#{currentUserId}"/> <field data="dataStatus" label="数据状态" multi="true"> <options> <option name="DRAFT" displayName="草稿" value="DRAFT" state="ACTIVE"/> <option name="NOT_ENABLED" displayName="未启用" value="NOT_ENABLED" state="ACTIVE"/> <option name="ENABLED" displayName="已启用" value="ENABLED" state="ACTIVE"/> <option name="DISABLED" displayName="已禁用" value="DISABLED" state="ACTIVE"/> </options> </field> <field data="createDate" label="创建时间"/> <field data="unStore" /> </template> 图4-1-19-2 前端使用后端占位符 Step3 重启看效果 请求上都带上了createUid==${currentUserId} 图4-1-19-3 示例效果

    2024年5月23日
    1.7K00
  • 4.3 Oinone的分布式体验

    在oinone的体系中分布式比较独特,boot工程中启动模块中包含就走本地,不包含就走远程,本文带您体验下分布式部署以及分布式部署需要注意点。 看下面例子之前先把话术统一下:启动或请求SecondModule代表启动或请求pamirs-second-boot工程,启动或请求DemoModule代表启动或请求pamirs-demo-boot工程,并没有严格意义上启动哪个模块之说,只有启动工程包含哪个模块。 一、构建SecondModule模块 Step1 构建模块工程 参考3.2.1【构建第一个Module】一文,利用脚手架工具构建一个SecondModule,记住需要修改脚本。 脚本修改如下: #!/bin/bash # 项目生成脚手架 # 用于新项目的构建 # 脚手架使用目录 # 本地 local # 本地脚手架信息存储路径 ~/.m2/repository/archetype-catalog.xml archetypeCatalog=local # 以下参数以pamirs-second为例 # 新项目的groupId groupId=pro.shushi.pamirs.second # 新项目的artifactId artifactId=pamirs-second # 新项目的version version=1.0.0-SNAPSHOT # Java包名前缀 packagePrefix=pro.shushi # Java包名后缀 packageSuffix=pamirs.second # 新项目的pamirs platform version pamirsVersion=4.6.0 # Java类名称前缀 javaClassNamePrefix=Second # 项目名称 module.displayName projectName=OinoneSecond # 模块 MODULE_MODULE 常量 moduleModule=second_core # 模块 MODULE_NAME 常量 moduleName=SecondCore # spring.application.name applicationName=pamirs-second # tomcat server address serverAddress=0.0.0.0 # tomcat server port serverPort=8090 # redis host redisHost=127.0.0.1 # redis port redisPort=6379 # 数据库名 db=demo # zookeeper connect string zkConnectString=127.0.0.1:2181 # zookeeper rootPath zkRootPath=/second mvn archetype:generate \ -DinteractiveMode=false \ -DarchetypeCatalog=${archetypeCatalog} \ -DarchetypeGroupId=pro.shushi.pamirs.archetype \ -DarchetypeArtifactId=pamirs-project-archetype \ -DarchetypeVersion=4.6.0 \ -DgroupId=${groupId} \ -DartifactId=${artifactId} \ -Dversion=${version} \ -DpamirsVersion=${pamirsVersion} \ -Dpackage=${packagePrefix}.${packageSuffix} \ -DpackagePrefix=${packagePrefix} \ -DpackageSuffix=${packageSuffix} \ -DjavaClassNamePrefix=${javaClassNamePrefix} \ -DprojectName="${projectName}" \ -DmoduleModule=${moduleModule} \ -DmoduleName=${moduleName} \ -DapplicationName=${applicationName} \ -DserverAddress=${serverAddress} \ -DserverPort=${serverPort} \ -DredisHost=${redisHost} \ -DredisPort=${redisPort} \ -Ddb=${db} \ -DzkConnectString=${zkConnectString} \ -DzkRootPath=${zkRootPath} 图4-3-1 构建一个名为SecondModule的模块 脚步执行生成工程如下: 图4-3-2 SecondModule的工程结构 Step2 调整配置 修改application-dev.yml文件 修改SecondModule的application-dev.yml的内容 base库换成与DemoModule一样的配置,配置项为:pamirs.datasource.base pamirs: datasource: base: driverClassName: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://127.0.0.1:3306/demo_base?useSSL=false&allowPublicKeyRetrieval=true&useServerPrepStmts=true&cachePrepStmts=true&useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&autoReconnect=true&allowMultiQueries=true username: root # 数据库用户 password: oinone # 数据库用户对应的密码 initialSize: 5 maxActive: 200 minIdle: 5 maxWait: 60000 timeBetweenEvictionRunsMillis: 60000…

    2024年5月23日
    1.6K00

Leave a Reply

登录后才能评论