zkqh-lagrange-utils 0.0.58 → 0.0.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,74 +1,74 @@
1
- {
2
- "name": "zkqh-lagrange-utils",
3
- "private": false,
4
- "version": "0.0.58",
5
- "type": "module",
6
- "scripts": {
7
- "dev": "vite",
8
- "build": "vite build",
9
- "gen-style": "node ./scripts/generate-naiveui-common-style.mjs"
10
- },
11
- "main": "dist/lagrange-utils.umd.cjs",
12
- "module": "dist/lagrange-utils.js",
13
- "sideEffects": [
14
- "*.css"
15
- ],
16
- "exports": {
17
- ".": {
18
- "import": "./dist/lagrange-utils.js",
19
- "require": "./dist/lagrange-utils.umd.cjs"
20
- },
21
- "./export_plugin": {
22
- "import": "./src/service/export_plugin/index.js",
23
- "default": "./src/service/export_plugin/index.js"
24
- },
25
- "./export_plugin/api": {
26
- "import": "./src/service/export_plugin/api/index.js",
27
- "default": "./src/service/export_plugin/api/index.js"
28
- },
29
- "./style.css": {
30
- "default": "./dist/style.css"
31
- },
32
- "./assets/*": "./dist/assets/*",
33
- "./assets/css/*": "./dist/assets/css/*",
34
- "./assets/font/*": "./dist/assets/font/*",
35
- "./assets/image/*": "./dist/assets/image/*",
36
- "./postcss.config.js": {
37
- "import": "./postcss.config.js",
38
- "require": "./postcss.config.cjs",
39
- "default": "./postcss.config.js"
40
- }
41
- },
42
- "files": [
43
- "dist",
44
- "assets",
45
- "src/service",
46
- "postcss.config.js",
47
- "postcss.config.cjs"
48
- ],
49
- "dependencies": {
50
- "autoprefixer": "^10.4.22",
51
- "axios": "^1.18.1",
52
- "postcss-pxtorem": "^6.1.0",
53
- "vue": "^3.3.0"
54
- },
55
- "peerDependencies": {
56
- "naive-ui": "^2.40.0",
57
- "vue": "^3.3.0"
58
- },
59
- "peerDependenciesMeta": {
60
- "naive-ui": {
61
- "optional": true
62
- }
63
- },
64
- "devDependencies": {
65
- "@vitejs/plugin-vue": "^5.0.4",
66
- "@vitejs/plugin-vue-jsx": "^3.0.2",
67
- "less": "^4.4.2",
68
- "naive-ui": "2.43.1",
69
- "vite": "^5.4.10",
70
- "vite-plugin-static-copy": "^0.17.0"
71
- },
72
- "author": "zkqh-ddh",
73
- "license": "MIT"
74
- }
1
+ {
2
+ "name": "zkqh-lagrange-utils",
3
+ "private": false,
4
+ "version": "0.0.59",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "gen-style": "node ./scripts/generate-naiveui-common-style.mjs"
10
+ },
11
+ "main": "dist/lagrange-utils.umd.cjs",
12
+ "module": "dist/lagrange-utils.js",
13
+ "sideEffects": [
14
+ "*.css"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/lagrange-utils.js",
19
+ "require": "./dist/lagrange-utils.umd.cjs"
20
+ },
21
+ "./export_plugin": {
22
+ "import": "./src/service/export_plugin/index.js",
23
+ "default": "./src/service/export_plugin/index.js"
24
+ },
25
+ "./export_plugin/api": {
26
+ "import": "./src/service/export_plugin/api/index.js",
27
+ "default": "./src/service/export_plugin/api/index.js"
28
+ },
29
+ "./style.css": {
30
+ "default": "./dist/style.css"
31
+ },
32
+ "./assets/*": "./dist/assets/*",
33
+ "./assets/css/*": "./dist/assets/css/*",
34
+ "./assets/font/*": "./dist/assets/font/*",
35
+ "./assets/image/*": "./dist/assets/image/*",
36
+ "./postcss.config.js": {
37
+ "import": "./postcss.config.js",
38
+ "require": "./postcss.config.cjs",
39
+ "default": "./postcss.config.js"
40
+ }
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "assets",
45
+ "src/service",
46
+ "postcss.config.js",
47
+ "postcss.config.cjs"
48
+ ],
49
+ "dependencies": {
50
+ "autoprefixer": "^10.4.22",
51
+ "axios": "^1.18.1",
52
+ "postcss-pxtorem": "^6.1.0",
53
+ "vue": "^3.3.0"
54
+ },
55
+ "peerDependencies": {
56
+ "naive-ui": "^2.40.0",
57
+ "vue": "^3.3.0"
58
+ },
59
+ "peerDependenciesMeta": {
60
+ "naive-ui": {
61
+ "optional": true
62
+ }
63
+ },
64
+ "devDependencies": {
65
+ "@vitejs/plugin-vue": "^5.0.4",
66
+ "@vitejs/plugin-vue-jsx": "^3.0.2",
67
+ "less": "^4.4.2",
68
+ "naive-ui": "2.43.1",
69
+ "vite": "^5.4.10",
70
+ "vite-plugin-static-copy": "^0.17.0"
71
+ },
72
+ "author": "zkqh-ddh",
73
+ "license": "MIT"
74
+ }
@@ -86,17 +86,22 @@ export default defineComponent({
86
86
  return Math.min(100, (used / total) * 100)
87
87
  })
