基于vue3.0和element-plus的组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
8.0 KiB

2 years ago
<template>
<div class="head">
2 years ago
<div class="title">{{ title || t('title') }}</div>
2 years ago
<div class="menu">
2 years ago
<el-dropdown class="icon" :size="state.size.size" :teleported="false">
2 years ago
<el-button :size="state.size.size" icon="Avatar" circle></el-button>
<template #dropdown>
<el-dropdown-menu>
2 years ago
<el-dropdown-item v-if="center" @click="router.push(center)">
{{ t('head.center') }}
</el-dropdown-item>
<el-dropdown-item @click="updatePass">{{ t('pwd.changePwd') }}</el-dropdown-item>
<el-dropdown-item @click="emit('logout')">{{ t('head.logout') }}</el-dropdown-item>
2 years ago
</el-dropdown-menu>
</template>
</el-dropdown>
2 years ago
<el-tooltip effect="dark" :content="t('head.fullScreen')" placement="bottom">
2 years ago
<el-icon @click="fullscreen" class="icon">
<FullScreen />
</el-icon>
</el-tooltip>
2 years ago
<el-tooltip effect="dark" :content="t('head.changeStyle')" placement="left">
<el-dropdown v-show="styleAble" class="icon" :size="state.size.size" trigger="click" :teleported="false">
2 years ago
<el-button :size="state.size.size" icon="Opportunity" circle></el-button>
<template #dropdown>
<el-dropdown-menu>
2 years ago
<el-dropdown-item @click="changeStyle('plain')">
<el-tooltip effect="dark" :content="t('head.default')" placement="left">
2 years ago
<el-icon class="dropdown-icon">
<Sunset />
</el-icon>
</el-tooltip>
</el-dropdown-item>
<el-dropdown-item @click="changeStyle('light')">
2 years ago
<el-tooltip effect="dark" :content="t('head.light')" placement="left">
2 years ago
<el-icon class="dropdown-icon">
<Sunny />
</el-icon>
</el-tooltip>
</el-dropdown-item>
<el-dropdown-item @click="changeStyle('dark')">
2 years ago
<el-tooltip effect="dark" :content="t('head.dark')" placement="left">
2 years ago
<el-icon class="dropdown-icon">
<MoonNight />
</el-icon>
</el-tooltip>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</el-tooltip>
2 years ago
<el-tooltip effect="dark" :content="t('head.language')" placement="left">
<el-dropdown v-show="langAble" class="icon" :size="state.size.size" trigger="click" :teleported="false">
2 years ago
<el-button icon="Flag" :size="state.size.size" circle></el-button>
<template #dropdown>
<el-dropdown-menu>
2 years ago
<el-dropdown-item @click="changeLang('zh')">{{ t('head.zh') }}</el-dropdown-item>
<el-dropdown-item @click="changeLang('en')">{{ t('head.en') }}</el-dropdown-item>
2 years ago
</el-dropdown-menu>
</template>
</el-dropdown>
</el-tooltip>
2 years ago
<el-tooltip effect="dark" :content="t('head.size')" placement="left">
<el-dropdown v-show="sizeAble" class="icon" :size="state.size.size" trigger="click" :teleported="false">
2 years ago
<el-button icon="Switch" :size="state.size.size" circle></el-button>
<template #dropdown>
<el-dropdown-menu>
2 years ago
<el-dropdown-item @click="changeSize('small')">{{ t('head.small') }}</el-dropdown-item>
<el-dropdown-item @click="changeSize('normal')">{{ t('head.normal') }}</el-dropdown-item>
<el-dropdown-item @click="changeSize('large')">{{ t('head.large') }}</el-dropdown-item>
2 years ago
</el-dropdown-menu>
</template>
</el-dropdown>
</el-tooltip>
</div>
</div>
2 years ago
<el-dialog :title="t('pwd.changePwd')" v-model="flag.update" :size="state.size.size" :close-on-click-modal="false"
2 years ago
top="10vh" width="40%">
<ModifyForm :width="150" :param="password" @cancel="flag.update = false" @confirm="emit('updatePwd', password)"
2 years ago
:rules="rules" :items="items">
2 years ago
</ModifyForm>
</el-dialog>
</template>
<script lang="ts" setup>
import { useStore } from "vuex";
import { reactive, onMounted, ref } from "vue";
2 years ago
import { ModifyForm } from "noob-mengyxu";
import { Element, Styles, Size, NoobInput } from "noob-mengyxu";
import { useRouter } from "vue-router";
import { useI18n } from "vue3-i18n";
2 years ago
2 years ago
const { SimpleRequired, SimplePassword } = Element;
2 years ago
const { state, commit, dispatch } = useStore();
2 years ago
const router = useRouter();
const i18n = useI18n();
const { t } = useI18n();
2 years ago
const emit = defineEmits(["updatePwd", "logout"]);
const flag = reactive({
update: false
})
const password = ref({
new: '',
reNew: '',
old: ''
})
const props = defineProps({
title: {
type: String,
default: null,
2 years ago
},
styleAble: {
type: Boolean,
},
sizeAble: {
type: Boolean,
},
langAble: {
type: Boolean,
},
center: {
type: String,
default: null,
},
2 years ago
});
const rules = {
2 years ago
old: [new SimpleRequired('pwd.oldPwd')],
new: [new SimpleRequired('pwd.newPwd'), new SimplePassword()],
2 years ago
reNew: [{
required: true,
trigger: 'blur',
validator: (rule: any, value: any, callback: any) => {
if (value == null || value === '') {
2 years ago
callback(new Error(t('pwd.plsRePwd')));
2 years ago
} else if (value != password.value.new) {
2 years ago
callback(new Error(t('pwd.rePwdError')));
2 years ago
}
callback();
}
}]
}
2 years ago
const items = [
{ i18n: 'pwd.oldPwd', code: 'old', type: "password" },
{ i18n: 'pwd.newPwd', code: 'new', type: "password" },
{ i18n: 'pwd.rePwd', code: 'reNew', type: "password" },
]
2 years ago
const updatePass = () => {
password.value = {
new: '',
reNew: '',
old: ''
};
flag.update = true;
}
const fullscreen = () => {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen();
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
}
}
const changeStyle = type => {
2 years ago
commit('updateState', ['style', Styles[type]]);
2 years ago
}
const changeLang = type => {
2 years ago
i18n.setLocale(type);
2 years ago
}
const changeSize = type => {
2 years ago
commit('updateState', ['size', Size[type]])
commit('initSize', window.innerHeight);
2 years ago
}
onMounted(() => { });
</script>
<style lang="scss" scoped>
.head {
background-color: v-bind('state.style.headBg');
height: v-bind('state.size.headHeight');
}
.title {
height: v-bind('state.size.headHeight');
width: v-bind('state.size.asideWidth');
text-align: center;
float: left;
font-size: v-bind('state.size.titleSize');
line-height: v-bind('state.size.headHeight');
font-weight: bold;
color: v-bind('state.style.titleColor');
}
.menu {
float: right;
line-height: v-bind('state.size.headHeight');
width: v-bind('state.size.headMenuWidth');
padding-right: 10px;
align-items: center;
justify-content: center;
.icon {
float: right;
cursor: pointer;
height: v-bind('state.size.headHeight');
margin-right: 20px;
font-size: v-bind('state.size.headIconSize');
align-items: center;
color: v-bind('state.style.color');
}
}
.dropdown-icon {
font-size: 20px;
margin: 5px 3px;
}
</style>