Skip to content

Commit fff32f2

Browse files
committed
feat: add component sort, fix alert/toast plugin docs
1 parent 4a4350d commit fff32f2

File tree

6 files changed

+106
-46
lines changed

6 files changed

+106
-46
lines changed

components/OneMenu.vue

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,69 @@
1717
name="hamburger"
1818
/>
1919
</div>
20-
<veui-menu
20+
<veui-sidenav
2121
class="one-menu"
2222
:items="menuItems"
2323
:expanded.sync="menuExpanded"
2424
>
25-
<template #item-label="{ label, sub, cn }">
26-
<small
27-
v-if="sub"
28-
class="sub"
29-
>⤷</small>{{ label
30-
}}<small
31-
v-if="cn"
32-
class="cn"
33-
>{{ cn }}</small>
25+
<template #item-label="{ name, label, sub, cn }">
26+
<template v-if="name === '/components'">
27+
{{ label }}
28+
<veui-button
29+
v-tooltip="t(sort ? 'unsort' : 'sort')"
30+
class="sort"
31+
:ui="`icon ${sort ? 'strong' : 'aux'}`"
32+
@click.stop="sort = !sort"
33+
>
34+
<veui-icon name="one-alphabetical-sort"/>
35+
</veui-button>
36+
</template>
37+
<template v-else>
38+
<small
39+
v-if="sub"
40+
class="sub"
41+
>⤷</small>{{ label
42+
}}<small
43+
v-if="cn"
44+
class="cn"
45+
>{{ cn }}</small>
46+
</template>
3447
</template>
35-
</veui-menu>
48+
</veui-sidenav>
3649
</nav>
3750
</template>
3851

