|
@@ -1,10 +1,17 @@
|
|
|
<template>
|
|
|
- <div class="flex flex-col rounded-xl bg-[#f2f4f7] px-3 py-2 shadow">
|
|
|
+ <div
|
|
|
+ class="flex size-full flex-col overflow-hidden rounded-xl bg-[#f2f4f7] px-3 py-2 shadow"
|
|
|
+ >
|
|
|
<div
|
|
|
class="flex items-center gap-2 py-1 text-xs font-semibold text-gray-700"
|
|
|
>
|
|
|
<div>回复</div>
|
|
|
- <div class="ml-auto">字数</div>
|
|
|
+ <div class="ml-auto">{{ state.textCount }}</div>
|
|
|
+ <varsPopover :node="node" @setVars="setVars">
|
|
|
+ <el-tooltip content="变量" placement="top">
|
|
|
+ <SvgIcon name="vars" color="#364153" size="16" />
|
|
|
+ </el-tooltip>
|
|
|
+ </varsPopover>
|
|
|
<el-tooltip content="复制" placement="top">
|
|
|
<SvgIcon
|
|
|
class="__hover"
|
|
@@ -15,46 +22,68 @@
|
|
|
/>
|
|
|
</el-tooltip>
|
|
|
</div>
|
|
|
- <div
|
|
|
- ref="ref_textarea"
|
|
|
- class="text-text-secondary flex-1 py-1 text-[13px] break-words whitespace-pre-wrap outline-none select-text"
|
|
|
- contenteditable="true"
|
|
|
- @input="updateMarkdown"
|
|
|
- ></div>
|
|
|
+ <div class="text-text-secondary flex-1 overflow-y-auto py-1 text-[13px]">
|
|
|
+ <div
|
|
|
+ class="break-all"
|
|
|
+ style="line-height: 1.5"
|
|
|
+ ref="ref_textarea"
|
|
|
+ contenteditable="true"
|
|
|
+ @input="updateMarkdown"
|
|
|
+ ></div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, computed, onMounted, reactive } from 'vue'
|
|
|
+import {
|
|
|
+ ref,
|
|
|
+ computed,
|
|
|
+ onMounted,
|
|
|
+ reactive,
|
|
|
+ h,
|
|
|
+ render,
|
|
|
+ createApp,
|
|
|
+ watch,
|
|
|
+} from 'vue'
|
|
|
import { copy } from '@/utils/czr-util'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
import SvgIcon from '@/components/SvgIcon/index.vue'
|
|
|
+import varsPopover from '@/views/workflow/instance/component/vars/vars-popover.vue'
|
|
|
+import paramValue from './param-value.vue'
|
|
|
+import { useWorkflowStore } from '@/stores'
|
|
|
|
|
|
+const WorkflowStore = useWorkflowStore()
|
|
|
const emit = defineEmits(['update:modelValue'])
|
|
|
const props = defineProps({
|
|
|
modelValue: {
|
|
|
type: String,
|
|
|
default: '',
|
|
|
},
|
|
|
+ node: {},
|
|
|
})
|
|
|
const state = reactive({
|
|
|
- optionsMap: new Map([
|
|
|
- ['123', { label: '变量1', id: '123', type: 'String' }],
|
|
|
- ['223', { label: '变量变量变量变量变量2', id: '223', type: 'String' }],
|
|
|
- [
|
|
|
- '333',
|
|
|
- {
|
|
|
- label: '变量变量变量变量变量变量变量变量变量变量变量3',
|
|
|
- id: '333',
|
|
|
- type: 'Number',
|
|
|
- },
|
|
|
- ],
|
|
|
- ]),
|
|
|
+ textCount: 0,
|
|
|
+ optionsMap: new Map(),
|
|
|
})
|
|
|
const ref_textarea = ref()
|
|
|
+watch(
|
|
|
+ () => props.node,
|
|
|
+ (n) => {
|
|
|
+ if (n) {
|
|
|
+ const all = WorkflowStore.getInVars(n)
|
|
|
+ const map = new Map()
|
|
|
+ all.forEach((p) => {
|
|
|
+ p.options.forEach((v) => {
|
|
|
+ map.set(v.nodeId, v)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ state.optionsMap = map
|
|
|
+ }
|
|
|
+ },
|
|
|
+ { immediate: true },
|
|
|
+)
|
|
|
const updateMarkdown = (e) => {
|
|
|
const selection: any = window.getSelection()
|
|
|
- const range = selection.rangeCount > 0 ? selection.getRangeAt(0) : null
|
|
|
let lastReplacedSpan: any = null
|
|
|
|
|
|
const regex = /\{\{#([^#]+)#\}\}/g
|
|
@@ -76,13 +105,17 @@ const updateMarkdown = (e) => {
|
|
|
document.createTextNode(text.substring(lastIndex, match.index)),
|
|
|
)
|
|
|
}
|
|
|
- const span = document.createElement('span')
|
|
|
- span.setAttribute('contenteditable', 'false')
|
|
|
- span.className = 'border-1 bg-red-400'
|
|
|
const key = match[1]
|
|
|
- span.textContent = state.optionsMap.get(key)?.label || ''
|
|
|
- fragment.appendChild(span)
|
|
|
- lastReplacedSpan = span
|
|
|
+ const varsValue = document.createElement('div')
|
|
|
+ varsValue.setAttribute('contenteditable', 'false')
|
|
|
+ varsValue.style.display = 'inline-block'
|
|
|
+ const app = createApp(paramValue, {
|
|
|
+ vars: state.optionsMap.get(key),
|
|
|
+ })
|
|
|
+ app.component('SvgIcon', SvgIcon)
|
|
|
+ app.mount(varsValue)
|
|
|
+ fragment.appendChild(varsValue)
|
|
|
+ lastReplacedSpan = varsValue
|
|
|
lastIndex = regex.lastIndex
|
|
|
}
|
|
|
|
|
@@ -102,11 +135,15 @@ const updateMarkdown = (e) => {
|
|
|
newSelection.removeAllRanges()
|
|
|
newSelection.addRange(newRange)
|
|
|
}
|
|
|
+ state.textCount = e.target.innerText?.length || 0
|
|
|
}
|
|
|
const onCopy = (text) => {
|
|
|
copy(text)
|
|
|
ElMessage.success('复制成功!')
|
|
|
}
|
|
|
+const setVars = (vars) => {
|
|
|
+ console.log(vars)
|
|
|
+}
|
|
|
onMounted(() => {})
|
|
|
</script>
|
|
|
|