CraftingDialog.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <view class="crafting-dialog" v-if="visible" @click.stop>
  3. <view class="dialog-mask" @click="onClose"></view>
  4. <view class="dialog-content" :class="{ 'slide-up': visible }">
  5. <!-- 顶部标题栏 -->
  6. <view class="dialog-header">
  7. <text class="title">初级工具台</text>
  8. <!-- <view class="close-btn" @click="onClose">×</view> -->
  9. </view>
  10. <!-- 制造台内容 -->
  11. <view class="dialog-body">
  12. <view class="crafting-content">
  13. <!-- 工具格子列表 -->
  14. <scroll-view
  15. class="tools-scroll"
  16. scroll-x="true"
  17. :scroll-left="scrollLeft"
  18. @scroll="onScroll"
  19. @touchstart.native="onTouchStart"
  20. @touchmove.native="onTouchMove"
  21. @touchend.native="onTouchEnd"
  22. :scroll-with-animation="true"
  23. :enhanced="true"
  24. :show-scrollbar="false"
  25. :bounces="false"
  26. >
  27. <view class="tools-grid" @touchstart.stop="onTouchStart" @touchmove.stop="onTouchMove" @touchend.stop="onTouchEnd">
  28. <view
  29. v-for="(tool, index) in tools"
  30. :key="index"
  31. class="tool-item"
  32. :class="{ 'selected': selectedToolIndex === index }"
  33. @click="selectTool(index)"
  34. >
  35. <image :src="tool.image" mode="aspectFit" class="tool-image"></image>
  36. <text class="tool-name">{{ tool.name }}</text>
  37. </view>
  38. </view>
  39. </scroll-view>
  40. <!-- 选中工具的详情 -->
  41. <view class="tool-details" v-if="selectedTool">
  42. <text class="tool-description">{{ selectedTool.description }}</text>
  43. <view class="materials-row">
  44. <view class="materials">
  45. <view v-for="(cost, index) in selectedTool.costs" :key="index" class="material-item">
  46. <image :src="index === 0 ? '/static/island/items/item_wood1.png' : index === 1 ? '/static/island/items/item_mine1.png' : '/static/island/UI/wd_icon_xingyuan.png'" mode="aspectFit" class="material-icon"></image>
  47. <text class="material-count">{{ cost }}</text>
  48. </view>
  49. </view>
  50. <view class="craft-btn" @click="onCraft">打造</view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. export default {
  60. name: 'CraftingDialog',
  61. props: {
  62. visible: {
  63. type: Boolean,
  64. default: false
  65. }
  66. },
  67. data() {
  68. return {
  69. selectedToolIndex: 0,
  70. scrollLeft: 0,
  71. startX: 0,
  72. lastX: 0,
  73. isDragging: false,
  74. tools: [
  75. {
  76. name: '捕虫网',
  77. image: '/static/island/items/item_bugnet1.png',
  78. description: '可以让你用来捕捉大虫',
  79. costs: [2000, 800, 920]
  80. },
  81. {
  82. name: '石镐',
  83. image: '/static/island/items/item_stonepickaxe1.png',
  84. description: '用来挖掘矿石',
  85. costs: [2000, 8000, 1300]
  86. },
  87. {
  88. name: '铲子',
  89. image: '/static/island/items/item_shovel1.png',
  90. description: '用来挖掘地面',
  91. costs: [3000, 7200, 2600]
  92. },
  93. {
  94. name: '斧子',
  95. image: '/static/island/items/item_axe1.png',
  96. description: '用来砍伐树木',
  97. costs: [5500, 10000, 5800]
  98. }
  99. ]
  100. }
  101. },
  102. computed: {
  103. selectedTool() {
  104. return this.tools[this.selectedToolIndex]
  105. }
  106. },
  107. methods: {
  108. onClose() {
  109. this.$emit('close')
  110. },
  111. selectTool(index) {
  112. this.selectedToolIndex = index
  113. },
  114. onCraft() {
  115. // TODO: 实现制造逻辑
  116. uni.showToast({
  117. title: `正在制造${this.selectedTool.name}`,
  118. icon: 'none'
  119. })
  120. },
  121. onScroll(e) {
  122. console.log('滚动事件:', {
  123. scrollLeft: e.detail.scrollLeft
  124. });
  125. this.scrollLeft = e.detail.scrollLeft;
  126. },
  127. onTouchStart(e) {
  128. console.log('触摸开始:', {
  129. clientX: e.touches[0].clientX,
  130. pageX: e.touches[0].pageX,
  131. screenX: e.touches[0].screenX,
  132. target: e.target
  133. });
  134. this.startX = e.touches[0].clientX;
  135. this.isDragging = true;
  136. e.preventDefault && e.preventDefault();
  137. },
  138. onTouchMove(e) {
  139. if (!this.isDragging) return;
  140. const currentX = e.touches[0].clientX;
  141. const deltaX = this.startX - currentX;
  142. console.log('触摸移动:', {
  143. currentX,
  144. startX: this.startX,
  145. deltaX,
  146. scrollLeft: this.scrollLeft,
  147. target: e.target
  148. });
  149. this.scrollLeft += deltaX;
  150. this.startX = currentX;
  151. e.preventDefault && e.preventDefault();
  152. },
  153. onTouchEnd(e) {
  154. console.log('触摸结束:', {
  155. finalScrollLeft: this.scrollLeft,
  156. target: e.target
  157. });
  158. this.isDragging = false;
  159. e.preventDefault && e.preventDefault();
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang="scss" scoped>
  165. .crafting-dialog {
  166. position: fixed;
  167. top: 0;
  168. left: 0;
  169. right: 0;
  170. bottom: 0;
  171. z-index: 1000;
  172. .dialog-mask {
  173. position: absolute;
  174. top: 0;
  175. left: 0;
  176. right: 0;
  177. bottom: 0;
  178. background: rgba(0, 0, 0, 0.5);
  179. }
  180. .dialog-content {
  181. position: absolute;
  182. left: 0;
  183. right: 0;
  184. bottom: 0;
  185. background: #E79D5E;
  186. box-shadow: inset 0rpx 4rpx 4rpx 0rpx rgba(255,190,134,0.3);
  187. border-radius: 20rpx 20rpx 0rpx 0rpx;
  188. transform: translateY(100%);
  189. transition: transform 0.3s ease-out;
  190. &.slide-up {
  191. transform: translateY(0);
  192. }
  193. }
  194. .dialog-header {
  195. display: flex;
  196. justify-content: space-between;
  197. align-items: center;
  198. margin-bottom: 32rpx;
  199. height: 72rpx;
  200. width: 220rpx;
  201. background: #FDDEC1;
  202. box-shadow: inset 0rpx 4rpx 4rpx 0rpx rgba(255,190,134,0.3);
  203. border-radius: 20rpx 20rpx 0rpx 0rpx;
  204. .title {
  205. font-size: 36rpx;
  206. font-weight: bold;
  207. padding-left: 20rpx;
  208. color: #A95F3C;
  209. }
  210. .close-btn {
  211. font-size: 48rpx;
  212. color: #999;
  213. padding: 0 20rpx;
  214. }
  215. }
  216. .dialog-body {
  217. background: #FDDEC1;
  218. margin-top: -32rpx;
  219. }
  220. .crafting-content {
  221. padding-bottom: 32rpx;
  222. .tools-scroll {
  223. width: 100%;
  224. white-space: nowrap;
  225. // margin-bottom: 32rpx;
  226. .tools-grid {
  227. display: flex;
  228. width: max-content;
  229. padding: 20rpx;
  230. .tool-item {
  231. width: 180rpx;
  232. height: 180rpx;
  233. flex-shrink: 0;
  234. margin-right: 20rpx;
  235. background: #FFF1E4;
  236. border-radius: 20rpx 20rpx 20rpx 20rpx;
  237. padding: 5rpx;
  238. text-align: center;
  239. border: 2rpx solid #DEB691;
  240. position: relative;
  241. display: flex;
  242. flex-direction: column;
  243. align-items: center;
  244. &:last-child {
  245. margin-right: 20rpx;
  246. }
  247. &.selected {
  248. border: 4rpx solid #84B654;
  249. background: #E8F5E9;
  250. }
  251. .tool-image {
  252. width: 178rpx;
  253. height: 178rpx;
  254. // margin: 2rpx;
  255. background: #FBD6A9;
  256. border-radius: 16rpx;
  257. // padding: 10rpx;
  258. box-sizing: border-box;
  259. }
  260. .tool-name {
  261. font-size: 28rpx;
  262. font-weight: bold;
  263. color:#A95F3C;
  264. white-space: normal;
  265. line-height: 1.2;
  266. width: 100%;
  267. padding: 12rpx 0;
  268. background: rgba(255, 255, 255, 0.8);
  269. position: absolute;
  270. bottom: 0;
  271. left: 0;
  272. right: 0;
  273. border-radius: 0 0 20rpx 20rpx;
  274. }
  275. }
  276. }
  277. }
  278. .tool-details {
  279. width: 694rpx;
  280. height: 170rpx;
  281. background: #FFF1E4;
  282. box-shadow: inset 0rpx 6rpx 0rpx 0rpx rgba(255,255,255,0.3), inset 0rpx -6rpx 0rpx 0rpx #F6E0CB, 0rpx 4rpx 4rpx 0rpx #F3D2B2;
  283. border-radius: 28rpx 28rpx 28rpx 28rpx;
  284. border: 2rpx solid #DEB691;
  285. margin: 0 auto;
  286. padding: 20rpx 30rpx;
  287. box-sizing: border-box;
  288. .tool-description {
  289. font-size: 28rpx;
  290. font-weight: bold;
  291. color: #A95F3C;
  292. margin-bottom: 16rpx;
  293. line-height: 1.4;
  294. }
  295. .materials-row {
  296. display: flex;
  297. justify-content: space-between;
  298. align-items: center;
  299. margin-top: 32rpx;
  300. }
  301. .materials {
  302. display: flex;
  303. gap: 32rpx;
  304. .material-item {
  305. display: flex;
  306. align-items: center;
  307. gap: 8rpx;
  308. .material-icon {
  309. width: 40rpx;
  310. height: 40rpx;
  311. }
  312. .material-count {
  313. font-size: 28rpx;
  314. color: #A95F3C;
  315. }
  316. }
  317. }
  318. .craft-btn {
  319. width: 144rpx;
  320. height: 53rpx;
  321. background: url('/static/island/UI/btn_green.png') no-repeat;
  322. background-size: 100% 100%;
  323. color: white;
  324. font-size: 28rpx;
  325. border: none;
  326. display: flex;
  327. align-items: center;
  328. justify-content: center;
  329. &:active {
  330. opacity: 0.9;
  331. }
  332. }
  333. }
  334. }
  335. }
  336. </style>