index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <div class="flex" v-loading="loading">
  3. <el-card class="workspace-info w-full" shadow="always" style="padding-bottom: 40px;">
  4. <template #header>
  5. <div class="card-header" style="display: flex; align-items: center; justify-content: space-between;">
  6. <span style="flex-grow: 1; text-align: center;font-weight: bold;">个人信息</span>
  7. <div class="pull-right">
  8. <el-button type="primary" @click="openDialog">修改</el-button>
  9. </div>
  10. </div>
  11. </template>
  12. <ul class="user-info">
  13. <div class="info-row">
  14. <li class="info-item">
  15. <Icon class="mr-5px" icon="ep:user" />
  16. <span class="info-label">姓名:</span>
  17. <span class="pull-right">{{ userInfo.nickname }}</span>
  18. </li>
  19. <li class="info-item">
  20. <Icon class="mr-5px" icon="ep:location" />
  21. <span class="info-label">工作间:</span>
  22. <span class="pull-right">{{ userInfo.dept ? userInfo.dept.name : '未知部门' }}</span>
  23. </li>
  24. </div>
  25. <div class="info-row">
  26. <li class="info-item">
  27. <Icon class="mr-5px" icon="ep:phone" />
  28. <span class="info-label">手机号码:</span>
  29. <span class="pull-right">{{ userInfo.mobile }}</span>
  30. </li>
  31. <li class="info-item">
  32. <Icon class="mr-5px" icon="fontisto:email" />
  33. <span class="info-label">邮箱:</span>
  34. <span class="pull-right">{{ userInfo.email }}</span>
  35. </li>
  36. </div>
  37. <div class="info-row">
  38. <li class="info-item">
  39. <Icon class="mr-5px" icon="ep:user" />
  40. <span class="info-label">用户类型:</span>
  41. <span class="pull-right"> {{ userTypeMapping[userInfo.userType] || '未知用户类型' }}</span>
  42. </li>
  43. <li class="info-item">
  44. <Icon class="mr-5px" icon="ep:bell" />
  45. <span class="info-label">工号:</span>
  46. <span class="pull-right">{{ userInfo.userNumber }}</span>
  47. </li>
  48. </div>
  49. </ul>
  50. <div class="info-remark">
  51. <div style="display: flex; align-items: center;">
  52. <Icon icon="fontisto:email" />
  53. <div class="div-label" style="margin-left: 8px;">个人简历:</div>
  54. </div>
  55. <div class="remark-content">userInfo.introduction</div>
  56. </div>
  57. <div class="info-remark">
  58. <div style="display: flex; align-items: center;">
  59. <Icon icon="ep:picture" />
  60. <div class="div-label" style="margin-left: 8px;">简介:</div>
  61. </div>
  62. <div class="remark-content">{{ cleanedremark }}</div>
  63. <div class="image-container">
  64. <div v-for="(url, index) in extractedImageUrls" :key="index" class="image-item">
  65. <img :src="url" />
  66. </div>
  67. </div>
  68. </div>
  69. </el-card>
  70. <TForm
  71. ref="formRef"
  72. :visible="dialogVisible"
  73. :form="userInfo"
  74. @update:visible="dialogVisible = $event"
  75. @success="handleSuccess"
  76. />
  77. </div>
  78. </template>
  79. <script lang="ts">
  80. import { defineComponent, reactive, ref, onMounted } from 'vue';
  81. import { useI18n } from 'vue-i18n';
  82. import { useMessage } from '@/hooks/web/useMessage';
  83. import TForm from './TForm.vue';
  84. import { getUserProfile, ProfileVO } from '@/api/system/user/profile'
  85. export default defineComponent({
  86. components: {
  87. TForm,
  88. },
  89. setup() {
  90. const { t } = useI18n();
  91. const message = useMessage();
  92. const dialogVisible = ref(false);
  93. const loading = ref(true) // 列表的加载中
  94. const formRef = ref();
  95. const form = reactive({
  96. mobile: '',
  97. email: '',
  98. nickname: '',
  99. password: '',
  100. sex: undefined,
  101. remark: '',
  102. userType: undefined,
  103. userNumber: '',
  104. dept: undefined,
  105. deptId: undefined,
  106. });
  107. // 将 userInfo 定义放入 setup 中
  108. const userInfo = ref({} as ProfileVO)
  109. const getUserInfo = async () => {
  110. try {
  111. loading.value = true;
  112. const users = await getUserProfile();
  113. console.log(users, 'users');
  114. userInfo.value = users;
  115. } catch (error) {
  116. console.error('获取用户信息失败:', error);
  117. } finally {
  118. loading.value = false; // 隐藏加载中
  119. }
  120. }
  121. const userTypeMapping = {
  122. '3': '导师',
  123. '5': '外聘导师',
  124. };
  125. const downloadPDF = () => {
  126. const url = userInfo.value.introduction
  127. if (!url) {
  128. message.error('没有简历文件!');
  129. return;
  130. }
  131. // 先预览
  132. // const link = document.createElement('a'); // 创建一个链接元素
  133. // link.href = url; // 设置链接地址
  134. // link.download = '下载文件.pdf'; // 设置下载文件的名称
  135. // document.body.appendChild(link); // 将链接添加到文档中
  136. // link.click(); // 触发下载
  137. // document.body.removeChild(link); // 下载后移除链接
  138. // 直接下载
  139. // 创建一个下载链接
  140. fetch(url)
  141. .then(response => {
  142. if (!response.ok) {
  143. throw new Error('网络错误');
  144. }
  145. return response.blob(); // 将响应转换为 Blob 对象
  146. })
  147. .then(blob => {
  148. const link = document.createElement('a');
  149. const blobUrl = URL.createObjectURL(blob); // 创建 Blob URL
  150. link.href = blobUrl;
  151. link.download = '下载文件.pdf'; // 设置下载文件的名称
  152. document.body.appendChild(link);
  153. link.click(); // 触发下载
  154. document.body.removeChild(link); // 下载后移除链接
  155. URL.revokeObjectURL(blobUrl); // 释放 Blob URL
  156. })
  157. .catch(error => {
  158. console.error('下载失败:', error);
  159. });
  160. }
  161. const openDialog = () => {
  162. loading.value = true; // 显示加载中
  163. dialogVisible.value = true;
  164. formRef.value.open(); // 打开弹窗
  165. loading.value = false; // 关闭加载状态
  166. };
  167. const extractedImageUrls = ref<string[]>([]);
  168. const handleSuccess = (urls) => {
  169. extractedImageUrls.value = urls;
  170. console.log('提取到的图片URL:', extractedImageUrls);
  171. dialogVisible.value = false;
  172. getUserInfo(); // 更新用户信息
  173. };
  174. const fetchImageUrls = async () => {
  175. try {
  176. loading.value = true; // 开始加载
  177. const res = await getUserProfile();
  178. const urls = res.remark.match(/<img.*?src="(.*?)"/g);
  179. if (urls) {
  180. extractedImageUrls.value = urls.map(url => {
  181. const match = url.match(/src="(.*?)"/);
  182. return match ? match[1] : '';
  183. });
  184. } else {
  185. extractedImageUrls.value = [];
  186. }
  187. } catch (error) {
  188. console.error('获取图片 URL 失败:', error);
  189. } finally {
  190. loading.value = false; // 完成加载
  191. }
  192. };
  193. // 创建一个 computed 属性来处理并去掉 <p> 标签
  194. const cleanedremark = computed(() => {
  195. return userInfo.value.remark ? userInfo.value.remark.replace(/<\/?[^>]+(>|$)/g, '') : '';
  196. });
  197. // // 表单提交
  198. // const submit = async () => {
  199. // try {
  200. // await formRef.value?.validate();
  201. // console.log('提交的数据:', form);
  202. // await updateDept(form).then((res) => {
  203. // console.log('更新成功:', res);
  204. // });
  205. // message.success('成功');
  206. // } catch (error) {
  207. // console.error('提交错误:', error);
  208. // message.error('错误');
  209. // }
  210. // };
  211. // // 表单重置
  212. // const init = async () => {
  213. // const res = await getUserProfile();
  214. // console.log('获取的数据:', res);
  215. // form.id = res.id;
  216. // form.address = res.address;
  217. // form.supervisor = res.user.nickname;
  218. // form.phone = res.phone;
  219. // form.email = res.email;
  220. // form.name = res.name;
  221. // form.leaderUserId = res.user.id;
  222. // form.remark = res.remark;
  223. // userInfo.value = res.user;
  224. // };
  225. onMounted(async () => {
  226. // await init();
  227. await getUserInfo();
  228. await fetchImageUrls(); // 这里 add 一個方法来加载图片
  229. });
  230. return {
  231. t,
  232. // form,
  233. userInfo,
  234. loading,
  235. // init,
  236. getUserInfo,
  237. fetchImageUrls,
  238. formRef,
  239. dialogVisible,
  240. openDialog,
  241. handleSuccess,
  242. extractedImageUrls,
  243. cleanedremark,
  244. userTypeMapping,
  245. downloadPDF,
  246. };
  247. }
  248. });
  249. </script>
  250. <style scoped>
  251. .user-info {
  252. margin-top: 10px;
  253. margin-left: 5%;
  254. margin-right: 5%;
  255. padding-right: 0;
  256. padding-left: 0;
  257. border-right: 0;
  258. border-left: 0;
  259. border-radius: 0;
  260. list-style: none;
  261. }
  262. .info-row {
  263. display: flex;
  264. justify-content: space-between; /* 保持并排显示 */
  265. align-items: center; /* 垂直居中对齐 */
  266. margin-bottom: 20px; /* 增加行之间的间距 */
  267. }
  268. .info-item {
  269. flex: 1; /* 每个信息项占据相同的空间 */
  270. padding: 11px 0; /* 内部上下填充 */
  271. margin-right: 50px; /* 每个信息项之间的右边距 */
  272. }
  273. /* 仅为每个信息项添加底部边框 */
  274. .info-item:first-child {
  275. border-bottom: 1px solid #e7eaec;
  276. }
  277. .info-item:last-child {
  278. border-bottom: 1px solid #e7eaec;
  279. }
  280. .info-remark {
  281. margin-top: 30px; /* 与上面的信息分隔 */
  282. margin-left: 5%; /* 左侧与上面列表保持一致 */
  283. margin-right: 5%; /* 右侧与上面列表保持一致 */
  284. /* display: flex; */
  285. align-items: center; /* 确保标题与描述对齐 */
  286. align-items: flex-start;
  287. }
  288. .info-label {
  289. font-weight: bold; /* 加粗标题 */
  290. margin-right: 10px; /* 标题与内容之间的间距 */
  291. }
  292. .div-label {
  293. font-weight: bold; /* 加粗标题 */
  294. display: block;
  295. }
  296. .remark-content {
  297. white-space: pre-wrap; /* 保持换行 */
  298. overflow-wrap: break-word; /* 自动断行 */
  299. margin-right: 5%;
  300. font-size: 13px; /* 根据需要设置字体大小 */
  301. margin-top: 20px; /* 内容与标题之间不需要额外间距 */
  302. letter-spacing: 3px;
  303. text-indent: 2em;
  304. line-height: 2;
  305. }
  306. .pull-right {
  307. float: right !important;
  308. }
  309. .info-label {
  310. font-weight: bold;
  311. }
  312. .image-container {
  313. display: flex; /* 使图片横向排列 */
  314. flex-wrap: wrap; /* 如果空间不足则换行 */
  315. gap: 10px; /* 图片之间的间距 */
  316. margin-left: 20px; /* 左边距,根据需要设置 */
  317. }
  318. .image-item img {
  319. width: 150px; /* 设置更大的宽度 */
  320. height: auto; /* 保持高度自动 */
  321. }
  322. </style>