ShipGameView.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. @touchstart="() => {
  73. curDragKey = item.key
  74. }"
  75. >
  76. <img
  77. draggable="false"
  78. :src="item.img"
  79. :style="{width: item.imgWidth}"
  80. >
  81. <div
  82. v-if="checkedModule.includes(item.key)"
  83. class="icon"
  84. />
  85. </Draggable>
  86. </Container>
  87. <div class="ship-game-footer">
  88. <div
  89. v-for="item in MODULE_LIST"
  90. :key="item.key"
  91. :class="['ship-game-footer__item']"
  92. >
  93. <span>{{ item.label }}</span>
  94. </div>
  95. </div>
  96. </template>
  97. <video
  98. v-if="showVideo"
  99. class="video"
  100. autoplay
  101. src="@/assets/videos/ship-game/end.mp4"
  102. @ended="back"
  103. />
  104. </div>
  105. </template>
  106. <script setup>
  107. import { ref, watch } from 'vue'
  108. // import { useRouter } from 'vue-router'
  109. import { Container, Draggable } from "vue3-smooth-dnd"
  110. // const router = useRouter()
  111. const showBanner = ref(true)
  112. const showVideo = ref(false)
  113. const MODULE_LIST = [
  114. {
  115. label: '甲板',
  116. img: require('@/assets/images/ship-game/jiaban-min.png'),
  117. imgWidth: '252px',
  118. hightImg: require('@/assets/images/ship-game//highlight_Deck-min.png'),
  119. hightImgStyle: 'right: 18px; bottom: 46px; width: 985px; height: 88px;',
  120. key: 'jiaban'
  121. },
  122. {
  123. label: '船底',
  124. img: require('@/assets/images/ship-game/di-min.png'),
  125. imgWidth: '261px',
  126. hightImg: require('@/assets/images/ship-game/highlight_Bilge-min.png'),
  127. hightImgStyle: 'right: 43px; bottom: 1px; width: 950px; height: 88px;',
  128. key: 'chuandi'
  129. },
  130. {
  131. label: '船舱',
  132. img: require('@/assets/images/ship-game/chuanxiang-min.png'),
  133. imgWidth: '166px',
  134. hightImg: require('@/assets/images/ship-game/highlight_Cabin-min.png'),
  135. hightImgStyle: 'left: 322px; bottom: 70px; z-index: 2; width: 223px; height: 155px;',
  136. key: 'chuancang'
  137. },
  138. {
  139. label: '船舵',
  140. img: require('@/assets/images/ship-game/duo-min.png'),
  141. imgWidth: '203px',
  142. hightImg: require('@/assets/images/ship-game/highlight_hoods-min.png'),
  143. hightImgStyle: 'left: 22px; bottom: 53px; z-index: 2; width: 272px; height: 107px;',
  144. key: 'chuanduo'
  145. },
  146. {
  147. label: '船篷',
  148. img: require('@/assets/images/ship-game/peng-min.png'),
  149. imgWidth: '104px',
  150. hightImg: require('@/assets/images/ship-game/highlight_ship-min.png'),
  151. hightImgStyle: 'left: 198px; bottom: 81px; z-index: 2; width: 158px; height: 146px;',
  152. key: 'chuanpeng'
  153. },
  154. {
  155. label: '桅杆',
  156. img: require('@/assets/images/ship-game/gan-min.png'),
  157. imgWidth: '206px',
  158. hightImg: require('@/assets/images/ship-game/highlight_Mast-min.png'),
  159. hightImgStyle: 'left: 200px; top: 0; z-index: 2; width: 806px; height: 509px;',
  160. key: 'weigan'
  161. }
  162. ]
  163. const curDragKey = ref('')
  164. const checkedModule = ref([])
  165. const emits = defineEmits(['close'])
  166. watch(checkedModule, val => {
  167. if (val.length === 6) {
  168. setTimeout(() => {
  169. showVideo.value = true
  170. }, 200)
  171. }
  172. }, {
  173. deep: true
  174. })
  175. const back = () => {
  176. // router.back()
  177. emits('close')
  178. }
  179. </script>
  180. <style lang="less" scoped>
  181. .drag-class {
  182. width: auto !important;
  183. }
  184. .ship-game {
  185. height: 100vh;
  186. background: #F3EAE3;
  187. .close {
  188. position: absolute;
  189. top: 52px;
  190. right: 58px;
  191. cursor: pointer;
  192. z-index: 8;
  193. }
  194. .video {
  195. position: absolute;
  196. top: 0;
  197. left: 0;
  198. right: 0;
  199. bottom: 0;
  200. z-index: 9;
  201. }
  202. &-container {
  203. position: absolute;
  204. top: 40px;
  205. left: 50%;
  206. width: 1144px;
  207. height: 611px;
  208. transform: translateX(-50%);
  209. background: url('@/assets/images/ship-game/bg-boat-min.png') no-repeat center / cover;
  210. .img {
  211. position: absolute;
  212. transition: all linear .2s;
  213. }
  214. }
  215. .logo2 {
  216. position: absolute;
  217. top: 76px;
  218. left: 62px;
  219. width: 460px;
  220. }
  221. .tips {
  222. position: absolute;
  223. top: 212px;
  224. left: 94px;
  225. width: 300px;
  226. font-size: 22px;
  227. color: #2E5A89;
  228. line-height: 37px;
  229. user-select: none;
  230. }
  231. &-footer {
  232. position: fixed;
  233. left: 0;
  234. right: 0;
  235. bottom: 0;
  236. display: flex;
  237. gap: 18px;
  238. padding: 18px;
  239. background: #AEAEAE;
  240. z-index: 1;
  241. &.drag {
  242. background: transparent;
  243. z-index: 2;
  244. .ship-game-footer__item {
  245. background: transparent;
  246. }
  247. }
  248. &__item {
  249. flex: 1;
  250. display: flex !important;
  251. align-items: center;
  252. justify-content: center;
  253. position: relative;
  254. padding: 19px;
  255. height: 182px;
  256. border-radius: 10px;
  257. box-sizing: border-box;
  258. background: #524B4B;
  259. &.checked {
  260. user-select: none;
  261. &::before {
  262. content: '';
  263. position: absolute;
  264. top: 0;
  265. left: 0;
  266. right: 0;
  267. bottom: 0;
  268. background: rgba(255, 255, 255, .3);
  269. z-index: 1;
  270. }
  271. }
  272. .icon {
  273. position: absolute;
  274. top: 9px;
  275. right: 13px;
  276. width: 45px;
  277. height: 45px;
  278. background: url('@/assets/images/ship-game/Frame-min.png') no-repeat center / cover;
  279. z-index: 2;
  280. }
  281. img {
  282. width: 100%;
  283. cursor: pointer;
  284. }
  285. span {
  286. position: absolute;
  287. left: 21px;
  288. bottom: 9px;
  289. color: white;
  290. font-size: 22px;
  291. }
  292. }
  293. }
  294. &-banner {
  295. position: absolute;
  296. top: 0;
  297. left: 0;
  298. display: flex;
  299. flex-direction: column;
  300. align-items: center;
  301. justify-content: center;
  302. width: 100vw;
  303. height: 100vh;
  304. background: url("@/assets/images/ship-game/bg_-min.png") no-repeat center /
  305. cover;
  306. z-index: 5;
  307. p {
  308. padding: 20px 0 120px;
  309. width: 714px;
  310. font-size: 22px;
  311. color: #2e5a89;
  312. line-height: 37px;
  313. text-align: center;
  314. }
  315. button {
  316. width: 90px;
  317. height: 40px;
  318. line-height: 40px;
  319. border-radius: 5px;
  320. color: #f3eae3;
  321. font-size: 26px;
  322. background: #2e5a89;
  323. }
  324. }
  325. }
  326. </style>