Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(category): 导航与列表支持滚动 #2457

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 71 additions & 77 deletions src/packages/__VUE/category/demo.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
<template>
<div class="demo">
<h2>{{ translate('title1') }}</h2>
<nut-category :category="category" @change="change">
<nut-category-pane :categoryChild="categoryChild1" @onChange="onChange"> </nut-category-pane>
</nut-category>
<h2>{{ translate('title2') }}</h2>
<nut-category :category="category" @change="changeText">
<nut-category-pane type="text" :categoryChild="categoryChild2" @onChange="onChange"> </nut-category-pane
></nut-category>
<div class="demo full category-demo">
<div v-if="tabIndex === 0">
<nut-category :category="category" @change="change" style="height: 500px">
<nut-category-pane :categoryChild="data.categoryChild1" @change="onChange"></nut-category-pane>
</nut-category>
</div>

<h2>{{ translate('title3') }}</h2>
<nut-category
><nut-category-pane type="custom" :customCategory="customCategory" @onChange="changeCustom"> </nut-category-pane
></nut-category>
<template v-if="tabIndex === 1">
<nut-category :category="category" @change="changeText">
<nut-category-pane type="text" :categoryChild="data.categoryChild2" @change="onChange"> </nut-category-pane
></nut-category>
</template>

<Tabbar safeAreaInsetBottom bottom placeholder v-model="tabIndex">
<nut-tabbar-item
v-for="item in List"
:tab-title="item.title"
:icon="item.icon"
:key="item.title"
></nut-tabbar-item>
</Tabbar>
</div>
</template>

<script lang="ts">
<script setup lang="ts">
import { createComponent } from '@/packages/utils/create';
import { reactive, toRefs, onMounted, defineComponent } from 'vue';
import { reactive, h, ref, onMounted } from 'vue';
import { Tabbar } from '@/packages/nutui.vue';
import { Home, Category } from '@nutui/icons-vue';
const { translate } = createComponent('cmt');
import { useTranslate } from '@/sites/assets/util/useTranslate';
const initTranslate = () =>
Expand All @@ -34,71 +43,56 @@ const initTranslate = () =>
title3: 'Custom taxonomy'
}
});
export default defineComponent({
props: {},
setup() {
initTranslate();
const data = reactive({
categoryInfo1: {},
category: [{}],
categoryChild1: [{}],
customCategory: [{}],
categoryInfo2: {},
categoryChild2: [{}]
});

onMounted(() => {
setTimeout(() => {
getData();
}, 500);
});

const getData = () => {
fetch('//storage.360buyimg.com/nutui/3x/categoryData.js')
.then((response) => response.json())
.then((res) => {
const { categoryInfo, categoryChild, customCategory } = res;
data.categoryInfo1 = categoryInfo;
data.category = categoryInfo.category;
data.categoryChild1 = categoryChild;
data.customCategory = customCategory;
data.categoryInfo2 = categoryInfo;
data.categoryChild2 = categoryChild;
})
.catch((err) => console.log('Oh, error', err));
};
initTranslate();
const category = ref([]);
const data = reactive({
categoryInfo1: {},
category: [{}],
categoryChild1: [{}],
categoryInfo2: {},
categoryChild2: [{}]
});
const tabIndex = ref(0);
onMounted(() => {
setTimeout(() => {
getData();
}, 500);
});

const change = (index: any) => {
data.categoryChild1 = [].concat(data?.categoryInfo1?.category[index]?.children as any);
};
const List = [
{
title: translate('title1'),
icon: h(Home)
},
{
title: translate('title2'),
icon: h(Category)
}
];

const changeText = (index: any) => {
data.categoryChild2 = [].concat(data.categoryInfo2.category[index].children as any);
};
const getData = () => {
fetch('//storage.360buyimg.com/nutui/3x/categoryData.js')
.then((response) => response.json())
.then((res) => {
const { categoryInfo, categoryChild } = res;
data.categoryInfo1 = categoryInfo;
category.value = categoryInfo.category;
data.categoryChild1 = categoryChild;
data.categoryInfo2 = categoryInfo;
data.categoryChild2 = categoryChild;
})
.catch((err) => console.log('Oh, error', err));
};

const changeCustom = (v: any) => {
console.log('点击分类数据:' + JSON.stringify(v));
};
const change = (index: number) => {
data.categoryChild1 = data?.categoryInfo1?.category[index]?.children;
};

const onChange = (v: any) => {
console.log('当前分类数据:' + JSON.stringify(v));
};
const changeText = (index: number) => {
data.categoryChild2 = data.categoryInfo2.category[index].children;
};

return {
change,
onChange,
changeText,
changeCustom,
...toRefs(data),
translate
};
}
});
const onChange = (v: any) => {
console.log('当前分类数据:', v);
};
</script>

