手机号注册手机号登录

This commit is contained in:
Songsl 2026-05-09 10:47:10 +08:00
parent 8d2350f231
commit 5e8f91c3bb
4 changed files with 132 additions and 67 deletions

View File

@ -85,6 +85,11 @@ const formData = ref({
api_url: '',
api_appid: '',
api_key: '',
beneficiary_name: '',
beneficiary_bank_name: '',
swift_bic_code: '',
beneficiary_bank_address: '',
channel_code: '',
status: 1,
})
const formItems = ref(formItemsData)
@ -116,6 +121,11 @@ const resetFormData = () => {
api_appid: '',
api_key: '',
status: 1,
beneficiary_name: '',
beneficiary_bank_name: '',
swift_bic_code: '',
beneficiary_bank_address: '',
channel_code: '',
}
}
@ -130,20 +140,12 @@ const handleEdit = () => {
dialogVisible.value = true
dialogTitleType.value = 2
formData.value = {
id: currentRow.id,
name: currentRow.name,
channel_fee: currentRow.channel_fee,
type: currentRow.type,
api_url: currentRow.api_url,
api_appid: currentRow.api_appid,
api_key: currentRow.api_key,
status: currentRow.status,
}
formData.value = currentRow
}
const handleDelete = () => {
console.log('handleDisable')
if (!currentRow.id) return ElMessage.warning('请先选择要删除的记录')
ElMessageBox.confirm('确认删除吗?', '提示', {
type: 'warning',
confirmButtonText: '确定',

View File

@ -34,6 +34,31 @@ export const formItemsData = [
{ label: '接口地址', prop: 'api_url', type: 'input', placeholder: '请输入接口地址' },
{ label: '接口appid', prop: 'api_appid', type: 'input', placeholder: '请输入接口appid' },
{ label: '接口密钥', prop: 'api_key', type: 'input', placeholder: '请输入接口密钥' },
{
label: '账户持有人姓名',
prop: 'beneficiary_name',
type: 'input',
placeholder: '请输入账户持有人姓名',
},
{
label: '银行名称',
prop: 'beneficiary_bank_name',
type: 'input',
placeholder: '请输入银行名称',
},
{
label: '银行识别代码',
prop: 'swift_bic_code',
type: 'input',
placeholder: '请输入银行识别代码',
},
{
label: '银行地址',
prop: 'beneficiary_bank_address',
type: 'input',
placeholder: '请输入银行地址',
},
{ label: '渠道编码', prop: 'channel_code', type: 'input', placeholder: '请输入渠道编码' },
{ label: '状态', prop: 'status', type: 'radio' },
]
@ -45,6 +70,11 @@ export const formRulesData = {
api_appid: [{ required: true, message: '请输入接口appid', trigger: ['change'] }],
api_key: [{ required: true, message: '请输入接口密钥', trigger: ['change'] }],
status: [{ required: true, message: '请选择状态', trigger: ['change'] }],
beneficiary_name: [{ required: true, message: '请输入账户持有人姓名', trigger: ['change'] }],
beneficiary_bank_name: [{ required: true, message: '请输入银行名称', trigger: ['change'] }],
swift_bic_code: [{ required: true, message: '请输入银行识别代码', trigger: ['change'] }],
beneficiary_bank_address: [{ required: true, message: '请输入银行地址', trigger: ['change'] }],
channel_code: [{ required: true, message: '请输入渠道编码', trigger: ['change'] }],
}
export const optionsMapData = {

View File

@ -1,5 +1,5 @@
<template>
<div class="user-card" >
<div class="user-card">
<UserHeader />
<UserText :user-text="userText" @back="handleBack" />
<UserTabs v-model="activeTab" :hide-tab="hideTab" :tab-list="tabList" />
@ -10,9 +10,25 @@
<el-input v-model="loginForm.email" placeholder="请输入邮箱" clearable size="large" />
</el-form-item>
<el-form-item class="phone-item" prop="phone" v-else-if="activeTab === 'phone'" key="form-phone-item">
<el-select v-model="loginForm.countryCode" :teleported="false" value-key="code" placeholder="国家" size="large">
<el-option v-for="item in countryOptions" :key="item.code" :label="item.code" :value="item.code">
<el-form-item
class="phone-item"
prop="phone"
v-else-if="activeTab === 'phone'"
key="form-phone-item"
>
<el-select
v-model="loginForm.countryCode"
:teleported="false"
value-key="code"
placeholder="国家"
size="large"
>
<el-option
v-for="item in countryOptions"
:key="item.code"
:label="item.code"
:value="item.code"
>
<div class="country-option">
<span class="country-name">{{ item.name }}</span>
<span class="country-code">{{ item.code }}</span>
@ -23,13 +39,21 @@
</el-form-item>
<el-form-item v-else-if="activeTab === 'password'" key="form-password-item" prop="password">
<el-input v-model="loginForm.password" placeholder="请输入密码" type="password" show-password clearable
size="large" />
<el-input
v-model="loginForm.password"
placeholder="请输入密码"
type="password"
show-password
clearable
size="large"
/>
<router-link to="/user/forgot-password" class="forgot-password">忘记密码</router-link>
</el-form-item>
</Transition>
<el-form-item class="form-submit">
<el-button type="primary" @click="handleLogin">{{ activeTab === 'password' ? '登录' : '注册/登录' }}</el-button>
<el-button type="primary" @click="handleLogin">{{
activeTab === 'password' ? '登录' : '注册/登录'
}}</el-button>
</el-form-item>
</el-form>
</div>
@ -58,7 +82,6 @@ const userText = ref({
title: '',
text: '初次登录时,您的电子邮箱或手机号码将被用于注册。',
account: '',
})
//tabs
@ -70,7 +93,7 @@ const activeTab = ref<string>('email')
const hideTab = ref<boolean>(false)
// login form
const userStore = useUserStore();
const userStore = useUserStore()
const loginFormRef = ref<FormInstance>()
const loginForm = ref({
email: '',
@ -94,39 +117,44 @@ const loginRules = ref<FormRules>({
*/
function generateTimestampWithRandomNum() {
// 1.
const timestamp = Date.now();
const timestamp = Date.now()
// 2. 6000000 ~ 999999
// Math.random()0~1100000060
const random6Num = Math.floor(Math.random() * 1000000).toString().padStart(6, '0');
const random6Num = Math.floor(Math.random() * 1000000)
.toString()
.padStart(6, '0')
// 3.
return timestamp + random6Num;
return timestamp + random6Num
}
//
const handleLogin = async () => {
if (!loginFormRef.value) return;
if (!loginFormRef.value) return
try {
const currentTab = activeTab.value;
const currentTab = activeTab.value
///
if (currentTab === 'email' || currentTab === 'phone') {
//email/phone
await loginFormRef.value.validateField(currentTab);
await loginFormRef.value.validateField(currentTab)
//便
const loginValue = loginForm.value[currentTab];
setStorage('loginType', currentTab, 'session'); // email/phone
setStorage('login', loginValue, 'session'); //
const loginValue =
currentTab === 'phone'
? loginForm.value.countryCode + loginForm.value[currentTab]
: loginForm.value[currentTab]
setStorage('loginType', currentTab, 'session') // email/phone
setStorage('login', loginValue, 'session') //
//
hideTab.value = true;
hideTab.value = true
userText.value = {
backText: '返回',
title: '欢迎回来!',
text: '请输入您的登录密码',
account: loginValue
};
activeTab.value = 'password';
account: loginValue,
}
activeTab.value = 'password'
if (currentTab === 'phone' && loginForm.value.email !== '') {
loginForm.value.email = ''
@ -135,32 +163,33 @@ const handleLogin = async () => {
// +
else if (currentTab === 'password') {
// +
await loginFormRef.value.validateField(['password', 'code']);
// device_no1
const deviceNo = generateTimestampWithRandomNum();
await loginFormRef.value.validateField(['password', 'code'])
// device_no1
const deviceNo = generateTimestampWithRandomNum()
//
const loginParams = {
email: loginForm.value.email,
mobile: loginForm.value.phone,
mobile: loginForm.value.countryCode + loginForm.value.phone,
login_type: getStorage('loginType', 'session') === 'email' ? 1 : 2,
code: loginForm.value.code,
password: loginForm.value.password,
device_no: deviceNo
};
await userStore.login(loginParams);
setStorage('device_no', deviceNo);
activeTab.value = 'email'; // tab
hideTab.value = false;
loginForm.value = { //
device_no: deviceNo,
}
await userStore.login(loginParams)
setStorage('device_no', deviceNo)
activeTab.value = 'email' // tab
hideTab.value = false
loginForm.value = {
//
email: '',
countryCode: '+86',
phone: '',
password: '',
code: ''
};
code: '',
}
}
} catch (error) {
console.error('表单校验失败:', error);
console.error('表单校验失败:', error)
}
}
@ -168,30 +197,30 @@ const handleLogin = async () => {
const handleBack = () => {
if (activeTab.value === 'password') {
// sessionStoragepasswordkey
const loginType = getStorage('loginType', 'session') || 'email';
const loginType = getStorage('loginType', 'session') || 'email'
//
loginForm.value.password = '';
loginForm.value.code = '';
loginForm.value.password = ''
loginForm.value.code = ''
//
loginFormRef.value?.clearValidate(['password', 'code']);
loginFormRef.value?.clearValidate(['password', 'code'])
// tab
hideTab.value = false;
hideTab.value = false
userText.value = {
backText: '',
title: '',
text: '初次登录时,您的电子邮箱或手机号码将被用于注册。',
account: ''
};
activeTab.value = loginType as string;
account: '',
}
activeTab.value = loginType as string
} else {
// passwordemailtab
activeTab.value = 'email';
activeTab.value = 'email'
//
loginForm.value.email = '';
loginForm.value.phone = '';
loginFormRef.value?.clearValidate(['email', 'phone']);
loginForm.value.email = ''
loginForm.value.phone = ''
loginFormRef.value?.clearValidate(['email', 'phone'])
}
};
}
</script>
<style scoped lang="scss">

View File

@ -170,7 +170,8 @@ const sendCodeApi = async () => {
//
const sendParams = {
email: registerForm.value.email,
mobile: registerForm.value.phone,
mobile: registerForm.value.countryCode + registerForm.value.phone,
mobile_area: registerForm.value.countryCode,
reg_type: activeTab.value === 'email' ? 1 : 2,
type: 'reg_code',
}
@ -188,10 +189,13 @@ const handleSendCode = async () => {
//
const type: string = activeTab.value === 'phone' ? 'phone' : 'email'
const receiver = type === 'phone' ? registerForm.value.phone : registerForm.value.email
const receiver =
type === 'phone'
? registerForm.value.countryCode + registerForm.value.phone
: registerForm.value.email
const currentCaptchaState = type === 'phone' ? phoneCaptchaState : emailCaptchaState
const sendFunc = type === 'phone' ? 'sendPhoneCaptcha' : 'sendEmailCaptcha'
console.log('registerForm.countryCode', registerForm.value.countryCode)
//
await sendCaptcha(
type,
@ -211,7 +215,7 @@ const handleRegister = async () => {
//
const registerParams = {
email: registerForm.value.email,
mobile: registerForm.value.phone,
mobile: registerForm.value.countryCode + registerForm.value.phone,
reg_type: activeTab.value === 'email' ? 1 : 2,
invite_code: registerForm.value.inviteCode,
code: registerForm.value.code,
@ -230,8 +234,8 @@ onUnmounted(() => {
clearCaptchaTimer(phoneCaptchaState)
})
onMounted(()=>{
registerForm.value.inviteCode = route.query.invite_code
onMounted(() => {
registerForm.value.inviteCode = route.query.invite_code
})
</script>