FlowDesign.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <script setup name="FlowDesign">
  2. import { onMounted, ref, watch } from 'vue'
  3. import CodeMirrorEditor from '@/components/CodeMirrorEditor/index.vue'
  4. import ScWorkflow from '@/components/scWorkflow'
  5. import useFlowStore from '@/store/modules/flow'
  6. import useClipboard from 'vue-clipboard3'
  7. import { storeToRefs } from 'pinia'
  8. import { ElMessage } from 'element-plus'
  9. const flowStore = useFlowStore()
  10. const { modelContent } = storeToRefs(flowStore)
  11. const { toClipboard } = useClipboard()
  12. const formRef = ref()
  13. const drawer = ref(false)
  14. const jsonFormat = ref({})
  15. let form = ref({
  16. processConfig: {
  17. nodeName: '发起人',
  18. type: 0,
  19. nodeAssigneeList: []
  20. }
  21. })
  22. // 接口保存审批流程
  23. const saveDesign = json => {
  24. modelContent.value = JSON.stringify(form.value.processConfig)
  25. }
  26. const updateCompInfo = () => {
  27. if (modelContent.value) {
  28. const _val = JSON.parse(modelContent.value)
  29. form.value = Object.assign({ processConfig: _val }, {})
  30. }
  31. }
  32. // const copyParseJson = async () => {
  33. // await toClipboard(JSON.stringify(jsonFormat.value, null, ' '))
  34. // }
  35. const copyJson = async () => {
  36. if (!jsonFormat.value) {
  37. return ElMessage.warning('当前没有数据噢')
  38. }
  39. const json = JSON.parse(jsonFormat.value || {})
  40. try {
  41. await toClipboard(JSON.stringify(json))
  42. ElMessage.success('复制成功')
  43. } catch (e) {
  44. ElMessage.warning('复制失败')
  45. }
  46. }
  47. const validate = () => {
  48. // 保存表单设计
  49. saveDesign()
  50. // 根据后续的业务需求 调整 validate 的功能
  51. return new Promise((resolve, reject) => {
  52. resolve()
  53. })
  54. }
  55. const openDrawerEv = () => {
  56. jsonFormat.value = JSON.stringify(form.value.processConfig, null, ' ')
  57. drawer.value = !drawer.value
  58. }
  59. const sureImportJson = () => {
  60. form.value.processConfig = JSON.parse(jsonFormat.value || {})
  61. drawer.value = !drawer.value
  62. }
  63. onMounted(() => {
  64. updateCompInfo()
  65. })
  66. defineExpose({
  67. formRef,
  68. saveDesign,
  69. validate,
  70. updateCompInfo
  71. })
  72. </script>
  73. <template>
  74. <div>
  75. <div style="z-index: 999" class="fixed top-44 right-48">
  76. <el-button type="primary" @click="openDrawerEv"> 查看/导入 JSON </el-button>
  77. </div>
  78. <ScWorkflow v-model="form.processConfig"></ScWorkflow>
  79. <el-dialog v-if="drawer" v-model="drawer" class="le-dialog" size="600px" :append-to-body="true" title="查看JSON" destroy-on-close>
  80. <code-mirror-editor v-model="jsonFormat"></code-mirror-editor>
  81. <template #footer>
  82. <el-button type="primary" @click="copyJson">复制 JSON</el-button>
  83. <el-popconfirm title="确定应用JSON模型吗?" @confirm="sureImportJson">
  84. <template #reference>
  85. <el-button>导入JSON</el-button>
  86. </template>
  87. </el-popconfirm>
  88. </template>
  89. </el-dialog>
  90. </div>
  91. </template>
  92. <style lang="scss"></style>