login.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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" labelWidth="140"
  16. 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. } from 'vue';
  47. import sheep from '@/sheep';
  48. import {
  49. onLoad
  50. } from '@dcloudio/uni-app';
  51. import {
  52. showAuthModal,
  53. closeAuthModal,
  54. getSmsCode,
  55. getSmsTimer
  56. } from '@/sheep/hooks/useModal';
  57. import {
  58. code,
  59. mobile
  60. } from '@/sheep/validate/form';
  61. import AuthUtil from '@/sheep/api/member/auth';
  62. const smsLoginRef = ref(null);
  63. // 数据
  64. const state = reactive({
  65. isPopup:true,
  66. loginReqVO:{
  67. type:31,
  68. code:"",
  69. state:"",
  70. },
  71. isMobileEnd: false, // 手机号输入完毕
  72. codeText: '获取验证码',
  73. model: {
  74. mobile: '', // 手机号
  75. code: '', // 验证码
  76. scene: 1
  77. },
  78. rules: {
  79. code,
  80. mobile,
  81. },
  82. });
  83. // 短信登录
  84. async function OfficialEnterLogin() {
  85. // 参数校验
  86. const validate = await unref(smsLoginRef)
  87. .validate()
  88. .catch((error) => {
  89. console.log('error: ', error);
  90. });
  91. if (!validate) {
  92. return;
  93. }
  94. // 提交数据
  95. const {
  96. code
  97. } = await AuthUtil.OfficialEnterLogin({reqVO:state.model,loginReqVO:state.loginReqVO});
  98. if (code === 0) {
  99. closeAuthModal();
  100. // 检测 H5 登录回调
  101. let returnUrl = uni.getStorageSync('returnUrl');
  102. if (returnUrl) {
  103. uni.removeStorage('returnUrl');
  104. location.replace(returnUrl);
  105. } else {
  106. uni.switchTab({
  107. url: '/',
  108. });
  109. }
  110. }
  111. }
  112. onLoad(async (options) => {
  113. // #ifdef H5
  114. // 将 search 参数赋值到 options 中,方便下面解析
  115. new URLSearchParams(location.search).forEach((value, key) => {
  116. options[key] = value;
  117. });
  118. const event = options.event;
  119. const code = options.code;
  120. const state = options.state;
  121. state.loginReqVO.code = options.code
  122. state.loginReqVO.state = options.state
  123. if (event === 'login') { // 场景一:登录
  124. const res = await sheep.$platform.useProvider().login(code, state)
  125. if(!res){
  126. state.isPopup = true
  127. return false
  128. }
  129. } else if (event === 'bind') { // 场景二:绑定
  130. sheep.$platform.useProvider().bind(code, state);
  131. }
  132. // 检测 H5 登录回调
  133. let returnUrl = uni.getStorageSync('returnUrl');
  134. if (returnUrl) {
  135. uni.removeStorage('returnUrl');
  136. location.replace(returnUrl);
  137. } else {
  138. uni.switchTab({
  139. url: '/',
  140. });
  141. }
  142. // #endif
  143. });
  144. </script>
  145. <style lang="scss" scoped>
  146. .wx-login-btn {
  147. width: 100%;
  148. border: 1rpx solid #55b774;
  149. border-radius: 10rpx;
  150. padding: 10rpx 0;
  151. color: #333333;
  152. display: flex;
  153. align-items: center;
  154. justify-content: center;
  155. font-size: 32rpx;
  156. margin: 0 0 0.625rem 0;
  157. box-sizing: border-box;
  158. text {
  159. margin-left: 20rpx
  160. }
  161. }
  162. .login-wrap {
  163. padding: 50rpx 34rpx;
  164. min-height: 500rpx;
  165. background-color: #fff;
  166. border-radius: 20rpx 20rpx 0 0;
  167. }
  168. .code-btn-start {
  169. width: 160rpx;
  170. height: 56rpx;
  171. line-height: normal;
  172. border: 2rpx solid var(--ui-BG-Main);
  173. border-radius: 28rpx;
  174. font-size: 26rpx;
  175. font-weight: 400;
  176. color: var(--ui-BG-Main);
  177. opacity: 1;
  178. }
  179. .forgot-btn {
  180. width: 160rpx;
  181. line-height: 56rpx;
  182. font-size: 30rpx;
  183. font-weight: 500;
  184. color: #999;
  185. }
  186. .login-btn-start {
  187. width: 158rpx;
  188. height: 56rpx;
  189. line-height: normal;
  190. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  191. border-radius: 28rpx;
  192. font-size: 26rpx;
  193. font-weight: 500;
  194. color: #fff;
  195. }
  196. .type-btn {
  197. padding: 20rpx;
  198. margin: 40rpx auto;
  199. width: 200rpx;
  200. font-size: 30rpx;
  201. font-weight: 500;
  202. color: #999999;
  203. }
  204. .auto-login-box {
  205. width: 100%;
  206. .auto-login-btn {
  207. width: 68rpx;
  208. height: 68rpx;
  209. border-radius: 50%;
  210. margin: 0 30rpx;
  211. }
  212. .auto-login-img {
  213. width: 68rpx;
  214. height: 68rpx;
  215. border-radius: 50%;
  216. }
  217. }
  218. // 修改密码
  219. .editPwd-btn-box {
  220. .save-btn {
  221. width: 690rpx;
  222. line-height: 70rpx;
  223. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  224. border-radius: 35rpx;
  225. font-size: 28rpx;
  226. font-weight: 500;
  227. color: #ffffff;
  228. }
  229. .forgot-btn {
  230. width: 690rpx;
  231. line-height: 70rpx;
  232. font-size: 28rpx;
  233. font-weight: 500;
  234. color: #999999;
  235. }
  236. }
  237. .code-btn-start {
  238. color: #55b774;
  239. border: 1px solid #55b774;
  240. }
  241. .login-btn-start {
  242. background: rgb(14, 147, 46);
  243. width: 100%;
  244. height: 80rpx;
  245. font-size: 32rpx;
  246. }
  247. .loginUniForm {
  248. border: 1rpx solid #d6d6d6;
  249. padding: 10rpx 15rpx;
  250. border-radius: 10rpx;
  251. }
  252. .loginUniFormItem:first-child {
  253. border-bottom: 1rpx solid #d6d6d6;
  254. padding-bottom: 10rpx;
  255. }
  256. .loginUniFormItem:last-child {
  257. // border-bottom: 1rpx solid #d6d6d6;
  258. padding-top: 10rpx;
  259. }
  260. ::v-deep .loginUniFormItem .uni-forms-item__inner {
  261. padding-bottom: 0;
  262. }
  263. ::v-deep .loginUniFormItem .uni-error-message {
  264. bottom: -20rpx;
  265. }
  266. </style>