趨勢標(biāo)記

一、圖標(biāo)的組合使用實(shí)現(xiàn)上升下降趨勢

(1)component/trend/src/index.vue

<!--
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-06-09 20:11:37
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-06-10 10:02:45
 * @FilePath: \mm-components\src\components\trend\src\index.vue
 * @Description: 這是默認(rèn)設(shè)置,請?jiān)O(shè)置`customMade`, 打開koroFileHeader查看配置 進(jìn)行設(shè)置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div class="trend">
        <div class="text">
            {{text}}
        </div>
        <div class="icon">
            <el-icon-arrowup :style="{color:upIconColor}" v-if="type === 'up'" />
            <el-icon-arrowdown :style="{color:downIconColor}"  v-else />
        </div>
    </div>
</template>

<script lang="ts" setup>
let props = defineProps({
    // 標(biāo)記當(dāng)前趨勢是上升(up)還是下降(down)
    type:{
        type:String,
        default:'up'
    },
    // 趨勢顯示文字
    // 1.父組件傳遞過來的數(shù)據(jù)
    // 2,插槽
    text:{
        type:String,
        default:'文字'
    },
    // 上升趨勢圖標(biāo)顏色
    upIconColor:{
        type:String,
        default:'#f5222d'
    },
    // 上升趨勢圖標(biāo)顏色
    downIconColor:{
        type:String,
        default:'#52c41a'
    }
})
</script>

<style lang="scss" scoped>
.trend{
    display: flex;
    align-items: center;
}
.text{
    font-size: 12px;
    margin-right: 4px;
}
.icon{
    height: 0.8em;
    width: 0.8em;
}
</style>

(2)views/trend/index.vue

<!--
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-06-09 20:27:32
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-06-10 10:08:40
 * @FilePath: \mm-components\src\views\trend\index.vue
 * @Description: 這是默認(rèn)設(shè)置,請?jiān)O(shè)置`customMade`, 打開koroFileHeader查看配置 進(jìn)行設(shè)置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <div class="flex">
            <div><m-trend text="營業(yè)額"></m-trend></div>
            <div><m-trend text="銷售額" type="down"></m-trend></div>
        </div>
        <br>
        <div class="flex">
            <div><m-trend text="營業(yè)額" upIconColor="red"></m-trend></div>
            <div><m-trend text="銷售額" type="down" downIconColor="#5dcc92"></m-trend></div>
        </div>
        
    </div>
</template>

<script lang="ts" setup>

</script>

<style lang="scss" scoped>
.flex{
    display: flex;
    div{
        margin-right: 10px;
    }
}
</style>

(3)界面效果


trend1.png
將圖標(biāo)顏色設(shè)置成屬性,便于后續(xù)按照需求改變顏色

二嚎朽、動(dòng)態(tài)綁定class妙用實(shí)現(xiàn)顏色反轉(zhuǎn)耿导。

1.通過插槽slot來判斷text

 <slot v-if="slot.default"></slot>
 <div v-else>{{text}}</div>

獲取插槽內(nèi)容

let slot = useSlots()

2.實(shí)現(xiàn)顏色反轉(zhuǎn)富拗,
定義屬性

 reverseColor:{
        type:Boolean,
        default:false
    },

使用

<div class="icon">
            <el-icon-arrowup :style="{color: !reverseColor ? upIconColor:'#52c41a'}" v-if="type === 'up'" />
            <el-icon-arrowdown :style="{color: !reverseColor ? downIconColor:'#f5222d'}"  v-else />
</div>

(1)component/trend/src/index.vue

<!--
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-06-09 20:11:37
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-06-10 11:25:30
 * @FilePath: \mm-components\src\components\trend\src\index.vue
 * @Description: 這是默認(rèn)設(shè)置,請?jiān)O(shè)置`customMade`, 打開koroFileHeader查看配置 進(jìn)行設(shè)置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div class="trend">
        <div class="text">
            
            <slot v-if="slot.default"></slot>
            <div v-else>{{text}}</div>
        </div>
        <div class="icon">
            <el-icon-arrowup :style="{color: !reverseColor ? upIconColor:'#52c41a'}" v-if="type === 'up'" />
            <el-icon-arrowdown :style="{color: !reverseColor ? downIconColor:'#f5222d'}"  v-else />
        </div>
    </div>
</template>

<script lang="ts" setup>
import { onMounted, useSlots } from "@vue/runtime-core"


let slot = useSlots()
console.log(slot)

