feat: update

This commit is contained in:
xiaoxian521 2021-10-28 21:52:21 +08:00
parent b520e234a1
commit 3851d284bf
4 changed files with 92 additions and 53 deletions

View File

@ -14,14 +14,8 @@ export default {
[ElConfigProvider.name]: ElConfigProvider [ElConfigProvider.name]: ElConfigProvider
}, },
computed: { computed: {
// eslint-disable-next-line vue/return-in-computed-property
currentLocale() { currentLocale() {
switch (this.$storage.locale?.locale) { return this.$storage.locale?.locale === "zh" ? zhCn : en;
case "zh":
return zhCn;
case "en":
return en;
}
} }
} }
}; };

View File

@ -1,7 +1,13 @@
import { http } from "../utils/http"; import { http } from "../utils/http";
interface userType extends Promise<any> {
svg?: string;
code?: number;
info?: object;
}
// 获取验证码 // 获取验证码
export const getVerify = () => { export const getVerify = (): userType => {
return http.request("get", "/captcha"); return http.request("get", "/captcha");
}; };
@ -11,6 +17,6 @@ export const getLogin = (data: object) => {
}; };
// 注册 // 注册
export const getRegist = (data: object) => { export const getRegist = (data: object): userType => {
return http.request("post", "/register", data); return http.request("post", "/register", data);
}; };

View File

