311 lines
7.4 KiB
Vue
311 lines
7.4 KiB
Vue
<template>
|
||
<view :style="componentStyle" data-component-name="diy-digit">
|
||
<scroll-view :class="['graphic-nav', value.showStyle == 'fixed' ? 'fixed-layout' : value.showStyle]"
|
||
:scroll-x="value.showStyle == 'singleSlide'">
|
||
<view class="uni-scroll-view-content">
|
||
<view v-for="(item, index) in value.list" :key="index"
|
||
:class="['graphic-nav-item', value.mode, value.mode === 'text' ? 'newright' : '']"
|
||
:style="itemStyle">
|
||
<view :style="innerWrapStyle">
|
||
<view :style="innerRowStyle">
|
||
<uv-count-to :ref="`countTo-${index}`" :autoplay="true" :startVal="30" :endVal="item.title"
|
||
:decimals="getvalue(item.title)" decimal="."
|
||
:color="value.font.titlecolor"
|
||
:fontSize="titleFontSize"
|
||
:bold="isBold(value.font.weight)"></uv-count-to>
|
||
<text :style="unitStyle">{{ item.unit }}</text>
|
||
</view>
|
||
</view>
|
||
<view class="graphic-text">
|
||
<text :style="descStyle">{{ item.desc }}</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</scroll-view>
|
||
<ns-login ref="login"></ns-login>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import DiyMinx from './minx.js'
|
||
// 自定义数字展示
|
||
export default {
|
||
name: 'diy-digit',
|
||
props: {
|
||
value: {
|
||
type: Object,
|
||
default: () => ({})
|
||
}
|
||
},
|
||
mixins: [DiyMinx],
|
||
data() {
|
||
return {
|
||
pageWidth: '',
|
||
indicatorDots: false,
|
||
swiperCurrent: 0
|
||
// #ifndef MP
|
||
,windowWidth: 375
|
||
// #endif
|
||
}
|
||
},
|
||
created() {
|
||
// 组件创建时的逻辑
|
||
// #ifndef MP
|
||
try {
|
||
let info = uni.getSystemInfoSync();
|
||
this.windowWidth = info.windowWidth || info.screenWidth || 375;
|
||
if (this.windowWidth > 960) this.windowWidth = 375;
|
||
} catch (e) { }
|
||
// #endif
|
||
},
|
||
watch: {
|
||
componentRefresh(newValue) {
|
||
// 监听组件刷新
|
||
}
|
||
},
|
||
computed: {
|
||
// 全部返回字符串:WeChat 小程序的 style="{{obj}}" 对象绑定不会被运行时正确解析为内联 CSS
|
||
//(参考 diy-graphic-nav.vue:那里同样用字符串拼接 style="{{'width:...%'}}",能正常生效)。
|
||
// 字符串既能被 MP 直接当 cssText,也能被 H5 的 CSSOM 正确解析。
|
||
itemStyle() {
|
||
return 'width:' + (100 / this.value.rowCount) + '%;';
|
||
},
|
||
innerWrapStyle() {
|
||
return 'display:flex;justify-content:center;align-items:center;width:100%;';
|
||
},
|
||
innerRowStyle() {
|
||
return 'display:flex;align-items:baseline;justify-content:center;width:100%;line-height:1.2;';
|
||
},
|
||
unitStyle() {
|
||
// #ifdef MP
|
||
return 'margin-left:4rpx;font-size:' + (this.value.font.unitsize * 2) + 'rpx;font-weight:' + this.value.font.weight + ';color:' + this.value.font.unitcolor + ';';
|
||
// #endif
|
||
// #ifndef MP
|
||
return 'margin-left:' + this.rpxToPx(4) + 'px;font-size:' + this.rpxToPx((Number(this.value.font.unitsize) || 12) * 2) + 'px;font-weight:' + this.value.font.weight + ';color:' + this.value.font.unitcolor + ';';
|
||
// #endif
|
||
},
|
||
descStyle() {
|
||
// #ifdef MP
|
||
return 'font-size:' + (this.value.font.descsize * 2) + 'rpx;font-weight:' + this.value.font.weight + ';color:' + this.value.font.desccolor + ';';
|
||
// #endif
|
||
// #ifndef MP
|
||
return 'font-size:' + this.rpxToPx((Number(this.value.font.descsize) || 12) * 2) + 'px;font-weight:' + this.value.font.weight + ';color:' + this.value.font.desccolor + ';';
|
||
// #endif
|
||
},
|
||
titleFontSize() {
|
||
// #ifdef MP
|
||
return this.value.font.titlesize || 22;
|
||
// #endif
|
||
// #ifndef MP
|
||
return this.rpxToPx((Number(this.value.font.titlesize) || 22) * 2);
|
||
// #endif
|
||
},
|
||
componentStyle() {
|
||
let style = '';
|
||
style += 'background-image:url(' + this.$util.img(this.value.imageUrl) + ');background-size:100% 100%;';
|
||
|
||
if (this.value.componentAngle == 'round') {
|
||
style += 'border-top-left-radius:' + (2 * this.value.topAroundRadius) + 'rpx;';
|
||
style += 'border-top-right-radius:' + (2 * this.value.topAroundRadius) + 'rpx;';
|
||
style += 'border-bottom-left-radius:' + (2 * this.value.bottomAroundRadius) + 'rpx;';
|
||
style += 'border-bottom-right-radius:' + (2 * this.value.bottomAroundRadius) + 'rpx;';
|
||
}
|
||
|
||
style += 'box-shadow:' + (this.value.ornament.type == 'shadow' ? '0 0 10rpx ' + this.value.ornament.color : '') + ';';
|
||
style += 'border:' + (this.value.ornament.type == 'stroke' ? '2rpx solid ' + this.value.ornament.color : '') + ';';
|
||
|
||
return style;
|
||
}
|
||
},
|
||
methods: {
|
||
// #ifndef MP
|
||
// rpx -> px:H5 行内样式里的 rpx 不生效,统一换算成 px
|
||
rpxToPx(rpx) {
|
||
let num = Number(rpx) || 0;
|
||
if (!num) return 0;
|
||
return Math.round((num * (this.windowWidth || 375) / 750) * 100) / 100;
|
||
},
|
||
// #endif
|
||
|
||
// 获取小数位数
|
||
getvalue(value) {
|
||
return value % 1 !== 0 ? 2 : 0;
|
||
},
|
||
|
||
// 是否加粗
|
||
isBold(weight) {
|
||
return weight === 'bold' || (weight && Number(weight) >= 600);
|
||
},
|
||
|
||
// 页面跳转
|
||
redirectTo(item) {
|
||
if (!item.wap_url || this.$util.getCurrRoute() != this.$util.MEMBER_PAGE_URL || this.storeToken) {
|
||
this.$util.diyRedirectTo(item);
|
||
} else {
|
||
this.$refs.login.open(item.wap_url);
|
||
}
|
||
},
|
||
|
||
// 轮播切换
|
||
swiperChange(event) {
|
||
this.swiperCurrent = event.detail.current;
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.graphic-nav {
|
||
padding: 16rpx;
|
||
box-sizing: border-box;
|
||
|
||
&.fixed-layout {
|
||
.uni-scroll-view-content {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
}
|
||
}
|
||
|
||
&.singleSlide {
|
||
.uni-scroll-view-content {
|
||
display: flex;
|
||
}
|
||
|
||
.graphic-nav-item {
|
||
flex-shrink: 0;
|
||
}
|
||
}
|
||
|
||
&.pageSlide {
|
||
position: relative;
|
||
|
||
.uni-swiper-dots-horizontal {
|
||
bottom: 0rpx;
|
||
}
|
||
|
||
&.straightLine {
|
||
.uni-swiper-dot {
|
||
width: 30rpx;
|
||
border-radius: 0;
|
||
height: 8rpx;
|
||
}
|
||
}
|
||
|
||
&.circle {
|
||
.uni-swiper-dot {
|
||
width: 14rpx;
|
||
height: 14rpx;
|
||
}
|
||
}
|
||
}
|
||
|
||
.graphic-nav-wrap {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
width: 100%;
|
||
height: 100%;
|
||
}
|
||
|
||
.graphic-nav-item {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
padding: 14rpx 0;
|
||
box-sizing: border-box;
|
||
|
||
.graphic-text {
|
||
line-height: 1.3;
|
||
white-space: nowrap;
|
||
text-overflow: ellipsis;
|
||
overflow: hidden;
|
||
width: 100%;
|
||
text-align: center;
|
||
|
||
&.alone {
|
||
padding-top: 0;
|
||
}
|
||
}
|
||
|
||
&.text {
|
||
.graphic-text {
|
||
padding-top: 0;
|
||
}
|
||
}
|
||
|
||
.graphic-img {
|
||
position: relative;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 100rpx;
|
||
height: 100rpx;
|
||
font-size: 90rpx;
|
||
|
||
.tag {
|
||
position: absolute;
|
||
top: -10rpx;
|
||
right: -24rpx;
|
||
color: #fff;
|
||
border-radius: 24rpx;
|
||
border-bottom-left-radius: 0;
|
||
-webkit-transform: scale(0.8);
|
||
transform: scale(0.8);
|
||
padding: 8rpx 16rpx;
|
||
line-height: 1;
|
||
font-size: 24rpx;
|
||
}
|
||
|
||
.icon {
|
||
font-size: 50rpx;
|
||
color: #606266;
|
||
}
|
||
}
|
||
}
|
||
|
||
&.pageSlide {
|
||
.graphic-nav-item {
|
||
flex-shrink: 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
.newright {
|
||
margin-right: 16rpx;
|
||
}
|
||
|
||
.swiper-dot-box {
|
||
width: 100%;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
margin-top: -20rpx;
|
||
padding-bottom: 8rpx;
|
||
|
||
.swiper-dot {
|
||
background-color: rgba(0, 0, 0, 0.3);
|
||
margin: 8rpx;
|
||
|
||
&.active {
|
||
background-color: #000;
|
||
}
|
||
}
|
||
|
||
&.straightLine {
|
||
.swiper-dot {
|
||
width: 30rpx;
|
||
border-radius: 0;
|
||
height: 8rpx;
|
||
}
|
||
}
|
||
|
||
&.circle {
|
||
.swiper-dot {
|
||
width: 15rpx;
|
||
border-radius: 50%;
|
||
height: 15rpx;
|
||
}
|
||
}
|
||
}
|
||
|
||
</style>
|