index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <view>
  3. <u-popup round="16" :show="show" @close="close" @open="open">
  4. <view class="message_more_func_container">
  5. <!-- 复制 -->
  6. <view
  7. v-if="msgBody.type === MESSAGE_TYPE.TEXT"
  8. class="message_more_func_item u-border-bottom"
  9. @click="copyTextMessage"
  10. >
  11. <u-icon
  12. class="message_more_func_item_content_icon"
  13. size="24"
  14. name="/static/images/new_ui/message/messagPopup/copy_msg_icon.png"
  15. ></u-icon>
  16. <text class="message_more_func_item_title">复制</text>
  17. </view>
  18. <!-- 回复 -->
  19. <view
  20. class="message_more_func_item u-border-bottom"
  21. @click="replyMessage"
  22. >
  23. <u-icon
  24. class="message_more_func_item_content_icon"
  25. size="24"
  26. name="/static/images/new_ui/message/messagPopup/reply_msg_icon.png"
  27. ></u-icon>
  28. <text class="message_more_func_item_title">回复</text>
  29. </view>
  30. <!-- 编辑 -->
  31. <view
  32. v-if="isSelf && msgBody.type === MESSAGE_TYPE.TEXT"
  33. class="message_more_func_item u-border-bottom"
  34. @click="editMessage"
  35. >
  36. <u-icon
  37. class="message_more_func_item_content_icon"
  38. size="24"
  39. name="/static/images/new_ui/message/messagPopup/edit_msg_icon.png"
  40. ></u-icon>
  41. <text class="message_more_func_item_title">编辑</text>
  42. </view>
  43. <!-- 删除 -->
  44. <view
  45. class="message_more_func_item u-border-bottom"
  46. @click="alertSencondConfirmModal"
  47. >
  48. <u-icon
  49. class="message_more_func_item_content_icon"
  50. size="24"
  51. name="/static/images/new_ui/message/messagPopup/del_msg_icon.png"
  52. ></u-icon>
  53. <text class="message_more_func_item_title">删除</text>
  54. </view>
  55. <!-- 撤回 -->
  56. <view
  57. v-if="isSelf"
  58. class="message_more_func_item u-border-bottom"
  59. @click="recallMessage"
  60. >
  61. <u-icon
  62. class="message_more_func_item_content_icon"
  63. size="24"
  64. name="/static/images/new_ui/message/messagPopup/recall_msg_icon.png"
  65. ></u-icon>
  66. <text class="message_more_func_item_title">撤回</text>
  67. </view>
  68. </view>
  69. </u-popup>
  70. <u-modal
  71. :show="isShowSencondConfirmModal"
  72. :zoom="true"
  73. title="确认删除这条消息?"
  74. content="删除后,对方依旧可以看到这条消息。"
  75. confirm-text="确认"
  76. cancel-text="取消"
  77. show-cancel-button
  78. @confirm="deleteLocalMessage"
  79. @cancel="isShowSencondConfirmModal = false"
  80. >
  81. </u-modal>
  82. </view>
  83. </template>
  84. <script>
  85. import { EMClient } from '@/EaseIM';
  86. import { getEMKey } from '@/EaseIM/utils';
  87. import { emAboutAck } from '@/EaseIM/emApis';
  88. import { MESSAGE_TYPE, MESSAGE_STATUS } from '@/EaseIM/constant';
  89. const { sendRecallAckMsg } = emAboutAck();
  90. export default {
  91. data() {
  92. return {
  93. MESSAGE_TYPE,
  94. show: false,
  95. isShowSencondConfirmModal: false,
  96. msgBody: {},
  97. };
  98. },
  99. computed: {
  100. isSelf() {
  101. const { from } = this.msgBody;
  102. return (
  103. from === this.$store.state.LoginStore.loginUserBaseInfos.loginUserId
  104. );
  105. },
  106. },
  107. methods: {
  108. open() {
  109. // console.log('open');
  110. },
  111. close() {
  112. this.show = false;
  113. },
  114. alertMessagePopup(msgBody) {
  115. this.msgBody = Object.assign({}, msgBody);
  116. this.show = true;
  117. },
  118. //复制文本消息至剪切板
  119. copyTextMessage() {
  120. uni.setClipboardData({
  121. data: this.msgBody.msg,
  122. success: (res) => {
  123. uni.showToast({
  124. title: '已复制',
  125. icon: 'none',
  126. });
  127. },
  128. fail: (e) => {
  129. console.log('文本复制失败', e);
  130. uni.showToast({
  131. title: '复制失败',
  132. icon: 'none',
  133. });
  134. },
  135. complete: () => {
  136. this.show = false;
  137. },
  138. });
  139. },
  140. //回复消息
  141. replyMessage() {
  142. this.$emit('callReplyMessage');
  143. this.show = false;
  144. },
  145. //编辑消息
  146. editMessage() {
  147. this.$emit('callEditMessage');
  148. this.show = false;
  149. },
  150. //弹出二次确认模态框【删除消息】
  151. alertSencondConfirmModal() {
  152. this.isShowSencondConfirmModal = true;
  153. this.show = false;
  154. },
  155. //删除本地消息
  156. deleteLocalMessage() {
  157. const key = getEMKey(
  158. EMClient.user,
  159. this.msgBody.from,
  160. this.msgBody.to,
  161. this.msgBody.chatType
  162. );
  163. const params = {
  164. key: key,
  165. mid: this.msgBody.id,
  166. };
  167. this.$store.commit('DELETE_MESSAGE_FROM_COLLECTION', params);
  168. uni.showToast({
  169. icon: 'none',
  170. title: '删除成功',
  171. });
  172. this.isShowSencondConfirmModal = false;
  173. },
  174. //撤回消息
  175. async recallMessage() {
  176. try {
  177. const params = {
  178. mid: this.msgBody.id,
  179. to: this.msgBody.to,
  180. chatType: this.msgBody.chatType,
  181. };
  182. await sendRecallAckMsg(params);
  183. uni.showToast({
  184. title: '撤回成功',
  185. icon: 'none',
  186. });
  187. //向消息状态集合缓存中更新该条消息的状态
  188. this.$store.commit('UPDATE_MESSAGE_COLLECTION_STATUS', {
  189. key: params.mid,
  190. status: MESSAGE_STATUS.RECALL,
  191. });
  192. } catch (error) {
  193. console.log('撤回失败', error);
  194. if (error?.type === 504) {
  195. uni.showToast({
  196. title: '已超过可撤回时间',
  197. icon: 'none',
  198. });
  199. return false;
  200. }
  201. uni.showToast({
  202. title: '撤回失败',
  203. icon: 'none',
  204. });
  205. } finally {
  206. this.show = false;
  207. }
  208. },
  209. },
  210. };
  211. </script>
  212. <style scoped>
  213. .message_more_func_container {
  214. width: 100%;
  215. padding: 20px 15px 20px 15px;
  216. }
  217. .message_more_func_item {
  218. display: flex;
  219. flex-direction: row;
  220. justify-content: flex-start;
  221. align-items: center;
  222. width: 100%;
  223. height: 56px;
  224. }
  225. .message_more_func_item_title {
  226. /* Enabled */
  227. width: 32px;
  228. height: 22px;
  229. /* 简体中文/文本/大 */
  230. font-family: 'PingFang SC';
  231. font-style: normal;
  232. font-weight: 400;
  233. font-size: 16px;
  234. line-height: 22px;
  235. /* identical to box height, or 138% */
  236. text-align: center;
  237. /* Neutral/1 */
  238. color: #171a1c;
  239. /* Inside auto layout */
  240. flex: none;
  241. order: 1;
  242. flex-grow: 0;
  243. }
  244. .modal_text_content {
  245. /* A message should be a short, complete sentence. */
  246. width: 308.28px;
  247. height: 18px;
  248. /* 简体中文/标签/中 */
  249. font-family: 'PingFang SC';
  250. font-style: normal;
  251. font-weight: 400;
  252. font-size: 14px;
  253. line-height: 18px;
  254. /* identical to box height, or 129% */
  255. text-align: center;
  256. /* Neutral/5 */
  257. color: #75828a;
  258. /* Inside auto layout */
  259. flex: none;
  260. order: 1;
  261. flex-grow: 0;
  262. }
  263. </style>