@king-design/intact 3.5.2 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/.DS_Store +0 -0
- package/components/button/index.md +1 -0
- package/components/cascader/index.spec.ts +7 -6
- package/components/datepicker/basepicker.ts +26 -267
- package/components/datepicker/calendar.ts +8 -2
- package/components/datepicker/calendar.vdt +23 -6
- package/components/datepicker/dayjs.ts +8 -2
- package/components/datepicker/demos/multiple.md +1 -1
- package/components/datepicker/demos/yearMonth.md +1 -1
- package/components/datepicker/helpers.ts +10 -12
- package/components/datepicker/index.md +2 -2
- package/components/datepicker/index.spec.ts +619 -190
- package/components/datepicker/index.ts +22 -21
- package/components/datepicker/index.vdt +47 -42
- package/components/datepicker/shortcuts.ts +1 -1
- package/components/datepicker/styles.ts +112 -4
- package/components/datepicker/useConfirm.ts +82 -0
- package/components/datepicker/useDisabled.ts +31 -33
- package/components/datepicker/useFormats.ts +10 -4
- package/components/datepicker/useHighlight.ts +81 -0
- package/components/datepicker/useKeyboards.ts +2 -1
- package/components/datepicker/useMergeRange.ts +54 -0
- package/components/datepicker/useMonths.ts +6 -3
- package/components/datepicker/usePanel.ts +19 -19
- package/components/datepicker/useQuarters.ts +47 -0
- package/components/datepicker/useShowDate.ts +14 -3
- package/components/datepicker/useStatus.ts +34 -15
- package/components/datepicker/useValue.ts +41 -39
- package/components/datepicker/useValueBase.ts +309 -0
- package/components/datepicker/useWeeks.ts +58 -0
- package/components/datepicker/useYears.ts +7 -3
- package/components/descriptions/.DS_Store +0 -0
- package/components/dialog/useFixBody.ts +7 -64
- package/components/dropdown/dropdown.ts +5 -4
- package/components/dropdown/index.md +1 -0
- package/components/dropdown/item.ts +1 -1
- package/components/dropdown/useKeyboard.ts +0 -1
- package/components/ellipsis/styles.ts +4 -0
- package/components/form/styles.ts +1 -0
- package/components/input/index.spec.ts +42 -0
- package/components/input/index.ts +8 -0
- package/components/input/index.vdt +3 -4
- package/components/input/useAutoWidth.ts +19 -1
- package/components/menu/.DS_Store +0 -0
- package/components/menu/demos/.DS_Store +0 -0
- package/components/scrollSelect/index.spec.ts +3 -3
- package/components/scrollSelect/useMouseEvents.ts +24 -10
- package/components/select/base.ts +3 -2
- package/components/select/base.vdt +3 -1
- package/components/select/demos/creatable.md +13 -0
- package/components/select/index.md +1 -0
- package/components/select/index.spec.ts +225 -6
- package/components/select/option.ts +10 -1
- package/components/select/select.ts +3 -0
- package/components/select/styles.ts +3 -1
- package/components/select/useFilterable.ts +1 -1
- package/components/select/useInput.ts +7 -9
- package/components/select/useSearchable.ts +2 -2
- package/components/table/.DS_Store +0 -0
- package/components/table/index.spec.ts +69 -1
- package/components/table/useStickyHeader.ts +1 -1
- package/components/timepicker/demos/step.md +1 -1
- package/components/timepicker/index.spec.ts +145 -27
- package/components/timepicker/panelPicker.ts +10 -4
- package/components/timepicker/panelPicker.vdt +5 -3
- package/components/timepicker/useConfirm.ts +33 -0
- package/components/timepicker/useDefaultValue.ts +30 -0
- package/components/timepicker/useDisabled.ts +17 -4
- package/components/timepicker/useFormats.ts +1 -1
- package/components/timepicker/useValue.ts +22 -19
- package/components/tour/.DS_Store +0 -0
- package/components/tour/demos/basic.md +73 -0
- package/components/tour/demos/beforeChange.md +109 -0
- package/components/tour/demos/closable.md +70 -0
- package/components/tour/demos/custom.md +98 -0
- package/components/tour/demos/customText.md +94 -0
- package/components/tour/demos/declarative.md +72 -0
- package/components/tour/demos/events.md +101 -0
- package/components/tour/demos/maskClosable.md +76 -0
- package/components/tour/demos/notarget.md +59 -0
- package/components/tour/index.md +48 -0
- package/components/tour/index.spec.ts +259 -0
- package/components/tour/index.ts +2 -0
- package/components/tour/step.ts +55 -0
- package/components/tour/step.vdt +75 -0
- package/components/tour/styles.ts +283 -0
- package/components/tour/tour.ts +107 -0
- package/components/tour/tour.vdt +83 -0
- package/components/tour/useArrow.ts +46 -0
- package/components/tour/useFixBody.ts +22 -0
- package/components/tour/useHighlight.ts +36 -0
- package/components/tour/useMaskClosable.ts +26 -0
- package/components/tour/useNavigation.ts +46 -0
- package/components/tour/usePosition.ts +91 -0
- package/components/tour/useSteps.ts +80 -0
- package/components/virtualList/.DS_Store +0 -0
- package/components/virtualList/demos/.DS_Store +0 -0
- package/es/components/cascader/index.spec.js +18 -19
- package/es/components/datepicker/basepicker.d.ts +6 -25
- package/es/components/datepicker/basepicker.js +22 -234
- package/es/components/datepicker/calendar.d.ts +36 -6
- package/es/components/datepicker/calendar.js +4 -0
- package/es/components/datepicker/calendar.vdt.js +21 -5
- package/es/components/datepicker/dayjs.d.ts +2 -2
- package/es/components/datepicker/dayjs.js +6 -0
- package/es/components/datepicker/helpers.d.ts +8 -7
- package/es/components/datepicker/helpers.js +2 -3
- package/es/components/datepicker/index.d.ts +26 -19
- package/es/components/datepicker/index.js +21 -13
- package/es/components/datepicker/index.spec.js +1389 -633
- package/es/components/datepicker/index.vdt.js +43 -46
- package/es/components/datepicker/shortcuts.d.ts +1 -1
- package/es/components/datepicker/styles.d.ts +22 -0
- package/es/components/datepicker/styles.js +26 -4
- package/es/components/datepicker/useConfirm.d.ts +6 -0
- package/es/components/datepicker/useConfirm.js +65 -0
- package/es/components/datepicker/useDisabled.d.ts +7 -5
- package/es/components/datepicker/useDisabled.js +22 -27
- package/es/components/datepicker/useFormats.d.ts +2 -2
- package/es/components/datepicker/useFormats.js +9 -3
- package/es/components/datepicker/useHighlight.d.ts +14 -0
- package/es/components/datepicker/useHighlight.js +60 -0
- package/es/components/datepicker/useKeyboards.js +2 -1
- package/es/components/datepicker/useMergeRange.d.ts +5 -0
- package/es/components/datepicker/useMergeRange.js +45 -0
- package/es/components/datepicker/useMonths.js +5 -3
- package/es/components/datepicker/usePanel.d.ts +1 -10
- package/es/components/datepicker/usePanel.js +19 -32
- package/es/components/datepicker/useQuarters.d.ts +15 -0
- package/es/components/datepicker/useQuarters.js +36 -0
- package/es/components/datepicker/useShowDate.js +10 -2
- package/es/components/datepicker/useStatus.d.ts +1 -1
- package/es/components/datepicker/useStatus.js +33 -16
- package/es/components/datepicker/useValue.d.ts +12 -6
- package/es/components/datepicker/useValue.js +49 -45
- package/es/components/datepicker/useValueBase.d.ts +28 -0
- package/es/components/datepicker/useValueBase.js +277 -0
- package/es/components/datepicker/useWeeks.d.ts +19 -0
- package/es/components/datepicker/useWeeks.js +48 -0
- package/es/components/datepicker/useYears.js +6 -3
- package/es/components/dialog/useFixBody.js +6 -58
- package/es/components/dropdown/dropdown.d.ts +1 -0
- package/es/components/dropdown/dropdown.js +7 -4
- package/es/components/ellipsis/styles.js +1 -1
- package/es/components/form/styles.js +1 -1
- package/es/components/input/index.d.ts +2 -0
- package/es/components/input/index.js +6 -0
- package/es/components/input/index.spec.js +45 -0
- package/es/components/input/index.vdt.js +4 -3
- package/es/components/input/useAutoWidth.d.ts +2 -0
- package/es/components/input/useAutoWidth.js +19 -1
- package/es/components/scrollSelect/index.spec.js +4 -6
- package/es/components/scrollSelect/useMouseEvents.js +22 -9
- package/es/components/select/base.d.ts +1 -1
- package/es/components/select/base.js +3 -2
- package/es/components/select/base.vdt.js +5 -2
- package/es/components/select/index.spec.js +329 -82
- package/es/components/select/option.d.ts +1 -0
- package/es/components/select/option.js +10 -2
- package/es/components/select/select.d.ts +1 -0
- package/es/components/select/select.js +4 -2
- package/es/components/select/styles.d.ts +79 -0
- package/es/components/select/styles.js +1 -0
- package/es/components/select/useFilterable.js +2 -1
- package/es/components/select/useInput.d.ts +1 -1
- package/es/components/select/useInput.js +7 -4
- package/es/components/select/useSearchable.js +1 -0
- package/es/components/table/index.spec.js +84 -6
- package/es/components/table/useStickyHeader.js +1 -1
- package/es/components/timepicker/index.spec.js +298 -128
- package/es/components/timepicker/panelPicker.d.ts +23 -17
- package/es/components/timepicker/panelPicker.js +7 -4
- package/es/components/timepicker/panelPicker.vdt.js +8 -4
- package/es/components/timepicker/selectPicker.d.ts +5 -4
- package/es/components/timepicker/useConfirm.d.ts +6 -0
- package/es/components/timepicker/useConfirm.js +19 -0
- package/es/components/timepicker/useDefaultValue.d.ts +4 -0
- package/es/components/timepicker/useDefaultValue.js +27 -0
- package/es/components/timepicker/useDisabled.d.ts +7 -4
- package/es/components/timepicker/useDisabled.js +13 -4
- package/es/components/timepicker/useFormats.d.ts +1 -1
- package/es/components/timepicker/useValue.d.ts +14 -8
- package/es/components/timepicker/useValue.js +14 -15
- package/es/components/tour/index.d.ts +2 -0
- package/es/components/tour/index.js +2 -0
- package/es/components/tour/index.spec.d.ts +1 -0
- package/es/components/tour/index.spec.js +356 -0
- package/es/components/tour/step.d.ts +23 -0
- package/es/components/tour/step.js +46 -0
- package/es/components/tour/step.vdt.js +74 -0
- package/es/components/tour/styles.d.ts +7 -0
- package/es/components/tour/styles.js +84 -0
- package/es/components/tour/tour.d.ts +73 -0
- package/es/components/tour/tour.js +70 -0
- package/es/components/tour/tour.vdt.js +66 -0
- package/es/components/tour/useArrow.d.ts +4 -0
- package/es/components/tour/useArrow.js +40 -0
- package/es/components/tour/useFixBody.d.ts +4 -0
- package/es/components/tour/useFixBody.js +17 -0
- package/es/components/tour/useHighlight.d.ts +4 -0
- package/es/components/tour/useHighlight.js +31 -0
- package/es/components/tour/useMaskClosable.d.ts +1 -0
- package/es/components/tour/useMaskClosable.js +25 -0
- package/es/components/tour/useNavigation.d.ts +5 -0
- package/es/components/tour/useNavigation.js +103 -0
- package/es/components/tour/usePosition.d.ts +6 -0
- package/es/components/tour/usePosition.js +93 -0
- package/es/components/tour/useSteps.d.ts +6 -0
- package/es/components/tour/useSteps.js +68 -0
- package/es/hooks/useFixBody.d.ts +11 -0
- package/es/hooks/useFixBody.js +72 -0
- package/es/index.d.ts +3 -2
- package/es/index.js +3 -2
- package/es/site/data/components/datepicker/demos/multiple/react.js +2 -2
- package/es/site/data/components/select/demos/creatable/index.d.ts +1 -0
- package/es/site/data/components/select/demos/creatable/index.js +2 -1
- package/es/site/data/components/select/demos/creatable/react.d.ts +1 -0
- package/es/site/data/components/select/demos/creatable/react.js +31 -2
- package/es/site/data/components/tour/demos/basic/index.d.ts +17 -0
- package/es/site/data/components/tour/demos/basic/index.js +46 -0
- package/es/site/data/components/tour/demos/basic/react.d.ts +16 -0
- package/es/site/data/components/tour/demos/basic/react.js +82 -0
- package/es/site/data/components/tour/demos/beforeChange/index.d.ts +20 -0
- package/es/site/data/components/tour/demos/beforeChange/index.js +69 -0
- package/es/site/data/components/tour/demos/beforeChange/react.d.ts +19 -0
- package/es/site/data/components/tour/demos/beforeChange/react.js +129 -0
- package/es/site/data/components/tour/demos/closable/index.d.ts +18 -0
- package/es/site/data/components/tour/demos/closable/index.js +42 -0
- package/es/site/data/components/tour/demos/closable/react.d.ts +17 -0
- package/es/site/data/components/tour/demos/closable/react.js +85 -0
- package/es/site/data/components/tour/demos/custom/index.d.ts +11 -0
- package/es/site/data/components/tour/demos/custom/index.js +35 -0
- package/es/site/data/components/tour/demos/custom/react.d.ts +11 -0
- package/es/site/data/components/tour/demos/custom/react.js +108 -0
- package/es/site/data/components/tour/demos/customText/index.d.ts +33 -0
- package/es/site/data/components/tour/demos/customText/index.js +55 -0
- package/es/site/data/components/tour/demos/customText/react.d.ts +33 -0
- package/es/site/data/components/tour/demos/customText/react.js +99 -0
- package/es/site/data/components/tour/demos/declarative/index.d.ts +11 -0
- package/es/site/data/components/tour/demos/declarative/index.js +36 -0
- package/es/site/data/components/tour/demos/declarative/react.d.ts +10 -0
- package/es/site/data/components/tour/demos/declarative/react.js +80 -0
- package/es/site/data/components/tour/demos/events/index.d.ts +18 -0
- package/es/site/data/components/tour/demos/events/index.js +58 -0
- package/es/site/data/components/tour/demos/events/react.d.ts +18 -0
- package/es/site/data/components/tour/demos/events/react.js +101 -0
- package/es/site/data/components/tour/demos/maskClosable/index.d.ts +18 -0
- package/es/site/data/components/tour/demos/maskClosable/index.js +47 -0
- package/es/site/data/components/tour/demos/maskClosable/react.d.ts +17 -0
- package/es/site/data/components/tour/demos/maskClosable/react.js +95 -0
- package/es/site/data/components/tour/demos/notarget/index.d.ts +11 -0
- package/es/site/data/components/tour/demos/notarget/index.js +35 -0
- package/es/site/data/components/tour/demos/notarget/react.d.ts +10 -0
- package/es/site/data/components/tour/demos/notarget/react.js +61 -0
- package/es/site/data/components/tour/index.d.ts +57 -0
- package/es/site/data/components/tour/index.js +32 -0
- package/hooks/useFixBody.ts +87 -0
- package/index.ts +3 -2
- package/package.json +2 -2
- package/styles/.DS_Store +0 -0
|
@@ -496,7 +496,6 @@ describe('Table', () => {
|
|
|
496
496
|
checkbox.click();
|
|
497
497
|
await wait();
|
|
498
498
|
expect(element.innerHTML).to.matchSnapshot();
|
|
499
|
-
debugger;
|
|
500
499
|
expect(table.getCheckedData()).to.have.lengthOf(8);
|
|
501
500
|
|
|
502
501
|
const arrow = element.querySelector('.k-table-arrow') as HTMLElement;
|
|
@@ -723,4 +722,73 @@ describe('Table', () => {
|
|
|
723
722
|
expect(spy.callCount).to.eql(5);
|
|
724
723
|
expect(spy.lastCall.lastArg).to.eql({value: 2, limit: 10});
|
|
725
724
|
});
|
|
725
|
+
|
|
726
|
+
it('fixHeader with Affix header scroll sync', async () => {
|
|
727
|
+
interface Props {
|
|
728
|
+
data: any[]
|
|
729
|
+
fixHeader: boolean | number
|
|
730
|
+
virtual: boolean
|
|
731
|
+
stickScrollbar: boolean | number
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
class Demo extends Component<Props> {
|
|
735
|
+
static template = `
|
|
736
|
+
const {Table, TableColumn} = this;
|
|
737
|
+
const {data, fixHeader, virtual, stickScrollbar} = this.get();
|
|
738
|
+
<Table data={data} fixHeader={fixHeader} virtual={virtual} stickScrollbar={stickScrollbar} ref="table">
|
|
739
|
+
<TableColumn fixed="left" key="name" title="Name" width="200" />
|
|
740
|
+
<TableColumn key="column1" title="Column1" width="300" />
|
|
741
|
+
<TableColumn key="column2" title="Column2" width="300" />
|
|
742
|
+
<TableColumn key="column3" title="Column3" width="300" />
|
|
743
|
+
<TableColumn fixed="right" key="action" title="Action" width="200" />
|
|
744
|
+
</Table>
|
|
745
|
+
`;
|
|
746
|
+
|
|
747
|
+
static defaults() {
|
|
748
|
+
return {
|
|
749
|
+
data: Array.from({length: 10}, (_, i) => ({
|
|
750
|
+
name: `Name ${i}`,
|
|
751
|
+
column1: `Column1 ${i}`,
|
|
752
|
+
column2: `Column2 ${i}`,
|
|
753
|
+
column3: `Column3 ${i}`,
|
|
754
|
+
action: `Action ${i}`
|
|
755
|
+
})),
|
|
756
|
+
fixHeader: 200,
|
|
757
|
+
virtual: false,
|
|
758
|
+
stickScrollbar: false
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
private Table = Table;
|
|
763
|
+
private TableColumn = TableColumn;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
const [instance, element] = mount(Demo);
|
|
767
|
+
|
|
768
|
+
// Test 1: fixHeader only - scroll left 50px
|
|
769
|
+
await wait();
|
|
770
|
+
const scrollContainer = element.querySelector('.k-table-wrapper') as HTMLElement;
|
|
771
|
+
scrollContainer.scrollLeft = 50;
|
|
772
|
+
await wait(100);
|
|
773
|
+
const affixWrapper1 = element.querySelector('.k-table-affix-header .k-affix-wrapper') as HTMLElement;
|
|
774
|
+
expect(affixWrapper1.scrollLeft).to.eql(50);
|
|
775
|
+
|
|
776
|
+
// Test 2: fixHeader + virtual - scroll left 50px more (total 100px)
|
|
777
|
+
instance.set('virtual', true);
|
|
778
|
+
await wait();
|
|
779
|
+
scrollContainer.scrollLeft = 100;
|
|
780
|
+
await wait(100);
|
|
781
|
+
|
|
782
|
+
const affixWrapper2 = element.querySelector('.k-table-affix-header .k-affix-wrapper') as HTMLElement;
|
|
783
|
+
expect(affixWrapper2.scrollLeft).to.eql(100);
|
|
784
|
+
|
|
785
|
+
// Test 3: stickScrollbar + fixHeader - scroll right 50px (back to 50px)
|
|
786
|
+
instance.set('stickScrollbar', true);
|
|
787
|
+
await wait();
|
|
788
|
+
scrollContainer.scrollLeft = 50;
|
|
789
|
+
await wait(100);
|
|
790
|
+
|
|
791
|
+
const affixWrapper3 = element.querySelector('.k-table-affix-header .k-affix-wrapper') as HTMLElement;
|
|
792
|
+
expect(affixWrapper3.scrollLeft).to.eql(50);
|
|
793
|
+
});
|
|
726
794
|
});
|
|
@@ -22,7 +22,7 @@ export function useStickyHeader(callbacks: ScrollCallback[]) {
|
|
|
22
22
|
|
|
23
23
|
// when the scroll element scroll horizontally, scroll the sticky header too
|
|
24
24
|
callbacks.push(scrollLeft => {
|
|
25
|
-
if (isNull(stickHeader.value)) return;
|
|
25
|
+
if (isNull(stickHeader.value) && !instance.get('fixHeader')) return;
|
|
26
26
|
|
|
27
27
|
const affixHeadWrapper = headRef.value!.parentElement as HTMLElement;
|
|
28
28
|
affixHeadWrapper.scrollLeft = scrollLeft;
|
|
@@ -6,7 +6,7 @@ order: 2
|
|
|
6
6
|
当指定了`step`属性时,组件将展示成`Select`样式,只能选择固定的几个时间点。通过`min`和`max`限定
|
|
7
7
|
选择时间范围(默认:00:00:00 ~ 23:59:59),`step`指定步长,它们值类型都为时间字符串
|
|
8
8
|
|
|
9
|
-
> 可以通过`
|
|
9
|
+
> 可以通过`showFormat`或`format`来格式化时间字符串,来隐藏“秒”
|
|
10
10
|
|
|
11
11
|
```vdt
|
|
12
12
|
import {Timepicker} from 'kpc';
|
|
@@ -8,7 +8,6 @@ import {Timepicker} from 'kpc';
|
|
|
8
8
|
import {Component} from 'intact';
|
|
9
9
|
|
|
10
10
|
describe('Timepicker', () => {
|
|
11
|
-
|
|
12
11
|
afterEach(async () => {
|
|
13
12
|
unmount();
|
|
14
13
|
await wait(500);
|
|
@@ -19,10 +18,18 @@ describe('Timepicker', () => {
|
|
|
19
18
|
const [instance, element] = mount(BasicDemo);
|
|
20
19
|
|
|
21
20
|
const [picker1, picker2] = element.querySelectorAll('.k-select') as NodeListOf<HTMLElement>;
|
|
21
|
+
const inputInner = picker1.querySelector('.k-input-inner') as HTMLInputElement;
|
|
22
|
+
|
|
23
|
+
expect(inputInner.value).eql('');
|
|
22
24
|
picker1.click();
|
|
23
25
|
await wait(500);
|
|
24
|
-
|
|
26
|
+
expect(inputInner.value).eql('');
|
|
27
|
+
|
|
28
|
+
const dropdown = getElement('.k-time-content')!;
|
|
29
|
+
const ok = dropdown.querySelector('.k-btn') as HTMLElement;
|
|
30
|
+
expect(ok.classList.contains('k-disabled')).eql(true);
|
|
25
31
|
expect(dropdown.innerHTML).to.matchSnapshot();
|
|
32
|
+
|
|
26
33
|
const next = dropdown.querySelector('.k-scroll-select-item:nth-child(11)') as HTMLElement;
|
|
27
34
|
next.click();
|
|
28
35
|
await wait();
|
|
@@ -32,7 +39,6 @@ describe('Timepicker', () => {
|
|
|
32
39
|
await wait();
|
|
33
40
|
expect(instance.get('time')).to.be.null;
|
|
34
41
|
expect(dropdown.innerHTML).to.matchSnapshot();
|
|
35
|
-
const ok = dropdown.querySelector('.k-btn') as HTMLElement;
|
|
36
42
|
ok.click();
|
|
37
43
|
await wait(500);
|
|
38
44
|
expect(instance.get('time')).to.eql('02:00:00');
|
|
@@ -43,27 +49,56 @@ describe('Timepicker', () => {
|
|
|
43
49
|
await wait(500);
|
|
44
50
|
expect(dropdown.innerHTML).to.matchSnapshot();
|
|
45
51
|
|
|
52
|
+
// should reset show value on hiding
|
|
53
|
+
const activeHour = dropdown.querySelector('.k-scroll-select-item.k-active') as HTMLElement;
|
|
54
|
+
dispatchEvent(activeHour.nextElementSibling!, 'click');
|
|
55
|
+
await wait();
|
|
56
|
+
expect(inputInner.value).eql('04:03:03');
|
|
57
|
+
expect(instance.get('time')).eql('03:03:03');
|
|
58
|
+
document.body.click();
|
|
59
|
+
await wait();
|
|
60
|
+
expect(inputInner.value).eql('03:03:03');
|
|
61
|
+
expect(instance.get('time')).eql('03:03:03');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('multipe time', async function() {
|
|
65
|
+
const [instance, element] = mount(BasicDemo);
|
|
66
|
+
const [picker1, picker2] = element.querySelectorAll('.k-select') as NodeListOf<HTMLElement>;
|
|
67
|
+
|
|
46
68
|
// multiple
|
|
47
69
|
picker2.click();
|
|
48
|
-
await wait(
|
|
49
|
-
dropdown = getElement('.k-time-content')!;
|
|
50
|
-
dropdown.querySelector<HTMLElement>('.k-scroll-select-item:nth-child(11)')!.click();
|
|
70
|
+
await wait();
|
|
71
|
+
let dropdown = getElement('.k-time-content')!;
|
|
51
72
|
const ok2 = dropdown.querySelector('.k-btn') as HTMLElement;
|
|
73
|
+
expect(ok2.classList.contains('k-disabled')).eql(false);
|
|
74
|
+
|
|
75
|
+
dropdown.querySelector<HTMLElement>('.k-scroll-select-item:nth-child(11)')!.click();
|
|
76
|
+
await wait();
|
|
77
|
+
const inputInner = picker2.querySelector('.k-input-inner') as HTMLInputElement;
|
|
78
|
+
expect(inputInner.value).eql('01:00:00');
|
|
79
|
+
expect(instance.get('timeArray')).eql([]);
|
|
80
|
+
|
|
52
81
|
ok2.click();
|
|
53
|
-
|
|
82
|
+
await wait();
|
|
83
|
+
expect(instance.get('timeArray')).eql(['01:00:00']);
|
|
84
|
+
|
|
85
|
+
dropdown.querySelector<HTMLElement>('.k-scroll-select-item:nth-child(11)')!.click();
|
|
86
|
+
await wait();
|
|
54
87
|
ok2.click();
|
|
55
88
|
await wait();
|
|
56
89
|
expect(instance.get('timeArray')).to.eql(['01:00:00', '02:00:00']);
|
|
90
|
+
expect(ok2.classList.contains('k-disabled')).eql(false);
|
|
91
|
+
|
|
57
92
|
// click the same time will do nothing
|
|
58
93
|
ok2.click();
|
|
59
94
|
await wait();
|
|
60
95
|
expect(instance.get('timeArray')).to.eql(['01:00:00', '02:00:00']);
|
|
96
|
+
|
|
61
97
|
// remove one value
|
|
62
98
|
const [, close] = picker2.querySelectorAll<HTMLElement>('.k-tag-close');
|
|
63
99
|
close.click();
|
|
64
100
|
await wait();
|
|
65
101
|
expect(instance.get('timeArray')).to.eql(['01:00:00']);
|
|
66
|
-
expect(dropdown.innerHTML).to.matchSnapshot();
|
|
67
102
|
|
|
68
103
|
// clear
|
|
69
104
|
picker2.querySelector<HTMLElement>('.k-select-clear')!.click();
|
|
@@ -79,24 +114,107 @@ describe('Timepicker', () => {
|
|
|
79
114
|
expect(dropdown.innerHTML).to.matchSnapshot();
|
|
80
115
|
});
|
|
81
116
|
|
|
82
|
-
|
|
83
|
-
|
|
117
|
+
describe('range', () => {
|
|
118
|
+
it('basic', async () => {
|
|
119
|
+
const [instance, element] = mount(RangeDemo);
|
|
84
120
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
121
|
+
const picker = element.querySelector('.k-select') as HTMLElement;
|
|
122
|
+
picker.click();
|
|
123
|
+
await wait(500);
|
|
124
|
+
const dropdown = getElement('.k-time-content')!;
|
|
125
|
+
expect(dropdown.innerHTML).to.matchSnapshot();
|
|
126
|
+
const [start, end] = dropdown.querySelectorAll<HTMLElement>('.k-datepicker-calendar-wrapper');
|
|
127
|
+
(start.querySelector('.k-active')!.nextElementSibling as HTMLElement).click();
|
|
128
|
+
await wait();
|
|
129
|
+
expect(dropdown.innerHTML).to.matchSnapshot();
|
|
130
|
+
(end.querySelector('.k-active')!.nextElementSibling!.nextElementSibling as HTMLElement).click();
|
|
131
|
+
await wait();
|
|
132
|
+
expect(dropdown.innerHTML).to.matchSnapshot();
|
|
133
|
+
dropdown.querySelector<HTMLElement>('.k-btn')!.click();
|
|
134
|
+
await wait();
|
|
135
|
+
expect(instance.get('time')).to.eql(['01:00:00', '01:59:59']);
|
|
136
|
+
|
|
137
|
+
// clear
|
|
138
|
+
picker.querySelector<HTMLElement>('.k-select-clear')!.click();
|
|
139
|
+
await wait();
|
|
140
|
+
expect(instance.get('time')).to.eql(null);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('only select one value then click confirm button directly', async () => {
|
|
144
|
+
const [instance, element] = mount(RangeDemo);
|
|
145
|
+
|
|
146
|
+
const picker = element.querySelector('.k-select') as HTMLElement;
|
|
147
|
+
picker.click();
|
|
148
|
+
await wait();
|
|
149
|
+
const dropdown = getElement('.k-time-content')!;
|
|
150
|
+
const [start, end] = dropdown.querySelectorAll<HTMLElement>('.k-datepicker-calendar-wrapper');
|
|
151
|
+
(start.querySelector('.k-active')!.nextElementSibling as HTMLElement).click();
|
|
152
|
+
await wait();
|
|
153
|
+
|
|
154
|
+
// skip select end and confirm
|
|
155
|
+
dropdown.querySelector<HTMLElement>('.k-btn')!.click();
|
|
156
|
+
await wait();
|
|
157
|
+
expect(instance.get('time')).eql(['01:00:00', '23:59:59']);
|
|
158
|
+
|
|
159
|
+
picker.querySelector<HTMLElement>('.k-select-clear')!.click();
|
|
160
|
+
await wait();
|
|
161
|
+
picker.click();
|
|
162
|
+
await wait();
|
|
163
|
+
(end.querySelector('.k-active')!.nextElementSibling as HTMLElement).click();
|
|
164
|
+
dropdown.querySelector<HTMLElement>('.k-btn')!.click();
|
|
165
|
+
await wait();
|
|
166
|
+
expect(instance.get('time')).eql(['00:00:00', '00:59:59']);
|
|
167
|
+
|
|
168
|
+
// click confirm directly
|
|
169
|
+
picker.querySelector<HTMLElement>('.k-select-clear')!.click();
|
|
170
|
+
await wait();
|
|
171
|
+
picker.click();
|
|
172
|
+
await wait();
|
|
173
|
+
dropdown.querySelector<HTMLElement>('.k-btn')!.click();
|
|
174
|
+
await wait();
|
|
175
|
+
expect(instance.get('time')).eql(['00:00:00', '23:59:59']);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('should unique', async () => {
|
|
179
|
+
const [instance, element] = mount(RangeDemo);
|
|
180
|
+
const [, multipe] = element.querySelectorAll('.k-select') as NodeListOf<HTMLElement>;
|
|
181
|
+
|
|
182
|
+
// multiple
|
|
183
|
+
multipe.click();
|
|
184
|
+
await wait();
|
|
185
|
+
let dropdown = getElement('.k-time-content')!;
|
|
186
|
+
const confirm = dropdown.querySelector('.k-btn') as HTMLElement;
|
|
187
|
+
|
|
188
|
+
confirm.click();
|
|
189
|
+
await wait();
|
|
190
|
+
expect(instance.get('timeArr')).eql([['00:00:00', '23:59:59']]);
|
|
191
|
+
|
|
192
|
+
// confirm again
|
|
193
|
+
confirm.click();
|
|
194
|
+
await wait();
|
|
195
|
+
expect(instance.get('timeArr')).eql([['00:00:00', '23:59:59']]);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should maintain consistency when we select the next value', async () => {
|
|
199
|
+
const [instance, element] = mount(RangeDemo);
|
|
200
|
+
const [, multipe] = element.querySelectorAll('.k-select') as NodeListOf<HTMLElement>;
|
|
201
|
+
instance.set('timeArr', [['01:00:00', '02:00:00']]);
|
|
202
|
+
|
|
203
|
+
// multiple
|
|
204
|
+
multipe.click();
|
|
205
|
+
await wait();
|
|
206
|
+
let dropdown = getElement('.k-time-content')!;
|
|
207
|
+
const confirm = dropdown.querySelector('.k-btn') as HTMLElement;
|
|
208
|
+
const [start, end] = dropdown.querySelectorAll<HTMLElement>('.k-datepicker-calendar-wrapper');
|
|
209
|
+
(start.querySelector('.k-active')!.nextElementSibling as HTMLElement).click();
|
|
210
|
+
await wait();
|
|
211
|
+
confirm.click();
|
|
212
|
+
await wait();
|
|
213
|
+
expect(instance.get('timeArr')).eql([
|
|
214
|
+
['01:00:00', '02:00:00'],
|
|
215
|
+
['02:00:00', '02:00:00'],
|
|
216
|
+
]);
|
|
217
|
+
});
|
|
100
218
|
});
|
|
101
219
|
|
|
102
220
|
it('step', async () => {
|
|
@@ -123,11 +241,11 @@ describe('Timepicker', () => {
|
|
|
123
241
|
(start.querySelector('.k-active')!.nextElementSibling as HTMLElement).click();
|
|
124
242
|
await wait();
|
|
125
243
|
expect(dropdown.innerHTML).to.matchSnapshot();
|
|
126
|
-
(end.querySelector('.k-
|
|
244
|
+
(end.querySelector('.k-active')!.previousElementSibling as HTMLElement).click();
|
|
127
245
|
await wait();
|
|
128
246
|
expect(dropdown.innerHTML).to.matchSnapshot();
|
|
129
247
|
dropdown.querySelector<HTMLElement>('.k-btn')!.click();
|
|
130
|
-
expect(instance.get('time')).to.eql(['00:30:00', '
|
|
248
|
+
expect(instance.get('time')).to.eql(['00:30:00', '23:30:00']);
|
|
131
249
|
});
|
|
132
250
|
|
|
133
251
|
it('format', async () => {
|
|
@@ -10,14 +10,18 @@ import {useValue} from './useValue';
|
|
|
10
10
|
import {useDisabled} from './useDisabled';
|
|
11
11
|
import {usePanel} from '../datepicker/usePanel';
|
|
12
12
|
import {State} from '../../hooks/useState';
|
|
13
|
-
import {PanelTypes} from '../datepicker/usePanel';
|
|
14
13
|
import {useStep} from './useStep';
|
|
15
14
|
import {
|
|
16
15
|
TimepickerProps,
|
|
17
16
|
TimepickerEvents,
|
|
18
17
|
TimepickerBlocks,
|
|
19
18
|
typeDefs,
|
|
19
|
+
NOW_START,
|
|
20
|
+
NOW_END,
|
|
20
21
|
} from './constants';
|
|
22
|
+
import { useConfirm } from './useConfirm';
|
|
23
|
+
import { StateValueItem } from '../datepicker/useValueBase';
|
|
24
|
+
import { useDefaultValue } from './useDefaultValue';
|
|
21
25
|
|
|
22
26
|
export class PanelPicker<
|
|
23
27
|
Multipe extends boolean = false,
|
|
@@ -31,10 +35,12 @@ export class PanelPicker<
|
|
|
31
35
|
static typeDefs = typeDefs;
|
|
32
36
|
|
|
33
37
|
public formats = useFormats();
|
|
34
|
-
public
|
|
35
|
-
public
|
|
36
|
-
public
|
|
38
|
+
public defaultValue = useDefaultValue();
|
|
39
|
+
public disabled = useDisabled(this.formats, this.defaultValue);
|
|
40
|
+
public panel = usePanel();
|
|
41
|
+
public value = useValue(this.formats, this.disabled, this.panel, this.defaultValue);
|
|
37
42
|
public step = useStep(this.disabled, this.formats);
|
|
43
|
+
public confirm = useConfirm(this.value, this.formats.getValueString, this.defaultValue);
|
|
38
44
|
|
|
39
45
|
protected getPlaceholder() {
|
|
40
46
|
const {placeholder, range} = this.get();
|
|
@@ -7,17 +7,19 @@ import {Button} from '../button';
|
|
|
7
7
|
import {PanelFlags} from '../datepicker/usePanel';
|
|
8
8
|
import {last} from '../datepicker/helpers';
|
|
9
9
|
import {ScrollSelect} from '../scrollSelect';
|
|
10
|
+
import { makeStyles as makeStylesInheritDatepicker } from '../datepicker/styles';
|
|
10
11
|
|
|
11
|
-
const {className, range, multiple} = this.get();
|
|
12
|
+
const {className, range, multiple, min, max} = this.get();
|
|
12
13
|
const {
|
|
13
14
|
value: {value},
|
|
14
|
-
onConfirm,
|
|
15
15
|
onChangeTime,
|
|
16
16
|
onChangeTimeByStep,
|
|
17
17
|
getTimeValue,
|
|
18
|
+
setMoment,
|
|
18
19
|
} = this.value;
|
|
19
20
|
const lastValue = last(value);
|
|
20
21
|
const { k } = this.config;
|
|
22
|
+
const { onConfirm } = this.confirm;
|
|
21
23
|
|
|
22
24
|
const classNameObj = {
|
|
23
25
|
[`${k}-time-content`]: true,
|
|
@@ -56,7 +58,7 @@ const generatePanel = flag => {
|
|
|
56
58
|
);
|
|
57
59
|
};
|
|
58
60
|
|
|
59
|
-
<t:super class={`${k}-timepicker`}>
|
|
61
|
+
<t:super class={`${k}-timepicker ${makeStylesInheritDatepicker(k)}`}>
|
|
60
62
|
<b:base-menu>
|
|
61
63
|
<DropdownMenu class={classNameObj}>
|
|
62
64
|
<div class={`${k}-datepicker-wrapper`}>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {useInstance, Component, TypeDefs} from 'intact';
|
|
2
|
+
import {useState, watchState, State} from '../../hooks/useState';
|
|
3
|
+
import type {useFormats} from './useFormats';
|
|
4
|
+
import type {useDisabled} from './useDisabled';
|
|
5
|
+
import {isEqualArray, last, bind} from '../utils';
|
|
6
|
+
import type { PanelPicker } from './panelPicker';
|
|
7
|
+
import { useValue } from './useValue';
|
|
8
|
+
import { StateValueRange, StateValue, DayjsValueRange, StateValueItem } from '../datepicker/useValueBase';
|
|
9
|
+
import type { useDefaultValue } from './useDefaultValue';
|
|
10
|
+
|
|
11
|
+
export function useConfirm(
|
|
12
|
+
value: ReturnType<typeof useValue>,
|
|
13
|
+
getValueString: ReturnType<typeof useFormats>['getValueString'],
|
|
14
|
+
defaultValue: ReturnType<typeof useDefaultValue>,
|
|
15
|
+
) {
|
|
16
|
+
const instance = useInstance() as PanelPicker;
|
|
17
|
+
|
|
18
|
+
function onConfirm() {
|
|
19
|
+
const { multiple } = instance.get();
|
|
20
|
+
// if we click confirm button directly, set the value to placeholder values
|
|
21
|
+
value.setValue(defaultValue.get(), false);
|
|
22
|
+
|
|
23
|
+
if (!multiple) {
|
|
24
|
+
instance.hide();
|
|
25
|
+
} else {
|
|
26
|
+
value.unique();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
value.updateValue();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return { onConfirm }
|
|
33
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useInstance } from 'intact';
|
|
2
|
+
import { StateValueItem } from '../datepicker/useValueBase';
|
|
3
|
+
import type { PanelPicker } from './panelPicker';
|
|
4
|
+
import { last } from '../datepicker/helpers';
|
|
5
|
+
import {NOW_START, NOW_END} from './constants';
|
|
6
|
+
import { isArray } from 'intact-shared';
|
|
7
|
+
|
|
8
|
+
export function useDefaultValue() {
|
|
9
|
+
const instance = useInstance() as PanelPicker;
|
|
10
|
+
|
|
11
|
+
function get(): StateValueItem {
|
|
12
|
+
const _value = instance.value.value.value;
|
|
13
|
+
const lastValue = last(_value);
|
|
14
|
+
const { range } = instance.get();
|
|
15
|
+
|
|
16
|
+
if (range) {
|
|
17
|
+
// consider the second last value to maintain consistency
|
|
18
|
+
const penulimate = getPenulimate(_value);
|
|
19
|
+
return Object.assign([NOW_START, NOW_END], penulimate, lastValue);
|
|
20
|
+
}
|
|
21
|
+
return lastValue || NOW_START;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return { get };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getPenulimate(value: unknown[]) {
|
|
28
|
+
if (!isArray(value)) return;
|
|
29
|
+
return value[value.length - 2];
|
|
30
|
+
}
|
|
@@ -1,13 +1,26 @@
|
|
|
1
|
+
import { useInstance } from 'intact';
|
|
1
2
|
import {useDisabled as useDisabledBase} from '../datepicker/useDisabled';
|
|
2
3
|
import type {useFormats} from './useFormats';
|
|
3
4
|
import {PanelFlags} from '../datepicker/usePanel';
|
|
5
|
+
import {isGT, isLT, last} from '../datepicker/helpers';
|
|
6
|
+
import type { PanelPicker } from './panelPicker';
|
|
7
|
+
import { StateValueItem } from '../datepicker/useValueBase';
|
|
8
|
+
import type { useDefaultValue } from './useDefaultValue';
|
|
4
9
|
|
|
5
|
-
export function useDisabled(
|
|
6
|
-
|
|
10
|
+
export function useDisabled(
|
|
11
|
+
formats: ReturnType<typeof useFormats>,
|
|
12
|
+
defaultValue: ReturnType<typeof useDefaultValue>,
|
|
13
|
+
) {
|
|
14
|
+
const instance = useInstance() as PanelPicker;
|
|
15
|
+
const {isDisabledTime, isDisabledConfirm: isDisabledConfirmBase, isDisabledValue, ...rest} = useDisabledBase(formats);
|
|
7
16
|
|
|
8
17
|
function isDisabledTimeByStep(value: string, flag: PanelFlags) {
|
|
9
|
-
return isDisabledTime(formats.createDateByValueFormat(value)
|
|
18
|
+
return isDisabledTime(formats.createDateByValueFormat(value));
|
|
10
19
|
}
|
|
11
20
|
|
|
12
|
-
|
|
21
|
+
function isDisabledConfirm(): boolean {
|
|
22
|
+
return isDisabledValue(defaultValue.get());
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {isDisabledTime, isDisabledTimeByStep, isDisabledConfirm, isDisabledValue, ...rest};
|
|
13
26
|
}
|
|
@@ -2,7 +2,7 @@ import {useInstance, Component} from 'intact';
|
|
|
2
2
|
import dayjs, {Dayjs} from '../datepicker/dayjs';
|
|
3
3
|
import {isString} from 'intact-shared';
|
|
4
4
|
import type {TimepickerProps} from './';
|
|
5
|
-
import type {Value} from '../datepicker/
|
|
5
|
+
import type {Value} from '../datepicker/useValueBase';
|
|
6
6
|
import {YEAR_FORMAT, TIME_FORMAT, PREFIX} from './constants'
|
|
7
7
|
|
|
8
8
|
export function useFormats<T extends Component<TimepickerProps>>() {
|
|
@@ -2,23 +2,29 @@ import {useInstance} from 'intact';
|
|
|
2
2
|
import type {PanelPicker} from './panelPicker';
|
|
3
3
|
import type {useFormats} from './useFormats';
|
|
4
4
|
import {last} from '../utils';
|
|
5
|
-
import {
|
|
6
|
-
useValue as useValueBase,
|
|
7
|
-
StateValueItem,
|
|
8
|
-
DayjsValueItem
|
|
9
|
-
} from '../datepicker/basepicker';
|
|
5
|
+
import {useValueBase, StateValueItem, DayjsValueItem, DayjsValue, StateValueRange} from '../datepicker/useValueBase';
|
|
10
6
|
import type {useDisabled} from '../datepicker/useDisabled';
|
|
11
7
|
import type {usePanel} from '../datepicker/usePanel';
|
|
12
8
|
import {NOW_START, NOW_END} from './constants';
|
|
13
9
|
import {PanelFlags} from '../datepicker/usePanel';
|
|
10
|
+
import type Dayjs from 'dayjs';
|
|
11
|
+
import type { useDefaultValue } from './useDefaultValue';
|
|
14
12
|
|
|
15
13
|
export function useValue(
|
|
16
14
|
formats: ReturnType<typeof useFormats>,
|
|
17
15
|
disabled: ReturnType<typeof useDisabled>,
|
|
18
16
|
panel: ReturnType<typeof usePanel>,
|
|
17
|
+
defaultValue: ReturnType<typeof useDefaultValue>,
|
|
19
18
|
) {
|
|
20
19
|
const instance = useInstance() as PanelPicker;
|
|
21
|
-
const {
|
|
20
|
+
const {
|
|
21
|
+
value,
|
|
22
|
+
getDayjsValue,
|
|
23
|
+
setValue,
|
|
24
|
+
onChangeTime,
|
|
25
|
+
getTimeValue: getTimeValueBase,
|
|
26
|
+
...rest
|
|
27
|
+
} = useValueBase(
|
|
22
28
|
formats,
|
|
23
29
|
disabled,
|
|
24
30
|
panel,
|
|
@@ -28,7 +34,7 @@ export function useValue(
|
|
|
28
34
|
function(v: DayjsValueItem) {
|
|
29
35
|
// pop the last value when input
|
|
30
36
|
// because it is a placeholder date
|
|
31
|
-
value.value.pop();
|
|
37
|
+
// value.value.pop(); // no placeholder any more
|
|
32
38
|
setValue(v, true);
|
|
33
39
|
},
|
|
34
40
|
function() {
|
|
@@ -39,21 +45,18 @@ export function useValue(
|
|
|
39
45
|
}
|
|
40
46
|
);
|
|
41
47
|
|
|
42
|
-
setValue(getPlaceholderDates(), false);
|
|
43
|
-
|
|
44
|
-
instance.watch('value', value => {
|
|
45
|
-
const dayjsValue = getDayjsValue();
|
|
46
|
-
setValue(last(dayjsValue) || getPlaceholderDates(), false);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
function getPlaceholderDates(): StateValueItem {
|
|
50
|
-
return instance.get('range') ? [NOW_START, NOW_END] : NOW_START;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
48
|
function onChangeTimeByStep(v: string, flag: PanelFlags) {
|
|
54
49
|
const date = formats.createDateByValueFormat(v);
|
|
55
50
|
onChangeTime(date, flag);
|
|
56
51
|
}
|
|
57
52
|
|
|
58
|
-
|
|
53
|
+
function getTimeValue(flag: PanelFlags): Dayjs.Dayjs | null | undefined {
|
|
54
|
+
const value = defaultValue.get();
|
|
55
|
+
if (instance.get('range')) {
|
|
56
|
+
return (value as StateValueRange)[flag];
|
|
57
|
+
}
|
|
58
|
+
return value as Dayjs.Dayjs;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {value, setValue, getDayjsValue, onChangeTime, onChangeTimeByStep, getTimeValue, ...rest};
|
|
59
62
|
}
|
|
Binary file
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 基础用法
|
|
3
|
+
order: 0
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
```vdt
|
|
7
|
+
import {Tour, Button} from 'kpc';
|
|
8
|
+
|
|
9
|
+
<div>
|
|
10
|
+
<div class="example-container">
|
|
11
|
+
<Button id="btn1">示例元素1</Button>
|
|
12
|
+
<Button id="btn2" style="margin-left: 20px;">示例元素2</Button>
|
|
13
|
+
</div>
|
|
14
|
+
<Tour
|
|
15
|
+
v-model="currentStep"
|
|
16
|
+
visible={this.get('showTour')}
|
|
17
|
+
data={this.get('tourData')}
|
|
18
|
+
ev-finish={this.close}
|
|
19
|
+
/>
|
|
20
|
+
<div style="margin-top: 20px;">
|
|
21
|
+
<Button ev-click={this.settour}>
|
|
22
|
+
启动引导
|
|
23
|
+
</Button>
|
|
24
|
+
<span style="margin-left: 10px;">
|
|
25
|
+
当前步骤: {this.get('currentStep') >= 0 ? this.get('currentStep') + 1 : '未启动'}
|
|
26
|
+
</span>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import {bind} from 'kpc';
|
|
33
|
+
import {TourStepProps} from 'kpc';
|
|
34
|
+
|
|
35
|
+
export default class extends Component {
|
|
36
|
+
static template = template;
|
|
37
|
+
static defaults() {
|
|
38
|
+
return {
|
|
39
|
+
currentStep: 0 as number,
|
|
40
|
+
showTour: false, // 默认不显示
|
|
41
|
+
tourData: [
|
|
42
|
+
{
|
|
43
|
+
target: '#btn1',
|
|
44
|
+
title: '第一步',
|
|
45
|
+
content: '这是第一步的引导说明',
|
|
46
|
+
position: 'bottom'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
target: '#btn2',
|
|
50
|
+
title: '第二步',
|
|
51
|
+
content: '这是第二步的引导说明',
|
|
52
|
+
position: 'right'
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@bind
|
|
59
|
+
settour() {
|
|
60
|
+
this.set({
|
|
61
|
+
showTour: true,
|
|
62
|
+
currentStep: 0
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@bind
|
|
67
|
+
close() {
|
|
68
|
+
this.set({
|
|
69
|
+
showTour: false
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|