index.vue 7.0 KB

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