123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- <template>
- <div class="tool-list">
- <h3>请在下方选择正确的工具({{ selectedToolNum }}/{{ requiredToolList.length }})</h3>
- <div class="wrapper">
- <ul
- ref="toolListEl"
- @scroll="onToolListElScroll"
- >
- <!-- @touchmove.prevent -->
- <li
- v-for="(toolItem, idx) in toolList"
- :key="toolItem.name"
- @click="onClickToolItem(idx)"
- >
- <div
- class="tool-frame"
- :class="{
- active: toolItem.selected,
- }"
- >
- <img
- class=""
- :class="{active: toolItem.selected,
- }"
- :src="toolItem.url"
- alt=""
- draggable="false"
- >
- </div>
- <span
- class="tool-name"
- :class="{
- active: toolItem.selected,
- }"
- >{{ toolItem.name }}</span>
- </li>
- </ul>
- <button
- v-show="isShowLeftArrow"
- class="arrow-left"
- @click="onClickLeftArrow"
- >
- <img
- class=""
- src="@/assets/images/arrow-left.png"
- alt=""
- draggable="false"
- >
- </button>
- <button
- v-show="isShowRightArrow"
- class="arrow-right"
- @click="onClickRightArrow"
- >
- <img
- class=""
- src="@/assets/images/arrow-right.png"
- alt=""
- draggable="false"
- >
- </button>
- </div>
- </div>
- </template>
- <script setup>
- import { ref, watch, computed } from "vue"
- import { toolList, selectedToolNum } from "@/store/index.js"
- const {
- windowSizeInCssForRef,
- windowSizeWhenDesignForRef,
- } = useSizeAdapt()
- const props = defineProps(['currentStepInfo'])
- const requiredToolList = computed(() => {
- return props.currentStepInfo.toolIdxList
- })
- /**
- * 选中工具逻辑
- */
- function onClickToolItem(idx) {
- if (requiredToolList.value.includes(idx)) {
- if (toolList.value[idx].selected === false) {
- if (requiredToolList.value.length === 1) {
- toolList.value[idx].selected = true
- window.alert('选择正确')
- } else if (!props.currentStepInfo.hasToolOrder) {
- toolList.value[idx].selected = true
- window.alert('选择正确')
- } else {
- const toolIdxInRequiredToolList = requiredToolList.value.indexOf(idx)
- if (toolIdxInRequiredToolList === 0) {
- toolList.value[idx].selected = true
- window.alert('选择正确')
- } else {
- for (let i = 0; i < toolIdxInRequiredToolList; i++) {
- const preToolIdxInToolList = requiredToolList.value[i]
- if (!toolList.value[preToolIdxInToolList].selected) {
- window.alert('您拿错工具了~请重新选择')
- return
- }
- toolList.value[idx].selected = true
- window.alert('选择正确')
- }
- }
- }
- }
- } else {
- window.alert('您拿错工具了~请重新选择')
- }
- }
- /**
- * 左右scroll逻辑
- */
- const toolListEl = ref(null)
- const isShowLeftArrow = ref(false)
- const isShowRightArrow = ref(true)
- function onToolListElScroll() {
- if (toolListEl.value.scrollLeft === 0) {
- isShowLeftArrow.value = false
- } else {
- isShowLeftArrow.value = true
- }
- if (toolListEl.value.scrollWidth - toolListEl.value.scrollLeft - toolListEl.value.clientWidth === 0) {
- isShowRightArrow.value = false
- } else {
- isShowRightArrow.value = true
- }
- }
- function onClickLeftArrow() {
- toolListEl.value.scrollLeft -= toolListEl.value.scrollWidth / 8
- }
- function onClickRightArrow() {
- toolListEl.value.scrollLeft += toolListEl.value.scrollWidth / 8
- }
- </script>
- <style lang="less" scoped>
- .tool-list{
- >h3{
- text-align: center;
- font-size: calc(14 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
- font-family: Source Han Sans CN-Regular, Source Han Sans CN;
- font-weight: 400;
- color: #FFFFFF;
- line-height: calc(16 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
- margin-bottom: calc(9 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
- }
- >.wrapper{
- position: relative;
- >ul{
- display: flex;
- overflow: auto;
- padding-top: calc(19 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
- &::-webkit-scrollbar { height: 0; };
- >li{
- flex: 0 0 auto;
- display: inline-block;
- text-align: center;
- margin-right: calc(5 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
- >.tool-frame{
- width: calc(83 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
- height: calc(83 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
- background: rgba(255,255,255,0.3);
- border-radius: 2px 2px 2px 2px;
- border: 1px solid #FFFFFF;
- margin-bottom: calc(3 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
- position: relative;
- >img{
- position: absolute;
- left: 0;
- bottom: 0;
- width: 100%;
- height: 100%;
- }
- >img.active{
- width: 125%;
- height: 125%;
- }
- }
- >.tool-frame.active{
- border: calc(4 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef')) solid #FFE096;
- }
- >span{
- font-size: calc(14 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
- font-family: Source Han Sans CN-Regular, Source Han Sans CN;
- font-weight: 400;
- color: #FFFFFF;
- line-height: calc(16 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
- }
- >span.active{
- font-size: calc(14 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
- font-family: Source Han Sans CN-Bold, Source Han Sans CN;
- font-weight: bold;
- color: #FFE096;
- line-height: calc(16 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
- }
- }
- >li:first-of-type{
- margin-left: calc(12 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
- }
- >li:last-of-type{
- margin-right: calc(12 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
- }
- }
- >button.arrow-left{
- position: absolute;
- left: calc(8 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
- top: 50%;
- transform: translateY(-50%);
- height: calc(24 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
- >img{
- height: 100%;
- }
- }
- >button.arrow-right{
- position: absolute;
- right: calc(8 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
- top: 50%;
- transform: translateY(-50%);
- height: calc(24 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));;
- >img{
- height: 100%;
- }
- }
- }
- }
- </style>
|