增加滚动提示组件

This commit is contained in:
BianLzhaoMin 2024-12-10 09:19:55 +08:00
parent e60bd7ef76
commit 9efd40232f
4 changed files with 217 additions and 33 deletions

View File

@ -4,16 +4,22 @@
"version" : "0.0", "version" : "0.0",
"configurations" : [ "configurations" : [
{ {
"app-plus" : { "app-plus" :
{
"launchtype" : "local" "launchtype" : "local"
}, },
"default" : { "default" :
{
"launchtype" : "local"
},
"mp-weixin" :
{
"launchtype" : "local" "launchtype" : "local"
}, },
"type" : "uniCloud" "type" : "uniCloud"
}, },
{ {
"playground" : "standard", "playground" : "custom",
"type" : "uni-app:app-android" "type" : "uni-app:app-android"
} }
] ]

View File

@ -0,0 +1,129 @@
<template>
<view class="notice-bar-container">
<view class="notice-bar-wrapper">
<view class="notice-bar-content" :style="scrollStyle">
<text v-for="(text, index) in textArray" :key="index" :style="textStyle[index]">
{{ text }}
</text>
</view>
</view>
</view>
</template>
<script>
export default {
props: {
textArray: {
type: Array,
default: () => []
},
textStyle: {
type: Array,
default: () => []
},
scrollSpeed: {
type: Number,
default: 1 //
}
},
data() {
return {
scrollPosition: 0, //
totalWidth: 0, //
containerWidth: 0, //
scrollInterval: null //
}
},
computed: {
// transform
scrollStyle() {
return {
transform: `translateX(${this.scrollPosition}px)`,
transition: 'transform 0s linear' // transition
}
}
},
mounted() {
this.calculateDimensions() //
},
methods: {
//
calculateDimensions() {
const query = uni.createSelectorQuery().in(this)
//
query
.select('.notice-bar-content')
.boundingClientRect(rect => {
this.totalWidth = rect.width
this.startScroll() //
})
.exec()
//
query
.select('.notice-bar-container')
.boundingClientRect(rect => {
this.containerWidth = rect.width
})
.exec()
},
//
startScroll() {
let currentPosition = 0 //
const speed = this.scrollSpeed
const updateScroll = () => {
//
currentPosition += speed
//
if (currentPosition >= this.totalWidth) {
currentPosition = 0 //
}
//
this.scrollPosition = -currentPosition
}
//
if (this.scrollInterval) {
clearInterval(this.scrollInterval) //
}
this.scrollInterval = setInterval(updateScroll, 20) // 20ms `scrollSpeed`
}
},
destroyed() {
if (this.scrollInterval) {
clearInterval(this.scrollInterval) //
}
}
}
</script>
<style scoped lang="scss">
.notice-bar-container {
width: 100%;
height: 100%;
overflow: hidden;
white-space: nowrap;
background-color: #fff; /* 可根据需要修改背景颜色 */
}
.notice-bar-wrapper {
display: flex;
align-items: center;
}
.notice-bar-content {
display: flex;
align-items: center;
white-space: nowrap;
height: 56rpx;
line-height: 56rpx;
text {
margin-left: 20rpx;
}
}
</style>

View File

