Skip to content

Commit 14eeda9

Browse files
committed
Merge branch 'dev' of gitee.com:devui/vue-devui into dev
2 parents 4e5441e + 799fb35 commit 14eeda9

File tree

40 files changed

+1702
-1398
lines changed

40 files changed

+1702
-1398
lines changed

README.md

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<p align="center">
22
<a href="https://devui.design/home" target="_blank" rel="noopener noreferrer">
3-
<img alt="DevUI Logo" src="packages/devui-vue/public/logo.svg?sanitize=true" width="180" style="max-width:100%;">
3+
<img alt="DevUI Logo" src="https://gitee.com/devui/vue-devui/raw/dev/packages/devui-vue/public/logo.svg?sanitize=true" width="180" style="max-width:100%;">
44
</a>
55
</p>
66

77
Vue DevUI 是 Vue3 版本的 DevUI 组件库,基于 [https://github.com/devcloudfe/ng-devui](https://github.com/devcloudfe/ng-devui),倡导`沉浸``灵活``至简`的设计价值观。
88

99
DevUI 官方网站:[https://devui.design](https://devui.design)
1010

11+
DevUI开源项目正在参加[2021年度OSC中国开源项目评选](https://www.oschina.net/project/top_cn_2021/?id=205&ticket=4b10864b99e57311d9897964acfc0c9c),欢迎大家给我们`DevUI Design`投上宝贵的一票:
12+
13+
[DevUI开源项目-2021年度OSC中国开源项目评选投票](https://www.oschina.net/project/top_cn_2021/?id=205&ticket=4b10864b99e57311d9897964acfc0c9c)
14+
1115
想了解[DevUI](https://devui.design)开源的故事,可以阅读以下文章:
1216

1317
[DevUI开源的故事](https://juejin.cn/post/7029092585452863525/)
@@ -70,6 +74,7 @@ yarn add vue-devui
7074

7175
## 2. 全量引入
7276

77+
`main.ts`文件中编写以下代码:
7378
```
7479
import { createApp } from 'vue'
7580
import App from './App.vue'
@@ -88,6 +93,7 @@ createApp(App)
8893

8994
除了全量引入,我们也支持单个组件按需引入。
9095

96+
`main.ts`文件中编写以下代码:
9197
```
9298
import { createApp } from 'vue'
9399
import App from './App.vue'
@@ -103,7 +109,32 @@ createApp(App)
103109
.mount('#app')
104110
```
105111

106-
## 4. 使用
112+
## 4. 配置自动按需引入`unplugin-vue-components`(推荐)
113+
114+
配置`unplugin-vue-components`插件可以无需引入Vue DevUI就可以直接按需使用其中的组件,具体使用方式如下:
115+
116+
`vite.config.ts`文件中添加以下代码:
117+
```
118+
import Components from 'unplugin-vue-components/vite'
119+
import { DevUiResolver } from 'unplugin-vue-components/resolvers'
120+
121+
export default defineConfig({
122+
plugins: [
123+
vue(),
124+
125+
// 新增
126+
Components({
127+
resolvers: [
128+
DevUiResolver()
129+
]
130+
})
131+
]
132+
})
133+
```
134+
135+
配置了以上插件,就可以直接在代码中使用`Vue DevUI`的组件,而无需在`main.ts`文件中引入`Vue DevUI`
136+
137+
## 5. 使用
107138

108139
```
109140
<template>
@@ -113,7 +144,7 @@ createApp(App)
113144

114145
# 图标库
115146

116-
图标库可以使用[DevUI图标库](https://devui.design/icon/ruleResource),也可以使用第三方图标库,比如:iconfont。
147+
图标库推荐使用[DevUI图标库](https://devui.design/icon/ruleResource),也可以使用第三方图标库,比如:iconfont。
117148

118149
## 使用DevUI图标库
119150

@@ -141,36 +172,6 @@ import '@devui-design/icons/icomoon/devui-icon.css'
141172
<d-icon name="love" color="red"></d-icon>
142173
```
143174

144-
## 使用第三方图标库
145-
146-
如果有第三方图标库,可以用类似的方式引入。
147-
148-
### 引入
149-
150-
`main.ts`文件中,编写以下代码:
151-
152-
```
153-
import 'your-folder/my-icon.css'
154-
```
155-
156-
### 使用
157-
158-
```
159-
<d-icon classPrefix="my-icon" name="love" color="red"></d-icon>
160-
```
161-
162-
其中的`classPrefix`参数的值,应该和你的字体图标样式文件`my-icon.css`里定义的样式前缀保持一致。
163-
164-
比如`my-icon.css`里的图标样式:
165-
166-
```css
167-
.my-icon-branch-node:before {
168-
content: "\E001";
169-
}
170-
```
171-
172-
那么`classPrefix`就是`my-icon`
173-
174175
# License
175176

176177
[MIT](https://gitee.com/devui/vue-devui/blob/dev/LICENSE)
Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,92 @@
1-
import { defineComponent } from 'vue'
1+
import { defineComponent, toRefs, computed, inject } from 'vue'
2+
import { accordionProps } from './accordion-types'
3+
import { AccordionItemClickEvent, AccordionMenuItem } from './accordion.type'
4+
import { getRootSlots } from '../src/utils'
25

36
export default defineComponent({
47
name: 'DAccordionItem',
58
props: {
6-
9+
item: Object as () => AccordionMenuItem,
10+
deepth: {
11+
type: Number,
12+
default: 0
13+
},
14+
parent: {
15+
type: Object as () => AccordionMenuItem,
16+
default: null
17+
},
18+
...accordionProps
719
},
8-
setup() {
20+
setup(props) {
21+
const {
22+
item,
23+
deepth,
24+
parent,
25+
titleKey,
26+
activeKey,
27+
disabledKey,
28+
} = toRefs(props)
29+
30+
const rootSlots = getRootSlots()
31+
const accordionCtx = inject('accordionContext') as any
32+
33+
let parentValue = parent.value
34+
let deepValue = deepth.value
35+
36+
const disabled = computed(() => {
37+
return item.value && item.value[disabledKey.value]
38+
})
39+
const title = computed(() => {
40+
return item.value && item.value[titleKey.value]
41+
})
42+
const active = computed(() => {
43+
return item.value && item.value[activeKey.value]
44+
})
45+
46+
const childActived = computed(() => {
47+
return active.value
48+
})
49+
50+
const itemClick = (itemEvent: AccordionItemClickEvent) => {
51+
if (item.value && !disabled.value) {
52+
accordionCtx.itemClickFn(itemEvent)
53+
}
54+
}
55+
956
return () => {
10-
return <li>d-accordion-item</li>
57+
return (
58+
<>
59+
<div
60+
class={[
61+
'devui-accordion-item-title',
62+
'devui-over-flow-ellipsis',
63+
childActived.value && 'active',
64+
disabled.value && 'disabled'
65+
]}
66+
title={title.value}
67+
style={{ textIndent: deepValue * 20 + 'px' }}
68+
onClick={(e) =>
69+
itemClick({
70+
item: item.value,
71+
parent: parentValue,
72+
event: e
73+
})
74+
}
75+
>
76+
<div
77+
class={['devui-accordion-splitter', deepValue === 0 && 'devui-parent-list']}
78+
style={{ left: deepValue * 20 + 10 + 'px' }}
79+
></div>
80+
{!rootSlots.itemTemplate && <>{title.value}</>}
81+
{rootSlots.itemTemplate &&
82+
rootSlots.itemTemplate?.({
83+
parent: parentValue,
84+
deepth: deepValue,
85+
item: item.value
86+
})}
87+
</div>
88+
</>
89+
)
1190
}
1291
}
13-
})
92+
})

0 commit comments

Comments
 (0)