Browse Source

fix: calendar 添加自定义方法 (#2084)

Co-authored-by: lkjh3214 <13121007159@163.com>
lkjh3214 2 years ago
parent
commit
cb393ca3e7

+ 1 - 0
src/packages/__VUE/calendar/doc.en-US.md

@@ -652,6 +652,7 @@ Through [ref](https://vuejs.org/guide/essentials/template-refs.html), you can ge
 | Name | Description             | Arguments          |
 |--------|------------------|---------------|
 | scrollToDate   | Scroll to the month of the specified date:'2021-12-30' | `string` |
+| initPosition `v4.0.1`   | Initialize scroll position |  |
 ## Theming
 
 ### CSS Variables

+ 1 - 0
src/packages/__VUE/calendar/doc.md

@@ -667,6 +667,7 @@ export default {
 | 方法名          | 说明               | 参数          |
 |----------------|-------------------|---------------|
 | scrollToDate   | 滚动到指定日期所在月,如:'2021-12-30' | `string` |
+| initPosition `v4.0.1`   | 初始化滚动位置 | 无 |
 
 ## 主题定制
 

+ 1 - 1
src/packages/__VUE/calendar/doc.taro.md

@@ -657,7 +657,7 @@ export default {
 | 方法名 | 说明             | 参数          |
 |--------|------------------|---------------|
 | scrollToDate   | 滚动到指定日期所在月,如:'2021-12-30' | `string` |
-
+| initPosition `v4.0.1`   | 初始化滚动位置 | 无 |
 ## 主题定制
 
 ### 样式变量

+ 5 - 1
src/packages/__VUE/calendar/index.taro.vue

@@ -187,8 +187,12 @@ export default create({
     const scrollToDate = (date: string) => {
       calendarRef.value?.scrollToDate(date);
     };
+    const initPosition = () => {
+      calendarRef.value?.initPosition();
+    };
     useExpose({
-      scrollToDate
+      scrollToDate,
+      initPosition
     });
     // methods
     const update = () => {

+ 5 - 1
src/packages/__VUE/calendar/index.vue

@@ -185,8 +185,12 @@ export default create({
     const scrollToDate = (date: string) => {
       calendarRef.value?.scrollToDate(date);
     };
+    const initPosition = () => {
+      calendarRef.value?.initPosition();
+    };
     useExpose({
-      scrollToDate
+      scrollToDate,
+      initPosition
     });
     // methods
     const update = () => {

+ 5 - 1
src/packages/__VUE/calendaritem/index.taro.vue

@@ -671,8 +671,12 @@ export default create({
         }
       });
     };
+    const initPosition = () => {
+      state.scrollTop = Math.ceil(state.monthsData[state.currentIndex].cssScrollHeight);
+    };
     useExpose({
-      scrollToDate
+      scrollToDate,
+      initPosition
     });
     const setDefaultRange = (monthsNum: number, current: number) => {
       let rangeArr: number[] = [];

+ 7 - 1
src/packages/__VUE/calendaritem/index.vue

@@ -624,8 +624,14 @@ export default create({
         }
       });
     };
+    const initPosition = () => {
+      if (months?.value) {
+        months.value.scrollTop = state.monthsData[state.currentIndex].cssScrollHeight;
+      }
+    };
     useExpose({
-      scrollToDate
+      scrollToDate,
+      initPosition
     });
     // 设置当前可见月份
     const setDefaultRange = (monthsNum: number, current: number) => {

+ 1 - 0
src/packages/__VUE/calendaritem/type.ts

@@ -71,4 +71,5 @@ export interface MonthInfo {
 }
 export interface CalendarRef extends HTMLElement {
   scrollToDate: (date: string) => void;
+  initPosition: () => void;
 }