mali-applet-ui 1.0.71 → 1.0.72
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
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Mali-Applet-UI 码里云小程序组件库
|
|
4
4
|
|
|
5
|
+
## 组件开发规范
|
|
6
|
+
|
|
7
|
+
### 命名规范
|
|
8
|
+
|
|
9
|
+
组件命名以开头 ml-*,全小写,配合 [easycom](https://uniapp.dcloud.net.cn/component/#easycom%E7%BB%84%E4%BB%B6%E8%A7%84%E8%8C%83) 规则按需加载
|
|
10
|
+
例如,新增按钮组件:src/components/ml-button/ml-button.vue
|
|
11
|
+
如果是内部组件,使用大写开头驼峰命名
|
|
12
|
+
|
|
5
13
|
## 运行项目
|
|
6
14
|
|
|
7
15
|
```
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const findTreeKey = (list, props = { key: 'key', children: 'children' }) => {
|
|
2
|
+
let keys = []
|
|
3
|
+
const { key = 'key', children = 'children' } = props
|
|
4
|
+
for (let i = 0; i < list.length; i++) {
|
|
5
|
+
const item = list[i]
|
|
6
|
+
if (item[key]) {
|
|
7
|
+
keys.push(item[key])
|
|
8
|
+
}
|
|
9
|
+
if (item[children] && item[children].length) {
|
|
10
|
+
const findKeys = findTreeKey(item[children], props)
|
|
11
|
+
keys = [...keys, ...findKeys]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return keys
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 根据节点ID找到对应节点
|
|
18
|
+
export const findTreeByKey = (node, key, parent, props = { key: 'key', children: 'children' }) => {
|
|
19
|
+
const propsKey = props.key || 'key'
|
|
20
|
+
const propsChildren = props.children || 'children'
|
|
21
|
+
for (let i = 0; i < node.length; i++) {
|
|
22
|
+
const item = node[i]
|
|
23
|
+
if (item[propsKey] === key) {
|
|
24
|
+
return {
|
|
25
|
+
node: item,
|
|
26
|
+
parent: parent
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (item[propsChildren] && item[propsChildren].length) {
|
|
30
|
+
const children = item[propsChildren]
|
|
31
|
+
const findTree = findTreeByKey(children, key, item, props)
|
|
32
|
+
if (findTree) {
|
|
33
|
+
return findTree
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 根据节点ID找到对应节点
|
|
40
|
+
export const findNodesByKeys = (node, keys, props = { key: 'key', children: 'children' }) => {
|
|
41
|
+
const propsKey = props.key || 'key'
|
|
42
|
+
const propsChildren = props.children || 'children'
|
|
43
|
+
let list = []
|
|
44
|
+
for (let i = 0; i < node.length; i++) {
|
|
45
|
+
const item = node[i]
|
|
46
|
+
if (keys.indexOf(item[propsKey]) > -1) {
|
|
47
|
+
list.push(item)
|
|
48
|
+
}
|
|
49
|
+
if (item[propsChildren] && item[propsChildren].length) {
|
|
50
|
+
const children = item[propsChildren]
|
|
51
|
+
const findTree = findNodesByKeys(children, keys, props)
|
|
52
|
+
if (findTree && findTree.length) {
|
|
53
|
+
list = [...list, ...findTree]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return list
|
|
58
|
+
}
|