qa.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="use-layout" :class="language">
  3. <lselect :options="navs" :selected="navActive" class="select" :class="{oy: navs.length > 15}" @change="handleChange" />
  4. <div class="use-con" ref="dcon" id="dcon">
  5. <img class="img" v-for="(item,i) in current.size" :src="`${$cdn}images/qa/${current.id}/${language==='en'?'en':'zh'}/${i+1}.jpg`" :key="i" :alt="i+1">
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. import lselect from '@/components/lselect'
  11. import {mapState} from 'vuex'
  12. export default {
  13. props: ['data'],
  14. computed: {
  15. ...mapState({
  16. language: state => state.language.current
  17. })
  18. },
  19. methods: {
  20. handleChange (nav) {
  21. setTimeout(async () => {
  22. let items = Array.from(this.$refs.dcon.querySelectorAll('img'))
  23. let offTop = 0
  24. items.forEach(item => {
  25. // item.style.background = '#fff'
  26. // let txt = item.querySelectorAll('span')[1].innerText
  27. if (String(item.alt) === String(nav.cover)) {
  28. offTop = item.offsetTop
  29. }
  30. })
  31. this.$refs.dcon.removeEventListener('scroll', this.listen)
  32. document.querySelector('#dcon').scrollTop = offTop
  33. setTimeout(() => {
  34. this.$refs.dcon.addEventListener('scroll', this.listen)
  35. }, 500)
  36. }, 0)
  37. },
  38. listen (e) {
  39. let sTop = e.target.scrollTop
  40. let items = Array.from(this.$refs.dcon.querySelectorAll('img'))
  41. let active = ''
  42. let nav = ''
  43. items.forEach(item => {
  44. if (sTop > item.offsetTop - 1) {
  45. active = item.alt
  46. }
  47. })
  48. this.navs.forEach(sub => {
  49. if (String(active) === String(sub.cover)) {
  50. nav = sub
  51. }
  52. })
  53. this.navActive = nav
  54. }
  55. },
  56. watch: {
  57. data: {
  58. immediate: false,
  59. deep: true,
  60. handler (newVal) {
  61. this.navs = this.data.data
  62. this.current = this.data.detail
  63. this.navActive = this.data.data[0]
  64. this.$refs.dcon.removeEventListener('scroll', this.listen)
  65. this.$refs.dcon.scrollTo(0, 0)
  66. setTimeout(() => {
  67. this.$refs.dcon.addEventListener('scroll', this.listen)
  68. }, 500)
  69. }
  70. }
  71. },
  72. data () {
  73. return {
  74. active: '',
  75. navs: this.data.data,
  76. current: this.data.detail,
  77. navActive: this.data.data[0]
  78. }
  79. },
  80. mounted () {
  81. setTimeout(() => {
  82. this.$refs.dcon.addEventListener('scroll', this.listen)
  83. }, 0)
  84. },
  85. components: {lselect}
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. $lw: 220px;
  90. $cw: 430px;
  91. $encw: 430px;
  92. .use-layout {
  93. position: relative;
  94. max-width: 800px;
  95. margin: 50px auto 72px;
  96. overflow: hidden;
  97. padding-left: $lw + 18px;
  98. padding-right: 10px;
  99. box-sizing: border-box;
  100. .select {
  101. min-width: $lw;
  102. position: absolute;
  103. top: 0;
  104. left: 0;
  105. max-height: 100%;
  106. overflow-y: auto;
  107. }
  108. .img{
  109. margin-bottom: 20px;
  110. width: 100%;
  111. text-align: center;
  112. }
  113. .use-con{
  114. max-height: 100%;
  115. height: calc(100vh - 380px);
  116. overflow-y: auto;
  117. width: $cw;
  118. text-align: center;
  119. .img{
  120. &:last-of-type{
  121. margin-bottom: 200px;
  122. }
  123. }
  124. &::-webkit-scrollbar {
  125. width: 5px;
  126. height: 8px;
  127. }
  128. &::-webkit-scrollbar-thumb {
  129. height: 50px;
  130. background-color: rgba(221, 221, 221, 0.2);
  131. -webkit-border-radius: 4px;
  132. outline: 2px solid #fff;
  133. outline-offset: -2px;
  134. }
  135. &::-webkit-scrollbar-thumb:hover {
  136. height: 50px;
  137. background-color: #9f9f9f;
  138. -webkit-border-radius: 4px;
  139. }
  140. }
  141. }
  142. .en{
  143. max-width: 800px;
  144. padding-left: $lw + 58px;
  145. .use-con{
  146. width: $encw;
  147. }
  148. }
  149. </style>