猫妈狗爸伴宠师小程序前端代码
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.

160 lines
3.1 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
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
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. console.log(code)
  53. wxLogin({
  54. code
  55. }).then(res => {
  56. if (res.code === 200) {
  57. uni.setStorageSync("token", res.data.token)
  58. uni.setStorageSync("baseInfo", JSON.stringify(res.data.userInfo))
  59. uni.navigateBack({
  60. delta: 1
  61. })
  62. }
  63. })
  64. }
  65. })
  66. }
  67. // 获取openid
  68. // if (!getOpenIdKey() && !getToken()) {
  69. // uni.login({
  70. // provider: 'weixin',
  71. // success: async (res) => {
  72. // const {
  73. // code,
  74. // data
  75. // } = await getOpenId(res.code)
  76. // if (code === 200 && data) {
  77. // let resData = JSON.parse(data)
  78. // setOpenIdKey(resData.openId)
  79. // }
  80. // },
  81. // fail: function(error) {
  82. // // 授权失败处理
  83. // uni.showToast('授权失败,请授权后再试')
  84. // }
  85. // });
  86. // }
  87. // 获取token
  88. const onGetPhoneNumber = async (e) => {
  89. // uni.login({
  90. // success: res => {
  91. // console.log("====>", res)
  92. // }
  93. // })
  94. console.log(e)
  95. getPhoneNumber({
  96. phoneCode: e.detail.code
  97. })
  98. // if (e.detail.errMsg === "getPhoneNumber:ok") {
  99. // if (getOpenIdKey()) {
  100. // try {
  101. // const {
  102. // data
  103. // } = await getPhoneNumber({
  104. // "openId": getOpenIdKey(),
  105. // "code": e.detail.code,
  106. // sourceType: 1
  107. // })
  108. // setToken(data.token)
  109. // setIsLogin(true)
  110. // await getUserInfo()
  111. // } catch (e) {
  112. // uni.showToast({
  113. // icon: 'error',
  114. // title: '获取手机号失败'
  115. // })
  116. // }
  117. // }
  118. // }
  119. }
  120. // // h获取用户信息
  121. // const getUserInfo = async () => {
  122. // const {
  123. // data
  124. // } = await getPersonalInfo()
  125. // setStorage('userInfo', data)
  126. // uni.navigateBack()
  127. // }
  128. </script>
  129. <style scoped lang="scss">
  130. @import "index";
  131. @import "@/style/index.scss";
  132. .select {
  133. width: 24rpx;
  134. height: 24rpx;
  135. border-radius: 50%;
  136. border: 1rpx solid #C7C7C7;
  137. margin-right: 8rpx;
  138. .active {
  139. background-color: $mainColor;
  140. }
  141. }
  142. .footer {
  143. color: #C7C7C7;
  144. position: fixed;
  145. bottom: 100rpx;
  146. }
  147. </style>