index.tsx 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { PropType, computed, defineComponent, ref, toRefs, onMounted, watch } from 'vue'
  2. import { Picker, Button, Icon } from 'vant'
  3. import styles from './index.module.less'
  4. import state, { IPlatform } from "/src/state";
  5. import changeName from "./imgs/changeName.png"
  6. import { headImg } from "/src/page-instrument/header-top/image";
  7. import { toggleMusicSheet } from "../index"
  8. export default defineComponent({
  9. name: 'choosePartName',
  10. props: {
  11. partListNames: {
  12. type: Array as PropType<string[]>,
  13. default: () => [],
  14. },
  15. partIndex: {
  16. type: Number,
  17. default: 0,
  18. },
  19. },
  20. emits: ['close'],
  21. setup(props, { emit }) {
  22. // #9463 bug,未更换声轨点击确定不应该重新加载,现在会导致切换错误
  23. const partIndexChanged = ref(false);
  24. const { partListNames, partIndex } = toRefs(props)
  25. let idx = partListNames.value.findIndex((item: any) => item.value === partIndex.value);
  26. idx = idx > -1 ? idx : 0;
  27. const selectIndex = ref(idx);
  28. const columns = computed(() => {
  29. return partListNames.value
  30. })
  31. // console.log(1111,partListNames.value, partIndex.value, selectIndex.value, columns.value, 999999)
  32. /**
  33. * 默认选中的
  34. * picker组件,3.x的版本可以使用defaultIndex,4.x的版本只能使用v-model传递
  35. * */
  36. const selValues = ref([partIndex.value]);
  37. const myPicker = ref();
  38. onMounted(() => {
  39. // console.log(myPicker.value,99999,selValues.value,props.partIndex)
  40. });
  41. watch(
  42. () => toggleMusicSheet.show,
  43. () => {
  44. if (toggleMusicSheet.show) {
  45. selectIndex.value = partIndex.value
  46. selValues.value = [partIndex.value]
  47. }
  48. //console.log('声轨',selValues.value,partIndex.value,selectIndex.value)
  49. }
  50. );
  51. return () => (
  52. <div class={[styles.container, state.platform === IPlatform.PC && styles.pcContainer, styles[state.modeType]]}>
  53. <div class={styles.head}>
  54. <img class={styles.headTit} src={changeName} />
  55. <img class={styles.closeImg} src={headImg("closeImg.png")} onClick={() => emit("close")} />
  56. </div>
  57. { state.platform === IPlatform.PC && <div class={[!state.guideInfo?.teacherDrag && styles.pcPartTopZIndex ,styles.pcPartTop,'top_drag']}></div> }
  58. <div class={styles.pickerCon}>
  59. <div class={styles.pickerBox}>
  60. <Picker
  61. ref={myPicker}
  62. class={[styles.picker, state.platform === IPlatform.PC && styles.pcPicker]}
  63. defaultIndex={props.partIndex}
  64. v-model={selValues.value}
  65. showToolbar={false}
  66. columns={columns.value}
  67. visibleItemCount={Math.ceil(document.body.clientHeight / 40 / 3)}
  68. onChange={(row) => {
  69. console.log(1111,'选择的索引', row)
  70. if (!partIndexChanged.value) partIndexChanged.value = true
  71. selectIndex.value = row.selectedValues[0]
  72. }}
  73. />
  74. <div class={styles.button} onClick={() => {
  75. // console.log(1111,selectIndex.value)
  76. if (partIndexChanged.value) {
  77. emit('close', selectIndex.value)
  78. } else {
  79. emit('close', partIndex.value)
  80. }
  81. }
  82. }></div>
  83. </div>
  84. </div>
  85. </div>
  86. )
  87. },
  88. })