Skip to content

Commit

Permalink
steedos-input-table调用ObjectForm中section相关函数支持宽窄字段
Browse files Browse the repository at this point in the history
  • Loading branch information
yinlianghui committed Nov 29, 2023
1 parent ae8248c commit 3b4b523
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: [email protected]
* @Date: 2022-05-26 16:02:08
* @LastEditors: 殷亮辉 [email protected]
* @LastEditTime: 2023-11-29 10:49:20
* @LastEditTime: 2023-11-29 17:48:27
* @Description:
*/
import * as Fields from '../fields';
Expand Down Expand Up @@ -63,18 +63,24 @@ const getSection = async (formFields, permissionFields, fieldSchemaArray, sectio
// console.log(`perField.type object ===> field`, field)
}
if (field.name.indexOf(".") < 0) {
ctx.__formFields = formFields;
const amisField = await Fields.convertSFieldToAmisField(field, field.readonly, ctx);
// 如果steedos-field稳定了,可以放开下面的代码直接用组件统一渲染字段
// const amisField = {
// "type": "steedos-field",
// "config": field,
// "readonly": field.readonly,
// "ctx": ctx
// };
// console.log(`${field.name} amisField`, field, amisField)
if (amisField) {
fieldSetBody.push(amisField);
if(field.type === "steedos-field"){
// 如果是steedos-field则不需要通过convertSFieldToAmisField函数转换,因为steedos-field组件会转换
fieldSetBody.push(field);
}
else{
ctx.__formFields = formFields;
const amisField = await Fields.convertSFieldToAmisField(field, field.readonly, ctx);
// 如果steedos-field稳定了,可以放开下面的代码直接用组件统一渲染字段
// const amisField = {
// "type": "steedos-field",
// "config": field,
// "readonly": field.readonly,
// "ctx": ctx
// };
// console.log(`${field.name} amisField`, field, amisField)
if (amisField) {
fieldSetBody.push(amisField);
}
}
}
}
Expand Down
35 changes: 20 additions & 15 deletions packages/@steedos-widgets/amis-lib/src/lib/input_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @Author: 殷亮辉 [email protected]
* @Date: 2023-11-15 09:50:22
* @LastEditors: 殷亮辉 [email protected]
* @LastEditTime: 2023-11-29 11:40:32
* @LastEditTime: 2023-11-29 17:48:02
*/

import { getTableColumns } from './converter/amis/fields/table';
import { getFormBody } from './converter/amis/form';

/**
* @param {*} props
Expand All @@ -15,6 +15,7 @@ function getFormFields(props, mode = "edit") {
return (props.fields || []).map(function (item) {
let formItem = {
"type": "steedos-field",
"name": item.name,
"config": item
}
if(mode === "readonly"){
Expand Down Expand Up @@ -88,12 +89,16 @@ async function getInputTableColumns(props) {
* @param {*} props
* @param {*} mode edit/new/readonly
*/
function getForm(props, mode = "edit") {
async function getForm(props, mode = "edit") {
let formFields = getFormFields(props, mode)
let body = await getFormBody(null, formFields);
let schema = {
"type": "form",
"title": "表单",
"debug": false,
"body": getFormFields(props, mode)
"mode": "normal",
"body": body,
"className": "steedos-object-form steedos-amis-form"
};
if (mode === "edit") {
Object.assign(schema, {
Expand Down Expand Up @@ -154,7 +159,7 @@ function getForm(props, mode = "edit") {
return schema;
}

function getButtonNew(props) {
async function getButtonNew(props) {
return {
"label": "新增",
"type": "button",
Expand All @@ -168,9 +173,9 @@ function getButtonNew(props) {
"type": "dialog",
"title": "新增行",
"body": [
getForm(props, "new")
await getForm(props, "new")
],
"size": "md",
"size": "lg",
"showCloseButton": true,
"showErrorMsg": true,
"showLoading": true,
Expand All @@ -185,7 +190,7 @@ function getButtonNew(props) {
};
}

function getButtonEdit(props) {
async function getButtonEdit(props) {
return {
"type": "button",
"label": "",
Expand All @@ -200,9 +205,9 @@ function getButtonEdit(props) {
"type": "dialog",
"title": "编辑行",
"body": [
getForm(props, "edit")
await getForm(props, "edit")
],
"size": "md",
"size": "lg",
"showCloseButton": true,
"showErrorMsg": true,
"showLoading": true,
Expand All @@ -216,7 +221,7 @@ function getButtonEdit(props) {
};
}

function getButtonView(props) {
async function getButtonView(props) {
return {
"type": "button",
"label": "",
Expand All @@ -231,9 +236,9 @@ function getButtonView(props) {
"type": "dialog",
"title": "查看行",
"body": [
getForm(props, "readonly")
await getForm(props, "readonly")
],
"size": "md",
"size": "lg",
"showCloseButton": true,
"showErrorMsg": true,
"showLoading": true,
Expand Down Expand Up @@ -275,14 +280,14 @@ export const getAmisInputTableSchema = async (props, readonly) => {
}
let buttonsForColumnOperations = [];
if (props.editable) {
let buttonEditSchema = getButtonEdit(props);
let buttonEditSchema = await getButtonEdit(props);
buttonsForColumnOperations.push(buttonEditSchema);
}
else{
// 只读时显示查看按钮
if(props.columns && props.columns.length > 0 && props.columns.length < props.fields.length){
// 只在有列被隐藏时才需要显示查看按钮
let buttonViewSchema = getButtonView(props);
let buttonViewSchema = await getButtonView(props);
buttonsForColumnOperations.push(buttonViewSchema);
}
}
Expand Down

0 comments on commit 3b4b523

Please sign in to comment.