This commit is contained in:
2026-04-27 14:48:54 +08:00
parent 739e08157b
commit 893a223e0e
28 changed files with 828 additions and 634 deletions

View File

@@ -1,17 +1,17 @@
<script setup>
import { computed, nextTick, onUnmounted, ref } from 'vue'
import { useDialogStore } from '@/stores/dialogStore'
import { useAgentStore } from '@/stores/agentStore'
import { useUserStore } from '@/stores/userStore'
import { setAuthSession } from '@/utils/storage'
const emit = defineEmits(['login-success'])
const dialogStore = useDialogStore()
const userStore = useUserStore()
const agentStore = useAgentStore()
const phoneNumber = ref('')
const verificationCode = ref('')
const password = ref('')
const isPasswordLogin = ref(false)
const isAgreed = ref(false)
const isCountingDown = ref(false)
const countdown = ref(60)
@@ -34,12 +34,7 @@ const isPhoneNumberValid = computed(() => {
const canLogin = computed(() => {
if (!isPhoneNumberValid.value)
return false
if (isPasswordLogin.value) {
return password.value.length >= 6
}
else {
return verificationCode.value.length === 6
}
return verificationCode.value.length === 6
})
async function sendVerificationCode() {
@@ -83,17 +78,9 @@ async function handleLogin() {
showToast({ message: '请输入有效的手机号' })
return
}
if (isPasswordLogin.value) {
if (password.value.length < 6) {
showToast({ message: '密码长度不能小于6位' })
return
}
}
else {
if (verificationCode.value.length !== 6) {
showToast({ message: '请输入有效的验证码' })
return
}
if (verificationCode.value.length !== 6) {
showToast({ message: '请输入有效的验证码' })
return
}
if (!isAgreed.value) {
showToast({ message: '请先同意用户协议' })
@@ -114,6 +101,7 @@ async function performLogin() {
setAuthSession(data.value.data)
await userStore.fetchUserInfo()
await agentStore.fetchAgentStatus()
showToast({ message: '登录成功' })
closeDialog()
@@ -123,6 +111,9 @@ async function performLogin() {
showToast(data.value.msg)
}
}
else {
showToast({ message: '登录失败' })
}
}
finally {
uni.hideLoading()
@@ -133,8 +124,6 @@ function closeDialog() {
dialogStore.closeLogin()
phoneNumber.value = ''
verificationCode.value = ''
password.value = ''
isPasswordLogin.value = false
isAgreed.value = false
isCountingDown.value = false
countdown.value = 60
@@ -203,7 +192,7 @@ onUnmounted(() => {
/>
</view>
<view v-if="!isPasswordLogin" class="form-item">
<view class="form-item">
<text class="form-label">
验证码
</text>
@@ -232,27 +221,6 @@ onUnmounted(() => {
</view>
</view>
<view v-else class="form-item">
<text class="form-label">
密码
</text>
<wd-input
v-model="password"
class="phone-wd-input"
type="text"
show-password
placeholder="请输入密码"
no-border
clearable
/>
</view>
<view class="flex items-center justify-end py-1">
<text class="switch-login-type" @click="isPasswordLogin = !isPasswordLogin">
{{ isPasswordLogin ? '验证码登录' : '密码登录' }}
</text>
</view>
<view class="agreement-wrapper">
<wd-checkbox v-model="isAgreed" shape="square" size="18px" />
<text class="agreement-text">
@@ -393,8 +361,4 @@ onUnmounted(() => {
letter-spacing: 0.25rem;
}
.switch-login-type {
font-size: 0.875rem;
color: #2563eb;
}
</style>

View File

@@ -1,4 +1,6 @@
<script setup>
import { calculatePromotionPricing, safeTruncate } from '@/utils/promotionPricing'
const props = defineProps({
defaultPrice: {
type: Number,
@@ -34,33 +36,12 @@ watch(show, (visible) => {
price.value = Number(defaultPrice.value || 0)
})
const costPrice = computed(() => {
if (!productConfig.value)
return 0.00
// 平台定价成本
let platformPricing = 0
platformPricing += productConfig.value.cost_price
if (price.value > productConfig.value.p_pricing_standard) {
platformPricing += (price.value - productConfig.value.p_pricing_standard) * productConfig.value.p_overpricing_ratio
}
if (productConfig.value.a_pricing_standard > platformPricing && productConfig.value.a_pricing_end > platformPricing && productConfig.value.a_overpricing_ratio > 0) {
if (price.value > productConfig.value.a_pricing_standard) {
if (price.value > productConfig.value.a_pricing_end) {
platformPricing += (productConfig.value.a_pricing_end - productConfig.value.a_pricing_standard) * productConfig.value.a_overpricing_ratio
}
else {
platformPricing += (price.value - productConfig.value.a_pricing_standard) * productConfig.value.a_overpricing_ratio
}
}
}
return safeTruncate(platformPricing)
const pricingResult = computed(() => {
return calculatePromotionPricing(price.value, productConfig.value)
})
const promotionRevenue = computed(() => {
return safeTruncate(price.value - costPrice.value)
})
const costPrice = computed(() => pricingResult.value.costPrice)
const promotionRevenue = computed(() => pricingResult.value.promotionRevenue)
/** APP 端 placeholder 需用原生 style否则字号易偏小 */
const PRICE_PLACEHOLDER_STYLE = 'color:#9ca3af;font-size:40rpx;font-weight:500;'
@@ -107,16 +88,6 @@ function validatePrice(currentPrice) {
}
return { newPrice, message }
}
function safeTruncate(num, decimals = 2) {
if (Number.isNaN(num) || !Number.isFinite(num))
return '0.00'
const factor = 10 ** decimals
const scaled = Math.trunc(num * factor)
const truncated = scaled / factor
return truncated.toFixed(decimals)
}
const isManualConfirm = ref(false)
function onConfirm() {
if (!hasProductConfig.value) {