index.vue 7.2 KB

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