index.vue 7.0 KB

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