From 48a2dac7389a9751830a019a8c5a48b95bdfcec2 Mon Sep 17 00:00:00 2001
From: zhanghao <774378400@qq.com>
Date: Tue, 25 Aug 2026 14:03:36 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=BC=80=E5=8F=91?=
=?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=92=8C=E7=94=A8=E6=88=B7=E6=9F=A5=E8=AF=A2?=
=?UTF-8?q?=E8=A1=A8=E5=8D=95=E6=A0=B7=E5=BC=8F=EF=BC=8C=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E4=BE=9D=E8=B5=96=E9=93=BE=E6=8E=A5=E7=AE=A1=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 3 ++
scripts/link-consumers.mjs | 69 +++++++++++++++++++++++++
src/utils/jsencrypt.js | 2 +-
src/views/system/user/index.vue | 89 ++++++++++++++++++++++++++++++++-
4 files changed, 161 insertions(+), 2 deletions(-)
create mode 100644 scripts/link-consumers.mjs
diff --git a/package.json b/package.json
index dfb4ef1..7dbf187 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,10 @@
"README.md"
],
"scripts": {
+ "dev": "vite build --watch",
"build": "vite build",
+ "link:consumers": "node scripts/link-consumers.mjs",
+ "unlink:consumers": "node scripts/link-consumers.mjs --unlink",
"prepublishOnly": "pnpm build"
},
"publishConfig": {
diff --git a/scripts/link-consumers.mjs b/scripts/link-consumers.mjs
new file mode 100644
index 0000000..d71e5ab
--- /dev/null
+++ b/scripts/link-consumers.mjs
@@ -0,0 +1,69 @@
+import { lstatSync, mkdirSync, realpathSync, rmSync, symlinkSync, unlinkSync } from 'node:fs'
+import path from 'node:path'
+import { spawnSync } from 'node:child_process'
+import { fileURLToPath } from 'node:url'
+
+const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
+const consumers = [
+ path.resolve(packageRoot, '../cmvr-iot-ui'),
+ path.resolve(packageRoot, '../cmvr-iot-aima'),
+ path.resolve(packageRoot, '../changan-inspection')
+]
+const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm'
+const pnpmCommand = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm'
+const shouldUnlink = process.argv.includes('--unlink')
+
+function run(command, args, cwd) {
+ const executable = process.platform === 'win32' ? process.env.ComSpec : command
+ const commandArgs = process.platform === 'win32'
+ ? ['/d', '/s', '/c', [command, ...args].join(' ')]
+ : args
+ const env = { ...process.env }
+ delete env.npm_config_verify_deps_before_run
+
+ const result = spawnSync(executable, commandArgs, {
+ cwd,
+ stdio: 'inherit',
+ env
+ })
+ if (result.error) throw result.error
+ if (result.status !== 0) process.exit(result.status ?? 1)
+}
+
+function removePackageLink(linkedPackage) {
+ try {
+ const stats = lstatSync(linkedPackage)
+ if (stats.isSymbolicLink()) unlinkSync(linkedPackage)
+ else rmSync(linkedPackage, { recursive: true, force: true })
+ } catch (error) {
+ if (error.code !== 'ENOENT') throw error
+ }
+}
+
+if (shouldUnlink) {
+ for (const consumer of consumers) {
+ const linkedPackage = path.join(consumer, 'node_modules/@cmvr/iot-common')
+ removePackageLink(linkedPackage)
+ run(pnpmCommand, ['install', '--offline', '--frozen-lockfile'], consumer)
+ console.log(`[restored] ${path.basename(consumer)} -> published dependency`)
+ }
+ process.exit(0)
+}
+
+const linkOptions = [
+ '--ignore-scripts',
+ '--package-lock=false',
+ '--audit=false',
+ '--fund=false',
+ '--legacy-peer-deps'
+]
+
+run(npmCommand, ['link', ...linkOptions], packageRoot)
+
+for (const consumer of consumers) {
+ const linkedPackage = path.join(consumer, 'node_modules/@cmvr/iot-common')
+ removePackageLink(linkedPackage)
+ mkdirSync(path.dirname(linkedPackage), { recursive: true })
+ symlinkSync(packageRoot, linkedPackage, process.platform === 'win32' ? 'junction' : 'dir')
+ console.log(`[linked] ${path.basename(consumer)} -> ${realpathSync(linkedPackage)}`)
+}
diff --git a/src/utils/jsencrypt.js b/src/utils/jsencrypt.js
index 78d9523..91eeff6 100644
--- a/src/utils/jsencrypt.js
+++ b/src/utils/jsencrypt.js
@@ -1,4 +1,4 @@
-import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'
+import JSEncrypt from 'jsencrypt'
// 密钥对生成 http://web.chacuo.net/netrsakeypair
diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue
index 6528964..671b039 100644
--- a/src/views/system/user/index.vue
+++ b/src/views/system/user/index.vue
@@ -3,7 +3,7 @@