功能:完善门店能力与用户安全配置

This commit is contained in:
xiaowang
2026-05-18 10:04:57 +08:00
parent 4563dd2538
commit 3797938616
356 changed files with 24983 additions and 1858 deletions
+150 -6
View File
@@ -245,6 +245,14 @@
</a-input-password>
</a-form-item>
<a-form-item v-if="activeTab === 'register'" name="inviteCode" label="邀请码">
<a-input
v-model:value="formData.inviteCode"
placeholder="可不填,不填默认归属所选店铺店长"
size="large"
/>
</a-form-item>
<a-form-item v-if="activeTab === 'register'" name="shopId" label="选择店铺">
<a-select
v-model:value="formData.shopId"
@@ -276,6 +284,15 @@
</div>
</a-form-item>
<a-form-item style="margin-bottom: 12px">
<a-checkbox v-model:checked="agreementAccepted">
我已阅读并同意
<a @click.stop.prevent="openAgreement('USER_TERMS')">《用户协议》</a>
和
<a @click.stop.prevent="openAgreement('PRIVACY_POLICY')">《隐私政策》</a>
</a-checkbox>
</a-form-item>
<a-form-item>
<a-button
type="primary"
@@ -283,6 +300,7 @@
size="large"
block
:loading="loading"
:disabled="!agreementAccepted"
>
{{ activeTab === 'login' ? '登录' : '注册' }}
</a-button>
@@ -380,16 +398,32 @@
</a-form-item>
</a-form>
</a-modal>
<a-modal
v-model:open="agreementModalOpen"
:title="selectedAgreement?.title || '协议内容'"
:footer="null"
width="90%"
>
<div class="agreement-content">
<div class="agreement-version">版本:{{ selectedAgreement?.version || '--' }}</div>
<pre>{{ selectedAgreement?.content || '暂无协议内容' }}</pre>
</div>
</a-modal>
</div>
</template>
<script setup lang="ts">
/**
* AuthView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { InfoCircleOutlined, LockOutlined, UserOutlined } from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import type { Rule } from 'ant-design-vue/es/form'
import { authApi } from '@/api/auth'
import { authApi, legalAgreementApi, type LegalAgreement } from '@/api/auth'
import { shopApi } from '@/api/shop'
import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
import { runWithGlobalLoading } from '@/utils/action-loading'
@@ -405,20 +439,32 @@ const router = useRouter()
const activeTab = ref<'login' | 'register'>('login')
const loginType = ref<'password' | 'phone'>('password')
/** loading is a reactive state variable used by the template and event handlers. */
const loading = ref(false)
/** loadingShops is a reactive state variable used by the template and event handlers. */
const loadingShops = ref(false)
const shops = ref<any[]>([])
const loginShops = ref<Array<{ id: IdType; shopName: string }>>([])
/** countdown is a reactive state variable used by the template and event handlers. */
const countdown = ref(0)
const loginAccountStatus = ref<LoginAccountCheckResponse | null>(null)
const registerAccountStatus = ref<AvailabilityCheckResponse | null>(null)
const registerPhoneStatus = ref<AvailabilityCheckResponse | null>(null)
/** loginShopMessage is a reactive state variable used by the template and event handlers. */
const loginShopMessage = ref('')
/** allowLoginShopless is a reactive state variable used by the template and event handlers. */
const allowLoginShopless = ref(false)
/** forgotPasswordVisible is a reactive state variable used by the template and event handlers. */
const forgotPasswordVisible = ref(false)
/** forgotCountdown is a reactive state variable used by the template and event handlers. */
const forgotCountdown = ref(0)
/** resettingPassword is a reactive state variable used by the template and event handlers. */
const resettingPassword = ref(false)
const agreementAccepted = ref(false)
const agreements = ref<LegalAgreement[]>([])
const agreementModalOpen = ref(false)
const selectedAgreement = ref<LegalAgreement | null>(null)
const forgotPasswordForm = reactive({
phone: '',
@@ -432,17 +478,32 @@ const formData = reactive({
confirmPassword: '',
nickname: '',
shopId: undefined as string | undefined,
inviteCode: '',
phone: '',
verificationCode: '',
rememberMe: false
})
const agreementVersions = computed<Record<string, string>>(() => {
return agreements.value.reduce((result, agreement) => {
result[agreement.agreementType] = agreement.version
return result
}, {} as Record<string, string>)
})
const agreementPayload = () => ({
agreementAccepted: agreementAccepted.value,
agreementVersions: agreementVersions.value,
clientType: 'WEB'
})
let loginAccountCheckTimer: number | undefined
let loginPhoneShopCheckTimer: number | undefined
const phoneRegex = /^1[3-9]\d{9}$/
const verificationCodeRegex = /^\d{6}$/
const loginShopUnsupportedMessage = '可直接登录;如账号绑定多家门店,登录后可在个人中心切换当前门店。'
/** loginShopPlaceholder is a reactive state variable used by the template and event handlers. */
const loginShopPlaceholder = computed(() => {
if (allowLoginShopless.value) {
return '当前暂无启用店铺,可直接登录'
@@ -453,6 +514,7 @@ const loginShopPlaceholder = computed(() => {
return loginShops.value.length ? '请选择登录店铺' : '请先输入账号或手机号'
})
/** validateLoginShopRequired is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const validateLoginShopRequired = async () => {
if (allowLoginShopless.value || !loginShops.value.length || formData.shopId) {
return Promise.resolve()
@@ -460,6 +522,7 @@ const validateLoginShopRequired = async () => {
return Promise.reject('请选择登录店铺')
}
/** validatePassword is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const validatePassword = async (_rule: Rule, value: string) => {
if (!value || value.length < 6) {
return Promise.reject('密码长度不能少于 6 位')
@@ -478,6 +541,7 @@ const validatePassword = async (_rule: Rule, value: string) => {
return Promise.resolve()
}
/** validateConfirmPassword is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const validateConfirmPassword = async (_rule: Rule, value: string) => {
if (!value) {
return Promise.reject('请确认密码')
@@ -488,6 +552,7 @@ const validateConfirmPassword = async (_rule: Rule, value: string) => {
return Promise.resolve()
}
/** handleAccountInput is a local helper used by this page script. */
const handleAccountInput = () => {
const normalized = sanitizeAccountInput(formData.account)
if (normalized !== formData.account) {
@@ -574,6 +639,7 @@ const currentRules = computed<Record<string, Rule[]>>(() => {
return loginType.value === 'phone' ? loginPhoneRules : loginPasswordRules
})
/** fetchShops is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const fetchShops = async () => {
loadingShops.value = true
try {
@@ -587,6 +653,7 @@ const fetchShops = async () => {
}
}
/** resetLoginAccountStatus is a local helper used by this page script. */
const resetLoginAccountStatus = () => {
if (loginAccountCheckTimer !== undefined) {
window.clearTimeout(loginAccountCheckTimer)
@@ -595,6 +662,7 @@ const resetLoginAccountStatus = () => {
loginAccountStatus.value = null
}
/** resetPhoneLoginShopCheck is a local helper used by this page script. */
const resetPhoneLoginShopCheck = () => {
if (loginPhoneShopCheckTimer !== undefined) {
window.clearTimeout(loginPhoneShopCheckTimer)
@@ -602,6 +670,7 @@ const resetPhoneLoginShopCheck = () => {
}
}
/** resetLoginShopState is a local helper used by this page script. */
const resetLoginShopState = (clearSelectedShop = activeTab.value === 'login') => {
resetPhoneLoginShopCheck()
loginShops.value = []
@@ -612,6 +681,7 @@ const resetLoginShopState = (clearSelectedShop = activeTab.value === 'login') =>
}
}
/** normalizeShopOptionValue is a local helper used by this page script. */
const normalizeShopOptionValue = (shopId?: string | number | null) => {
if (shopId === undefined || shopId === null || shopId === '') {
return undefined
@@ -619,11 +689,13 @@ const normalizeShopOptionValue = (shopId?: string | number | null) => {
return String(shopId)
}
/** isLoginShopPrefetchUnsupported is a local helper used by this page script. */
const isLoginShopPrefetchUnsupported = (error: unknown) => {
const status = (error as any)?.response?.status
return status === 404
}
/** applyLoginShopSelection is a local helper used by this page script. */
const applyLoginShopSelection = (selection?: LoginShopSelectionResponse | null) => {
loginShops.value = selection?.shops || []
allowLoginShopless.value = Boolean(selection?.allowShoplessLogin)
@@ -657,6 +729,7 @@ const applyLoginShopSelection = (selection?: LoginShopSelectionResponse | null)
formData.shopId = undefined
}
/** loadLoginShopsByAccount is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadLoginShopsByAccount = async (account = formData.account) => {
const trimmedAccount = account.trim()
if (activeTab.value !== 'login' || loginType.value !== 'password' || !trimmedAccount) {
@@ -693,6 +766,7 @@ const loadLoginShopsByAccount = async (account = formData.account) => {
}
}
/** loadLoginShopsByPhone is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadLoginShopsByPhone = async (phone = formData.phone) => {
const trimmedPhone = phone.trim()
if (activeTab.value !== 'login' || loginType.value !== 'phone' || !phoneRegex.test(trimmedPhone)) {
@@ -729,6 +803,7 @@ const loadLoginShopsByPhone = async (phone = formData.phone) => {
}
}
/** checkLoginAccountAvailability is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const checkLoginAccountAvailability = async (account = formData.account) => {
const trimmedAccount = account.trim()
if (activeTab.value !== 'login' || loginType.value !== 'password' || !trimmedAccount) {
@@ -755,6 +830,7 @@ const checkLoginAccountAvailability = async (account = formData.account) => {
}
}
/** checkRegisterAccountAvailability is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const checkRegisterAccountAvailability = async (showWarning = true) => {
const trimmedAccount = formData.account.trim()
if (activeTab.value !== 'register' || !trimmedAccount) {
@@ -770,6 +846,7 @@ const checkRegisterAccountAvailability = async (showWarning = true) => {
return response.available
}
/** checkRegisterPhoneAvailability is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const checkRegisterPhoneAvailability = async (showWarning = true) => {
const trimmedPhone = formData.phone.trim()
if (activeTab.value !== 'register' || !trimmedPhone) {
@@ -785,7 +862,36 @@ const checkRegisterPhoneAvailability = async (showWarning = true) => {
return response.available
}
const loadAgreements = async () => {
try {
agreements.value = await legalAgreementApi.listCurrent() as unknown as LegalAgreement[]
} catch (error) {
console.error('加载协议失败:', error)
message.warning('协议内容加载失败,请稍后重试')
}
}
const openAgreement = async (type: 'USER_TERMS' | 'PRIVACY_POLICY') => {
const cached = agreements.value.find(item => item.agreementType === type)
if (cached) {
selectedAgreement.value = cached
agreementModalOpen.value = true
return
}
selectedAgreement.value = await legalAgreementApi.getCurrent(type) as unknown as LegalAgreement
agreementModalOpen.value = true
}
/** handleSubmit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleSubmit = async () => {
if (!agreementAccepted.value) {
message.warning('请先阅读并同意用户协议和隐私政策')
return
}
if (!agreementVersions.value.USER_TERMS || !agreementVersions.value.PRIVACY_POLICY) {
message.warning('协议内容未加载完成,请稍后再试')
return
}
loading.value = true
try {
await runWithGlobalLoading(async () => {
@@ -796,14 +902,16 @@ const handleSubmit = async () => {
response = await authApi.phoneLogin({
phone: formData.phone,
verificationCode: formData.verificationCode,
shopId: formData.shopId
shopId: formData.shopId,
...agreementPayload()
})
} else {
response = await authApi.login({
account: formData.account,
password: formData.password,
rememberMe: formData.rememberMe,
shopId: formData.shopId
shopId: formData.shopId,
...agreementPayload()
})
}
@@ -846,7 +954,9 @@ const handleSubmit = async () => {
nickname: formData.nickname,
phone: formData.phone,
verificationCode: formData.verificationCode,
shopId: formData.shopId!
shopId: formData.shopId!,
inviteCode: formData.inviteCode,
...agreementPayload()
})
message.success('注册成功,请登录')
@@ -865,10 +975,12 @@ const handleSubmit = async () => {
}
}
/** handleForgotPassword is a local helper used by this page script. */
const handleForgotPassword = () => {
forgotPasswordVisible.value = true
}
/** handleSendForgotCode is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleSendForgotCode = async () => {
if (!forgotPasswordForm.phone) {
message.error('请输入手机号')
@@ -880,7 +992,10 @@ const handleSendForgotCode = async () => {
}
try {
await runWithGlobalLoading(() => authApi.sendVerificationCode({ phone: forgotPasswordForm.phone }))
await runWithGlobalLoading(() => authApi.sendVerificationCode({
phone: forgotPasswordForm.phone,
sceneCode: 'USER_RESET_PASSWORD_SMS_CODE'
}))
message.success('验证码已发送')
forgotCountdown.value = 60
const timer = window.setInterval(() => {
@@ -894,6 +1009,7 @@ const handleSendForgotCode = async () => {
}
}
/** handleResetPassword is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleResetPassword = async () => {
resettingPassword.value = true
try {
@@ -914,6 +1030,7 @@ const handleResetPassword = async () => {
}
}
/** handleRegisterAccountBlur is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleRegisterAccountBlur = async () => {
if (activeTab.value !== 'register' || !formData.account.trim()) {
registerAccountStatus.value = null
@@ -928,6 +1045,7 @@ const handleRegisterAccountBlur = async () => {
}
}
/** handleRegisterPhoneBlur is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleRegisterPhoneBlur = async () => {
if (activeTab.value !== 'register' || !formData.phone.trim()) {
registerPhoneStatus.value = null
@@ -946,6 +1064,7 @@ const handleRegisterPhoneBlur = async () => {
}
}
/** handleSendVerificationCode is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleSendVerificationCode = async () => {
if (!formData.phone) {
message.error('请输入手机号')
@@ -965,7 +1084,10 @@ const handleSendVerificationCode = async () => {
}
}
await runWithGlobalLoading(() => userApi.sendVerificationCode({ phone: formData.phone }))
await runWithGlobalLoading(() => userApi.sendVerificationCode({
phone: formData.phone,
sceneCode: activeTab.value === 'register' ? 'USER_REGISTER_SMS_CODE' : 'USER_LOGIN_SMS_CODE'
}))
message.success('验证码已发送')
countdown.value = 60
const timer = window.setInterval(() => {
@@ -979,6 +1101,7 @@ const handleSendVerificationCode = async () => {
}
}
/** handleAdminLogin is a local helper used by this page script. */
const handleAdminLogin = () => {
localStorage.removeItem('accessToken')
localStorage.removeItem('refreshToken')
@@ -1058,6 +1181,7 @@ watch(
onMounted(() => {
fetchShops()
loadAgreements()
})
onBeforeUnmount(() => {
@@ -1258,4 +1382,24 @@ onBeforeUnmount(() => {
display: flex;
align-items: center;
}
.agreement-content {
max-height: 60vh;
overflow: auto;
}
.agreement-version {
margin-bottom: 12px;
color: #8c8c8c;
font-size: 13px;
}
.agreement-content pre {
white-space: pre-wrap;
word-break: break-word;
margin: 0;
font-family: inherit;
line-height: 1.7;
color: #333;
}
</style>