| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <template>
- <scroll-view
- v-if="direction === 'horizontal'"
- :scroll-x="true"
- :show-scrollbar="false"
- :scroll-with-animation="true"
- :scroll-left="scrollLeft"
- :style="themeStyles.scrollHorizontal.value"
- >
- <view :style="themeStyles.stepHorizontal.value">
- <slot />
- </view>
- </scroll-view>
- <view v-else :style="themeStyles.stepVertical.value">
- <slot />
- </view>
- </template>
- <script setup lang="ts">
- //TODO
- import { computed, provide, toRef, type Ref } from 'vue';
- import type { IconProps } from '../basic/Icon.vue';
- import { propGetThemeVar, useTheme, type TextStyle } from '../theme/ThemeDefine';
- import { useChildLinkParent } from '../composeabe/ChildItem';
- const themeContext = useTheme();
- export interface StepProps {
- /**
- * 步骤条的方向
- * @default 'horizontal'
- */
- direction?: 'vertical'|'horizontal',
- /**
- * 激活时的颜色
- * @default primary
- */
- activeColor?: string,
- /**
- * 未激活时的颜色
- * @default Color.grey
- */
- inactiveColor?: string,
- /**
- * 文字颜色
- * @default text.content
- */
- textColor?: string,
- /**
- * 当为水平模式时,条目的宽度
- * @default 150rpx
- */
- lineItemWidth?: number,
- /**
- * 当为水平模式时,分隔线的边距偏移
- * @default 10
- */
- lineOffset?: number,
- /**
- * 线段粗细
- * @default 1
- */
- lineWidth?: number;
- /**
- * 当前激活的步骤
- */
- activeIndex: number,
- /**
- * 同 StepItemProps.activeIcon 此项用于所有子条目的设置
- */
- activeIcon?: string,
- /**
- * 同 StepItemProps.inactiveIcon 此项用于所有子条目的设置
- */
- inactiveIcon?: string,
- /**
- * 同 StepItemProps.finishIcon 此项用于所有子条目的设置
- */
- finishIcon?: string,
- /**
- * 同 StepItemProps.iconProps 此项用于所有子条目的设置
- */
- iconProps?: IconProps;
- /**
- * 同 StepItemProps.textStyle 此项用于所有子条目的设置
- */
- textStyle?: TextStyle,
- }
- const emit = defineEmits([ 'click' ]);
- const props = withDefaults(defineProps<StepProps>(), {
- direction: 'horizontal',
- lineItemWidth: () => propGetThemeVar('StepLineItemWidth', 150),
- lineOffset: () => propGetThemeVar('StepLineOffset', 25),
- lineWidth: () => propGetThemeVar('StepLineWidth', 2),
- activeColor: () => propGetThemeVar('StepActiveColor', 'primary'),
- inactiveColor: () => propGetThemeVar('StepInactiveColor', 'lightGrey'),
- textColor: () => propGetThemeVar('StepTextColor', 'text.content'),
- });
- const scrollLeft = computed(() => {
- if (props.direction === 'vertical')
- return 0;
- return uni.upx2px((props.activeIndex - 1) * props.lineItemWidth - props.lineItemWidth / 2);
- })
- const themeStyles = themeContext.useThemeStyles({
- stepVertical: {
- position: 'relative',
- display: 'flex',
- flexDirection: 'column',
- },
- stepHorizontal: {
- display: 'flex',
- position: 'relative',
- flexDirection: 'row',
- justifyContent: 'flex-start',
- width: 'auto',
- },
- scrollHorizontal: {
- position: 'relative',
- flex: 0,
- width: '100%',
- },
- });
- const {
- getPosition,
- resetCounter,
- getLength,
- } = useChildLinkParent({
- getPositionExtra(index) {
- return {}
- },
- });
- export interface StepContext {
- direction: Ref<StepProps['direction']>,
- activeColor: Ref<StepProps['activeColor']>,
- inactiveColor: Ref<StepProps['inactiveColor']>,
- textColor: Ref<StepProps['textColor']>,
- lineItemWidth: Ref<StepProps['lineItemWidth']>,
- lineOffset: Ref<StepProps['lineOffset']>,
- lineWidth: Ref<StepProps['lineWidth']>,
- activeIndex: Ref<StepProps['activeIndex']>,
- getLength: () => number,
- getPosition: () => number,
- resetCounter: () => void,
- }
- provide<StepContext>('StepContext', {
- direction: toRef(props, 'direction'),
- activeColor: toRef(props, 'activeColor'),
- inactiveColor: toRef(props, 'inactiveColor'),
- textColor: toRef(props, 'textColor'),
- lineItemWidth: toRef(props, 'lineItemWidth'),
- lineOffset: toRef(props, 'lineOffset'),
- lineWidth: toRef(props, 'lineWidth'),
- activeIndex: toRef(props, 'activeIndex'),
- getLength,
- getPosition: () => getPosition().index,
- resetCounter,
- });
- </script>
|