Skip to content

Commit

Permalink
[Feature]: 审批王表单支持时间类型字段,规则与对象中时间类型字段一致 #6781
Browse files Browse the repository at this point in the history
  • Loading branch information
sunhaolin committed Apr 26, 2024
1 parent 5471706 commit 7a72f5a
Show file tree
Hide file tree
Showing 31 changed files with 224 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ getInstanceFieldValue = (objField, formField, record, object_field, spaceId, rec
value = selectFieldValue
else if formField && objField && formField.type == 'date' && recordFieldValue
value = uuflowManagerForInitApproval.formatDate(recordFieldValue) # Date转String
else if formField && objField && formField.type == 'time' && recordFieldValue
value = uuflowManagerForInitApproval.formatTime(recordFieldValue) # Time转String
else if formField && objField && recordFieldValue && (formField.type == 'image' || formField.type == 'file')
value = getFileFieldValue(recordFieldValue, formField.type)
else if formField && objField && recordFieldValue && formField.type == 'lookup' && ['lookup', 'master_detail'].includes(objField.type) && _.isString(objField.reference_to)
Expand Down Expand Up @@ -721,4 +723,7 @@ uuflowManagerForInitApproval.checkIsInApproval = (recordIds, spaceId) ->


uuflowManagerForInitApproval.formatDate = (date) ->
return moment(date).format("YYYY-MM-DD")
return moment(date).format("YYYY-MM-DD")

uuflowManagerForInitApproval.formatTime = (date) ->
return moment(date).utcOffset(0).format("1970-01-01THH:mm:00.000[Z]")
21 changes: 18 additions & 3 deletions creator/packages/steedos-formbuilder/lib/options.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 定义 formBuilder 所有的字段类型
FORMBUILDERFIELDTYPES = ["autocomplete", "paragraph", "header", "select",
"checkbox-group", "radio-group", "checkbox", "text", "file", "image", "lookup"
"checkbox-group", "radio-group", "checkbox", "text", "file", "image", "lookup",
"date", "number", "textarea",
"dateTime", "dateNew", "checkboxBoolean", "email", "url", "password", "user", "group",
"dateTime", "dateNew", "time", "checkboxBoolean", "email", "url", "password", "user", "group",
"table", "section",
"odata", "html"]

Expand All @@ -17,7 +17,7 @@ DISABLEDATTRS = ['description', 'maxlength', 'placeholder', "access", "value", '
'toggle', 'rows', 'subtype', 'multiple', 'name']

# 定义字段类型排序
CONTROLORDER = ['text', 'textarea', 'number', 'dateNew', 'dateTime', 'date', 'checkboxBoolean',
CONTROLORDER = ['text', 'textarea', 'number', 'dateNew', 'dateTime', 'date', "time", 'checkboxBoolean',
'email', 'url', 'password', 'select', 'user', 'group', "radio-group", "checkbox-group", "file", "image", "lookup", "odata", "html", 'table', 'section']

# 获取各字段类型禁用的字段属性
Expand Down Expand Up @@ -177,6 +177,8 @@ getTypeUserAttrs = ()->
typeUserAttrs[item] = _.extend {}, CODEUSERATTRS, BASEUSERATTRS
when 'dateTime'
typeUserAttrs[item] = _.extend {}, CODEUSERATTRS, BASEUSERATTRS
when 'time'
typeUserAttrs[item] = _.extend {}, CODEUSERATTRS, BASEUSERATTRS
when 'checkboxBoolean'
typeUserAttrs[item] = _.extend {}, CODEUSERATTRS, BASEUSERATTRS
when 'email'
Expand Down Expand Up @@ -328,6 +330,13 @@ getFields = ()->
}
icon: "🕛"
},
{
label: "时间",
attrs: {
type: 'time'
}
icon: "🕛"
},
{
label: "勾选框"
attrs: {
Expand Down Expand Up @@ -433,6 +442,12 @@ getFieldTemplates = ()->
return {
field: "<input id='#{fieldData.name}' placeholder='yyyy-MM-dd HH:mm' type='text' #{Creator.formBuilder.utils.attrString(fieldData)} readonly>",
};
time: (fieldData) ->
if !fieldData.className
fieldData.className = 'form-control'
return {
field: "<input id='#{fieldData.name}' placeholder='HH:mm' type='text' #{Creator.formBuilder.utils.attrString(fieldData)} readonly>",
};
checkboxBoolean: (fieldData)->
if fieldData.value
fieldData.checked = fieldData.value
Expand Down
3 changes: 3 additions & 0 deletions creator/packages/steedos-formbuilder/lib/transform.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ Creator.formBuilder.transformFormFieldsIn = (formFields)->
when 'lookup'
field.type = 'lookup';
fields.push field;
when 'time'
field.type = 'time';
fields.push field;
else
console.log(f.code, f.name, f.type)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ SteedosTable.getTDValue = function (field, value) {
case 'file':
case 'lookup':
case 'image':
case 'time':
td_value = InstanceReadOnlyTemplate.getValue(value, field);
break
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@
display: none;
}
}

.form-control{
height: 100%;
min-height: 34px;
}

}

