index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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-item icon="error-circle" icon-size="38" :icon-style="{color:'#aaaaff'}" :value="version" @click="checkUpdate" title="版本检查"></u-cell-item>
  21. </u-cell-group>
  22. </view>
  23. <view class="user-list quit">
  24. <u-cell-group>
  25. <u-cell-item v-if="hasLogin" icon="minus-circle" icon-size="40" index="3" @click="quitSys" title="退出登录"></u-cell-item>
  26. </u-cell-group>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import { checkLogin, getUserInfo, logout } from '@/api/login.js'
  32. export default {
  33. data() {
  34. return {
  35. hasLogin: false,
  36. userData: {},
  37. version: '' // 小程序版本
  38. };
  39. },
  40. onShow() {
  41. checkLogin().then(res => {
  42. this.hasLogin = res.status == 200
  43. console.log(this.hasLogin,res,'this.hasLogin')
  44. if(this.hasLogin){
  45. this.getUserInfo()
  46. }else{
  47. // uni.navigateTo({
  48. // url:"/pages/login/login"
  49. // })
  50. }
  51. })
  52. },
  53. computed: {
  54. user() {
  55. return this.userData
  56. }
  57. },
  58. onLoad() {
  59. this.getVersion()
  60. // 开启分享
  61. uni.showShareMenu({
  62. withShareTicket: true,
  63. menus: ['shareAppMessage', 'shareTimeline']
  64. })
  65. },
  66. methods:{
  67. // 获取当前小程序版本
  68. getVersion(){
  69. const accountInfo = uni.getAccountInfoSync();
  70. this.version = accountInfo.miniProgram.version
  71. // console.log(accountInfo,accountInfo.miniProgram.appId,'ppppppppp'); // 小程序 appId
  72. },
  73. // 检查更新
  74. checkUpdate(){
  75. if (uni.canIUse('getUpdateManager')) {
  76. const updateManager = uni.getUpdateManager()
  77. updateManager.onCheckForUpdate(function (res) {
  78. console.log('onCheckForUpdate====', res)
  79. // 请求完新版本信息的回调
  80. if (res.hasUpdate) {
  81. console.log('res.hasUpdate====')
  82. updateManager.onUpdateReady(function () {
  83. uni.showModal({
  84. title: '更新提示',
  85. content: '新版本已经准备好,是否重启应用?',
  86. success: function (res) {
  87. console.log('success====', res)
  88. // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
  89. if (res.confirm) {
  90. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  91. updateManager.applyUpdate()
  92. }
  93. }
  94. })
  95. })
  96. updateManager.onUpdateFailed(function () {
  97. // 新的版本下载失败
  98. uni.showModal({
  99. title: '已经有新版本了哟~',
  100. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  101. })
  102. })
  103. }
  104. })
  105. }
  106. },
  107. // 获取用户信息
  108. getUserInfo(){
  109. getUserInfo().then(res => {
  110. console.log(res,'getUserInfo')
  111. if(res.status == 200){
  112. this.$u.vuex("vuex_userData",res.data)
  113. this.userData = res.data
  114. console.log(this.userData,'-----用户信息')
  115. }
  116. })
  117. },
  118. // 打开对应的页面
  119. toPage(index){
  120. console.log(index)
  121. let pageUrl=[
  122. '/pages/agreement/agreement?fromPage=usercenter',
  123. '/pages/userCenter/changePwd',
  124. ]
  125. uni.navigateTo({
  126. url: pageUrl[index]
  127. })
  128. },
  129. // 退出登录
  130. quitSys(){
  131. let _this = this
  132. uni.showModal({
  133. title: '提示',
  134. content: '您确定要退出登录吗?',
  135. success(res) {
  136. if (res.confirm) {
  137. logout().then(res => {
  138. console.log(res,'logout')
  139. getApp().globalData.token = ''
  140. _this.$u.vuex('vuex_token','')
  141. // 关闭socket
  142. uni.reLaunch({
  143. url: '/pages/login/login'
  144. })
  145. })
  146. }
  147. }
  148. })
  149. },
  150. toLoginPage(){
  151. uni.navigateTo({
  152. url: '/pages/login/login'
  153. })
  154. }
  155. }
  156. }
  157. </script>
  158. <style lang="scss">
  159. .user-content{
  160. width: 100%;
  161. .user-head{
  162. background: #0DC55F;
  163. display: flex;
  164. align-items: center;
  165. padding: 35rpx 55rpx;
  166. .user-info{
  167. flex-grow: 1;
  168. padding: 0 20rpx;
  169. color: #FFFFFF;
  170. .user-info-item{
  171. margin: 10rpx 0;
  172. :first-child{
  173. font-size: 34upx;
  174. }
  175. }
  176. }
  177. .user-photo{
  178. display: block;
  179. width: 100rpx;
  180. height: 100rpx;
  181. border-radius: 50%;
  182. overflow: hidden;
  183. }
  184. }
  185. .my-ledou{
  186. background: #FFFFFF;
  187. border-radius: 15upx;
  188. display: flex;
  189. align-items: center;
  190. justify-content: space-between;
  191. padding: 20upx;
  192. margin: 20upx;
  193. box-shadow: 0upx 3upx 6upx #eee;
  194. .user-jifen{
  195. display: flex;
  196. align-items: center;
  197. text{
  198. font-size: 40upx;
  199. font-weight: bold;
  200. color: red;
  201. }
  202. >view{
  203. &:first-child{
  204. display: flex;
  205. align-items: center;
  206. }
  207. }
  208. }
  209. }
  210. .user-list{
  211. border-radius: 15upx;
  212. margin: 20upx;
  213. overflow: hidden;
  214. box-shadow: 0upx 3upx 6upx #eee;
  215. .quit{
  216. margin-top: 20upx;
  217. }
  218. }
  219. .user-btn{
  220. padding: 85rpx 200rpx;
  221. }
  222. }
  223. </style>