fix: some
This commit is contained in:
425
src/views/agent-registration/index.vue
Normal file
425
src/views/agent-registration/index.vue
Normal file
@@ -0,0 +1,425 @@
|
||||
<template>
|
||||
<div class="agent-registration-page">
|
||||
<div class="register-card">
|
||||
<div class="register-header">
|
||||
<h1 class="register-title">代理扫码注册</h1>
|
||||
<p class="register-subtitle">填写资料提交后,审核结果将通过通知告知</p>
|
||||
</div>
|
||||
|
||||
<div v-if="submitted" class="register-result">
|
||||
<ElResult icon="success" title="提交成功" sub-title="待审批,审核结果将通知你">
|
||||
<template #extra>
|
||||
<ElButton type="primary" @click="handleFillAgain">重新填写</ElButton>
|
||||
</template>
|
||||
</ElResult>
|
||||
</div>
|
||||
|
||||
<ElForm
|
||||
v-else
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
label-position="top"
|
||||
size="large"
|
||||
class="register-form"
|
||||
>
|
||||
<div class="form-grid">
|
||||
<ElFormItem label="分销码" prop="distribution_code">
|
||||
<ElInput
|
||||
v-model="form.distribution_code"
|
||||
:disabled="lockedDistributionCode"
|
||||
placeholder="请输入分销码"
|
||||
maxlength="64"
|
||||
clearable
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="手机号" prop="phone">
|
||||
<ElInput v-model="form.phone" placeholder="请输入手机号" maxlength="11" clearable />
|
||||
</ElFormItem>
|
||||
</div>
|
||||
|
||||
<ElFormItem label="短信验证码" prop="code">
|
||||
<div class="code-row">
|
||||
<ElInput v-model="form.code" placeholder="请输入短信验证码" maxlength="6" />
|
||||
<ElButton :disabled="!canSendCode" :loading="sending" @click="handleSendCode">
|
||||
{{ countdownText }}
|
||||
</ElButton>
|
||||
</div>
|
||||
</ElFormItem>
|
||||
|
||||
<ElFormItem label="密码" prop="password">
|
||||
<ElInput
|
||||
v-model="form.password"
|
||||
type="password"
|
||||
show-password
|
||||
placeholder="请输入密码(8-32 位)"
|
||||
maxlength="32"
|
||||
/>
|
||||
<div class="strength-bar" :class="strengthClass">
|
||||
<i v-for="n in 3" :key="n" :class="{ active: passwordStrength >= n }" />
|
||||
</div>
|
||||
</ElFormItem>
|
||||
|
||||
<div class="form-grid">
|
||||
<ElFormItem label="店铺名称" prop="shop_name">
|
||||
<ElInput
|
||||
v-model="form.shop_name"
|
||||
:disabled="lockedShopName"
|
||||
placeholder="请输入店铺名称"
|
||||
maxlength="50"
|
||||
clearable
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="店铺编号" prop="shop_code">
|
||||
<ElInput
|
||||
v-model="form.shop_code"
|
||||
:disabled="lockedShopCode"
|
||||
placeholder="请输入店铺编号"
|
||||
maxlength="50"
|
||||
clearable
|
||||
/>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
|
||||
<ElFormItem label="用户名" prop="username">
|
||||
<ElInput v-model="form.username" placeholder="请输入登录用户名" maxlength="50" clearable />
|
||||
</ElFormItem>
|
||||
|
||||
<div class="form-grid">
|
||||
<ElFormItem label="联系人" prop="contact_name">
|
||||
<ElInput v-model="form.contact_name" placeholder="选填" maxlength="50" clearable />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="省市区">
|
||||
<ElCascader
|
||||
v-model="form.region"
|
||||
:options="regionOptions"
|
||||
placeholder="请选择省市区"
|
||||
clearable
|
||||
class="region-cascader"
|
||||
@change="handleRegionChange"
|
||||
/>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
|
||||
<ElFormItem label="详细地址" prop="address">
|
||||
<ElInput v-model="form.address" placeholder="选填,请输入详细地址" maxlength="200" clearable />
|
||||
</ElFormItem>
|
||||
|
||||
<ElButton
|
||||
type="primary"
|
||||
size="large"
|
||||
class="submit-btn"
|
||||
:loading="submitting"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
提交注册
|
||||
</ElButton>
|
||||
</ElForm>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, reactive, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { CascaderOption, CascaderValue, FormInstance, FormRules } from 'element-plus'
|
||||
import {
|
||||
AgentDistributionService,
|
||||
type AgentDistributionRegistrationParams
|
||||
} from '@/api/modules/agentDistribution'
|
||||
import { regionData } from '@/utils/constants/regionData'
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
const regionOptions = regionData as CascaderOption[]
|
||||
|
||||
interface RegisterForm {
|
||||
distribution_code: string
|
||||
phone: string
|
||||
code: string
|
||||
password: string
|
||||
shop_name: string
|
||||
shop_code: string
|
||||
username: string
|
||||
contact_name: string
|
||||
province: string
|
||||
city: string
|
||||
district: string
|
||||
address: string
|
||||
region: string[]
|
||||
}
|
||||
|
||||
const form = reactive<RegisterForm>({
|
||||
distribution_code: (route.query.distribution_code as string) || '',
|
||||
phone: '',
|
||||
code: '',
|
||||
password: '',
|
||||
shop_name: (route.query.shop_name as string) || '',
|
||||
shop_code: (route.query.shop_code as string) || '',
|
||||
username: '',
|
||||
contact_name: '',
|
||||
province: '',
|
||||
city: '',
|
||||
district: '',
|
||||
address: '',
|
||||
region: []
|
||||
})
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const submitted = ref(false)
|
||||
const sending = ref(false)
|
||||
const submitting = ref(false)
|
||||
const countdown = ref(0)
|
||||
let timer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
const rules: FormRules = {
|
||||
distribution_code: [{ required: true, message: '请输入分销码', trigger: 'blur' }],
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
|
||||
],
|
||||
code: [{ required: true, message: '请输入短信验证码', trigger: 'blur' }],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||
{ min: 8, max: 32, message: '密码长度为 8-32 位', trigger: 'blur' }
|
||||
],
|
||||
shop_name: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
|
||||
shop_code: [{ required: true, message: '请输入店铺编号', trigger: 'blur' }],
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const lockedDistributionCode = computed(() => !!route.query.distribution_code)
|
||||
const lockedShopName = computed(() => !!route.query.shop_name)
|
||||
const lockedShopCode = computed(() => !!route.query.shop_code)
|
||||
|
||||
const canSendCode = computed(() => countdown.value <= 0 && !sending.value)
|
||||
|
||||
const countdownText = computed(() =>
|
||||
countdown.value > 0 ? `${countdown.value}s 后重发` : '获取验证码'
|
||||
)
|
||||
|
||||
const startCountdown = () => {
|
||||
countdown.value = 60
|
||||
if (timer) clearInterval(timer)
|
||||
timer = setInterval(() => {
|
||||
countdown.value -= 1
|
||||
if (countdown.value <= 0 && timer) {
|
||||
clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
const handleSendCode = async () => {
|
||||
if (!/^1[3-9]\d{9}$/.test(form.phone)) {
|
||||
ElMessage.warning('请先输入正确的手机号')
|
||||
return
|
||||
}
|
||||
sending.value = true
|
||||
try {
|
||||
const res = await AgentDistributionService.sendCode({
|
||||
phone: form.phone,
|
||||
scene: 'bind_phone'
|
||||
})
|
||||
if (res.code === 0) {
|
||||
ElMessage.success('验证码已发送')
|
||||
startCountdown()
|
||||
}
|
||||
} catch {
|
||||
// 错误提示由请求层统一处理
|
||||
} finally {
|
||||
sending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const passwordStrength = computed(() => {
|
||||
const pwd = form.password
|
||||
if (!pwd) return 0
|
||||
let score = 0
|
||||
if (pwd.length >= 8) score += 1
|
||||
if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd)) score += 1
|
||||
if (/\d/.test(pwd)) score += 1
|
||||
if (/[^A-Za-z0-9]/.test(pwd)) score += 1
|
||||
if (score >= 4) return 3
|
||||
if (score >= 2) return 2
|
||||
return 1
|
||||
})
|
||||
|
||||
const strengthClass = computed(() => {
|
||||
const map = ['', 'is-weak', 'is-medium', 'is-strong']
|
||||
return map[passwordStrength.value] || ''
|
||||
})
|
||||
|
||||
const handleRegionChange = (value: CascaderValue | null | undefined) => {
|
||||
const parts = Array.isArray(value) ? value.map((item) => String(item)) : []
|
||||
form.province = parts[0] || ''
|
||||
form.city = parts[1] || ''
|
||||
form.district = parts[2] || ''
|
||||
}
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (!formRef.value) return
|
||||
formRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
submitting.value = true
|
||||
try {
|
||||
const params: AgentDistributionRegistrationParams = {
|
||||
distribution_code: form.distribution_code.trim(),
|
||||
phone: form.phone.trim(),
|
||||
code: form.code.trim(),
|
||||
password: form.password,
|
||||
shop_name: form.shop_name.trim(),
|
||||
shop_code: form.shop_code.trim(),
|
||||
username: form.username.trim()
|
||||
}
|
||||
if (form.contact_name.trim()) params.contact_name = form.contact_name.trim()
|
||||
if (form.province) params.province = form.province
|
||||
if (form.city) params.city = form.city
|
||||
if (form.district) params.district = form.district
|
||||
if (form.address.trim()) params.address = form.address.trim()
|
||||
|
||||
const res = await AgentDistributionService.registerAgent(params)
|
||||
if (res.code === 0) {
|
||||
submitted.value = true
|
||||
} else {
|
||||
ElMessage.error('分销码不可用')
|
||||
}
|
||||
} catch {
|
||||
ElMessage.error('分销码不可用')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const handleFillAgain = () => {
|
||||
submitted.value = false
|
||||
formRef.value?.resetFields()
|
||||
form.distribution_code = (route.query.distribution_code as string) || form.distribution_code
|
||||
form.shop_name = (route.query.shop_name as string) || form.shop_name
|
||||
form.shop_code = (route.query.shop_code as string) || form.shop_code
|
||||
form.code = ''
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (timer) clearInterval(timer)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.agent-registration-page {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
padding: 48px 16px 64px;
|
||||
box-sizing: border-box;
|
||||
background: linear-gradient(160deg, #eef3fb 0%, #f7f9fd 40%, #eef3fb 100%);
|
||||
|
||||
.register-card {
|
||||
width: 100%;
|
||||
max-width: 520px;
|
||||
padding: 36px 36px 28px;
|
||||
box-sizing: border-box;
|
||||
background: #fff;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 30px rgb(93 135 255 / 12%);
|
||||
}
|
||||
|
||||
.register-header {
|
||||
margin-bottom: 24px;
|
||||
text-align: center;
|
||||
|
||||
.register-title {
|
||||
margin: 0;
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
|
||||
.register-subtitle {
|
||||
margin: 8px 0 0;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0 16px;
|
||||
}
|
||||
|
||||
.code-row {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
width: 100%;
|
||||
|
||||
.el-input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.el-button {
|
||||
flex: 0 0 auto;
|
||||
width: 128px;
|
||||
}
|
||||
}
|
||||
|
||||
.strength-bar {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
margin-top: 8px;
|
||||
|
||||
i {
|
||||
flex: 1;
|
||||
height: 4px;
|
||||
border-radius: 2px;
|
||||
background: var(--el-border-color-lighter);
|
||||
transition: background-color 0.2s ease;
|
||||
|
||||
&.active {
|
||||
background: var(--el-color-warning);
|
||||
}
|
||||
}
|
||||
|
||||
&.is-strong i.active {
|
||||
background: var(--el-color-success);
|
||||
}
|
||||
|
||||
&.is-weak i.active {
|
||||
background: var(--el-color-danger);
|
||||
}
|
||||
}
|
||||
|
||||
.region-cascader {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
width: 100%;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.register-result {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 24px 12px 40px;
|
||||
|
||||
.register-card {
|
||||
padding: 24px 16px 20px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.code-row .el-button {
|
||||
width: 112px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user