index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <div class="page_container">
  3. <img :src="bg" mode="" />
  4. <view class="w-[90%] h-[98px] rounded-md bg-white flex items-center pl-4 pr-2 mx-auto mt-[-60px]">
  5. <Avatar :size="46" :src="userStore.storeSelfInfo.faceURL" :desc="userStore.storeSelfInfo.nickname" />
  6. <view class="id_row flex justify-between items-start h-[46px] flex-col flex-1 ml-2">
  7. <text class="nickname">{{ userStore.storeSelfInfo.nickname }}</text>
  8. <view class="flex items-center" @click="copyUserID">
  9. <text class=" text-sub-text text-sm">{{ userStore.storeSelfInfo.userID }}</text>
  10. <img style="width: 16px; height: 16px" :src="copy_icon" mode="" />
  11. </view>
  12. </view>
  13. <view class="flex flex-row items-center" @click="$router.push('selfOrGroupQr')">
  14. <img class="w-[18px] h-[18px]" :src="qr_code" alt="" />
  15. <img class="w-[24px] h-[24px]" :src="back" alt="" />
  16. </view>
  17. </view>
  18. <div class="w-[90%] mx-auto mt-[10px] bg-white rounded-md">
  19. <div v-for="(menu, idx) in profileMenus" :key="idx" class="flex items-center justify-between p-4"
  20. @click="menuClick(menu.route)">
  21. <div class="flex">
  22. <img width="24" :src="menu.icon" alt="" />
  23. <span class="ml-3">{{ menu.title }}</span>
  24. </div>
  25. <img :src="back" width="24" alt="back">
  26. </div>
  27. </div>
  28. </div>
  29. </template>
  30. <script name="profile" setup lang='ts'>
  31. import Avatar from '@/components/Avatar/index.vue';
  32. import qr_code from '@assets/images/profile/qr_code.png'
  33. import info from '@assets/images/profile/info.png'
  34. import settings from '@assets/images/profile/settings.png'
  35. import about from '@assets/images/profile/about.png'
  36. import logout from '@assets/images/profile/logout.png'
  37. import back from '@assets/images/profile/back.png'
  38. import copy_icon from '@assets/images/profile/copy.png'
  39. import bg from '@assets/images/profile/bg.png'
  40. import { showConfirmDialog, showToast } from 'vant';
  41. import useUserStore from '@/store/modules/user';
  42. import { useClipboard } from '@vueuse/core';
  43. const { copy, isSupported } = useClipboard();
  44. const { t, locale } = useI18n()
  45. const profileMenus = [
  46. {
  47. icon: info,
  48. title: t("profileMenu.personalInformation"),
  49. route: 'selfInfoDetails'
  50. },
  51. {
  52. icon: settings,
  53. title: t("profileMenu.accountSetting"),
  54. route: 'accountSettings'
  55. },
  56. {
  57. icon: about,
  58. title: t("profileMenu.aboutUs"),
  59. route: 'about'
  60. },
  61. {
  62. icon: logout,
  63. title: t("profileMenu.logOut"),
  64. },
  65. ]
  66. watch(locale, () => {
  67. profileMenus[0].title = t("profileMenu.personalInformation");
  68. profileMenus[1].title = t("profileMenu.accountSetting");
  69. profileMenus[2].title = t("profileMenu.aboutUs");
  70. profileMenus[3].title = t("profileMenu.logOut");
  71. });
  72. const router = useRouter()
  73. const userStore = useUserStore()
  74. const menuClick = (route?: string) => {
  75. if (route) {
  76. router.push(route)
  77. } else {
  78. tryLogout()
  79. }
  80. }
  81. const copyUserID = () => {
  82. if (isSupported) {
  83. copy(userStore.storeSelfInfo.userID);
  84. }
  85. showToast(isSupported ? t('messageTip.copySuccess') : t('messageTip.environmentNotSupported'));
  86. };
  87. const tryLogout = () => {
  88. showConfirmDialog({
  89. message: t('messageTip.tryLogout'),
  90. beforeClose: (action: string) => {
  91. return new Promise((resolve) => {
  92. if (action !== 'confirm') {
  93. resolve(true);
  94. return
  95. }
  96. userStore.userLogout()
  97. .finally(() => {
  98. resolve(true)
  99. window.location.href = '/login'
  100. })
  101. })
  102. }
  103. }).catch(() => { })
  104. }
  105. </script>
  106. <style lang='scss' scoped></style>