Skip to content
本页目录

CreateFormView

基于视图渲染的表单,表格的页面组件

说明

  • 表格的操作列不用代码写死,直接在视图按钮那配置,将是否操作按钮选择 true
  • 多级表格配置除了配父子关联之外,还得注意父级 col_level 为 1,col_span 为子级的个数,二级 col_level 为 2,col_span 为 1
  • 多级表格如果合计行的列数与表格不一致,请检查 col_span,col_level
  • 表格的合计在视图那配置是否合计,开启后默认金额列都会合计
  • 豆腐块上面的按钮视图样式类型配置支持 主,次,普通 三种类型,在备注配置 btnLevel,同 create-view 组件
  • 表单项的 disable 优先级 视图定义 > sectionDisable > pageDisabled ,最后前三者都不为 true 时,disabledCondition 生效
  • 下拉和树形下拉多选时暂不支持配置缺省值,缺省值赋值仅支持字符串类型和是否的数字类型

基本用法

组件演示

示例
vue
<template>
  <div>
    <CreateFormView
      ref="createFormRef"
      :all-ui-views="formUiViews"
      :form-data="formData"
      :dataSource="dataSource"
      :is-anchor="true"
      show-type="card"
      :tabBeforeChange="tabBeforeChanges"
    >
      <template #cardInfo_QUOTA_LIST>
        <a-alert message="提示信息" type="warning" show-icon />
      </template>
    </CreateFormView>
  </div>
</template>
<script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue'
// 引用组件
import { CreateFormView } from 'ctj-ui-next'

const formUiViews = reactive({})

const formData = reactive({})
const dataSource = reactive({
  BILL_LIST: [{}, {}],
})
const tabBeforeChanges = async (prev: any, next: any) => {
  return new Promise((resolve, reject) => {
    if (next == 'comMeetingTopicsPOS') {
      resolve(false)
    } else {
      resolve(true)
    }
  })
}
</script>
<style lang="less" scoped></style>
<template>
  <div>
    <CreateFormView
      ref="createFormRef"
      :all-ui-views="formUiViews"
      :form-data="formData"
      :dataSource="dataSource"
      :is-anchor="true"
      show-type="card"
      :tabBeforeChange="tabBeforeChanges"
    >
      <template #cardInfo_QUOTA_LIST>
        <a-alert message="提示信息" type="warning" show-icon />
      </template>
    </CreateFormView>
  </div>
</template>
<script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue'
// 引用组件
import { CreateFormView } from 'ctj-ui-next'

const formUiViews = reactive({})

const formData = reactive({})
const dataSource = reactive({
  BILL_LIST: [{}, {}],
})
const tabBeforeChanges = async (prev: any, next: any) => {
  return new Promise((resolve, reject) => {
    if (next == 'comMeetingTopicsPOS') {
      resolve(false)
    } else {
      resolve(true)
    }
  })
}
</script>
<style lang="less" scoped></style>

属性 Props

参数说明类型可选值默认值
allUiViews视图数据(必填)UiData--
formData表单数据(必填)Record<string, any>--
dataSource表格数据(必填)Record<string, any[]>--
showType展示类型CreateFormShowType'line' or 'card'line
isAnchor是否显示锚点boolean-false
viewConfigData表单表格配置viewConfig参考viewConfig 配置-
saveRules保存校验规则SaveRule[]参考SaveRule 说明-
cusOptionObj自定义的下拉框下拉树的 options 数据Record<string, any[]>--
cardContentHshowType='card'时最小高度,不传默认内容高度number--
pageDisabled是否让整个页面 disabledboolean-false
uploadParams附件上传需要的参数UploadParams参考UploadParams 配置-
billTypeId业务类型 idstring--
queryExtra通用的接口参数QueryExtra参考queryExtra 配置-
namedType下拉等,拼接 id,name 的命名方式'hump' / 'underline'hump:驼峰,underline:下划线-
importConfig导入参数配置{tempType?:string,templatePath?: string}tempType:模版 code,templatePath:下载路径-
formTotalCol表单总共显示列数,默认一行显示 3 列-1/2/3-
attachGetAttribute附件模块默认 get_attrtibutestring-'pmApplyAttachList'
invoiceGetAttribute发票模块默认 get_attrtibutestring-'invoiceDTOS'
tabBeforeChange页签切换限制函数Promise-tabBeforeChange(prev:当前页签 key,next:即将切换的页签 key)
formShowType表单展现形式:表单模式/打印模式FormShowType-FormShowType.form
rowData编辑进入的当前行数据object-{}
formLayoutType表单布局FormLayoutType'horizontal''vertical''inline''horizontal'

事件 Events