3952
<script>
53+
import { Button, Sidenav, Icon } from 'veui'
4054
import i18n from '../common/i18n'
41-
import { Menu, Icon } from 'veui'
55+
import veuiI18n from 'veui/mixins/i18n'
56+
import tooltip from 'veui/directives/tooltip'
4257
import outside from 'veui/directives/outside'
58+
import { loadPref, savePref } from '../common/util'
4359
import 'veui-theme-dls-icons/hamburger'
4460
import 'veui-theme-dls-icons/chevron-left'
4561
62+
Icon.register({
63+
'one-alphabetical-sort': {
64+
width: 24,
65+
height: 24,
66+
d:
67+
'M12 5h10v2H12m0 12v-2h10v2m-10-8h10v2H12m-3 0v2l-3.33 4H9v2H3v-2l3.33-4H3v-2M7 3H5c-1.1 0-2 .9-2 2v6h2V9h2v2h2V5a2 2 0 0 0-2-2m0 4H5V5h2Z'
68+
}
69+
})
70+
4671
export default {
4772
name: 'one-menu',
4873
directives: {
49-
outside
74+
outside,
75+
tooltip
5076
},
5177
components: {
52-
'veui-menu': Menu,
78+
'veui-button': Button,
79+
'veui-sidenav': Sidenav,
5380
'veui-icon': Icon
5481
},
55-
mixins: [i18n],
82+
mixins: [i18n, veuiI18n],
5683
props: {
5784
expanded: Boolean,
5885
nav: {
@@ -64,14 +91,20 @@ export default {
6491
},
6592
data () {
6693
return {
67-
menuExpanded: []
94+
menuExpanded: [],
95+
sort: loadPref('sort-components') || false
6896
}
6997
},
7098
computed: {
7199
menuItems () {
72100
return this.nav.map(item => this.normalizeItem(item))
73101
}
74102
},
103+
watch: {
104+
sort (val) {
105+
savePref('sort-components', val)
106+
}
107+
},
75108
created () {
76109
this.menuExpanded = this.menuItems.map(({ name }) => name)
77110
},
@@ -90,16 +123,20 @@ export default {
90123
const to = link !== false && fullSlug && !disabled ? localePath : null
91124
const [main, cn] = this.getTitleDetail(title)
92125
126+
const normalizedChildren = children
127+
? children.map(child => this.normalizeItem(child, fullSlug))
128+
: []
129+
93130
return {
94131
label: main,
95132
cn,
96133
to,
97134
name: fullSlug,
98-
sub,
135+
sub: this.sort ? false : sub,
99136
disabled,
100-
children: children
101-
? children.map(child => this.normalizeItem(child, fullSlug))
102-
: []
137+
children: fullSlug === '/components' && this.sort
138+
? normalizedChildren.sort((a, b) => a.label.localeCompare(b.label))
139+
: normalizedChildren
103140
}
104141
},
105142
toggleMenu () {
@@ -124,11 +161,6 @@ export default {
124161
width 100%
125162
overflow auto
126163
127-
& >>> .DocSearch
128-
margin 0
129-
border-radius 6px
130-
font inherit
131-
132164
.cn
133165
margin-left 8px
134166
opacity 0.7
@@ -137,6 +169,12 @@ export default {
137169
margin-right 8px
138170
opacity 0.3
139171
172+
& >>> .veui-menu-item-label
173+
flex-grow 1
174+
175+
.sort
176+
margin-left 8px
177+
140178
.toggle
141179
display none
142180

one/docs/en-US/plugins/alert.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ The method returns a `Promise` object that is resolved when the alert dialog is
3131
| `ok` | `function(): Promise<void>` | The function to be called when the "I got it" button is clicked. If the `Promise` returned by this function is resolved, the dialog will be closed, otherwise it will not. |
3232
^^^
3333

34-
The `$alert` method also provides the following shortcut methods, which set the `type` option to the corresponding value:
34+
The `$alert` method also provides the following shortcut methods, which set the `status` option to the corresponding value:
3535

3636
| Method | Type | Description |
3737
| -- | -- | -- |
38-
| `success` | `function(content, title, options): Promise<void>` | Shows an alert dialog with the "success" style. |
39-
| `warn` | `function(content, title, options): Promise<void>` | Shows an alert dialog with the "warning" style. |
40-
| `info` | `function(content, title, options): Promise<void>` | Shows an alert dialog with the "info" style. |
41-
| `error` | `function(content, title, options): Promise<void>` | Shows an alert dialog with the "error" style. |
38+
| `success` | `function(content, title, options): Promise<void>` | Shows an alert dialog with the "success" status. |
39+
| `warn` | `function(content, title, options): Promise<void>` | Shows an alert dialog with the "warning" status. |
40+
| `info` | `function(content, title, options): Promise<void>` | Shows an alert dialog with the "info" status. |
41+
| `error` | `function(content, title, options): Promise<void>` | Shows an alert dialog with the "error" status. |

one/docs/en-US/plugins/toast.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ After installing, this plugin will provide a `$toast` object on all component in
1818
| `message` | `string` | The text content displayed in the message popup. |
1919
| `options` | `Object` | [^options] |
2020

21-
^^^ref
21+
^^^options
2222
| Name | Type | Default | Description |
2323
| -- | -- | -- | -- |
2424
| `status` | `string` | `'info'` | The type of message, can be `'success'` / `'warning'` / `'info'` / `'error'`. |
2525
| `type` | `string` | `'info'` | Deprecated. Please use the `status` property instead. |
2626
| `duration` | `number` | `3000` | Sets the duration in milliseconds before the message disappears. |
2727
^^^
2828

29-
The `$toast` method also provides the following shortcut methods, which will set the `type` value of `options` to the corresponding type:
29+
The `$toast` method also provides the following shortcut methods, which will set the `status` value of `options` to the corresponding value:
3030

3131
| Method Name | Type | Description |
3232
| -- | -- | -- |
33-
| `success` | `function(message, options): void` | Displays a message with the "success" style. |
34-
| `warn` | `function(message, options): void` | Displays a message with the "warning" style. |
35-
| `info` | `function(message, options): void` | Displays a message with the "normal message" style. |
36-
| `error` | `function(message, options): void` | Displays a message with the "error" style. |
33+
| `success` | `function(message, options): void` | Displays a message with the "success" status. |
34+
| `warn` | `function(message, options): void` | Displays a message with the "warning" status. |
35+
| `info` | `function(message, options): void` | Displays a message with the "normal message" status. |
36+
| `error` | `function(message, options): void` | Displays a message with the "error" status. |

one/docs/plugins/alert.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ Vue.use($alert)
3131
| `ok` | `function(): Promise<void>` | 点击“知道了”按钮后调用。如果该函数返回的 `Promise` 被 resolve,则弹框会被关闭,否则不会关闭。 |
3232
^^^
3333

34-
`$alert` 方法上还提供如下快捷方法,将把 `options` 中的 `type` 指定为对应类型值
34+
`$alert` 方法上还提供如下快捷方法,将把 `options` 中的 `status` 指定为对应状态值
3535

3636
| 方法名 | 类型 | 描述 |
3737
| -- | -- | -- |
38-
| `success` | `function(content, title, options): Promise<void>` | 展示“成功”样式的弹框|
39-
| `warn` | `function(content, title, options): Promise<void>` | 展示“警告”样式的弹框|
40-
| `info` | `function(content, title, options): Promise<void>` | 展示“普通消息”样式的弹框|
41-
| `error` | `function(content, title, options): Promise<void>` | 展示“错误”样式的弹框|
38+
| `success` | `function(content, title, options): Promise<void>` | 展示“成功”状态的弹框|
39+
| `warn` | `function(content, title, options): Promise<void>` | 展示“警告”状态的弹框|
40+
| `info` | `function(content, title, options): Promise<void>` | 展示“普通消息”状态的弹框|
41+
| `error` | `function(content, title, options): Promise<void>` | 展示“错误”状态的弹框|

one/docs/plugins/toast.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ Vue.use(toast)
2626
| `duration` | `number` | `3000` | 设置消息经过指定的毫秒数之后消失。 |
2727
^^^
2828

29-
`$toast` 方法上还提供如下快捷方法,将把 `options` 中的 `type` 指定为对应类型值
29+
`$toast` 方法上还提供如下快捷方法,将把 `options` 中的 `status` 指定为对应状态值
3030

3131
| 方法名 | 类型 | 描述 |
3232
| -- | -- | -- |
33-
| `success` | `function(message, options): void` | 展示“成功”样式的消息|
34-
| `warn` | `function(message, options): void` | 展示“警告”样式的消息|
35-
| `info` | `function(message, options): void` | 展示“普通消息”样式的消息|
36-
| `error` | `function(message, options): void` | 展示“错误”样式的消息|
33+
| `success` | `function(message, options): void` | 展示“成功”状态的消息|
34+
| `warn` | `function(message, options): void` | 展示“警告”状态的消息|
35+
| `info` | `function(message, options): void` | 展示“普通消息”状态的消息|
36+
| `error` | `function(message, options): void` | 展示“错误”状态的消息|

plugins/l10n.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ i18n.register(
3232
}
3333
)
3434

35+
i18n.register(
36+
'zh-Hans',
37+
{
38+
sort: '按字母顺序排列',
39+
unsort: '取消排列'
40+
},
41+
{
42+
ns: 'onemenu'
43+
}
44+
)
45+
46+
i18n.register(
47+
'en-US',
48+
{
49+
sort: 'Sort by alphabetical oder',
50+
unsort: 'Unsort'
51+
},
52+
{
53+
ns: 'onemenu'
54+
}
55+
)
56+
3557
i18n.register(
3658
'zh-Hans',
3759
{

0 commit comments

Comments
 (0)