index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="block">
  3. <!-- <div class="user-header rounded-sm text-center">
  4. <div class="pt-3 mx-auto avatar-box">
  5. <sa-upload-image v-model="userInfo.avatar" rounded />
  6. </div>
  7. <div>
  8. <a-tag size="large" class="mt-3 rounded-full tag-primary">
  9. {{ (userStore.user && userStore.user.nickname) || (userStore.user && userStore.user.username) }}
  10. </a-tag>
  11. </div>
  12. </div> -->
  13. <a-layout-content class="block lg:flex lg:justify-between">
  14. <div class="ma-content-block w-full lg:w-6/12 mt-3 p-4">
  15. <a-tabs type="rounded">
  16. <a-tab-pane key="info" title="个人资料">
  17. <user-infomation />
  18. </a-tab-pane>
  19. <a-tab-pane key="safe" title="安全设置">
  20. <modify-password />
  21. </a-tab-pane>
  22. </a-tabs>
  23. </div>
  24. <div class="ma-content-block w-full lg:w-6/12 mt-3 p-4 ml-0 lg:ml-3">
  25. <a-tabs type="rounded">
  26. <a-tab-pane key="login-log" title="登录日志">
  27. <a-timeline
  28. class="pl-5 mt-3"
  29. v-if="loginLogList && loginLogList.length"
  30. >
  31. <a-timeline-item
  32. :label="`地理位置;${item.ip_location},操作系统:${item.os}`"
  33. v-for="(item, idx) in loginLogList"
  34. :key="idx"
  35. >
  36. 您于 {{ item.login_time }} 登录系统,{{ item.message }}
  37. </a-timeline-item>
  38. </a-timeline>
  39. <a-empty v-else />
  40. </a-tab-pane>
  41. <a-tab-pane key="operation-log" title="操作日志">
  42. <a-timeline
  43. class="pl-5 mt-3"
  44. v-if="operationLogList && operationLogList.length"
  45. >
  46. <a-timeline-item
  47. :label="`地理位置;${item.ip_location},方式:${item.method},路由:${item.router}`"
  48. v-for="(item, idx) in operationLogList"
  49. :key="idx"
  50. >
  51. 您于 {{ item.create_time }} 执行了 {{ item.service_name }}
  52. </a-timeline-item>
  53. </a-timeline>
  54. <a-empty v-else />
  55. </a-tab-pane>
  56. </a-tabs>
  57. </div>
  58. </a-layout-content>
  59. </div>
  60. </template>
  61. <script setup>
  62. import { ref, reactive, onMounted, watch } from "vue";
  63. import { useUserStore } from "@/store";
  64. import { Message } from "@arco-design/web-vue";
  65. import user from "@/api/system/user";
  66. import commonApi from "@/api/common";
  67. import ModifyPassword from "./components/modifyPassword.vue";
  68. import UserInfomation from "./components/userInfomation.vue";
  69. const userStore = useUserStore();
  70. const userInfo = reactive({
  71. ...userStore.user,
  72. });
  73. const loginLogList = ref([]);
  74. const operationLogList = ref([]);
  75. const requestParams = reactive({
  76. limit: 5,
  77. });
  78. onMounted(() => {
  79. commonApi
  80. .getLoginLogList(
  81. Object.assign(requestParams, { orderBy: "login_time", orderType: "desc" })
  82. )
  83. .then((res) => {
  84. loginLogList.value = res.data.data;
  85. });
  86. commonApi
  87. .getOperationLogList(
  88. Object.assign(requestParams, {
  89. orderBy: "create_time",
  90. orderType: "desc",
  91. })
  92. )
  93. .then((res) => {
  94. operationLogList.value = res.data.data;
  95. });
  96. });
  97. userInfo.avatar = userStore?.user?.avatar ?? undefined;
  98. watch(
  99. () => userInfo.avatar,
  100. async (newAvatar) => {
  101. if (newAvatar) {
  102. const response = await user.updateInfo({ avatar: newAvatar });
  103. if (response.code === 200) {
  104. Message.success("头像修改成功");
  105. userStore.user.avatar = newAvatar;
  106. }
  107. }
  108. }
  109. );
  110. </script>
  111. <script>
  112. export default { name: "userCenter" };
  113. </script>
  114. <style scoped>
  115. .avatar-box {
  116. width: 130px;
  117. }
  118. .user-header {
  119. width: 100%;
  120. height: 200px;
  121. background: url("@/assets/userBanner.jpg") no-repeat;
  122. background-size: cover;
  123. }
  124. </style>