index.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <!-- 登录 -->
  2. <template>
  3. <view class="login">
  4. <view class="middle">
  5. <view class="logo">
  6. <u-input style="width: 100%;height: 100%;background-color: #0D1A3C;" type="text"></u-input>
  7. </view>
  8. <button class="button" @click="login">
  9. 微信用户一键登录/注册
  10. </button>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import { getOpenid } from '@/apis/main.js'
  16. export default {
  17. components: {},
  18. data() {
  19. return {
  20. };
  21. },
  22. computed: {},
  23. watch: {},
  24. methods: {
  25. login(){
  26. uni.login({
  27. provider: 'weixin',
  28. success: (res) => {
  29. console.log(res)
  30. // uni.getUserInfo({
  31. // provider: 'weixin',
  32. // success: (res) => {
  33. // console.log(res)
  34. // }
  35. // })
  36. getOpenid({ code: res.code }).then(result => {
  37. const { wxBindType, wxOpenId, accessToken, openId,userName } = result.data
  38. if (wxBindType === 1) { // 已经绑定
  39. this.$setSS('accessToken', accessToken)
  40. this.$setSS('phone', userName)
  41. } else { // 未绑定
  42. this.$setSS('wxOpenId', wxOpenId)
  43. }
  44. })
  45. }
  46. })
  47. }
  48. },
  49. created() {
  50. },
  51. mounted() {
  52. },
  53. }
  54. </script>
  55. <style lang='scss' scoped>
  56. </style>