无人机管理后台前端(已迁走)
张含笑
2025-09-01 2ca94de8ede18ac07ccfd8dec7b6f6a707adde9b
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<template>
  <div class="user-info-new">
    <div class="titleBoxs">
      <div
        class="titleItem"
        :class="index === checked ? 'activeItem' : ''"
        v-for="(item, index) in titleList"
        :key="index"
        @click="titleClick(item, index)"
      >
        {{ item }}
      </div>
    </div>
    <!-- 个人信息 -->
    <div class="message" v-if="checked === 0">
      <div class="info">
        <div class="section">
          <el-form label-width="120px">
            <el-form-item label="头像:">
              <el-upload
                class="avatar-uploader"
                :http-request="customUpload"
                :show-file-list="false"
                :before-upload="beforeAvatarUpload"
                :disabled="uploadLoading"
                action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
              >
                <img v-if="userInfo.avatar" :src="userInfo.avatar" class="avatar" />
                <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
 
                <template #tip>
                  <div class="upload-tip">只能上传jpg/png用户头像,且不超过500kb</div>
                </template>
              </el-upload>
              <!-- <el-dialog v-model="dialogVisible">
                                <img w-full :src="dialogImageUrl" alt="Preview Image" />
                            </el-dialog> -->
            </el-form-item>
          </el-form>
        </div>
 
        <div class="section">
          <el-form :model="userInfo" label-width="120px">
            <el-form-item label="姓名:">
              <el-input
                class="ztzf-input"
                :style="{ width: pxToRem(230) }"
                v-model="userInfo.realName"
                disabled
              />
            </el-form-item>
            <!--                        <el-form-item label="昵称:">
                                                    <el-input class="ztzf-input" v-model="userInfo.name" />
                                                </el-form-item>-->
            <el-form-item label="所属单位:">
              <el-input class="ztzf-input" v-model="userInfo.deptName" disabled />
            </el-form-item>
            <el-form-item label="手机号:">
              <el-input class="ztzf-input" v-model="userInfo.phone" />
            </el-form-item>
            <el-form-item label="邮箱:">
              <el-input class="ztzf-input" v-model="userInfo.email" />
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="butn">
        <!-- <img @click="reset" :style="{ marginRight: pxToRem(23) }" :src="cancel1" alt="" />
                <img @click="submit" :style="{ marginRight: pxToRem(23) }" :src="publish1" alt="" /> -->
        <el-button type="primary" @click="submit" style="margin-right: 10px">提交</el-button>
        <el-button @click="reset">重置</el-button>
      </div>
    </div>
    <!-- 修改密码 -->
    <div class="passwordBox" v-else-if="checked === 1">
      <div class="password">
        <el-form :model="passwordForm" label-width="120px">
          <el-form-item label="原始密码:" prop="oldPassword">
            <el-input
              class="ztzf-input"
              v-model="passwordForm.oldPassword"
              type="password"
              show-password
            />
          </el-form-item>
          <el-form-item label="新密码:" prop="newPassword">
            <el-input
              class="ztzf-input"
              v-model="passwordForm.newPassword"
              type="password"
              show-password
            />
          </el-form-item>
          <el-form-item label="确认密码:" prop="newPassword1">
            <el-input
              class="ztzf-input"
              v-model="passwordForm.newPassword1"
              type="password"
              show-password
            />
          </el-form-item>
        </el-form>
      </div>
      <div class="butn">
        <!-- <img @click="reset" :style="{ marginRight: pxToRem(23) }" :src="cancel1" alt="" />
                <img @click="submit" :style="{ marginRight: pxToRem(23) }" :src="publish1" alt="" /> -->
        <el-button type="primary" @click="submit" style="margin-right: 10px">提交</el-button>
        <el-button @click="reset">重置</el-button>
      </div>
    </div>
  </div>
</template>
 
<script setup>
import { pxToRem } from '@/utils/rem';
import { useStore } from 'vuex';
import { ElMessage } from 'element-plus';
import { getToken } from '@/utils/auth';
import md5 from 'js-md5';
import request from '@/axios';
import { getUserInfo, updateInfo, updatePassword } from '@/api/system/user';
import { findLicenseDate } from '@/api/system/dict';
import uploadSuccess from '@/assets/images/uoload-success.png';
import uploadError from '@/assets/images/upload-error.png';
import cancel1 from '@/assets/images/task/cancel1.png';
import publish1 from '@/assets/images/task/publish1.png';
 
