ShipGameView.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div class="ship-game">
  3. <img
  4. class="close"
  5. draggable="false"
  6. src="@/assets/images/ship-game/icon_cancel-min.png"
  7. @click="back"
  8. >
  9. <div
  10. v-if="showBanner"
  11. class="ship-game-banner"
  12. >
  13. <img
  14. class="logo"
  15. src="@/assets/images/ship-game/Group 493-min.png"
  16. >
  17. <p>
  18. 选择船只,出现此船只轮廓图和船只构件,选择构件拖拽至线稿船对应区域填充,搭建完整船只
  19. </p>
  20. <button @click="showBanner = false">
  21. 开始
  22. </button>
  23. </div>
  24. <template v-else>
  25. <img
  26. class="logo2"
  27. draggable="false"
  28. src="@/assets/images/ship-game/Group 493-min.png"
  29. >
  30. <p class="tips">
  31. 长按下方部件并拖动到正确位置,完成船只拼图
  32. </p>
  33. <div class="ship-game-container">
  34. <template
  35. v-for="item in MODULE_LIST"
  36. :key="item.key"
  37. >
  38. <Container
  39. v-if="curDragKey === item.key || checkedModule.includes(item.key)"
  40. class="img"
  41. group-name="default"
  42. :should-animate-drop="() => false"
  43. :style="`${item.hightImgStyle} background: url(${checkedModule.includes(item.key) ? item.img : item.hightImg}) no-repeat center / cover`"
  44. @drop="res => {
  45. if (!checkedModule.includes(res.payload.key)) {
  46. checkedModule.push(res.payload.key)
  47. }
  48. }"
  49. >
  50. <div />
  51. </Container>
  52. </template>
  53. </div>
  54. <Container
  55. behaviour="copy"
  56. drag-class="drag-class"
  57. class="ship-game-footer drag"
  58. group-name="default"
  59. non-drag-area-selector=".checked"
  60. :get-child-payload="(x) => MODULE_LIST[x]"
  61. @drag-end="() => {
  62. curDragKey = ''
  63. }"
  64. >
  65. <Draggable
  66. v-for="item in MODULE_LIST"
  67. :key="item.key"
  68. :class="['ship-game-footer__item', checkedModule.includes(item.key) && 'checked']"
  69. @mousedown="() => {
  70. curDragKey = item.key
  71. }"
  72. >
  73. <img
  74. draggable="false"
  75. :src="item.img"
  76. :style="{width: item.imgWidth}"
  77. >
  78. <div
  79. v-if="checkedModule.includes(item.key)"
  80. class="icon"
  81. />
  82. </Draggable>
  83. </Container>
  84. <div class="ship-game-footer">
  85. <div
  86. v-for="item in MODULE_LIST"
  87. :key="item.key"
  88. :class="['ship-game-footer__item']"
  89. >
  90. <span>{{ item.label }}</span>
  91. </div>
  92. </div>
  93. </template>
  94. <video
  95. v-if="showVideo"
  96. class="video"
  97. autoplay
  98. src="@/assets/videos/ship-game/end.mp4"
  99. @ended="back"
  100. />
  101. </div>
  102. </template>
  103. <script setup>
  104. import { ref, watch } from 'vue'
  105. import { useRouter } from 'vue-router'
  106. import { Container, Draggable } from "vue3-smooth-dnd"
  107. const router = useRouter()
  108. const showBanner = ref(true)
  109. const showVideo = ref(false)
  110. const MODULE_LIST = [
  111. {
  112. label: '甲板',
  113. img: require('@/assets/images/ship-game/jiaban-min.png'),
  114. imgWidth: '252px',
  115. hightImg: require('@/assets/images/ship-game//highlight_Deck-min.png'),
  116. hightImgStyle: 'right: 18px; bottom: 46px; width: 985px; height: 88px;',
  117. key: 'jiaban'
  118. },
  119. {
  120. label: '船底',
  121. img: require('@/assets/images/ship-game/di-min.png'),
  122. imgWidth: '261px',
  123. hightImg: require('@/assets/images/ship-game/highlight_Bilge-min.png'),
  124. hightImgStyle: 'right: 43px; bottom: 1px; width: 950px; height: 88px;',
  125. key: 'chuandi'
  126. },
  127. {
  128. label: '船舱',
  129. img: require('@/assets/images/ship-game/chuanxiang-min.png'),
  130. imgWidth: '166px',
  131. hightImg: require('@/assets/images/ship-game/highlight_Cabin-min.png'),
  132. hightImgStyle: 'left: 322px; bottom: 70px; z-index: 2; width: 223px; height: 155px;',
  133. key: 'chuancang'
  134. },
  135. {
  136. label: '船舵',
  137. img: require('@/assets/images/ship-game/duo-min.png'),
  138. imgWidth: '203px',
  139. hightImg: require('@/assets/images/ship-game/highlight_hoods-min.png'),
  140. hightImgStyle: 'left: 22px; bottom: 53px; z-index: 2; width: 272px; height: 107px;',
  141. key: 'chuanduo'
  142. },
  143. {
  144. label: '船篷',
  145. img: require('@/assets/images/ship-game/peng-min.png'),
  146. imgWidth: '104px',
  147. hightImg: require('@/assets/images/ship-game/highlight_ship-min.png'),
  148. hightImgStyle: 'left: 198px; bottom: 81px; z-index: 2; width: 158px; height: 146px;',
  149. key: 'chuanpeng'
  150. },
  151. {
  152. label: '桅杆',
  153. img: require('@/assets/images/ship-game/gan-min.png'),
  154. imgWidth: '206px',
  155. hightImg: require('@/assets/images/ship-game/highlight_Mast-min.png'),
  156. hightImgStyle: 'left: 200px; top: 0; z-index: 2; width: 806px; height: 509px;',
  157. key: 'weigan'
  158. }
  159. ]
  160. const curDragKey = ref('')
  161. const checkedModule = ref([])
  162. watch(checkedModule, val => {
  163. if (val.length === 6) {
  164. setTimeout(() => {
  165. showVideo.value = true
  166. }, 200)
  167. }
  168. }, {
  169. deep: true
  170. })
  171. const back = () => {
  172. router.back()
  173. }
  174. </script>
  175. <style lang="less" scoped>
  176. .drag-class {
  177. width: auto !important;
  178. }
  179. .ship-game {
  180. height: 100vh;
  181. background: #F3EAE3;
  182. .close {
  183. position: absolute;
  184. top: 52px;
  185. right: 58px;
  186. cursor: pointer;
  187. z-index: 8;
  188. }
  189. .video {
  190. position: absolute;
  191. top: 0;
  192. left: 0;
  193. right: 0;
  194. bottom: 0;
  195. z-index: 9;
  196. }
  197. &-container {
  198. position: absolute;
  199. top: 40px;
  200. left: 50%;
  201. width: 1144px;
  202. height: 611px;
  203. transform: translateX(-50%);
  204. background: url('@/assets/images/ship-game/bg-boat-min.png') no-repeat center / cover;
  205. .img {
  206. position: absolute;
  207. transition: all linear .2s;
  208. }
  209. }
  210. .logo2 {
  211. position: absolute;
  212. top: 76px;
  213. left: 62px;
  214. width: 460px;
  215. }
  216. .tips {
  217. position: absolute;
  218. top: 212px;
  219. left: 94px;
  220. width: 300px;
  221. font-size: 22px;
  222. color: #2E5A89;
  223. line-height: 37px;
  224. user-select: none;
  225. }
  226. &-footer {
  227. position: fixed;
  228. left: 0;
  229. right: 0;
  230. bottom: 0;
  231. display: flex;
  232. gap: 18px;
  233. padding: 18px;
  234. background: #AEAEAE;
  235. z-index: 1;
  236. &.drag {
  237. background: transparent;
  238. z-index: 2;
  239. .ship-game-footer__item {
  240. background: transparent;
  241. }
  242. }
  243. &__item {
  244. flex: 1;
  245. display: flex !important;
  246. align-items: center;
  247. justify-content: center;
  248. position: relative;
  249. padding: 19px;
  250. height: 182px;
  251. border-radius: 10px;
  252. box-sizing: border-box;
  253. background: #524B4B;
  254. &.checked {
  255. user-select: none;
  256. &::before {
  257. content: '';
  258. position: absolute;
  259. top: 0;
  260. left: 0;
  261. right: 0;
  262. bottom: 0;
  263. background: rgba(255, 255, 255, .3);
  264. z-index: 1;
  265. }
  266. }
  267. .icon {
  268. position: absolute;
  269. top: 9px;
  270. right: 13px;
  271. width: 45px;
  272. height: 45px;
  273. background: url('@/assets/images/ship-game/Frame-min.png') no-repeat center / cover;
  274. z-index: 2;
  275. }
  276. img {
  277. width: 100%;
  278. cursor: pointer;
  279. }
  280. span {
  281. position: absolute;
  282. left: 21px;
  283. bottom: 9px;
  284. color: white;
  285. font-size: 22px;
  286. }
  287. }
  288. }
  289. &-banner {
  290. position: absolute;
  291. top: 0;
  292. left: 0;
  293. display: flex;
  294. flex-direction: column;
  295. align-items: center;
  296. justify-content: center;
  297. width: 100vw;
  298. height: 100vh;
  299. background: url("@/assets/images/ship-game/bg_-min.png") no-repeat center /
  300. cover;
  301. z-index: 5;
  302. p {
  303. padding: 20px 0 120px;
  304. width: 714px;
  305. font-size: 22px;
  306. color: #2e5a89;
  307. line-height: 37px;
  308. text-align: center;
  309. }
  310. button {
  311. width: 90px;
  312. height: 40px;
  313. line-height: 40px;
  314. border-radius: 5px;
  315. color: #f3eae3;
  316. font-size: 26px;
  317. background: #2e5a89;
  318. }
  319. }
  320. }
  321. </style>