index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div>
  3. {{this.$store.state.user.deptName}}
  4. </div>
  5. <!--
  6. <treeselect
  7. style="
  8. width: 180px;
  9. height: 40px;
  10. position: relative;
  11. display: inline-block;
  12. line-height: 50px;
  13. "
  14. v-model="value"
  15. :options="options"
  16. :defaultExpandLevel="Infinity"
  17. />
  18. -->
  19. </template>
  20. <script>
  21. import { userdepttree } from "@/api/system/dept";
  22. import Treeselect from "@riophae/vue-treeselect";
  23. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  24. export default {
  25. components: { Treeselect },
  26. data() {
  27. return {
  28. value: null,
  29. options: [],
  30. Infinity: 2,
  31. num: 0,
  32. };
  33. },
  34. watch: {
  35. // 监听deptId
  36. value: "currDeptChange",
  37. },
  38. created() {
  39. this.getTreeselect();
  40. },
  41. methods: {
  42. /** 查询部门下拉树结构 */
  43. getTreeselect() {
  44. userdepttree().then((response) => {
  45. this.options = response.data;
  46. if (response.data != null && response.data.length > 0) {
  47. this.value = response.data[0].id;
  48. this.$store.selectDeptName = response.data[0].label;
  49. this.$store.selectDeptId = response.data[0].id;
  50. console.log("this.$store",this.$store)
  51. }
  52. });
  53. },
  54. currDeptChange(val) {
  55. if (val) {
  56. this.$store.selectDeptId = val;
  57. if (this.num > 0) {
  58. let path = this.$route.path;
  59. let visitedViews = this.$store.state.tagsView.visitedViews;
  60. let stagpath = null;
  61. const proArr = [];
  62. for (let i = 0; i < visitedViews.length; i++) {
  63. let view = visitedViews[i];
  64. proArr.push(
  65. this.$store.dispatch("tagsView/delCachedView", view).then(() => {
  66. const { fullPath } = view;
  67. if (path === fullPath) {
  68. stagpath = view;
  69. } else {
  70. this.$nextTick(() => {
  71. this.$router.replace({
  72. path: "/redirect" + fullPath,
  73. });
  74. });
  75. }
  76. })
  77. );
  78. }
  79. Promise.all(proArr).then(() => {
  80. if (stagpath != null) {
  81. this.$store
  82. .dispatch("tagsView/delCachedView", stagpath)
  83. .then(() => {
  84. const { fullPath } = stagpath;
  85. this.$nextTick(() => {
  86. this.$router.replace({
  87. path: "/redirect" + fullPath,
  88. });
  89. });
  90. });
  91. }
  92. });
  93. }
  94. this.num = this.num + 1;
  95. }
  96. },
  97. },
  98. };
  99. </script>
  100. <style lang="scss">
  101. .vue-treeselect__control {
  102. height: 20px;
  103. line-height: 26px;
  104. font-size: 12px;
  105. text-indent: 4px;
  106. }
  107. .vue-treeselect__menu-container {
  108. position: absolute;
  109. left: 0;
  110. width: 100%;
  111. overflow: visible;
  112. transition: 0s;
  113. }
  114. .vue-treeselect__menu {
  115. font-size: 12px;
  116. }
  117. </style>