ToolList.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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, showToast } 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. const isDisabled = ref(false)
  80. function onClickToolItem(idx) {
  81. if (isDisabled.value === true) {
  82. return
  83. }
  84. if (requiredToolList.value.includes(idx)) {
  85. if (toolList.value[idx].selected === false) {
  86. if (requiredToolList.value.length === 1) {
  87. toolList.value[idx].selected = true
  88. showToast('选择正确')
  89. } else if (!props.currentStepInfo.hasToolOrder) {
  90. toolList.value[idx].selected = true
  91. showToast('选择正确')
  92. if (props.currentStepInfo.needWait) {
  93. isDisabled.value = true
  94. setTimeout(() => {
  95. isDisabled.value = false
  96. }, 1000)
  97. }
  98. } else {
  99. const toolIdxInRequiredToolList = requiredToolList.value.indexOf(idx)
  100. if (toolIdxInRequiredToolList === 0) {
  101. toolList.value[idx].selected = true
  102. showToast('选择正确')
  103. if (props.currentStepInfo.needWait) {
  104. isDisabled.value = true
  105. setTimeout(() => {
  106. isDisabled.value = false
  107. }, 1000)
  108. }
  109. } else {
  110. for (let i = 0; i < toolIdxInRequiredToolList; i++) {
  111. const preToolIdxInToolList = requiredToolList.value[i]
  112. if (!toolList.value[preToolIdxInToolList].selected) {
  113. showToast('您拿错工具了~请重新选择')
  114. return
  115. }
  116. toolList.value[idx].selected = true
  117. showToast('选择正确')
  118. if (props.currentStepInfo.needWait) {
  119. isDisabled.value = true
  120. setTimeout(() => {
  121. isDisabled.value = false
  122. }, 1000)
  123. }
  124. }
  125. }
  126. }
  127. }
  128. } else {
  129. showToast('您拿错工具了~请重新选择')
  130. }
  131. }
  132. /**
  133. * 左右scroll逻辑
  134. */
  135. const toolListEl = ref(null)
  136. const isShowLeftArrow = ref(false)
  137. const isShowRightArrow = ref(true)
  138. function onToolListElScroll() {
  139. if (toolListEl.value.scrollLeft === 0) {
  140. isShowLeftArrow.value = false
  141. } else {
  142. isShowLeftArrow.value = true
  143. }
  144. if (toolListEl.value.scrollWidth - toolListEl.value.scrollLeft - toolListEl.value.clientWidth === 0) {
  145. isShowRightArrow.value = false
  146. } else {
  147. isShowRightArrow.value = true
  148. }
  149. }
  150. function onClickLeftArrow() {
  151. toolListEl.value.scrollLeft -= toolListEl.value.scrollWidth / 8
  152. }
  153. function onClickRightArrow() {
  154. toolListEl.value.scrollLeft += toolListEl.value.scrollWidth / 8
  155. }
  156. </script>
  157. <style lang="less" scoped>
  158. .tool-list{
  159. >h3{
  160. text-align: center;
  161. font-size: calc(14 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  162. font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  163. font-weight: 400;
  164. color: #FFFFFF;
  165. line-height: calc(16 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  166. margin-bottom: calc(9 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  167. }
  168. >.wrapper{
  169. position: relative;
  170. >ul{
  171. display: flex;
  172. overflow: auto;
  173. padding-top: calc(19 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  174. &::-webkit-scrollbar { height: 0; };
  175. >li{
  176. flex: 0 0 auto;
  177. display: inline-block;
  178. text-align: center;
  179. margin-right: calc(5 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  180. >.tool-frame{
  181. width: calc(83 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  182. height: calc(83 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  183. background: rgba(255,255,255,0.3);
  184. border-radius: 2px 2px 2px 2px;
  185. border: 1px solid #FFFFFF;
  186. margin-bottom: calc(3 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  187. position: relative;
  188. >img{
  189. position: absolute;
  190. left: 0;
  191. bottom: 0;
  192. width: 100%;
  193. height: 100%;
  194. }
  195. >img.active{
  196. width: 125%;
  197. height: 125%;
  198. }
  199. }
  200. >.tool-frame.active{
  201. border: calc(4 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef')) solid #FFE096;
  202. }
  203. >span{
  204. font-size: calc(14 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  205. font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  206. font-weight: 400;
  207. color: #FFFFFF;
  208. line-height: calc(16 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  209. }
  210. >span.active{
  211. font-size: calc(14 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  212. font-family: Source Han Sans CN-Bold, Source Han Sans CN;
  213. font-weight: bold;
  214. color: #FFE096;
  215. line-height: calc(16 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  216. }
  217. }
  218. >li:first-of-type{
  219. margin-left: calc(12 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  220. }
  221. >li:last-of-type{
  222. margin-right: calc(12 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  223. }
  224. }
  225. >button.arrow-left{
  226. position: absolute;
  227. left: calc(8 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  228. top: 50%;
  229. transform: translateY(-50%);
  230. height: calc(24 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  231. >img{
  232. height: 100%;
  233. }
  234. }
  235. >button.arrow-right{
  236. position: absolute;
  237. right: calc(8 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  238. top: 50%;
  239. transform: translateY(-50%);
  240. height: calc(24 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
  241. >img{
  242. height: 100%;
  243. }
  244. }
  245. }
  246. }
  247. </style>