index.vue 6.1 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. </view>
  8. <view class="user-info">
  9. <view>
  10. <view v-if="hasLogin" class="user-info-item">{{name ? name :''}}</view>
  11. <open-data type="userNickName" class="user-info-item" v-if="!name && hasLogin"></open-data>
  12. <view v-if="hasLogin" class="user-info-item">{{mobile? mobile:''}}</view>
  13. <u-button v-else="!hasLogin" plain size="mini" shape="circle" @click="toLoginPage">立即登录</u-button>
  14. </view>
  15. <view>
  16. <u-tag v-if="hasLogin" :text="userData?userData.reserveUserHistoryAccount+'元' :0+'元'" bg-color="#ff2c5c30" color="#FF2C5C" shape="circleLeft" mode="dark" class="tagPrice"/>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 列表 -->
  21. <view class="list-container">
  22. <view @click="checkUpdate" class="list-item flex align_center justify_between">
  23. <view class="flex align_center">
  24. <u-icon class="icon" name="error-circle" color="#5c655eb0" size="48"></u-icon>
  25. <text>版本检查</text>
  26. </view>
  27. <view>
  28. <text>{{version}}</text>
  29. <u-icon name="arrow-right" color="#9DA8B5" size="32"></u-icon>
  30. </view>
  31. </view>
  32. <view v-if="hasLogin" @click="quitSys" class="list-item flex align_center justify_between">
  33. <view class="flex align_center">
  34. <view class="t-icon icon t-icon-icon_out"></view>
  35. <text>退出登录</text>
  36. </view>
  37. <u-icon name="arrow-right" color="#9DA8B5" size="32"></u-icon>
  38. </view>
  39. <!-- <u-cell-group>
  40. <u-cell-item icon="error-circle" icon-size="38" :value="version" @click="checkUpdate" title="版本检查"></u-cell-item>
  41. <u-cell-item v-if="hasLogin" icon="minus-circle" icon-size="38" @click="quitSys" title="退出登录"></u-cell-item>
  42. </u-cell-group> -->
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import { checkLogin, getUserInfo, logout } from '@/api/login.js'
  48. export default {
  49. data() {
  50. return {
  51. hasLogin: false,
  52. name:this.$store.state.vuex_userInfoData.contactName,
  53. mobile:this.$store.state.vuex_userInfoData.contactMobile,
  54. userData: {},
  55. price:'500元', // 交易金额
  56. version: '1.0.0' // 小程序版本
  57. };
  58. },
  59. onShow() {
  60. checkLogin().then(res => {
  61. this.hasLogin = res.status == 200
  62. console.log(this.hasLogin,res,'this.hasLogin')
  63. if(this.hasLogin){
  64. this.getUserInfo()
  65. }else{
  66. // uni.navigateTo({
  67. // url:"/pages/login/login"
  68. // })
  69. }
  70. })
  71. },
  72. computed: {
  73. user() {
  74. return this.userData
  75. }
  76. },
  77. onLoad() {
  78. // this.getVersion()
  79. // 开启分享
  80. uni.showShareMenu({
  81. withShareTicket: true,
  82. menus: ['shareAppMessage', 'shareTimeline']
  83. })
  84. },
  85. methods:{
  86. // 获取当前小程序版本
  87. getVersion(){
  88. const accountInfo = uni.getAccountInfoSync();
  89. this.version = accountInfo.miniProgram.version
  90. console.log(accountInfo,accountInfo.miniProgram.appId,'ppppppppp'); // 小程序 appId
  91. },
  92. // 检查更新
  93. checkUpdate(){
  94. if (uni.canIUse('getUpdateManager')) {
  95. const updateManager = uni.getUpdateManager()
  96. updateManager.onCheckForUpdate(function (res) {
  97. console.log('onCheckForUpdate====', res)
  98. // 请求完新版本信息的回调
  99. if (res.hasUpdate) {
  100. console.log('res.hasUpdate====')
  101. updateManager.onUpdateReady(function () {
  102. uni.showModal({
  103. title: '更新提示',
  104. content: '新版本已经准备好,是否重启应用?',
  105. success: function (res) {
  106. console.log('success====', res)
  107. // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
  108. if (res.confirm) {
  109. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  110. updateManager.applyUpdate()
  111. }
  112. }
  113. })
  114. })
  115. updateManager.onUpdateFailed(function () {
  116. // 新的版本下载失败
  117. uni.showModal({
  118. title: '已经有新版本了哟~',
  119. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  120. })
  121. })
  122. } else {
  123. uni.showToast({
  124. title: '已是最新版本',
  125. icon: 'none'
  126. })
  127. }
  128. })
  129. }
  130. },
  131. // 获取用户信息
  132. getUserInfo(){
  133. getUserInfo().then(res => {
  134. console.log(res,'getUserInfo')
  135. if(res.status == 200){
  136. this.$u.vuex("vuex_userData",res.data)
  137. this.userData = res.data
  138. console.log(this.userData,'-----用户信息')
  139. }
  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. background: #fff;
  175. .user-head{
  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. align-items: center;
  183. flex-grow: 1;
  184. padding-left: 20rpx;
  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. .list-container{
  204. width: 100%;
  205. .icon{
  206. width: 48rpx;
  207. height: 48rpx;
  208. margin-right: 30rpx;
  209. }
  210. .list-item{
  211. padding: 32rpx 36rpx;
  212. background-color: #fff;
  213. text{
  214. font-size: 34rpx;
  215. color: #191919;
  216. }
  217. }
  218. .margin-bot{
  219. margin-bottom: 20rpx;
  220. }
  221. }
  222. }
  223. </style>