message-custom.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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-if="isCustom.businessID === constant.TC_GROUP_NOTICE">
  70. <div class="notice-message" @click="handleNotice">
  71. <div class="notice-title">
  72. <i class="iconNotice"></i>
  73. <span>群公告</span>
  74. </div>
  75. <div class="content">
  76. <div class="content-title">
  77. {{isCustom.msgTitle}}
  78. </div>
  79. <div class="content-text">{{isCustom.msgContent}}</div>
  80. </div>
  81. </div>
  82. </template>
  83. <template v-else>
  84. <span v-html="data.custom"></span>
  85. </template>
  86. </div>
  87. </template>
  88. <script lang="ts">
  89. import { defineComponent, watchEffect, reactive, toRefs } from 'vue';
  90. import { isUrl, JSONToObject } from '../utils/utils';
  91. import constant from '../../constant';
  92. import { useStore } from 'vuex';
  93. import { eventGlobal } from "@/helpers";
  94. import TUIMessage from "../../../components/messageTUI/index";
  95. import { imGroupNoticeDetail } from "../../../../api";
  96. export default defineComponent({
  97. props: {
  98. data: {
  99. type: Object,
  100. default: () => ({})
  101. }
  102. },
  103. setup(props: any, ctx: any) {
  104. const VuexStore =
  105. ((window as any)?.TUIKitTUICore?.isOfficial && useStore && useStore()) ||
  106. {};
  107. const data = reactive({
  108. data: {} as any,
  109. extension: {},
  110. isCustom: '',
  111. constant: constant
  112. });
  113. watchEffect(() => {
  114. data.data = props.data;
  115. const {
  116. message: { payload }
  117. } = props.data;
  118. data.isCustom = payload.data || ' ';
  119. data.isCustom = JSONToObject(payload.data);
  120. if (payload.data === constant.typeService) {
  121. data.extension = JSONToObject(payload.extension);
  122. }
  123. });
  124. const openLink = (url: any) => {
  125. window.open(url);
  126. };
  127. const handleCallMessageIcon = () => {
  128. const callType = JSON.parse(
  129. JSON.parse(data?.data?.message?.payload?.data)?.data
  130. )?.call_type;
  131. let className = '';
  132. switch (callType) {
  133. case 1:
  134. className = 'icon-call-voice';
  135. break;
  136. case 2:
  137. className = 'icon-call-video';
  138. break;
  139. default:
  140. break;
  141. }
  142. return className;
  143. };
  144. const handleCallAgain = async () => {
  145. const callType = JSON.parse(
  146. JSON.parse(props?.data?.message?.payload?.data)?.data
  147. )?.call_type;
  148. switch (data?.data?.message?.conversationType) {
  149. case (window as any).TUIKitTUICore.TIM.TYPES.CONV_C2C:
  150. // eslint-disable-next-line no-case-declarations, no-unsafe-optional-chaining
  151. const { flow, to, from } = data?.data?.message;
  152. if (to === from) break;
  153. try {
  154. await (window as any)?.TUIKitTUICore?.TUIServer?.TUICallKit?.call({
  155. userID: flow === 'out' ? to : from,
  156. type: callType
  157. });
  158. (window as any)?.TUIKitTUICore?.isOfficial &&
  159. VuexStore?.commit &&
  160. VuexStore?.commit('handleTask', 6);
  161. } catch (error) {
  162. console.warn(error);
  163. }
  164. break;
  165. case (window as any).TUIKitTUICore.TIM.TYPES.CONV_GROUP:
  166. break;
  167. default:
  168. break;
  169. }
  170. };
  171. const handleNotice = async () => {
  172. if(!data.isCustom?.msgId) return
  173. try {
  174. await imGroupNoticeDetail(data.isCustom?.msgId)
  175. eventGlobal.emit('handleNotice', data.isCustom?.msgId)
  176. } catch(e) {
  177. //
  178. TUIMessage({
  179. message: e.message,
  180. isH5: false,
  181. type: "error",
  182. });
  183. }
  184. }
  185. return {
  186. ...toRefs(data),
  187. isUrl,
  188. openLink,
  189. handleCallMessageIcon,
  190. handleNotice,
  191. handleCallAgain
  192. };
  193. }
  194. });
  195. </script>
  196. <style lang="scss" scoped>
  197. @import url('../../../styles/common.scss');
  198. @import url('../../../styles/icon.scss');
  199. a {
  200. color: #679ce1;
  201. }
  202. .custom {
  203. font-size: 14Px;
  204. h1 {
  205. font-size: 14Px;
  206. color: #000000;
  207. }
  208. h1,
  209. a,
  210. p {
  211. font-size: 14Px;
  212. }
  213. .evaluate {
  214. ul {
  215. display: flex;
  216. padding-top: 10Px;
  217. }
  218. }
  219. .order {
  220. display: flex;
  221. main {
  222. padding-left: 5Px;
  223. p {
  224. font-family: PingFangSC-Regular;
  225. width: 145Px;
  226. line-height: 17Px;
  227. font-size: 14Px;
  228. color: #999999;
  229. letter-spacing: 0;
  230. margin-bottom: 6Px;
  231. word-break: break-word;
  232. }
  233. span {
  234. font-family: PingFangSC-Regular;
  235. line-height: 25Px;
  236. color: #ff7201;
  237. }
  238. }
  239. img {
  240. width: 67Px;
  241. height: 67Px;
  242. }
  243. }
  244. .call {
  245. display: flex;
  246. flex-direction: row;
  247. align-items: center;
  248. &-C2C {
  249. cursor: pointer;
  250. }
  251. &-GROUP {
  252. cursor: default;
  253. }
  254. }
  255. .notice-message {
  256. max-width: 376px;
  257. cursor: pointer;
  258. .notice-title {
  259. display: flex;
  260. align-items: center;
  261. padding-bottom: 6px;
  262. span {
  263. font-weight: 600;
  264. font-size: 16px;
  265. color: #198CFE;
  266. line-height: 24px;
  267. }
  268. .iconNotice {
  269. width: 18px;
  270. height: 18px;
  271. display: inline-block;
  272. margin-right: 6px;
  273. }
  274. }
  275. .content {
  276. font-size: 16px;
  277. color: #131415;
  278. line-height: 24px;
  279. .content-title {
  280. font-weight: 600;
  281. }
  282. }
  283. }
  284. }
  285. </style>