style: 统一行尾符为LF(gitattributes renormalize,无代码变更)
This commit is contained in:
@@ -1,476 +1,476 @@
|
||||
<script lang="ts" setup>
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
modelValue?: string
|
||||
placeholder?: string
|
||||
minRows?: number
|
||||
maxRows?: number
|
||||
disabled?: boolean
|
||||
bordered?: boolean
|
||||
}>(), {
|
||||
modelValue: '',
|
||||
placeholder: '',
|
||||
minRows: 1,
|
||||
maxRows: 100,
|
||||
disabled: false,
|
||||
bordered: true,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: string): void
|
||||
}>()
|
||||
|
||||
const editorRef = ref<HTMLDivElement | null>(null)
|
||||
const isFocused = ref(false)
|
||||
const showColorPicker = ref(false)
|
||||
|
||||
const LINE_HEIGHT = 22 // 单行高度(px)
|
||||
|
||||
const colorOptions = [
|
||||
{ label: '红色', value: '#e8364e', bg: '#e8364e' },
|
||||
{ label: '蓝色', value: '#1890ff', bg: '#1890ff' },
|
||||
{ label: '橙色', value: '#fa8c16', bg: '#fa8c16' },
|
||||
{ label: '绿色', value: '#52c41a', bg: '#52c41a' },
|
||||
{ label: '紫色', value: '#722ed1', bg: '#722ed1' },
|
||||
{ label: '默认', value: '', bg: '#333333' },
|
||||
]
|
||||
|
||||
// 获取编辑器中去掉 HTML 标签后的纯文本,用于判断是否为空
|
||||
function getPlainText(): string {
|
||||
if (!editorRef.value)
|
||||
return ''
|
||||
return editorRef.value.innerText?.trim() || ''
|
||||
}
|
||||
|
||||
const hasContent = ref(false)
|
||||
|
||||
// 设置编辑器内容(仅在内容确实不同时才更新,防止光标重置)
|
||||
function setEditorHtml(html: string) {
|
||||
if (!editorRef.value)
|
||||
return
|
||||
if (editorRef.value.innerHTML !== html)
|
||||
editorRef.value.innerHTML = html || ''
|
||||
}
|
||||
|
||||
// 输入事件:同步内容到 modelValue
|
||||
function onInput() {
|
||||
if (!editorRef.value)
|
||||
return
|
||||
const html = editorRef.value.innerHTML || ''
|
||||
// 如果内容只是 <br> 或空 div 则视为空
|
||||
const plain = getPlainText()
|
||||
hasContent.value = !!plain
|
||||
emit('update:modelValue', plain ? html : '')
|
||||
}
|
||||
|
||||
function onFocus() {
|
||||
isFocused.value = true
|
||||
}
|
||||
|
||||
function onBlur() {
|
||||
// 延迟关闭,让工具栏按钮的 mousedown 有时间执行
|
||||
setTimeout(() => {
|
||||
isFocused.value = false
|
||||
showColorPicker.value = false
|
||||
}, 200)
|
||||
}
|
||||
|
||||
// =============== 工具栏操作 ===============
|
||||
|
||||
// 保存和恢复选区
|
||||
let savedSelection: Range | null = null
|
||||
|
||||
function saveSelection() {
|
||||
const sel = window.getSelection()
|
||||
if (sel && sel.rangeCount > 0)
|
||||
savedSelection = sel.getRangeAt(0).cloneRange()
|
||||
}
|
||||
|
||||
function restoreSelection() {
|
||||
if (savedSelection) {
|
||||
const sel = window.getSelection()
|
||||
if (sel) {
|
||||
sel.removeAllRanges()
|
||||
sel.addRange(savedSelection)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 执行粗体
|
||||
function execBold(e: Event) {
|
||||
e.preventDefault()
|
||||
restoreSelection()
|
||||
document.execCommand('bold', false)
|
||||
editorRef.value?.focus()
|
||||
onInput()
|
||||
}
|
||||
|
||||
// 执行文字颜色
|
||||
function execColor(color: string, e: Event) {
|
||||
e.preventDefault()
|
||||
restoreSelection()
|
||||
if (color) {
|
||||
document.execCommand('foreColor', false, color)
|
||||
}
|
||||
else {
|
||||
// 移除颜色:先获取选区文本,删除后用无格式文本替换
|
||||
document.execCommand('removeFormat', false)
|
||||
}
|
||||
showColorPicker.value = false
|
||||
editorRef.value?.focus()
|
||||
onInput()
|
||||
}
|
||||
|
||||
function toggleColorPicker(e: Event) {
|
||||
e.preventDefault()
|
||||
saveSelection()
|
||||
showColorPicker.value = !showColorPicker.value
|
||||
}
|
||||
|
||||
// 工具栏按钮 mousedown 时保存选区
|
||||
function onToolbarMousedown(e: Event) {
|
||||
e.preventDefault()
|
||||
saveSelection()
|
||||
}
|
||||
|
||||
// 监听粘贴事件,只粘贴纯文本(保留已有的 HTML 标记,但不引入外部格式)
|
||||
function onPaste(e: ClipboardEvent) {
|
||||
e.preventDefault()
|
||||
// 优先粘贴 HTML(保留粗体/颜色),fallback 纯文本
|
||||
const html = e.clipboardData?.getData('text/html')
|
||||
const text = e.clipboardData?.getData('text/plain') || ''
|
||||
if (html) {
|
||||
// 清理外部 HTML:只保留简单的格式标签
|
||||
const cleanHtml = sanitizeHtml(html)
|
||||
document.execCommand('insertHTML', false, cleanHtml)
|
||||
}
|
||||
else {
|
||||
document.execCommand('insertText', false, text)
|
||||
}
|
||||
onInput()
|
||||
}
|
||||
|
||||
// 简易 HTML 清洗:只保留 b/strong/span/em/i/br 标签
|
||||
function sanitizeHtml(html: string): string {
|
||||
const div = document.createElement('div')
|
||||
div.innerHTML = html
|
||||
// 递归清洗
|
||||
function cleanNode(node: Node): string {
|
||||
if (node.nodeType === Node.TEXT_NODE)
|
||||
return node.textContent || ''
|
||||
|
||||
if (node.nodeType !== Node.ELEMENT_NODE)
|
||||
return ''
|
||||
|
||||
const el = node as HTMLElement
|
||||
const tag = el.tagName.toLowerCase()
|
||||
const allowedTags = ['b', 'strong', 'span', 'em', 'i', 'br', 'u']
|
||||
let inner = ''
|
||||
el.childNodes.forEach((child) => {
|
||||
inner += cleanNode(child)
|
||||
})
|
||||
|
||||
if (tag === 'br')
|
||||
return '<br>'
|
||||
|
||||
if (allowedTags.includes(tag)) {
|
||||
// 保留 span 的 style 中的 color
|
||||
if (tag === 'span' && el.style.color)
|
||||
return `<span style="color:${el.style.color}">${inner}</span>`
|
||||
|
||||
if (tag === 'b' || tag === 'strong')
|
||||
return `<b>${inner}</b>`
|
||||
|
||||
if (tag === 'em' || tag === 'i')
|
||||
return `<em>${inner}</em>`
|
||||
|
||||
return inner
|
||||
}
|
||||
// 块级元素转换为换行
|
||||
const blockTags = ['div', 'p', 'li', 'tr', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']
|
||||
if (blockTags.includes(tag))
|
||||
return `${inner}<br>`
|
||||
|
||||
return inner
|
||||
}
|
||||
return cleanNode(div)
|
||||
}
|
||||
|
||||
// 监听外部 modelValue 变化
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newVal:string) => {
|
||||
if (!editorRef.value)
|
||||
return
|
||||
// 仅在编辑器不聚焦或内容确实不同时更新
|
||||
if (!isFocused.value || editorRef.value.innerHTML !== newVal) {
|
||||
setEditorHtml(newVal || '')
|
||||
hasContent.value = !!getPlainText()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
nextTick(() => {
|
||||
setEditorHtml(props.modelValue || '')
|
||||
hasContent.value = !!getPlainText()
|
||||
})
|
||||
})
|
||||
|
||||
// 点击编辑器外部关闭颜色选择器
|
||||
function handleDocClick(e: MouseEvent) {
|
||||
const target = e.target as HTMLElement
|
||||
if (!target.closest('.rich-text-input'))
|
||||
showColorPicker.value = false
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('click', handleDocClick)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('click', handleDocClick)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="rich-text-input"
|
||||
:class="{ 'is-focused': isFocused, 'is-disabled': disabled, 'bordered': bordered }"
|
||||
>
|
||||
<!-- 工具栏 -->
|
||||
<div v-show="isFocused && !disabled" class="rti-toolbar">
|
||||
<button
|
||||
class="rti-btn"
|
||||
title="粗体 (Ctrl+B)"
|
||||
@mousedown="onToolbarMousedown"
|
||||
@click="execBold"
|
||||
>
|
||||
<b>B</b>
|
||||
</button>
|
||||
<div class="rti-color-wrap">
|
||||
<button
|
||||
class="rti-btn rti-btn-color"
|
||||
title="文字颜色"
|
||||
@mousedown="toggleColorPicker"
|
||||
>
|
||||
<span class="rti-color-icon">A</span>
|
||||
<span class="rti-color-bar" />
|
||||
</button>
|
||||
<div v-show="showColorPicker" class="rti-color-dropdown">
|
||||
<button
|
||||
v-for="c in colorOptions"
|
||||
:key="c.value"
|
||||
class="rti-color-option"
|
||||
:title="c.label"
|
||||
@mousedown="(e: Event) => execColor(c.value, e)"
|
||||
>
|
||||
<span class="rti-color-dot" :style="{ background: c.bg }" />
|
||||
<span class="rti-color-label">{{ c.label }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 编辑区域 -->
|
||||
<div class="rti-editor-wrap">
|
||||
<div
|
||||
ref="editorRef"
|
||||
class="rti-editor"
|
||||
:contenteditable="!disabled"
|
||||
:style="{
|
||||
maxHeight: `${maxRows * LINE_HEIGHT}px`,
|
||||
}"
|
||||
@input="onInput"
|
||||
@focus="onFocus"
|
||||
@blur="onBlur"
|
||||
@paste="onPaste"
|
||||
@mouseup="saveSelection"
|
||||
@keyup="saveSelection"
|
||||
></div>
|
||||
<div v-if="!hasContent && !isFocused" class="rti-placeholder">
|
||||
{{ placeholder }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.rich-text-input {
|
||||
position: relative;
|
||||
background: #fafbfc;
|
||||
transition: all 0.2s ease;
|
||||
overflow: visible;
|
||||
}
|
||||
.bordered {
|
||||
border: 1px solid #e5e8ef;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.rich-text-input:hover {
|
||||
border-color: #2080f0;
|
||||
}
|
||||
|
||||
.rich-text-input.is-focused {
|
||||
border-color: #2080f0;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
|
||||
}
|
||||
|
||||
.rich-text-input.is-disabled {
|
||||
opacity: 0.8;
|
||||
background: transparent;
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
.rich-text-input.is-disabled:hover {
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
/* 工具栏 */
|
||||
.rti-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
padding: 4px 8px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
background: #fafbfc;
|
||||
border-radius: 6px 6px 0 0;
|
||||
}
|
||||
|
||||
.rti-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 26px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
color: #4e5969;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.rti-btn:hover {
|
||||
background: #e8f4ff;
|
||||
color: #2080f0;
|
||||
}
|
||||
|
||||
.rti-btn b {
|
||||
font-weight: 700;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* 颜色按钮 */
|
||||
.rti-color-wrap {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.rti-btn-color {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 1px;
|
||||
width: 28px;
|
||||
}
|
||||
|
||||
.rti-color-icon {
|
||||
font-weight: 700;
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.rti-color-bar {
|
||||
width: 14px;
|
||||
height: 3px;
|
||||
background: linear-gradient(90deg, #e8364e, #2080f0, #fa8c16, #52c41a);
|
||||
border-radius: 1px;
|
||||
}
|
||||
|
||||
/* 颜色下拉 */
|
||||
.rti-color-dropdown {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
margin-top: 4px;
|
||||
padding: 6px;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 90px;
|
||||
}
|
||||
|
||||
.rti-color-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 5px 8px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
color: #4e5969;
|
||||
transition: background 0.15s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.rti-color-option:hover {
|
||||
background: #f2f3f5;
|
||||
}
|
||||
|
||||
.rti-color-dot {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid rgba(0, 0, 0, 0.06);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.rti-color-label {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* 编辑区域 */
|
||||
.rti-editor-wrap {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.rti-editor {
|
||||
padding: 2px 10px;
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
color: #1d2129;
|
||||
overflow-y: auto;
|
||||
outline: none;
|
||||
word-break: break-word;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.rti-editor:empty::before {
|
||||
content: '';
|
||||
}
|
||||
|
||||
/* 粗体和颜色在编辑器内的渲染 */
|
||||
.rti-editor :deep(b),
|
||||
.rti-editor :deep(strong) {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.rti-placeholder {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 10px;
|
||||
color: #c9cdd4;
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
pointer-events: none;
|
||||
user-select: none;
|
||||
}
|
||||
</style>
|
||||
<script lang="ts" setup>
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
modelValue?: string
|
||||
placeholder?: string
|
||||
minRows?: number
|
||||
maxRows?: number
|
||||
disabled?: boolean
|
||||
bordered?: boolean
|
||||
}>(), {
|
||||
modelValue: '',
|
||||
placeholder: '',
|
||||
minRows: 1,
|
||||
maxRows: 100,
|
||||
disabled: false,
|
||||
bordered: true,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: string): void
|
||||
}>()
|
||||
|
||||
const editorRef = ref<HTMLDivElement | null>(null)
|
||||
const isFocused = ref(false)
|
||||
const showColorPicker = ref(false)
|
||||
|
||||
const LINE_HEIGHT = 22 // 单行高度(px)
|
||||
|
||||
const colorOptions = [
|
||||
{ label: '红色', value: '#e8364e', bg: '#e8364e' },
|
||||
{ label: '蓝色', value: '#1890ff', bg: '#1890ff' },
|
||||
{ label: '橙色', value: '#fa8c16', bg: '#fa8c16' },
|
||||
{ label: '绿色', value: '#52c41a', bg: '#52c41a' },
|
||||
{ label: '紫色', value: '#722ed1', bg: '#722ed1' },
|
||||
{ label: '默认', value: '', bg: '#333333' },
|
||||
]
|
||||
|
||||
// 获取编辑器中去掉 HTML 标签后的纯文本,用于判断是否为空
|
||||
function getPlainText(): string {
|
||||
if (!editorRef.value)
|
||||
return ''
|
||||
return editorRef.value.innerText?.trim() || ''
|
||||
}
|
||||
|
||||
const hasContent = ref(false)
|
||||
|
||||
// 设置编辑器内容(仅在内容确实不同时才更新,防止光标重置)
|
||||
function setEditorHtml(html: string) {
|
||||
if (!editorRef.value)
|
||||
return
|
||||
if (editorRef.value.innerHTML !== html)
|
||||
editorRef.value.innerHTML = html || ''
|
||||
}
|
||||
|
||||
// 输入事件:同步内容到 modelValue
|
||||
function onInput() {
|
||||
if (!editorRef.value)
|
||||
return
|
||||
const html = editorRef.value.innerHTML || ''
|
||||
// 如果内容只是 <br> 或空 div 则视为空
|
||||
const plain = getPlainText()
|
||||
hasContent.value = !!plain
|
||||
emit('update:modelValue', plain ? html : '')
|
||||
}
|
||||
|
||||
function onFocus() {
|
||||
isFocused.value = true
|
||||
}
|
||||
|
||||
function onBlur() {
|
||||
// 延迟关闭,让工具栏按钮的 mousedown 有时间执行
|
||||
setTimeout(() => {
|
||||
isFocused.value = false
|
||||
showColorPicker.value = false
|
||||
}, 200)
|
||||
}
|
||||
|
||||
// =============== 工具栏操作 ===============
|
||||
|
||||
// 保存和恢复选区
|
||||
let savedSelection: Range | null = null
|
||||
|
||||
function saveSelection() {
|
||||
const sel = window.getSelection()
|
||||
if (sel && sel.rangeCount > 0)
|
||||
savedSelection = sel.getRangeAt(0).cloneRange()
|
||||
}
|
||||
|
||||
function restoreSelection() {
|
||||
if (savedSelection) {
|
||||
const sel = window.getSelection()
|
||||
if (sel) {
|
||||
sel.removeAllRanges()
|
||||
sel.addRange(savedSelection)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 执行粗体
|
||||
function execBold(e: Event) {
|
||||
e.preventDefault()
|
||||
restoreSelection()
|
||||
document.execCommand('bold', false)
|
||||
editorRef.value?.focus()
|
||||
onInput()
|
||||
}
|
||||
|
||||
// 执行文字颜色
|
||||
function execColor(color: string, e: Event) {
|
||||
e.preventDefault()
|
||||
restoreSelection()
|
||||
if (color) {
|
||||
document.execCommand('foreColor', false, color)
|
||||
}
|
||||
else {
|
||||
// 移除颜色:先获取选区文本,删除后用无格式文本替换
|
||||
document.execCommand('removeFormat', false)
|
||||
}
|
||||
showColorPicker.value = false
|
||||
editorRef.value?.focus()
|
||||
onInput()
|
||||
}
|
||||
|
||||
function toggleColorPicker(e: Event) {
|
||||
e.preventDefault()
|
||||
saveSelection()
|
||||
showColorPicker.value = !showColorPicker.value
|
||||
}
|
||||
|
||||
// 工具栏按钮 mousedown 时保存选区
|
||||
function onToolbarMousedown(e: Event) {
|
||||
e.preventDefault()
|
||||
saveSelection()
|
||||
}
|
||||
|
||||
// 监听粘贴事件,只粘贴纯文本(保留已有的 HTML 标记,但不引入外部格式)
|
||||
function onPaste(e: ClipboardEvent) {
|
||||
e.preventDefault()
|
||||
// 优先粘贴 HTML(保留粗体/颜色),fallback 纯文本
|
||||
const html = e.clipboardData?.getData('text/html')
|
||||
const text = e.clipboardData?.getData('text/plain') || ''
|
||||
if (html) {
|
||||
// 清理外部 HTML:只保留简单的格式标签
|
||||
const cleanHtml = sanitizeHtml(html)
|
||||
document.execCommand('insertHTML', false, cleanHtml)
|
||||
}
|
||||
else {
|
||||
document.execCommand('insertText', false, text)
|
||||
}
|
||||
onInput()
|
||||
}
|
||||
|
||||
// 简易 HTML 清洗:只保留 b/strong/span/em/i/br 标签
|
||||
function sanitizeHtml(html: string): string {
|
||||
const div = document.createElement('div')
|
||||
div.innerHTML = html
|
||||
// 递归清洗
|
||||
function cleanNode(node: Node): string {
|
||||
if (node.nodeType === Node.TEXT_NODE)
|
||||
return node.textContent || ''
|
||||
|
||||
if (node.nodeType !== Node.ELEMENT_NODE)
|
||||
return ''
|
||||
|
||||
const el = node as HTMLElement
|
||||
const tag = el.tagName.toLowerCase()
|
||||
const allowedTags = ['b', 'strong', 'span', 'em', 'i', 'br', 'u']
|
||||
let inner = ''
|
||||
el.childNodes.forEach((child) => {
|
||||
inner += cleanNode(child)
|
||||
})
|
||||
|
||||
if (tag === 'br')
|
||||
return '<br>'
|
||||
|
||||
if (allowedTags.includes(tag)) {
|
||||
// 保留 span 的 style 中的 color
|
||||
if (tag === 'span' && el.style.color)
|
||||
return `<span style="color:${el.style.color}">${inner}</span>`
|
||||
|
||||
if (tag === 'b' || tag === 'strong')
|
||||
return `<b>${inner}</b>`
|
||||
|
||||
if (tag === 'em' || tag === 'i')
|
||||
return `<em>${inner}</em>`
|
||||
|
||||
return inner
|
||||
}
|
||||
// 块级元素转换为换行
|
||||
const blockTags = ['div', 'p', 'li', 'tr', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']
|
||||
if (blockTags.includes(tag))
|
||||
return `${inner}<br>`
|
||||
|
||||
return inner
|
||||
}
|
||||
return cleanNode(div)
|
||||
}
|
||||
|
||||
// 监听外部 modelValue 变化
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newVal:string) => {
|
||||
if (!editorRef.value)
|
||||
return
|
||||
// 仅在编辑器不聚焦或内容确实不同时更新
|
||||
if (!isFocused.value || editorRef.value.innerHTML !== newVal) {
|
||||
setEditorHtml(newVal || '')
|
||||
hasContent.value = !!getPlainText()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
nextTick(() => {
|
||||
setEditorHtml(props.modelValue || '')
|
||||
hasContent.value = !!getPlainText()
|
||||
})
|
||||
})
|
||||
|
||||
// 点击编辑器外部关闭颜色选择器
|
||||
function handleDocClick(e: MouseEvent) {
|
||||
const target = e.target as HTMLElement
|
||||
if (!target.closest('.rich-text-input'))
|
||||
showColorPicker.value = false
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('click', handleDocClick)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('click', handleDocClick)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="rich-text-input"
|
||||
:class="{ 'is-focused': isFocused, 'is-disabled': disabled, 'bordered': bordered }"
|
||||
>
|
||||
<!-- 工具栏 -->
|
||||
<div v-show="isFocused && !disabled" class="rti-toolbar">
|
||||
<button
|
||||
class="rti-btn"
|
||||
title="粗体 (Ctrl+B)"
|
||||
@mousedown="onToolbarMousedown"
|
||||
@click="execBold"
|
||||
>
|
||||
<b>B</b>
|
||||
</button>
|
||||
<div class="rti-color-wrap">
|
||||
<button
|
||||
class="rti-btn rti-btn-color"
|
||||
title="文字颜色"
|
||||
@mousedown="toggleColorPicker"
|
||||
>
|
||||
<span class="rti-color-icon">A</span>
|
||||
<span class="rti-color-bar" />
|
||||
</button>
|
||||
<div v-show="showColorPicker" class="rti-color-dropdown">
|
||||
<button
|
||||
v-for="c in colorOptions"
|
||||
:key="c.value"
|
||||
class="rti-color-option"
|
||||
:title="c.label"
|
||||
@mousedown="(e: Event) => execColor(c.value, e)"
|
||||
>
|
||||
<span class="rti-color-dot" :style="{ background: c.bg }" />
|
||||
<span class="rti-color-label">{{ c.label }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 编辑区域 -->
|
||||
<div class="rti-editor-wrap">
|
||||
<div
|
||||
ref="editorRef"
|
||||
class="rti-editor"
|
||||
:contenteditable="!disabled"
|
||||
:style="{
|
||||
maxHeight: `${maxRows * LINE_HEIGHT}px`,
|
||||
}"
|
||||
@input="onInput"
|
||||
@focus="onFocus"
|
||||
@blur="onBlur"
|
||||
@paste="onPaste"
|
||||
@mouseup="saveSelection"
|
||||
@keyup="saveSelection"
|
||||
></div>
|
||||
<div v-if="!hasContent && !isFocused" class="rti-placeholder">
|
||||
{{ placeholder }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.rich-text-input {
|
||||
position: relative;
|
||||
background: #fafbfc;
|
||||
transition: all 0.2s ease;
|
||||
overflow: visible;
|
||||
}
|
||||
.bordered {
|
||||
border: 1px solid #e5e8ef;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.rich-text-input:hover {
|
||||
border-color: #2080f0;
|
||||
}
|
||||
|
||||
.rich-text-input.is-focused {
|
||||
border-color: #2080f0;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
|
||||
}
|
||||
|
||||
.rich-text-input.is-disabled {
|
||||
opacity: 0.8;
|
||||
background: transparent;
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
.rich-text-input.is-disabled:hover {
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
/* 工具栏 */
|
||||
.rti-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
padding: 4px 8px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
background: #fafbfc;
|
||||
border-radius: 6px 6px 0 0;
|
||||
}
|
||||
|
||||
.rti-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 26px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
color: #4e5969;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.rti-btn:hover {
|
||||
background: #e8f4ff;
|
||||
color: #2080f0;
|
||||
}
|
||||
|
||||
.rti-btn b {
|
||||
font-weight: 700;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* 颜色按钮 */
|
||||
.rti-color-wrap {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.rti-btn-color {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 1px;
|
||||
width: 28px;
|
||||
}
|
||||
|
||||
.rti-color-icon {
|
||||
font-weight: 700;
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.rti-color-bar {
|
||||
width: 14px;
|
||||
height: 3px;
|
||||
background: linear-gradient(90deg, #e8364e, #2080f0, #fa8c16, #52c41a);
|
||||
border-radius: 1px;
|
||||
}
|
||||
|
||||
/* 颜色下拉 */
|
||||
.rti-color-dropdown {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
margin-top: 4px;
|
||||
padding: 6px;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 90px;
|
||||
}
|
||||
|
||||
.rti-color-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 5px 8px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
color: #4e5969;
|
||||
transition: background 0.15s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.rti-color-option:hover {
|
||||
background: #f2f3f5;
|
||||
}
|
||||
|
||||
.rti-color-dot {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid rgba(0, 0, 0, 0.06);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.rti-color-label {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* 编辑区域 */
|
||||
.rti-editor-wrap {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.rti-editor {
|
||||
padding: 2px 10px;
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
color: #1d2129;
|
||||
overflow-y: auto;
|
||||
outline: none;
|
||||
word-break: break-word;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.rti-editor:empty::before {
|
||||
content: '';
|
||||
}
|
||||
|
||||
/* 粗体和颜色在编辑器内的渲染 */
|
||||
.rti-editor :deep(b),
|
||||
.rti-editor :deep(strong) {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.rti-placeholder {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 10px;
|
||||
color: #c9cdd4;
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
pointer-events: none;
|
||||
user-select: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,232 +1,232 @@
|
||||
<!-- 变更关闭确认表 -->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { Icon } from '@iconify/vue'
|
||||
import { useThemeStore } from '@/store/modules/theme';
|
||||
import Footer from './footer.vue';
|
||||
|
||||
const themeStore = useThemeStore();
|
||||
const props = defineProps(['type','isAiOpen','title','currentId','members'])
|
||||
const emit = defineEmits(['save','submit','confirmTab']);
|
||||
|
||||
const form = ref<{ content: string }>({
|
||||
content: ''
|
||||
});
|
||||
|
||||
const closeDocs = ref([
|
||||
{ name: "PID 图纸(PID-R201-03,受控最新版)", cat: "图纸与规程类", scope: "是", archived: true },
|
||||
{ name: "操作规程(含超温应急处置卡)", cat: "图纸与规程类", scope: "是", archived: false },
|
||||
{ name: "应急预案修订", cat: "图纸与规程类", scope: "不涉及", archived: false },
|
||||
{ name: "总图更新", cat: "图纸与规程类", scope: "否", archived: false },
|
||||
{ name: "DCS 联锁台账(新报警 / 联锁值)", cat: "台账与制度类", scope: "是", archived: false },
|
||||
{ name: "设备台账与备件清单", cat: "台账与制度类", scope: "是", archived: true },
|
||||
{ name: "风险分析报告(HAZOP / 检查表法)", cat: "过程与结果文件类", scope: "是", archived: true },
|
||||
{ name: "培训签到与考核记录", cat: "过程与结果文件类", scope: "是", archived: true },
|
||||
{ name: "PSSR 检查记录(含现场照片)", cat: "过程与结果文件类", scope: "是", archived: false },
|
||||
{ name: "验收报告与化验数据", cat: "过程与结果文件类", scope: "是", archived: false },
|
||||
]);
|
||||
const closeFold = ref<Record<string, boolean>>({});
|
||||
const uploadDoc = ref<string | null>(null);
|
||||
const uploadSel = ref<string | null>(null);
|
||||
|
||||
const updateDocs = ref<string[]>([]);
|
||||
const UPDATE_DOC_KW: Record<string, string> = { PID图纸: "PID", 操作规程: "操作规程", 总图: "总图", 设备台账: "设备台账", 工艺卡片: "工艺卡片", 联锁台账: "联锁台账", 应急预案: "应急预案" };
|
||||
const needUpdate = (name: string) => updateDocs.value.some((d:any) => name.includes(UPDATE_DOC_KW[d] ?? d));
|
||||
|
||||
const changeScope = (d: any, v: string) => {
|
||||
closeDocs.value = closeDocs.value.map((x:any) => (x.name === d.name ? { ...x, scope: v } : x));
|
||||
if (v !== d.scope) window.$message?.info(`演示:「${d.name}」改判为「${v}」,改判理由与操作人已留痕`);
|
||||
}
|
||||
|
||||
const uploadDocInfo = computed(() => {
|
||||
if (!uploadDoc.value) return null;
|
||||
const doc = closeDocs.value.find((x) => x.name === uploadDoc.value);
|
||||
const base = uploadDoc.value.replace(/[((].*$/, "");
|
||||
return {
|
||||
storePath: `\\\\PLANT-DMS\\变更管理\\2026\\MOC-2026-R01-0041\\${doc?.cat ?? ""}\\`,
|
||||
candidates: [`${base}_RevC_受控版.pdf`, `${base}_2026-08 更新版.docx`],
|
||||
base,
|
||||
};
|
||||
});
|
||||
const openDir = () => {
|
||||
window.$message?.info('演示:已在文档管理系统中打开该目录')
|
||||
}
|
||||
const uploadFiles = () => {
|
||||
uploadSel.value = `本地文件:${uploadDocInfo.value?.base}_最新版.pdf`;
|
||||
window.$message?.info('演示:已接收拖拽 / 选择的本地文件');
|
||||
}
|
||||
const uploadConfirm = () => {
|
||||
closeDocs.value = closeDocs.value.map((x) => (x.name === uploadDoc.value ? { ...x, archived: true } : x));
|
||||
window.$message?.success(`「${uploadDoc.value}」已上传并归档(${uploadSel.value},受控版本,哈希留痕)`);
|
||||
uploadDoc.value = null;
|
||||
}
|
||||
|
||||
// 保存草稿
|
||||
const saveDraft = () => {
|
||||
emit('save');
|
||||
}
|
||||
// 提交
|
||||
const submitConfirm = () => {
|
||||
emit('submit', props.type);
|
||||
}
|
||||
// // 确认标签内容
|
||||
const confirmTab = (tab:string, val:boolean) => {
|
||||
emit('confirmTab', tab, val);
|
||||
}
|
||||
|
||||
defineExpose({form})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-4">
|
||||
<div class="space-y-4 scroll">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<span class="flex items-center gap-1.5 text-sm font-semibold text-slate-700">
|
||||
<Icon icon="quill:folder-open" class="size-16px" />
|
||||
变更关闭确认表(资料归档清单)
|
||||
</span>
|
||||
<span class="inline-flex items-center gap-1 rounded-full border border-violet-200 bg-violet-100 px-2 py-0.5 text-xs font-medium text-violet-700">
|
||||
✨ AI 生成 · 需人工确认
|
||||
</span>
|
||||
<NTag size="small" class="text-xs">AI 辅助判定一次 · 支持人工改判留痕</NTag>
|
||||
<span class="ml-auto text-xs text-slate-400">判定为「是」的资料全部归档后,变更主管部门专责方可确认关闭</span>
|
||||
</div>
|
||||
<div class="border" :style="{ borderRadius: themeStore.themeRadius + 'px' }">
|
||||
<div class="flex items-center gap-3 bg-slate-100 px-3 py-2 text-xs font-medium text-slate-500">
|
||||
<span class="w-5"></span>
|
||||
<span class="flex-1">资料名称(与申请表「需更新的资料」勾选联动,勾选资料标记「需更新版本」)</span>
|
||||
<span class="w-48 text-center">是否涉及(AI 判定,可改判)</span>
|
||||
<span class="w-32 text-center">归档状态</span>
|
||||
</div>
|
||||
<template v-for="cat in (['图纸与规程类', '台账与制度类', '过程与结果文件类'])" :key="cat">
|
||||
<div v-if="closeDocs.filter((d) => d.cat === cat).length">
|
||||
<button @click="closeFold = { ...closeFold, [cat]: !closeFold[cat] }"
|
||||
class="flex w-full items-center gap-2 border-t bg-slate-50 px-3 py-2 text-left text-xs font-semibold text-slate-600 transition hover:bg-[#EAF0F9]">
|
||||
<Icon icon="formkit:right" class="size-14px text-slate-400 transition" :class="closeFold[cat] ? '' : 'rotate-90'" />
|
||||
{{ cat }}
|
||||
<span class="font-normal text-slate-400">
|
||||
{{ closeDocs.filter((d) => d.cat === cat).length }} 项 · 已归档
|
||||
{{ closeDocs.filter((d) => d.cat === cat && d.scope === '是' && d.archived).length }}/{{ closeDocs.filter((d) => d.cat === cat && d.scope === '是').length }}
|
||||
</span>
|
||||
<span class="ml-auto text-[11px] font-normal text-slate-400">{{ closeFold[cat] ? '点击展开' : '点击折叠' }}</span>
|
||||
</button>
|
||||
<template v-if="!closeFold[cat]">
|
||||
<div v-for="d in closeDocs.filter((x) => x.cat === cat)" :key="d.name" class="flex flex-wrap items-center gap-3 border-t px-3 py-2.5 text-sm">
|
||||
<span class="w-5 text-slate-400">{{ closeDocs.indexOf(d) + 1 }}</span>
|
||||
<span class="min-w-0 flex-1 text-slate-800">
|
||||
{{ d.name }}
|
||||
<NTag v-if="needUpdate(d.name)" size="small" type="info" class="ml-2">需更新版本</NTag>
|
||||
</span>
|
||||
<span class="flex w-48 shrink-0 justify-center gap-1.5">
|
||||
<NButton size="tiny" round v-for="v in (['是', '否', '不涉及'])" :key="v"
|
||||
@click="changeScope(d, v)"
|
||||
class="text-[11px]"
|
||||
:type="d.scope === v ? 'primary' : 'default'">
|
||||
{{ v }}
|
||||
</NButton>
|
||||
</span>
|
||||
<span class="flex w-32 shrink-0 items-center justify-center gap-2">
|
||||
<template v-if="d.scope === '是'">
|
||||
<NTag v-if="d.archived" size="small" type="success">已归档</NTag>
|
||||
<template v-else>
|
||||
<NTag size="small" type="warning">待上传</NTag>
|
||||
<NButton text type="primary" class="text-xs hover:underline" @click="uploadDoc = d.name; uploadSel = null;">上传</NButton>
|
||||
</template>
|
||||
</template>
|
||||
<NTag v-else size="small">{{ d.scope }}</NTag>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-4 text-xs text-slate-500">
|
||||
<span>
|
||||
统计:涉及 <b class="text-[#17407F]">{{ closeDocs.filter((d) => d.scope === '是').length }}</b> 项 ·
|
||||
已归档 <b class="text-emerald-600">{{ closeDocs.filter((d) => d.scope === '是' && d.archived).length }}</b> 项 ·
|
||||
待上传 <b class="text-amber-600">{{ closeDocs.filter((d) => d.scope === '是' && !d.archived).length }}</b> 项 ·
|
||||
需更新版本 <b class="text-[#1D4E9C]">{{ closeDocs.filter((d) => needUpdate(d.name)).length }}</b> 项(联动申请表勾选)
|
||||
</span>
|
||||
<span class="text-slate-400">资料上传支持 PC / 移动端(拍照上传),版本受控</span>
|
||||
</div>
|
||||
<div class="rounded-lg bg-[#EAF0F9] px-4 py-2.5 text-xs leading-5 text-[#17407F]">
|
||||
关闭校验说明:判定为「是」的资料项全部归档后,系统将全部流程完毕信号推送变更主管部门专责,专责确认后点击关闭,系统记录变更关闭时间;「否 / 不涉及」由 AI 辅助判定一次,人工改判须填写理由并留痕。临时变更恢复完成后,恢复操作票与参数核对记录自动追加至本清单。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Footer
|
||||
ref="footerRef"
|
||||
:type="props.type"
|
||||
:currentId="props.currentId"
|
||||
:title="props.title"
|
||||
:isAiOpen="props.isAiOpen"
|
||||
:members="props.members"
|
||||
@save="saveDraft"
|
||||
@submit="submitConfirm"
|
||||
@confirmTab="confirmTab"
|
||||
/>
|
||||
<!-- 资料上传弹窗 -->
|
||||
<NModal
|
||||
:show="uploadDoc !== null"
|
||||
preset="card"
|
||||
:auto-focus="false"
|
||||
:style="{ width: '550px', height: 'auto' }"
|
||||
:segmented="{ content: true, footer: true }"
|
||||
@update:show="(v) => !v && (uploadDoc = null)"
|
||||
>
|
||||
<template #header>
|
||||
<div class="flex items-center gap-2 text-base font-semibold text-slate-800">
|
||||
<Icon icon="material-symbols:upload" class="size-20px" /> 资料上传归档 — {{ uploadDoc }}
|
||||
</div>
|
||||
</template>
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<div class="mb-1 text-xs font-medium text-slate-500">系统文档存储地址(受控目录)</div>
|
||||
<div class="flex items-center gap-2 rounded-lg border bg-slate-50 px-3 py-2">
|
||||
<Icon icon="quill:folder-open" class="size-16px" />
|
||||
<code class="min-w-0 flex-1 truncate text-xs text-slate-600">{{ uploadDocInfo?.storePath }}</code>
|
||||
<NButton text type="primary" class="text-xs hover:underline" @click="openDir">打开目录</NButton>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="mb-1 text-xs font-medium text-slate-500">方式一:从存储地址选择资料</div>
|
||||
<div class="space-y-1.5">
|
||||
<p v-for="f in uploadDocInfo?.candidates" :key="f" @click="uploadSel = f"
|
||||
class="flex w-full items-center gap-2 rounded-lg border px-3 py-2 text-left text-xs transition cursor-pointer"
|
||||
:class="uploadSel === f ? 'border-[var(--theme-color)] bg-[var(--theme-color)] text-[var(--theme-color)] text-white' : 'bg-white text-slate-600 hover:border-[var(--theme-color)] hover:text-[var(--theme-color)]'"
|
||||
:style="{'--theme-color': themeStore.themeColor}"
|
||||
>
|
||||
<Icon icon="akar-icons:file" class="size-14px mr-1" /> {{ f }}
|
||||
<Icon v-if="uploadSel === f" icon="ix:success" class="ml-auto size-16px" />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="mb-1 text-xs font-medium text-slate-500">方式二:拖拽本地文件到区域</div>
|
||||
<button @click="uploadFiles"
|
||||
class="flex h-20 w-full flex-col items-center justify-center gap-1 rounded-lg border-2 border-dashed px-3 text-xs transition"
|
||||
:class="uploadSel?.startsWith('本地文件') ? 'border-[var(--theme-color)] bg-[#EAF0F9] text-[var(--theme-color)]' : 'border-slate-300 text-slate-400 hover:border-[var(--theme-color)] hover:text-[var(--theme-color)]'"
|
||||
:style="{'--theme-color': themeStore.themeColor}"
|
||||
>
|
||||
<Icon icon="material-symbols:upload" class="size-24px" />
|
||||
{{ uploadSel?.startsWith('本地文件') ? uploadSel : '将资料文件拖拽到此处,或点击选择本地文件' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="flex justify-end gap-2">
|
||||
<NButton @click="uploadDoc = null">取消</NButton>
|
||||
<NButton type="primary" :disabled="!uploadSel" @click="uploadConfirm">
|
||||
确认上传归档
|
||||
</NButton>
|
||||
</div>
|
||||
</template>
|
||||
</NModal>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.scroll {
|
||||
height: calc(100vh - 393px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
<!-- 变更关闭确认表 -->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { Icon } from '@iconify/vue'
|
||||
import { useThemeStore } from '@/store/modules/theme';
|
||||
import Footer from './footer.vue';
|
||||
|
||||
const themeStore = useThemeStore();
|
||||
const props = defineProps(['type','isAiOpen','title','currentId','members'])
|
||||
const emit = defineEmits(['save','submit','confirmTab']);
|
||||
|
||||
const form = ref<{ content: string }>({
|
||||
content: ''
|
||||
});
|
||||
|
||||
const closeDocs = ref([
|
||||
{ name: "PID 图纸(PID-R201-03,受控最新版)", cat: "图纸与规程类", scope: "是", archived: true },
|
||||
{ name: "操作规程(含超温应急处置卡)", cat: "图纸与规程类", scope: "是", archived: false },
|
||||
{ name: "应急预案修订", cat: "图纸与规程类", scope: "不涉及", archived: false },
|
||||
{ name: "总图更新", cat: "图纸与规程类", scope: "否", archived: false },
|
||||
{ name: "DCS 联锁台账(新报警 / 联锁值)", cat: "台账与制度类", scope: "是", archived: false },
|
||||
{ name: "设备台账与备件清单", cat: "台账与制度类", scope: "是", archived: true },
|
||||
{ name: "风险分析报告(HAZOP / 检查表法)", cat: "过程与结果文件类", scope: "是", archived: true },
|
||||
{ name: "培训签到与考核记录", cat: "过程与结果文件类", scope: "是", archived: true },
|
||||
{ name: "PSSR 检查记录(含现场照片)", cat: "过程与结果文件类", scope: "是", archived: false },
|
||||
{ name: "验收报告与化验数据", cat: "过程与结果文件类", scope: "是", archived: false },
|
||||
]);
|
||||
const closeFold = ref<Record<string, boolean>>({});
|
||||
const uploadDoc = ref<string | null>(null);
|
||||
const uploadSel = ref<string | null>(null);
|
||||
|
||||
const updateDocs = ref<string[]>([]);
|
||||
const UPDATE_DOC_KW: Record<string, string> = { PID图纸: "PID", 操作规程: "操作规程", 总图: "总图", 设备台账: "设备台账", 工艺卡片: "工艺卡片", 联锁台账: "联锁台账", 应急预案: "应急预案" };
|
||||
const needUpdate = (name: string) => updateDocs.value.some((d:any) => name.includes(UPDATE_DOC_KW[d] ?? d));
|
||||
|
||||
const changeScope = (d: any, v: string) => {
|
||||
closeDocs.value = closeDocs.value.map((x:any) => (x.name === d.name ? { ...x, scope: v } : x));
|
||||
if (v !== d.scope) window.$message?.info(`演示:「${d.name}」改判为「${v}」,改判理由与操作人已留痕`);
|
||||
}
|
||||
|
||||
const uploadDocInfo = computed(() => {
|
||||
if (!uploadDoc.value) return null;
|
||||
const doc = closeDocs.value.find((x) => x.name === uploadDoc.value);
|
||||
const base = uploadDoc.value.replace(/[((].*$/, "");
|
||||
return {
|
||||
storePath: `\\\\PLANT-DMS\\变更管理\\2026\\MOC-2026-R01-0041\\${doc?.cat ?? ""}\\`,
|
||||
candidates: [`${base}_RevC_受控版.pdf`, `${base}_2026-08 更新版.docx`],
|
||||
base,
|
||||
};
|
||||
});
|
||||
const openDir = () => {
|
||||
window.$message?.info('演示:已在文档管理系统中打开该目录')
|
||||
}
|
||||
const uploadFiles = () => {
|
||||
uploadSel.value = `本地文件:${uploadDocInfo.value?.base}_最新版.pdf`;
|
||||
window.$message?.info('演示:已接收拖拽 / 选择的本地文件');
|
||||
}
|
||||
const uploadConfirm = () => {
|
||||
closeDocs.value = closeDocs.value.map((x) => (x.name === uploadDoc.value ? { ...x, archived: true } : x));
|
||||
window.$message?.success(`「${uploadDoc.value}」已上传并归档(${uploadSel.value},受控版本,哈希留痕)`);
|
||||
uploadDoc.value = null;
|
||||
}
|
||||
|
||||
// 保存草稿
|
||||
const saveDraft = () => {
|
||||
emit('save');
|
||||
}
|
||||
// 提交
|
||||
const submitConfirm = () => {
|
||||
emit('submit', props.type);
|
||||
}
|
||||
// // 确认标签内容
|
||||
const confirmTab = (tab:string, val:boolean) => {
|
||||
emit('confirmTab', tab, val);
|
||||
}
|
||||
|
||||
defineExpose({form})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-4">
|
||||
<div class="space-y-4 scroll">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<span class="flex items-center gap-1.5 text-sm font-semibold text-slate-700">
|
||||
<Icon icon="quill:folder-open" class="size-16px" />
|
||||
变更关闭确认表(资料归档清单)
|
||||
</span>
|
||||
<span class="inline-flex items-center gap-1 rounded-full border border-violet-200 bg-violet-100 px-2 py-0.5 text-xs font-medium text-violet-700">
|
||||
✨ AI 生成 · 需人工确认
|
||||
</span>
|
||||
<NTag size="small" class="text-xs">AI 辅助判定一次 · 支持人工改判留痕</NTag>
|
||||
<span class="ml-auto text-xs text-slate-400">判定为「是」的资料全部归档后,变更主管部门专责方可确认关闭</span>
|
||||
</div>
|
||||
<div class="border" :style="{ borderRadius: themeStore.themeRadius + 'px' }">
|
||||
<div class="flex items-center gap-3 bg-slate-100 px-3 py-2 text-xs font-medium text-slate-500">
|
||||
<span class="w-5"></span>
|
||||
<span class="flex-1">资料名称(与申请表「需更新的资料」勾选联动,勾选资料标记「需更新版本」)</span>
|
||||
<span class="w-48 text-center">是否涉及(AI 判定,可改判)</span>
|
||||
<span class="w-32 text-center">归档状态</span>
|
||||
</div>
|
||||
<template v-for="cat in (['图纸与规程类', '台账与制度类', '过程与结果文件类'])" :key="cat">
|
||||
<div v-if="closeDocs.filter((d) => d.cat === cat).length">
|
||||
<button @click="closeFold = { ...closeFold, [cat]: !closeFold[cat] }"
|
||||
class="flex w-full items-center gap-2 border-t bg-slate-50 px-3 py-2 text-left text-xs font-semibold text-slate-600 transition hover:bg-[#EAF0F9]">
|
||||
<Icon icon="formkit:right" class="size-14px text-slate-400 transition" :class="closeFold[cat] ? '' : 'rotate-90'" />
|
||||
{{ cat }}
|
||||
<span class="font-normal text-slate-400">
|
||||
{{ closeDocs.filter((d) => d.cat === cat).length }} 项 · 已归档
|
||||
{{ closeDocs.filter((d) => d.cat === cat && d.scope === '是' && d.archived).length }}/{{ closeDocs.filter((d) => d.cat === cat && d.scope === '是').length }}
|
||||
</span>
|
||||
<span class="ml-auto text-[11px] font-normal text-slate-400">{{ closeFold[cat] ? '点击展开' : '点击折叠' }}</span>
|
||||
</button>
|
||||
<template v-if="!closeFold[cat]">
|
||||
<div v-for="d in closeDocs.filter((x) => x.cat === cat)" :key="d.name" class="flex flex-wrap items-center gap-3 border-t px-3 py-2.5 text-sm">
|
||||
<span class="w-5 text-slate-400">{{ closeDocs.indexOf(d) + 1 }}</span>
|
||||
<span class="min-w-0 flex-1 text-slate-800">
|
||||
{{ d.name }}
|
||||
<NTag v-if="needUpdate(d.name)" size="small" type="info" class="ml-2">需更新版本</NTag>
|
||||
</span>
|
||||
<span class="flex w-48 shrink-0 justify-center gap-1.5">
|
||||
<NButton size="tiny" round v-for="v in (['是', '否', '不涉及'])" :key="v"
|
||||
@click="changeScope(d, v)"
|
||||
class="text-[11px]"
|
||||
:type="d.scope === v ? 'primary' : 'default'">
|
||||
{{ v }}
|
||||
</NButton>
|
||||
</span>
|
||||
<span class="flex w-32 shrink-0 items-center justify-center gap-2">
|
||||
<template v-if="d.scope === '是'">
|
||||
<NTag v-if="d.archived" size="small" type="success">已归档</NTag>
|
||||
<template v-else>
|
||||
<NTag size="small" type="warning">待上传</NTag>
|
||||
<NButton text type="primary" class="text-xs hover:underline" @click="uploadDoc = d.name; uploadSel = null;">上传</NButton>
|
||||
</template>
|
||||
</template>
|
||||
<NTag v-else size="small">{{ d.scope }}</NTag>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-4 text-xs text-slate-500">
|
||||
<span>
|
||||
统计:涉及 <b class="text-[#17407F]">{{ closeDocs.filter((d) => d.scope === '是').length }}</b> 项 ·
|
||||
已归档 <b class="text-emerald-600">{{ closeDocs.filter((d) => d.scope === '是' && d.archived).length }}</b> 项 ·
|
||||
待上传 <b class="text-amber-600">{{ closeDocs.filter((d) => d.scope === '是' && !d.archived).length }}</b> 项 ·
|
||||
需更新版本 <b class="text-[#1D4E9C]">{{ closeDocs.filter((d) => needUpdate(d.name)).length }}</b> 项(联动申请表勾选)
|
||||
</span>
|
||||
<span class="text-slate-400">资料上传支持 PC / 移动端(拍照上传),版本受控</span>
|
||||
</div>
|
||||
<div class="rounded-lg bg-[#EAF0F9] px-4 py-2.5 text-xs leading-5 text-[#17407F]">
|
||||
关闭校验说明:判定为「是」的资料项全部归档后,系统将全部流程完毕信号推送变更主管部门专责,专责确认后点击关闭,系统记录变更关闭时间;「否 / 不涉及」由 AI 辅助判定一次,人工改判须填写理由并留痕。临时变更恢复完成后,恢复操作票与参数核对记录自动追加至本清单。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Footer
|
||||
ref="footerRef"
|
||||
:type="props.type"
|
||||
:currentId="props.currentId"
|
||||
:title="props.title"
|
||||
:isAiOpen="props.isAiOpen"
|
||||
:members="props.members"
|
||||
@save="saveDraft"
|
||||
@submit="submitConfirm"
|
||||
@confirmTab="confirmTab"
|
||||
/>
|
||||
<!-- 资料上传弹窗 -->
|
||||
<NModal
|
||||
:show="uploadDoc !== null"
|
||||
preset="card"
|
||||
:auto-focus="false"
|
||||
:style="{ width: '550px', height: 'auto' }"
|
||||
:segmented="{ content: true, footer: true }"
|
||||
@update:show="(v) => !v && (uploadDoc = null)"
|
||||
>
|
||||
<template #header>
|
||||
<div class="flex items-center gap-2 text-base font-semibold text-slate-800">
|
||||
<Icon icon="material-symbols:upload" class="size-20px" /> 资料上传归档 — {{ uploadDoc }}
|
||||
</div>
|
||||
</template>
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<div class="mb-1 text-xs font-medium text-slate-500">系统文档存储地址(受控目录)</div>
|
||||
<div class="flex items-center gap-2 rounded-lg border bg-slate-50 px-3 py-2">
|
||||
<Icon icon="quill:folder-open" class="size-16px" />
|
||||
<code class="min-w-0 flex-1 truncate text-xs text-slate-600">{{ uploadDocInfo?.storePath }}</code>
|
||||
<NButton text type="primary" class="text-xs hover:underline" @click="openDir">打开目录</NButton>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="mb-1 text-xs font-medium text-slate-500">方式一:从存储地址选择资料</div>
|
||||
<div class="space-y-1.5">
|
||||
<p v-for="f in uploadDocInfo?.candidates" :key="f" @click="uploadSel = f"
|
||||
class="flex w-full items-center gap-2 rounded-lg border px-3 py-2 text-left text-xs transition cursor-pointer"
|
||||
:class="uploadSel === f ? 'border-[var(--theme-color)] bg-[var(--theme-color)] text-[var(--theme-color)] text-white' : 'bg-white text-slate-600 hover:border-[var(--theme-color)] hover:text-[var(--theme-color)]'"
|
||||
:style="{'--theme-color': themeStore.themeColor}"
|
||||
>
|
||||
<Icon icon="akar-icons:file" class="size-14px mr-1" /> {{ f }}
|
||||
<Icon v-if="uploadSel === f" icon="ix:success" class="ml-auto size-16px" />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="mb-1 text-xs font-medium text-slate-500">方式二:拖拽本地文件到区域</div>
|
||||
<button @click="uploadFiles"
|
||||
class="flex h-20 w-full flex-col items-center justify-center gap-1 rounded-lg border-2 border-dashed px-3 text-xs transition"
|
||||
:class="uploadSel?.startsWith('本地文件') ? 'border-[var(--theme-color)] bg-[#EAF0F9] text-[var(--theme-color)]' : 'border-slate-300 text-slate-400 hover:border-[var(--theme-color)] hover:text-[var(--theme-color)]'"
|
||||
:style="{'--theme-color': themeStore.themeColor}"
|
||||
>
|
||||
<Icon icon="material-symbols:upload" class="size-24px" />
|
||||
{{ uploadSel?.startsWith('本地文件') ? uploadSel : '将资料文件拖拽到此处,或点击选择本地文件' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="flex justify-end gap-2">
|
||||
<NButton @click="uploadDoc = null">取消</NButton>
|
||||
<NButton type="primary" :disabled="!uploadSel" @click="uploadConfirm">
|
||||
确认上传归档
|
||||
</NButton>
|
||||
</div>
|
||||
</template>
|
||||
</NModal>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.scroll {
|
||||
height: calc(100vh - 393px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,53 +1,53 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { useThemeStore } from '@/store/modules/theme';
|
||||
import { Icon } from '@iconify/vue'
|
||||
import RichTextInput from './RichTextInput.vue'
|
||||
|
||||
const themeStore = useThemeStore();
|
||||
const props = defineProps(['formInfo'])
|
||||
const emit = defineEmits(['update:data']);
|
||||
|
||||
const form = ref<any>(null);
|
||||
watch(() => props.formInfo,
|
||||
(val: any) => {
|
||||
// 深度拷贝以避免直接修改 props,并确保响应式
|
||||
form.value = val
|
||||
},
|
||||
{ immediate: true, deep: true },
|
||||
)
|
||||
// 编辑风险预分析
|
||||
const preRiskEdit = ref<boolean>(false);
|
||||
// 更新数据
|
||||
const onCellChange = (key:string,val:string) => {
|
||||
form.value[key] = val;
|
||||
emit('update:data', key, val)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="border" :style="{ borderRadius: themeStore.themeRadius + 'px' }">
|
||||
<div class="flex items-center justify-between px-4 py-2 border-b">
|
||||
<div class="flex items-center">
|
||||
<Icon icon="lucide:list-checks" class="size-16px text-emerald-500" />
|
||||
<span class="font-semibold text-base ml-2">风险预分析报告</span>
|
||||
</div>
|
||||
<NButton text type="primary" class="ml-auto text-xs hover:underline" @click="preRiskEdit = !preRiskEdit">
|
||||
{{ preRiskEdit ? "完成" : "编辑" }}
|
||||
</NButton>
|
||||
</div>
|
||||
<div class="p-4">
|
||||
<div class="space-y-4">
|
||||
<div v-for="s in ([{ key: 'severity', name: '危害严重性分析' }, { key: 'probability', name: '事件概率分析' }, { key: 'protection', name: '保护措施影响分析' }])" :key="s.key" class="rounded-lg border">
|
||||
<div class="flex items-center gap-2 border-b bg-slate-50/60 px-4 py-2">
|
||||
<span class="text-sm font-semibold text-slate-700">{{ s.name }}</span>
|
||||
</div>
|
||||
<RichTextInput :disabled="!preRiskEdit" :modelValue="form[s.key]" :minRows="2" :bordered="false" @update:modelValue="(v) => onCellChange(s.key,v)" />
|
||||
</div>
|
||||
<div class="rounded-lg bg-amber-50 px-3 py-2 text-xs leading-5 text-amber-700">
|
||||
AI 风险预分析仅供参考,用于申请阶段的快速研判;正式风险识别请前往「风险分析记录表」标签页,使用 HAZOP / JSA / 检查表法开展并留存记录。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { useThemeStore } from '@/store/modules/theme';
|
||||
import { Icon } from '@iconify/vue'
|
||||
import RichTextInput from './RichTextInput.vue'
|
||||
|
||||
const themeStore = useThemeStore();
|
||||
const props = defineProps(['formInfo'])
|
||||
const emit = defineEmits(['update:data']);
|
||||
|
||||
const form = ref<any>(null);
|
||||
watch(() => props.formInfo,
|
||||
(val: any) => {
|
||||
// 深度拷贝以避免直接修改 props,并确保响应式
|
||||
form.value = val
|
||||
},
|
||||
{ immediate: true, deep: true },
|
||||
)
|
||||
// 编辑风险预分析
|
||||
const preRiskEdit = ref<boolean>(false);
|
||||
// 更新数据
|
||||
const onCellChange = (key:string,val:string) => {
|
||||
form.value[key] = val;
|
||||
emit('update:data', key, val)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="border" :style="{ borderRadius: themeStore.themeRadius + 'px' }">
|
||||
<div class="flex items-center justify-between px-4 py-2 border-b">
|
||||
<div class="flex items-center">
|
||||
<Icon icon="lucide:list-checks" class="size-16px text-emerald-500" />
|
||||
<span class="font-semibold text-base ml-2">风险预分析报告</span>
|
||||
</div>
|
||||
<NButton text type="primary" class="ml-auto text-xs hover:underline" @click="preRiskEdit = !preRiskEdit">
|
||||
{{ preRiskEdit ? "完成" : "编辑" }}
|
||||
</NButton>
|
||||
</div>
|
||||
<div class="p-4">
|
||||
<div class="space-y-4">
|
||||
<div v-for="s in ([{ key: 'severity', name: '危害严重性分析' }, { key: 'probability', name: '事件概率分析' }, { key: 'protection', name: '保护措施影响分析' }])" :key="s.key" class="rounded-lg border">
|
||||
<div class="flex items-center gap-2 border-b bg-slate-50/60 px-4 py-2">
|
||||
<span class="text-sm font-semibold text-slate-700">{{ s.name }}</span>
|
||||
</div>
|
||||
<RichTextInput :disabled="!preRiskEdit" :modelValue="form[s.key]" :minRows="2" :bordered="false" @update:modelValue="(v) => onCellChange(s.key,v)" />
|
||||
</div>
|
||||
<div class="rounded-lg bg-amber-50 px-3 py-2 text-xs leading-5 text-amber-700">
|
||||
AI 风险预分析仅供参考,用于申请阶段的快速研判;正式风险识别请前往「风险分析记录表」标签页,使用 HAZOP / JSA / 检查表法开展并留存记录。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,492 +1,492 @@
|
||||
<!-- 风险分析记录表 -->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { Icon } from '@iconify/vue'
|
||||
import { useThemeStore } from '@/store/modules/theme';
|
||||
import RiskPre from "./riskPre.vue";
|
||||
import Hazop from "./hazop.vue";
|
||||
import Jsa from "./jsa.vue";
|
||||
import Fmea from "./fmea.vue";
|
||||
import RiskCheck from "./riskCheck.vue";
|
||||
import Footer from './footer.vue'
|
||||
import { matrixConfigApi } from "@/service/api/system";
|
||||
|
||||
const themeStore = useThemeStore();
|
||||
|
||||
const props = defineProps(['type','isAiOpen','title','currentId','formInfo', 'currentForm', 'confirmed','members','steps']);
|
||||
const emit = defineEmits(['save','submit','confirmTab','update:steps']);
|
||||
|
||||
const hazopRiskMatrixConfig = ref<any>(null);
|
||||
const fmeaRiskMatrixConfig = ref<any>(null);
|
||||
const jsaRiskMatrixConfig = ref<any>(null);
|
||||
const pluginDone = computed(() =>
|
||||
riskRecords.value.reduce((acc:any, item:any) => {
|
||||
const s = item.source;
|
||||
if (s) acc[s] = (acc[s] || 0) + 1;
|
||||
return acc;
|
||||
}, {} as Record<string, number>)
|
||||
);
|
||||
const tools = ref<string[]>(["RISK","HAZOP","FMEA", "RISK_CHECK"]);
|
||||
const riskRecords = ref<any>([]);
|
||||
const pluginDrawer = ref<boolean>(false);
|
||||
const currentPlugin = ref<string>('');
|
||||
|
||||
watch(() => props.currentForm, (newVal:any) => {
|
||||
const omit = (obj:any, fields: string[]) => Object.fromEntries(Object.entries(obj).filter(([k]) => !fields.includes(k)));
|
||||
const result = newVal?.records.map((item:any) => omit(item, [
|
||||
'created_at', 'updated_at', 'change_id', 'source_row_id'
|
||||
]));
|
||||
riskRecords.value = result || [];
|
||||
}, { immediate: true })
|
||||
|
||||
// 风险识别分析记录表
|
||||
const TOOL_CARDS = [
|
||||
{ key: "RISK", name: "风险预分析" },
|
||||
{ key: "HAZOP", name: "HAZOP 分析" },
|
||||
{ key: "FMEA", name: "FMEA 分析" },
|
||||
{ key: "RISK_CHECK", name: "风险检查表" },
|
||||
];
|
||||
|
||||
// 根据l和s获取风险等级
|
||||
const hazopRiskLevel = (level: string) => {
|
||||
for (let i = 0; i < hazopRiskMatrixConfig.value?.risk_grades.length; i++) {
|
||||
const item = hazopRiskMatrixConfig.value?.risk_grades[i];
|
||||
if (level === item.name) {
|
||||
return item; // 返回整条数据
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const jsaRiskLevel = (level: string) => {
|
||||
for (let i = 0; i < jsaRiskMatrixConfig.value?.risk_grades.length; i++) {
|
||||
const item = jsaRiskMatrixConfig.value?.risk_grades[i];
|
||||
if (level === item.name) {
|
||||
return item; // 返回整条数据
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const fmeaRiskLevel = (level: string) => {
|
||||
for (let i = 0; i < fmeaRiskMatrixConfig.value?.risk_grades.length; i++) {
|
||||
const item = fmeaRiskMatrixConfig.value?.risk_grades[i];
|
||||
if (level === item.name) {
|
||||
return item; // 返回整条数据
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 删除记录
|
||||
const delRec = (i: number) => {
|
||||
riskRecords.value.splice(i, 1);
|
||||
};
|
||||
|
||||
// 单个转换为 PSSR 行动项
|
||||
const toPssr = (i: number) => {
|
||||
const rec = riskRecords.value[i];
|
||||
if (!rec || rec.to_pssr) return;
|
||||
riskRecords.value[i] = { ...rec, to_pssr: 1 };
|
||||
window.$message?.success("建议措施已转为 PSSR 行动项(见「PSSR 检查内容」· 一、风险分析行动项落实)");
|
||||
};
|
||||
|
||||
// 全部转为 PSSR 行动项
|
||||
const toPssrAll = () => {
|
||||
const result = riskRecords.value.filter((item:any) => item.to_pssr === 0);
|
||||
if (!result.length) {
|
||||
return window.$message?.info("所有建议措施均已转为 PSSR 行动项");
|
||||
}
|
||||
riskRecords.value = riskRecords.value.map((x:any) => ({ ...x, to_pssr: 1 }));
|
||||
window.$message?.success(`已将建议措施全部转为 PSSR 行动项(见「PSSR 检查内容」)`);
|
||||
};
|
||||
|
||||
// AI 自动整理
|
||||
const aiOrganize = async () => {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据 id 字段对数组去重(保留首次出现)
|
||||
* @param {Array} arr - 包含 id 字段的对象数组
|
||||
* @returns {Array} 去重后的新数组
|
||||
*/
|
||||
function uniqueById(arr: any[]) {
|
||||
const seen = new Set();
|
||||
const result = [];
|
||||
for (const item of arr) {
|
||||
const key = `${item.id}_${item.source}`;
|
||||
if (!seen.has(key)) {
|
||||
seen.add(key);
|
||||
result.push(item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// 整理入表
|
||||
const exportAll = (type: string, items: any[]) => {
|
||||
riskRecords.value = uniqueById([...riskRecords.value, ...items]);
|
||||
if (type === "all") {
|
||||
pluginDrawer.value = false;
|
||||
currentPlugin.value = '';
|
||||
window.$message?.success(`AI 已自动整理形成风险分析记录表(新增 ${items.length} 项),支持手动修改`);
|
||||
} else {
|
||||
window.$message?.success(`已选入 ${items.length} 条风险记录,可继续挑选或返回查看记录表`);
|
||||
}
|
||||
}
|
||||
|
||||
// 使用插件弹框
|
||||
const usePlugin = (key: string) => {
|
||||
currentPlugin.value = key;
|
||||
pluginDrawer.value = true;
|
||||
}
|
||||
// 关闭插件弹框
|
||||
const closePlugin = () => {
|
||||
pluginDrawer.value = false;
|
||||
}
|
||||
|
||||
// 保存草稿
|
||||
const saveDraft = () => {
|
||||
emit('save');
|
||||
}
|
||||
// 提交
|
||||
const submitConfirm = () => {
|
||||
emit('submit', props.type);
|
||||
}
|
||||
// // 确认标签内容
|
||||
const confirmTab = (tab:string, val:boolean) => {
|
||||
emit('confirmTab', tab, val);
|
||||
}
|
||||
|
||||
// 更新审批流程
|
||||
const updateSteps = (steps:any[]) => {
|
||||
emit('update:steps', steps);
|
||||
}
|
||||
|
||||
// 获取JSA风险矩阵配置
|
||||
const getRiskMatrixConfig = async () => {
|
||||
const {data,error} = await matrixConfigApi();
|
||||
if(!error){
|
||||
hazopRiskMatrixConfig.value = data?.hazop || null;
|
||||
jsaRiskMatrixConfig.value = data?.jsa || null;
|
||||
fmeaRiskMatrixConfig.value = data?.fmea || null;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({riskRecords})
|
||||
|
||||
onMounted(() => {
|
||||
getRiskMatrixConfig();
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-4">
|
||||
<div class="space-y-4 scroll">
|
||||
<div class="border p-3" :style="{ borderRadius: themeStore.themeRadius + 'px' }">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<span class="flex items-center gap-1.5 text-sm font-semibold text-slate-700">
|
||||
<Icon icon="lucide:shield-alert" class="size-16px" />
|
||||
风险识别工具(按变更等级匹配)
|
||||
</span>
|
||||
<NTag size="small" :type="formInfo?.change_level === 2 ? 'error' : 'default'">
|
||||
{{ formInfo?.change_level === 2 ? '重要变更' : '一般变更' }}
|
||||
</NTag>
|
||||
<span class="text-xs text-slate-400">
|
||||
{{ formInfo?.change_level === 2 ? '规则:HAZOP 必做' : '规则:涉及工艺安全边界的应升级 HAZOP' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="grid gap-2 grid-cols-4 mt-3">
|
||||
<div v-for="t in TOOL_CARDS" :key="t.key"
|
||||
class="flex items-center gap-2 rounded-lg border px-3 py-2 transition"
|
||||
:class="pluginDone[t.key] !== undefined ? 'border-[var(--theme-color)] bg-[var(--theme-color)]' : tools.includes(t.key) ? 'border-[var(--theme-color)] bg-white' : 'border-slate-200 bg-white'"
|
||||
:style="{'--theme-color': themeStore.themeColor}"
|
||||
>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div
|
||||
class="flex items-center gap-1.5 text-xs font-semibold"
|
||||
:class="pluginDone[t.key] !== undefined ? 'text-white' : tools.includes(t.key) ? 'text-[var(--theme-color)]' : 'text-slate-500'"
|
||||
:style="{'--theme-color': themeStore.themeColor}"
|
||||
>
|
||||
<Icon icon="fluent:wand-24-regular" class="size-16px" />
|
||||
{{ t.name }}
|
||||
</div>
|
||||
<div class="mt-0.5 text-[10px]" :class="pluginDone[t.key] !== undefined ? 'text-white' : 'text-slate-400'">
|
||||
{{ pluginDone[t.key] !== undefined ? `已使用并分析了 ${pluginDone[t.key]} 条内容` : '未使用此工具分析' }}
|
||||
</div>
|
||||
</div>
|
||||
<NButton size="small" class="text-xs !text-white" :tertiary="pluginDone[t.key] !== undefined" type="primary" @click="usePlugin(t.key)">
|
||||
使用
|
||||
</NButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="border" :style="{ borderRadius: themeStore.themeRadius + 'px' }">
|
||||
<div class="flex flex-wrap items-center gap-2 bg-slate-100 px-3 py-2">
|
||||
<span class="flex items-center gap-1.5 text-sm font-medium text-slate-700">
|
||||
<Icon icon="proicons:alert-triangle" class="size-16px text-amber-500" />
|
||||
风险分析记录表
|
||||
</span>
|
||||
<span class="text-[11px] text-slate-400">共 {{ riskRecords.length }} 项</span>
|
||||
<span class="ml-auto hidden text-[11px] text-slate-400 lg:block">插件结果「入表」或 AI 自动整理形成;单元格点击修改,风险等级点击切换</span>
|
||||
<NButton ghost size="small" color="#7c3aed" class="text-xs" @click="toPssrAll">
|
||||
<Icon icon="tabler:clipboard-check" class="size-14px" />
|
||||
全部转 PSSR 行动项
|
||||
</NButton>
|
||||
<NButton v-if="isAiOpen" ghost size="small" type="primary" class="text-xs" @click="aiOrganize">
|
||||
<Icon icon="lucide:sparkles" class="size-12px" />
|
||||
AI 自动整理
|
||||
</NButton>
|
||||
</div>
|
||||
<div v-if="riskRecords.length === 0" class="px-3 py-6 text-center text-xs text-slate-400">
|
||||
尚无风险记录:调用上方插件完成分析后逐条「入表」,或点击「AI 自动整理」形成记录表
|
||||
</div>
|
||||
<div v-else class="overflow-x-auto p-3">
|
||||
<table class="w-full border-collapse text-xs">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="w-40 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">风险项</th>
|
||||
<th class="w-80 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">场景描述</th>
|
||||
<th class="w-16 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">固有风险</th>
|
||||
<th class="w-60 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">现有措施</th>
|
||||
<th class="w-60 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">建议措施</th>
|
||||
<th class="w-16 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">剩余风险</th>
|
||||
<th class="w-16 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">来源</th>
|
||||
<th class="w-15 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(rec, i) in riskRecords" :key="i">
|
||||
<td class="border px-1.5 py-1 font-medium text-slate-700">
|
||||
<NInput type="textarea" size="small" v-model:value="rec.item" :autosize="{minRows:1}" class="text-xs" />
|
||||
</td>
|
||||
<td class="border px-1.5 py-1">
|
||||
<NInput type="textarea" size="small" v-model:value="rec.scene" :autosize="{minRows:1}" class="text-xs" />
|
||||
</td>
|
||||
<td class="border px-1.5 py-1 text-center align-top">
|
||||
<div v-if="rec.source==='RISK'">
|
||||
<NTag
|
||||
v-if="rec.inherent_level && rec.inherent_level === '低'"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
type="success"
|
||||
>
|
||||
{{rec.inherent_level}}
|
||||
</NTag>
|
||||
<NTag
|
||||
v-if="rec.inherent_level && rec.inherent_level === '中'"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
type="warning"
|
||||
>
|
||||
{{rec.inherent_level}}
|
||||
</NTag>
|
||||
<NTag
|
||||
v-if="rec.inherent_level && rec.inherent_level === '高'"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
type="error"
|
||||
>
|
||||
{{rec.inherent_level}}
|
||||
</NTag>
|
||||
</div>
|
||||
<div v-if="rec.source==='HAZOP'">
|
||||
<NTag
|
||||
v-if="rec.inherent_level"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
:color="{
|
||||
color: hazopRiskLevel(rec.inherent_level)?.bg_color,
|
||||
textColor: hazopRiskLevel(rec.inherent_level)?.font_color,
|
||||
borderColor: hazopRiskLevel(rec.inherent_level)?.bg_color,
|
||||
}"
|
||||
>
|
||||
{{rec.inherent_level}}
|
||||
</NTag>
|
||||
</div>
|
||||
<div v-if="rec.source==='FMEA'">
|
||||
<NTag
|
||||
v-if="rec.inherent_level"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
:color="{
|
||||
color: fmeaRiskLevel(rec.inherent_level)?.bg_color,
|
||||
textColor: fmeaRiskLevel(rec.inherent_level)?.font_color,
|
||||
borderColor: fmeaRiskLevel(rec.inherent_level)?.bg_color,
|
||||
}"
|
||||
>
|
||||
{{rec.inherent_level}}
|
||||
</NTag>
|
||||
<span v-else>-</span>
|
||||
</div>
|
||||
<div v-if="rec.source==='JSA'">
|
||||
<NTag
|
||||
v-if="rec.inherent_level"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
:color="{
|
||||
color: jsaRiskLevel(rec.inherent_level)?.bg_color,
|
||||
textColor: jsaRiskLevel(rec.inherent_level)?.font_color,
|
||||
borderColor: jsaRiskLevel(rec.inherent_level)?.bg_color,
|
||||
}"
|
||||
>
|
||||
{{rec.inherent_level}}
|
||||
</NTag>
|
||||
</div>
|
||||
<div v-if="rec.source==='RISK_CHECK'">
|
||||
<span>
|
||||
{{rec.inherent_level?rec.inherent_level:'-'}}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="border px-1.5 py-1">
|
||||
<NInput type="textarea" size="small" v-model:value="rec.safeguards" :autosize="{minRows:1}" class="text-xs" />
|
||||
</td>
|
||||
<td class="border px-1.5 py-1">
|
||||
<NInput type="textarea" size="small" v-model:value="rec.suggestions" :autosize="{minRows:1}" class="text-xs" />
|
||||
</td>
|
||||
<td class="border px-1.5 py-1 text-center align-top">
|
||||
<div v-if="rec.source==='RISK'">
|
||||
<NTag
|
||||
v-if="rec.residual_level && rec.residual_level === '低'"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
type="success"
|
||||
>
|
||||
{{rec.residual_level}}
|
||||
</NTag>
|
||||
<NTag
|
||||
v-if="rec.residual_level && rec.residual_level === '中'"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
type="warning"
|
||||
>
|
||||
{{rec.residual_level}}
|
||||
</NTag>
|
||||
<NTag
|
||||
v-if="rec.residual_level && rec.residual_level === '高'"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
type="error"
|
||||
>
|
||||
{{rec.residual_level}}
|
||||
</NTag>
|
||||
</div>
|
||||
<div v-if="rec.source==='HAZOP'">
|
||||
<NTag
|
||||
v-if="rec.residual_level"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
:color="{
|
||||
color: hazopRiskLevel(rec.residual_level)?.bg_color,
|
||||
textColor: hazopRiskLevel(rec.residual_level)?.font_color,
|
||||
borderColor: hazopRiskLevel(rec.residual_level)?.bg_color,
|
||||
}"
|
||||
>
|
||||
<span>
|
||||
{{rec.residual_level}}
|
||||
</span>
|
||||
</NTag>
|
||||
</div>
|
||||
<div v-if="rec.source==='FMEA'">
|
||||
<NTag
|
||||
v-if="rec.residual_level"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
:color="{
|
||||
color: fmeaRiskLevel(rec.residual_level)?.bg_color,
|
||||
textColor: fmeaRiskLevel(rec.residual_level)?.font_color,
|
||||
borderColor: fmeaRiskLevel(rec.residual_level)?.bg_color,
|
||||
}"
|
||||
>
|
||||
{{rec.residual_level}}
|
||||
</NTag>
|
||||
<span v-else>-</span>
|
||||
</div>
|
||||
<div v-if="rec.source==='JSA'">
|
||||
<NTag
|
||||
v-if="rec.residual_level"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
:color="{
|
||||
color: jsaRiskLevel(rec.residual_level)?.bg_color,
|
||||
textColor: jsaRiskLevel(rec.residual_level)?.font_color,
|
||||
borderColor: jsaRiskLevel(rec.residual_level)?.bg_color,
|
||||
}"
|
||||
>
|
||||
<span>
|
||||
{{rec.residual_level}}
|
||||
</span>
|
||||
</NTag>
|
||||
</div>
|
||||
<div v-if="rec.source==='RISK_CHECK'">
|
||||
<span>
|
||||
{{rec.residual_level?rec.residual_level:'-'}}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="border px-1.5 py-1 text-center align-top">
|
||||
<NTag size="small" type="info" class="text-11px">{{ rec.source==='RISK'?'风险预分析':rec.source==='RISK_CHECK'?'风险检查': rec.source }}</NTag>
|
||||
</td>
|
||||
<td class="border px-1.5 py-1 text-center align-top">
|
||||
<NTag v-if="rec.to_pssr" size="small" :color="{ color: '#f5f3ff', textColor: '#7c3aed', borderColor: '#f5f3ff' }">已转 PSSR</NTag>
|
||||
<NButton text size="tiny" color="#7c3aed" v-else class="hover:underline" @click="toPssr(Number(i))">转 PSSR</NButton>
|
||||
<div>
|
||||
<NPopconfirm
|
||||
positive-text="确定"
|
||||
:positiveButtonProps="{ size: 'tiny' }"
|
||||
:negativeButtonProps="{ size: 'tiny' }"
|
||||
@positive-click="delRec(Number(i))"
|
||||
>
|
||||
<template #trigger>
|
||||
<NButton text type="error" size="tiny" class="mt-1 hover:underline">删除</NButton>
|
||||
</template>
|
||||
确定删除吗?
|
||||
</NPopconfirm>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Footer
|
||||
ref="footerRef"
|
||||
:type="props.type"
|
||||
:currentId="props.currentId"
|
||||
:title="props.title"
|
||||
:isAiOpen="props.isAiOpen"
|
||||
:currentForm="formInfo"
|
||||
:confirmed="props.confirmed"
|
||||
:members="props.members"
|
||||
:steps="props.steps"
|
||||
@save="saveDraft"
|
||||
@submit="submitConfirm"
|
||||
@confirmTab="confirmTab"
|
||||
@update:steps="updateSteps"
|
||||
/>
|
||||
<!-- 插件抽屉 -->
|
||||
<NDrawer v-model:show="pluginDrawer" width="100%" placement="right" :auto-focus="false">
|
||||
<NDrawerContent>
|
||||
<template v-if="currentPlugin === 'RISK'">
|
||||
<RiskPre :isAiOpen="props.isAiOpen" :currentId="props.currentId" @close="closePlugin" @toTable="exportAll" />
|
||||
</template>
|
||||
<template v-if="currentPlugin === 'HAZOP'">
|
||||
<Hazop :isAiOpen="props.isAiOpen" :currentId="props.currentId" :hazopRiskMatrixConfig="hazopRiskMatrixConfig" @close="closePlugin" @toTable="exportAll" />
|
||||
</template>
|
||||
<template v-if="currentPlugin === 'FMEA'">
|
||||
<Fmea :isAiOpen="props.isAiOpen" :currentId="props.currentId" :fmeaRiskMatrixConfig="fmeaRiskMatrixConfig" @close="closePlugin" @toTable="exportAll" />
|
||||
</template>
|
||||
<template v-if="currentPlugin === 'RISK_CHECK'">
|
||||
<RiskCheck :isAiOpen="props.isAiOpen" :currentId="props.currentId" @close="closePlugin" @toTable="exportAll" />
|
||||
</template>
|
||||
</NDrawerContent>
|
||||
</NDrawer>
|
||||
</template>
|
||||
<style scoped lang="scss">
|
||||
.scroll {
|
||||
height: calc(100vh - 379px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
<!-- 风险分析记录表 -->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { Icon } from '@iconify/vue'
|
||||
import { useThemeStore } from '@/store/modules/theme';
|
||||
import RiskPre from "./riskPre.vue";
|
||||
import Hazop from "./hazop.vue";
|
||||
import Jsa from "./jsa.vue";
|
||||
import Fmea from "./fmea.vue";
|
||||
import RiskCheck from "./riskCheck.vue";
|
||||
import Footer from './footer.vue'
|
||||
import { matrixConfigApi } from "@/service/api/system";
|
||||
|
||||
const themeStore = useThemeStore();
|
||||
|
||||
const props = defineProps(['type','isAiOpen','title','currentId','formInfo', 'currentForm', 'confirmed','members','steps']);
|
||||
const emit = defineEmits(['save','submit','confirmTab','update:steps']);
|
||||
|
||||
const hazopRiskMatrixConfig = ref<any>(null);
|
||||
const fmeaRiskMatrixConfig = ref<any>(null);
|
||||
const jsaRiskMatrixConfig = ref<any>(null);
|
||||
const pluginDone = computed(() =>
|
||||
riskRecords.value.reduce((acc:any, item:any) => {
|
||||
const s = item.source;
|
||||
if (s) acc[s] = (acc[s] || 0) + 1;
|
||||
return acc;
|
||||
}, {} as Record<string, number>)
|
||||
);
|
||||
const tools = ref<string[]>(["RISK","HAZOP","FMEA", "RISK_CHECK"]);
|
||||
const riskRecords = ref<any>([]);
|
||||
const pluginDrawer = ref<boolean>(false);
|
||||
const currentPlugin = ref<string>('');
|
||||
|
||||
watch(() => props.currentForm, (newVal:any) => {
|
||||
const omit = (obj:any, fields: string[]) => Object.fromEntries(Object.entries(obj).filter(([k]) => !fields.includes(k)));
|
||||
const result = newVal?.records.map((item:any) => omit(item, [
|
||||
'created_at', 'updated_at', 'change_id', 'source_row_id'
|
||||
]));
|
||||
riskRecords.value = result || [];
|
||||
}, { immediate: true })
|
||||
|
||||
// 风险识别分析记录表
|
||||
const TOOL_CARDS = [
|
||||
{ key: "RISK", name: "风险预分析" },
|
||||
{ key: "HAZOP", name: "HAZOP 分析" },
|
||||
{ key: "FMEA", name: "FMEA 分析" },
|
||||
{ key: "RISK_CHECK", name: "风险检查表" },
|
||||
];
|
||||
|
||||
// 根据l和s获取风险等级
|
||||
const hazopRiskLevel = (level: string) => {
|
||||
for (let i = 0; i < hazopRiskMatrixConfig.value?.risk_grades.length; i++) {
|
||||
const item = hazopRiskMatrixConfig.value?.risk_grades[i];
|
||||
if (level === item.name) {
|
||||
return item; // 返回整条数据
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const jsaRiskLevel = (level: string) => {
|
||||
for (let i = 0; i < jsaRiskMatrixConfig.value?.risk_grades.length; i++) {
|
||||
const item = jsaRiskMatrixConfig.value?.risk_grades[i];
|
||||
if (level === item.name) {
|
||||
return item; // 返回整条数据
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const fmeaRiskLevel = (level: string) => {
|
||||
for (let i = 0; i < fmeaRiskMatrixConfig.value?.risk_grades.length; i++) {
|
||||
const item = fmeaRiskMatrixConfig.value?.risk_grades[i];
|
||||
if (level === item.name) {
|
||||
return item; // 返回整条数据
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 删除记录
|
||||
const delRec = (i: number) => {
|
||||
riskRecords.value.splice(i, 1);
|
||||
};
|
||||
|
||||
// 单个转换为 PSSR 行动项
|
||||
const toPssr = (i: number) => {
|
||||
const rec = riskRecords.value[i];
|
||||
if (!rec || rec.to_pssr) return;
|
||||
riskRecords.value[i] = { ...rec, to_pssr: 1 };
|
||||
window.$message?.success("建议措施已转为 PSSR 行动项(见「PSSR 检查内容」· 一、风险分析行动项落实)");
|
||||
};
|
||||
|
||||
// 全部转为 PSSR 行动项
|
||||
const toPssrAll = () => {
|
||||
const result = riskRecords.value.filter((item:any) => item.to_pssr === 0);
|
||||
if (!result.length) {
|
||||
return window.$message?.info("所有建议措施均已转为 PSSR 行动项");
|
||||
}
|
||||
riskRecords.value = riskRecords.value.map((x:any) => ({ ...x, to_pssr: 1 }));
|
||||
window.$message?.success(`已将建议措施全部转为 PSSR 行动项(见「PSSR 检查内容」)`);
|
||||
};
|
||||
|
||||
// AI 自动整理
|
||||
const aiOrganize = async () => {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据 id 字段对数组去重(保留首次出现)
|
||||
* @param {Array} arr - 包含 id 字段的对象数组
|
||||
* @returns {Array} 去重后的新数组
|
||||
*/
|
||||
function uniqueById(arr: any[]) {
|
||||
const seen = new Set();
|
||||
const result = [];
|
||||
for (const item of arr) {
|
||||
const key = `${item.id}_${item.source}`;
|
||||
if (!seen.has(key)) {
|
||||
seen.add(key);
|
||||
result.push(item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// 整理入表
|
||||
const exportAll = (type: string, items: any[]) => {
|
||||
riskRecords.value = uniqueById([...riskRecords.value, ...items]);
|
||||
if (type === "all") {
|
||||
pluginDrawer.value = false;
|
||||
currentPlugin.value = '';
|
||||
window.$message?.success(`AI 已自动整理形成风险分析记录表(新增 ${items.length} 项),支持手动修改`);
|
||||
} else {
|
||||
window.$message?.success(`已选入 ${items.length} 条风险记录,可继续挑选或返回查看记录表`);
|
||||
}
|
||||
}
|
||||
|
||||
// 使用插件弹框
|
||||
const usePlugin = (key: string) => {
|
||||
currentPlugin.value = key;
|
||||
pluginDrawer.value = true;
|
||||
}
|
||||
// 关闭插件弹框
|
||||
const closePlugin = () => {
|
||||
pluginDrawer.value = false;
|
||||
}
|
||||
|
||||
// 保存草稿
|
||||
const saveDraft = () => {
|
||||
emit('save');
|
||||
}
|
||||
// 提交
|
||||
const submitConfirm = () => {
|
||||
emit('submit', props.type);
|
||||
}
|
||||
// // 确认标签内容
|
||||
const confirmTab = (tab:string, val:boolean) => {
|
||||
emit('confirmTab', tab, val);
|
||||
}
|
||||
|
||||
// 更新审批流程
|
||||
const updateSteps = (steps:any[]) => {
|
||||
emit('update:steps', steps);
|
||||
}
|
||||
|
||||
// 获取JSA风险矩阵配置
|
||||
const getRiskMatrixConfig = async () => {
|
||||
const {data,error} = await matrixConfigApi();
|
||||
if(!error){
|
||||
hazopRiskMatrixConfig.value = data?.hazop || null;
|
||||
jsaRiskMatrixConfig.value = data?.jsa || null;
|
||||
fmeaRiskMatrixConfig.value = data?.fmea || null;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({riskRecords})
|
||||
|
||||
onMounted(() => {
|
||||
getRiskMatrixConfig();
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-4">
|
||||
<div class="space-y-4 scroll">
|
||||
<div class="border p-3" :style="{ borderRadius: themeStore.themeRadius + 'px' }">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<span class="flex items-center gap-1.5 text-sm font-semibold text-slate-700">
|
||||
<Icon icon="lucide:shield-alert" class="size-16px" />
|
||||
风险识别工具(按变更等级匹配)
|
||||
</span>
|
||||
<NTag size="small" :type="formInfo?.change_level === 2 ? 'error' : 'default'">
|
||||
{{ formInfo?.change_level === 2 ? '重要变更' : '一般变更' }}
|
||||
</NTag>
|
||||
<span class="text-xs text-slate-400">
|
||||
{{ formInfo?.change_level === 2 ? '规则:HAZOP 必做' : '规则:涉及工艺安全边界的应升级 HAZOP' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="grid gap-2 grid-cols-4 mt-3">
|
||||
<div v-for="t in TOOL_CARDS" :key="t.key"
|
||||
class="flex items-center gap-2 rounded-lg border px-3 py-2 transition"
|
||||
:class="pluginDone[t.key] !== undefined ? 'border-[var(--theme-color)] bg-[var(--theme-color)]' : tools.includes(t.key) ? 'border-[var(--theme-color)] bg-white' : 'border-slate-200 bg-white'"
|
||||
:style="{'--theme-color': themeStore.themeColor}"
|
||||
>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div
|
||||
class="flex items-center gap-1.5 text-xs font-semibold"
|
||||
:class="pluginDone[t.key] !== undefined ? 'text-white' : tools.includes(t.key) ? 'text-[var(--theme-color)]' : 'text-slate-500'"
|
||||
:style="{'--theme-color': themeStore.themeColor}"
|
||||
>
|
||||
<Icon icon="fluent:wand-24-regular" class="size-16px" />
|
||||
{{ t.name }}
|
||||
</div>
|
||||
<div class="mt-0.5 text-[10px]" :class="pluginDone[t.key] !== undefined ? 'text-white' : 'text-slate-400'">
|
||||
{{ pluginDone[t.key] !== undefined ? `已使用并分析了 ${pluginDone[t.key]} 条内容` : '未使用此工具分析' }}
|
||||
</div>
|
||||
</div>
|
||||
<NButton size="small" class="text-xs !text-white" :tertiary="pluginDone[t.key] !== undefined" type="primary" @click="usePlugin(t.key)">
|
||||
使用
|
||||
</NButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="border" :style="{ borderRadius: themeStore.themeRadius + 'px' }">
|
||||
<div class="flex flex-wrap items-center gap-2 bg-slate-100 px-3 py-2">
|
||||
<span class="flex items-center gap-1.5 text-sm font-medium text-slate-700">
|
||||
<Icon icon="proicons:alert-triangle" class="size-16px text-amber-500" />
|
||||
风险分析记录表
|
||||
</span>
|
||||
<span class="text-[11px] text-slate-400">共 {{ riskRecords.length }} 项</span>
|
||||
<span class="ml-auto hidden text-[11px] text-slate-400 lg:block">插件结果「入表」或 AI 自动整理形成;单元格点击修改,风险等级点击切换</span>
|
||||
<NButton ghost size="small" color="#7c3aed" class="text-xs" @click="toPssrAll">
|
||||
<Icon icon="tabler:clipboard-check" class="size-14px" />
|
||||
全部转 PSSR 行动项
|
||||
</NButton>
|
||||
<NButton v-if="isAiOpen" ghost size="small" type="primary" class="text-xs" @click="aiOrganize">
|
||||
<Icon icon="lucide:sparkles" class="size-12px" />
|
||||
AI 自动整理
|
||||
</NButton>
|
||||
</div>
|
||||
<div v-if="riskRecords.length === 0" class="px-3 py-6 text-center text-xs text-slate-400">
|
||||
尚无风险记录:调用上方插件完成分析后逐条「入表」,或点击「AI 自动整理」形成记录表
|
||||
</div>
|
||||
<div v-else class="overflow-x-auto p-3">
|
||||
<table class="w-full border-collapse text-xs">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="w-40 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">风险项</th>
|
||||
<th class="w-80 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">场景描述</th>
|
||||
<th class="w-16 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">固有风险</th>
|
||||
<th class="w-60 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">现有措施</th>
|
||||
<th class="w-60 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">建议措施</th>
|
||||
<th class="w-16 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">剩余风险</th>
|
||||
<th class="w-16 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">来源</th>
|
||||
<th class="w-15 border bg-slate-50 px-2 py-1.5 text-[11px] font-medium text-slate-500">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(rec, i) in riskRecords" :key="i">
|
||||
<td class="border px-1.5 py-1 font-medium text-slate-700">
|
||||
<NInput type="textarea" size="small" v-model:value="rec.item" :autosize="{minRows:1}" class="text-xs" />
|
||||
</td>
|
||||
<td class="border px-1.5 py-1">
|
||||
<NInput type="textarea" size="small" v-model:value="rec.scene" :autosize="{minRows:1}" class="text-xs" />
|
||||
</td>
|
||||
<td class="border px-1.5 py-1 text-center align-top">
|
||||
<div v-if="rec.source==='RISK'">
|
||||
<NTag
|
||||
v-if="rec.inherent_level && rec.inherent_level === '低'"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
type="success"
|
||||
>
|
||||
{{rec.inherent_level}}
|
||||
</NTag>
|
||||
<NTag
|
||||
v-if="rec.inherent_level && rec.inherent_level === '中'"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
type="warning"
|
||||
>
|
||||
{{rec.inherent_level}}
|
||||
</NTag>
|
||||
<NTag
|
||||
v-if="rec.inherent_level && rec.inherent_level === '高'"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
type="error"
|
||||
>
|
||||
{{rec.inherent_level}}
|
||||
</NTag>
|
||||
</div>
|
||||
<div v-if="rec.source==='HAZOP'">
|
||||
<NTag
|
||||
v-if="rec.inherent_level"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
:color="{
|
||||
color: hazopRiskLevel(rec.inherent_level)?.bg_color,
|
||||
textColor: hazopRiskLevel(rec.inherent_level)?.font_color,
|
||||
borderColor: hazopRiskLevel(rec.inherent_level)?.bg_color,
|
||||
}"
|
||||
>
|
||||
{{rec.inherent_level}}
|
||||
</NTag>
|
||||
</div>
|
||||
<div v-if="rec.source==='FMEA'">
|
||||
<NTag
|
||||
v-if="rec.inherent_level"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
:color="{
|
||||
color: fmeaRiskLevel(rec.inherent_level)?.bg_color,
|
||||
textColor: fmeaRiskLevel(rec.inherent_level)?.font_color,
|
||||
borderColor: fmeaRiskLevel(rec.inherent_level)?.bg_color,
|
||||
}"
|
||||
>
|
||||
{{rec.inherent_level}}
|
||||
</NTag>
|
||||
<span v-else>-</span>
|
||||
</div>
|
||||
<div v-if="rec.source==='JSA'">
|
||||
<NTag
|
||||
v-if="rec.inherent_level"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
:color="{
|
||||
color: jsaRiskLevel(rec.inherent_level)?.bg_color,
|
||||
textColor: jsaRiskLevel(rec.inherent_level)?.font_color,
|
||||
borderColor: jsaRiskLevel(rec.inherent_level)?.bg_color,
|
||||
}"
|
||||
>
|
||||
{{rec.inherent_level}}
|
||||
</NTag>
|
||||
</div>
|
||||
<div v-if="rec.source==='RISK_CHECK'">
|
||||
<span>
|
||||
{{rec.inherent_level?rec.inherent_level:'-'}}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="border px-1.5 py-1">
|
||||
<NInput type="textarea" size="small" v-model:value="rec.safeguards" :autosize="{minRows:1}" class="text-xs" />
|
||||
</td>
|
||||
<td class="border px-1.5 py-1">
|
||||
<NInput type="textarea" size="small" v-model:value="rec.suggestions" :autosize="{minRows:1}" class="text-xs" />
|
||||
</td>
|
||||
<td class="border px-1.5 py-1 text-center align-top">
|
||||
<div v-if="rec.source==='RISK'">
|
||||
<NTag
|
||||
v-if="rec.residual_level && rec.residual_level === '低'"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
type="success"
|
||||
>
|
||||
{{rec.residual_level}}
|
||||
</NTag>
|
||||
<NTag
|
||||
v-if="rec.residual_level && rec.residual_level === '中'"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
type="warning"
|
||||
>
|
||||
{{rec.residual_level}}
|
||||
</NTag>
|
||||
<NTag
|
||||
v-if="rec.residual_level && rec.residual_level === '高'"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
type="error"
|
||||
>
|
||||
{{rec.residual_level}}
|
||||
</NTag>
|
||||
</div>
|
||||
<div v-if="rec.source==='HAZOP'">
|
||||
<NTag
|
||||
v-if="rec.residual_level"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
:color="{
|
||||
color: hazopRiskLevel(rec.residual_level)?.bg_color,
|
||||
textColor: hazopRiskLevel(rec.residual_level)?.font_color,
|
||||
borderColor: hazopRiskLevel(rec.residual_level)?.bg_color,
|
||||
}"
|
||||
>
|
||||
<span>
|
||||
{{rec.residual_level}}
|
||||
</span>
|
||||
</NTag>
|
||||
</div>
|
||||
<div v-if="rec.source==='FMEA'">
|
||||
<NTag
|
||||
v-if="rec.residual_level"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
:color="{
|
||||
color: fmeaRiskLevel(rec.residual_level)?.bg_color,
|
||||
textColor: fmeaRiskLevel(rec.residual_level)?.font_color,
|
||||
borderColor: fmeaRiskLevel(rec.residual_level)?.bg_color,
|
||||
}"
|
||||
>
|
||||
{{rec.residual_level}}
|
||||
</NTag>
|
||||
<span v-else>-</span>
|
||||
</div>
|
||||
<div v-if="rec.source==='JSA'">
|
||||
<NTag
|
||||
v-if="rec.residual_level"
|
||||
class="text-[11px]"
|
||||
size="small"
|
||||
:color="{
|
||||
color: jsaRiskLevel(rec.residual_level)?.bg_color,
|
||||
textColor: jsaRiskLevel(rec.residual_level)?.font_color,
|
||||
borderColor: jsaRiskLevel(rec.residual_level)?.bg_color,
|
||||
}"
|
||||
>
|
||||
<span>
|
||||
{{rec.residual_level}}
|
||||
</span>
|
||||
</NTag>
|
||||
</div>
|
||||
<div v-if="rec.source==='RISK_CHECK'">
|
||||
<span>
|
||||
{{rec.residual_level?rec.residual_level:'-'}}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="border px-1.5 py-1 text-center align-top">
|
||||
<NTag size="small" type="info" class="text-11px">{{ rec.source==='RISK'?'风险预分析':rec.source==='RISK_CHECK'?'风险检查': rec.source }}</NTag>
|
||||
</td>
|
||||
<td class="border px-1.5 py-1 text-center align-top">
|
||||
<NTag v-if="rec.to_pssr" size="small" :color="{ color: '#f5f3ff', textColor: '#7c3aed', borderColor: '#f5f3ff' }">已转 PSSR</NTag>
|
||||
<NButton text size="tiny" color="#7c3aed" v-else class="hover:underline" @click="toPssr(Number(i))">转 PSSR</NButton>
|
||||
<div>
|
||||
<NPopconfirm
|
||||
positive-text="确定"
|
||||
:positiveButtonProps="{ size: 'tiny' }"
|
||||
:negativeButtonProps="{ size: 'tiny' }"
|
||||
@positive-click="delRec(Number(i))"
|
||||
>
|
||||
<template #trigger>
|
||||
<NButton text type="error" size="tiny" class="mt-1 hover:underline">删除</NButton>
|
||||
</template>
|
||||
确定删除吗?
|
||||
</NPopconfirm>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Footer
|
||||
ref="footerRef"
|
||||
:type="props.type"
|
||||
:currentId="props.currentId"
|
||||
:title="props.title"
|
||||
:isAiOpen="props.isAiOpen"
|
||||
:currentForm="formInfo"
|
||||
:confirmed="props.confirmed"
|
||||
:members="props.members"
|
||||
:steps="props.steps"
|
||||
@save="saveDraft"
|
||||
@submit="submitConfirm"
|
||||
@confirmTab="confirmTab"
|
||||
@update:steps="updateSteps"
|
||||
/>
|
||||
<!-- 插件抽屉 -->
|
||||
<NDrawer v-model:show="pluginDrawer" width="100%" placement="right" :auto-focus="false">
|
||||
<NDrawerContent>
|
||||
<template v-if="currentPlugin === 'RISK'">
|
||||
<RiskPre :isAiOpen="props.isAiOpen" :currentId="props.currentId" @close="closePlugin" @toTable="exportAll" />
|
||||
</template>
|
||||
<template v-if="currentPlugin === 'HAZOP'">
|
||||
<Hazop :isAiOpen="props.isAiOpen" :currentId="props.currentId" :hazopRiskMatrixConfig="hazopRiskMatrixConfig" @close="closePlugin" @toTable="exportAll" />
|
||||
</template>
|
||||
<template v-if="currentPlugin === 'FMEA'">
|
||||
<Fmea :isAiOpen="props.isAiOpen" :currentId="props.currentId" :fmeaRiskMatrixConfig="fmeaRiskMatrixConfig" @close="closePlugin" @toTable="exportAll" />
|
||||
</template>
|
||||
<template v-if="currentPlugin === 'RISK_CHECK'">
|
||||
<RiskCheck :isAiOpen="props.isAiOpen" :currentId="props.currentId" @close="closePlugin" @toTable="exportAll" />
|
||||
</template>
|
||||
</NDrawerContent>
|
||||
</NDrawer>
|
||||
</template>
|
||||
<style scoped lang="scss">
|
||||
.scroll {
|
||||
height: calc(100vh - 379px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
@@ -1,304 +1,304 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { Icon } from '@iconify/vue'
|
||||
import { useThemeStore } from '@/store/modules/theme';
|
||||
import { peopleListApi } from '@/service/api/system';
|
||||
import { riskPreDetailApi, riskPreSaveApi } from '@/service/api/plugin';
|
||||
|
||||
const themeStore = useThemeStore();
|
||||
const props = defineProps(['isAiOpen','currentId'])
|
||||
const emit = defineEmits(['close','toTable']);
|
||||
// 表格样式
|
||||
const TH = "border bg-slate-100 px-2 py-1.5 text-[11px] font-medium text-slate-500";
|
||||
const TD = "border px-1.5 py-1 align-top";
|
||||
|
||||
// 加载状态
|
||||
const loading = ref(false);
|
||||
// 风险分析记录
|
||||
const riskRecords = ref<{id:number,risk_item:string,scene_desc:string,risk_value:string,residual_risk_value:string,safeguards:string,suggestions:string}[]>([]);
|
||||
// 风险等级
|
||||
const risk_grades = ref<{label:string,value:string}[]>([
|
||||
{label:'低',value:'低'},
|
||||
{label:'中',value:'中'},
|
||||
{label:'高',value:'高'},
|
||||
]);
|
||||
// 人员列表源数据
|
||||
const workers = ref<{user_id:number,user_name:string,org_name?:string}[]>([]);
|
||||
// 选中的人员
|
||||
const selectedWorkers = ref<{user_id:number,user_name:string,org_name?:string}[]>([]);
|
||||
// 选择分析人员弹窗
|
||||
const openSelectWorker = ref(false);
|
||||
// 搜索分析人员
|
||||
const searchWorker = ref("");
|
||||
// 分析人员列表
|
||||
const workerList = computed(() => workers.value.filter((x:{user_id:number,user_name:string,org_name?:string}) => !searchWorker.value || x.user_name.includes(searchWorker.value)));
|
||||
// 选择分析人员
|
||||
const selectWorker = (n: {user_id:number,user_name:string,org_name?:string}) => {
|
||||
selectedWorkers.value = selectedWorkers.value.includes(n) ? selectedWorkers.value.filter((x:any) => x.user_id !== n.user_id) : [...selectedWorkers.value, n];
|
||||
};
|
||||
// 匹配是否有人员
|
||||
const hasWorker = (id:number) => {
|
||||
return selectedWorkers.value.some((item:{user_id:number,user_name:string,org_name?:string}) => item.user_id === id);
|
||||
};
|
||||
|
||||
// 运行 AI 执行风险分析
|
||||
const runAi = async () => {
|
||||
|
||||
};
|
||||
|
||||
// 导出Word
|
||||
const generateReport = async () => {
|
||||
window.$message?.warning("还差接口");
|
||||
}
|
||||
|
||||
// 保存
|
||||
const save = async () => {
|
||||
loading.value = true;
|
||||
// 处理选中的人员,移除 org_name 字段
|
||||
const workers = (selectedWorkers.value ?? []).map((item: { org_name?:string; user_id: number; user_name: string }) => {
|
||||
const { org_name, ...rest } = item;
|
||||
return rest;
|
||||
});
|
||||
const {error} = await riskPreSaveApi(props.currentId, {
|
||||
rows: riskRecords.value,
|
||||
users: workers,
|
||||
});
|
||||
if(!error){
|
||||
window.$message?.success("保存成功");
|
||||
getDetail();
|
||||
}
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
// AI整理如表、入表
|
||||
const enterToTable = (type: string, row: any) => {
|
||||
if(type==='single'){
|
||||
if(!row?.id){
|
||||
return window.$message?.warning("请先保存再入表");
|
||||
}
|
||||
const enrichedRow:any[] = [];
|
||||
enrichedRow.push({
|
||||
id: row?.id || 0,
|
||||
scene: row?.scene_desc || '',
|
||||
source: 'RISK',
|
||||
item: row?.risk_item || '',
|
||||
inherent_level: row?.risk_value || '',
|
||||
safeguards: row?.safeguards || '',
|
||||
suggestions: row?.suggestions || '',
|
||||
residual_level: row?.residual_risk_value || '',
|
||||
to_pssr: 0,
|
||||
source_row_id: row?.id || 0,
|
||||
});
|
||||
emit('toTable',type,enrichedRow);
|
||||
}
|
||||
if(type==='all'){
|
||||
const result = riskRecords.value.filter((item:any) => !item.id);
|
||||
if(result.length){
|
||||
return window.$message?.warning("请先保存再入表");
|
||||
}
|
||||
const enrichedRows:any[] = [];
|
||||
riskRecords.value.forEach((row:any) => {
|
||||
enrichedRows.push({
|
||||
id: row?.id || 0,
|
||||
scene: row?.scene_desc || '',
|
||||
source: 'RISK',
|
||||
item: row?.risk_item || '',
|
||||
inherent_level: row?.risk_value || '',
|
||||
safeguards: row?.safeguards || '',
|
||||
suggestions: row?.suggestions || '',
|
||||
residual_level: row?.residual_risk_value || '',
|
||||
to_pssr: 0,
|
||||
source_row_id: row?.id || 0,
|
||||
});
|
||||
})
|
||||
emit('toTable',type,enrichedRows);
|
||||
}
|
||||
}
|
||||
|
||||
// 新增风险分析记录
|
||||
const addRisk = () => {
|
||||
riskRecords.value.push({
|
||||
id: 0,
|
||||
risk_item: '',
|
||||
scene_desc: '',
|
||||
risk_value: '',
|
||||
residual_risk_value: '',
|
||||
safeguards: '',
|
||||
suggestions: '',
|
||||
})
|
||||
}
|
||||
// 删除行
|
||||
const delRow = (rowIndex: number) => {
|
||||
riskRecords.value.splice(rowIndex, 1);
|
||||
}
|
||||
|
||||
// 获取人员列表
|
||||
const getWorkers = async () => {
|
||||
const {data,error} = await peopleListApi();
|
||||
if(!error){
|
||||
const transformed = data.map((item:any) => ({
|
||||
user_id: item.id,
|
||||
user_name: item.realname,
|
||||
org_name: item.user_departments.map((d:any) => d.label).join(';')
|
||||
}));
|
||||
workers.value = transformed;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取详情
|
||||
const getDetail = async () => {
|
||||
loading.value = true;
|
||||
const {data,error} = await riskPreDetailApi(props.currentId);
|
||||
if(!error){
|
||||
riskRecords.value = data?.rows || [];
|
||||
selectedWorkers.value = data?.users || [];
|
||||
}
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getWorkers();
|
||||
getDetail();
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NSpin :show="loading" size="small">
|
||||
<div class="space-y-3">
|
||||
<div
|
||||
class="flex flex-wrap items-center gap-2 rounded-lg border border-[#ACC6E5] bg-[#EAF0F9] px-3 py-2"
|
||||
:style="{
|
||||
'--theme-color': themeStore.themeColor
|
||||
}"
|
||||
>
|
||||
<NButton size="small" ghost type="primary" class="text-xs" @click="emit('close')">
|
||||
<Icon icon="basil:arrow-left-outline" class="size-18px" />
|
||||
返回工具列表
|
||||
</NButton>
|
||||
<NButton size="small" ghost type="primary" class="text-xs" @click="save()">保存</NButton>
|
||||
<span class="text-sm font-bold text-[var(--theme-color)]">风险预分析插件</span>
|
||||
<NTag size="small" type="info">插件</NTag>
|
||||
<span class="text-[11px] text-slate-500">{{`共${riskRecords.length} 条风险项`}}</span>
|
||||
<div class="relative">
|
||||
<NButton size="small" ghost type="primary" class="text-[11px]" @click="openSelectWorker = !openSelectWorker">
|
||||
<Icon icon="lucide:users" class="size-12px" /> 分析组成员 · 已选 {{ selectedWorkers.length }} 人
|
||||
</NButton>
|
||||
<template v-if="openSelectWorker">
|
||||
<div class="fixed inset-0 z-10" @click="openSelectWorker = false"></div>
|
||||
<div class="absolute right-0 top-8 z-20 w-72 rounded-lg border bg-white p-2 shadow-xl">
|
||||
<div class="mb-1.5 flex items-center justify-between">
|
||||
<span class="text-xs font-semibold text-slate-700">选择分析组成员(岗位人员库)</span>
|
||||
<span class="text-[11px] text-slate-400">已选 {{ selectedWorkers.length }} 人</span>
|
||||
</div>
|
||||
<NInput v-model:value="searchWorker" size="small" placeholder="搜索人名…" class="mb-1.5 text-xs" />
|
||||
<div class="max-h-48 space-y-0.5 overflow-y-auto">
|
||||
<div v-for="x in workerList" :key="x.user_id" @click="selectWorker(x)"
|
||||
class="cursor-pointer flex w-full items-center min-h-34px gap-2 rounded-md px-2 py-1.5 text-left text-xs"
|
||||
:class="hasWorker(x.user_id) ? 'bg-[#DFE9F6]' : 'hover:bg-slate-50'">
|
||||
<span class="flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border text-[10px]"
|
||||
:class="hasWorker(x.user_id) ? 'border-[var(--theme-color)] bg-[var(--theme-color)] text-white' : 'border-slate-300'">{{ hasWorker(x.user_id) ? "✓" : "" }}</span>
|
||||
<span class="font-medium text-slate-800">{{ x.user_name }}</span>
|
||||
<span class="text-[11px] text-slate-400">{{ x.org_name }}</span>
|
||||
<NTag v-if="selectedWorkers[0]?.user_id === x.user_id" size="small" type="primary" class="ml-auto">组长</NTag>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-1.5 border-t pt-1.5 text-[11px] leading-4 text-slate-400">
|
||||
首位选择者默认为组长;成员为选择式(非手写),参与记录自动归属到人,用于「参与风险分析次数」统计采集。
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="ml-auto flex items-center gap-1.5">
|
||||
<NButton size="small" ghost type="primary" class="text-xs" :disabled="riskRecords.length === 0" @click="enterToTable('all',null)">
|
||||
<Icon icon="carbon:document-import" class="size-14px mr-1" /> 全部整理入表
|
||||
</NButton>
|
||||
<NButton size="small" ghost type="primary" class="text-xs" @click="generateReport">
|
||||
<Icon icon="material-symbols:download" class="size-14px" /> 导出 Word
|
||||
</NButton>
|
||||
<NButton v-if="isAiOpen" size="small" type="primary" class="text-xs" :disabled="loading" @click="runAi">
|
||||
<Icon v-if="loading" icon="ri:loader-4-fill" class="size-14px animate-spin" />
|
||||
<Icon v-else icon="lucide:sparkles" class="size-12px" />
|
||||
AI 执行风险分析
|
||||
</NButton>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-3" :style="{'--theme-color': themeStore.themeColor}">
|
||||
<!-- 作业活动分析记录 -->
|
||||
<div class="bg-white">
|
||||
<div class="flex items-center gap-2 px-3 py-2 text-xs font-semibold text-slate-600 border border-b-0 rounded-tl-lg rounded-tr-lg">
|
||||
风险分析记录表
|
||||
<NButton size="small" ghost type="primary" class="text-xs ml-2" @click="addRisk">
|
||||
<Icon icon="ic:round-plus" class="size-14px" /> 新增风险分析记录
|
||||
</NButton>
|
||||
<span class="ml-auto text-[11px] font-normal text-slate-400">「入表」将本条选入风险分析记录表</span>
|
||||
</div>
|
||||
<p v-if="riskRecords.length===0" class="border py-5 text-center text-xs text-slate-400">暂无风险分析记录</p>
|
||||
<div v-else class="scroll">
|
||||
<table class="w-full">
|
||||
<thead>
|
||||
<tr>
|
||||
<th :class="TH" class="w-80px">操作</th>
|
||||
<th :class="TH" class="w-30">风险项</th>
|
||||
<th :class="TH" class="w-60">场景描述</th>
|
||||
<th :class="TH" class="w-20">固有风险</th>
|
||||
<th :class="TH" class="w-50">现有措施</th>
|
||||
<th :class="TH" class="w-60">建议措施</th>
|
||||
<th :class="TH" class="w-20">剩余风险</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(row, rowIndex) in riskRecords" :key="rowIndex">
|
||||
<td :class="TD">
|
||||
<div class="flex items-center justify-center gap-2 px-1 mt-2">
|
||||
<NButton text type="primary" size="tiny" @click="enterToTable('single',row)">
|
||||
入表
|
||||
</NButton>
|
||||
<NPopconfirm
|
||||
positive-text="确定"
|
||||
:positiveButtonProps="{ size: 'tiny' }"
|
||||
:negativeButtonProps="{ size: 'tiny' }"
|
||||
@positive-click="delRow(Number(rowIndex))"
|
||||
>
|
||||
<template #trigger>
|
||||
<NButton text type="error" size="tiny" title="删除行">
|
||||
<Icon icon="ep:delete" class="size-14px" />
|
||||
</NButton>
|
||||
</template>
|
||||
确定删除此行吗?
|
||||
</NPopconfirm>
|
||||
</div>
|
||||
</td>
|
||||
<td :class="TD">
|
||||
<NInput type="textarea" size="small" v-model:value="row.risk_item" :autosize="{minRows:1}" />
|
||||
</td>
|
||||
<td :class="TD">
|
||||
<NInput type="textarea" size="small" v-model:value="row.scene_desc" :autosize="{minRows:1}" />
|
||||
</td>
|
||||
<td :class="TD" class="text-center">
|
||||
<NSelect v-model:value="row.risk_value" :options="risk_grades" size="small" class="w-full" />
|
||||
</td>
|
||||
<td :class="TD">
|
||||
<NInput type="textarea" size="small" v-model:value="row.safeguards" :autosize="{minRows:1}" />
|
||||
</td>
|
||||
<td :class="TD">
|
||||
<NInput type="textarea" size="small" v-model:value="row.suggestions" :autosize="{minRows:1}" />
|
||||
</td>
|
||||
<td :class="TD" class="text-center">
|
||||
<NSelect v-model:value="row.residual_risk_value" :options="risk_grades" size="small" class="w-full" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</NSpin>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.scroll{
|
||||
height: calc(100vh - 135px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { Icon } from '@iconify/vue'
|
||||
import { useThemeStore } from '@/store/modules/theme';
|
||||
import { peopleListApi } from '@/service/api/system';
|
||||
import { riskPreDetailApi, riskPreSaveApi } from '@/service/api/plugin';
|
||||
|
||||
const themeStore = useThemeStore();
|
||||
const props = defineProps(['isAiOpen','currentId'])
|
||||
const emit = defineEmits(['close','toTable']);
|
||||
// 表格样式
|
||||
const TH = "border bg-slate-100 px-2 py-1.5 text-[11px] font-medium text-slate-500";
|
||||
const TD = "border px-1.5 py-1 align-top";
|
||||
|
||||
// 加载状态
|
||||
const loading = ref(false);
|
||||
// 风险分析记录
|
||||
const riskRecords = ref<{id:number,risk_item:string,scene_desc:string,risk_value:string,residual_risk_value:string,safeguards:string,suggestions:string}[]>([]);
|
||||
// 风险等级
|
||||
const risk_grades = ref<{label:string,value:string}[]>([
|
||||
{label:'低',value:'低'},
|
||||
{label:'中',value:'中'},
|
||||
{label:'高',value:'高'},
|
||||
]);
|
||||
// 人员列表源数据
|
||||
const workers = ref<{user_id:number,user_name:string,org_name?:string}[]>([]);
|
||||
// 选中的人员
|
||||
const selectedWorkers = ref<{user_id:number,user_name:string,org_name?:string}[]>([]);
|
||||
// 选择分析人员弹窗
|
||||
const openSelectWorker = ref(false);
|
||||
// 搜索分析人员
|
||||
const searchWorker = ref("");
|
||||
// 分析人员列表
|
||||
const workerList = computed(() => workers.value.filter((x:{user_id:number,user_name:string,org_name?:string}) => !searchWorker.value || x.user_name.includes(searchWorker.value)));
|
||||
// 选择分析人员
|
||||
const selectWorker = (n: {user_id:number,user_name:string,org_name?:string}) => {
|
||||
selectedWorkers.value = selectedWorkers.value.includes(n) ? selectedWorkers.value.filter((x:any) => x.user_id !== n.user_id) : [...selectedWorkers.value, n];
|
||||
};
|
||||
// 匹配是否有人员
|
||||
const hasWorker = (id:number) => {
|
||||
return selectedWorkers.value.some((item:{user_id:number,user_name:string,org_name?:string}) => item.user_id === id);
|
||||
};
|
||||
|
||||
// 运行 AI 执行风险分析
|
||||
const runAi = async () => {
|
||||
|
||||
};
|
||||
|
||||
// 导出Word
|
||||
const generateReport = async () => {
|
||||
window.$message?.warning("还差接口");
|
||||
}
|
||||
|
||||
// 保存
|
||||
const save = async () => {
|
||||
loading.value = true;
|
||||
// 处理选中的人员,移除 org_name 字段
|
||||
const workers = (selectedWorkers.value ?? []).map((item: { org_name?:string; user_id: number; user_name: string }) => {
|
||||
const { org_name, ...rest } = item;
|
||||
return rest;
|
||||
});
|
||||
const {error} = await riskPreSaveApi(props.currentId, {
|
||||
rows: riskRecords.value,
|
||||
users: workers,
|
||||
});
|
||||
if(!error){
|
||||
window.$message?.success("保存成功");
|
||||
getDetail();
|
||||
}
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
// AI整理如表、入表
|
||||
const enterToTable = (type: string, row: any) => {
|
||||
if(type==='single'){
|
||||
if(!row?.id){
|
||||
return window.$message?.warning("请先保存再入表");
|
||||
}
|
||||
const enrichedRow:any[] = [];
|
||||
enrichedRow.push({
|
||||
id: row?.id || 0,
|
||||
scene: row?.scene_desc || '',
|
||||
source: 'RISK',
|
||||
item: row?.risk_item || '',
|
||||
inherent_level: row?.risk_value || '',
|
||||
safeguards: row?.safeguards || '',
|
||||
suggestions: row?.suggestions || '',
|
||||
residual_level: row?.residual_risk_value || '',
|
||||
to_pssr: 0,
|
||||
source_row_id: row?.id || 0,
|
||||
});
|
||||
emit('toTable',type,enrichedRow);
|
||||
}
|
||||
if(type==='all'){
|
||||
const result = riskRecords.value.filter((item:any) => !item.id);
|
||||
if(result.length){
|
||||
return window.$message?.warning("请先保存再入表");
|
||||
}
|
||||
const enrichedRows:any[] = [];
|
||||
riskRecords.value.forEach((row:any) => {
|
||||
enrichedRows.push({
|
||||
id: row?.id || 0,
|
||||
scene: row?.scene_desc || '',
|
||||
source: 'RISK',
|
||||
item: row?.risk_item || '',
|
||||
inherent_level: row?.risk_value || '',
|
||||
safeguards: row?.safeguards || '',
|
||||
suggestions: row?.suggestions || '',
|
||||
residual_level: row?.residual_risk_value || '',
|
||||
to_pssr: 0,
|
||||
source_row_id: row?.id || 0,
|
||||
});
|
||||
})
|
||||
emit('toTable',type,enrichedRows);
|
||||
}
|
||||
}
|
||||
|
||||
// 新增风险分析记录
|
||||
const addRisk = () => {
|
||||
riskRecords.value.push({
|
||||
id: 0,
|
||||
risk_item: '',
|
||||
scene_desc: '',
|
||||
risk_value: '',
|
||||
residual_risk_value: '',
|
||||
safeguards: '',
|
||||
suggestions: '',
|
||||
})
|
||||
}
|
||||
// 删除行
|
||||
const delRow = (rowIndex: number) => {
|
||||
riskRecords.value.splice(rowIndex, 1);
|
||||
}
|
||||
|
||||
// 获取人员列表
|
||||
const getWorkers = async () => {
|
||||
const {data,error} = await peopleListApi();
|
||||
if(!error){
|
||||
const transformed = data.map((item:any) => ({
|
||||
user_id: item.id,
|
||||
user_name: item.realname,
|
||||
org_name: item.user_departments.map((d:any) => d.label).join(';')
|
||||
}));
|
||||
workers.value = transformed;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取详情
|
||||
const getDetail = async () => {
|
||||
loading.value = true;
|
||||
const {data,error} = await riskPreDetailApi(props.currentId);
|
||||
if(!error){
|
||||
riskRecords.value = data?.rows || [];
|
||||
selectedWorkers.value = data?.users || [];
|
||||
}
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getWorkers();
|
||||
getDetail();
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NSpin :show="loading" size="small">
|
||||
<div class="space-y-3">
|
||||
<div
|
||||
class="flex flex-wrap items-center gap-2 rounded-lg border border-[#ACC6E5] bg-[#EAF0F9] px-3 py-2"
|
||||
:style="{
|
||||
'--theme-color': themeStore.themeColor
|
||||
}"
|
||||
>
|
||||
<NButton size="small" ghost type="primary" class="text-xs" @click="emit('close')">
|
||||
<Icon icon="basil:arrow-left-outline" class="size-18px" />
|
||||
返回工具列表
|
||||
</NButton>
|
||||
<NButton size="small" ghost type="primary" class="text-xs" @click="save()">保存</NButton>
|
||||
<span class="text-sm font-bold text-[var(--theme-color)]">风险预分析插件</span>
|
||||
<NTag size="small" type="info">插件</NTag>
|
||||
<span class="text-[11px] text-slate-500">{{`共${riskRecords.length} 条风险项`}}</span>
|
||||
<div class="relative">
|
||||
<NButton size="small" ghost type="primary" class="text-[11px]" @click="openSelectWorker = !openSelectWorker">
|
||||
<Icon icon="lucide:users" class="size-12px" /> 分析组成员 · 已选 {{ selectedWorkers.length }} 人
|
||||
</NButton>
|
||||
<template v-if="openSelectWorker">
|
||||
<div class="fixed inset-0 z-10" @click="openSelectWorker = false"></div>
|
||||
<div class="absolute right-0 top-8 z-20 w-72 rounded-lg border bg-white p-2 shadow-xl">
|
||||
<div class="mb-1.5 flex items-center justify-between">
|
||||
<span class="text-xs font-semibold text-slate-700">选择分析组成员(岗位人员库)</span>
|
||||
<span class="text-[11px] text-slate-400">已选 {{ selectedWorkers.length }} 人</span>
|
||||
</div>
|
||||
<NInput v-model:value="searchWorker" size="small" placeholder="搜索人名…" class="mb-1.5 text-xs" />
|
||||
<div class="max-h-48 space-y-0.5 overflow-y-auto">
|
||||
<div v-for="x in workerList" :key="x.user_id" @click="selectWorker(x)"
|
||||
class="cursor-pointer flex w-full items-center min-h-34px gap-2 rounded-md px-2 py-1.5 text-left text-xs"
|
||||
:class="hasWorker(x.user_id) ? 'bg-[#DFE9F6]' : 'hover:bg-slate-50'">
|
||||
<span class="flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border text-[10px]"
|
||||
:class="hasWorker(x.user_id) ? 'border-[var(--theme-color)] bg-[var(--theme-color)] text-white' : 'border-slate-300'">{{ hasWorker(x.user_id) ? "✓" : "" }}</span>
|
||||
<span class="font-medium text-slate-800">{{ x.user_name }}</span>
|
||||
<span class="text-[11px] text-slate-400">{{ x.org_name }}</span>
|
||||
<NTag v-if="selectedWorkers[0]?.user_id === x.user_id" size="small" type="primary" class="ml-auto">组长</NTag>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-1.5 border-t pt-1.5 text-[11px] leading-4 text-slate-400">
|
||||
首位选择者默认为组长;成员为选择式(非手写),参与记录自动归属到人,用于「参与风险分析次数」统计采集。
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="ml-auto flex items-center gap-1.5">
|
||||
<NButton size="small" ghost type="primary" class="text-xs" :disabled="riskRecords.length === 0" @click="enterToTable('all',null)">
|
||||
<Icon icon="carbon:document-import" class="size-14px mr-1" /> 全部整理入表
|
||||
</NButton>
|
||||
<NButton size="small" ghost type="primary" class="text-xs" @click="generateReport">
|
||||
<Icon icon="material-symbols:download" class="size-14px" /> 导出 Word
|
||||
</NButton>
|
||||
<NButton v-if="isAiOpen" size="small" type="primary" class="text-xs" :disabled="loading" @click="runAi">
|
||||
<Icon v-if="loading" icon="ri:loader-4-fill" class="size-14px animate-spin" />
|
||||
<Icon v-else icon="lucide:sparkles" class="size-12px" />
|
||||
AI 执行风险分析
|
||||
</NButton>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-3" :style="{'--theme-color': themeStore.themeColor}">
|
||||
<!-- 作业活动分析记录 -->
|
||||
<div class="bg-white">
|
||||
<div class="flex items-center gap-2 px-3 py-2 text-xs font-semibold text-slate-600 border border-b-0 rounded-tl-lg rounded-tr-lg">
|
||||
风险分析记录表
|
||||
<NButton size="small" ghost type="primary" class="text-xs ml-2" @click="addRisk">
|
||||
<Icon icon="ic:round-plus" class="size-14px" /> 新增风险分析记录
|
||||
</NButton>
|
||||
<span class="ml-auto text-[11px] font-normal text-slate-400">「入表」将本条选入风险分析记录表</span>
|
||||
</div>
|
||||
<p v-if="riskRecords.length===0" class="border py-5 text-center text-xs text-slate-400">暂无风险分析记录</p>
|
||||
<div v-else class="scroll">
|
||||
<table class="w-full">
|
||||
<thead>
|
||||
<tr>
|
||||
<th :class="TH" class="w-80px">操作</th>
|
||||
<th :class="TH" class="w-30">风险项</th>
|
||||
<th :class="TH" class="w-60">场景描述</th>
|
||||
<th :class="TH" class="w-20">固有风险</th>
|
||||
<th :class="TH" class="w-50">现有措施</th>
|
||||
<th :class="TH" class="w-60">建议措施</th>
|
||||
<th :class="TH" class="w-20">剩余风险</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(row, rowIndex) in riskRecords" :key="rowIndex">
|
||||
<td :class="TD">
|
||||
<div class="flex items-center justify-center gap-2 px-1 mt-2">
|
||||
<NButton text type="primary" size="tiny" @click="enterToTable('single',row)">
|
||||
入表
|
||||
</NButton>
|
||||
<NPopconfirm
|
||||
positive-text="确定"
|
||||
:positiveButtonProps="{ size: 'tiny' }"
|
||||
:negativeButtonProps="{ size: 'tiny' }"
|
||||
@positive-click="delRow(Number(rowIndex))"
|
||||
>
|
||||
<template #trigger>
|
||||
<NButton text type="error" size="tiny" title="删除行">
|
||||
<Icon icon="ep:delete" class="size-14px" />
|
||||
</NButton>
|
||||
</template>
|
||||
确定删除此行吗?
|
||||
</NPopconfirm>
|
||||
</div>
|
||||
</td>
|
||||
<td :class="TD">
|
||||
<NInput type="textarea" size="small" v-model:value="row.risk_item" :autosize="{minRows:1}" />
|
||||
</td>
|
||||
<td :class="TD">
|
||||
<NInput type="textarea" size="small" v-model:value="row.scene_desc" :autosize="{minRows:1}" />
|
||||
</td>
|
||||
<td :class="TD" class="text-center">
|
||||
<NSelect v-model:value="row.risk_value" :options="risk_grades" size="small" class="w-full" />
|
||||
</td>
|
||||
<td :class="TD">
|
||||
<NInput type="textarea" size="small" v-model:value="row.safeguards" :autosize="{minRows:1}" />
|
||||
</td>
|
||||
<td :class="TD">
|
||||
<NInput type="textarea" size="small" v-model:value="row.suggestions" :autosize="{minRows:1}" />
|
||||
</td>
|
||||
<td :class="TD" class="text-center">
|
||||
<NSelect v-model:value="row.residual_risk_value" :options="risk_grades" size="small" class="w-full" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</NSpin>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.scroll{
|
||||
height: calc(100vh - 135px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user