|
|
@@ -2,12 +2,7 @@
|
|
|
<div class="edit-profile-page">
|
|
|
<el-form ref="formRef" :model="form" label-width="100px" class="edit-form">
|
|
|
<el-form-item label="头像">
|
|
|
- <el-upload
|
|
|
- class="avatar-uploader"
|
|
|
- :show-file-list="false"
|
|
|
- accept="image/*"
|
|
|
- :before-upload="beforeUpload"
|
|
|
- >
|
|
|
+ <el-upload class="avatar-uploader" :show-file-list="false" accept="image/*">
|
|
|
<el-avatar :size="64" :src="form.avatar || undefined">
|
|
|
{{ userStore.loginUser.user?.name?.[0] || 'U' }}
|
|
|
</el-avatar>
|
|
|
@@ -24,7 +19,7 @@
|
|
|
|
|
|
<el-form-item label="实名认证">
|
|
|
<el-tag v-if="userStore.userInfo.isRealname" type="success">已认证</el-tag>
|
|
|
- <el-button v-else size="small" type="primary" plain>去认证</el-button>
|
|
|
+ <el-button v-else size="small" type="primary" plain @click="showRealname = true">去认证</el-button>
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-divider />
|
|
|
@@ -45,6 +40,33 @@
|
|
|
<el-button type="primary" :loading="saving" @click="handleSave">保存</el-button>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
+
|
|
|
+ <el-dialog v-model="showRealname" title="实名认证" width="90%" max-width="500px">
|
|
|
+ <el-form :model="realnameForm" label-width="100px">
|
|
|
+ <el-form-item label="真实姓名">
|
|
|
+ <el-input v-model="realnameForm.realName" placeholder="请输入真实姓名" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="身份证号">
|
|
|
+ <el-input v-model="realnameForm.idCard" placeholder="请输入身份证号" maxlength="18" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="身份证正面">
|
|
|
+ <el-upload class="upload-card" accept="image/*" :before-upload="(file: File) => uploadIdCard(file, 'front')">
|
|
|
+ <el-button size="small">上传正面</el-button>
|
|
|
+ </el-upload>
|
|
|
+ <span v-if="realnameForm.idCardFront" class="uploaded">已上传</span>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="身份证反面">
|
|
|
+ <el-upload class="upload-card" accept="image/*" :before-upload="(file: File) => uploadIdCard(file, 'back')">
|
|
|
+ <el-button size="small">上传反面</el-button>
|
|
|
+ </el-upload>
|
|
|
+ <span v-if="realnameForm.idCardBack" class="uploaded">已上传</span>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <template #footer>
|
|
|
+ <el-button @click="showRealname = false">取消</el-button>
|
|
|
+ <el-button type="primary" :loading="realnameSubmitting" @click="submitRealname">提交认证</el-button>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -52,37 +74,62 @@
|
|
|
import { ref, reactive, onMounted } from 'vue'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
import { useLoginUserStore } from '../store'
|
|
|
+import { getRealnameAuthController } from '../api/realname-auth-controller'
|
|
|
|
|
|
const userStore = useLoginUserStore()
|
|
|
const formRef = ref()
|
|
|
const saving = ref(false)
|
|
|
|
|
|
-const form = reactive({
|
|
|
- username: '',
|
|
|
- avatar: '',
|
|
|
- mobile: ''
|
|
|
-})
|
|
|
+const form = reactive({ username: '', avatar: '', mobile: '' })
|
|
|
+const passwordForm = reactive({ oldPassword: '', newPassword: '', confirmPassword: '' })
|
|
|
|
|
|
-const passwordForm = reactive({
|
|
|
- oldPassword: '',
|
|
|
- newPassword: '',
|
|
|
- confirmPassword: ''
|
|
|
-})
|
|
|
-
|
|
|
-function beforeUpload(_file: File): boolean {
|
|
|
- return true
|
|
|
-}
|
|
|
+const showRealname = ref(false)
|
|
|
+const realnameSubmitting = ref(false)
|
|
|
+const realnameForm = reactive({ realName: '', idCard: '', idCardFront: '', idCardBack: '' })
|
|
|
|
|
|
-function handleSave() {
|
|
|
+async function handleSave() {
|
|
|
saving.value = true
|
|
|
- setTimeout(() => {
|
|
|
+ try {
|
|
|
+ const { getUserController } = await import('../api/user-controller')
|
|
|
+ await getUserController().edit({
|
|
|
+ id: userStore.userInfo.id,
|
|
|
+ username: form.username,
|
|
|
+ account: userStore.userInfo.username,
|
|
|
+ role: userStore.userInfo.role,
|
|
|
+ password: undefined,
|
|
|
+ } as any)
|
|
|
userStore.updateProfile({ username: form.username, avatar: form.avatar, mobile: form.mobile })
|
|
|
if (userStore.loginUser.user) {
|
|
|
userStore.loginUser.user.name = form.username
|
|
|
}
|
|
|
ElMessage.success('保存成功')
|
|
|
+ } catch {
|
|
|
+ ElMessage.error('保存失败')
|
|
|
+ } finally {
|
|
|
saving.value = false
|
|
|
- }, 500)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function uploadIdCard(_file: File, _side: string): boolean {
|
|
|
+ ElMessage.info('图片上传功能对接 OSS 后实现')
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+async function submitRealname() {
|
|
|
+ if (!realnameForm.realName || !realnameForm.idCard) {
|
|
|
+ ElMessage.warning('请填写姓名和身份证号')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ realnameSubmitting.value = true
|
|
|
+ try {
|
|
|
+ await getRealnameAuthController().submit(realnameForm)
|
|
|
+ ElMessage.success('认证资料已提交,等待管理员审核')
|
|
|
+ showRealname.value = false
|
|
|
+ } catch {
|
|
|
+ ElMessage.error('提交失败')
|
|
|
+ } finally {
|
|
|
+ realnameSubmitting.value = false
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
|
@@ -104,4 +151,9 @@ onMounted(() => {
|
|
|
font-weight: 600;
|
|
|
margin-bottom: 12px;
|
|
|
}
|
|
|
+.uploaded {
|
|
|
+ margin-left: 8px;
|
|
|
+ color: #67c23a;
|
|
|
+ font-size: 12px;
|
|
|
+}
|
|
|
</style>
|