index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <view class="container">
  3. <button v-if="canIUseGetUserProfile" class="userinfo" @tap="getUserProfile">
  4. <image class="userinfo-avatar" :src="userInfo.avatarUrl" background-size="cover"></image>
  5. <text class="userinfo-nickname">{{ userInfo.nickName}}</text>
  6. </button>
  7. <button v-else class="userinfo" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">
  8. <image class="userinfo-avatar" :src="userInfo.avatarUrl" background-size="cover"></image>
  9. <text class="userinfo-nickname">{{ userInfo.nickName}}</text>
  10. </button>
  11. <view style="height:20rpx;background: #eee;width:100%;"></view>
  12. <view class="my-item" style='background:none;display:flex;flex-direction:column;height:auto;'></view>
  13. <view class="user-menu">
  14. <view class="item">
  15. <navigator url="/pages/ucenter/order/order" class="a">
  16. <text class="icon order"></text>
  17. <text class="txt">我的订单</text>
  18. </navigator>
  19. </view>
  20. <view class="item">
  21. <navigator url="/pages/ucenter/coupon/coupon" class="a">
  22. <text class="icon coupon"></text>
  23. <text class="txt">优惠券</text>
  24. </navigator>
  25. </view>
  26. <view class="item">
  27. <navigator url="/pages/ucenter/collect/collect" class="a">
  28. <text class="icon address"></text>
  29. <text class="txt">我的收藏</text>
  30. </navigator>
  31. </view>
  32. <view class="item">
  33. <navigator url="/pages/ucenter/footprint/footprint" class="a">
  34. <text class="icon security"></text>
  35. <text class="txt">我的足迹</text>
  36. </navigator>
  37. </view>
  38. <view class="item">
  39. <navigator url="../address/address" class="a">
  40. <text class="icon address"></text>
  41. <text class="txt">地址管理</text>
  42. </navigator>
  43. </view>
  44. <button class='service' open-type="contact">
  45. <view class="item no-border">
  46. <navigator url="url" class="a">
  47. <text class="icon kefu"></text>
  48. <text class="txt">联系客服</text>
  49. </navigator>
  50. </view>
  51. </button>
  52. <view class="item item-bottom">
  53. <navigator url="/pages/ucenter/help/help" class="a">
  54. <text class="icon help"></text>
  55. <text class="txt">帮助中心</text>
  56. </navigator>
  57. </view>
  58. <view class="item item-bottom">
  59. <navigator url="/pages/ucenter/feedback/feedback" class="a">
  60. <text class="icon feedback"></text>
  61. <text class="txt">意见反馈</text>
  62. </navigator>
  63. </view>
  64. <view class="item item-bottom" v-if="!hasMobile">
  65. <navigator url="/pages/auth/mobile/mobile" class="a">
  66. <text class="icon phone"></text>
  67. <text class="txt">绑定手机</text>
  68. </navigator>
  69. </view>
  70. </view>
  71. <view class='company'>安徽微同科技有限公司提供技术支持 © fly2you.cn</view>
  72. <view class="logout" v-if="userInfo.userName!='点击去登录'" @tap="exitLogin">退出登录</view>
  73. </view>
  74. </template>
  75. <script>
  76. const util = require("@/utils/util.js")
  77. const api = require('@/utils/api.js');
  78. const app = getApp();
  79. export default {
  80. data() {
  81. return {
  82. canIUseGetUserProfile: false,
  83. userInfo: {},
  84. hasMobile: ''
  85. }
  86. },
  87. methods: {
  88. loginByWeixin: function(userInfo) {
  89. let code = null;
  90. return new Promise(function(resolve, reject) {
  91. return util.login().then((res) => {
  92. code = res.code;
  93. return userInfo;
  94. }).then((userInfo) => {
  95. //登录远程服务器
  96. util.request(api.AuthLoginByWeixin, {
  97. code: code,
  98. userInfo: userInfo
  99. }, 'POST', 'application/json').then(res => {
  100. if (res.errno === 0) {
  101. //存储用户信息
  102. uni.setStorageSync('userInfo', res.data.userInfo);
  103. uni.setStorageSync('X-Nideshop-Token', res.data.token);
  104. resolve(res);
  105. } else {
  106. util.toast(res.errmsg)
  107. reject(res);
  108. }
  109. }).catch((err) => {
  110. reject(err);
  111. });
  112. }).catch((err) => {
  113. reject(err);
  114. })
  115. });
  116. },
  117. getUserProfile() {
  118. let that = this;
  119. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
  120. // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  121. wx.getUserProfile({
  122. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  123. success: (resp) => {
  124. //登录远程服务器
  125. that.loginByWeixin(resp).then(res => {
  126. that.userInfo = res.data.userInfo
  127. app.globalData.userInfo = res.data.userInfo;
  128. app.globalData.token = res.data.token;
  129. }).catch((err) => {
  130. console.log(err)
  131. });
  132. }
  133. })
  134. },
  135. bindGetUserInfo(e) {
  136. let that = this;
  137. that.loginByWeixin(e.detail).then(res => {
  138. that.userInfo = res.data.userInfo
  139. app.globalData.userInfo = res.data.userInfo;
  140. app.globalData.token = res.data.token;
  141. }).catch((err) => {
  142. console.log(err)
  143. });
  144. },
  145. exitLogin: function() {
  146. uni.showModal({
  147. title: '',
  148. confirmColor: '#b4282d',
  149. content: '退出登录?',
  150. success: function(res) {
  151. if (res.confirm) {
  152. uni.removeStorageSync('X-Nideshop-Token');
  153. uni.removeStorageSync('userInfo');
  154. app.globalData.userInfo = {
  155. nickName: 'Hi,游客',
  156. userName: '点击去登录',
  157. avatarUrl: 'https://platform-wxmall.oss-cn-beijing.aliyuncs.com/upload/20180727/150547696d798c.png'
  158. }
  159. util.toast('退出成功');
  160. uni.switchTab({
  161. url: '/pages/index/index'
  162. });
  163. }
  164. }
  165. })
  166. }
  167. },
  168. onShow: function() {
  169. let that = this;
  170. let userInfo = uni.getStorageSync('userInfo');
  171. let token = uni.getStorageSync('X-Nideshop-Token');
  172. // 页面显示
  173. if (userInfo && token) {
  174. app.globalData.userInfo = userInfo;
  175. app.globalData.token = token;
  176. } else {
  177. uni.login({
  178. success: function(res) {
  179. if (res.code) {
  180. that.code = res.code
  181. }
  182. }
  183. });
  184. }
  185. that.userInfo = app.globalData.userInfo
  186. },
  187. onLoad: function() {
  188. // 页面初始化 options为页面跳转所带来的参数
  189. if (wx.getUserProfile) {
  190. this.canIUseGetUserProfile = true
  191. }
  192. }
  193. }
  194. </script>
  195. <style lang="scss">
  196. page {
  197. height: 100%;
  198. width: 100%;
  199. background: #f4f4f4;
  200. }
  201. .container {
  202. background: #f4f4f4;
  203. height: auto;
  204. overflow: hidden;
  205. width: 100%;
  206. }
  207. .userinfo {
  208. display: flex;
  209. flex-direction: column;
  210. padding: 50rpx 0;
  211. align-items: center;
  212. background: #333;
  213. width: 750rpx;
  214. }
  215. .userinfo-avatar {
  216. width: 160rpx;
  217. height: 160rpx;
  218. margin: 20rpx;
  219. border-radius: 50%;
  220. }
  221. .userinfo-nickname {
  222. margin-top: 20rpx;
  223. color: #FFF;
  224. }
  225. .profile-info {
  226. width: 100%;
  227. height: 280rpx;
  228. display: flex;
  229. flex-wrap: wrap;
  230. align-items: center;
  231. justify-content: flex-start;
  232. padding: 0 30.25rpx;
  233. background: #333;
  234. }
  235. .profile-info .avatar {
  236. height: 148rpx;
  237. width: 148rpx;
  238. border-radius: 50%;
  239. }
  240. .profile-info .info {
  241. flex: 1;
  242. height: 85rpx;
  243. padding-left: 31.25rpx;
  244. }
  245. .profile-info .name {
  246. display: block;
  247. height: 45rpx;
  248. line-height: 45rpx;
  249. color: #fff;
  250. font-size: 37.5rpx;
  251. margin-bottom: 10rpx;
  252. }
  253. .profile-info .level {
  254. display: block;
  255. height: 30rpx;
  256. line-height: 30rpx;
  257. margin-bottom: 10rpx;
  258. color: #7f7f7f;
  259. font-size: 30rpx;
  260. }
  261. .user-menu {
  262. width: 100%;
  263. height: auto;
  264. overflow: hidden;
  265. background: #fff;
  266. }
  267. .user-menu .item {
  268. float: left;
  269. width: 33.33333%;
  270. height: 187.5rpx;
  271. border-right: 1px solid rgba(0, 0, 0, .15);
  272. border-bottom: 1px solid rgba(0, 0, 0, .15);
  273. text-align: center;
  274. }
  275. .user-menu .item .a {
  276. display: flex;
  277. width: 100%;
  278. height: 100%;
  279. flex-direction: column;
  280. align-items: center;
  281. justify-content: center;
  282. }
  283. .user-menu .item.no-border {
  284. border-right: 0;
  285. }
  286. .user-menu .item.item-bottom {
  287. border-bottom: none;
  288. }
  289. .user-menu .icon {
  290. margin: 0 auto;
  291. display: block;
  292. height: 52.803rpx;
  293. width: 52.803rpx;
  294. margin-bottom: 16rpx;
  295. }
  296. .user-menu .icon.order {
  297. background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -437.5rpx no-repeat;
  298. background-size: 52.803rpx;
  299. }
  300. .user-menu .icon.coupon {
  301. background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -62.4997rpx no-repeat;
  302. background-size: 52.803rpx;
  303. }
  304. .user-menu .icon.gift {
  305. background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -187.5rpx no-repeat;
  306. background-size: 52.803rpx;
  307. }
  308. .user-menu .icon.address {
  309. background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 0 no-repeat;
  310. background-size: 52.803rpx;
  311. }
  312. .user-menu .icon.security {
  313. background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -500rpx no-repeat;
  314. background-size: 52.803rpx;
  315. }
  316. .user-menu .icon.kefu {
  317. background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -312.5rpx no-repeat;
  318. background-size: 52.803rpx;
  319. }
  320. .user-menu .icon.help {
  321. background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -250rpx no-repeat;
  322. background-size: 52.803rpx;
  323. }
  324. .user-menu .icon.feedback {
  325. background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -125rpx no-repeat;
  326. background-size: 52.803rpx;
  327. }
  328. .user-menu .icon.phone {
  329. background: url(https://platform-wxmall.oss-cn-beijing.aliyuncs.com/upload/20180727/15011540ebe21.png) no-repeat;
  330. background-size: 52.803rpx;
  331. }
  332. .user-menu .txt {
  333. display: block;
  334. height: 24rpx;
  335. width: 100%;
  336. font-size: 24rpx;
  337. color: #333;
  338. }
  339. .logout {
  340. margin-top: 50rpx;
  341. height: 101rpx;
  342. width: 100%;
  343. line-height: 101rpx;
  344. text-align: center;
  345. background: #fff;
  346. color: #333;
  347. font-size: 30rpx;
  348. }
  349. .service {
  350. position: static;
  351. background-color: transparent;
  352. color: transparent;
  353. margin: 0;
  354. padding: 0;
  355. border: none;
  356. text-align: left;
  357. line-height: normal;
  358. display: inline;
  359. }
  360. .company {
  361. font-size: 20rpx;
  362. text-align: center;
  363. margin-top: 50px;
  364. }
  365. </style>