507 lines
16 KiB
Vue
507 lines
16 KiB
Vue
<template>
|
||
<div class="app-container">
|
||
<el-card v-loading="loadingName" class="mb-3">
|
||
<template #header>
|
||
<div class="card-header">
|
||
<span class="mr-1 text-[var(--el-text-color-secondary)]">实名认证</span>
|
||
<el-tooltip effect="dark" content="用于唱作音符提现" placement="right">
|
||
<el-icon><QuestionFilled /></el-icon>
|
||
</el-tooltip>
|
||
<el-tag class="ml-5" effect="dark" :type="nameTagType()">{{ nameTagStr() }}</el-tag>
|
||
</div>
|
||
</template>
|
||
<el-form
|
||
ref="nameFormRef"
|
||
:model="realNameInfo"
|
||
:rules="nameRules"
|
||
label-width="120px"
|
||
style="max-width: 600px"
|
||
size="large"
|
||
>
|
||
<el-form-item label="姓名/机构名称" prop="name">
|
||
<el-input
|
||
type="text"
|
||
autocomplete="off"
|
||
placeholder="请输入姓名/机构名称"
|
||
v-model="realNameInfo.name"
|
||
:disabled="nameState != 2"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="证件类型" prop="identityType">
|
||
<el-select
|
||
v-model="realNameInfo.identityType"
|
||
style="width: 150px"
|
||
placeholder="请选择证件类型"
|
||
:disabled="nameState != 2"
|
||
>
|
||
<el-option v-for="item in DocumentType" :key="item.value" :label="item.label" :value="item.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="证件号" prop="identityCard">
|
||
<el-input
|
||
type="text"
|
||
placeholder="请输入证件号"
|
||
v-model="realNameInfo.identityCard"
|
||
:disabled="nameState != 2"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="联系地址" prop="address">
|
||
<el-input
|
||
type="text"
|
||
placeholder="请输入详细的联系地址"
|
||
v-model="realNameInfo.address"
|
||
:disabled="nameState != 2"
|
||
/>
|
||
</el-form-item>
|
||
<div>
|
||
<el-form-item label="证件图片" prop="identityPic">
|
||
<div class="pictures">
|
||
<image-upload
|
||
v-model="picUrls"
|
||
ref="uploaderRef"
|
||
:limit="2"
|
||
:disabled="nameState != 2"
|
||
:data="{ prefix: '/File/User/Name/' }"
|
||
/>
|
||
<el-tooltip effect="dark" placement="left-start">
|
||
<template #content>
|
||
* 身份证扫描件请务必上传身份证正面和反面两张图片
|
||
<br />
|
||
* 经营单位请传营业执照扫描件(盖章页)
|
||
<br />
|
||
* 学生可传学生证扫描件或是户口本扫描件(盖章页)
|
||
<br />
|
||
* 军人可传士兵证扫描件(盖章页)
|
||
<br />
|
||
* 外国国籍可提交护照扫描件
|
||
<br />
|
||
* 有效证件也可用相机或手机拍摄上传,但要保证清晰
|
||
<br />
|
||
</template>
|
||
<el-icon :size="20" style="margin-left: 10px"><QuestionFilled /></el-icon>
|
||
</el-tooltip>
|
||
</div>
|
||
</el-form-item>
|
||
</div>
|
||
<el-form-item style="float: right">
|
||
<el-button type="primary" @click.prevent="summitNameForm">
|
||
{{ nameState == 2 ? "提交认证" : "修改信息" }}
|
||
</el-button>
|
||
<el-button type="info" @click="resetNameForm" :disabled="nameState != 2">清空</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
</el-card>
|
||
|
||
<el-card v-loading="loadingMail" class="mb-3">
|
||
<template #header>
|
||
<div class="flex flex-items-center">
|
||
<span class="mr-1 text-[var(--el-text-color-secondary)]">邮箱绑定</span>
|
||
<el-tooltip effect="dark" content="用于找回登录密码" placement="right">
|
||
<el-icon><QuestionFilled /></el-icon>
|
||
</el-tooltip>
|
||
<el-tag class="ml-5" effect="dark" :type="mailTagType()">{{ mailTagStr() }}</el-tag>
|
||
</div>
|
||
</template>
|
||
|
||
<el-form
|
||
ref="mailFormRef"
|
||
:model="mailForm"
|
||
:rules="mailRules"
|
||
label-width="120px"
|
||
style="max-width: 600px"
|
||
size="large"
|
||
>
|
||
<el-form-item label="邮箱地址" prop="email">
|
||
<el-input type="text" placeholder="请输入邮箱地址" v-model="mailForm.email" :disabled="mailStep == 2" />
|
||
</el-form-item>
|
||
<el-form-item label="验证码" prop="code" v-if="mailStep < 2">
|
||
<div class="flex-inline">
|
||
<el-input type="text" placeholder="请输入验证码" v-model.number="mailForm.code" style="width: 150px" />
|
||
<div class="ml-2">
|
||
<SendCodeButton
|
||
ref="sendMCButtonRef"
|
||
@sendCodeClick="sendMailCode"
|
||
@updateCaptcha="handleMailCaptchaData"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</el-form-item>
|
||
<el-form-item style="float: right">
|
||
<el-button type="primary" @click.prevent="summitMailForm">
|
||
{{ mailStep == 2 ? "修改邮箱" : "提交绑定" }}
|
||
</el-button>
|
||
<el-button type="info" @click="resetMailForm" :disabled="mailStep == 2">清空</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
</el-card>
|
||
|
||
<el-card v-loading="loadingCell">
|
||
<template #header>
|
||
<div class="flex flex-items-center">
|
||
<span class="mr-1 text-[var(--el-text-color-secondary)]">手机绑定</span>
|
||
<el-tooltip effect="dark" content="用于找回登录密码" placement="right">
|
||
<el-icon><QuestionFilled /></el-icon>
|
||
</el-tooltip>
|
||
<el-tag class="ml-5" effect="dark" :type="cellTagType()">{{ cellTagStr() }}</el-tag>
|
||
</div>
|
||
</template>
|
||
<el-form
|
||
ref="cellFormRef"
|
||
:model="cellForm"
|
||
:rules="cellRules"
|
||
label-width="120px"
|
||
style="max-width: 600px"
|
||
size="large"
|
||
>
|
||
<el-form-item label="手机号" prop="mobile">
|
||
<el-input type="text" placeholder="请输入手机号" v-model.number="cellForm.mobile" :disabled="cellStep == 2" />
|
||
</el-form-item>
|
||
<el-form-item label="验证码" prop="code" v-if="cellStep < 2">
|
||
<el-input type="text" placeholder="请输入验证码" v-model.number="cellForm.code" style="width: 150px" />
|
||
<div class="ml-2">
|
||
<SendCodeButton
|
||
ref="sendPCButtonRef"
|
||
@sendCodeClick="sendCellCode"
|
||
@updateCaptcha="handleCellCaptchaData"
|
||
/>
|
||
</div>
|
||
</el-form-item>
|
||
<el-form-item style="float: right">
|
||
<el-button type="primary" @click.prevent="summitCellForm">
|
||
{{ cellStep == 2 ? "修改手机" : "提交绑定" }}
|
||
</el-button>
|
||
<el-button type="info" @click="resetCellForm" :disabled="cellStep == 2">清空</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
</el-card>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import UserAPI, { EmailBindingForm, MobileBindingForm, RealNameInfo } from "@/api/user";
|
||
import { useUserStore } from "@/store";
|
||
import { FormRules } from "element-plus";
|
||
import ImageUpload from "@/components/Upload/ImageUpload.vue";
|
||
import { DocumentType } from "@/enums/DocumentTypeEnum";
|
||
import { BASE_NAME_URL } from "@/utils/baseurls";
|
||
import { isPhone } from "@/utils";
|
||
import { CaptchaData, SendCodeData } from "@/api/auth";
|
||
|
||
const userStore = useUserStore();
|
||
const loadingName = ref(false);
|
||
const loadingMail = ref(false);
|
||
const loadingCell = ref(false);
|
||
|
||
const nameState = ref(userStore.account.isName);
|
||
const nameFormRef = ref();
|
||
const realNameInfo = reactive<RealNameInfo>({});
|
||
|
||
const nameRules = reactive<FormRules<typeof realNameInfo>>({
|
||
name: [{ required: true, message: "请输入姓名/机构名称", trigger: "blur" }],
|
||
identityType: [{ required: true, message: "请选择证件类型", trigger: "blur", type: "number" }],
|
||
identityCard: [{ required: true, message: "请输入证件号码", trigger: "blur" }],
|
||
address: [{ required: true, message: "请输入详细的联系地址", trigger: "blur" }],
|
||
identityPic: [{ required: true, message: "请选择证件图片", validator: validateIdentyPic }],
|
||
});
|
||
|
||
function validateIdentyPic(rule: any, value: string, callback: any) {
|
||
if (!picUrls.value || picUrls.value.length == 0) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
function nameTagType() {
|
||
switch (realNameInfo.isName) {
|
||
case 1:
|
||
return "success";
|
||
case 3:
|
||
return "warning";
|
||
default:
|
||
return "info";
|
||
}
|
||
}
|
||
|
||
function nameTagStr() {
|
||
switch (realNameInfo.isName) {
|
||
case 1:
|
||
return "已认证";
|
||
case 3:
|
||
return "认证中";
|
||
default:
|
||
return "未认证";
|
||
}
|
||
}
|
||
|
||
let picUrls = ref<string[]>([]);
|
||
const uploaderRef = ref();
|
||
|
||
function summitNameForm() {
|
||
if (nameState.value != 2) {
|
||
nameState.value = 2;
|
||
return;
|
||
}
|
||
|
||
nameFormRef.value.validate(async (valid: any) => {
|
||
if (valid) {
|
||
ElMessageBox.confirm("确认提交数据进行实名认证?", "", {
|
||
confirmButtonText: "确定",
|
||
cancelButtonText: "取消",
|
||
type: "info",
|
||
}).then(async function () {
|
||
loadingName.value = true;
|
||
|
||
//先上传图片
|
||
const res = await uploaderRef.value.handleSubmit("user-name");
|
||
if (res) {
|
||
realNameInfo.identityPic = "";
|
||
picUrls.value.forEach((pic) => {
|
||
if (realNameInfo.identityPic) realNameInfo.identityPic += ",";
|
||
realNameInfo.identityPic += pic.substring(16);
|
||
});
|
||
} else {
|
||
ElMessage.error("图片上传失败,请稍后重试");
|
||
loadingName.value = false;
|
||
return;
|
||
}
|
||
|
||
UserAPI.updateRealNameInfo(realNameInfo)
|
||
.then((data) => {
|
||
userStore.account.name = realNameInfo.name;
|
||
userStore.account.isName = realNameInfo.isName = 3;
|
||
nameState.value = 3;
|
||
|
||
ElMessage.success("实名认证提交成功,请等待审核");
|
||
})
|
||
.finally(() => {
|
||
loadingName.value = false;
|
||
});
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
function resetNameForm() {
|
||
nameFormRef.value.resetFields();
|
||
picUrls.value = [];
|
||
}
|
||
|
||
const mailStep = ref(0);
|
||
const mailFormRef = ref();
|
||
const mailForm = reactive<EmailBindingForm>({
|
||
email: "",
|
||
code: "",
|
||
});
|
||
|
||
const sendMCButtonRef = ref();
|
||
|
||
const mailRules = reactive<FormRules<typeof mailForm>>({
|
||
email: [{ type: "email", required: true, message: "请输入正确的邮箱地址", trigger: "blur" }],
|
||
code: [{ type: "number", required: true, message: "请输入邮箱验证码", trigger: "blur" }],
|
||
});
|
||
|
||
function mailTagType() {
|
||
if (userStore.account.state == 2) return "success";
|
||
else return "info";
|
||
}
|
||
|
||
function mailTagStr() {
|
||
if (userStore.account.state == 2) return "已绑定";
|
||
else return "未绑定";
|
||
}
|
||
|
||
/** 获得防刷验证码后,正式请求绑定邮箱验证码 */
|
||
function handleMailCaptchaData(data: CaptchaData) {
|
||
loadingMail.value = true;
|
||
|
||
const sendData: SendCodeData = {
|
||
contact: mailForm.email!,
|
||
captchaKey: data.captchaKey,
|
||
captchaCode: data.captchaCode,
|
||
};
|
||
|
||
UserAPI.sendBindCode(sendData)
|
||
.then((data) => {
|
||
sendMCButtonRef.value.startCountdown(); //开始倒计时
|
||
ElMessage.success("已向 " + mailForm.email + " 发送验证码(15分钟内有效,请勿重复提交!)");
|
||
})
|
||
.finally(() => {
|
||
loadingMail.value = false;
|
||
});
|
||
}
|
||
|
||
/** 先检验邮箱,再进行防刷 */
|
||
function sendMailCode() {
|
||
mailFormRef.value?.validateField(["email"], (valid: boolean) => {
|
||
if (valid) {
|
||
sendMCButtonRef.value.handleClick();
|
||
}
|
||
});
|
||
}
|
||
|
||
function summitMailForm() {
|
||
if (mailStep.value == 2) {
|
||
//解绑邮箱
|
||
mailStep.value = 0;
|
||
} else {
|
||
//绑定邮箱
|
||
mailFormRef.value?.validate((valid: any) => {
|
||
if (valid) {
|
||
ElMessageBox.confirm("确认绑定该邮箱?", "", {
|
||
confirmButtonText: "确定",
|
||
cancelButtonText: "取消",
|
||
type: "info",
|
||
}).then(function () {
|
||
loadingMail.value = true;
|
||
|
||
UserAPI.bindEmail(mailForm)
|
||
.then(() => {
|
||
userStore.account.email = mailForm.email;
|
||
userStore.account.state = 2;
|
||
mailForm.code = "";
|
||
mailStep.value = 2;
|
||
ElMessage.success("邮箱绑定成功");
|
||
})
|
||
.finally(() => {
|
||
loadingMail.value = false;
|
||
});
|
||
});
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
function resetMailForm() {
|
||
mailFormRef.value.resetFields();
|
||
mailStep.value = 0;
|
||
}
|
||
|
||
const cellStep = ref(0);
|
||
const cellFormRef = ref();
|
||
const cellForm = reactive<MobileBindingForm>({
|
||
mobile: "",
|
||
code: "",
|
||
});
|
||
|
||
const sendPCButtonRef = ref();
|
||
|
||
const cellRules = reactive<FormRules<typeof cellForm>>({
|
||
mobile: [{ required: true, validator: validatePhone, trigger: "blur" }],
|
||
code: [{ type: "number", required: true, message: "请输入手机验证码", trigger: "blur" }],
|
||
});
|
||
|
||
function validatePhone(rule: any, value: string, callback: any) {
|
||
if (!isPhone(value)) {
|
||
callback(new Error("请输入正确的手机号"));
|
||
} else {
|
||
callback();
|
||
}
|
||
}
|
||
|
||
function cellTagType() {
|
||
if (userStore.account.isPhone == 1) return "success";
|
||
else return "info";
|
||
}
|
||
|
||
function cellTagStr() {
|
||
if (userStore.account.isPhone == 1) return "已绑定";
|
||
else return "未绑定";
|
||
}
|
||
|
||
/** 获得防刷验证码后,正式请求绑定邮箱验证码 */
|
||
function handleCellCaptchaData(data: CaptchaData) {
|
||
loadingCell.value = true;
|
||
|
||
const sendData: SendCodeData = {
|
||
contact: cellForm.mobile!,
|
||
captchaKey: data.captchaKey,
|
||
captchaCode: data.captchaCode,
|
||
};
|
||
|
||
// AuthAPI.sendCode(sendData)
|
||
UserAPI.sendBindCode(sendData)
|
||
.then((data) => {
|
||
sendPCButtonRef.value.startCountdown(); //开始倒计时
|
||
ElMessage.success("已向 " + cellForm.mobile + " 发送验证码(15分钟内有效,请勿重复提交!)");
|
||
})
|
||
.finally(() => {
|
||
loadingCell.value = false;
|
||
});
|
||
}
|
||
|
||
/** 先检验邮箱,再进行防刷 */
|
||
function sendCellCode() {
|
||
cellFormRef.value?.validateField(["mobile"], (valid: boolean) => {
|
||
if (valid) {
|
||
sendPCButtonRef.value.handleClick();
|
||
}
|
||
});
|
||
}
|
||
|
||
function summitCellForm() {
|
||
if (cellStep.value == 2) {
|
||
//解绑邮箱
|
||
cellStep.value = 0;
|
||
} else {
|
||
//绑定邮箱
|
||
cellFormRef.value?.validate((valid: any) => {
|
||
if (valid) {
|
||
ElMessageBox.confirm("确认绑定该手机?", "", {
|
||
confirmButtonText: "确定",
|
||
cancelButtonText: "取消",
|
||
type: "info",
|
||
}).then(function () {
|
||
loadingCell.value = true;
|
||
|
||
UserAPI.bindMobile(cellForm)
|
||
.then(() => {
|
||
userStore.account.phone = cellForm.mobile;
|
||
userStore.account.isPhone = 1;
|
||
cellForm.code = "";
|
||
cellStep.value = 2;
|
||
ElMessage.success("手机绑定成功");
|
||
})
|
||
.finally(() => {
|
||
loadingCell.value = false;
|
||
});
|
||
});
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
function resetCellForm() {
|
||
cellFormRef.value.resetFields();
|
||
cellStep.value = 0;
|
||
}
|
||
|
||
function getRealNameInfo() {
|
||
UserAPI.getRealNameInfo().then((data) => {
|
||
Object.assign(realNameInfo, data);
|
||
|
||
if (realNameInfo.identityPic) {
|
||
realNameInfo.identityPic.split(",").forEach((name) => {
|
||
picUrls.value.push(BASE_NAME_URL + name);
|
||
});
|
||
} else {
|
||
realNameInfo.identityPic = "";
|
||
}
|
||
});
|
||
}
|
||
|
||
onMounted(() => {
|
||
if (userStore.account.state == 2) mailStep.value = 2;
|
||
if (userStore.account.email) mailForm.email = userStore.account.email;
|
||
if (userStore.account.isPhone == 1) cellStep.value = 2;
|
||
if (userStore.account.phone) cellForm.mobile = userStore.account.phone;
|
||
getRealNameInfo();
|
||
});
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.pictures {
|
||
width: 100%;
|
||
display: flex;
|
||
}
|
||
</style>
|