let props = defineProps({
    // 標(biāo)記當(dāng)前趨勢是上升(up)還是下降(down)
    type:{
        type:String,
        default:'up'
    },
    // 趨勢顯示文字
    // 1.父組件傳遞過來的數(shù)據(jù)
    // 2,插槽
    text:{
        type:String,
        default:'文字'
    },
    // 顏色反轉(zhuǎn)只在默認(rèn)的顏色下生效粟矿, 如果使用了自定義顏色磕道,這個(gè)屬性就不生效了
    reverseColor:{
        type:Boolean,
        default:false
    },

    // 上升趨勢圖標(biāo)顏色
    upIconColor:{
        type:String,
        default:'#f5222d'
    },
    // 上升趨勢圖標(biāo)顏色
    downIconColor:{
        type:String,
        default:'#52c41a'
    }
})

</script>

<style lang="scss" scoped>
.trend{
    display: flex;
    align-items: center;
}
.text{
    font-size: 12px;
    margin-right: 4px;
}
.icon{
    svg{
        height: 0.8em;
        width: 0.8em;
    }
    
}
</style>

(2)views/trend/index.vue

<m-trend text="銷售額" reverseColor></m-trend>
<m-trend text="營業(yè)額" type="down" reverseColor></m-trend>
trend2.png

三、計(jì)算屬性的妙用實(shí)現(xiàn)文字顏色

1.定義屬性

// 上升趨勢文字顏色
    upTextColor:{
        type:String,
        default:'rgb(0,0,0)'
    },
    // 下降趨勢文字顏色
    downTextColor:{
        type:String,
        default:'rgb(0,0,0)'
    }

2.調(diào)用計(jì)算屬性

// 文字顏色
let textColor = computed(()=>{
    return props.type === 'up' ? props.upTextColor : props.downTextColor
})

3.動(dòng)態(tài)綁定文字顏色樣式

<el-icon-arrowup :style="{color: !reverseColor ? upIconColor:'#52c41a'}" v-if="type === 'up'" />
<el-icon-arrowdown :style="{color: !reverseColor ? downIconColor:'#f5222d'}"  v-else />

四讳侨、圖標(biāo)自定義

1.定義圖標(biāo)屬性

// 上升趨勢顯示的圖標(biāo)
    upIcon:{
        type:String,
        default:'ArrowUp'
    },

    // 下降趨勢顯示的圖標(biāo)
    downIcon:{
        type:String,
        default:'ArrowDown'
    },

2.使用自定義圖標(biāo)動(dòng)態(tài)顯示呵萨,使用component動(dòng)態(tài)組件
(toLine方法是之前編寫的處理圖標(biāo)的函數(shù),記得引入)

<component 
  :is="`el-icon-${toLine(upIcon)}`"
  :style="{color: !reverseColor ? upIconColor:'#52c41a'}" 
   v-if="type === 'up'"
>
  </component>
 <component 
    :is="`el-icon-${toLine(downIcon)}`"
    :style="{color: !reverseColor ? downIconColor:'#f5222d'}" 
    v-else
>
</component>

3.views/trend/inde.vue模板調(diào)用實(shí)現(xiàn)

<m-trend upIcon="CaretTop">營業(yè)額</m-trend>
        <m-trend type="down" downIcon="CaretBottom">銷售額</m-trend>

4.完整代碼
(1)component/trend/src/index.vue

<!--
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-06-09 20:11:37
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-06-10 11:58:58
 * @FilePath: \mm-components\src\components\trend\src\index.vue
 * @Description: 這是默認(rèn)設(shè)置,請?jiān)O(shè)置`customMade`, 打開koroFileHeader查看配置 進(jìn)行設(shè)置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div class="trend">
        <div class="text" :style="{color:textColor}">
            
            <slot v-if="slot.default"></slot>
            <div v-else>{{text}}</div>
        </div>
        <div class="icon">
            <!-- <el-icon-arrowup :style="{color: !reverseColor ? upIconColor:'#52c41a'}" v-if="type === 'up'" />
            <el-icon-arrowdown :style="{color: !reverseColor ? downIconColor:'#f5222d'}"  v-else /> -->
            <component 
                :is="`el-icon-${toLine(upIcon)}`"
                :style="{color: !reverseColor ? upIconColor:'#52c41a'}" 
                v-if="type === 'up'"
            >
            </component>
            <component 
                :is="`el-icon-${toLine(downIcon)}`"
                :style="{color: !reverseColor ? downIconColor:'#f5222d'}" 
                v-else
            >
            </component>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { computed, onMounted, useSlots } from "@vue/runtime-core"
import {toLine} from '../../../utils/index'
// 獲取插槽內(nèi)容
let slot = useSlots()
console.log(slot)

