index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. <!-- <u-image v-show="!hasLogin" src="/static/logo.png" width="100" height="100"></u-image> -->
  8. </view>
  9. <view class="user-info">
  10. <view v-if="hasLogin" class="user-info-item">{{userData.userName || ''}}</view>
  11. <view v-if="hasLogin" class="user-info-item">{{userData.userMobile || ''}}</view>
  12. <view v-if="!hasLogin" class="user-info-item" @click="toLoginPage">
  13. 请点击登录
  14. </view>
  15. <!-- <u-button v-else="!hasLogin" plain size="mini" shape="circle" @click="toLoginPage">立即登录</u-button> -->
  16. </view>
  17. </view>
  18. <!-- 列表 -->
  19. <view class="list-container">
  20. <navigator url="/pages/order/historyOrder" class="list-item flex align_center justify_between">
  21. <view class="flex align_center">
  22. <view class="t-icon icon t-icon-icon_order"></view>
  23. <text>历史订单</text>
  24. </view>
  25. <u-icon name="arrow-right" color="#9DA8B5" size="32"></u-icon>
  26. </navigator>
  27. <navigator url="/pages/recoveryTotal/index" class="list-item flex align_center justify_between">
  28. <view class="flex align_center">
  29. <view class="t-icon icon t-icon-icon_statistics"></view>
  30. <text>回收统计</text>
  31. </view>
  32. <u-icon name="arrow-right" color="#9DA8B5" size="32"></u-icon>
  33. </navigator>
  34. <navigator url="/pages/userCenter/changePwd" class="list-item flex align_center justify_between">
  35. <view class="flex align_center">
  36. <view class="t-icon icon t-icon-icon_modify"></view>
  37. <text>修改密码</text>
  38. </view>
  39. <u-icon name="arrow-right" color="#9DA8B5" size="32"></u-icon>
  40. </navigator>
  41. <view @click="quitSys" class="list-item flex align_center justify_between">
  42. <view class="flex align_center">
  43. <view class="t-icon icon t-icon-icon_out"></view>
  44. <text>退出登录</text>
  45. </view>
  46. <u-icon name="arrow-right" color="#9DA8B5" size="32"></u-icon>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import { checkLogin, getUserInfo, logout } from '@/api/login.js'
  53. export default {
  54. data() {
  55. return {
  56. hasLogin: false,
  57. userData: {},
  58. version: '1.0.0' // 小程序版本
  59. };
  60. },
  61. onShow() {
  62. checkLogin().then(res => {
  63. this.hasLogin = res.status == 200
  64. console.log(this.hasLogin,res,'this.hasLogin')
  65. if(this.hasLogin){
  66. this.getUserInfo()
  67. }else{
  68. // uni.navigateTo({
  69. // url:"/pages/login/login"
  70. // })
  71. }
  72. })
  73. },
  74. computed: {
  75. },
  76. onLoad() {
  77. // this.getVersion()
  78. // 开启分享
  79. uni.showShareMenu({
  80. withShareTicket: true,
  81. menus: ['shareAppMessage', 'shareTimeline']
  82. })
  83. },
  84. methods:{
  85. // 获取当前小程序版本
  86. getVersion(){
  87. const accountInfo = uni.getAccountInfoSync();
  88. this.version = accountInfo.miniProgram.version
  89. console.log(accountInfo,accountInfo.miniProgram.appId,'ppppppppp'); // 小程序 appId
  90. },
  91. // 检查更新
  92. checkUpdate(){
  93. if (uni.canIUse('getUpdateManager')) {
  94. const updateManager = uni.getUpdateManager()
  95. updateManager.onCheckForUpdate(function (res) {
  96. console.log('onCheckForUpdate====', res)
  97. // 请求完新版本信息的回调
  98. if (res.hasUpdate) {
  99. console.log('res.hasUpdate====')
  100. updateManager.onUpdateReady(function () {
  101. uni.showModal({
  102. title: '更新提示',
  103. content: '新版本已经准备好,是否重启应用?',
  104. success: function (res) {
  105. console.log('success====', res)
  106. // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
  107. if (res.confirm) {
  108. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  109. updateManager.applyUpdate()
  110. }
  111. }
  112. })
  113. })
  114. updateManager.onUpdateFailed(function () {
  115. // 新的版本下载失败
  116. uni.showModal({
  117. title: '已经有新版本了哟~',
  118. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  119. })
  120. })
  121. } else {
  122. uni.showToast({
  123. title: '已是最新版本',
  124. icon: 'none'
  125. })
  126. }
  127. })
  128. }
  129. },
  130. // 获取用户信息
  131. getUserInfo(){
  132. getUserInfo().then(res => {
  133. console.log(res,'getUserInfo')
  134. if(res.status == 200){
  135. this.$u.vuex("vuex_userData",res.data)
  136. this.userData = res.data
  137. console.log(this.userData,'-----用户信息')
  138. }
  139. })
  140. },
  141. // 打开对应的页面
  142. toPage(index){
  143. console.log(index)
  144. let pageUrl=[
  145. '/pages/agreement/agreement?fromPage=usercenter',
  146. '/pages/userCenter/changePwd',
  147. ]
  148. uni.navigateTo({
  149. url: pageUrl[index]
  150. })
  151. },
  152. // 退出登录
  153. quitSys(){
  154. let _this = this
  155. uni.showModal({
  156. title: '提示',
  157. content: '您确定要退出登录吗?',
  158. success(res) {
  159. if (res.confirm) {
  160. logout().then(res => {
  161. console.log(res,'logout')
  162. getApp().globalData.token = ''
  163. _this.$u.vuex('vuex_token','')
  164. // 关闭socket
  165. uni.reLaunch({
  166. url: '/pages/login/login'
  167. })
  168. })
  169. }
  170. }
  171. })
  172. },
  173. toLoginPage(){
  174. uni.navigateTo({
  175. url: '/pages/login/login'
  176. })
  177. }
  178. }
  179. }
  180. </script>
  181. <style lang="scss">
  182. .user-content{
  183. width: 100%;
  184. height: 100vh;
  185. background-color: #fff;
  186. .user-head{
  187. display: flex;
  188. align-items: center;
  189. padding: 35rpx 55rpx;
  190. .user-info{
  191. flex-grow: 1;
  192. padding: 0 20rpx;
  193. color: #FFFFFF;
  194. .user-info-item{
  195. margin: 10rpx 0;
  196. color: #666666;
  197. font-size: 32upx;
  198. }
  199. :first-child{
  200. color: #000000;
  201. font-size: 48upx;
  202. }
  203. }
  204. .user-photo{
  205. display: block;
  206. width: 146rpx;
  207. height: 146rpx;
  208. border-radius: 50%;
  209. overflow: hidden;
  210. }
  211. }
  212. .list-container{
  213. width: 100%;
  214. .icon{
  215. width: 48rpx;
  216. height: 48rpx;
  217. }
  218. .list-item{
  219. padding: 32rpx 36rpx;
  220. background-color: #fff;
  221. text{
  222. font-size: 34rpx;
  223. color: #191919;
  224. margin-left: 30rpx;
  225. }
  226. }
  227. .margin-bot{
  228. margin-bottom: 20rpx;
  229. }
  230. }
  231. .my-ledou{
  232. background: #FFFFFF;
  233. border-radius: 15upx;
  234. display: flex;
  235. align-items: center;
  236. justify-content: space-between;
  237. padding: 20upx;
  238. margin: 20upx;
  239. box-shadow: 0upx 3upx 6upx #eee;
  240. .user-jifen{
  241. display: flex;
  242. align-items: center;
  243. text{
  244. font-size: 40upx;
  245. font-weight: bold;
  246. color: red;
  247. }
  248. >view{
  249. &:first-child{
  250. display: flex;
  251. align-items: center;
  252. }
  253. }
  254. }
  255. }
  256. .user-list{
  257. border-radius: 15upx;
  258. margin: 20upx;
  259. overflow: hidden;
  260. box-shadow: 0upx 3upx 6upx #eee;
  261. .quit{
  262. margin-top: 20upx;
  263. }
  264. }
  265. .user-btn{
  266. padding: 85rpx 200rpx;
  267. }
  268. }
  269. </style>