mirror of
https://gitee.com/niucloud-team/niucloud.git
synced 2026-06-27 08:11:59 +00:00
v2.0-beta-20260626
v2框架公测版测试流程请看v2.0-beta.md
This commit is contained in:
parent
67e7669694
commit
3e71008192
@ -8,4 +8,4 @@ VITE_IMG_DOMAIN=''
|
||||
VITE_REQUEST_HEADER_TOKEN_KEY='token'
|
||||
|
||||
# 请求时header中站点的参数名
|
||||
VITE_REQUEST_HEADER_SITEID_KEY='site-id'
|
||||
VITE_REQUEST_HEADER_SITEID_KEY='site-id'
|
||||
|
||||
4
admin/.gitignore
vendored
4
admin/.gitignore
vendored
@ -22,3 +22,7 @@ dist-ssr
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
.build
|
||||
build-report.json
|
||||
auto-imports.d.ts
|
||||
components.d.ts
|
||||
|
||||
3
admin/auto-imports.d.ts
vendored
3
admin/auto-imports.d.ts
vendored
@ -1,6 +1,5 @@
|
||||
// Generated by 'unplugin-auto-import'
|
||||
export {}
|
||||
declare global {
|
||||
const ElMessageBox: typeof import('element-plus/es')['ElMessageBox']
|
||||
const ElNotification: typeof import('element-plus/es')['ElNotification']
|
||||
|
||||
}
|
||||
|
||||
40
admin/components.d.ts
vendored
40
admin/components.d.ts
vendored
@ -11,60 +11,36 @@ declare module '@vue/runtime-core' {
|
||||
DiyLink: typeof import('./src/components/diy-link/index.vue')['default']
|
||||
DiyPage: typeof import('./src/components/diy-page/index.vue')['default']
|
||||
Editor: typeof import('./src/components/editor/index.vue')['default']
|
||||
ElAlert: typeof import('element-plus/es')['ElAlert']
|
||||
ElAside: typeof import('element-plus/es')['ElAside']
|
||||
ElAvatar: typeof import('element-plus/es')['ElAvatar']
|
||||
ElBreadcrumb: typeof import('element-plus/es')['ElBreadcrumb']
|
||||
ElBreadcrumbItem: typeof import('element-plus/es')['ElBreadcrumbItem']
|
||||
ElButton: typeof import('element-plus/es')['ElButton']
|
||||
ElCard: typeof import('element-plus/es')['ElCard']
|
||||
ElCarousel: typeof import('element-plus/es')['ElCarousel']
|
||||
ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem']
|
||||
ElCascader: typeof import('element-plus/es')['ElCascader']
|
||||
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
|
||||
ElCheckboxGroup: typeof import('element-plus/es')['ElCheckboxGroup']
|
||||
ElCol: typeof import('element-plus/es')['ElCol']
|
||||
ElColorPicker: typeof import('element-plus/es')['ElColorPicker']
|
||||
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
|
||||
ElContainer: typeof import('element-plus/es')['ElContainer']
|
||||
ElDatePicker: typeof import('element-plus/es')['ElDatePicker']
|
||||
ElDialog: typeof import('element-plus/es')['ElDialog']
|
||||
ElDrawer: typeof import('element-plus/es')['ElDrawer']
|
||||
ElDropdown: typeof import('element-plus/es')['ElDropdown']
|
||||
ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
|
||||
ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
|
||||
ElForm: typeof import('element-plus/es')['ElForm']
|
||||
ElFormItem: typeof import('element-plus/es')['ElFormItem']
|
||||
ElHeader: typeof import('element-plus/es')['ElHeader']
|
||||
ElIcon: typeof import('element-plus/es')['ElIcon']
|
||||
ElImage: typeof import('element-plus/es')['ElImage']
|
||||
ElImageViewer: typeof import('element-plus/es')['ElImageViewer']
|
||||
ElInput: typeof import('element-plus/es')['ElInput']
|
||||
ElMain: typeof import('element-plus/es')['ElMain']
|
||||
ElMenu: typeof import('element-plus/es')['ElMenu']
|
||||
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
|
||||
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
|
||||
ElOption: typeof import('element-plus/es')['ElOption']
|
||||
ElPageHeader: typeof import('element-plus/es')['ElPageHeader']
|
||||
ElPagination: typeof import('element-plus/es')['ElPagination']
|
||||
ElPopover: typeof import('element-plus/es')['ElPopover']
|
||||
ElResult: typeof import('element-plus/es')['ElResult']
|
||||
ElRadio: typeof import('element-plus/es')['ElRadio']
|
||||
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
|
||||
ElRow: typeof import('element-plus/es')['ElRow']
|
||||
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
|
||||
ElSelect: typeof import('element-plus/es')['ElSelect']
|
||||
ElSkeleton: typeof import('element-plus/es')['ElSkeleton']
|
||||
ElSkeletonItem: typeof import('element-plus/es')['ElSkeletonItem']
|
||||
ElStatistic: typeof import('element-plus/es')['ElStatistic']
|
||||
ElStep: typeof import('element-plus/es')['ElStep']
|
||||
ElSteps: typeof import('element-plus/es')['ElSteps']
|
||||
ElSubMenu: typeof import('element-plus/es')['ElSubMenu']
|
||||
ElSwitch: typeof import('element-plus/es')['ElSwitch']
|
||||
ElSlider: typeof import('element-plus/es')['ElSlider']
|
||||
ElTable: typeof import('element-plus/es')['ElTable']
|
||||
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
|
||||
ElTabPane: typeof import('element-plus/es')['ElTabPane']
|
||||
ElTabs: typeof import('element-plus/es')['ElTabs']
|
||||
ElTag: typeof import('element-plus/es')['ElTag']
|
||||
ElTimeline: typeof import('element-plus/es')['ElTimeline']
|
||||
ElTimelineItem: typeof import('element-plus/es')['ElTimelineItem']
|
||||
ElTooltip: typeof import('element-plus/es')['ElTooltip']
|
||||
ElUpload: typeof import('element-plus/es')['ElUpload']
|
||||
ElTimeSelect: typeof import('element-plus/es')['ElTimeSelect']
|
||||
ElTree: typeof import('element-plus/es')['ElTree']
|
||||
ExportSure: typeof import('./src/components/export-sure/index.vue')['default']
|
||||
HeatMap: typeof import('./src/components/heat-map/index.vue')['default']
|
||||
Icon: typeof import('./src/components/icon/index.vue')['default']
|
||||
|
||||
@ -8,6 +8,16 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
// 外挂配置 — 部署后可直接修改此处的值,无需重新编译
|
||||
window.__ENV__ = {
|
||||
VITE_APP_BASE_URL: "",
|
||||
VITE_IMG_DOMAIN: "",
|
||||
VITE_REQUEST_HEADER_TOKEN_KEY: "token",
|
||||
VITE_REQUEST_HEADER_SITEID_KEY: "site-id",
|
||||
VITE_DETAULT_TITLE: ""
|
||||
};
|
||||
</script>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -5,7 +5,11 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "cross-env NODE_OPTIONS=--max-old-space-size=4096 vite build && node publish.cjs",
|
||||
"build": "node scripts/build-all.cjs",
|
||||
"build:core": "node scripts/build-shared.cjs && node scripts/clean-core.cjs && node node_modules/vite/bin/vite.js build --config vite.config.core.ts --force && node scripts/verify-core-lang.cjs && node scripts/assemble-admin.cjs",
|
||||
"build:shared": "node scripts/build-shared.cjs",
|
||||
"build:addon": "node scripts/build-addon.cjs",
|
||||
"build:assemble": "node scripts/assemble-admin.cjs",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
@ -24,7 +28,8 @@
|
||||
"date-fns": "^4.1.0",
|
||||
"day": "^0.0.2",
|
||||
"echarts": "5.4.1",
|
||||
"element-plus": "^2.7.4",
|
||||
"element-plus": "2.7.4",
|
||||
"esbuild": "^0.16.17",
|
||||
"highlight.js": "11.0.1",
|
||||
"lodash-es": "4.17.21",
|
||||
"nprogress": "0.2.0",
|
||||
@ -33,7 +38,7 @@
|
||||
"sass": "1.58.0",
|
||||
"sortablejs": "1.15.0",
|
||||
"vditor": "^3.10.9",
|
||||
"vue": "3.2.45",
|
||||
"vue": "3.3.7",
|
||||
"vue-i18n": "9.2.2",
|
||||
"vue-jsonp": "2.0.0",
|
||||
"vue-router": "4.1.6",
|
||||
@ -48,6 +53,7 @@
|
||||
"@typescript-eslint/eslint-plugin": "5.53.0",
|
||||
"@vitejs/plugin-vue": "4.0.0",
|
||||
"autoprefixer": "10.4.13",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "8.34.0",
|
||||
"eslint-config-standard-with-typescript": "34.0.0",
|
||||
"eslint-plugin-import": "2.27.5",
|
||||
@ -60,7 +66,6 @@
|
||||
"unplugin-auto-import": "0.13.0",
|
||||
"unplugin-vue-components": "0.23.0",
|
||||
"vite": "4.1.0",
|
||||
"vue-tsc": "1.0.24",
|
||||
"cross-env": "^7.0.3"
|
||||
"vue-tsc": "1.0.24"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,40 +1,49 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const publish = () => {
|
||||
const src = './dist'
|
||||
const dest = '../niucloud/public/admin'
|
||||
const ROOT = path.resolve(__dirname)
|
||||
const src = path.join(ROOT, 'dist')
|
||||
const dest = path.resolve(ROOT, process.env.PUBLISH_DEST || '../niucloud/public/admin')
|
||||
|
||||
solve()
|
||||
|
||||
// 目标目录不存在停止复制
|
||||
try {
|
||||
const dir = fs.readdirSync(dest)
|
||||
} catch (e) {
|
||||
return
|
||||
}
|
||||
|
||||
// 删除目标目录下文件
|
||||
fs.rm(dest, { recursive: true }, err => {
|
||||
if(err) {
|
||||
console.log(err)
|
||||
return
|
||||
function fixIndexHtml() {
|
||||
const fn = path.join(src, 'index.html')
|
||||
if (!fs.existsSync(fn)) {
|
||||
const core = path.join(src, '.core', 'index.html')
|
||||
if (fs.existsSync(core)) {
|
||||
fs.copyFileSync(core, fn)
|
||||
} else {
|
||||
throw new Error('missing dist/index.html — run assemble or build:core first')
|
||||
}
|
||||
|
||||
fs.cp(src, dest, { recursive: true }, (err) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const solve = () => {
|
||||
const fn = './dist/index.html'
|
||||
const fc = fs.readFileSync(fn, 'utf-8')
|
||||
let text = new String(fc)
|
||||
}
|
||||
let text = fs.readFileSync(fn, 'utf-8')
|
||||
text = text.replaceAll('./assets/', '/admin/assets/')
|
||||
text = text.replace('./niucloud.ico', '/admin/niucloud.ico')
|
||||
fs.writeFileSync(fn, text, 'utf8')
|
||||
fs.writeFileSync(fn, text, 'utf-8')
|
||||
}
|
||||
|
||||
function publish() {
|
||||
fixIndexHtml()
|
||||
|
||||
if (!fs.existsSync(dest)) {
|
||||
console.error(`[publish] target not found: ${dest}`)
|
||||
console.error('[publish] set PUBLISH_DEST to your web admin directory')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
fs.rmSync(dest, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 })
|
||||
fs.cpSync(src, dest, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
filter: (srcPath) => {
|
||||
const relative = path.relative(src, srcPath)
|
||||
const parts = relative.split(path.sep)
|
||||
return !parts.includes('.core') && !parts.includes('.shared')
|
||||
}
|
||||
})
|
||||
|
||||
const shopEntry = path.join(dest, 'assets', 'addons', 'shop', 'index.js')
|
||||
console.log(`[publish] ${src} -> ${dest}`)
|
||||
console.log(`[publish] shop addon: ${fs.existsSync(shopEntry) ? 'OK' : 'MISSING — run node scripts/sync-addon.cjs shop'}`)
|
||||
}
|
||||
|
||||
publish()
|
||||
|
||||
69
admin/scripts/addon-utils.cjs
Normal file
69
admin/scripts/addon-utils.cjs
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 插件构建公共工具
|
||||
* - 扫描 src/addon 下目录、视图、语言包
|
||||
* - 供 generate-addon-entry / build-all / assemble 等脚本复用
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
/** 项目根目录(admin/) */
|
||||
const ROOT = path.resolve(__dirname, '..')
|
||||
/** 插件源码根目录 */
|
||||
const ADDON_DIR = path.join(ROOT, 'src', 'addon')
|
||||
|
||||
/** 列出 src/addon 下所有插件 key(目录名) */
|
||||
function listAddonKeys() {
|
||||
if (!fs.existsSync(ADDON_DIR)) return []
|
||||
return fs.readdirSync(ADDON_DIR, { withFileTypes: true })
|
||||
.filter((d) => d.isDirectory())
|
||||
.map((d) => d.name)
|
||||
.sort()
|
||||
}
|
||||
|
||||
/** 递归遍历目录,收集满足 filter 的文件相对路径 */
|
||||
function walkFiles(dir, filter, base = dir) {
|
||||
const out = []
|
||||
if (!fs.existsSync(dir)) return out
|
||||
for (const name of fs.readdirSync(dir)) {
|
||||
const full = path.join(dir, name)
|
||||
const stat = fs.statSync(full)
|
||||
if (stat.isDirectory()) {
|
||||
out.push(...walkFiles(full, filter, base))
|
||||
} else if (filter(full)) {
|
||||
out.push(path.relative(base, full).replace(/\\/g, '/'))
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描插件 views 目录,返回视图路径列表(不含 .vue)
|
||||
* 例:order/list、goods/category
|
||||
*/
|
||||
function scanAddonViews(key) {
|
||||
const viewsDir = path.join(ADDON_DIR, key, 'views')
|
||||
return walkFiles(viewsDir, (f) => f.endsWith('.vue'), viewsDir)
|
||||
.map((p) => p.replace(/\.vue$/, ''))
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描插件 lang 目录
|
||||
* @returns {Record<string, string[]>} locale -> json 文件名(不含 .json)
|
||||
* 例:{ 'zh-cn': ['common', 'order.list'], 'en': ['common'] }
|
||||
*/
|
||||
function scanAddonLang(key) {
|
||||
const langDir = path.join(ADDON_DIR, key, 'lang')
|
||||
const out = {}
|
||||
if (!fs.existsSync(langDir)) return out
|
||||
for (const locale of fs.readdirSync(langDir)) {
|
||||
const localeDir = path.join(langDir, locale)
|
||||
if (!fs.statSync(localeDir).isDirectory()) continue
|
||||
out[locale] = fs.readdirSync(localeDir)
|
||||
.filter((f) => f.endsWith('.json'))
|
||||
.map((f) => f.replace(/\.json$/, ''))
|
||||
.sort()
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
module.exports = { ROOT, ADDON_DIR, listAddonKeys, walkFiles, scanAddonViews, scanAddonLang }
|
||||
67
admin/scripts/admin-lang-import-utils.cjs
Normal file
67
admin/scripts/admin-lang-import-utils.cjs
Normal file
@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 修复构建产物中错误的 admin-lang import 路径
|
||||
*
|
||||
* Rollup external @/lang 时可能生成相对路径,从 /admin/assets/*.js 解析会变成:
|
||||
* ../admin/assets/shared/admin-lang.js → /admin/admin/assets/...(HTML 404)
|
||||
* ../shared/admin-lang.js → /admin/shared/...(HTML 404)
|
||||
*
|
||||
* 被 verify-core-lang、assemble-admin、check-deploy 引用。
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { ADMIN_LANG_URL } = require('./shared-external.cjs')
|
||||
|
||||
/** [错误路径, 正确绝对路径] */
|
||||
const REPLACEMENTS = [
|
||||
['../admin/assets/shared/admin-lang.js', ADMIN_LANG_URL],
|
||||
['../shared/admin-lang.js', ADMIN_LANG_URL],
|
||||
['./shared/admin-lang.js', ADMIN_LANG_URL]
|
||||
]
|
||||
|
||||
/** 递归收集目录下所有 .js 文件 */
|
||||
function walkJs(dir, out = []) {
|
||||
if (!fs.existsSync(dir)) return out
|
||||
const stat = fs.statSync(dir)
|
||||
if (!stat.isDirectory()) return out
|
||||
for (const name of fs.readdirSync(dir)) {
|
||||
const p = path.join(dir, name)
|
||||
if (fs.statSync(p).isDirectory()) walkJs(p, out)
|
||||
else if (name.endsWith('.js')) out.push(p)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function fixCode(code) {
|
||||
let next = code
|
||||
for (const [bad, good] of REPLACEMENTS) {
|
||||
if (next.includes(bad)) next = next.split(bad).join(good)
|
||||
}
|
||||
return next
|
||||
}
|
||||
|
||||
function hasBadImport(code) {
|
||||
return REPLACEMENTS.some(([bad]) => code.includes(bad))
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描目录内 JS 并就地替换错误路径
|
||||
* @returns 修改过的文件数量
|
||||
*/
|
||||
function fixDir(dir) {
|
||||
if (!fs.existsSync(dir)) {
|
||||
throw new Error(`[admin-lang-import] directory not found: ${dir}`)
|
||||
}
|
||||
if (!fs.statSync(dir).isDirectory()) {
|
||||
throw new Error(`[admin-lang-import] not a directory: ${dir}`)
|
||||
}
|
||||
let fixed = 0
|
||||
for (const file of walkJs(dir)) {
|
||||
const code = fs.readFileSync(file, 'utf-8')
|
||||
if (!hasBadImport(code)) continue
|
||||
fs.writeFileSync(file, fixCode(code), 'utf-8')
|
||||
fixed++
|
||||
}
|
||||
return fixed
|
||||
}
|
||||
|
||||
module.exports = { fixCode, hasBadImport, REPLACEMENTS, ADMIN_LANG_URL, fixDir }
|
||||
304
admin/scripts/assemble-admin.cjs
Normal file
304
admin/scripts/assemble-admin.cjs
Normal file
@ -0,0 +1,304 @@
|
||||
/**
|
||||
* 组装最终可部署 dist/
|
||||
*
|
||||
* 将 staging 目录合并为站点可访问结构:
|
||||
* dist/.addons/* → dist/assets/addons/{key}/
|
||||
* dist/.core/* → dist/(index.html、assets 等,跳过 addons 子目录)
|
||||
* dist/.shared/* → dist/assets/shared/
|
||||
*
|
||||
* 并注入 Import Map、修正 /admin 路径、修复 admin-lang import、剥离多余 style import。
|
||||
*
|
||||
* 用法:npm run build:assemble(需先 build-shared + build:core + build-addon)
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { ROOT, listAddonKeys } = require('./addon-utils.cjs')
|
||||
const { IMPORT_MAP } = require('./shared-external.cjs')
|
||||
const { stripBuiltAssets } = require('./strip-style-imports.cjs')
|
||||
|
||||
const CORE_DIR = path.join(ROOT, 'dist', '.core')
|
||||
const ADDONS_STAGING = path.join(ROOT, 'dist', '.addons')
|
||||
const OUT_DIR = path.join(ROOT, 'dist')
|
||||
const SHARED_DIR = path.join(ROOT, 'dist', '.shared')
|
||||
const REPORT_PATH = path.join(ROOT, 'build-report.json')
|
||||
|
||||
function toWinLongPath(dir) {
|
||||
if (process.platform !== 'win32') return dir
|
||||
if (dir.startsWith('\\\\?\\')) return dir
|
||||
return `\\\\?\\${path.resolve(dir)}`
|
||||
}
|
||||
|
||||
function rmDir(dir) {
|
||||
if (!fs.existsSync(dir)) return
|
||||
try {
|
||||
fs.rmSync(toWinLongPath(dir), { recursive: true, force: true, maxRetries: 8, retryDelay: 300 })
|
||||
} catch {
|
||||
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 8, retryDelay: 300 })
|
||||
}
|
||||
}
|
||||
|
||||
/** Windows 下 rename 容易因文件锁失败,加重试 + 降级为 copy+delete */
|
||||
function safeRename(src, dest, maxRetries = 5) {
|
||||
for (let i = 0; i < maxRetries; i++) {
|
||||
try {
|
||||
fs.renameSync(src, dest)
|
||||
return
|
||||
} catch (e) {
|
||||
if (e.code === 'EPERM' || e.code === 'EBUSY') {
|
||||
if (i < maxRetries - 1) {
|
||||
console.log(`[assemble] rename busy, retry ${i + 1}/${maxRetries}...`)
|
||||
const s = Date.now(); while (Date.now() - s < 500) {}
|
||||
} else {
|
||||
// 最终降级:copy + delete
|
||||
copyDir(src, dest)
|
||||
rmDir(src)
|
||||
console.log(`[assemble] rename failed, fallback to copy+delete`)
|
||||
}
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function copyDir(src, dest) {
|
||||
fs.mkdirSync(dest, { recursive: true })
|
||||
for (const name of fs.readdirSync(src)) {
|
||||
const s = path.join(src, name)
|
||||
const d = path.join(dest, name)
|
||||
if (fs.statSync(s).isDirectory()) copyDir(s, d)
|
||||
else fs.copyFileSync(s, d)
|
||||
}
|
||||
}
|
||||
|
||||
function copyTree(src, dest) {
|
||||
fs.mkdirSync(path.dirname(dest), { recursive: true })
|
||||
fs.cpSync(src, dest, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理 dist/assets 下旧的 core 产物,保留 addons(shared 随后从 .shared 重拷)
|
||||
* Vite 每次构建 chunk hash 会变,不清理会留下上一版同名不同 hash 的孤儿文件
|
||||
*/
|
||||
function cleanCoreAssetsOutput() {
|
||||
const outAssets = path.join(OUT_DIR, 'assets')
|
||||
if (!fs.existsSync(outAssets)) {
|
||||
fs.mkdirSync(outAssets, { recursive: true })
|
||||
return
|
||||
}
|
||||
const addonsSrc = path.join(outAssets, 'addons')
|
||||
const addonsTmp = path.join(OUT_DIR, '.addons_staging')
|
||||
if (fs.existsSync(addonsTmp)) rmDir(addonsTmp)
|
||||
if (fs.existsSync(addonsSrc)) {
|
||||
safeRename(addonsSrc, addonsTmp)
|
||||
}
|
||||
if (fs.existsSync(outAssets)) {
|
||||
const staleAssets = path.join(ROOT, '.build', '.assets_stale_' + Date.now())
|
||||
try { safeRename(outAssets, staleAssets) } catch { rmDir(outAssets) }
|
||||
}
|
||||
fs.mkdirSync(outAssets, { recursive: true })
|
||||
if (fs.existsSync(addonsTmp)) {
|
||||
safeRename(addonsTmp, path.join(outAssets, 'addons'))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并 core 产物到 dist 根目录
|
||||
* 注意:跳过 core/assets/addons,避免覆盖已同步的插件目录
|
||||
*/
|
||||
function mergeCoreOutput() {
|
||||
for (const name of ['index.html', 'manifest.json', 'niucloud.ico']) {
|
||||
const src = path.join(CORE_DIR, name)
|
||||
if (fs.existsSync(src)) {
|
||||
fs.copyFileSync(src, path.join(OUT_DIR, name))
|
||||
console.log(`[assemble] core ${name}`)
|
||||
}
|
||||
}
|
||||
const ueditor = path.join(CORE_DIR, 'ueditor')
|
||||
if (fs.existsSync(ueditor)) {
|
||||
copyTree(ueditor, path.join(OUT_DIR, 'ueditor'))
|
||||
console.log('[assemble] core ueditor/')
|
||||
}
|
||||
const coreAssets = path.join(CORE_DIR, 'assets')
|
||||
const outAssets = path.join(OUT_DIR, 'assets')
|
||||
if (!fs.existsSync(coreAssets)) return
|
||||
fs.mkdirSync(outAssets, { recursive: true })
|
||||
for (const name of fs.readdirSync(coreAssets)) {
|
||||
if (name === 'addons') continue
|
||||
const src = path.join(coreAssets, name)
|
||||
const dest = path.join(outAssets, name)
|
||||
if (fs.statSync(src).isDirectory()) {
|
||||
copyDir(src, dest)
|
||||
} else {
|
||||
fs.copyFileSync(src, dest)
|
||||
}
|
||||
console.log(`[assemble] core assets/${name}`)
|
||||
}
|
||||
}
|
||||
|
||||
function copyLang(key, destAddonDir) {
|
||||
const langSrc = path.join(ROOT, 'src', 'addon', key, 'lang')
|
||||
if (!fs.existsSync(langSrc)) return
|
||||
const langDest = path.join(destAddonDir, 'lang')
|
||||
copyDir(langSrc, langDest)
|
||||
}
|
||||
|
||||
function writeAddonManifest(key, destAddonDir) {
|
||||
const manifest = {
|
||||
key,
|
||||
version: '1.0.0',
|
||||
sharedVersion: 'admin-core-1.0.0',
|
||||
entry: './index.js',
|
||||
langBase: './lang/'
|
||||
}
|
||||
fs.writeFileSync(path.join(destAddonDir, 'manifest.json'), JSON.stringify(manifest, null, 2) + '\n', 'utf-8')
|
||||
}
|
||||
|
||||
/** Vite 默认相对路径 ./assets/ → 部署绝对路径 /admin/assets/ */
|
||||
function fixIndexHtml() {
|
||||
const fn = path.join(OUT_DIR, 'index.html')
|
||||
if (!fs.existsSync(fn)) return
|
||||
let text = fs.readFileSync(fn, 'utf-8')
|
||||
text = text.replaceAll('./assets/', '/admin/assets/')
|
||||
text = text.replace('./niucloud.ico', '/admin/niucloud.ico')
|
||||
fs.writeFileSync(fn, text, 'utf-8')
|
||||
}
|
||||
|
||||
/** 注入 Import Map,使 vue / @/lang 等解析到 shared 单例 */
|
||||
function injectImportMap() {
|
||||
const fn = path.join(OUT_DIR, 'index.html')
|
||||
if (!fs.existsSync(fn)) return
|
||||
let text = fs.readFileSync(fn, 'utf-8')
|
||||
const script = `<script type="importmap">\n${JSON.stringify({ imports: IMPORT_MAP }, null, 2)}\n</script>`
|
||||
if (text.includes('type="importmap"')) {
|
||||
text = text.replace(/<script type="importmap">[\s\S]*?<\/script>/, script)
|
||||
} else {
|
||||
text = text.replace('<head>', `<head>\n ${script}`)
|
||||
}
|
||||
fs.writeFileSync(fn, text, 'utf-8')
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理 dist 根下旧文件,保留 staging(.core/.addons/.shared)与 assets
|
||||
* addon 子目录在 runAssemble 里按 key 单独 rm,避免 Windows ENOTEMPTY
|
||||
*/
|
||||
function cleanAssembledOutput() {
|
||||
if (!fs.existsSync(OUT_DIR)) {
|
||||
fs.mkdirSync(OUT_DIR, { recursive: true })
|
||||
return
|
||||
}
|
||||
const keep = new Set(['.core', '.addons', '.shared', '.addons_staging', 'assets'])
|
||||
for (const name of fs.readdirSync(OUT_DIR)) {
|
||||
if (keep.has(name)) continue
|
||||
// 历史 trash 目录不阻塞构建,可手动删除 dist/assets.__trash_*
|
||||
if (name.includes('.__trash_') || name.startsWith('assets.__')) continue
|
||||
rmDir(path.join(OUT_DIR, name))
|
||||
}
|
||||
}
|
||||
|
||||
/** Element Plus 语言包,importmap 中 locale 路径指向此处 */
|
||||
function copySharedLocales() {
|
||||
const srcBase = path.join(ROOT, 'node_modules', 'element-plus', 'dist', 'locale')
|
||||
const destBase = path.join(OUT_DIR, 'assets', 'shared', 'locale')
|
||||
fs.mkdirSync(destBase, { recursive: true })
|
||||
for (const file of ['zh-cn.mjs', 'en.mjs']) {
|
||||
const src = path.join(srcBase, file)
|
||||
if (fs.existsSync(src)) {
|
||||
fs.copyFileSync(src, path.join(destBase, file))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function main() {
|
||||
try {
|
||||
runAssemble()
|
||||
} catch (err) {
|
||||
console.error('[assemble] ERROR:', err)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
function runAssemble() {
|
||||
const report = fs.existsSync(REPORT_PATH)
|
||||
? JSON.parse(fs.readFileSync(REPORT_PATH, 'utf-8'))
|
||||
: { success: listAddonKeys(), failed: [] }
|
||||
|
||||
cleanAssembledOutput()
|
||||
|
||||
if (!fs.existsSync(CORE_DIR)) {
|
||||
console.error('[assemble] missing dist/.core — run core build first')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const successKeys = report.success || []
|
||||
const installedKeys = []
|
||||
|
||||
// 先同步 addon,避免后续 core 合并耗时过长时 assets/addons 仍为空
|
||||
for (const key of successKeys) {
|
||||
const src = path.join(ADDONS_STAGING, key)
|
||||
if (!fs.existsSync(src)) continue
|
||||
const dest = path.join(OUT_DIR, 'assets', 'addons', key)
|
||||
rmDir(dest)
|
||||
copyTree(src, dest)
|
||||
copyLang(key, dest)
|
||||
writeAddonManifest(key, dest)
|
||||
const entryFile = path.join(dest, 'index.js')
|
||||
if (!fs.existsSync(entryFile)) {
|
||||
console.error(`[assemble] missing ${key}/index.js — run: node scripts/build-addon.cjs ${key}`)
|
||||
process.exit(1)
|
||||
}
|
||||
installedKeys.push(key)
|
||||
console.log(`[assemble] addon "${key}" -> assets/addons/${key}/`)
|
||||
}
|
||||
|
||||
const indexJson = { keys: installedKeys, sharedVersion: 'admin-core-1.0.0' }
|
||||
fs.mkdirSync(path.join(OUT_DIR, 'assets', 'addons'), { recursive: true })
|
||||
fs.writeFileSync(
|
||||
path.join(OUT_DIR, 'assets', 'addons', 'index.json'),
|
||||
JSON.stringify(indexJson, null, 2) + '\n',
|
||||
'utf-8'
|
||||
)
|
||||
|
||||
cleanCoreAssetsOutput()
|
||||
mergeCoreOutput()
|
||||
|
||||
// 修复 Rollup 生成的错误 admin-lang 相对路径(否则会请求到 HTML 404)
|
||||
const { fixDir } = require('./admin-lang-import-utils.cjs')
|
||||
fixDir(path.join(OUT_DIR, 'assets'))
|
||||
|
||||
if (fs.existsSync(SHARED_DIR)) {
|
||||
const sharedDest = path.join(OUT_DIR, 'assets', 'shared')
|
||||
fs.mkdirSync(sharedDest, { recursive: true })
|
||||
for (const name of fs.readdirSync(SHARED_DIR)) {
|
||||
copyTree(path.join(SHARED_DIR, name), path.join(sharedDest, name))
|
||||
}
|
||||
console.log('[assemble] shared -> assets/shared/')
|
||||
} else {
|
||||
console.warn('[assemble] missing dist/.shared — run build-shared first')
|
||||
}
|
||||
copySharedLocales()
|
||||
|
||||
// core 合并可能覆盖 addons/index.json,需再次写入
|
||||
fs.writeFileSync(
|
||||
path.join(OUT_DIR, 'assets', 'addons', 'index.json'),
|
||||
JSON.stringify(indexJson, null, 2) + '\n',
|
||||
'utf-8'
|
||||
)
|
||||
for (const key of installedKeys) {
|
||||
writeAddonManifest(key, path.join(OUT_DIR, 'assets', 'addons', key))
|
||||
}
|
||||
|
||||
fixIndexHtml()
|
||||
injectImportMap()
|
||||
const cleaned = stripBuiltAssets(OUT_DIR)
|
||||
if (cleaned.length) {
|
||||
console.log(`[assemble] stripped element-plus style imports from ${cleaned.length} js files`)
|
||||
}
|
||||
console.log(`[assemble] done: core + ${installedKeys.length} addons`)
|
||||
if (report.failed?.length) {
|
||||
console.warn('[assemble] skipped failed addons:', report.failed.map((f) => f.key).join(', '))
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
56
admin/scripts/build-addon.cjs
Normal file
56
admin/scripts/build-addon.cjs
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* 编译单个 addon
|
||||
*
|
||||
* 流程:generate-addon-entry → vite lib build → sync-addon
|
||||
* 输出 staging:dist/.addons/{key}/
|
||||
* 同步部署目录:dist/assets/addons/{key}/
|
||||
*
|
||||
* 用法:
|
||||
* node scripts/build-addon.cjs shop
|
||||
* ADDON_KEY=shop node scripts/build-addon.cjs
|
||||
*/
|
||||
const { spawnSync } = require('child_process')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { ROOT } = require('./addon-utils.cjs')
|
||||
|
||||
const key = process.argv[2] || process.env.ADDON_KEY
|
||||
if (!key) {
|
||||
console.error('Usage: node build-addon.cjs <addon-key>')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// 生成 .build/addons/{key}/entry.ts
|
||||
require('./generate-addon-entry.cjs')
|
||||
|
||||
const env = {
|
||||
...process.env,
|
||||
ADDON_KEY: key,
|
||||
NODE_OPTIONS: process.env.NODE_OPTIONS || '--max-old-space-size=4096'
|
||||
}
|
||||
|
||||
console.log(`[build-addon] building "${key}"...`)
|
||||
const r = spawnSync('npx', ['vite', 'build', '--config', 'vite.config.addon.ts'], {
|
||||
cwd: ROOT,
|
||||
env,
|
||||
stdio: 'inherit',
|
||||
shell: process.platform === 'win32'
|
||||
})
|
||||
|
||||
if (r.status !== 0) {
|
||||
console.error(`[build-addon] FAILED: ${key}`)
|
||||
process.exit(r.status ?? 1)
|
||||
}
|
||||
|
||||
// 复制到 dist/assets/addons 并更新 build-report.json
|
||||
const sync = spawnSync('node', ['scripts/sync-addon.cjs', key], {
|
||||
cwd: ROOT,
|
||||
stdio: 'inherit',
|
||||
shell: process.platform === 'win32'
|
||||
})
|
||||
if (sync.status !== 0) {
|
||||
process.exit(sync.status ?? 1)
|
||||
}
|
||||
|
||||
console.log(`[build-addon] OK: ${key}`)
|
||||
process.exit(0)
|
||||
86
admin/scripts/build-all.cjs
Normal file
86
admin/scripts/build-all.cjs
Normal file
@ -0,0 +1,86 @@
|
||||
/**
|
||||
* 全量生产构建(npm run build)
|
||||
*
|
||||
* 1. build-shared 共享 ESM(vue、admin-lang 等)
|
||||
* 2. vite core 主应用 → dist/.core
|
||||
* 3. addon 并行编译 每个 src/addon/* → dist/.addons/*
|
||||
* 4. assemble 合并为可部署 dist/
|
||||
* 5. publish 复制到 PUBLISH_DEST(默认 ../niucloud/public/admin)
|
||||
*/
|
||||
const { spawnSync } = require('child_process')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { ROOT, listAddonKeys } = require('./addon-utils.cjs')
|
||||
|
||||
const REPORT_PATH = path.join(ROOT, 'build-report.json')
|
||||
|
||||
function run(cmd, args, env = {}) {
|
||||
const r = spawnSync(cmd, args, {
|
||||
cwd: ROOT,
|
||||
env: { ...process.env, ...env },
|
||||
stdio: 'inherit',
|
||||
shell: process.platform === 'win32'
|
||||
})
|
||||
return r.status ?? 1
|
||||
}
|
||||
|
||||
/** 多 worker 从队列取 key 构建 addon,限制并发降低内存峰值 */
|
||||
async function buildAddonsParallel(keys, concurrency = 2) {
|
||||
const success = []
|
||||
const failed = []
|
||||
const queue = [...keys]
|
||||
|
||||
async function worker() {
|
||||
while (queue.length) {
|
||||
const key = queue.shift()
|
||||
if (!key) break
|
||||
const code = run('node', [path.join(__dirname, 'build-addon.cjs'), key])
|
||||
if (code === 0) success.push(key)
|
||||
else failed.push({ key, error: 'build failed' })
|
||||
}
|
||||
}
|
||||
|
||||
const workers = Array.from({ length: Math.min(concurrency, keys.length) }, () => worker())
|
||||
await Promise.all(workers)
|
||||
return { success, failed }
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('[build-all] step 1/5: shared deps')
|
||||
const sharedCode = run('node', [path.join(__dirname, 'build-shared.cjs')])
|
||||
if (sharedCode !== 0) {
|
||||
console.error('[build-all] shared build failed')
|
||||
process.exit(sharedCode)
|
||||
}
|
||||
|
||||
console.log('[build-all] step 2/5: core build')
|
||||
const coreCode = run('npx', ['vite', 'build', '--config', 'vite.config.core.ts'], {
|
||||
NODE_OPTIONS: '--max-old-space-size=4096'
|
||||
})
|
||||
if (coreCode !== 0) {
|
||||
console.error('[build-all] core build failed')
|
||||
process.exit(coreCode)
|
||||
}
|
||||
|
||||
const keys = listAddonKeys()
|
||||
console.log(`[build-all] step 3/5: addon builds (${keys.length} addons, concurrency 2)`)
|
||||
const { success, failed } = await buildAddonsParallel(keys, 2)
|
||||
|
||||
fs.writeFileSync(REPORT_PATH, JSON.stringify({ success, failed, time: new Date().toISOString() }, null, 2) + '\n', 'utf-8')
|
||||
console.log(`[build-all] addons: ${success.length} ok, ${failed.length} failed`)
|
||||
|
||||
console.log('[build-all] step 4/5: assemble')
|
||||
const asmCode = run('node', [path.join(__dirname, 'assemble-admin.cjs')])
|
||||
if (asmCode !== 0) process.exit(asmCode)
|
||||
|
||||
console.log('[build-all] step 5/5: publish')
|
||||
const pubCode = run('node', [path.join(ROOT, 'publish.cjs')])
|
||||
if (pubCode !== 0) process.exit(pubCode)
|
||||
|
||||
console.log('[build-all] complete')
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e)
|
||||
process.exit(1)
|
||||
})
|
||||
120
admin/scripts/build-shared.cjs
Normal file
120
admin/scripts/build-shared.cjs
Normal file
@ -0,0 +1,120 @@
|
||||
/**
|
||||
* 构建浏览器 ESM 共享依赖 → dist/.shared/
|
||||
*
|
||||
* 产物经 assemble 复制到 dist/assets/shared/,由 Import Map 加载。
|
||||
* admin-lang 将 src/lang 打成独立包,供 core 与 addon 共用 t()。
|
||||
*
|
||||
* 用法:npm run build:shared
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { spawnSync } = require('child_process')
|
||||
const { ROOT } = require('./addon-utils.cjs')
|
||||
const { SHARED_BUILD_ORDER } = require('./shared-external.cjs')
|
||||
|
||||
/** 临时入口目录,每次构建前重写 */
|
||||
const SHARED_SRC = path.join(ROOT, '.build', 'shared')
|
||||
/** Vite shared 构建 staging 输出 */
|
||||
const OUT_DIR = path.join(ROOT, 'dist', '.shared')
|
||||
|
||||
/** 各 shared 包的极简 re-export 入口(由 vite.config.shared.ts 打包) */
|
||||
const ENTRY_CONTENT = {
|
||||
vue: "import * as Vue from 'vue'\nexport * from 'vue'\nexport default Vue\n",
|
||||
'vue-router': "export * from 'vue-router'\n",
|
||||
pinia: "export * from 'pinia'\n",
|
||||
'element-plus': "import * as ElementPlus from 'element-plus'\nexport * from 'element-plus'\nexport default ElementPlus\n",
|
||||
'icons-vue': "export * from '@element-plus/icons-vue'\n",
|
||||
axios: "export { default } from 'axios'\nexport * from 'axios'\n",
|
||||
'vue-i18n': "export * from 'vue-i18n/dist/vue-i18n.esm-bundler.js'\n",
|
||||
'admin-lang': "export { language, t, default } from '../../src/lang/index.ts'\n",
|
||||
'core-shared': '' // 动态生成,从 API 目录扫描
|
||||
}
|
||||
|
||||
function writeEntries() {
|
||||
fs.mkdirSync(SHARED_SRC, { recursive: true })
|
||||
|
||||
// 动态生成 core-shared:全量重导出所有 @/app/api/* + @/utils/* 模块
|
||||
const apiDir = path.join(ROOT, 'src', 'app', 'api')
|
||||
const apiExports = []
|
||||
if (fs.existsSync(apiDir)) {
|
||||
for (const f of fs.readdirSync(apiDir)) {
|
||||
if (f.endsWith('.ts') && f !== 'addon.ts' && f !== 'module.ts') {
|
||||
const mod = f.replace('.ts', '')
|
||||
apiExports.push(`export * from '../../src/app/api/${mod}'`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const utilsDir = path.join(ROOT, 'src', 'utils')
|
||||
const utilsExports = []
|
||||
if (fs.existsSync(utilsDir)) {
|
||||
for (const f of fs.readdirSync(utilsDir)) {
|
||||
// common 和 request 单独处理,其余全量重导出
|
||||
if (f.endsWith('.ts') && f !== 'common.ts' && f !== 'request.ts' && f !== 'addon-loader.ts' && f !== 'addon-lang.ts') {
|
||||
const mod = f.replace('.ts', '')
|
||||
utilsExports.push(`export * from '../../src/utils/${mod}'`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ENTRY_CONTENT['core-shared'] = [
|
||||
"export * from '../../src/utils/common'",
|
||||
"import _request from '../../src/utils/request'",
|
||||
"export { _request as request }",
|
||||
"export default _request",
|
||||
...utilsExports,
|
||||
...apiExports,
|
||||
"export { default as UploadImage } from '../../src/components/upload-image/index.vue'",
|
||||
"export { default as DiyPage } from '../../src/components/diy-page/index.vue'",
|
||||
"export { default as MapSelector } from '../../src/components/map-selector/index.vue'",
|
||||
"export { default as Editor } from '../../src/components/editor/index.vue'"
|
||||
].join('\n')
|
||||
|
||||
for (const [key, content] of Object.entries(ENTRY_CONTENT)) {
|
||||
fs.writeFileSync(path.join(SHARED_SRC, `${key}.ts`), content, 'utf-8')
|
||||
}
|
||||
}
|
||||
|
||||
/** 构建单个 shared 包;仅第一个包 emptyOutDir 清空 .shared */
|
||||
function runBuild(pkgKey, emptyOutDir) {
|
||||
const r = spawnSync('npx', ['vite', 'build', '--config', 'vite.config.shared.ts'], {
|
||||
cwd: ROOT,
|
||||
env: {
|
||||
...process.env,
|
||||
SHARED_PKG: pkgKey,
|
||||
SHARED_EMPTY: emptyOutDir ? '1' : '0',
|
||||
NODE_OPTIONS: '--max-old-space-size=4096'
|
||||
},
|
||||
stdio: 'inherit',
|
||||
shell: process.platform === 'win32'
|
||||
})
|
||||
if ((r.status ?? 1) !== 0) {
|
||||
console.error(`[build-shared] failed: ${pkgKey}`)
|
||||
process.exit(r.status ?? 1)
|
||||
}
|
||||
console.log(`[build-shared] ok: ${pkgKey}.js`)
|
||||
}
|
||||
|
||||
function main() {
|
||||
writeEntries()
|
||||
fs.mkdirSync(OUT_DIR, { recursive: true })
|
||||
|
||||
SHARED_BUILD_ORDER.forEach((pkgKey, i) => {
|
||||
runBuild(pkgKey, i === 0)
|
||||
})
|
||||
|
||||
console.log(`[build-shared] done -> ${path.relative(ROOT, OUT_DIR)}/`)
|
||||
|
||||
// 若 dist/assets 已存在(曾 assemble 过),顺便同步一份 shared 便于单独调试
|
||||
const distAssets = path.join(ROOT, 'dist', 'assets', 'shared')
|
||||
if (fs.existsSync(path.join(ROOT, 'dist', 'assets'))) {
|
||||
fs.mkdirSync(distAssets, { recursive: true })
|
||||
for (const name of fs.readdirSync(OUT_DIR)) {
|
||||
if (!name.endsWith('.js')) continue
|
||||
fs.copyFileSync(path.join(OUT_DIR, name), path.join(distAssets, name))
|
||||
}
|
||||
console.log(`[build-shared] synced -> dist/assets/shared/`)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
97
admin/scripts/check-deploy.cjs
Normal file
97
admin/scripts/check-deploy.cjs
Normal file
@ -0,0 +1,97 @@
|
||||
/**
|
||||
* 部署目录健康检查
|
||||
*
|
||||
* 校验 public/admin 是否具备 split 架构所需文件:
|
||||
* - index.html 入口、shared、admin-lang.js
|
||||
* - addons/index.json、shop 等插件
|
||||
* - 无错误 admin-lang 相对路径、无重复 createI18n
|
||||
*
|
||||
* 用法:node scripts/check-deploy.cjs [deploy-dir]
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const DEPLOY = process.argv[2] || 'D:/AppData/phpstudy_pro/WWW/test/niucloud/public/admin'
|
||||
const issues = []
|
||||
const ok = []
|
||||
|
||||
function check(name, pass, detail) {
|
||||
if (pass) ok.push(`[OK] ${name}${detail ? ': ' + detail : ''}`)
|
||||
else issues.push(`[FAIL] ${name}${detail ? ': ' + detail : ''}`)
|
||||
}
|
||||
|
||||
if (!fs.existsSync(DEPLOY)) {
|
||||
console.error('deploy dir not found:', DEPLOY)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const html = fs.readFileSync(path.join(DEPLOY, 'index.html'), 'utf-8')
|
||||
const entryMatch = html.match(/\/admin\/assets\/(index-[a-f0-9]+\.js)/)
|
||||
const entry = entryMatch ? entryMatch[1] : null
|
||||
check('index.html entry', !!entry, entry || 'no index-*.js in script src')
|
||||
|
||||
if (entry) {
|
||||
const entryPath = path.join(DEPLOY, 'assets', entry)
|
||||
check('entry file exists', fs.existsSync(entryPath))
|
||||
if (fs.existsSync(entryPath)) {
|
||||
const code = fs.readFileSync(entryPath, 'utf-8')
|
||||
check('core not stale', !code.includes('loadAddonCommonLocales'), 'must not contain loadAddonCommonLocales')
|
||||
check('core has addon loader', code.includes('assets/addons') || code.includes('/admin/assets/addons'))
|
||||
const oldPreload = /async function \w+\(\w+,t=\["zh-cn","en"\]\)/.test(code)
|
||||
check('core preload not old-only-common', !oldPreload)
|
||||
}
|
||||
}
|
||||
|
||||
// CSS hash 随构建变化;若 core 重建后此处失败,需同步更新此文件名
|
||||
const css = 'index-c72b4d30.css'
|
||||
check('entry css', fs.existsSync(path.join(DEPLOY, 'assets', css)), css)
|
||||
|
||||
for (const f of ['vue.js', 'element-plus.js', 'vue-i18n.js', 'admin-lang.js']) {
|
||||
check('shared/' + f, fs.existsSync(path.join(DEPLOY, 'assets', 'shared', f)))
|
||||
}
|
||||
|
||||
// 抽样检查 shop 列表页是否走共享 admin-lang
|
||||
const shopList = fs.existsSync(path.join(DEPLOY, 'assets', 'addons', 'shop'))
|
||||
? fs.readdirSync(path.join(DEPLOY, 'assets', 'addons', 'shop')).find((n) => n.startsWith('list-') && n.endsWith('.js'))
|
||||
: null
|
||||
if (shopList) {
|
||||
const code = fs.readFileSync(path.join(DEPLOY, 'assets', 'addons', 'shop', shopList), 'utf-8')
|
||||
check('shop list uses shared t()', code.includes('/admin/assets/shared/admin-lang.js'))
|
||||
check('shop list not duplicate i18n', !code.includes('createI18n'))
|
||||
}
|
||||
|
||||
const addonsIndex = path.join(DEPLOY, 'assets', 'addons', 'index.json')
|
||||
check('addons/index.json', fs.existsSync(addonsIndex))
|
||||
if (fs.existsSync(addonsIndex)) {
|
||||
const data = JSON.parse(fs.readFileSync(addonsIndex, 'utf-8'))
|
||||
check('addons keys', Array.isArray(data.keys) && data.keys.length > 0, data.keys?.join(', '))
|
||||
}
|
||||
|
||||
const shopIndex = path.join(DEPLOY, 'assets', 'addons', 'shop', 'index.js')
|
||||
check('shop/index.js', fs.existsSync(shopIndex))
|
||||
if (fs.existsSync(shopIndex)) {
|
||||
const shop = fs.readFileSync(shopIndex, 'utf-8')
|
||||
check('shop exports langs', shop.includes('langs'))
|
||||
}
|
||||
|
||||
const { hasBadImport } = require('./admin-lang-import-utils.cjs')
|
||||
let badLangImports = 0
|
||||
const assetsDir = path.join(DEPLOY, 'assets')
|
||||
if (fs.existsSync(assetsDir)) {
|
||||
for (const name of fs.readdirSync(assetsDir)) {
|
||||
if (!name.endsWith('.js')) continue
|
||||
if (hasBadImport(fs.readFileSync(path.join(assetsDir, name), 'utf-8'))) badLangImports++
|
||||
}
|
||||
}
|
||||
check('no bad admin-lang import paths', badLangImports === 0, badLangImports ? `${badLangImports} core chunk(s)` : '')
|
||||
|
||||
const staleEntry = path.join(DEPLOY, 'assets', 'index-d2fee835.js')
|
||||
if (fs.existsSync(staleEntry)) {
|
||||
issues.push('[WARN] old bundle still present: index-d2fee835.js (harmless if index.html points to new entry)')
|
||||
}
|
||||
|
||||
console.log('\n=== Deploy check:', DEPLOY, '===\n')
|
||||
ok.forEach((l) => console.log(l))
|
||||
issues.forEach((l) => console.log(l))
|
||||
console.log('\nSummary:', ok.length, 'ok,', issues.length, 'issue(s)')
|
||||
process.exit(issues.some((l) => l.startsWith('[FAIL]')) ? 1 : 0)
|
||||
25
admin/scripts/clean-core.cjs
Normal file
25
admin/scripts/clean-core.cjs
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 删除 dist/.core(core 构建 staging)
|
||||
*
|
||||
* build:core 在 vite build 前执行,避免 Windows 上旧 chunk 残留导致 hash 不一致。
|
||||
* 使用 rename → 再删 的策略,降低文件被占用时 rmSync 失败的概率。
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const core = path.join(__dirname, '..', 'dist', '.core')
|
||||
|
||||
function rmDir(dir) {
|
||||
if (!fs.existsSync(dir)) return
|
||||
const trash = `${dir}.__trash_${Date.now()}`
|
||||
try {
|
||||
fs.renameSync(dir, trash)
|
||||
} catch {
|
||||
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 })
|
||||
return
|
||||
}
|
||||
fs.rmSync(trash, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 })
|
||||
}
|
||||
|
||||
rmDir(core)
|
||||
console.log('[clean-core] removed dist/.core')
|
||||
128
admin/scripts/deploy-to.cjs
Normal file
128
admin/scripts/deploy-to.cjs
Normal file
@ -0,0 +1,128 @@
|
||||
/**
|
||||
* 发布 dist 到目标 admin 目录(保留已 drop-in 的插件)
|
||||
*
|
||||
* 用法:
|
||||
* node scripts/deploy-to.cjs [deploy-dir]
|
||||
* node scripts/deploy-to.cjs "D:/path/to/public/admin"
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { ROOT } = require('./addon-utils.cjs')
|
||||
const { fixDir } = require('./admin-lang-import-utils.cjs')
|
||||
|
||||
const src = path.join(ROOT, 'dist')
|
||||
const dest = path.resolve(process.argv[2] || process.env.PUBLISH_DEST || path.join(ROOT, '../niucloud/public/admin'))
|
||||
const backup = path.join(ROOT, '.deploy_addons_backup')
|
||||
|
||||
function rmDir(dir) {
|
||||
if (!fs.existsSync(dir)) return
|
||||
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 8, retryDelay: 200 })
|
||||
}
|
||||
|
||||
function copyTree(from, to) {
|
||||
fs.mkdirSync(path.dirname(to), { recursive: true })
|
||||
fs.cpSync(from, to, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
function readKeys(addonsDir) {
|
||||
const p = path.join(addonsDir, 'index.json')
|
||||
if (!fs.existsSync(p)) return []
|
||||
try {
|
||||
const data = JSON.parse(fs.readFileSync(p, 'utf-8'))
|
||||
return Array.isArray(data.keys) ? data.keys : []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
function writeKeys(addonsDir, keys) {
|
||||
fs.mkdirSync(addonsDir, { recursive: true })
|
||||
fs.writeFileSync(
|
||||
path.join(addonsDir, 'index.json'),
|
||||
JSON.stringify({ keys: [...new Set(keys)].sort(), sharedVersion: 'admin-core-1.0.0' }, null, 2) + '\n'
|
||||
)
|
||||
}
|
||||
|
||||
function listDropInKeys(addonsDir) {
|
||||
if (!fs.existsSync(addonsDir)) return []
|
||||
return fs.readdirSync(addonsDir).filter((name) => {
|
||||
if (name === 'index.json' || name.startsWith('.')) return false
|
||||
return fs.existsSync(path.join(addonsDir, name, 'index.js'))
|
||||
})
|
||||
}
|
||||
|
||||
function main() {
|
||||
if (!fs.existsSync(path.join(src, 'index.html'))) {
|
||||
console.error('[deploy] missing dist/index.html — run: npm run build:core')
|
||||
process.exit(1)
|
||||
}
|
||||
if (!fs.existsSync(dest)) {
|
||||
console.error(`[deploy] target not found: ${dest}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const destAddons = path.join(dest, 'assets', 'addons')
|
||||
rmDir(backup)
|
||||
if (fs.existsSync(destAddons)) {
|
||||
copyTree(destAddons, backup)
|
||||
console.log(`[deploy] backed up existing addons -> ${path.relative(ROOT, backup)}`)
|
||||
}
|
||||
|
||||
const preserveKeys = [...new Set([...readKeys(backup), ...listDropInKeys(backup)])]
|
||||
|
||||
// 根目录静态文件
|
||||
for (const name of ['index.html', 'manifest.json', 'niucloud.ico']) {
|
||||
const f = path.join(src, name)
|
||||
if (fs.existsSync(f)) fs.copyFileSync(f, path.join(dest, name))
|
||||
}
|
||||
const ueditor = path.join(src, 'ueditor')
|
||||
if (fs.existsSync(ueditor)) {
|
||||
rmDir(path.join(dest, 'ueditor'))
|
||||
copyTree(ueditor, path.join(dest, 'ueditor'))
|
||||
}
|
||||
|
||||
// core assets(跳过 addons,单独合并)
|
||||
const srcAssets = path.join(src, 'assets')
|
||||
const destAssets = path.join(dest, 'assets')
|
||||
fs.mkdirSync(destAssets, { recursive: true })
|
||||
for (const name of fs.readdirSync(srcAssets)) {
|
||||
if (name === 'addons') continue
|
||||
const from = path.join(srcAssets, name)
|
||||
const to = path.join(destAssets, name)
|
||||
rmDir(to)
|
||||
copyTree(from, to)
|
||||
}
|
||||
|
||||
// 合并 addons:dist 构建产物 + 目标站 drop-in
|
||||
const mergedAddons = path.join(destAssets, 'addons')
|
||||
fs.mkdirSync(mergedAddons, { recursive: true })
|
||||
const srcAddons = path.join(srcAssets, 'addons')
|
||||
if (fs.existsSync(srcAddons)) {
|
||||
copyTree(srcAddons, mergedAddons)
|
||||
}
|
||||
for (const key of preserveKeys) {
|
||||
const from = path.join(backup, key)
|
||||
const to = path.join(mergedAddons, key)
|
||||
if (!fs.existsSync(path.join(from, 'index.js'))) continue
|
||||
if (fs.existsSync(path.join(to, 'index.js'))) continue
|
||||
copyTree(from, to)
|
||||
console.log(`[deploy] preserved drop-in addon "${key}"`)
|
||||
}
|
||||
|
||||
const keys = [...new Set([
|
||||
...readKeys(mergedAddons),
|
||||
...readKeys(backup),
|
||||
...preserveKeys
|
||||
])]
|
||||
if (keys.length) writeKeys(mergedAddons, keys)
|
||||
|
||||
fixDir(destAssets)
|
||||
rmDir(backup)
|
||||
|
||||
console.log(`[deploy] ${src} -> ${dest}`)
|
||||
console.log(`[deploy] addons: ${keys.join(', ') || '(none)'}`)
|
||||
const hasDropIn = fs.readFileSync(path.join(destAssets, 'shared', 'admin-lang.js'), 'utf-8').includes('drop-in entry')
|
||||
console.log(`[deploy] drop-in runtime: ${hasDropIn ? 'OK' : 'MISSING — rebuild shared'}`)
|
||||
}
|
||||
|
||||
main()
|
||||
185
admin/scripts/ensure-esbuild.cjs
Normal file
185
admin/scripts/ensure-esbuild.cjs
Normal file
@ -0,0 +1,185 @@
|
||||
/**
|
||||
* 构建前确保 esbuild 原生二进制可用。
|
||||
*
|
||||
* Windows 上 @esbuild/win32-x64/esbuild.exe 常被杀毒删除,或 npm postinstall
|
||||
* 在二进制缺失时调用 install.js 形成死循环。本脚本直接从 npm 拉取 tgz 解压,
|
||||
* 不依赖 esbuild/install.js。
|
||||
*
|
||||
* 若 npm install 因 esbuild postinstall 失败,请先:
|
||||
* npm install --ignore-scripts
|
||||
* node scripts/ensure-esbuild.cjs
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const https = require('https')
|
||||
const zlib = require('zlib')
|
||||
const { spawnSync, execFileSync } = require('child_process')
|
||||
|
||||
const ROOT = path.resolve(__dirname, '..')
|
||||
const DEFAULT_ESBUILD_VERSION = '0.16.17'
|
||||
|
||||
function platformPackage() {
|
||||
const key = `${process.platform} ${process.arch} ${require('os').endianness()}`
|
||||
const map = {
|
||||
'win32 x64 LE': { pkg: '@esbuild/win32-x64', subpath: 'esbuild.exe' },
|
||||
'win32 ia32 LE': { pkg: '@esbuild/win32-ia32', subpath: 'esbuild.exe' },
|
||||
'win32 arm64 LE': { pkg: '@esbuild/win32-arm64', subpath: 'esbuild.exe' },
|
||||
'darwin x64 LE': { pkg: '@esbuild/darwin-x64', subpath: 'bin/esbuild' },
|
||||
'darwin arm64 LE': { pkg: '@esbuild/darwin-arm64', subpath: 'bin/esbuild' },
|
||||
'linux x64 LE': { pkg: '@esbuild/linux-x64', subpath: 'bin/esbuild' }
|
||||
}
|
||||
const hit = map[key]
|
||||
if (!hit) throw new Error(`Unsupported platform for esbuild: ${key}`)
|
||||
return hit
|
||||
}
|
||||
|
||||
function resolveEsbuildVersion() {
|
||||
const candidates = [
|
||||
path.join(ROOT, 'node_modules', 'esbuild', 'package.json'),
|
||||
path.join(ROOT, 'node_modules', 'vite', 'node_modules', 'esbuild', 'package.json')
|
||||
]
|
||||
for (const file of candidates) {
|
||||
try {
|
||||
return require(file).version
|
||||
} catch {
|
||||
// continue
|
||||
}
|
||||
}
|
||||
return DEFAULT_ESBUILD_VERSION
|
||||
}
|
||||
|
||||
function platformBinaryPath() {
|
||||
const { pkg, subpath } = platformPackage()
|
||||
return path.join(ROOT, 'node_modules', ...pkg.split('/'), subpath)
|
||||
}
|
||||
|
||||
function downloadedBinaryPath(version) {
|
||||
const { pkg, subpath } = platformPackage()
|
||||
const libDir = path.join(ROOT, 'node_modules', 'esbuild', 'lib')
|
||||
const base = path.basename(subpath)
|
||||
return path.join(libDir, `downloaded-${pkg.replace('/', '-')}-${base}`)
|
||||
}
|
||||
|
||||
function binaryCandidates(version) {
|
||||
return [platformBinaryPath(), downloadedBinaryPath(version)]
|
||||
}
|
||||
|
||||
function fetchBuffer(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
https.get(url, (res) => {
|
||||
if ((res.statusCode === 301 || res.statusCode === 302) && res.headers.location) {
|
||||
return fetchBuffer(res.headers.location).then(resolve, reject)
|
||||
}
|
||||
if (res.statusCode !== 200) {
|
||||
return reject(new Error(`HTTP ${res.statusCode} for ${url}`))
|
||||
}
|
||||
const chunks = []
|
||||
res.on('data', (c) => chunks.push(c))
|
||||
res.on('end', () => resolve(Buffer.concat(chunks)))
|
||||
}).on('error', reject)
|
||||
})
|
||||
}
|
||||
|
||||
function extractFileFromTarGzip(buffer, subpath) {
|
||||
try {
|
||||
buffer = zlib.unzipSync(buffer)
|
||||
} catch (err) {
|
||||
throw new Error(`Invalid gzip: ${err.message}`)
|
||||
}
|
||||
const str = (i, n) => String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\0.*$/, '')
|
||||
let offset = 0
|
||||
const target = `package/${subpath}`
|
||||
while (offset < buffer.length) {
|
||||
const name = str(offset, 100)
|
||||
const size = parseInt(str(offset + 124, 12), 8)
|
||||
offset += 512
|
||||
if (!Number.isNaN(size)) {
|
||||
if (name === target) return buffer.subarray(offset, offset + size)
|
||||
offset += (size + 511) & ~511
|
||||
}
|
||||
}
|
||||
throw new Error(`Not found in archive: ${target}`)
|
||||
}
|
||||
|
||||
async function downloadPlatformBinary(version) {
|
||||
const { pkg, subpath } = platformPackage()
|
||||
const shortName = pkg.replace('@esbuild/', '')
|
||||
const url = `https://registry.npmjs.org/${pkg}/-/${shortName}-${version}.tgz`
|
||||
console.log(`[ensure-esbuild] downloading ${pkg}@${version} ...`)
|
||||
const tgz = await fetchBuffer(url)
|
||||
const data = extractFileFromTarGzip(tgz, subpath)
|
||||
const dest = platformBinaryPath()
|
||||
fs.mkdirSync(path.dirname(dest), { recursive: true })
|
||||
fs.writeFileSync(dest, data)
|
||||
if (process.platform !== 'win32') fs.chmodSync(dest, 0o755)
|
||||
console.log(`[ensure-esbuild] wrote ${path.relative(ROOT, dest)} (${data.length} bytes)`)
|
||||
return dest
|
||||
}
|
||||
|
||||
function copyToDownloadedCache(version, src) {
|
||||
const cache = downloadedBinaryPath(version)
|
||||
const libDir = path.dirname(cache)
|
||||
if (!fs.existsSync(path.join(ROOT, 'node_modules', 'esbuild'))) return
|
||||
fs.mkdirSync(libDir, { recursive: true })
|
||||
fs.copyFileSync(src, cache)
|
||||
}
|
||||
|
||||
function verifyBinary(binPath, version) {
|
||||
const out = execFileSync(binPath, ['--version'], { stdio: 'pipe' }).toString().trim()
|
||||
if (out !== version) {
|
||||
throw new Error(`Expected esbuild ${version}, got ${out}`)
|
||||
}
|
||||
}
|
||||
|
||||
function hasWorkingBinary(version) {
|
||||
for (const p of binaryCandidates(version)) {
|
||||
try {
|
||||
if (fs.existsSync(p) && fs.statSync(p).size > 1024) {
|
||||
verifyBinary(p, version)
|
||||
return p
|
||||
}
|
||||
} catch {
|
||||
// try next
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async function repair(version) {
|
||||
const dest = await downloadPlatformBinary(version)
|
||||
copyToDownloadedCache(version, dest)
|
||||
verifyBinary(dest, version)
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const version = resolveEsbuildVersion()
|
||||
const existing = hasWorkingBinary(version)
|
||||
if (existing) {
|
||||
console.log(`[ensure-esbuild] ok (${path.relative(ROOT, existing)}, v${version})`)
|
||||
return
|
||||
}
|
||||
|
||||
console.log(`[ensure-esbuild] binary missing or invalid, repairing (esbuild@${version})...`)
|
||||
try {
|
||||
await repair(version)
|
||||
} catch (err) {
|
||||
console.error('[ensure-esbuild] repair failed:', err.message || err)
|
||||
console.error('')
|
||||
console.error('Try:')
|
||||
console.error(' npm install --ignore-scripts')
|
||||
console.error(' node scripts/ensure-esbuild.cjs')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const ok = hasWorkingBinary(version)
|
||||
if (!ok) {
|
||||
console.error('[ensure-esbuild] binary still not usable after repair.')
|
||||
process.exit(1)
|
||||
}
|
||||
console.log('[ensure-esbuild] ok')
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error('[ensure-esbuild]', err)
|
||||
process.exit(1)
|
||||
})
|
||||
39
admin/scripts/fix-admin-lang-imports.cjs
Normal file
39
admin/scripts/fix-admin-lang-imports.cjs
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* CLI:修复构建产物中的 admin-lang import 路径
|
||||
*
|
||||
* 默认扫描 dist/.core/assets 与 dist/assets;
|
||||
* 部署后可对 public/admin/assets 单独执行。
|
||||
*
|
||||
* 用法:
|
||||
* node scripts/fix-admin-lang-imports.cjs
|
||||
* node scripts/fix-admin-lang-imports.cjs "D:/path/to/public/admin/assets"
|
||||
*/
|
||||
const path = require('path')
|
||||
const { fixDir, ADMIN_LANG_URL } = require('./admin-lang-import-utils.cjs')
|
||||
|
||||
const targets = process.argv.slice(2)
|
||||
const dirs = targets.length
|
||||
? targets.map((d) => path.resolve(d))
|
||||
: [
|
||||
path.join(__dirname, '..', 'dist', '.core', 'assets'),
|
||||
path.join(__dirname, '..', 'dist', 'assets')
|
||||
]
|
||||
|
||||
let total = 0
|
||||
for (const dir of dirs) {
|
||||
try {
|
||||
const n = fixDir(dir)
|
||||
if (n) console.log(`[fix-admin-lang-imports] ${path.relative(process.cwd(), dir)}: ${n} file(s)`)
|
||||
total += n
|
||||
} catch (err) {
|
||||
console.error(err.message)
|
||||
console.error('Usage: node scripts/fix-admin-lang-imports.cjs <assets-directory>')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
if (total === 0) {
|
||||
console.log('[fix-admin-lang-imports] no bad imports found')
|
||||
} else {
|
||||
console.log(`[fix-admin-lang-imports] fixed ${total} file(s) -> ${ADMIN_LANG_URL}`)
|
||||
}
|
||||
115
admin/scripts/generate-addon-entry.cjs
Normal file
115
admin/scripts/generate-addon-entry.cjs
Normal file
@ -0,0 +1,115 @@
|
||||
/**
|
||||
* 为单个 addon 生成 Vite lib 构建入口:.build/addons/{key}/entry.ts
|
||||
*
|
||||
* 入口导出:
|
||||
* - addonKey / sharedVersion
|
||||
* - views:视图路径 → 动态 import 函数(运行时 loadAddonView 调用)
|
||||
* - langs:各 locale 语言 json 静态 import(打进 index.js,启动时 preload)
|
||||
*
|
||||
* 由 build-addon.cjs 在 vite build 前调用。
|
||||
* 用法:node scripts/generate-addon-entry.cjs <addon-key>
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { ROOT, ADDON_DIR, scanAddonViews, scanAddonLang } = require('./addon-utils.cjs')
|
||||
|
||||
const key = process.argv[2] || process.env.ADDON_KEY
|
||||
if (!key) {
|
||||
console.error('Usage: node generate-addon-entry.cjs <addon-key>')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const views = scanAddonViews(key)
|
||||
const langMap = scanAddonLang(key)
|
||||
const outDir = path.join(ROOT, '.build', 'addons', key)
|
||||
fs.mkdirSync(outDir, { recursive: true })
|
||||
|
||||
// views 映射:'order/list' => () => import('.../order/list.vue')
|
||||
const viewLines = views.map((v) =>
|
||||
` '${v.replace(/'/g, "\\'")}': () => import('@/addon/${key}/views/${v}.vue'),`
|
||||
).join('\n')
|
||||
|
||||
// components 映射:diy/poster/printer/delivery 等子目录下的可复用组件
|
||||
// 供 loadAddonComponent / diy 编辑页在生产环境使用
|
||||
const componentSubdirs = ['diy/components', 'diy_form/components', 'poster/components', 'printer/components', 'delivery/components']
|
||||
const componentLines = []
|
||||
for (const sub of componentSubdirs) {
|
||||
const dir = path.join(ADDON_DIR, key, 'views', sub)
|
||||
if (!fs.existsSync(dir)) continue
|
||||
const files = fs.readdirSync(dir).filter((f) => f.endsWith('.vue'))
|
||||
for (const f of files) {
|
||||
const name = f.replace('.vue', '')
|
||||
componentLines.push(` '${sub}/${name}': () => import('@/addon/${key}/views/${sub}/${f}'),`)
|
||||
}
|
||||
}
|
||||
const componentBlock = componentLines.length ? componentLines.join('\n') : ''
|
||||
|
||||
// 插件 router/index.ts 中的 ROUTE/NO_LOGIN_ROUTES 不做 re-export
|
||||
// 原因:
|
||||
// 1. 生产环境下插件路由由 core 通过后端菜单 API 下发(src/router/index.ts:13 DEV only)
|
||||
// 2. router/index.ts 通常引用 @/layout/index.vue,该文件又导入 @/utils/addon-loader
|
||||
// 其中的 import.meta.glob 会匹配数百个核心 .vue 文件,全部打进插件包导致 404
|
||||
let routerExport = ''
|
||||
// 如需开发调试,设置 ADDON_ENTRY_DEV=1 环境变量
|
||||
const isDev = process.env.ADDON_ENTRY_DEV === '1'
|
||||
const routerPath = path.join(ADDON_DIR, key, 'router', 'index.ts')
|
||||
if (fs.existsSync(routerPath)) {
|
||||
const routerText = fs.readFileSync(routerPath, 'utf-8')
|
||||
const routerExports = []
|
||||
if (/export\s+(?:const|let|var)\s+ROUTE\b/.test(routerText) || /export\s*\{[^}]*\bROUTE\b/.test(routerText)) {
|
||||
routerExports.push('ROUTE')
|
||||
}
|
||||
if (/export\s+(?:const|let|var)\s+NO_LOGIN_ROUTES\b/.test(routerText) || /export\s*\{[^}]*\bNO_LOGIN_ROUTES\b/.test(routerText)) {
|
||||
routerExports.push('NO_LOGIN_ROUTES')
|
||||
}
|
||||
if (routerExports.length && isDev) {
|
||||
routerExport = `export { ${routerExports.join(', ')} } from '@/addon/${key}/router/index.ts'\n`
|
||||
}
|
||||
if (routerExports.length && !isDev) {
|
||||
console.log(`[addon-entry] ${key}: skipping ROUTE/NO_LOGIN_ROUTES re-export (prod: routes from backend API)`)
|
||||
}
|
||||
}
|
||||
|
||||
/** 语言 json 文件名含点号,变量名需消毒为合法标识符 */
|
||||
function safeImportVar(locale, file) {
|
||||
return 'lang_' + `${locale}_${file}`.replace(/[^a-zA-Z0-9_]/g, '_')
|
||||
}
|
||||
|
||||
const langImports = []
|
||||
const langByLocale = {}
|
||||
for (const [locale, files] of Object.entries(langMap)) {
|
||||
langByLocale[locale] = []
|
||||
for (const file of files) {
|
||||
const varName = safeImportVar(locale, file)
|
||||
langImports.push(`import ${varName} from '@/addon/${key}/lang/${locale}/${file}.json'`)
|
||||
langByLocale[locale].push(` '${file.replace(/'/g, "\\'")}': ${varName}`)
|
||||
}
|
||||
}
|
||||
|
||||
const langsBlock = Object.keys(langByLocale).length
|
||||
? `export const langs: Record<string, Record<string, Record<string, string>>> = {\n${Object.entries(langByLocale).map(([locale, entries]) =>
|
||||
` '${locale.replace(/'/g, "\\'")}': {\n${entries.join(',\n')}\n }`
|
||||
).join(',\n')
|
||||
}\n}\n`
|
||||
: 'export const langs: Record<string, Record<string, Record<string, string>>> = {}\n'
|
||||
|
||||
const langCount = Object.values(langMap).reduce((n, files) => n + files.length, 0)
|
||||
|
||||
const content = `/* AUTO-GENERATED entry for addon "${key}" */
|
||||
${langImports.join('\n')}
|
||||
|
||||
export const addonKey = '${key}'
|
||||
export const sharedVersion = 'admin-core-1.0.0'
|
||||
|
||||
export const views: Record<string, () => Promise<any>> = {
|
||||
${viewLines}
|
||||
}
|
||||
|
||||
export const components: Record<string, () => Promise<any>> = {
|
||||
${componentBlock}
|
||||
}
|
||||
|
||||
${langsBlock}${routerExport}`
|
||||
|
||||
fs.writeFileSync(path.join(outDir, 'entry.ts'), content, 'utf-8')
|
||||
console.log(`[addon-entry] ${key}: ${views.length} views, ${langCount} lang files -> ${path.relative(ROOT, outDir)}/entry.ts`)
|
||||
67
admin/scripts/register-addon.cjs
Normal file
67
admin/scripts/register-addon.cjs
Normal file
@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 手动 drop-in 插件后登记到 assets/addons/index.json(可选)
|
||||
*
|
||||
* 场景:从另一个 admin 项目拷贝 assets/addons/{key}/ 到目标站点。
|
||||
* 运行时也会在登录后根据后端已安装插件 + 菜单自动探测 index.js,不强制依赖本脚本。
|
||||
*
|
||||
* 用法:
|
||||
* node scripts/register-addon.cjs <addon-key> [deploy-dir]
|
||||
* 示例:
|
||||
* node scripts/register-addon.cjs sd_minsu
|
||||
* node scripts/register-addon.cjs sd_minsu "D:/path/to/public/admin"
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { ROOT } = require('./addon-utils.cjs')
|
||||
|
||||
const key = process.argv[2]
|
||||
const deployDir = process.argv[3] ? path.resolve(process.argv[3]) : path.join(ROOT, 'dist')
|
||||
|
||||
if (!key) {
|
||||
console.error('Usage: node scripts/register-addon.cjs <addon-key> [deploy-dir]')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const addonDir = path.join(deployDir, 'assets', 'addons', key)
|
||||
const indexPath = path.join(deployDir, 'assets', 'addons', 'index.json')
|
||||
const entryPath = path.join(addonDir, 'index.js')
|
||||
const manifestPath = path.join(addonDir, 'manifest.json')
|
||||
|
||||
if (!fs.existsSync(entryPath)) {
|
||||
console.error(`[register-addon] missing ${entryPath}`)
|
||||
console.error('[register-addon] copy the full addon folder (index.js + chunks + lang/) first')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (!fs.existsSync(manifestPath)) {
|
||||
const manifest = {
|
||||
key,
|
||||
version: '1.0.0',
|
||||
sharedVersion: 'admin-core-1.0.0',
|
||||
entry: './index.js',
|
||||
langBase: './lang/'
|
||||
}
|
||||
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n', 'utf-8')
|
||||
console.log(`[register-addon] wrote manifest.json`)
|
||||
}
|
||||
|
||||
let data = { keys: [], sharedVersion: 'admin-core-1.0.0' }
|
||||
if (fs.existsSync(indexPath)) {
|
||||
try {
|
||||
data = JSON.parse(fs.readFileSync(indexPath, 'utf-8'))
|
||||
} catch {
|
||||
console.warn('[register-addon] index.json parse failed, recreating')
|
||||
}
|
||||
}
|
||||
|
||||
const keys = new Set(Array.isArray(data.keys) ? data.keys : [])
|
||||
const before = keys.size
|
||||
keys.add(key)
|
||||
data.keys = [...keys].sort()
|
||||
|
||||
fs.mkdirSync(path.dirname(indexPath), { recursive: true })
|
||||
fs.writeFileSync(indexPath, JSON.stringify(data, null, 2) + '\n', 'utf-8')
|
||||
|
||||
console.log(`[register-addon] ${key} registered in assets/addons/index.json (${before} -> ${data.keys.length} keys)`)
|
||||
console.log(`[register-addon] keys: ${data.keys.join(', ')}`)
|
||||
console.log('[register-addon] reminder: backend must also install this addon (menu API returns addon=sd_minsu)')
|
||||
30
admin/scripts/run-vite.cjs
Normal file
30
admin/scripts/run-vite.cjs
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 统一用 node 直接启动 vite(避免 Windows 上 npx + shell 触发 spawn EPERM)
|
||||
*
|
||||
* 用法:node scripts/run-vite.cjs build --config vite.config.shared.ts
|
||||
*/
|
||||
const path = require('path')
|
||||
const { spawnSync } = require('child_process')
|
||||
|
||||
const ROOT = path.resolve(__dirname, '..')
|
||||
const VITE_BIN = path.join(ROOT, 'node_modules', 'vite', 'bin', 'vite.js')
|
||||
|
||||
require('./ensure-esbuild.cjs')
|
||||
|
||||
const args = process.argv.slice(2)
|
||||
if (!args.length) {
|
||||
console.error('Usage: node scripts/run-vite.cjs <vite-args...>')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const r = spawnSync(process.execPath, [VITE_BIN, ...args], {
|
||||
cwd: ROOT,
|
||||
env: {
|
||||
...process.env,
|
||||
NODE_OPTIONS: process.env.NODE_OPTIONS || '--max-old-space-size=4096'
|
||||
},
|
||||
stdio: 'inherit',
|
||||
shell: false
|
||||
})
|
||||
|
||||
process.exit(r.status ?? 1)
|
||||
150
admin/scripts/shared-external.cjs
Normal file
150
admin/scripts/shared-external.cjs
Normal file
@ -0,0 +1,150 @@
|
||||
/**
|
||||
* Core / Addon 共用的「运行时 external」配置
|
||||
*
|
||||
* 生产构建时,vue / element-plus / @/lang 等不打进 bundle,
|
||||
* 由 index.html 的 Import Map 指向 /admin/assets/shared/*.js,
|
||||
* 保证全应用只有一份 Vue 实例与一套 i18n。
|
||||
*/
|
||||
const SHARED_PACKAGES = [
|
||||
'vue',
|
||||
'vue-router',
|
||||
'pinia',
|
||||
'element-plus',
|
||||
'@element-plus/icons-vue',
|
||||
'axios',
|
||||
'vue-i18n',
|
||||
'core-shared'
|
||||
]
|
||||
|
||||
/** build-shared 按此顺序逐个 vite lib 构建(core-shared/admin-lang 最后) */
|
||||
const SHARED_BUILD_ORDER = [
|
||||
'vue',
|
||||
'vue-router',
|
||||
'pinia',
|
||||
'element-plus',
|
||||
'icons-vue',
|
||||
'axios',
|
||||
'vue-i18n',
|
||||
'core-shared',
|
||||
'admin-lang'
|
||||
]
|
||||
|
||||
/** build-shared 包名 -> npm 模块名 */
|
||||
const PKG_TO_MODULE = {
|
||||
vue: 'vue',
|
||||
'vue-router': 'vue-router',
|
||||
pinia: 'pinia',
|
||||
'element-plus': 'element-plus',
|
||||
'icons-vue': '@element-plus/icons-vue',
|
||||
axios: 'axios',
|
||||
'vue-i18n': 'vue-i18n'
|
||||
}
|
||||
|
||||
/** 全局 t() / language 的浏览器绝对路径(须与部署前缀 /admin 一致) */
|
||||
const ADMIN_LANG_URL = '/admin/assets/shared/admin-lang.js'
|
||||
const CORE_SHARED_URL = '/admin/assets/shared/core-shared.js'
|
||||
|
||||
/** 写入 index.html 的 importmap(assemble-admin 注入) */
|
||||
const IMPORT_MAP = {
|
||||
vue: '/admin/assets/shared/vue.js',
|
||||
'vue-router': '/admin/assets/shared/vue-router.js',
|
||||
pinia: '/admin/assets/shared/pinia.js',
|
||||
'element-plus': '/admin/assets/shared/element-plus.js',
|
||||
'element-plus/es': '/admin/assets/shared/element-plus.js',
|
||||
'element-plus/dist/locale/zh-cn.mjs': '/admin/assets/shared/locale/zh-cn.mjs',
|
||||
'element-plus/dist/locale/en.mjs': '/admin/assets/shared/locale/en.mjs',
|
||||
'@element-plus/icons-vue': '/admin/assets/shared/icons-vue.js',
|
||||
axios: '/admin/assets/shared/axios.js',
|
||||
'vue-i18n': '/admin/assets/shared/vue-i18n.js',
|
||||
'@/lang': ADMIN_LANG_URL,
|
||||
'@/utils/common': CORE_SHARED_URL,
|
||||
'@/utils/request': CORE_SHARED_URL,
|
||||
'@/app/api/diy': CORE_SHARED_URL,
|
||||
'@/app/api/sys': CORE_SHARED_URL,
|
||||
'@/app/api/member': CORE_SHARED_URL,
|
||||
'@/app/api/site': CORE_SHARED_URL,
|
||||
'@/components/upload-image': CORE_SHARED_URL,
|
||||
'@/components/diy-page': CORE_SHARED_URL,
|
||||
'@/components/map-selector': CORE_SHARED_URL,
|
||||
'@/components/editor': CORE_SHARED_URL
|
||||
}
|
||||
|
||||
/** 所有需要 external 化并映射到 core-shared 的核心路径 */
|
||||
const CORE_EXTERNAL_PATHS = Object.keys(IMPORT_MAP).filter(k => k.startsWith('@/'))
|
||||
|
||||
/** 是否将 @/lang 或 src/lang 标为 external(避免 addon/core 内嵌第二套 i18n) */
|
||||
function isAdminLangExternal(id) {
|
||||
const norm = id.replace(/\\/g, '/')
|
||||
if (id === '@/lang' || id.startsWith('@/lang/')) return true
|
||||
if (norm.includes('/src/lang/')) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/** Rollup output.paths 中 @/lang 解析到的 URL */
|
||||
function adminLangExternalPath() {
|
||||
return ADMIN_LANG_URL
|
||||
}
|
||||
|
||||
/** 核心应用模块路径是否应 external(不打进 addon 包) */
|
||||
function isCoreExternal(id) {
|
||||
const norm = id.replace(/\\/g, '/')
|
||||
// 直接匹配 @/ 别名形式(Vite resolveId 前的 source)
|
||||
if (CORE_EXTERNAL_PATHS.some(p => norm === p || norm.startsWith(p + '/'))) return true
|
||||
// 匹配已解析的文件路径(如 /path/src/utils/common.ts)
|
||||
if (norm.includes('/src/') && !norm.includes('/src/addon/')) {
|
||||
return /\/src\/(utils|app|components)\//.test(norm)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/** core external 路径统一映射到 core-shared.js */
|
||||
function coreExternalPath() {
|
||||
return CORE_SHARED_URL
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否将依赖标为 external(不打进当前 chunk)
|
||||
* element-plus 的 locale / theme-chalk 除外,仍由各自包处理
|
||||
*/
|
||||
function isSharedExternal(id) {
|
||||
const norm = id.replace(/\\/g, '/')
|
||||
if (norm.includes('/style/css') || norm.includes('/style/index')) return false
|
||||
if (norm.includes('element-plus/dist/')) return false
|
||||
if (norm.includes('element-plus/theme-chalk')) return false
|
||||
if (SHARED_PACKAGES.includes(id)) return true
|
||||
if (SHARED_PACKAGES.some((p) => id === p || id.startsWith(p + '/'))) return true
|
||||
if (!norm.includes('node_modules/')) return false
|
||||
return SHARED_PACKAGES.some((p) => {
|
||||
return norm.includes(`/node_modules/${p}/`) || norm.endsWith(`/node_modules/${p}`)
|
||||
})
|
||||
}
|
||||
|
||||
/** 构建 shared 单包时,不把「自身」再 external 掉 */
|
||||
function isSelfSharedPackage(id, pkgKey) {
|
||||
const mod = PKG_TO_MODULE[pkgKey]
|
||||
if (!mod) return false
|
||||
if (id === mod || id.startsWith(mod + '/')) return true
|
||||
const norm = id.replace(/\\/g, '/')
|
||||
return norm.includes(`/node_modules/${mod}/`) || norm.endsWith(`/node_modules/${mod}`)
|
||||
}
|
||||
|
||||
/** vite.config.shared.ts 用:external 除当前正在打的包以外的 shared 依赖 */
|
||||
function sharedExternalForBuild(pkgKey) {
|
||||
return (id) => isSharedExternal(id) && !isSelfSharedPackage(id, pkgKey)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
SHARED_PACKAGES,
|
||||
SHARED_BUILD_ORDER,
|
||||
PKG_TO_MODULE,
|
||||
IMPORT_MAP,
|
||||
ADMIN_LANG_URL,
|
||||
CORE_SHARED_URL,
|
||||
isSharedExternal,
|
||||
isAdminLangExternal,
|
||||
adminLangExternalPath,
|
||||
isCoreExternal,
|
||||
coreExternalPath,
|
||||
isSelfSharedPackage,
|
||||
sharedExternalForBuild
|
||||
}
|
||||
48
admin/scripts/strip-style-imports.cjs
Normal file
48
admin/scripts/strip-style-imports.cjs
Normal file
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 从已构建 JS 中移除 element-plus style/css side-effect import
|
||||
*
|
||||
* assemble 最后一步兜底:vite 插件可能未覆盖到的 import 语句在此二次清理。
|
||||
* 也可单独运行:node scripts/strip-style-imports.cjs [dist-root]
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const STYLE_IMPORT_RE = /import\s*["']element-plus[^"']*\/style\/css["'];?/g
|
||||
|
||||
function stripFile(filePath) {
|
||||
const text = fs.readFileSync(filePath, 'utf-8')
|
||||
if (!STYLE_IMPORT_RE.test(text)) return false
|
||||
STYLE_IMPORT_RE.lastIndex = 0
|
||||
const next = text.replace(STYLE_IMPORT_RE, '')
|
||||
if (next === text) return false
|
||||
fs.writeFileSync(filePath, next, 'utf-8')
|
||||
return true
|
||||
}
|
||||
|
||||
function walkJs(dir, changed) {
|
||||
if (!fs.existsSync(dir)) return
|
||||
for (const name of fs.readdirSync(dir)) {
|
||||
const full = path.join(dir, name)
|
||||
if (fs.statSync(full).isDirectory()) {
|
||||
walkJs(full, changed)
|
||||
} else if (name.endsWith('.js')) {
|
||||
if (stripFile(full)) changed.push(full)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @param rootDir dist 根目录,递归处理 assets 下所有 .js */
|
||||
function stripBuiltAssets(rootDir) {
|
||||
const assetsDir = path.join(rootDir, 'assets')
|
||||
const changed = []
|
||||
walkJs(assetsDir, changed)
|
||||
return changed
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
const root = process.argv[2] || path.join(__dirname, '..', 'dist')
|
||||
const changed = stripBuiltAssets(root)
|
||||
console.log(`[strip-style-imports] cleaned ${changed.length} files under ${root}/assets`)
|
||||
}
|
||||
|
||||
module.exports = { stripBuiltAssets, stripFile }
|
||||
118
admin/scripts/sync-addon.cjs
Normal file
118
admin/scripts/sync-addon.cjs
Normal file
@ -0,0 +1,118 @@
|
||||
/**
|
||||
* 将 dist/.addons/{key} 同步到 dist/assets/addons/{key}
|
||||
*
|
||||
* build-addon 成功后调用;也可单独执行以刷新已构建插件到 assets 目录。
|
||||
* 同时写入 manifest.json、lang/ 备份、assets/addons/index.json,并更新 build-report.json。
|
||||
*
|
||||
* 用法:node scripts/sync-addon.cjs <addon-key>
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { ROOT } = require('./addon-utils.cjs')
|
||||
|
||||
/** Vite addon 构建 staging */
|
||||
const ADDONS_STAGING = path.join(ROOT, 'dist', '.addons')
|
||||
const OUT_DIR = path.join(ROOT, 'dist')
|
||||
/** 记录各 addon 构建成功/失败,assemble 据此决定复制哪些 key */
|
||||
const REPORT_PATH = path.join(ROOT, 'build-report.json')
|
||||
|
||||
function rmDir(dir) {
|
||||
if (!fs.existsSync(dir)) return
|
||||
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 })
|
||||
}
|
||||
|
||||
function copyDir(src, dest) {
|
||||
fs.mkdirSync(dest, { recursive: true })
|
||||
for (const name of fs.readdirSync(src)) {
|
||||
const s = path.join(src, name)
|
||||
const d = path.join(dest, name)
|
||||
if (fs.statSync(s).isDirectory()) copyDir(s, d)
|
||||
else fs.copyFileSync(s, d)
|
||||
}
|
||||
}
|
||||
|
||||
/** 复制源码 lang 目录,供运行时 fetch json 降级或运维查阅 */
|
||||
function copyLang(key, destAddonDir) {
|
||||
const langSrc = path.join(ROOT, 'src', 'addon', key, 'lang')
|
||||
if (!fs.existsSync(langSrc)) return
|
||||
copyDir(langSrc, path.join(destAddonDir, 'lang'))
|
||||
}
|
||||
|
||||
/** 运行时 initAddonManifests 会 fetch 此文件 */
|
||||
function writeAddonManifest(key, destAddonDir) {
|
||||
const manifest = {
|
||||
key,
|
||||
version: '1.0.0',
|
||||
sharedVersion: 'admin-core-1.0.0',
|
||||
entry: './index.js',
|
||||
langBase: './lang/'
|
||||
}
|
||||
fs.writeFileSync(
|
||||
path.join(destAddonDir, 'manifest.json'),
|
||||
JSON.stringify(manifest, null, 2) + '\n',
|
||||
'utf-8'
|
||||
)
|
||||
}
|
||||
|
||||
function readReport() {
|
||||
if (!fs.existsSync(REPORT_PATH)) return { success: [], failed: [] }
|
||||
return JSON.parse(fs.readFileSync(REPORT_PATH, 'utf-8'))
|
||||
}
|
||||
|
||||
function writeReport(report) {
|
||||
fs.writeFileSync(REPORT_PATH, JSON.stringify(report, null, 2) + '\n', 'utf-8')
|
||||
}
|
||||
|
||||
/** 将 key 记入 success 列表,并从 failed 中移除 */
|
||||
function markSuccess(key) {
|
||||
const report = readReport()
|
||||
const success = new Set(report.success || [])
|
||||
success.add(key)
|
||||
report.success = [...success].sort()
|
||||
report.failed = (report.failed || []).filter((f) => f.key !== key)
|
||||
writeReport(report)
|
||||
}
|
||||
|
||||
/** 浏览器启动时 fetch:/admin/assets/addons/index.json */
|
||||
function writeAddonsIndex(keys) {
|
||||
const addonsDir = path.join(OUT_DIR, 'assets', 'addons')
|
||||
fs.mkdirSync(addonsDir, { recursive: true })
|
||||
fs.writeFileSync(
|
||||
path.join(addonsDir, 'index.json'),
|
||||
JSON.stringify({ keys, sharedVersion: 'admin-core-1.0.0' }, null, 2) + '\n',
|
||||
'utf-8'
|
||||
)
|
||||
}
|
||||
|
||||
function syncAddon(key) {
|
||||
const src = path.join(ADDONS_STAGING, key)
|
||||
if (!fs.existsSync(src)) {
|
||||
console.error(`[sync-addon] missing staging: ${src}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const entry = path.join(src, 'index.js')
|
||||
if (!fs.existsSync(entry)) {
|
||||
console.error(`[sync-addon] missing ${key}/index.js — rebuild addon first`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const dest = path.join(OUT_DIR, 'assets', 'addons', key)
|
||||
rmDir(dest)
|
||||
fs.cpSync(src, dest, { recursive: true, force: true })
|
||||
copyLang(key, dest)
|
||||
writeAddonManifest(key, dest)
|
||||
|
||||
markSuccess(key)
|
||||
const report = readReport()
|
||||
writeAddonsIndex(report.success || [key])
|
||||
|
||||
console.log(`[sync-addon] ${key} -> dist/assets/addons/${key}/`)
|
||||
}
|
||||
|
||||
const key = process.argv[2] || process.env.ADDON_KEY
|
||||
if (!key) {
|
||||
console.error('Usage: node scripts/sync-addon.cjs <addon-key>')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
syncAddon(key)
|
||||
53
admin/scripts/verify-core-lang.cjs
Normal file
53
admin/scripts/verify-core-lang.cjs
Normal file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Core 构建后校验(build:core 中 vite build 之后、assemble 之前执行)
|
||||
*
|
||||
* 检查项:
|
||||
* 1. dist/.core/manifest.json 存在
|
||||
* 2. 入口 bundle 不含旧版 loadAddonCommonLocales(防 stale 缓存)
|
||||
* 3. 含新版 preloadAllAddonLangs 逻辑
|
||||
* 4. 修复并校验 admin-lang import 路径
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const core = path.join(__dirname, '..', 'dist', '.core')
|
||||
const manifestPath = path.join(core, 'manifest.json')
|
||||
|
||||
if (!fs.existsSync(manifestPath)) {
|
||||
console.error('[verify-core-lang] missing dist/.core/manifest.json — run build:core first')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'))
|
||||
const entry = manifest['index.html']?.file
|
||||
const code = fs.readFileSync(path.join(core, entry), 'utf-8')
|
||||
|
||||
// 旧构建特征:仅加载 common.json 或旧函数名
|
||||
const stale = code.includes('loadAddonCommonLocales') || code.includes('async function os(e,t=["zh-cn","en"])')
|
||||
const hasPreload = code.includes('preloadAllAddonLangs') || code.includes('.langs')
|
||||
|
||||
if (stale) {
|
||||
console.error('[verify-core-lang] STALE bundle:', entry)
|
||||
console.error(' still contains old loadAddonCommonLocales — delete dist/.core and rebuild')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (!hasPreload) {
|
||||
console.warn('[verify-core-lang] warn: preloadAllAddonLangs string not found (may be minified)')
|
||||
}
|
||||
|
||||
const assetsDir = path.join(core, 'assets')
|
||||
const { fixDir, hasBadImport } = require('./admin-lang-import-utils.cjs')
|
||||
fixDir(assetsDir)
|
||||
if (fs.existsSync(assetsDir)) {
|
||||
for (const name of fs.readdirSync(assetsDir)) {
|
||||
if (!name.endsWith('.js')) continue
|
||||
const code = fs.readFileSync(path.join(assetsDir, name), 'utf-8')
|
||||
if (hasBadImport(code)) {
|
||||
console.error('[verify-core-lang] bad admin-lang import still in', name)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[verify-core-lang] ok:', entry)
|
||||
47
admin/scripts/vite-plugin-strip-element-plus-style.cjs
Normal file
47
admin/scripts/vite-plugin-strip-element-plus-style.cjs
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Vite 插件:构建期剥离 element-plus 按需 style/css import
|
||||
*
|
||||
* 背景:
|
||||
* - 全局样式已在 src/styles/index.scss 引入 element-plus
|
||||
* - Core/Addon external element-plus 后,残留的 style/css side-effect import
|
||||
* 会进入 chunk 且浏览器无法通过 importmap 解析,导致运行时报错
|
||||
*
|
||||
* 用于 vite.config.core.ts / vite.config.addon.ts
|
||||
*/
|
||||
const STYLE_IMPORT_RE = /import\s*["']element-plus[^"']*["'];?/g
|
||||
|
||||
function isElementPlusStyleImport(source) {
|
||||
const norm = source.replace(/\\/g, '/')
|
||||
if (!norm.includes('element-plus')) return false
|
||||
// 匹配 style/css、style/index、theme-chalk、dist/{comp}/style 等
|
||||
if (/\/style\/(css|index)(\.mjs|\.js)?$/i.test(norm)) return true
|
||||
if (/\/theme-chalk\//i.test(norm)) return true
|
||||
if (/\/dist\/[^/]+\/style\//i.test(norm)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
function stripElementPlusStylePlugin() {
|
||||
const EMPTY_ID = '\0element-plus-empty-style'
|
||||
return {
|
||||
name: 'strip-element-plus-style',
|
||||
enforce: 'pre',
|
||||
// resolve 阶段将 style import 指向空模块
|
||||
resolveId(source) {
|
||||
if (isElementPlusStyleImport(source)) return EMPTY_ID
|
||||
return null
|
||||
},
|
||||
load(id) {
|
||||
if (id === EMPTY_ID) return 'export {}'
|
||||
return null
|
||||
},
|
||||
// generateBundle 再扫一遍 chunk 文本,删除遗漏的 import 语句
|
||||
generateBundle(_, bundle) {
|
||||
for (const item of Object.values(bundle)) {
|
||||
if (item.type !== 'chunk') continue
|
||||
item.code = item.code.replace(STYLE_IMPORT_RE, '')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { stripElementPlusStylePlugin, isElementPlusStyleImport }
|
||||
@ -2,7 +2,7 @@ import axios from 'axios'
|
||||
import request from '@/utils/request'
|
||||
import storage from '@/utils/storage'
|
||||
|
||||
export const CLOUD_COMPILE_BASE_URL = 'http://go.site.niucloud.com'
|
||||
export const CLOUD_COMPILE_BASE_URL = location.protocol + '//go.site.niucloud.com'
|
||||
|
||||
function createCloudCompileRequest() {
|
||||
const instance = axios.create({
|
||||
|
||||
@ -114,12 +114,6 @@
|
||||
<div class="flex flex-col" v-show="active == 'backup'">
|
||||
<el-scrollbar>
|
||||
<div class="bg-[#fff] my-3">
|
||||
<div class="p-[20px] mt-[50px] mx-[10px] border-[1px] border-[#E6E6E6] rounded-[10px]">
|
||||
<div class="flex justify-between items-center mt-[-9px]">
|
||||
<el-checkbox v-model="upgradeOption.is_need_cloudbuild" :label="t('upgrade.isNeedCloudbuild')" :true-value="true" :false-value="false" size="large" ></el-checkbox>
|
||||
</div>
|
||||
<div class="text-[14px] text-[#374151] mb-[10px]">{{ t('upgrade.cloudbuildTips') }}</div>
|
||||
</div>
|
||||
<div class="p-[20px] mt-[20px] mx-[10px] border-[1px] border-[#E6E6E6] rounded-[10px]" v-if="upgradeContent.last_backup">
|
||||
<div class="flex justify-between items-center mt-[-9px]">
|
||||
<el-checkbox v-model="upgradeOption.is_need_backup" :label="t('upgrade.isNeedBackup')" :true-value="true" :false-value="false" size="large" ></el-checkbox>
|
||||
@ -198,8 +192,7 @@
|
||||
<el-button v-if="step == 1 && upgradeContent.content.length && isAllowUpgrade" @click="step = 2" type="primary">{{ t("upgrade.upgradeButton") }}</el-button>
|
||||
<el-button type="primary" v-show="step == 2 && showTerminal && upgradeTask && !errorDialog" :loading="timeloading" class="!w-[140px]">已用时 {{ formatUpgradeDuration }}</el-button>
|
||||
<template v-if="step == 2 && active != 'complete'">
|
||||
<!-- <el-button v-if="active == 'content'" @click="showDialog = false">{{ t("return") }}</el-button>-->
|
||||
<el-button type="primary" :disabled="!is_pass" v-if="active == 'upgrade' && !upgradeTask" @click="() => { active = 'backup'; numberOfSteps = 1 }">{{ t("nextStep") }}</el-button>
|
||||
<el-button type="primary" :disabled="!is_pass" v-if="active == 'upgrade' && !upgradeTask" @click="showUpgradeOption">{{ t("nextStep") }}</el-button>
|
||||
<el-button v-if="active == 'backup'" @click="() => { active = 'upgrade'; numberOfSteps = 1 } ">{{ t("prev") }}</el-button>
|
||||
<el-button type="primary" v-if="active == 'backup'" :loading="loading" @click="() => { upgradeAddonFn() }">{{ t("nextStep") }}</el-button>
|
||||
<el-button v-if="active == 'complete'" @click="showDialog = false">{{ t("complete") }}</el-button>
|
||||
@ -283,7 +276,7 @@ const retrySecond = ref(30)
|
||||
let retrySecondInterval: any = null
|
||||
const upgradeOption = ref({
|
||||
is_need_backup: true,
|
||||
is_need_cloudbuild: true
|
||||
is_need_cloudbuild: false
|
||||
})
|
||||
|
||||
// 升级步骤排除,backupCode 备份代码,backupSql 备份数据库
|
||||
@ -543,6 +536,15 @@ const handleUpgrade = async () => {
|
||||
})
|
||||
}
|
||||
|
||||
const showUpgradeOption = () => {
|
||||
if (upgradeContent.value.last_backup) {
|
||||
active.value = 'backup';
|
||||
numberOfSteps.value = 1
|
||||
} else {
|
||||
upgradeAddonFn()
|
||||
}
|
||||
}
|
||||
|
||||
const upgradeAddonFn = () => {
|
||||
if (!is_pass.value) return
|
||||
if (loading.value) return
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
<div class="flex-1 h-0 flex justify-center items-center flex-col">
|
||||
<el-result icon="success" title="上传成功">
|
||||
<template #sub-title>
|
||||
<p class="text-[16px]">小程序上传成功,耗时 {{ formattedDuration }}</p>
|
||||
<p class="text-[16px]">小程序上传成功</p>
|
||||
</template>
|
||||
<template #extra>
|
||||
<el-button type="primary" @click="handleComplete">完成</el-button>
|
||||
@ -438,4 +438,4 @@ defineExpose({
|
||||
loading,
|
||||
showDialog
|
||||
})
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@ -9,6 +9,7 @@ import { computed, ref } from 'vue'
|
||||
import { getToken } from '@/utils/common'
|
||||
import storage from '@/utils/storage'
|
||||
import { ElMessage, UploadFile, UploadFiles } from 'element-plus'
|
||||
import envConfig from '@/utils/config'
|
||||
|
||||
const prop = defineProps({
|
||||
type: {
|
||||
@ -23,11 +24,11 @@ const uploadRef = ref<Record<string, any> | null>(null)
|
||||
// 上传文件
|
||||
const upload = computed(() => {
|
||||
const headers: Record<string, any> = {}
|
||||
headers[import.meta.env.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
|
||||
headers[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = storage.get('siteId') || 0
|
||||
headers[envConfig.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
|
||||
headers[envConfig.VITE_REQUEST_HEADER_SITEID_KEY] = storage.get('siteId') || 0
|
||||
|
||||
return {
|
||||
action: `${import.meta.env.VITE_APP_BASE_URL}/wechat/media/${prop.type}`,
|
||||
action: `${envConfig.VITE_APP_BASE_URL}/wechat/media/${prop.type}`,
|
||||
multiple: true,
|
||||
headers,
|
||||
accept: prop.type == 'image' ? '.bmp,.png,.jpeg,.jpg,.gif' : '.mp4',
|
||||
|
||||
@ -213,7 +213,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, toRaw, watch, inject } from 'vue'
|
||||
import { ref, reactive, toRaw, watch, inject, defineAsyncComponent } from 'vue'
|
||||
import { t } from '@/lang'
|
||||
import { ArrowLeft } from "@element-plus/icons-vue"
|
||||
import { img } from '@/utils/common'
|
||||
@ -296,10 +296,14 @@ const goBack = () => {
|
||||
|
||||
// 动态加载后台自定义组件编辑
|
||||
const modulesFiles = import.meta.glob('./components/*.vue', { eager: true })
|
||||
const addonModulesFiles = import.meta.glob('@/addon/**/views/diy/components/*.vue', { eager: true })
|
||||
addonModulesFiles && Object.assign(modulesFiles, addonModulesFiles)
|
||||
|
||||
const modules = {}
|
||||
// 开发环境:直接 glob 插件源码
|
||||
if (import.meta.env.DEV) {
|
||||
const addonModulesFiles = import.meta.glob('@/addon/**/views/diy/components/*.vue', { eager: true })
|
||||
Object.assign(modulesFiles, addonModulesFiles)
|
||||
}
|
||||
|
||||
const modules: Record<string, any> = {}
|
||||
for (const [key, value] of Object.entries(modulesFiles)) {
|
||||
const moduleName = key.split('/').pop()
|
||||
const name = moduleName.split('.')[0]
|
||||
@ -455,6 +459,33 @@ initPage({
|
||||
diyStore.components.push(com)
|
||||
}
|
||||
}
|
||||
|
||||
// 生产环境:通过编译产物异步加载插件 DIY 组件编辑器
|
||||
if (!import.meta.env.DEV && component.value) {
|
||||
const { loadAddonComponent, getInstalledAddonKeys } = await import('@/utils/addon-loader')
|
||||
const addonKeys = getInstalledAddonKeys()
|
||||
for (const type of Object.values(component.value) as any[]) {
|
||||
if (!type.list) continue
|
||||
for (const rawKey of Object.keys(type.list)) {
|
||||
const compDef = type.list[rawKey]
|
||||
const componentPath = compDef.value?.path || compDef.path || rawKey
|
||||
if (modules[componentPath]) continue
|
||||
modules[componentPath] = defineAsyncComponent(() =>
|
||||
(async () => {
|
||||
for (const addon of addonKeys) {
|
||||
const loader = loadAddonComponent(addon, 'diy/components', componentPath)
|
||||
try {
|
||||
const result = await loader()
|
||||
if (result?.default) return result.default
|
||||
} catch {}
|
||||
}
|
||||
throw new Error(`DIY component "${componentPath}" not found in any addon`)
|
||||
})()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log( component.value )
|
||||
loadDiyTemplatePages(data.type)
|
||||
|
||||
@ -469,21 +500,18 @@ initPage({
|
||||
if (import.meta.env.MODE == 'development') {
|
||||
|
||||
// env文件配置过wap域名
|
||||
// if (wapDomain.value) {
|
||||
// wapUrl.value = wapDomain.value + '/wap'
|
||||
// repeat = false
|
||||
// setDomain()
|
||||
// }
|
||||
if (wapDomain.value) {
|
||||
wapUrl.value = wapDomain.value + '/wap'
|
||||
repeat = false
|
||||
setDomain()
|
||||
}
|
||||
|
||||
// let wap_domain_storage = storage.get('wap_domain')
|
||||
// if (wap_domain_storage) {
|
||||
// wapUrl.value = wap_domain_storage
|
||||
// repeat = false
|
||||
// setDomain()
|
||||
// }
|
||||
wapUrl.value = 'http://localhost:5173/wap'
|
||||
repeat = false
|
||||
setDomain()
|
||||
let wap_domain_storage = storage.get('wap_domain')
|
||||
if (wap_domain_storage) {
|
||||
wapUrl.value = wap_domain_storage
|
||||
repeat = false
|
||||
setDomain()
|
||||
}
|
||||
}
|
||||
|
||||
if (repeat) {
|
||||
|
||||
@ -582,30 +582,9 @@
|
||||
</div>
|
||||
<!-- </el-scrollbar> -->
|
||||
<div class="flex justify-end">
|
||||
<el-tooltip effect="dark" placement="top">
|
||||
<template #content>
|
||||
<div class="w-[400px]">
|
||||
{{ t('installTips') }}
|
||||
</div>
|
||||
</template>
|
||||
<el-button :disabled="!installCheckResult.is_pass || cloudInstalling" :loading="localInstalling" @click="handleInstall"
|
||||
>{{ t('localInstall') }}
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip effect="dark" placement="top">
|
||||
<template #content>
|
||||
<div class="w-[400px]">
|
||||
{{ t('cloudInstallTips') }}
|
||||
</div>
|
||||
</template>
|
||||
<el-button
|
||||
type="primary"
|
||||
:disabled="!installCheckResult.is_pass || localInstalling"
|
||||
:loading="cloudInstalling"
|
||||
@click="handleCloudInstall"
|
||||
>{{ t('cloudInstall') }}
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
<el-button type="primary" class="!w-[140px]" :disabled="!installCheckResult.is_pass || cloudInstalling" :loading="localInstalling" @click="handleInstall"
|
||||
>{{ t('install') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-show="installStep == 1 && !errorDialog" class="h-[50vh] mt-[20px]">
|
||||
|
||||
@ -11,6 +11,7 @@ import { computed, ref } from 'vue'
|
||||
import { getToken, img } from '@/utils/common'
|
||||
import { VueUeditorWrap } from 'vue-ueditor-wrap'
|
||||
import storage from '@/utils/storage'
|
||||
import envConfig from '@/utils/config'
|
||||
|
||||
const editorRef = ref()
|
||||
|
||||
@ -46,9 +47,9 @@ const content = computed({
|
||||
let editorEl = null
|
||||
|
||||
const serverHeaders = {}
|
||||
serverHeaders[import.meta.env.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
|
||||
serverHeaders[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = storage.get('siteId') || 0
|
||||
const baseUrl = import.meta.env.VITE_APP_BASE_URL.substr(-1) == '/' ? import.meta.env.VITE_APP_BASE_URL : `${import.meta.env.VITE_APP_BASE_URL}/`
|
||||
serverHeaders[envConfig.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
|
||||
serverHeaders[envConfig.VITE_REQUEST_HEADER_SITEID_KEY] = storage.get('siteId') || 0
|
||||
const baseUrl = envConfig.VITE_APP_BASE_URL.substr(-1) == '/' ? envConfig.VITE_APP_BASE_URL : `${envConfig.VITE_APP_BASE_URL}/`
|
||||
|
||||
const editorConfig = ref({
|
||||
debug: false,
|
||||
|
||||
@ -199,6 +199,7 @@ import {
|
||||
import { debounce, img, getToken } from '@/utils/common'
|
||||
import { ElMessage, UploadFile, UploadFiles, ElMessageBox, MessageParams } from 'element-plus'
|
||||
import storage from '@/utils/storage'
|
||||
import envConfig from '@/utils/config'
|
||||
|
||||
const attachmentCategoryName = ref('')
|
||||
const operate = ref(false)
|
||||
@ -446,9 +447,9 @@ const time = ref<any>(null)
|
||||
// 上传文件
|
||||
const upload = computed(() => {
|
||||
const headers: Record<string, any> = {}
|
||||
headers[import.meta.env.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
|
||||
headers[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = storage.get('siteId') || 0
|
||||
const baseURL = import.meta.env.VITE_APP_BASE_URL.substr(-1) == '/' ? import.meta.env.VITE_APP_BASE_URL : `${import.meta.env.VITE_APP_BASE_URL}/`
|
||||
headers[envConfig.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
|
||||
headers[envConfig.VITE_REQUEST_HEADER_SITEID_KEY] = storage.get('siteId') || 0
|
||||
const baseURL = envConfig.VITE_APP_BASE_URL.substr(-1) == '/' ? envConfig.VITE_APP_BASE_URL : `${envConfig.VITE_APP_BASE_URL}/`
|
||||
|
||||
return {
|
||||
action: `${baseURL}sys/${prop.type}`,
|
||||
|
||||
@ -12,6 +12,7 @@ import { t } from '@/lang'
|
||||
import { getToken } from '@/utils/common'
|
||||
import { UploadFile, ElMessage } from 'element-plus'
|
||||
import storage from '@/utils/storage'
|
||||
import envConfig from '@/utils/config'
|
||||
|
||||
const prop = defineProps({
|
||||
modelValue: {
|
||||
@ -36,7 +37,7 @@ const value = computed({
|
||||
})
|
||||
|
||||
const upload: Record<string, any> = {
|
||||
action: `${import.meta.env.VITE_APP_BASE_URL}/${prop.api}`,
|
||||
action: `${envConfig.VITE_APP_BASE_URL}/${prop.api}`,
|
||||
showFileList: false,
|
||||
headers: {},
|
||||
accept: 'audio/*,.mp3,.wav,.ogg,.m4a,.flac,.aac,.wma',
|
||||
@ -62,8 +63,8 @@ const upload: Record<string, any> = {
|
||||
ElMessage({ message: t('upload.success'), type: 'success' })
|
||||
}
|
||||
}
|
||||
upload.headers[import.meta.env.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
|
||||
upload.headers[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = storage.get('siteId') || 0
|
||||
upload.headers[envConfig.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
|
||||
upload.headers[envConfig.VITE_REQUEST_HEADER_SITEID_KEY] = storage.get('siteId') || 0
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ import { t } from '@/lang'
|
||||
import { getToken } from '@/utils/common'
|
||||
import { UploadFile, ElMessage } from 'element-plus'
|
||||
import storage from '@/utils/storage'
|
||||
import envConfig from '@/utils/config'
|
||||
|
||||
const prop = defineProps({
|
||||
modelValue: {
|
||||
@ -43,9 +44,9 @@ const value = computed({
|
||||
|
||||
const upload = computed(() => {
|
||||
const headers: Record<string, any> = {}
|
||||
headers[import.meta.env.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
|
||||
headers[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = storage.get('siteId') || 0
|
||||
const baseURL = import.meta.env.VITE_APP_BASE_URL.substr(-1) == '/' ? import.meta.env.VITE_APP_BASE_URL : `${import.meta.env.VITE_APP_BASE_URL}/`
|
||||
headers[envConfig.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
|
||||
headers[envConfig.VITE_REQUEST_HEADER_SITEID_KEY] = storage.get('siteId') || 0
|
||||
const baseURL = envConfig.VITE_APP_BASE_URL.substr(-1) == '/' ? envConfig.VITE_APP_BASE_URL : `${envConfig.VITE_APP_BASE_URL}/`
|
||||
|
||||
return {
|
||||
action: `${baseURL}${prop.api}`,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import axios from 'axios'
|
||||
import envConfig from '@/utils/config'
|
||||
|
||||
axios.defaults.baseURL = import.meta.env.VITE_APP_BASE_URL
|
||||
axios.defaults.baseURL = envConfig.VITE_APP_BASE_URL
|
||||
|
||||
const service = axios.create({
|
||||
timeout: 40000,
|
||||
|
||||
@ -4,18 +4,21 @@ import Language from "./language"
|
||||
import zhCn from "./zh-cn/common.json";
|
||||
import en from "./en/common.json"
|
||||
|
||||
const addonZhCnCommon = import.meta.globEager('@/addon/**/lang/zh-cn/common.json')
|
||||
const addonEnCommon = import.meta.globEager('@/addon/**/lang/en/common.json')
|
||||
|
||||
for (let key in addonZhCnCommon) {
|
||||
Object.assign(zhCn, addonZhCnCommon[key].default)
|
||||
}
|
||||
for (let key in addonEnCommon) {
|
||||
Object.assign(en, addonEnCommon[key].default)
|
||||
if (import.meta.env.DEV) {
|
||||
const addonZhCnCommon = import.meta.globEager('@/addon/**/lang/zh-cn/common.json')
|
||||
const addonEnCommon = import.meta.globEager('@/addon/**/lang/en/common.json')
|
||||
for (const key in addonZhCnCommon) {
|
||||
Object.assign(zhCn, addonZhCnCommon[key].default)
|
||||
}
|
||||
for (const key in addonEnCommon) {
|
||||
Object.assign(en, addonEnCommon[key].default)
|
||||
}
|
||||
}
|
||||
|
||||
//创建实例
|
||||
let i18n = createI18n({
|
||||
locale: 'zh-cn',
|
||||
fallbackLocale: 'zh-cn',
|
||||
datetimeFormats: {},
|
||||
numberFormats: {},
|
||||
globalInjection: true, //是否全局注入
|
||||
|
||||
@ -1,10 +1,22 @@
|
||||
import i18n, { language } from "./i18n"
|
||||
import useAppStore from '@/stores/modules/app'
|
||||
import { resolveLangFile, resolveRouteAddon, resolveRouteView, inferAddonFromPath } from '@/utils/addon-lang'
|
||||
import { getCurrentInstance } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
function currentRoute() {
|
||||
if (getCurrentInstance()) {
|
||||
return useRoute()
|
||||
}
|
||||
return useAppStore().route as Parameters<typeof resolveRouteAddon>[0]
|
||||
}
|
||||
|
||||
const t = (message: string) => {
|
||||
const route = useAppStore().route
|
||||
const path = route.meta.view || route.path
|
||||
const file = path == '/' ? 'index' : path.replace(/^(\/admin\/|\/site\/|\/)/, '').replaceAll('/', '.')
|
||||
const route = currentRoute()
|
||||
let app = resolveRouteAddon(route)
|
||||
const path = resolveRouteView(route)
|
||||
if (!app) app = inferAddonFromPath(path)
|
||||
const file = resolveLangFile(app, path)
|
||||
const key = `${file}.${message}`
|
||||
return i18n.global.t(key) != key ? i18n.global.t(key) : i18n.global.t(message)
|
||||
}
|
||||
@ -13,9 +25,6 @@ export { language, t }
|
||||
|
||||
export default {
|
||||
install(app: any) {
|
||||
//注册i18n
|
||||
app.use(i18n);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { nextTick } from 'vue'
|
||||
import { loadAddonLang, preloadAllAddonLangs, resolveLangFile, inferAddonFromPath } from '@/utils/addon-lang'
|
||||
|
||||
class Language {
|
||||
private i18n: any;
|
||||
@ -31,25 +32,42 @@ class Language {
|
||||
*/
|
||||
public async loadLocaleMessages(app: string, path: string, locale: string) {
|
||||
try {
|
||||
const file = path == '/' ? 'index' : path.replace(/^(\/admin\/|\/site\/|\/)/, '').replaceAll('/', '.')
|
||||
if (!app) app = inferAddonFromPath(path)
|
||||
const file = resolveLangFile(app, path)
|
||||
|
||||
// 引入语言包文件
|
||||
const messages = await import(app ? `@/addon/${app}/lang/${locale}/${file}.json` : `@/app/lang/${locale}/${file}.json`)
|
||||
let pageMessages: Record<string, string> = {}
|
||||
if (app) {
|
||||
if (import.meta.env.DEV) {
|
||||
const messages = await import(/* @vite-ignore */ `@/addon/${app}/lang/${locale}/${file}.json`)
|
||||
pageMessages = messages.default || {}
|
||||
} else {
|
||||
pageMessages = await loadAddonLang(app, locale, file)
|
||||
}
|
||||
} else {
|
||||
const messages = await import(`@/app/lang/${locale}/${file}.json`)
|
||||
pageMessages = messages.default || {}
|
||||
}
|
||||
|
||||
let data: Record<string, string> = {}
|
||||
Object.keys(messages.default).forEach(key => {
|
||||
data[`${file}.${key}`] = messages.default[key]
|
||||
Object.keys(pageMessages).forEach(key => {
|
||||
data[`${file}.${key}`] = pageMessages[key]
|
||||
})
|
||||
|
||||
// 查询插件的公共语言包
|
||||
// 查询插件的公共语言包(合并到根 key,与 dev 启动时 globEager 行为一致)
|
||||
if (app) {
|
||||
try {
|
||||
const messagesCommon = await import( `@/${ app }/lang/${ locale }/common.json`);
|
||||
Object.keys(messagesCommon.default).forEach(key => {
|
||||
data[`${file}.${key}`] = messagesCommon.default[key]
|
||||
let commonMessages: Record<string, string> = {}
|
||||
if (import.meta.env.DEV) {
|
||||
const messagesCommon = await import(/* @vite-ignore */ `@/addon/${app}/lang/${locale}/common.json`)
|
||||
commonMessages = messagesCommon.default || {}
|
||||
} else {
|
||||
commonMessages = await loadAddonLang(app, locale, 'common')
|
||||
}
|
||||
Object.keys(commonMessages).forEach(key => {
|
||||
data[key] = commonMessages[key]
|
||||
})
|
||||
} catch (e) {
|
||||
// console.log('未找到插件公共语言包')
|
||||
// 未找到插件公共语言包
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,6 +79,13 @@ class Language {
|
||||
return nextTick()
|
||||
}
|
||||
}
|
||||
|
||||
/** 生产环境启动时预加载各插件全部语言包 */
|
||||
public async preloadAddonLangs() {
|
||||
await preloadAllAddonLangs((locale, messages) => {
|
||||
this.i18n.global.mergeLocaleMessage(locale, messages)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default Language
|
||||
|
||||
@ -138,7 +138,7 @@ getVersionsInfo()
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.one-menu{
|
||||
padding: 20px 10px 10px;
|
||||
width: 78px;
|
||||
@ -198,10 +198,10 @@ getVersionsInfo()
|
||||
&.expanded .menu-item .text-center {
|
||||
opacity: 1;
|
||||
}
|
||||
.el-menu{
|
||||
:deep(.el-menu){
|
||||
border: 0;
|
||||
}
|
||||
.el-scrollbar{
|
||||
:deep(.el-scrollbar){
|
||||
height: calc(100vh - 65px);
|
||||
}
|
||||
}
|
||||
@ -210,7 +210,7 @@ getVersionsInfo()
|
||||
width: 185px;
|
||||
border: 0;
|
||||
padding-top: 15px;
|
||||
.el-menu-item{
|
||||
:deep(.el-menu-item){
|
||||
height: 40px;
|
||||
margin: 4px 15px;
|
||||
padding: 0 8px !important;
|
||||
@ -232,11 +232,11 @@ getVersionsInfo()
|
||||
// color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
.el-sub-menu{
|
||||
:deep(.el-sub-menu){
|
||||
width: 185px;
|
||||
margin: 4px 0;
|
||||
// margin-bottom: 8px;
|
||||
.el-sub-menu__title{
|
||||
:deep(.el-sub-menu__title){
|
||||
margin: 0 15px;
|
||||
height: 40px;
|
||||
padding-left: 8px;
|
||||
@ -253,11 +253,11 @@ getVersionsInfo()
|
||||
// background-color: var(--el-color-primary-light-9) !important;
|
||||
// color: var(--el-color-primary);
|
||||
}
|
||||
.el-icon.el-sub-menu__icon-arrow{
|
||||
.el-icon:deep(.el-sub-menu__icon-arrow){
|
||||
right: 5px;
|
||||
}
|
||||
}
|
||||
.el-menu-item{
|
||||
:deep(.el-menu-item){
|
||||
padding-left: 25px !important;
|
||||
}
|
||||
}
|
||||
@ -286,7 +286,7 @@ getVersionsInfo()
|
||||
// :deep(.el-scrollbar__bar){
|
||||
// display: none !important;
|
||||
// }
|
||||
// .layout-aside .el-scrollbar__wrap--hidden-default, .layout-aside .el-scrollbar{
|
||||
// .layout-aside .el-scrollbar__wrap--hidden-default, .layout-aside :deep(.el-scrollbar){
|
||||
// overflow: inherit !important;
|
||||
// }
|
||||
// 隐藏滚动条
|
||||
|
||||
@ -45,8 +45,8 @@ const props = defineProps({
|
||||
const meta = computed(() => props.routes.meta)
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.el-sub-menu{
|
||||
<style lang="scss" scoped>
|
||||
:deep(.el-sub-menu){
|
||||
.el-icon{
|
||||
width: auto;
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ userStore.routers = userStore.routers.filter((item, index) => {
|
||||
// })
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.logo-wrap {
|
||||
padding: 0;
|
||||
display: flex;
|
||||
@ -84,7 +84,7 @@ userStore.routers = userStore.routers.filter((item, index) => {
|
||||
flex: 1 !important;
|
||||
padding: 0 !important;
|
||||
|
||||
.el-menu {
|
||||
:deep(.el-menu) {
|
||||
border-right: 0 !important;
|
||||
}
|
||||
}
|
||||
@ -100,15 +100,15 @@ userStore.routers = userStore.routers.filter((item, index) => {
|
||||
border-bottom: 2px solid #101117;
|
||||
}
|
||||
|
||||
.el-menu {
|
||||
:deep(.el-menu) {
|
||||
background-color: #191a23;
|
||||
|
||||
.el-sub-menu {
|
||||
:deep(.el-sub-menu) {
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
.el-sub-menu__title,
|
||||
.el-menu-item {
|
||||
:deep(.el-sub-menu__title),
|
||||
:deep(.el-menu-item) {
|
||||
background: transparent !important;
|
||||
color: #B7B7ba;
|
||||
|
||||
@ -118,7 +118,7 @@ userStore.routers = userStore.routers.filter((item, index) => {
|
||||
}
|
||||
}
|
||||
|
||||
.el-menu-item.is-active {
|
||||
:deep(.el-menu-item).is-active {
|
||||
color: #fff !important;
|
||||
background-color: var(--el-color-primary) !important;
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ watch(route, () => {
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.layout-aside {
|
||||
//--side-dark-color: #141414;
|
||||
//background-color: var(--side-dark-color, var(--el-bg-color));
|
||||
|
||||
@ -85,22 +85,22 @@ watch(route, () => {
|
||||
}, { immediate: true })
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.el-sub-menu{
|
||||
<style lang="scss" scoped>
|
||||
:deep(.el-sub-menu){
|
||||
.el-icon{
|
||||
// width: auto;
|
||||
}
|
||||
}
|
||||
.el-menu {
|
||||
.el-sub-menu__title,
|
||||
.el-menu-item {
|
||||
:deep(.el-menu) {
|
||||
:deep(.el-sub-menu__title),
|
||||
:deep(.el-menu-item) {
|
||||
&:hover {
|
||||
// background-color: #F1F5FF !important;
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.el-icon.el-sub-menu__icon-arrow{
|
||||
.el-icon:deep(.el-sub-menu__icon-arrow){
|
||||
font-size: 15px;
|
||||
top: 50%;
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ if (siteInfo?.apps.length > 1) {
|
||||
defaultOpeneds.value = menuData.value.map(item => item.name)
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.logo-wrap {
|
||||
// background: #1f2531;
|
||||
background: #fff;
|
||||
@ -91,22 +91,22 @@ defaultOpeneds.value = menuData.value.map(item => item.name)
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.el-menu {
|
||||
:deep(.el-menu) {
|
||||
border-right: 0!important;
|
||||
|
||||
&:not(.el-menu--collapse) {
|
||||
width: var(--aside-width);
|
||||
}
|
||||
|
||||
.el-menu-item, .el-sub-menu__title {
|
||||
:deep(.el-menu-item), :deep(.el-sub-menu__title) {
|
||||
--el-menu-item-height: 40px;
|
||||
}
|
||||
|
||||
.el-sub-menu .el-menu-item {
|
||||
:deep(.el-sub-menu) :deep(.el-menu-item) {
|
||||
--el-menu-sub-item-height: 40px;
|
||||
}
|
||||
|
||||
.el-menu-item.is-active {
|
||||
:deep(.el-menu-item).is-active {
|
||||
background: var(--el-color-primary) !important;
|
||||
color: #fff !important;
|
||||
}
|
||||
@ -115,14 +115,14 @@ defaultOpeneds.value = menuData.value.map(item => item.name)
|
||||
// background: #282e3a;
|
||||
// background: #fff;
|
||||
}
|
||||
.el-menu-item .el-menu-tooltip__trigger{
|
||||
:deep(.el-menu-item) .el-menu-tooltip__trigger{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
&.el-menu--collapse {
|
||||
.el-menu-item, .el-sub-menu__title {
|
||||
:deep(.el-menu-item), :deep(.el-sub-menu__title) {
|
||||
--el-menu-item-height: 60px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ watch(route, () => {
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.layout-aside {
|
||||
background-color: var(--side-dark-color, var(--el-bg-color));
|
||||
border-right: 1px solid var(--el-border-color-lighter);
|
||||
|
||||
@ -83,8 +83,8 @@ const handleJump = (routeName: string) => {
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.el-sub-menu{
|
||||
<style lang="scss" scoped>
|
||||
:deep(.el-sub-menu){
|
||||
.el-icon{
|
||||
width: auto;
|
||||
}
|
||||
|
||||
@ -355,11 +355,11 @@ watch(route, () => {
|
||||
}, { immediate: true })
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.one-menu{
|
||||
.aside-menu:not(.el-menu--collapse) {
|
||||
background-color: transparent;
|
||||
.el-menu-item{
|
||||
:deep(.el-menu-item){
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
@ -395,10 +395,10 @@ watch(route, () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
.el-menu{
|
||||
:deep(.el-menu){
|
||||
border: 0;
|
||||
}
|
||||
.el-scrollbar{
|
||||
:deep(.el-scrollbar){
|
||||
height: calc(100vh - 65px);
|
||||
}
|
||||
}
|
||||
@ -407,7 +407,7 @@ watch(route, () => {
|
||||
width: 190px;
|
||||
border: 0;
|
||||
padding-top: 10px;
|
||||
.el-menu-item{
|
||||
:deep(.el-menu-item){
|
||||
height: 40px;
|
||||
margin: 0 8px 2px;
|
||||
padding: 0 10px !important;
|
||||
@ -425,8 +425,8 @@ watch(route, () => {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
.el-sub-menu{
|
||||
.el-sub-menu__title{
|
||||
:deep(.el-sub-menu){
|
||||
:deep(.el-sub-menu__title){
|
||||
margin: 0 8px 2px;
|
||||
height: 40px;
|
||||
padding-left: 8px;
|
||||
@ -442,11 +442,11 @@ watch(route, () => {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
.el-menu-item{
|
||||
:deep(.el-menu-item){
|
||||
padding-left: 20px !important;
|
||||
}
|
||||
.el-sub-menu{
|
||||
.el-sub-menu__title{
|
||||
:deep(.el-sub-menu){
|
||||
:deep(.el-sub-menu__title){
|
||||
margin: 0 8px 2px;
|
||||
height: 40px;
|
||||
padding-left: 18px;
|
||||
@ -462,7 +462,7 @@ watch(route, () => {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
.el-menu-item{
|
||||
:deep(.el-menu-item){
|
||||
padding-left: 30px !important;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ watch(route, () => {
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.layout-aside {
|
||||
--side-dark-color: #141414;
|
||||
background-color: var(--side-dark-color, var(--el-bg-color));
|
||||
|
||||
@ -285,10 +285,21 @@ onMounted(() => {
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.el-sub-menu{
|
||||
.el-icon{
|
||||
<style lang="scss" scoped>
|
||||
:deep(.el-sub-menu) {
|
||||
.el-icon {
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
:deep(.el-menu-item) {
|
||||
height: 40px!important;
|
||||
line-height: 40px!important;
|
||||
&.is-active {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
:deep(.el-sub-menu__title) {
|
||||
height: 40px!important;
|
||||
line-height: 40px!important;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -133,22 +133,22 @@ if (siteInfo?.apps.length > 1) {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.menu-wrap {
|
||||
padding: 0!important;
|
||||
|
||||
.el-menu {
|
||||
:deep(.el-menu) {
|
||||
border-right: 0!important;
|
||||
|
||||
.el-menu-item, .el-sub-menu__title {
|
||||
:deep(.el-menu-item), :deep(.el-sub-menu__title) {
|
||||
--el-menu-item-height: 40px;
|
||||
}
|
||||
|
||||
.el-sub-menu .el-menu-item {
|
||||
:deep(.el-sub-menu) :deep(.el-menu-item) {
|
||||
--el-menu-sub-item-height: 40px;
|
||||
}
|
||||
|
||||
.el-menu-item.is-active {
|
||||
:deep(.el-menu-item).is-active {
|
||||
background-color: var(--el-color-primary)
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ watch(route, () => {
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.layout-aside {
|
||||
&.bright {
|
||||
background-color: #F5F7F9;
|
||||
|
||||
@ -273,10 +273,18 @@ onMounted(() => {
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.el-sub-menu {
|
||||
<style lang="scss" scoped>
|
||||
:deep(.el-sub-menu) {
|
||||
.el-icon {
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
:deep(.el-menu-item) {
|
||||
height: 40px!important;
|
||||
line-height: 40px!important;
|
||||
}
|
||||
:deep(.el-sub-menu__title) {
|
||||
height: 40px!important;
|
||||
line-height: 40px!important;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -135,18 +135,18 @@ if (siteInfo?.apps.length > 1) {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.menu-wrap {
|
||||
padding: 0!important;
|
||||
|
||||
.el-menu {
|
||||
:deep(.el-menu) {
|
||||
border-right: 0!important;
|
||||
|
||||
.el-menu-item, .el-sub-menu__title {
|
||||
:deep(.el-menu-item), :deep(.el-sub-menu__title) {
|
||||
--el-menu-item-height: 40px;
|
||||
}
|
||||
|
||||
.el-sub-menu .el-menu-item {
|
||||
:deep(.el-sub-menu) :deep(.el-menu-item) {
|
||||
--el-menu-sub-item-height: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
@ -255,7 +255,7 @@ getVersionsInfo()
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.one-menu{
|
||||
padding: 20px 10px 10px;
|
||||
width: 78px;
|
||||
@ -315,10 +315,10 @@ getVersionsInfo()
|
||||
&.expanded .menu-item .text-center {
|
||||
opacity: 1;
|
||||
}
|
||||
.el-menu{
|
||||
:deep(.el-menu){
|
||||
border: 0;
|
||||
}
|
||||
.el-scrollbar{
|
||||
:deep(.el-scrollbar){
|
||||
height: calc(100vh - 65px);
|
||||
}
|
||||
}
|
||||
@ -327,7 +327,7 @@ getVersionsInfo()
|
||||
width: 185px;
|
||||
border: 0;
|
||||
padding-top: 15px;
|
||||
.el-menu-item{
|
||||
:deep(.el-menu-item){
|
||||
height: 40px;
|
||||
margin: 4px 15px;
|
||||
padding: 0 8px !important;
|
||||
@ -349,11 +349,11 @@ getVersionsInfo()
|
||||
// color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
.el-sub-menu{
|
||||
:deep(.el-sub-menu){
|
||||
width: 185px;
|
||||
margin: 4px 0;
|
||||
// margin-bottom: 8px;
|
||||
.el-sub-menu__title{
|
||||
:deep(.el-sub-menu__title){
|
||||
margin: 0 15px;
|
||||
height: 40px;
|
||||
padding-left: 8px;
|
||||
@ -370,11 +370,11 @@ getVersionsInfo()
|
||||
// background-color: var(--el-color-primary-light-9) !important;
|
||||
// color: var(--el-color-primary);
|
||||
}
|
||||
.el-icon.el-sub-menu__icon-arrow{
|
||||
.el-icon:deep(.el-sub-menu__icon-arrow){
|
||||
right: 5px;
|
||||
}
|
||||
}
|
||||
.el-menu-item{
|
||||
:deep(.el-menu-item){
|
||||
padding-left: 25px !important;
|
||||
}
|
||||
}
|
||||
@ -403,7 +403,7 @@ getVersionsInfo()
|
||||
// :deep(.el-scrollbar__bar){
|
||||
// display: none !important;
|
||||
// }
|
||||
// .layout-aside .el-scrollbar__wrap--hidden-default, .layout-aside .el-scrollbar{
|
||||
// .layout-aside .el-scrollbar__wrap--hidden-default, .layout-aside :deep(.el-scrollbar){
|
||||
// overflow: inherit !important;
|
||||
// }
|
||||
// 隐藏滚动条
|
||||
|
||||
@ -45,8 +45,8 @@ const props = defineProps({
|
||||
const meta = computed(() => props.routes.meta)
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.el-sub-menu{
|
||||
<style lang="scss" scoped>
|
||||
:deep(.el-sub-menu){
|
||||
.el-icon{
|
||||
width: auto;
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ userStore.routers = userStore.routers.filter((item, index) => {
|
||||
// })
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.logo-wrap {
|
||||
padding: 0;
|
||||
display: flex;
|
||||
@ -84,7 +84,7 @@ userStore.routers = userStore.routers.filter((item, index) => {
|
||||
flex: 1 !important;
|
||||
padding: 0 !important;
|
||||
|
||||
.el-menu {
|
||||
:deep(.el-menu) {
|
||||
border-right: 0 !important;
|
||||
}
|
||||
}
|
||||
@ -100,15 +100,15 @@ userStore.routers = userStore.routers.filter((item, index) => {
|
||||
border-bottom: 2px solid #101117;
|
||||
}
|
||||
|
||||
.el-menu {
|
||||
:deep(.el-menu) {
|
||||
background-color: #191a23;
|
||||
|
||||
.el-sub-menu {
|
||||
:deep(.el-sub-menu) {
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
.el-sub-menu__title,
|
||||
.el-menu-item {
|
||||
:deep(.el-sub-menu__title),
|
||||
:deep(.el-menu-item) {
|
||||
background: transparent !important;
|
||||
color: #B7B7ba;
|
||||
|
||||
@ -118,7 +118,7 @@ userStore.routers = userStore.routers.filter((item, index) => {
|
||||
}
|
||||
}
|
||||
|
||||
.el-menu-item.is-active {
|
||||
:deep(.el-menu-item).is-active {
|
||||
color: #fff !important;
|
||||
background-color: var(--el-color-primary) !important;
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ watch(route, () => {
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.layout-aside {
|
||||
border-right: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
@ -80,8 +80,8 @@ const handleJump = (routeName: string) => {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.el-sub-menu {
|
||||
<style lang="scss" scoped>
|
||||
:deep(.el-sub-menu) {
|
||||
|
||||
.el-icon {
|
||||
width: auto;
|
||||
|
||||
@ -377,13 +377,13 @@ watch(route, () => {
|
||||
}, { immediate: true })
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.one-menu {
|
||||
|
||||
.aside-menu:not(.el-menu--collapse) {
|
||||
background-color: transparent;
|
||||
|
||||
.el-menu-item {
|
||||
:deep(.el-menu-item) {
|
||||
font-size: 14px;
|
||||
height: 40px;
|
||||
margin-bottom: 4px;
|
||||
@ -408,11 +408,11 @@ watch(route, () => {
|
||||
}
|
||||
}
|
||||
|
||||
.el-menu {
|
||||
:deep(.el-menu) {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.el-scrollbar {
|
||||
:deep(.el-scrollbar) {
|
||||
height: calc(100vh - 65px);
|
||||
}
|
||||
}
|
||||
@ -424,7 +424,7 @@ watch(route, () => {
|
||||
padding-top: 16px;
|
||||
border: 0;
|
||||
|
||||
.el-menu-item {
|
||||
:deep(.el-menu-item) {
|
||||
height: 36px;
|
||||
margin: 0 12px 4px;
|
||||
padding: 0 !important;
|
||||
@ -445,10 +445,10 @@ watch(route, () => {
|
||||
}
|
||||
}
|
||||
|
||||
.el-sub-menu {
|
||||
:deep(.el-sub-menu) {
|
||||
margin-bottom: 8px;
|
||||
|
||||
.el-sub-menu__title {
|
||||
:deep(.el-sub-menu__title) {
|
||||
height: 36px;
|
||||
margin: 0 8px 4px;
|
||||
padding-left: 0;
|
||||
@ -465,19 +465,19 @@ watch(route, () => {
|
||||
color: var(--el-color-primary);
|
||||
background-color: var(--el-color-primary-light-9) !important;
|
||||
}
|
||||
.el-icon.el-sub-menu__icon-arrow {
|
||||
.el-icon:deep(.el-sub-menu__icon-arrow) {
|
||||
right: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.el-menu-item {
|
||||
:deep(.el-menu-item) {
|
||||
padding-left: 20px !important;
|
||||
span{
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
}
|
||||
.el-sub-menu{
|
||||
.el-sub-menu__title{
|
||||
:deep(.el-sub-menu){
|
||||
:deep(.el-sub-menu__title){
|
||||
margin: 0 8px 2px;
|
||||
height: 40px;
|
||||
padding-left: 18px;
|
||||
@ -493,7 +493,7 @@ watch(route, () => {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
.el-menu-item{
|
||||
:deep(.el-menu-item){
|
||||
padding-left: 40px !important;
|
||||
span{
|
||||
margin-left: 0 !important;
|
||||
|
||||
@ -20,7 +20,7 @@ watch(route, () => {
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.layout-aside {
|
||||
background-color: var(--side-dark-color, var(--el-bg-color));
|
||||
border-right: 1px solid var(--el-border-color-lighter);
|
||||
|
||||
@ -82,5 +82,5 @@ const handleJump = (routeName: string) => {
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
|
||||
@ -202,7 +202,7 @@ const collectSpecialMenuNamesLevel1 = (menus: any[]) =>{
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
<style scoped>
|
||||
:root,
|
||||
body {
|
||||
--layout-side-hover-bg: #f7f8fa;
|
||||
@ -210,7 +210,7 @@ body {
|
||||
--layout-side-active-text: var(--el-color-primary);
|
||||
}
|
||||
</style>
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.two-menu {
|
||||
|
||||
.aside-menu:not(.el-menu--collapse) {
|
||||
@ -218,7 +218,7 @@ body {
|
||||
padding-top: 16px;
|
||||
border: 0;
|
||||
|
||||
.el-menu-item {
|
||||
:deep(.el-menu-item) {
|
||||
height: 36px;
|
||||
margin: 0 8px 4px;
|
||||
padding: 0 !important;
|
||||
@ -242,10 +242,10 @@ body {
|
||||
}
|
||||
}
|
||||
|
||||
.el-sub-menu {
|
||||
:deep(.el-sub-menu) {
|
||||
margin-bottom: 8px;
|
||||
|
||||
.el-sub-menu__title {
|
||||
:deep(.el-sub-menu__title) {
|
||||
height: 36px;
|
||||
margin: 0 8px 4px;
|
||||
padding-left: 0;
|
||||
@ -262,19 +262,19 @@ body {
|
||||
color: var(--el-color-primary);
|
||||
background-color: #fff !important;
|
||||
}
|
||||
.el-icon.el-sub-menu__icon-arrow {
|
||||
.el-icon:deep(.el-sub-menu__icon-arrow) {
|
||||
right: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.el-menu-item {
|
||||
:deep(.el-menu-item) {
|
||||
padding-left: 25px !important;
|
||||
span{
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
}
|
||||
.el-sub-menu{
|
||||
.el-sub-menu__title{
|
||||
:deep(.el-sub-menu){
|
||||
:deep(.el-sub-menu__title){
|
||||
margin: 0 8px 2px;
|
||||
height: 40px;
|
||||
padding-left: 18px;
|
||||
@ -290,7 +290,7 @@ body {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
.el-menu-item{
|
||||
:deep(.el-menu-item){
|
||||
padding-left: 40px !important;
|
||||
span{
|
||||
margin-left: 0 !important;
|
||||
@ -306,7 +306,7 @@ body {
|
||||
padding: 8px;
|
||||
min-width: auto;
|
||||
}
|
||||
.el-menu-item, .el-sub-menu, .el-sub-menu{
|
||||
:deep(.el-menu-item), :deep(.el-sub-menu), :deep(.el-sub-menu){
|
||||
height: auto!important;
|
||||
padding: 10px;
|
||||
line-height: 1;
|
||||
|
||||
@ -397,7 +397,7 @@ const handleRouteSelect = (name:any) => {
|
||||
}
|
||||
|
||||
</script>
|
||||
<style>
|
||||
<style scoped>
|
||||
:root,
|
||||
body {
|
||||
--layout-header-bg: #fff;
|
||||
|
||||
@ -14,7 +14,14 @@ import VueUeditorWrap from 'vue-ueditor-wrap'
|
||||
|
||||
window.hl = hljs
|
||||
|
||||
import { initAddonManifests } from '@/utils/addon-lang'
|
||||
import { language } from '@/lang'
|
||||
|
||||
async function run() {
|
||||
if (!import.meta.env.DEV) {
|
||||
await initAddonManifests()
|
||||
await language.preloadAddonLangs()
|
||||
}
|
||||
const app = createApp(App)
|
||||
app.use(pinia)
|
||||
app.use(lang)
|
||||
|
||||
@ -6,14 +6,17 @@ import { language } from '@/lang'
|
||||
import useSystemStore from '@/stores/modules/system'
|
||||
import useUserStore from '@/stores/modules/user'
|
||||
import { setWindowTitle, getAppType, urlToRouteRaw } from '@/utils/common'
|
||||
import { resolveRouteAddon, resolveRouteView } from '@/utils/addon-loader'
|
||||
|
||||
// 加载插件中定义的router
|
||||
const ADDON_ROUTE = []
|
||||
const addonRoutes = import.meta.globEager('@/addon/**/router/index.ts')
|
||||
for (const key in addonRoutes) {
|
||||
const addon: any = addonRoutes[key]
|
||||
addon.ROUTE && ADDON_ROUTE.push(...addon.ROUTE)
|
||||
addon.NO_LOGIN_ROUTES && NO_LOGIN_ROUTES.push(...addon.NO_LOGIN_ROUTES)
|
||||
// 加载插件中定义的router(仅开发环境从源码加载)
|
||||
const ADDON_ROUTE: any[] = []
|
||||
if (import.meta.env.DEV) {
|
||||
const addonRoutes = import.meta.globEager('@/addon/**/router/index.ts')
|
||||
for (const key in addonRoutes) {
|
||||
const addon: any = addonRoutes[key]
|
||||
addon.ROUTE && ADDON_ROUTE.push(...addon.ROUTE)
|
||||
addon.NO_LOGIN_ROUTES && NO_LOGIN_ROUTES.push(...addon.NO_LOGIN_ROUTES)
|
||||
}
|
||||
}
|
||||
|
||||
const router = createRouter({
|
||||
@ -66,7 +69,11 @@ router.beforeEach(async (to: any, from, next) => {
|
||||
}
|
||||
|
||||
// 加载语言包
|
||||
await language.loadLocaleMessages(to.meta.addon || '', (to.meta.view || to.path), systemStore.lang);
|
||||
await language.loadLocaleMessages(
|
||||
resolveRouteAddon(to),
|
||||
resolveRouteView(to),
|
||||
systemStore.lang
|
||||
);
|
||||
|
||||
let matched: any = to.matched;
|
||||
if (matched && matched.length && matched[0].path != '/:pathMatch(.*)*') {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { RouteRecordRaw, RouterView } from 'vue-router'
|
||||
import Default from '@/layout/index.vue'
|
||||
import Decorate from '@/layout/decorate/index.vue'
|
||||
import { loadAddonView } from '@/utils/addon-loader'
|
||||
|
||||
// 静态路由
|
||||
export const STATIC_ROUTES: Array<RouteRecordRaw> = [
|
||||
@ -104,8 +105,9 @@ export const DECORATE_ROUTER: RouteRecordRaw = {
|
||||
children: []
|
||||
}
|
||||
|
||||
const modules = import.meta.glob('@/app/views/**/*.vue')
|
||||
const addonModules = import.meta.glob('@/addon/**/views/**/*.vue')
|
||||
const modules = import.meta.glob('../app/views/**/*.vue')
|
||||
// 开发环境:直接用 import.meta.glob 从源码加载所有插件视图(无需 manifest)
|
||||
const addonModules = import.meta.glob('../addon/**/views/**/*.vue')
|
||||
|
||||
interface Route {
|
||||
menu_name: string,
|
||||
@ -151,7 +153,26 @@ const createRoute = function (route: Route, parentRoute: RouteRecordRaw | null =
|
||||
}
|
||||
}
|
||||
if (route.menu_type == 1) {
|
||||
record.component = route.addon ? addonModules[`/src/addon/${ route.addon }/views/${ route.view_path }.vue`] : modules[`/src/app/views/${ route.view_path }.vue`]
|
||||
if (route.addon) {
|
||||
// view_path 优先,为空时 fallback 用 router_path
|
||||
let viewPath = route.view_path
|
||||
if (!viewPath && route.router_path) {
|
||||
viewPath = route.router_path
|
||||
}
|
||||
if (viewPath) {
|
||||
if (import.meta.env.DEV) {
|
||||
// 开发环境:直接用 import.meta.glob 从源码加载(无需 addon-loader/manifest)
|
||||
record.component = addonModules[`../addon/${route.addon}/views/${viewPath}.vue`]
|
||||
} else {
|
||||
// 生产环境:通过编译产物的 addon-loader 加载
|
||||
record.component = loadAddonView(route.addon, viewPath)
|
||||
}
|
||||
}
|
||||
// 无 viewPath 且无 router_path → 不设 component,作为容器路由,
|
||||
// 其 children(由 formatRouters 递归创建)通过父级 <RouterView> 渲染
|
||||
} else {
|
||||
record.component = modules[`../app/views/${ route.view_path }.vue`]
|
||||
}
|
||||
}
|
||||
return record
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
@import "addon/higohome/iconfont.css";
|
||||
@import "addon/home_service/iconfont.css";
|
||||
@import "addon/o2o/iconfont.css";
|
||||
@import "addon/tourism/iconfont.css";
|
||||
|
||||
643
admin/src/styles/icon/addon/higohome/iconfont.css
Normal file
643
admin/src/styles/icon/addon/higohome/iconfont.css
Normal file
@ -0,0 +1,643 @@
|
||||
@font-face {
|
||||
font-family: 'hi_iconfont'; /* Project id 4494655 */
|
||||
src: url('//at.alicdn.com/t/c/font_4494655_tdxdqgcaf5r.woff2?t=1737198657789') format('woff2'),
|
||||
url('//at.alicdn.com/t/c/font_4494655_tdxdqgcaf5r.woff?t=1737198657789') format('woff'),
|
||||
url('//at.alicdn.com/t/c/font_4494655_tdxdqgcaf5r.ttf?t=1737198657789') format('truetype');
|
||||
}
|
||||
|
||||
.hi_iconfont {
|
||||
font-family: "hi_iconfont" !important;
|
||||
font-size: 16px;
|
||||
font-style: normal;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
.hi_icon-biaodan:before {
|
||||
content: "\e669";
|
||||
}
|
||||
|
||||
.hi_icon-dianhua:before {
|
||||
content: "\e665";
|
||||
}
|
||||
|
||||
.hi_icon-shengao:before {
|
||||
content: "\e662";
|
||||
}
|
||||
|
||||
.hi_icon-edu-line:before {
|
||||
content: "\e663";
|
||||
}
|
||||
|
||||
.hi_icon-edu-s:before {
|
||||
content: "\e664";
|
||||
}
|
||||
|
||||
.hi_icon-sousuo:before {
|
||||
content: "\e661";
|
||||
}
|
||||
|
||||
.hi_icon-fenxiang:before {
|
||||
content: "\e660";
|
||||
}
|
||||
|
||||
.hi_icon-nv1:before {
|
||||
content: "\e668";
|
||||
}
|
||||
|
||||
.hi_icon-xuanzhong:before {
|
||||
content: "\e65f";
|
||||
}
|
||||
|
||||
.hi_icon-nan:before {
|
||||
content: "\e65d";
|
||||
}
|
||||
|
||||
.hi_icon-nv:before {
|
||||
content: "\e8b3";
|
||||
}
|
||||
|
||||
.hi_icon-shezhi1:before {
|
||||
content: "\e65c";
|
||||
}
|
||||
|
||||
.hi_icon-jifenshuoming:before {
|
||||
content: "\e7ae";
|
||||
}
|
||||
|
||||
.hi_icon-tuiguangpaihang:before {
|
||||
content: "\e65b";
|
||||
}
|
||||
|
||||
.hi_icon-dingdan1:before {
|
||||
content: "\e6ad";
|
||||
}
|
||||
|
||||
.hi_icon-dengjixunzhang:before {
|
||||
content: "\1012e";
|
||||
}
|
||||
|
||||
.hi_icon-yongjin:before {
|
||||
content: "\e708";
|
||||
}
|
||||
|
||||
.hi_icon-paihangbang:before {
|
||||
content: "\e66e";
|
||||
}
|
||||
|
||||
.hi_icon-icon:before {
|
||||
content: "\e658";
|
||||
}
|
||||
|
||||
.hi_icon-dingdan:before {
|
||||
content: "\e655";
|
||||
}
|
||||
|
||||
.hi_icon-top:before {
|
||||
content: "\e659";
|
||||
}
|
||||
|
||||
.hi_icon-tuandui:before {
|
||||
content: "\e65a";
|
||||
}
|
||||
|
||||
.hi_icon-shuoming:before {
|
||||
content: "\f4f9";
|
||||
}
|
||||
|
||||
.hi_icon-fenxiao-fenxiaojilu:before {
|
||||
content: "\e653";
|
||||
}
|
||||
|
||||
.hi_icon-RectangleCopy:before {
|
||||
content: "\e6b1";
|
||||
}
|
||||
|
||||
.hi_icon-pc-fenxiaoshangfenxiao:before {
|
||||
content: "\e786";
|
||||
}
|
||||
|
||||
.hi_icon-woyaofenxiao:before {
|
||||
content: "\e66f";
|
||||
}
|
||||
|
||||
.hi_icon-fenxiao-fenxiaoshuju:before {
|
||||
content: "\e8d1";
|
||||
}
|
||||
|
||||
.hi_icon-fenxiaoyeji:before {
|
||||
content: "\e76c";
|
||||
}
|
||||
|
||||
.hi_icon-jiantou1:before {
|
||||
content: "\e64e";
|
||||
}
|
||||
|
||||
.hi_icon-jiantoushang:before {
|
||||
content: "\e652";
|
||||
}
|
||||
|
||||
.hi_icon-erweima:before {
|
||||
content: "\e64b";
|
||||
}
|
||||
|
||||
.hi_icon-yanse:before {
|
||||
content: "\e679";
|
||||
}
|
||||
|
||||
.hi_icon-youhuiquan2:before {
|
||||
content: "\e884";
|
||||
}
|
||||
|
||||
.hi_icon-shouye:before {
|
||||
content: "\e649";
|
||||
}
|
||||
|
||||
.hi_icon-weixin:before {
|
||||
content: "\e64a";
|
||||
}
|
||||
|
||||
.hi_icon-dashiruzhu:before {
|
||||
content: "\e645";
|
||||
}
|
||||
|
||||
.hi_icon-hehuoren:before {
|
||||
content: "\e646";
|
||||
}
|
||||
|
||||
.hi_icon-daili:before {
|
||||
content: "\e647";
|
||||
}
|
||||
|
||||
.hi_icon-amazon-onestore:before {
|
||||
content: "\e75f";
|
||||
}
|
||||
|
||||
.hi_icon-a-Property1yewuyuanruzhu:before {
|
||||
content: "\e648";
|
||||
}
|
||||
|
||||
.hi_icon-mendianruzhu:before {
|
||||
content: "\e66b";
|
||||
}
|
||||
|
||||
.hi_icon-mendian1:before {
|
||||
content: "\e682";
|
||||
}
|
||||
|
||||
.hi_icon-shijian:before {
|
||||
content: "\e63f";
|
||||
}
|
||||
|
||||
.hi_icon-shezhi:before {
|
||||
content: "\e656";
|
||||
}
|
||||
|
||||
.hi_icon-jishiguanli:before {
|
||||
content: "\e63e";
|
||||
}
|
||||
|
||||
.hi_icon-jujue1:before {
|
||||
content: "\e639";
|
||||
}
|
||||
|
||||
.hi_icon-tuikuanshouhou:before {
|
||||
content: "\e6bb";
|
||||
}
|
||||
|
||||
.hi_icon-zhuandan:before {
|
||||
content: "\e677";
|
||||
}
|
||||
|
||||
.hi_icon-tongyi:before {
|
||||
content: "\e636";
|
||||
}
|
||||
|
||||
.hi_icon-jujue:before {
|
||||
content: "\e638";
|
||||
}
|
||||
|
||||
.hi_icon-wancheng1:before {
|
||||
content: "\e633";
|
||||
}
|
||||
|
||||
.hi_icon-daijiedan1:before {
|
||||
content: "\e62b";
|
||||
}
|
||||
|
||||
.hi_icon-chufa:before {
|
||||
content: "\e62c";
|
||||
}
|
||||
|
||||
.hi_icon-bangdingqudaoshang:before {
|
||||
content: "\e629";
|
||||
}
|
||||
|
||||
.hi_icon-xiangmu:before {
|
||||
content: "\e614";
|
||||
}
|
||||
|
||||
.hi_icon-kehuC:before {
|
||||
content: "\e60d";
|
||||
}
|
||||
|
||||
.hi_icon-huiyuan2:before {
|
||||
content: "\e644";
|
||||
}
|
||||
|
||||
.hi_icon-qianbao1:before {
|
||||
content: "\e651";
|
||||
}
|
||||
|
||||
.hi_icon-dapinglunxun:before {
|
||||
content: "\e627";
|
||||
}
|
||||
|
||||
.hi_icon-yingshoubaobiao:before {
|
||||
content: "\e6b2";
|
||||
}
|
||||
|
||||
.hi_icon-xuanzekuangmoren:before {
|
||||
content: "\e6c1";
|
||||
}
|
||||
|
||||
.hi_icon-xuanzekuangxuanzhong:before {
|
||||
content: "\e678";
|
||||
}
|
||||
|
||||
.hi_icon-icon-test1:before {
|
||||
content: "\e666";
|
||||
}
|
||||
|
||||
.hi_icon-zan1:before {
|
||||
content: "\e872";
|
||||
}
|
||||
|
||||
.hi_icon-tubiaozhizuo-:before {
|
||||
content: "\e60f";
|
||||
}
|
||||
|
||||
.hi_icon-jia:before {
|
||||
content: "\e625";
|
||||
}
|
||||
|
||||
.hi_icon-shipin1:before {
|
||||
content: "\e622";
|
||||
}
|
||||
|
||||
.hi_icon-tuwenzixun:before {
|
||||
content: "\e683";
|
||||
}
|
||||
|
||||
.hi_icon-shipin:before {
|
||||
content: "\e642";
|
||||
}
|
||||
|
||||
.hi_icon-zan:before {
|
||||
content: "\e870";
|
||||
}
|
||||
|
||||
.hi_icon-pinglun3:before {
|
||||
content: "\e641";
|
||||
}
|
||||
|
||||
.hi_icon-xiangji1fill:before {
|
||||
content: "\e77e";
|
||||
}
|
||||
|
||||
.hi_icon-xiangji:before {
|
||||
content: "\e621";
|
||||
}
|
||||
|
||||
.hi_icon-xuanze:before {
|
||||
content: "\e62f";
|
||||
}
|
||||
|
||||
.hi_icon-xuanze-weixuanze:before {
|
||||
content: "\e615";
|
||||
}
|
||||
|
||||
.hi_icon-gou:before {
|
||||
content: "\e66c";
|
||||
}
|
||||
|
||||
.hi_icon-dacha:before {
|
||||
content: "\e711";
|
||||
}
|
||||
|
||||
.hi_icon-chanpin1:before {
|
||||
content: "\e61f";
|
||||
}
|
||||
|
||||
.hi_icon-xiaoxi:before {
|
||||
content: "\e635";
|
||||
}
|
||||
|
||||
.hi_icon-chanpin:before {
|
||||
content: "\e650";
|
||||
}
|
||||
|
||||
.hi_icon-airudiantubiaohuizhi-zhuanqu_zixundongtai:before {
|
||||
content: "\e69d";
|
||||
}
|
||||
|
||||
.hi_icon-dongtai:before {
|
||||
content: "\e64f";
|
||||
}
|
||||
|
||||
.hi_icon-ziyuan:before {
|
||||
content: "\e61d";
|
||||
}
|
||||
|
||||
.hi_icon-youhuiquan1:before {
|
||||
content: "\e61e";
|
||||
}
|
||||
|
||||
.hi_icon-shengyin08-mianxing:before {
|
||||
content: "\e6eb";
|
||||
}
|
||||
|
||||
.hi_icon-pinglun2:before {
|
||||
content: "\e63a";
|
||||
}
|
||||
|
||||
.hi_icon-zanfill:before {
|
||||
content: "\e6ce";
|
||||
}
|
||||
|
||||
.hi_icon-fensiguanli:before {
|
||||
content: "\e62a";
|
||||
}
|
||||
|
||||
.hi_icon-basesalesupgradeSet:before {
|
||||
content: "\e632";
|
||||
}
|
||||
|
||||
.hi_icon-tixian:before {
|
||||
content: "\e67c";
|
||||
}
|
||||
|
||||
.hi_icon-tixian1:before {
|
||||
content: "\e619";
|
||||
}
|
||||
|
||||
.hi_icon-dingdanwuliaocaigouguanli:before {
|
||||
content: "\e63b";
|
||||
}
|
||||
|
||||
.hi_icon-chefeijilu:before {
|
||||
content: "\e613";
|
||||
}
|
||||
|
||||
.hi_icon-zhongchaping:before {
|
||||
content: "\e634";
|
||||
}
|
||||
|
||||
.hi_icon-addBlack:before {
|
||||
content: "\e630";
|
||||
}
|
||||
|
||||
.hi_icon-yidongfanyong:before {
|
||||
content: "\eb68";
|
||||
}
|
||||
|
||||
.hi_icon-fanyong:before {
|
||||
content: "\e67d";
|
||||
}
|
||||
|
||||
.hi_icon-fanyongjilu:before {
|
||||
content: "\e605";
|
||||
}
|
||||
|
||||
.hi_icon-daifuwu2:before {
|
||||
content: "\e7e5";
|
||||
}
|
||||
|
||||
.hi_icon-daijiedan:before {
|
||||
content: "\e60c";
|
||||
}
|
||||
|
||||
.hi_icon-jiantou:before {
|
||||
content: "\e65e";
|
||||
}
|
||||
|
||||
.hi_icon-icon-test:before {
|
||||
content: "\e60b";
|
||||
}
|
||||
|
||||
.hi_icon-show_more:before {
|
||||
content: "\e637";
|
||||
}
|
||||
|
||||
.hi_icon-jiantoukongxin_up:before {
|
||||
content: "\e612";
|
||||
}
|
||||
|
||||
.hi_icon-jiantou-zuoxia:before {
|
||||
content: "\e643";
|
||||
}
|
||||
|
||||
.hi_icon-zuojiantou:before {
|
||||
content: "\e61b";
|
||||
}
|
||||
|
||||
.hi_icon-xiajiantou:before {
|
||||
content: "\e6b3";
|
||||
}
|
||||
|
||||
.hi_icon-alarm-full:before {
|
||||
content: "\e871";
|
||||
}
|
||||
|
||||
.hi_icon-weizhigengxin:before {
|
||||
content: "\e929";
|
||||
}
|
||||
|
||||
.hi_icon-jihuatingjishijianshezhi_:before {
|
||||
content: "\e60a";
|
||||
}
|
||||
|
||||
.hi_icon-ditu:before {
|
||||
content: "\e72d";
|
||||
}
|
||||
|
||||
.hi_icon-jinjiqiuzhu-:before {
|
||||
content: "\e6be";
|
||||
}
|
||||
|
||||
.hi_icon-qianbao:before {
|
||||
content: "\e829";
|
||||
}
|
||||
|
||||
.hi_icon-zhifubaozhifu:before {
|
||||
content: "\e654";
|
||||
}
|
||||
|
||||
.hi_icon-weixinzhifu:before {
|
||||
content: "\e607";
|
||||
}
|
||||
|
||||
.hi_icon-dingwei:before {
|
||||
content: "\e63c";
|
||||
}
|
||||
|
||||
.hi_icon-dingwei1:before {
|
||||
content: "\e603";
|
||||
}
|
||||
|
||||
.hi_icon-dingwei2:before {
|
||||
content: "\e604";
|
||||
}
|
||||
|
||||
.hi_icon-dingwei3:before {
|
||||
content: "\e717";
|
||||
}
|
||||
|
||||
.hi_icon-dingwei4:before {
|
||||
content: "\e8c4";
|
||||
}
|
||||
|
||||
.hi_icon-dingwei5:before {
|
||||
content: "\e62d";
|
||||
}
|
||||
|
||||
.hi_icon-zaixianjiedan2mian:before {
|
||||
content: "\e64d";
|
||||
}
|
||||
|
||||
.hi_icon-wancheng:before {
|
||||
content: "\e60e";
|
||||
}
|
||||
|
||||
.hi_icon-chufadi:before {
|
||||
content: "\e6ff";
|
||||
}
|
||||
|
||||
.hi_icon-chufagangkou:before {
|
||||
content: "\e626";
|
||||
}
|
||||
|
||||
.hi_icon-daodamudedi:before {
|
||||
content: "\e657";
|
||||
}
|
||||
|
||||
.hi_icon-woyaofankui:before {
|
||||
content: "\e631";
|
||||
}
|
||||
|
||||
.hi_icon-pinglun1:before {
|
||||
content: "\e8b4";
|
||||
}
|
||||
|
||||
.hi_icon-tousutiwen:before {
|
||||
content: "\e624";
|
||||
}
|
||||
|
||||
.hi_icon-quanqudaofuwujiankong:before {
|
||||
content: "\e6cf";
|
||||
}
|
||||
|
||||
.hi_icon-mendian:before {
|
||||
content: "\e61a";
|
||||
}
|
||||
|
||||
.hi_icon-fenxianglaxin:before {
|
||||
content: "\e617";
|
||||
}
|
||||
|
||||
.hi_icon-dituibang1-09:before {
|
||||
content: "\e618";
|
||||
}
|
||||
|
||||
.hi_icon-laxinliebian:before {
|
||||
content: "\e74c";
|
||||
}
|
||||
|
||||
.hi_icon-quan:before {
|
||||
content: "\e602";
|
||||
}
|
||||
|
||||
.hi_icon-shoucang:before {
|
||||
content: "\e623";
|
||||
}
|
||||
|
||||
.hi_icon-bangzhu:before {
|
||||
content: "\e8a3";
|
||||
}
|
||||
|
||||
.hi_icon-youhuiquan:before {
|
||||
content: "\e61c";
|
||||
}
|
||||
|
||||
.hi_icon-daifuwu1:before {
|
||||
content: "\e610";
|
||||
}
|
||||
|
||||
.hi_icon-pinglun:before {
|
||||
content: "\e609";
|
||||
}
|
||||
|
||||
.hi_icon-daipingjia20:before {
|
||||
content: "\e63d";
|
||||
}
|
||||
|
||||
.hi_icon-yiwancheng:before {
|
||||
content: "\e6a6";
|
||||
}
|
||||
|
||||
.hi_icon-yiquxiao:before {
|
||||
content: "\e69c";
|
||||
}
|
||||
|
||||
.hi_icon-daizhifu:before {
|
||||
content: "\e694";
|
||||
}
|
||||
|
||||
.hi_icon-icon_xinyong_xianxing_jijin-:before {
|
||||
content: "\e640";
|
||||
}
|
||||
|
||||
.hi_icon-licai:before {
|
||||
content: "\e600";
|
||||
}
|
||||
|
||||
.hi_icon-diwup12:before {
|
||||
content: "\e62e";
|
||||
}
|
||||
|
||||
.hi_icon-shenqingdailishang:before {
|
||||
content: "\e608";
|
||||
}
|
||||
|
||||
.hi_icon-dailishang:before {
|
||||
content: "\e628";
|
||||
}
|
||||
|
||||
.hi_icon-yewuyuan:before {
|
||||
content: "\e601";
|
||||
}
|
||||
|
||||
.hi_icon-zu176:before {
|
||||
content: "\e606";
|
||||
}
|
||||
|
||||
.hi_icon-shenpitongguo:before {
|
||||
content: "\e611";
|
||||
}
|
||||
|
||||
.hi_icon-daifuwu:before {
|
||||
content: "\e64c";
|
||||
}
|
||||
|
||||
.hi_icon-jishi:before {
|
||||
content: "\e616";
|
||||
}
|
||||
|
||||
.hi_icon-yonghu:before {
|
||||
content: "\e620";
|
||||
}
|
||||
|
||||
.hi_icon-yonghu1:before {
|
||||
content: "\e667";
|
||||
}
|
||||
|
||||
1101
admin/src/styles/icon/addon/higohome/iconfont.json
Normal file
1101
admin/src/styles/icon/addon/higohome/iconfont.json
Normal file
File diff suppressed because it is too large
Load Diff
255
admin/src/utils/addon-lang.ts
Normal file
255
admin/src/utils/addon-lang.ts
Normal file
@ -0,0 +1,255 @@
|
||||
/**
|
||||
* 插件语言与 manifest 初始化(供 core shared admin-lang 与 addon-loader 共用)
|
||||
*/
|
||||
|
||||
export interface AddonManifest {
|
||||
key: string
|
||||
version?: string
|
||||
sharedVersion?: string
|
||||
views?: Record<string, string>
|
||||
components?: Record<string, string>
|
||||
layout?: string
|
||||
langBase?: string
|
||||
}
|
||||
|
||||
let prodManifests: Record<string, AddonManifest> = {}
|
||||
let installedAddonKeys: string[] = []
|
||||
let prodReady = false
|
||||
let prodInitPromise: Promise<void> | null = null
|
||||
const addonModuleCache: Record<string, Promise<Record<string, unknown> | null>> = {}
|
||||
|
||||
const ADMIN_PREFIX = '/admin'
|
||||
|
||||
export function adminUrl(relative: string) {
|
||||
if (!relative) return relative
|
||||
if (relative.startsWith('http') || relative.startsWith('/admin/')) return relative
|
||||
if (relative.startsWith('/assets/')) return `${ADMIN_PREFIX}${relative}`
|
||||
if (relative.startsWith('./')) return `${ADMIN_PREFIX}/assets/addons/${relative.slice(2)}`
|
||||
return `${ADMIN_PREFIX}/${relative.replace(/^\//, '')}`
|
||||
}
|
||||
|
||||
function addonAssetUrl(addon: string, ...segments: string[]) {
|
||||
const rel = ['assets', 'addons', addon, ...segments].join('/').replace(/\/+/g, '/')
|
||||
return `${ADMIN_PREFIX}/${rel}`
|
||||
}
|
||||
|
||||
export function resolveLangFile(app: string, path: string): string {
|
||||
if (path === '/') return 'index'
|
||||
let view = path.replace(/^(\/admin\/|\/site\/|\/)/, '').replace(/\.vue$/, '')
|
||||
if (view.startsWith('views/')) view = view.slice('views/'.length)
|
||||
if (app) {
|
||||
if (view.startsWith(`${app}/`)) view = view.slice(app.length + 1)
|
||||
else if (view === app) view = 'index'
|
||||
}
|
||||
return view.replaceAll('/', '.')
|
||||
}
|
||||
|
||||
export function resolveRouteAddon(route: { meta: Record<string, unknown>; matched: Array<{ meta: Record<string, unknown> }> }): string {
|
||||
if (route.meta.addon) return String(route.meta.addon)
|
||||
for (let i = route.matched.length - 1; i >= 0; i--) {
|
||||
const addon = route.matched[i].meta.addon
|
||||
if (addon) return String(addon)
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
export function resolveRouteView(route: { meta: Record<string, unknown>; matched: Array<{ meta: Record<string, unknown> }>; path: string }): string {
|
||||
if (route.meta.view) return String(route.meta.view)
|
||||
for (let i = route.matched.length - 1; i >= 0; i--) {
|
||||
const view = route.matched[i].meta.view
|
||||
if (view) return String(view)
|
||||
}
|
||||
return route.path
|
||||
}
|
||||
|
||||
function unwrapLangPack(pack: unknown): Record<string, string> {
|
||||
if (!pack || typeof pack !== 'object') return {}
|
||||
const obj = pack as Record<string, unknown>
|
||||
if (obj.default && typeof obj.default === 'object') {
|
||||
return unwrapLangPack(obj.default)
|
||||
}
|
||||
const result: Record<string, string> = {}
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (key === 'default' || key === '__esModule') continue
|
||||
if (typeof value === 'string') result[key] = value
|
||||
}
|
||||
return Object.keys(result).length ? result : (obj as Record<string, string>)
|
||||
}
|
||||
|
||||
function flattenLangPack(file: string, pack: Record<string, string>): Record<string, string> {
|
||||
const data: Record<string, string> = {}
|
||||
for (const [key, value] of Object.entries(pack)) {
|
||||
if (typeof value !== 'string') continue
|
||||
data[`${file}.${key}`] = value
|
||||
if (file === 'common') data[key] = value
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
export function inferAddonFromPath(path: string, knownAddons?: string[]): string {
|
||||
const view = path.replace(/^(\/admin\/|\/site\/|\/)/, '')
|
||||
const first = view.split('/').filter(Boolean)[0]
|
||||
if (!first) return ''
|
||||
const keys = knownAddons?.length ? knownAddons : getInstalledAddonKeys()
|
||||
return keys.includes(first) ? first : ''
|
||||
}
|
||||
|
||||
async function isAddonEntryAvailable(key: string): Promise<boolean> {
|
||||
try {
|
||||
const res = await fetch(adminUrl(`/assets/addons/${key}/index.js`), { method: 'HEAD' })
|
||||
if (!res.ok) return false
|
||||
const ct = (res.headers.get('content-type') || '').toLowerCase()
|
||||
return !ct.includes('text/html')
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function isAddonInstalled(addon: string): boolean {
|
||||
return !!addon && getInstalledAddonKeys().includes(addon)
|
||||
}
|
||||
|
||||
export async function loadAddonModule(addon: string): Promise<Record<string, unknown> | null> {
|
||||
if (!(addon in addonModuleCache)) {
|
||||
addonModuleCache[addon] = (async () => {
|
||||
try {
|
||||
const url = adminUrl(`/assets/addons/${addon}/index.js`)
|
||||
return await import(/* @vite-ignore */ url) as Record<string, unknown>
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
})()
|
||||
}
|
||||
return addonModuleCache[addon]
|
||||
}
|
||||
|
||||
/** 清除插件模块缓存(布局切换时调用,确保样式重新注入) */
|
||||
export function clearAddonModuleCache() {
|
||||
for (const key of Object.keys(addonModuleCache)) {
|
||||
delete addonModuleCache[key]
|
||||
}
|
||||
}
|
||||
|
||||
export function isAddonProdReady() {
|
||||
return prodReady
|
||||
}
|
||||
|
||||
export async function ensureAddonProdReady() {
|
||||
if (!prodReady) await initAddonManifests()
|
||||
}
|
||||
|
||||
export async function initAddonManifests(keys?: string[]) {
|
||||
if (import.meta.env.DEV) {
|
||||
prodReady = true
|
||||
return
|
||||
}
|
||||
if (prodInitPromise) return prodInitPromise
|
||||
|
||||
prodInitPromise = (async () => {
|
||||
prodManifests = {}
|
||||
installedAddonKeys = []
|
||||
let addonKeys = keys
|
||||
if (!addonKeys?.length) {
|
||||
try {
|
||||
const indexUrl = adminUrl('/assets/addons/index.json')
|
||||
const res = await fetch(indexUrl)
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
addonKeys = Array.isArray(data.keys) ? data.keys : []
|
||||
}
|
||||
} catch {
|
||||
addonKeys = []
|
||||
}
|
||||
}
|
||||
const verifiedKeys: string[] = []
|
||||
for (const key of addonKeys || []) {
|
||||
if (!(await isAddonEntryAvailable(key))) continue
|
||||
verifiedKeys.push(key)
|
||||
try {
|
||||
const url = adminUrl(`/assets/addons/${key}/manifest.json`)
|
||||
const res = await fetch(url)
|
||||
if (res.ok) {
|
||||
prodManifests[key] = await res.json()
|
||||
}
|
||||
} catch {
|
||||
// skip missing manifest
|
||||
}
|
||||
}
|
||||
installedAddonKeys = verifiedKeys
|
||||
prodReady = true
|
||||
})()
|
||||
|
||||
return prodInitPromise
|
||||
}
|
||||
|
||||
export function getInstalledAddonKeys(): string[] {
|
||||
if (installedAddonKeys.length) return installedAddonKeys
|
||||
return Object.keys(prodManifests)
|
||||
}
|
||||
|
||||
export function getProdManifests(): Record<string, AddonManifest> {
|
||||
return prodManifests
|
||||
}
|
||||
|
||||
export async function preloadAllAddonLangs(
|
||||
merge: (locale: string, messages: Record<string, string>) => void
|
||||
) {
|
||||
if (import.meta.env.DEV) return
|
||||
if (!prodReady) await initAddonManifests()
|
||||
|
||||
for (const addon of getInstalledAddonKeys()) {
|
||||
try {
|
||||
const mod = await loadAddonModule(addon)
|
||||
if (!mod) continue
|
||||
const langs = mod.langs as Record<string, Record<string, unknown>> | undefined
|
||||
if (!langs) continue
|
||||
for (const [locale, files] of Object.entries(langs)) {
|
||||
const merged: Record<string, string> = {}
|
||||
for (const [file, pack] of Object.entries(files || {})) {
|
||||
Object.assign(merged, flattenLangPack(file, unwrapLangPack(pack)))
|
||||
}
|
||||
if (Object.keys(merged).length) merge(locale, merged)
|
||||
}
|
||||
} catch {
|
||||
// skip broken addon module
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function registerAddonManifest(manifest: AddonManifest) {
|
||||
prodManifests[manifest.key] = manifest
|
||||
prodReady = true
|
||||
}
|
||||
|
||||
export async function loadAddonLang(addon: string, locale: string, file: string): Promise<Record<string, string>> {
|
||||
if (import.meta.env.DEV) {
|
||||
try {
|
||||
const messages = await import(/* @vite-ignore */ `@/addon/${addon}/lang/${locale}/${file}.json`)
|
||||
return messages.default || {}
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
if (!prodReady) await initAddonManifests()
|
||||
|
||||
try {
|
||||
const mod = await loadAddonModule(addon)
|
||||
if (mod) {
|
||||
const langs = mod.langs as Record<string, Record<string, Record<string, unknown>>> | undefined
|
||||
const pack = langs?.[locale]?.[file]
|
||||
const messages = unwrapLangPack(pack)
|
||||
if (Object.keys(messages).length) return messages
|
||||
}
|
||||
} catch {
|
||||
// fallback to static lang files
|
||||
}
|
||||
|
||||
const url = addonAssetUrl(addon, 'lang', locale, `${file}.json`)
|
||||
try {
|
||||
const res = await fetch(url)
|
||||
if (res.ok) return await res.json()
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
return {}
|
||||
}
|
||||
204
admin/src/utils/addon-loader.ts
Normal file
204
admin/src/utils/addon-loader.ts
Normal file
@ -0,0 +1,204 @@
|
||||
/**
|
||||
* 插件运行时加载:dev 用 import.meta.glob 直读源码,prod 用 drop-in 编译产物
|
||||
*/
|
||||
import type { Component } from 'vue'
|
||||
import { defineAsyncComponent } from 'vue'
|
||||
import {
|
||||
type AddonManifest,
|
||||
adminUrl,
|
||||
clearAddonModuleCache,
|
||||
ensureAddonProdReady,
|
||||
getProdManifests,
|
||||
initAddonManifests,
|
||||
loadAddonLang,
|
||||
loadAddonModule,
|
||||
preloadAllAddonLangs,
|
||||
registerAddonManifest,
|
||||
resolveLangFile,
|
||||
resolveRouteAddon,
|
||||
resolveRouteView,
|
||||
inferAddonFromPath,
|
||||
getInstalledAddonKeys,
|
||||
isAddonInstalled
|
||||
} from '@/utils/addon-lang'
|
||||
|
||||
export type { AddonManifest }
|
||||
export {
|
||||
adminUrl,
|
||||
initAddonManifests,
|
||||
loadAddonLang,
|
||||
preloadAllAddonLangs,
|
||||
registerAddonManifest,
|
||||
resolveLangFile,
|
||||
resolveRouteAddon,
|
||||
resolveRouteView,
|
||||
inferAddonFromPath,
|
||||
getInstalledAddonKeys,
|
||||
loadAddonModule
|
||||
}
|
||||
|
||||
/** 清除插件样式 DOM 节点和模块缓存(布局切换时用) */
|
||||
export function clearAddonStyleCache() {
|
||||
document.querySelectorAll('style[data-addon-style]').forEach(el => el.remove())
|
||||
clearAddonModuleCache()
|
||||
}
|
||||
|
||||
type ViewLoader = () => Promise<{ default: Component }>
|
||||
|
||||
const load404 = (): Promise<{ default: Component }> =>
|
||||
import('@/app/views/error/404.vue') as Promise<{ default: Component }>
|
||||
|
||||
// 开发环境:用 import.meta.glob 直读所有插件源码(无需 addon-manifest.dev.ts)
|
||||
const allAddonVueModules = import.meta.glob('../addon/**/views/**/*.vue')
|
||||
const addonLayoutModules = import.meta.glob('../addon/*/layout/index.vue')
|
||||
|
||||
async function importProdModule(url: string): Promise<Component | null> {
|
||||
try {
|
||||
const full = adminUrl(url.startsWith('./') ? url : url)
|
||||
const mod = await import(/* @vite-ignore */ full)
|
||||
return mod.default ?? mod
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function loadAddonView(addon: string, viewPath: string): ViewLoader {
|
||||
if (!addon) {
|
||||
return () => load404()
|
||||
}
|
||||
|
||||
// 开发环境:glob 直读源码(routers.ts 已优先走 glob,此处为兜底)
|
||||
if (import.meta.env.DEV) {
|
||||
return async () => {
|
||||
const loader = allAddonVueModules[`../addon/${addon}/views/${viewPath}.vue`] as ViewLoader | undefined
|
||||
if (loader) return loader()
|
||||
return load404()
|
||||
}
|
||||
}
|
||||
|
||||
return async () => {
|
||||
await ensureAddonProdReady()
|
||||
if (!isAddonInstalled(addon)) {
|
||||
console.error(`[loadAddonView] addon "${addon}" not installed. Installed:`, getInstalledAddonKeys())
|
||||
return load404()
|
||||
}
|
||||
try {
|
||||
const mod = await loadAddonModule(addon)
|
||||
if (!mod) {
|
||||
console.error(`[loadAddonView] addon "${addon}" module loaded as null/undefined`)
|
||||
return load404()
|
||||
}
|
||||
const loader = mod.views?.[viewPath] as ViewLoader | undefined
|
||||
if (!loader) {
|
||||
const available = Object.keys(mod.views || {})
|
||||
console.error(`[loadAddonView] addon="${addon}" viewPath="${viewPath}" NOT FOUND. Available (${available.length}):`, available.slice(0, 10), available.length > 10 ? `... and ${available.length - 10} more` : '')
|
||||
return load404()
|
||||
}
|
||||
try {
|
||||
return await loader()
|
||||
} catch (e) {
|
||||
console.error(`[loadAddonView] addon="${addon}" viewPath="${viewPath}" loader threw:`, e)
|
||||
return load404()
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`[loadAddonView] addon="${addon}" module import failed:`, e)
|
||||
return load404()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function loadAddonComponent(addon: string, subPath: string, name: string): ViewLoader {
|
||||
const key = `${subPath}/${name}`.replace(/\/+/g, '/')
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
return async () => {
|
||||
const loader = allAddonVueModules[`../addon/${addon}/views/${subPath}/${name}.vue`] as ViewLoader | undefined
|
||||
if (loader) return loader()
|
||||
return load404()
|
||||
}
|
||||
}
|
||||
|
||||
return (async () => {
|
||||
await ensureAddonProdReady()
|
||||
if (!isAddonInstalled(addon)) return null as any
|
||||
try {
|
||||
const mod = await loadAddonModule(addon)
|
||||
if (!mod) return null as any
|
||||
const components = (mod as Record<string, unknown>).components as Record<string, ViewLoader> | undefined
|
||||
if (!components) return null as any
|
||||
const loader = components[key] as ViewLoader | undefined
|
||||
if (!loader) return null as any
|
||||
return await loader()
|
||||
} catch {
|
||||
return null as any
|
||||
}
|
||||
}) as unknown as ViewLoader
|
||||
}
|
||||
|
||||
export function loadAddonLayout(addon: string): ViewLoader | null {
|
||||
if (import.meta.env.DEV) {
|
||||
return async () => {
|
||||
const loader = addonLayoutModules[`../addon/${addon}/layout/index.vue`] as ViewLoader | undefined
|
||||
if (loader) return loader()
|
||||
return load404()
|
||||
}
|
||||
}
|
||||
|
||||
return async () => {
|
||||
await ensureAddonProdReady()
|
||||
if (!isAddonInstalled(addon)) return load404()
|
||||
const rel = getProdManifests()[addon]?.layout
|
||||
if (!rel) return load404()
|
||||
const mod = await importProdModule(rel)
|
||||
if (!mod) return load404()
|
||||
return { default: mod as Component }
|
||||
}
|
||||
}
|
||||
|
||||
/** Core 内动态组件(pay/diy-link 等),不含 addon 部分 */
|
||||
export const coreVueModules = {
|
||||
...import.meta.glob('../app/**/*.vue'),
|
||||
...import.meta.glob('../components/**/*.vue'),
|
||||
...import.meta.glob('../layout/**/*.vue')
|
||||
}
|
||||
|
||||
function normalizeComponentKey(p: string): string {
|
||||
return p
|
||||
.replace(/^@\//, '')
|
||||
.replace(/^\/src\//, '')
|
||||
.replace(/^\.\.\//, '')
|
||||
.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
function findCoreModuleLoader(componentPath: string): ViewLoader | undefined {
|
||||
const map = coreVueModules as Record<string, ViewLoader>
|
||||
if (map[componentPath]) return map[componentPath]
|
||||
const target = normalizeComponentKey(componentPath)
|
||||
const key = Object.keys(map).find((k) => normalizeComponentKey(k) === target || normalizeComponentKey(k).endsWith(`/${target}`))
|
||||
return key ? map[key] : undefined
|
||||
}
|
||||
|
||||
export function resolveAsyncComponent(componentPath: string) {
|
||||
return defineAsyncComponent(async () => {
|
||||
const loader = findCoreModuleLoader(componentPath)
|
||||
if (loader) return (await loader()).default as Component
|
||||
const mod = await loadCoreVueModule(componentPath)
|
||||
return mod.default as Component
|
||||
})
|
||||
}
|
||||
|
||||
export async function loadCoreVueModule(componentPath: string) {
|
||||
const loader = findCoreModuleLoader(componentPath)
|
||||
if (loader) return loader()
|
||||
if (import.meta.env.DEV) {
|
||||
if (componentPath.includes('/addon/')) {
|
||||
const m = componentPath.match(/\/addon\/([^/]+)\/views\/(.+)\.vue$/)
|
||||
if (m) {
|
||||
const [, addon, rest] = m
|
||||
const viewLoader = allAddonVueModules[`../addon/${addon}/views/${rest}.vue`] as ViewLoader | undefined
|
||||
if (viewLoader) return viewLoader()
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error(`Component not found: ${componentPath}`)
|
||||
}
|
||||
@ -3,6 +3,7 @@ import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
||||
import { useCssVar, useTitle } from '@vueuse/core'
|
||||
import colorFunction from 'css-color-function'
|
||||
import storage from './storage'
|
||||
import envConfig from '@/utils/config'
|
||||
|
||||
/**
|
||||
* 全局注册element-icon
|
||||
@ -65,7 +66,7 @@ export function getAppType() {
|
||||
*/
|
||||
export function setWindowTitle(value: string = ''): void {
|
||||
const title = useTitle()
|
||||
title.value = value ? value : import.meta.env.VITE_DETAULT_TITLE
|
||||
title.value = value ? value : envConfig.VITE_DETAULT_TITLE
|
||||
}
|
||||
|
||||
/**
|
||||
@ -129,7 +130,7 @@ export function isUrl(str: string): boolean {
|
||||
export function img(path: string): string {
|
||||
if (!path) return ''
|
||||
|
||||
let imgDomain = import.meta.env.VITE_IMG_DOMAIN || location.origin
|
||||
let imgDomain = envConfig.VITE_IMG_DOMAIN || location.origin
|
||||
|
||||
if (path.startsWith('/')) path = path.replace(/^\//, '')
|
||||
if (imgDomain.endsWith('/')) imgDomain = imgDomain.slice(0, -1)
|
||||
|
||||
10
admin/src/utils/config.ts
Normal file
10
admin/src/utils/config.ts
Normal file
@ -0,0 +1,10 @@
|
||||
// 优先读取外挂 window.__ENV__,部署后可直接修改,无需重编译
|
||||
const env = (typeof window !== 'undefined' ? (window as any).__ENV__ : null) || {}
|
||||
|
||||
export default {
|
||||
VITE_APP_BASE_URL: env.VITE_APP_BASE_URL || import.meta.env.VITE_APP_BASE_URL,
|
||||
VITE_IMG_DOMAIN: env.VITE_IMG_DOMAIN || import.meta.env.VITE_IMG_DOMAIN,
|
||||
VITE_REQUEST_HEADER_TOKEN_KEY: env.VITE_REQUEST_HEADER_TOKEN_KEY || import.meta.env.VITE_REQUEST_HEADER_TOKEN_KEY || 'token',
|
||||
VITE_REQUEST_HEADER_SITEID_KEY: env.VITE_REQUEST_HEADER_SITEID_KEY || import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY || 'site-id',
|
||||
VITE_DETAULT_TITLE: env.VITE_DETAULT_TITLE || import.meta.env.VITE_DETAULT_TITLE || ''
|
||||
}
|
||||
57
admin/src/utils/core-component-resolver.ts
Normal file
57
admin/src/utils/core-component-resolver.ts
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Core 内动态组件解析(pay/diy-link 等),仅 core 使用,不可打进 addon 包
|
||||
*/
|
||||
import type { Component } from 'vue'
|
||||
import { defineAsyncComponent } from 'vue'
|
||||
|
||||
export const coreVueModules = {
|
||||
...import.meta.glob('../app/**/*.vue'),
|
||||
...import.meta.glob('../components/**/*.vue'),
|
||||
...import.meta.glob('../layout/**/*.vue')
|
||||
}
|
||||
|
||||
type ViewLoader = () => Promise<{ default: Component }>
|
||||
|
||||
function normalizeComponentKey(p: string): string {
|
||||
return p
|
||||
.replace(/^@\//, '')
|
||||
.replace(/^\/src\//, '')
|
||||
.replace(/^\.\.\//, '')
|
||||
.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
function findCoreModuleLoader(componentPath: string): ViewLoader | undefined {
|
||||
const map = coreVueModules as Record<string, ViewLoader>
|
||||
if (map[componentPath]) return map[componentPath]
|
||||
const target = normalizeComponentKey(componentPath)
|
||||
const key = Object.keys(map).find((k) => normalizeComponentKey(k) === target || normalizeComponentKey(k).endsWith(`/${target}`))
|
||||
return key ? map[key] : undefined
|
||||
}
|
||||
|
||||
export function resolveAsyncComponent(componentPath: string) {
|
||||
return defineAsyncComponent(async () => {
|
||||
const loader = findCoreModuleLoader(componentPath)
|
||||
if (loader) return (await loader()).default as Component
|
||||
const mod = await loadCoreVueModule(componentPath)
|
||||
return mod.default as Component
|
||||
})
|
||||
}
|
||||
|
||||
// 开发环境:glob 直读插件源码(无需 addon-manifest.dev.ts)
|
||||
const allAddonVueModules = import.meta.glob('../addon/**/views/**/*.vue')
|
||||
|
||||
export async function loadCoreVueModule(componentPath: string) {
|
||||
const loader = findCoreModuleLoader(componentPath)
|
||||
if (loader) return loader()
|
||||
if (import.meta.env.DEV) {
|
||||
if (componentPath.includes('/addon/')) {
|
||||
const m = componentPath.match(/\/addon\/([^/]+)\/views\/(.+)\.vue$/)
|
||||
if (m) {
|
||||
const [, addon, rest] = m
|
||||
const viewLoader = (allAddonVueModules as Record<string, ViewLoader>)[`../addon/${addon}/views/${rest}.vue`]
|
||||
if (viewLoader) return viewLoader()
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error(`Component not found: ${componentPath}`)
|
||||
}
|
||||
@ -6,6 +6,7 @@ import type { MessageParams } from 'element-plus'
|
||||
import { t } from '@/lang'
|
||||
import useUserStore from '@/stores/modules/user'
|
||||
import storage from '@/utils/storage'
|
||||
import envConfig from '@/utils/config'
|
||||
|
||||
interface RequestConfig extends AxiosRequestConfig {
|
||||
showErrorMessage?: boolean
|
||||
@ -47,7 +48,7 @@ class Request {
|
||||
|
||||
constructor() {
|
||||
this.instance = axios.create({
|
||||
baseURL: import.meta.env.VITE_APP_BASE_URL.substr(-1) == '/' ? import.meta.env.VITE_APP_BASE_URL : `${import.meta.env.VITE_APP_BASE_URL}/`,
|
||||
baseURL: envConfig.VITE_APP_BASE_URL.substr(-1) == '/' ? envConfig.VITE_APP_BASE_URL : `${envConfig.VITE_APP_BASE_URL}/`,
|
||||
timeout: 0,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -60,9 +61,9 @@ class Request {
|
||||
(config: InternalRequestConfig) => {
|
||||
// 携带token site-id
|
||||
if (getToken()) {
|
||||
config.headers[import.meta.env.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
|
||||
config.headers[envConfig.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
|
||||
}
|
||||
config.headers[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = storage.get('siteId') || 0
|
||||
config.headers[envConfig.VITE_REQUEST_HEADER_SITEID_KEY] = storage.get('siteId') || 0
|
||||
return config
|
||||
},
|
||||
(err: any) => {
|
||||
|
||||
81
admin/vite.config.addon.ts
Normal file
81
admin/vite.config.addon.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
import { createRequire } from 'node:module'
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import AutoImport from 'unplugin-auto-import/vite'
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const { isSharedExternal, isAdminLangExternal, adminLangExternalPath, isCoreExternal, coreExternalPath } = require('./scripts/shared-external.cjs')
|
||||
const { stripElementPlusStylePlugin } = require('./scripts/vite-plugin-strip-element-plus-style.cjs')
|
||||
|
||||
const addonKey = process.env.ADDON_KEY || ''
|
||||
if (!addonKey) {
|
||||
throw new Error('ADDON_KEY is required for addon build')
|
||||
}
|
||||
|
||||
const entry = fileURLToPath(new URL(`./.build/addons/${addonKey}/entry.ts`, import.meta.url))
|
||||
|
||||
const elementPlusResolver = ElementPlusResolver({ importStyle: false })
|
||||
|
||||
/** 单插件生产构建 */
|
||||
export default defineConfig({
|
||||
base: '',
|
||||
publicDir: false,
|
||||
define: {
|
||||
'process.env.NODE_ENV': JSON.stringify('production'),
|
||||
__VUE_OPTIONS_API__: true,
|
||||
__VUE_PROD_DEVTOOLS__: false,
|
||||
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
|
||||
},
|
||||
plugins: [
|
||||
stripElementPlusStylePlugin(),
|
||||
vue(),
|
||||
AutoImport({ resolvers: [elementPlusResolver] }),
|
||||
Components({ resolvers: [elementPlusResolver] }),
|
||||
// 注入 CSS:lib 模式 CSS 统一提取到 style.css,运行时注入为 <style> 标签
|
||||
{
|
||||
name: 'addon-css-inject',
|
||||
enforce: 'post',
|
||||
generateBundle(_opts, bundle) {
|
||||
const entry = bundle['index.js']
|
||||
const cssAsset = bundle['style.css']
|
||||
if (entry && entry.type === 'chunk' && cssAsset && cssAsset.type === 'asset') {
|
||||
const css = JSON.stringify(cssAsset.source)
|
||||
entry.code = `(function(){var s=document.createElement('style');s.textContent=${css};s.setAttribute('data-addon-style','${addonKey}');document.head.insertBefore(s,document.head.firstChild)})();\n${entry.code}`
|
||||
delete bundle['style.css']
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||
assets: fileURLToPath(new URL('./src/assets', import.meta.url)),
|
||||
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
|
||||
}
|
||||
},
|
||||
build: {
|
||||
cssCodeSplit: false,
|
||||
outDir: `dist/.addons/${addonKey}`,
|
||||
emptyOutDir: true,
|
||||
lib: {
|
||||
entry,
|
||||
formats: ['es'],
|
||||
fileName: () => 'index.js'
|
||||
},
|
||||
rollupOptions: {
|
||||
external: (id) => isAdminLangExternal(id) || isSharedExternal(id) || isCoreExternal(id),
|
||||
output: {
|
||||
inlineDynamicImports: false,
|
||||
chunkFileNames: '[name]-[hash].js',
|
||||
entryFileNames: 'index.js',
|
||||
paths(id) {
|
||||
if (isAdminLangExternal(id)) return adminLangExternalPath()
|
||||
if (isCoreExternal(id)) return coreExternalPath()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
77
admin/vite.config.core.ts
Normal file
77
admin/vite.config.core.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
import { createRequire } from 'node:module'
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import AutoImport from 'unplugin-auto-import/vite'
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const { isSharedExternal, isAdminLangExternal, adminLangExternalPath } = require('./scripts/shared-external.cjs')
|
||||
const { stripElementPlusStylePlugin } = require('./scripts/vite-plugin-strip-element-plus-style.cjs')
|
||||
|
||||
const rootDir = fileURLToPath(new URL('.', import.meta.url))
|
||||
|
||||
const elementPlusResolver = ElementPlusResolver({ importStyle: false })
|
||||
|
||||
/** Core 生产构建:不包含 src/addon 源码(运行时通过 manifest 加载) */
|
||||
export default defineConfig({
|
||||
base: '',
|
||||
define: {
|
||||
'process.env.NODE_ENV': JSON.stringify('production'),
|
||||
__VUE_OPTIONS_API__: true,
|
||||
__VUE_PROD_DEVTOOLS__: false,
|
||||
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
|
||||
},
|
||||
plugins: [
|
||||
stripElementPlusStylePlugin(),
|
||||
vue(),
|
||||
AutoImport({ resolvers: [elementPlusResolver] }),
|
||||
Components({ resolvers: [elementPlusResolver] }),
|
||||
{
|
||||
name: 'exclude-addon-source',
|
||||
enforce: 'pre',
|
||||
resolveId(source, importer) {
|
||||
if (source.includes('*')) return null
|
||||
const norm = source.replace(/\\/g, '/')
|
||||
if (importer && importer.includes('/src/addon/')) return null
|
||||
if (norm.startsWith('@/addon/') || norm.includes('/src/addon/')) {
|
||||
// 虚拟 id 勿以 .json 结尾,否则 vite:json 会尝试解析
|
||||
return '\0addon-external:' + norm.replace(/\.json$/i, '.langdata')
|
||||
}
|
||||
},
|
||||
load(id) {
|
||||
if (id.startsWith('\0addon-external:')) {
|
||||
return 'export default {}'
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||
assets: fileURLToPath(new URL('./src/assets', import.meta.url)),
|
||||
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
|
||||
}
|
||||
},
|
||||
build: {
|
||||
outDir: 'dist/.core',
|
||||
emptyOutDir: true,
|
||||
manifest: true,
|
||||
rollupOptions: {
|
||||
external: (id) => {
|
||||
const norm = id.replace(/\\/g, '/')
|
||||
if (norm.includes('/style/css') || norm.includes('/style/index')) return false
|
||||
if (norm.includes('element-plus/dist/')) return false
|
||||
if (norm.includes('element-plus/theme-chalk')) return false
|
||||
if (isAdminLangExternal(id)) return true
|
||||
return isSharedExternal(id)
|
||||
},
|
||||
output: {
|
||||
paths(id) {
|
||||
if (isAdminLangExternal(id)) return adminLangExternalPath()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
67
admin/vite.config.shared.ts
Normal file
67
admin/vite.config.shared.ts
Normal file
@ -0,0 +1,67 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
import { createRequire } from 'node:module'
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const { sharedExternalForBuild } = require('./scripts/shared-external.cjs')
|
||||
|
||||
const pkgKey = process.env.SHARED_PKG || 'vue'
|
||||
const emptyOutDir = process.env.SHARED_EMPTY === '1'
|
||||
|
||||
const entry = fileURLToPath(new URL(`./.build/shared/${pkgKey}.ts`, import.meta.url))
|
||||
const outName = pkgKey === 'icons-vue' ? 'icons-vue' : pkgKey
|
||||
|
||||
const needsCore = pkgKey === 'admin-lang' || pkgKey === 'core-shared'
|
||||
|
||||
/** 单包 shared ESM 构建,peer 依赖保持 external 由 import map 解析 */
|
||||
export default defineConfig({
|
||||
publicDir: false,
|
||||
define: {
|
||||
'process.env.NODE_ENV': JSON.stringify('production'),
|
||||
__VUE_OPTIONS_API__: true,
|
||||
__VUE_PROD_DEVTOOLS__: false,
|
||||
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
|
||||
},
|
||||
resolve: needsCore
|
||||
? {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
|
||||
}
|
||||
}
|
||||
: undefined,
|
||||
plugins: needsCore
|
||||
? [
|
||||
vue(),
|
||||
{
|
||||
name: 'shared-exclude-addon',
|
||||
enforce: 'pre',
|
||||
resolveId(source) {
|
||||
if (source.includes('*')) return null
|
||||
const norm = source.replace(/\\?vue.*$/, '').replace(/\\/g, '/')
|
||||
if (norm.startsWith('@/addon/') || norm.includes('/src/addon/')) {
|
||||
return { id: 'virtual:addon-empty', moduleSideEffects: false }
|
||||
}
|
||||
return null
|
||||
},
|
||||
load(id) {
|
||||
if (id === 'virtual:addon-empty') return 'export default {}'
|
||||
return null
|
||||
}
|
||||
}
|
||||
]
|
||||
: [],
|
||||
build: {
|
||||
outDir: 'dist/.shared',
|
||||
emptyOutDir,
|
||||
lib: {
|
||||
entry,
|
||||
formats: ['es'],
|
||||
fileName: () => `${outName}.js`
|
||||
},
|
||||
rollupOptions: {
|
||||
external: sharedExternalForBuild(pkgKey)
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -1020,20 +1020,6 @@ return [
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'menu_name' => '云编译',
|
||||
'menu_key' => 'cloud_compile',
|
||||
'menu_short_name' => '云编译',
|
||||
'menu_type' => '1',
|
||||
'icon' => 'iconfont iconyunbianyi',
|
||||
'api_url' => '',
|
||||
'router_path' => 'tools/cloud_compile',
|
||||
'view_path' => 'tools/cloud_compile',
|
||||
'methods' => 'post',
|
||||
'sort' => '0',
|
||||
'status' => '1',
|
||||
'is_show' => '1',
|
||||
],
|
||||
[
|
||||
'menu_name' => '应用开发',
|
||||
'menu_key' => 'tool',
|
||||
@ -1659,6 +1645,20 @@ return [
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'menu_name' => '云编译',
|
||||
'menu_key' => 'cloud_compile',
|
||||
'menu_short_name' => '云编译',
|
||||
'menu_type' => '1',
|
||||
'icon' => 'iconfont iconyunbianyi',
|
||||
'api_url' => '',
|
||||
'router_path' => 'tools/cloud_compile',
|
||||
'view_path' => 'tools/cloud_compile',
|
||||
'methods' => 'post',
|
||||
'sort' => '98',
|
||||
'status' => '1',
|
||||
'is_show' => '1',
|
||||
],
|
||||
[
|
||||
'menu_name' => '授权信息',
|
||||
'menu_key' => 'app_auth',
|
||||
@ -1669,7 +1669,7 @@ return [
|
||||
'router_path' => 'tools/authorize',
|
||||
'view_path' => 'app/authorize',
|
||||
'methods' => '',
|
||||
'sort' => '98',
|
||||
'sort' => '97',
|
||||
'status' => '1',
|
||||
'is_show' => '1',
|
||||
'children' => [
|
||||
|
||||
@ -66,10 +66,9 @@ class UpgradeService extends BaseAdminService
|
||||
'backupSql' => [ 'step' => 'backupSql', 'title' => '' ],
|
||||
'coverCode' => [ 'step' => 'coverCode', 'title' => '合并更新文件' ],
|
||||
'handleUniapp' => [ 'step' => 'handleUniapp', 'title' => '处理uniapp' ],
|
||||
'installDepend' => ['step' => 'installDepend', 'title' => '合并依赖'],
|
||||
'refreshMenu' => [ 'step' => 'refreshMenu', 'title' => '刷新菜单' ],
|
||||
'installSchedule' => [ 'step' => 'installSchedule', 'title' => '安装计划任务' ],
|
||||
'cloudBuild' => [ 'step' => 'cloudBuild', 'title' => '开始云编译' ],
|
||||
'gteCloudBuildLog' => [ 'step' => 'gteCloudBuildLog', 'title' => '' ],
|
||||
'upgradeComplete' => [ 'step' => 'upgradeComplete', 'title' => '升级完成' ]
|
||||
];
|
||||
|
||||
@ -211,21 +210,6 @@ class UpgradeService extends BaseAdminService
|
||||
$upgrade[ 'app_key' ] = $upgrade_content['content'][0]['app']['app_key'];
|
||||
$upgrade[ 'version' ] = $upgrade_content['content'][0]['version'];
|
||||
|
||||
// if (!$addon) {
|
||||
// $upgrade[ 'app_key' ] = AddonDict::FRAMEWORK_KEY;
|
||||
// $upgrade[ 'version' ] = config('version.version');
|
||||
// } else {
|
||||
// $upgrade[ 'app_key' ] = $addon;
|
||||
// $upgrade[ 'version' ] = ( new Addon() )->where([ [ 'key', '=', $addon ] ])->value('version');
|
||||
// $upgrade_title = ( new Addon() )->where([ [ 'key', '=', $addon ] ])->value('title');
|
||||
//
|
||||
// // 判断框架版本是否低于插件支持版本
|
||||
// $last_version = $upgrade_content[ 'version_list' ][ count($upgrade_content[ 'version_list' ]) - 1 ];
|
||||
// if (str_replace('.', '', config('version.version')) < str_replace('.', '', $last_version[ 'niucloud_version' ][ 'version_no' ])) {
|
||||
// throw new CommonException('BEFORE_UPGRADING_NEED_UPGRADE_FRAMEWORK');
|
||||
// }
|
||||
// }
|
||||
|
||||
$response = ( new CoreAddonCloudService() )->upgradeAddon($upgrade);
|
||||
if (isset($response[ 'code' ]) && $response[ 'code' ] == 0) throw new CommonException($response[ 'msg' ]);
|
||||
|
||||
@ -243,16 +227,6 @@ class UpgradeService extends BaseAdminService
|
||||
unset($this->steps['backupSql']);
|
||||
}
|
||||
|
||||
// 是否需要云编译
|
||||
$is_need_cloudbuild = $data['is_need_cloudbuild'] ?? true;
|
||||
if (!$is_need_cloudbuild) {
|
||||
unset($this->steps['cloudBuild']);
|
||||
unset($this->steps['gteCloudBuildLog']);
|
||||
} else {
|
||||
// 校验云编译服务
|
||||
(new CloudService())->checkLocal();
|
||||
}
|
||||
|
||||
try {
|
||||
$upgrade_task = [
|
||||
'key' => $key,
|
||||
@ -464,14 +438,12 @@ class UpgradeService extends BaseAdminService
|
||||
@unlink($to_dir . $file);
|
||||
}
|
||||
}
|
||||
// 合并依赖
|
||||
$this->installDepend($code_dir . $version_no, array_column($change, 2));
|
||||
}
|
||||
|
||||
// 覆盖文件
|
||||
if (is_dir($code_dir . $version_no)) {
|
||||
// 忽略环境变量文件
|
||||
$exclude_files = [ '.env.development', '.env.production', '.env', '.env.dev', '.env.product', 'favicon.ico', 'niucloud.ico' ];
|
||||
$exclude_files = [ '.env.development', '.env.production', '.env', '.env.dev', '.env.product', 'favicon.ico', 'niucloud.ico', 'index.json' ];
|
||||
dir_copy($code_dir . $version_no, $to_dir, exclude_files: $exclude_files);
|
||||
if ($addon != AddonDict::FRAMEWORK_KEY) {
|
||||
( new CoreAddonInstallService($addon) )->installDir();
|
||||
@ -514,58 +486,54 @@ class UpgradeService extends BaseAdminService
|
||||
* @param string $version_no
|
||||
* @return void
|
||||
*/
|
||||
public function installDepend(string $dir, array $change_files)
|
||||
public function installDepend()
|
||||
{
|
||||
$addon = $this->upgrade_task[ 'upgrade' ][ 'app_key' ];
|
||||
$depend_service = new CoreDependService();
|
||||
$addon_list = ( new CoreAddonService() )->getInstallAddonList();
|
||||
|
||||
if ($addon == AddonDict::FRAMEWORK_KEY) {
|
||||
$composer = '/niucloud/composer.json';
|
||||
$admin_package = '/admin/package.json';
|
||||
$web_package = '/web/package.json';
|
||||
$uniapp_package = '/uni-app/package.json';
|
||||
} else {
|
||||
$composer = "/niucloud/addon/{$addon}/package/composer.json";
|
||||
$admin_package = "/niucloud/addon/{$addon}/package/admin-package.json";
|
||||
$web_package = "/niucloud/addon/{$addon}/package/web-package.json";
|
||||
$uniapp_package = "/niucloud/addon/{$addon}/package/uni-app-package.json";
|
||||
}
|
||||
$composer = 'niucloud'. DIRECTORY_SEPARATOR .'composer.json';
|
||||
$admin_package = 'admin'. DIRECTORY_SEPARATOR .'package.json';
|
||||
$web_package = 'web'. DIRECTORY_SEPARATOR .'package.json';
|
||||
$uniapp_package = 'uni-app'. DIRECTORY_SEPARATOR .'package.json';
|
||||
|
||||
if (in_array($composer, $change_files)) {
|
||||
$original = $depend_service->getComposerContent();
|
||||
$new = $depend_service->jsonFileToArray($dir . $composer);
|
||||
foreach ($new as $name => $value) {
|
||||
$original[ $name ] = isset($original[ $name ]) && is_array($original[ $name ]) ? array_map('unserialize', array_unique(array_map('serialize', array_merge($original[ $name ], $new[ $name ])))) : $new[ $name ];
|
||||
$composer_original = $depend_service->getComposerContent();
|
||||
$admin_original = $depend_service->getNpmContent('admin');
|
||||
$web_original = $depend_service->getNpmContent('web');
|
||||
$uni_app_original = $depend_service->getNpmContent('uni-app');
|
||||
|
||||
foreach ($addon_list as $addon => $item) {
|
||||
$new = $depend_service->jsonFileToArray($this->geAddonPackagePath($addon) . 'composer.json');
|
||||
if (!empty($new)) {
|
||||
foreach ($new as $name => $value) {
|
||||
$composer_original[ $name ] = isset($composer_original[ $name ]) && is_array($composer_original[ $name ]) ? array_map('unserialize', array_unique(array_map('serialize', array_merge($composer_original[ $name ], $new[ $name ])))) : $new[ $name ];
|
||||
}
|
||||
}
|
||||
$depend_service->writeArrayToJsonFile($original, $dir . $composer);
|
||||
}
|
||||
if (in_array($admin_package, $change_files)) {
|
||||
$original = $depend_service->getNpmContent('admin');
|
||||
$new = $depend_service->jsonFileToArray($dir . $admin_package);
|
||||
|
||||
foreach ($new as $name => $value) {
|
||||
$original[ $name ] = isset($original[ $name ]) && is_array($original[ $name ]) ? array_merge($original[ $name ], $new[ $name ]) : $new[ $name ];
|
||||
$new = $depend_service->jsonFileToArray($this->geAddonPackagePath($addon) . 'admin-package.json');
|
||||
if (!empty($new)) {
|
||||
foreach ($new as $name => $value) {
|
||||
$admin_original[ $name ] = isset($admin_original[ $name ]) && is_array($admin_original[ $name ]) ? array_merge($admin_original[ $name ], $new[ $name ]) : $new[ $name ];
|
||||
}
|
||||
}
|
||||
$depend_service->writeArrayToJsonFile($original, $dir . $admin_package);
|
||||
}
|
||||
if (in_array($web_package, $change_files)) {
|
||||
$original = $depend_service->getNpmContent('web');
|
||||
$new = $depend_service->jsonFileToArray($dir . $web_package);
|
||||
|
||||
foreach ($new as $name => $value) {
|
||||
$original[ $name ] = isset($original[ $name ]) && is_array($original[ $name ]) ? array_merge($original[ $name ], $new[ $name ]) : $new[ $name ];
|
||||
$new = $depend_service->jsonFileToArray($this->geAddonPackagePath($addon) . 'web-package.json');
|
||||
if (!empty($new)) {
|
||||
foreach ($new as $name => $value) {
|
||||
$web_original[ $name ] = isset($web_original[ $name ]) && is_array($web_original[ $name ]) ? array_merge($web_original[ $name ], $new[ $name ]) : $new[ $name ];
|
||||
}
|
||||
}
|
||||
$depend_service->writeArrayToJsonFile($original, $dir . $web_package);
|
||||
}
|
||||
if (in_array($uniapp_package, $change_files)) {
|
||||
$original = $depend_service->getNpmContent('uni-app');
|
||||
$new = $depend_service->jsonFileToArray($dir . $uniapp_package);
|
||||
|
||||
foreach ($new as $name => $value) {
|
||||
$original[ $name ] = isset($original[ $name ]) && is_array($original[ $name ]) ? array_merge($original[ $name ], $new[ $name ]) : $new[ $name ];
|
||||
$new = $depend_service->jsonFileToArray($this->geAddonPackagePath($addon) . 'uni-app-package.json');
|
||||
if (!empty($new)) {
|
||||
foreach ($new as $name => $value) {
|
||||
$uni_app_original[ $name ] = isset($uni_app_original[ $name ]) && is_array($uni_app_original[ $name ]) ? array_merge($uni_app_original[ $name ], $new[ $name ]) : $new[ $name ];
|
||||
}
|
||||
}
|
||||
$depend_service->writeArrayToJsonFile($original, $dir . $uniapp_package);
|
||||
}
|
||||
$depend_service->writeArrayToJsonFile($composer_original, $this->root_path . $composer);
|
||||
$depend_service->writeArrayToJsonFile($admin_original, $this->root_path . $admin_package);
|
||||
$depend_service->writeArrayToJsonFile($web_original, $this->root_path . $web_package);
|
||||
$depend_service->writeArrayToJsonFile($uni_app_original, $this->root_path . $uniapp_package);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -581,36 +549,17 @@ class UpgradeService extends BaseAdminService
|
||||
dir_copy($code_dir . 'uni-app', $this->root_path . 'uni-app', exclude_files: $exclude_files);
|
||||
|
||||
$addon_list = ( new CoreAddonService() )->getInstallAddonList();
|
||||
$depend_service = new CoreDependService();
|
||||
|
||||
if (!empty($addon_list)) {
|
||||
|
||||
foreach ($addon_list as $addon => $item) {
|
||||
$this->addon = $addon;
|
||||
|
||||
// 编译 diy-group 自定义组件代码文件
|
||||
$this->compileDiyComponentsCode($this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $addon);
|
||||
|
||||
// 编译 pages.json 页面路由代码文件
|
||||
$this->installPageCode($this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR);
|
||||
|
||||
// 编译 加载插件标题语言包
|
||||
$this->compileLocale($this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $addon);
|
||||
|
||||
// 合并插件依赖
|
||||
$addon_uniapp_package = str_replace('/', DIRECTORY_SEPARATOR, project_path() . "niucloud/addon/{$addon}/package/uni-app-package.json");
|
||||
|
||||
if (file_exists($addon_uniapp_package)) {
|
||||
$original = $depend_service->getNpmContent('uni-app');
|
||||
$new = $depend_service->jsonFileToArray($addon_uniapp_package);
|
||||
|
||||
foreach ($new as $name => $value) {
|
||||
$original[ $name ] = isset($original[ $name ]) && is_array($original[ $name ]) ? array_merge($original[ $name ], $new[ $name ]) : $new[ $name ];
|
||||
}
|
||||
|
||||
$uniapp_package = $this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'package.json';
|
||||
$depend_service->writeArrayToJsonFile($original, $uniapp_package);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@ use app\dict\sys\MenuDict;
|
||||
use app\model\sys\SysMenu;
|
||||
use core\base\BaseCoreService;
|
||||
use core\exception\AddonException;
|
||||
use core\exception\CommonException;
|
||||
|
||||
/**
|
||||
* 插件开发服务层
|
||||
@ -48,6 +49,9 @@ class CoreAddonDevelopBuildService extends BaseCoreService
|
||||
|
||||
$this->admin();
|
||||
$this->uniapp();
|
||||
$this->adminDist();
|
||||
$this->wapDist();
|
||||
$this->mpWeixinDist();
|
||||
$this->buildUniappPagesJson();
|
||||
$this->buildUniappLangJson();
|
||||
$this->web();
|
||||
@ -199,6 +203,17 @@ class CoreAddonDevelopBuildService extends BaseCoreService
|
||||
return true;
|
||||
}
|
||||
|
||||
public function adminDist() {
|
||||
$admin_path = str_replace('/', DIRECTORY_SEPARATOR, $this->root_path . 'admin/dist/assets/addons/' . $this->addon . '/');
|
||||
if (!is_dir($admin_path) || !is_readable($admin_path)) throw new CommonException("请先在admin目录下执行 npm run build:addon {$this->addon}命令编译插件admin端");
|
||||
|
||||
if (count(scandir($admin_path)) === 2) throw new CommonException("请先在admin目录下执行 npm run build:addon {$this->addon}命令编译插件admin端");
|
||||
|
||||
$addon_admin_path = $this->addon_path . 'dist' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR;
|
||||
if (is_dir($addon_admin_path)) del_target_dir($addon_admin_path, true);
|
||||
dir_copy($admin_path, $addon_admin_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* wap打包
|
||||
* @return true
|
||||
@ -215,6 +230,34 @@ class CoreAddonDevelopBuildService extends BaseCoreService
|
||||
return true;
|
||||
}
|
||||
|
||||
public function wapDist() {
|
||||
$uniapp_path = $this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'addon' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR;
|
||||
if (!is_dir($uniapp_path)) return true;
|
||||
|
||||
$uniapp_path = str_replace('/', DIRECTORY_SEPARATOR, $this->root_path . 'uni-app/dist/build/h5/assets/addons/' . $this->addon . '/');
|
||||
if (!is_dir($uniapp_path) || !is_readable($uniapp_path)) throw new CommonException("请先在uni-app目录下执行 npm run build:h5:addon {$this->addon}命令编译插件wap端");
|
||||
|
||||
if (count(scandir($uniapp_path)) === 2) throw new CommonException("请先在uni-app目录下执行 npm run build:h5:addon {$this->addon}命令编译插件wap端");
|
||||
|
||||
$addon_uniapp_path = $this->addon_path . 'dist' . DIRECTORY_SEPARATOR . 'wap' . DIRECTORY_SEPARATOR;
|
||||
if (is_dir($addon_uniapp_path)) del_target_dir($addon_uniapp_path, true);
|
||||
dir_copy($uniapp_path, $addon_uniapp_path);
|
||||
}
|
||||
|
||||
public function mpWeixinDist() {
|
||||
$uniapp_path = $this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'addon' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR;
|
||||
if (!is_dir($uniapp_path)) return true;
|
||||
|
||||
$uniapp_path = str_replace('/', DIRECTORY_SEPARATOR, $this->root_path . 'uni-app/dist/mp-weixin-addons/' . $this->addon . '/');
|
||||
if (!is_dir($uniapp_path) || !is_readable($uniapp_path)) throw new CommonException("请先在uni-app目录下执行 npm run build:mp-weixin:addon {$this->addon}命令编译插件微信小程序");
|
||||
|
||||
if (count(scandir($uniapp_path)) === 2) throw new CommonException("请先在uni-app目录下执行 npm run build:mp-weixin:addon {$this->addon}命令编译插件微信小程序");
|
||||
|
||||
$addon_uniapp_path = $this->addon_path . 'dist' . DIRECTORY_SEPARATOR . 'mp-weixin' . DIRECTORY_SEPARATOR;
|
||||
if (is_dir($addon_uniapp_path)) del_target_dir($addon_uniapp_path, true);
|
||||
dir_copy($uniapp_path, $addon_uniapp_path);
|
||||
}
|
||||
|
||||
public function buildUniappPagesJson() {
|
||||
$pages_json = file_get_contents($this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'pages.json');
|
||||
$code_begin = strtoupper($this->addon) . '_PAGE_BEGIN' . PHP_EOL;
|
||||
|
||||
@ -226,16 +226,6 @@ class CoreAddonInstallService extends CoreAddonBaseService
|
||||
$this->backupFrontend();
|
||||
|
||||
$tips = [];
|
||||
if ($mode != 'cloud') {
|
||||
$tips[] = get_lang('dict_addon.install_after_update');
|
||||
} else {
|
||||
try {
|
||||
(new CloudService())->checkLocal();
|
||||
} catch (\Exception $e) {
|
||||
Cache::set('install_task', null);
|
||||
throw new CommonException($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->addon_list as $addon) {
|
||||
$this->install_task['addon'] = $addon;
|
||||
@ -287,6 +277,8 @@ class CoreAddonInstallService extends CoreAddonBaseService
|
||||
}
|
||||
|
||||
$this->installWap();
|
||||
$this->rebuildPublicAdminAddonIndexJson();
|
||||
$this->rebuildPublicWapAddonIndexJson();
|
||||
|
||||
if ($mode == 'cloud') {
|
||||
$this->install_task['tips'] = $tips;
|
||||
@ -343,15 +335,19 @@ class CoreAddonInstallService extends CoreAddonBaseService
|
||||
$from_web_dir = $this->install_addon_path . 'web' . DIRECTORY_SEPARATOR;
|
||||
$from_wap_dir = $this->install_addon_path . 'uni-app' . DIRECTORY_SEPARATOR;
|
||||
$from_resource_dir = $this->install_addon_path . 'resource' . DIRECTORY_SEPARATOR;
|
||||
$from_wap_dist_dir = $this->install_addon_path . 'dist' . DIRECTORY_SEPARATOR . 'wap' . DIRECTORY_SEPARATOR;
|
||||
$from_admin_dist_dir = $this->install_addon_path . 'dist' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR;
|
||||
|
||||
// 放入的文件
|
||||
$to_admin_dir = $this->root_path . 'admin' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'addon' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR;
|
||||
$to_web_dir = $this->root_path . 'web' . DIRECTORY_SEPARATOR . 'addon' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR;
|
||||
$to_wap_dir = $this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'addon' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR;
|
||||
$to_resource_dir = public_path() . 'addon' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR;
|
||||
$to_wap_dist_dir = public_path() . 'wap' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR;
|
||||
$to_admin_dist_dir = public_path() . 'admin' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR;
|
||||
|
||||
// 安装admin管理端
|
||||
if (file_exists($from_admin_dir)) {
|
||||
if (is_dir($from_admin_dir)) {
|
||||
dir_copy($from_admin_dir, $to_admin_dir, $this->files['admin'], exclude_dirs:['icon']);
|
||||
// 判断图标目录是否存在
|
||||
if (is_dir($from_admin_dir . 'icon')) {
|
||||
@ -363,7 +359,7 @@ class CoreAddonInstallService extends CoreAddonBaseService
|
||||
}
|
||||
|
||||
// 安装电脑端
|
||||
if (file_exists($from_web_dir)) {
|
||||
if (is_dir($from_web_dir)) {
|
||||
// 安装布局文件
|
||||
$layout = $from_web_dir . 'layouts';
|
||||
if (is_dir($layout)) {
|
||||
@ -374,15 +370,23 @@ class CoreAddonInstallService extends CoreAddonBaseService
|
||||
}
|
||||
|
||||
// 安装手机端
|
||||
if (file_exists($from_wap_dir)) {
|
||||
if (is_dir($from_wap_dir)) {
|
||||
dir_copy($from_wap_dir, $to_wap_dir, $this->files['wap']);
|
||||
}
|
||||
|
||||
//安装资源文件
|
||||
if (file_exists($from_resource_dir)) {
|
||||
if (is_dir($from_resource_dir)) {
|
||||
dir_copy($from_resource_dir, $to_resource_dir, $this->files['resource']);
|
||||
}
|
||||
|
||||
if (is_dir($from_admin_dist_dir)) {
|
||||
dir_copy($from_admin_dist_dir, $to_admin_dist_dir);
|
||||
}
|
||||
|
||||
if (is_dir($from_wap_dist_dir)) {
|
||||
dir_copy($from_wap_dist_dir, $to_wap_dist_dir);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -681,6 +685,8 @@ class CoreAddonInstallService extends CoreAddonBaseService
|
||||
$to_web_layouts = $this->root_path . 'web' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR;
|
||||
$to_wap_dir = $this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'addon' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR;
|
||||
$to_resource_dir = public_path() . 'addon' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR;
|
||||
$to_wap_dist_dir = public_path() . 'wap' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'addons' . $this->addon . DIRECTORY_SEPARATOR;
|
||||
$to_admin_dist_dir = public_path() . 'admin' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'addons' . $this->addon . DIRECTORY_SEPARATOR;
|
||||
|
||||
// 卸载admin管理端
|
||||
if (is_dir($to_admin_dir)) del_target_dir($to_admin_dir, true);
|
||||
@ -701,6 +707,9 @@ class CoreAddonInstallService extends CoreAddonBaseService
|
||||
//删除资源文件
|
||||
if (is_dir($to_resource_dir)) del_target_dir($to_resource_dir, true);
|
||||
|
||||
if (is_dir($to_wap_dist_dir)) del_target_dir($to_wap_dist_dir, true);
|
||||
if (is_dir($to_admin_dist_dir)) del_target_dir($to_admin_dist_dir, true);
|
||||
|
||||
//todo 卸载插件目录涉及到的空文件
|
||||
return true;
|
||||
}
|
||||
@ -734,9 +743,6 @@ class CoreAddonInstallService extends CoreAddonBaseService
|
||||
*/
|
||||
public function uninstallWap()
|
||||
{
|
||||
// 编译 diy-group 自定义组件代码文件
|
||||
$this->compileDiyComponentsCode($this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $this->addon);
|
||||
|
||||
// 编译 pages.json 页面路由代码文件
|
||||
$this->uninstallPageCode($this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR);
|
||||
|
||||
@ -762,16 +768,65 @@ class CoreAddonInstallService extends CoreAddonBaseService
|
||||
*/
|
||||
public function installWap()
|
||||
{
|
||||
|
||||
// 编译 diy-group 自定义组件代码文件
|
||||
$this->compileDiyComponentsCode($this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $this->addon_list);
|
||||
|
||||
// 编译 pages.json 页面路由代码文件
|
||||
$this->installPageCode($this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $this->addon_list);
|
||||
|
||||
// 编译 加载插件标题语言包
|
||||
$this->compileLocale($this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $this->addon_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新构建 public/admin/assets/addons/index.json
|
||||
* 读取 addons 目录下的所有插件子目录,重新配置 keys
|
||||
* @return true
|
||||
*/
|
||||
public function rebuildPublicAdminAddonIndexJson() {
|
||||
$addons_dir = public_path() . 'admin' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'addons';
|
||||
$index_file = $addons_dir . DIRECTORY_SEPARATOR . 'index.json';
|
||||
|
||||
// 读取已有的 index.json,保留 sharedVersion 等字段
|
||||
$index_data = $this->jsonFileToArray($index_file);
|
||||
|
||||
// 扫描 addons 目录下的所有子目录作为插件 keys
|
||||
$keys = [];
|
||||
if (is_dir($addons_dir)) {
|
||||
$keys = get_files_by_dir($addons_dir);
|
||||
}
|
||||
|
||||
// 更新 keys
|
||||
$index_data['keys'] = $keys;
|
||||
|
||||
// 写入文件
|
||||
$this->writeArrayToJsonFile($index_data, $index_file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新构建 public/wap/assets/addons/index.json
|
||||
* 读取 addons 目录下的所有插件子目录,重新配置 keys
|
||||
* @return true
|
||||
*/
|
||||
public function rebuildPublicWapAddonIndexJson() {
|
||||
$addons_dir = public_path() . 'wap' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'addons';
|
||||
$index_file = $addons_dir . DIRECTORY_SEPARATOR . 'index.json';
|
||||
|
||||
// 读取已有的 index.json,保留 sharedVersion 等字段
|
||||
$index_data = $this->jsonFileToArray($index_file);
|
||||
|
||||
// 扫描 addons 目录下的所有子目录作为插件 keys
|
||||
$keys = [];
|
||||
if (is_dir($addons_dir)) {
|
||||
$keys = get_files_by_dir($addons_dir);
|
||||
}
|
||||
|
||||
// 更新 keys
|
||||
$index_data['keys'] = $keys;
|
||||
|
||||
// 写入文件
|
||||
$this->writeArrayToJsonFile($index_data, $index_file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function download()
|
||||
|
||||
@ -173,10 +173,7 @@ class CoreAppCloudService extends CoreCloudBaseService
|
||||
|
||||
$addon_dir = $dir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'addon' . DIRECTORY_SEPARATOR . $addon;
|
||||
if (is_dir($addon_dir)) del_target_dir($addon_dir, true);
|
||||
|
||||
// 编译 diy-group 自定义组件代码文件
|
||||
$this->compileDiyComponentsCode($dir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $addon);
|
||||
|
||||
|
||||
// 编译 加载插件标题语言包
|
||||
$this->compileLocale($dir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $addon);
|
||||
|
||||
|
||||
@ -112,7 +112,9 @@ class CoreTiandituMap extends BaseService
|
||||
if (is_string($res)) {
|
||||
$res = json_decode($res, true);
|
||||
}
|
||||
if ($res['status'] == 400) throw new CommonException($res['msg']);
|
||||
if (!isset($res['status'])) throw new CommonException($res['message'] ?? ($res['msg'] ?? '请求参数非法或不合规'));
|
||||
if ($res['status'] != 0) throw new CommonException($res['msg'] ?? '未解析到地址');
|
||||
if (!isset($res['result']) || empty($res['result'])) throw new CommonException($res['msg'] ?? '未解析到地址');
|
||||
|
||||
$t_result = $res['result'];
|
||||
$t_component = $t_result['addressComponent'] ?? [];
|
||||
|
||||
@ -152,8 +152,6 @@ class CoreCloudBuildService extends BaseCoreService
|
||||
if (!empty($exclude_addon)) {
|
||||
// 处理pages.json
|
||||
$this->handlePageCode($package_dir . 'uni-app' . DIRECTORY_SEPARATOR .'src' . DIRECTORY_SEPARATOR, $param['addon']);
|
||||
// 处理diy-group
|
||||
$this->compileDiyComponentsCode($package_dir . 'uni-app'. DIRECTORY_SEPARATOR .'src' . DIRECTORY_SEPARATOR, $exclude_addon[0]);
|
||||
}
|
||||
}
|
||||
// 拷贝admin端文件
|
||||
|
||||
@ -83,18 +83,11 @@ class CoreWeappCloudService extends CoreCloudBaseService
|
||||
// uni
|
||||
$uni_dir = $package_dir . 'uni-app';
|
||||
|
||||
// 如果不存在编译版小程序
|
||||
if ($compile_addon->isEmpty()) {
|
||||
dir_copy($this->root_path . 'uni-app', $uni_dir, exclude_dirs: [ 'node_modules', 'unpackage', 'dist', '.git']);
|
||||
$this->handleUniapp($uni_dir);
|
||||
// 替换env文件
|
||||
$this->weappEnvReplace($uni_dir . DIRECTORY_SEPARATOR . '.env.production');
|
||||
} else {
|
||||
$compile_dir = $this->addonPath($compile_addon->key) . 'compile' . DIRECTORY_SEPARATOR . 'weapp';
|
||||
if (!is_dir($compile_dir)) throw new CommonException('CLOUD_WEAPP_COMPILE_NOT_EXIST');
|
||||
dir_copy($compile_dir, $uni_dir);
|
||||
$this->weappCompileReplace($uni_dir);
|
||||
}
|
||||
dir_copy(public_path() . 'mp-weixin', $uni_dir);
|
||||
$this->handleUniapp($uni_dir);
|
||||
// 替换env文件
|
||||
$this->weappEnvReplace($uni_dir);
|
||||
|
||||
file_put_contents($package_dir . 'private.key', file_get_contents($this->config[ 'upload_private_key' ]));
|
||||
|
||||
// 将临时目录下文件生成压缩包
|
||||
@ -111,7 +104,7 @@ class CoreWeappCloudService extends CoreCloudBaseService
|
||||
'timestamp' => time(),
|
||||
'token' => $action_token[ 'data' ][ 'token' ] ?? ''
|
||||
];
|
||||
$response = ( new CloudService(true) )->httpPost('cloud/weapp?' . http_build_query($query), [
|
||||
$response = ( new CloudService(true) )->httpPost('cloud/weapp_v2?' . http_build_query($query), [
|
||||
'multipart' => [
|
||||
[
|
||||
'name' => 'file',
|
||||
@ -131,160 +124,45 @@ class CoreWeappCloudService extends CoreCloudBaseService
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理uniapp 查询出站点没有的插件进行移除
|
||||
* @param string $dir
|
||||
* @return void
|
||||
*/
|
||||
private function handleUniapp(string $dir)
|
||||
{
|
||||
$site_addon = $this->config[ 'addon' ];
|
||||
$local_addon = ( new Addon() )->where([ [ 'status', '=', AddonDict::ON ] ])->column('key');
|
||||
foreach ($site_addon as $addon) {
|
||||
$src = root_path() . 'addon' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR . 'dist' . DIRECTORY_SEPARATOR . 'mp-weixin' . DIRECTORY_SEPARATOR;
|
||||
if (!is_dir($src)) continue;
|
||||
|
||||
// 移除uniapp中该站点没有的插件
|
||||
$diff_addon = array_filter(array_map(function ($key) use ($site_addon) {
|
||||
if (!in_array($key, $site_addon)) return $key;
|
||||
}, $local_addon));
|
||||
|
||||
$this->handlePageCode($dir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $site_addon);
|
||||
|
||||
// $this->handleTabbar($dir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $site_addon);
|
||||
|
||||
if (!empty($diff_addon)) {
|
||||
foreach ($diff_addon as $addon) {
|
||||
$this->addon = $addon;
|
||||
|
||||
$addon_dir = $dir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'addon' . DIRECTORY_SEPARATOR . $addon;
|
||||
if (is_dir($addon_dir)) del_target_dir($addon_dir, true);
|
||||
|
||||
// 编译 diy-group 自定义组件代码文件
|
||||
$this->compileDiyComponentsCode($dir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $addon);
|
||||
|
||||
// 编译 加载插件标题语言包
|
||||
$this->compileLocale($dir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $addon);
|
||||
|
||||
$manifest_json = root_path() . 'addon' . DIRECTORY_SEPARATOR . $addon . DIRECTORY_SEPARATOR . 'package' . DIRECTORY_SEPARATOR . 'manifest.json';
|
||||
if (file_exists($manifest_json)) {
|
||||
$this->mergeManifestJson($dir . DIRECTORY_SEPARATOR, json_decode($manifest_json, true));
|
||||
}
|
||||
}
|
||||
dir_copy($src, $dir . DIRECTORY_SEPARATOR . 'mp-addons' . DIRECTORY_SEPARATOR . $addon);
|
||||
}
|
||||
}
|
||||
|
||||
private function handlePageCode($compile_path, $addon_arr)
|
||||
{
|
||||
$pages = [];
|
||||
foreach ($addon_arr as $addon) {
|
||||
if (!file_exists($this->geAddonPackagePath($addon) . 'uni-app-pages.php')) continue;
|
||||
$uniapp_pages = require $this->geAddonPackagePath($addon) . 'uni-app-pages.php';
|
||||
if (empty($uniapp_pages[ 'pages' ])) continue;
|
||||
|
||||
$page_begin = strtoupper($addon) . '_PAGE_BEGIN';
|
||||
$page_end = strtoupper($addon) . '_PAGE_END';
|
||||
|
||||
// 对0.2.0之前的版本做处理
|
||||
$uniapp_pages[ 'pages' ] = preg_replace_callback('/(.*)(\\r\\n.*\/\/ PAGE_END.*)/s', function ($match) {
|
||||
return $match[ 1 ] . ( substr($match[ 1 ], -1) == ',' ? '' : ',' ) . $match[ 2 ];
|
||||
}, $uniapp_pages[ 'pages' ]);
|
||||
|
||||
$uniapp_pages[ 'pages' ] = str_replace('PAGE_BEGIN', $page_begin, $uniapp_pages[ 'pages' ]);
|
||||
$uniapp_pages[ 'pages' ] = str_replace('PAGE_END', $page_end, $uniapp_pages[ 'pages' ]);
|
||||
$uniapp_pages[ 'pages' ] = str_replace('{{addon_name}}', $addon, $uniapp_pages[ 'pages' ]);
|
||||
|
||||
$pages[] = $uniapp_pages[ 'pages' ];
|
||||
}
|
||||
|
||||
$content = @file_get_contents($compile_path . "pages.json");
|
||||
$content = preg_replace_callback('/(.*\/\/ \{\{ PAGE_BEGAIN \}\})(.*)(\/\/ \{\{ PAGE_END \}\}.*)/s', function ($match) use ($pages) {
|
||||
return $match[ 1 ] . PHP_EOL . implode(PHP_EOL, $pages) . PHP_EOL . $match[ 3 ];
|
||||
}, $content);
|
||||
|
||||
// 找到页面路由文件 pages.json,写入内容
|
||||
return file_put_contents($compile_path . "pages.json", $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理底部导航【暂时停止调用,存在小程序兼容性问题】
|
||||
* @param $compile_path
|
||||
* @param $addon_arr
|
||||
* @return void
|
||||
*/
|
||||
public function handleTabbar($compile_path, $addon_arr = [])
|
||||
{
|
||||
$bottomList = array_column(( new DiyConfigService() )->getBottomList(), null, 'key');
|
||||
$tabbarList = [];
|
||||
if (empty($addon_arr)) {
|
||||
foreach ($bottomList as $app_item) {
|
||||
array_push($tabbarList, ...$app_item[ 'value' ][ 'list' ]);
|
||||
}
|
||||
} else {
|
||||
foreach ($addon_arr as $addon) {
|
||||
if (isset($bottomList[ $addon ])) {
|
||||
array_push($tabbarList, ...$bottomList[ $addon ][ 'value' ][ 'list' ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tabbarList = array_map(function ($item) {
|
||||
if (strpos($item[ 'link' ][ 'url' ], '?') !== false) {
|
||||
$item[ 'link' ][ 'url' ] = explode('?', $item[ 'link' ][ 'url' ])[0];
|
||||
}
|
||||
$link = array_filter(explode('/', $item[ 'link' ][ 'url' ]));
|
||||
$item[ 'link' ] = $item[ 'link' ][ 'url' ];
|
||||
$item[ 'component' ] = implode('-', $link);
|
||||
$item[ 'name' ] = lcfirst(implode('', array_map(function ($str) {
|
||||
return ucfirst($str);
|
||||
}, $link)));
|
||||
return $item;
|
||||
}, $tabbarList);
|
||||
$tabbarList = array_column($tabbarList, null, 'name');
|
||||
|
||||
if (isset($tabbarList[ 'appPagesIndexIndex' ])) unset($tabbarList[ 'appPagesIndexIndex' ]);
|
||||
if (isset($tabbarList[ 'appPagesMemberIndex' ])) unset($tabbarList[ 'appPagesMemberIndex' ]);
|
||||
|
||||
// 处理vue文件
|
||||
$tpl = str_replace('/', DIRECTORY_SEPARATOR, public_path() . 'static/tpl/tabbar.tpl');
|
||||
$content = view($tpl, [ 'tabbarList' => $tabbarList ])->getContent();
|
||||
file_put_contents(str_replace('/', DIRECTORY_SEPARATOR, $compile_path . 'app/pages/index/tabbar.vue'), $content);
|
||||
|
||||
// 处理tabbar.json
|
||||
file_put_contents($compile_path . 'tabbar.json', json_encode(array_column($tabbarList, 'link'), JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序上传env文件处理
|
||||
* @param string $env_file
|
||||
* config.js 格式: "use strict";exports.envConfig={VITE_APP_BASE_URL:"",...};
|
||||
* 使用正则替换配置项的值
|
||||
* @param string $dir
|
||||
* @return void
|
||||
*/
|
||||
private function weappEnvReplace(string $env_file)
|
||||
private function weappEnvReplace(string $dir)
|
||||
{
|
||||
$env_file = $dir . DIRECTORY_SEPARATOR . 'utils' . DIRECTORY_SEPARATOR . 'config.js';
|
||||
|
||||
$env = file_get_contents($env_file);
|
||||
$env = str_replace("VITE_APP_BASE_URL=''", "VITE_APP_BASE_URL='" . $this->config[ 'base_url' ] . 'api/' . "'", $env);
|
||||
$env = str_replace("VITE_IMG_DOMAIN=''", "VITE_IMG_DOMAIN='" . $this->config[ 'base_url' ] . "'", $env);
|
||||
$env = str_replace("VITE_SITE_ID = ''", "VITE_SITE_ID='" . $this->site_id . "'", $env);
|
||||
|
||||
// 替换 VITE_APP_BASE_URL
|
||||
$env = preg_replace('/VITE_APP_BASE_URL:"[^"]*"/', 'VITE_APP_BASE_URL:"' . $this->config['base_url'] . 'api/' . '"', $env);
|
||||
|
||||
// 替换 VITE_IMG_DOMAIN
|
||||
$env = preg_replace('/VITE_IMG_DOMAIN:"[^"]*"/', 'VITE_IMG_DOMAIN:"' . $this->config['base_url'] . '"', $env);
|
||||
|
||||
// 替换 VITE_SITE_ID
|
||||
$env = preg_replace('/VITE_SITE_ID:"[^"]*"/', 'VITE_SITE_ID:"' . $this->site_id . '"', $env);
|
||||
|
||||
file_put_contents($env_file, $env);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序上传vendor文件处理
|
||||
* @param string $vendor_file
|
||||
* @return void
|
||||
*/
|
||||
private function weappCompileReplace(string $path)
|
||||
{
|
||||
// 替换request.js
|
||||
$request_file = $path . DIRECTORY_SEPARATOR . 'utils' . DIRECTORY_SEPARATOR . 'request.js';
|
||||
$content = file_get_contents($request_file);
|
||||
$content = str_replace('{{$baseUrl}}', $this->config[ 'base_url' ] . 'api/', $content);
|
||||
$content = str_replace('{{$siteId}}', $this->site_id, $content);
|
||||
file_put_contents($request_file, $content);
|
||||
|
||||
// 替换common.js
|
||||
$common_file = $path . DIRECTORY_SEPARATOR . 'utils' . DIRECTORY_SEPARATOR . 'common.js';
|
||||
$content = file_get_contents($common_file);
|
||||
$content = str_replace('{{$imgUrl}}', $this->config[ 'base_url' ], $content);
|
||||
file_put_contents($common_file, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信小程序预览码
|
||||
* @return void
|
||||
|
||||
@ -9,6 +9,7 @@ return [
|
||||
'max_retries' => 1,// 重试次数,默认 1,指定当 http 请求失败时重试的次数。
|
||||
'retry_delay' => 1000,//重试延迟间隔(单位:ms),默认 500
|
||||
'timeout' => 5.0,//最大运行时间(超时)
|
||||
'connect_timeout' => 10,
|
||||
'verify' => false,//请求时验证SSL证书行为。设置成 true 启用SSL证书验证,默认使用操作系统提供的CA包。设置成 false 禁用证书验证(这是不安全的!)。设置成字符串启用验证,并使用该字符串作为自定义证书CA包的路径。
|
||||
],
|
||||
'response_type' => 'array',
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'version' => '1.2.4',
|
||||
'version' => '2.0.0',
|
||||
'code' => '202606060001'
|
||||
];
|
||||
|
||||
@ -1 +0,0 @@
|
||||
const s="Your account permissions are insufficient. Please contact the administrator to add permissions!",t={tips:s};export{t as default,s as tips};
|
||||
@ -1 +0,0 @@
|
||||
const t="您的账号权限不足,请联系管理员添加权限!",s={tips:t};export{s as default,t as tips};
|
||||
@ -1 +0,0 @@
|
||||
import{d as l,r as d,u as i,o as p,c as m,a as t,b as u,e as x,w as v,f,E as h,p as b,g as I,h as g,i as S,t as w}from"./index-8eead49b.js";/* empty css */import{_ as B}from"./error-54aee623.js";import{_ as k}from"./_plugin-vue_export-helper-c27b6911.js";const o=e=>(b("data-v-4f4088b5"),e=e(),I(),e),y={class:"error"},C={class:"flex items-center"},E=o(()=>t("div",null,[t("img",{class:"w-[240px]",src:B})],-1)),N={class:"text-left ml-[100px]"},V=o(()=>t("div",{class:"error-text text-[28px] font-bold"},"404错误!",-1)),R=o(()=>t("div",{class:"text-[#222] text-[20px] mt-[15px]"},"哎呀,出错了!您访问的页面不存在...",-1)),U=o(()=>t("div",{class:"text-[#c4c2c2] text-[12px] mt-[5px]"},"尝试检查URL的错误,然后点击浏览器刷新按钮。",-1)),$={class:"mt-[40px]"},D=l({__name:"404",setup(e){let s=null;const a=d(5),c=i();return s=setInterval(()=>{a.value===0?(clearInterval(s),c.go(-1)):a.value--},1e3),p(()=>{s&&clearInterval(s)}),(_,n)=>{const r=h;return g(),m("div",y,[t("div",C,[u(_.$slots,"content",{},()=>[E],!0),t("div",N,[V,R,U,t("div",$,[x(r,{class:"bottom",onClick:n[0]||(n[0]=L=>f(c).go(-1))},{default:v(()=>[S(w(a.value)+" 秒后返回上一页",1)]),_:1})])])])])}}});const A=k(D,[["__scopeId","data-v-4f4088b5"]]);export{A as default};
|
||||
1
niucloud/public/admin/assets/404-9842e605.js
Normal file
1
niucloud/public/admin/assets/404-9842e605.js
Normal file
@ -0,0 +1 @@
|
||||
import{ElButton as d}from"element-plus/es";import{defineComponent as i,ref as a,onUnmounted as p,openBlock as m,createElementBlock as u,createElementVNode as t,renderSlot as x,createVNode as f,unref as v,withCtx as h,createTextVNode as I,toDisplayString as b,pushScopeId as g,popScopeId as S}from"vue";import{_ as k}from"./error-54aee623.js";import{useRouter as w}from"vue-router";import{_ as y}from"./_plugin-vue_export-helper-c27b6911.js";const s=e=>(g("data-v-4f4088b5"),e=e(),S(),e),B={class:"error"},C={class:"flex items-center"},E=s(()=>t("div",null,[t("img",{class:"w-[240px]",src:k})],-1)),N={class:"text-left ml-[100px]"},V=s(()=>t("div",{class:"error-text text-[28px] font-bold"},"404错误!",-1)),R=s(()=>t("div",{class:"text-[#222] text-[20px] mt-[15px]"},"哎呀,出错了!您访问的页面不存在...",-1)),U=s(()=>t("div",{class:"text-[#c4c2c2] text-[12px] mt-[5px]"},"尝试检查URL的错误,然后点击浏览器刷新按钮。",-1)),$={class:"mt-[40px]"},D=i({__name:"404",setup(e){let o=null;const n=a(5),c=w();return o=setInterval(()=>{n.value===0?(clearInterval(o),c.go(-1)):n.value--},1e3),p(()=>{o&&clearInterval(o)}),(_,r)=>{const l=d;return m(),u("div",B,[t("div",C,[x(_.$slots,"content",{},()=>[E],!0),t("div",N,[V,R,U,t("div",$,[f(l,{class:"bottom",onClick:r[0]||(r[0]=L=>v(c).go(-1))},{default:h(()=>[I(b(n.value)+" 秒后返回上一页",1)]),_:1})])])])])}}});const F=y(D,[["__scopeId","data-v-4f4088b5"]]);export{F as default};
|
||||
@ -1 +0,0 @@
|
||||
import{dY as f}from"./index-8eead49b.js";export{f as default};
|
||||
1
niucloud/public/admin/assets/App-6cbb08c8.js
Normal file
1
niucloud/public/admin/assets/App-6cbb08c8.js
Normal file
@ -0,0 +1 @@
|
||||
import{bE as o}from"./index-3c23140f.js";import"vue";import"pinia";import"@element-plus/icons-vue";import"axios";import"/admin/assets/shared/admin-lang.js";import"vue-router";import"/admin/assets/shared/admin-lang.js";export{o as default};
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
niucloud/public/admin/assets/TencentMap-529d5e75.css
Normal file
1
niucloud/public/admin/assets/TencentMap-529d5e75.css
Normal file
@ -0,0 +1 @@
|
||||
.map[data-v-a9c9c03d]{height:400px}
|
||||
1
niucloud/public/admin/assets/TencentMap-d3dff4aa.js
Normal file
1
niucloud/public/admin/assets/TencentMap-d3dff4aa.js
Normal file
@ -0,0 +1 @@
|
||||
import{defineComponent as r,ref as p,onMounted as s,openBlock as d,createElementBlock as i}from"vue";import{_}from"./_plugin-vue_export-helper-c27b6911.js";const l=r({name:"MapComponent",setup(){const t=p(null),c=()=>new Promise((e,o)=>{const n=document.createElement("script");n.src="https://map.qq.com/api/js?v=2.exp&key=OUZBZ-O7AK5-Y57ID-QHLSW-OFQY7-EFFCO",n.async=!0,n.onload=()=>{e(window.TencentMap)},n.onerror=o,document.head.appendChild(n)}),a=async()=>{try{const e=await c();if(e&&t.value){const o=new e.Map(t.value,{center:[116.397428,39.90923],zoom:12})}}catch(e){console.error("Failed to load Tencent Map API:",e)}};return s(()=>{a()}),{mapContainer:t}}});const m={ref:"mapContainer",class:"map"};function u(t,c,a,e,o,n){return d(),i("div",m,null,512)}const v=_(l,[["render",u],["__scopeId","data-v-a9c9c03d"]]);export{v as default};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user