Skip to content

Commit

Permalink
fix: 修复 Menu 组件的 TS 问题 (jd-opensource#798)
Browse files Browse the repository at this point in the history
fix: 修复 Menu 组件的 TS 问题 (jd-opensource#798)
  • Loading branch information
yangjinjun3 authored Oct 28, 2021
1 parent 5a3f44d commit 612cdcc
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/packages/__VUE/menu/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export default createDemo({
const item = ref<HTMLElement>();
const handleChoose = (val, index) => {
const handleChoose = (val: string, index: string | number) => {
console.log(val, index);
};
const handleClick = () => {
item.value.toggle();
(item.value as any).toggle();
};
return {
Expand Down
3 changes: 3 additions & 0 deletions src/packages/__VUE/menu/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
ul {
display: flex;
flex-wrap: wrap;
list-style: none;
margin: 0;
padding: 0;
}

li {
Expand Down
41 changes: 27 additions & 14 deletions src/packages/__VUE/menu/index.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ export default create({
},
emits: ['choose'],
setup(props, { slots, emit }) {
const menuList = reactive([]);
interface IOption {
text: string,
value: string | number
}
interface IMenuItem {
title: string,
disabled: boolean,
options?: Array<IOption>
}
const menuList:Array<IMenuItem> = reactive([]);
let activeTitle = ref('');
let showMask = ref(false);
let styleObj = reactive({
Expand All @@ -87,22 +98,24 @@ export default create({
let hasOptions = ref(true);
let isShowCustomer = ref(false);
for (let i = 0; i < slots.default().length; i++) {
if (slots.default()[i].type['name'] === 'nut-menu-item') {
let item = {
title: slots.default()[i].props['title'],
disabled: !!slots.default()[i].props['disabled']
};
if (slots.default()[i].props['options']) {
item['options'] = slots.default()[i].props['options'];
} else {
hasOptions.value = false;
if(slots.default){
for (let i = 0; i < slots.default().length; i++) {
if ((slots.default()[i] as any).type['name'] === 'nut-menu-item') {
let item:IMenuItem = {
title: (slots.default()[i] as any).props['title'],
disabled: !!(slots.default()[i] as any).props['disabled']
};
if ((slots.default()[i] as any).props['options']) {
item['options'] = (slots.default()[i] as any).props['options'];
} else {
hasOptions.value = false;
}
menuList.push(item);
}
menuList.push(item);
}
}
const handleClickTitle = (title, index) => {
const handleClickTitle = (title: string, index: number) => {
if (!hasOptions.value) {
if (activeTitle.value) {
activeTitle.value = '';
Expand Down Expand Up @@ -141,7 +154,7 @@ export default create({
}
};
const handleClickOption = (text, index, value) => {
const handleClickOption = (text: string, index: number, value: string | number) => {
menuList[index].title = text;
activeTitle.value = '';
showMask.value = false;
Expand Down
41 changes: 27 additions & 14 deletions src/packages/__VUE/menu/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ export default create({
},
emits: ['choose'],
setup(props, { slots, emit }) {
const menuList = reactive([]);
interface IOption {
text: string,
value: string | number
}
interface IMenuItem {
title: string,
disabled: boolean,
options?: Array<IOption>
}
const menuList:Array<IMenuItem> = reactive([]);
let activeTitle = ref('');
let showMask = ref(false);
let styleObj = reactive({
Expand All @@ -87,22 +98,24 @@ export default create({
let hasOptions = ref(true);
let isShowCustomer = ref(false);
for (let i = 0; i < slots.default().length; i++) {
if (slots.default()[i].type['name'] === 'nut-menu-item') {
let item = {
title: slots.default()[i].props['title'],
disabled: !!slots.default()[i].props['disabled']
};
if (slots.default()[i].props['options']) {
item['options'] = slots.default()[i].props['options'];
} else {
hasOptions.value = false;
if(slots.default){
for (let i = 0; i < slots.default().length; i++) {
if ((slots.default()[i] as any).type['name'] === 'nut-menu-item') {
let item:IMenuItem = {
title: (slots.default()[i] as any).props['title'],
disabled: !!(slots.default()[i] as any).props['disabled']
};
if ((slots.default()[i] as any).props['options']) {
item['options'] = (slots.default()[i] as any).props['options'];
} else {
hasOptions.value = false;
}
menuList.push(item);
}
menuList.push(item);
}
}
const handleClickTitle = (title, index) => {
const handleClickTitle = (title: string, index: number) => {
if (!hasOptions.value) {
if (activeTitle.value) {
activeTitle.value = '';
Expand Down Expand Up @@ -141,7 +154,7 @@ export default create({
}
};
const handleClickOption = (text, index, value) => {
const handleClickOption = (text: string, index: number, value: string | number) => {
menuList[index].title = text;
activeTitle.value = '';
showMask.value = false;
Expand Down
4 changes: 2 additions & 2 deletions src/sites/mobile-taro/vue/src/nav/pages/menu/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ export default {
const item = ref<HTMLElement>();
const handleChoose = (val, index) => {
const handleChoose = (val: string, index: string | number) => {
console.log(val, index);
};
const handleClick = () => {
item.value.toggle();
(item.value as any).toggle();
};
return {
Expand Down

0 comments on commit 612cdcc

Please sign in to comment.