Ben Lin
2024-03-24 b72cc34ab2fef7d6bcaca3e2b11231713d622fce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!--
 * @Description: 拖拽节点控件
-->
<template>
  <div
    class="drag-move-box"
    @click.stop="handleSelectItem"
    :class="{ active: schema.key === formConfig.currentItem?.key }"
  >
    <div class="form-item-box">
      <VFormItem :formConfig="formConfig" :schema="schema" />
    </div>
    <div class="show-key-box">
      {{ schema.label + (schema.field ? '/' + schema.field : '') }}
    </div>
    <FormNodeOperate :schema="schema" :currentItem="formConfig.currentItem" />
  </div>
</template>
<script lang="ts">
  import { defineComponent, reactive, toRefs, PropType } from 'vue';
  import { IVFormComponent } from '../../../typings/v-form-component';
  import FormNodeOperate from './FormNodeOperate.vue';
  import { useFormDesignState } from '../../../hooks/useFormDesignState';
  import VFormItem from '../../VFormItem/index.vue';
  // import VFormItem from '../../VFormItem/vFormItem.vue';
  export default defineComponent({
    name: 'FormNode',
    components: {
      VFormItem,
      FormNodeOperate,
    },
    props: {
      schema: {
        type: Object as PropType<IVFormComponent>,
        required: true,
      },
    },
    setup(props) {
      const { formConfig, formDesignMethods } = useFormDesignState();
      const state = reactive({});
      // 获取 formDesignMethods
      const handleSelectItem = () => {
        // 调用 formDesignMethods
        formDesignMethods.handleSetSelectItem(props.schema);
      };
      return {
        ...toRefs(state),
        handleSelectItem,
        formConfig,
      };
    },
  });
</script>