Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/devui-vue/devui/progress/src/progress-types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { ExtractPropTypes } from 'vue';

export interface SvgData {
interface ISvgPath {
stroke: string;
strokeDasharray: string;
strokeDashoffset: string;
transition: string;
}

export interface ISvgData {
pathString: string;
trailPath: any;
strokePath: any;
trailPath: ISvgPath;
strokePath: ISvgPath;
}

export const progressProps = {
Expand Down
4 changes: 2 additions & 2 deletions packages/devui-vue/devui/progress/src/progress.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineComponent, reactive, toRefs, watch } from 'vue';
import { ProgressProps, progressProps, SvgData } from './progress-types';
import { ProgressProps, progressProps, ISvgData } from './progress-types';
import './progress.scss';

export default defineComponent({
Expand All @@ -8,7 +8,7 @@ export default defineComponent({
setup(props: ProgressProps) {
const { height, percentage, percentageText, barBgColor, isCircle, strokeWidth, showContent } = toRefs(props);

const data: SvgData = reactive({
const data: ISvgData = reactive({
pathString: '',
trailPath: null,
strokePath: null,
Expand Down
12 changes: 9 additions & 3 deletions packages/devui-vue/devui/rate/src/rate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export default defineComponent({
props: rateProps,
emits: ['change', 'update:modelValue'],
setup(props: RateProps, ctx) {
const totalLevelArray = reactive<Record<string, any>[]>([]);
const totalLevelArray = reactive<{
width: string;
}[]>([]);
const chooseValue = ref(0);

// 根据mouseMove,mouseLeave,select等操作,改变颜色与是否选中
Expand Down Expand Up @@ -117,7 +119,9 @@ export default defineComponent({
xmlns-xlink="http://www.w3.org/1999/xlink">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g fill="#E3E5E9" id="Mask">
<polygon points="8 12.7603585 3.67376208 14.3147912 3.81523437 9.71994835 1 6.0857977 5.41367261 4.80046131 8 1 10.5863274 4.80046131 15 6.0857977 12.1847656 9.71994835 12.3262379 14.3147912"></polygon>
<polygon points="8 12.7603585 3.67376208 14.3147912 3.81523437 9.71994835 \
1 6.0857977 5.41367261 4.80046131 8 1 10.5863274 4.80046131 15 6.0857977 \
12.1847656 9.71994835 12.3262379 14.3147912"></polygon>
</g>
</g>
</svg>
Expand Down Expand Up @@ -148,7 +152,9 @@ export default defineComponent({
xmlns-xlink="http://www.w3.org/1999/xlink">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Mask">
<polygon points="8 12.7603585 3.67376208 14.3147912 3.81523437 9.71994835 1 6.0857977 5.41367261 4.80046131 8 1 10.5863274 4.80046131 15 6.0857977 12.1847656 9.71994835 12.3262379 14.3147912"></polygon>
<polygon points="8 12.7603585 3.67376208 14.3147912 3.81523437 9.71994835 1 \
6.0857977 5.41367261 4.80046131 8 1 10.5863274 4.80046131 15 6.0857977 \
12.1847656 9.71994835 12.3262379 14.3147912"></polygon>
</g>
</g>
</svg>
Expand Down
6 changes: 3 additions & 3 deletions packages/devui-vue/devui/splitter/__tests__/splitter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mount, VueWrapper } from '@vue/test-utils';
import { ref } from 'vue';
import { ComponentPublicInstance, ref } from 'vue';
import DSplitter from '../src/splitter';
import DSplitterPane from '../src/splitter-pane';

Expand Down Expand Up @@ -74,7 +74,7 @@ describe('splitter', () => {
},
};

let wrapper: VueWrapper<any>;
let wrapper: VueWrapper<ComponentPublicInstance>;
let splitterElement: HTMLElement;
beforeEach(() => {
wrapper = mount(testComponent);
Expand Down Expand Up @@ -325,7 +325,7 @@ describe('splitter', () => {
},
};

let wrapper: VueWrapper<any>;
let wrapper: VueWrapper<ComponentPublicInstance>;
beforeEach(() => {
wrapper = mount(testComponent);
});
Expand Down
36 changes: 18 additions & 18 deletions packages/devui-vue/devui/timeline/__tests__/timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('timeline test', () => {

it('position should be rendered correctly', async () => {

const wrapper = mount({
const wrapperPosition = mount({
components: { DTimeline, DTimelineItem },
template: `
<d-timeline mode="alternative">
Expand All @@ -70,22 +70,22 @@ describe('timeline test', () => {
return;
}
});
let timeAxisItems = wrapper.findAll('.devui-timeline-item');
let timeAxisItemsPosition = wrapperPosition.findAll('.devui-timeline-item');
// 内容是否在正确的位置
expect(timeAxisItems[0].find('.devui-timeline-item-data-left .devui-timeline-item-content').exists()).toBe(true);
expect(timeAxisItems[1].find('.devui-timeline-item-data-right .devui-timeline-item-content').exists()).toBe(true);
expect(timeAxisItems[2].find('.devui-timeline-item-data-right .devui-timeline-item-content').exists()).toBe(true);
expect(timeAxisItemsPosition[0].find('.devui-timeline-item-data-left .devui-timeline-item-content').exists()).toBe(true);
expect(timeAxisItemsPosition[1].find('.devui-timeline-item-data-right .devui-timeline-item-content').exists()).toBe(true);
expect(timeAxisItemsPosition[2].find('.devui-timeline-item-data-right .devui-timeline-item-content').exists()).toBe(true);
// 设置横向时间轴
await wrapper.setProps({ direction: 'horizontal' });
timeAxisItems = wrapper.findAll('.devui-timeline-item');
expect(timeAxisItems[0].find('.devui-timeline-item-data-bottom .devui-timeline-item-content').exists()).toBe(true);
expect(timeAxisItems[1].find('.devui-timeline-item-data-top .devui-timeline-item-content').exists()).toBe(true);
expect(timeAxisItems[3].find('.devui-timeline-item-data-top .devui-timeline-item-content').exists()).toBe(true);
await wrapperPosition.setProps({ direction: 'horizontal' });
timeAxisItemsPosition = wrapperPosition.findAll('.devui-timeline-item');
expect(timeAxisItemsPosition[0].find('.devui-timeline-item-data-bottom .devui-timeline-item-content').exists()).toBe(true);
expect(timeAxisItemsPosition[1].find('.devui-timeline-item-data-top .devui-timeline-item-content').exists()).toBe(true);
expect(timeAxisItemsPosition[3].find('.devui-timeline-item-data-top .devui-timeline-item-content').exists()).toBe(true);

});

it('time-position should be rendered correctly', async () => {
const wrapper = mount({
const wrapperTimePosition = mount({
components: { DTimeline, DTimelineItem },
template: `
<d-timeline time-position="bottom">
Expand All @@ -97,16 +97,16 @@ describe('timeline test', () => {
return;
}
});
const timeAxisItems = wrapper.findAll('.devui-timeline-item');
const timeAxisItemsTimePosition = wrapperTimePosition.findAll('.devui-timeline-item');
// 时间是否在正确的位置
expect(timeAxisItems[0].find('.devui-timeline-item-data-left .devui-timeline-item-time').exists()).toBe(false);
expect(timeAxisItems[0].find('.devui-timeline-item-axis .devui-timeline-item-time').exists()).toBe(true);
expect(timeAxisItems[1].find('.devui-timeline-item-data-left .devui-timeline-item-time').exists()).toBe(true);
expect(timeAxisItems[1].find('.devui-timeline-item-axis .devui-timeline-item-time').exists()).toBe(false);
expect(timeAxisItemsTimePosition[0].find('.devui-timeline-item-data-left .devui-timeline-item-time').exists()).toBe(false);
expect(timeAxisItemsTimePosition[0].find('.devui-timeline-item-axis .devui-timeline-item-time').exists()).toBe(true);
expect(timeAxisItemsTimePosition[1].find('.devui-timeline-item-data-left .devui-timeline-item-time').exists()).toBe(true);
expect(timeAxisItemsTimePosition[1].find('.devui-timeline-item-axis .devui-timeline-item-time').exists()).toBe(false);
});

it('line-style should be rendered correctly', async () => {
const wrapper = mount({
const wrapperLineStyle = mount({
components: { DTimeline, DTimelineItem },
template: `
<d-timeline>
Expand All @@ -121,7 +121,7 @@ describe('timeline test', () => {
return;
}
});
const timeAxisItemAxis = wrapper.findAll('.devui-timeline-item .devui-timeline-item-axis');
const timeAxisItemAxis = wrapperLineStyle.findAll('.devui-timeline-item .devui-timeline-item-axis');
expect(timeAxisItemAxis[0].find('.devui-timeline-item-line').classes()).toContain('devui-timeline-item-line-style-solid');
expect(timeAxisItemAxis[1].find('.devui-timeline-item-line').classes()).toContain('devui-timeline-item-line-style-dashed');
expect(timeAxisItemAxis[2].find('.devui-timeline-item-line').classes()).toContain('devui-timeline-item-line-style-dotted');
Expand Down
14 changes: 7 additions & 7 deletions packages/devui-vue/devui/timeline/src/timeline-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PropType, ExtractPropTypes,SetupContext } from 'vue';
import type { PropType, ExtractPropTypes, SetupContext } from 'vue';
export type DataDirection = 'vertical' | 'horizontal';
export type Mode = 'normal' | 'alternative';
export type TimePosition = 'left' | 'bottom';
Expand All @@ -8,28 +8,28 @@ export const timeAxisProps = {
// 设置时间轴方向
direction: {
type: String as PropType<DataDirection>,
default: 'vertical'
default: 'vertical',
},
// 设置居中
center: {
type: Boolean,
default: false
default: false,
},
// 设置排序方向
mode: {
type: String as PropType<Mode>,
default: 'normal'
default: 'normal',
},
// 设置时间位置
timePosition: {
type: String as PropType<TimePosition>,
default: 'left'
}
default: 'left',
},
} as const;

export type TimelineProps = ExtractPropTypes<typeof timeAxisProps>;

export interface TimelineRootType {
ctx: SetupContext<any>;
ctx: SetupContext;
props: TimelineProps;
}
58 changes: 30 additions & 28 deletions packages/devui-vue/devui/timeline/src/timeline.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
import {defineComponent, Fragment, nextTick, onMounted, provide, reactive, ref, toRef, watch} from 'vue';
import {timeAxisProps, TimelineProps, TimelineRootType} from './timeline-types';
import { defineComponent, Fragment, nextTick, onMounted, provide, reactive, ref, toRef, watch } from 'vue';
import { timeAxisProps, TimelineProps, TimelineRootType } from './timeline-types';
import TimelineItem from './components/timeline-item';
import './timeline.scss';

export default defineComponent({
name: 'DTimeline',
components: {TimelineItem},
components: { TimelineItem },
props: timeAxisProps,
emits: [],
setup(props: TimelineProps, ctx) {
provide<TimelineRootType>('timeAxis', {ctx, props});
provide<TimelineRootType>('timeAxis', { ctx, props });
const timeAxis = ref<null | HTMLElement>();
const style = reactive({
marginLeft: '0px',
height: 'auto'
height: 'auto',
});
const setStyle = () => {
style.height = 'auto';
style.marginLeft = '0px';
if (props.direction === 'horizontal') {
nextTick(() => {
const el = timeAxis.value;
const element = timeAxis.value;
if (props.center) {
// 计算偏移量
style.marginLeft = (el?.firstElementChild?.clientWidth || 0) / 2 + 'px';
style.marginLeft = (element?.firstElementChild?.clientWidth || 0) / 2 + 'px';
}
// 算出最大高度
style.height = Math.max(
...Array.from(el?.querySelectorAll('.devui-timeline-item-data-top')).map(el => el.clientHeight),
...Array.from(el?.querySelectorAll('.devui-timeline-item-data-bottom')).map(el => el.clientHeight)
) * 2
+ Math.max(...Array.from(el?.querySelectorAll('.devui-timeline-item-axis')).map(el => el.clientHeight))
+ 'px';
style.height =
Math.max(
...Array.from(element?.querySelectorAll('.devui-timeline-item-data-top')).map((el) => el.clientHeight),
...Array.from(element?.querySelectorAll('.devui-timeline-item-data-bottom')).map((el) => el.clientHeight)
) *
2 +
Math.max(...Array.from(element?.querySelectorAll('.devui-timeline-item-axis')).map((el) => el.clientHeight)) +
'px';
});
}
};
Expand All @@ -43,14 +45,11 @@ export default defineComponent({
});
return () => {
const renderItemPosition = (item, position?) => {
return position
? <item position={position}/>
: <item/>;
return position ? <item position={position} /> : <item />;
};


const renderItem = () => {
const slots: any[] = ctx.slots.default?.() ?? [];
const slots = ctx.slots.default?.() ?? [];
let children;
if (slots.length === 1 && slots[0].type === Fragment) {
children = slots[0].children || [];
Expand All @@ -59,30 +58,34 @@ export default defineComponent({
}
return children.map((item, index) => {
// 默认隐藏最后一条线
if ((index + 1) === children.length) {
if (index + 1 === children.length) {
if (!item.props?.lineStyle && !item.props?.['line-style']) {
item = <item line-style="none"/>;
item = <item line-style="none" />;
}
}
// 如果没有单独设置time-position属性,则以全局为准
if (!item.props?.timePosition && !item.props?.['time-position']) {
item = <item time-position={props.timePosition ? props.timePosition : 'left'}/>;
item = <item time-position={props.timePosition ? props.timePosition : 'left'} />;
}

if (props.direction === 'horizontal') {
// 判断是否有自定义的位置信息,且是否正确 有,且正确直接用
if (item.props?.position === 'top' || item.props?.position === 'bottom') {return item;}
if (item.props?.position === 'top' || item.props?.position === 'bottom') {
return item;
}
// 判断是否需要交替
if (props.mode === 'alternative') {
return renderItemPosition(item, index % 2 == 0 ? 'bottom' : 'top');
return renderItemPosition(item, index % 2 === 0 ? 'bottom' : 'top');
} else {
// 不需要交替的直接给默认值
return renderItemPosition(item, 'bottom');
}
} else {
if (item.props?.position === 'left' || item.props?.position === 'right') {return item;}
if (item.props?.position === 'left' || item.props?.position === 'right') {
return item;
}
if (props.mode === 'alternative') {
return renderItemPosition(item, index % 2 == 0 ? 'left' : 'right');
return renderItemPosition(item, index % 2 === 0 ? 'left' : 'right');
} else {
return renderItemPosition(item, 'right');
}
Expand All @@ -98,11 +101,10 @@ export default defineComponent({
<div
class={`devui-timeline devui-timeline-${getDirection()} ${props.center ? 'devui-timeline-' + getDirection() + '-center' : ''} `}
ref={timeAxis}
style={style}
>
style={style}>
{renderItem()}
</div>
);
};
}
},
});