Home.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="context">
  3. <router-view class="context_router"></router-view>
  4. <mt-tabbar v-model="selected" fixed class="tabber" style="display:none">
  5. <mt-tab-item id="tab1" @click.native="changeTab(1)">
  6. <img v-if="selected == 'tab1'" slot="icon" src="../assets/image/tab_ass_choose.png">
  7. <img v-else slot="icon" src="../assets/image/tab_ass.png">
  8. 资产
  9. </mt-tab-item>
  10. <mt-tab-item id="tab2" @click.native="changeTab(2)">
  11. <img v-if="selected == 'tab2'" slot="icon" src="../assets/image/tab_task_choose.png">
  12. <img v-else slot="icon" src="../assets/image/tab_task.png">
  13. 工单
  14. </mt-tab-item>
  15. <mt-tab-item id="tab3" @click.native="changeTab(3)">
  16. <img v-if="selected == 'tab3'" slot="icon" src="../assets/image/tab_my_choose.png">
  17. <img v-else slot="icon" src="../assets/image/tab_my.png">
  18. <mt-badge v-if="num != 0 && num != null" class="myMsg" size="small" type="error">{{num}}</mt-badge>
  19. 我的
  20. </mt-tab-item>
  21. </mt-tabbar>
  22. </div>
  23. </template>
  24. <script>
  25. export default {
  26. inject: ['reload'],
  27. data() {
  28. return {
  29. selected: 'tab1',
  30. user: sessionStorage.getItem("user"),
  31. showTab: true,
  32. num: sessionStorage.noRead,
  33. };
  34. },
  35. methods: {
  36. changeTab(type) {
  37. if(type == 1) {
  38. if(this.$router.history.current.fullPath == '/assets') {
  39. this.reload();
  40. } else {
  41. this.$router.push({ path: '/assets' });
  42. this.getNoRead();
  43. }
  44. } else if(type == 2) {
  45. if(this.$router.history.current.fullPath == '/task') {
  46. this.reload();
  47. } else {
  48. this.$router.push({ path: '/task' });
  49. this.getNoRead();
  50. }
  51. } else if(type == 3) {
  52. if(this.$router.history.current.fullPath == '/my') {
  53. this.reload();
  54. } else {
  55. this.$router.push({ path: '/my' });
  56. this.getNoRead();
  57. }
  58. }
  59. },
  60. getNoRead() {
  61. this.http.post(this.port.my.noReadNum, {
  62. 'uid': this.user.id,
  63. } ,
  64. res => {
  65. if (res.code == "ok") {
  66. sessionStorage.setItem('noRead', res.data==null?0:res.data);
  67. this.num = sessionStorage.noRead;
  68. } else {
  69. this.$toast({
  70. message: res.msg,
  71. duration: 2000
  72. });
  73. }
  74. }, error => {
  75. this.$toast({
  76. message: error,
  77. duration: 2000
  78. });
  79. })
  80. },
  81. },
  82. created() {
  83. if(this.$router.history.current.meta.parentPath == "/tab_assets") {
  84. this.selected = "tab1"
  85. } else if(this.$router.history.current.meta.parentPath == "/tab_task") {
  86. this.selected = "tab2"
  87. } else if(this.$router.history.current.meta.parentPath == "/tab_my") {
  88. this.selected = "tab3"
  89. }
  90. },
  91. mounted() {
  92. if( this.$router.history.current.fullPath == '/assets' ||
  93. this.$router.history.current.fullPath == '/task' ||
  94. this.$router.history.current.fullPath == '/my') {
  95. $(".tabber").show();
  96. } else {
  97. $(".tabber").hide();
  98. }
  99. if (this.user) {
  100. var user = JSON.parse(this.user);
  101. this.user = user;
  102. this.getNoRead();
  103. } else {
  104. this.$router.push("/login");
  105. }
  106. }
  107. };
  108. </script>
  109. <style scoped lang="scss">
  110. .context {
  111. height: 100%;
  112. background: #EFEFEF;
  113. }
  114. .context_router {
  115. height: calc(100% - 55px);
  116. }
  117. #tab3 {
  118. position: relative;
  119. }
  120. .myMsg {
  121. position: absolute;
  122. right: 0.3rem;
  123. top: 0.06rem;
  124. }
  125. </style>