const store = useStore();
const token = getToken();
const userinforShow = defineModel('show');
const userInfoAs = computed(() => store.state.user.userInfo);
const titleList = ref(['个人信息', '修改密码']);
const checked = ref(0);
const uploadUrl = computed(
  () => `${import.meta.env.VITE_APP_API_URL}/blade-resource/oss/endpoint/put-file`
);
// 表单数据
const userInfo = ref({
  id: '',
  avatar: '',
  realName: '',
  name: '',
  phone: '',
  email: '',
  deptName: '',
});
// 校验手机号
const validatePhone = () => {
  const phoneRegex = /^1[3-9]\d{9}$/;
  if (!phoneRegex.test(userInfo.value.phone)) {
    ElMessage.error('请输入正确的手机号码');
    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)) {
        ElMessage.error('请输入正确的邮箱地址')
        return false
    }
    return true
}
const passwordForm = ref({
  oldPassword: '',
  newPassword: '',
  newPassword1: '',
});
// 头像
const beforeAvatarUpload = file => {
  const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
  const isLt500KB = file.size / 1024 < 500;
  if (!isJpgOrPng) {
    ElMessage.error('头像图片只能是 JPG/PNG 格式!');
    return false;
  }
  if (!isLt500KB) {
    ElMessage.error('头像图片大小不能超过 500KB!');
    return false;
  }
  return true;
};
const uploadLoading = ref(false);
 
const customUpload = async options => {
  const { file } = options;
  uploadLoading.value = true;
 
  const formData = new FormData();
  formData.append('file', file); // 根据后端API调整字段名
  try {
    const res = await request.post('/blade-resource/oss/endpoint/put-file', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    });
 
    if (res.data.code === 200) {
      ElMessage.success('头像上传成功');
      userInfo.value.avatar = res.data.data.link;
      return res.data;
    } else {
      throw new Error(res.data.msg || '上传失败');
    }
  } catch (error) {
    ElMessage.error(error.response?.data?.msg || error.message || '上传失败');
    return Promise.reject(error);
  } finally {
    uploadLoading.value = false;
  }
};
 
const titleClick = (item, index) => {
  checked.value = index;
};
const getUserInfoData = () => {
  getUserInfo().then(res => {
    const user = res.data.data;
    userInfo.value = {
      id: user.id,
      avatar: user.avatar,
      name: user.name,
      realName: user.realName,
      phone: user.phone,
      email: user.email,
      deptName: user.deptName,
    };
  });
};
const emit = defineEmits(['logout']);
const submit = () => {
  if (checked.value === 0) {
   if (!validatePhone() || !validateEmail()) return
    userInfo.value.name = userInfo.value.realName;
    updateInfo(userInfo.value).then(res => {
      if (res.data.code === 200) {
        ElMessage.success('修改信息成功!');
        userinforShow.value = false;
      } else {
        ElMessage.error(res.msg);
      }
    });
  } else if (checked.value === 1) {
    updatePassword(
      md5(passwordForm.value.oldPassword),
      md5(passwordForm.value.newPassword),
      md5(passwordForm.value.newPassword1)
    ).then(res => {
      if (res.data.code === 200) {
        ElMessage.success('修改密码成功!');
        // 调用父组件方法
        userinforShow.value = false;
        emit('logout');
      } else {
        ElMessage.error(res.msg);
      }
    });
  }
};
const reset = () => {
  if (checked.value === 0) {
    getUserInfoData();
    userinforShow.value = false;
  } else if (checked.value === 1) {
    passwordForm.value = {
      id: userInfoAs.value.userId,
      oldPassword: '',
      newPassword: '',
      newPassword1: '',
    };
    userinforShow.value = false;
  }
};
const isSuccess = ref('');
const passwordTime = ref('');
const getFindLicenseDate = () => {
  findLicenseDate()
    .then(res => {
      if (res.data.code !== 0) return ElMessage.error('获取失败');
      passwordTime.value = res.data.data;
    })
    .catch(err => {
      ElMessage.error('获取失败');
    });
};
// const dialogImageUrl = ref('')
// const dialogVisible = ref(false)
// const handlePictureCardPreview = () => {}
// const handleRemove = () => {}
onMounted(() => {
  getUserInfoData();
});
</script>
<style scoped lang="scss">
.user-info-new {
  margin: 16px;
  padding: 10px;
  background-color: #ffffff;
}
.titleBoxs {
  margin: 0 24px;
  margin-bottom: 10px;
  // background: url('/src/assets/images/signMachineNest/machineRight/detailtitle.png') no-repeat center;
  // background-size: 100% 100%;
  p {
    display: inline-block;
    margin-left: 30px;
    font-size: 16px;
    color: #000;
    line-height: 20px;
    text-align: left;
    margin-bottom: 8px;
  }
}
:deep(.el-form-item__label) {
  color: #000 !important;
}
:deep(.el-button) {
  width: 150px !important;
}
.info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 80px 0 50px;
}
.password {
  padding: 0 120px 0 50px;
}
.butn {
  // position: absolute;
  // bottom: 20px;
  // left: 50%;
  // transform: translate(-50%);
  display: flex;
  justify-content: center;
  cursor: pointer;
  img {
    width: 96px;
    height: 32px;
  }
}
.titleBoxs {
  display: flex;
  padding: 0 20px;
}
.titleItem {
  color: #61809c;
  font-size: 16px;
  margin-right: 50px;
  cursor: pointer;
}
.activeItem {
  border-radius: 0px 0px 0px 0px;
  color: #51abff;
  border-bottom: 2px solid #198cff;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.upload-tip {
  margin-top: 10px;
  color: #999;
  font-size: 12px;
  text-align: center;
}
.message,
.passwordBox {
  margin-top: 40px;
}
 
</style>