build: 升级 vite 到4.x版本, 修改不兼容的代码

This commit is contained in:
奔跑的面条 2023-04-01 21:33:01 +08:00
parent 9fd408e8ef
commit 47d1dcbc04
4 changed files with 1805 additions and 1264 deletions

View File

@ -75,7 +75,7 @@
"sass": "^1.49.11", "sass": "^1.49.11",
"sass-loader": "^12.6.0", "sass-loader": "^12.6.0",
"typescript": "4.6.3", "typescript": "4.6.3",
"vite": "2.9.9", "vite": "4.2.1",
"vite-plugin-compression": "^0.5.1", "vite-plugin-compression": "^0.5.1",
"vite-plugin-importer": "^0.2.5", "vite-plugin-importer": "^0.2.5",
"vite-plugin-mock": "^2.9.6", "vite-plugin-mock": "^2.9.6",

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,34 @@
/** /**
* *
* *
*/ */
interface ITextures { interface ITextures {
name: string name: string
url: string url: string
} }
export interface IResources { export interface IResources {
textures?: ITextures[] textures?: ITextures[]
} }
const fileSuffix = ['earth', 'gradient', 'redCircle', 'label', 'aperture', 'glow', 'light_column', 'aircraft'] const fileSuffix = ['earth', 'gradient', 'redCircle', 'label', 'aperture', 'glow', 'light_column', 'aircraft']
const textures: ITextures[] = [] const textures: ITextures[] = []
const modules = import.meta.globEager("../../images/earth/*"); const modules: Record<string, { default: string }> = import.meta.glob("../../images/earth/*", { eager: true })
for(let item in modules) { for(let item in modules) {
const n = item.split('/').pop() const n = item.split('/').pop()
if(n) { if(n) {
textures.push({ textures.push({
name: n.split('.')[0], name: n.split('.')[0],
url: modules[item].default url: modules[item].default
}) })
} }
} }
const resources: IResources = { const resources: IResources = {
textures textures
} }
export { resources } export { resources }

View File

@ -1,81 +1,87 @@
import { ChartList } from '@/packages/components/Charts/index' import { ChartList } from '@/packages/components/Charts/index'
import { DecorateList } from '@/packages/components/Decorates/index' import { DecorateList } from '@/packages/components/Decorates/index'
import { InformationList } from '@/packages/components/Informations/index' import { InformationList } from '@/packages/components/Informations/index'
import { TableList } from '@/packages/components/Tables/index' import { TableList } from '@/packages/components/Tables/index'
import { PackagesCategoryEnum, PackagesType, ConfigType, FetchComFlagType } from '@/packages/index.d' import { PackagesCategoryEnum, PackagesType, ConfigType, FetchComFlagType } from '@/packages/index.d'
const configModules = import.meta.globEager('./components/**/config.vue') const configModules: Record<string, { default: string }> = import.meta.glob('./components/**/config.vue', {
const indexModules = import.meta.globEager('./components/**/index.vue') eager: true
const imagesModules = import.meta.globEager('../assets/images/chart/**') })
const indexModules: Record<string, { default: string }> = import.meta.glob('./components/**/index.vue', {
// * 所有图表 eager: true
export let packagesList: PackagesType = { })
[PackagesCategoryEnum.CHARTS]: ChartList, const imagesModules: Record<string, { default: string }> = import.meta.glob('../assets/images/chart/**', {
[PackagesCategoryEnum.INFORMATIONS]: InformationList, eager: true
[PackagesCategoryEnum.TABLES]: TableList, })
[PackagesCategoryEnum.DECORATES]: DecorateList
} // * 所有图表
export let packagesList: PackagesType = {
/** [PackagesCategoryEnum.CHARTS]: ChartList,
* * [PackagesCategoryEnum.INFORMATIONS]: InformationList,
* @param targetData [PackagesCategoryEnum.TABLES]: TableList,
*/ [PackagesCategoryEnum.DECORATES]: DecorateList
export const createComponent = async (targetData: ConfigType) => { }
const { category, key } = targetData
const chart = await import(`./components/${targetData.package}/${category}/${key}/config.ts`) /**
return new chart.default() * *
} * @param targetData
*/
/** export const createComponent = async (targetData: ConfigType) => {
* * const { category, key } = targetData
* @param {string} chartName const chart = await import(`./components/${targetData.package}/${category}/${key}/config.ts`)
* @param {FetchComFlagType} flag 0, 1 return new chart.default()
*/ }
const fetchComponent = (chartName: string, flag: FetchComFlagType) => {
const module = flag === FetchComFlagType.VIEW ? indexModules : configModules /**
for (const key in module) { * *
const urlSplit = key.split('/') * @param {string} chartName
if (urlSplit[urlSplit.length - 2] === chartName) { * @param {FetchComFlagType} flag 0, 1
return module[key] */
} const fetchComponent = (chartName: string, flag: FetchComFlagType) => {
} const module = flag === FetchComFlagType.VIEW ? indexModules : configModules
} for (const key in module) {
const urlSplit = key.split('/')
/** if (urlSplit[urlSplit.length - 2] === chartName) {
* * return module[key]
* @param {ConfigType} dropData }
*/ }
export const fetchChartComponent = (dropData: ConfigType) => { }
const { key } = dropData
return fetchComponent(key, FetchComFlagType.VIEW)?.default /**
} * *
* @param {ConfigType} dropData
/** */
* * export const fetchChartComponent = (dropData: ConfigType) => {
* @param {ConfigType} dropData const { key } = dropData
*/ return fetchComponent(key, FetchComFlagType.VIEW)?.default
export const fetchConfigComponent = (dropData: ConfigType) => { }
const { key } = dropData
return fetchComponent(key, FetchComFlagType.CONFIG)?.default /**
} * *
* @param {ConfigType} dropData
/** */
* * export const fetchConfigComponent = (dropData: ConfigType) => {
* @param {ConfigType} targetData const { key } = dropData
*/ return fetchComponent(key, FetchComFlagType.CONFIG)?.default
export const fetchImages = async (targetData?: ConfigType) => { }
if (!targetData) return ''
// 新数据动态处理 /**
const { image, package: targetDataPackage } = targetData * *
// 兼容旧数据 * @param {ConfigType} targetData
if (image.includes('@') || image.includes('base64')) return image */
export const fetchImages = async (targetData?: ConfigType) => {
const imageName = image.substring(image.lastIndexOf('/') + 1) if (!targetData) return ''
for (const key in imagesModules) { // 新数据动态处理
const urlSplit = key.split('/') const { image, package: targetDataPackage } = targetData
if (urlSplit[urlSplit.length - 1] === imageName) { // 兼容旧数据
return imagesModules[key]?.default if (image.includes('@') || image.includes('base64')) return image
}
} const imageName = image.substring(image.lastIndexOf('/') + 1)
return '' for (const key in imagesModules) {
} const urlSplit = key.split('/')
if (urlSplit[urlSplit.length - 1] === imageName) {
return imagesModules[key]?.default
}
}
return ''
}