index.vue 7.7 KB

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