前言
由于一些定制化的需求无法在网上直接找到可用插件来实现,只能DIY设计实现,如以下步骤条。
一、首先设计子组件
(1)【/src/Example/DiyStep/component/SkyStep.vue】
<template>
<div>
<ul class="diy-steps">
<li v-for="(item, index) in stepList" :key="index">
<div class="diy-step">
<div class="diy-step-line_left" v-if="index === 0 && item.status === 'undone'" :style="'background-image: linear-gradient(' + '90deg' + ', #ffffff, #bbbbbb)'"/>
<div class="diy-step-line_left" v-if="index === 0 && item.status !== 'undone'" :style="'background-image: linear-gradient(' + '90deg' + ', #ffffff, #4cb45b)'"/>
<div class="diy-step-line_left" v-else-if="index !== 0 && item.status === 'undone'" :style="'background-image: linear-gradient(' + '0deg' + ', #bbbbbb, #bbbbbb)'"/>
<div class="diy-step-line_left" v-else-if="index !== 0 && item.status !== 'undone'" :style="'background-image: linear-gradient(' + '0deg' + ', #4cb45b, #4cb45b)'"/>
<div class="diy-step-box diy-step__success" v-if="item.status === 'success'">
<span>
<i class="el-icon-check"></i>
</span>
<strong>{
{ item.label }}</strong>
</div>
<div class="diy-step-box diy-step__fail" v-else-if="item.status === 'fail'">
<span>
<i class="el-icon-close"></i>
</span>
<strong>{
{ item.label }}</strong>
</div>
<div class="diy-step-box diy-step__doing" v-else-if="item.status === 'doing'">
<span>
<i class=""></i>
</span>
<strong>{
{ item.label }}</strong>
</div>
<div class="diy-step-box diy-step__undone" v-else-if="item.status === 'undone'">
<span>
<i class=""></i>
</span>
<strong>{
{ item.label }}</strong>
</div>
<div class="diy-step-line_right" v-if="index === stepList.length - 1 && item.status === 'success'" :style="'background-image: linear-gradient(' + '90deg' + ', #4cb45b, #ffffff)'"/>
<div class="diy-step-line_right" v-else-if="index === stepList.length - 1 && item.status === 'fail'" :style="'background-image: linear-gradient(' + '90deg' + ', #4cb45b, #ffffff)'"/>
<div class="diy-step-line_right" v-else-if="index === stepList.length - 1 && item.status === 'doing'" :style="'background-image: linear-gradient(' + '90deg' + ', #bbbbbb, #ffffff)'"/>
<div class="diy-step-line_right" v-else-if="index === stepList.length - 1 && item.status === 'undone'" :style="'background-image: linear-gradient(' + '90deg' + ', #bbbbbb, #ffffff)'"/>
<div class="diy-step-line_right" v-else-if="index !== stepList.length - 1 && item.status === 'undone' && (index + 1 <= stepList.length - 1) && stepList[index + 1].status === 'undone' " :style="'background-image: linear-gradient(' + '180deg' + ', #bbbbbb, #bbbbbb)'"/>
<div class="diy-step-line_right" v-else-if="index !== stepList.length - 1 && item.status !== 'undone' && (index + 1 <= stepList.length - 1) && stepList[index + 1].status === 'undone' " :style="'background-image: linear-gradient(' + '180deg' + ', #bbbbbb, #bbbbbb)'"/>
<div class="diy-step-line_right" v-else-if="index !== stepList.length - 1 && item.status !== 'undone' && (index + 1 <= stepList.length - 1) && stepList[index + 1].status !== 'undone' " :style="'background-image: linear-gradient(' + '180deg' + ', #4cb45b, #4cb45b)'"/>
</div>
</li>
</ul>
</div>
</template>
<script>
export default {
props: ['stepList'],
data: () => ({
// stepList : [
// {label: '准备好所有的食材', status: 'success'},
// {label: '把茶叶和白砂糖放入锅中', status: 'success'},
// {label: '将其翻炒至冒泡', status: 'fail'},
// {label: '加入白开水煮沸', status: 'doing'},
// {label: '倒入纯牛奶', status: 'undone'},
// {label: '滤出茶叶就好了', status: 'undone'}
// ],
})
}
</script>
<style lang="less">
.diy-steps {
display: flex;
width: 100%;
height: 55px;
margin: 15px auto 0 auto;
padding: 0;
position: relative;
font-family: "微软雅黑";
overflow: hidden;
}
.diy-steps li {
width: auto;
height: 100%;
flex: 1;
list-style-type: none;
font-size: 12px;
text-align: center;
position: relative;
float: left;
}
.diy-steps li .diy-step {
width: 100%;
display: inline-block;
position: relative;
z-index: 1;
}
.diy-step-line_left {
border-bottom: 1px solid transparent;
background-image: linear-gradient(90deg, #bbbbbb, #4cb45b);
width: 50%;
height: 1px;
display: inline-block;
position: absolute;
top: 9px;
left: 0;
z-index: 0;
}
.diy-step-line_right {
border-bottom: 1px solid transparent;
background-image: linear-gradient(180deg, #bbbbbb, #4cb45b);
width: 50%;
height: 1px;
display: inline-block;
position: absolute;
top: 9px;
right: 0;
z-index: 0;
}
.diy-steps li .diy-step .diy-step-box {
position: relative;
z-index: 1;
}
.diy-steps li .diy-step .diy-step-box span {
display: block;
width: 13px;
height: 13px;
border-radius: 100%;
color: #fff;
/* transform: scale(1.2); */
text-align: center;
margin: 0 auto 8px auto;
}
.diy-steps li .diy-step .diy-step-box span i {
display: block;
width: 13px;
height: 13px;
border-radius: 100%;
line-height: 13px;
}
.diy-steps li .diy-step .diy-step-box strong {
letter-spacing: 0.5px;
}
/* diy-step__success */
.diy-step__success span {
border: rgba(55, 171, 71, 0.2) 4px solid;
border: rgb(215 238 218) 4px solid;
}
.diy-step__success span i {
background-color: #37ab47;
}
.diy-step__success strong {
color: #37ab47;
}
/* / diy-step__success */
/* diy-step__fail */
.diy-step__fail span {
border: rgba(252, 94, 90, 0.2) 4px solid;
border: rgb(254 223 222) 4px solid;
}
.diy-step__fail span i {
background-color: #fc5e5a;
}
.diy-step__fail strong {
color: #fc5e5a;
}
/* / diy-step__fail */
/* diy-step__doing */
.diy-step__doing span {
border: rgba(94, 124, 224, 0.2) 4px solid;
border: rgb(223 229 249) 4px solid;
}
.diy-step__doing span i {
background-color: #5e7ce0;
}
.diy-step__doing strong {
color: #5e7ce0;
}
/* / diy-step__doing */
/* diy-step__undone */
.diy-step__undone span {
border: rgba(153, 153, 153, 0.2) 4px solid;
border: rgb(235 235 235) 4px solid;
}
.diy-step__undone span i {
background-color: #999999;
}
.diy-step__undone strong {
color: #999999;
}
/* / diy-step__undone */
</style>
二、然后实现父页面
(2)【/src/Example/DiyStep/index.vue】
<template>
<div>
<SkyStep :stepList="stepList1"/>
<SkyStep :stepList="stepList2"/>
<SkyStep :stepList="stepList3"/>
<SkyStep :stepList="stepList4"/>
<SkyStep :stepList="stepList5"/>
<SkyStep :stepList="stepList6"/>
<SkyStep :stepList="stepList7"/>
</div>
</template>
<script>
import SkyStep from './components/SkyStep.vue'
export default {
components: {
SkyStep
},
data: () => ({
stepList1: [
{
label: '准备好所有的食材', status: 'doing' },
{
label: '把茶叶和白砂糖放入锅中', status: 'undone' },
{
label: '将其翻炒至冒泡', status: 'undone' },
{
label: '加入白开水煮沸', status: 'undone' },
{
label: '倒入纯牛奶', status: 'undone' },
{
label: '滤出茶叶就好了', status: 'undone' }
],
stepList2: [
{
label: '准备好所有的食材', status: 'success' },
{
label: '把茶叶和白砂糖放入锅中', status: 'doing' },
{
label: '将其翻炒至冒泡', status: 'undone' },
{
label: '加入白开水煮沸', status: 'undone' },
{
label: '倒入纯牛奶', status: 'undone' },
{
label: '滤出茶叶就好了', status: 'undone' }
],
stepList3: [
{
label: '准备好所有的食材', status: 'success' },
{
label: '把茶叶和白砂糖放入锅中', status: 'fail' },
{
label: '将其翻炒至冒泡', status: 'doing' },
{
label: '加入白开水煮沸', status: 'undone' },
{
label: '倒入纯牛奶', status: 'undone' },
{
label: '滤出茶叶就好了', status: 'undone' }
],
stepList4: [
{
label: '准备好所有的食材', status: 'success' },
{
label: '把茶叶和白砂糖放入锅中', status: 'success' },
{
label: '将其翻炒至冒泡', status: 'fail' },
{
label: '加入白开水煮沸', status: 'doing' },
{
label: '倒入纯牛奶', status: 'undone' },
{
label: '滤出茶叶就好了', status: 'undone' }
],
stepList5: [
{
label: '准备好所有的食材', status: 'success' },
{
label: '把茶叶和白砂糖放入锅中', status: 'success' },
{
label: '将其翻炒至冒泡', status: 'success' },
{
label: '加入白开水煮沸', status: 'fail' },
{
label: '倒入纯牛奶', status: 'doing' },
{
label: '滤出茶叶就好了', status: 'undone' }
],
stepList6: [
{
label: '准备好所有的食材', status: 'success' },
{
label: '把茶叶和白砂糖放入锅中', status: 'success' },
{
label: '将其翻炒至冒泡', status: 'success' },
{
label: '加入白开水煮沸', status: 'success' },
{
label: '倒入纯牛奶', status: 'fail' },
{
label: '滤出茶叶就好了', status: 'doing' }
],
stepList7: [
{
label: '准备好所有的食材', status: 'success' },
{
label: '把茶叶和白砂糖放入锅中', status: 'success' },
{
label: '将其翻炒至冒泡', status: 'success' },
{
label: '加入白开水煮沸', status: 'success' },
{
label: '倒入纯牛奶', status: 'success' },
{
label: '滤出茶叶就好了', status: 'success' }
]
})
}
</script>
<style lang="less" scoped>
</style>