File tree Expand file tree Collapse file tree 4 files changed +75
-3
lines changed
uni_modules/wot-design-uni/components Expand file tree Collapse file tree 4 files changed +75
-3
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,35 @@ function handleOpened() {
112112</view >
113113```
114114
115+ ## 自定义菜单图标
116+
117+ 可以通过 ` icon ` 设置菜单右侧图标,等同于 ` <wd-icon /> ` 的 ` name ` 属性。通过 ` icon-size ` 设置图标尺寸,等同于 ` <wd-icon /> ` 的 ` size ` 属性。
118+
119+ ``` html
120+ <wd-drop-menu >
121+ <wd-drop-menu-item title =" 地图" icon =" location" icon-size =" 24px" />
122+ </wd-drop-menu >
123+ ```
124+
125+ ## 自定义菜单点击事件
126+
127+ 可以通过 ` before-toggle ` 来自定义菜单点击事件,不传则默认展开菜单。
128+
129+ ``` html
130+ <wd-drop-menu >
131+ <wd-drop-menu-item title =" 延迟 0.5s 展开" :before-toggle =" handleBeforeToggle" />
132+ </wd-drop-menu >
133+ ```
134+
135+ ``` typescript
136+ function handleBeforeToggle(showPop : boolean , toggle : () => void ) {
137+ console .log (' 当前菜单展开状态:' , showPop )
138+
139+ // 异步展开(如果不需要展开则不调用 toggle 函数即可)
140+ setTimeout (toggle , 500 )
141+ }
142+ ```
143+
115144## 向上展开
116145
117146将 ` direction ` 属性值设置为 ` up ` ,菜单即可向上展开
@@ -150,6 +179,9 @@ function handleOpened() {
150179| options | 列表数据,对应数据结构 ` [{text: '标题', value: '0', tip: '提示文字'}] ` | array | - | - | - |
151180| icon-name | 选中的图标名称(可选名称在 wd-icon 组件中) | string | - | check | - |
152181| title | 菜单标题 | string | - | - | - |
182+ | icon | 菜单图标 | string | - | arrow-down | - |
183+ | icon-size | 菜单图标尺寸 | string | - | 14px | _ |
184+ | before-toggle | 在切换操作之前调用的函数,类型:` (showPop: boolean, toggle: () => void) => void ` ,其中 ` showPop ` 为当前菜单展开状态 | function | - | - | - |
153185| value-key | 选项对象中,value 对应的 key | string | - | value | - |
154186| label-key | 选项对象中,展示的文本对应的 key | string | - | label | - |
155187| tip-key | 选项对象中,选项说明对应的 key | string | - | tip | - |
Original file line number Diff line number Diff line change 3232 </view >
3333 </view >
3434 </demo-block >
35+ <demo-block title =" 自定义菜单图标" transparent >
36+ <wd-drop-menu >
37+ <wd-drop-menu-item title =" 地图" icon =" location" icon-size =" 24px" />
38+ </wd-drop-menu >
39+ </demo-block >
40+ <demo-block title =" 自定义点击事件" transparent >
41+ <wd-drop-menu >
42+ <wd-drop-menu-item title =" 延迟 0.5s 展开" :before-toggle =" handleBeforeToggle" />
43+ </wd-drop-menu >
44+ </demo-block >
3545 <demo-block title =" 向上弹出" transparent >
3646 <wd-drop-menu direction =" up" >
3747 <wd-drop-menu-item v-model =" value6" :options =" option1" @change =" handleChange6" />
@@ -116,6 +126,13 @@ function handleChange9({ value }: any) {
116126function confirm() {
117127 dropMenu .value .close ()
118128}
129+
130+ function handleBeforeToggle(showPop : boolean , toggle : () => void ) {
131+ console .log (' 当前菜单展开状态:' , showPop )
132+
133+ // 异步展开(如果不需要展开则不调用 toggle 函数即可)
134+ setTimeout (toggle , 500 )
135+ }
119136 </script >
120137<style lang="scss" scoped>
121138.wot-theme-dark {
Original file line number Diff line number Diff line change 1- import type { ComponentPublicInstance , ExtractPropTypes } from 'vue'
1+ import type { ComponentPublicInstance , ExtractPropTypes , PropType } from 'vue'
22import { baseProps , makeArrayProp , makeBooleanProp , makeStringProp } from '../common/props'
33
4+ export type DropMenuItemBeforeToggle = ( showPop : boolean , toggle : ( ) => void ) => void
5+
46export const dorpMenuItemProps = {
57 ...baseProps ,
68 /**
@@ -31,6 +33,18 @@ export const dorpMenuItemProps = {
3133 * 菜单标题
3234 */
3335 title : String ,
36+ /**
37+ * 菜单图标
38+ */
39+ icon : makeStringProp ( 'arrow-down' ) ,
40+ /**
41+ * 菜单图标大小
42+ */
43+ iconSize : makeStringProp ( '14px' ) ,
44+ /**
45+ * 自定义点击事件
46+ */
47+ beforeToggle : Function as PropType < DropMenuItemBeforeToggle > ,
3448 /**
3549 * 选项对象中,value 对应的 key
3650 */
Original file line number Diff line number Diff line change 77 <view
88 v-for =" (child, index) in children"
99 :key =" index"
10- @click =" toggle (child)"
10+ @click =" handleItemClick (child)"
1111 :class =" `wd-drop-menu__item ${child.disabled ? 'is-disabled' : ''} ${currentUid === child.$.uid ? 'is-active' : ''}`"
1212 >
1313 <view class =" wd-drop-menu__item-title" >
1414 <view class =" wd-drop-menu__item-title-text" >{{ getDisplayTitle(child) }}</view >
15- <wd-icon name =" arrow-down " custom-class =" wd-drop-menu__arrow" />
15+ <wd-icon : name =" child.icon " :size = " child.iconSize " custom-class =" wd-drop-menu__arrow" />
1616 </view >
1717 </view >
1818 </view >
@@ -90,6 +90,15 @@ function getDisplayTitle(child: any) {
9090 console .error (' [wot-design] warning(wd-drop-menu-item): no value is matched in the options option.' )
9191}
9292
93+ function handleItemClick(child : any ) {
94+ if (child .beforeToggle ) {
95+ const showPop = child .$ .exposed ! .getShowPop ()
96+ child .beforeToggle (showPop , () => toggle (child ))
97+ } else {
98+ toggle (child )
99+ }
100+ }
101+
93102function toggle(child : any ) {
94103 // 点击当前 menu, 关闭其他 menu
95104
You can’t perform that action at this time.
0 commit comments