index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view>
  3. <u-cell-item :title="userInfo.mobile?'修改手机号':'绑定手机号'" :value="tel" @click="gophone"></u-cell-item>
  4. <u-cell-item title="修改密码" @click="gopwd"></u-cell-item>
  5. <view class="fixed-bottom pb-80" v-if="token">
  6. <u-button type="primary" @click="exit">退出登录</u-button>
  7. </view>
  8. <u-modal v-model="show" content="确定解除微信绑定?" :show-cancel-button="true" @confirm="confirm"></u-modal>
  9. </view>
  10. </template>
  11. <script>
  12. import {
  13. mapState
  14. } from 'vuex'
  15. export default {
  16. data() {
  17. return {
  18. show: false,
  19. }
  20. },
  21. computed: {
  22. ...mapState(['userInfo', 'token']),
  23. tel() {
  24. return !this.token? '请登录':this.userInfo.mobile ? this.userInfo.mobile : '未绑定'
  25. },
  26. vx() {
  27. return !this.token? '请登录':this.userInfo.openid ? '已绑定(' + this.userInfo.wx_name + ')' : '未绑定'
  28. }
  29. },
  30. methods: {
  31. gophone() { //修改手机号
  32. if (this.token) {
  33. if (this.userInfo.mobile) {
  34. uni.navigateTo({
  35. url: '/pages/my/set/phone-number'
  36. })
  37. } else {
  38. uni.navigateTo({
  39. url: '/pages/login/phone?type=1'
  40. })
  41. }
  42. }
  43. },
  44. gopwd() { //修改密码
  45. if (this.token) {
  46. uni.navigateTo({
  47. url: '/pages/login/forget-pwd?type=2'
  48. })
  49. }
  50. },
  51. exit() {
  52. this.$store.commit('exitLogin')
  53. uni.navigateBack({})
  54. setTimeout(() => {
  55. uni.showToast({
  56. title: '退出成功'
  57. })
  58. }, 100)
  59. },
  60. wxLogin() {
  61. if (this.token) {
  62. if (this.vx == '未绑定') {
  63. let _this = this;
  64. uni.login({
  65. provider: 'weixin',
  66. success: function(loginRes) {
  67. console.log(loginRes.authResult);
  68. // 获取用户信息
  69. uni.getUserInfo({
  70. provider: 'weixin',
  71. success: function(infoRes) {
  72. console.log(infoRes.userInfo);
  73. _this.$http('/addons/ddrive/wx_login/wxlogin', {
  74. openid: infoRes.userInfo.openId,
  75. wx_name: infoRes.userInfo.nickName
  76. }, "POST").then(data => {
  77. console.log(data);
  78. _this.$store.dispatch('updateUserInfo')
  79. setTimeout(() => {
  80. uni.showToast({
  81. title: '绑定成功'
  82. })
  83. }, 100)
  84. })
  85. }
  86. });
  87. }
  88. });
  89. } else {
  90. if (this.userInfo.mobile) {
  91. this.show = true
  92. }
  93. }
  94. }
  95. },
  96. // 解除微信绑定
  97. confirm() {
  98. this.$http('/addons/ddrive/wx_login/untie', "POST").then(data => {
  99. this.$store.dispatch('updateUserInfo')
  100. uni.showToast({
  101. title: '解绑成功'
  102. })
  103. console.log(data);
  104. })
  105. }
  106. }
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. /deep/.u-btn {
  111. height: 96rpx !important;
  112. }
  113. /deep/.u-primary-hover {
  114. background-color: $blue !important;
  115. }
  116. /deep/.u-cell {
  117. padding: 30rpx 32rpx;
  118. }
  119. </style>