mirror of
				https://github.com/pure-admin/vue-pure-admin.git
				synced 2025-11-03 13:44:47 +08:00 
			
		
		
		
	refactor: setting
This commit is contained in:
		
							parent
							
								
									782cea9995
								
							
						
					
					
						commit
						e98dee9f0a
					
				@ -7,6 +7,9 @@
 | 
				
			|||||||
  "Locale": "zh",
 | 
					  "Locale": "zh",
 | 
				
			||||||
  "Layout": "vertical",
 | 
					  "Layout": "vertical",
 | 
				
			||||||
  "Theme": "default",
 | 
					  "Theme": "default",
 | 
				
			||||||
 | 
					  "Grey": false,
 | 
				
			||||||
 | 
					  "Weak": false,
 | 
				
			||||||
 | 
					  "HideTabs": false,
 | 
				
			||||||
  "MapConfigure": {
 | 
					  "MapConfigure": {
 | 
				
			||||||
    "amapKey": "97b3248d1553172e81f168cf94ea667e",
 | 
					    "amapKey": "97b3248d1553172e81f168cf94ea667e",
 | 
				
			||||||
    "baiduKey": "wTHbkkEweiFqZLKunMIjcrb2RcqNXkhc",
 | 
					    "baiduKey": "wTHbkkEweiFqZLKunMIjcrb2RcqNXkhc",
 | 
				
			||||||
 | 
				
			|||||||
@ -17,6 +17,8 @@ const props = defineProps({
 | 
				
			|||||||
const keepAlive: Boolean = ref(
 | 
					const keepAlive: Boolean = ref(
 | 
				
			||||||
  getCurrentInstance().appContext.config.globalProperties.$config?.KeepAlive
 | 
					  getCurrentInstance().appContext.config.globalProperties.$config?.KeepAlive
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					const instance =
 | 
				
			||||||
 | 
					  getCurrentInstance().appContext.app.config.globalProperties.$storage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const transitions = computed(() => {
 | 
					const transitions = computed(() => {
 | 
				
			||||||
  return route => {
 | 
					  return route => {
 | 
				
			||||||
@ -24,6 +26,13 @@ const transitions = computed(() => {
 | 
				
			|||||||
  };
 | 
					  };
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const hideTabs = computed(() => {
 | 
				
			||||||
 | 
					  return instance?.sets.hideTabs;
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					const layout = computed(() => {
 | 
				
			||||||
 | 
					  return instance?.layout.layout === "vertical";
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const transitionMain = defineComponent({
 | 
					const transitionMain = defineComponent({
 | 
				
			||||||
  render() {
 | 
					  render() {
 | 
				
			||||||
    return h(
 | 
					    return h(
 | 
				
			||||||
@ -62,6 +71,12 @@ const transitionMain = defineComponent({
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <section
 | 
					  <section
 | 
				
			||||||
    :class="[props.fixedHeader ? 'app-main' : 'app-main-nofixed-header']"
 | 
					    :class="[props.fixedHeader ? 'app-main' : 'app-main-nofixed-header']"
 | 
				
			||||||
 | 
					    :style="[
 | 
				
			||||||
 | 
					      hideTabs && layout ? 'padding-top: 48px;' : '',
 | 
				
			||||||
 | 
					      !hideTabs && layout ? 'padding-top: 85px;' : '',
 | 
				
			||||||
 | 
					      hideTabs && !layout ? 'padding-top: 62px' : '',
 | 
				
			||||||
 | 
					      !hideTabs && !layout ? 'padding-top: 98px;' : ''
 | 
				
			||||||
 | 
					    ]"
 | 
				
			||||||
  >
 | 
					  >
 | 
				
			||||||
    <router-view>
 | 
					    <router-view>
 | 
				
			||||||
      <template #default="{ Component, route }">
 | 
					      <template #default="{ Component, route }">
 | 
				
			||||||
 | 
				
			|||||||
@ -5,6 +5,7 @@ import {
 | 
				
			|||||||
  unref,
 | 
					  unref,
 | 
				
			||||||
  watch,
 | 
					  watch,
 | 
				
			||||||
  computed,
 | 
					  computed,
 | 
				
			||||||
 | 
					  nextTick,
 | 
				
			||||||
  useCssModule,
 | 
					  useCssModule,
 | 
				
			||||||
  getCurrentInstance
 | 
					  getCurrentInstance
 | 
				
			||||||
} from "vue";
 | 
					} from "vue";
 | 
				
			||||||
@ -72,32 +73,12 @@ const markValue = ref(storageLocal.getItem("showModel") || "smart");
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const logoVal = ref(storageLocal.getItem("logoVal") || "1");
 | 
					const logoVal = ref(storageLocal.getItem("logoVal") || "1");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const localOperate = (key: string, value?: any, model?: string): any => {
 | 
					 | 
				
			||||||
  model && model === "set"
 | 
					 | 
				
			||||||
    ? storageLocal.setItem(key, value)
 | 
					 | 
				
			||||||
    : storageLocal.getItem(key);
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const settings = reactive({
 | 
					const settings = reactive({
 | 
				
			||||||
  greyVal: storageLocal.getItem("greyVal"),
 | 
					  greyVal: instance.sets.grey,
 | 
				
			||||||
  weekVal: storageLocal.getItem("weekVal"),
 | 
					  weakVal: instance.sets.weak,
 | 
				
			||||||
  tagsVal: storageLocal.getItem("tagsVal")
 | 
					  tabsVal: instance.sets.hideTabs
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
settings.greyVal === null
 | 
					 | 
				
			||||||
  ? localOperate("greyVal", false, "set")
 | 
					 | 
				
			||||||
  : document.querySelector("html")?.setAttribute("class", "html-grey");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
settings.weekVal === null
 | 
					 | 
				
			||||||
  ? localOperate("weekVal", false, "set")
 | 
					 | 
				
			||||||
  : document.querySelector("html")?.setAttribute("class", "html-weakness");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if (settings.tagsVal === null) {
 | 
					 | 
				
			||||||
  localOperate("tagsVal", false, "set");
 | 
					 | 
				
			||||||
  settings.tagsVal = false;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
window.document.body.setAttribute("data-show-tag", settings.tagsVal);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) {
 | 
					function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) {
 | 
				
			||||||
  const targetEl = target || document.body;
 | 
					  const targetEl = target || document.body;
 | 
				
			||||||
  let { className } = targetEl;
 | 
					  let { className } = targetEl;
 | 
				
			||||||
@ -108,35 +89,52 @@ function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) {
 | 
				
			|||||||
// 灰色模式设置
 | 
					// 灰色模式设置
 | 
				
			||||||
const greyChange = ({ value }): void => {
 | 
					const greyChange = ({ value }): void => {
 | 
				
			||||||
  toggleClass(settings.greyVal, "html-grey", document.querySelector("html"));
 | 
					  toggleClass(settings.greyVal, "html-grey", document.querySelector("html"));
 | 
				
			||||||
  value
 | 
					  instance.sets = {
 | 
				
			||||||
    ? localOperate("greyVal", true, "set")
 | 
					    grey: value,
 | 
				
			||||||
    : localOperate("greyVal", false, "set");
 | 
					    weak: instance.sets.weak,
 | 
				
			||||||
 | 
					    hideTabs: instance.sets.hideTabs
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 色弱模式设置
 | 
					// 色弱模式设置
 | 
				
			||||||
const weekChange = ({ value }): void => {
 | 
					const weekChange = ({ value }): void => {
 | 
				
			||||||
  toggleClass(
 | 
					  toggleClass(
 | 
				
			||||||
    settings.weekVal,
 | 
					    settings.weakVal,
 | 
				
			||||||
    "html-weakness",
 | 
					    "html-weakness",
 | 
				
			||||||
    document.querySelector("html")
 | 
					    document.querySelector("html")
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
  value
 | 
					  instance.sets = {
 | 
				
			||||||
    ? localOperate("weekVal", true, "set")
 | 
					    grey: instance.sets.grey,
 | 
				
			||||||
    : localOperate("weekVal", false, "set");
 | 
					    weak: value,
 | 
				
			||||||
 | 
					    hideTabs: instance.sets.hideTabs
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const tagsChange = () => {
 | 
					const tagsChange = () => {
 | 
				
			||||||
  let showVal = settings.tagsVal;
 | 
					  let showVal = settings.tabsVal;
 | 
				
			||||||
  showVal
 | 
					  instance.sets = {
 | 
				
			||||||
    ? storageLocal.setItem("tagsVal", true)
 | 
					    grey: instance.sets.grey,
 | 
				
			||||||
    : storageLocal.setItem("tagsVal", false);
 | 
					    weak: instance.sets.weak,
 | 
				
			||||||
 | 
					    hideTabs: showVal
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
  emitter.emit("tagViewsChange", showVal);
 | 
					  emitter.emit("tagViewsChange", showVal);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//初始化项目配置
 | 
				
			||||||
 | 
					nextTick(() => {
 | 
				
			||||||
 | 
					  settings.greyVal &&
 | 
				
			||||||
 | 
					    document.querySelector("html")?.setAttribute("class", "html-grey");
 | 
				
			||||||
 | 
					  settings.weakVal &&
 | 
				
			||||||
 | 
					    document.querySelector("html")?.setAttribute("class", "html-weakness");
 | 
				
			||||||
 | 
					  settings.tabsVal && tagsChange();
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 清空缓存并返回登录页
 | 
					// 清空缓存并返回登录页
 | 
				
			||||||
function onReset() {
 | 
					function onReset() {
 | 
				
			||||||
  storageLocal.clear();
 | 
					  storageLocal.clear();
 | 
				
			||||||
  storageSession.clear();
 | 
					  storageSession.clear();
 | 
				
			||||||
 | 
					  toggleClass(false, "html-grey", document.querySelector("html"));
 | 
				
			||||||
 | 
					  toggleClass(false, "html-weakness", document.querySelector("html"));
 | 
				
			||||||
  router.push("/login");
 | 
					  router.push("/login");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -271,7 +269,7 @@ function setLayoutThemeColor(theme: string) {
 | 
				
			|||||||
      <li>
 | 
					      <li>
 | 
				
			||||||
        <span>色弱模式</span>
 | 
					        <span>色弱模式</span>
 | 
				
			||||||
        <el-switch
 | 
					        <el-switch
 | 
				
			||||||
          v-model="settings.weekVal"
 | 
					          v-model="settings.weakVal"
 | 
				
			||||||
          inline-prompt
 | 
					          inline-prompt
 | 
				
			||||||
          inactive-color="#a6a6a6"
 | 
					          inactive-color="#a6a6a6"
 | 
				
			||||||
          active-text="开"
 | 
					          active-text="开"
 | 
				
			||||||
@ -283,7 +281,7 @@ function setLayoutThemeColor(theme: string) {
 | 
				
			|||||||
      <li>
 | 
					      <li>
 | 
				
			||||||
        <span>隐藏标签页</span>
 | 
					        <span>隐藏标签页</span>
 | 
				
			||||||
        <el-switch
 | 
					        <el-switch
 | 
				
			||||||
          v-model="settings.tagsVal"
 | 
					          v-model="settings.tabsVal"
 | 
				
			||||||
          inline-prompt
 | 
					          inline-prompt
 | 
				
			||||||
          inactive-color="#a6a6a6"
 | 
					          inactive-color="#a6a6a6"
 | 
				
			||||||
          active-text="开"
 | 
					          active-text="开"
 | 
				
			||||||
 | 
				
			|||||||
@ -447,7 +447,6 @@ onBeforeMount(() => {
 | 
				
			|||||||
  emitter.on("tagViewsChange", key => {
 | 
					  emitter.on("tagViewsChange", key => {
 | 
				
			||||||
    if (unref(showTags) === key) return;
 | 
					    if (unref(showTags) === key) return;
 | 
				
			||||||
    showTags.value = key;
 | 
					    showTags.value = key;
 | 
				
			||||||
    window.document.body.setAttribute("data-show-tag", key);
 | 
					 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // 改变标签风格
 | 
					  // 改变标签风格
 | 
				
			||||||
 | 
				
			|||||||
@ -57,6 +57,15 @@ const layout = computed(() => {
 | 
				
			|||||||
      theme: instance.$config?.Theme ?? "default"
 | 
					      theme: instance.$config?.Theme ?? "default"
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  // 灰色模式、色弱模式、隐藏标签页
 | 
				
			||||||
 | 
					  if (!instance.$storage.sets) {
 | 
				
			||||||
 | 
					    // eslint-disable-next-line
 | 
				
			||||||
 | 
					    instance.$storage.sets = {
 | 
				
			||||||
 | 
					      grey: instance.$config?.Grey ?? false,
 | 
				
			||||||
 | 
					      weak: instance.$config?.Weak ?? false,
 | 
				
			||||||
 | 
					      hideTabs: instance.$config?.HideTabs ?? false
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  return instance.$storage?.layout.layout;
 | 
					  return instance.$storage?.layout.layout;
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -80,6 +89,10 @@ const set: setType = reactive({
 | 
				
			|||||||
      withoutAnimation: set.sidebar.withoutAnimation,
 | 
					      withoutAnimation: set.sidebar.withoutAnimation,
 | 
				
			||||||
      mobile: set.device === "mobile"
 | 
					      mobile: set.device === "mobile"
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					  }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  hideTabs: computed(() => {
 | 
				
			||||||
 | 
					    return instance.$storage?.sets.hideTabs;
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -144,7 +157,14 @@ const layoutHeader = defineComponent({
 | 
				
			|||||||
  render() {
 | 
					  render() {
 | 
				
			||||||
    return h(
 | 
					    return h(
 | 
				
			||||||
      "div",
 | 
					      "div",
 | 
				
			||||||
      { class: { "fixed-header": set.fixedHeader } },
 | 
					      {
 | 
				
			||||||
 | 
					        class: { "fixed-header": set.fixedHeader },
 | 
				
			||||||
 | 
					        style: [
 | 
				
			||||||
 | 
					          set.hideTabs && layout.value.includes("horizontal")
 | 
				
			||||||
 | 
					            ? "box-shadow: 0 1px 4px rgb(0 21 41 / 8%);"
 | 
				
			||||||
 | 
					            : ""
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        default: () => [
 | 
					        default: () => [
 | 
				
			||||||
          !hiddenSideBar.value && layout.value.includes("vertical")
 | 
					          !hiddenSideBar.value && layout.value.includes("vertical")
 | 
				
			||||||
 | 
				
			|||||||
@ -47,6 +47,7 @@ export interface setType {
 | 
				
			|||||||
    withoutAnimation: boolean;
 | 
					    withoutAnimation: boolean;
 | 
				
			||||||
    mobile: boolean;
 | 
					    mobile: boolean;
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					  hideTabs: boolean;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type childrenType = {
 | 
					export type childrenType = {
 | 
				
			||||||
 | 
				
			|||||||
@ -640,35 +640,3 @@ body[layout="horizontal"] {
 | 
				
			|||||||
    transition: none !important;
 | 
					    transition: none !important;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
// vertical模式下不隐藏标签页
 | 
					 | 
				
			||||||
body[layout="vertical"][data-show-tag="false"] {
 | 
					 | 
				
			||||||
  .fixed-header + .app-main {
 | 
					 | 
				
			||||||
    padding-top: 85px;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// vertical模式下隐藏标签页
 | 
					 | 
				
			||||||
body[layout="vertical"][data-show-tag="true"] {
 | 
					 | 
				
			||||||
  .fixed-header + .app-main {
 | 
					 | 
				
			||||||
    padding-top: 48px;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// horizontal模式下不隐藏标签页
 | 
					 | 
				
			||||||
body[layout="horizontal"][data-show-tag="false"] {
 | 
					 | 
				
			||||||
  .fixed-header + .app-main {
 | 
					 | 
				
			||||||
    padding-top: 98px;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// horizontal模式下隐藏标签页
 | 
					 | 
				
			||||||
body[layout="horizontal"][data-show-tag="true"] {
 | 
					 | 
				
			||||||
  .fixed-header {
 | 
					 | 
				
			||||||
    box-shadow: 0 1px 4px rgb(0 21 41 / 8%);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  .fixed-header + .app-main {
 | 
					 | 
				
			||||||
    padding-top: 62px;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -33,6 +33,14 @@ export const injectResponsiveStorage = (app: App, config: ServerConfigs) => {
 | 
				
			|||||||
        layout: config.Layout ?? "vertical",
 | 
					        layout: config.Layout ?? "vertical",
 | 
				
			||||||
        theme: config.Theme ?? "default"
 | 
					        theme: config.Theme ?? "default"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    sets: {
 | 
				
			||||||
 | 
					      type: Object,
 | 
				
			||||||
 | 
					      default: Storage.getData(undefined, "sets") ?? {
 | 
				
			||||||
 | 
					        grey: config.Grey,
 | 
				
			||||||
 | 
					        weak: config.Weak,
 | 
				
			||||||
 | 
					        hideTabs: config.HideTabs
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										3
									
								
								types/global.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								types/global.d.ts
									
									
									
									
										vendored
									
									
								
							@ -91,6 +91,9 @@ declare global {
 | 
				
			|||||||
    Locale?: string;
 | 
					    Locale?: string;
 | 
				
			||||||
    Layout?: string;
 | 
					    Layout?: string;
 | 
				
			||||||
    Theme?: string;
 | 
					    Theme?: string;
 | 
				
			||||||
 | 
					    Grey?: boolean;
 | 
				
			||||||
 | 
					    Weak?: boolean;
 | 
				
			||||||
 | 
					    HideTabs?: boolean;
 | 
				
			||||||
    MapConfigure?: {
 | 
					    MapConfigure?: {
 | 
				
			||||||
      amapKey?: string;
 | 
					      amapKey?: string;
 | 
				
			||||||
      baiduKey?: string;
 | 
					      baiduKey?: string;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user