index.tsx 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  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 state, { IPlatform } from "/src/state";
  18. import { api_musicalInstrumentList, api_subjectList, getSubjectList } from "../api";
  19. import ChangeSubject from "./change-subject";
  20. import { Tabs,Tab } from "vant"
  21. import useDrag from '/src/hooks/useDrag';
  22. import Dragbom from '/src/hooks/useDrag/dragbom';
  23. export default defineComponent({
  24. name: "viewFigner",
  25. emits: ["close"],
  26. props: {
  27. show: {
  28. type: Boolean,
  29. default: true,
  30. },
  31. isComponent: {
  32. type: Boolean,
  33. default: false,
  34. },
  35. subject: {
  36. type: String as PropType<IVocals>,
  37. default: "",
  38. },
  39. },
  40. setup(props, { emit }) {
  41. const query = getQuery();
  42. const browsInfo = browser();
  43. const code = mappingVoicePart(query.code, "INSTRUMENT");
  44. const subject = props.isComponent ? props.subject || "pan-flute" : code || "pan-flute";
  45. const data = reactive({
  46. linkSource: query.linkSource, // 来源,目前只有课件里使用
  47. loading: true,
  48. subject: subject as any,
  49. realKey: 0,
  50. notes: [] as IFIGNER_INSTRUMENT_Note[],
  51. tones: [] as IFIGNER_INSTRUMENT_Note[],
  52. activeTone: {} as IFIGNER_INSTRUMENT_Note,
  53. popupActiveTone: {} as IFIGNER_INSTRUMENT_Note,
  54. activeToneName: "",
  55. soundFonts: {} as any,
  56. viewIndex: 0,
  57. viewTotal: 1,
  58. noteAudio: null as unknown as Howl,
  59. transform: {
  60. scale: 1,
  61. x: 0,
  62. y: 0,
  63. startScale: 1,
  64. startX: 0,
  65. startY: 0,
  66. transition: "",
  67. },
  68. tipShow: false,
  69. tips: [] as IFIGNER_INSTRUMENT_Note[],
  70. tnoteShow: false,
  71. loadingSoundFonts: true,
  72. loadingSoundProgress: 0,
  73. changeSubjectShow: false,
  74. huaweiPad: navigator?.userAgent?.includes("UAWEIVRD-W09") ? true : false,
  75. paddingTop: "",
  76. paddingLeft: "",
  77. subjects: [] as any,
  78. fingeringModeList: [
  79. {
  80. text: "指法模式",
  81. value: "fingeringMode",
  82. icon: icons.icon_click,
  83. },
  84. {
  85. text: "听音模式",
  86. value: "listenMode",
  87. icon: icons.icon_listen,
  88. },
  89. {
  90. text: "音阶模式",
  91. value: "scaleMode",
  92. icon: icons.icon_mode,
  93. },
  94. ],
  95. fingeringMode: query.type || ("scaleMode" as "fingeringMode" | "listenMode" | "scaleMode"), // 模式
  96. noteType: "all" as "#c" | "all", // 音调
  97. loadingDom: false, // 切换乐器时需要重置
  98. loadingImg: false, // 切换模式,加载图片
  99. });
  100. const fingerData = reactive({
  101. relationshipIndex: 0,
  102. subject: null as unknown as ITypeFingering,
  103. fingeringInfo: subjectFingering(data.subject),
  104. });
  105. if (!props.isComponent) {
  106. state.fingeringInfo = fingerData.fingeringInfo;
  107. }
  108. const getAPPData = async (type: "top" | "left") => {
  109. const screenData = await isSpecialShapedScreen();
  110. if (screenData?.content) {
  111. console.log("🚀 ~ screenData:", screenData.content);
  112. const { isSpecialShapedScreen, notchHeight } = screenData.content;
  113. if (isSpecialShapedScreen) {
  114. if (type === "top") {
  115. data.paddingTop = 25 + "px";
  116. }
  117. if (type === "left") {
  118. data.paddingLeft = 25 + "px";
  119. }
  120. }
  121. }
  122. };
  123. const getHeadTop = () => {
  124. if (fingerData.fingeringInfo.orientation === 1) {
  125. getAPPData("top");
  126. }
  127. if (fingerData.fingeringInfo.orientation === 0) {
  128. getAPPData("left");
  129. }
  130. };
  131. const getNotes = () => {
  132. const fignerData = FIGNER_INSTRUMENT_DATA[data.subject as keyof typeof FIGNER_INSTRUMENT_DATA];
  133. if (fignerData) {
  134. data.tones = fignerData.tones || [];
  135. if (data.tones.length) {
  136. data.activeTone = data.tones[0];
  137. data.popupActiveTone = data.tones[0];
  138. }
  139. data.tips = fignerData.tips || [];
  140. setNotes();
  141. setTimeout(() => {
  142. data.loading = false;
  143. }, 600);
  144. }
  145. };
  146. const setNotes = () => {
  147. const fignerData = FIGNER_INSTRUMENT_DATA[data.subject as keyof typeof FIGNER_INSTRUMENT_DATA];
  148. if (fignerData) {
  149. const tempNotes = fignerData[`list${data.activeTone.realName || ""}`];
  150. const appendNote: any = [];
  151. tempNotes.forEach((note: any) => {
  152. note.steps = new Array(Math.abs(note.step)).fill(1);
  153. if (FIGNER_INSTRUMENT_REALKEY.includes(note.realKey)) {
  154. appendNote.push(note);
  155. }
  156. });
  157. // 判断是音符状态
  158. data.notes = data.noteType === "#c" ? appendNote : tempNotes;
  159. // data.notes = fignerData[`list${data.activeTone.realName || ""}`];
  160. }
  161. };
  162. const getFingeringData = async () => {
  163. const subject: any = data.subject + (data.viewIndex === 0 ? "" : data.viewIndex);
  164. console.log("🚀 ~ subject:模式", subject, data.viewIndex, data.fingeringMode);
  165. fingerData.subject = await getFingeringConfig(subject);
  166. };
  167. const createAudio = (url: string) => {
  168. return new Promise((resolve, reject) => {
  169. const noteAudio = new Howl({
  170. src: url,
  171. loop: true,
  172. onload: () => {
  173. resolve(noteAudio);
  174. },
  175. onloaderror: () => {
  176. reject(new Error(`加载音频失败`));
  177. },
  178. });
  179. });
  180. };
  181. const getSounFonts = async () => {
  182. const pathname = /(192|localhost)/.test(location.origin) ? "/" : location.pathname;
  183. data.loadingSoundFonts = true;
  184. try {
  185. data.loadingSoundProgress = 0;
  186. for (let i = 0; i < data.notes.length; i++) {
  187. const note = data.notes[i];
  188. // console.log("🚀 ~ note:", i);
  189. let url = `${pathname}soundfonts/${data.subject}/`;
  190. url += note.realName;
  191. url += ".mp3";
  192. data.soundFonts[note.realKey] = await createAudio(url);
  193. data.loadingSoundProgress = Math.floor(((i + 1) / data.notes.length) * 100);
  194. }
  195. data.loadingSoundProgress = 100;
  196. } catch (e: any) {
  197. //
  198. showToast(e.message);
  199. }
  200. api_cloudLoading();
  201. data.loadingSoundFonts = false;
  202. };
  203. // const selectSubjectType = (subject: string) => {
  204. // data.subjects.forEach((item: any) => {
  205. // if (item.value === subject) {
  206. // item.className = styles.selected;
  207. // } else {
  208. // item.className = "";
  209. // }
  210. // });
  211. // };
  212. // 切换当前模式
  213. const onChangeFingeringModel = (e: any) => {
  214. e.stopPropagation();
  215. //
  216. if (playAction.listenLock) return;
  217. if (playAction.showAnswerLoading) return;
  218. data.loadingImg = true;
  219. if (data.fingeringMode === "scaleMode") {
  220. if (["pan-flute", "ocarina", "whistling"].includes(data.subject)) {
  221. data.viewIndex = 1;
  222. } else {
  223. data.viewIndex = 0;
  224. }
  225. const o: any = {
  226. "pan-flute": 2,
  227. ocarina: 2,
  228. whistling: 2,
  229. piccolo: 2,
  230. "hulusi-flute": 2,
  231. "baroque-recorder": 2,
  232. };
  233. data.viewTotal = o[data.subject] || 1;
  234. data.fingeringMode = "listenMode";
  235. } else if (data.fingeringMode === "listenMode") {
  236. data.fingeringMode = "fingeringMode";
  237. } else if (data.fingeringMode === "fingeringMode") {
  238. data.fingeringMode = "scaleMode";
  239. data.viewIndex = 0;
  240. data.noteType = "all";
  241. }
  242. data.tipShow = false;
  243. resetMode(true, 0);
  244. setTimeout(() => {
  245. __init(false);
  246. }, 100);
  247. };
  248. const __init = async (loadSong = true) => {
  249. data.loadingDom = true;
  250. getNotes();
  251. // selectSubjectType(data.subject);
  252. if (data.fingeringMode === "fingeringMode") {
  253. if (data.subject === "pan-flute") {
  254. data.viewIndex = 3;
  255. } else if (["pan-flute", "ocarina", "melodica", "whistling"].includes(data.subject)) {
  256. data.viewIndex = 1;
  257. }
  258. } else {
  259. if (["pan-flute", "ocarina", "whistling"].includes(data.subject)) {
  260. data.viewIndex = 1;
  261. }
  262. }
  263. const o: any = {
  264. "pan-flute": 2,
  265. ocarina: 2,
  266. whistling: 2,
  267. piccolo: 2,
  268. "hulusi-flute": 2,
  269. "baroque-recorder": 2,
  270. };
  271. data.viewTotal = o[data.subject] || 1;
  272. getFingeringData();
  273. getHeadTop();
  274. if (loadSong) {
  275. await getSounFonts();
  276. }
  277. data.loadingDom = false;
  278. data.loadingImg = false;
  279. };
  280. // 获取声部
  281. const getSubjects = async () => {
  282. try {
  283. // api_subjectList
  284. // const subjects = await api_musicalInstrumentList({
  285. // enableFlag: true,
  286. // });
  287. // const rows = subjects.data || [];
  288. // rows.forEach((row: any) => {
  289. // const tempList: any = {
  290. // text: row.name,
  291. // value: mappingVoicePart(row.code, "INSTRUMENT"), // mappingVoicePart(row.code, "INSTRUMENT"),
  292. // id: row.id,
  293. // };
  294. // data.subjects.push(tempList);
  295. // });
  296. const subjects = await api_subjectList({
  297. enableFlag: true,
  298. delFlag: 0,
  299. page: 1,
  300. rows: 999,
  301. });
  302. const rows = subjects.data || [];
  303. const tempSubjects: any[] = [];
  304. rows.forEach((row: any) => {
  305. const tempList: any = {
  306. text: row.name,
  307. value: "", // mappingVoicePart(row.code, "INSTRUMENT"),
  308. id: row.id,
  309. children: [] as any,
  310. };
  311. if (Array.isArray(row.instruments)) {
  312. row.instruments.forEach((i: any) => {
  313. tempList.children.push({
  314. text: i.name,
  315. id: i.id,
  316. value: mappingVoicePart(i.code, "INSTRUMENT"),
  317. });
  318. });
  319. }
  320. tempSubjects.push(tempList);
  321. // if (row.instruments && row.instruments.length > 0) {
  322. // if (row.instruments.length > 1) {
  323. // row.instruments.forEach((i: any) => {
  324. // tempList.children.push({
  325. // text: i.name,
  326. // id: i.id,
  327. // value: mappingVoicePart(i.code, "INSTRUMENT"),
  328. // });
  329. // });
  330. // } else {
  331. // const singleRow = row.instruments[0];
  332. // if (singleRow.code) {
  333. // tempList.value = mappingVoicePart(singleRow.code, "INSTRUMENT");
  334. // tempList.id = singleRow.id;
  335. // }
  336. // }
  337. // }
  338. // data.subjects.push(tempList);
  339. });
  340. console.log(data.subject, "data.subject");
  341. // tempSubjects.forEach((item: any) => {
  342. // if (item.value === data.subject && item.children?.length > 1) {
  343. // data.subject = item.children[0].value;
  344. // }
  345. // });
  346. data.subjects = tempSubjects;
  347. } catch (e) {
  348. //
  349. console.log(e, "e");
  350. }
  351. };
  352. onBeforeMount(async () => {
  353. if (browser().isApp) {
  354. state.platform = "APP" as IPlatform;
  355. } else {
  356. state.platform = query.platform?.toLocaleUpperCase() || "";
  357. }
  358. if (state.platform === IPlatform.PC) {
  359. document.title = "听音练习";
  360. }
  361. await getSubjects();
  362. __init();
  363. });
  364. /**
  365. * 播放音频
  366. * @param item 音频节点
  367. * @param showNote 是否显示对应的指法
  368. * @returns
  369. */
  370. const noteClick = (item: IFIGNER_INSTRUMENT_Note, showNote = true) => {
  371. // console.log('音高', item.realKey)
  372. if (data.noteAudio) {
  373. data.noteAudio.stop();
  374. if (data.realKey === item.realKey) {
  375. data.realKey = 0;
  376. data.noteAudio = null as unknown as Howl;
  377. return;
  378. }
  379. }
  380. if (showNote) {
  381. data.realKey = item.realKey;
  382. }
  383. console.log("key:", item.realKey, data.soundFonts);
  384. data.noteAudio = data.soundFonts[item.realKey];
  385. if (data.noteAudio) {
  386. data.noteAudio.play();
  387. }
  388. };
  389. const handleStop = () => {
  390. if (data.noteAudio) {
  391. data.noteAudio.stop();
  392. data.realKey = 0;
  393. data.noteAudio = null as unknown as Howl;
  394. }
  395. };
  396. /** 返回 */
  397. const handleBack = () => {
  398. // platform: query.platform,
  399. handleStop();
  400. if (props.isComponent) {
  401. // 返回的时候默认横屏
  402. // api_setRequestedOrientation(0);
  403. emit("close");
  404. return;
  405. } else if (state.platform === IPlatform.PC) {
  406. console.log(1, query);
  407. if (query.matchMedia == 1) {
  408. // 老师端,首页
  409. window.parent.postMessage(
  410. {
  411. api: "iframe_exit",
  412. },
  413. "*"
  414. );
  415. return;
  416. } else {
  417. window.close();
  418. return;
  419. }
  420. // if (fingerData.fingeringInfo.orientation === 0) {
  421. // api_setRequestedOrientation(1);
  422. // }
  423. }
  424. // 不在APP中,
  425. if (!storeData.isApp) {
  426. window.close();
  427. return;
  428. }
  429. api_back();
  430. };
  431. // 排箫,默认0.9显示
  432. const setDefaultScale = () => {
  433. if (data.subject === "pan-flute") {
  434. data.transform.scale = 0.9;
  435. data.transform.startScale = 0.9;
  436. }
  437. };
  438. onMounted(() => {
  439. loadElement();
  440. api_setStatusBarVisibility();
  441. });
  442. const loadElement = () => {
  443. const fingeringContainer = document.getElementById("fingeringContainer");
  444. setDefaultScale();
  445. // console.log("🚀 ~ fingeringContainer:", fingeringContainer);
  446. const mc = new Hammer.Manager(fingeringContainer as HTMLElement);
  447. mc.add(new Hammer.Pan({ threshold: 0, pointers: 0 }));
  448. mc.add(new Hammer.Pinch({ threshold: 0 })).recognizeWith([mc.get("pan")]);
  449. // mc.get("pan").set({ direction: Hammer.DIRECTION_ALL });
  450. // mc.get("pinch").set({ enable: true });
  451. mc.on("panstart pinchstart", function (ev) {
  452. data.transform.transition = "";
  453. });
  454. mc.on("panmove pinchmove", function (ev) {
  455. if (ev.type === "pinchmove") {
  456. // console.log("🚀 ~ ev:", ev.type, ev.scale, ev.deltaX, ev.deltaY);
  457. data.transform.scale = ev.scale * data.transform.startScale;
  458. data.transform.x = data.transform.startX + ev.deltaX;
  459. data.transform.y = data.transform.startY + ev.deltaY;
  460. }
  461. if (ev.type === "panmove") {
  462. // console.log("🚀 ~ ev:", ev.type, ev.deltaX, ev.deltaY);
  463. data.transform.x = data.transform.startX + ev.deltaX;
  464. data.transform.y = data.transform.startY + ev.deltaY;
  465. }
  466. });
  467. //
  468. mc.on("hammer.input", function (ev) {
  469. if (ev.isFinal) {
  470. data.transform.startScale = data.transform.scale;
  471. data.transform.startX = data.transform.x;
  472. data.transform.startY = data.transform.y;
  473. }
  474. });
  475. };
  476. const resetElement = () => {
  477. data.transform.transition = "all 0.3s";
  478. nextTick(() => {
  479. data.transform.scale = data.subject === "pan-flute" ? 0.9 : 1;
  480. data.transform.x = 0;
  481. data.transform.y = 0;
  482. data.transform.startScale = data.subject === "pan-flute" ? 0.9 : 1;
  483. data.transform.startX = 0;
  484. data.transform.startY = 0;
  485. });
  486. };
  487. // 判断乐器是否移动
  488. const instrumentTranstion = computed(() => {
  489. const transform = data.transform;
  490. let scale = 1;
  491. if (data.subject === "pan-flute") {
  492. scale = 0.9;
  493. }
  494. if (transform.scale !== scale || transform.x !== 0 || transform.y !== 0 || transform.startScale !== scale || transform.startX !== 0 || transform.startY !== 0) {
  495. return true;
  496. } else {
  497. return false;
  498. }
  499. });
  500. const pageVisible = usePageVisibility();
  501. watch(
  502. () => pageVisible.value,
  503. (val) => {
  504. if (val === "hidden") {
  505. clearTimeout(playAction.timer);
  506. playAction.listenLock = false;
  507. playAction.listenTipsStatus = false;
  508. playAction.exampleAnser = {};
  509. resetMode(true, 0);
  510. handleStop();
  511. gaumntPause();
  512. }
  513. }
  514. );
  515. /** 课件播放 */
  516. const changePlay = (res: any) => {
  517. if (res?.data?.api === "setPlayState") {
  518. clearTimeout(playAction.timer);
  519. playAction.listenLock = false;
  520. playAction.listenTipsStatus = false;
  521. playAction.exampleAnser = {};
  522. resetMode(true, 0);
  523. handleStop();
  524. gaumntPause();
  525. // 重置乐器
  526. if (res?.data?.data.code) {
  527. data.subject = code;
  528. data.viewIndex = 0;
  529. data.tipShow = false;
  530. data.loadingDom = true;
  531. fingerData.fingeringInfo = subjectFingering(data.subject);
  532. data.activeTone = {} as any;
  533. resetElement();
  534. // 设置屏幕方向
  535. setTimeout(() => {
  536. __init();
  537. }, 100);
  538. }
  539. }
  540. };
  541. const noteBoxRef = ref();
  542. const scrollNoteBox = (type: "left" | "right") => {
  543. const width = noteBoxRef.value.offsetWidth / 2;
  544. (noteBoxRef.value as unknown as HTMLElement).scrollBy({
  545. left: type === "left" ? -width : width,
  546. behavior: "smooth",
  547. });
  548. };
  549. const playStatus = reactive({
  550. gamut: false, // 是否播放音阶
  551. gamutTimer: null as any, // 播放音阶定时器
  552. answer: false, // 是否显示答案
  553. action: false, // 是否开始播放
  554. });
  555. /** 音符切换 */
  556. const noteChangeShow = () => {
  557. if (playStatus.action) {
  558. if (playAction.listenLock) return;
  559. playAction.resetAction = true;
  560. resetMode(true, 0);
  561. }
  562. // // 播放音阶时不能切换
  563. // if (playStatus.gamut) return;
  564. // // 开始答题不能切换
  565. // if (playStatus.action) return;
  566. playStatus.gamut = false;
  567. gaumntPause();
  568. if (data.noteType === "all") {
  569. data.noteType = "#c";
  570. } else {
  571. data.noteType = "all";
  572. }
  573. getNotes();
  574. setTimeout(() => {
  575. playAction.resetAction = false;
  576. }, 2000);
  577. };
  578. // 开始播放音阶
  579. const onGamutPlayOrPause = async () => {
  580. playAction.resetAction = false;
  581. if (playStatus.gamut) {
  582. playStatus.gamut = false;
  583. gaumntPause();
  584. } else {
  585. // 不管当前显示在哪个音老师滚动到开始位置
  586. (noteBoxRef.value as unknown as HTMLElement).scroll({
  587. left: 0,
  588. top: 0,
  589. behavior: "smooth",
  590. });
  591. playStatus.gamut = true;
  592. const notes = data.notes;
  593. let scrollCount = 0;
  594. for (let i = 0; i < notes.length; i++) {
  595. if (!playStatus.gamut) return false;
  596. const activeDom = document.querySelectorAll(".note-class")[i] as any;
  597. if (activeDom.offsetLeft >= noteBoxRef.value.offsetWidth + (noteBoxRef.value.offsetWidth / 2) * scrollCount - activeDom.offsetWidth) {
  598. scrollNoteBox("right");
  599. scrollCount++;
  600. }
  601. await gaumtPlay(notes[i]);
  602. }
  603. // // 处理播放到最后一个
  604. setTimeout(() => {
  605. playStatus.gamut = false;
  606. gaumntPause();
  607. }, 667);
  608. }
  609. };
  610. const gaumtPlay = (note: any, status?: boolean) => {
  611. return new Promise((resolve) => {
  612. playStatus.gamutTimer = setTimeout(() => {
  613. if (playStatus.gamut || status) {
  614. noteClick(note);
  615. }
  616. resolve(note);
  617. }, 667);
  618. });
  619. };
  620. const gaumntPause = () => {
  621. clearTimeout(playStatus.gamutTimer);
  622. if (data.noteAudio) {
  623. data.noteAudio.stop();
  624. data.realKey = 0;
  625. data.noteAudio = null as unknown as Howl;
  626. }
  627. };
  628. /** 开始播放 */
  629. const playAction = reactive({
  630. exampleAnser: {} as any, // 示例声音
  631. standardAnswer: {} as any, // 标准答案key
  632. showAnswerLoading: false, // 显示按答案中
  633. listenModeStatus: false, // 是否开始了模式
  634. listenLock: false,
  635. listenTipsStatus: false, // 开始播放状态
  636. resetAction: false, // 是否重置
  637. /** 0: 未答,1: 答对,2: 答错 */
  638. userAnswerStatus: 0 as 0 | 1 | 2, // 用户回答状态
  639. userAnswer: {} as any, // 用户答的数据
  640. timer: null as any,
  641. });
  642. const onActionPlay = async () => {
  643. playAction.resetAction = false;
  644. if (playAction.listenLock) return;
  645. if (playAction.showAnswerLoading) return;
  646. playStatus.action = true;
  647. playStatus.answer = true;
  648. // 先暂停播放声音
  649. gaumntPause();
  650. if (data.fingeringMode === "fingeringMode") {
  651. onFingeringMode();
  652. } else if (data.fingeringMode === "listenMode") {
  653. if (playAction.listenModeStatus) {
  654. playAction.listenLock = true;
  655. await fingeringPlay(playAction.standardAnswer, 1500, false);
  656. gaumntPause();
  657. playAction.listenLock = false;
  658. } else {
  659. onListenMode();
  660. }
  661. }
  662. };
  663. // 指法模式
  664. const fingeringPlay = (note: any, timer = 1500, showNote = true) => {
  665. return new Promise((resolve) => {
  666. noteClick(note, showNote);
  667. playAction.timer = setTimeout(() => {
  668. resolve(note);
  669. }, timer);
  670. });
  671. };
  672. const onFingeringMode = () => {
  673. const randomIndex = Math.floor(Math.random() * data.notes.length);
  674. playAction.standardAnswer = data.notes[randomIndex];
  675. data.realKey = data.notes[randomIndex].realKey;
  676. if (playAction.listenModeStatus) {
  677. return;
  678. }
  679. playAction.listenModeStatus = true; // 是否开始听音
  680. playAction.listenLock = true; // 锁
  681. playAction.listenTipsStatus = true;
  682. playAction.timer = setTimeout(() => {
  683. playAction.listenTipsStatus = false;
  684. playAction.listenLock = false; // 锁
  685. }, 2000);
  686. };
  687. // 听音模式
  688. const onListenMode = async () => {
  689. playAction.listenModeStatus = true; // 是否开始听音
  690. playAction.listenLock = true; // 锁
  691. playAction.listenTipsStatus = true;
  692. // 设置并保存示例数据
  693. let randomIndex = data.notes.findIndex((item: any) => item.realKey === 67); // Math.floor(Math.random() * data.notes.length);
  694. playAction.exampleAnser = data.notes[randomIndex];
  695. data.realKey = playAction.exampleAnser.realKey;
  696. scrollAnswer(playAction.exampleAnser.realKey);
  697. await fingeringPlay(playAction.exampleAnser);
  698. data.realKey = 0;
  699. playAction.exampleAnser = {};
  700. gaumntPause();
  701. playAction.timer = setTimeout(async () => {
  702. // 设置答题数据
  703. randomIndex = Math.floor(Math.random() * data.notes.length);
  704. playAction.standardAnswer = data.notes[randomIndex];
  705. await fingeringPlay(data.notes[randomIndex], 1500, false);
  706. gaumntPause();
  707. playAction.listenLock = false;
  708. playAction.listenTipsStatus = false;
  709. }, 1000);
  710. };
  711. // 显示答案
  712. const onShowAnswer = async () => {
  713. if (playAction.listenLock) return;
  714. playAction.showAnswerLoading = true;
  715. scrollAnswer(playAction.standardAnswer.realKey);
  716. await fingeringPlay(playAction.standardAnswer);
  717. resetMode(true, 0);
  718. // }
  719. };
  720. // 滚动到对应答案位置
  721. const scrollAnswer = (realKey?: any) => {
  722. const tempRealKey = realKey || data.realKey;
  723. const index = data.notes.findIndex((item: any) => item.realKey === tempRealKey);
  724. const activeDom = document.querySelectorAll(".note-class")[index] as any;
  725. if (activeDom) {
  726. const aWidth = activeDom.offsetWidth;
  727. const width = noteBoxRef.value.offsetWidth;
  728. const aLeft = Math.max(activeDom?.offsetLeft - aWidth, 0);
  729. (noteBoxRef.value as unknown as HTMLElement).scroll({
  730. left: Math.max(aLeft - width / 2, 0),
  731. top: 0,
  732. behavior: "smooth",
  733. });
  734. }
  735. };
  736. /**
  737. * 重置播放状态
  738. * @param status 是否全部重置
  739. * @param timer 延时时长(默认2s)
  740. */
  741. const resetMode = (status = true, timer = 2000) => {
  742. // 2秒钟后重置
  743. setTimeout(() => {
  744. gaumntPause();
  745. if (status) {
  746. playAction.standardAnswer = {};
  747. playAction.showAnswerLoading = false;
  748. playAction.userAnswerStatus = 0;
  749. playAction.userAnswer = {};
  750. playAction.listenModeStatus = false;
  751. playStatus.action = false;
  752. playStatus.answer = false;
  753. playStatus.gamut = false;
  754. data.realKey = 0;
  755. } else {
  756. playAction.userAnswerStatus = 0;
  757. playAction.userAnswer = {};
  758. }
  759. }, timer);
  760. };
  761. /** 滚轮缩放 */
  762. const handleWheel = (e: WheelEvent) => {
  763. e.preventDefault();
  764. if (e.deltaY > 0) {
  765. data.transform.scale -= 0.1;
  766. if (data.transform.scale <= 0.5) {
  767. data.transform.scale = 0.5;
  768. }
  769. } else {
  770. data.transform.scale += 0.1;
  771. if (data.transform.scale >= 2) {
  772. data.transform.scale = 2;
  773. }
  774. }
  775. };
  776. onMounted(() => {
  777. window.addEventListener("message", changePlay);
  778. const fingeringContainer = document.getElementById("fingeringContainer");
  779. fingeringContainer?.addEventListener("wheel", handleWheel);
  780. });
  781. onUnmounted(() => {
  782. window.removeEventListener("message", changePlay);
  783. const fingeringContainer = document.getElementById("fingeringContainer");
  784. fingeringContainer?.removeEventListener("wheel", handleWheel);
  785. document.title = "Ai学练";
  786. });
  787. const containerBox = computed(() => {
  788. if (state.platform === IPlatform.PC || query.modelType) {
  789. return {
  790. paddingTop: "1.3rem",
  791. paddingBottom: "",
  792. };
  793. }
  794. if (data.fingeringMode === "scaleMode") {
  795. if (data.subject === "hulusi-flute") {
  796. return {
  797. paddingTop: "1.3rem",
  798. paddingBottom: ".5rem",
  799. };
  800. } else if (data.subject === "piccolo" || data.subject === "baroque-recorder") {
  801. return {
  802. paddingTop: "1.3rem",
  803. paddingBottom: ".5rem",
  804. };
  805. } else if (data.subject === "pan-flute") {
  806. return {
  807. paddingTop: "1.3rem",
  808. paddingBottom: "0",
  809. };
  810. } else if (data.subject === "ocarina" || data.subject === "whistling") {
  811. return {
  812. paddingTop: "1.3rem",
  813. paddingBottom: "0",
  814. };
  815. } else if (data.subject === "melodica") {
  816. return {
  817. paddingTop: "1.8rem",
  818. paddingBottom: "0.2rem",
  819. };
  820. } else {
  821. return {
  822. paddingTop: "",
  823. paddingBottom: "",
  824. };
  825. }
  826. } else {
  827. if (data.subject === "hulusi-flute") {
  828. return {
  829. paddingTop: "1.3rem",
  830. paddingBottom: "0rem",
  831. };
  832. } else if (data.subject === "piccolo" || data.subject === "baroque-recorder") {
  833. return {
  834. paddingTop: "1.3rem",
  835. paddingBottom: ".5rem",
  836. };
  837. } else if (data.subject === "pan-flute") {
  838. return {
  839. paddingTop: "1.3rem",
  840. paddingBottom: "0",
  841. };
  842. } else if (data.subject === "ocarina" || data.subject === "whistling") {
  843. return {
  844. paddingTop: "1.3rem",
  845. paddingBottom: "0",
  846. };
  847. } else if (data.subject === "melodica") {
  848. return {
  849. paddingTop: "1.8rem",
  850. paddingBottom: "0.2rem",
  851. };
  852. } else {
  853. return {
  854. paddingTop: "",
  855. paddingBottom: "",
  856. };
  857. }
  858. }
  859. });
  860. const listenText = computed(() => {
  861. if (data.fingeringMode === "fingeringMode") {
  862. if (playStatus.action) {
  863. return "换一换";
  864. } else {
  865. return "开始练习";
  866. }
  867. } else if (data.fingeringMode === "listenMode") {
  868. if (playStatus.action) {
  869. return "再听一遍";
  870. } else {
  871. return "开始听音";
  872. }
  873. }
  874. return "开始听音";
  875. });
  876. const modeText = computed(() => {
  877. let text = "";
  878. let icon = icons.icon_mode;
  879. data.fingeringModeList.forEach((item: any) => {
  880. if (item.value === data.fingeringMode) {
  881. text = item.text;
  882. icon = item.icon;
  883. }
  884. });
  885. return {
  886. text,
  887. icon,
  888. };
  889. });
  890. // 屏幕方向 0 竖,1 横
  891. const orientationDirection = computed(() => {
  892. return ["hulusi-flute", "piccolo", "baroque-recorder"].includes(data.subject) ? 1 : 0;
  893. });
  894. const resultImg = (note: any) => {
  895. if (data.realKey === note.realKey && !playStatus.action) {
  896. return {
  897. icon: icons.icon_btn_ylow,
  898. status: false,
  899. };
  900. } else if (playAction.exampleAnser.realKey === note.realKey) {
  901. return {
  902. icon: icons.icon_btn_ylow,
  903. status: false,
  904. };
  905. } else if (playAction.standardAnswer.realKey === note.realKey) {
  906. // 没有开始答题
  907. if (!playStatus.action) {
  908. return {
  909. icon: icons.icon_btn_ylow,
  910. status: false,
  911. };
  912. }
  913. // 显示答案中
  914. if (playAction.showAnswerLoading) {
  915. return {
  916. icon: icons.icon_btn_green,
  917. status: true,
  918. };
  919. }
  920. // 用户答对
  921. if (playAction.userAnswerStatus === 1) {
  922. return {
  923. icon: icons.icon_btn_green,
  924. status: true,
  925. };
  926. }
  927. } else {
  928. // 用户答错
  929. if (playAction.userAnswerStatus === 2 && playAction.userAnswer.realKey === note.realKey) {
  930. return {
  931. icon: icons.icon_btn_red,
  932. status: true,
  933. };
  934. }
  935. }
  936. return {
  937. icon: icons.icon_btn_blue,
  938. status: true,
  939. };
  940. };
  941. const userTabActive=ref<"1"|"2">("1")
  942. const userTabs=[
  943. {
  944. name:"音阶",
  945. value:"1"
  946. },
  947. {
  948. name:"功能",
  949. value:"2"
  950. }
  951. ]
  952. // 切换乐器弹窗
  953. let changeSubjectShowBoxDragData: any;
  954. let changeSubjectShowBoxClass: string;
  955. if (query.platform==="pc") {
  956. changeSubjectShowBoxClass = 'changeSubjectShowBoxClass_drag';
  957. changeSubjectShowBoxDragData = useDrag(
  958. [`${changeSubjectShowBoxClass} .dragTopBox`, `${changeSubjectShowBoxClass} .dragbomBox`],
  959. changeSubjectShowBoxClass,
  960. toRef(data, 'changeSubjectShow'),
  961. storeData.user.id as string
  962. );
  963. }
  964. return () => {
  965. const relationship = fingerData.subject?.relationship?.[data.realKey] || [];
  966. const rs: number[] = Array.isArray(relationship[1]) ? relationship[fingerData.relationshipIndex] : relationship;
  967. const canTizhi = Array.isArray(relationship[1]);
  968. return (
  969. <div
  970. class={[styles.fingerBox, state.platform !== IPlatform.PC && !query.modelType && fingerData.fingeringInfo.orientation === 1 ? styles.fingerBottom : styles.fingerRight, data.linkSource === "class" ? styles.linkSourceClass : ""]}
  971. onClick={() => {
  972. if (data.linkSource === "class") {
  973. window.parent.postMessage(
  974. {
  975. api: "clickViewFigner",
  976. },
  977. "*"
  978. );
  979. }
  980. }}
  981. >
  982. {/* 老师端过来隐藏 */}
  983. {
  984. query.platform!=='pc'&&(
  985. <div
  986. class={styles.head}
  987. style={{
  988. paddingTop: data.paddingTop && !browser().ios ? data.paddingTop : "",
  989. paddingLeft: data.paddingLeft && !browser().ios ? data.paddingLeft : "",
  990. }}
  991. >
  992. <div class={styles.left}>
  993. <button class={[styles.backBtn]} onClick={() => handleBack()}>
  994. <img src={icons.icon_back} />
  995. </button>
  996. <div
  997. class={[styles.baseBtn, styles.changeInstrumentBtn]}
  998. onClick={(e) => {
  999. e.stopPropagation();
  1000. //
  1001. // 播放音阶时不能切换
  1002. if (playStatus.gamut) {
  1003. return;
  1004. }
  1005. // 开始答题不能切换
  1006. if (playAction.listenLock) {
  1007. return;
  1008. }
  1009. data.changeSubjectShow = true;
  1010. }}
  1011. >
  1012. <img src={icons.icon_change_instrument} />
  1013. <span>切换乐器</span>
  1014. </div>
  1015. <div class={styles.baseBtn} onClick={onChangeFingeringModel}>
  1016. <img src={modeText.value.icon} />
  1017. <span>{modeText.value.text}</span>
  1018. </div>
  1019. {/* */}
  1020. </div>
  1021. {/* */}
  1022. </div>
  1023. )
  1024. }
  1025. <div
  1026. class={styles.fingerContent}
  1027. style={{
  1028. paddingTop: data.paddingTop ? data.paddingTop : "",
  1029. paddingLeft: data.paddingLeft ? data.paddingLeft : "",
  1030. }}
  1031. >
  1032. <div class={styles.wrapFinger}>
  1033. <div
  1034. id="fingeringContainer"
  1035. class={[styles.boxFinger,query.platform==='pc'?styles.pcBoxFinger:""]}
  1036. style={{
  1037. paddingTop: containerBox.value.paddingTop,
  1038. paddingBottom: containerBox.value.paddingBottom,
  1039. }}
  1040. >
  1041. <div
  1042. style={{
  1043. transform: `translate3d(${data.transform.x}px,${data.transform.y}px,0px) scale(${data.transform.scale})`,
  1044. transition: data.transform.transition,
  1045. }}
  1046. class={[styles.fingeringContainer]}
  1047. >
  1048. <div class={styles.imgs}>
  1049. {!data.loadingImg && <img src={data.fingeringMode === "scaleMode" ? fingerData.subject?.json?.full : fingerData.subject?.json?.full1} />}
  1050. {rs.map((key: number | string, index: number) => {
  1051. const nk: string = typeof key === "string" ? key.replace("active-", "") : String(key);
  1052. return <img data-index={nk} src={fingerData.subject?.json?.[nk]} />;
  1053. })}
  1054. <div style={{ left: data.viewIndex == 2 ? "0" : "64%" }} class={[styles.tizhi, canTizhi && styles.canDisplay]} onClick={() => (fingerData.relationshipIndex = fingerData.relationshipIndex === 0 ? 1 : 0)}>
  1055. 替指
  1056. </div>
  1057. <div id="finger-note-2" style={{ left: "50%", transform: "translateX(-50%)" }} class={styles.tizhi} onClick={() => (fingerData.relationshipIndex = fingerData.relationshipIndex === 0 ? 1 : 0)}></div>
  1058. </div>
  1059. </div>
  1060. </div>
  1061. {/* 老师端过来隐藏 */}
  1062. {
  1063. query.platform==='pc'?(
  1064. <div class={styles.userTab}>
  1065. <Tabs v-model:active={userTabActive.value} class={styles.userTabBox}>
  1066. {
  1067. userTabs.map(item=>{
  1068. return <Tab title={item.name} name={item.value}>
  1069. {
  1070. item.value==="1"?(<>
  1071. <div
  1072. class={styles.notes}
  1073. style={{
  1074. paddingLeft: data.paddingLeft ? data.paddingLeft : "",
  1075. }}
  1076. >
  1077. {playAction.listenTipsStatus && <div class={[styles.tipsT, data.fingeringMode === "fingeringMode" ? styles.playTips2 : styles.playTips]}></div>}
  1078. {playAction.userAnswerStatus === 1 && <div class={[styles.tipsT, styles.playSuccess]}></div>}
  1079. {playAction.userAnswerStatus === 2 && <div class={[styles.tipsT, styles.playError]}></div>}
  1080. {playAction.resetAction && <div class={[styles.tipsT, styles.playTips5]}></div>}
  1081. <div class={styles.changeMusBtn} onClick={onChangeFingeringModel}>
  1082. <span>{modeText.value.text}</span>
  1083. </div>
  1084. <div
  1085. class={[styles.noteContent, data.fingeringMode !== "scaleMode" && orientationDirection.value === 0 && styles.noteContentOther, browsInfo.ios ? "" : styles.noteContentWrap, data.huaweiPad && styles.huaweiPad]}
  1086. onClick={(e: any) => {
  1087. e.stopPropagation();
  1088. }}
  1089. >
  1090. {((data.noteType !== "#c" && (orientationDirection.value === 0 || (orientationDirection.value === 1 && state.platform === IPlatform.PC))) || (orientationDirection.value === 1 && state.platform === IPlatform.APP)) && (
  1091. <Button
  1092. class={styles.noteBtn}
  1093. onClick={(e: any) => {
  1094. e.stopPropagation();
  1095. scrollNoteBox("left");
  1096. }}
  1097. >
  1098. <Icon name="arrow-left" />
  1099. </Button>
  1100. )}
  1101. {/* 判断是否为音阶模式 */}
  1102. {data.fingeringMode !== "scaleMode" && (
  1103. <div draggable={false} class={styles.note} onClick={noteChangeShow}>
  1104. <img draggable={false} src={data.noteType === "all" ? icons.icon_btn_orange : icons.icon_btn_orange2} />
  1105. </div>
  1106. )}
  1107. {/* [styles.noteContent, browsInfo.ios ? "" : styles.noteContentWrap, data.huaweiPad && styles.huaweiPad] */}
  1108. <div class={styles.lastNoteContent}>
  1109. <div ref={noteBoxRef} class={styles.noteBox}>
  1110. {data.notes.map((note: IFIGNER_INSTRUMENT_Note, index: number) => {
  1111. const steps = new Array(Math.abs(note.step)).fill(1);
  1112. return (
  1113. <div
  1114. id={index == 0 ? "finger-note-0" : ""}
  1115. draggable={false}
  1116. class={[styles.note, "note-class"]}
  1117. key={note.realKey}
  1118. onClick={async () => {
  1119. // 判断是否在播放音阶
  1120. if (playStatus.gamut) return;
  1121. if (playAction.listenLock) return;
  1122. if (playAction.showAnswerLoading) return;
  1123. if (playStatus.action) {
  1124. playAction.userAnswer = note;
  1125. // 判断用户答题
  1126. const userResult = note.realKey === playAction.standardAnswer.realKey ? 1 : 2;
  1127. playAction.userAnswerStatus = userResult;
  1128. playAction.listenLock = true;
  1129. data.realKey = note.realKey;
  1130. await fingeringPlay(note, 1000);
  1131. resetMode(userResult === 1 ? true : false, 0);
  1132. data.realKey = 0;
  1133. // 如果是指法模式显示完之后要还原
  1134. if (data.fingeringMode === "fingeringMode" && userResult === 2) {
  1135. // 延迟显示,因为重置的时候有一个异步操作
  1136. setTimeout(() => {
  1137. data.realKey = playAction.standardAnswer.realKey;
  1138. }, 10);
  1139. }
  1140. playAction.listenLock = false;
  1141. } else {
  1142. noteClick(note);
  1143. }
  1144. }}
  1145. >
  1146. <img draggable={false} src={resultImg(note).icon} />
  1147. {playStatus.action && ((playAction.showAnswerLoading && playAction.standardAnswer.realKey === note.realKey) || (playAction.userAnswerStatus === 1 && playAction.userAnswer.realKey === note.realKey)) ? <span class={styles.showAnswer}></span> : ""}
  1148. {playStatus.action && playAction.userAnswerStatus === 2 && playAction.userAnswer.realKey === note.realKey ? <span class={[styles.showAnswer, styles.errorAnswer]}></span> : ""}
  1149. <div
  1150. class={[
  1151. styles.noteKey,
  1152. ((data.realKey === note.realKey && !playStatus.action) ||
  1153. (playStatus.action && playAction.exampleAnser.realKey === note.realKey) ||
  1154. (playStatus.action && ((playAction.showAnswerLoading && playAction.standardAnswer.realKey === note.realKey) || (playAction.userAnswerStatus === 1 && playAction.userAnswer.realKey === note.realKey))) ||
  1155. (playStatus.action && playAction.userAnswerStatus === 2 && playAction.userAnswer.realKey === note.realKey)) &&
  1156. styles.keyActive,
  1157. ]}
  1158. >
  1159. {/* 显示对应的点 */}
  1160. {note.step > 0 ? steps.map((n: any) => <span class={styles.dot}></span>) : null}
  1161. <div class={styles.noteName}>
  1162. <sup>{note.mark && (note.mark === "rise" ? "#" : "b")}</sup>
  1163. {note.key}
  1164. </div>
  1165. {/* 显示对应的点 */}
  1166. {note.step < 0 ? steps.map((n: any) => <span class={styles.dot}></span>) : null}
  1167. </div>
  1168. </div>
  1169. );
  1170. })}
  1171. </div>
  1172. </div>
  1173. {((data.noteType !== "#c" && (orientationDirection.value === 0 || (orientationDirection.value === 1 && state.platform === IPlatform.PC))) || (orientationDirection.value === 1 && state.platform === IPlatform.APP)) && (
  1174. <Button
  1175. class={styles.noteBtn}
  1176. onClick={(e: any) => {
  1177. e.stopPropagation();
  1178. scrollNoteBox("right");
  1179. }}
  1180. >
  1181. <Icon name="arrow" />
  1182. </Button>
  1183. )}
  1184. </div>
  1185. </div>
  1186. {data.fingeringMode !== "scaleMode" && (
  1187. <div
  1188. class={styles.optionBtns}
  1189. onClick={(e: any) => {
  1190. e.stopPropagation();
  1191. }}
  1192. >
  1193. <Button class={[styles.oBtn, styles.gamut, playStatus.action && styles.disabled]} round onClick={onGamutPlayOrPause}>
  1194. {playStatus.gamut ? "暂停" : "播放音阶"}
  1195. </Button>
  1196. <Button class={[styles.oBtn, styles.play, playStatus.gamut && styles.disabled]} round onClick={onActionPlay}>
  1197. {listenText.value}
  1198. </Button>
  1199. <Button class={[styles.oBtn, styles.success, !playStatus.answer && styles.disabled]} round onClick={onShowAnswer}>
  1200. 显示答案
  1201. </Button>
  1202. </div>
  1203. )}
  1204. </>):(<>
  1205. <div class={styles.btnBox}>
  1206. <div class={styles.btnCon}>
  1207. <div
  1208. class={[styles.btnGr]}
  1209. onClick={(e) => {
  1210. e.stopPropagation();
  1211. //
  1212. // 播放音阶时不能切换
  1213. if (playStatus.gamut) {
  1214. return;
  1215. }
  1216. // 开始答题不能切换
  1217. if (playAction.listenLock) {
  1218. return;
  1219. }
  1220. data.changeSubjectShow = true;
  1221. }}
  1222. >
  1223. <img src={icons.icon_change_instrument} />
  1224. <span>切换乐器</span>
  1225. </div>
  1226. {data.subject !== "melodica" && data.fingeringMode === "scaleMode" && (
  1227. <div
  1228. class={styles.btnGr}
  1229. onClick={() => {
  1230. data.viewIndex++;
  1231. if (data.viewIndex > data.viewTotal) {
  1232. if (["pan-flute", "ocarina", "whistling"].includes(data.subject)) {
  1233. data.viewIndex = 1;
  1234. } else {
  1235. data.viewIndex = 0;
  1236. }
  1237. }
  1238. getFingeringData();
  1239. }}
  1240. >
  1241. <img src={icons.icon_toggle} />
  1242. <span>视图</span>
  1243. </div>
  1244. )}
  1245. <div
  1246. class={styles.btnGr}
  1247. onClick={() => {
  1248. resetElement();
  1249. data.tipShow = !data.tipShow;
  1250. }}
  1251. >
  1252. <img src={icons.icon_2_1} />
  1253. <span>说明</span>
  1254. </div>
  1255. {!!data.tones.length && data.fingeringMode === "scaleMode" && (
  1256. <>
  1257. {fingerData.fingeringInfo.name == "hulusi-flute" ? (
  1258. <div id="finger-note-1" class={[styles.btnGr, styles.btnGrToggleBtn]} onClick={() => (data.tnoteShow = true)}>
  1259. <div class={styles.nameBox}>
  1260. 全按作
  1261. <div class={[styles.noteKey, styles.noteKeyBtn]}>
  1262. {data.activeTone.step > 0 ? <span class={styles.dot}></span> : null}
  1263. <span class={styles.dot}></span>
  1264. <div class={styles.noteName}>
  1265. <sup>{data.activeTone.mark && (data.activeTone.mark === "rise" ? "#" : "b")}</sup>
  1266. {data.activeTone.key}
  1267. </div>
  1268. {data.activeTone.step < 0 ? <span class={styles.dot}></span> : null}
  1269. </div>
  1270. </div>
  1271. <img class={styles.arrowImg} src={icons.icon_arrow} />
  1272. </div>
  1273. ) : (
  1274. <div id="finger-note-1" class={[styles.btnGr, styles.btnGrToggleBtn]} onClick={() => (data.tnoteShow = true)}>
  1275. <div>
  1276. <div class={styles.name}>
  1277. <div>
  1278. <sup>{data.activeTone.mark && (data.activeTone.mark === "rise" ? "#" : "b")}</sup>
  1279. {data.activeTone.name}
  1280. </div>
  1281. </div>
  1282. <img class={styles.arrowImg} src={icons.icon_arrow} />
  1283. </div>
  1284. </div>
  1285. )}
  1286. </>
  1287. )}
  1288. {
  1289. instrumentTranstion.value &&
  1290. <div class={[styles.btnGr]} onClick={() => resetElement()}>
  1291. <img src={icons.icon_2_0} />
  1292. <span>还原</span>
  1293. </div>
  1294. }
  1295. </div>
  1296. </div>
  1297. </>)
  1298. }
  1299. </Tab>
  1300. })
  1301. }
  1302. </Tabs>
  1303. </div>
  1304. ):
  1305. (
  1306. <>
  1307. <div
  1308. class={styles.notes}
  1309. style={{
  1310. paddingLeft: data.paddingLeft ? data.paddingLeft : "",
  1311. }}
  1312. >
  1313. {playAction.listenTipsStatus && <div class={[styles.tipsT, data.fingeringMode === "fingeringMode" ? styles.playTips2 : styles.playTips]}></div>}
  1314. {playAction.userAnswerStatus === 1 && <div class={[styles.tipsT, styles.playSuccess]}></div>}
  1315. {playAction.userAnswerStatus === 2 && <div class={[styles.tipsT, styles.playError]}></div>}
  1316. {playAction.resetAction && <div class={[styles.tipsT, styles.playTips5]}></div>}
  1317. {((data.noteType !== "#c" && (orientationDirection.value === 0 || (orientationDirection.value === 1 && state.platform === IPlatform.PC))) || (orientationDirection.value === 1 && state.platform === IPlatform.APP)) && (
  1318. <Button
  1319. class={styles.noteBtn}
  1320. onClick={(e: any) => {
  1321. e.stopPropagation();
  1322. scrollNoteBox("left");
  1323. }}
  1324. >
  1325. <Icon name="arrow-left" />
  1326. </Button>
  1327. )}
  1328. <div
  1329. class={[styles.noteContent, data.fingeringMode !== "scaleMode" && orientationDirection.value === 0 && styles.noteContentOther, browsInfo.ios ? "" : styles.noteContentWrap, data.huaweiPad && styles.huaweiPad]}
  1330. onClick={(e: any) => {
  1331. e.stopPropagation();
  1332. }}
  1333. >
  1334. {/* 判断是否为音阶模式 */}
  1335. {data.fingeringMode !== "scaleMode" && (
  1336. <div draggable={false} class={styles.note} onClick={noteChangeShow}>
  1337. <img draggable={false} src={data.noteType === "all" ? icons.icon_btn_orange : icons.icon_btn_orange2} />
  1338. </div>
  1339. )}
  1340. {/* [styles.noteContent, browsInfo.ios ? "" : styles.noteContentWrap, data.huaweiPad && styles.huaweiPad] */}
  1341. <div class={styles.lastNoteContent}>
  1342. <div ref={noteBoxRef} class={styles.noteBox}>
  1343. {data.notes.map((note: IFIGNER_INSTRUMENT_Note, index: number) => {
  1344. const steps = new Array(Math.abs(note.step)).fill(1);
  1345. return (
  1346. <div
  1347. id={index == 0 ? "finger-note-0" : ""}
  1348. draggable={false}
  1349. class={[styles.note, "note-class"]}
  1350. key={note.realKey}
  1351. onClick={async () => {
  1352. // 判断是否在播放音阶
  1353. if (playStatus.gamut) return;
  1354. if (playAction.listenLock) return;
  1355. if (playAction.showAnswerLoading) return;
  1356. if (playStatus.action) {
  1357. playAction.userAnswer = note;
  1358. // 判断用户答题
  1359. const userResult = note.realKey === playAction.standardAnswer.realKey ? 1 : 2;
  1360. playAction.userAnswerStatus = userResult;
  1361. playAction.listenLock = true;
  1362. data.realKey = note.realKey;
  1363. await fingeringPlay(note, 1000);
  1364. resetMode(userResult === 1 ? true : false, 0);
  1365. data.realKey = 0;
  1366. // 如果是指法模式显示完之后要还原
  1367. if (data.fingeringMode === "fingeringMode" && userResult === 2) {
  1368. // 延迟显示,因为重置的时候有一个异步操作
  1369. setTimeout(() => {
  1370. data.realKey = playAction.standardAnswer.realKey;
  1371. }, 10);
  1372. }
  1373. playAction.listenLock = false;
  1374. } else {
  1375. noteClick(note);
  1376. }
  1377. }}
  1378. >
  1379. <img draggable={false} src={resultImg(note).icon} />
  1380. {playStatus.action && ((playAction.showAnswerLoading && playAction.standardAnswer.realKey === note.realKey) || (playAction.userAnswerStatus === 1 && playAction.userAnswer.realKey === note.realKey)) ? <span class={styles.showAnswer}></span> : ""}
  1381. {playStatus.action && playAction.userAnswerStatus === 2 && playAction.userAnswer.realKey === note.realKey ? <span class={[styles.showAnswer, styles.errorAnswer]}></span> : ""}
  1382. <div
  1383. class={[
  1384. styles.noteKey,
  1385. ((data.realKey === note.realKey && !playStatus.action) ||
  1386. (playStatus.action && playAction.exampleAnser.realKey === note.realKey) ||
  1387. (playStatus.action && ((playAction.showAnswerLoading && playAction.standardAnswer.realKey === note.realKey) || (playAction.userAnswerStatus === 1 && playAction.userAnswer.realKey === note.realKey))) ||
  1388. (playStatus.action && playAction.userAnswerStatus === 2 && playAction.userAnswer.realKey === note.realKey)) &&
  1389. styles.keyActive,
  1390. ]}
  1391. >
  1392. {/* 显示对应的点 */}
  1393. {note.step > 0 ? steps.map((n: any) => <span class={styles.dot}></span>) : null}
  1394. <div class={styles.noteName}>
  1395. <sup>{note.mark && (note.mark === "rise" ? "#" : "b")}</sup>
  1396. {note.key}
  1397. </div>
  1398. {/* 显示对应的点 */}
  1399. {note.step < 0 ? steps.map((n: any) => <span class={styles.dot}></span>) : null}
  1400. </div>
  1401. </div>
  1402. );
  1403. })}
  1404. </div>
  1405. </div>
  1406. </div>
  1407. {((data.noteType !== "#c" && (orientationDirection.value === 0 || (orientationDirection.value === 1 && state.platform === IPlatform.PC))) || (orientationDirection.value === 1 && state.platform === IPlatform.APP)) && (
  1408. <Button
  1409. class={styles.noteBtn}
  1410. onClick={(e: any) => {
  1411. e.stopPropagation();
  1412. scrollNoteBox("right");
  1413. }}
  1414. >
  1415. <Icon name="arrow" />
  1416. </Button>
  1417. )}
  1418. </div>
  1419. {data.fingeringMode !== "scaleMode" && (
  1420. <div
  1421. class={styles.optionBtns}
  1422. onClick={(e: any) => {
  1423. e.stopPropagation();
  1424. }}
  1425. >
  1426. <Button class={[styles.oBtn, styles.gamut, playStatus.action && styles.disabled]} round onClick={onGamutPlayOrPause}>
  1427. {playStatus.gamut ? "暂停" : "播放音阶"}
  1428. </Button>
  1429. <Button class={[styles.oBtn, styles.play, playStatus.gamut && styles.disabled]} round onClick={onActionPlay}>
  1430. {listenText.value}
  1431. </Button>
  1432. <Button class={[styles.oBtn, styles.success, !playStatus.answer && styles.disabled]} round onClick={onShowAnswer}>
  1433. 显示答案
  1434. </Button>
  1435. </div>
  1436. )}
  1437. </>
  1438. )
  1439. }
  1440. </div>
  1441. {/* 老师端过来隐藏 */}
  1442. {
  1443. query.platform!=='pc'&&(
  1444. <div
  1445. class={styles.fixedRightBtns}
  1446. style={{
  1447. paddingTop: data.paddingTop ? data.paddingTop : "",
  1448. paddingLeft: data.paddingLeft ? data.paddingLeft : "",
  1449. }}
  1450. onClick={(e: any) => {
  1451. e.stopPropagation();
  1452. }}
  1453. >
  1454. <div class={styles.rightBtn}>
  1455. {data.subject !== "melodica" && data.fingeringMode === "scaleMode" && (
  1456. <div
  1457. class={styles.baseBtn}
  1458. onClick={() => {
  1459. data.viewIndex++;
  1460. if (data.viewIndex > data.viewTotal) {
  1461. if (["pan-flute", "ocarina", "whistling"].includes(data.subject)) {
  1462. data.viewIndex = 1;
  1463. } else {
  1464. data.viewIndex = 0;
  1465. }
  1466. }
  1467. getFingeringData();
  1468. }}
  1469. >
  1470. <img src={icons.icon_toggle} />
  1471. <span>视图</span>
  1472. </div>
  1473. )}
  1474. <div
  1475. class={styles.baseBtn}
  1476. onClick={() => {
  1477. resetElement();
  1478. data.tipShow = !data.tipShow;
  1479. }}
  1480. >
  1481. <img src={icons.icon_2_1} />
  1482. <span>说明</span>
  1483. </div>
  1484. {!!data.tones.length && data.fingeringMode === "scaleMode" && (
  1485. <>
  1486. {fingerData.fingeringInfo.name == "hulusi-flute" ? (
  1487. <div id="finger-note-1" class={[styles.baseBtn, styles.toggleBtnhulusi, styles.active]} onClick={() => (data.tnoteShow = true)}>
  1488. <div>
  1489. 全按作
  1490. <div class={[styles.noteKey, styles.noteKeyBtn]}>
  1491. {data.activeTone.step > 0 ? <span class={styles.dot}></span> : null}
  1492. <span class={styles.dot}></span>
  1493. <div class={styles.noteName}>
  1494. <sup>{data.activeTone.mark && (data.activeTone.mark === "rise" ? "#" : "b")}</sup>
  1495. {data.activeTone.key}
  1496. </div>
  1497. {data.activeTone.step < 0 ? <span class={styles.dot}></span> : null}
  1498. </div>
  1499. </div>
  1500. <img src={icons.icon_arrow} />
  1501. </div>
  1502. ) : (
  1503. <div id="finger-note-1" class={[styles.baseBtn, styles.toggleBtnhulusi2, styles.active]} onClick={() => (data.tnoteShow = true)}>
  1504. <div class={styles.oterhD}>
  1505. <div>
  1506. <div style={{ marginTop: "-4px" }}>
  1507. <sup>{data.activeTone.mark && (data.activeTone.mark === "rise" ? "#" : "b")}</sup>
  1508. {data.activeTone.name}
  1509. </div>
  1510. </div>
  1511. <img src={icons.icon_arrow} />
  1512. </div>
  1513. </div>
  1514. )}
  1515. </>
  1516. )}
  1517. </div>
  1518. <div class={[styles.baseBtn, !instrumentTranstion.value && styles.resetBtn]} style={{ marginTop: "8px" }} onClick={() => resetElement()}>
  1519. <img src={icons.icon_2_0} />
  1520. <span>还原</span>
  1521. </div>
  1522. </div>
  1523. )
  1524. }
  1525. {/* 老师端加上遮罩点击关闭 */}
  1526. {
  1527. query.platform==='pc'&&data.tipShow&&(
  1528. <div class={[styles.tipsOverlay,data.tipShow?styles.tipsOverlayBg:'']} onClick={()=>{data.tipShow=false}}></div>
  1529. )
  1530. }
  1531. <div class={[styles.tips, data.loadingDom ? styles.hiddens : "", data.tipShow ? "" : styles.tipHidden,query.platform==='pc'&&data.tipShow?styles.tipsPcBg:""]}>
  1532. <div class={styles.tipTitle}>
  1533. <div class={styles.tipTitleName}>{fingerData.fingeringInfo.code}使用说明</div>
  1534. <Button
  1535. class={styles.tipClose}
  1536. onClick={(e: any) => {
  1537. e.stopPropagation();
  1538. data.tipShow = false;
  1539. }}
  1540. >
  1541. <Icon name="cross" size={19} color="#fff" />
  1542. </Button>
  1543. </div>
  1544. <div class={styles.iconBook}></div>
  1545. <div class={styles.tipContentbox}>
  1546. <div class={styles.tipContent}>
  1547. {data.tips.map((tip, tipIndex) => (
  1548. <div class={styles.tipItem}>
  1549. <div class={styles.iconWrap}>
  1550. <div class={styles.tipItemIcon}>{tipIndex + 1}</div>
  1551. </div>
  1552. <div>
  1553. {tip.name}: {tip.realName}
  1554. </div>
  1555. </div>
  1556. ))}
  1557. </div>
  1558. </div>
  1559. </div>
  1560. {data.loadingSoundFonts && (
  1561. <div class={styles.loading}>
  1562. <div class={styles.loadingWrap}>
  1563. <img class={styles.loadingIcon} src={icon_loading_img} />
  1564. <Progress percentage={data.loadingSoundProgress} />
  1565. <div class={styles.loadingTip}>加载中,请稍后…</div>
  1566. </div>
  1567. </div>
  1568. )}
  1569. </div>
  1570. <Popup class="tonePopup" v-model:show={data.tnoteShow} position={state.platform !== IPlatform.PC && !query.modelType && fingerData.fingeringInfo.orientation === 1 ? "bottom" : "right"}>
  1571. <div class={styles.tones}>
  1572. <div class={styles.toneTitle}>
  1573. <div class={styles.tipTitleName}>移调</div>
  1574. <Button
  1575. class={styles.tipClose}
  1576. onClick={(e: any) => {
  1577. e.stopPropagation();
  1578. data.tnoteShow = false;
  1579. }}
  1580. >
  1581. <Icon name="cross" size={19} color="#fff" />
  1582. </Button>
  1583. </div>
  1584. <div class={styles.tipContentbox}>
  1585. <div class={styles.tipContent}>
  1586. <div class={styles.tipWrap}>
  1587. <Space size={0} class={styles.toneContent}>
  1588. {data.tones.map((tone: IFIGNER_INSTRUMENT_Note) => {
  1589. const steps = new Array(Math.abs(tone.step)).fill(1);
  1590. return (
  1591. <Button
  1592. class={[fingerData.fingeringInfo.name == "hulusi-flute" && styles.hulusiBtn]}
  1593. round
  1594. plain
  1595. type={data.popupActiveTone.realName === tone.realName ? "primary" : "default"}
  1596. onClick={(e: any) => {
  1597. e.stopPropagation();
  1598. data.popupActiveTone = tone;
  1599. setNotes();
  1600. }}
  1601. >
  1602. {fingerData.fingeringInfo.name == "hulusi-flute" ? (
  1603. <div style={{ display: "flex", alignItems: "center" }}>
  1604. 全按作
  1605. <div class={[styles.noteKey, styles.hulusiNoteKey]}>
  1606. {tone.step > 0 ? <span class={styles.dot}></span> : null}
  1607. <div class={styles.noteName} style={{ fontSize: "0.25rem" }}>
  1608. <sup>{tone.mark && (tone.mark === "rise" ? "#" : "b")}</sup>
  1609. {tone.key}
  1610. </div>
  1611. {tone.step < 0 ? <span class={styles.dot}></span> : null}
  1612. </div>
  1613. </div>
  1614. ) : (
  1615. <div class={styles.noteName}>
  1616. <sup>{tone.mark && (tone.mark === "rise" ? "#" : "b")}</sup>
  1617. {tone.name}
  1618. </div>
  1619. )}
  1620. </Button>
  1621. );
  1622. })}
  1623. </Space>
  1624. </div>
  1625. <div class={styles.toneAction}>
  1626. <img
  1627. onClick={(e: any) => {
  1628. e.stopPropagation();
  1629. data.tnoteShow = false;
  1630. }}
  1631. src={icons.icon_action_cancel}
  1632. />
  1633. <img
  1634. onClick={(e: any) => {
  1635. e.stopPropagation();
  1636. data.activeTone = data.popupActiveTone;
  1637. setNotes();
  1638. data.tnoteShow = false;
  1639. }}
  1640. src={icons.icon_action_confirm}
  1641. />
  1642. </div>
  1643. </div>
  1644. </div>
  1645. </div>
  1646. </Popup>
  1647. <Popup
  1648. style={
  1649. query.platform==="pc" ? changeSubjectShowBoxDragData.styleDrag.value : {}
  1650. }
  1651. v-model:show={data.changeSubjectShow}
  1652. class={[styles.changeSubjectPopup,changeSubjectShowBoxClass]}
  1653. onClick={(e: any) => {
  1654. e.stopPropagation();
  1655. }}
  1656. >
  1657. <ChangeSubject
  1658. subjectList={data.subjects}
  1659. subject={data.subject}
  1660. onClose={() => (data.changeSubjectShow = false)}
  1661. onConfirm={(code: any) => {
  1662. if (data.subject === code) {
  1663. data.changeSubjectShow = false;
  1664. return;
  1665. }
  1666. const originalSubject = JSON.parse(JSON.stringify(data.subject));
  1667. data.subject = code;
  1668. data.viewIndex = 0;
  1669. data.tipShow = false;
  1670. data.loadingDom = true;
  1671. fingerData.fingeringInfo = subjectFingering(data.subject);
  1672. data.activeTone = {} as any;
  1673. resetElement();
  1674. resetMode(true, 0);
  1675. // api_setRequestedOrientation(orientationDirection.value);
  1676. data.changeSubjectShow = false;
  1677. // 设置屏幕方向
  1678. setTimeout(() => {
  1679. const before = ["hulusi-flute", "piccolo", "baroque-recorder"].includes(originalSubject) ? 0 : 0;
  1680. if (orientationDirection.value !== before) {
  1681. data.paddingTop = "";
  1682. data.paddingLeft = "";
  1683. }
  1684. __init();
  1685. }, 100);
  1686. }}
  1687. />
  1688. {query.platform==="pc" && <>
  1689. <div class={[styles.dragTopBox,"dragTopBox"]}></div>
  1690. <div class={[styles.dragbomBox,"dragbomBox"]}>
  1691. <Dragbom></Dragbom>
  1692. </div>
  1693. </>}
  1694. </Popup>
  1695. {props.show && !data.loading && !data.loadingSoundFonts && <GuideIndex fingeringMode={data.fingeringMode} showGuide={false} list={["finger"]} />}
  1696. </div>
  1697. );
  1698. };
  1699. },
  1700. });