first commit
This commit is contained in:
49
uni_modules/tdesign-uniapp/components/swiper-nav/props.ts
Normal file
49
uni_modules/tdesign-uniapp/components/swiper-nav/props.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
|
||||
* */
|
||||
|
||||
import type { TdSwiperNavProps } from './type';
|
||||
export default {
|
||||
/** 当前轮播在哪一项(下标) */
|
||||
current: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
/** 轮播滑动方向,包括横向滑动和纵向滑动两个方向 */
|
||||
direction: {
|
||||
type: String,
|
||||
default: 'horizontal' as TdSwiperNavProps['direction'],
|
||||
validator(val: TdSwiperNavProps['direction']): boolean {
|
||||
if (!val) return true;
|
||||
return ['horizontal', 'vertical'].includes(val);
|
||||
},
|
||||
},
|
||||
/** 小于这个数字不会显示导航器 */
|
||||
minShowNum: {
|
||||
type: Number,
|
||||
default: 2,
|
||||
},
|
||||
/** 页码信息展示位置 */
|
||||
paginationPosition: {
|
||||
type: String,
|
||||
default: 'bottom' as TdSwiperNavProps['paginationPosition'],
|
||||
validator(val: TdSwiperNavProps['paginationPosition']): boolean {
|
||||
if (!val) return true;
|
||||
return ['top-left', 'top', 'top-right', 'bottom-left', 'bottom', 'bottom-right', 'left', 'right'].includes(val);
|
||||
},
|
||||
},
|
||||
/** 是否显示两侧的控制按钮 */
|
||||
showControls: Boolean,
|
||||
/** 总共的项数 */
|
||||
total: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
/** 导航器类型,点状(dots)、点条状(dots-bar)、分式(fraction)等 */
|
||||
type: {
|
||||
type: String,
|
||||
default: 'dots',
|
||||
},
|
||||
};
|
||||
130
uni_modules/tdesign-uniapp/components/swiper-nav/swiper-nav.css
Normal file
130
uni_modules/tdesign-uniapp/components/swiper-nav/swiper-nav.css
Normal file
@@ -0,0 +1,130 @@
|
||||
.t-swiper-nav__dots,
|
||||
.t-swiper-nav__dots-bar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
.t-swiper-nav__dots-item,
|
||||
.t-swiper-nav__dots-bar-item {
|
||||
width: var(--td-swiper-nav-dot-size, 12rpx);
|
||||
height: var(--td-swiper-nav-dot-size, 12rpx);
|
||||
background: var(--td-swiper-nav-dot-color, var(--td-font-white-2, rgba(255, 255, 255, 0.55)));
|
||||
border-radius: 50%;
|
||||
margin: 0 10rpx;
|
||||
transition: all 0.4s ease-in;
|
||||
}
|
||||
.t-swiper-nav__dots-item--vertical,
|
||||
.t-swiper-nav__dots-bar-item--vertical {
|
||||
margin: 10rpx 0;
|
||||
}
|
||||
.t-swiper-nav__dots-item--active,
|
||||
.t-swiper-nav__dots-bar-item--active {
|
||||
background-color: var(--td-swiper-nav-dot-active-color, var(--td-text-color-anti, var(--td-font-white-1, #ffffff)));
|
||||
}
|
||||
.t-swiper-nav__dots-bar-item--vertical.t-swiper-nav__dots-bar-item--active {
|
||||
width: var(--td-swiper-nav-dot-size, 12rpx);
|
||||
height: var(--td-swiper-nav-dots-bar-active-width, 40rpx);
|
||||
}
|
||||
.t-swiper-nav__dots-bar-item--active {
|
||||
width: var(--td-swiper-nav-dots-bar-active-width, 40rpx);
|
||||
border-radius: calc(var(--td-swiper-nav-dot-size, 12rpx) / 2);
|
||||
background-color: var(--td-swiper-nav-dot-active-color, var(--td-text-color-anti, var(--td-font-white-1, #ffffff)));
|
||||
}
|
||||
.t-swiper-nav--left {
|
||||
position: absolute;
|
||||
left: 24rpx;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
.t-swiper-nav--right {
|
||||
position: absolute;
|
||||
right: 24rpx;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
.t-swiper-nav--top-left {
|
||||
position: absolute;
|
||||
top: 24rpx;
|
||||
left: 24rpx;
|
||||
}
|
||||
.t-swiper-nav--top {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 24rpx;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
.t-swiper-nav--top-right {
|
||||
position: absolute;
|
||||
top: 24rpx;
|
||||
right: 24rpx;
|
||||
}
|
||||
.t-swiper-nav--bottom-left {
|
||||
position: absolute;
|
||||
left: 24rpx;
|
||||
bottom: 24rpx;
|
||||
}
|
||||
.t-swiper-nav--bottom {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
bottom: 24rpx;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
.t-swiper-nav--bottom-right {
|
||||
position: absolute;
|
||||
right: 24rpx;
|
||||
bottom: 24rpx;
|
||||
}
|
||||
.t-swiper-nav--vertical {
|
||||
flex-direction: column;
|
||||
}
|
||||
.t-swiper-nav__fraction {
|
||||
padding: 0 16rpx;
|
||||
height: var(--td-swiper-nav-fraction-height, 48rpx);
|
||||
border-radius: calc(var(--td-swiper-nav-fraction-height, 48rpx) / 2);
|
||||
background: var(--td-swiper-nav-fraction-bg-color, var(--td-font-gray-3, rgba(0, 0, 0, 0.4)));
|
||||
color: var(--td-swiper-nav-fraction-color, var(--td-text-color-anti, var(--td-font-white-1, #ffffff)));
|
||||
font: var(--td-swiper-nav-fraction-font, var(--td-font-body-small, 24rpx / 40rpx var(--td-font-family, PingFang SC, Microsoft YaHei, Arial Regular)));
|
||||
}
|
||||
.t-swiper-nav__btn {
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
.t-swiper-nav__btn--prev,
|
||||
.t-swiper-nav__btn--next {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: var(--td-swiper-nav-btn-size, 48rpx);
|
||||
height: var(--td-swiper-nav-btn-size, 48rpx);
|
||||
border-radius: 50%;
|
||||
background: var(--td-swiper-nav-btn-bg-color, var(--td-font-gray-3, rgba(0, 0, 0, 0.4)));
|
||||
}
|
||||
.t-swiper-nav__btn--prev::after,
|
||||
.t-swiper-nav__btn--next::after {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
display: block;
|
||||
content: '';
|
||||
width: 12rpx;
|
||||
height: 12rpx;
|
||||
border-color: var(--td-swiper-nav-btn-color, var(--td-text-color-anti, var(--td-font-white-1, #ffffff)));
|
||||
border-style: solid;
|
||||
}
|
||||
.t-swiper-nav__btn--prev {
|
||||
left: 30rpx;
|
||||
}
|
||||
.t-swiper-nav__btn--prev::after {
|
||||
margin-left: 4rpx;
|
||||
border-width: 2rpx 0 0 2rpx;
|
||||
transform: translate(-50%, -50%) rotateZ(-45deg);
|
||||
}
|
||||
.t-swiper-nav__btn--next {
|
||||
right: 30rpx;
|
||||
}
|
||||
.t-swiper-nav__btn--next::after {
|
||||
margin-left: -4rpx;
|
||||
border-width: 2rpx 2rpx 0 0;
|
||||
transform: translate(-50%, -50%) rotateZ(45deg);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<template>
|
||||
<view>
|
||||
<view
|
||||
v-if="showControls"
|
||||
:class="classPrefix + '__btn ' + ' ' + tClass"
|
||||
:style="tools._style([customStyle])"
|
||||
>
|
||||
<view
|
||||
:class="classPrefix + '__btn--prev'"
|
||||
data-dir="prev"
|
||||
aria-role="button"
|
||||
aria-label="上一张"
|
||||
@click="nav($event, { dir: 'prev'})"
|
||||
/>
|
||||
<view
|
||||
:class="classPrefix + '__btn--next'"
|
||||
data-dir="next"
|
||||
aria-role="button"
|
||||
aria-label="下一张"
|
||||
@click="nav($event, { dir: 'next'})"
|
||||
/>
|
||||
</view>
|
||||
<view
|
||||
v-if="total >= minShowNum"
|
||||
:style="tools._style([customStyle])"
|
||||
:class="
|
||||
tClass +
|
||||
' ' + classPrefix +
|
||||
' ' + classPrefix + '--' + direction +
|
||||
' ' + classPrefix + '__' + type +
|
||||
' ' + classPrefix + '--' + paginationPosition
|
||||
"
|
||||
>
|
||||
<block v-if="type === 'dots' || type === 'dots-bar'">
|
||||
<view
|
||||
v-for="(item, idx) in total"
|
||||
:key="idx"
|
||||
:class="tools.cls(classPrefix + '__' + type + '-item', [['active', current === idx], direction])"
|
||||
/>
|
||||
</block>
|
||||
<block v-if="type === 'fraction'">
|
||||
{{ current + 1 }}/{{ total }}
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
import { uniComponent } from '../common/src/index';
|
||||
import { prefix } from '../common/config';
|
||||
import props from './props';
|
||||
import tools from '../common/utils.wxs';
|
||||
import { ChildrenMixin, RELATION_MAP } from '../common/relation';
|
||||
|
||||
const name = `${prefix}-swiper-nav`;
|
||||
|
||||
export default uniComponent({
|
||||
name,
|
||||
options: {
|
||||
styleIsolation: 'shared',
|
||||
},
|
||||
externalClasses: [`${prefix}-class`],
|
||||
mixins: [ChildrenMixin(RELATION_MAP.SwiperNav)],
|
||||
components: { },
|
||||
props: {
|
||||
...props,
|
||||
},
|
||||
emits: [
|
||||
'nav-btn-change',
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
prefix,
|
||||
classPrefix: name,
|
||||
tools,
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
nav(e, dataset) {
|
||||
const { dir } = dataset;
|
||||
const source = 'nav';
|
||||
this.$emit('nav-btn-change', { dir, source });
|
||||
const parent = this[RELATION_MAP.SwiperNav];
|
||||
if (parent) {
|
||||
parent.doNavBtnChange(dir, source);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style scoped>
|
||||
@import './swiper-nav.css';
|
||||
</style>
|
||||
45
uni_modules/tdesign-uniapp/components/swiper-nav/type.ts
Normal file
45
uni_modules/tdesign-uniapp/components/swiper-nav/type.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
|
||||
* */
|
||||
|
||||
export interface TdSwiperNavProps {
|
||||
/**
|
||||
* 当前轮播在哪一项(下标)
|
||||
* @default 0
|
||||
*/
|
||||
current?: number;
|
||||
/**
|
||||
* 轮播滑动方向,包括横向滑动和纵向滑动两个方向
|
||||
* @default horizontal
|
||||
*/
|
||||
direction?: 'horizontal' | 'vertical';
|
||||
/**
|
||||
* 小于这个数字不会显示导航器
|
||||
* @default 2
|
||||
*/
|
||||
minShowNum?: number;
|
||||
/**
|
||||
* 页码信息展示位置
|
||||
* @default bottom
|
||||
*/
|
||||
paginationPosition?: 'top-left' | 'top' | 'top-right' | 'bottom-left' | 'bottom' | 'bottom-right' | 'left' | 'right';
|
||||
/**
|
||||
* 是否显示两侧的控制按钮
|
||||
* @default false
|
||||
*/
|
||||
showControls?: boolean;
|
||||
/**
|
||||
* 总共的项数
|
||||
* @default 0
|
||||
*/
|
||||
total?: number;
|
||||
/**
|
||||
* 导航器类型,点状(dots)、点条状(dots-bar)、分式(fraction)等
|
||||
* @default dots
|
||||
*/
|
||||
type?: SwiperNavigationType;
|
||||
}
|
||||
|
||||
export type SwiperNavigationType = 'dots' | 'dots-bar' | 'fraction';
|
||||
Reference in New Issue
Block a user