state.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { Toast } from 'vant'
  2. import { reactive, watchEffect } from 'vue'
  3. import { GradualNote } from './calcSpeed'
  4. import { IDifficulty } from './setting-state'
  5. type IRenderType = 'native' | 'cache'
  6. type IMode = 'homework' | 'contact' | 'evaluating'
  7. type URLSetting = {
  8. mode?: 'EVALUATING',
  9. resets?: ['SPEED'],
  10. difficulty?: IDifficulty,
  11. feeType?: 'FREE',
  12. submitData?: any
  13. }
  14. const state = reactive({
  15. sectionStatus: false,
  16. maskStatus: false,
  17. section: [] as any[],
  18. times: [] as any[],
  19. timesById: {} as any,
  20. sectionBoundingBoxs: [] as any[],
  21. activeTick: -1,
  22. activeTickRepeat: 1,
  23. showTick: false,
  24. isSpecialShapedScreen: false,
  25. notchHeight: 0,
  26. fixedKey: 0,
  27. renderLoading: false,
  28. evaluatings: {} as any,
  29. isPauseRecording: false,
  30. feeShow: false,
  31. vipShow: false,
  32. mode: 'contact' as IMode,
  33. subjectId: 0 as number,
  34. activeSpeed: 90 as number, // 当前速度
  35. baseSpeed: 90 as number, // 基准速度
  36. activeDetail: null as any,
  37. needTick: false, // 是否需要节拍器
  38. /** 跳过节拍器 */
  39. skipTick: false,
  40. /** 重复节拍 */
  41. repeatedBeats: true,
  42. sectionFlash: false,
  43. befireSection: null as any,
  44. /* 是否是打击乐 */
  45. isPercussion: false,
  46. enableEvaluation: true, // 是否开启评测
  47. isAppPlay: false, // 是否是app播放
  48. partListNames: [] as string[], // 当前曲谱中所有声部名字
  49. partIndex: 0, // 当前显示声部索引
  50. midiPlayIniting: false, // midi播放器是否初始化中
  51. isSpecialBookCategory: false, // 是否是特殊乐谱类型
  52. // 声部对应code
  53. code: '',
  54. /** 是否冻结模式 */
  55. frozenMode: false,
  56. /** 初次render结束 */
  57. initRendered: false,
  58. /** URL参数设置 */
  59. setting: null as null | URLSetting,
  60. /**当前激活的note */
  61. activeNote: '' as any,
  62. /** 免费试用比例,默认10% */
  63. freeRate: 0.1 as number,
  64. /** 渲染比例 */
  65. zoom: 1,
  66. /** 渲染模式*/
  67. renderType: 'native' as IRenderType,
  68. /** 渐变速度信息 */
  69. gradual: [] as GradualNote[],
  70. /** 渐变速度版本 */
  71. /** 渐变时间信息 */
  72. gradualTimes: null as GradualTimes
  73. })
  74. let toastItem: any = null
  75. watchEffect(() => {
  76. const data: any = {}
  77. for (const time of state.times) {
  78. if (time.id) {
  79. data[time.id] = time
  80. }
  81. }
  82. state.timesById = data
  83. if (state.subjectId > 0) {
  84. state.isPercussion = state.subjectId == 23 || state.subjectId == 113
  85. }
  86. if (state.renderLoading) {
  87. // toastItem = Toast({
  88. // duration: 0,
  89. // message: '加载中...',
  90. // })
  91. } else {
  92. if (toastItem) {
  93. toastItem.close()
  94. toastItem = null
  95. }
  96. }
  97. })
  98. export default state
  99. export type GradualTimes = null | {
  100. [key: string]: string
  101. }