perf: 优化右下角、登录页主题设置

This commit is contained in:
kuaifan 2022-02-14 16:59:17 +08:00
parent 0e66ca148d
commit 6229a103aa
10 changed files with 146 additions and 78 deletions

View File

@ -6,17 +6,17 @@
</keep-alive> </keep-alive>
</transition> </transition>
<Spinner/> <Spinner/>
<AppDown/> <RightBottom/>
</div> </div>
</template> </template>
<script> <script>
import Spinner from "./components/Spinner"; import Spinner from "./components/Spinner";
import AppDown from "./components/AppDown"; import RightBottom from "./components/RightBottom";
import {mapState} from "vuex"; import {mapState} from "vuex";
export default { export default {
components: {AppDown, Spinner}, components: {RightBottom, Spinner},
data() { data() {
return { return {

View File

@ -1,11 +1,19 @@
<template> <template>
<div v-if="showButton" class="common-app-down" :class="{'on-client': !!$Electron}" :data-route="$route.name"> <div class="common-right-bottom">
<div v-if="$Electron" class="common-app-down-link" @click="releasesNotification"> <div v-if="$Electron" class="common-right-bottom-link" @click="useSSOLogin">
<Icon type="md-download"/> {{$L(repoTitle)}} <Icon type="ios-globe-outline"/>
{{ $L('使用 SSO 登录') }}
</div> </div>
<a v-else class="common-app-down-link" :href="repoReleases.html_url" target="_blank"> <template v-if="showDown">
<Icon type="md-download"/> {{$L(repoTitle)}} <div v-if="$Electron" class="common-right-bottom-link" @click="releasesNotification">
</a> <Icon type="md-download"/>
{{ $L(repoTitle) }}
</div>
<a v-else class="common-right-bottom-link" :href="repoReleases.html_url" target="_blank">
<Icon type="md-download"/>
{{ $L(repoTitle) }}
</a>
</template>
</div> </div>
</template> </template>
@ -16,9 +24,10 @@ import axios from "axios";
Vue.component('MarkdownPreview', MarkdownPreview) Vue.component('MarkdownPreview', MarkdownPreview)
import {mapState} from "vuex"; import {mapState} from "vuex";
import {Store} from "le5le-store";
export default { export default {
name: 'AppDown', name: 'RightBottom',
data() { data() {
return { return {
loadIng: 0, loadIng: 0,
@ -48,10 +57,12 @@ export default {
'isDesktop', 'isDesktop',
'wsOpenNum', 'wsOpenNum',
]), ]),
repoTitle() { repoTitle() {
return this.repoStatus == 2 ? '更新客户端' : '客户端下载'; return this.repoStatus == 2 ? '更新客户端' : '客户端下载';
}, },
showButton() {
showDown() {
return this.repoStatus && this.isDesktop && ['login', 'manage-dashboard'].includes(this.$route.name) return this.repoStatus && this.isDesktop && ['login', 'manage-dashboard'].includes(this.$route.name)
} }
}, },
@ -197,7 +208,7 @@ export default {
}, },
render: (h) => { render: (h) => {
return h('div', { return h('div', {
class: 'common-app-down-notification' class: 'common-right-bottom-notification'
}, [ }, [
h('div', { h('div', {
class: "notification-head" class: "notification-head"
@ -230,6 +241,10 @@ export default {
path: this.downloadResult.savePath path: this.downloadResult.savePath
}); });
this.$Electron.ipcRenderer.send('windowQuit'); this.$Electron.ipcRenderer.send('windowQuit');
},
useSSOLogin() {
Store.set('useSSOLogin', true);
} }
} }
}; };

View File

@ -31,26 +31,45 @@
</div> </div>
</div> </div>
<div class="login-bottom"> <div class="login-bottom">
<Dropdown trigger="click" @on-click="setLanguage" transfer> <Dropdown trigger="click" placement="bottom-start">
<div class="login-language"> <div class="login-setting">
{{currentLanguage}} {{$L('设置')}}
<i class="taskfont">&#xe689;</i> <i class="taskfont">&#xe689;</i>
</div> </div>
<Dropdown-menu slot="list"> <Dropdown-menu slot="list" class="login-setting-menu">
<Dropdown-item v-for="(item, key) in languageList" :key="key" :name="key" :selected="getLanguage() === key">{{item}}</Dropdown-item> <Dropdown placement="right-start" @on-click="setTheme">
<DropdownItem>
<div class="login-setting-item">
{{$L('主题皮肤')}}
<Icon type="ios-arrow-forward"></Icon>
</div>
</DropdownItem>
<DropdownMenu slot="list">
<Dropdown-item v-for="(item, key) in themeList" :key="key" :name="item.value" :selected="themeMode === item.value">{{$L(item.name)}}</Dropdown-item>
</DropdownMenu>
</Dropdown>
<Dropdown placement="right-start" @on-click="setLanguage">
<DropdownItem divided>
<div class="login-setting-item">
{{currentLanguage}}
<Icon type="ios-arrow-forward"></Icon>
</div>
</DropdownItem>
<DropdownMenu slot="list">
<Dropdown-item v-for="(item, key) in languageList" :key="key" :name="key" :selected="getLanguage() === key">{{item}}</Dropdown-item>
</DropdownMenu>
</Dropdown>
</Dropdown-menu> </Dropdown-menu>
</Dropdown> </Dropdown>
<div class="login-forgot">{{$L('忘记密码了?')}}<a href="javascript:void(0)" @click="forgotPassword">{{$L('重置密码')}}</a></div> <div class="login-forgot">{{$L('忘记密码了?')}}<a href="javascript:void(0)" @click="forgotPassword">{{$L('重置密码')}}</a></div>
</div> </div>
</div> </div>
<div v-if="$Electron" class="login-right-bottom">
<Button icon="ios-globe-outline" type="primary" @click="inputServerUrl">{{$L('自定义服务器')}}</Button>
</div>
</div> </div>
</template> </template>
<script> <script>
import {mapState} from "vuex"; import {mapState} from "vuex";
import {Store} from "le5le-store";
export default { export default {
data() { data() {
@ -71,6 +90,8 @@ export default {
demoAccount: {}, demoAccount: {},
needInvite: false, needInvite: false,
subscribe: null,
} }
}, },
mounted() { mounted() {
@ -81,6 +102,16 @@ export default {
} else { } else {
this.clearServerUrl(); this.clearServerUrl();
} }
//
this.subscribe = Store.subscribe('useSSOLogin', () => {
this.inputServerUrl();
});
},
beforeDestroy() {
if (this.subscribe) {
this.subscribe.unsubscribe();
this.subscribe = null;
}
}, },
deactivated() { deactivated() {
this.loginJump = false; this.loginJump = false;
@ -90,7 +121,12 @@ export default {
this.invite = ""; this.invite = "";
}, },
computed: { computed: {
...mapState(['cacheServerUrl']), ...mapState([
'cacheServerUrl',
'themeMode',
'themeList',
]),
currentLanguage() { currentLanguage() {
return this.languageList[this.languageType] || 'Language' return this.languageList[this.languageType] || 'Language'
@ -121,6 +157,10 @@ export default {
} }
}, },
methods: { methods: {
setTheme(mode) {
this.$store.dispatch("setTheme", mode)
},
getDemoAccount() { getDemoAccount() {
if (this.isNotServer()) { if (this.isNotServer()) {
return; return;
@ -158,7 +198,7 @@ export default {
inputServerUrl() { inputServerUrl() {
$A.modalInput({ $A.modalInput({
title: "自定义服务器", title: "使用 SSO 登录",
value: this.cacheServerUrl, value: this.cacheServerUrl,
placeholder: "请输入服务器地址", placeholder: "请输入服务器地址",
onOk: (value, cb) => { onOk: (value, cb) => {

View File

@ -517,27 +517,7 @@ export default {
}, },
setTheme(mode) { setTheme(mode) {
if (mode === undefined) { this.$store.dispatch("setTheme", mode)
return;
}
if (!$A.isChrome()) {
$A.modalWarning("仅客户端或Chrome浏览器支持主题功能");
return;
}
switch (mode) {
case 'dark':
$A.dark.enableDarkMode()
break;
case 'light':
$A.dark.disableDarkMode()
break;
default:
$A.dark.autoDarkMode()
break;
}
this.$store.state.themeMode = mode;
this.$store.state.themeIsDark = $A.dark.isDarkEnabled();
$A.setStorage("cacheThemeMode", mode);
}, },
toggleRoute(path) { toggleRoute(path) {

View File

@ -166,6 +166,35 @@ export default {
} }
}, },
/**
* 设置主题
* @param state
* @param mode
*/
setTheme({state}, mode) {
if (mode === undefined) {
return;
}
if (!$A.isChrome()) {
$A.modalWarning("仅客户端或Chrome浏览器支持主题功能");
return;
}
switch (mode) {
case 'dark':
$A.dark.enableDarkMode()
break;
case 'light':
$A.dark.disableDarkMode()
break;
default:
$A.dark.autoDarkMode()
break;
}
state.themeMode = mode;
state.themeIsDark = $A.dark.isDarkEnabled();
$A.setStorage("cacheThemeMode", mode);
},
/** /**
* 获取基本数据项目对话仪表盘任务 * 获取基本数据项目对话仪表盘任务
* @param dispatch * @param dispatch

View File

@ -1,4 +1,3 @@
@import "app-down";
@import "auto-tip"; @import "auto-tip";
@import "circle"; @import "circle";
@import "drawer-overlay"; @import "drawer-overlay";
@ -12,3 +11,4 @@
@import "user-avatar"; @import "user-avatar";
@import "user-input"; @import "user-input";
@import "report"; @import "report";
@import "right-bottom";

View File

@ -1,19 +1,33 @@
.common-app-down { .common-right-bottom {
position: absolute; position: absolute;
bottom: 26px; bottom: 22px;
right: 26px; right: 26px;
z-index: 1; z-index: 1;
display: flex; display: flex;
align-items: center; flex-direction: column;
align-items: flex-end;
transition: bottom 0.3s; transition: bottom 0.3s;
&.on-client {
&[data-route=login] { .common-right-bottom-link {
bottom: 75px; display: inline-block;
cursor: pointer;
line-height: 32px;
height: 32px;
padding: 0 15px;
margin: 4px 0;
font-size: 14px;
border-radius: 4px;
color: #fff;
background-color: #8bcf70;
border-color: #8bcf70;
&:hover {
color: #fff;
opacity: 0.9;
} }
} }
} }
.common-app-down-notification { .common-right-bottom-notification {
.notification-head { .notification-head {
display: flex; display: flex;
align-items: center; align-items: center;
@ -57,19 +71,3 @@
} }
} }
} }
.common-app-down-link {
display: inline-block;
cursor: pointer;
line-height: 32px;
height: 32px;
padding: 0 15px;
font-size: 14px;
border-radius: 4px;
color: #fff;
background-color: #8bcf70;
border-color: #8bcf70;
&:hover {
color: #fff;
opacity: 0.9;
}
}

View File

@ -1,7 +1,7 @@
body.dark-mode-reverse { body.dark-mode-reverse {
.ivu-btn-primary, .ivu-btn-primary,
.ivu-badge-count, .ivu-badge-count,
.common-app-down-link { .common-right-bottom .common-right-bottom-link {
color: #000; color: #000;
} }

View File

@ -102,7 +102,7 @@
display: flex; display: flex;
align-items: center; align-items: center;
width: 388px; width: 388px;
.login-language { .login-setting {
flex-shrink: 0; flex-shrink: 0;
display: flex; display: flex;
align-items: center; align-items: center;
@ -115,6 +115,20 @@
font-size: 12px; font-size: 12px;
} }
} }
.login-setting-menu {
display: flex;
flex-direction: column;
}
.login-setting-item {
display: flex;
align-items: center;
justify-content: space-between;
.ivu-icon {
color: #666666;
padding-left: 6px;
margin-right: -6px;
}
}
.login-forgot { .login-forgot {
flex: 1; flex: 1;
padding-left: 24px; padding-left: 24px;
@ -123,12 +137,4 @@
} }
} }
} }
.login-right-bottom {
position: absolute;
bottom: 26px;
right: 26px;
z-index: 1;
display: flex;
align-items: center;
}
} }

View File

@ -382,7 +382,7 @@
{"CN": "搜索","EN": "Search for","TC": "搜索","KM": "ស្វែងរក","TH": "ค้นหา","KO": "찾아서","JA": "検索する"}, {"CN": "搜索","EN": "Search for","TC": "搜索","KM": "ស្វែងរក","TH": "ค้นหา","KO": "찾아서","JA": "検索する"},
{"CN": "时间","EN": "Time","TC": "時間","KM": "បេលវេលា","TH": "เวลา","KO": "시각","JA": "時間"}, {"CN": "时间","EN": "Time","TC": "時間","KM": "បេលវេលា","TH": "เวลา","KO": "시각","JA": "時間"},
{"CN": "身份","EN": "Identity","TC": "身份","KM": "អត្ដសហ្ញាន","TH": "ตัวตน","KO": "정체","JA": "身元"}, {"CN": "身份","EN": "Identity","TC": "身份","KM": "អត្ដសហ្ញាន","TH": "ตัวตน","KO": "정체","JA": "身元"},
{"CN": "设置","EN": "Set","TC": "設置","KM": "តសសនីយផាប","TH": "ตั้ง","KO": "세트","JA": "セットする"}, {"CN": "设置","EN": "Setting","TC": "設置","KM": "តសសនីយផាប","TH": "ตั้ง","KO": "세트","JA": "セットする"},
{"CN": "上传","EN": "Upload","TC": "上傳","KM": "ផ្ទុកឡើង","TH": "ที่อัพโหลด","KO": "업로드","JA": "アップロード"}, {"CN": "上传","EN": "Upload","TC": "上傳","KM": "ផ្ទុកឡើង","TH": "ที่อัพโหลด","KO": "업로드","JA": "アップロード"},
{"CN": "删除","EN": "Delete","TC": "刪除","KM": "របៅបេលរសច","TH": "ลบ","KO": "지우다","JA": "削除する"}, {"CN": "删除","EN": "Delete","TC": "刪除","KM": "របៅបេលរសច","TH": "ลบ","KO": "지우다","JA": "削除する"},
{"CN": "日历","EN": "Calendar","TC": "日曆","KM": "របកតីតិន","TH": "ปฏิทิน","KO": "달력","JA": "カレンダー"}, {"CN": "日历","EN": "Calendar","TC": "日曆","KM": "របកតីតិន","TH": "ปฏิทิน","KO": "달력","JA": "カレンダー"},