Refactor form modal creation and extra button logic

This commit is contained in:
RB 2025-08-15 13:49:55 +08:00
parent bc34b1e9c6
commit 05131e9941
6 changed files with 38 additions and 40 deletions

View file

@ -575,7 +575,6 @@ class ApprovalApproveForm extends ApprovalUsersForm {
title: $L('编辑%s', res.entityLabel),
icon: res.icon,
id: this.props.id,
noExtraButton: true,
postAfter: (recordId, next, formObject) => {
// 刷新列表
const rlp = window.RbListPage || parent.RbListPage
@ -588,8 +587,7 @@ class ApprovalApproveForm extends ApprovalUsersForm {
})
},
}
if ((window.__LAB40_EDIT_PROVIDERS || {})[this.props.entity]) window.__LAB40_EDIT_PROVIDERS[this.props.entity](editProps)
else RbFormModal.create(editProps, true)
RbFormModal.create(editProps, true)
})
}}>
<i className="icon zmdi zmdi-edit mr-1" />

View file

@ -883,16 +883,16 @@ const RbListCommon = {
RbListPage.init(wpc.listConfig, entity, wpc.privileges)
if (wpc.advFilter !== false) AdvFilters.init('.adv-search', entity[0])
const newProps = { title: $L('新建%s', entity[1]), entity: entity[0], icon: entity[2] }
const newProps = { title: $L('新建%s', entity[1]), entity: entity[0], icon: entity[2], showExtraButton: true }
const $new = $('.J_new')
.attr('disabled', false)
.on('click', () => RbFormModal.create(newProps))
if (wpc.formsAttr) {
$new.next().removeClass('hide')
const $nn = $new.next().next()
const $next = $new.next().next()
wpc.formsAttr.map((n) => {
$(`<a class="dropdown-item" data-id="${n.id}">${n.name || $L('默认布局')}</a>`)
.appendTo($nn)
.appendTo($next)
.on('click', () => RbFormModal.create({ ...newProps, specLayout: n.id }, true))
})
} else {

View file

@ -39,10 +39,7 @@ const RbListPage = {
$('.J_edit').on('click', () => {
const ids = this._RbList.getSelectedIds()
if (ids.length >= 1) {
const _entity = entity[0]
const editProps = { id: ids[0], title: $L('编辑%s', entity[1]), entity: _entity, icon: entity[2] }
if ((window.__LAB40_EDIT_PROVIDERS || {})[_entity]) window.__LAB40_EDIT_PROVIDERS[_entity](editProps)
else RbFormModal.create(editProps, true)
RbFormModal.create({ id: ids[0], title: $L('编辑%s', entity[1]), entity: entity[0], icon: entity[2], showExtraButton: true }, true)
}
})
$('.J_delete').on('click', () => {
@ -111,7 +108,7 @@ class RbViewModal extends React.Component {
super(props)
this.state = { ...props, inLoad: true, isHide: true, destroy: false }
this._mcWidth = this.props.subView === true ? 1344 : 1404
this._mcWidth = props.subView === true ? 1344 : 1404
if ($(window).width() < 1464) this._mcWidth -= 184
}
@ -122,7 +119,14 @@ class RbViewModal extends React.Component {
<div className="modal-dialog">
<div className="modal-content" style={{ width: this._mcWidth }}>
<div className={`modal-body iframe rb-loading ${this.state.inLoad === true && 'rb-loading-active'}`}>
<iframe ref={(c) => (this._iframe = c)} className={this.state.isHide ? 'invisible' : ''} src={this.state.showAfterUrl || 'about:blank'} frameBorder="0" scrolling="no" />
<iframe
data-subview={this.props.subView || false}
ref={(c) => (this._iframe = c)}
className={this.state.isHide ? 'invisible' : ''}
src={this.state.showAfterUrl || 'about:blank'}
frameBorder="0"
scrolling="no"
/>
<RbSpinner />
</div>
</div>

View file

@ -254,6 +254,12 @@ class RbFormModal extends React.Component {
* @param {*} forceNew
*/
static create(props, forceNew) {
// 自定义编辑
if ((window.__LAB40_EDIT_PROVIDERS || {})[props.entity]) {
window.__LAB40_EDIT_PROVIDERS[props.entity](props, forceNew)
return
}
// `__CURRENT35`, `__HOLDER` 可能已 unmount
const that = this
if (forceNew === true) {
@ -559,7 +565,7 @@ class RbForm extends React.Component {
let moreActions = []
// 添加明细
if (props.rawModel.mainMeta) {
if (parentProps._nextAddDetail) {
if (parentProps.nextAddDetail) {
moreActions.push(
<a key="Action101" className="dropdown-item" onClick={() => this.post(RbForm.NEXT_NEWDETAIL)}>
{$L('保存并添加')}
@ -567,10 +573,8 @@ class RbForm extends React.Component {
)
}
} else {
if (parentProps.noExtraButton) {
// 无扩展按钮
} else {
// 保存并...
// 保存并...
if (parentProps.showExtraButton) {
if (props.rawModel.hadApproval && window.ApprovalSubmitForm) {
moreActions.push(
<a key="Action103" className="dropdown-item" onClick={() => this.post(RbForm.NEXT_SUBMIT37)}>

View file

@ -505,15 +505,7 @@ class EntityRelatedList extends RelatedList {
_handleEdit(e, id) {
$stopEvent(e, true)
const editProps = {
id: id,
entity: this.__entity,
title: $L('编辑%s', this.props.entity2[0]),
icon: this.props.entity2[1],
noExtraButton: true,
}
if ((window.__LAB40_EDIT_PROVIDERS || {})[this.__entity]) window.__LAB40_EDIT_PROVIDERS[this.__entity](editProps)
else RbFormModal.create(editProps, true)
RbFormModal.create({ id: id, entity: this.__entity, title: $L('编辑%s', this.props.entity2[0]), icon: this.props.entity2[1] }, true)
}
_handleView(e) {
@ -670,10 +662,7 @@ const RbViewPage = {
})
$('.J_edit').on('click', () => {
const _entity = entity[0]
const editProps = { id: id, title: $L('编辑%s', entity[1]), entity: _entity, icon: entity[2] }
if ((window.__LAB40_EDIT_PROVIDERS || {})[_entity]) window.__LAB40_EDIT_PROVIDERS[_entity](editProps)
else RbFormModal.create(editProps, true)
RbFormModal.create({ id: id, title: $L('编辑%s', entity[1]), entity: entity[0], icon: entity[2] }, true)
})
$('.J_assign').on('click', () => DlgAssign.create({ entity: entity[0], ids: [id] }))
$('.J_share').on('click', () => DlgShare.create({ entity: entity[0], ids: [id] }))
@ -681,7 +670,7 @@ const RbViewPage = {
$('.J_add-detail-menu>a').on('click', function () {
const iv = { $MAINID$: id }
const $this = $(this)
RbFormModal.create({ title: $L('添加%s', $this.data('label')), entity: $this.data('entity'), icon: $this.data('icon'), initialValue: iv, _nextAddDetail: true })
RbFormModal.create({ title: $L('添加%s', $this.data('label')), entity: $this.data('entity'), icon: $this.data('icon'), initialValue: iv, nextAddDetail: true })
})
if (wpc.transformTos && wpc.transformTos.length > 0) {
@ -940,7 +929,6 @@ const RbViewPage = {
entity: entity[0],
icon: item.icon,
initialValue: iv,
noExtraButton: true,
}
RbFormModal.create(newProps)
}
@ -1049,13 +1037,17 @@ $(document).ready(() => {
$('.J_home').removeClass('hide')
}
// v4.2
if (parent && parent.RbListPage && parent.RbListPage._RbList && parent.RbListPage._RbList.jumpView) {
$('.J_record-next')
.removeClass('hide')
.on('click', () => parent.RbListPage._RbList.jumpView(1))
$('.J_record-prev')
.removeClass('hide')
.on('click', () => parent.RbListPage._RbList.jumpView(-1))
if (window.frameElement && parent && parent.RbListPage && parent.RbListPage._RbList && parent.RbListPage._RbList.jumpView) {
if ($(window.frameElement).data('subview')) {
// SubView
} else {
$('.J_record-next')
.removeClass('hide')
.on('click', () => parent.RbListPage._RbList.jumpView(1))
$('.J_record-prev')
.removeClass('hide')
.on('click', () => parent.RbListPage._RbList.jumpView(-1))
}
}
// iframe 点击穿透

View file

@ -610,7 +610,7 @@ var _initGlobalCreate = function () {
var $item = $('<a class="dropdown-item"><i class="icon zmdi zmdi-' + this.icon + '"></i>' + this.entityLabel + '</a>').appendTo($gc)
var _this = this
$item.on('click', function () {
RbFormModal.create({ title: $L('新建%s', _this.entityLabel), entity: _this.entity, icon: _this.icon })
RbFormModal.create({ title: $L('新建%s', _this.entityLabel), entity: _this.entity, icon: _this.icon, showExtraButton: true })
})
})
}