forked from jd-opensource/nutui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(trend-arrow): move to script setup (jd-opensource#2993)
- Loading branch information
Showing
10 changed files
with
201 additions
and
184 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,11 @@ | ||
import TrendArrow from './trend-arrow.taro.vue'; | ||
import type { ComponentPublicInstance } from 'vue'; | ||
import { withInstall } from '@/packages/utils'; | ||
|
||
withInstall(TrendArrow); | ||
|
||
export type { TrendArrowProps } from './trend-arrow.taro.vue'; | ||
|
||
export type TrendArrowInstance = ComponentPublicInstance & InstanceType<typeof TrendArrow>; | ||
|
||
export { TrendArrow, TrendArrow 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,11 @@ | ||
import TrendArrow from './trend-arrow.vue'; | ||
import type { ComponentPublicInstance } from 'vue'; | ||
import { withInstall } from '@/packages/utils'; | ||
|
||
withInstall(TrendArrow); | ||
|
||
export type { TrendArrowProps } from './trend-arrow.vue'; | ||
|
||
export type TrendArrowInstance = ComponentPublicInstance & InstanceType<typeof TrendArrow>; | ||
|
||
export { TrendArrow, TrendArrow 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,77 @@ | ||
<template> | ||
<view class="nut-trend-arrow"> | ||
<span v-if="!arrowLeft" class="nut-trend-arrow-icon-before nut-trend-arrow-rate" :style="calcStyle">{{ | ||
calcRate | ||
}}</span> | ||
<slot v-if="Number(rate) !== 0 && isPositive" name="up-icon"> | ||
<TriangleUp :color="riseColor" /> | ||
</slot> | ||
<slot v-if="Number(rate) !== 0 && !isPositive" name="down-icon"> | ||
<TriangleDown :color="dropColor" /> | ||
</slot> | ||
<span v-if="arrowLeft" class="nut-trend-arrow-icon-after nut-trend-arrow-rate" :style="calcStyle">{{ | ||
calcRate | ||
}}</span> | ||
</view> | ||
</template> | ||
<script setup lang="ts"> | ||
import { computed } from 'vue'; | ||
import { myFixed } from '@/packages/utils/util'; | ||
import { TriangleUp, TriangleDown } from '@nutui/icons-vue-taro'; | ||
defineOptions({ | ||
name: 'NutTrendArrow' | ||
}); | ||
export type TrendArrowProps = Partial<{ | ||
rate: number; | ||
digits: number; | ||
showSign: boolean; | ||
showZero: boolean; | ||
arrowLeft: boolean; | ||
syncTextColor: boolean; | ||
textColor: string; | ||
riseColor: string; | ||
dropColor: string; | ||
}>; | ||
const props = withDefaults(defineProps<TrendArrowProps>(), { | ||
rate: 0, | ||
digits: 2, | ||
showSign: false, | ||
showZero: false, | ||
arrowLeft: false, | ||
syncTextColor: true, | ||
textColor: '#333', | ||
riseColor: '#fa2c19', | ||
dropColor: '#64b578' | ||
}); | ||
const isPositive = computed(() => { | ||
return props.rate > 0 ? true : false; | ||
}); | ||
const calcRate = computed(() => { | ||
const absRate = Math.abs(props.rate); | ||
if (!props.showZero && props.rate === 0) { | ||
return '--'; | ||
} | ||
let resultRate = `${props.showSign && props.rate !== 0 ? (isPositive.value ? '+' : '-') : ''}${myFixed( | ||
Number(absRate), | ||
props.digits | ||
)}%`; | ||
return resultRate; | ||
}); | ||
const calcStyle = computed(() => { | ||
return { | ||
color: | ||
props.rate === 0 | ||
? props.textColor | ||
: props.syncTextColor | ||
? isPositive.value | ||
? props.riseColor | ||
: props.dropColor | ||
: props.textColor | ||
}; | ||
}); | ||
</script> |
Oops, something went wrong.