CraftingDialog.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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">{{ getToolDescription(selectedTool) }}</text>
  43. <view class="materials-row">
  44. <view class="materials">
  45. <view class="material-item">
  46. <image src="/static/island/items/item_wood1.png" mode="aspectFit" class="material-icon"></image>
  47. <text class="material-count">{{ selectedTool.price }}</text>
  48. </view>
  49. <view class="material-item">
  50. <image src="/static/island/items/item_mine1.png" mode="aspectFit" class="material-icon"></image>
  51. <text class="material-count">{{ selectedTool.limit_time }}</text>
  52. </view>
  53. <view class="material-item">
  54. <image src="/static/island/UI/wd_icon_xingyuan.png" mode="aspectFit" class="material-icon"></image>
  55. <text class="material-count">{{ selectedTool.num_out }}</text>
  56. </view>
  57. </view>
  58. <view class="craft-btn" @click="onCraft">打造</view>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. export default {
  68. name: 'CraftingDialog',
  69. props: {
  70. visible: {
  71. type: Boolean,
  72. default: false
  73. }
  74. },
  75. data() {
  76. return {
  77. selectedToolIndex: 0,
  78. scrollLeft: 0,
  79. startX: 0,
  80. lastX: 0,
  81. isDragging: false,
  82. tools: [],
  83. loading: false
  84. }
  85. },
  86. computed: {
  87. selectedTool() {
  88. return this.tools[this.selectedToolIndex]
  89. }
  90. },
  91. watch: {
  92. visible(val) {
  93. if (val) {
  94. this.fetchCraftingData()
  95. }
  96. }
  97. },
  98. methods: {
  99. onClose() {
  100. this.$emit('close')
  101. },
  102. selectTool(index) {
  103. this.selectedToolIndex = index
  104. },
  105. onCraft() {
  106. // TODO: 实现制造逻辑
  107. uni.showToast({
  108. title: `你的材料不足`,
  109. icon: 'none'
  110. })
  111. },
  112. onScroll(e) {
  113. console.log('滚动事件:', {
  114. scrollLeft: e.detail.scrollLeft
  115. });
  116. this.scrollLeft = e.detail.scrollLeft;
  117. },
  118. onTouchStart(e) {
  119. console.log('触摸开始:', {
  120. clientX: e.touches[0].clientX,
  121. pageX: e.touches[0].pageX,
  122. screenX: e.touches[0].screenX,
  123. target: e.target
  124. });
  125. this.startX = e.touches[0].clientX;
  126. this.isDragging = true;
  127. e.preventDefault && e.preventDefault();
  128. },
  129. onTouchMove(e) {
  130. if (!this.isDragging) return;
  131. const currentX = e.touches[0].clientX;
  132. const deltaX = this.startX - currentX;
  133. console.log('触摸移动:', {
  134. currentX,
  135. startX: this.startX,
  136. deltaX,
  137. scrollLeft: this.scrollLeft,
  138. target: e.target
  139. });
  140. this.scrollLeft += deltaX;
  141. this.startX = currentX;
  142. e.preventDefault && e.preventDefault();
  143. },
  144. onTouchEnd(e) {
  145. console.log('触摸结束:', {
  146. finalScrollLeft: this.scrollLeft,
  147. target: e.target
  148. });
  149. this.isDragging = false;
  150. e.preventDefault && e.preventDefault();
  151. },
  152. // 获取制造工具数据
  153. async fetchCraftingData() {
  154. if (this.loading) return
  155. this.loading = true
  156. try {
  157. uni.request({
  158. url: this.$apiHost + '/Game/get_crafting_list',
  159. method: 'GET',
  160. data: {
  161. uuid: getApp().globalData.uuid
  162. },
  163. header: {
  164. 'Content-Type': 'application/x-www-form-urlencoded',
  165. 'sign': getApp().globalData.headerSign,
  166. },
  167. success: (res) => {
  168. console.log("制造工具数据:", res.data)
  169. if (res.data && res.data.code === 0) {
  170. this.tools = res.data.list || []
  171. } else {
  172. uni.showToast({
  173. title: res.data?.msg || '获取制造工具数据失败',
  174. icon: 'none'
  175. })
  176. }
  177. },
  178. fail: (err) => {
  179. console.error('获取制造工具数据异常', err)
  180. uni.showToast({
  181. title: '网络异常,请重试',
  182. icon: 'none'
  183. })
  184. },
  185. complete: () => {
  186. this.loading = false
  187. }
  188. })
  189. } catch (error) {
  190. console.error('获取制造工具数据异常', error)
  191. uni.showToast({
  192. title: '网络异常,请重试',
  193. icon: 'none'
  194. })
  195. this.loading = false
  196. }
  197. },
  198. // 获取工具描述
  199. getToolDescription(tool) {
  200. if (!tool) return ''
  201. const descriptions = {
  202. 1: '可以让你用来捕捉大虫',
  203. 2: '用来挖掘矿石',
  204. 3: '用来挖掘地面',
  205. 4: '用来砍伐树木'
  206. }
  207. return descriptions[tool.id] || '工具描述'
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. .crafting-dialog {
  214. position: fixed;
  215. top: 0;
  216. left: 0;
  217. right: 0;
  218. bottom: 0;
  219. z-index: 1000;
  220. .dialog-mask {
  221. position: absolute;
  222. top: 0;
  223. left: 0;
  224. right: 0;
  225. bottom: 0;
  226. background: rgba(0, 0, 0, 0.5);
  227. }
  228. .dialog-content {
  229. position: absolute;
  230. left: 0;
  231. right: 0;
  232. bottom: 0;
  233. background: #E79D5E;
  234. box-shadow: inset 0rpx 4rpx 4rpx 0rpx rgba(255,190,134,0.3);
  235. border-radius: 20rpx 20rpx 0rpx 0rpx;
  236. transform: translateY(100%);
  237. transition: transform 0.3s ease-out;
  238. &.slide-up {
  239. transform: translateY(0);
  240. }
  241. }
  242. .dialog-header {
  243. display: flex;
  244. justify-content: space-between;
  245. align-items: center;
  246. margin-bottom: 32rpx;
  247. height: 72rpx;
  248. width: 220rpx;
  249. background: #FDDEC1;
  250. box-shadow: inset 0rpx 4rpx 4rpx 0rpx rgba(255,190,134,0.3);
  251. border-radius: 20rpx 20rpx 0rpx 0rpx;
  252. .title {
  253. font-size: 36rpx;
  254. font-weight: bold;
  255. padding-left: 20rpx;
  256. color: #A95F3C;
  257. }
  258. .close-btn {
  259. font-size: 48rpx;
  260. color: #999;
  261. padding: 0 20rpx;
  262. }
  263. }
  264. .dialog-body {
  265. background: #FDDEC1;
  266. margin-top: -32rpx;
  267. }
  268. .crafting-content {
  269. padding-bottom: 32rpx;
  270. .tools-scroll {
  271. width: 100%;
  272. white-space: nowrap;
  273. // margin-bottom: 32rpx;
  274. .tools-grid {
  275. display: flex;
  276. width: max-content;
  277. padding: 20rpx;
  278. .tool-item {
  279. width: 180rpx;
  280. height: 180rpx;
  281. flex-shrink: 0;
  282. margin-right: 20rpx;
  283. background: #FFF1E4;
  284. border-radius: 20rpx 20rpx 20rpx 20rpx;
  285. padding: 5rpx;
  286. text-align: center;
  287. border: 2rpx solid #DEB691;
  288. position: relative;
  289. display: flex;
  290. flex-direction: column;
  291. align-items: center;
  292. &:last-child {
  293. margin-right: 20rpx;
  294. }
  295. &.selected {
  296. border: 4rpx solid #84B654;
  297. background: #E8F5E9;
  298. }
  299. .tool-image {
  300. width: 178rpx;
  301. height: 178rpx;
  302. // margin: 2rpx;
  303. background: #FBD6A9;
  304. border-radius: 16rpx;
  305. // padding: 10rpx;
  306. box-sizing: border-box;
  307. }
  308. .tool-name {
  309. font-size: 28rpx;
  310. font-weight: bold;
  311. color:#A95F3C;
  312. white-space: normal;
  313. line-height: 1.2;
  314. width: 100%;
  315. padding: 12rpx 0;
  316. background: rgba(255, 255, 255, 0.8);
  317. position: absolute;
  318. bottom: 0;
  319. left: 0;
  320. right: 0;
  321. border-radius: 0 0 20rpx 20rpx;
  322. }
  323. }
  324. }
  325. }
  326. .tool-details {
  327. width: 694rpx;
  328. height: 170rpx;
  329. background: #FFF1E4;
  330. box-shadow: inset 0rpx 6rpx 0rpx 0rpx rgba(255,255,255,0.3), inset 0rpx -6rpx 0rpx 0rpx #F6E0CB, 0rpx 4rpx 4rpx 0rpx #F3D2B2;
  331. border-radius: 28rpx 28rpx 28rpx 28rpx;
  332. border: 2rpx solid #DEB691;
  333. margin: 0 auto;
  334. padding: 20rpx 30rpx;
  335. box-sizing: border-box;
  336. .tool-description {
  337. font-size: 28rpx;
  338. font-weight: bold;
  339. color: #A95F3C;
  340. margin-bottom: 16rpx;
  341. line-height: 1.4;
  342. }
  343. .materials-row {
  344. display: flex;
  345. justify-content: space-between;
  346. align-items: center;
  347. margin-top: 32rpx;
  348. }
  349. .materials {
  350. display: flex;
  351. gap: 32rpx;
  352. .material-item {
  353. display: flex;
  354. align-items: center;
  355. gap: 8rpx;
  356. .material-icon {
  357. width: 40rpx;
  358. height: 40rpx;
  359. }
  360. .material-count {
  361. font-size: 28rpx;
  362. color: #A95F3C;
  363. }
  364. }
  365. }
  366. .craft-btn {
  367. width: 144rpx;
  368. height: 53rpx;
  369. background: url('/static/island/UI/btn_green.png') no-repeat;
  370. background-size: 100% 100%;
  371. color: white;
  372. font-size: 28rpx;
  373. border: none;
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. &:active {
  378. opacity: 0.9;
  379. }
  380. }
  381. }
  382. }
  383. }
  384. </style>