.steedosTable-item-add{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @Author: [email protected]
* @Date: 2023-10-28 15:25:17
* @LastEditors: baozhoutao@steedos.com
* @LastEditTime: 2023-11-23 13:27:39
* @LastEditors: 孙浩林 sunhaolin@steedos.com
* @LastEditTime: 2024-04-26 10:45:13
* @Description:
*/
if (Meteor.isClient) {
Expand Down Expand Up @@ -110,6 +110,14 @@ if (Meteor.isClient) {
$("[name='"+atts.name+"']").data('value', values);
$("[name='"+atts.name+"']").data('multiple', atts.multiple);
const config = JSON.parse(atts.config || "{}");

let data = disabled ? {[atts.name]: values, _display: {}} : {_display: {}};
let value = values;
if (atts.fieldType === 'time') { // 因为time类型在amis中给value赋值时,在编辑状态下值显示会多8小时,所以这里特殊处理。
data = {[atts.name]: values, _display: {}};
value = undefined;
}

const schema = {
render_engine: 'amis',
name: "steedos-field-"+atts.id,
Expand All @@ -123,7 +131,7 @@ if (Meteor.isClient) {
"actions": false,
"wrapWithPanel": false,
id: 'steedosField_' + atts.id,
data: disabled ? {[atts.name]: values, _display: {}} : {_display: {}},
data: data,
body: [
{
type: 'steedos-field',
Expand All @@ -137,7 +145,7 @@ if (Meteor.isClient) {
reference_to_field: atts.reference_to_field,
filters: _.isString(atts.filters) ? JSON.parse(atts.filters) : atts.filters,
amis: {
value: values,
value: value,
static: disabled,
disabled: disabled,
disabledOn: undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ var s_autoform = function (schema, field) {
autoform.filters = field.filters;
autoform.config = field.config;
break;
case 'time':
schema.type = String;
autoform.readonly = (permission == 'readonly');
autoform.disabled = (permission == 'readonly');
autoform.type = 'steedos-field'
autoform.fieldType = 'time'
break;
default:
schema.type = String;
autoform.readonly = (permission == 'readonly');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,23 @@ InstanceReadOnlyTemplate.getValue = (value, field, locale, utcOffset) ->
value = new Date(value)

value = InstanceReadOnlyTemplate.formatDate(value, utcOffset);
when 'time'
if value && value.length == 16
t = value.split("T")
t0 = t[0].split("-");
t1 = t[1].split(":");

year = t0[0];
month = t0[1];
date = t0[2];
hours = t1[0];
seconds = t1[1];

value = new Date(year, month - 1, date, hours, seconds)
else
value = new Date(value)

value = InstanceReadOnlyTemplate.formatTime(value);
when 'input'
if field.is_textarea
value = value
Expand Down Expand Up @@ -553,6 +570,10 @@ InstanceReadOnlyTemplate.formatDate = (date, utcOffset)->

return moment(date).utcOffset(utcOffset, passing).format("YYYY-MM-DD HH:mm");

InstanceReadOnlyTemplate.formatTime = (date)->
utcOffset = 0
return moment(date).utcOffset(utcOffset).format("HH:mm");

InstanceReadOnlyTemplate.getInstanceView = (user, space, instance, options)->

steedosData = _getTemplateData(user, space, instance, options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ fields:
value: dateTimeD
- label: Date
value: date
- label: Time
value: time
- label: EmailGM
- label: Group
value: group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ fields:
value: dateTime
- label: 日期
value: date
- label: 时间
value: time
- label: 电子邮件
value: email
- label: Group
Expand Down
2 changes: 2 additions & 0 deletions packages/standard-objects/workflow/forms.object.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ fields:
value: dateTime
- label: Date
value: date
- label: Time
value: time
- label: Email
value: email
- label: Group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ const getRecordFieldValue = function (oField, wField, ofValue, wfValue, spaceId,
value = wfValue ? wfValue : null
}
// 日期、日期时间
else if (oFieldType === 'date' || oFieldType === 'datetime') {
else if (oFieldType === 'date' || oFieldType === 'datetime' || oFieldType === 'time') {
if (wfValue && _.isDate(new Date(wfValue))) {
value = new Date(wfValue);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/workflow/src/designerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ async function _transformObjectFieldToFormField(objField, codePrefix = '') {
formField.type = "dateTime";
break;
case 'time':
formField.type = "input";
formField.type = "time";
break;
case 'number':
formField.type = "number";
Expand Down
26 changes: 13 additions & 13 deletions server/bundle/programs/server/packages/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/objectql",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "lib/index.js"
};

Expand All @@ -490,7 +490,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/i18n",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "lib/index.js"
};

Expand All @@ -517,7 +517,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/core",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "lib/index.js"
};

Expand All @@ -544,7 +544,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/service-meteor-package-loader",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "index.js"
};

Expand All @@ -571,7 +571,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/service-api",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "index.js"
};

Expand All @@ -598,7 +598,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/service-metadata-server",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "index.js"
};

Expand All @@ -625,7 +625,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/service-package-registry",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "package.service.js"
};

Expand All @@ -652,7 +652,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/service-objectql",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "package.service.js"
};

Expand All @@ -679,7 +679,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/service-ui",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "package.service.js"
};

Expand All @@ -706,7 +706,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/service-pages",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "package.service.js"
};

Expand All @@ -733,7 +733,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/router",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "lib/index.js"
};

Expand All @@ -760,7 +760,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/auth",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "lib/index.js"
};

Expand All @@ -787,7 +787,7 @@ module.useNode();
//
module.exports = {
"name": "@steedos/workflow",
"version": "2.7.0-beta.34",
"version": "2.7.1-beta.2",
"main": "index.js"
};

Expand Down
8 changes: 7 additions & 1 deletion server/bundle/programs/server/packages/steedos_creator.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 7a72f5a

Please sign in to comment.