mailDetail.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div v-loading="loading" class="box">
  3. <div style="margin-bottom: 10px">
  4. <el-button type="primary" @click="handleReply('10')">回 复</el-button>
  5. <el-button type="warning" @click="handleReply('20')">转 发</el-button>
  6. </div>
  7. <div class="top">
  8. <div class="top-row">
  9. <div class="label">发 件 人:</div>
  10. <div class="value">
  11. <span
  12. v-for="item in replyTo"
  13. :key="item.id"
  14. style="margin-right: 10px"
  15. >
  16. {{ item.email || item.personalName }}</span
  17. >
  18. </div>
  19. </div>
  20. <div class="top-row">
  21. <div class="label">收 件 人:</div>
  22. <div class="value">
  23. <span v-for="item in to" :key="item.id" style="margin-right: 10px">{{
  24. item.email || item.personalName
  25. }}</span>
  26. </div>
  27. </div>
  28. <div class="top-row" v-if="cc && cc.length > 0">
  29. <div class="label">抄 送 人:</div>
  30. <div class="value">
  31. <span v-for="item in cc" :key="item.id" style="margin-right: 10px">
  32. {{ item.email || item.personalName }}</span
  33. >
  34. </div>
  35. </div>
  36. <div class="top-row" v-if="bcc && bcc.length > 0">
  37. <div class="label">密 送 人:</div>
  38. <div class="value">
  39. <span v-for="item in bcc" :key="item.id" style="margin-right: 10px">
  40. {{ item.email || item.personalName }}</span
  41. >
  42. </div>
  43. </div>
  44. <div class="top-row">
  45. <div class="label">时 间:</div>
  46. <div class="value">
  47. {{ time }}
  48. </div>
  49. </div>
  50. <div class="top-row" v-if="fileList && fileList.length > 0">
  51. <div class="label">附 件:</div>
  52. <div class="value">
  53. <div
  54. v-for="(item, index) in fileList"
  55. style="margin-right: 20px; display: flex; align-items: center"
  56. :key="index"
  57. >
  58. <span style="cursor: pointer" @click="handleClickFile(item)">{{
  59. item.name
  60. }}</span>
  61. <span
  62. style="margin-left: 8px; cursor: pointer"
  63. @click="handleClickDownload(item)"
  64. ><el-icon color="#0084FF"><Download /></el-icon
  65. ></span>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. <div class="body">
  71. <iframe
  72. frameborder="0"
  73. allowTransparency="true"
  74. style="
  75. width: 99% !important;
  76. overflow-x: scroll;
  77. padding-top: 10px;
  78. height: 500px;
  79. "
  80. :srcdoc="showBodyText(detailsData.data.content)"
  81. :ref="'iframeText_' + mailStore.currentId"
  82. :id="'iframeText_' + mailStore.currentId"
  83. >
  84. </iframe>
  85. </div>
  86. </div>
  87. </template>
  88. <script setup>
  89. import byTable from "@/components/byTable/index";
  90. import useMailStore from "@/store/modules/mail";
  91. const { proxy } = getCurrentInstance();
  92. const mailStore = useMailStore();
  93. let loading = ref(false);
  94. const detailsData = reactive({
  95. data: {},
  96. });
  97. const to = ref([]);
  98. const cc = ref([]);
  99. const bcc = ref([]);
  100. const replyTo = ref([]);
  101. const fileList = ref([]);
  102. const requestData = ref({});
  103. const time = ref("");
  104. const getDetails = () => {
  105. loading.value = true;
  106. proxy
  107. .post("/mailService/getMessageDetail", {
  108. type: mailStore.currentMenu.type,
  109. messageId: mailStore.currentMenu.messageId,
  110. })
  111. .then((res) => {
  112. if (mailStore.currentMenu.time) {
  113. time.value = mailStore.currentMenu.time;
  114. }
  115. detailsData.data = res;
  116. to.value = res.messageAddressList.filter((x) => x.type === 1);
  117. cc.value = res.messageAddressList.filter((x) => x.type === 2);
  118. bcc.value = res.messageAddressList.filter((x) => x.type === 3);
  119. replyTo.value = res.messageAddressList.filter((x) => x.type === 4);
  120. fileList.value = res.messageAttachmentList;
  121. loading.value = false;
  122. });
  123. };
  124. const showBodyText = (text) => {
  125. if (text) {
  126. let val = JSON.parse(JSON.stringify(text));
  127. val = val.replace("body {", "tbody {");
  128. val = val.replace(
  129. "td, p, li, th {",
  130. "tbody td, tbody p, tbody li, tbody th {"
  131. );
  132. val = val.replace(
  133. /<p>/g,
  134. '<p style="margin-block-start: 0; margin-block-end: 0;">'
  135. );
  136. return val;
  137. } else {
  138. return text;
  139. }
  140. };
  141. const init = () => {
  142. getDetails();
  143. };
  144. onMounted(() => {
  145. // init();
  146. });
  147. const handleReply = (pageType) => {
  148. // pageType 10为回复 20为转发 0为写信
  149. let title = "";
  150. if (pageType === "10") {
  151. title = "回复";
  152. } else if (pageType === "20") {
  153. title = "转发";
  154. }
  155. const menu = {
  156. title: title,
  157. type: mailStore.currentMenu.type,
  158. id: "write",
  159. pageType: pageType,
  160. details: {
  161. ...detailsData.data,
  162. ...mailStore.currentMenu.row,
  163. },
  164. };
  165. const index = mailStore.mailMenuList.findIndex((x) => x.id === menu.id);
  166. if (index >= 0) {
  167. mailStore.mailMenuList[index] = menu;
  168. } else {
  169. mailStore.mailMenuList.push(menu);
  170. }
  171. mailStore.currentMenu = menu;
  172. mailStore.currentId = menu.id;
  173. };
  174. const handleClickFile = (file) => {
  175. const path = file.path ? file.path : file.url ? file.url : "";
  176. if (path) {
  177. window.open(path, "_blank");
  178. }
  179. };
  180. const handleClickDownload = (file) => {
  181. let xhr = new XMLHttpRequest();
  182. //域名是华为云的
  183. xhr.open("GET", `${file.url}`, true);
  184. xhr.responseType = "blob";
  185. xhr.send();
  186. xhr.onreadystatechange = function () {
  187. if (xhr.readyState === 4 && xhr.status === 200) {
  188. let url = window.URL.createObjectURL(xhr.response);
  189. const a = document.createElement("a");
  190. a.href = url;
  191. a.download = file.fileName; // 下载后文件名
  192. a.style.display = "none";
  193. document.body.appendChild(a);
  194. a.click(); // 点击下载
  195. window.URL.revokeObjectURL(a.href);
  196. document.body.removeChild(a); // 下载完成移除元素
  197. }
  198. };
  199. };
  200. defineExpose({
  201. initFn: init,
  202. });
  203. </script>
  204. <style lang="scss" scoped>
  205. .box {
  206. padding: 0 10px;
  207. font-size: 12px;
  208. .top {
  209. padding: 10px;
  210. background: #f1f1f1;
  211. .top-row {
  212. display: flex;
  213. margin-bottom: 10px;
  214. .label {
  215. min-width: 60px;
  216. color: #999999;
  217. text-align: right;
  218. }
  219. .value {
  220. flex: 1;
  221. color: #333333;
  222. font-weight: 700;
  223. margin-right: 10px;
  224. display: flex;
  225. }
  226. }
  227. }
  228. }
  229. </style>