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