cbvirtua 1.0.68 → 1.0.69

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,6 +1,6 @@
1
1
  {
2
2
  "name": "cbvirtua",
3
- "version": "1.0.68",
3
+ "version": "1.0.69",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,77 @@
1
+ function remove(arr, item) {
2
+ if (arr.length) {
3
+ var index = arr.indexOf(item)
4
+ if (index > -1) {
5
+ return arr.splice(index, 1)
6
+ }
7
+ }
8
+ }
9
+
10
+ function getFirstComponentChild(children) {
11
+ if (Array.isArray(children)) {
12
+ for (var i = 0; i < children.length; i++) {
13
+ var c = children[i]
14
+ if (isDef(c) && (isDef(c.componentOptions) || isAsyncPlaceholder(c))) {
15
+ return c
16
+ }
17
+ }
18
+ }
19
+ }
20
+ function isDef(v) {
21
+ return v !== undefined && v !== null
22
+ }
23
+
24
+ function isAsyncPlaceholder(node) {
25
+ return node.isComment && node.asyncFactory
26
+ }
27
+ var patternTypes = [String, RegExp, Array]
28
+
29
+ export default {
30
+ name: 'keep-alive',
31
+ abstract: true,
32
+ computed: {
33
+ // 这里算是一个伪代码
34
+ // 缓存的数组 [{ 'tab1/组件名称':comp, 'tab2/组件名称':comp },{ 'tab1/组件名称':comp, 'tab2/组件名称':comp }]
35
+ cacheArray() {
36
+ return this.$store.state.xxx.groupCache
37
+ },
38
+ // 当前选中的分组 例:0/1/2... 这里用来读取cache数组的index
39
+ groupIndex() {
40
+ return this.$store.state.xxx.groupIndex
41
+ }
42
+ },
43
+
44
+ created: function created() {
45
+ // 当前tab的缓存
46
+ const cache = this.cacheArray[this.groupIndex]
47
+ this.cache = cache || Object.create(null)
48
+ // TODO 页面初始化事件,后续可触发初始化事件
49
+ },
50
+ destroyed: function destroyed(to, form) {
51
+ // TODO 页面离开事件,后续可触发关闭事件
52
+ },
53
+ render: function render() {
54
+ var slot = this.$slots.default
55
+ var vnode = getFirstComponentChild(slot)
56
+ var componentOptions = vnode && vnode.componentOptions
57
+ // check pattern
58
+ var ref$1 = this
59
+ var cache = ref$1.cache
60
+ const key = `${this.groupIndex}/${componentOptions.Ctor.options.name}`
61
+ // 存在key直接读取
62
+ if (cache[key]) {
63
+ vnode.componentInstance = cache[key].componentInstance
64
+ } else {
65
+ // 没有进行缓存
66
+ cache[key] = vnode
67
+ }
68
+
69
+ // 写入缓存
70
+ this.$store.dispatch('setGroupCache', {
71
+ cache: this.cache
72
+ })
73
+
74
+ return vnode || (slot && slot[0])
75
+ }
76
+ }
77
+