mirror of
https://github.com/pure-admin/pure-admin-thin.git
synced 2025-12-15 06:40:33 +08:00
release: update 5.1.0
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import type { App } from "vue";
|
||||
import * as echarts from "echarts/core";
|
||||
import { CanvasRenderer } from "echarts/renderers";
|
||||
import { PieChart, BarChart, LineChart } from "echarts/charts";
|
||||
import { CanvasRenderer, SVGRenderer } from "echarts/renderers";
|
||||
import {
|
||||
GridComponent,
|
||||
TitleComponent,
|
||||
PolarComponent,
|
||||
LegendComponent,
|
||||
GraphicComponent,
|
||||
ToolboxComponent,
|
||||
@@ -20,8 +21,10 @@ use([
|
||||
BarChart,
|
||||
LineChart,
|
||||
CanvasRenderer,
|
||||
SVGRenderer,
|
||||
GridComponent,
|
||||
TitleComponent,
|
||||
PolarComponent,
|
||||
LegendComponent,
|
||||
GraphicComponent,
|
||||
ToolboxComponent,
|
||||
@@ -31,9 +34,8 @@ use([
|
||||
]);
|
||||
|
||||
/**
|
||||
* @description 按需引入echarts
|
||||
* @see {@link https://echarts.apache.org/handbook/zh/basics/import#%E6%8C%89%E9%9C%80%E5%BC%95%E5%85%A5-echarts-%E5%9B%BE%E8%A1%A8%E5%92%8C%E7%BB%84%E4%BB%B6}
|
||||
* @see 温馨提示:必须将 `$echarts` 添加到全局 `globalProperties` ,为了配合 https://pure-admin-utils.netlify.app/hooks/useEcharts/useEcharts.html 使用
|
||||
* @description 按需引入echarts,具体看 https://echarts.apache.org/handbook/zh/basics/import/#%E5%9C%A8-typescript-%E4%B8%AD%E6%8C%89%E9%9C%80%E5%BC%95%E5%85%A5
|
||||
* @see 温馨提示:必须将 `$echarts` 添加到全局 `globalProperties` ,具体看 https://pure-admin-utils.netlify.app/hooks/useECharts/useECharts#%E4%BD%BF%E7%94%A8%E5%89%8D%E6%8F%90
|
||||
*/
|
||||
export function useEcharts(app: App) {
|
||||
app.config.globalProperties.$echarts = echarts;
|
||||
@@ -1,141 +0,0 @@
|
||||
import { App, Component } from "vue";
|
||||
import {
|
||||
ElTag,
|
||||
ElAffix,
|
||||
ElSkeleton,
|
||||
ElBreadcrumb,
|
||||
ElBreadcrumbItem,
|
||||
ElScrollbar,
|
||||
ElSubMenu,
|
||||
ElButton,
|
||||
ElCol,
|
||||
ElRow,
|
||||
ElSpace,
|
||||
ElDivider,
|
||||
ElCard,
|
||||
ElDropdown,
|
||||
ElDialog,
|
||||
ElMenu,
|
||||
ElMenuItem,
|
||||
ElDropdownItem,
|
||||
ElDropdownMenu,
|
||||
ElIcon,
|
||||
ElInput,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElPopover,
|
||||
ElPopper,
|
||||
ElTooltip,
|
||||
ElDrawer,
|
||||
ElPagination,
|
||||
ElAlert,
|
||||
ElRadio,
|
||||
ElRadioButton,
|
||||
ElRadioGroup,
|
||||
ElDescriptions,
|
||||
ElDescriptionsItem,
|
||||
ElBacktop,
|
||||
ElSwitch,
|
||||
ElBadge,
|
||||
ElTabs,
|
||||
ElTabPane,
|
||||
ElAvatar,
|
||||
ElEmpty,
|
||||
ElCollapse,
|
||||
ElCollapseItem,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
ElLink,
|
||||
ElColorPicker,
|
||||
ElSelect,
|
||||
ElOption,
|
||||
ElTimeline,
|
||||
ElTimelineItem,
|
||||
ElResult,
|
||||
ElSteps,
|
||||
ElStep,
|
||||
ElTree,
|
||||
ElTreeV2,
|
||||
ElPopconfirm,
|
||||
ElCheckbox,
|
||||
ElCheckboxGroup,
|
||||
// 指令
|
||||
ElLoading,
|
||||
ElInfiniteScroll
|
||||
} from "element-plus";
|
||||
|
||||
// Directives
|
||||
const plugins = [ElLoading, ElInfiniteScroll];
|
||||
|
||||
const components = [
|
||||
ElTag,
|
||||
ElAffix,
|
||||
ElSkeleton,
|
||||
ElBreadcrumb,
|
||||
ElBreadcrumbItem,
|
||||
ElScrollbar,
|
||||
ElSubMenu,
|
||||
ElButton,
|
||||
ElCol,
|
||||
ElRow,
|
||||
ElSpace,
|
||||
ElDivider,
|
||||
ElCard,
|
||||
ElDropdown,
|
||||
ElDialog,
|
||||
ElMenu,
|
||||
ElMenuItem,
|
||||
ElDropdownItem,
|
||||
ElDropdownMenu,
|
||||
ElIcon,
|
||||
ElInput,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElPopover,
|
||||
ElPopper,
|
||||
ElTooltip,
|
||||
ElDrawer,
|
||||
ElPagination,
|
||||
ElAlert,
|
||||
ElRadio,
|
||||
ElRadioButton,
|
||||
ElRadioGroup,
|
||||
ElDescriptions,
|
||||
ElDescriptionsItem,
|
||||
ElBacktop,
|
||||
ElSwitch,
|
||||
ElBadge,
|
||||
ElTabs,
|
||||
ElTabPane,
|
||||
ElAvatar,
|
||||
ElEmpty,
|
||||
ElCollapse,
|
||||
ElCollapseItem,
|
||||
ElTree,
|
||||
ElTreeV2,
|
||||
ElPopconfirm,
|
||||
ElCheckbox,
|
||||
ElCheckboxGroup,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
ElLink,
|
||||
ElColorPicker,
|
||||
ElSelect,
|
||||
ElOption,
|
||||
ElTimeline,
|
||||
ElTimelineItem,
|
||||
ElResult,
|
||||
ElSteps,
|
||||
ElStep
|
||||
];
|
||||
|
||||
export function useElementPlus(app: App) {
|
||||
// 注册组件
|
||||
components.forEach((component: Component) => {
|
||||
app.component(component.name, component);
|
||||
});
|
||||
// 注册指令
|
||||
plugins.forEach(plugin => {
|
||||
app.use(plugin);
|
||||
});
|
||||
}
|
||||
242
src/plugins/elementPlus.ts
Normal file
242
src/plugins/elementPlus.ts
Normal file
@@ -0,0 +1,242 @@
|
||||
// 按需引入element-plus(该方法稳定且明确。当然也支持:https://element-plus.org/zh-CN/guide/quickstart.html#%E6%8C%89%E9%9C%80%E5%AF%BC%E5%85%A5)
|
||||
import type { App, Component } from "vue";
|
||||
import {
|
||||
/**
|
||||
* 为了方便演示平台将 element-plus 导出的所有组件引入,实际使用中如果你没用到哪个组件,将其注释掉就行
|
||||
* 导出来源:https://github.com/element-plus/element-plus/blob/dev/packages/element-plus/component.ts#L111-L211
|
||||
* */
|
||||
ElAffix,
|
||||
ElAlert,
|
||||
ElAutocomplete,
|
||||
ElAutoResizer,
|
||||
ElAvatar,
|
||||
ElBacktop,
|
||||
ElBadge,
|
||||
ElBreadcrumb,
|
||||
ElBreadcrumbItem,
|
||||
ElButton,
|
||||
ElButtonGroup,
|
||||
ElCalendar,
|
||||
ElCard,
|
||||
ElCarousel,
|
||||
ElCarouselItem,
|
||||
ElCascader,
|
||||
ElCascaderPanel,
|
||||
ElCheckTag,
|
||||
ElCheckbox,
|
||||
ElCheckboxButton,
|
||||
ElCheckboxGroup,
|
||||
ElCol,
|
||||
ElCollapse,
|
||||
ElCollapseItem,
|
||||
ElCollapseTransition,
|
||||
ElColorPicker,
|
||||
ElConfigProvider,
|
||||
ElContainer,
|
||||
ElAside,
|
||||
ElFooter,
|
||||
ElHeader,
|
||||
ElMain,
|
||||
ElDatePicker,
|
||||
ElDescriptions,
|
||||
ElDescriptionsItem,
|
||||
ElDialog,
|
||||
ElDivider,
|
||||
ElDrawer,
|
||||
ElDropdown,
|
||||
ElDropdownItem,
|
||||
ElDropdownMenu,
|
||||
ElEmpty,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElIcon,
|
||||
ElImage,
|
||||
ElImageViewer,
|
||||
ElInput,
|
||||
ElInputNumber,
|
||||
ElLink,
|
||||
ElMenu,
|
||||
ElMenuItem,
|
||||
ElMenuItemGroup,
|
||||
ElSubMenu,
|
||||
ElPageHeader,
|
||||
ElPagination,
|
||||
ElPopconfirm,
|
||||
ElPopover,
|
||||
ElPopper,
|
||||
ElProgress,
|
||||
ElRadio,
|
||||
ElRadioButton,
|
||||
ElRadioGroup,
|
||||
ElRate,
|
||||
ElResult,
|
||||
ElRow,
|
||||
ElScrollbar,
|
||||
ElSelect,
|
||||
ElOption,
|
||||
ElOptionGroup,
|
||||
ElSelectV2,
|
||||
ElSkeleton,
|
||||
ElSkeletonItem,
|
||||
ElSlider,
|
||||
ElSpace,
|
||||
ElStatistic,
|
||||
ElCountdown,
|
||||
ElSteps,
|
||||
ElStep,
|
||||
ElSwitch,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
ElTableV2,
|
||||
ElTabs,
|
||||
ElTabPane,
|
||||
ElTag,
|
||||
ElText,
|
||||
ElTimePicker,
|
||||
ElTimeSelect,
|
||||
ElTimeline,
|
||||
ElTimelineItem,
|
||||
ElTooltip,
|
||||
ElTransfer,
|
||||
ElTree,
|
||||
ElTreeSelect,
|
||||
ElTreeV2,
|
||||
ElUpload,
|
||||
ElWatermark,
|
||||
ElTour,
|
||||
ElTourStep,
|
||||
/**
|
||||
* 为了方便演示平台将 element-plus 导出的所有插件引入,实际使用中如果你没用到哪个插件,将其注释掉就行
|
||||
* 导出来源:https://github.com/element-plus/element-plus/blob/dev/packages/element-plus/plugin.ts#L11-L16
|
||||
* */
|
||||
ElLoading, // v-loading 指令
|
||||
ElInfiniteScroll, // v-infinite-scroll 指令
|
||||
ElPopoverDirective, // v-popover 指令
|
||||
ElMessage, // $message 全局属性对象globalProperties
|
||||
ElMessageBox, // $msgbox、$alert、$confirm、$prompt 全局属性对象globalProperties
|
||||
ElNotification // $notify 全局属性对象globalProperties
|
||||
} from "element-plus";
|
||||
|
||||
const components = [
|
||||
ElAffix,
|
||||
ElAlert,
|
||||
ElAutocomplete,
|
||||
ElAutoResizer,
|
||||
ElAvatar,
|
||||
ElBacktop,
|
||||
ElBadge,
|
||||
ElBreadcrumb,
|
||||
ElBreadcrumbItem,
|
||||
ElButton,
|
||||
ElButtonGroup,
|
||||
ElCalendar,
|
||||
ElCard,
|
||||
ElCarousel,
|
||||
ElCarouselItem,
|
||||
ElCascader,
|
||||
ElCascaderPanel,
|
||||
ElCheckTag,
|
||||
ElCheckbox,
|
||||
ElCheckboxButton,
|
||||
ElCheckboxGroup,
|
||||
ElCol,
|
||||
ElCollapse,
|
||||
ElCollapseItem,
|
||||
ElCollapseTransition,
|
||||
ElColorPicker,
|
||||
ElConfigProvider,
|
||||
ElContainer,
|
||||
ElAside,
|
||||
ElFooter,
|
||||
ElHeader,
|
||||
ElMain,
|
||||
ElDatePicker,
|
||||
ElDescriptions,
|
||||
ElDescriptionsItem,
|
||||
ElDialog,
|
||||
ElDivider,
|
||||
ElDrawer,
|
||||
ElDropdown,
|
||||
ElDropdownItem,
|
||||
ElDropdownMenu,
|
||||
ElEmpty,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElIcon,
|
||||
ElImage,
|
||||
ElImageViewer,
|
||||
ElInput,
|
||||
ElInputNumber,
|
||||
ElLink,
|
||||
ElMenu,
|
||||
ElMenuItem,
|
||||
ElMenuItemGroup,
|
||||
ElSubMenu,
|
||||
ElPageHeader,
|
||||
ElPagination,
|
||||
ElPopconfirm,
|
||||
ElPopover,
|
||||
ElPopper,
|
||||
ElProgress,
|
||||
ElRadio,
|
||||
ElRadioButton,
|
||||
ElRadioGroup,
|
||||
ElRate,
|
||||
ElResult,
|
||||
ElRow,
|
||||
ElScrollbar,
|
||||
ElSelect,
|
||||
ElOption,
|
||||
ElOptionGroup,
|
||||
ElSelectV2,
|
||||
ElSkeleton,
|
||||
ElSkeletonItem,
|
||||
ElSlider,
|
||||
ElSpace,
|
||||
ElStatistic,
|
||||
ElCountdown,
|
||||
ElSteps,
|
||||
ElStep,
|
||||
ElSwitch,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
ElTableV2,
|
||||
ElTabs,
|
||||
ElTabPane,
|
||||
ElTag,
|
||||
ElText,
|
||||
ElTimePicker,
|
||||
ElTimeSelect,
|
||||
ElTimeline,
|
||||
ElTimelineItem,
|
||||
ElTooltip,
|
||||
ElTransfer,
|
||||
ElTree,
|
||||
ElTreeSelect,
|
||||
ElTreeV2,
|
||||
ElUpload,
|
||||
ElWatermark,
|
||||
ElTour,
|
||||
ElTourStep
|
||||
];
|
||||
|
||||
const plugins = [
|
||||
ElLoading,
|
||||
ElInfiniteScroll,
|
||||
ElPopoverDirective,
|
||||
ElMessage,
|
||||
ElMessageBox,
|
||||
ElNotification
|
||||
];
|
||||
|
||||
/** 按需引入`element-plus` */
|
||||
export function useElementPlus(app: App) {
|
||||
// 全局注册组件
|
||||
components.forEach((component: Component) => {
|
||||
app.component(component.name, component);
|
||||
});
|
||||
// 全局注册插件
|
||||
plugins.forEach(plugin => {
|
||||
app.use(plugin);
|
||||
});
|
||||
}
|
||||
@@ -1,23 +1,27 @@
|
||||
// 多组件库的国际化和本地项目国际化兼容
|
||||
import { App, WritableComputedRef } from "vue";
|
||||
import { storageLocal } from "@pureadmin/utils";
|
||||
import { type I18n, createI18n } from "vue-i18n";
|
||||
import type { App, WritableComputedRef } from "vue";
|
||||
import { responsiveStorageNameSpace } from "@/config";
|
||||
import { storageLocal, isObject } from "@pureadmin/utils";
|
||||
|
||||
// element-plus国际化
|
||||
import enLocale from "element-plus/lib/locale/lang/en";
|
||||
import zhLocale from "element-plus/lib/locale/lang/zh-cn";
|
||||
import enLocale from "element-plus/dist/locale/en.mjs";
|
||||
import zhLocale from "element-plus/dist/locale/zh-cn.mjs";
|
||||
|
||||
function siphonI18n(prefix = "zh-CN") {
|
||||
return Object.fromEntries(
|
||||
const siphonI18n = (function () {
|
||||
// 仅初始化一次国际化配置
|
||||
let cache = Object.fromEntries(
|
||||
Object.entries(
|
||||
import.meta.glob("../../locales/*.y(a)?ml", { eager: true })
|
||||
).map(([key, value]: any) => {
|
||||
const matched = key.match(/([A-Za-z0-9-_]+)\./i)[1];
|
||||
return [matched, value.default];
|
||||
})
|
||||
)[prefix];
|
||||
}
|
||||
);
|
||||
return (prefix = "zh-CN") => {
|
||||
return cache[prefix];
|
||||
};
|
||||
})();
|
||||
|
||||
export const localesConfigs = {
|
||||
zh: {
|
||||
@@ -30,6 +34,41 @@ export const localesConfigs = {
|
||||
}
|
||||
};
|
||||
|
||||
/** 获取对象中所有嵌套对象的key键,并将它们用点号分割组成字符串 */
|
||||
function getObjectKeys(obj) {
|
||||
const stack = [];
|
||||
const keys: Set<string> = new Set();
|
||||
|
||||
stack.push({ obj, key: "" });
|
||||
|
||||
while (stack.length > 0) {
|
||||
const { obj, key } = stack.pop();
|
||||
|
||||
for (const k in obj) {
|
||||
const newKey = key ? `${key}.${k}` : k;
|
||||
|
||||
if (obj[k] && isObject(obj[k])) {
|
||||
stack.push({ obj: obj[k], key: newKey });
|
||||
} else {
|
||||
keys.add(newKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
/** 将展开的key缓存 */
|
||||
const keysCache: Map<string, Set<string>> = new Map();
|
||||
const flatI18n = (prefix = "zh-CN") => {
|
||||
let cache = keysCache.get(prefix);
|
||||
if (!cache) {
|
||||
cache = getObjectKeys(siphonI18n(prefix));
|
||||
keysCache.set(prefix, cache);
|
||||
}
|
||||
return cache;
|
||||
};
|
||||
|
||||
/**
|
||||
* 国际化转换工具函数(自动读取根目录locales文件夹下文件进行国际化匹配)
|
||||
* @param message message
|
||||
@@ -47,10 +86,11 @@ export function transformI18n(message: any = "") {
|
||||
return message[locale?.value];
|
||||
}
|
||||
|
||||
const key = message.match(/(\S*)\./)?.[1];
|
||||
if (key && Object.keys(siphonI18n("zh-CN")).includes(key)) {
|
||||
const key = message.match(/(\S*)\./)?.input;
|
||||
|
||||
if (key && flatI18n("zh-CN").has(key)) {
|
||||
return i18n.global.t.call(i18n.global.locale, message);
|
||||
} else if (!key && Object.keys(siphonI18n("zh-CN")).includes(message)) {
|
||||
} else if (!key && Object.hasOwn(siphonI18n("zh-CN"), message)) {
|
||||
// 兼容非嵌套形式的国际化写法
|
||||
return i18n.global.t.call(i18n.global.locale, message);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user