index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <view class="page-box login-box">
  3. <view class="login-form sys-radius-50">
  4. <view class="from-title">
  5. <view class="title-list">
  6. <view class="title-text sys-size-28 text-center sys-weight-600" :class="{'default-text':type===1}"
  7. @click="setType(1)">验证码登录</view>
  8. <view class="title-text sys-size-28 text-center sys-weight-600" :class="{'default-text':type===2}"
  9. @click="setType(2)">密码登录</view>
  10. </view>
  11. <view class="title-bg sys-background-fff" :class="{'title-bg-two':type===2}">
  12. <view class="bg-icon sys-background-dominant "></view>
  13. </view>
  14. </view>
  15. <view class="from-box sys-background-fff " :class="{'one-from':type===1,'two-from':type===2}">
  16. <view class="from-animation animate__animated animate__fadeIn" v-if="type===1">
  17. <view class="input-item sys-from-background-color sys-radius-30 "
  18. :class="{'apply-shake':phoneShake}">
  19. <en-input type="number" class="login-input" placeholder="请输入手机号" v-model="loginData.phone"
  20. maxlength="11"></en-input>
  21. </view>
  22. <view class="input-item input-send sys-from-background-color sys-radius-30"
  23. :class="{'apply-shake':codedShake}">
  24. <en-input type="number" class="login-input" placeholder="请输入验证码" v-model="loginData.code"
  25. maxlength="6"></en-input>
  26. <view class="login-send text-color-dominant sys-size-28 sys-weight-400" @click="getVerifiedCode"
  27. v-if="timeNum<=0">发送验证码</view>
  28. <view class="login-send text-color-dominant sys-size-28 sys-weight-400" v-else>{{ timeNum }} s
  29. </view>
  30. </view>
  31. </view>
  32. <view class="from-animation animate__animated animate__fadeIn" v-else>
  33. <view class="input-item sys-from-background-color sys-radius-30 "
  34. :class="{'apply-shake':phoneShake}">
  35. <en-input type="number" class="login-input" placeholder="请输入手机号" v-model="loginData.phone"
  36. maxlength="11"></en-input>
  37. </view>
  38. <view class="input-item input-send sys-from-background-color sys-radius-30"
  39. :class="{'apply-shake':passwordShake}">
  40. <en-input type="password" class="login-input" placeholder="请输入密码"
  41. v-model="loginData.password"></en-input>
  42. <view class="login-send text-color-dominant sys-size-28 sys-weight-400" @click="goToUrl(2)">
  43. 忘记密码?</view>
  44. </view>
  45. </view>
  46. <agreement v-model="isConsent" ref="agreement"></agreement>
  47. <view class="input-but sys-background-dominant text-color-fff sys-size-30 sys-radius-100 sys-weight-600"
  48. :class="{'sys-selected-but':isLogin,'sys-unselected-but':!isLogin}" @click="login">登陆</view>
  49. </view>
  50. </view>
  51. <view class="register-box">
  52. <view class="register-text sys-weight-400 sys-size-24 text-color-666">还没有账号?</view>
  53. <view class="register-text text-color-dominant sys-size-24 sys-weight-400" @click="goToUrl(1)">立即注册</view>
  54. </view>
  55. <view class="wx-box">
  56. <view class="wx-title">
  57. <view class="wx-wire"></view>
  58. <view class="wx-text sys-size-24 text-color-7c sys-weight-400">第三方登录</view>
  59. <view class="wx-wire"></view>
  60. </view>
  61. <image @click="wxLogin" class="wx-logo"
  62. src="https://wealfavor-1257406827.cos.ap-beijing.myqcloud.com/new-xcx/login/wx-img.png"
  63. mode="aspectFill"></image>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import {
  69. commonSend
  70. } from "@/api/common";
  71. import tools from "@/service/tools";
  72. import {
  73. login,
  74. wxLogin
  75. } from "@/api/login";
  76. import EnInput from "@/components/en-from/en-input/index.vue";
  77. import Agreement from "@/pages/login/model/agreement.vue";
  78. export default {
  79. components: {
  80. Agreement,
  81. EnInput
  82. },
  83. data() {
  84. return {
  85. type: 1,
  86. loginData: {
  87. phone: '18623152213',
  88. password: '',
  89. code: '1234',
  90. },
  91. phoneShake: false,
  92. passwordShake: false,
  93. codedShake: false,
  94. consentShake: false,
  95. isConsent: false,
  96. isLogin: false,
  97. timeNum: 0,
  98. timer: null,
  99. }
  100. },
  101. watch: {
  102. 'loginData': {
  103. handler() {
  104. this.verifyData()
  105. },
  106. deep: true
  107. },
  108. 'isConsent': function() {
  109. this.verifyData()
  110. }
  111. },
  112. mounted() {
  113. },
  114. methods: {
  115. wxLogin() {
  116. if (!this.isConsent) {
  117. tools.error('请阅读并同意协议');
  118. this.$refs.agreement.setConsentShake()
  119. return;
  120. }
  121. if (this.isAjax) {
  122. return false;
  123. }
  124. this.isAjax = true;
  125. uni.login({
  126. provider: "weixin",
  127. success: (loginRes) => {
  128. wxLogin({
  129. 'code': loginRes.code
  130. }).then((res) => {
  131. if (res.code === 403) {
  132. tools.error('当前用户未注册')
  133. uni.setStorageSync('openid', res.data.openid)
  134. setTimeout(() => {
  135. //跳转至注册页面
  136. uni.navigateTo({
  137. url: '/pages/login/register'
  138. });
  139. }, 1500)
  140. } else if (res.code === 1) {
  141. tools.setLoginData(res.data, true)
  142. } else {
  143. tools.error(res.msg)
  144. }
  145. this.isAjax = false;
  146. })
  147. }
  148. })
  149. },
  150. goToUrl(type) {
  151. if (type === 1) {
  152. uni.navigateTo({
  153. 'url': '/pages/login/register'
  154. })
  155. } else if (type === 2) {
  156. uni.navigateTo({
  157. 'url': '/pages/login/forget'
  158. })
  159. } else {
  160. }
  161. },
  162. setShake(type) {
  163. if (type === 1) {
  164. this.phoneShake = true
  165. } else if (type === 2) {
  166. this.passwordShake = true
  167. } else if (type === 3) {
  168. this.codedShake = true
  169. } else if (type === 4) {
  170. this.$refs.agreement.setConsentShake()
  171. }
  172. setTimeout(() => {
  173. this.phoneShake = false
  174. this.passwordShake = false
  175. this.codedShake = false
  176. }, 500)
  177. },
  178. login() {
  179. if (this.loginData.phone === '') {
  180. tools.error('请输入手机号码');
  181. this.setShake(1)
  182. return;
  183. }
  184. if (this.type !== 1) {
  185. if (this.loginData.password === '') {
  186. this.setShake(2)
  187. tools.error('请输入登陆密码');
  188. return;
  189. }
  190. } else {
  191. if (this.loginData.code === '') {
  192. this.setShake(3)
  193. tools.error('请输入验证码');
  194. return;
  195. }
  196. }
  197. if (!this.isConsent) {
  198. this.setShake(4)
  199. tools.error('请阅读并同意协议');
  200. return;
  201. }
  202. login(this.loginData).then((res) => {
  203. if (res.code === 1) {
  204. tools.setLoginData(res.data, true)
  205. } else {
  206. tools.error(res.msg)
  207. }
  208. })
  209. },
  210. verifyData() {
  211. if (this.type === 1) {
  212. this.isLogin = this.loginData.phone !== '' && this.loginData.code !== '' && this.isConsent
  213. } else {
  214. this.isLogin = this.loginData.phone !== '' && this.loginData.password !== '' && this.isConsent
  215. }
  216. },
  217. getVerifiedCode() {
  218. if (this.timeNum > 0) {
  219. return;
  220. }
  221. if (this.loginData.phone === '') {
  222. tools.error("请输入手机号码")
  223. return;
  224. }
  225. let regPhone = /^(?:(?:\+|00)86)?1\d{10}$/;
  226. if (!regPhone.test(this.loginData.phone)) {
  227. tools.error("手机号码格式错误")
  228. return;
  229. }
  230. commonSend({
  231. 'phone': this.loginData.phone,
  232. 'send_type': 'retrieve'
  233. }).then((res) => {
  234. if (res.code === 1) {
  235. tools.success(res.msg);
  236. this.timeNum = 60;
  237. this.timer = setInterval(() => {
  238. this.timeNum--;
  239. if (this.timeNum <= 0) {
  240. clearInterval(this.timer);
  241. }
  242. }, 1000);
  243. } else {
  244. tools.error(res.msg);
  245. }
  246. })
  247. },
  248. setIsConsent() {
  249. this.isConsent = !this.isConsent
  250. },
  251. setType(type) {
  252. if (type !== this.type) {
  253. this.type = type
  254. }
  255. },
  256. },
  257. }
  258. </script>
  259. <style lang="scss" scoped>
  260. @import "/static/css/login.css";
  261. .page-box {
  262. position: relative;
  263. padding-top: 370rpx;
  264. .login-form {
  265. margin: 0 30rpx;
  266. border-radius: 50rpx;
  267. background-color: rgba(255, 255, 255, 0.5);
  268. .from-title {
  269. border-radius: 50rpx 50rpx 0 0;
  270. height: 110rpx;
  271. position: relative;
  272. .title-bg {
  273. position: absolute;
  274. border-radius: 50rpx 50rpx 0 0;
  275. top: 0;
  276. left: 0;
  277. height: 110rpx;
  278. width: 50%;
  279. transition: .5s ease;
  280. z-index: 0;
  281. .bg-icon {
  282. margin: 86rpx auto 0 auto;
  283. width: 36rpx;
  284. height: 6rpx;
  285. border-radius: 99rpx;
  286. }
  287. }
  288. .title-bg-two {
  289. left: 50%;
  290. transition: .5s ease;
  291. }
  292. //.title-bg::after {
  293. // content: '';
  294. // position: absolute;
  295. // right: -50rpx;
  296. // bottom: 0;
  297. // width: 50rpx;
  298. // height:50rpx;
  299. // background-color: #fff;
  300. // border-radius: 50rpx 50rpx 50rpx 0;
  301. //}
  302. .title-list {
  303. display: flex;
  304. justify-content: space-between;
  305. z-index: 1;
  306. position: relative;
  307. .title-text {
  308. width: 50%;
  309. height: 110rpx;
  310. line-height: 102rpx;
  311. color: #333333;
  312. }
  313. .default-text {
  314. color: #10B261;
  315. }
  316. .title-text:first-child {
  317. background-image: url("https://wealfavor-1257406827.cos.ap-beijing.myqcloud.com/new-xcx/login/right.png");
  318. background-repeat: no-repeat;
  319. background-position: right bottom;
  320. }
  321. .title-text:last-child {
  322. background-image: url("https://wealfavor-1257406827.cos.ap-beijing.myqcloud.com/new-xcx/login/left.png");
  323. background-repeat: no-repeat;
  324. background-position: left bottom;
  325. }
  326. }
  327. }
  328. .from-box {
  329. box-shadow: 0rpx 4rpx 36rpx 0rpx rgba(196, 196, 196, 0.25);
  330. border-radius: 0 0 50rpx 50rpx;
  331. padding: 50rpx 45rpx;
  332. .input-item {
  333. height: 96rpx;
  334. padding: 28rpx 40rpx;
  335. box-sizing: border-box;
  336. .login-input {
  337. width: 100%;
  338. }
  339. }
  340. .input-item:last-child {
  341. margin-top: 30rpx;
  342. }
  343. .input-send {
  344. display: flex;
  345. justify-content: flex-start;
  346. align-items: center;
  347. .login-input {
  348. width: calc(100% - 140rpx);
  349. }
  350. .login-send {
  351. width: 140rpx;
  352. text-align: center;
  353. }
  354. }
  355. .input-but {
  356. margin-top: 40rpx;
  357. width: 100%;
  358. height: 96rpx;
  359. line-height: 96rpx;
  360. text-align: center;
  361. }
  362. }
  363. .one-from {
  364. border-radius: 0 50rpx 50rpx 50rpx;
  365. transition: 0.85s ease;
  366. }
  367. .two-from {
  368. border-radius: 50rpx 0 50rpx 50rpx;
  369. transition: 0.85s ease;
  370. }
  371. }
  372. .register-box {
  373. display: flex;
  374. justify-content: center;
  375. align-items: center;
  376. margin-top: 60rpx;
  377. .register-text {
  378. height: 34rpx;
  379. line-height: 34rpx;
  380. }
  381. .register-text:last-child {
  382. margin-right: 5rpx;
  383. }
  384. }
  385. .wx-box {
  386. position: absolute;
  387. bottom: calc(60rpx + env(safe-area-inset-bottom));
  388. left: 0;
  389. width: 100%;
  390. display: flex;
  391. flex-direction: column;
  392. justify-content: center;
  393. .wx-title {
  394. display: flex;
  395. justify-content: center;
  396. align-items: center;
  397. .wx-wire {
  398. background: linear-gradient(90deg, #D9D9D9 0%, rgba(115, 115, 115, 0) 100%);
  399. width: 174rpx;
  400. height: 2rpx;
  401. border-radius: 50%;
  402. }
  403. .wx-text {
  404. margin: 0 15rpx;
  405. height: 34rpx;
  406. line-height: 34rpx;
  407. }
  408. }
  409. .wx-logo {
  410. margin: 25rpx auto 0 auto;
  411. width: 80rpx;
  412. height: 80rpx;
  413. }
  414. }
  415. }
  416. </style>