Skip to content

Commit dcb29e9

Browse files
committed
增加了部分iView-UI组件的支持
1 parent dd2ba1b commit dcb29e9

File tree

16 files changed

+674
-6
lines changed

16 files changed

+674
-6
lines changed

index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
88
<!-- muse-ui -->
99
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
10+
<!-- iView-UI -->
11+
<link rel="stylesheet" href="//unpkg.com/iview/dist/styles/iview.css">
1012
<!-- iconfont字体 -->
1113
<link rel="stylesheet" href="//at.alicdn.com/t/font_383130_czyo4j6dtjxos9k9.css">
1214
<!-- 在线css编辑器样式 -->

src/components/components.vue

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
</ul>
155155
</div>
156156
<div v-if="activeUI === 'iView-UI'">
157-
<ul class="components-list">
157+
<ul class="components-list iview-ui">
158158
<li draggable="true" @dragstart="dragStart" data-name="Row">
159159
<iview-row />
160160
</li>
@@ -165,7 +165,32 @@
165165
<iview-button-group />
166166
</li>
167167
<li draggable="true" @dragstart="dragStart" data-name="Icon">
168-
<Icon type="happy-outline" :size="32"/>
168+
<Icon type="happy-outline" :size="28" /> icon
169+
</li>
170+
<li draggable="true" @dragstart="dragStart" data-name="Radio">
171+
<Radio>Radio</Radio>
172+
</li>
173+
<li draggable="true" @dragstart="dragStart" data-name="RadioGroup">
174+
<iview-radio-group />
175+
</li>
176+
<li draggable="true" @dragstart="dragStart" data-name="Checkbox">
177+
<Checkbox>Checkbox</Checkbox>
178+
</li>
179+
<li draggable="true" @dragstart="dragStart" data-name="iSwitch">
180+
<i-switch></i-switch>
181+
</li>
182+
<li draggable="true" @dragstart="dragStart" data-name="Select">
183+
<iview-select />
184+
</li>
185+
<li draggable="true" @dragstart="dragStart" data-name="Slider">
186+
Slider
187+
<Slider :value="50" style="width:75%;display:inline-block;vertical-align:middle;" />
188+
</li>
189+
<li draggable="true" @dragstart="dragStart" data-name="DatePicker">
190+
<Date-picker size="large" type="date" placeholder="Date Picker"></Date-picker>
191+
</li>
192+
<li draggable="true" @dragstart="dragStart" data-name="TimePicker">
193+
<Time-picker size="large" type="time" placeholder="Time Picker"></Time-picker>
169194
</li>
170195
</ul>
171196
</div>
@@ -280,4 +305,11 @@ export default {
280305
vertical-align: middle;
281306
}
282307
}
308+
309+
.components-list.iview-ui >li {
310+
transform: scale(0.8)translateX(-5%);
311+
&:hover {
312+
transform: scale(1.1)translateX(10%);
313+
}
314+
}
283315
</style>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<template>
2+
</template>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<template>
2+
<Radio-group type="button">
3+
<Radio label="Radio"></Radio>
4+
<Radio label="Group"></Radio>
5+
</Radio-group>
6+
</template>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<template>
2+
<Select v-model="model1">
3+
<Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option>
4+
</Select>
5+
</template>
6+
<script>
7+
export default {
8+
data() {
9+
return {
10+
cityList: [{
11+
value: '1',
12+
label: 'Select '
13+
}, {
14+
value: '2',
15+
label: 'Select 2'
16+
}, {
17+
value: '3',
18+
label: 'Select 3'
19+
}],
20+
model1: '1'
21+
}
22+
}
23+
}
24+
</script>
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import iviewRow from './Row'
22
import iviewButtonGroup from './ButtonGroup'
3+
import iviewRadioGroup from './RadioGroup'
4+
import iviewSelect from './Select'
5+
36
export default{
47
iviewRow,
5-
iviewButtonGroup
8+
iviewButtonGroup,
9+
iviewRadioGroup,
10+
iviewSelect
611
}

