MCPcopy
hub / github.com/jaweii/Vue-Layout / handle

Function handle

src/components/template/Muse-UI/Card.js:4–101  ·  view source on GitHub ↗
(_attr, _slots, _info)

Source from the content-addressed store, hash-verified

2import guid from '@/utils/guid'
3
4var handle = function(_attr, _slots, _info) {
5 //定义默认属性
6 let attributes = {},
7 slots = {
8 default: []
9 }
10
11 //覆盖默认属性
12 Object.assign(slots, _slots)
13 Object.assign(attributes, _attr)
14
15 //根据组件不同需要做的不同操作
16 let components = JSON.parse(JSON.stringify(_Vue.$store.state.components))
17 let isFirstCreate = !components.find(c => c.info.id === _info.id)
18 let newComponents=[]
19 let addComponent = function(info) {
20 let component = getTemplate(info)
21 //尽量每次getTemplate后都重新获取components,避免里面修改了后造成不同步会报错
22 components = JSON.parse(JSON.stringify(_Vue.$store.state.components))
23 component.parentId = _info.id
24 newComponents.push(component)
25 return component
26 }
27 if (isFirstCreate) {
28 //添加card-header组件
29 let headerInfo = {
30 name: 'Card Header',
31 ui: 'Muse-UI',
32 id: guid()
33 }
34 let header = addComponent(headerInfo)
35 slots.default.push({ id: header.info.id })
36
37 //添加car-media组件
38 let mediaInfo = {
39 name: 'Card Media',
40 ui: 'Muse-UI',
41 id: guid()
42 }
43 let media = addComponent(mediaInfo)
44 slots.default.push({ id: media.info.id })
45
46 //添加card-title
47 let titleInfo = {
48 name: 'Card Title',
49 ui: 'Muse-UI',
50 id: guid()
51 }
52 let title = addComponent(titleInfo)
53 slots.default.push({ id: title.info.id })
54
55 //添加card-text
56 let textInfo = {
57 name: 'Card Text',
58 ui: 'Muse-UI',
59 id: guid()
60 }
61 let text = addComponent(textInfo)

Callers

nothing calls this directly

Calls 4

getSlotContentFunction · 0.90
getStringTypeAttrFunction · 0.90
guidFunction · 0.85
addComponentFunction · 0.70

Tested by

no test coverage detected