index.vue 7.4 KB

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