吉安感知网项目-前端
shuishen
2026-02-03 89380e6260a75d1d3b94de687ebcc2f50d50659d
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!-- 个人资料 -->
<template>
    <view class="container">
        <view class="pageBg"></view>
        <div class="avatarBox">
            <u-avatar @click="uploadAvatar" :src="userInfo.avatar ? userInfo.avatar : showDefaultHeader" size="114" mode="aspectFill" />
        </div>
        <view class="detailBox">
            <div class="detailCon">
                <div class="orderRow">
                    <div class="rowTitle">昵称</div>
                    <div>{{userInfo.nickName}}</div>
                </div>
                <div class="orderRow">
                    <div class="rowTitle">认证状态</div>
                    <div>{{userInfo.status === 1 ? '已认证' : '未认证'}}</div>
                </div>
                <div class="orderRow">
                    <div class="rowTitle">性别</div>
                    <div>
                        <u-radio-group v-model="userInfo.sex">
                            <up-radio
                                v-for="(item, index) in sexList"
                                :key="index"
                                :label="item.label"
                                :name="item.name"
                                @change="radioChange"
                                >
                            </up-radio>
                        </u-radio-group>
                    </div>
                </div>
                <div class="orderRow">
                    <div class="rowTitle">手机号</div>
                    <u-input input-align="right" v-model="userInfo.phone" type="number" placeholder="请输入手机号"
                        class="input-item" />
 
                </div>
                <div class="orderRow">
                    <div class="rowTitle">邮箱</div>
                    <u-input input-align="right" v-model="userInfo.email" type="email" placeholder="请输入邮箱"
                        class="input-item" />
                </div>
            </div>
        </view>
        <view class="note">注:请前往吉安市低空经济服务一体化平台进行认证</view>
        <view class="btngroup">
            <u-button color="#AEAEAE" class="custom-style" @click="reset">重置</u-button>
            <u-button color="#1D6FE9" class="custom-style" @click="submit">提交</u-button>
        </view>
    </view>
</template>
 
<script setup>
    import { uploadFileApi } from '@/api/index'
    import showDefaultHeader from "@/static/images/user/default-header.png";
    import {
        getEnvObj,
        getWebViewUrl
    } from "@/utils/index.js";
    import {
        getUserInfo,
        updateInfo,
        updatePassword
    } from '@/api/user/index.js';
    import {
        useUserStore
    } from "@/store/index.js";
    const userInfo = ref({
        id: '',
        avatar: '',
        nickName: '',
        name: '',
        phone: '',
        email: '',
        deptName: '',
        sex: 2,
    });
    const sexList = [
        {
            label: '男',
            name: '0'
        },
        {
            label: '女',
            name: '1'
        },
        {
            label: '未知',
            name: '2'
        }
    ]
    // 校验手机号
    const validatePhone = () => {
        const phone = userInfo.value.phone
        if (!phone) return true
        const phoneRegex = /^1[3-9]\d{9}$/
        if (!phoneRegex.test(phone)) {
 
            uni.showToast({
                title: '请输入正确的手机号码',
                icon: 'none',
                duration: 2000
            });
            return false
        }
        return true
    }
    // 校验邮箱
    const validateEmail = () => {
        if (!userInfo.value.email) return true
        const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
        if (!emailRegex.test(userInfo.value.email)) {
 
            uni.showToast({
                title: '请输入正确的邮箱地址',
                icon: 'none',
                duration: 2000
            });
            return false
        }
        return true
    }
    const getUserInfoData = () => {
        getUserInfo().then(res => {
            const user = res.data.data;
            userInfo.value = {
                id: user.userId,
                avatar: user.avatar,
                nickName: user.nickName,
                phone: user.phonenumber,
                email: user.sysDept.email,
                deptName: user.sysDept.deptName,
                sex: user.sex || 2,
            };
 
        });
    };
    const reset = () => {
        getUserInfoData();
    };
    // 提交文件
