fix: 批量修复功能问题 - 购物车结算/订单库存积分/搜索/抽奖/个人资料等
This commit is contained in:
@@ -418,7 +418,8 @@ async function handleCheckout() {
|
||||
try {
|
||||
await orderApi.create({
|
||||
shipping_address_id: selectedAddressId.value,
|
||||
payment_method: selectedPayment.value
|
||||
payment_method: selectedPayment.value,
|
||||
cart_item_ids: selectedIds.value
|
||||
})
|
||||
ElMessage.success('订单创建成功')
|
||||
await cartStore.fetchCart()
|
||||
|
||||
@@ -59,8 +59,8 @@
|
||||
<p>{{ l.description }}</p>
|
||||
</div>
|
||||
<div class="lottery-right">
|
||||
<span class="lottery-status" :class="l.status === 'active' ? 'active' : ''">
|
||||
{{ l.status === 'active' ? '进行中' : '已结束' }}
|
||||
<span class="lottery-status" :class="l.is_active ? 'active' : ''">
|
||||
{{ l.is_active ? '进行中' : '已结束' }}
|
||||
</span>
|
||||
<button class="lottery-btn">参与</button>
|
||||
</div>
|
||||
@@ -99,7 +99,7 @@
|
||||
</div>
|
||||
<div class="category-info">
|
||||
<h3>{{ cat.name }}</h3>
|
||||
<p>{{ cat.product_count || 0 }} 件商品</p>
|
||||
<p>{{ cat.description || '精选好物' }}</p>
|
||||
</div>
|
||||
<el-icon class="category-arrow"><ArrowRight /></el-icon>
|
||||
</div>
|
||||
|
||||
@@ -30,9 +30,9 @@ const route = useRoute()
|
||||
const lottery = ref<any>(null)
|
||||
|
||||
const prizeTypeMap: Record<string, string> = {
|
||||
product: '商品',
|
||||
credits: '积分',
|
||||
cash: '现金',
|
||||
physical: '实物',
|
||||
virtual: '虚拟',
|
||||
credit: '积分',
|
||||
}
|
||||
function prizeTypeText(t: string) { return prizeTypeMap[t] || t }
|
||||
|
||||
|
||||
@@ -19,19 +19,95 @@
|
||||
<el-button @click="$router.push('/orders')">我的订单</el-button>
|
||||
<el-button v-if="user.role === 'admin'" type="primary" @click="$router.push('/admin')">管理后台</el-button>
|
||||
<el-button v-if="user.role === 'supplier'" type="primary" @click="$router.push('/supplier')">供应商后台</el-button>
|
||||
<el-button type="warning" @click="showEditProfile = true">编辑资料</el-button>
|
||||
<el-button type="danger" @click="showChangePassword = true">修改密码</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="showEditProfile" title="编辑资料" width="400px">
|
||||
<el-form :model="profileForm" label-width="80px">
|
||||
<el-form-item label="用户名"><el-input v-model="profileForm.username" /></el-form-item>
|
||||
<el-form-item label="邮箱"><el-input v-model="profileForm.email" /></el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="showEditProfile = false">取消</el-button>
|
||||
<el-button type="primary" @click="saveProfile" :loading="saving">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="showChangePassword" title="修改密码" width="400px">
|
||||
<el-form :model="passwordForm" label-width="80px">
|
||||
<el-form-item label="旧密码"><el-input v-model="passwordForm.old_password" type="password" show-password /></el-form-item>
|
||||
<el-form-item label="新密码"><el-input v-model="passwordForm.new_password" type="password" show-password /></el-form-item>
|
||||
<el-form-item label="确认密码"><el-input v-model="passwordForm.confirm_password" type="password" show-password /></el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="showChangePassword = false">取消</el-button>
|
||||
<el-button type="primary" @click="changePassword" :loading="saving">确认修改</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted } from 'vue'
|
||||
import { computed, onMounted, ref, reactive, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useUserStore } from '../../store/user'
|
||||
import { userApi } from '../../api'
|
||||
import BackNav from '../../components/BackNav.vue'
|
||||
|
||||
const userStore = useUserStore()
|
||||
const user = computed(() => userStore.user)
|
||||
|
||||
const showEditProfile = ref(false)
|
||||
const showChangePassword = ref(false)
|
||||
const saving = ref(false)
|
||||
const profileForm = reactive({ username: '', email: '' })
|
||||
const passwordForm = reactive({ old_password: '', new_password: '', confirm_password: '' })
|
||||
|
||||
watch(() => userStore.user, (u) => {
|
||||
if (u) {
|
||||
profileForm.username = u.username || ''
|
||||
profileForm.email = u.email || ''
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
async function saveProfile() {
|
||||
saving.value = true
|
||||
try {
|
||||
await userApi.updateProfile(profileForm)
|
||||
ElMessage.success('资料已更新')
|
||||
showEditProfile.value = false
|
||||
await userStore.fetchProfile()
|
||||
} catch (err: any) {
|
||||
ElMessage.error(err.response?.data?.error || '更新失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function changePassword() {
|
||||
if (passwordForm.new_password !== passwordForm.confirm_password) {
|
||||
ElMessage.warning('两次密码不一致')
|
||||
return
|
||||
}
|
||||
if (passwordForm.new_password.length < 6) {
|
||||
ElMessage.warning('密码至少6位')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
await userApi.changePassword({ old_password: passwordForm.old_password, new_password: passwordForm.new_password })
|
||||
ElMessage.success('密码已修改')
|
||||
showChangePassword.value = false
|
||||
Object.assign(passwordForm, { old_password: '', new_password: '', confirm_password: '' })
|
||||
} catch (err: any) {
|
||||
ElMessage.error(err.response?.data?.error || '修改失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const roleMap: Record<string, string> = {
|
||||
admin: '管理员',
|
||||
supplier: '供应商',
|
||||
|
||||
Reference in New Issue
Block a user