login.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. onBeforeMount
  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. onBeforeMount(() => {
  114. const options = {}
  115. new URLSearchParams(location.search).forEach((value, key) => {
  116. options[key] = value;
  117. });
  118. state.loginReqVO.code = options.code
  119. state.loginReqVO.state = options.state
  120. })
  121. onLoad(async (options) => {
  122. // #ifdef H5
  123. // 将 search 参数赋值到 options 中,方便下面解析
  124. new URLSearchParams(location.search).forEach((value, key) => {
  125. options[key] = value;
  126. });
  127. const event = options.event;
  128. const code = options.code;
  129. const state = options.state;
  130. if (event === 'login') { // 场景一:登录
  131. const res = await sheep.$platform.useProvider().login(code, state)
  132. if (!res) {
  133. state.isPopup = true
  134. return false
  135. }
  136. } else if (event === 'bind') { // 场景二:绑定
  137. sheep.$platform.useProvider().bind(code, state);
  138. }
  139. // 检测 H5 登录回调
  140. let returnUrl = uni.getStorageSync('returnUrl');
  141. if (returnUrl) {
  142. uni.removeStorage('returnUrl');
  143. location.replace(returnUrl);
  144. } else {
  145. uni.switchTab({
  146. url: '/',
  147. });
  148. }
  149. // #endif
  150. });
  151. </script>
  152. <style lang="scss" scoped>
  153. @keyframes title-animation {
  154. 0% {
  155. font-size: 32rpx;
  156. }
  157. 100% {
  158. font-size: 36rpx;
  159. }
  160. }
  161. .login-wrap {
  162. padding: 50rpx 34rpx;
  163. min-height: 500rpx;
  164. background-color: #fff;
  165. border-radius: 20rpx 20rpx 0 0;
  166. }
  167. .head-box {
  168. .head-title {
  169. min-width: 160rpx;
  170. font-size: 36rpx;
  171. font-weight: bold;
  172. color: #333333;
  173. line-height: 36rpx;
  174. }
  175. .head-title-active {
  176. width: 160rpx;
  177. font-size: 32rpx;
  178. font-weight: 600;
  179. color: #999;
  180. line-height: 36rpx;
  181. }
  182. .head-title-animation {
  183. animation-name: title-animation;
  184. animation-duration: 0.1s;
  185. animation-timing-function: ease-out;
  186. animation-fill-mode: forwards;
  187. }
  188. .head-title-line {
  189. position: relative;
  190. &::before {
  191. content: '';
  192. width: 1rpx;
  193. height: 34rpx;
  194. background-color: #e4e7ed;
  195. position: absolute;
  196. left: -30rpx;
  197. top: 50%;
  198. transform: translateY(-50%);
  199. }
  200. }
  201. .head-subtitle {
  202. font-size: 26rpx;
  203. font-weight: 400;
  204. color: #afb6c0;
  205. text-align: left;
  206. display: flex;
  207. }
  208. }
  209. // .code-btn[disabled] {
  210. // background-color: #fff;
  211. // }
  212. .code-btn-start {
  213. width: 160rpx;
  214. height: 56rpx;
  215. line-height: normal;
  216. border: 2rpx solid var(--ui-BG-Main);
  217. border-radius: 28rpx;
  218. font-size: 26rpx;
  219. font-weight: 400;
  220. color: var(--ui-BG-Main);
  221. opacity: 1;
  222. }
  223. .forgot-btn {
  224. width: 160rpx;
  225. line-height: 56rpx;
  226. font-size: 30rpx;
  227. font-weight: 500;
  228. color: #999;
  229. }
  230. .login-btn-start {
  231. width: 158rpx;
  232. height: 56rpx;
  233. line-height: normal;
  234. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  235. border-radius: 28rpx;
  236. font-size: 26rpx;
  237. font-weight: 500;
  238. color: #fff;
  239. }
  240. .type-btn {
  241. padding: 20rpx;
  242. margin: 40rpx auto;
  243. width: 200rpx;
  244. font-size: 30rpx;
  245. font-weight: 500;
  246. color: #999999;
  247. }
  248. .agreement-box {
  249. margin: 80rpx auto 0;
  250. .protocol-check {
  251. transform: scale(0.7);
  252. }
  253. .agreement-text {
  254. font-size: 26rpx;
  255. font-weight: 500;
  256. color: #999999;
  257. .tcp-text {
  258. color: var(--ui-BG-Main);
  259. }
  260. }
  261. }
  262. </style>