index.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <RatingStar
  3. v-if="ratingTemplate.type === RATING_TEMPLATE_TYPE.STAR"
  4. :ratingTemplate="ratingTemplate"
  5. @sendMessage="sendCustomMessage"
  6. />
  7. <RatingNumber
  8. v-else
  9. :ratingTemplate="ratingTemplate"
  10. @sendMessage="sendCustomMessage"
  11. />
  12. </template>
  13. <script lang="ts">
  14. import vue from '../../adapter-vue';
  15. import { JSONToObject } from '../../utils/index';
  16. import { RATING_TEMPLATE_TYPE } from '../../constant';
  17. import RatingStar from './message-rating-star.vue';
  18. import RatingNumber from './message-rating-number.vue';
  19. import { IMessageModel } from '../../interface';
  20. const { computed } = vue;
  21. interface Props {
  22. message: IMessageModel;
  23. }
  24. export default {
  25. components: {
  26. RatingStar,
  27. RatingNumber,
  28. },
  29. props: {
  30. message: {
  31. type: Object as () => IMessageModel,
  32. default: () => ({}),
  33. },
  34. },
  35. emits: ['sendMessage'],
  36. setup(props: Props, { emit }) {
  37. const ratingTemplate = computed(() => {
  38. const data = props.message && JSONToObject(props.message.payload.data);
  39. return data?.menuContent;
  40. });
  41. const sendCustomMessage = (data: any) => {
  42. emit('sendMessage', data);
  43. };
  44. return {
  45. sendCustomMessage,
  46. ratingTemplate,
  47. RATING_TEMPLATE_TYPE,
  48. };
  49. },
  50. };
  51. </script>