初步修改

This commit is contained in:
2026-08-09 14:13:34 +08:00
parent 1173feed12
commit cb86fbeca5
19 changed files with 579 additions and 1880 deletions
+81 -1
View File
@@ -6,6 +6,86 @@ import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const cesiumSource = path.join(__dirname, 'node_modules', 'cesium', 'Build', 'Cesium')
const modelSource = path.join(__dirname, 'model')
const adminiveFrontend = path.join(__dirname, '..', 'Adminive', 'frontend')
const amisSdkSource = path.join(adminiveFrontend, 'node_modules', 'amis', 'sdk')
const amisPackage = JSON.parse(fs.readFileSync(path.join(adminiveFrontend, 'node_modules', 'amis', 'package.json'), 'utf8'))
const amisSdkUrlPrefix = `/ui/vendor/amis/${amisPackage.version}/`
function amisContentType(fileName) {
const extension = path.extname(fileName).toLowerCase()
if (extension === '.css') return 'text/css; charset=utf-8'
if (extension === '.js') return 'text/javascript; charset=utf-8'
if (extension === '.json') return 'application/json; charset=utf-8'
if (extension === '.svg') return 'image/svg+xml'
if (extension === '.woff') return 'font/woff'
if (extension === '.woff2') return 'font/woff2'
if (extension === '.ttf') return 'font/ttf'
return 'application/octet-stream'
}
function serveAmisSdk(server) {
server.middlewares.use((request, response, next) => {
const pathname = new URL(request.url || '/', 'http://localhost').pathname
if (!pathname.startsWith(amisSdkUrlPrefix)) {
next()
return
}
const relativePath = decodeURIComponent(pathname.slice(amisSdkUrlPrefix.length))
const sourcePath = path.resolve(amisSdkSource, relativePath)
if (sourcePath !== amisSdkSource && !sourcePath.startsWith(`${amisSdkSource}${path.sep}`)) {
next()
return
}
try {
response.statusCode = 200
response.setHeader('Content-Type', amisContentType(sourcePath))
response.end(fs.readFileSync(sourcePath))
} catch {
next()
}
})
}
function amisSdkPlugin() {
return {
name: 'ecap-adminive-amis-sdk',
enforce: 'pre',
resolveId(source) {
if (source === 'amis' || source.startsWith('amis/')) {
this.error(`Do not import ${source} into the Vite module graph; use the AMIS SDK runtime`)
}
return null
},
buildStart() {
const emitDirectory = (directory, prefix) => {
for (const entry of fs.readdirSync(directory)) {
const sourcePath = path.join(directory, entry)
const relativePath = `${prefix}${entry}`
if (fs.statSync(sourcePath).isDirectory()) {
emitDirectory(sourcePath, `${relativePath}/`)
} else {
this.emitFile({type: 'asset', fileName: `vendor/amis/${amisPackage.version}/${relativePath}`, source: fs.readFileSync(sourcePath)})
}
}
}
emitDirectory(amisSdkSource, '')
},
transformIndexHtml: {
order: 'post',
handler() {
return [
{tag: 'link', attrs: {rel: 'stylesheet', href: `${amisSdkUrlPrefix}sdk.css`}, injectTo: 'head-prepend'},
{tag: 'link', attrs: {rel: 'stylesheet', href: `${amisSdkUrlPrefix}helper.css`}, injectTo: 'head-prepend'},
{tag: 'link', attrs: {rel: 'stylesheet', href: `${amisSdkUrlPrefix}iconfont.css`}, injectTo: 'head-prepend'},
{tag: 'script', attrs: {src: `${amisSdkUrlPrefix}sdk.js`}, injectTo: 'head-prepend'}
]
}
},
configureServer(server) {
serveAmisSdk(server)
},
configurePreviewServer(server) {
serveAmisSdk(server)
}
}
}
function copyDir(source, target) {
fs.mkdirSync(target, { recursive: true })
for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
@@ -98,7 +178,7 @@ export default defineConfig({
define: {
CESIUM_BASE_URL: JSON.stringify('/ui/cesium/')
},
plugins: [react(), cesiumAssetsPlugin(), spaAliasesPlugin()],
plugins: [react(), amisSdkPlugin(), cesiumAssetsPlugin(), spaAliasesPlugin()],
server: {
proxy: {
'/map/imagery': {