index.vue
8.57 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<template>
<BasicModal
:useWrapper="true"
width="82vw"
:height="compHeight"
v-bind="$attrs"
@register="registerModal"
@ok="handleSubmit"
:draggable="false"
>
<div
style="
height: 62vh;
width: 120vw;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
"
>
<div style="width: 29vw; height: 62vh; border: 1px solid #e9edf6; box-shadow: 0 0 5px -5px">
<div style="width: 29vw; height: 4vh; border: 1px solid #e9edf6"
><p style="font-size: 17px; margin-top: 7px; margin-left: 10px">个人信息</p></div
>
<div class="change-avatar" style="text-align: center">
<div class="mb-2" style="font-weight: 700">个人头像</div>
<div style="text-align: center; width: 100%">
<Upload
style="width: 20vw"
name="avatar"
list-type="picture-card"
class="avatar-uploader"
:show-upload-list="false"
:customRequest="customUploadqrcodePic"
:before-upload="beforeUploadqrcodePic"
>
<img
style="text-align: center; border-radius: 50%"
v-if="peresonalPic"
:src="peresonalPic"
alt="avatar"
/>
<div v-else>
<div style="margin-top: 5.2vh; margin-left: 3.21vw">
<PlusOutlined style="font-size: 30px" />
</div>
</div>
</Upload>
</div>
</div>
<Description
class="mt-8"
:column="1"
:schema="schema"
:bordered="true"
:data="getPersonalDetailValue"
@register="registerDesc"
/>
</div>
<div
style="
width: 90vw;
height: 60vh;
border: 1px solid #e9edf6;
margin-top: -15px;
box-shadow: 0 0 5px -5px;
"
>
<div style="width: 90vw; height: 4vh; border: 1px solid #e9edf6"
><p style="font-size: 17px; margin-top: 7px; margin-left: 20px">基本资料</p></div
>
<div style="margin-left: 20px">
<BasicForm @register="registerForm" />
</div>
</div>
</div>
</BasicModal>
</template>
<script lang="ts">
import { defineComponent, ref, computed } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal/index';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './config';
import { Description, DescItem, useDescription } from '/@/components/Description/index';
import { uploadApi, personalPut } from '/@/api/personal/index';
import { useMessage } from '/@/hooks/web/useMessage';
import { USER_INFO_KEY } from '/@/enums/cacheEnum';
import { getAuthCache } from '/@/utils/auth';
import { Upload } from 'ant-design-vue';
import { PlusOutlined } from '@ant-design/icons-vue';
import { useUserStore } from '/@/store/modules/user';
import type { FileItem } from '/@/components/Upload/src/typing';
const schema: DescItem[] = [
{
field: 'username',
label: '用户名称:',
},
{
field: 'phoneNumber',
label: '手机号码:',
},
{
field: 'email',
label: '用户邮箱:',
},
{
field: 'realName',
label: '用户昵称:',
},
{
field: 'accountExpireTime',
label: '过期时间:',
},
{
field: 'createTime',
label: '创建时间:',
},
];
export default defineComponent({
name: 'Index',
components: { BasicModal, BasicForm, Description, Upload, PlusOutlined },
emits: ['refreshPersonl', 'register'],
setup(_, { emit }) {
const userInfo = getAuthCache(USER_INFO_KEY);
const { createMessage } = useMessage();
const getPersonalValue: any = ref({});
const getPersonalDetailValue: any = ref({});
const updatePersonalData: any = ref({});
const getBackendV: any = ref({});
const getData: any = ref({});
const updataPersonlData: any = ref({});
const userStore = useUserStore();
// const getUpdateUserInfo: any = ref({});
const [registerDesc] = useDescription({
title: '个人详情',
schema: schema,
});
const peresonalPic = ref();
const customUploadqrcodePic = async ({ file }) => {
if (beforeUploadqrcodePic(file)) {
const formData = new FormData();
formData.append('file', file);
const response = await uploadApi(formData);
if (response.fileStaticUri) {
peresonalPic.value = response.fileStaticUri;
}
}
};
const beforeUploadqrcodePic = (file: FileItem) => {
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
if (!isJpgOrPng) {
createMessage.error('只能上传图片文件!');
}
const isLt2M = (file.size as number) / 1024 / 1024 < 5;
if (!isLt2M) {
createMessage.error('图片大小不能超过5MB!');
}
return isJpgOrPng && isLt2M;
};
const [registerForm, { validate, resetFields, setFieldsValue }] = useForm({
showActionButtonGroup: false,
schemas: formSchema,
});
const refreshCacheGetData = () => {
const getItem = window.localStorage.getItem('updateUserInfo');
const newItem = JSON.parse(getItem);
updataPersonlData.value = newItem;
};
const [registerModal, { closeModal }] = useModalInner(async (data) => {
refreshCacheGetData();
try {
if (updataPersonlData.value != null) {
(peresonalPic.value = updataPersonlData.value.avatar),
setFieldsValue({
realName: updataPersonlData.value.realName,
phoneNumber: updataPersonlData.value.phoneNumber,
email: updataPersonlData.value.email,
});
getPersonalDetailValue.value = updataPersonlData.value;
} else {
if (data.userInfo) {
getPersonalDetailValue.value = data.userInfo;
peresonalPic.value = data.userInfo.avatar;
setFieldsValue({
realName: data.userInfo.realName,
phoneNumber: data.userInfo.phoneNumber,
email: data.userInfo.email,
});
}
}
} catch (e) {
return e;
}
if (Object.keys(updatePersonalData.value).length != 0) {
getPersonalDetailValue.value = updatePersonalData.value;
peresonalPic.value = updatePersonalData.value.avatar;
setFieldsValue({
realName: updatePersonalData.value.realName,
phoneNumber: updatePersonalData.value.phoneNumber,
email: updatePersonalData.value.email,
});
}
});
const handleSubmit = async () => {
const getUserInfo = await userInfo;
getPersonalValue.value = await validate();
getPersonalValue.value.id = getUserInfo.userId;
getPersonalValue.value.username = getBackendV.value.username;
getPersonalValue.value.avatar = peresonalPic.value;
getData.value = await personalPut(getPersonalValue.value);
console.log(getData.value.realName);
userStore.setUserInfo(getData.value);
updatePersonalData.value = getData.value;
createMessage.success('修改成功');
const setUpdateUserInfo = JSON.stringify(getData.value);
window.localStorage.setItem('updateUserInfo', setUpdateUserInfo);
closeModal();
resetFields();
emit('refreshPersonl', updatePersonalData.value);
};
const compHeight = computed(() => {
return 1000;
});
return {
peresonalPic,
beforeUploadqrcodePic,
customUploadqrcodePic,
compHeight,
handleSubmit,
getPersonalDetailValue,
registerDesc,
schema,
registerModal,
registerForm,
};
},
});
</script>
<style scoped lang="less">
.change-avatar {
:deep .ant-upload-select-picture-card {
display: inherit;
float: none;
width: 35%;
height: 0;
padding-bottom: 35%;
margin: 0;
// width: 8.6vw;
// height: 17vh;
// margin-right: 0.2vw;
// margin-bottom: 0.2vw;
text-align: center;
vertical-align: top;
background-color: #fafafa;
border: 1px dashed #d9d9d9;
border-radius: 50%;
cursor: pointer;
transition: border-color 0.3s ease;
}
}
</style>