fix(oa): 同意/拒绝/打回前自动发送评论草稿
审批动作前冲刷评论区未发送内容,减少先点发送再审批的一步操作。 关联 #118。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0929164bf5
commit
a69dcc5bca
8 files changed
+137
-13
No files matched your search
@@ -192,6 +192,7 @@
|
||||
} from '@/api/oaApproval'
|
||||
import OaCommentFileCards from '@/components/oa-approval/OaCommentFileCards.vue'
|
||||
import { attachmentFullUrl } from '@/composables/useAttachmentActions'
|
||||
import { hasOaCommentDraft } from '@/utils/oa-comment-draft'
|
||||
import { isOaUploadImageFile, isOaUploadVideoFile } from '@/utils/oa-upload-file-type'
|
||||
|
||||
defineOptions({ name: 'OaCommentPanel' })
|
||||
@@ -546,12 +547,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function onSend() {
|
||||
const content = draft.value.trim()
|
||||
if (!content && !mentionUsers.value.length && !picked.value.length) {
|
||||
ElMessage.warning('请填写评论、@人员或添加附件')
|
||||
return
|
||||
function draftPending() {
|
||||
return hasOaCommentDraft({
|
||||
content: draft.value,
|
||||
mentionCount: mentionUsers.value.length,
|
||||
attachmentCount: picked.value.length
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 审批动作前冲刷未发送草稿:无草稿直接成功;有草稿则等同点击「发送」。
|
||||
* @returns false 表示发送失败或忙碌,调用方应中止审批动作
|
||||
*/
|
||||
async function flushDraft(opts?: { quiet?: boolean }): Promise<boolean> {
|
||||
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()
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
@@ -99,6 +99,7 @@
|
||||
/>
|
||||
<OaCommentPanel
|
||||
v-if="detail?.id"
|
||||
ref="commentPanelRef"
|
||||
:instance-id="detail.id"
|
||||
:instance-status="detail.status || ''"
|
||||
@refresh="load"
|
||||
@@ -236,6 +237,9 @@
|
||||
const userStore = useUserStore()
|
||||
const loading = ref(false)
|
||||
const acting = ref(false)
|
||||
const commentPanelRef = ref<{ flushDraft?: (opts?: { quiet?: boolean }) => Promise<boolean> } | null>(
|
||||
null
|
||||
)
|
||||
const detail = ref<any>(null)
|
||||
const viewFormData = ref<Record<string, any>>({})
|
||||
const viewRule = ref<any[]>([])
|
||||
@@ -392,9 +396,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
/** 同意/拒绝/打回前先发送评论区未提交草稿 */
|
||||
async function flushPendingComment(): Promise<boolean> {
|
||||
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('请填写打回意见(必填)', '打回', {
|
||||
|
||||
Reference in new issue
Block a user