index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <div class="app-process">
  3. <div class="app-process__left hidden-xs-only" @click="toLeft">
  4. <i class="el-icon-arrow-left"></i>
  5. </div>
  6. <div class="app-process__scroller">
  7. <div
  8. class="block"
  9. v-for="(item, index) in processList"
  10. :key="index"
  11. :class="{ active: item.active }"
  12. :data-index="index"
  13. @mousedown="
  14. (e) => {
  15. onTap(e, item);
  16. }
  17. "
  18. >
  19. <span>{{ item.label }}</span>
  20. <i
  21. class="el-icon-close"
  22. v-if="index > 0"
  23. :class="{ active: index > 0 }"
  24. @mousedown.stop="onDel(index)"
  25. ></i>
  26. </div>
  27. </div>
  28. <div class="app-process__right hidden-xs-only" @click="toRight">
  29. <i class="el-icon-arrow-right"></i>
  30. </div>
  31. <ul class="context-menu" v-show="menu.visible" :style="menu.style">
  32. <li @click="onClose('current')" v-if="isHit">关闭当前</li>
  33. <li @click="onClose('other')">关闭其他</li>
  34. <li @click="onClose('all')">关闭所有</li>
  35. </ul>
  36. </div>
  37. </template>
  38. <script>
  39. import { mapGetters, mapMutations } from "vuex";
  40. export default {
  41. name: "cl-process",
  42. data() {
  43. return {
  44. menu: {
  45. visible: false,
  46. current: {},
  47. style: {
  48. left: 0,
  49. top: 0
  50. }
  51. },
  52. isHit: false
  53. };
  54. },
  55. computed: {
  56. ...mapGetters(["processList"])
  57. },
  58. mounted() {
  59. this.$el.oncontextmenu = (e) => {
  60. e.returnValue = false;
  61. };
  62. document.body.addEventListener("click", () => {
  63. if (this.menu.visible) {
  64. this.menu.visible = false;
  65. }
  66. });
  67. },
  68. methods: {
  69. ...mapMutations(["ADD_PROCESS", "DEL_PROCESS", "SET_PROCESS"]),
  70. onTap(e, item) {
  71. this.isHit = item.active;
  72. if (e.button == 0) {
  73. this.$router.push(item.value);
  74. } else {
  75. this.menu = {
  76. current: item,
  77. visible: true,
  78. style: {
  79. left: e.layerX + "px",
  80. top: e.layerY + "px"
  81. }
  82. };
  83. }
  84. },
  85. onDel(index) {
  86. this.DEL_PROCESS(index);
  87. this.toPath();
  88. },
  89. onClose(cmd) {
  90. const { current } = this.menu;
  91. switch (cmd) {
  92. case "current":
  93. this.onDel(this.processList.findIndex((e) => e.value == current.value));
  94. break;
  95. case "other":
  96. this.SET_PROCESS(
  97. this.processList.filter((e) => e.value == current.value || e.value == "/")
  98. );
  99. break;
  100. case "all":
  101. this.SET_PROCESS(this.processList.filter((e) => e.value == "/"));
  102. break;
  103. }
  104. this.toPath();
  105. },
  106. toPath() {
  107. const active = this.processList.find((e) => e.active);
  108. if (!active) {
  109. const next = this.processList[this.processList.length - 1];
  110. this.$router.push(next ? next.value : "/");
  111. }
  112. },
  113. toLeft() {
  114. let scroller = this.$el.querySelector(".app-process__scroller");
  115. scroller.scrollTo(scroller.scrollLeft - 100, 0);
  116. },
  117. toRight() {
  118. let scroller = this.$el.querySelector(".app-process__scroller");
  119. scroller.scrollTo(scroller.scrollLeft + 100, 0);
  120. }
  121. }
  122. };
  123. </script>
  124. <style lang="scss" scoped>
  125. .app-process {
  126. display: flex;
  127. align-items: center;
  128. height: 30px;
  129. position: relative;
  130. &__left,
  131. &__right {
  132. background-color: #fff;
  133. height: 30px;
  134. line-height: 30px;
  135. padding: 0 2px;
  136. border-radius: 3px;
  137. cursor: pointer;
  138. &:hover {
  139. background-color: #eee;
  140. }
  141. }
  142. &__left {
  143. margin-right: 10px;
  144. }
  145. &__right {
  146. margin-left: 10px;
  147. }
  148. &__scroller {
  149. width: 100%;
  150. flex: 1;
  151. overflow-x: auto;
  152. overflow-y: hidden;
  153. white-space: nowrap;
  154. &::-webkit-scrollbar {
  155. display: none;
  156. }
  157. }
  158. .block {
  159. display: inline-flex;
  160. align-items: center;
  161. border-radius: 3px;
  162. height: 30px;
  163. line-height: 30px;
  164. padding: 0 10px;
  165. background-color: #fff;
  166. font-size: 12px;
  167. margin-right: 10px;
  168. color: #909399;
  169. cursor: pointer;
  170. &:last-child {
  171. margin-right: 0;
  172. }
  173. i {
  174. font-size: 14px;
  175. width: 0;
  176. overflow: hidden;
  177. transition: all 0.3s;
  178. &:hover {
  179. color: #fff;
  180. background-color: $color-main;
  181. }
  182. }
  183. &:hover {
  184. .el-icon-close {
  185. width: auto;
  186. margin-left: 5px;
  187. }
  188. }
  189. &.active {
  190. span {
  191. color: $color-main;
  192. }
  193. i {
  194. width: auto;
  195. margin-left: 5px;
  196. }
  197. &:before {
  198. background-color: $color-main;
  199. }
  200. }
  201. }
  202. .context-menu {
  203. margin: 0;
  204. background: #fff;
  205. z-index: 100;
  206. position: absolute;
  207. list-style-type: none;
  208. padding: 5px 0;
  209. border-radius: 4px;
  210. font-size: 12px;
  211. font-weight: 400;
  212. color: #333;
  213. box-shadow: 2px 2px 3px 0 rgba(0, 0, 0, 0.3);
  214. li {
  215. margin: 0;
  216. padding: 7px 16px;
  217. cursor: pointer;
  218. &:hover {
  219. background: #eee;
  220. }
  221. }
  222. }
  223. }
  224. </style>