Skip to content

A full-featured download manager.

refactor: task subnav switcher

Dr_rOotfe2dc7a5419c
diff --git a/src/renderer/components/Subnav/SubnavSwitcher.vue b/src/renderer/components/Subnav/SubnavSwitcher.vue
new file mode 100644
index 00000000..cbb54c1c
--- /dev/null
+++ b/src/renderer/components/Subnav/SubnavSwitcher.vue
@@ -0,0 +1,76 @@
+<template>
+ <el-dropdown @command="handleRoute" class="subnav-switch" size="medium">
+ <h4 class="subnav-title">
+ {{ title }}
+ <i class="el-icon-arrow-down el-icon--right" />
+ </h4>
+ <el-dropdown-menu slot="dropdown" class="subnav-switch-dropdown">
+ <el-dropdown-item :command="sn.route" v-for="sn in subnavs" :key="sn.key">
+ {{ sn.title }}
+ </el-dropdown-item>
+ </el-dropdown-menu>
+ </el-dropdown>
+</template>
+
+<script>
+export default {
+ name: 'mo-subnav-switcher',
+ props: {
+ title: {
+ type: String
+ },
+ subnavs: {
+ type: Array
+ }
+ },
+ methods: {
+ handleRoute (route) {
+ console.log('route=====>', route)
+ this.$router.push({
+ path: route
+ }).catch(err => {
+ console.log(err)
+ })
+ }
+ }
+}
+</script>
+
+<style lang='scss'>
+.subnav-switch-dropdown {
+ background: $--select-dropdown-background;
+ & .el-dropdown-menu__item {
+ font-size: 16px;
+ color: $--select-option-color;
+ }
+}
+.subnav-switch {
+ & .subnav-title {
+ color: $--subnav-action-color;
+ font-size: 16px;
+ }
+}
+.theme-dark {
+ .subnav-switch-dropdown {
+ background-color: $--dk-subnav-background;
+ border-color: $--dk-subnav-border-color;
+ color: $--dk-subnav-text-color;
+ & .el-dropdown-menu__item {
+ color: $--dk-subnav-text-color;
+ &.selected {
+ color: $--color-primary;
+ }
+ &.hover,
+ &:hover {
+ background-color: $--color-primary;
+ color: $--dk-titlebar-close-active-color;
+ }
+ }
+ }
+ & .el-dropdown {
+ & .subnav-title {
+ color: $--dk-subnav-action-color;
+ }
+ }
+}
+</style>
diff --git a/src/renderer/components/Task/Index.vue b/src/renderer/components/Task/Index.vue
index b5ef178d..38ce8484 100644
--- a/src/renderer/components/Task/Index.vue
+++ b/src/renderer/components/Task/Index.vue
@@ -1,18 +1,28 @@
<template>
- <el-container class="content panel"
- direction="horizontal">
- <el-aside width="200px"
- class="subnav hidden-xs-only">
+ <el-container
+ class="content panel"
+ direction="horizontal"
+ >
+ <el-aside
+ width="200px"
+ class="subnav hidden-xs-only"
+ >
<mo-task-subnav :current="status" />
</el-aside>
- <el-container class="content panel"
- direction="vertical">
- <el-header class="panel-header"
- height="84">
+ <el-container
+ class="content panel"
+ direction="vertical"
+ >
+ <el-header
+ class="panel-header"
+ height="84"
+ >
<h4 class="task-title hidden-xs-only">{{ title }}</h4>
- <mo-task-switcher :title="title"
- :commands="titles"
- class="hidden-sm-and-up" />
+ <mo-subnav-switcher
+ :title="title"
+ :subnavs="subnavs"
+ class="hidden-sm-and-up"
+ />
<mo-task-actions />
</el-header>
<el-main class="panel-content">
@@ -27,6 +37,7 @@ import TaskSubnav from '@/components/Subnav/TaskSubnav'
import TaskActions from '@/components/Task/TaskActions'
import TaskList from '@/components/Task/TaskList'
import TaskSwitch from '@/components/Task/TaskSwitcher'
+import SubnavSwitch from '@/components/Subnav/SubnavSwitcher'
export default {
name: 'mo-content-task',
@@ -34,6 +45,7 @@ export default {
[TaskSubnav.name]: TaskSubnav,
[TaskActions.name]: TaskActions,
[TaskList.name]: TaskList,
+ [SubnavSwitch.name]: SubnavSwitch,
[TaskSwitch.name]: TaskSwitch
},
props: {
@@ -43,23 +55,28 @@ export default {
}
},
computed: {
- titleMap: function () {
- return {
- active: this.$t('task.active'),
- waiting: this.$t('task.waiting'),
- stopped: this.$t('task.stopped')
- }
- },
- titles: function () {
- return Object.keys(this.titleMap).map(key => {
- return {
- key,
- label: this.titleMap[key]
+ subnavs: function () {
+ return [
+ {
+ key: 'active',
+ title: this.$t('task.active'),
+ route: '/task/active'
+ },
+ {
+ key: 'waiting',
+ title: this.$t('task.waiting'),
+ route: '/task/waiting'
+ },
+ {
+ key: 'stopped',
+ title: this.$t('task.stopped'),
+ route: '/task/stopped'
}
- })
+ ]
},
title: function () {
- return this.titleMap[this.status]
+ const subnav = this.subnavs.find((item) => item.key === this.status)
+ return subnav.title
}
},
watch: {
diff --git a/src/renderer/components/Task/TaskSwitcher.vue b/src/renderer/components/Task/TaskSwitcher.vue
deleted file mode 100644
index f4e0a6af..00000000
--- a/src/renderer/components/Task/TaskSwitcher.vue
+++ /dev/null
@@ -1,97 +0,0 @@
-<template>
- <el-dropdown @command="handleCommand"
- class="task-switch"
- size="medium">
- <h4 class="task-title">
- {{ title }}<i class="el-icon-arrow-down el-icon--right"></i>
- </h4>
- <el-dropdown-menu slot="dropdown"
- class="task-switch-dropdown">
- <el-dropdown-item :command="s.key"
- v-for="s in commands"
- :key="s.key">{{s.label}}</el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
-</template>
-
-<script>
-export default {
- name: 'mo-task-switcher',
- props: {
- title: {
- type: String,
- default: function () {
- return this.$t('task.active')
- }
- },
- commands: {
- type: Array,
- default: function () {
- const s = ['active', 'waiting', 'stopped']
- return s.map(key => {
- return {
- key,
- label: this.$t(`task.${key}`)
- }
- })
- }
- }
- },
- methods: {
- calcIconName (key) {
- const statusIconMap = {
- active: 'start',
- waiting: 'pause',
- stopped: 'stop'
- }
- return `task-${statusIconMap[key]}` || ''
- },
- handleCommand (status) {
- this.$router.push({
- path: `/task/${status}`
- }).catch(err => {
- console.log(err)
- })
- }
- }
-}
-</script>
-
-<style lang='scss'>
- .task-switch-dropdown {
- background: $--select-dropdown-background;
- & .el-dropdown-menu__item {
- font-size: 16px;
- color: $--select-option-color;
- }
- }
- .task-switch {
- & .task-title {
- color: $--task-action-color;
- font-size: 16px;
- }
- }
- .theme-dark {
- .task-switch-dropdown {
- background-color: $--dk-task-item-backgroud;
- border-color: $--dk-task-item-border-color;
- color: $--dk-task-item-text-color;
- & .el-dropdown-menu__item {
- color: $--dk-task-item-text-color;
- &.selected {
- color: $--color-primary;
- }
- &.hover,
- &:hover {
- background-color: $--color-primary;
- color: $--dk-titlebar-close-active-color;
- }
- }
- }
- & .el-dropdown {
- & .task-title {
- color: $--dk-task-action-color;
- }
- }
- }
-</style>
diff --git a/src/renderer/components/Theme/Dark/Variables.scss b/src/renderer/components/Theme/Dark/Variables.scss
index b574ad55..2bc38c41 100644
--- a/src/renderer/components/Theme/Dark/Variables.scss
+++ b/src/renderer/components/Theme/Dark/Variables.scss
@@ -20,9 +20,11 @@ $--dk-aside-text-color: #fff !default;
-------------------------- */
$--dk-subnav-background: #2D2D2D !default;
$--dk-subnav-title-color: #fff !default;
+$--dk-subnav-action-color: #fff !default;
$--dk-subnav-text-color: #aaa !default;
$--dk-subnav-active-text-color: #fff !default;
$--dk-subnav-active-background: #444 !default;
+$--dk-subnav-border-color: #ccc !default;
/* Panel
-------------------------- */
diff --git a/src/renderer/components/Theme/Light/Variables.scss b/src/renderer/components/Theme/Light/Variables.scss
index 222931ab..23cae3cc 100644
--- a/src/renderer/components/Theme/Light/Variables.scss
+++ b/src/renderer/components/Theme/Light/Variables.scss
@@ -20,9 +20,11 @@ $--aside-text-color: #fff !default;
-------------------------- */
$--subnav-background: #F4F5F7 !default;
$--subnav-title-color: $--color-text-primary !default;
+$--subnav-action-color: #4D515A !default;
$--subnav-text-color: #4D515A !default;
$--subnav-active-text-color: $--color-primary !default;
$--subnav-active-background: #EAECF0 !default;
+$--subnav-border-color: #ccc !default;
/* Panel
-------------------------- */