|
@@ -0,0 +1,105 @@
|
|
|
|
+<script setup lang="ts">
|
|
|
|
+import { reactive, ref } from 'vue';
|
|
|
|
+import { useAntdForm, useFormRules } from '@/hooks/common/form';
|
|
|
|
+import { fetchUserEdit, fetchUserProfile } from '@/service/api';
|
|
|
|
+
|
|
|
|
+interface Emits {
|
|
|
|
+ (e: 'submitted'): void;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const emit = defineEmits<Emits>();
|
|
|
|
+
|
|
|
|
+const { formRef, validate, resetFields } = useAntdForm();
|
|
|
|
+const { defaultRequiredRule, formRules } = useFormRules();
|
|
|
|
+
|
|
|
|
+type Model = Pick<Api.Admin.UserProfile, 'nickName' | 'phone' | 'email' | 'sex'>;
|
|
|
|
+
|
|
|
|
+const model: Model = reactive(createDefaultModel());
|
|
|
|
+
|
|
|
|
+function createDefaultModel(): Model {
|
|
|
|
+ return {
|
|
|
|
+ nickName: '',
|
|
|
|
+ phone: '',
|
|
|
|
+ email: '',
|
|
|
|
+ sex: '0'
|
|
|
|
+ };
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type RuleKey = Extract<keyof Model, 'nickName' | 'phone' | 'email' | 'sex'>;
|
|
|
|
+
|
|
|
|
+const rules: Record<RuleKey, App.Global.FormRule> = {
|
|
|
|
+ nickName: defaultRequiredRule,
|
|
|
|
+ phone: formRules.phone,
|
|
|
|
+ email: formRules.email,
|
|
|
|
+ sex: defaultRequiredRule
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+async function gethUserProfile() {
|
|
|
|
+ const { data } = await fetchUserProfile();
|
|
|
|
+ Object.assign(model, data.user);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+async function handleInitModel() {
|
|
|
|
+ Object.assign(model, createDefaultModel());
|
|
|
|
+ gethUserProfile();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const sexStatus = ref([
|
|
|
|
+ { label: '男', value: '0' },
|
|
|
|
+ { label: '女', value: '1' }
|
|
|
|
+]);
|
|
|
|
+
|
|
|
|
+async function handleSubmit() {
|
|
|
|
+ await validate();
|
|
|
|
+
|
|
|
|
+ const formData = { ...model };
|
|
|
|
+ fetchUserEdit(formData).then(({ code, msg }) => {
|
|
|
|
+ if (code === 200) {
|
|
|
|
+ window.$message?.success(msg);
|
|
|
|
+ emit('submitted');
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+handleInitModel();
|
|
|
|
+resetFields();
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<template>
|
|
|
|
+ <AForm ref="formRef" :model="model" :rules="rules" :label-col="{ lg: 8, xs: 4 }" label-wrap class="pr-20px">
|
|
|
|
+ <ARow wrap>
|
|
|
|
+ <ACol :span="12" :md="12" :xs="24">
|
|
|
|
+ <AFormItem label="用户昵称" name="nickName">
|
|
|
|
+ <AInput v-model:value="model.nickName" placeholder="请输入用户昵称" allow-clear />
|
|
|
|
+ </AFormItem>
|
|
|
|
+ </ACol>
|
|
|
|
+ <ACol :span="12" :md="12" :xs="24">
|
|
|
|
+ <AFormItem label="手机号码" name="phone">
|
|
|
|
+ <AInput v-model:value="model.phone" placeholder="请输入手机号码" allow-clear />
|
|
|
|
+ </AFormItem>
|
|
|
|
+ </ACol>
|
|
|
|
+ <ACol :span="12" :md="12" :xs="24">
|
|
|
|
+ <AFormItem label="邮箱" name="email">
|
|
|
|
+ <AInput v-model:value="model.email" placeholder="请输入邮箱" allow-clear />
|
|
|
|
+ </AFormItem>
|
|
|
|
+ </ACol>
|
|
|
|
+
|
|
|
|
+ <ACol :span="12" :md="12" :xs="24">
|
|
|
|
+ <AFormItem label="性别" name="sex">
|
|
|
|
+ <ARadioGroup v-model:value="model.sex">
|
|
|
|
+ <ARadio v-for="item in sexStatus" :key="item.value" :value="item.value">
|
|
|
|
+ {{ item.label }}
|
|
|
|
+ </ARadio>
|
|
|
|
+ </ARadioGroup>
|
|
|
|
+ </AFormItem>
|
|
|
|
+ </ACol>
|
|
|
|
+ </ARow>
|
|
|
|
+ </AForm>
|
|
|
|
+ <ARow wrap>
|
|
|
|
+ <ACol :offset="4" :span="12" :md="12" :xs="24">
|
|
|
|
+ <AButton type="primary" @click="handleSubmit">更新信息</AButton>
|
|
|
|
+ </ACol>
|
|
|
|
+ </ARow>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<style scoped></style>
|