@ -1,4 +1,13 @@
<script setup lang="ts"> <script setup lang="ts">
import {
reactive,
ref,
unref,
watch,
computed,
useCssModule,
getCurrentInstance
} from "vue";
import panel from "../panel/index.vue"; import panel from "../panel/index.vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import { emitter } from "/@/utils/mitt"; import { emitter } from "/@/utils/mitt";
@ -7,41 +16,52 @@ import { debounce } from "/@/utils/debounce";
import { themeColorsType } from "../../types"; import { themeColorsType } from "../../types";
import { useAppStoreHook } from "/@/store/modules/app"; import { useAppStoreHook } from "/@/store/modules/app";
import { storageLocal, storageSession } from "/@/utils/storage"; import { storageLocal, storageSession } from "/@/utils/storage";
import { import { addClassNameToHtmlTag } from "@zougt/vite-plugin-theme-preprocessor/dist/browser-utils";
reactive,
ref,
unref,
watch,
useCssModule,
getCurrentInstance
} from "vue";
const router = useRouter(); const router = useRouter();
const { isSelect } = useCssModule(); const { isSelect } = useCssModule();
const instance =
getCurrentInstance().appContext.app.config.globalProperties.$storage;
const instanceConfig =
getCurrentInstance().appContext.app.config.globalProperties.$config;
let themeColors = ref<Array<themeColorsType>>([ let themeColors = ref<Array<themeColorsType>>([
// //
{ rgb: "27, 42, 71", themeColor: "layout-theme-default" }, { rgb: "27, 42, 71", themeColor: "default" },
// //
{ rgb: "255, 255, 255", themeColor: "layout-theme-light" }, { rgb: "255, 255, 255", themeColor: "light" },
// //
{ rgb: "245, 34, 45", themeColor: "layout-theme-dusk" }, { rgb: "245, 34, 45", themeColor: "dusk" },
// //
{ rgb: "250, 84, 28", themeColor: "layout-theme-volcano" }, { rgb: "250, 84, 28", themeColor: "volcano" },
// //
{ rgb: "250, 84, 28", themeColor: "layout-theme-higurashi" }, { rgb: "250, 84, 28", themeColor: "higurashi" },
// //
{ rgb: "19, 194, 194", themeColor: "layout-theme-mingQing" }, { rgb: "19, 194, 194", themeColor: "mingQing" },
// 绿 // 绿
{ rgb: "82, 196, 26", themeColor: "layout-theme-auroraGreen" }, { rgb: "82, 196, 26", themeColor: "auroraGreen" },
// //
{ rgb: "47, 84, 235", themeColor: "layout-theme-geekBlue" }, { rgb: "47, 84, 235", themeColor: "geekBlue" },
// //
{ rgb: "114, 46, 209", themeColor: "layout-theme-saucePurple" } { rgb: "114, 46, 209", themeColor: "saucePurple" }
]); ]);
const instance = const verticalRef = templateRef<HTMLElement | null>("verticalRef", null);
getCurrentInstance().appContext.app.config.globalProperties.$storage; const horizontalRef = templateRef<HTMLElement | null>("horizontalRef", null);
let layoutTheme =
ref(storageLocal.getItem("responsive-layout")) ||
ref({
layout: instanceConfig?.Layout ?? "vertical",
theme: instanceConfig?.Theme ?? "default"
});
// bodylayoutsrc/style/sidebar.scss
if (unref(layoutTheme)) {
let layout = unref(layoutTheme).layout;
window.document.body.setAttribute("layout", layout);
}
// //
const markValue = ref(storageLocal.getItem("showModel") || "smart"); const markValue = ref(storageLocal.getItem("showModel") || "smart");
@ -109,6 +129,7 @@ const tagsChange = () => {
emitter.emit("tagViewsChange", showVal); emitter.emit("tagViewsChange", showVal);
}; };
//
function onReset() { function onReset() {
storageLocal.clear(); storageLocal.clear();
storageSession.clear(); storageSession.clear();
@ -120,22 +141,6 @@ function onChange({ label }) {
emitter.emit("tagViewsShowModel", label); emitter.emit("tagViewsShowModel", label);
} }
const verticalRef = templateRef<HTMLElement | null>("verticalRef", null);
const horizontalRef = templateRef<HTMLElement | null>("horizontalRef", null);
let dataTheme =
ref(storageLocal.getItem("responsive-layout")) ||
ref({
layout: "vertical"
});
if (unref(dataTheme)) {
//
//
let layout = unref(dataTheme).layout;
window.document.body.setAttribute("layout", layout);
}
// Logo // Logo
function logoChange() { function logoChange() {
unref(logoVal) === "1" unref(logoVal) === "1"
@ -163,12 +168,41 @@ watch(instance, ({ layout }) => {
} }
}); });
function setTheme(layout: string) { //
dataTheme.value.layout = `${layout}`; const getThemeColor = computed(() => {
return current => {
if (
current === layoutTheme.value.theme &&
layoutTheme.value.theme !== "light"
) {
return "#fff";
} else if (
current === layoutTheme.value.theme &&
layoutTheme.value.theme === "light"
) {
return "#1d2b45";
} else {
return "transparent";
}
};
});
//
function setLayoutModel(layout: string) {
layoutTheme.value.layout = layout;
window.document.body.setAttribute("layout", layout); window.document.body.setAttribute("layout", layout);
instance.layout = { layout: `${layout}` }; instance.layout = { layout, theme: layoutTheme.value.theme };
useAppStoreHook().setLayout(layout); useAppStoreHook().setLayout(layout);
} }
//
function setLayoutThemeColor(theme: string) {
layoutTheme.value.theme = theme;
addClassNameToHtmlTag({
scopeName: `layout-theme-${theme}`
});
instance.layout = { layout: useAppStoreHook().layout, theme };
}
</script> </script>
<template> <template>
@ -177,9 +211,9 @@ function setTheme(layout: string) {
<ul class="pure-theme"> <ul class="pure-theme">
<el-tooltip class="item" content="左侧菜单暗色模式" placement="bottom"> <el-tooltip class="item" content="左侧菜单暗色模式" placement="bottom">
<li <li
:class="dataTheme.layout === 'vertical' ? $style.isSelect : ''" :class="layoutTheme.layout === 'vertical' ? $style.isSelect : ''"
ref="verticalRef" ref="verticalRef"
@click="setTheme('vertical')" @click="setLayoutModel('vertical')"
> >
<div></div> <div></div>
<div></div> <div></div>
@ -188,9 +222,9 @@ function setTheme(layout: string) {
<el-tooltip class="item" content="顶部菜单暗色模式" placement="bottom"> <el-tooltip class="item" content="顶部菜单暗色模式" placement="bottom">
<li <li
:class="dataTheme.layout === 'horizontal' ? $style.isSelect : ''" :class="layoutTheme.layout === 'horizontal' ? $style.isSelect : ''"
ref="horizontalRef" ref="horizontalRef"
@click="setTheme('horizontal')" @click="setLayoutModel('horizontal')"
> >
<div></div> <div></div>
<div></div> <div></div>
@ -204,8 +238,13 @@ function setTheme(layout: string) {
v-for="(item, index) in themeColors" v-for="(item, index) in themeColors"
:key="index" :key="index"
:style="{ background: `rgb(${item.rgb})` }" :style="{ background: `rgb(${item.rgb})` }"
@click="setLayoutThemeColor(item.themeColor)"
>
<el-icon
style="margin: 0.1em 0.1em 0 0"
:size="17"
:color="getThemeColor(item.themeColor)"
> >
<el-icon style="margin: 4px 3px 0 0">
<Check /> <Check />
</el-icon> </el-icon>
</li> </li>
@ -360,7 +399,6 @@ function setTheme(layout: string) {
height: 20px; height: 20px;
margin-top: 8px; margin-top: 8px;
margin-right: 8px; margin-right: 8px;
color: #fff;
font-weight: 700; font-weight: 700;
text-align: center; text-align: center;
border-radius: 2px; border-radius: 2px;

View File

@ -21,6 +21,7 @@ export const useAppStore = defineStore({
: true, : true,
withoutAnimation: false withoutAnimation: false
}, },
// 这里的layout用于监听容器拖拉后恢复对应的导航模式
layout: storageLocal.getItem("responsive-layout")?.layout ?? "vertical", layout: storageLocal.getItem("responsive-layout")?.layout ?? "vertical",
device: deviceDetection() ? "mobile" : "desktop" device: deviceDetection() ? "mobile" : "desktop"
}), }),