@ -115,15 +115,26 @@
<!-- 风险提示 --> <!-- 风险提示 -->
<view class="today-warning"> <view class="today-warning">
<image class="warning-img" src="../../../static/images/img-phase-two/index_news.png" mode=""></image> <image class="warning-img" src="../../../static/images/img-phase-two/index_news.png" mode=""></image>
<text>今日风险</text> <text style="margin-right: 20rpx">今日风险</text>
<view class="uni-notice-bar" @tap="onJumpWorkPlan"> <view class="uni-notice-bar" @tap="onJumpWorkPlan">
<uni-notice-bar <!-- <uni-notice-bar
style="height: 100%" style="height: 100%"
:speed="30" :speed="30"
background-color="#fff" background-color="#fff"
scrollable scrollable
:text="noticeText" :text="noticeText"
></uni-notice-bar> ></uni-notice-bar> -->
<MultiColorNoticeBar
:textArray="[
`高风险:${highRiskNum}`,
`中风险:${mediumRiskNum}`,
`低风险:${lowRiskNum}`,
`作业计划人数:${planPersonNum}`
]"
:textStyle="[{ color: '#bc2843' }, { color: '#ffed51' }, { color: '#7dda76' }, { color: '#000000' }]"
:scrollSpeed="1"
/>
</view> </view>
</view> </view>
@ -352,6 +363,7 @@ import PieChartsModelRingTwo from './components/pie-charts-model-ring-two'
import PieChartsModelMan from './components/pie-charts-model-man.vue' import PieChartsModelMan from './components/pie-charts-model-man.vue'
import PieChartsModelGirl from './components/pie-charts-model-girl.vue' import PieChartsModelGirl from './components/pie-charts-model-girl.vue'
import { getHomePageListApi } from '@/api/phaseTwo/homePage' import { getHomePageListApi } from '@/api/phaseTwo/homePage'
import MultiColorNoticeBar from '../../../components/MultiColorNoticeBar'
export default { export default {
components: { components: {
@ -360,7 +372,8 @@ export default {
PieChartsModelRing, PieChartsModelRing,
PieChartsModelRingTwo, PieChartsModelRingTwo,
PieChartsModelMan, PieChartsModelMan,
PieChartsModelGirl PieChartsModelGirl,
MultiColorNoticeBar
}, },
data() { data() {
return { return {
@ -1064,7 +1077,7 @@ export default {
.today-warning { .today-warning {
margin: 30rpx 0; margin: 30rpx 0;
height: 68rpx; height: 68rpx;
padding: 0 30rpx; padding-left: 30rpx;
display: flex; display: flex;
align-items: center; align-items: center;
border: 1rpx solid #ccc; border: 1rpx solid #ccc;
@ -1077,8 +1090,10 @@ export default {
} }
.uni-notice-bar { .uni-notice-bar {
flex: 1; // flex: 1;
width: 65%;
height: 50rpx; height: 50rpx;
padding-left: 20rpx;
// line-height: 50rpx; // line-height: 50rpx;
// background-color: orange; // background-color: orange;
} }

View File

@ -2,22 +2,49 @@
<view class="notice-container"> <view class="notice-container">
<!-- <uni-notice-bar :showClose="showClose" :showIcon="showIcon" scrollable :text="noticeContent" /> --> <!-- <uni-notice-bar :showClose="showClose" :showIcon="showIcon" scrollable :text="noticeContent" /> -->
<image class="warning-img" src="../../../../static/images/img-phase-two/index_news.png" mode=""></image> <image class="warning-img" src="../../../../static/images/img-phase-two/index_news.png" mode=""></image>
<text>今日风险</text> <view style="width: 200rpx">今日风险</view>
<view class="uni-notice-bar" @tap="onViewRiskDetails">
<uni-notice-bar <!-- <MultiColorNoticeBar :speed="30" backgroundColor="#fff" @tap="onViewRiskDetails">
style="height: 100%" <text style="color: red">重要通知</text>
:speed="50" <text style="color: blue">这是一条</text>
scrollable <text style="color: green">多彩的</text>
:text="noticeContent" <text style="color: orange">滚动公告</text>
:showClose="showClose" <text style="color: orange">滚动公告</text>
:showIcon="showIcon" <text style="color: orange">滚动公告</text>
></uni-notice-bar> <text style="color: orange">滚动公告</text>
</MultiColorNoticeBar> -->
<view @tap="onViewRiskDetails" style="width: 70%">
<MultiColorNoticeBar
:textArray="[
`风险总数:${tfx} `,
`可接受风险:${kjs} `,
`低风险:${dfx} `,
`中风险:${zfx} `,
`高风险:${gfx} `,
`特高风险:${tfx} `
]"
:textStyle="[
{ color: '#000000' },
{ color: '#7dda76' },
{ color: '#7dda76' },
{ color: '#ffed51' },
{ color: '#bc2843' },
{ color: '#bc2843' }
]"
:scrollSpeed="1"
/>
</view> </view>
<!-- <view class="uni-notice-bar" >
</view> -->
</view> </view>
</template> </template>
<script> <script>
import { getTitleRiskApi } from '../../../../api/workPlan/homePage' import { getTitleRiskApi } from '../../../../api/workPlan/homePage'
import MultiColorNoticeBar from '../../../../components/MultiColorNoticeBar/index.vue'
export default { export default {
props: { props: {
// /* */ // /* */
@ -36,13 +63,17 @@ export default {
default: false default: false
} }
}, },
components: {
MultiColorNoticeBar
},
data() { data() {
return { return {
kjs: 0, kjs: 0,
dfx: 0, dfx: 0,
zfx: 0, zfx: 0,
gfx: 0, gfx: 0,
tfx: 0 tfx: 0,
amount: 0
} }
}, },
computed: { computed: {
@ -74,6 +105,8 @@ export default {
this.tfx = e.num * 1 this.tfx = e.num * 1
} }
}) })
this.amount = this.kjs + this.dfx + +this.zfx + this.gfx + this.tfx
} }
}, },
onViewRiskDetails() { onViewRiskDetails() {
@ -89,6 +122,7 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
.notice-container { .notice-container {
width: 100vw;
height: 56rpx; height: 56rpx;
margin: 20rpx 0; margin: 20rpx 0;
display: flex; display: flex;
@ -98,15 +132,15 @@ export default {
.warning-img { .warning-img {
width: 48rpx; width: 48rpx;
height: 48rpx; height: 48rpx;
}
.uni-notice-bar {
flex: 1;
height: 56rpx;
}
text {
margin: 0 10rpx; margin: 0 10rpx;
} }
// .uni-notice-bar {
// flex: 1;
// }
// text {
// margin: 0 10rpx;
// }
} }
</style> </style>