index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <route lang="json5" type="page">
  2. {
  3. layout: 'default',
  4. style: {
  5. navigationBarTitleText: '我的',
  6. },
  7. }
  8. </route>
  9. <template>
  10. <view class="main overflow-hidden pt-2 px4" :style="{ marginTop: safeAreaInsets?.top + 'px' }">
  11. <view class="head">
  12. <wd-img
  13. v-if="userInfo.avatar"
  14. custom-class="img-btn"
  15. :width="40"
  16. :height="40"
  17. :src="userInfo.avatar"
  18. />
  19. <view class="head-name">{{ userInfo.name }}</view>
  20. </view>
  21. <view class="main-content mt6">
  22. <view class="content-item line-b" @click="toAddUserHub">
  23. <view>添加打印助手</view>
  24. <wd-icon name="arrow-right" size="20px" color="#808080"></wd-icon>
  25. </view>
  26. <view v-if="isLogined" class="content-item" @click="handleLogout">
  27. <view>退出登录</view>
  28. <wd-icon name="arrow-right" size="20px" color="#808080"></wd-icon>
  29. </view>
  30. <view v-else class="content-item" @click="toLogin">
  31. <view>前往登录</view>
  32. <wd-icon name="arrow-right" size="20px" color="#808080"></wd-icon>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script lang="ts" setup>
  38. import { logout } from '@/service/api/index'
  39. import { useUserStore } from '@/store'
  40. import { useToast } from 'wot-design-uni'
  41. // 获取屏幕边界到安全区域距离
  42. const { safeAreaInsets } = uni.getSystemInfoSync()
  43. const userInfo = reactive({
  44. avatar: '',
  45. name: '',
  46. })
  47. const toast = useToast()
  48. const isLogined = computed(() => !!useUserStore().token)
  49. function toAddUserHub() {
  50. if (isLogined.value) {
  51. uni.navigateTo({
  52. url: `/pages/assistant/detail?type=add`,
  53. })
  54. } else {
  55. toast.warning('请先前往登录')
  56. }
  57. }
  58. function handleLogout() {
  59. // logout().then((res) => {
  60. // if (res.code === 0) {
  61. // useUserStore().setToken('')
  62. // useUserStore().setAvatar('')
  63. // useUserStore().setUserInfo({})
  64. // toast.success('退出登录成功')
  65. // toLogin()
  66. // }
  67. // })
  68. useUserStore().clearUserInfo()
  69. toast.success('退出登录成功')
  70. toLogin()
  71. }
  72. function toLogin() {
  73. uni.reLaunch({
  74. url: `/pages/login/index?isLogout=1`,
  75. })
  76. }
  77. function initFn() {
  78. // userInfo.name = useUserStore().userInfo.name
  79. // userInfo.avatar = useUserStore().userInfo.avatar
  80. userInfo.name = "微信用户"
  81. userInfo.avatar = "/static/images/avatar.png"
  82. }
  83. onLoad(() => {
  84. initFn()
  85. })
  86. </script>
  87. <style lang="scss" scoped>
  88. .head {
  89. display: flex;
  90. align-items: center;
  91. .head-name {
  92. @apply pl-3;
  93. }
  94. }
  95. .main-content {
  96. padding: 20rpx;
  97. background-color: white;
  98. border-radius: 16rpx;
  99. }
  100. .content-item {
  101. display: flex;
  102. align-items: start;
  103. justify-content: space-between;
  104. padding: 30rpx 0;
  105. }
  106. .line-b {
  107. border-bottom: 1px solid #eee;
  108. }
  109. :deep(.head .wd-upload__evoke) {
  110. width: 80rpx;
  111. height: 80rpx;
  112. margin-bottom: 0;
  113. border-radius: 100%;
  114. }
  115. :deep(.wd-upload) {
  116. display: flex;
  117. }
  118. :deep(.wd-upload__evoke-num) {
  119. display: none;
  120. }
  121. :deep(.wd-icon) {
  122. font-size: 50rpx;
  123. }
  124. :deep(.img-btn .wd-img__image) {
  125. width: 80rpx;
  126. height: 80rpx;
  127. border-radius: 40rpx;
  128. }
  129. :deep(.wd-upload__preview) {
  130. display: none !important;
  131. }
  132. :deep(.gray-btn.wd-button) {
  133. width: 80rpx;
  134. height: 80rpx;
  135. background-color: #ddd;
  136. border-radius: 40rpx;
  137. }
  138. :deep(.form-ipt) {
  139. padding-right: 0 !important;
  140. padding-left: 0 !important;
  141. }
  142. </style>