code-mirror-dialog.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <div class="code-mirror-item">
  3. <el-alert :closable="false" @click="visible = true">
  4. 编辑{{ fnName }}函数
  5. </el-alert>
  6. <cip-code-mirror
  7. readonly="nocursor"
  8. type="javascript"
  9. theme="default"
  10. :model-value="getCompleteFun(itemConfig[fieldKey])"
  11. @click="visible = true"></cip-code-mirror>
  12. <cip-dialog v-model="visible" title="函数编辑" :show-only="true">
  13. <el-alert :closable="false">
  14. function {{ fnName }}{{ paramsStr }} {
  15. </el-alert>
  16. <cip-code-mirror
  17. type="javascript"
  18. theme="default"
  19. :model-value="itemConfig[fieldKey]"
  20. @update:model-value="updateModel"></cip-code-mirror>
  21. <el-alert :closable="false">}</el-alert>
  22. </cip-dialog>
  23. </div>
  24. </template>
  25. <script>
  26. import { defineComponent, ref, computed } from 'vue'
  27. import CipCodeMirror from '@cip/components/cip-code-mirror/index.vue'
  28. import CipDialog from '@cip/components/cip-dialog'
  29. import { ElAlert } from 'element-plus'
  30. export default defineComponent({
  31. components: { CipCodeMirror, CipDialog, ElAlert },
  32. props: {
  33. fnName: {},
  34. updateModel: {},
  35. itemConfig: {},
  36. fieldKey: {}
  37. },
  38. setup(props) {
  39. const visible = ref(false)
  40. const paramsStr = computed(() => {
  41. const paramsStrMap = {
  42. changeConfig: '(config, dependOnValues, outDependOnValues)',
  43. changeValue: '(dependOnValues, outDependOnValues)'
  44. }
  45. return paramsStrMap[props.fnName] ?? ''
  46. })
  47. const getCompleteFun = (funcBody) => {
  48. return `function ${props.fnName}${paramsStr.value} {
  49. ${funcBody ?? ''}
  50. }`
  51. }
  52. return {
  53. visible,
  54. getCompleteFun,
  55. paramsStr
  56. }
  57. }
  58. })
  59. </script>
  60. <style lang="less">
  61. .code-mirror-item {
  62. display: flex;
  63. flex-direction: column;
  64. flex: 1;
  65. overflow: auto;
  66. }
  67. .CodeMirror-hints {
  68. z-index: 99999;
  69. }
  70. </style>