index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. // uni.getSystemInfo({
  63. // success: function(res) {
  64. // console.log(res.model,'1')
  65. // console.log(res.pixelRatio,'2')
  66. // console.log(res.windowWidth,'3')
  67. // console.log(res.windowHeight,'4')
  68. // console.log(res.language,'5')
  69. // console.log(res.version,'6')
  70. // console.log(res.SDKVersion,'7','---当前使用小程序版本号')
  71. // console.log(res.swanNativeVersion,'7','宿主平台版本号')
  72. // }
  73. // })
  74. },
  75. methods:{
  76. // 获取用户信息
  77. getUserInfo(){
  78. getUserInfo().then(res => {
  79. console.log(res,'getUserInfo')
  80. if(res.status == 200){
  81. this.$u.vuex("vuex_userData",res.data)
  82. this.userData = res.data
  83. console.log(this.userData,'-----用户信息')
  84. }
  85. })
  86. },
  87. // 打开对应的页面
  88. toPage(index){
  89. console.log(index)
  90. let pageUrl=[
  91. '/pages/agreement/agreement?fromPage=usercenter',
  92. '/pages/userCenter/changePwd',
  93. ]
  94. uni.navigateTo({
  95. url: pageUrl[index]
  96. })
  97. },
  98. // 退出登录
  99. quitSys(){
  100. let _this = this
  101. uni.showModal({
  102. title: '提示',
  103. content: '您确定要退出登录吗?',
  104. success(res) {
  105. if (res.confirm) {
  106. logout().then(res => {
  107. console.log(res,'logout')
  108. getApp().globalData.token = ''
  109. _this.$u.vuex('vuex_token','')
  110. // 关闭socket
  111. uni.reLaunch({
  112. url: '/pages/login/login'
  113. })
  114. })
  115. }
  116. }
  117. })
  118. },
  119. toLoginPage(){
  120. uni.navigateTo({
  121. url: '/pages/login/login'
  122. })
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss">
  128. .user-content{
  129. width: 100%;
  130. .user-head{
  131. background: #0DC55F;
  132. display: flex;
  133. align-items: center;
  134. padding: 35rpx 55rpx;
  135. .user-info{
  136. flex-grow: 1;
  137. padding: 0 20rpx;
  138. color: #FFFFFF;
  139. .user-info-item{
  140. margin: 10rpx 0;
  141. :first-child{
  142. font-size: 34upx;
  143. }
  144. }
  145. }
  146. .user-photo{
  147. display: block;
  148. width: 100rpx;
  149. height: 100rpx;
  150. border-radius: 50%;
  151. overflow: hidden;
  152. }
  153. }
  154. .my-ledou{
  155. background: #FFFFFF;
  156. border-radius: 15upx;
  157. display: flex;
  158. align-items: center;
  159. justify-content: space-between;
  160. padding: 20upx;
  161. margin: 20upx;
  162. box-shadow: 0upx 3upx 6upx #eee;
  163. .user-jifen{
  164. display: flex;
  165. align-items: center;
  166. text{
  167. font-size: 40upx;
  168. font-weight: bold;
  169. color: red;
  170. }
  171. >view{
  172. &:first-child{
  173. display: flex;
  174. align-items: center;
  175. }
  176. }
  177. }
  178. }
  179. .user-list{
  180. border-radius: 15upx;
  181. margin: 20upx;
  182. overflow: hidden;
  183. box-shadow: 0upx 3upx 6upx #eee;
  184. .quit{
  185. margin-top: 20upx;
  186. }
  187. }
  188. .user-btn{
  189. padding: 85rpx 200rpx;
  190. }
  191. }
  192. </style>