index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view class="user-content">
  3. <!-- 头部 -->
  4. <view class="user-head" >
  5. <view>
  6. <open-data type="userAvatarUrl" class="user-photo"></open-data>
  7. <u-image v-show="!hasLogin" src="/static/logo.png" width="100" height="100"></u-image>
  8. </view>
  9. <view class="user-info">
  10. <view v-if="hasLogin" class="user-info-item">{{userData.stationName || ''}}</view>
  11. <view v-if="hasLogin" class="user-info-item">{{userData.gatherName||''}} {{userData.gatherPhone || ''}}</view>
  12. <u-button v-else="!hasLogin" plain size="mini" shape="circle" @click="toLoginPage">立即登录</u-button>
  13. </view>
  14. </view>
  15. <!-- 列表 -->
  16. <view class="user-list">
  17. <u-cell-group>
  18. <u-cell-item icon="file-text" icon-size="40" :icon-style="{color:'#ffaa00'}" index="0" @click="toPage" title="服务协议及隐私政策"></u-cell-item>
  19. <u-cell-item v-if="hasLogin" icon="lock" icon-size="38" :icon-style="{color:'#00aaff'}" index="1" @click="toPage" title="修改密码"></u-cell-item>
  20. </u-cell-group>
  21. </view>
  22. <view class="user-list quit">
  23. <u-cell-group>
  24. <u-cell-item v-if="hasLogin" icon="minus-circle" icon-size="40" index="3" @click="quitSys" title="退出登录"></u-cell-item>
  25. </u-cell-group>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import { checkLogin, getUserInfo, logout } from '@/api/login.js'
  31. export default {
  32. data() {
  33. return {
  34. hasLogin: false,
  35. userData: {},
  36. };
  37. },
  38. onShow() {
  39. checkLogin().then(res => {
  40. this.hasLogin = res.status == 200
  41. console.log(this.hasLogin,res,'this.hasLogin')
  42. if(this.hasLogin){
  43. this.getUserInfo()
  44. }else{
  45. // uni.navigateTo({
  46. // url:"/pages/login/login"
  47. // })
  48. }
  49. })
  50. },
  51. computed: {
  52. user() {
  53. return this.userData
  54. }
  55. },
  56. onLoad() {
  57. // 开启分享
  58. uni.showShareMenu({
  59. withShareTicket: true,
  60. menus: ['shareAppMessage', 'shareTimeline']
  61. })
  62. },
  63. methods:{
  64. // 获取用户信息
  65. getUserInfo(){
  66. getUserInfo().then(res => {
  67. console.log(res,'getUserInfo')
  68. if(res.status == 200){
  69. this.$u.vuex("vuex_userData",res.data)
  70. this.userData = res.data
  71. console.log(this.userData,'-----用户信息')
  72. }
  73. })
  74. },
  75. // 打开对应的页面
  76. toPage(index){
  77. console.log(index)
  78. let pageUrl=[
  79. '/pages/agreement/agreement?fromPage=usercenter',
  80. '/pages/userCenter/changePwd',
  81. ]
  82. uni.navigateTo({
  83. url: pageUrl[index]
  84. })
  85. },
  86. // 退出登录
  87. quitSys(){
  88. let _this = this
  89. uni.showModal({
  90. title: '提示',
  91. content: '您确定要退出登录吗?',
  92. success(res) {
  93. if (res.confirm) {
  94. logout().then(res => {
  95. console.log(res,'logout')
  96. getApp().globalData.token = ''
  97. _this.$u.vuex('vuex_token','')
  98. // 关闭socket
  99. uni.reLaunch({
  100. url: '/pages/login/login'
  101. })
  102. })
  103. }
  104. }
  105. })
  106. },
  107. toLoginPage(){
  108. uni.navigateTo({
  109. url: '/pages/login/login'
  110. })
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss">
  116. .user-content{
  117. width: 100%;
  118. .user-head{
  119. background: #0DC55F;
  120. display: flex;
  121. align-items: center;
  122. padding: 35rpx 55rpx;
  123. .user-info{
  124. flex-grow: 1;
  125. padding: 0 20rpx;
  126. color: #FFFFFF;
  127. .user-info-item{
  128. margin: 10rpx 0;
  129. :first-child{
  130. font-size: 34upx;
  131. }
  132. }
  133. }
  134. .user-photo{
  135. display: block;
  136. width: 100rpx;
  137. height: 100rpx;
  138. border-radius: 50%;
  139. overflow: hidden;
  140. }
  141. }
  142. .my-ledou{
  143. background: #FFFFFF;
  144. border-radius: 15upx;
  145. display: flex;
  146. align-items: center;
  147. justify-content: space-between;
  148. padding: 20upx;
  149. margin: 20upx;
  150. box-shadow: 0upx 3upx 6upx #eee;
  151. .user-jifen{
  152. display: flex;
  153. align-items: center;
  154. text{
  155. font-size: 40upx;
  156. font-weight: bold;
  157. color: red;
  158. }
  159. >view{
  160. &:first-child{
  161. display: flex;
  162. align-items: center;
  163. }
  164. }
  165. }
  166. }
  167. .user-list{
  168. border-radius: 15upx;
  169. margin: 20upx;
  170. overflow: hidden;
  171. box-shadow: 0upx 3upx 6upx #eee;
  172. .quit{
  173. margin-top: 20upx;
  174. }
  175. }
  176. .user-btn{
  177. padding: 85rpx 200rpx;
  178. }
  179. }
  180. </style>