123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <template>
- <custom-dialog :visible.sync="dialogVisible" title="商店" @close="onClose">
- <view class="shop-content">
- <view class="shop-tabs">
- <view
- v-for="(tab, index) in tabs"
- :key="index"
- class="tab-item"
- :class="{'active': currentTab === index}"
- @click="currentTab = index"
- >
- {{tab}}
- </view>
- </view>
- <view class="shop-items">
- <view class="shop-item" v-for="(item, index) in currentItems" :key="index" @click="onItemClick(item)">
- <image class="item-icon" :src="item.icon" mode="aspectFit"></image>
- <view class="item-info">
- <text class="item-name">{{item.name}}</text>
- <text class="item-desc">{{item.description}}</text>
- </view>
- <view class="item-price">
- <image class="currency-icon" src="/static/currency/coin.png" mode="aspectFit"></image>
- <text>{{item.price}}</text>
- </view>
- </view>
- </view>
- </view>
- </custom-dialog>
- </template>
- <script>
- import CustomDialog from '../CustomDialog/CustomDialog.vue'
- export default {
- name: 'ShopDialog',
- components: {
- CustomDialog
- },
- props: {
- visible: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- dialogVisible: false,
- currentTab: 0,
- tabs: ['道具', '装备', '材料'],
- items: {
- 0: [
- { icon: '/static/items/potion1.png', name: '生命药水', description: '恢复100点生命值', price: 100 },
- { icon: '/static/items/potion2.png', name: '魔法药水', description: '恢复50点魔法值', price: 150 },
- { icon: '/static/items/potion3.png', name: '体力药水', description: '恢复50点体力值', price: 120 }
- ],
- 1: [
- { icon: '/static/items/weapon1.png', name: '铁剑', description: '攻击力+10', price: 500 },
- { icon: '/static/items/armor1.png', name: '皮甲', description: '防御力+5', price: 300 }
- ],
- 2: [
- { icon: '/static/items/material1.png', name: '木材', description: '基础材料', price: 50 },
- { icon: '/static/items/material2.png', name: '铁矿', description: '基础材料', price: 80 }
- ]
- }
- }
- },
- computed: {
- currentItems() {
- return this.items[this.currentTab]
- }
- },
- watch: {
- visible(val) {
- this.dialogVisible = val
- },
- dialogVisible(val) {
- this.$emit('update:visible', val)
- }
- },
- methods: {
- onClose() {
- this.dialogVisible = false
- },
- onItemClick(item) {
- // 处理购买逻辑
- this.$emit('buy', item)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .shop-content {
- .shop-tabs {
- display: flex;
- border-bottom: 2rpx solid #eee;
- margin-bottom: 20rpx;
- .tab-item {
- flex: 1;
- text-align: center;
- padding: 20rpx 0;
- font-size: 28rpx;
- color: #666;
- position: relative;
- &.active {
- color: #007AFF;
- font-weight: 500;
- &::after {
- content: '';
- position: absolute;
- bottom: 0;
- left: 50%;
- transform: translateX(-50%);
- width: 40rpx;
- height: 4rpx;
- background: #007AFF;
- border-radius: 2rpx;
- }
- }
- }
- }
- .shop-items {
- .shop-item {
- display: flex;
- align-items: center;
- padding: 20rpx;
- border-bottom: 2rpx solid #f5f5f5;
- .item-icon {
- width: 80rpx;
- height: 80rpx;
- margin-right: 20rpx;
- }
- .item-info {
- flex: 1;
- .item-name {
- font-size: 28rpx;
- color: #333;
- margin-bottom: 4rpx;
- }
- .item-desc {
- font-size: 24rpx;
- color: #999;
- }
- }
- .item-price {
- display: flex;
- align-items: center;
- gap: 8rpx;
- .currency-icon {
- width: 32rpx;
- height: 32rpx;
- }
- text {
- font-size: 28rpx;
- color: #FF9500;
- font-weight: 500;
- }
- }
- }
- }
- }
- </style>
|