index.vue 6.1 KB

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