index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <script lang="ts" setup>
  2. import { weixinMiniAppLogin } from '@/core/libs/requests'
  3. const loginCode = ref('')
  4. const phoneCode = ref('')
  5. const loginType = ref('weixin')
  6. const loginTypeOption = ref([
  7. {
  8. value: 'weixin',
  9. text: '微信',
  10. },
  11. {
  12. value: 'univerify',
  13. text: '一键登录',
  14. },
  15. {
  16. value: 'username',
  17. text: '账号密码',
  18. },
  19. {
  20. value: 'smsCode',
  21. text: '手机验证码',
  22. },
  23. ])
  24. const toLogin = () => {
  25. if (loginType.value === 'username') {
  26. uni.navigateTo({
  27. url: '/uni_modules/uni-id-pages/pages/login/login-withpwd',
  28. })
  29. } else {
  30. uni.navigateTo({
  31. url: '/pages/login/login-withoutpwd?type=' + loginType.value,
  32. animationType: 'none',
  33. animationDuration: 0,
  34. })
  35. }
  36. }
  37. const toUserInfoPage = () => {
  38. uni.navigateTo({
  39. url: '/uni_modules/uni-id-pages/pages/userinfo/userinfo?showLoginManage=true',
  40. })
  41. }
  42. const weixinLogin = async () => {
  43. // wx.getPhoneNumber
  44. }
  45. const getPhoneNumber = async ({ detail }) => {
  46. console.log(phoneCode)
  47. phoneCode.value = detail.code
  48. const { code } = await uni.login()
  49. loginCode.value = code
  50. console.log(code)
  51. const a = await weixinMiniAppLogin(phoneCode.value, code, '9b2ffbc1-7425-4155-9894-9d5c08541d62')
  52. console.log(a)
  53. }
  54. const getTestCode = async ({ detail }) => {
  55. phoneCode.value = detail.code
  56. const { code } = await uni.login()
  57. loginCode.value = code
  58. }
  59. </script>
  60. <template>
  61. <view class="content">
  62. <textarea v-model="loginCode" placeholder="" placeholder-class="textarea-placeholder" />
  63. <textarea v-model="phoneCode" placeholder="" placeholder-class="textarea-placeholder" />
  64. <button style="margin: 20px 0 20px 0" @click="toUserInfoPage">个人资料</button>
  65. <uni-forms-item label="切换登录方式" labelWidth="70">
  66. <uni-data-checkbox
  67. :multiple="false"
  68. v-model="loginType"
  69. :localdata="loginTypeOption"
  70. mode="button"
  71. ></uni-data-checkbox>
  72. </uni-forms-item>
  73. <button @click="weixinLogin">前往登录</button>
  74. <!-- #ifdef MP-WEIXIN -->
  75. <button type="primary" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  76. 手机号一键登录
  77. </button>
  78. <!-- #endif -->
  79. <!-- #ifdef MP-WEIXIN -->
  80. <button type="primary" open-type="getPhoneNumber" @getphonenumber="getTestCode">
  81. 获取测试码
  82. </button>
  83. <!-- #endif -->
  84. </view>
  85. </template>
  86. <style lang="scss">
  87. .content {
  88. display: flex;
  89. flex-direction: column;
  90. align-items: center;
  91. justify-content: center;
  92. padding: 6rpx;
  93. }
  94. .logo {
  95. width: 200rpx;
  96. height: 200rpx;
  97. margin-top: 200rpx;
  98. margin-right: auto;
  99. margin-bottom: 50rpx;
  100. margin-left: auto;
  101. }
  102. .text-area {
  103. display: flex;
  104. justify-content: center;
  105. }
  106. .title {
  107. font-size: 18px;
  108. color: #8f8f94;
  109. }
  110. </style>