index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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">{{ isLogined ? "微信用户" : "请登录" }}</view>
  20. <!-- <view class="head-name">{{ userInfo.name }}</view> -->
  21. </view>
  22. <view class="main-content mt6">
  23. <!-- TODO: 测试 -->
  24. <!-- <view class="content-item line-b" @click="toTest">
  25. <view>测试页</view>
  26. <wd-icon name="arrow-right" size="20px" color="#808080"></wd-icon>
  27. </view> -->
  28. <view class="content-item line-b" @click="toAddUserHub">
  29. <view>添加打印助手</view>
  30. <wd-icon name="arrow-right" size="20px" color="#808080"></wd-icon>
  31. </view>
  32. <view class="content-item line-b" @click="toJob">
  33. <view>查看打印任务</view>
  34. <wd-icon name="arrow-right" size="20px" color="#808080"></wd-icon>
  35. </view>
  36. <view v-if="isLogined" class="content-item" @click="handleLogout">
  37. <view>退出登录</view>
  38. <wd-icon name="arrow-right" size="20px" color="#808080"></wd-icon>
  39. </view>
  40. <view v-else class="content-item" @click="toLogin()">
  41. <view>前往登录</view>
  42. <wd-icon name="arrow-right" size="20px" color="#808080"></wd-icon>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script lang="ts" setup>
  48. import { logout } from '@/service/api/index'
  49. import { useUserStore } from '@/store'
  50. import { useToast } from 'wot-design-uni'
  51. import { toLogin, toLoginWait } from '@/utils'
  52. // 获取屏幕边界到安全区域距离
  53. const { safeAreaInsets } = uni.getSystemInfoSync()
  54. const userInfo = reactive({
  55. avatar: '',
  56. name: '',
  57. })
  58. const toast = useToast()
  59. const isLogined = computed(() => !!useUserStore().token)
  60. function toAddUserHub() {
  61. if (isLogined.value) {
  62. uni.navigateTo({
  63. url: `/pages/assistant/detail?type=add`,
  64. })
  65. } else {
  66. toast.warning('请先前往登录')
  67. toLogin(1500)
  68. }
  69. }
  70. function toJob() {
  71. if (isLogined.value) {
  72. uni.navigateTo({
  73. url: `/pages/print/job`,
  74. })
  75. } else {
  76. toast.warning('请先前往登录')
  77. toLogin(1500)
  78. }
  79. }
  80. function handleLogout() {
  81. // logout().then((res) => {
  82. // if (res.code === 0) {
  83. // useUserStore().setToken('')
  84. // useUserStore().setAvatar('')
  85. // useUserStore().setUserInfo({})
  86. // toast.success('退出登录成功')
  87. // toLogin()
  88. // }
  89. // })
  90. useUserStore().clearUserInfo()
  91. toast.success('退出登录成功')
  92. toLoginWait(1500)
  93. }
  94. function initFn() {
  95. // userInfo.name = useUserStore().userInfo.name
  96. // userInfo.avatar = useUserStore().userInfo.avatar
  97. userInfo.name = "微信用户"
  98. userInfo.avatar = "/static/images/avatar.png"
  99. }
  100. function toTest() {
  101. if (isLogined.value) {
  102. uni.navigateTo({
  103. url: `/pages/test/index`,
  104. })
  105. } else {
  106. toast.warning('请先前往登录')
  107. toLogin(1500)
  108. }
  109. }
  110. onLoad(() => {
  111. initFn()
  112. })
  113. </script>
  114. <style lang="scss" scoped>
  115. .head {
  116. display: flex;
  117. align-items: center;
  118. .head-name {
  119. @apply pl-3;
  120. }
  121. }
  122. .main-content {
  123. padding: 20rpx;
  124. background-color: white;
  125. border-radius: 16rpx;
  126. }
  127. .content-item {
  128. display: flex;
  129. align-items: start;
  130. justify-content: space-between;
  131. padding: 30rpx 0;
  132. }
  133. .line-b {
  134. border-bottom: 1px solid #eee;
  135. }
  136. :deep(.head .wd-upload__evoke) {
  137. width: 80rpx;
  138. height: 80rpx;
  139. margin-bottom: 0;
  140. border-radius: 100%;
  141. }
  142. :deep(.wd-upload) {
  143. display: flex;
  144. }
  145. :deep(.wd-upload__evoke-num) {
  146. display: none;
  147. }
  148. :deep(.wd-icon) {
  149. font-size: 50rpx;
  150. }
  151. :deep(.img-btn .wd-img__image) {
  152. width: 80rpx;
  153. height: 80rpx;
  154. border-radius: 40rpx;
  155. }
  156. :deep(.wd-upload__preview) {
  157. display: none !important;
  158. }
  159. :deep(.gray-btn.wd-button) {
  160. width: 80rpx;
  161. height: 80rpx;
  162. background-color: #ddd;
  163. border-radius: 40rpx;
  164. }
  165. :deep(.form-ipt) {
  166. padding-right: 0 !important;
  167. padding-left: 0 !important;
  168. }
  169. </style>