提交 3ed863e6 编写于 作者: VK1688's avatar VK1688

新增u-swiper-plus组件,支持视频轮播

上级 cebaf6eb
<template>
<view class="wrap">
<page-nav></page-nav>
<view class="list-wrap">
<u-cell-group title-bg-color="rgb(243, 244, 246)" :title="item.groupName" v-for="(item, index) in components" :key="index">
<u-cell-item :titleStyle="{ fontWeight: 500 }" @click="openPage(item1.path)" :title="item1.title" v-for="(item1, index1) in item.list" :key="index1">
<template v-slot:icon>
<image class="u-cell-icon" :src="getIcon(item1.icon)" mode="widthFix"></image>
</template>
</u-cell-item>
</u-cell-group>
</view>
<view class="other">
<u-alert-tips type="primary" title="其他组件的使用方法与之前一样!"></u-alert-tips>
</view>
<u-gap height="70"></u-gap>
<u-swiper-plus :list="list" :height="750" :indicator="true" indicatorMode="dot" :videoAutoplay="true" :videoMuted="false" :radius="0"></u-swiper-plus>
</view>
</template>
<script>
import components from "./components.config.js";
export default {
data() {
return {
components: components
list: [
{
url: 'https://mp-682ae78c-682a-45cd-a7d4-1289bec9cd4f.cdn.bspapp.com/cloudstorage/77c09154-caa4-4547-b300-b5e1d4ede958.mp4',
// poster: 'https://mp-682ae78c-682a-45cd-a7d4-1289bec9cd4f.cdn.bspapp.com/cloudstorage/9c2a399f-c4ae-4743-bbb4-dae4caf55e5a.png'
},
'https://mp-682ae78c-682a-45cd-a7d4-1289bec9cd4f.cdn.bspapp.com/cloudstorage/77c09154-caa4-4547-b300-b5e1d4ede958.mp4',
{
url: 'https://mp-682ae78c-682a-45cd-a7d4-1289bec9cd4f.cdn.bspapp.com/cloudstorage/9c2a399f-c4ae-4743-bbb4-dae4caf55e5a.png',
title: '身无彩凤双飞翼,心有灵犀一点通'
}, {
url: 'https://mp-682ae78c-682a-45cd-a7d4-1289bec9cd4f.cdn.bspapp.com/cloudstorage/9c2a399f-c4ae-4743-bbb4-dae4caf55e5a.png',
title: '谁念西风独自凉,萧萧黄叶闭疏窗,沉思往事立残阳'
}
]
};
},
methods: {
openPage(path) {
this.$u.route({
url: path
});
}
},
computed: {
getIcon() {
return path => {
return "https://cdn.uviewui.com/uview/example/" + path + ".png";
};
}
}
};
</script>
<style>
/* page {
background-color: rgb(240, 242, 244);
} */
</style>
<style lang="scss" scoped>
.u-cell-icon {
width: 36rpx;
height: 36rpx;
margin-right: 8rpx;
}
.other {
padding: 30rpx;
}
</style>
</style>
\ No newline at end of file
<template>
<view class="u-swiper-indicator">
<view
class="u-swiper-indicator__wrapper"
v-if="indicatorMode === 'line'"
:class="[`u-swiper-indicator__wrapper--${indicatorMode}`]"
:style="{
width: $u.addUnit(lineWidth * length),
backgroundColor: indicatorInactiveColor
}"
>
<view
class="u-swiper-indicator__wrapper--line__bar"
:style="[lineStyle]"
></view>
</view>
<view
class="u-swiper-indicator__wrapper"
v-if="indicatorMode === 'dot'"
>
<view
class="u-swiper-indicator__wrapper__dot"
v-for="(item, index) in length"
:key="index"
:class="[index === current && 'u-swiper-indicator__wrapper__dot--active']"
:style="[dotStyle(index)]"
>
</view>
</view>
</view>
</template>
<script>
/**
* SwiperIndicator 轮播图指示器
* @description 该组件一般用于导航轮播,广告展示等场景,可开箱即用,
* @tutorial https://www.uviewui.com/components/swiper.html
* @property {String | Number} length 轮播的长度(默认 0 )
* @property {String | Number} current 当前处于活动状态的轮播的索引(默认 0 )
* @property {String} indicatorActiveColor 指示器非激活颜色
* @property {String} indicatorInactiveColor 指示器的激活颜色
* @property {String} indicatorMode 指示器模式(默认 'line' )
* @example <u-swiper :list="list4" indicator keyName="url" :autoplay="false"></u-swiper>
*/
export default {
name: 'u-swiper-indicator',
props:{
// 轮播的长度
length: {
type: [String, Number],
default: 0
},
// 当前处于活动状态的轮播的索引
current: {
type: [String, Number],
default: 0
},
// 指示器非激活颜色
indicatorActiveColor: {
type: String,
default: ''
},
// 指示器的激活颜色
indicatorInactiveColor: {
type: String,
default: ''
},
// 指示器模式,line-线型,dot-点型
indicatorMode: {
type: String,
default: 'line'
}
},
data() {
return {
lineWidth: 22
}
},
computed: {
// 指示器为线型的样式
lineStyle() {
let style = {}
style.width = uni.$u.addUnit(this.lineWidth)
style.transform = `translateX(${ uni.$u.addUnit(this.current * this.lineWidth) })`
style.backgroundColor = this.indicatorActiveColor
return style
},
// 指示器为点型的样式
dotStyle() {
return index => {
let style = {}
style.backgroundColor = index === this.current ? this.indicatorActiveColor : this.indicatorInactiveColor
return style
}
}
},
}
</script>
<style lang="scss" scoped>
@import "../../../libs/css/style.components.scss";
.u-swiper-indicator {
&__wrapper {
@include vue-flex;
&--line {
border-radius: 100px;
height: 4px;
&__bar {
width: 22px;
height: 4px;
border-radius: 100px;
background-color: #FFFFFF;
transition: transform 0.3s;
}
}
&__dot {
width: 5px;
height: 5px;
border-radius: 100px;
margin: 0 4px;
&--active {
width: 12px;
}
}
}
}
</style>
......@@ -68,6 +68,8 @@ import {sys, os} from './libs/function/sys.js'
import debounce from './libs/function/debounce.js'
// 节流方法
import throttle from './libs/function/throttle.js'
// 对象转字符串,或者字符串转对象
import addStyle from './libs/function/addStyle.js'
// 配置信息
......@@ -111,6 +113,7 @@ const $u = {
zIndex,
debounce,
throttle,
addStyle
}
// $u挂载到uni对象上
......
import test from './test.js'
/**
* @description 样式转换
* 对象转字符串,或者字符串转对象
* @param {object | string} customStyle 需要转换的目标
* @param {String} target 转换的目的,object-转为对象,string-转为字符串
* @returns {object|string}
*/
function addStyle(customStyle, target = 'object') {
// 字符串转字符串,对象转对象情形,直接返回
if (test.empty(customStyle) || typeof(customStyle) === 'object' && target === 'object' || target === 'string' && typeof(customStyle) === 'string') {
return customStyle
}
// 字符串转对象
if (target === 'object') {
// 去除字符串样式中的两端空格(中间的空格不能去掉,比如padding: 20px 0如果去掉了就错了),空格是无用的
customStyle = trim(customStyle)
// 根据";"将字符串转为数组形式
const styleArray = customStyle.split(';')
const style = {}
// 历遍数组,拼接成对象
for (let i = 0; i < styleArray.length; i++) {
// 'font-size:20px;color:red;',如此最后字符串有";"的话,会导致styleArray最后一个元素为空字符串,这里需要过滤
if (styleArray[i]) {
const item = styleArray[i].split(':')
style[trim(item[0])] = trim(item[1])
}
}
return style
}
// 这里为对象转字符串形式
let string = ''
for (const i in customStyle) {
// 驼峰转为中划线的形式,否则css内联样式,无法识别驼峰样式属性名
const key = i.replace(/([A-Z])/g, '-$1').toLowerCase()
string += `${key}:${customStyle[i]};`
}
// 去除两端空格
return trim(string)
}
export default addStyle
......@@ -205,6 +205,56 @@ function code(value, len = 6) {
}
/**
* 是否函数方法
* @param {Object} value
*/
function func(value) {
return typeof value === 'function'
}
/**
* 是否promise对象
* @param {Object} value
*/
function promise(value) {
return object(value) && func(value.then) && func(value.catch)
}
/** 是否图片格式
* @param {Object} value
*/
function image(value) {
const newValue = value.split('?')[0]
const IMAGE_REGEXP = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i
return IMAGE_REGEXP.test(newValue)
}
/**
* 是否视频格式
* @param {Object} value
*/
function video(value) {
const VIDEO_REGEXP = /\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv|m3u8)/i
return VIDEO_REGEXP.test(value)
}
/**
* 是否为正则对象
* @param {Object}
* @return {Boolean}
*/
function regExp(o) {
return o && Object.prototype.toString.call(o) === '[object RegExp]'
}
/**
* 验证字符串
*/
function string(value) {
return typeof value === 'string'
}
export default {
email,
mobile,
......@@ -228,5 +278,11 @@ export default {
landline,
object,
array,
code
code,
func,
promise,
video,
image,
regExp,
string
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册