left.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. <template>
  2. <div class="left">
  3. <div class="top">
  4. <el-dropdown>
  5. <span class="mail">
  6. {{ selectMail.mailUser }}
  7. <el-icon class="el-icon--right">
  8. <arrow-down />
  9. </el-icon>
  10. </span>
  11. <template #dropdown>
  12. <el-dropdown-menu>
  13. <el-dropdown-item
  14. v-for="item in mailList"
  15. :key="item.id"
  16. @click="handleClickMail(item)"
  17. >{{ item.mailUser }}</el-dropdown-item
  18. >
  19. </el-dropdown-menu>
  20. </template>
  21. </el-dropdown>
  22. <el-tabs v-model="activeName" class="demo-tabs" stretch>
  23. <el-tab-pane label="邮箱" name="first">
  24. <template #label>
  25. <span>邮箱</span>
  26. </template>
  27. </el-tab-pane>
  28. <el-tab-pane label="联系人" name="second">
  29. <template #label>
  30. <span>联系人</span>
  31. </template>
  32. </el-tab-pane>
  33. <el-tab-pane label="客户" name="third">
  34. <template #label>
  35. <span>客户</span>
  36. </template>
  37. </el-tab-pane>
  38. </el-tabs>
  39. <div>
  40. <el-button type="primary" style="width: 100%" @click="handleGoWrite()"
  41. >写信</el-button
  42. >
  43. </div>
  44. </div>
  45. <div class="body">
  46. <div v-if="activeName === 'first'">
  47. <ul class="mail-menu">
  48. <li
  49. class="menu-item"
  50. v-bind:class="{ 'select-menu': item.id === selectFloderId }"
  51. v-for="item in selectMail.mailFolderInfoList"
  52. :key="item.id"
  53. @click="handleOpenMenu(item, '10')"
  54. >
  55. {{ item.name }}
  56. </li>
  57. <!-- <li class="menu-item" @click="handleOpenMenu()">
  58. <i class="iconfont icon-iconm_inbox leftIcon"></i>
  59. <span style="margin-left: 10px">收件箱</span>
  60. </li>
  61. <li class="menu-item" @click="handleOpenMenu()">
  62. <i class="iconfont icon_unread leftIcon"></i>
  63. <span style="margin-left: 10px">未读邮件</span>
  64. </li>
  65. <li class="menu-item" @click="handleOpenMenu()">
  66. <i class="iconfont icon-icomm_draftbox leftIcon"></i>
  67. <span style="margin-left: 10px">草稿箱</span>
  68. </li>
  69. <li class="menu-item" @click="handleOpenMenu()">
  70. <i class="iconfont icon_sent leftIcon"></i>
  71. <span style="margin-left: 10px">已发送</span>
  72. </li>
  73. <li class="menu-item" @click="handleOpenMenu()">
  74. <i class="iconfont icon_delete leftIcon"></i>
  75. <span style="margin-left: 10px">已删除</span>
  76. </li>
  77. <li class="menu-item" @click="handleOpenMenu()">
  78. <i class="iconfont icon_ljyx leftIcon"></i>
  79. <span style="margin-left: 10px">垃圾邮件</span>
  80. </li> -->
  81. </ul>
  82. <div
  83. class="tree"
  84. v-if="staffMailData[0] && staffMailData[0].children.length > 0"
  85. >
  86. <el-tree
  87. :data="staffMailData"
  88. ref="tree"
  89. node-key="id"
  90. default-expand-all
  91. :props="{
  92. label: 'mailUser',
  93. }"
  94. @node-click="(data) => handleTreeNodeClick(data, 'staff')"
  95. ></el-tree>
  96. </div>
  97. <div
  98. class="tree"
  99. v-if="myFolderTreeData && myFolderTreeData.length > 0"
  100. >
  101. <el-tree
  102. :data="myFolderTreeData"
  103. node-key="id"
  104. default-expand-all
  105. :expand-on-click-node="false"
  106. @node-click="(data) => handleTreeNodeClick(data, 'folder')"
  107. >
  108. <template #default="{ node, data }">
  109. <span class="tree-content">
  110. <span>{{ data.label }}</span>
  111. <el-popover
  112. placement="bottom-start"
  113. title=""
  114. :width="200"
  115. trigger="click"
  116. >
  117. <div default style="display: flex">
  118. <el-button
  119. size="small"
  120. @click.stop="handleEditFolder(data, 'add')"
  121. >添加</el-button
  122. >
  123. <el-button
  124. size="small"
  125. v-if="data.id != '0'"
  126. @click.stop="handleEditFolder(data, 'edit')"
  127. >编辑</el-button
  128. >
  129. <el-button
  130. size="small"
  131. v-if="data.id != '0'"
  132. @click.stop="handleDelFolder(data)"
  133. >删除</el-button
  134. >
  135. </div>
  136. <template #reference>
  137. <span class="iconfont icon_more" style="padding-bottom: 5px"
  138. >...</span
  139. >
  140. </template>
  141. </el-popover>
  142. </span>
  143. </template>
  144. </el-tree>
  145. </div>
  146. <div class="tree" v-if="tagsTreeData && tagsTreeData.length > 0">
  147. <el-tree
  148. :data="tagsTreeData"
  149. node-key="id"
  150. default-expand-all
  151. :expand-on-click-node="false"
  152. @node-click="(data) => handleTreeNodeClick(data, 'tag')"
  153. >
  154. <template #default="{ node, data }">
  155. <span class="tree-content">
  156. <span>{{ data.name }}</span>
  157. <el-popover
  158. placement="bottom-start"
  159. title=""
  160. :width="150"
  161. trigger="click"
  162. >
  163. <div default style="display: flex">
  164. <el-button
  165. size="small"
  166. v-if="data.id == '0'"
  167. @click.stop="handleEditTag(data, 'add')"
  168. >添加</el-button
  169. >
  170. <el-button
  171. size="small"
  172. v-if="data.id != '0'"
  173. @click.stop="handleEditTag(data, 'edit')"
  174. >编辑</el-button
  175. >
  176. <el-button
  177. size="small"
  178. v-if="data.id != '0'"
  179. @click.stop="handleDelTag(data)"
  180. >删除</el-button
  181. >
  182. </div>
  183. <template #reference>
  184. <span class="iconfont icon_more" style="padding-bottom: 5px"
  185. >...</span
  186. >
  187. </template>
  188. </el-popover>
  189. </span>
  190. </template>
  191. </el-tree>
  192. </div>
  193. </div>
  194. <div v-if="activeName === 'second'">暂未开放</div>
  195. <div v-if="activeName === 'third'">暂未开放</div>
  196. </div>
  197. <el-dialog
  198. :title="editType === 'add' ? '添加文件夹' : '编辑文件夹'"
  199. v-model="myFolderDialog"
  200. width="300px"
  201. destroy-on-close
  202. v-loading="submitLoading"
  203. >
  204. <byForm
  205. :formConfig="myFolderFormConfig"
  206. :formOption="formOption"
  207. v-model="formData.myFolderData"
  208. :rules="rules"
  209. ref="myFolderForm"
  210. >
  211. </byForm>
  212. <template #footer>
  213. <el-button @click="myFolderDialog = false" size="large"
  214. >取 消</el-button
  215. >
  216. <el-button
  217. type="primary"
  218. @click="submitMyFolderForm()"
  219. size="large"
  220. :loading="submitLoading"
  221. >
  222. 确 定
  223. </el-button>
  224. </template>
  225. </el-dialog>
  226. <el-dialog
  227. :title="editType === 'add' ? '添加标签' : '编辑标签'"
  228. v-model="tagDialog"
  229. width="300px"
  230. destroy-on-close
  231. v-loading="submitLoading"
  232. >
  233. <byForm
  234. :formConfig="tagFormConfig"
  235. :formOption="formOption"
  236. v-model="formData.tagData"
  237. :rules="tagRules"
  238. ref="tagForm"
  239. >
  240. </byForm>
  241. <template #footer>
  242. <el-button @click="tagDialog = false" size="large">取 消</el-button>
  243. <el-button
  244. type="primary"
  245. @click="submitTagForm()"
  246. size="large"
  247. :loading="submitLoading"
  248. >
  249. 确 定
  250. </el-button>
  251. </template>
  252. </el-dialog>
  253. </div>
  254. </template>
  255. <script setup>
  256. import useMailStore from "@/store/modules/mail";
  257. import useUserStore from "@/store/modules/user";
  258. import byForm from "@/components/byForm/index";
  259. import { ElMessage, ElMessageBox } from "element-plus";
  260. const mailStore = useMailStore();
  261. const { proxy } = getCurrentInstance();
  262. let selectMail = ref({});
  263. let activeName = ref("first");
  264. const mailMapData = {
  265. inbox: ["INBOX"],
  266. unread: ["UNREAD"],
  267. draft: ["草稿箱"],
  268. sent: ["已发送"],
  269. delete: ["已删除"],
  270. waste: ["垃圾邮件"],
  271. };
  272. let selectFloderId = ref("");
  273. const mailList = ref([]);
  274. const staffMailData = ref([]);
  275. const formOption = reactive({
  276. inline: true,
  277. labelWidth: 100,
  278. itemWidth: 100,
  279. });
  280. const myFolderForm = ref(null);
  281. const myFolderTreeData = ref([]);
  282. const myFolderDialog = ref(false);
  283. const submitLoading = ref(false);
  284. const editType = ref("add");
  285. const myFolderFormConfig = computed(() => [
  286. {
  287. type: "input",
  288. prop: "name",
  289. label: "文件夹名称",
  290. disabled: false,
  291. itemWidth: 100,
  292. },
  293. ]);
  294. const formData = reactive({
  295. myFolderData: {},
  296. tagData: {},
  297. });
  298. const rules = ref({
  299. name: [{ required: true, message: "请输入文件夹名称", trigger: "blur" }],
  300. });
  301. const tagForm = ref(null);
  302. const tagsTreeData = ref([]);
  303. const tagDialog = ref(false);
  304. const tagFormConfig = computed(() => [
  305. {
  306. type: "input",
  307. prop: "name",
  308. label: "标签名称",
  309. disabled: false,
  310. itemWidth: 100,
  311. },
  312. ]);
  313. const tagRules = ref({
  314. name: [{ required: true, message: "请输入标签名称", trigger: "blur" }],
  315. });
  316. const getTagsList = () => {
  317. proxy
  318. .post("/myTag/page", {
  319. pageNum: 1,
  320. pageSize: 9999,
  321. id: useUserStore().user.userId,
  322. })
  323. .then((res) => {
  324. tagsTreeData.value = [
  325. {
  326. name: "我的标签",
  327. id: "0",
  328. children: res.rows,
  329. },
  330. ];
  331. });
  332. };
  333. const submitTagForm = () => {
  334. tagForm.value.handleSubmit(() => {
  335. submitLoading.value = true;
  336. proxy.post("/myTag/" + editType.value, formData.tagData).then(
  337. (res) => {
  338. ElMessage({
  339. message: `操作成功!`,
  340. type: "success",
  341. });
  342. tagDialog.value = false;
  343. submitLoading.value = false;
  344. getTagsList(selectMail.value);
  345. },
  346. (err) => {
  347. submitLoading.value = false;
  348. }
  349. );
  350. });
  351. };
  352. const handleEditTag = (data, type) => {
  353. editType.value = type;
  354. if (type === "add") {
  355. formData.tagData.name = "";
  356. formData.tagData.type = selectMail.value.type;
  357. formData.tagData.mailboxId = selectMail.value.id;
  358. } else {
  359. formData.tagData = data;
  360. }
  361. tagDialog.value = true;
  362. };
  363. const handleDelTag = (data) => {
  364. ElMessageBox.confirm(`此操作将删除该标签, 是否继续?`, "提示", {
  365. confirmButtonText: "确定",
  366. cancelButtonText: "取消",
  367. type: "warning",
  368. }).then(() => {
  369. // 删除
  370. proxy.post("/myTag/delete", { id: data.id }).then((res) => {
  371. ElMessage({
  372. message: `操作成功!`,
  373. type: "success",
  374. });
  375. getTagsList();
  376. });
  377. });
  378. };
  379. const getMyFolderTree = (data) => {
  380. proxy.post("/myFolder/tree", { mailboxId: data.id }).then((res) => {
  381. myFolderTreeData.value = [
  382. {
  383. label: "我的文件夹",
  384. id: "0",
  385. children: res,
  386. },
  387. ];
  388. });
  389. };
  390. const submitMyFolderForm = () => {
  391. myFolderForm.value.handleSubmit(() => {
  392. submitLoading.value = true;
  393. proxy.post("/myFolder/" + editType.value, formData.myFolderData).then(
  394. (res) => {
  395. ElMessage({
  396. message: `操作成功!`,
  397. type: "success",
  398. });
  399. myFolderDialog.value = false;
  400. submitLoading.value = false;
  401. getMyFolderTree(selectMail.value);
  402. },
  403. (err) => {
  404. submitLoading.value = false;
  405. }
  406. );
  407. });
  408. };
  409. const handleEditFolder = (data, type) => {
  410. formData.myFolderData = {};
  411. editType.value = type;
  412. if (type === "add") {
  413. formData.myFolderData.parentId = data.id;
  414. } else {
  415. formData.myFolderData = data;
  416. formData.myFolderData.name = data.label;
  417. }
  418. formData.myFolderData.type = selectMail.value.type;
  419. formData.myFolderData.mailboxId = selectMail.value.id;
  420. myFolderDialog.value = true;
  421. };
  422. const handleDelFolder = (data) => {
  423. ElMessageBox.confirm(`此操作将删除该文件夹, 是否继续?`, "提示", {
  424. confirmButtonText: "确定",
  425. cancelButtonText: "取消",
  426. type: "warning",
  427. }).then(() => {
  428. // 删除
  429. proxy.post("/myFolder/delete", { id: data.id }).then((res) => {
  430. ElMessage({
  431. message: `操作成功!`,
  432. type: "success",
  433. });
  434. getMyFolderTree(selectMail.value);
  435. });
  436. });
  437. };
  438. const otherFolder = ref([]);
  439. const getMialList = () => {
  440. proxy.get("/mailService/getUserEmailList").then((res) => {
  441. for (let i = 0; i < res.data.length; i++) {
  442. const iele = res.data[i];
  443. for (let j = 0; j < iele.mailFolderInfoList.length; j++) {
  444. const jele = iele.mailFolderInfoList[j];
  445. iele.mailFolderInfoListCopy = [];
  446. iele.otherFolder = [];
  447. if (mailMapData["inbox"].includes(jele.name)) {
  448. iele.mailFolderInfoListCopy.push({
  449. ...jele,
  450. name: "收件箱",
  451. sort: 1,
  452. });
  453. } else if (mailMapData["unread"].includes(jele.name)) {
  454. iele.mailFolderInfoListCopy.push({
  455. ...jele,
  456. name: "未读邮件",
  457. sort: 2,
  458. });
  459. } else if (mailMapData["draft"].includes(jele.name)) {
  460. iele.mailFolderInfoListCopy.push({
  461. ...jele,
  462. name: "草稿箱",
  463. sort: 3,
  464. });
  465. } else if (mailMapData["sent"].includes(jele.name)) {
  466. iele.mailFolderInfoListCopy.push({
  467. ...jele,
  468. name: "已发送",
  469. sort: 4,
  470. });
  471. } else if (mailMapData["delete"].includes(jele.name)) {
  472. iele.mailFolderInfoListCopy.push({
  473. ...jele,
  474. name: "已删除",
  475. sort: 5,
  476. });
  477. } else if (mailMapData["waste"].includes(jele.name)) {
  478. iele.mailFolderInfoListCopy.push({
  479. ...jele,
  480. name: "垃圾邮件",
  481. sort: 6,
  482. });
  483. } else {
  484. iele.otherFolder.push(jele);
  485. }
  486. }
  487. }
  488. mailList.value = res.data;
  489. console.log(res.data, "daa");
  490. if (mailList.value.length) {
  491. // 默认赋值第一邮箱
  492. selectMail.value = mailList.value[0];
  493. mailStore.selectMail = mailList.value[0];
  494. // 获取我的文件夹树形
  495. getMyFolderTree(selectMail.value);
  496. // 默认打开第一邮箱文件夹
  497. if (selectMail.value.mailFolderInfoList.length > 0) {
  498. handleOpenMenu(selectMail.value.mailFolderInfoList[0], "10");
  499. }
  500. }
  501. });
  502. proxy
  503. .post("/mailInfo/getUserEmailList", { id: useUserStore().user.userId })
  504. .then((res) => {
  505. staffMailData.value = [
  506. {
  507. mailUser: "员工邮箱",
  508. id: "0",
  509. children: res,
  510. },
  511. ];
  512. });
  513. };
  514. const handleClickMail = (item) => {
  515. mailStore.mailMenuList = [];
  516. selectMail.value = item;
  517. mailStore.selectMail = item;
  518. // 默认打开第一邮箱文件夹
  519. if (selectMail.value.mailFolderInfoList.length > 0) {
  520. handleOpenMenu(selectMail.value.mailFolderInfoList[0], "10");
  521. }
  522. };
  523. const changeFloderId = (val) => {
  524. selectFloderId.value = val;
  525. };
  526. const handleOpenMenu = (item, listPageType = "10") => {
  527. // 10为官方文件夹以及六个外侧文件夹 20为我的文件夹 30为标签文件夹
  528. selectFloderId.value = item.id;
  529. const menu = {
  530. title: item.name,
  531. type: selectMail.value.type,
  532. folderId: item.id,
  533. id: "folder" + "," + item.id,
  534. listPageType,
  535. };
  536. // 如没有这个菜单则push
  537. const menuItem = mailStore.mailMenuList.find((x) => x.id === menu.id);
  538. if (menuItem === undefined) {
  539. mailStore.mailMenuList.push(menu);
  540. }
  541. // 更新当前选择的tab数据和tab的Id值
  542. mailStore.currentMenu = menu;
  543. mailStore.currentId = menu.id;
  544. };
  545. const handleGoWrite = (mail = "", pageType = "0") => {
  546. const menu = {
  547. title: "写信",
  548. type: selectMail.value.type,
  549. id: "write",
  550. pageType,
  551. };
  552. if (mail) {
  553. menu.reMail = mail;
  554. }
  555. const index = mailStore.mailMenuList.findIndex((x) => x.id === menu.id);
  556. if (index >= 0) {
  557. mailStore.mailMenuList[index] = menu;
  558. } else {
  559. mailStore.mailMenuList.push(menu);
  560. }
  561. mailStore.currentMenu = menu;
  562. mailStore.currentId = menu.id;
  563. };
  564. const handleTreeNodeClick = (data, type) => {
  565. if (data.id != "0") {
  566. let menuData = {};
  567. let listPageType = "10";
  568. if (type === "staff") {
  569. menuData = {
  570. name: data.label,
  571. id: data.id,
  572. };
  573. } else if (type === "folder") {
  574. menuData = {
  575. name: data.label,
  576. id: data.id,
  577. };
  578. listPageType = "20";
  579. } else if (type === "tag") {
  580. menuData = {
  581. name: data.name,
  582. id: data.id,
  583. };
  584. listPageType = "30";
  585. }
  586. handleOpenMenu(menuData, listPageType);
  587. }
  588. };
  589. // const clickTreeMail = (data, att) => {
  590. // if (data.id !== "0" && data[att]) {
  591. // handleGoWrite(data[att], "50");
  592. // }
  593. // };
  594. onMounted(() => {
  595. getMialList();
  596. getTagsList();
  597. });
  598. defineExpose({
  599. handleGoWrite,
  600. changeFloderId,
  601. });
  602. </script>
  603. <style lang="scss" scoped>
  604. .left {
  605. font-size: 14px;
  606. .top {
  607. padding: 10px;
  608. text-align: center;
  609. border-bottom: 1px solid #ddd;
  610. .mail {
  611. color: black;
  612. font-weight: 700;
  613. font-size: 14px;
  614. }
  615. }
  616. .body {
  617. height: calc(100vh - 260px);
  618. overflow: auto;
  619. // padding: 10px;
  620. .mail-menu {
  621. list-style: none;
  622. margin-block-start: 0;
  623. margin-block-end: 0;
  624. padding: 0px;
  625. padding: 10px 10px 0 10px;
  626. .menu-item {
  627. display: flex;
  628. align-items: center;
  629. font-weight: 700;
  630. padding-left: 10px;
  631. font-size: 12px;
  632. width: 100%;
  633. height: 40px;
  634. line-height: 40px;
  635. border-radius: 3px;
  636. color: #333333;
  637. cursor: pointer;
  638. &:hover {
  639. background: #ddedfe;
  640. }
  641. .leftIcon {
  642. font-size: 20px;
  643. color: #999999;
  644. }
  645. }
  646. }
  647. }
  648. }
  649. .select-menu {
  650. background: #ddedfe;
  651. color: #0084ff !important;
  652. }
  653. .tree {
  654. margin-top: 10px;
  655. border-top: 1px solid #ddd;
  656. padding: 10px 10px 0 10px;
  657. .tree-content {
  658. width: 100%;
  659. display: flex;
  660. justify-content: space-between;
  661. padding-right: 10px;
  662. align-items: center;
  663. }
  664. }
  665. </style>
  666. <style lang="scss">
  667. .body {
  668. .el-tree-node__content {
  669. font-weight: 700;
  670. color: #666 !important;
  671. font-size: 12px !important;
  672. }
  673. }
  674. </style>