浏览代码

选段提示

liushengqiang 2 年之前
父节点
当前提交
4e7c40bafc
共有 1 个文件被更改,包括 16 次插入19 次删除
  1. 16 19
      src/state.ts

+ 16 - 19
src/state.ts

@@ -1,4 +1,4 @@
-import { showToast } from "vant";
+import { closeToast, showToast } from "vant";
 import { reactive } from "vue";
 import { OpenSheetMusicDisplay } from "../osmd-extended/src";
 import { metronomeData } from "./helpers/metronome";
@@ -89,8 +89,6 @@ const state = reactive({
 	sectionStatus: false,
 	/** 选段数据 */
 	section: [] as any[],
-	/** 选段提示 */
-	sectionToast: null as any,
 	/** 选段背景 */
 	sectionBoundingBoxs: [] as any[],
 	/** 开启选段预备 */
@@ -387,7 +385,7 @@ export const handleSetSpeed = (speed: number) => {
 export const clearSelection = () => {
 	state.sectionStatus = false;
 	state.section = [];
-	state.sectionToast?.close();
+	closeToast();
 };
 
 /** 开启选段 */
@@ -404,18 +402,12 @@ export const handleChangeSection = () => {
 	if (state.sectionStatus) {
 		togglePlay("paused");
 	}
-	if (state.sectionToast) {
-		state.sectionToast.message = "请选择开始小节"
-		state.sectionToast.duration = 0
-		state.sectionToast.toggle(true)
-	} else {
-		state.sectionToast = showToast({
-			message: "请选择开始小节",
-			duration: 0,
-			position: "top",
-			className: "selectionToast",
-		});
-	}
+	showToast({
+		message: "请选择开始小节",
+		duration: 0,
+		position: "top",
+		className: "selectionToast",
+	})
 };
 
 /** 效验并格式化选段小节 */
@@ -451,11 +443,16 @@ export const handleSelection = (item: any) => {
 		state.section.push(item);
 		if (state.section.length === 2) {
 			state.section = formateSelectMearure(state.section);
-			state.sectionToast?.close();
+			closeToast();
 		}
 	}
-	if (state.section.length === 1 && state.sectionToast) {
-		state.sectionToast.message = "请选择结束小节";
+	if (state.section.length === 1) {
+		showToast({
+			message: "请选择结束小节",
+			duration: 0,
+			position: "top",
+			className: "selectionToast",
+		})
 	}
 };