猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
3.2 KiB

3 months ago
3 months ago
2 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 months ago
2 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
  1. <template>
  2. <view class="login">
  3. <view class="login-logo">
  4. <image src="https://cdn.catmdogd.com/Work/image/user/logo.png"></image>
  5. </view>
  6. <view class="login-submit">
  7. <up-button type="primary" text="授权手机号登录" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber"
  8. shape="circle" color="#FFBF60"></up-button>
  9. <up-button class="mt24" type="primary" text="微信授权登陆" @tap="loginWx" shape="circle"
  10. color="#FFBF60"></up-button>
  11. </view>
  12. <view class="flex-rowc">
  13. <view class="select">
  14. <image mode="widthFix"></image>
  15. </view>
  16. <view class="size-26">
  17. <text>我已阅读并同意猫爸狗妈</text>
  18. <text class="main-color">注册协议</text>
  19. <text></text>
  20. <text class="main-color">隐私政策</text>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="footer size-30 flex-rowc w100">
  25. 暂不登陆
  26. </view>
  27. </template>
  28. <script setup>
  29. import {
  30. getOpenIdKey,
  31. getToken,
  32. setIsLogin,
  33. setOpenIdKey,
  34. setStorage,
  35. setToken
  36. } from "../../utils/auth";
  37. import {
  38. getOpenId,
  39. getPersonalInfo,
  40. getPhoneNumber,
  41. wxLogin
  42. } from "../../api/system/user";
  43. import {
  44. ref
  45. } from "vue"
  46. const value = ref(false)
  47. // 微信授权登陆
  48. const loginWx = () => {
  49. uni.login({
  50. success: (res) => {
  51. const code = res.code
  52. wxLogin({
  53. code
  54. }).then(res => {
  55. if (res.code === 200) {
  56. uni.setStorageSync("token", res.data.token)
  57. uni.setStorageSync("baseInfo", JSON.stringify(res.data.userInfo))
  58. uni.navigateTo({
  59. url: "/pages/login/wxUserInfo"
  60. })
  61. }
  62. })
  63. }
  64. })
  65. }
  66. // 获取openid
  67. // if (!getOpenIdKey() && !getToken()) {
  68. // uni.login({
  69. // provider: 'weixin',
  70. // success: async (res) => {
  71. // const {
  72. // code,
  73. // data
  74. // } = await getOpenId(res.code)
  75. // if (code === 200 && data) {
  76. // let resData = JSON.parse(data)
  77. // setOpenIdKey(resData.openId)
  78. // }
  79. // },
  80. // fail: function(error) {
  81. // // 授权失败处理
  82. // uni.showToast('授权失败,请授权后再试')
  83. // }
  84. // });
  85. // }
  86. // 获取token
  87. const onGetPhoneNumber = async (e) => {
  88. // uni.login({
  89. // success: res => {
  90. // console.log("====>", res)
  91. // }
  92. // })
  93. console.log(e)
  94. getPhoneNumber({
  95. phoneCode: e.detail.code
  96. })
  97. // if (e.detail.errMsg === "getPhoneNumber:ok") {
  98. // if (getOpenIdKey()) {
  99. // try {
  100. // const {
  101. // data
  102. // } = await getPhoneNumber({
  103. // "openId": getOpenIdKey(),
  104. // "code": e.detail.code,
  105. // sourceType: 1
  106. // })
  107. // setToken(data.token)
  108. // setIsLogin(true)
  109. // await getUserInfo()
  110. // } catch (e) {
  111. // uni.showToast({
  112. // icon: 'error',
  113. // title: '获取手机号失败'
  114. // })
  115. // }
  116. // }
  117. // }
  118. }
  119. // // h获取用户信息
  120. // const getUserInfo = async () => {
  121. // const {
  122. // data
  123. // } = await getPersonalInfo()
  124. // setStorage('userInfo', data)
  125. // uni.navigateBack()
  126. // }
  127. </script>
  128. <style scoped lang="scss">
  129. @import "index";
  130. @import "@/style/index.scss";
  131. .select {
  132. width: 24rpx;
  133. height: 24rpx;
  134. border-radius: 50%;
  135. border: 1rpx solid #C7C7C7;
  136. margin-right: 8rpx;
  137. .active {
  138. background-color: $mainColor;
  139. }
  140. }
  141. .footer {
  142. color: #C7C7C7;
  143. position: fixed;
  144. bottom: 100rpx;
  145. }
  146. </style>