<style lang="scss" scoped>
.demo {
padding-left: 0 !important;
padding-right: 0px !important;
}
</style>
89 changes: 19 additions & 70 deletions src/packages/__VUE/category/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data defination
```html
<template>
<nut-category :category="category" @change="change">
<nut-category-pane :categoryChild="categoryChild" @onChange="onChange"> </nut-category-pane>
<nut-category-pane :categoryChild="categoryChild" @change="onChange"> </nut-category-pane>
</nut-category>
</template>
<script lang="ts">
Expand Down Expand Up @@ -82,7 +82,7 @@ data defination
```html
<template>
<nut-category :category="category" @change="changeText">
<nut-category-pane type="text" :categoryChild="categoryChild" @onChange="onChange"> </nut-category-pane
<nut-category-pane type="text" :categoryChild="categoryChild" @change="onChange"> </nut-category-pane
></nut-category>
</template>
<script lang="ts">
Expand Down Expand Up @@ -134,87 +134,36 @@ data defination

:::

### Custom taxonomy
## Category

:::demo

```html
<template>
<nut-category @change="changeCustom"
><nut-category-pane type="custom" :customCategory="customCategory" @onChange="changeCustom"> </nut-category-pane
></nut-category>
</template>
<script lang="ts">
import { reactive, toRefs, onMounted } from 'vue';

export default {
setup() {
const data = reactive({
customCategory: [{}]
});
onMounted(() => {
setTimeout(() => {
getData();
}, 500);
});
const getData = () => {
fetch('//storage.360buyimg.com/nutui/3x/categoryData.js')
.then((response) => response.json())
.then((res) => {
const { customCategory } = res;
data.customCategory = customCategory;
})
.catch((err) => console.log('Oh, error', err));
};
const changeCustom = () => {
console.log('Click to categorize data');
};
return {
changeCustom,
...toRefs(data)
};
}
};
</script>
```
### Props

:::
| Attribute | Description | Type | Default |
| ---------------- | --------------------------------------- | ------ | ---------------------------------------- |
| type | Classification mode: `classify`, `text` | string | `classify` |
| category | Left navigation bar data list | Array | `[]` |
| optionKey`4.1.3` | Custom keys in `category` | Object | `{ catId: 'catId', catName: 'catName' }` |

## API
### Events

### Category Props
| Event | Description | Arguments |
| ------ | ------------------------------------------------------------------------------------------ | ------------ |
| change | Classic classification, click on the left navigation bar to get the data list on the right | Clicked data |

| Attribute | Description | Type | Default |
| --------- | ------------------------------------------------- | ------ | ---------- |
| type | Classification mode: `classify`, `text`, `custom` | string | `classify` |
| category | Left navigation bar data list | Array | `[]` |
## CategoryPane

### Category Events

| Event | Description | Arguments |
| ------------- | ----------------------------------------------------------------------------------------------- | ---------------- |
| change | Classic classification, click on the left navigation bar to get the data list on the right | Clicked data |
| change-text | In text classification mode, click on the left navigation bar to get the data list on the right | Input data |
| change-custom | Customize, click the left navigation bar to get the data list on the right | Current quantity |

### CategoryPane Props
### Props

| Attribute | Description | Type | Default |
| --------------- | --------------------------------------------------------- | ----- | ------- |
| category-child | The current classification data is displayed on the right | Array | `[]` |
| custom-category | Custom categorical data | Array | `[]` |

### CategoryPane Events

| Event | Description | Arguments |
| --------- | ------------------------------------------ | ------------ |
| on-change | Click on the right classified data trigger | Clicked data |

### CategoryPane Slots
### Events

| Name | Description |
| ------- | -------------- |
| default | Custom content |
| Event | Description | Arguments |
| ------ | ------------------------------------------ | ------------ |
| change | Click on the right classified data trigger | Clicked data |

## Theming

Expand Down
Loading
Loading