2021-12-12 01:04:13 +08:00
|
|
|
<template>
|
|
|
|
<t-drawer
|
|
|
|
v-model:visible="showSettingPanel"
|
2021-12-22 12:07:29 +08:00
|
|
|
size="408px"
|
2021-12-12 01:04:13 +08:00
|
|
|
:footer="false"
|
|
|
|
header="页面配置"
|
|
|
|
:close-btn="true"
|
|
|
|
class="setting-drawer-container"
|
2021-12-22 12:07:29 +08:00
|
|
|
@close-btn-click="handleCloseDrawer"
|
2021-12-12 01:04:13 +08:00
|
|
|
>
|
|
|
|
<div class="setting-container">
|
|
|
|
<t-form ref="form" :data="formData" label-align="left">
|
|
|
|
<div class="setting-group-title">主题模式</div>
|
2021-12-22 12:07:29 +08:00
|
|
|
<t-radio-group v-model="formData.mode">
|
2021-12-12 01:04:13 +08:00
|
|
|
<div v-for="(item, index) in MODE_OPTIONS" :key="index" class="setting-layout-drawer">
|
2021-12-22 12:07:29 +08:00
|
|
|
<div>
|
|
|
|
<t-radio-button :key="index" :value="item.type"
|
|
|
|
><component :is="getModeIcon(item.type)"
|
|
|
|
/></t-radio-button>
|
|
|
|
<p :style="{ textAlign: 'center', marginTop: '8px' }">{{ item.text }}</p>
|
|
|
|
</div>
|
2021-12-12 01:04:13 +08:00
|
|
|
</div>
|
|
|
|
</t-radio-group>
|
|
|
|
<div class="setting-group-title">主题色</div>
|
|
|
|
<t-radio-group v-model="formData.brandTheme" default-vaule="default">
|
2021-12-22 12:07:29 +08:00
|
|
|
<div
|
|
|
|
v-for="(item, index) in COLOR_OPTIONS.slice(0, COLOR_OPTIONS.length - 1)"
|
|
|
|
:key="index"
|
|
|
|
class="setting-layout-drawer"
|
|
|
|
>
|
2021-12-12 01:04:13 +08:00
|
|
|
<t-radio-button :key="index" :value="item" class="setting-layout-color-group">
|
|
|
|
<color-container :value="item" />
|
|
|
|
</t-radio-button>
|
|
|
|
</div>
|
2021-12-22 12:07:29 +08:00
|
|
|
<div class="setting-layout-drawer">
|
|
|
|
<t-popup
|
|
|
|
destroy-on-close
|
|
|
|
expand-animation
|
|
|
|
placement="bottom-right"
|
|
|
|
trigger="click"
|
|
|
|
:visible="isColoPickerDisplay"
|
|
|
|
:overlay-style="{ padding: 0 }"
|
|
|
|
@visible-change="onPopupVisibleChange"
|
|
|
|
>
|
|
|
|
<template #content>
|
|
|
|
<color-picker :theme="mode" @changeColor="changeColor" />
|
|
|
|
</template>
|
|
|
|
<t-radio-button
|
|
|
|
:value="COLOR_OPTIONS[COLOR_OPTIONS.length - 1]"
|
|
|
|
class="setting-layout-color-group dynamic-color-btn"
|
|
|
|
>
|
|
|
|
<color-container :value="COLOR_OPTIONS[COLOR_OPTIONS.length - 1]" />
|
|
|
|
</t-radio-button>
|
|
|
|
</t-popup>
|
|
|
|
</div>
|
2021-12-12 01:04:13 +08:00
|
|
|
</t-radio-group>
|
|
|
|
|
|
|
|
<div class="setting-group-title">导航布局</div>
|
|
|
|
<t-radio-group v-model="formData.layout" default-vaule="top">
|
|
|
|
<div v-for="(item, index) in LAYOUT_OPTION" :key="index" class="setting-layout-drawer">
|
|
|
|
<t-radio-button :key="index" :value="item">
|
|
|
|
<thumbnail :src="getThumbnailUrl(item)" />
|
|
|
|
</t-radio-button>
|
|
|
|
</div>
|
|
|
|
</t-radio-group>
|
|
|
|
|
|
|
|
<t-form-item v-show="formData.layout === 'mix'" label="分割菜单(混合模式下有效)" name="splitMenu">
|
|
|
|
<t-switch v-model="formData.splitMenu" />
|
|
|
|
</t-form-item>
|
|
|
|
|
2021-12-24 11:24:14 +08:00
|
|
|
<t-form-item v-show="formData.layout === 'mix'" label="固定 Sidebar" name="isSidebarFixed">
|
2021-12-12 01:04:13 +08:00
|
|
|
<t-switch v-model="formData.isSidebarFixed" />
|
|
|
|
</t-form-item>
|
|
|
|
|
|
|
|
<div class="setting-group-title">元素开关</div>
|
|
|
|
<t-form-item v-show="formData.layout === 'side'" label="显示 Header" name="showHeader">
|
|
|
|
<t-switch v-model="formData.showHeader" />
|
|
|
|
</t-form-item>
|
|
|
|
<t-form-item label="显示 Breadcrumbs" name="showBreadcrumb">
|
|
|
|
<t-switch v-model="formData.showBreadcrumb" />
|
|
|
|
</t-form-item>
|
|
|
|
<t-form-item label="显示 Footer" name="showFooter">
|
|
|
|
<t-switch v-model="formData.showFooter" />
|
|
|
|
</t-form-item>
|
|
|
|
</t-form>
|
|
|
|
<div class="setting-info">
|
2021-12-31 12:16:26 +08:00
|
|
|
<p>请复制后手动修改配置文件: /src/config/style.ts</p>
|
2021-12-12 01:04:13 +08:00
|
|
|
<t-button theme="primary" variant="text" @click="handleCopy"> 复制配置项 </t-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</t-drawer>
|
|
|
|
</template>
|
2022-02-16 19:56:36 +08:00
|
|
|
<script setup lang="ts">
|
2022-02-19 16:23:32 +08:00
|
|
|
import { ref, computed, watch, onMounted, watchEffect } from 'vue';
|
2021-12-12 01:04:13 +08:00
|
|
|
import { useStore } from 'vuex';
|
2021-12-22 12:07:29 +08:00
|
|
|
import { ColorPicker } from 'vue-color-kit';
|
|
|
|
import { MessagePlugin, PopupVisibleChangeContext } from 'tdesign-vue-next';
|
|
|
|
import { Color } from 'tvision-color';
|
2021-12-31 12:16:26 +08:00
|
|
|
import useClipboard from 'vue-clipboard3';
|
|
|
|
|
2021-12-22 12:07:29 +08:00
|
|
|
import 'vue-color-kit/dist/vue-color-kit.css';
|
|
|
|
|
2021-12-12 01:04:13 +08:00
|
|
|
import STYLE_CONFIG from '@/config/style';
|
2021-12-22 12:07:29 +08:00
|
|
|
import { insertThemeStylesheet, generateColorMap } from '@/config/color';
|
2021-12-12 01:04:13 +08:00
|
|
|
|
|
|
|
import Thumbnail from '@/components/thumbnail/index.vue';
|
|
|
|
import ColorContainer from '@/components/color/index.vue';
|
|
|
|
|
2021-12-22 12:07:29 +08:00
|
|
|
import SettingDarkIcon from '@/assets/assets-setting-dark.svg';
|
|
|
|
import SettingLightIcon from '@/assets/assets-setting-light.svg';
|
|
|
|
import SettingAutoIcon from '@/assets/assets-setting-auto.svg';
|
|
|
|
|
2021-12-12 01:04:13 +08:00
|
|
|
const LAYOUT_OPTION = ['side', 'top', 'mix'];
|
2021-12-23 01:46:02 +08:00
|
|
|
const COLOR_OPTIONS = ['default', 'cyan', 'green', 'yellow', 'orange', 'red', 'pink', 'purple', 'dynamic'];
|
2021-12-22 12:07:29 +08:00
|
|
|
const MODE_OPTIONS = [
|
|
|
|
{ type: 'light', text: '明亮' },
|
|
|
|
{ type: 'dark', text: '暗黑' },
|
|
|
|
{ type: 'auto', text: '跟随系统' },
|
|
|
|
];
|
2021-12-12 01:04:13 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
const formData = ref({ ...STYLE_CONFIG });
|
|
|
|
const store = useStore();
|
|
|
|
const colors = ref();
|
|
|
|
const isColoPickerDisplay = ref(false);
|
2021-12-12 01:04:13 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
const showSettingPanel = computed({
|
|
|
|
get() {
|
|
|
|
return store.state.setting.showSettingPanel;
|
|
|
|
},
|
|
|
|
set(newVal) {
|
|
|
|
store.commit('setting/toggleSettingPanel', newVal);
|
|
|
|
},
|
|
|
|
});
|
2021-12-12 01:04:13 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
const mode = computed(() => {
|
|
|
|
return store.getters['setting/mode'];
|
|
|
|
});
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
watch(
|
|
|
|
() => colors.value,
|
|
|
|
(newColor) => {
|
|
|
|
const { hex } = newColor;
|
|
|
|
const { setting } = store.state;
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
// hex 主题色
|
|
|
|
const newPalette = Color.getPaletteByGradation({
|
|
|
|
colors: [hex],
|
|
|
|
step: 10,
|
|
|
|
})[0];
|
|
|
|
const { mode } = store.state.setting;
|
|
|
|
const colorMap = generateColorMap(hex, newPalette, mode);
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
store.commit('setting/addColor', { [hex]: colorMap });
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
insertThemeStylesheet(hex, colorMap, mode);
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
store.dispatch('setting/changeTheme', { ...setting, brandTheme: hex });
|
|
|
|
},
|
|
|
|
);
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
const changeColor = (val) => {
|
|
|
|
const { hex } = val;
|
|
|
|
const { setting } = store.state;
|
|
|
|
// hex 主题色
|
|
|
|
const newPalette = Color.getPaletteByGradation({
|
|
|
|
colors: [hex],
|
|
|
|
step: 10,
|
|
|
|
})[0];
|
|
|
|
const { mode } = store.state.setting;
|
|
|
|
const colorMap = generateColorMap(hex, newPalette, mode);
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
store.commit('setting/addColor', { [hex]: colorMap });
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
insertThemeStylesheet(hex, colorMap, mode);
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
store.dispatch('setting/changeTheme', { ...setting, brandTheme: hex });
|
|
|
|
};
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
onMounted(() => {
|
|
|
|
document.querySelector('.dynamic-color-btn').addEventListener('click', () => {
|
|
|
|
isColoPickerDisplay.value = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const onPopupVisibleChange = (visible: boolean, context: PopupVisibleChangeContext) => {
|
|
|
|
if (!visible && context.trigger === 'document') {
|
|
|
|
isColoPickerDisplay.value = visible;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleCopy = () => {
|
|
|
|
const text = JSON.stringify(formData.value, null, 4);
|
|
|
|
const { toClipboard } = useClipboard();
|
|
|
|
toClipboard(text)
|
|
|
|
.then(() => {
|
|
|
|
MessagePlugin.closeAll();
|
|
|
|
MessagePlugin.success('复制成功');
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
MessagePlugin.closeAll();
|
|
|
|
MessagePlugin.error('复制失败');
|
2021-12-22 12:07:29 +08:00
|
|
|
});
|
2022-02-16 19:56:36 +08:00
|
|
|
};
|
|
|
|
const getModeIcon = (mode: string) => {
|
|
|
|
if (mode === 'light') {
|
|
|
|
return SettingLightIcon;
|
|
|
|
}
|
|
|
|
if (mode === 'dark') {
|
|
|
|
return SettingDarkIcon;
|
|
|
|
}
|
|
|
|
return SettingAutoIcon;
|
|
|
|
};
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
const handleCloseDrawer = () => {
|
|
|
|
store.commit('setting/toggleSettingPanel', false);
|
|
|
|
};
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-16 19:56:36 +08:00
|
|
|
const getThumbnailUrl = (name: string): string => {
|
|
|
|
return `https://tdesign.gtimg.com/tdesign-pro/setting/${name}.png`;
|
|
|
|
};
|
2021-12-22 12:07:29 +08:00
|
|
|
|
2022-02-19 16:23:32 +08:00
|
|
|
watchEffect(() => {
|
|
|
|
store.dispatch('setting/changeTheme', formData.value);
|
|
|
|
});
|
2021-12-12 01:04:13 +08:00
|
|
|
</script>
|
|
|
|
<style lang="less">
|
|
|
|
@import '@/style/variables';
|
2021-12-22 12:07:29 +08:00
|
|
|
.hu-color-picker {
|
|
|
|
width: 220px !important;
|
|
|
|
}
|
2021-12-12 01:04:13 +08:00
|
|
|
.tdesign-setting {
|
|
|
|
z-index: 100;
|
|
|
|
position: fixed;
|
|
|
|
bottom: 200px;
|
|
|
|
right: 0;
|
|
|
|
transition: transform 0.3s cubic-bezier(0.7, 0.3, 0.1, 1), visibility 0.3s cubic-bezier(0.7, 0.3, 0.1, 1);
|
|
|
|
height: 40px;
|
|
|
|
width: 40px;
|
|
|
|
border-radius: 20px 0 0 20px;
|
|
|
|
transition: all 0.3s;
|
|
|
|
|
|
|
|
.t-icon {
|
|
|
|
margin-left: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.tdesign-setting-text {
|
|
|
|
font-size: 12px;
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
width: 96px;
|
|
|
|
|
|
|
|
.tdesign-setting-text {
|
|
|
|
display: inline-block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.setting-layout-color-group {
|
|
|
|
display: inline-flex;
|
2021-12-22 12:07:29 +08:00
|
|
|
width: 36px;
|
|
|
|
height: 36px;
|
2021-12-12 01:04:13 +08:00
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
border-radius: 50% !important;
|
2021-12-22 12:07:29 +08:00
|
|
|
padding: 6px !important;
|
2021-12-12 01:04:13 +08:00
|
|
|
border: 2px solid transparent !important;
|
|
|
|
|
2021-12-22 12:07:29 +08:00
|
|
|
> .t-radio-button__label {
|
2021-12-12 01:04:13 +08:00
|
|
|
display: inline-flex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.tdesign-setting-close {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 200px;
|
|
|
|
right: 300px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.setting-group-title {
|
|
|
|
font-size: 14px;
|
|
|
|
line-height: 22px;
|
|
|
|
margin: 32px 0 24px 0;
|
|
|
|
text-align: left;
|
|
|
|
font-family: PingFang SC;
|
|
|
|
font-style: normal;
|
|
|
|
font-weight: 500;
|
|
|
|
color: @text-color-primary;
|
|
|
|
}
|
|
|
|
|
|
|
|
.setting-link {
|
|
|
|
cursor: pointer;
|
|
|
|
color: @brand-color;
|
|
|
|
margin-bottom: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.setting-info {
|
|
|
|
position: absolute;
|
|
|
|
padding: 24px;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
line-height: 20px;
|
|
|
|
font-size: 12px;
|
|
|
|
text-align: center;
|
|
|
|
color: @text-color-placeholder;
|
|
|
|
width: 100%;
|
|
|
|
background: @bg-color-container;
|
|
|
|
}
|
|
|
|
|
|
|
|
.setting-drawer-container {
|
|
|
|
.setting-container {
|
|
|
|
padding-bottom: 100px;
|
|
|
|
}
|
2021-12-24 11:24:14 +08:00
|
|
|
.t-radio-group.t-size-m {
|
2021-12-12 01:04:13 +08:00
|
|
|
min-height: 32px;
|
|
|
|
width: 100%;
|
|
|
|
height: auto;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.setting-layout-drawer {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
|
|
|
.t-radio-button {
|
|
|
|
display: inline-flex;
|
|
|
|
max-height: 78px;
|
2021-12-22 12:07:29 +08:00
|
|
|
padding: 8px;
|
2021-12-12 01:04:13 +08:00
|
|
|
border-radius: @border-radius;
|
|
|
|
border: 2px solid #e3e6eb;
|
|
|
|
> .t-radio-button__label {
|
|
|
|
display: inline-flex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.t-is-checked {
|
|
|
|
border: 2px solid @brand-color !important;
|
|
|
|
}
|
|
|
|
|
2021-12-24 11:24:14 +08:00
|
|
|
.t-form__controls-content {
|
2021-12-12 01:04:13 +08:00
|
|
|
justify-content: end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-24 11:24:14 +08:00
|
|
|
.t-form__controls-content {
|
2021-12-12 01:04:13 +08:00
|
|
|
justify-content: end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.setting-route-theme {
|
|
|
|
.t-form__label {
|
|
|
|
min-width: 310px !important;
|
|
|
|
color: @text-color-secondary;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.setting-color-theme {
|
|
|
|
.setting-layout-drawer {
|
|
|
|
.t-radio-button {
|
|
|
|
height: 32px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:last-child {
|
|
|
|
margin-right: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|