let props = defineProps({
    // 標(biāo)記當(dāng)前趨勢是上升(up)還是下降(down)
    type:{
        type:String,
        default:'up'
    },
    // 上升趨勢顯示的圖標(biāo)
    upIcon:{
        type:String,
        default:'ArrowUp'
    },

    // 下降趨勢顯示的圖標(biāo)
    downIcon:{
        type:String,
        default:'ArrowDown'
    },

    // 趨勢顯示文字
    // 1.父組件傳遞過來的數(shù)據(jù)
    // 2,插槽
    text:{
        type:String,
        default:'文字'
    },
    // 顏色反轉(zhuǎn)只在默認(rèn)的顏色下生效爷耀, 如果使用了自定義顏色甘桑,這個(gè)屬性就不生效了
    reverseColor:{
        type:Boolean,
        default:false
    },

    // 上升趨勢圖標(biāo)顏色
    upIconColor:{
        type:String,
        default:'#f5222d'
    },
    // 下降趨勢圖標(biāo)顏色
    downIconColor:{
        type:String,
        default:'#52c41a'
    },

    // 上升趨勢文字顏色
    upTextColor:{
        type:String,
        default:'rgb(0,0,0)'
    },
    // 下降趨勢文字顏色
    downTextColor:{
        type:String,
        default:'rgb(0,0,0)'
    }
})

// 文字顏色
let textColor = computed(()=>{
    return props.type === 'up' ? props.upTextColor : props.downTextColor
})
</script>

<style lang="scss" scoped>
.trend{
    display: flex;
    align-items: center;
}
.text{
    font-size: 12px;
    margin-right: 4px;
}
.icon{
    svg{
        height: 0.8em;
        width: 0.8em;
    }
    
}
</style>

(2)views/trend/index.vue

<!--
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-06-09 20:27:32
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-06-10 11:57:45
 * @FilePath: \mm-components\src\views\trend\index.vue
 * @Description: 這是默認(rèn)設(shè)置,請?jiān)O(shè)置`customMade`, 打開koroFileHeader查看配置 進(jìn)行設(shè)置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <!-- <div class="flex">
            <div><m-trend text="營業(yè)額"></m-trend></div>
            <div><m-trend text="銷售額" type="down"></m-trend></div>
        </div>
        <br>
        <div class="flex">
            <div><m-trend text="營業(yè)額" upIconColor="red"></m-trend></div>
            <div><m-trend text="銷售額" type="down" downIconColor="#5dcc92"></m-trend></div>
        </div> -->

        <!-- <m-trend text="銷售額" reverseColor></m-trend>
        <m-trend text="營業(yè)額" type="down" reverseColor></m-trend>
         -->

         <!-- <m-trend text="營業(yè)額" upTextColor="blue"></m-trend>
         <m-trend text="銷售額" type="down" downTextColor="yellow"></m-trend> -->
        <m-trend upIcon="CaretTop">營業(yè)額</m-trend>
        <m-trend type="down" downIcon="CaretBottom">銷售額</m-trend>
    </div>
</template>

<script lang="ts" setup>

</script>

<style lang="scss" scoped>
.flex{
    display: flex;
    div{
        margin-right: 10px;
    }
}
</style>

5.界面效果


trend3.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市歹叮,隨后出現(xiàn)的幾起案子跑杭,更是在濱河造成了極大的恐慌,老刑警劉巖咆耿,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件德谅,死亡現(xiàn)場離奇詭異,居然都是意外死亡萨螺,警方通過查閱死者的電腦和手機(jī)窄做,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來慰技,“玉大人椭盏,你說我怎么就攤上這事∥巧蹋” “怎么了掏颊?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵,是天一觀的道長艾帐。 經(jīng)常有香客問我乌叶,道長,這世上最難降的妖魔是什么柒爸? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任准浴,我火速辦了婚禮,結(jié)果婚禮上捎稚,老公的妹妹穿的比我還像新娘乐横。我一直安慰自己,他們只是感情好阳藻,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布晰奖。 她就那樣靜靜地躺著,像睡著了一般腥泥。 火紅的嫁衣襯著肌膚如雪匾南。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天蛔外,我揣著相機(jī)與錄音蛆楞,去河邊找鬼溯乒。 笑死,一個(gè)胖子當(dāng)著我的面吹牛豹爹,可吹牛的內(nèi)容都是我干的裆悄。 我是一名探鬼主播,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼臂聋,長吁一口氣:“原來是場噩夢啊……” “哼光稼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起孩等,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤艾君,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后肄方,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體冰垄,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年权她,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了虹茶。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,040評論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡隅要,死狀恐怖蝴罪,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情步清,我是刑警寧澤洲炊,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站尼啡,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏询微。R本人自食惡果不足惜崖瞭,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望撑毛。 院中可真熱鬧书聚,春花似錦、人聲如沸藻雌。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽胯杭。三九已至驯杜,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間做个,已是汗流浹背鸽心。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工滚局, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人顽频。 一個(gè)月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓藤肢,卻偏偏與公主長得像,于是被迫代替她去往敵國和親糯景。 傳聞我的和親對象是個(gè)殘疾皇子嘁圈,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,979評論 2 355

推薦閱讀更多精彩內(nèi)容