-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(empty): move to script setup (#2991)
- Loading branch information
Showing
10 changed files
with
185 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<template> | ||
<view class="nut-empty"> | ||
<view class="nut-empty__box" :style="style"> | ||
<slot name="image"> | ||
<img v-if="src" class="nut-empty__box--img" :src="src" /> | ||
</slot> | ||
</view> | ||
|
||
<slot name="description"> | ||
<view class="nut-empty__description">{{ descriptionText }}</view> | ||
</slot> | ||
|
||
<slot></slot> | ||
</view> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from 'vue'; | ||
import { EmptyImage } from './types'; | ||
import { pxCheck } from '@/packages/utils/pxCheck'; | ||
import { useLocale } from '@/packages/utils/useLocale'; | ||
defineOptions({ | ||
name: 'NutEmpty' | ||
}); | ||
export type emptyProps = Partial<{ | ||
image: EmptyImage; | ||
imageSize: number | string; | ||
description: string; | ||
}>; | ||
const props = withDefaults(defineProps<emptyProps>(), { | ||
image: 'empty', | ||
imageSize: '', | ||
description: '' | ||
}); | ||
const translate = useLocale('NutEmpty'); | ||
const defaultStatus: any = { | ||
empty: 'https://static-ftcms.jd.com/p/files/61a9e3183985005b3958672b.png', | ||
error: 'https://ftcms.jd.com/p/files/61a9e33ee7dcdbcc0ce62736.png', | ||
network: 'https://static-ftcms.jd.com/p/files/61a9e31de7dcdbcc0ce62734.png' | ||
}; | ||
const style = computed(() => { | ||
if (props.imageSize) { | ||
return { | ||
width: pxCheck(props.imageSize), | ||
height: pxCheck(props.imageSize) | ||
}; | ||
} | ||
return {}; | ||
}); | ||
const src = computed(() => { | ||
if (props.image.startsWith('https://') || props.image.startsWith('http://') || props.image.startsWith('//')) { | ||
return props.image; | ||
} else { | ||
return defaultStatus[props.image]; | ||
} | ||
}); | ||
const descriptionText = computed(() => { | ||
return props.description || translate('noData'); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<template> | ||
<view class="nut-empty"> | ||
<view class="nut-empty__box" :style="style"> | ||
<slot name="image"> | ||
<img v-if="src" class="nut-empty__box--img" :src="src" /> | ||
</slot> | ||
</view> | ||
|
||
<slot name="description"> | ||
<view class="nut-empty__description">{{ descriptionText }}</view> | ||
</slot> | ||
|
||
<slot></slot> | ||
</view> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from 'vue'; | ||
import { EmptyImage } from './types'; | ||
import { pxCheck } from '@/packages/utils/pxCheck'; | ||
import { useLocale } from '@/packages/utils/useLocale'; | ||
defineOptions({ | ||
name: 'NutEmpty' | ||
}); | ||
export type emptyProps = Partial<{ | ||
image: EmptyImage; | ||
imageSize: number | string; | ||
description: string; | ||
}>; | ||
const props = withDefaults(defineProps<emptyProps>(), { | ||
image: 'empty', | ||
imageSize: '', | ||
description: '' | ||
}); | ||
const translate = useLocale('NutEmpty'); | ||
const defaultStatus: any = { | ||
empty: 'https://static-ftcms.jd.com/p/files/61a9e3183985005b3958672b.png', | ||
error: 'https://ftcms.jd.com/p/files/61a9e33ee7dcdbcc0ce62736.png', | ||
network: 'https://static-ftcms.jd.com/p/files/61a9e31de7dcdbcc0ce62734.png' | ||
}; | ||
const style = computed(() => { | ||
if (props.imageSize) { | ||
return { | ||
width: pxCheck(props.imageSize), | ||
height: pxCheck(props.imageSize) | ||
}; | ||
} | ||
return {}; | ||
}); | ||
const src = computed(() => { | ||
if (props.image.startsWith('https://') || props.image.startsWith('http://') || props.image.startsWith('//')) { | ||
return props.image; | ||
} else { | ||
return defaultStatus[props.image]; | ||
} | ||
}); | ||
const descriptionText = computed(() => { | ||
return props.description || translate('noData'); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Empty from './empty.taro.vue'; | ||
import type { ComponentPublicInstance } from 'vue'; | ||
import { withInstall } from '@/packages/utils'; | ||
|
||
withInstall(Empty); | ||
|
||
export type { emptyProps } from './empty.taro.vue'; | ||
export type { EmptyImage } from './types'; | ||
|
||
export type EmptyInstance = ComponentPublicInstance & InstanceType<typeof Empty>; | ||
|
||
export { Empty, Empty as default }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Empty from './empty.vue'; | ||
import type { ComponentPublicInstance } from 'vue'; | ||
import { withInstall } from '@/packages/utils'; | ||
|
||
withInstall(Empty); | ||
|
||
export type { emptyProps } from './empty.vue'; | ||
export type { EmptyImage } from './types'; | ||
|
||
export type EmptyInstance = ComponentPublicInstance & InstanceType<typeof Empty>; | ||
|
||
export { Empty, Empty as default }; |
This file was deleted.
Oops, something went wrong.