function afterReadFile(event) {
    console.log('上传的文件:', event);
    
    // 准备上传参数
    const uploadParams = {
        name: event.name, // 服务器端接收文件的字段名
        file: event.file, // 传入文件对象
        filePath: event.filePath, // 文件路径
    };
    
    // 调用上传文件接口
    uploadFileApi(uploadParams).then(res => {
        uni.hideLoading();
        
        console.log('上传成功结果:', res);
        
        // 根据接口返回的数据结构处理结果
        if (res.data && res.data.code === 200) {
            const uploadResult = res.data.data;
            userInfo.value.avatar = uploadResult.fileUrl || '文件上传成功';
            
            uni.showToast({
                title: '上传成功',
                icon: 'success'
            });
        } else {
            uni.showToast({
                title: res.msg || '上传失败',
                icon: 'none'
            });
        }
    }).catch(err => {
        uni.hideLoading();
        console.error('上传失败:', err);
        uni.showToast({
            title: '上传失败',
            icon: 'none'
        });
    });
}
    const uploadAvatar = () => {
        uni.chooseImage({
            count: 1,
            success: (res) => {
                const tempFile = res.tempFiles[0]; // 获取文件对象
                const filePath = tempFile.path || tempFile.tempFilePath;
                if (!filePath) {
                    uni.showToast({
                        title: '获取文件路径失败',
                        icon: 'none'
                    });
                    return;
                }
                let fileName = tempFile.name;
                if (!fileName) {
                    const pathWithoutProtocol = filePath.replace(/^file:\/\//, '');
                    fileName = pathWithoutProtocol.split('/').pop() || 'unknown.png';
                }
            
                // 显示加载中
                uni.showLoading({
                    title: '上传中...'
                });
 
                afterReadFile({
                    file: tempFile,
                    filePath: filePath,
                    name: fileName,
                })
            }
        });
    }
    const submit = () => {
        if (!validatePhone() || !validateEmail()) return
        userInfo.value.name = userInfo.value.realName;
        updateInfo(userInfo.value).then(res => {
            if (res.data.code === 200) {
                uni.showToast({
                    title: '修改信息成功',
                    icon: 'none',
                    duration: 2000
                });
                    getUserInfoData()
 
            } else {
                uni.showToast({
                    title: res.msg,
                    icon: 'none',
                    duration: 2000
                });
                    getUserInfoData()
            }
 
        });
    
    };
    onShow(async () => {
        getUserInfoData()
    });
</script>
 
<style lang="scss" scoped>
    .container {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        position: relative;
    }
    .pageBg {
        width: 100%;
        height: 100%;
        background: url("https://wrj.shuixiongit.com/aiskyminio/cloud-bucket/ja-app-wx/images/user/userBg1.png")  no-repeat ;
          background-size: 100%;
    }
    .avatarBox {
        position: absolute;
        top: 30rpx;
        width: 228rpx;
        height: 228rpx;
    }
 
    .detailBox {
        position: absolute;
        top: 280rpx;
        width: 702rpx;
        min-height: 430rpx;
        background: #FFFFFF;
        border-radius: 12rpx;
        box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
 
        .detailCon {
            padding: 0 24rpx;
        }
 
        .orderRow {
            display: flex;
            justify-content: space-between;
            align-items: center;
            height: 96rpx;
            border-bottom: 2rpx solid #f5f5f5;
            color: #7b7b7b;
 
            .rowTitle {
                font-family: Source Han Sans CN, Source Han Sans CN;
                font-weight: 400;
                font-size: 30rpx;
                color: #222324;
                white-space: nowrap;
            }
 
            ::v-deep .u-input {
                border: none !important;
                background: transparent !important;
                padding: 0 !important;
            }
 
            ::v-deep .u-input__input {
                border: none !important;
                box-shadow: none !important;
                background: transparent !important;
                padding: 0 !important;
                margin: 0 !important;
                height: auto !important;
            }
        }
    }
 
    .btngroup {
        display: flex;
        position: absolute;
        bottom: 150rpx;
    }
 
    :deep(.u-button:first-child) {
        margin-right: 30rpx !important;
    }
 
    .custom-style {
        width: 276rpx;
        height: 76rpx;    
    }
    :deep(.u-button.data-v-461e713c){
        width: 276rpx !important;
        height: 76rpx !important;
    }
    .note {
        position: absolute;
        bottom: 300rpx;
        font-family: Source Han Sans CN, Source Han Sans CN;
        font-weight: 400;
        font-size: 10px;
        color: #1D6FE9;
        margin-top: 40rpx;
    }
</style>