事件名说明回调参数参数说明
headerBtnClick豆腐块上的按钮点击事件({type,btn,get_attribute}:HeaderBtnParams)
type 当前按钮的 icon,btn 当前点击的按钮, get_attribute 当前豆腐块的 get_attribute
tableFormChange表格内的 form 表单 change 事件({value,column,index,dateStrings,option}:tableFormParams,get_attribute:string)
value 当前 form 表单的 value, column 当前 form 表单的 column,index:当前行 index,dateStrings 为范围日期框的字符串日期数组,option 为下拉框,下拉树当前选择的 option
formChange表单内的 form 表单 change 事件({value,column,dateStrings,option}:tableFormParams,get_attribute:string)
value 当前 form 表单的 value, column 当前 form 表单的 column,dateStrings 为范围日期框的字符串日期数组,option 为下拉框,下拉树当前选择的 option
operate表格内的按钮点击事件({record,column,index}:OperateParams)
record 当前行数据, column 当前操作按钮的属性,index:当前行 index
doModalCheck弹框选中事件(selectRows,currentBtn,index,closeJumpModal)
selectRows 选中的数据, currentBtn 当前点击的按钮或者表单项 index 当前行的 index,表格时有用,closeJumpModal 手动关闭三级弹框方法
tableAddRow表格新增事件({dataSource,get_attribute})
dataSource 当前表数据, get_attribute 当前豆腐块的 get_attribute
formClick自定义下拉框的 formatter 显示的点击事件({column,event,index},get_attribute:string)-
importSuccess导入成功事件,传了 tempType 时直接调接口成功的事件(data, get_attrtibute)接口返回的数据,不一定有、当前导入按钮所在区块的 get_attrtibute
importFulfill导入文件完成事件,没传 tempType 时的导入完成事件formData, get_attrtibute文件数据、当前导入按钮所在区块的 get_attrtibute
downloadTemplate下载按钮点击事件,不传 templatePath,tempType、templateParams 时抛出的事件get_attrtibute当前导入按钮所在区块的 get_attrtibute
formTabChangecreate-form-view showType='card'并且未传递 tabBeforeChange 时抛出事件 formTabChange,参数为当前页签的 key

方法和数据

方法名说明参数参数说明备注|
formValidate触发表单表格的必填校验回调函数中传会传出 formData,dataSourcecreateFormRef.value.formValidate().then(async () => {})-
clearHideData删除隐藏区块的对象数据示例:BillFormRef.value?.clearHideData()
toggleCalc触发计算(get_attribute,singleParams?: { column: any; index?: number })豆腐块 get_attribute,singleParams:当需要触发单表时传,其中 index 时表格时传
示例:BillFormRef?.value?.toggleCalc('SERVICE_DETAIL')
initAfterDetail获取到详情数据之后初始化操作(目前执行了 js 脚本,联动规则)-示例:createFormRef.value.initAfterDetail()-
refreshAttachData刷新附件数据---
formDatacreateFormView 的 formData 数据---
dataSourcecreateFormView 的 dataSource 数据---
eleDataObjcreateFormView 的下拉数据数据---

viewConfig 配置

viewConfig 的数据格式为{[key: string]: viewConfigItem},key 为每个豆腐块的 get_attribute,值为 viewConfigItem 类型的数据,下表是 viewConfigItem 的配置

参数说明类型可选值默认值
showIndex是否显示序号列(表格时才生效)boolean-false
rowKey表格的 rowKey,当需要显示复选框,单选框时,rowKey 必传string--
visible是否显示该豆腐块boolean-true
isAdd是否显示新增按钮(表格时才生效)boolean-true
isDelete是否显示删除操作(表格时才生效)boolean-true
isCopy是否显示复制操作(表格时才生效)boolean-true
cusDelete是否自己处理删除操作,传 true 时,内部不进行删除,由外部自己写删除逻辑boolean-false
cusCopy是否自己处理复制操作,传 true 时,内部不进行复制,由外部自己写复制逻辑boolean-false
cusAdd是否自己处理新增操作,传 true 时,内部不进行新增,自己监听 tableAddRow 事件boolean-false
cusSummary是否自己写表格总结栏,自己写了这个,合计行不生效了boolean-false
primaryKey当内部处理复制时,需要传一个 id 的名称,防止复制的时候把 id 也复制了stirng--
isAttachDown附件列表是显示附件下载按钮boolean-true
cusAttachDown是否自己处理附件下载boolean-false
isAttachDelete附件列表是显示附件删除按钮boolean-true
sectionDisabled当前豆腐块是否 disabledboolean-false
pagination分页配置,如需分页,参考 antd-vue 表格那的分页配置boolean/TablePaginationConfig-false
footerConfig合计行配置参考footerConfig 配置--
columnConfig表单项配置(表格,表单)[key: string]: UiColumnConfig,key 为 field_code,参考columnConfig 配置--
originColumnConfig表格对表格列原始 antDesign-vue 配置(表格)[key: string]: any,key 为 field_code--
operateConfig表格的操作列配置[key: string]: OperateConfig,key 为每个按钮的 type,参考operateConfig 配置--
buttonConfig豆腐块的按钮配置(专门配置弹出框的参数)[key: string]: JumpButtonConfig,key 为每个按钮的 icon,参考JumpButtonConfig 配置--
btnConfig豆腐块的按钮配置[key: string]: {disabled:boolean,visible:boolean}disabled 是否禁用,visible:是否显示-
requiredFn是否显示必填星号*(record, column):boolean=>{}--
isTextFn是否显示 text(record, column):boolean=>{}--
recordDisabledFn是否行禁用(record, column):boolean=>{}--
requiredFn是否显示必填星号*(record, column):boolean=>{}--
handleRowExpand表格展开行处理函数(expanded, record)=>{}--
isVirtualScrolling是否开启虚拟滚动boolean-false
cardTipStyle区块提示信息的个性化样式object-{display: inline-block;color: red; font-size: 14px; padding: 0 14px;}

