login.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <!-- 微信公众号的登录回调页 -->
  2. <template>
  3. <!-- 空登陆页 -->
  4. <view />
  5. <su-popup :show="state.isPopup" round="10" :showClose="false" @close="closeAuthModal">
  6. <view>
  7. <view class="head-box ">
  8. <view class="ss-flex ss-m-b-20">
  9. <view class="isActive head-title">
  10. 您首次登录,请输入手机号验证
  11. </view>
  12. </view>
  13. </view>
  14. <!-- 表单项 -->
  15. <uni-forms ref="smsLoginRef" v-model="state.model" :rules="state.rules" validateTrigger="bind"
  16. labelWidth="140" labelAlign="center" class="loginUniForm">
  17. <uni-forms-item name="mobile" label="手机号" class="loginUniFormItem">
  18. <uni-easyinput placeholder="请输入手机号" v-model="state.model.mobile" :inputBorder="false" type="number">
  19. <template v-slot:right>
  20. <button class="ss-reset-button code-btn code-btn-start" :disabled="state.isMobileEnd"
  21. :class="{ 'code-btn-end': state.isMobileEnd }"
  22. @tap="getSmsCode('smsLogin', state.model.mobile)">
  23. {{ getSmsTimer('smsLogin') }}
  24. </button>
  25. </template>
  26. </uni-easyinput>
  27. </uni-forms-item>
  28. <uni-forms-item name="code" label="验证码" class="loginUniFormItem">
  29. <uni-easyinput placeholder="请输入验证码" v-model="state.model.code" :inputBorder="false" type="number"
  30. maxlength="4">
  31. </uni-easyinput>
  32. </uni-forms-item>
  33. </uni-forms>
  34. <view style="display: flex;justify-content: space-between;margin-top: 20rpx;">
  35. <button class="ss-reset-button login-btn-start" @tap="OfficialEnterLogin"> 继续登录 </button>
  36. </view>
  37. </view>
  38. </su-popup>
  39. </template>
  40. <script setup>
  41. import {
  42. ref,
  43. reactive,
  44. unref,
  45. computed,
  46. onMounted
  47. } from 'vue';
  48. import sheep from '@/sheep';
  49. import {
  50. onLoad
  51. } from '@dcloudio/uni-app';
  52. import {
  53. showAuthModal,
  54. closeAuthModal,
  55. getSmsCode,
  56. getSmsTimer
  57. } from '@/sheep/hooks/useModal';
  58. import {
  59. code,
  60. mobile
  61. } from '@/sheep/validate/form';
  62. import AuthUtil from '@/sheep/api/member/auth';
  63. const smsLoginRef = ref(null);
  64. // 数据
  65. const state = reactive({
  66. isPopup: true,
  67. loginReqVO: {
  68. type: 31,
  69. code: "",
  70. state: "",
  71. },
  72. isMobileEnd: false, // 手机号输入完毕
  73. codeText: '获取验证码',
  74. model: {
  75. mobile: '', // 手机号
  76. code: '', // 验证码
  77. scene: 1
  78. },
  79. rules: {
  80. code,
  81. mobile,
  82. },
  83. });
  84. // 短信登录
  85. async function OfficialEnterLogin() {
  86. // 参数校验
  87. const validate = await unref(smsLoginRef)
  88. .validate()
  89. .catch((error) => {
  90. console.log('error: ', error);
  91. });
  92. if (!validate) {
  93. return;
  94. }
  95. // 提交数据
  96. const {
  97. code
  98. } = await AuthUtil.OfficialEnterLogin(state.model, state.loginReqVO);
  99. if (code === 0) {
  100. closeAuthModal();
  101. // 检测 H5 登录回调
  102. let returnUrl = uni.getStorageSync('returnUrl');
  103. if (returnUrl) {
  104. uni.removeStorage('returnUrl');
  105. location.replace(returnUrl);
  106. } else {
  107. uni.switchTab({
  108. url: '/',
  109. });
  110. }
  111. }
  112. }
  113. onMounted(async (options) => {
  114. const instance = getCurrentInstance();
  115. if (instance) {
  116. // #ifdef H5
  117. // 将 search 参数赋值到 options 中,方便下面解析
  118. new URLSearchParams(location.search).forEach((value, key) => {
  119. options[key] = value;
  120. });
  121. const event = options.event;
  122. const code = options.code;
  123. const state = options.state;
  124. console.log("state.loginReqVO", state.loginReqVO)
  125. state.loginReqVO.code = options.code
  126. state.loginReqVO.state = options.state
  127. if (event === 'login') { // 场景一:登录
  128. const res = await sheep.$platform.useProvider().login(code, state)
  129. if (!res) {
  130. state.isPopup = true
  131. return false
  132. }
  133. } else if (event === 'bind') { // 场景二:绑定
  134. sheep.$platform.useProvider().bind(code, state);
  135. }
  136. // 检测 H5 登录回调
  137. let returnUrl = uni.getStorageSync('returnUrl');
  138. if (returnUrl) {
  139. uni.removeStorage('returnUrl');
  140. location.replace(returnUrl);
  141. } else {
  142. uni.switchTab({
  143. url: '/',
  144. });
  145. }
  146. // #endif
  147. }
  148. });
  149. </script>
  150. <style lang="scss" scoped>
  151. @keyframes title-animation {
  152. 0% {
  153. font-size: 32rpx;
  154. }
  155. 100% {
  156. font-size: 36rpx;
  157. }
  158. }
  159. .login-wrap {
  160. padding: 50rpx 34rpx;
  161. min-height: 500rpx;
  162. background-color: #fff;
  163. border-radius: 20rpx 20rpx 0 0;
  164. }
  165. .head-box {
  166. .head-title {
  167. min-width: 160rpx;
  168. font-size: 36rpx;
  169. font-weight: bold;
  170. color: #333333;
  171. line-height: 36rpx;
  172. }
  173. .head-title-active {
  174. width: 160rpx;
  175. font-size: 32rpx;
  176. font-weight: 600;
  177. color: #999;
  178. line-height: 36rpx;
  179. }
  180. .head-title-animation {
  181. animation-name: title-animation;
  182. animation-duration: 0.1s;
  183. animation-timing-function: ease-out;
  184. animation-fill-mode: forwards;
  185. }
  186. .head-title-line {
  187. position: relative;
  188. &::before {
  189. content: '';
  190. width: 1rpx;
  191. height: 34rpx;
  192. background-color: #e4e7ed;
  193. position: absolute;
  194. left: -30rpx;
  195. top: 50%;
  196. transform: translateY(-50%);
  197. }
  198. }
  199. .head-subtitle {
  200. font-size: 26rpx;
  201. font-weight: 400;
  202. color: #afb6c0;
  203. text-align: left;
  204. display: flex;
  205. }
  206. }
  207. // .code-btn[disabled] {
  208. // background-color: #fff;
  209. // }
  210. .code-btn-start {
  211. width: 160rpx;
  212. height: 56rpx;
  213. line-height: normal;
  214. border: 2rpx solid var(--ui-BG-Main);
  215. border-radius: 28rpx;
  216. font-size: 26rpx;
  217. font-weight: 400;
  218. color: var(--ui-BG-Main);
  219. opacity: 1;
  220. }
  221. .forgot-btn {
  222. width: 160rpx;
  223. line-height: 56rpx;
  224. font-size: 30rpx;
  225. font-weight: 500;
  226. color: #999;
  227. }
  228. .login-btn-start {
  229. width: 158rpx;
  230. height: 56rpx;
  231. line-height: normal;
  232. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  233. border-radius: 28rpx;
  234. font-size: 26rpx;
  235. font-weight: 500;
  236. color: #fff;
  237. }
  238. .type-btn {
  239. padding: 20rpx;
  240. margin: 40rpx auto;
  241. width: 200rpx;
  242. font-size: 30rpx;
  243. font-weight: 500;
  244. color: #999999;
  245. }
  246. .agreement-box {
  247. margin: 80rpx auto 0;
  248. .protocol-check {
  249. transform: scale(0.7);
  250. }
  251. .agreement-text {
  252. font-size: 26rpx;
  253. font-weight: 500;
  254. color: #999999;
  255. .tcp-text {
  256. color: var(--ui-BG-Main);
  257. }
  258. }
  259. }
  260. </style>