From 05131e9941be89e38f5ef1c58eb60ef892f2aabd Mon Sep 17 00:00:00 2001
From: RB <42044143+getrebuild@users.noreply.github.com>
Date: Fri, 15 Aug 2025 13:49:55 +0800
Subject: [PATCH] Refactor form modal creation and extra button logic
---
.../web/assets/js/general/rb-approval.js | 4 +--
.../assets/js/general/rb-datalist.common.js | 6 ++--
.../web/assets/js/general/rb-datalist.js | 16 +++++----
.../web/assets/js/general/rb-forms.js | 14 +++++---
.../web/assets/js/general/rb-view.js | 36 ++++++++-----------
src/main/resources/web/assets/js/rb-page.js | 2 +-
6 files changed, 38 insertions(+), 40 deletions(-)
diff --git a/src/main/resources/web/assets/js/general/rb-approval.js b/src/main/resources/web/assets/js/general/rb-approval.js
index db7e1f4a2..fe5fde213 100644
--- a/src/main/resources/web/assets/js/general/rb-approval.js
+++ b/src/main/resources/web/assets/js/general/rb-approval.js
@@ -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)
})
}}>
diff --git a/src/main/resources/web/assets/js/general/rb-datalist.common.js b/src/main/resources/web/assets/js/general/rb-datalist.common.js
index 206b89d8b..51763e7fb 100644
--- a/src/main/resources/web/assets/js/general/rb-datalist.common.js
+++ b/src/main/resources/web/assets/js/general/rb-datalist.common.js
@@ -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) => {
$(`${n.name || $L('默认布局')}`)
- .appendTo($nn)
+ .appendTo($next)
.on('click', () => RbFormModal.create({ ...newProps, specLayout: n.id }, true))
})
} else {
diff --git a/src/main/resources/web/assets/js/general/rb-datalist.js b/src/main/resources/web/assets/js/general/rb-datalist.js
index 52f8509de..678b69fc7 100644
--- a/src/main/resources/web/assets/js/general/rb-datalist.js
+++ b/src/main/resources/web/assets/js/general/rb-datalist.js
@@ -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 {
diff --git a/src/main/resources/web/assets/js/general/rb-forms.js b/src/main/resources/web/assets/js/general/rb-forms.js
index 2507d5314..b5f4af918 100644
--- a/src/main/resources/web/assets/js/general/rb-forms.js
+++ b/src/main/resources/web/assets/js/general/rb-forms.js
@@ -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(
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(
this.post(RbForm.NEXT_SUBMIT37)}>
diff --git a/src/main/resources/web/assets/js/general/rb-view.js b/src/main/resources/web/assets/js/general/rb-view.js
index 1b2fd7ae7..aba0b0e57 100644
--- a/src/main/resources/web/assets/js/general/rb-view.js
+++ b/src/main/resources/web/assets/js/general/rb-view.js
@@ -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 点击穿透
diff --git a/src/main/resources/web/assets/js/rb-page.js b/src/main/resources/web/assets/js/rb-page.js
index 87b982b85..841127c88 100644
--- a/src/main/resources/web/assets/js/rb-page.js
+++ b/src/main/resources/web/assets/js/rb-page.js
@@ -610,7 +610,7 @@ var _initGlobalCreate = function () {
var $item = $('' + this.entityLabel + '').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 })
})
})
}