index.tsx 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226
  1. import { PropType, computed, defineComponent, nextTick, onBeforeMount, onMounted, onUnmounted, reactive, ref, toRef } from "vue";
  2. import styles from "./index.module.less";
  3. import icons from "./image/icons.json";
  4. import { FIGNER_INSTRUMENT_DATA, FIGNER_INSTRUMENT_REALKEY, IFIGNER_INSTRUMENT_Note } from "/src/view/figner-preview";
  5. import { ITypeFingering, IVocals, getFingeringConfig, mappingVoicePart, subjectFingering } from "/src/view/fingering/fingering-config";
  6. import { Howl } from "howler";
  7. import { storeData } from "/src/store";
  8. import { api_back, api_cloudLoading, api_setRequestedOrientation, api_setStatusBarVisibility, isSpecialShapedScreen } from "/src/helpers/communication";
  9. import Hammer from "hammerjs";
  10. import { Button, Icon, Loading, Popover, Popup, Progress, Space, showToast } from "vant";
  11. import GuideIndex from "./guide/guide-index";
  12. import { getQuery } from "/src/utils/queryString";
  13. import { browser } from "/src/utils";
  14. import { usePageVisibility } from "@vant/use";
  15. import { watch } from "vue";
  16. import icon_loading_img from "./image/icon_loading_img.png";
  17. import noteImg from "./image/noteImg.png";
  18. import state, { IPlatform } from "/src/state";
  19. import { api_musicalInstrumentList, api_subjectList, getSubjectList } from "../api";
  20. import ChangeSubject from "./change-subject";
  21. import { Tabs, Tab } from "vant";
  22. import useDrag from "/src/hooks/useDrag";
  23. import Dragbom from "/src/hooks/useDrag/dragbom";
  24. import useDragGuidance from "/src/hooks/useDrag/useDragGuidance";
  25. import { FINER_INSTRUMENT_POINT } from "./fingeringPoint";
  26. export default defineComponent({
  27. name: "viewFigner",
  28. emits: ["close"],
  29. props: {
  30. show: {
  31. type: Boolean,
  32. default: true,
  33. },
  34. isComponent: {
  35. type: Boolean,
  36. default: false,
  37. },
  38. subject: {
  39. type: String as PropType<IVocals>,
  40. default: "",
  41. },
  42. },
  43. setup(props, { emit }) {
  44. const query = getQuery();
  45. const browsInfo = browser();
  46. const tempCode = query.code ? query.code.split(",")[0] : "";
  47. const code = mappingVoicePart(tempCode, "INSTRUMENT");
  48. const subject = props.isComponent ? props.subject || "pan-flute" : code || "pan-flute";
  49. const data = reactive({
  50. linkSource: query.linkSource, // 来源,目前只有课件里使用
  51. loading: true,
  52. subject: subject as any,
  53. realKey: 0,
  54. notes: [] as IFIGNER_INSTRUMENT_Note[],
  55. notePoints: [] as any, // 显示的点
  56. tones: [] as IFIGNER_INSTRUMENT_Note[],
  57. activeTone: {} as IFIGNER_INSTRUMENT_Note,
  58. popupActiveTone: {} as IFIGNER_INSTRUMENT_Note,
  59. activeToneName: "",
  60. soundFonts: {} as any,
  61. viewIndex: 0,
  62. viewTotal: 1,
  63. noteAudio: null as unknown as Howl,
  64. transform: {
  65. scale: 1,
  66. x: 0,
  67. y: 0,
  68. startScale: 1,
  69. startX: 0,
  70. startY: 0,
  71. transition: "",
  72. },
  73. tipShow: false,
  74. tips: [] as IFIGNER_INSTRUMENT_Note[],
  75. tnoteShow: false,
  76. loadingSoundFonts: true,
  77. loadingSoundProgress: 0,
  78. changeSubjectShow: false,
  79. huaweiPad: navigator?.userAgent?.includes("UAWEIVRD-W09") ? true : false,
  80. paddingTop: "",
  81. paddingLeft: "",
  82. subjects: [] as any,
  83. fingeringModeList: [
  84. {
  85. text: "指法模式",
  86. value: "fingeringMode",
  87. icon: icons.icon_click,
  88. },
  89. {
  90. text: "听音模式",
  91. value: "listenMode",
  92. icon: icons.icon_listen,
  93. },
  94. {
  95. text: "音阶模式",
  96. value: "scaleMode",
  97. icon: icons.icon_mode,
  98. },
  99. ],
  100. fingeringMode: query.type || ("scaleMode" as "fingeringMode" | "listenMode" | "scaleMode"), // 模式
  101. noteType: "all" as "#c" | "all", // 音调
  102. loadingDom: false, // 切换乐器时需要重置
  103. loadingImg: false, // 切换模式,加载图片
  104. domOverlapping: false, // 元素是否被遮住
  105. domOverImgPropery: {
  106. width: "100%",
  107. height: "100%",
  108. } as any,
  109. });
  110. const fingerData = reactive({
  111. relationshipIndex: 0,
  112. subject: null as unknown as ITypeFingering,
  113. fingeringInfo: subjectFingering(data.subject),
  114. });
  115. if (!props.isComponent) {
  116. state.fingeringInfo = fingerData.fingeringInfo;
  117. }
  118. const getAPPData = async (type: "top" | "left") => {
  119. const screenData = await isSpecialShapedScreen();
  120. if (screenData?.content) {
  121. console.log("🚀 ~ screenData:", screenData.content);
  122. const { isSpecialShapedScreen, notchHeight } = screenData.content;
  123. if (isSpecialShapedScreen) {
  124. if (type === "top") {
  125. data.paddingTop = 25 + "px";
  126. }
  127. if (type === "left") {
  128. data.paddingLeft = 25 + "px";
  129. }
  130. }
  131. }
  132. };
  133. const getHeadTop = () => {
  134. if (fingerData.fingeringInfo.orientation === 1) {
  135. getAPPData("top");
  136. }
  137. if (fingerData.fingeringInfo.orientation === 0) {
  138. getAPPData("left");
  139. }
  140. };
  141. const getNotes = () => {
  142. const fignerData = FIGNER_INSTRUMENT_DATA[data.subject as keyof typeof FIGNER_INSTRUMENT_DATA];
  143. if (fignerData) {
  144. data.tones = fignerData.tones || [];
  145. if (data.tones.length) {
  146. data.activeTone = data.tones[0];
  147. data.popupActiveTone = data.tones[0];
  148. }
  149. data.tips = fignerData.tips || [];
  150. setNotes();
  151. setTimeout(() => {
  152. data.loading = false;
  153. }, 600);
  154. }
  155. };
  156. const setNotes = () => {
  157. const fignerData = FIGNER_INSTRUMENT_DATA[data.subject as keyof typeof FIGNER_INSTRUMENT_DATA];
  158. if (fignerData) {
  159. const tempNotes = fignerData[`list${data.activeTone.realName || ""}`];
  160. const appendNote: any = [];
  161. tempNotes.forEach((note: any) => {
  162. note.steps = new Array(Math.abs(note.step)).fill(1);
  163. if (FIGNER_INSTRUMENT_REALKEY.includes(note.realKey)) {
  164. appendNote.push(note);
  165. }
  166. });
  167. // 判断是音符状态
  168. data.notes = data.noteType === "#c" ? appendNote : tempNotes;
  169. // data.notes = fignerData[`list${data.activeTone.realName || ""}`];
  170. data.notePoints = FINER_INSTRUMENT_POINT[data.subject];
  171. }
  172. };
  173. const getFingeringData = async () => {
  174. const subject: any = data.subject + (data.viewIndex === 0 ? "" : data.viewIndex);
  175. console.log("🚀 ~ subject:模式", subject, data.viewIndex, data.fingeringMode);
  176. fingerData.subject = await getFingeringConfig(subject);
  177. };
  178. const createAudio = (url: string) => {
  179. return new Promise((resolve, reject) => {
  180. const noteAudio = new Howl({
  181. src: url,
  182. loop: true,
  183. onload: () => {
  184. resolve(noteAudio);
  185. },
  186. onloaderror: () => {
  187. reject(new Error(`加载音频失败`));
  188. },
  189. });
  190. });
  191. };
  192. const getSounFonts = async () => {
  193. const pathname = /(192|localhost)/.test(location.origin) ? "/" : location.pathname;
  194. data.loadingSoundFonts = true;
  195. try {
  196. data.loadingSoundProgress = 0;
  197. for (let i = 0; i < data.notes.length; i++) {
  198. const note = data.notes[i];
  199. // console.log("🚀 ~ note:", i);
  200. let url = `${pathname}soundfonts/${data.subject}/`;
  201. url += note.realName;
  202. url += ".mp3";
  203. data.soundFonts[note.realKey] = await createAudio(url);
  204. data.loadingSoundProgress = Math.floor(((i + 1) / data.notes.length) * 100);
  205. }
  206. data.loadingSoundProgress = 100;
  207. } catch (e: any) {
  208. //
  209. showToast(e.message);
  210. }
  211. api_cloudLoading();
  212. data.loadingSoundFonts = false;
  213. };
  214. // const selectSubjectType = (subject: string) => {
  215. // data.subjects.forEach((item: any) => {
  216. // if (item.value === subject) {
  217. // item.className = styles.selected;
  218. // } else {
  219. // item.className = "";
  220. // }
  221. // });
  222. // };
  223. // 切换当前模式
  224. const onChangeFingeringModel = (e: any) => {
  225. e.stopPropagation();
  226. //
  227. if (playAction.listenLock) return;
  228. if (playAction.showAnswerLoading) return;
  229. data.loadingImg = true;
  230. if (data.fingeringMode === "scaleMode") {
  231. if (["pan-flute", "ocarina", "whistling"].includes(data.subject)) {
  232. data.viewIndex = 1;
  233. } else {
  234. data.viewIndex = 0;
  235. }
  236. const o: any = {
  237. "pan-flute": 2,
  238. ocarina: 2,
  239. whistling: 2,
  240. piccolo: 2,
  241. "hulusi-flute": 2,
  242. "baroque-recorder": 2,
  243. };
  244. data.viewTotal = o[data.subject] || 1;
  245. data.fingeringMode = "listenMode";
  246. } else if (data.fingeringMode === "listenMode") {
  247. data.fingeringMode = "fingeringMode";
  248. } else if (data.fingeringMode === "fingeringMode") {
  249. data.fingeringMode = "scaleMode";
  250. data.viewIndex = 0;
  251. data.noteType = "all";
  252. }
  253. data.tipShow = false;
  254. resetElement();
  255. resetMode(true, 0);
  256. setTimeout(() => {
  257. __init(false);
  258. }, 100);
  259. };
  260. const __init = async (loadSong = true) => {
  261. data.loadingDom = true;
  262. getNotes();
  263. // selectSubjectType(data.subject);
  264. if (data.fingeringMode === "fingeringMode") {
  265. if (data.subject === "pan-flute") {
  266. data.viewIndex = 3;
  267. } else if (["pan-flute", "ocarina", "melodica", "whistling"].includes(data.subject)) {
  268. data.viewIndex = 1;
  269. }
  270. } else {
  271. if (["pan-flute", "ocarina", "whistling"].includes(data.subject)) {
  272. data.viewIndex = 1;
  273. }
  274. }
  275. // 音阶模式 默认设置正反面
  276. if(data.fingeringMode === "scaleMode"){
  277. if(["hulusi-flute", "ocarina", "whistling", "piccolo", "baroque-recorder"].includes(data.subject)){
  278. data.viewIndex = 2;
  279. }
  280. }
  281. const o: any = {
  282. "pan-flute": 2,
  283. ocarina: 2,
  284. whistling: 2,
  285. piccolo: 2,
  286. "hulusi-flute": 2,
  287. "baroque-recorder": 2,
  288. };
  289. data.viewTotal = o[data.subject] || 1;
  290. getFingeringData();
  291. getHeadTop();
  292. if (loadSong) {
  293. await getSounFonts();
  294. }
  295. data.loadingDom = false;
  296. data.loadingImg = false;
  297. // 初始化获取元素宽高
  298. onResize();
  299. };
  300. // 获取声部
  301. const getSubjects = async () => {
  302. try {
  303. // api_subjectList
  304. // const subjects = await api_musicalInstrumentList({
  305. // enableFlag: true,
  306. // });
  307. // const rows = subjects.data || [];
  308. // rows.forEach((row: any) => {
  309. // const tempList: any = {
  310. // text: row.name,
  311. // value: mappingVoicePart(row.code, "INSTRUMENT"), // mappingVoicePart(row.code, "INSTRUMENT"),
  312. // id: row.id,
  313. // };
  314. // data.subjects.push(tempList);
  315. // });
  316. const subjects = await api_subjectList({
  317. enableFlag: true,
  318. delFlag: 0,
  319. page: 1,
  320. rows: 999,
  321. });
  322. const rows = subjects.data || [];
  323. const tempSubjects: any[] = [];
  324. rows.forEach((row: any) => {
  325. const tempList: any = {
  326. text: row.name,
  327. value: "", // mappingVoicePart(row.code, "INSTRUMENT"),
  328. id: row.id,
  329. children: [] as any,
  330. };
  331. if (Array.isArray(row.instruments)) {
  332. row.instruments.forEach((i: any) => {
  333. const code = i.code ? i.code.split(",") : [];
  334. tempList.children.push({
  335. text: i.name,
  336. id: i.id,
  337. value: mappingVoicePart(code[0] || "", "INSTRUMENT"),
  338. });
  339. });
  340. }
  341. tempSubjects.push(tempList);
  342. });
  343. console.log(data.subject, "data.subject");
  344. data.subjects = tempSubjects;
  345. } catch (e) {
  346. //
  347. console.log(e, "e");
  348. }
  349. };
  350. onBeforeMount(async () => {
  351. if (browser().isApp) {
  352. state.platform = "APP" as IPlatform;
  353. } else {
  354. state.platform = query.platform?.toLocaleUpperCase() || "";
  355. }
  356. if (state.platform === IPlatform.PC) {
  357. document.title = "听音练习";
  358. }
  359. await getSubjects();
  360. __init();
  361. });
  362. // 播放时间
  363. let noteTimer: any = null;
  364. /**
  365. * 播放音频
  366. * @param item 音频节点
  367. * @param showNote 是否显示对应的指法
  368. * @param isScrollShowNote 是否滚动到对应播放的位置
  369. * @param autoStop 是否自动停止
  370. * @returns
  371. */
  372. const noteClick = (item: IFIGNER_INSTRUMENT_Note, showNote = true, isScrollShowNote = false, autoStop = false, callBack?: any) => {
  373. // console.log('音高', item.realKey)
  374. if (data.noteAudio) {
  375. data.noteAudio.stop();
  376. if (data.realKey === item.realKey) {
  377. data.realKey = 0;
  378. data.noteAudio = null as unknown as Howl;
  379. return;
  380. }
  381. clearTimeout(noteTimer);
  382. }
  383. if (showNote) {
  384. data.realKey = item.realKey;
  385. }
  386. // console.log("key:", item.realKey, data.soundFonts);
  387. data.noteAudio = data.soundFonts[item.realKey];
  388. if (data.noteAudio) {
  389. clearTimeout(noteTimer);
  390. data.noteAudio.play();
  391. if (isScrollShowNote) scrollAnswer(item.realKey);
  392. // 判断是否自动停止播放停止
  393. if (autoStop) return;
  394. noteTimer = setTimeout(() => {
  395. handleStop();
  396. if (callBack && typeof callBack === "function") {
  397. callBack(item);
  398. }
  399. }, 300);
  400. }
  401. };
  402. const handleStop = () => {
  403. if (data.noteAudio) {
  404. data.noteAudio.stop();
  405. data.realKey = 0;
  406. data.noteAudio = null as unknown as Howl;
  407. }
  408. };
  409. const isLongPress = ref(false); // 是否长按
  410. const isTouchStart = ref(false); // 是否长按
  411. let isTouch = false;
  412. let timerNoteId: any;
  413. const longPressDuration = 200;
  414. const onLongPress = () => {
  415. console.log("长按检测成功!");
  416. isLongPress.value = true;
  417. clearTimeout(noteTimer);
  418. };
  419. // 开始长按检测
  420. const startNotePress = async (note: any, isScrollShowNote = true) => {
  421. if (playStatus.gamut) return;
  422. if (playAction.listenLock) return;
  423. if (playAction.showAnswerLoading) return;
  424. timerNoteId = setTimeout(onLongPress, longPressDuration);
  425. // 为了处理希沃白板垃圾事件
  426. if (isTouchStart.value) return;
  427. isTouchStart.value = true;
  428. if (playStatus.action) {
  429. playAction.userAnswer = note;
  430. // 判断用户答题
  431. const userResult = note.realKey === playAction.standardAnswer.realKey ? 1 : 2;
  432. playAction.userAnswerStatus = userResult;
  433. playAction.listenLock = true;
  434. data.realKey = note.realKey;
  435. noteClick(note, true, isScrollShowNote, false, playCallBack);
  436. } else {
  437. handleStop();
  438. noteClick(note, true, isScrollShowNote);
  439. }
  440. };
  441. // 取消长按检测
  442. const cancelNotePress = async (note: any, isScrollShowNote = true) => {
  443. if (timerNoteId !== null) {
  444. clearTimeout(timerNoteId);
  445. timerNoteId = null;
  446. }
  447. if (isLongPress.value) {
  448. handleStop();
  449. playCallBack(note);
  450. }
  451. if (isLongPress.value) {
  452. isLongPress.value = false;
  453. }
  454. isTouchStart.value = false;
  455. console.log(isLongPress.value, timerNoteId, note.realName);
  456. };
  457. const playCallBack = (note: any) => {
  458. if (playAction.listenLock) {
  459. const userResult = note.realKey === playAction.standardAnswer.realKey ? 1 : 2;
  460. resetMode(userResult === 1 ? true : false, 0);
  461. data.realKey = 0;
  462. // 如果是指法模式显示完之后要还原
  463. if (data.fingeringMode === "fingeringMode" && userResult === 2) {
  464. // 延迟显示,因为重置的时候有一个异步操作
  465. setTimeout(() => {
  466. data.realKey = playAction.standardAnswer.realKey;
  467. }, 10);
  468. }
  469. playAction.listenLock = false;
  470. }
  471. };
  472. /** 点击音符播放 */
  473. const noteInstrumentPlay = async (note: any, isScroll = false) => {
  474. // 判断是否在播放音阶
  475. if (playStatus.gamut) return;
  476. if (playAction.listenLock) return;
  477. if (playAction.showAnswerLoading) return;
  478. if (playStatus.action) {
  479. playAction.userAnswer = note;
  480. // 判断用户答题
  481. const userResult = note.realKey === playAction.standardAnswer.realKey ? 1 : 2;
  482. playAction.userAnswerStatus = userResult;
  483. playAction.listenLock = true;
  484. data.realKey = note.realKey;
  485. await fingeringPlay(note, 1000);
  486. resetMode(userResult === 1 ? true : false, 0);
  487. data.realKey = 0;
  488. // 如果是指法模式显示完之后要还原
  489. if (data.fingeringMode === "fingeringMode" && userResult === 2) {
  490. // 延迟显示,因为重置的时候有一个异步操作
  491. setTimeout(() => {
  492. data.realKey = playAction.standardAnswer.realKey;
  493. }, 10);
  494. }
  495. playAction.listenLock = false;
  496. } else {
  497. noteClick(note, true, isScroll);
  498. }
  499. };
  500. /** 返回 */
  501. const handleBack = () => {
  502. // platform: query.platform,
  503. handleStop();
  504. if (props.isComponent) {
  505. // 返回的时候默认横屏
  506. // api_setRequestedOrientation(0);
  507. emit("close");
  508. return;
  509. } else if (state.platform === IPlatform.PC) {
  510. console.log(1, query);
  511. if (query.matchMedia == 1) {
  512. // 老师端,首页
  513. window.parent.postMessage(
  514. {
  515. api: "iframe_exit",
  516. },
  517. "*"
  518. );
  519. return;
  520. } else {
  521. window.close();
  522. return;
  523. }
  524. // if (fingerData.fingeringInfo.orientation === 0) {
  525. // api_setRequestedOrientation(1);
  526. // }
  527. }
  528. // 不在APP中,
  529. if (!storeData.isApp) {
  530. window.close();
  531. return;
  532. }
  533. api_back();
  534. };
  535. // 排箫,默认0.9显示
  536. const setDefaultScale = () => {
  537. if (data.subject === "pan-flute") {
  538. data.transform.scale = 0.9;
  539. data.transform.startScale = 0.9;
  540. }
  541. };
  542. onMounted(() => {
  543. loadElement();
  544. api_setStatusBarVisibility();
  545. });
  546. // 判断两个元素是否重叠
  547. const isElementOverlapping = (el1: any, el2: any) => {
  548. const rect1 = el1?.getBoundingClientRect();
  549. const rect2 = el2?.getBoundingClientRect();
  550. return !(rect1.right < rect2.left || rect1.left > rect2.right || rect1.bottom < rect2.top || rect1.top > rect2.bottom);
  551. };
  552. // 是否在拖拽
  553. const isDragging = ref(false);
  554. const loadElement = () => {
  555. const fingeringContainer = document.getElementById("fingeringContainer");
  556. setDefaultScale();
  557. // console.log("🚀 ~ fingeringContainer:", fingeringContainer);
  558. const mc = new Hammer.Manager(fingeringContainer as HTMLElement);
  559. mc.add(new Hammer.Pan({ threshold: 0, pointers: 0 }));
  560. mc.add(new Hammer.Pinch({ threshold: 0 })).recognizeWith([mc.get("pan")]);
  561. let dragTimeout: any;
  562. mc.on("panstart pinchstart", function (ev) {
  563. isDragging.value = true;
  564. clearTimeout(dragTimeout);
  565. data.transform.transition = "";
  566. });
  567. mc.on("panmove pinchmove", function (ev) {
  568. if (ev.type === "pinchmove") {
  569. // console.log("🚀 ~ ev:", ev.type, ev.scale, ev.deltaX, ev.deltaY);
  570. data.transform.scale = ev.scale * data.transform.startScale;
  571. data.transform.x = data.transform.startX + ev.deltaX;
  572. data.transform.y = data.transform.startY + ev.deltaY;
  573. // 使用示例
  574. const element1 = document.getElementById("fullInstrumentImg");
  575. const element2 = document.getElementById("fullInstrumentUserTab");
  576. data.domOverlapping = isElementOverlapping(element1, element2);
  577. }
  578. if (ev.type === "panmove") {
  579. // console.log("🚀 ~ ev:", ev.type, ev.deltaX, ev.deltaY);
  580. data.transform.x = data.transform.startX + ev.deltaX;
  581. data.transform.y = data.transform.startY + ev.deltaY;
  582. // 使用示例
  583. const element1 = document.getElementById("fullInstrumentImg");
  584. const element2 = document.getElementById("fullInstrumentUserTab");
  585. data.domOverlapping = isElementOverlapping(element1, element2);
  586. }
  587. });
  588. mc.on("panend pinchend", function (ev) {
  589. dragTimeout = setTimeout(() => {
  590. isDragging.value = false;
  591. }, 100); // 设置一个短暂的延迟以确保拖拽操作结束
  592. });
  593. //
  594. mc.on("hammer.input", function (ev) {
  595. if (ev.isFinal) {
  596. // isDragging.value = false;
  597. data.transform.startScale = data.transform.scale;
  598. data.transform.startX = data.transform.x;
  599. data.transform.startY = data.transform.y;
  600. // 使用示例
  601. const element1 = document.getElementById("fullInstrumentImg");
  602. const element2 = document.getElementById("fullInstrumentUserTab");
  603. data.domOverlapping = isElementOverlapping(element1, element2);
  604. }
  605. });
  606. };
  607. const resetElement = () => {
  608. data.transform.transition = "all 0.3s";
  609. nextTick(() => {
  610. data.transform.scale = data.subject === "pan-flute" ? 0.9 : 1;
  611. data.transform.x = 0;
  612. data.transform.y = 0;
  613. data.transform.startScale = data.subject === "pan-flute" ? 0.9 : 1;
  614. data.transform.startX = 0;
  615. data.transform.startY = 0;
  616. data.domOverlapping = false;
  617. });
  618. };
  619. // 判断乐器是否移动
  620. const instrumentTranstion = computed(() => {
  621. const transform = data.transform;
  622. let scale = 1;
  623. if (data.subject === "pan-flute") {
  624. scale = 0.9;
  625. }
  626. if (transform.scale !== scale || transform.x !== 0 || transform.y !== 0 || transform.startScale !== scale || transform.startX !== 0 || transform.startY !== 0) {
  627. return true;
  628. } else {
  629. return false;
  630. }
  631. });
  632. const pageVisible = usePageVisibility();
  633. watch(
  634. () => pageVisible.value,
  635. (val) => {
  636. if (val === "hidden") {
  637. clearTimeout(playAction.timer);
  638. playAction.listenLock = false;
  639. playAction.listenTipsStatus = false;
  640. playAction.exampleAnser = {};
  641. resetMode(true, 0);
  642. handleStop();
  643. gaumntPause();
  644. }
  645. }
  646. );
  647. watch(
  648. () => data.tipShow,
  649. (val: any) => {
  650. if (!val) {
  651. onResize();
  652. }
  653. }
  654. );
  655. /** 课件播放 */
  656. const changePlay = (res: any) => {
  657. if (res?.data?.api === "setPlayState") {
  658. clearTimeout(playAction.timer);
  659. playAction.listenLock = false;
  660. playAction.listenTipsStatus = false;
  661. playAction.exampleAnser = {};
  662. resetMode(true, 0);
  663. handleStop();
  664. gaumntPause();
  665. // 重置乐器
  666. if (res?.data?.data?.code) {
  667. data.subject = code;
  668. data.viewIndex = 0;
  669. data.tipShow = false;
  670. data.loadingDom = true;
  671. fingerData.fingeringInfo = subjectFingering(data.subject);
  672. data.activeTone = {} as any;
  673. data.popupActiveTone = {} as any;
  674. resetElement();
  675. // 设置屏幕方向
  676. setTimeout(() => {
  677. __init();
  678. }, 100);
  679. }
  680. } else if (res.data.api === "startPlayState") {
  681. onStartPlayState();
  682. }
  683. };
  684. const onStartPlayState = () => {
  685. if (!localStorage.getItem("fingerGuideKey")) return;
  686. if (!(props.show && !data.loading && !data.loadingSoundFonts)) return;
  687. if (data.changeSubjectShow) return;
  688. if (data.fingeringMode === "fingeringMode" || data.fingeringMode === "listenMode") {
  689. onActionPlay();
  690. }
  691. };
  692. const noteBoxRef = ref();
  693. const scrollNoteBox = (type: "left" | "right") => {
  694. const domOffsetWidth = noteBoxRef.value.offsetWidth;
  695. const width = domOffsetWidth / 2;
  696. const scrollLeft: any = noteBoxRef.value.scrollLeft;
  697. // 判断是否移动到最左边
  698. if (width >= scrollLeft && type === "left") {
  699. // 不管当前显示在哪个音老师滚动到开始位置
  700. (noteBoxRef.value as unknown as HTMLElement).scroll({
  701. left: 0,
  702. top: 0,
  703. behavior: "smooth",
  704. });
  705. return;
  706. }
  707. // 处理在部分手机点击左右会超出范围
  708. if (type === "right") {
  709. // 遍历子元素并累加它们的宽度
  710. let childElementsWidth = 0;
  711. for (let i = 0; i < noteBoxRef.value.children.length; i++) {
  712. childElementsWidth += noteBoxRef.value.children[i].offsetWidth;
  713. }
  714. // 判断是否移动到最右边
  715. if (width > childElementsWidth - scrollLeft - domOffsetWidth) {
  716. // 不管当前显示在哪个音老师滚动到开始位置
  717. (noteBoxRef.value as unknown as HTMLElement).scroll({
  718. left: noteBoxRef.value.scrollWidth,
  719. top: 0,
  720. behavior: "smooth",
  721. });
  722. return;
  723. }
  724. }
  725. (noteBoxRef.value as unknown as HTMLElement).scrollBy({
  726. left: type === "left" ? -width : width,
  727. behavior: "smooth",
  728. });
  729. };
  730. const playStatus = reactive({
  731. gamut: false, // 是否播放音阶
  732. gamutTimer: null as any, // 播放音阶定时器
  733. answer: false, // 是否显示答案
  734. action: false, // 是否开始播放
  735. });
  736. /** 音符切换 */
  737. const noteChangeShow = () => {
  738. if (playStatus.action) {
  739. if (playAction.listenLock) return;
  740. playAction.resetAction = true;
  741. resetMode(true, 0);
  742. }
  743. // // 播放音阶时不能切换
  744. // if (playStatus.gamut) return;
  745. // // 开始答题不能切换
  746. // if (playStatus.action) return;
  747. playStatus.gamut = false;
  748. gaumntPause();
  749. if (data.noteType === "all") {
  750. data.noteType = "#c";
  751. } else {
  752. data.noteType = "all";
  753. }
  754. getNotes();
  755. setTimeout(() => {
  756. (noteBoxRef.value as unknown as HTMLElement).scroll({
  757. left: 0,
  758. top: 0,
  759. behavior: "smooth",
  760. });
  761. }, 0);
  762. setTimeout(() => {
  763. playAction.resetAction = false;
  764. }, 2000);
  765. };
  766. // 开始播放音阶
  767. const onGamutPlayOrPause = async () => {
  768. playAction.resetAction = false;
  769. if (playStatus.gamut) {
  770. playStatus.gamut = false;
  771. gaumntPause();
  772. } else {
  773. // 不管当前显示在哪个音老师滚动到开始位置
  774. (noteBoxRef.value as unknown as HTMLElement).scroll({
  775. left: 0,
  776. top: 0,
  777. behavior: "smooth",
  778. });
  779. playStatus.gamut = true;
  780. const notes = data.notes;
  781. let scrollCount = 0;
  782. for (let i = 0; i < notes.length; i++) {
  783. if (!playStatus.gamut) return false;
  784. const activeDom = document.querySelectorAll(".note-class")[i] as any;
  785. if (activeDom.offsetLeft >= noteBoxRef.value.offsetWidth + (noteBoxRef.value.offsetWidth / 2) * scrollCount - activeDom.offsetWidth) {
  786. scrollNoteBox("right");
  787. scrollCount++;
  788. }
  789. await gaumtPlay(notes[i]);
  790. }
  791. // // 处理播放到最后一个
  792. setTimeout(() => {
  793. playStatus.gamut = false;
  794. gaumntPause();
  795. }, 667);
  796. }
  797. };
  798. const gaumtPlay = (note: any, status?: boolean) => {
  799. return new Promise((resolve) => {
  800. playStatus.gamutTimer = setTimeout(() => {
  801. if (playStatus.gamut || status) {
  802. noteClick(note);
  803. }
  804. resolve(note);
  805. }, 667);
  806. });
  807. };
  808. const gaumntPause = () => {
  809. clearTimeout(playStatus.gamutTimer);
  810. if (data.noteAudio) {
  811. data.noteAudio.stop();
  812. data.realKey = 0;
  813. data.noteAudio = null as unknown as Howl;
  814. }
  815. };
  816. /** 开始播放 */
  817. const playAction = reactive({
  818. exampleAnser: {} as any, // 示例声音
  819. standardAnswer: {} as any, // 标准答案key
  820. showAnswerLoading: false, // 显示按答案中
  821. listenModeStatus: false, // 是否开始了模式
  822. listenLock: false,
  823. listenTipsStatus: false, // 开始播放状态
  824. resetAction: false, // 是否重置
  825. /** 0: 未答,1: 答对,2: 答错 */
  826. userAnswerStatus: 0 as 0 | 1 | 2, // 用户回答状态
  827. userAnswer: {} as any, // 用户答的数据
  828. timer: null as any,
  829. });
  830. const onActionPlay = async () => {
  831. playAction.resetAction = false;
  832. if (playAction.listenLock) return;
  833. if (playAction.showAnswerLoading) return;
  834. playStatus.action = true;
  835. playStatus.answer = true;
  836. // 先暂停播放声音
  837. gaumntPause();
  838. if (data.fingeringMode === "fingeringMode") {
  839. onFingeringMode();
  840. } else if (data.fingeringMode === "listenMode") {
  841. if (playAction.listenModeStatus) {
  842. playAction.listenLock = true;
  843. await fingeringPlay(playAction.standardAnswer, 1500, false);
  844. gaumntPause();
  845. playAction.listenLock = false;
  846. } else {
  847. onListenMode();
  848. }
  849. }
  850. };
  851. // 指法模式
  852. const fingeringPlay = (note: any, timer = 1500, showNote = true) => {
  853. return new Promise((resolve) => {
  854. noteClick(note, showNote);
  855. playAction.timer = setTimeout(() => {
  856. resolve(note);
  857. }, timer);
  858. });
  859. };
  860. const onFingeringMode = () => {
  861. const randomIndex = Math.floor(Math.random() * data.notes.length);
  862. playAction.standardAnswer = data.notes[randomIndex];
  863. data.realKey = data.notes[randomIndex].realKey;
  864. if (playAction.listenModeStatus) {
  865. return;
  866. }
  867. playAction.listenModeStatus = true; // 是否开始听音
  868. playAction.listenLock = true; // 锁
  869. playAction.listenTipsStatus = true;
  870. playAction.timer = setTimeout(() => {
  871. playAction.listenTipsStatus = false;
  872. playAction.listenLock = false; // 锁
  873. }, 2000);
  874. };
  875. // 听音模式
  876. const onListenMode = async () => {
  877. playAction.listenModeStatus = true; // 是否开始听音
  878. playAction.listenLock = true; // 锁
  879. playAction.listenTipsStatus = true;
  880. // 设置并保存示例数据
  881. let randomIndex = data.notes.findIndex((item: any) => item.realKey === 69); // Math.floor(Math.random() * data.notes.length);
  882. playAction.exampleAnser = data.notes[randomIndex];
  883. data.realKey = playAction.exampleAnser.realKey;
  884. scrollAnswer(playAction.exampleAnser.realKey);
  885. await fingeringPlay(playAction.exampleAnser);
  886. data.realKey = 0;
  887. playAction.exampleAnser = {};
  888. gaumntPause();
  889. playAction.timer = setTimeout(async () => {
  890. // 设置答题数据
  891. randomIndex = Math.floor(Math.random() * data.notes.length);
  892. playAction.standardAnswer = data.notes[randomIndex];
  893. await fingeringPlay(data.notes[randomIndex], 1500, false);
  894. gaumntPause();
  895. playAction.listenLock = false;
  896. playAction.listenTipsStatus = false;
  897. }, 1000);
  898. };
  899. // 显示答案
  900. const onShowAnswer = async () => {
  901. if (playAction.listenLock) return;
  902. playAction.showAnswerLoading = true;
  903. scrollAnswer(playAction.standardAnswer.realKey);
  904. await fingeringPlay(playAction.standardAnswer);
  905. resetMode(true, 0);
  906. // }
  907. };
  908. // 滚动到对应答案位置
  909. const scrollAnswer = (realKey?: any) => {
  910. const tempRealKey = realKey || data.realKey;
  911. const index = data.notes.findIndex((item: any) => item.realKey === tempRealKey);
  912. const activeDom = document.querySelectorAll(".note-class")[index] as any;
  913. if (activeDom) {
  914. const aWidth = activeDom.offsetWidth;
  915. const width = noteBoxRef.value.offsetWidth;
  916. const aLeft = Math.max(activeDom?.offsetLeft - aWidth, 0);
  917. (noteBoxRef.value as unknown as HTMLElement).scroll({
  918. left: Math.max(aLeft - width / 2, 0),
  919. top: 0,
  920. behavior: "smooth",
  921. });
  922. }
  923. };
  924. /**
  925. * 重置播放状态
  926. * @param status 是否全部重置
  927. * @param timer 延时时长(默认2s)
  928. */
  929. const resetMode = (status = true, timer = 2000) => {
  930. // 2秒钟后重置
  931. setTimeout(() => {
  932. gaumntPause();
  933. if (status) {
  934. playAction.standardAnswer = {};
  935. playAction.showAnswerLoading = false;
  936. playAction.userAnswerStatus = 0;
  937. playAction.userAnswer = {};
  938. playAction.listenModeStatus = false;
  939. playStatus.action = false;
  940. playStatus.answer = false;
  941. playStatus.gamut = false;
  942. data.realKey = 0;
  943. } else {
  944. playAction.userAnswerStatus = 0;
  945. playAction.userAnswer = {};
  946. }
  947. }, timer);
  948. };
  949. /** 滚轮缩放 */
  950. const handleWheel = (e: WheelEvent) => {
  951. e.preventDefault();
  952. if (e.deltaY > 0) {
  953. data.transform.scale -= 0.1;
  954. if (data.transform.scale <= 0.5) {
  955. data.transform.scale = 0.5;
  956. }
  957. } else {
  958. data.transform.scale += 0.1;
  959. if (data.transform.scale >= 2) {
  960. data.transform.scale = 2;
  961. }
  962. }
  963. // 使用示例
  964. setTimeout(() => {
  965. const element1 = document.getElementById("fullInstrumentImg");
  966. const element2 = document.getElementById("fullInstrumentUserTab");
  967. data.domOverlapping = isElementOverlapping(element1, element2);
  968. }, 0);
  969. };
  970. const onResize = () => {
  971. nextTick(() => {
  972. setTimeout(() => {
  973. const element1: any = document.querySelector("#fullInstrumentImg");
  974. // console.log(element1, "element1");
  975. const rect = element1?.getBoundingClientRect();
  976. data.domOverImgPropery = {
  977. ...rect,
  978. width: rect.width * (1 / data.transform.scale) + "px",
  979. height: rect.height * (1 / data.transform.scale) + "px",
  980. };
  981. }, 330);
  982. });
  983. };
  984. onMounted(() => {
  985. window.addEventListener("message", changePlay);
  986. window.addEventListener("resize", onResize);
  987. const fingeringContainer = document.getElementById("fingeringContainer");
  988. fingeringContainer?.addEventListener("wheel", handleWheel);
  989. document.addEventListener("keydown", (e: KeyboardEvent) => {
  990. if (e.code === "Tab") {
  991. e.stopPropagation();
  992. e.preventDefault();
  993. // onStartPlayState();
  994. // 判断是否在应用中
  995. window.parent.postMessage(
  996. {
  997. api: "documentBodyKeyup",
  998. code: "Tab",
  999. },
  1000. "*"
  1001. );
  1002. }
  1003. });
  1004. });
  1005. onUnmounted(() => {
  1006. window.removeEventListener("message", changePlay);
  1007. window.removeEventListener("resize", onResize);
  1008. const fingeringContainer = document.getElementById("fingeringContainer");
  1009. fingeringContainer?.removeEventListener("wheel", handleWheel);
  1010. document.title = "Ai学练";
  1011. });
  1012. const containerBox = computed(() => {
  1013. if (state.platform === IPlatform.PC || query.modelType) {
  1014. return {
  1015. paddingTop: "1.3rem",
  1016. paddingBottom: "",
  1017. };
  1018. }
  1019. if (data.fingeringMode === "scaleMode") {
  1020. if (data.subject === "hulusi-flute") {
  1021. return {
  1022. paddingTop: "1.3rem",
  1023. paddingBottom: ".5rem",
  1024. };
  1025. } else if (data.subject === "piccolo" || data.subject === "baroque-recorder") {
  1026. return {
  1027. paddingTop: "1.3rem",
  1028. paddingBottom: ".5rem",
  1029. };
  1030. } else if (data.subject === "pan-flute") {
  1031. return {
  1032. paddingTop: "1.3rem",
  1033. paddingBottom: "0",
  1034. };
  1035. } else if (data.subject === "ocarina" || data.subject === "whistling") {
  1036. return {
  1037. paddingTop: "1.3rem",
  1038. paddingBottom: "0",
  1039. };
  1040. } else if (data.subject === "melodica") {
  1041. return {
  1042. paddingTop: "1.8rem",
  1043. paddingBottom: "0.2rem",
  1044. };
  1045. } else {
  1046. return {
  1047. paddingTop: "",
  1048. paddingBottom: "",
  1049. };
  1050. }
  1051. } else {
  1052. if (data.subject === "hulusi-flute") {
  1053. return {
  1054. paddingTop: "1.3rem",
  1055. paddingBottom: "0rem",
  1056. };
  1057. } else if (data.subject === "piccolo" || data.subject === "baroque-recorder") {
  1058. return {
  1059. paddingTop: "1.3rem",
  1060. paddingBottom: ".5rem",
  1061. };
  1062. } else if (data.subject === "pan-flute") {
  1063. return {
  1064. paddingTop: "1.3rem",
  1065. paddingBottom: "0",
  1066. };
  1067. } else if (data.subject === "ocarina" || data.subject === "whistling") {
  1068. return {
  1069. paddingTop: "1.3rem",
  1070. paddingBottom: "0",
  1071. };
  1072. } else if (data.subject === "melodica") {
  1073. return {
  1074. paddingTop: "1.8rem",
  1075. paddingBottom: "0.2rem",
  1076. };
  1077. } else {
  1078. return {
  1079. paddingTop: "",
  1080. paddingBottom: "",
  1081. };
  1082. }
  1083. }
  1084. });
  1085. const listenText = computed(() => {
  1086. if (data.fingeringMode === "fingeringMode") {
  1087. if (playStatus.action) {
  1088. return "换一换";
  1089. } else {
  1090. return "开始练习";
  1091. }
  1092. } else if (data.fingeringMode === "listenMode") {
  1093. if (playStatus.action) {
  1094. return "再听一遍";
  1095. } else {
  1096. return "开始听音";
  1097. }
  1098. }
  1099. return "开始听音";
  1100. });
  1101. const modeText = computed(() => {
  1102. let text = "";
  1103. let icon = icons.icon_mode;
  1104. data.fingeringModeList.forEach((item: any) => {
  1105. if (item.value === data.fingeringMode) {
  1106. text = item.text;
  1107. icon = item.icon;
  1108. }
  1109. });
  1110. return {
  1111. text,
  1112. icon,
  1113. };
  1114. });
  1115. // 屏幕方向 0 竖,1 横
  1116. const orientationDirection = computed(() => {
  1117. return ["hulusi-flute", "piccolo", "baroque-recorder"].includes(data.subject) ? 1 : 0;
  1118. });
  1119. const resultImg = (note: any) => {
  1120. if (data.realKey === note.realKey && !playStatus.action) {
  1121. return {
  1122. icon: icons.icon_btn_ylow,
  1123. status: false,
  1124. };
  1125. } else if (playAction.exampleAnser.realKey === note.realKey) {
  1126. return {
  1127. icon: icons.icon_btn_ylow,
  1128. status: false,
  1129. };
  1130. } else if (playAction.standardAnswer.realKey === note.realKey) {
  1131. // 没有开始答题
  1132. if (!playStatus.action) {
  1133. return {
  1134. icon: icons.icon_btn_ylow,
  1135. status: false,
  1136. };
  1137. }
  1138. // 显示答案中
  1139. if (playAction.showAnswerLoading) {
  1140. return {
  1141. icon: icons.icon_btn_green,
  1142. status: true,
  1143. };
  1144. }
  1145. // 用户答对
  1146. if (playAction.userAnswerStatus === 1) {
  1147. return {
  1148. icon: icons.icon_btn_green,
  1149. status: true,
  1150. };
  1151. }
  1152. } else {
  1153. // 用户答错
  1154. if (playAction.userAnswerStatus === 2 && playAction.userAnswer.realKey === note.realKey) {
  1155. return {
  1156. icon: icons.icon_btn_red,
  1157. status: true,
  1158. };
  1159. }
  1160. }
  1161. return {
  1162. icon: icons.icon_btn_blue,
  1163. status: true,
  1164. };
  1165. };
  1166. const userTabActive = ref<"1" | "2">("1");
  1167. const userTabs = [
  1168. {
  1169. name: "音阶",
  1170. value: "1",
  1171. },
  1172. {
  1173. name: "功能",
  1174. value: "2",
  1175. },
  1176. ];
  1177. // 引导页
  1178. const { guidanceShow, setGuidanceShow } = useDragGuidance();
  1179. // 切换乐器弹窗
  1180. let changeSubjectShowBoxDragData: any;
  1181. let changeSubjectShowBoxClass: string;
  1182. if (query.platform === "pc") {
  1183. changeSubjectShowBoxClass = "changeSubjectShowBoxClass_drag";
  1184. changeSubjectShowBoxDragData = useDrag([`${changeSubjectShowBoxClass} .dragTopBox`, `${changeSubjectShowBoxClass} .dragbomBox`], changeSubjectShowBoxClass, toRef(data, "changeSubjectShow"), storeData.user.id as string);
  1185. }
  1186. // 移调弹窗
  1187. let tnoteShowBoxDragData: any;
  1188. let tnoteShowBoxClass: string;
  1189. if (query.platform === "pc") {
  1190. tnoteShowBoxClass = "tnoteShowBoxClass_drag";
  1191. tnoteShowBoxDragData = useDrag([`${tnoteShowBoxClass} .dragTopBox`, `${tnoteShowBoxClass} .dragbomBox`], tnoteShowBoxClass, toRef(data, "tnoteShow"), storeData.user.id as string);
  1192. }
  1193. return () => {
  1194. const relationship = fingerData.subject?.relationship?.[data.realKey] || [];
  1195. const rs: number[] = Array.isArray(relationship[1]) ? relationship[fingerData.relationshipIndex] : relationship;
  1196. const canTizhi = Array.isArray(relationship[1]);
  1197. return (
  1198. <div
  1199. class={[styles.fingerBox, state.platform !== IPlatform.PC && !query.modelType && fingerData.fingeringInfo.orientation === 1 ? styles.fingerBottom : styles.fingerRight, data.linkSource === "class" ? styles.linkSourceClass : ""]}
  1200. onClick={() => {
  1201. if (data.linkSource === "class") {
  1202. window.parent.postMessage(
  1203. {
  1204. api: "clickViewFigner",
  1205. },
  1206. "*"
  1207. );
  1208. }
  1209. }}
  1210. >
  1211. {/* 老师端过来隐藏 */}
  1212. {query.platform !== "pc" && (
  1213. <div
  1214. class={styles.head}
  1215. style={{
  1216. paddingTop: data.paddingTop && !browser().ios ? data.paddingTop : "",
  1217. paddingLeft: data.paddingLeft && !browser().ios ? data.paddingLeft : "",
  1218. }}
  1219. >
  1220. <div class={styles.left}>
  1221. <button class={[styles.backBtn]} onClick={() => handleBack()}>
  1222. <img src={icons.icon_back} />
  1223. </button>
  1224. <div
  1225. class={[styles.baseBtn, styles.changeInstrumentBtn]}
  1226. onClick={(e) => {
  1227. e.stopPropagation();
  1228. //
  1229. // 播放音阶时不能切换
  1230. if (playStatus.gamut) {
  1231. return;
  1232. }
  1233. // 开始答题不能切换
  1234. if (playAction.listenLock) {
  1235. return;
  1236. }
  1237. data.changeSubjectShow = true;
  1238. }}
  1239. >
  1240. <img src={icons.icon_change_instrument} />
  1241. <span>切换乐器</span>
  1242. </div>
  1243. <div class={styles.baseBtn} onClick={onChangeFingeringModel}>
  1244. <img src={modeText.value.icon} />
  1245. <span>{modeText.value.text}</span>
  1246. </div>
  1247. {/* */}
  1248. </div>
  1249. {/* */}
  1250. </div>
  1251. )}
  1252. <div
  1253. class={styles.fingerContent}
  1254. style={{
  1255. paddingTop: data.paddingTop ? data.paddingTop : "",
  1256. paddingLeft: data.paddingLeft ? data.paddingLeft : "",
  1257. }}
  1258. >
  1259. <div class={styles.wrapFinger}>
  1260. <div
  1261. id="fingeringContainer"
  1262. class={[styles.boxFinger, query.platform === "pc" ? styles.pcBoxFinger : "", data.domOverlapping && data.notePoints?.length > 0 && styles.boxFingerOverlapping]}
  1263. style={{
  1264. paddingTop: containerBox.value.paddingTop,
  1265. paddingBottom: containerBox.value.paddingBottom,
  1266. }}
  1267. >
  1268. <div
  1269. style={{
  1270. transform: `translate3d(${data.transform.x}px,${data.transform.y}px,0px) scale(${data.transform.scale})`,
  1271. transition: data.transform.transition,
  1272. }}
  1273. class={[styles.fingeringContainer]}
  1274. >
  1275. <div class={styles.imgs}>
  1276. {!data.loadingImg && <img id="fullInstrumentImg" src={data.fingeringMode === "scaleMode" ? fingerData.subject?.json?.full : fingerData.subject?.json?.full1} />}
  1277. {rs.map((key: number | string, index: number) => {
  1278. const nk: string = typeof key === "string" ? key.replace("active-", "") : String(key);
  1279. return <img class={styles.showImgNk} data-index={nk} src={fingerData.subject?.json?.[nk]} />;
  1280. })}
  1281. <div style={{ left: data.viewIndex == 2 ? "0" : "64%" }} class={[styles.tizhi, canTizhi && styles.canDisplay]} onClick={() => (fingerData.relationshipIndex = fingerData.relationshipIndex === 0 ? 1 : 0)}>
  1282. 替指
  1283. </div>
  1284. <div id="finger-note-2" style={{ left: "50%", transform: "translateX(-50%)" }} class={styles.tizhi} onClick={() => (fingerData.relationshipIndex = fingerData.relationshipIndex === 0 ? 1 : 0)}></div>
  1285. {data.notePoints?.length > 0 && (
  1286. <div
  1287. class={[styles.fingeringPointSection]}
  1288. style={{
  1289. width: data.domOverImgPropery.width,
  1290. height: data.domOverImgPropery.height,
  1291. }}
  1292. >
  1293. <div class={[styles[data.subject], data.viewIndex === 2 && data.subject === "pan-flute" && styles["pan-flute-back"]]}>
  1294. {data.notePoints.map((point: any) => (
  1295. <div
  1296. class={styles.p1}
  1297. style={point.style}
  1298. // onClick={(e: any) => {
  1299. // e.stopPropagation();
  1300. // if (isDragging.value) return;
  1301. // noteInstrumentPlay(point, true);
  1302. // }}
  1303. onMousedown={(e: any) => {
  1304. e.stopPropagation();
  1305. e.preventDefault();
  1306. console.log("onMousedown", e);
  1307. if (isTouch) return;
  1308. startNotePress(point);
  1309. }}
  1310. onMouseup={(e: any) => {
  1311. e.stopPropagation();
  1312. e.preventDefault();
  1313. // console.log("onMouseup", e);
  1314. if (isTouch) return;
  1315. cancelNotePress(point);
  1316. }}
  1317. onMouseleave={(e: any) => {
  1318. e.stopPropagation();
  1319. e.preventDefault();
  1320. // console.log("onMouseleave", e);
  1321. if (isTouch) return;
  1322. cancelNotePress(point);
  1323. }}
  1324. onTouchstart={(e: any) => {
  1325. e.stopPropagation();
  1326. e.preventDefault();
  1327. // console.log("onTouchstart", e);
  1328. isTouch = true;
  1329. startNotePress(point);
  1330. }}
  1331. onTouchend={(e: any) => {
  1332. e.stopPropagation();
  1333. e.preventDefault();
  1334. // console.log("onTouchend", e);
  1335. cancelNotePress(point);
  1336. }}
  1337. onTouchcancel={(e: any) => {
  1338. e.stopPropagation();
  1339. e.preventDefault();
  1340. // console.log("onTouchcancel", e);
  1341. cancelNotePress(point);
  1342. }}
  1343. >
  1344. {point.children && (
  1345. <div
  1346. class={styles.p2}
  1347. // onClick={(e: any) => {
  1348. // e.stopPropagation();
  1349. // if (isDragging.value) return;
  1350. // noteInstrumentPlay(point.children, true);
  1351. // }}
  1352. onMousedown={(e: any) => {
  1353. e.stopPropagation();
  1354. e.preventDefault();
  1355. if (isTouch) return;
  1356. startNotePress(point.children);
  1357. }}
  1358. onMouseup={(e: any) => {
  1359. e.stopPropagation();
  1360. e.preventDefault();
  1361. if (isTouch) return;
  1362. cancelNotePress(point.children);
  1363. }}
  1364. onMouseleave={(e: any) => {
  1365. e.stopPropagation();
  1366. e.preventDefault();
  1367. if (isTouch) return;
  1368. cancelNotePress(point.children);
  1369. }}
  1370. onTouchstart={(e: any) => {
  1371. e.stopPropagation();
  1372. e.preventDefault();
  1373. isTouch = true;
  1374. startNotePress(point.children);
  1375. }}
  1376. onTouchend={(e: any) => {
  1377. e.stopPropagation();
  1378. e.preventDefault();
  1379. cancelNotePress(point.children);
  1380. }}
  1381. onTouchcancel={(e: any) => {
  1382. e.stopPropagation();
  1383. e.preventDefault();
  1384. cancelNotePress(point.children);
  1385. }}
  1386. style={point.children.style}
  1387. ></div>
  1388. )}
  1389. </div>
  1390. ))}
  1391. </div>
  1392. </div>
  1393. )}
  1394. </div>
  1395. </div>
  1396. </div>
  1397. {/* 老师端过来隐藏 */}
  1398. {query.platform === "pc" ? (
  1399. <div class={[styles.userTab, data.domOverlapping && data.notePoints?.length > 0 && styles.usrTabOverlaping]} id="fullInstrumentUserTab">
  1400. <Tabs v-model:active={userTabActive.value} class={styles.userTabBox}>
  1401. {userTabs.map((item) => {
  1402. return (
  1403. <Tab title={item.name} name={item.value}>
  1404. {item.value === "1" ? (
  1405. <>
  1406. <div
  1407. class={styles.notes}
  1408. style={{
  1409. paddingLeft: data.paddingLeft ? data.paddingLeft : "",
  1410. }}
  1411. >
  1412. {playAction.listenTipsStatus && <div class={[styles.tipsT, data.fingeringMode === "fingeringMode" ? styles.playTips2 : styles.playTips]}></div>}
  1413. {playAction.userAnswerStatus === 1 && <div class={[styles.tipsT, styles.playSuccess]}></div>}
  1414. {playAction.userAnswerStatus === 2 && <div class={[styles.tipsT, styles.playError]}></div>}
  1415. {playAction.resetAction && <div class={[styles.tipsT, styles.playTips5]}></div>}
  1416. <div class={[styles.backBtn, styles.changeMusBtn]} onClick={() => handleBack()}>
  1417. <span>返回</span>
  1418. </div>
  1419. <div class={styles.changeMusBtn} onClick={onChangeFingeringModel}>
  1420. <span>{modeText.value.text}</span>
  1421. </div>
  1422. <div
  1423. class={[styles.noteContent, data.fingeringMode !== "scaleMode" && orientationDirection.value === 0 && styles.noteContentOther, browsInfo.ios ? "" : styles.noteContentWrap, data.huaweiPad && styles.huaweiPad]}
  1424. onClick={(e: any) => {
  1425. e.stopPropagation();
  1426. }}
  1427. >
  1428. {((data.noteType !== "#c" && (orientationDirection.value === 0 || (orientationDirection.value === 1 && state.platform === IPlatform.PC))) || (orientationDirection.value === 1 && state.platform === IPlatform.APP)) && (
  1429. <Button
  1430. class={styles.noteBtn}
  1431. onClick={(e: any) => {
  1432. e.stopPropagation();
  1433. scrollNoteBox("left");
  1434. }}
  1435. >
  1436. <Icon name="arrow-left" />
  1437. </Button>
  1438. )}
  1439. {/* 判断是否为音阶模式 */}
  1440. {data.fingeringMode !== "scaleMode" && (
  1441. <div draggable={false} class={styles.note} onClick={noteChangeShow}>
  1442. <img draggable={false} src={data.noteType === "all" ? icons.icon_btn_orange : icons.icon_btn_orange2} />
  1443. </div>
  1444. )}
  1445. {!!data.tones.length && data.fingeringMode === "scaleMode" && (
  1446. <>
  1447. {fingerData.fingeringInfo.name == "hulusi-flute" ? (
  1448. <div id="finger-note-1" class={[styles.note, styles.btnGrToggleBtn]} onClick={() => (data.tnoteShow = true)}>
  1449. <img draggable={false} src={noteImg} />
  1450. <div class={styles.nameBox}>
  1451. <div class={styles.name}>全按作</div>
  1452. <div class={[styles.noteKey, styles.noteKeyBtn]}>
  1453. {data.activeTone.step > 0 ? <span class={styles.dot}></span> : null}
  1454. <div class={styles.noteName}>
  1455. <sup>{data.activeTone.mark && (data.activeTone.mark === "rise" ? "#" : "b")}</sup>
  1456. {data.activeTone.key}
  1457. </div>
  1458. {data.activeTone.step < 0 ? <span class={[styles.dot, styles.botDot]}></span> : null}
  1459. </div>
  1460. </div>
  1461. </div>
  1462. ) : (
  1463. <div id="finger-note-1" class={[styles.note, styles.btnGrToggleBtn]} onClick={() => (data.tnoteShow = true)}>
  1464. <img draggable={false} src={noteImg} />
  1465. <div>
  1466. <div class={styles.name}>
  1467. <div>
  1468. <sup>{data.activeTone.mark && (data.activeTone.mark === "rise" ? "#" : "b")}</sup>
  1469. {data.activeTone.name}
  1470. </div>
  1471. </div>
  1472. </div>
  1473. </div>
  1474. )}
  1475. </>
  1476. )}
  1477. {/* [styles.noteContent, browsInfo.ios ? "" : styles.noteContentWrap, data.huaweiPad && styles.huaweiPad] */}
  1478. <div class={styles.lastNoteContent}>
  1479. <div ref={noteBoxRef} class={styles.noteBox}>
  1480. {data.notes.map((note: IFIGNER_INSTRUMENT_Note, index: number) => {
  1481. const steps = new Array(Math.abs(note.step)).fill(1);
  1482. return (
  1483. <div
  1484. id={index == 0 ? "finger-note-0" : ""}
  1485. draggable={false}
  1486. class={[styles.note, "note-class"]}
  1487. key={note.realKey}
  1488. // onClick={async () => {
  1489. // noteInstrumentPlay(note);
  1490. // }}
  1491. onMousedown={(e: any) => {
  1492. e.stopPropagation();
  1493. e.preventDefault();
  1494. if (isTouch) return;
  1495. startNotePress(note, false);
  1496. }}
  1497. onMouseup={(e: any) => {
  1498. e.stopPropagation();
  1499. e.preventDefault();
  1500. if (isTouch) return;
  1501. cancelNotePress(note, false);
  1502. }}
  1503. onMouseleave={(e: any) => {
  1504. e.stopPropagation();
  1505. e.preventDefault();
  1506. if (isTouch) return;
  1507. cancelNotePress(note, false);
  1508. }}
  1509. onTouchstart={(e: any) => {
  1510. e.stopPropagation();
  1511. e.preventDefault();
  1512. isTouch = true;
  1513. startNotePress(note, false);
  1514. }}
  1515. onTouchend={(e: any) => {
  1516. e.stopPropagation();
  1517. e.preventDefault();
  1518. cancelNotePress(note, false);
  1519. }}
  1520. onTouchcancel={(e: any) => {
  1521. e.stopPropagation();
  1522. e.preventDefault();
  1523. cancelNotePress(note, false);
  1524. }}
  1525. >
  1526. <img draggable={false} src={resultImg(note).icon} />
  1527. {playStatus.action && ((playAction.showAnswerLoading && playAction.standardAnswer.realKey === note.realKey) || (playAction.userAnswerStatus === 1 && playAction.userAnswer.realKey === note.realKey)) ? <span class={styles.showAnswer}></span> : ""}
  1528. {playStatus.action && playAction.userAnswerStatus === 2 && playAction.userAnswer.realKey === note.realKey ? <span class={[styles.showAnswer, styles.errorAnswer]}></span> : ""}
  1529. <div
  1530. class={[
  1531. styles.noteKey,
  1532. ((data.realKey === note.realKey && !playStatus.action) ||
  1533. (playStatus.action && playAction.exampleAnser.realKey === note.realKey) ||
  1534. (playStatus.action && ((playAction.showAnswerLoading && playAction.standardAnswer.realKey === note.realKey) || (playAction.userAnswerStatus === 1 && playAction.userAnswer.realKey === note.realKey))) ||
  1535. (playStatus.action && playAction.userAnswerStatus === 2 && playAction.userAnswer.realKey === note.realKey)) &&
  1536. styles.keyActive,
  1537. ]}
  1538. >
  1539. {/* 显示对应的点 */}
  1540. {note.step > 0 ? steps.map((n: any) => <span class={styles.dot}></span>) : null}
  1541. <div class={styles.noteName}>
  1542. <sup>{note.mark && (note.mark === "rise" ? "#" : "b")}</sup>
  1543. {note.key}
  1544. </div>
  1545. {/* 显示对应的点 */}
  1546. {note.step < 0 ? steps.map((n: any) => <span class={styles.dot}></span>) : null}
  1547. </div>
  1548. </div>
  1549. );
  1550. })}
  1551. </div>
  1552. </div>
  1553. {((data.noteType !== "#c" && (orientationDirection.value === 0 || (orientationDirection.value === 1 && state.platform === IPlatform.PC))) || (orientationDirection.value === 1 && state.platform === IPlatform.APP)) && (
  1554. <Button
  1555. class={styles.noteBtn}
  1556. onClick={(e: any) => {
  1557. e.stopPropagation();
  1558. scrollNoteBox("right");
  1559. }}
  1560. >
  1561. <Icon name="arrow" />
  1562. </Button>
  1563. )}
  1564. </div>
  1565. <div class={styles.restoreBox}>
  1566. {instrumentTranstion.value && (
  1567. <div class={[styles.restoreBtn]} onClick={() => resetElement()}>
  1568. </div>
  1569. )}
  1570. </div>
  1571. <div class={styles.moreFun}>
  1572. 更多功能
  1573. <div class={styles.btnBox}>
  1574. <div class={styles.btnCon}>
  1575. <div
  1576. class={[styles.btnGr]}
  1577. onClick={(e) => {
  1578. e.stopPropagation();
  1579. //
  1580. // 播放音阶时不能切换
  1581. if (playStatus.gamut) {
  1582. return;
  1583. }
  1584. // 开始答题不能切换
  1585. if (playAction.listenLock) {
  1586. return;
  1587. }
  1588. data.changeSubjectShow = true;
  1589. }}
  1590. >
  1591. <img src={icons.icon_change_instrument} />
  1592. <span>切换乐器</span>
  1593. </div>
  1594. {data.subject !== "melodica" && data.fingeringMode === "scaleMode" && (
  1595. <div
  1596. class={styles.btnGr}
  1597. onClick={(e) => {
  1598. e.stopPropagation();
  1599. data.viewIndex++;
  1600. if (data.viewIndex > data.viewTotal) {
  1601. if (["pan-flute", "ocarina", "whistling"].includes(data.subject)) {
  1602. data.viewIndex = 1;
  1603. } else {
  1604. data.viewIndex = 0;
  1605. }
  1606. }
  1607. getFingeringData();
  1608. }}
  1609. >
  1610. <img src={icons.icon_toggle} />
  1611. <span>视图</span>
  1612. </div>
  1613. )}
  1614. <div
  1615. class={styles.btnGr}
  1616. onClick={(e) => {
  1617. e.stopPropagation();
  1618. resetElement();
  1619. data.tipShow = !data.tipShow;
  1620. onResize();
  1621. }}
  1622. >
  1623. <img src={icons.icon_2_1} />
  1624. <span>说明</span>
  1625. </div>
  1626. <div class={styles.triangle}></div>
  1627. </div>
  1628. </div>
  1629. </div>
  1630. </div>
  1631. {data.fingeringMode !== "scaleMode" && (
  1632. <div
  1633. class={styles.optionBtns}
  1634. onClick={(e: any) => {
  1635. e.stopPropagation();
  1636. }}
  1637. >
  1638. <Button class={[styles.oBtn, styles.gamut, playStatus.action && styles.disabled]} round onClick={onGamutPlayOrPause}>
  1639. {playStatus.gamut ? "暂停" : "播放音阶"}
  1640. </Button>
  1641. <Button class={[styles.oBtn, styles.play, playStatus.gamut && styles.disabled]} round onClick={onActionPlay}>
  1642. {listenText.value}
  1643. </Button>
  1644. <Button class={[styles.oBtn, styles.success, !playStatus.answer && styles.disabled]} round onClick={onShowAnswer}>
  1645. 显示答案
  1646. </Button>
  1647. </div>
  1648. )}
  1649. </>
  1650. ) : (
  1651. <>
  1652. {/* <div class={styles.btnBox}>
  1653. <div class={styles.btnCon}>
  1654. <div
  1655. class={[styles.btnGr]}
  1656. onClick={(e) => {
  1657. e.stopPropagation();
  1658. //
  1659. // 播放音阶时不能切换
  1660. if (playStatus.gamut) {
  1661. return;
  1662. }
  1663. // 开始答题不能切换
  1664. if (playAction.listenLock) {
  1665. return;
  1666. }
  1667. data.changeSubjectShow = true;
  1668. }}
  1669. >
  1670. <img src={icons.icon_change_instrument} />
  1671. <span>切换乐器</span>
  1672. </div>
  1673. {data.subject !== "melodica" && data.fingeringMode === "scaleMode" && (
  1674. <div
  1675. class={styles.btnGr}
  1676. onClick={() => {
  1677. data.viewIndex++;
  1678. if (data.viewIndex > data.viewTotal) {
  1679. if (["pan-flute", "ocarina", "whistling"].includes(data.subject)) {
  1680. data.viewIndex = 1;
  1681. } else {
  1682. data.viewIndex = 0;
  1683. }
  1684. }
  1685. getFingeringData();
  1686. }}
  1687. >
  1688. <img src={icons.icon_toggle} />
  1689. <span>视图</span>
  1690. </div>
  1691. )}
  1692. <div
  1693. class={styles.btnGr}
  1694. onClick={() => {
  1695. resetElement();
  1696. data.tipShow = !data.tipShow;
  1697. onResize();
  1698. }}
  1699. >
  1700. <img src={icons.icon_2_1} />
  1701. <span>说明</span>
  1702. </div>
  1703. {instrumentTranstion.value && (
  1704. <div class={[styles.btnGr]} onClick={() => resetElement()}>
  1705. <img src={icons.icon_2_0} />
  1706. <span>还原</span>
  1707. </div>
  1708. )}
  1709. </div>
  1710. </div> */}
  1711. </>
  1712. )}
  1713. </Tab>
  1714. );
  1715. })}
  1716. </Tabs>
  1717. </div>
  1718. ) : (
  1719. <div class={[data.domOverlapping && data.notePoints?.length > 0 && styles.usrTabOverlapingNotes]} id="fullInstrumentUserTab">
  1720. <div
  1721. class={[styles.notes]}
  1722. style={{
  1723. paddingLeft: data.paddingLeft ? data.paddingLeft : "",
  1724. }}
  1725. >
  1726. {playAction.listenTipsStatus && <div class={[styles.tipsT, data.fingeringMode === "fingeringMode" ? styles.playTips2 : styles.playTips]}></div>}
  1727. {playAction.userAnswerStatus === 1 && <div class={[styles.tipsT, styles.playSuccess]}></div>}
  1728. {playAction.userAnswerStatus === 2 && <div class={[styles.tipsT, styles.playError]}></div>}
  1729. {playAction.resetAction && <div class={[styles.tipsT, styles.playTips5]}></div>}
  1730. {((data.noteType !== "#c" && (orientationDirection.value === 0 || (orientationDirection.value === 1 && state.platform === IPlatform.PC))) || (orientationDirection.value === 1 && state.platform === IPlatform.APP)) && (
  1731. <Button
  1732. class={styles.noteBtn}
  1733. onClick={(e: any) => {
  1734. e.stopPropagation();
  1735. scrollNoteBox("left");
  1736. }}
  1737. >
  1738. <Icon name="arrow-left" />
  1739. </Button>
  1740. )}
  1741. <div
  1742. class={[styles.noteContent, data.fingeringMode !== "scaleMode" && orientationDirection.value === 0 && styles.noteContentOther, browsInfo.ios ? "" : styles.noteContentWrap, data.huaweiPad && styles.huaweiPad]}
  1743. onClick={(e: any) => {
  1744. e.stopPropagation();
  1745. }}
  1746. >
  1747. {/* 判断是否为音阶模式 */}
  1748. {data.fingeringMode !== "scaleMode" && (
  1749. <div draggable={false} class={styles.note} onClick={noteChangeShow}>
  1750. <img draggable={false} src={data.noteType === "all" ? icons.icon_btn_orange : icons.icon_btn_orange2} />
  1751. </div>
  1752. )}
  1753. {/* [styles.noteContent, browsInfo.ios ? "" : styles.noteContentWrap, data.huaweiPad && styles.huaweiPad] */}
  1754. <div class={styles.lastNoteContent}>
  1755. <div ref={noteBoxRef} class={styles.noteBox} id="noteBox">
  1756. {data.notes.map((note: IFIGNER_INSTRUMENT_Note, index: number) => {
  1757. const steps = new Array(Math.abs(note.step)).fill(1);
  1758. return (
  1759. <div
  1760. id={index == 0 ? "finger-note-0" : ""}
  1761. draggable={false}
  1762. class={[styles.note, "note-class"]}
  1763. key={note.realKey}
  1764. // onClick={async () => {
  1765. // noteInstrumentPlay(note);
  1766. // }}
  1767. onMousedown={(e: any) => {
  1768. e.stopPropagation();
  1769. e.preventDefault();
  1770. if (isTouch) return;
  1771. startNotePress(note, false);
  1772. }}
  1773. onMouseup={(e: any) => {
  1774. e.stopPropagation();
  1775. e.preventDefault();
  1776. if (isTouch) return;
  1777. cancelNotePress(note, false);
  1778. }}
  1779. onMouseleave={(e: any) => {
  1780. e.stopPropagation();
  1781. e.preventDefault();
  1782. if (isTouch) return;
  1783. cancelNotePress(note, false);
  1784. }}
  1785. onTouchstart={(e: any) => {
  1786. e.stopPropagation();
  1787. e.preventDefault();
  1788. isTouch = true;
  1789. startNotePress(note, false);
  1790. }}
  1791. onTouchend={(e: any) => {
  1792. e.stopPropagation();
  1793. e.preventDefault();
  1794. cancelNotePress(note, false);
  1795. }}
  1796. onTouchcancel={(e: any) => {
  1797. e.stopPropagation();
  1798. e.preventDefault();
  1799. cancelNotePress(note, false);
  1800. }}
  1801. >
  1802. <img draggable={false} src={resultImg(note).icon} />
  1803. {playStatus.action && ((playAction.showAnswerLoading && playAction.standardAnswer.realKey === note.realKey) || (playAction.userAnswerStatus === 1 && playAction.userAnswer.realKey === note.realKey)) ? <span class={styles.showAnswer}></span> : ""}
  1804. {playStatus.action && playAction.userAnswerStatus === 2 && playAction.userAnswer.realKey === note.realKey ? <span class={[styles.showAnswer, styles.errorAnswer]}></span> : ""}
  1805. <div
  1806. class={[
  1807. styles.noteKey,
  1808. ((data.realKey === note.realKey && !playStatus.action) ||
  1809. (playStatus.action && playAction.exampleAnser.realKey === note.realKey) ||
  1810. (playStatus.action && ((playAction.showAnswerLoading && playAction.standardAnswer.realKey === note.realKey) || (playAction.userAnswerStatus === 1 && playAction.userAnswer.realKey === note.realKey))) ||
  1811. (playStatus.action && playAction.userAnswerStatus === 2 && playAction.userAnswer.realKey === note.realKey)) &&
  1812. styles.keyActive,
  1813. ]}
  1814. >
  1815. {/* 显示对应的点 */}
  1816. {note.step > 0 ? steps.map((n: any) => <span class={styles.dot}></span>) : null}
  1817. <div class={styles.noteName}>
  1818. <sup>{note.mark && (note.mark === "rise" ? "#" : "b")}</sup>
  1819. {note.key}
  1820. </div>
  1821. {/* 显示对应的点 */}
  1822. {note.step < 0 ? steps.map((n: any) => <span class={styles.dot}></span>) : null}
  1823. </div>
  1824. </div>
  1825. );
  1826. })}
  1827. </div>
  1828. </div>
  1829. </div>
  1830. {((data.noteType !== "#c" && (orientationDirection.value === 0 || (orientationDirection.value === 1 && state.platform === IPlatform.PC))) || (orientationDirection.value === 1 && state.platform === IPlatform.APP)) && (
  1831. <Button
  1832. class={styles.noteBtn}
  1833. onClick={(e: any) => {
  1834. e.stopPropagation();
  1835. scrollNoteBox("right");
  1836. }}
  1837. >
  1838. <Icon name="arrow" />
  1839. </Button>
  1840. )}
  1841. </div>
  1842. {data.fingeringMode !== "scaleMode" && (
  1843. <div
  1844. class={styles.optionBtns}
  1845. onClick={(e: any) => {
  1846. e.stopPropagation();
  1847. }}
  1848. >
  1849. <Button class={[styles.oBtn, styles.gamut, playStatus.action && styles.disabled]} round onClick={onGamutPlayOrPause}>
  1850. {playStatus.gamut ? "暂停" : "播放音阶"}
  1851. </Button>
  1852. <Button class={[styles.oBtn, styles.play, playStatus.gamut && styles.disabled]} round onClick={onActionPlay}>
  1853. {listenText.value}
  1854. </Button>
  1855. <Button class={[styles.oBtn, styles.success, !playStatus.answer && styles.disabled]} round onClick={onShowAnswer}>
  1856. 显示答案
  1857. </Button>
  1858. </div>
  1859. )}
  1860. </div>
  1861. )}
  1862. </div>
  1863. {/* 老师端过来隐藏 */}
  1864. {query.platform !== "pc" && (
  1865. <div
  1866. class={styles.fixedRightBtns}
  1867. style={{
  1868. paddingTop: data.paddingTop ? data.paddingTop : "",
  1869. paddingLeft: data.paddingLeft ? data.paddingLeft : "",
  1870. }}
  1871. onClick={(e: any) => {
  1872. e.stopPropagation();
  1873. }}
  1874. >
  1875. <div class={styles.rightBtn}>
  1876. {data.subject !== "melodica" && data.fingeringMode === "scaleMode" && (
  1877. <div
  1878. class={styles.baseBtn}
  1879. onClick={() => {
  1880. data.viewIndex++;
  1881. if (data.viewIndex > data.viewTotal) {
  1882. if (["pan-flute", "ocarina", "whistling"].includes(data.subject)) {
  1883. data.viewIndex = 1;
  1884. } else {
  1885. data.viewIndex = 0;
  1886. }
  1887. }
  1888. getFingeringData();
  1889. }}
  1890. >
  1891. <img src={icons.icon_toggle} />
  1892. <span>视图</span>
  1893. </div>
  1894. )}
  1895. <div
  1896. class={styles.baseBtn}
  1897. onClick={() => {
  1898. resetElement();
  1899. data.tipShow = !data.tipShow;
  1900. onResize();
  1901. }}
  1902. >
  1903. <img src={icons.icon_2_1} />
  1904. <span>说明</span>
  1905. </div>
  1906. {!!data.tones.length && data.fingeringMode === "scaleMode" && (
  1907. <>
  1908. {fingerData.fingeringInfo.name == "hulusi-flute" ? (
  1909. <div id="finger-note-1" class={[styles.baseBtn, styles.toggleBtnhulusi, styles.active]} onClick={() => (data.tnoteShow = true)}>
  1910. <div>
  1911. 全按作
  1912. <div class={[styles.noteKey, styles.noteKeyBtn]}>
  1913. {data.activeTone.step > 0 ? <span class={[styles.topDot, styles.dot]}></span> : null}
  1914. <div class={styles.noteName}>
  1915. <sup>{data.activeTone.mark && (data.activeTone.mark === "rise" ? "#" : "b")}</sup>
  1916. {data.activeTone.key}
  1917. </div>
  1918. {data.activeTone.step < 0 ? <span class={[styles.bottomDot, styles.dot]}></span> : null}
  1919. </div>
  1920. </div>
  1921. <img src={icons.icon_arrow} />
  1922. </div>
  1923. ) : (
  1924. <div id="finger-note-1" class={[styles.baseBtn, styles.toggleBtnhulusi2, styles.active]} onClick={() => (data.tnoteShow = true)}>
  1925. <div class={styles.oterhD}>
  1926. <div>
  1927. <div style={{ marginTop: "-4px" }}>
  1928. <sup>{data.activeTone.mark && (data.activeTone.mark === "rise" ? "#" : "b")}</sup>
  1929. {data.activeTone.name}
  1930. </div>
  1931. </div>
  1932. <img src={icons.icon_arrow} />
  1933. </div>
  1934. </div>
  1935. )}
  1936. </>
  1937. )}
  1938. </div>
  1939. <div class={[styles.baseBtn, !instrumentTranstion.value && styles.resetBtn]} style={{ marginTop: "8px" }} onClick={() => resetElement()}>
  1940. <img src={icons.icon_2_0} />
  1941. <span>还原</span>
  1942. </div>
  1943. </div>
  1944. )}
  1945. {/* 老师端加上遮罩点击关闭 */}
  1946. {query.platform === "pc" && data.tipShow && (
  1947. <div
  1948. class={[styles.tipsOverlay, data.tipShow ? styles.tipsOverlayBg : ""]}
  1949. onClick={() => {
  1950. data.tipShow = false;
  1951. }}
  1952. ></div>
  1953. )}
  1954. <div class={[styles.tips, data.loadingDom ? styles.hiddens : "", data.tipShow ? "" : styles.tipHidden, query.platform === "pc" && data.tipShow ? styles.tipsPcBg : ""]}>
  1955. <div class={styles.tipTitle}>
  1956. <div class={styles.tipTitleName}>{fingerData.fingeringInfo.code}使用说明</div>
  1957. <Button
  1958. class={styles.tipClose}
  1959. onClick={(e: any) => {
  1960. e.stopPropagation();
  1961. data.tipShow = false;
  1962. }}
  1963. >
  1964. <Icon name="cross" size={19} color="#fff" />
  1965. </Button>
  1966. </div>
  1967. <div class={styles.iconBook}></div>
  1968. <div class={styles.tipContentbox}>
  1969. <div class={styles.tipContent}>
  1970. {data.tips.map((tip, tipIndex) => (
  1971. <div class={styles.tipItem}>
  1972. <div class={styles.iconWrap}>
  1973. <div class={styles.tipItemIcon}>{tipIndex + 1}</div>
  1974. </div>
  1975. <div>
  1976. {tip.name}: {tip.realName}
  1977. </div>
  1978. </div>
  1979. ))}
  1980. </div>
  1981. </div>
  1982. </div>
  1983. {data.loadingSoundFonts && (
  1984. <div class={styles.loading}>
  1985. <div class={styles.loadingWrap}>
  1986. <img class={styles.loadingIcon} src={icon_loading_img} />
  1987. <Progress percentage={data.loadingSoundProgress} />
  1988. <div class={styles.loadingTip}>加载中,请稍后…</div>
  1989. </div>
  1990. </div>
  1991. )}
  1992. </div>
  1993. <Popup
  1994. class={["tonePopup", tnoteShowBoxClass]}
  1995. style={query.platform === "pc" ? tnoteShowBoxDragData.styleDrag.value : {}}
  1996. v-model:show={data.tnoteShow}
  1997. position={state.platform === IPlatform.PC ? "center" : !query.modelType && fingerData.fingeringInfo.orientation === 1 ? "bottom" : "right"}
  1998. >
  1999. <div class={styles.tones}>
  2000. <div class={[styles.toneTitle, "toneTitle_pc"]}>
  2001. <div class={styles.tipTitleName}>移调</div>
  2002. <Button
  2003. class={styles.tipClose}
  2004. onClick={(e: any) => {
  2005. e.stopPropagation();
  2006. data.tnoteShow = false;
  2007. }}
  2008. >
  2009. <Icon name="cross" size={19} color="#fff" />
  2010. </Button>
  2011. </div>
  2012. <div class={[styles.tipContentbox, "tipContentbox_pc"]}>
  2013. <div class={[styles.tipContent, "tipContent_pc"]}>
  2014. <div class={[styles.tipWrap, "tipWrap_pc"]}>
  2015. <Space size={0} class={styles.toneContent}>
  2016. {data.tones.map((tone: IFIGNER_INSTRUMENT_Note) => {
  2017. const steps = new Array(Math.abs(tone.step)).fill(1);
  2018. return (
  2019. <Button
  2020. class={[fingerData.fingeringInfo.name == "hulusi-flute" && styles.hulusiBtn]}
  2021. round
  2022. plain
  2023. type={data.popupActiveTone.realName === tone.realName ? "primary" : "default"}
  2024. onClick={(e: any) => {
  2025. e.stopPropagation();
  2026. data.popupActiveTone = tone;
  2027. setNotes();
  2028. }}
  2029. >
  2030. {fingerData.fingeringInfo.name == "hulusi-flute" ? (
  2031. <div style={{ display: "flex", alignItems: "center" }}>
  2032. 全按作
  2033. <div class={[styles.noteKey, styles.hulusiNoteKey]}>
  2034. {tone.step > 0 ? <span class={styles.dot}></span> : null}
  2035. <div class={styles.noteName} style={{ fontSize: "0.25rem" }}>
  2036. <sup>{tone.mark && (tone.mark === "rise" ? "#" : "b")}</sup>
  2037. {tone.key}
  2038. </div>
  2039. {tone.step < 0 ? <span class={styles.dot}></span> : null}
  2040. </div>
  2041. </div>
  2042. ) : (
  2043. <div class={styles.noteName}>
  2044. <sup>{tone.mark && (tone.mark === "rise" ? "#" : "b")}</sup>
  2045. {tone.name}
  2046. </div>
  2047. )}
  2048. </Button>
  2049. );
  2050. })}
  2051. </Space>
  2052. </div>
  2053. <div class={[styles.toneAction, "toneAction_pc"]}>
  2054. <img
  2055. onClick={(e: any) => {
  2056. e.stopPropagation();
  2057. data.tnoteShow = false;
  2058. }}
  2059. src={icons.icon_action_cancel}
  2060. />
  2061. <img
  2062. onClick={(e: any) => {
  2063. e.stopPropagation();
  2064. data.activeTone = data.popupActiveTone;
  2065. setNotes();
  2066. data.tnoteShow = false;
  2067. }}
  2068. src={icons.icon_action_confirm}
  2069. />
  2070. </div>
  2071. </div>
  2072. </div>
  2073. </div>
  2074. {query.platform === "pc" && (
  2075. <>
  2076. <div class={[styles.dragTopBox, "dragTopBox"]}></div>
  2077. <Dragbom showGuide={guidanceShow.value} onGuideDone={setGuidanceShow}></Dragbom>
  2078. </>
  2079. )}
  2080. </Popup>
  2081. <Popup
  2082. style={query.platform === "pc" ? changeSubjectShowBoxDragData.styleDrag.value : {}}
  2083. v-model:show={data.changeSubjectShow}
  2084. class={[styles.changeSubjectPopup, query.platform === "pc" && styles.changeSubjectPopupPc, changeSubjectShowBoxClass]}
  2085. closeOnClickOverlay={query.platform === "pc" ? false : true}
  2086. onClick={(e: any) => {
  2087. e.stopPropagation();
  2088. }}
  2089. >
  2090. <ChangeSubject
  2091. changeSubjectShow={data.changeSubjectShow}
  2092. subjectList={data.subjects}
  2093. subject={data.subject}
  2094. onClose={() => (data.changeSubjectShow = false)}
  2095. onConfirm={(code: any) => {
  2096. if (data.subject === code) {
  2097. data.changeSubjectShow = false;
  2098. return;
  2099. }
  2100. const originalSubject = JSON.parse(JSON.stringify(data.subject));
  2101. data.subject = code;
  2102. data.viewIndex = 0;
  2103. data.tipShow = false;
  2104. data.loadingDom = true;
  2105. fingerData.fingeringInfo = subjectFingering(data.subject);
  2106. data.activeTone = {} as any;
  2107. data.noteType = "all";
  2108. resetElement();
  2109. resetMode(true, 0);
  2110. // api_setRequestedOrientation(orientationDirection.value);
  2111. data.changeSubjectShow = false;
  2112. // 设置屏幕方向
  2113. setTimeout(() => {
  2114. const before = ["hulusi-flute", "piccolo", "baroque-recorder"].includes(originalSubject) ? 0 : 0;
  2115. if (orientationDirection.value !== before) {
  2116. data.paddingTop = "";
  2117. data.paddingLeft = "";
  2118. }
  2119. __init();
  2120. }, 100);
  2121. }}
  2122. />
  2123. {query.platform === "pc" && (
  2124. <>
  2125. <div class={[styles.dragTopBox, "dragTopBox"]}></div>
  2126. <Dragbom showGuide={guidanceShow.value} onGuideDone={setGuidanceShow}></Dragbom>
  2127. </>
  2128. )}
  2129. </Popup>
  2130. {props.show && !data.loading && !data.loadingSoundFonts && <GuideIndex fingeringMode={data.fingeringMode} showGuide={false} list={["finger"]} />}
  2131. </div>
  2132. );
  2133. };
  2134. },
  2135. });