info.vue 2.67 KB
Newer Older
1 2 3
<template>
    <div class="tw-flex">
        <a-form-model layout="vertical" style="flex: 0 0 400px">
shuiluo's avatar
shuiluo committed
4
            <a-form-model-item :label="$t('user.account')">
5 6
                <a-input disabled :value="loginId" />
            </a-form-model-item>
shuiluo's avatar
shuiluo committed
7
            <a-form-model-item :label="$t('user.name')">
8 9
                <a-input v-model="form.userName" />
            </a-form-model-item>
shuiluo's avatar
shuiluo committed
10
            <a-form-model-item :label="$t('user.fixedPhone')">
11 12
                <a-input v-model="form.fixedPhone" />
            </a-form-model-item>
shuiluo's avatar
shuiluo committed
13
            <a-form-model-item :label="$t('user.mobilePhone')">
14 15
                <a-input v-model="form.mobilePhone" />
            </a-form-model-item>
shuiluo's avatar
shuiluo committed
16
            <a-form-model-item :label="$t('user.email')">
17 18 19
                <a-input v-model="form.userEmail" />
            </a-form-model-item>
            <a-form-model-item>
shuiluo's avatar
shuiluo committed
20 21 22
                <a-button type="primary" :loading="loading" @click="update">
                    {{ $t('user.updateInfo') }}
                </a-button>
23 24
            </a-form-model-item>
        </a-form-model>
shuiluo's avatar
shuiluo committed
25 26
        <div style="flex: 0 0 300px" class="tw-flex tw-flex-col tw-items-center">
            <div>{{ $t('user.avator') }}</div>
27
            <img
shuiluo's avatar
shuiluo committed
28
                style="width: 100px; height: 100px"
29
                class="tw-max-w-full tw-max-h-full tw-rounded-full tw-my-4"
30
                :src="userAvatar"
31 32 33 34 35 36 37 38
            />
            <my-upload v-model="form.userAvatar" />
        </div>
    </div>
</template>

<script>
import { updateUserInfoApi } from '@/api';
水落(YangLei)'s avatar
水落(YangLei) committed
39
import { getUserInfo, setUserInfoByRequest } from '@/utils';
40 41 42 43 44 45 46 47 48 49 50

export default {
    data: () => ({
        form: {
            userName: '',
            mobilePhone: '',
            fixedPhone: '',
            userEmail: '',
            userAvatar: '',
        },
        loading: false,
水落(YangLei)'s avatar
水落(YangLei) committed
51
        loginId: '',
52 53
    }),
    computed: {
54 55 56
        userAvatar() {
            return this.form.userAvatar ? `${this.$fileUrl}${this.form.userAvatar}` : null;
        },
57
    },
58
    mounted() {
水落(YangLei)'s avatar
水落(YangLei) committed
59 60 61 62 63 64 65
        const userInfo = getUserInfo();
        this.form.userName = userInfo.userName;
        this.form.fixedPhone = userInfo.fixedPhone;
        this.form.mobilePhone = userInfo.mobilePhone;
        this.form.userEmail = userInfo.userEmail;
        this.form.userAvatar = userInfo.userAvatar;
        this.loginId = userInfo.loginId;
66
    },
水落(YangLei)'s avatar
水落(YangLei) committed
67

68 69 70 71 72
    methods: {
        async update() {
            this.loading = true;
            await updateUserInfoApi(this.form);
            this.$message.success('更新成功');
水落(YangLei)'s avatar
水落(YangLei) committed
73 74 75 76 77
            await setUserInfoByRequest();
            this.loading = false;
            setTimeout(() => {
                location.reload();
            });
78 79 80 81
        },
    },
};
</script>