feat: merge github
This commit is contained in:
@@ -1,65 +1,102 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { BasicOption } from '@vben/types';
|
import type { Recordable } from '@vben/types';
|
||||||
|
|
||||||
import type { VbenFormSchema } from '#/adapter/form';
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
|
import type { SystemUserProfileApi } from '#/api/system/user/profile';
|
||||||
|
|
||||||
import { computed, onMounted, ref } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { ProfileBaseSetting } from '@vben/common-ui';
|
import { ProfileBaseSetting, z } from '@vben/common-ui';
|
||||||
|
import { DICT_TYPE } from '@vben/constants';
|
||||||
|
import { getDictOptions } from '@vben/hooks';
|
||||||
|
|
||||||
import { getUserInfoApi } from '#/api';
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { updateUserProfile } from '#/api/system/user/profile';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
profile?: SystemUserProfileApi.UserProfileRespVO;
|
||||||
|
}>();
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'success'): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
const profileBaseSettingRef = ref();
|
const profileBaseSettingRef = ref();
|
||||||
|
|
||||||
const MOCK_ROLES_OPTIONS: BasicOption[] = [
|
|
||||||
{
|
|
||||||
label: '管理员',
|
|
||||||
value: 'super',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '用户',
|
|
||||||
value: 'user',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '测试',
|
|
||||||
value: 'test',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const formSchema = computed((): VbenFormSchema[] => {
|
const formSchema = computed((): VbenFormSchema[] => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
fieldName: 'realName',
|
label: '用户昵称',
|
||||||
|
fieldName: 'nickname',
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
label: '姓名',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldName: 'username',
|
|
||||||
component: 'Input',
|
|
||||||
label: '用户名',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldName: 'roles',
|
|
||||||
component: 'Select',
|
|
||||||
componentProps: {
|
componentProps: {
|
||||||
mode: 'tags',
|
placeholder: '请输入用户昵称',
|
||||||
options: MOCK_ROLES_OPTIONS,
|
|
||||||
},
|
},
|
||||||
label: '角色',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'introduction',
|
label: '用户手机',
|
||||||
component: 'Textarea',
|
fieldName: 'mobile',
|
||||||
label: '个人简介',
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入用户手机',
|
||||||
|
},
|
||||||
|
rules: z.string(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '用户邮箱',
|
||||||
|
fieldName: 'email',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入用户邮箱',
|
||||||
|
},
|
||||||
|
rules: z.string().email('请输入正确的邮箱'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '用户性别',
|
||||||
|
fieldName: 'sex',
|
||||||
|
component: 'RadioGroup',
|
||||||
|
componentProps: {
|
||||||
|
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
|
||||||
|
buttonStyle: 'solid',
|
||||||
|
optionType: 'button',
|
||||||
|
},
|
||||||
|
rules: z.number(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
async function handleSubmit(values: Recordable<any>) {
|
||||||
const data = await getUserInfoApi();
|
try {
|
||||||
profileBaseSettingRef.value.getFormApi().setValues(data);
|
profileBaseSettingRef.value.getFormApi().setLoading(true);
|
||||||
});
|
// 提交表单
|
||||||
|
await updateUserProfile(values as SystemUserProfileApi.UpdateProfileReqVO);
|
||||||
|
// 关闭并提示
|
||||||
|
emit('success');
|
||||||
|
message.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
profileBaseSettingRef.value.getFormApi().setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 监听 profile 变化 */
|
||||||
|
watch(
|
||||||
|
() => props.profile,
|
||||||
|
(newProfile) => {
|
||||||
|
if (newProfile) {
|
||||||
|
profileBaseSettingRef.value.getFormApi().setValues(newProfile);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<ProfileBaseSetting ref="profileBaseSettingRef" :form-schema="formSchema" />
|
<ProfileBaseSetting
|
||||||
|
ref="profileBaseSettingRef"
|
||||||
|
:form-schema="formSchema"
|
||||||
|
@submit="handleSubmit"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const tabsValue = defineModel<string>('modelValue');
|
|||||||
class="size-20"
|
class="size-20"
|
||||||
/>
|
/>
|
||||||
<span class="text-lg font-semibold">
|
<span class="text-lg font-semibold">
|
||||||
{{ userInfo?.realName ?? '' }}
|
{{ userInfo?.nickname ?? '' }}
|
||||||
</span>
|
</span>
|
||||||
<span class="text-foreground/80 text-sm">
|
<span class="text-foreground/80 text-sm">
|
||||||
{{ userInfo?.username ?? '' }}
|
{{ userInfo?.username ?? '' }}
|
||||||
|
|||||||
Reference in New Issue
Block a user