smirk-ui 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -341,4 +341,60 @@ onMounted(() => {
341
341
 
342
342
  ### smx-file-viewer
343
343
 
344
- > 略略略...
344
+ > 略略略...
345
+ >
346
+
347
+ ### 【smirk-ui/kit】useDsCore
348
+
349
+ > 还是记录下吧。久了自己都不会用了 O(∩_∩)O~~
350
+ >
351
+ > 数据源管理(常用于大屏项目)。基于 pinia 实现(主要能够在 vue-devtools 中调试),采用发布订阅模式,使请求的触发和响应解耦。支持多个 request 聚合;支持设置轮询;支持响应结果预处理以及创建新的数据源等。
352
+ >
353
+ `Methods`
354
+ ```
355
+ deps() ——查看当前所有的依赖参数
356
+ initDeps(params) ——初始化依赖参数
357
+ updateDeps(params) ——更新依赖参数,关联的 request 会发起请求
358
+ provide(obj|arr) ——启动数据源引擎
359
+ send(reqOrName, opts) ——触发一个数据源任务,共享数据源维护的依赖参数,但不会被动执行,响应结果也不会放进数据池
360
+ listener(name, callback) ——监听数据源
361
+ stop(name) ——停止轮询
362
+ get(name) ——获取某数据源,一般搭配计算属性使用
363
+ set(name, data) ——手动新增或更新某数据源,可在 interceptor 中拦截,将一个 request 响应分别存储到多个数据源
364
+ reload() ——全部更新
365
+ ```
366
+ `示例:`
367
+ ```javascript
368
+ // apis 定义任务
369
+ const dsTasks = {
370
+ foo: {
371
+ interval: 10,
372
+ deps: ['id'],
373
+ request: p => fetch('/api/foo?id=' + p.id),
374
+ interceptor: (res, o) => {
375
+ // 响应结果预处理
376
+ // 增加数据源 o.set('name1', res.xx)
377
+ return res
378
+ }
379
+ }
380
+ }
381
+ // 组件中 实例化
382
+ import smkit from 'smirk-ui/kit'
383
+ const dsCore = smkit.useDsCore(/*可以传个字符串,以创建多个数据源管理*/)
384
+
385
+ // 启动所有任务
386
+ dsCore.provide(dsTasks)
387
+
388
+ // 更新依赖
389
+ dsCore.updateDeps({ id: 2 })
390
+
391
+ // 接收响应结果
392
+ const foo = computed(() => dsCore.get('foo') ?? {})
393
+ // 或
394
+ dsCore.listener('foo', res => {
395
+ console.log('foo:', res)
396
+ })
397
+ ```
398
+
399
+
400
+ >
package/dist/kit.es.js CHANGED
@@ -558,7 +558,7 @@ const trsListToTree = (list, idField = "id", parentIdField = "parentId") => {
558
558
  });
559
559
  return tree;
560
560
  };
561
- const getTreePathById = (tree, targetId, idField = "id", childrenField = "children") => {
561
+ const getTreePathById = (tree, targetId, idField = "id", removeChild = true, childrenField = "children") => {
562
562
  if (!Array.isArray(tree) || !targetId && targetId !== 0) return [];
563
563
  const findPath = (nodes, path = []) => {
564
564
  for (const node of nodes) {
@@ -587,6 +587,10 @@ const getTreePathById = (tree, targetId, idField = "id", childrenField = "childr
587
587
  } else {
588
588
  newNode[childrenField] = [];
589
589
  }
590
+ } else {
591
+ if (removeChild) {
592
+ delete newNode[childrenField];
593
+ }
590
594
  }
591
595
  newNodeList.push(newNode);
592
596
  return newNodeList;
@@ -622,7 +626,7 @@ const getTreeByLevel = (tree, maxLevel, childrenField = "children", topLevel = 0
622
626
  return tree.map((node) => {
623
627
  const newNode = { ...node };
624
628
  if (topLevel < maxLevel && newNode.children && Array.isArray(newNode.children)) {
625
- newNode.children = cropTreeByLevel(newNode.children, maxLevel, "children", topLevel + 1);
629
+ newNode.children = getTreeByLevel(newNode.children, maxLevel, "children", topLevel + 1);
626
630
  } else {
627
631
  delete newNode.children;
628
632
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "smirk-ui",
3
3
  "private": false,
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "license": "MIT",
6
6
  "author": "lukas <768157417@qq.com>",
7
7
  "description": "",