info.vue 2.56 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<template>
    <div class="tw-flex">
        <a-form-model layout="vertical" style="flex: 0 0 400px">
            <a-form-model-item label="用户账户">
                <a-input disabled :value="loginId" />
            </a-form-model-item>
            <a-form-model-item label="姓名">
                <a-input v-model="form.userName" />
            </a-form-model-item>
            <a-form-model-item label="固定电话">
                <a-input v-model="form.fixedPhone" />
            </a-form-model-item>
            <a-form-model-item label="移动电话">
                <a-input v-model="form.mobilePhone" />
            </a-form-model-item>
            <a-form-model-item label="电子邮箱">
                <a-input v-model="form.userEmail" />
            </a-form-model-item>
            <a-form-model-item>
                <a-button type="primary" :loading="loading" @click="update">更新信息</a-button>
            </a-form-model-item>
        </a-form-model>
        <div style="flex: 0 0 300px" class="tw-flex tw-flex-col tw-items-center ">
            <div>头像</div>
            <img
                style="width: 100px;height: 100px"
                class="tw-max-w-full tw-max-h-full tw-rounded-full tw-my-4"
28
                :src="userAvatar"
29 30 31 32 33 34 35 36
            />
            <my-upload v-model="form.userAvatar" />
        </div>
    </div>
</template>

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

export default {
    data: () => ({
        form: {
            userName: '',
            mobilePhone: '',
            fixedPhone: '',
            userEmail: '',
            userAvatar: '',
        },
        loading: false,
水落(YangLei)'s avatar
水落(YangLei) committed
49
        loginId: '',
50 51
    }),
    computed: {
52 53 54
        userAvatar() {
            return this.form.userAvatar ? `${this.$fileUrl}${this.form.userAvatar}` : null;
        },
55
    },
56
    mounted() {
水落(YangLei)'s avatar
水落(YangLei) committed
57 58 59 60 61 62 63
        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;
64
    },
水落(YangLei)'s avatar
水落(YangLei) committed
65

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