index.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div
  3. v-if="content.type === 1"
  4. class="message-form"
  5. >
  6. <FormBranch
  7. :title="content.header"
  8. :list="content.items"
  9. @input-click="handleContentListItemClick"
  10. />
  11. </div>
  12. <div
  13. v-else
  14. class="message-form"
  15. >
  16. <FormInput
  17. :title="content.header"
  18. @input-submit="handleFormSaveInputSubmit"
  19. />
  20. </div>
  21. </template>
  22. <script lang="ts">
  23. import vue from '../../adapter-vue';
  24. import FormBranch from './form-branch.vue';
  25. import FormInput from './form-input.vue';
  26. const { computed } = vue;
  27. interface branchItem {
  28. content: string;
  29. desc: string;
  30. }
  31. interface Props {
  32. payload: any;
  33. }
  34. export default {
  35. components: {
  36. FormBranch,
  37. FormInput,
  38. },
  39. props: {
  40. payload: {
  41. type: Object,
  42. default: () => ({}),
  43. },
  44. },
  45. emits: ['sendMessage'],
  46. setup(props: Props, { emit }) {
  47. const content = computed(() => {
  48. return props.payload?.content || {
  49. type: 0,
  50. header: '',
  51. items: [],
  52. };
  53. });
  54. const handleContentListItemClick = (branch: branchItem) => {
  55. emit('sendMessage', { text: branch.content });
  56. };
  57. const handleFormSaveInputSubmit = (text: string) => {
  58. emit('sendMessage', { text });
  59. };
  60. return {
  61. content,
  62. handleContentListItemClick,
  63. handleFormSaveInputSubmit,
  64. };
  65. },
  66. };
  67. </script>
  68. <style lang="scss">
  69. .message-form {
  70. max-width: 300px;
  71. }
  72. </style>