message-custom.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div class="custom">
  3. <template v-if="isCustom === constant.typeService">
  4. <div>
  5. <h1>
  6. <label>{{ extension.title }}</label>
  7. <a
  8. v-if="extension.hyperlinks_text"
  9. :href="extension.hyperlinks_text.value"
  10. target="view_window"
  11. >
  12. {{ extension.hyperlinks_text.key }}
  13. </a>
  14. </h1>
  15. <ul v-if="extension.item && extension.item.length > 0">
  16. <li v-for="(item, index) in extension.item" :key="index">
  17. <a v-if="isUrl(item.value)" :href="item.value" target="view_window">
  18. {{ item.key }}
  19. </a>
  20. <p v-else>{{ item.key }}</p>
  21. </li>
  22. </ul>
  23. <article>{{ extension.description }}</article>
  24. </div>
  25. </template>
  26. <template v-else-if="isCustom.businessID === constant.typeEvaluate">
  27. <div class="evaluate">
  28. <h1>{{ $t('message.custom.对本次服务评价') }}</h1>
  29. <ul>
  30. <li
  31. class="evaluate-list-item"
  32. v-for="(item, index) in ~~isCustom.score"
  33. :key="index"
  34. >
  35. <i class="icon icon-star-light"></i>
  36. </li>
  37. </ul>
  38. <article>{{ isCustom.comment }}</article>
  39. </div>
  40. </template>
  41. <template v-else-if="isCustom.businessID === constant.typeOrder">
  42. <div class="order" @click="openLink(isCustom.link)">
  43. <img :src="isCustom.imageUrl" alt="" />
  44. <main>
  45. <h1>{{ isCustom.title }}</h1>
  46. <p>{{ isCustom.description }}</p>
  47. <span>{{ isCustom.price }}</span>
  48. </main>
  49. </div>
  50. </template>
  51. <template v-else-if="isCustom.businessID === constant.typeTextLink">
  52. <div class="textLink">
  53. <p>{{ isCustom.text }}</p>
  54. <a :href="isCustom.link" target="view_window">
  55. {{ $t('message.custom.查看详情>>') }}
  56. </a>
  57. </div>
  58. </template>
  59. <template v-else-if="isCustom.businessID === constant.TYPE_CALL_MESSAGE">
  60. <div
  61. class="call"
  62. @click="handleCallAgain"
  63. :class="`call-${data?.message?.conversationType}`"
  64. >
  65. <i class="icon" :class="handleCallMessageIcon()"></i>
  66. <span>{{ data.custom }}</span>
  67. </div>
  68. </template>
  69. <template v-else>
  70. <span v-html="data.custom"></span>
  71. </template>
  72. </div>
  73. </template>
  74. <script lang="ts">
  75. import { defineComponent, watchEffect, reactive, toRefs } from 'vue';
  76. import { isUrl, JSONToObject } from '../utils/utils';
  77. import constant from '../../constant';
  78. import { useStore } from 'vuex';
  79. export default defineComponent({
  80. props: {
  81. data: {
  82. type: Object,
  83. default: () => ({})
  84. }
  85. },
  86. setup(props: any, ctx: any) {
  87. const VuexStore =
  88. ((window as any)?.TUIKitTUICore?.isOfficial && useStore && useStore()) ||
  89. {};
  90. const data = reactive({
  91. data: {} as any,
  92. extension: {},
  93. isCustom: '',
  94. constant: constant
  95. });
  96. watchEffect(() => {
  97. data.data = props.data;
  98. const {
  99. message: { payload }
  100. } = props.data;
  101. data.isCustom = payload.data || ' ';
  102. data.isCustom = JSONToObject(payload.data);
  103. if (payload.data === constant.typeService) {
  104. data.extension = JSONToObject(payload.extension);
  105. }
  106. });
  107. const openLink = (url: any) => {
  108. window.open(url);
  109. };
  110. const handleCallMessageIcon = () => {
  111. const callType = JSON.parse(
  112. JSON.parse(data?.data?.message?.payload?.data)?.data
  113. )?.call_type;
  114. let className = '';
  115. switch (callType) {
  116. case 1:
  117. className = 'icon-call-voice';
  118. break;
  119. case 2:
  120. className = 'icon-call-video';
  121. break;
  122. default:
  123. break;
  124. }
  125. return className;
  126. };
  127. const handleCallAgain = async () => {
  128. const callType = JSON.parse(
  129. JSON.parse(props?.data?.message?.payload?.data)?.data
  130. )?.call_type;
  131. switch (data?.data?.message?.conversationType) {
  132. case (window as any).TUIKitTUICore.TIM.TYPES.CONV_C2C:
  133. // eslint-disable-next-line no-case-declarations, no-unsafe-optional-chaining
  134. const { flow, to, from } = data?.data?.message;
  135. if (to === from) break;
  136. try {
  137. await (window as any)?.TUIKitTUICore?.TUIServer?.TUICallKit?.call({
  138. userID: flow === 'out' ? to : from,
  139. type: callType
  140. });
  141. (window as any)?.TUIKitTUICore?.isOfficial &&
  142. VuexStore?.commit &&
  143. VuexStore?.commit('handleTask', 6);
  144. } catch (error) {
  145. console.warn(error);
  146. }
  147. break;
  148. case (window as any).TUIKitTUICore.TIM.TYPES.CONV_GROUP:
  149. break;
  150. default:
  151. break;
  152. }
  153. };
  154. return {
  155. ...toRefs(data),
  156. isUrl,
  157. openLink,
  158. handleCallMessageIcon,
  159. handleCallAgain
  160. };
  161. }
  162. });
  163. </script>
  164. <style lang="scss" scoped>
  165. @import url('../../../styles/common.scss');
  166. @import url('../../../styles/icon.scss');
  167. a {
  168. color: #679ce1;
  169. }
  170. .custom {
  171. font-size: 14Px;
  172. h1 {
  173. font-size: 14Px;
  174. color: #000000;
  175. }
  176. h1,
  177. a,
  178. p {
  179. font-size: 14Px;
  180. }
  181. .evaluate {
  182. ul {
  183. display: flex;
  184. padding-top: 10Px;
  185. }
  186. }
  187. .order {
  188. display: flex;
  189. main {
  190. padding-left: 5Px;
  191. p {
  192. font-family: PingFangSC-Regular;
  193. width: 145Px;
  194. line-height: 17Px;
  195. font-size: 14Px;
  196. color: #999999;
  197. letter-spacing: 0;
  198. margin-bottom: 6Px;
  199. word-break: break-word;
  200. }
  201. span {
  202. font-family: PingFangSC-Regular;
  203. line-height: 25Px;
  204. color: #ff7201;
  205. }
  206. }
  207. img {
  208. width: 67Px;
  209. height: 67Px;
  210. }
  211. }
  212. .call {
  213. display: flex;
  214. flex-direction: row;
  215. align-items: center;
  216. &-C2C {
  217. cursor: pointer;
  218. }
  219. &-GROUP {
  220. cursor: default;
  221. }
  222. }
  223. }
  224. </style>