OaCommentPanel.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <!-- OA 审批详情 · 实例讨论评论(≠ 审批意见) -->
  2. <template>
  3. <section class="oa-comment-panel">
  4. <h3 class="oa-comment-panel__title">
  5. <el-icon class="oa-comment-panel__title-icon"><ChatDotRound /></el-icon>
  6. 评论
  7. </h3>
  8. <div v-if="!comments.length" class="oa-comment-panel__empty">暂无评论</div>
  9. <ul v-else class="oa-comment-panel__list">
  10. <li v-for="c in comments" :key="c.id" class="oa-comment-panel__item">
  11. <template v-if="c.status === 'revoked'">
  12. <span class="oa-comment-panel__revoked">
  13. {{ c.createByName || c.createBy }} 撤回了一条评论
  14. <span v-if="c.revokedTime" class="oa-comment-panel__time">{{ c.revokedTime }}</span>
  15. </span>
  16. </template>
  17. <template v-else>
  18. <div class="oa-comment-panel__meta">
  19. <strong>{{ c.createByName || c.createBy }}</strong>
  20. <span class="oa-comment-panel__time">{{ c.createTime }}</span>
  21. <el-button
  22. v-if="c.canRevoke"
  23. link
  24. type="danger"
  25. :loading="revokingId === c.id"
  26. @click="onRevoke(c)"
  27. >
  28. <el-icon><RefreshLeft /></el-icon>
  29. 撤回
  30. </el-button>
  31. </div>
  32. <div class="oa-comment-panel__content">{{ c.content }}</div>
  33. <div v-if="c.attachmentRefs?.length" class="oa-comment-panel__refs">
  34. <el-tag
  35. v-for="(f, idx) in c.attachmentRefs"
  36. :key="`${c.id}-${idx}-${f.url}`"
  37. class="oa-comment-panel__ref"
  38. size="small"
  39. effect="plain"
  40. @click="openUrl(f.url)"
  41. >
  42. {{ f.fileName || f.url }}
  43. </el-tag>
  44. </div>
  45. </template>
  46. </li>
  47. </ul>
  48. <div v-if="instanceStatus === 'running'" class="oa-comment-panel__composer">
  49. <el-input
  50. v-model="draft"
  51. type="textarea"
  52. :rows="3"
  53. maxlength="1024"
  54. show-word-limit
  55. placeholder="填写评论"
  56. />
  57. <div v-if="picked.length" class="oa-comment-panel__picked">
  58. <el-tag
  59. v-for="(f, idx) in picked"
  60. :key="`${f.url}-${idx}`"
  61. closable
  62. size="small"
  63. effect="plain"
  64. @close="picked.splice(idx, 1)"
  65. >
  66. {{ f.fileName || f.url }}
  67. </el-tag>
  68. </div>
  69. <div class="oa-comment-panel__actions">
  70. <el-button class="btn-ghost" @click="openAttach">
  71. <el-icon><Paperclip /></el-icon>
  72. 引用附件
  73. </el-button>
  74. <el-button type="primary" class="btn-main" :loading="sending" @click="onSend">
  75. <el-icon><Promotion /></el-icon>
  76. 发送
  77. </el-button>
  78. </div>
  79. </div>
  80. <el-dialog
  81. v-model="attachVisible"
  82. title="引用表单附件"
  83. width="560px"
  84. class="dialog-form-layout"
  85. align-center
  86. append-to-body
  87. modal-class="protocol-dialog-mask"
  88. destroy-on-close
  89. :close-on-click-modal="false"
  90. >
  91. <div v-loading="attachLoading" class="oa-comment-attach">
  92. <div v-if="!attachLoading && !attachGroups.length" class="oa-comment-attach__empty">
  93. 暂无可引用附件
  94. </div>
  95. <el-checkbox-group v-else v-model="selectedUrls" class="oa-comment-attach__groups">
  96. <div v-for="g in attachGroups" :key="g.fieldKey" class="oa-comment-attach__group">
  97. <div class="oa-comment-attach__label">{{ g.fieldLabel || g.fieldKey }}</div>
  98. <div class="oa-comment-attach__files">
  99. <el-checkbox
  100. v-for="f in g.files"
  101. :key="f.url"
  102. :value="f.url"
  103. class="oa-comment-attach__file"
  104. >
  105. {{ f.fileName || f.url }}
  106. </el-checkbox>
  107. </div>
  108. </div>
  109. </el-checkbox-group>
  110. </div>
  111. <template #footer>
  112. <el-button class="btn-ghost" @click="attachVisible = false">
  113. <el-icon><Close /></el-icon>
  114. 取消
  115. </el-button>
  116. <el-button
  117. type="primary"
  118. class="btn-main"
  119. :disabled="!attachGroups.length"
  120. @click="confirmAttach"
  121. >
  122. <el-icon><Check /></el-icon>
  123. 确定
  124. </el-button>
  125. </template>
  126. </el-dialog>
  127. </section>
  128. </template>
  129. <script setup lang="ts">
  130. import {
  131. ChatDotRound,
  132. Check,
  133. Close,
  134. Paperclip,
  135. Promotion,
  136. RefreshLeft
  137. } from '@element-plus/icons-vue'
  138. import {
  139. fetchCreateOaComment,
  140. fetchOaFormAttachments,
  141. fetchRevokeOaComment,
  142. type OaCommentAttachmentRef,
  143. type OaInstanceComment
  144. } from '@/api/oaApproval'
  145. import { attachmentFullUrl } from '@/composables/useAttachmentActions'
  146. defineOptions({ name: 'OaCommentPanel' })
  147. const props = withDefaults(
  148. defineProps<{
  149. instanceId: string
  150. instanceStatus: string
  151. comments?: OaInstanceComment[]
  152. }>(),
  153. {
  154. comments: () => []
  155. }
  156. )
  157. const emit = defineEmits<{ refresh: [] }>()
  158. const draft = ref('')
  159. const picked = ref<OaCommentAttachmentRef[]>([])
  160. const sending = ref(false)
  161. const revokingId = ref('')
  162. const attachVisible = ref(false)
  163. const attachLoading = ref(false)
  164. const attachGroups = ref<
  165. Array<{ fieldKey: string; fieldLabel: string; files: OaCommentAttachmentRef[] }>
  166. >([])
  167. const selectedUrls = ref<string[]>([])
  168. function openUrl(url: string) {
  169. const full = attachmentFullUrl(url) || url
  170. if (full) window.open(full, '_blank')
  171. }
  172. async function openAttach() {
  173. attachVisible.value = true
  174. attachLoading.value = true
  175. selectedUrls.value = picked.value.map((f) => f.url)
  176. try {
  177. const res = await fetchOaFormAttachments(props.instanceId)
  178. const items = res?.items || []
  179. attachGroups.value = items
  180. if (!items.length) {
  181. ElMessage.info('暂无可引用附件')
  182. }
  183. } catch (e: any) {
  184. attachGroups.value = []
  185. ElMessage.error(e?.message || '加载附件失败')
  186. } finally {
  187. attachLoading.value = false
  188. }
  189. }
  190. function confirmAttach() {
  191. const map = new Map<string, OaCommentAttachmentRef>()
  192. for (const g of attachGroups.value) {
  193. for (const f of g.files || []) {
  194. if (f?.url) map.set(f.url, f)
  195. }
  196. }
  197. const next: OaCommentAttachmentRef[] = []
  198. for (const url of selectedUrls.value) {
  199. const found = map.get(url) || picked.value.find((p) => p.url === url)
  200. if (found) next.push({ ...found })
  201. }
  202. picked.value = next
  203. attachVisible.value = false
  204. }
  205. async function onSend() {
  206. const content = draft.value.trim()
  207. if (!content) {
  208. ElMessage.warning('请填写评论')
  209. return
  210. }
  211. sending.value = true
  212. try {
  213. await fetchCreateOaComment(props.instanceId, {
  214. content,
  215. attachmentRefs: picked.value.length ? [...picked.value] : undefined
  216. })
  217. draft.value = ''
  218. picked.value = []
  219. ElMessage.success('已发送')
  220. emit('refresh')
  221. } catch (e: any) {
  222. ElMessage.error(e?.message || '发送失败')
  223. } finally {
  224. sending.value = false
  225. }
  226. }
  227. async function onRevoke(c: OaInstanceComment) {
  228. try {
  229. await ElMessageBox.confirm('确定撤回该评论吗?', '提示', { type: 'warning' })
  230. } catch {
  231. return
  232. }
  233. revokingId.value = c.id
  234. try {
  235. await fetchRevokeOaComment(props.instanceId, c.id)
  236. ElMessage.success('已撤回')
  237. emit('refresh')
  238. } catch (e: any) {
  239. ElMessage.error(e?.message || '撤回失败')
  240. } finally {
  241. revokingId.value = ''
  242. }
  243. }
  244. </script>
  245. <style scoped lang="scss">
  246. .oa-comment-panel {
  247. max-width: 960px;
  248. }
  249. .oa-comment-panel__title {
  250. display: flex;
  251. gap: 6px;
  252. align-items: center;
  253. margin: 16px 0 12px;
  254. font-size: 14px;
  255. font-weight: 600;
  256. color: var(--mint-text, #0f172a);
  257. }
  258. .oa-comment-panel__title-icon {
  259. color: var(--primary, #10b981);
  260. font-size: 16px;
  261. }
  262. .oa-comment-panel__empty {
  263. padding: 8px 0 12px;
  264. color: var(--mint-text-muted, #94a3b8);
  265. font-size: 12px;
  266. }
  267. .oa-comment-panel__list {
  268. margin: 0;
  269. padding: 0;
  270. list-style: none;
  271. }
  272. .oa-comment-panel__item {
  273. padding: 10px 0;
  274. border-bottom: 1px solid var(--mint-border, #e2e8f0);
  275. &:last-child {
  276. border-bottom: none;
  277. }
  278. }
  279. .oa-comment-panel__revoked {
  280. color: var(--mint-text-muted, #94a3b8);
  281. font-size: 13px;
  282. line-height: 1.5;
  283. }
  284. .oa-comment-panel__meta {
  285. display: flex;
  286. flex-wrap: wrap;
  287. gap: 8px;
  288. align-items: center;
  289. margin-bottom: 6px;
  290. strong {
  291. color: var(--mint-text-strong, #0f172a);
  292. font-size: 13px;
  293. font-weight: 600;
  294. }
  295. }
  296. .oa-comment-panel__time {
  297. margin-left: 4px;
  298. color: var(--mint-text-muted, #94a3b8);
  299. font-size: 12px;
  300. }
  301. .oa-comment-panel__content {
  302. color: var(--mint-text, #334155);
  303. font-size: 13px;
  304. line-height: 1.55;
  305. white-space: pre-wrap;
  306. word-break: break-word;
  307. }
  308. .oa-comment-panel__refs,
  309. .oa-comment-panel__picked {
  310. display: flex;
  311. flex-wrap: wrap;
  312. gap: 6px;
  313. margin-top: 8px;
  314. }
  315. .oa-comment-panel__ref {
  316. cursor: pointer;
  317. &:hover {
  318. color: var(--primary-dark, #059669);
  319. border-color: #a7f3d0;
  320. background: var(--primary-bg, #ecfdf5);
  321. }
  322. }
  323. .oa-comment-panel__composer {
  324. margin-top: 12px;
  325. padding-top: 12px;
  326. border-top: 1px solid var(--mint-border, #e2e8f0);
  327. }
  328. .oa-comment-panel__actions {
  329. display: flex;
  330. flex-wrap: wrap;
  331. gap: 8px;
  332. margin-top: 10px;
  333. }
  334. .oa-comment-attach {
  335. min-height: 80px;
  336. }
  337. .oa-comment-attach__empty {
  338. padding: 16px 0;
  339. color: var(--mint-text-muted, #94a3b8);
  340. font-size: 13px;
  341. text-align: center;
  342. }
  343. .oa-comment-attach__groups {
  344. display: grid;
  345. gap: 14px;
  346. width: 100%;
  347. }
  348. .oa-comment-attach__label {
  349. margin-bottom: 6px;
  350. color: var(--mint-text-strong, #0f172a);
  351. font-size: 13px;
  352. font-weight: 600;
  353. }
  354. .oa-comment-attach__files {
  355. display: grid;
  356. gap: 4px;
  357. }
  358. .oa-comment-attach__file {
  359. margin-right: 0;
  360. height: auto;
  361. white-space: normal;
  362. align-items: flex-start;
  363. }
  364. </style>