index.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <ToolbarItemContainer
  3. :iconFile="wordsIcon"
  4. title="常用语"
  5. :needBottomPopup="true"
  6. :iconWidth="isUniFrameWork ? '26px' : '20px'"
  7. :iconHeight="isUniFrameWork ? '26px' : '20px'"
  8. @onDialogShow="onDialogShow"
  9. @onDialogClose="onDialogClose"
  10. ref="container"
  11. >
  12. <div :class="['words', !isPC && 'words-h5']">
  13. <div :class="['words-header', !isPC && 'words-h5-header']">
  14. <span :class="['words-header-title', !isPC && 'words-h5-header-title']">
  15. {{ TUITranslateService.t("Words.常用语-快捷回复工具") }}
  16. </span>
  17. <span
  18. v-if="!isPC"
  19. :class="['words-header-close', !isPC && 'words-h5-header-close']"
  20. @click="closeDialog"
  21. >
  22. 关闭
  23. </span>
  24. </div>
  25. <ul :class="['words-list', !isPC && 'words-h5-list']">
  26. <li
  27. :class="['words-list-item', !isPC && 'words-h5-list-item']"
  28. v-for="(item, index) in wordsList"
  29. :key="index"
  30. @click="selectWord(item)"
  31. >
  32. {{ TUITranslateService.t(`Words.${item.value}`) }}
  33. </li>
  34. </ul>
  35. </div>
  36. </ToolbarItemContainer>
  37. </template>
  38. <script setup lang="ts">
  39. import {
  40. TUITranslateService,
  41. TUIStore,
  42. StoreName,
  43. IConversationModel,
  44. SendMessageParams,
  45. TUIChatService,
  46. } from "@tencentcloud/chat-uikit-engine";
  47. import { ref } from "../../../../adapter-vue";
  48. import ToolbarItemContainer from "../toolbar-item-container/index.vue";
  49. import wordsIcon from "../../../../assets/icon/words.svg";
  50. import { wordsList } from "../../utils/wordsList";
  51. import { isEnabledMessageReadReceiptGlobal } from "../../utils/utils";
  52. import { isPC, isUniFrameWork } from "../../../../utils/env";
  53. const emits = defineEmits(["onDialogPopupShowOrHide"]);
  54. const currentConversation = ref<IConversationModel>();
  55. const container = ref();
  56. TUIStore.watch(StoreName.CONV, {
  57. currentConversation: (conversation: IConversationModel) => {
  58. currentConversation.value = conversation;
  59. },
  60. });
  61. const selectWord = (item: any) => {
  62. const options = {
  63. to:
  64. currentConversation?.value?.groupProfile?.groupID ||
  65. currentConversation?.value?.userProfile?.userID,
  66. conversationType: currentConversation?.value?.type,
  67. payload: {
  68. text: TUITranslateService.t(`Words.${item.value}`),
  69. },
  70. needReadReceipt: isEnabledMessageReadReceiptGlobal(),
  71. } as SendMessageParams;
  72. TUIChatService.sendTextMessage(options);
  73. // 提交后关闭 dialog
  74. // close dialog after submit evaluate
  75. container?.value?.toggleDialogDisplay(false);
  76. };
  77. const closeDialog = () => {
  78. container?.value?.toggleDialogDisplay(false);
  79. };
  80. const onDialogShow = () => {
  81. emits("onDialogPopupShowOrHide", true);
  82. };
  83. const onDialogClose = () => {
  84. emits("onDialogPopupShowOrHide", false);
  85. };
  86. </script>
  87. <style scoped lang="scss" src="./style/index.scss"></style>