ToolList.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <div class="tool-list">
  3. <h3>请在下方选择正确的工具({{ selectedToolNum }}/{{ requiredToolList.length }})</h3>
  4. <div class="wrapper">
  5. <ul
  6. ref="toolListEl"
  7. @scroll="onToolListElScroll"
  8. >
  9. <!-- @touchmove.prevent -->
  10. <li
  11. v-for="(toolItem, idx) in toolList"
  12. :key="toolItem.name"
  13. @click="onClickToolItem(idx)"
  14. >
  15. <div
  16. class="tool-frame"
  17. :class="{
  18. active: toolItem.selected,
  19. }"
  20. >
  21. <img
  22. class=""
  23. :class="{active: toolItem.selected,
  24. }"
  25. :src="toolItem.url"
  26. alt=""
  27. draggable="false"
  28. >
  29. </div>
  30. <span
  31. class="tool-name"
  32. :class="{
  33. active: toolItem.selected,
  34. }"
  35. >{{ toolItem.name }}</span>
  36. </li>
  37. </ul>
  38. <button
  39. v-show="isShowLeftArrow"
  40. class="arrow-left"
  41. @click="onClickLeftArrow"
  42. >
  43. <img
  44. class=""
  45. src="@/assets/images/arrow-left.png"
  46. alt=""
  47. draggable="false"
  48. >
  49. </button>
  50. <button
  51. v-show="isShowRightArrow"
  52. class="arrow-right"
  53. @click="onClickRightArrow"
  54. >
  55. <img
  56. class=""
  57. src="@/assets/images/arrow-right.png"
  58. alt=""
  59. draggable="false"
  60. >
  61. </button>
  62. </div>
  63. </div>
  64. </template>
  65. <script setup>
  66. import { ref, watch, computed } from "vue"
  67. import { toolList, selectedToolNum } from "@/store/index.js"
  68. const {
  69. windowSizeInCssForRef,
  70. windowSizeWhenDesignForRef,
  71. } = useSizeAdapt()
  72. const props = defineProps(['currentStepInfo'])
  73. const requiredToolList = computed(() => {
  74. return props.currentStepInfo.toolIdxList
  75. })
  76. /**
  77. * 选中工具逻辑
  78. */
  79. function onClickToolItem(idx) {
  80. if (requiredToolList.value.includes(idx)) {
  81. if (toolList.value[idx].selected === false) {
  82. if (requiredToolList.value.length === 1) {
  83. toolList.value[idx].selected = true
  84. window.alert('选择正确')
  85. } else if (!props.currentStepInfo.hasToolOrder) {
  86. toolList.value[idx].selected = true
  87. window.alert('选择正确')
  88. } else {
  89. const toolIdxInRequiredToolList = requiredToolList.value.indexOf(idx)
  90. if (toolIdxInRequiredToolList === 0) {
  91. toolList.value[idx].selected = true
  92. window.alert('选择正确')
  93. } else {
  94. for (let i = 0; i < toolIdxInRequiredToolList; i++) {
  95. const preToolIdxInToolList = requiredToolList.value[i]
  96. if (!toolList.value[preToolIdxInToolList].selected) {
  97. window.alert('您拿错工具了~请重新选择')
  98. return
  99. }
  100. toolList.value[idx].selected = true
  101. window.alert('选择正确')
  102. }
  103. }
  104. }
  105. }
  106. } else {
  107. window.alert('您拿错工具了~请重新选择')
  108. }
  109. }
  110. /**
  111. * 左右scroll逻辑
  112. */
  113. const toolListEl = ref(null)
  114. const isShowLeftArrow = ref(false)
  115. const isShowRightArrow = ref(true)
  116. function onToolListElScroll() {
  117. if (toolListEl.value.scrollLeft === 0) {
  118. isShowLeftArrow.value = false
  119. } else {
  120. isShowLeftArrow.value = true
  121. }
  122. if (toolListEl.value.scrollWidth - toolListEl.value.scrollLeft - toolListEl.value.clientWidth === 0) {
  123. isShowRightArrow.value = false
  124. } else {
  125. isShowRightArrow.value = true
  126. }
  127. }
  128. function onClickLeftArrow() {
  129. toolListEl.value.scrollLeft -= toolListEl.value.scrollWidth / 8
  130. }
  131. function onClickRightArrow() {
  132. toolListEl.value.scrollLeft += toolListEl.value.scrollWidth / 8
  133. }
  134. </script>
  135. <style lang="less" scoped>
  136. .tool-list{
  137. >h3{
  138. text-align: center;
  139. font-size: calc(14 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  140. font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  141. font-weight: 400;
  142. color: #FFFFFF;
  143. line-height: calc(16 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  144. margin-bottom: calc(9 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  145. }
  146. >.wrapper{
  147. position: relative;
  148. >ul{
  149. display: flex;
  150. overflow: auto;
  151. padding-top: calc(19 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  152. &::-webkit-scrollbar { height: 0; };
  153. >li{
  154. flex: 0 0 auto;
  155. display: inline-block;
  156. text-align: center;
  157. margin-right: calc(5 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  158. >.tool-frame{
  159. width: calc(83 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  160. height: calc(83 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  161. background: rgba(255,255,255,0.3);
  162. border-radius: 2px 2px 2px 2px;
  163. border: 1px solid #FFFFFF;
  164. margin-bottom: calc(3 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  165. position: relative;
  166. >img{
  167. position: absolute;
  168. left: 0;
  169. bottom: 0;
  170. width: 100%;
  171. height: 100%;
  172. }
  173. >img.active{
  174. width: 125%;
  175. height: 125%;
  176. }
  177. }
  178. >.tool-frame.active{
  179. border: calc(4 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef')) solid #FFE096;
  180. }
  181. >span{
  182. font-size: calc(14 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  183. font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  184. font-weight: 400;
  185. color: #FFFFFF;
  186. line-height: calc(16 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  187. }
  188. >span.active{
  189. font-size: calc(14 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  190. font-family: Source Han Sans CN-Bold, Source Han Sans CN;
  191. font-weight: bold;
  192. color: #FFE096;
  193. line-height: calc(16 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  194. }
  195. }
  196. >li:first-of-type{
  197. margin-left: calc(12 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  198. }
  199. >li:last-of-type{
  200. margin-right: calc(12 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  201. }
  202. }
  203. >button.arrow-left{
  204. position: absolute;
  205. left: calc(8 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  206. top: 50%;
  207. transform: translateY(-50%);
  208. height: calc(24 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  209. >img{
  210. height: 100%;
  211. }
  212. }
  213. >button.arrow-right{
  214. position: absolute;
  215. right: calc(8 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  216. top: 50%;
  217. transform: translateY(-50%);
  218. height: calc(24 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  219. >img{
  220. height: 100%;
  221. }
  222. }
  223. }
  224. }
  225. </style>