feat:新增开启水印配置
This commit is contained in:
parent
6b505312d9
commit
47937c2e87
@ -59,6 +59,12 @@
|
||||
<el-switch v-model="showFooter" class="drawer-switch" />
|
||||
</span>
|
||||
</div>
|
||||
<div class="drawer-item">
|
||||
<span>开启水印</span>
|
||||
<span class="comp-style">
|
||||
<el-switch v-model="showWatermark" class="drawer-switch" />
|
||||
</span>
|
||||
</div>
|
||||
<!-- <div class="drawer-item">
|
||||
<span>{{ $t('layout.fixed') }} Header</span>
|
||||
<span class="comp-style">
|
||||
@ -93,10 +99,11 @@ import 'element-plus/theme-chalk/dark/css-vars.css'
|
||||
import { useDark, useCycleList, useColorMode } from '@vueuse/core'
|
||||
import { useDynamicTitle } from '@/utils/dynamicTitle'
|
||||
import { getLightColor } from '@/utils/index'
|
||||
import { getmark } from '@/utils/wartermark'
|
||||
import useAppStore from '@/store/modules/app'
|
||||
import useSettingsStore from '@/store/modules/settings'
|
||||
import usePermissionStore from '@/store/modules/permission'
|
||||
|
||||
import useUserStore from '@/store/modules/user'
|
||||
const { proxy } = getCurrentInstance()
|
||||
const appStore = useAppStore()
|
||||
const settingsStore = useSettingsStore()
|
||||
@ -106,7 +113,7 @@ const theme = ref(settingsStore.theme)
|
||||
const sideTheme = ref(settingsStore.sideTheme)
|
||||
const storeSettings = computed(() => settingsStore)
|
||||
const predefineColors = ref(['#409EFF', '#ff4500', '#ff8c00', '#ffd700', '#90ee90', '#00ced1', '#1e90ff', '#c71585'])
|
||||
|
||||
const { setWatermark, removeWatermark } = getmark()
|
||||
// 可以手动更改当前值 model.value = 'cafe'
|
||||
const mode = useColorMode({
|
||||
modes: {
|
||||
@ -166,6 +173,19 @@ const dynamicTitle = computed({
|
||||
useDynamicTitle()
|
||||
},
|
||||
})
|
||||
/**是否显示水印 */
|
||||
const showWatermark = computed({
|
||||
get: () => storeSettings.value.showWatermark,
|
||||
set: (val) => {
|
||||
settingsStore.changeSetting({ key: 'showWatermark', value: val })
|
||||
changeWatermark()
|
||||
},
|
||||
})
|
||||
const changeWatermark = () => {
|
||||
storeSettings.value.showWatermark ? setWatermark(useUserStore().userInfo.userName) : removeWatermark()
|
||||
}
|
||||
// 开启水印
|
||||
changeWatermark()
|
||||
// 监控主题颜色
|
||||
watch(
|
||||
() => theme,
|
||||
@ -189,7 +209,6 @@ watch(
|
||||
watch(
|
||||
() => mode,
|
||||
(val) => {
|
||||
console.log(val.value)
|
||||
if (val.value === 'dark') {
|
||||
handleTheme('')
|
||||
}
|
||||
@ -231,6 +250,7 @@ function saveSetting() {
|
||||
sideTheme: storeSettings.value.sideTheme,
|
||||
theme: storeSettings.value.theme,
|
||||
showFooter: storeSettings.value.showFooter,
|
||||
showWatermark: storeSettings.value.showWatermark,
|
||||
}
|
||||
localStorage.setItem('layout-setting', JSON.stringify(layoutSetting))
|
||||
setTimeout(proxy.$modal.closeLoading(), 100)
|
||||
|
||||
@ -59,5 +59,13 @@ export default {
|
||||
/**
|
||||
* 是否显示底部栏
|
||||
*/
|
||||
showFooter: true
|
||||
showFooter: true,
|
||||
/**
|
||||
* 是否显示水印
|
||||
*/
|
||||
showWatermark: false,
|
||||
/**
|
||||
* 水印文案
|
||||
*/
|
||||
watermarkText: 'ZRAdmin.NET'
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
import defaultSettings from '@/settings'
|
||||
import { useDynamicTitle } from '@/utils/dynamicTitle'
|
||||
|
||||
const { sideTheme, theme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo, dynamicTitle, showFooter } = defaultSettings
|
||||
const { sideTheme, theme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo, dynamicTitle, showFooter, showWatermark, watermarkText } = defaultSettings
|
||||
|
||||
const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || ''
|
||||
const useSettingsStore = defineStore('settings', {
|
||||
@ -15,7 +15,9 @@ const useSettingsStore = defineStore('settings', {
|
||||
fixedHeader: storageSetting.fixedHeader === undefined ? fixedHeader : storageSetting.fixedHeader,
|
||||
sidebarLogo: storageSetting.sidebarLogo === undefined ? sidebarLogo : storageSetting.sidebarLogo,
|
||||
dynamicTitle: storageSetting.dynamicTitle === undefined ? dynamicTitle : storageSetting.dynamicTitle,
|
||||
showFooter: storageSetting.showFooter === undefined ? showFooter : storageSetting.showFooter
|
||||
showFooter: storageSetting.showFooter === undefined ? showFooter : storageSetting.showFooter,
|
||||
showWatermark: storageSetting.showWatermark === undefined ? showWatermark : storageSetting.showWatermark,
|
||||
watermarkText: storageSetting.watermarkText === undefined ? watermarkText : storageSetting.watermarkText
|
||||
}),
|
||||
actions: {
|
||||
// 修改布局设置
|
||||
@ -32,30 +34,4 @@ const useSettingsStore = defineStore('settings', {
|
||||
}
|
||||
}
|
||||
})
|
||||
export default useSettingsStore
|
||||
// const mutations = {
|
||||
// CHANGE_SETTING: (state, { key, value }) => {
|
||||
// if (state.hasOwnProperty(key)) {
|
||||
// state[key] = value
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// const actions = {
|
||||
// // 修改布局设置
|
||||
// changeSetting({ commit }, data) {
|
||||
// commit('CHANGE_SETTING', data)
|
||||
// },
|
||||
// // 设置网页标题
|
||||
// setTitle({ commit }, title) {
|
||||
// state.title = title
|
||||
// useDynamicTitle();
|
||||
// }
|
||||
// }
|
||||
|
||||
// export default {
|
||||
// namespaced: true,
|
||||
// state,
|
||||
// mutations,
|
||||
// actions
|
||||
// }
|
||||
export default useSettingsStore
|
||||
62
src/utils/wartermark.js
Normal file
62
src/utils/wartermark.js
Normal file
@ -0,0 +1,62 @@
|
||||
export const getmark = () => {
|
||||
const setWatermark = (str) => {
|
||||
const id = "1.23452384164.123412416";
|
||||
|
||||
if (document.getElementById(id) !== null) {
|
||||
document.body.removeChild(document.getElementById(id));
|
||||
}
|
||||
|
||||
//创建一个画布
|
||||
const can = document.createElement("canvas");
|
||||
//设置画布的长宽
|
||||
can.width = 150;
|
||||
can.height = 120;
|
||||
|
||||
const cans = can.getContext("2d");
|
||||
//旋转角度
|
||||
cans.rotate((-15 * Math.PI) / 180);
|
||||
cans.font = "18px Vedana";
|
||||
//设置填充绘画的颜色、渐变或者模式
|
||||
cans.fillStyle = "rgba(200, 200, 200, 0.40)";
|
||||
//设置文本内容的当前对齐方式
|
||||
cans.textAlign = "left";
|
||||
//设置在绘制文本时使用的当前文本基线
|
||||
// cans.textBaseline = "Middle";
|
||||
//在画布上绘制填色的文本(输出的文本,开始绘制文本的X坐标位置,开始绘制文本的Y坐标位置)
|
||||
cans.fillText(str, can.width / 8, can.height / 2);
|
||||
|
||||
const div = document.createElement("div");
|
||||
div.id = id;
|
||||
div.style.pointerEvents = "none";
|
||||
div.style.top = "30px";
|
||||
div.style.left = "0px";
|
||||
div.style.position = "fixed";
|
||||
div.style.zIndex = "100000";
|
||||
div.style.width = document.documentElement.clientWidth + "px";
|
||||
div.style.height = document.documentElement.clientHeight + "px";
|
||||
div.style.background =
|
||||
"url(" + can.toDataURL("image/png") + ") left top repeat";
|
||||
document.body.appendChild(div);
|
||||
return id;
|
||||
};
|
||||
|
||||
// 该方法只允许调用一次
|
||||
const watermark = (str) => {
|
||||
let id = setWatermark(str);
|
||||
setInterval(() => {
|
||||
if (document.getElementById(id) === null) {
|
||||
id = setWatermark(str);
|
||||
}
|
||||
}, 500);
|
||||
window.onresize = () => {
|
||||
setWatermark(str);
|
||||
};
|
||||
};
|
||||
const removeWatermark = () => {
|
||||
const id = "1.23452384164.123412416";
|
||||
if (document.getElementById(id) !== null) {
|
||||
document.body.removeChild(document.getElementById(id));
|
||||
}
|
||||
}
|
||||
return { setWatermark, watermark, removeWatermark };
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user