src/components/subAttribute.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<!-- 开关(boolean)属性 -->
2121
<mu-switch v-if="v.type==='boolean'" :label="k" v-model="v.value" @change="updateAttribute" labelLeft :style="{width:'100%',marginBottom:'10px'}" />
2222
<!-- 选择型 (selection) 属性 -->
23-
<mu-select-field v-if="v.type==='selection'" autoWidth v-model="v.value" :label="k" @input="updateAttribute" style="width:100%;">
23+
<mu-select-field v-if="v.type==='selection'" v-model="v.value" :label="k" @input="updateAttribute" style="width:100%;">
2424
<mu-menu-item v-for="(item,index) in v.items" :value="item" :title="item" :key="index" />
2525
</mu-select-field>
2626
<!-- 图标型 (icon) 属性 Muse-UI专用 -->
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { getTemplate, getSlotContent, getStringTypeAttr } from '@/components/template'
2+
3+
var handle = function(_attr, _slots) {
4+
//定义默认属性
5+
let attributes = {
6+
value:{
7+
type:'boolean',
8+
value:false
9+
},
10+
label: {
11+
type: 'text',
12+
value: 'label'
13+
},
14+
disabled: {
15+
type: 'boolean',
16+
value: false
17+
},
18+
indeterminate:{
19+
type:'boolean',
20+
value:false
21+
},
22+
['true-value']:{
23+
type:'boolean',
24+
value:false
25+
},
26+
['false-value']:{
27+
type:'boolean',
28+
value:false
29+
}
30+
},
31+
slots = {
32+
default: []
33+
}
34+
35+
//覆盖默认属性
36+
Object.assign(slots, _slots)
37+
Object.assign(attributes, _attr)
38+
39+
//根据组件不同需要做的不同操作
40+
41+
42+
//获取插槽模板内容
43+
var subContent = getSlotContent(slots)
44+
//设置当前组件的slot
45+
if (attributes.slot && attributes.slot !== 'default') {
46+
attributes.slot = {
47+
type: 'text',
48+
value: attributes.slot
49+
}
50+
} else {
51+
attributes.slot = {
52+
type: 'text',
53+
value: ''
54+
}
55+
}
56+
57+
//字符串模板操作
58+
let stringAttr = getStringTypeAttr(attributes)
59+
let template = `<Checkbox
60+
${stringAttr}>
61+
${subContent||attributes.label.value}
62+
</Checkbox>`
63+
return { template, attributes, slots }
64+
}
65+
export default handle
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { getTemplate, getSlotContent, getStringTypeAttr } from '@/components/template'
2+
import guid from '@/utils/guid'
3+
// 深度合并
4+
import mergeDeep from '@/utils/mergeDeep'
5+
var handle = function(_attr, _slots, { id }) {
6+
//定义默认属性
7+
let attributes = {
8+
quantity:{
9+
type:'number',
10+
value:2
11+
},
12+
value:{
13+
type:'text',
14+
value:''
15+
}
16+
},
17+
slots = {
18+
default: []
19+
}
20+
21+
//覆盖默认属性
22+
Object.assign(slots, _slots)
23+
Object.assign(attributes, _attr)
24+
if (attributes.quantity.value < 0)
25+
attributes.quantity.value = 0
26+
27+
//根据组件不同需要做的不同操作
28+
let max = _attr.quantity ? _attr.quantity.value : attributes.quantity.value
29+
let components = JSON.parse(JSON.stringify(_Vue.$store.state.components))
30+
let component = components.find(c => c.info.id === id) || { slots }
31+
let oldSlots = component.slots
32+
let defaul = [] //default
33+
let addComponent = (_attr, _slots) => {
34+
let info = {
35+
name: 'Checkbox',
36+
ui: 'iView-UI',
37+
id: guid()
38+
}
39+
let colComponent = getTemplate(info, _attr, _slots)
40+
colComponent.parentId = id
41+
components.push(colComponent)
42+
return colComponent
43+
}
44+
for (let i = 0; i < max; i++) {
45+
if (oldSlots.default[i]) {
46+
defaul.push(oldSlots.default[i])
47+
} else {
48+
defaul.push({ id: addComponent().info.id })
49+
}
50+
}
51+
52+
//quantity数值减少时,子属性要对应的删除
53+
let arr = oldSlots.default.filter(item => { //得到所有要删除的对象
54+
return defaul.findIndex(({ id }) => id === item.id) === -1
55+
})
56+
arr.forEach(({ id }) => {
57+
let index = components.findIndex(c => c.info.id === id)
58+
components.splice(index, 1)
59+
})
60+
slots.default = defaul
61+
_Vue.$store.commit('setState', { components: components })
62+
63+
//获取插槽模板内容
64+
let subContent = getSlotContent(slots)
65+
66+
//设置当前组件的slot
67+
if (attributes.slot && attributes.slot !== 'default') {
68+
attributes.slot = {
69+
type: 'text',
70+
value: attributes.slot
71+
}
72+
} else {
73+
attributes.slot = {
74+
type: 'text',
75+
value: ''
76+
}
77+
}
78+
79+
//字符串模板操作
80+
let stringAttr = getStringTypeAttr(attributes)
81+
let template = `<Checkbox-group
82+
${stringAttr}>
83+
${subContent}
84+
</Checkbox-group>`
85+
86+
//删除自定义非ui属性
87+
template = template.replace(`:quantity="${attributes.quantity.value}"`, '')
88+
89+
return { template, attributes, slots }
90+
}
91+
export default handle
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { getTemplate, getSlotContent, getStringTypeAttr } from '@/components/template'
2+
3+
var handle = function(_attr, _slots) {
4+
//定义默认属性
5+
let attributes = {
6+
label: {
7+
type: 'text',
8+
value: 'Option'
9+
},
10+
value:{
11+
type:'text',
12+
value:''
13+
},
14+
disabled: {
15+
type: 'boolean',
16+
value: false
17+
}
18+
},
19+
slots = {
20+
}
21+
22+
//覆盖默认属性
23+
Object.assign(slots, _slots)
24+
Object.assign(attributes, _attr)
25+
26+
//根据组件不同需要做的不同操作
27+
28+
29+
//获取插槽模板内容
30+
var subContent = getSlotContent(slots)
31+
//设置当前组件的slot
32+
if (attributes.slot && attributes.slot !== 'default') {
33+
attributes.slot = {
34+
type: 'text',
35+
value: attributes.slot
36+
}
37+
} else {
38+
attributes.slot = {
39+
type: 'text',
40+
value: ''
41+
}
42+
}
43+
44+
//字符串模板操作
45+
let stringAttr = getStringTypeAttr(attributes)
46+
let template = `<Option
47+
${stringAttr}>
48+
${subContent}
49+
</Option>`
50+
return { template, attributes, slots }
51+
}
52+
export default handle

0 commit comments

Comments
 (0)