index.vue 6.6 KB

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