InventoryDialog.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <custom-dialog :visible.sync="dialogVisible" title="背包" @close="onClose">
  3. <view class="inventory-content">
  4. <view class="inventory-grid">
  5. <view class="inventory-slot" v-for="(item, index) in items" :key="index">
  6. <image v-if="item" :src="item.icon" mode="aspectFit" class="item-icon"></image>
  7. <text v-if="item && item.count > 1" class="item-count">{{item.count}}</text>
  8. </view>
  9. </view>
  10. </view>
  11. </custom-dialog>
  12. </template>
  13. <script>
  14. import CustomDialog from '../CustomDialog/CustomDialog.vue'
  15. export default {
  16. name: 'InventoryDialog',
  17. components: {
  18. CustomDialog
  19. },
  20. props: {
  21. visible: {
  22. type: Boolean,
  23. default: false
  24. }
  25. },
  26. data() {
  27. return {
  28. dialogVisible: false,
  29. items: [
  30. { icon: '/static/items/item1.png', count: 1 },
  31. { icon: '/static/items/item2.png', count: 5 },
  32. null,
  33. null,
  34. null,
  35. null,
  36. null,
  37. null,
  38. null,
  39. null,
  40. null,
  41. null
  42. ]
  43. }
  44. },
  45. watch: {
  46. visible(val) {
  47. this.dialogVisible = val
  48. },
  49. dialogVisible(val) {
  50. this.$emit('update:visible', val)
  51. }
  52. },
  53. methods: {
  54. onClose() {
  55. this.dialogVisible = false
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .inventory-content {
  62. .inventory-grid {
  63. display: grid;
  64. grid-template-columns: repeat(4, 1fr);
  65. gap: 20rpx;
  66. padding: 20rpx;
  67. }
  68. .inventory-slot {
  69. position: relative;
  70. width: 120rpx;
  71. height: 120rpx;
  72. background: #f5f5f5;
  73. border-radius: 8rpx;
  74. display: flex;
  75. align-items: center;
  76. justify-content: center;
  77. border: 2rpx solid #eee;
  78. .item-icon {
  79. width: 80rpx;
  80. height: 80rpx;
  81. }
  82. .item-count {
  83. position: absolute;
  84. right: 4rpx;
  85. bottom: 4rpx;
  86. font-size: 24rpx;
  87. color: #666;
  88. background: rgba(255, 255, 255, 0.8);
  89. padding: 2rpx 6rpx;
  90. border-radius: 4rpx;
  91. }
  92. }
  93. }
  94. </style>