其余表格 antd 原生配置也支持(#https://www.antdv.com/components/table-cn#table)

uploadParams 说明

参数说明类型可选值默认值
isUpload是否需要附件上传(必传)boolean-false
billTypeId表单对应的 billTypeId(必传)string--
billId表单对应的 billId(必传)string--
businessType表单对应的 businessType(必传)string--
attach_remark上传附件需要的 attach_remarkstring--
pro_code上传附件需要的 pro_codestring--
his_id上传附件需要的 his_idstring--
is_additional上传附件需要的 is_additionalany--
isDisable是否 disabledboolean-false
isCamera是否显示高拍仪上传boolean-false
isFilterDevice高拍仪上传时是否需要过滤电脑白名单boolean-false

footerConfig 配置

参数说明类型可选值默认值
visible是否显示合计行boolean-false
titleKey“合计”显示在哪一列string--
title‘合计’名称string-‘合计’
computedKeys需要计算的列string[]--

columnConfig 配置

参数说明类型可选值默认值
showBtn是否显示右边的按钮(只有输入框和特殊框生效)boolean-false
dataFormateType日期框的 formateTypestring-日期框:YYYY-MM-DD,有时分秒的:YYYY-MM-DD HH:mm:ss
visible是否显示当前表单项,默认显示boolean-true
getDisableDate日期框或日期范围框 disableDate 的回调函数(current,record):date=>{}--
getDisableTime日期框或日期范围框 disableTime 的回调函数(current,record):date=>{}--
disabledCondition表单 disable 的回调函数(record):boolean=>{}--
getClassName设置表单的 class(record):string=>{}--
chooseModal当 showBtn=true 时,点击右侧按钮的响应函数(record, index, column)=>{}--
formatter控件类型为特殊框时的自定义渲染函数(可以为 html)(record)=>{}--
columnFormatter自定义渲染函数(可以为 html)(record)=>{}--
cusRender自定义渲染组件(必须为 vue 的 h 函数书写)(record)=>{}--
textFormate自定义 显示 函数,只有输入框以及文本框时有效,textFormate 与 columnFormatter 的区别在于 textFormate 只处理当前文本的显示,输入框还保留,columnFormatter 是直接显示函数返回的内容(record)=>{}--
cellOption自定义下拉数据,可以配置表格同一列中不同行的 options(record)=>{}--
isRequired当前字段是否必填boolean--
defaultMaskStatus需要掩码的默认是否需要掩码boolean--
buttonConfigshowBtn=true 时右侧按钮配置(专门配置弹出框的参数)JumpButtonConfig,参考JumpButtonConfig 配置--
isConcat是否允许使用拼接下拉 optionbooleantrue/falsefalse
beforeClick点击获取验证码的按钮之前的判断,例如是否录入了手机号等()=>{}--
codeSeconds手机验证码倒计时秒数number-60
uploadParams单独文件上传组件的相关配置参数{ limit?: number,type?: any,uploadUrl?: string,previewUrl?: string,listType?: string}--
text分割线-文字string--
orientationMargin分割线-标题和最近 left/right 边框之间的距离,去除了分割线,同时 orientation 必须为 left 或 rightnumber | string--
isCCAmount金额类组件是否显示汉字金额IsOrNOT-IsOrNOT.not

operateConfig 配置

参数说明类型可选值默认值
visible是否显示当前按钮,默认显示boolean-true
disabledCondition按钮的 disable 的回调函数(record):boolean=>{}--
visibleCondition按钮的 是否显示 的回调函数(record):boolean=>{}--

JumpButtonConfig 配置

参数说明类型可选值默认值
isCustom是否内部处理弹出框boolean-false
request弹出框表格接口及参数api,params--
searchConfigs弹出框表格查询项配置 参考SearchConfig 配置api,params--
options查询下拉数据{field_code:[]}-
modalWidth弹框宽度number | string-'90%'
beforeShowModal弹框显示前的周期函数--
cusHandleModal是否自己处理隐藏操作,设 true 时需要自己在 doCheck 以及 modalCancel 隐藏弹框boolean-false

其它参数见 create-view tableConfigs 配置

queryExtra 配置

因为 create-view 组件内部现在有很多内部请求,有很多接口用的参数有相同的,为了避免重复传,公共的参数放在这里 | 参数 | 说明 | 类型 | 可选值 | 默认值 | | --- | --- | --- | --- | :-: | | businessType | 业务 id | string | - | - | | menuId | 菜单 id | string | - | - |

插槽

${get_attribute}是动态值,get_attribute 是每个豆腐块的get_attribute

插槽名称数据说明
formHeader-页面头部信息插槽
cardBtn_${get*attribute}-豆腐块上的按钮插槽
cardInfo_${get*attribute}-豆腐块顶部标题名称和右侧按钮中间的提示信息插槽

Demo

表格豆腐块显示自定义总结栏

  1. viewConfigs 对应 getAttribute 加上 cusSummary 为 true
js
const viewConfigs =
  reactive <
  viewConfig >
  {
    comMeetingTopicsPOS: {
      cusSummary: true,
    },
  }
const viewConfigs =
  reactive <
  viewConfig >
  {
    comMeetingTopicsPOS: {
      cusSummary: true,
    },
  }
vue
<CreateFormView
  ref="createFormRef"
  :all-ui-views="formUiViews"
  :form-data="formData"
  :dataSource="dataSource"
  :is-anchor="true"
  show-type="line"
  :view-config-data="viewConfigs"
  :cus-option-obj="cusOptionObj"
  :upload-params="uploadParams"
  :billTypeId="billTypeId"
  :query-extra="QueryExtra"
  @import-fulfill="handleImport"
  @download-template="handleDownLoad"
  @table-form-change="tableFormChange"
  @operate="tableOperate"
  @do-modal-check="handleModalCheck"
  @form-click="handleFormClick"
  @header-btn-click="handleHeaderBtnClick"
>
    <template #summary_QUOTA_LIST="scoped">
      <a-table-summary-row>
        <template v-for="(column, index) in scoped.footerColumns" :key="index">
          <a-table-summary-cell :fixed="column.fixed" :align="column.align" :index="index">
            {{ column.dataIndex }}
          </a-table-summary-cell>
        </template>
      </a-table-summary-row>
      <a-table-summary-row>
        <template v-for="(column, index) in scoped.footerColumns" :key="index">
          <a-table-summary-cell :fixed="column.fixed" :align="column.align" :index="index">
            {{ column.dataIndex }}
          </a-table-summary-cell>
        </template>
      </a-table-summary-row>
    </template>
  </CreateFormView>
<CreateFormView
  ref="createFormRef"
  :all-ui-views="formUiViews"
  :form-data="formData"
  :dataSource="dataSource"
  :is-anchor="true"
  show-type="line"
  :view-config-data="viewConfigs"
  :cus-option-obj="cusOptionObj"
  :upload-params="uploadParams"
  :billTypeId="billTypeId"
  :query-extra="QueryExtra"
  @import-fulfill="handleImport"
  @download-template="handleDownLoad"
  @table-form-change="tableFormChange"
  @operate="tableOperate"
  @do-modal-check="handleModalCheck"
  @form-click="handleFormClick"
  @header-btn-click="handleHeaderBtnClick"
>
    <template #summary_QUOTA_LIST="scoped">
      <a-table-summary-row>
        <template v-for="(column, index) in scoped.footerColumns" :key="index">
          <a-table-summary-cell :fixed="column.fixed" :align="column.align" :index="index">
            {{ column.dataIndex }}
          </a-table-summary-cell>
        </template>
      </a-table-summary-row>
      <a-table-summary-row>
        <template v-for="(column, index) in scoped.footerColumns" :key="index">
          <a-table-summary-cell :fixed="column.fixed" :align="column.align" :index="index">
            {{ column.dataIndex }}
          </a-table-summary-cell>
        </template>
      </a-table-summary-row>
    </template>
  </CreateFormView>

预算单位软件产品开发部