index.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. import { defineComponent, reactive, computed, toRef } from "vue";
  2. import styles from "./index.module.less"
  3. import { headImg } from "../image";
  4. import { headTopData } from "../index"
  5. import { Switch, showToast, Field, Popup, Slider } from "vant";
  6. import state, { refreshMusicSvg, IPlatform, checkMoveNoSave } from "/src/state"
  7. import { api_closeCamera, api_openCamera, api_savePicture } from "/src/helpers/communication";
  8. import { smoothAnimationState} from "/src/page-instrument/view-detail/smoothAnimation"
  9. import Recommendation from "../../custom-plugins/helper-model/recommendation";
  10. import { resetRenderMusicScore } from "/src/view/music-score";
  11. import ScreenModel from "../../custom-plugins/helper-model/screen-model";
  12. import { getQuery } from "/src/utils/queryString";
  13. import { reCheckDelay } from "/src/page-instrument/evaluat-model"
  14. import { audioData, changeMingSongType } from "/src/view/audio-list"
  15. import useDrag from "/src/view/plugins/useDrag/index";
  16. import Dragbom from "/src/view/plugins/useDrag/dragbom";
  17. import { storeData } from "/src/store";
  18. import { getGuidance, setGuidance } from "../../custom-plugins/guide-page/api";
  19. import { handleLoadBeatMusic } from "/src/view/audio-list"
  20. export default defineComponent({
  21. name: "settting",
  22. setup() {
  23. const query = getQuery();
  24. const helperData = reactive({
  25. screenModelShow: false, // 投屏帮助
  26. recommendationShow: false, // 建议
  27. });
  28. const zoomList = [{name:'0.5x',value: 0.5},{name:'0.75x',value: 0.65},{name:'1x',value: 0.8},{name:'1.25x',value: 1.25},{name:'1.5x',value: 1.5},{name:'1.75x',value: 1.75},{name:'2x',value: 2},{name:'2.25x',value: 2.25}]
  29. const parentClassName = "recommenBoxClass_drag";
  30. const userId = storeData.user?.id ? String(storeData.user?.id) : "";
  31. const positionInfo =
  32. state.platform !== IPlatform.PC
  33. ? {
  34. styleDrag: { value: null },
  35. }
  36. : useDrag([`${parentClassName} .top_draging`, `${parentClassName} .bom_drag`], parentClassName, toRef(helperData, "recommendationShow"), userId);
  37. // 完成拖动弹窗引导页
  38. const handleGuide = async () => {
  39. state.guideInfo.teacherDrag = true;
  40. try {
  41. const res = await setGuidance({ guideTag: "guideInfo", guideValue: JSON.stringify(state.guideInfo) });
  42. } catch (e) {
  43. console.log(e);
  44. }
  45. };
  46. // 加减评测频率
  47. const operateHz = (type: number) => {
  48. const minFrequency = state.baseFrequency - 10, maxFrequency = state.baseFrequency + 10
  49. let currentFrequency = state.setting.frequency
  50. if (type === 1) {
  51. if (currentFrequency - 1 < minFrequency) return showToast({ message: `最低标准音高${minFrequency}HZ` })
  52. currentFrequency = currentFrequency - 1
  53. } else {
  54. if (currentFrequency + 1 > maxFrequency) return showToast({ message: `最高标准音高${maxFrequency}HZ` })
  55. currentFrequency = currentFrequency + 1
  56. }
  57. state.setting.frequency = currentFrequency >= 0 ? currentFrequency : 0
  58. }
  59. const formatterTimeMs = (value: any) => value = String(Math.min(3000, value));
  60. const notationList = computed(() => {
  61. const list = state.enableNotation ? [{name:'五线谱',value:'staff'},{name:'首调',value:'firstTone'},{name:'固定调',value:'fixedTone'}] : [{name:'首调',value:'firstTone'},{name:'固定调',value:'fixedTone'}];
  62. return list;
  63. });
  64. return () => (
  65. <div class={[styles.settting, styles[state.modeType]]}>
  66. <div class={[styles.head, "top_draging"]}>
  67. <img class={styles.headTit} src={headImg("settingName.png")} />
  68. <img class={styles.closeImg} src={headImg("closeImg.png")} onClick={()=>{ headTopData.settingMode = false }} />
  69. </div>
  70. <div class={styles.content}>
  71. <div class={styles.conBox}>
  72. {
  73. state.isShowFingering && state.fingeringInfo.name && ["practise", "follow", "evaluating"].includes(state.modeType) && state.playType === "play" &&
  74. <div class={styles.cellBox}>
  75. <div class={styles.tit}>指法</div>
  76. <Switch v-model={state.setting.displayFingering}></Switch>
  77. </div>
  78. }
  79. {
  80. ["practise", "follow"].includes(state.modeType) &&
  81. <div class={styles.cellBox}>
  82. <div class={styles.tit}>循环播放</div>
  83. <Switch v-model={state.setting.repeatAutoPlay}></Switch>
  84. </div>
  85. }
  86. { !state.isCombineRender &&
  87. <div class={styles.cellBox}>
  88. <div class={styles.tit}>合并休止小节</div>
  89. <Switch
  90. v-model={state.setting.combineMultipleRest}
  91. onChange={ async (value) => {
  92. await checkMoveNoSave();
  93. headTopData.settingMode = false
  94. const _time = setTimeout(() => {
  95. clearTimeout(_time)
  96. refreshMusicSvg();
  97. }, 100);
  98. }}
  99. ></Switch>
  100. </div>
  101. }
  102. {
  103. state.isSingleLine && state.modeType === "practise" && !state.isCombineRender && !state.isPercussion &&
  104. <div class={styles.cellBox}>
  105. <div class={styles.tit}>旋律线</div>
  106. <Switch
  107. v-model={smoothAnimationState.isShow.value}
  108. onChange={(value) => {
  109. state.melodyLine = value
  110. }}
  111. ></Switch>
  112. </div>
  113. }
  114. {
  115. state.modeType === 'practise' && state.playSource === "mingSong" && state.mingSong && state.mingSongGirl &&
  116. <div class={styles.cellBox}>
  117. <div class={styles.tit}>唱名类型</div>
  118. <div class={styles.radioBox}>
  119. {
  120. [{name:'男声',value:1}, {name:'女声',value:0}].map(item=>{
  121. return <div class={ audioData.mingSongType===item.value && styles.active } onClick={ ()=>{
  122. if(audioData.mingSongType === item.value){
  123. return
  124. }
  125. audioData.mingSongType = item.value as 0|1
  126. // 加载节拍器音频
  127. handleLoadBeatMusic()
  128. changeMingSongType()
  129. } }>{item.name}</div>
  130. })
  131. }
  132. </div>
  133. </div>
  134. }
  135. {
  136. state.modeType === "evaluating" &&
  137. <>
  138. {
  139. !query.workRecord &&
  140. <div class={styles.cellBox}>
  141. <div class={styles.tit}>评测难度</div>
  142. <div class={styles.radioBox}>
  143. {
  144. [{name:'入门',value:"BEGINNER"},{name:'进阶',value:"ADVANCED"},{name:'大师',value:"PERFORMER"}].map(item=>{
  145. return <div class={ state.setting.evaluationDifficulty===item.value && styles.active } onClick={ ()=>{
  146. state.setting.evaluationDifficulty = item.value as any
  147. } }>{item.name}</div>
  148. })
  149. }
  150. </div>
  151. </div>
  152. }
  153. <div class={styles.cellBox}>
  154. <div class={styles.tit}>延迟检测</div>
  155. {/* <Switch v-model={state.setting.soundEffect}></Switch> */}
  156. <div class={styles.titbtn} onClick={() => {
  157. reCheckDelay();
  158. }}>重新检测</div>
  159. </div>
  160. <div class={[styles.cellBox, state.setting.camera && styles.isCamera]}>
  161. <div class={styles.tit}>摄像头</div>
  162. <Switch
  163. // v-model={state.setting.camera}
  164. modelValue={state.setting.camera}
  165. onChange={ async (value) => {
  166. if (value) {
  167. const res = await api_openCamera();
  168. // 没有授权
  169. if (res?.content?.reson) {
  170. state.setting.camera = false
  171. } else {
  172. state.setting.camera = true
  173. }
  174. } else {
  175. api_closeCamera();
  176. state.setting.camera = false;
  177. }
  178. }}
  179. ></Switch>
  180. </div>
  181. <div class={styles.cellBox} style={{ display: state.setting.camera ? "" : "none", paddingTop: 0 }}>
  182. <div class={styles.tit}>不透明度</div>
  183. <div class={styles.spendCon}>
  184. <div class={styles.sliderCon}>
  185. <Slider class={styles.slider} max={100} min={0} v-model={state.setting.cameraOpacity}>
  186. {{
  187. button: () =>
  188. <div class={styles.customButton}>
  189. <div class={styles.speedVal}>{ state.setting.cameraOpacity }</div>
  190. <div class={styles.speedBtn}></div>
  191. </div>
  192. }}
  193. </Slider>
  194. </div>
  195. </div>
  196. </div>
  197. <div class={styles.cellBox}>
  198. <div class={styles.tit}>标准音高</div>
  199. <div class={styles.frequency}>
  200. <img src={headImg("cutImg.png")} class={[styles.btn]} onClick={() => operateHz(1)} />
  201. <div class={styles.frequencyNum}>{state.setting.frequency}HZ</div>
  202. <img src={headImg("addImg.png")} class={[styles.btn]} onClick={() => operateHz(2)} />
  203. </div>
  204. </div>
  205. <div class={styles.cellBox}>
  206. <div class={styles.tit}>反应时间</div>
  207. <div class={styles.reactionTimeBox}>
  208. <Field class={styles.reactionTime} type="digit"
  209. placeholder="最大可输入3000毫秒"
  210. formatter={formatterTimeMs}
  211. input-align={'center'}
  212. v-model:modelValue={state.setting.reactionTimeMs} />
  213. <div class={styles.timeName}>毫秒</div>
  214. </div>
  215. </div>
  216. </>
  217. }
  218. {/** 练习模式才有单行/多行谱切换功能,跟练、评测只有单行谱模式 */}
  219. {
  220. ["practise", "evaluating"].includes(state.modeType) ?
  221. <div class={styles.cellBox}>
  222. <div class={styles.tit}>切换谱面</div>
  223. <div class={styles.radioBox}>
  224. {
  225. [{name:'单行谱',value:true},{name:'多行谱',value:false}].map(item=>{
  226. return <div class={ state.isSingleLine===item.value && styles.active } onClick={ async ()=>{
  227. if(state.isSingleLine === item.value){
  228. return
  229. }
  230. await checkMoveNoSave();
  231. headTopData.settingMode = false
  232. // resetRenderMusicScore(state.musicRenderType)
  233. const _time = setTimeout(() => {
  234. state.isSingleLine = item.value
  235. clearTimeout(_time)
  236. refreshMusicSvg();
  237. }, 100);
  238. // musicScoreRef.value?.refreshMusicScore()
  239. } }>{item.name}</div>
  240. })
  241. }
  242. </div>
  243. </div> : null
  244. }
  245. {
  246. state.enableNotation || state.specialShowNotation ?
  247. <div class={styles.cellBox}>
  248. <div class={styles.tit}>转谱</div>
  249. <div class={styles.radioBox}>
  250. {
  251. notationList.value.map(item=>{
  252. return <div class={ state.musicRenderType===item.value && styles.active } onClick={ async ()=>{
  253. if(state.musicRenderType === item.value){
  254. return
  255. }
  256. await checkMoveNoSave();
  257. headTopData.settingMode = false
  258. // resetRenderMusicScore(state.musicRenderType)
  259. const _time = setTimeout(() => {
  260. state.musicRenderType = item.value as any
  261. clearTimeout(_time)
  262. refreshMusicSvg();
  263. }, 100);
  264. } }>{item.name}</div>
  265. })
  266. }
  267. </div>
  268. </div> : null
  269. }
  270. {
  271. !state.isCbsView ?
  272. <div class={[styles.cellBox, styles.speCon]}>
  273. <div class={styles.tit}>谱面大小</div>
  274. <div class={styles.radioBox}>
  275. {
  276. zoomList.map(item=>{
  277. return <div class={ state.zoom===item.value && styles.active } onClick={ async ()=>{
  278. if(state.zoom === item.value){
  279. return
  280. }
  281. await checkMoveNoSave();
  282. headTopData.settingMode = false
  283. // resetRenderMusicScore(state.musicRenderType)
  284. const _time = setTimeout(() => {
  285. state.zoom = item.value as any
  286. localStorage.setItem('scoreZoom',String(state.zoom))
  287. clearTimeout(_time)
  288. refreshMusicSvg();
  289. }, 100);
  290. } }>{item.name}</div>
  291. })
  292. }
  293. </div>
  294. </div> : null
  295. }
  296. <div class={styles.cellBtnBox}>
  297. <img src={headImg("tpbz.png")} onClick={() => (helperData.screenModelShow = true)} />
  298. {
  299. !query.isCbs && <img src={headImg("yjfk.png")} onClick={() => (helperData.recommendationShow = true)} />
  300. }
  301. </div>
  302. </div>
  303. </div>
  304. <Popup
  305. v-model:show={helperData.recommendationShow}
  306. class="popup-custom van-scale center-closeBtn recommenBoxClass_drag"
  307. transition="van-scale"
  308. teleport="body"
  309. overlay-style={{background:'rgba(0, 0, 0, 0.7)'}}
  310. style={positionInfo.styleDrag.value}
  311. >
  312. <Recommendation
  313. onClose={() => {
  314. helperData.recommendationShow = false;
  315. }}
  316. />
  317. {state.platform === IPlatform.PC && <Dragbom showGuide={!state.guideInfo?.teacherDrag} onGuideDone={handleGuide} />}
  318. </Popup>
  319. <Popup
  320. class={["popup-custom"]}
  321. v-model:show={helperData.screenModelShow}
  322. onClose={() => {
  323. helperData.screenModelShow = false;
  324. }}
  325. position="right"
  326. teleport="body"
  327. >
  328. <ScreenModel
  329. onClose={(open: Boolean) => {
  330. helperData.screenModelShow = false;
  331. }}
  332. />
  333. </Popup>
  334. </div>
  335. );
  336. },
  337. });