index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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="personal_icon_version" custom-prefix="custom-icon" size="48" color="#333"></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. <u-icon class="icon" name="icon_out" custom-prefix="custom-icon" size="48" color="#333"></u-icon>
  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:'',
  53. // mobile:
  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. name(){
  77. return this.$store.state.vuex_userInfoData.contactName
  78. },
  79. mobile(){
  80. return this.$store.state.vuex_userInfoData.contactMobile
  81. }
  82. },
  83. onLoad() {
  84. console.log(this.$store.state.vuex_userInfoData,this.$store.state.vuex_userInfoData.contactName,this.$store.state.vuex_userInfoData.contactMobile,'-------------用户信息')
  85. // this.getVersion()
  86. // 开启分享
  87. uni.showShareMenu({
  88. withShareTicket: true,
  89. menus: ['shareAppMessage', 'shareTimeline']
  90. })
  91. },
  92. methods:{
  93. // 获取当前小程序版本
  94. getVersion(){
  95. const accountInfo = uni.getAccountInfoSync();
  96. this.version = accountInfo.miniProgram.version
  97. console.log(accountInfo,accountInfo.miniProgram.appId,'ppppppppp'); // 小程序 appId
  98. },
  99. // 检查更新
  100. checkUpdate(){
  101. if (uni.canIUse('getUpdateManager')) {
  102. const updateManager = uni.getUpdateManager()
  103. updateManager.onCheckForUpdate(function (res) {
  104. console.log('onCheckForUpdate====', res)
  105. // 请求完新版本信息的回调
  106. if (res.hasUpdate) {
  107. console.log('res.hasUpdate====')
  108. updateManager.onUpdateReady(function () {
  109. uni.showModal({
  110. title: '更新提示',
  111. content: '新版本已经准备好,是否重启应用?',
  112. success: function (res) {
  113. console.log('success====', res)
  114. // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
  115. if (res.confirm) {
  116. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  117. updateManager.applyUpdate()
  118. }
  119. }
  120. })
  121. })
  122. updateManager.onUpdateFailed(function () {
  123. // 新的版本下载失败
  124. uni.showModal({
  125. title: '已经有新版本了哟~',
  126. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  127. })
  128. })
  129. } else {
  130. uni.showToast({
  131. title: '已是最新版本',
  132. icon: 'none'
  133. })
  134. }
  135. })
  136. }
  137. },
  138. // 获取用户信息
  139. getUserInfo(){
  140. getUserInfo().then(res => {
  141. console.log(res,'getUserInfo')
  142. if(res.status == 200){
  143. this.$u.vuex("vuex_userData",res.data)
  144. this.userData = res.data
  145. console.log(this.userData,'-----用户信息')
  146. }
  147. })
  148. },
  149. // 退出登录
  150. quitSys(){
  151. let _this = this
  152. uni.showModal({
  153. title: '提示',
  154. content: '您确定要退出登录吗?',
  155. success(res) {
  156. if (res.confirm) {
  157. logout().then(res => {
  158. console.log(res,'logout')
  159. getApp().globalData.token = ''
  160. _this.$u.vuex('vuex_token','')
  161. // 关闭socket
  162. uni.reLaunch({
  163. url: '/pages/login/login'
  164. })
  165. })
  166. }
  167. }
  168. })
  169. },
  170. toLoginPage(){
  171. uni.navigateTo({
  172. url: '/pages/login/login'
  173. })
  174. }
  175. }
  176. }
  177. </script>
  178. <style lang="scss">
  179. .user-content{
  180. width: 100%;
  181. background: #fff;
  182. .user-head{
  183. display: flex;
  184. align-items: center;
  185. padding: 35rpx 0rpx 35rpx 55rpx;
  186. .user-info{
  187. display: flex;
  188. justify-content: space-between;
  189. align-items: center;
  190. flex-grow: 1;
  191. padding-left: 20rpx;
  192. .user-info-item{
  193. margin: 10rpx 0;
  194. :first-child{
  195. font-size: 34upx;
  196. }
  197. }
  198. .tagPrice{
  199. width: 200rpx;
  200. }
  201. }
  202. .user-photo{
  203. display: block;
  204. width: 100rpx;
  205. height: 100rpx;
  206. border-radius: 50%;
  207. overflow: hidden;
  208. }
  209. }
  210. .list-container{
  211. width: 100%;
  212. .icon{
  213. width: 48rpx;
  214. height: 48rpx;
  215. margin-right: 30rpx;
  216. }
  217. .list-item{
  218. padding: 32rpx 36rpx;
  219. background-color: #fff;
  220. text{
  221. font-size: 34rpx;
  222. color: #191919;
  223. }
  224. }
  225. .margin-bot{
  226. margin-bottom: 20rpx;
  227. }
  228. }
  229. }
  230. </style>