index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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: '1.0.0' // 小程序版本
  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. } else {
  104. uni.showToast({
  105. title: '已是最新版本',
  106. icon: 'none'
  107. })
  108. }
  109. })
  110. }
  111. },
  112. // 获取用户信息
  113. getUserInfo(){
  114. getUserInfo().then(res => {
  115. console.log(res,'getUserInfo')
  116. if(res.status == 200){
  117. this.$u.vuex("vuex_userData",res.data)
  118. this.userData = res.data
  119. console.log(this.userData,'-----用户信息')
  120. }
  121. })
  122. },
  123. // 打开对应的页面
  124. toPage(index){
  125. console.log(index)
  126. let pageUrl=[
  127. '/pages/agreement/agreement?fromPage=usercenter',
  128. '/pages/userCenter/changePwd',
  129. ]
  130. uni.navigateTo({
  131. url: pageUrl[index]
  132. })
  133. },
  134. // 退出登录
  135. quitSys(){
  136. let _this = this
  137. uni.showModal({
  138. title: '提示',
  139. content: '您确定要退出登录吗?',
  140. success(res) {
  141. if (res.confirm) {
  142. logout().then(res => {
  143. console.log(res,'logout')
  144. getApp().globalData.token = ''
  145. _this.$u.vuex('vuex_token','')
  146. // 关闭socket
  147. uni.reLaunch({
  148. url: '/pages/login/login'
  149. })
  150. })
  151. }
  152. }
  153. })
  154. },
  155. toLoginPage(){
  156. uni.navigateTo({
  157. url: '/pages/login/login'
  158. })
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss">
  164. .user-content{
  165. width: 100%;
  166. .user-head{
  167. background: #0DC55F;
  168. display: flex;
  169. align-items: center;
  170. padding: 35rpx 55rpx;
  171. .user-info{
  172. flex-grow: 1;
  173. padding: 0 20rpx;
  174. color: #FFFFFF;
  175. .user-info-item{
  176. margin: 10rpx 0;
  177. :first-child{
  178. font-size: 34upx;
  179. }
  180. }
  181. }
  182. .user-photo{
  183. display: block;
  184. width: 100rpx;
  185. height: 100rpx;
  186. border-radius: 50%;
  187. overflow: hidden;
  188. }
  189. }
  190. .my-ledou{
  191. background: #FFFFFF;
  192. border-radius: 15upx;
  193. display: flex;
  194. align-items: center;
  195. justify-content: space-between;
  196. padding: 20upx;
  197. margin: 20upx;
  198. box-shadow: 0upx 3upx 6upx #eee;
  199. .user-jifen{
  200. display: flex;
  201. align-items: center;
  202. text{
  203. font-size: 40upx;
  204. font-weight: bold;
  205. color: red;
  206. }
  207. >view{
  208. &:first-child{
  209. display: flex;
  210. align-items: center;
  211. }
  212. }
  213. }
  214. }
  215. .user-list{
  216. border-radius: 15upx;
  217. margin: 20upx;
  218. overflow: hidden;
  219. box-shadow: 0upx 3upx 6upx #eee;
  220. .quit{
  221. margin-top: 20upx;
  222. }
  223. }
  224. .user-btn{
  225. padding: 85rpx 200rpx;
  226. }
  227. }
  228. </style>