88
88
 
89
- const emitDiskInfo = () => {
89
+ const setDirname = (path) => {
90
+ emit("update:modelValue", path ? normalizeDir(path) : "")
91
+ }
92
+
93
+ /**
94
+ * 更新右侧占用;传空则清空
95
+ * @param {object | null} disk
96
+ */
97
+ const applyDisk = (disk) => {
98
+ defaultDisk.value = disk || {}
90
99
  emit("update:diskInfo", {
91
100
  total_size: defaultDisk.value?.total_size || 0,
92
101
  used_size: defaultDisk.value?.used_size || 0,
93
102
  })
94
103
  }
95
104
 
96
- const setDirname = (path) => {
97
- emit("update:modelValue", path)
98
- }
99
-
100
105
  /** 打开新建文件夹弹窗 */
101
106
  const openCreateFolder = (parentPath, e) => {
102
107
  e?.stopPropagation?.()
@@ -144,8 +149,8 @@ export default defineComponent({
144
149
  }
145
150
 
146
151
  /**
147
- * 按路径切分并行 listdir,再挂到树上,保证深层路径可回显
148
- * @param {string} targetPath 默认目录
152
+ * 按路径展开目录树,保证深层路径可回显
153
+ * @param {string} targetPath
149
154
  */
150
155
  const hydrateTreePath = async (targetPath) => {
151
156
  const targetKey = toTreeKey(targetPath)
@@ -223,20 +228,20 @@ export default defineComponent({
223
228
  await hydrateTreePath(newPath)
224
229
  }
225
230
 
226
- const loadDefault = async () => {
231
+ /**
232
+ * @returns {Promise<{ root: string, disk: object } | null>}
233
+ */
234
+ const fetchDefault = async () => {
227
235
  try {
228
236
  const res = await pluginApi.getDefaultDir()
229
237
  if (res.code === 200 && res.data) {
230
- defaultDisk.value = res.data
231
238
  const root = normalizeDir(res.data.root || "")
232
- setDirname(root)
233
- emitDiskInfo()
234
- return root
239
+ return root ? { root, disk: res.data } : null
235
240
  }
236
241
  } catch (e) {
237
242
  console.error(e)
238
243
  }
239
- return ""
244
+ return null
240
245
  }
241
246
 
242
247
  const loadDisks = async () => {
@@ -248,17 +253,46 @@ export default defineComponent({
248
253
  key: toTreeKey(disk.path) || disk.path,
249
254
  isLeaf: false,
250
255
  }))
256
+ return
251
257
  }
252
258
  } catch (e) {
253
- treeOptions.value = []
259
+ console.error(e)
254
260
  }
261
+ treeOptions.value = []
255
262
  }
256
263
 
264
+ /**
265
+ * 并行拉默认目录与磁盘列表;有默认目录则先反填,再展开树
266
+ */
257
267
  const initDirectory = async () => {
258
- await loadDisks()
259
- const root = await loadDefault()
260
- if (root) {
261
- await hydrateTreePath(root)
268
+ const [info] = await Promise.all([fetchDefault(), loadDisks()])
269
+ if (!info) {
270
+ setDirname("")
271
+ applyDisk(null)
272
+ return
273
+ }
274
+ setDirname(info.root)
275
+ applyDisk(info.disk)
276
+ await hydrateTreePath(info.root)
277
+ }
278
+
279
+ /**
280
+ * 写入默认目录并刷新占用;path 为空表示清空
281
+ * @param {string} path
282
+ */
283
+ const syncDefaultDir = async (path) => {
284
+ const next = path ? normalizeDir(path) : ""
285
+ setDirname(next)
286
+ try {
287
+ await pluginApi.setDefaultDir(next)
288
+ if (!next) {
289
+ applyDisk(null)
290
+ return
291
+ }
292
+ const info = await fetchDefault()
293
+ applyDisk(info?.disk || null)
294
+ } catch (e) {
295
+ console.error(e)
262
296
  }
263
297
  }
264
298
 
@@ -271,18 +305,7 @@ export default defineComponent({
271
305
  }
272
306
 
273
307
  const onDirChange = async (path) => {
274
- if (!path) {
275
- setDirname("")
276
- return
277
- }
278
- const next = normalizeDir(path)
279
- setDirname(next)
280
- try {
281
- await pluginApi.setDefaultDir(next)
282
- await loadDefault()
283
- } catch (e) {
284
- console.error(e)
285
- }
308
+ await syncDefaultDir(path || "")
286
309
  }
287
310
 
288
311
  /**
@@ -290,7 +313,7 @@ export default defineComponent({
290
313
  */
291
314
  const onFolderCreated = async ({ parentDir, newPath }) => {
292
315
  await refreshTreeAfterCreate(parentDir, newPath)
293
- await onDirChange(toTreeKey(newPath))
316
+ await syncDefaultDir(toTreeKey(newPath) || newPath)
294
317
  }
295
318
 
296
319
  initDirectory()
@@ -1,58 +1,58 @@
1
- /**
2
- * 默认读取平台登录 token
3
- * @returns {string}
4
- */
5
- export const getDefaultToken = () => {
6
- try {
7
- const token = localStorage.getItem("token")
8
- if (!token) return ""
9
- return JSON.parse(token)?.access_token || ""
10
- } catch {
11
- return ""
12
- }
13
- }
14
-
15
- /**
16
- * 默认平台根地址(当前页 origin,或 sys_con.baseURL)
17
- * @returns {string}
18
- */
19
- export const getDefaultUrl = () => {
20
- const base =
21
- (typeof window !== "undefined" && window.sys_con?.baseURL) ||
22
- `${location.protocol}//${location.host}`
23
- return String(base).replace(/\/$/, "")
24
- }
25
-
26
- /**
27
- * 默认插件安装包地址:当前域名端口 + /plugins/main.exe(对应前端 public/plugins/main.exe
28
- * @returns {string}
29
- */
30
- export const getDefaultDownloadUrl = () => {
31
- if (typeof window === "undefined" || !window.location) return "/plugins/main.exe"
32
- return `${window.location.origin}/plugins/main.exe`
33
- }
34
-
35
- /**
36
- * 默认校验:导出 args 需含完整时间范围
37
- * @param {Record<string, any>} args
38
- * @returns {boolean}
39
- */
40
- export const validateTimeRangeArgs = (args = {}) => {
41
- if (!(args.start_time && args.end_time)) {
42
- window.$message?.warning?.("请选择发生时间")
43
- return false
44
- }
45
- return true
46
- }
47
-
48
- /**
49
- * 生成导出默认名称:导出数据_<年><月><日>
50
- * @returns {string}
51
- */
52
- export const buildTaskName = () => {
53
- const d = new Date()
54
- const y = d.getFullYear()
55
- const m = String(d.getMonth() + 1).padStart(2, "0")
56
- const day = String(d.getDate()).padStart(2, "0")
57
- return `导出数据_${y}${m}${day}`
58
- }
1
+ /**
2
+ * 默认读取平台登录 token
3
+ * @returns {string}
4
+ */
5
+ export const getDefaultToken = () => {
6
+ try {
7
+ const token = localStorage.getItem("token")
8
+ if (!token) return ""
9
+ return JSON.parse(token)?.access_token || ""
10
+ } catch {
11
+ return ""
12
+ }
13
+ }
14
+
15
+ /**
16
+ * 默认平台根地址(当前页 origin,或 sys_con.baseURL)
17
+ * @returns {string}
18
+ */
19
+ export const getDefaultUrl = () => {
20
+ const base =
21
+ (typeof window !== "undefined" && window.sys_con?.baseURL) ||
22
+ `${location.protocol}//${location.host}`
23
+ return String(base).replace(/\/$/, "")
24
+ }
25
+
26
+ /**
27
+ * 默认插件安装包地址:当前域名端口 + /plugins.main.exe(由 nginx 代理到前端 dist
28
+ * @returns {string}
29
+ */
30
+ export const getDefaultDownloadUrl = () => {
31
+ if (typeof window === "undefined" || !window.location) return "/plugins/main.exe"
32
+ return `${window.location.origin}/plugins/main.exe`
33
+ }
34
+
35
+ /**
36
+ * 默认校验:导出 args 需含完整时间范围
37
+ * @param {Record<string, any>} args
38
+ * @returns {boolean}
39
+ */
40
+ export const validateTimeRangeArgs = (args = {}) => {
41
+ if (!(args.start_time && args.end_time)) {
42
+ window.$message?.warning?.("请选择发生时间")
43
+ return false
44
+ }
45
+ return true
46
+ }
47
+
48
+ /**
49
+ * 生成导出默认名称:导出数据_<年><月><日>
50
+ * @returns {string}
51
+ */
52
+ export const buildTaskName = () => {
53
+ const d = new Date()
54
+ const y = d.getFullYear()
55
+ const m = String(d.getMonth() + 1).padStart(2, "0")
56
+ const day = String(d.getDate()).padStart(2, "0")
57
+ return `导出数据_${y}${m}${day}`
58
+ }