index.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div id="classHoursReviews">
  3. <el-tabs
  4. v-model="parseSession.activeData"
  5. :closable="parseSession.options.length > 1"
  6. @tab-remove="removeTab"
  7. :before-leave="beforeLeave"
  8. >
  9. <el-tab-pane
  10. lazy
  11. v-for="(item, index) in parseSession.options"
  12. :key="item.keyId"
  13. :label="item.realName + '-' + item.goodsName"
  14. :name="item.keyId"
  15. ><study-times :key="index" :setData="item" @removeTab="removeTab"
  16. /></el-tab-pane>
  17. </el-tabs>
  18. </div>
  19. </template>
  20. <script>
  21. import studyTimes from "./studyTimes.vue";
  22. export default {
  23. name: "ClassHoursReviews",
  24. components: { studyTimes },
  25. data() {
  26. return {
  27. parseSession: {
  28. options: [],
  29. },
  30. };
  31. },
  32. created() {
  33. this.init();
  34. },
  35. activated() {
  36. this.init();
  37. },
  38. methods: {
  39. init() {
  40. const SESSION = sessionStorage.getItem("hoursAudit");
  41. if (SESSION) {
  42. this.parseSession = JSON.parse(SESSION);
  43. } else {
  44. console.log("错误处理");
  45. }
  46. },
  47. beforeLeave(activeName) {
  48. try {
  49. console.log(activeName, "activeName处理");
  50. this.parseSession.activeData = activeName;
  51. sessionStorage.setItem("hoursAudit", JSON.stringify(this.parseSession));
  52. console.log("处理成功");
  53. return true;
  54. } catch (error) {
  55. console.log("错误处理");
  56. return false;
  57. }
  58. },
  59. removeTab(targetName) {
  60. let tabs = JSON.parse(JSON.stringify(this.parseSession.options));
  61. let activeName = this.parseSession.activeData;
  62. if (activeName === targetName) {
  63. tabs.forEach((tab, index) => {
  64. if (tab.keyId === targetName) {
  65. let nextTab = tabs[index + 1] || tabs[index - 1];
  66. if (nextTab) {
  67. activeName = nextTab.keyId;
  68. }
  69. }
  70. });
  71. }
  72. let ary = tabs.filter((tab) => tab.keyId !== targetName);
  73. this.$set(this.parseSession, "options", ary);
  74. this.$set(this.parseSession, "activeData", activeName);
  75. },
  76. },
  77. destroyed() {
  78. sessionStorage.removeItem("hoursAudit");
  79. console.log("清除");
  80. },
  81. };
  82. </script>
  83. <style lang="less" scoped>
  84. /deep/ .el-tabs__content{
  85. padding: 6px;
  86. }
  87. </style>