user.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view class="">
  3. <view class="center">
  4. <view class="logo" @click="bindLogin" :hover-class="!hasLogin ? 'logo-hover' : ''">
  5. <image class="logo-img" :src="avatarUrl"></image>
  6. <view class="logo-title">
  7. <text class="uer-name">Hi,{{hasLogin ? userName : '您未登录'}}</text>
  8. <text class="go-login navigat-arrow" v-if="!hasLogin">&#xe65e;</text>
  9. </view>
  10. </view>
  11. <view class="center-list">
  12. <view class="center-list-item border-bottom">
  13. <text class="list-icon">&#xe60f;</text>
  14. <text class="list-text">帐号管理</text>
  15. <text class="navigat-arrow">&#xe65e;</text>
  16. </view>
  17. <view class="center-list-item">
  18. <text class="list-icon">&#xe639;</text>
  19. <text class="list-text">新消息通知</text>
  20. <text class="navigat-arrow">&#xe65e;</text>
  21. </view>
  22. </view>
  23. <view class="center-list">
  24. <view class="center-list-item border-bottom">
  25. <text class="list-icon">&#xe60b;</text>
  26. <text class="list-text">帮助与反馈</text>
  27. <text class="navigat-arrow">&#xe65e;</text>
  28. </view>
  29. <view class="center-list-item">
  30. <text class="list-icon">&#xe65f;</text>
  31. <text class="list-text">服务条款及隐私</text>
  32. <text class="navigat-arrow">&#xe65e;</text>
  33. </view>
  34. </view>
  35. <view class="center-list">
  36. <view class="center-list-item">
  37. <text class="list-icon">&#xe614;</text>
  38. <text class="list-text">关于应用</text>
  39. <text class="navigat-arrow">&#xe65e;</text>
  40. </view>
  41. </view>
  42. <view class="btn-row">
  43. <button v-if="hasLogin" class="primary" type="primary" @tap="bindLogout">退出登录</button>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import {
  50. mapState,
  51. mapMutations
  52. } from 'vuex'
  53. export default {
  54. data() {
  55. return {
  56. avatarUrl: "../../static/img/logo.png",
  57. }
  58. },
  59. computed: {
  60. ...mapState(['hasLogin', 'forcedLogin', 'userName'])
  61. },
  62. methods: {
  63. ...mapMutations(['logout']),
  64. bindLogin() {
  65. uni.navigateTo({
  66. url: '../login/login',
  67. });
  68. },
  69. bindLogout() {
  70. const loginType = uni.getStorageSync('login_type')
  71. if (loginType === 'local') {
  72. this.logout();
  73. if (this.forcedLogin) {
  74. uni.reLaunch({
  75. url: '../login/login',
  76. });
  77. }
  78. return
  79. }
  80. uniCloud.callFunction({
  81. name: 'user-center',
  82. data: {
  83. action: 'logout'
  84. },
  85. success: (e) => {
  86. console.log('logout success', e);
  87. if (e.result.code == 0) {
  88. this.logout();
  89. uni.removeStorageSync('uniIdToken')
  90. uni.removeStorageSync('username')
  91. /**
  92. * 如果需要强制登录跳转回登录页面
  93. */
  94. if (this.forcedLogin) {
  95. uni.reLaunch({
  96. url: '../login/login',
  97. });
  98. }
  99. } else {
  100. uni.showModal({
  101. content: e.result.msg,
  102. showCancel: false
  103. })
  104. console.log('登出失败', e);
  105. }
  106. },
  107. fail(e) {
  108. uni.showModal({
  109. content: JSON.stringify(e),
  110. showCancel: false
  111. })
  112. }
  113. })
  114. }
  115. }
  116. }
  117. </script>
  118. <style>
  119. @font-face {
  120. font-family: texticons;
  121. font-weight: normal;
  122. font-style: normal;
  123. src: url('https://at.alicdn.com/t/font_984210_5cs13ndgqsn.ttf') format('truetype');
  124. }
  125. page,
  126. view {
  127. display: flex;
  128. }
  129. page {
  130. background-color: #f8f8f8;
  131. }
  132. button {
  133. width: 100%;
  134. }
  135. .center {
  136. flex-direction: column;
  137. }
  138. .logo {
  139. width: 750rpx;
  140. height: 240rpx;
  141. padding: 20rpx;
  142. box-sizing: border-box;
  143. background-color: #0faeff;
  144. flex-direction: row;
  145. align-items: center;
  146. }
  147. .logo-hover {
  148. opacity: 0.8;
  149. }
  150. .logo-img {
  151. width: 150rpx;
  152. height: 150rpx;
  153. border-radius: 150rpx;
  154. }
  155. .logo-title {
  156. height: 150rpx;
  157. flex: 1;
  158. align-items: center;
  159. justify-content: space-between;
  160. flex-direction: row;
  161. margin-left: 20rpx;
  162. }
  163. .uer-name {
  164. height: 60rpx;
  165. line-height: 60rpx;
  166. font-size: 38rpx;
  167. color: #FFFFFF;
  168. }
  169. .go-login.navigat-arrow {
  170. font-size: 38rpx;
  171. color: #FFFFFF;
  172. }
  173. .login-title {
  174. height: 150rpx;
  175. align-items: self-start;
  176. justify-content: center;
  177. flex-direction: column;
  178. margin-left: 20rpx;
  179. }
  180. .center-list {
  181. background-color: #FFFFFF;
  182. margin-top: 20rpx;
  183. width: 750rpx;
  184. flex-direction: column;
  185. }
  186. .center-list-item {
  187. height: 90rpx;
  188. width: 750rpx;
  189. box-sizing: border-box;
  190. flex-direction: row;
  191. padding: 0rpx 20rpx;
  192. }
  193. .border-bottom {
  194. border-bottom-width: 1rpx;
  195. border-color: #c8c7cc;
  196. border-bottom-style: solid;
  197. }
  198. .list-icon {
  199. width: 40rpx;
  200. height: 90rpx;
  201. line-height: 90rpx;
  202. font-size: 34rpx;
  203. color: #0faeff;
  204. text-align: center;
  205. font-family: texticons;
  206. margin-right: 20rpx;
  207. }
  208. .list-text {
  209. height: 90rpx;
  210. line-height: 90rpx;
  211. font-size: 34rpx;
  212. color: #555;
  213. flex: 1;
  214. text-align: left;
  215. }
  216. .navigat-arrow {
  217. height: 90rpx;
  218. width: 40rpx;
  219. line-height: 90rpx;
  220. font-size: 34rpx;
  221. color: #555;
  222. text-align: right;
  223. font-family: texticons;
  224. }
  225. </style>