Skip to content

Commit

Permalink
chore(empty): optimize (#2443)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiinu authored Jul 20, 2023
1 parent 2b6cdcf commit 4d67af7
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 233 deletions.
24 changes: 7 additions & 17 deletions packages/nutui-taro-demo/src/exhibition/pages/empty/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@

<h2>自定义图片</h2>
<div class="show">
<nut-empty description="无优惠券">
<template #image>
<img src="https://static-ftcms.jd.com/p/files/61a9e3313985005b3958672e.png" />
</template>
</nut-empty>
<nut-empty
image="https://static-ftcms.jd.com/p/files/61a9e3313985005b3958672e.png"
description="无优惠券"
></nut-empty>
</div>

<h2>底部内容</h2>
Expand All @@ -41,21 +40,12 @@
</div>
</template>

<script lang="ts">
<script setup lang="ts">
import { ref } from 'vue';
import Taro from '@tarojs/taro';
import Header from '../../../components/header.vue';
export default {
components: { Header },
setup() {
const env = Taro.getEnv();
const tabValue = ref(0);
return {
tabValue,
env
};
}
};
const env = Taro.getEnv();
const tabValue = ref(0);
</script>

<style lang="scss">
Expand Down
66 changes: 34 additions & 32 deletions src/packages/__VUE/empty/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
import { mount } from '@vue/test-utils';
import Empty from '../../empty/index.vue';

describe('Empty', () => {
test('should be shown when passing image and description', () => {
const wrapper = mount(Empty, {
props: {
image: 'empty',
description: '这是文字描述'
}
});

expect(wrapper.html()).toContain('img');
expect(wrapper.html()).toContain('这是文字描述');
test('Empty: should be shown when passing image and description', () => {
const wrapper = mount(Empty, {
props: {
image: 'empty',
imageSize: '50',
description: '这是文字描述'
}
});

test('should be shown when passing slot image', () => {
const wrapper = mount(Empty, {
slots: {
image: '<img src="https://abc.png"/>'
}
});
expect(wrapper.html()).toContain('img');
expect(wrapper.html()).toContain('这是文字描述');
});

expect(wrapper.html()).toContain('abc.png');
test('Empty: should be shown when passing slot image', () => {
const wrapper = mount(Empty, {
slots: {
image: '<img src="https://abc.png"/>'
}
});

test('should be shown when passing slot description', () => {
const wrapper = mount(Empty, {
slots: {
description: 'test'
}
});
expect(wrapper.html()).toContain('abc.png');
});

expect(wrapper.html()).toContain('test');
test('Empty: should be shown when passing slot description', () => {
const wrapper = mount(Empty, {
props: {
image: 'https://abc.png'
},
slots: {
description: 'test'
}
});

test('should be shown when passing slot defalut', () => {
const wrapper = mount(Empty, {
slots: {
default: '加载失败,请刷新页面'
}
});
expect(wrapper.html()).toContain('test');
});

expect(wrapper.html()).toContain('加载失败');
test('Empty: should be shown when passing slot defalut', () => {
const wrapper = mount(Empty, {
slots: {
default: '加载失败,请刷新页面'
}
});

expect(wrapper.html()).toContain('加载失败');
});
25 changes: 8 additions & 17 deletions src/packages/__VUE/empty/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

<h2>{{ translate('customImg') }}</h2>
<div class="show">
<nut-empty :description="translate('description')">
<template #image>
<img src="https://static-ftcms.jd.com/p/files/61a9e3313985005b3958672e.png" />
</template>
<nut-empty
image="https://static-ftcms.jd.com/p/files/61a9e3313985005b3958672e.png"
:description="translate('description')"
>
</nut-empty>
</div>

Expand All @@ -40,8 +40,8 @@
</div>
</template>

<script lang="ts">
import { ref, defineComponent } from 'vue';
<script setup lang="ts">
import { ref } from 'vue';
import { createComponent } from '@/packages/utils/create';
const { translate } = createComponent('empty');
import { useTranslate } from '@/sites/assets/util/useTranslate';
Expand Down Expand Up @@ -74,17 +74,8 @@ const initTranslate = () =>
retry: 'Retry'
}
});
export default defineComponent({
props: {},
setup() {
initTranslate();
const tabValue = ref(0);
return {
tabValue,
translate
};
}
});
initTranslate();
const tabValue = ref(0);
</script>

<style lang="scss" scoped>
Expand Down
33 changes: 12 additions & 21 deletions src/packages/__VUE/empty/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Occupation reminder when empty.

### Install

```javascript
```js
import { createApp } from 'vue';
import { Empty } from '@nutui/nutui';

Expand All @@ -18,7 +18,7 @@ app.use(Empty);

:::demo

```html
```vue
<template>
<nut-empty description="no data"></nut-empty>
</template>
Expand All @@ -30,7 +30,7 @@ app.use(Empty);

:::demo

```html
```vue
<template>
<nut-tabs v-model="tabValue">
<nut-tab-pane title="empty">
Expand All @@ -44,16 +44,8 @@ app.use(Empty);
</nut-tab-pane>
</nut-tabs>
</template>
<script lang="ts">
import { ref } from 'vue';
export default {
setup() {
const tabValue = ref(0);
return {
tabValue
};
}
};
<script setup>
const tabValue = ref(0);
</script>
```

Expand All @@ -63,13 +55,12 @@ app.use(Empty);

:::demo

```html
```vue
<template>
<nut-empty description="Description">
<template #image>
<img src="https://static-ftcms.jd.com/p/files/61a9e3313985005b3958672e.png" />
</template>
</nut-empty>
<nut-empty
image="https://static-ftcms.jd.com/p/files/61a9e3313985005b3958672e.png"
description="Description"
></nut-empty>
</template>
```

Expand All @@ -79,7 +70,7 @@ app.use(Empty);

:::demo

```html
```vue
<template>
<nut-empty image="error" description="Failed to load">
<div style="margin-top: 10px">
Expand All @@ -91,7 +82,7 @@ app.use(Empty);

:::

## API
## Empty

### Props

Expand Down
33 changes: 12 additions & 21 deletions src/packages/__VUE/empty/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

### 安装

```javascript
```js
import { createApp } from 'vue';
import { Empty } from '@nutui/nutui';

Expand All @@ -18,7 +18,7 @@ app.use(Empty);

:::demo

```html
```vue
<template>
<nut-empty description="无数据"></nut-empty>
</template>
Expand All @@ -30,7 +30,7 @@ app.use(Empty);

:::demo

```html
```vue
<template>
<nut-tabs v-model="tabValue">
<nut-tab-pane title="无内容">
Expand All @@ -44,16 +44,8 @@ app.use(Empty);
</nut-tab-pane>
</nut-tabs>
</template>
<script lang="ts">
import { ref } from 'vue';
export default {
setup() {
const tabValue = ref(0);
return {
tabValue
};
}
};
<script setup>
const tabValue = ref(0);
</script>
```

Expand All @@ -63,13 +55,12 @@ app.use(Empty);

:::demo

```html
```vue
<template>
<nut-empty description="描述文字">
<template #image>
<img src="https://static-ftcms.jd.com/p/files/61a9e3313985005b3958672e.png" />
</template>
</nut-empty>
<nut-empty
image="https://static-ftcms.jd.com/p/files/61a9e3313985005b3958672e.png"
description="描述文字"
></nut-empty>
</template>
```

Expand All @@ -79,7 +70,7 @@ app.use(Empty);

:::demo

```html
```vue
<template>
<nut-empty image="error" description="加载失败">
<div style="margin-top: 10px">
Expand All @@ -91,7 +82,7 @@ app.use(Empty);

:::

## API
## Empty

### Props

Expand Down
Loading

0 comments on commit 4d67af7

Please sign in to comment.