From a69dcc5bca464c30ea8c6db95c8e980e7f8c1f12 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Thu, 19 Nov 2026 11:55:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(oa):=20=E5=90=8C=E6=84=8F/=E6=8B=92?= =?UTF-8?q?=E7=BB=9D/=E6=89=93=E5=9B=9E=E5=89=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8F=91=E9=80=81=E8=AF=84=E8=AE=BA=E8=8D=89=E7=A8=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 审批动作前冲刷评论区未发送内容,减少先点发送再审批的一步操作。 关联 #118。 Co-authored-by: Cursor --- .../src/oa/components/OaCommentComposer.vue | 38 ++++++++++++++++--- mobile-oa-h5/src/oa/oa-comment-draft.js | 7 ++++ mobile-oa-h5/src/oa/oa-comment-draft.test.js | 14 +++++++ mobile-oa-h5/src/views/OaDetail.vue | 12 +++++- .../components/oa-approval/OaCommentPanel.vue | 38 ++++++++++++++++--- web-admin/src/utils/oa-comment-draft.test.ts | 16 ++++++++ web-admin/src/utils/oa-comment-draft.ts | 12 ++++++ .../views/oa-approval/instances/detail.vue | 13 +++++++ 8 files changed, 137 insertions(+), 13 deletions(-) create mode 100644 mobile-oa-h5/src/oa/oa-comment-draft.js create mode 100644 mobile-oa-h5/src/oa/oa-comment-draft.test.js create mode 100644 web-admin/src/utils/oa-comment-draft.test.ts create mode 100644 web-admin/src/utils/oa-comment-draft.ts diff --git a/mobile-oa-h5/src/oa/components/OaCommentComposer.vue b/mobile-oa-h5/src/oa/components/OaCommentComposer.vue index ce5aa607..aea0c5e2 100644 --- a/mobile-oa-h5/src/oa/components/OaCommentComposer.vue +++ b/mobile-oa-h5/src/oa/components/OaCommentComposer.vue @@ -150,6 +150,7 @@ import { uploadAttachment } from '../../api/oa.js' import OaCommentFileCards from './OaCommentFileCards.vue' +import { hasOaCommentDraft } from '../oa-comment-draft.js' import { attachmentFullUrl } from '../../utils/attachment.js' import { isHarmonyWechat } from '../../utils/harmony-file-picker.js' import HarmonyFileSource from '../../components/HarmonyFileSource.vue' @@ -516,12 +517,25 @@ function confirmMention() { mentionVisible.value = false } -async function onSend() { - const content = draft.value.trim() - if (!content && !mentionUsers.value.length && !picked.value.length) { - showToast('请填写评论、@人员或添加附件') - return +function draftPending() { + return hasOaCommentDraft({ + content: draft.value, + mentionCount: mentionUsers.value.length, + attachmentCount: picked.value.length + }) +} + +/** + * 审批动作前冲刷未发送草稿:无草稿直接成功;有草稿则等同点击「发送」。 + * @returns {Promise} false 表示发送失败或忙碌,调用方应中止审批动作 + */ +async function flushDraft(opts = {}) { + if (!draftPending()) return true + if (sending.value || uploading.value) { + showToast(uploading.value ? '附件上传中,请稍后再试' : '评论发送中,请稍后再试') + return false } + const content = draft.value.trim() sending.value = true try { await fetchCreateOaComment(props.instanceId, { @@ -533,15 +547,27 @@ async function onSend() { picked.value = [] mentionUsers.value = [] closeAtSuggest() - showToast('已发送') + if (!opts.quiet) showToast('已发送') emit('refresh') + return true } catch (e) { showToast(e?.message || '发送失败') + return false } finally { sending.value = false } } +async function onSend() { + if (!draftPending()) { + showToast('请填写评论、@人员或添加附件') + return + } + await flushDraft() +} + +defineExpose({ flushDraft, draftPending }) + onMounted(() => { void ensureUserCache() }) diff --git a/mobile-oa-h5/src/oa/oa-comment-draft.js b/mobile-oa-h5/src/oa/oa-comment-draft.js new file mode 100644 index 00000000..c8991c6b --- /dev/null +++ b/mobile-oa-h5/src/oa/oa-comment-draft.js @@ -0,0 +1,7 @@ +/** 评论区是否有未发送草稿(文字 / @ / 附件) */ +export function hasOaCommentDraft(input = {}) { + const content = String(input.content || '').trim() + const mentionCount = Number(input.mentionCount || 0) + const attachmentCount = Number(input.attachmentCount || 0) + return !!(content || mentionCount > 0 || attachmentCount > 0) +} diff --git a/mobile-oa-h5/src/oa/oa-comment-draft.test.js b/mobile-oa-h5/src/oa/oa-comment-draft.test.js new file mode 100644 index 00000000..24c6c30b --- /dev/null +++ b/mobile-oa-h5/src/oa/oa-comment-draft.test.js @@ -0,0 +1,14 @@ +import assert from 'node:assert/strict' +import test from 'node:test' +import { hasOaCommentDraft } from './oa-comment-draft.js' + +test('empty draft is false', () => { + assert.equal(hasOaCommentDraft({}), false) + assert.equal(hasOaCommentDraft({ content: ' ', mentionCount: 0, attachmentCount: 0 }), false) +}) + +test('text / mention / attachment counts as draft', () => { + assert.equal(hasOaCommentDraft({ content: '@test' }), true) + assert.equal(hasOaCommentDraft({ mentionCount: 1 }), true) + assert.equal(hasOaCommentDraft({ attachmentCount: 2 }), true) +}) diff --git a/mobile-oa-h5/src/views/OaDetail.vue b/mobile-oa-h5/src/views/OaDetail.vue index 95775057..75a6e73b 100644 --- a/mobile-oa-h5/src/views/OaDetail.vue +++ b/mobile-oa-h5/src/views/OaDetail.vue @@ -29,6 +29,7 @@ @refresh="reloadDetail" /> { + if (!draftPending()) return true + if (sending.value || uploading.value) { + ElMessage.warning(uploading.value ? '附件上传中,请稍后再试' : '评论发送中,请稍后再试') + return false } + const content = draft.value.trim() sending.value = true try { await fetchCreateOaComment(props.instanceId, { @@ -565,15 +579,27 @@ picked.value = [] mentionUsers.value = [] closeAtSuggest() - ElMessage.success('已发送') + if (!opts?.quiet) ElMessage.success('已发送') emit('refresh') + return true } catch (e: any) { ElMessage.error(e?.message || '发送失败') + return false } finally { sending.value = false } } + async function onSend() { + if (!draftPending()) { + ElMessage.warning('请填写评论、@人员或添加附件') + return + } + await flushDraft() + } + + defineExpose({ flushDraft, draftPending }) + onMounted(() => { void ensureUserCache() }) diff --git a/web-admin/src/utils/oa-comment-draft.test.ts b/web-admin/src/utils/oa-comment-draft.test.ts new file mode 100644 index 00000000..ce6ff73b --- /dev/null +++ b/web-admin/src/utils/oa-comment-draft.test.ts @@ -0,0 +1,16 @@ +import { describe, it } from 'node:test' +import assert from 'node:assert/strict' +import { hasOaCommentDraft } from './oa-comment-draft.ts' + +describe('hasOaCommentDraft', () => { + it('treats blank content without mentions/files as empty', () => { + assert.equal(hasOaCommentDraft({}), false) + assert.equal(hasOaCommentDraft({ content: ' ', mentionCount: 0, attachmentCount: 0 }), false) + }) + + it('detects text, mentions and attachments', () => { + assert.equal(hasOaCommentDraft({ content: '@test' }), true) + assert.equal(hasOaCommentDraft({ mentionCount: 1 }), true) + assert.equal(hasOaCommentDraft({ attachmentCount: 2 }), true) + }) +}) diff --git a/web-admin/src/utils/oa-comment-draft.ts b/web-admin/src/utils/oa-comment-draft.ts new file mode 100644 index 00000000..7e8cc33d --- /dev/null +++ b/web-admin/src/utils/oa-comment-draft.ts @@ -0,0 +1,12 @@ +/** 评论区是否有未发送草稿(文字 / @ / 附件) */ +export function hasOaCommentDraft(input: { + content?: string | null + mentionCount?: number + attachmentCount?: number +}): boolean { + return !!( + String(input.content || '').trim() || + (input.mentionCount || 0) > 0 || + (input.attachmentCount || 0) > 0 + ) +} diff --git a/web-admin/src/views/oa-approval/instances/detail.vue b/web-admin/src/views/oa-approval/instances/detail.vue index 36d1cf57..4fad7f1a 100644 --- a/web-admin/src/views/oa-approval/instances/detail.vue +++ b/web-admin/src/views/oa-approval/instances/detail.vue @@ -99,6 +99,7 @@ /> Promise } | null>( + null + ) const detail = ref(null) const viewFormData = ref>({}) const viewRule = ref([]) @@ -392,9 +396,17 @@ } } + /** 同意/拒绝/打回前先发送评论区未提交草稿 */ + async function flushPendingComment(): Promise { + const flush = commentPanelRef.value?.flushDraft + if (!flush) return true + return await flush() + } + async function act(kind: 'approve' | 'reject') { const task = myPendingTask.value if (!task) return + if (!(await flushPendingComment())) return let comment = '' try { const res = await ElMessageBox.prompt( @@ -436,6 +448,7 @@ async function doReturn() { const task = myPendingTask.value if (!task) return + if (!(await flushPendingComment())) return let comment = '' try { const res = await ElMessageBox.prompt('请填写打回意见(必填)', '打回', { -- 2.54.0