index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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: '',
  88. password: '',
  89. code: '',
  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. if (res.data.status * 1 === 0){
  142. tools.error('信息正在审核...')
  143. }else {
  144. tools.setLoginData(res.data, true)
  145. }
  146. } else {
  147. tools.error(res.msg)
  148. }
  149. this.isAjax = false;
  150. })
  151. }
  152. })
  153. },
  154. goToUrl(type) {
  155. if (type === 1) {
  156. uni.navigateTo({
  157. 'url': '/pages/login/register'
  158. })
  159. } else if (type === 2) {
  160. uni.navigateTo({
  161. 'url': '/pages/login/forget'
  162. })
  163. } else {
  164. }
  165. },
  166. setShake(type) {
  167. if (type === 1) {
  168. this.phoneShake = true
  169. } else if (type === 2) {
  170. this.passwordShake = true
  171. } else if (type === 3) {
  172. this.codedShake = true
  173. } else if (type === 4) {
  174. this.$refs.agreement.setConsentShake()
  175. }
  176. setTimeout(() => {
  177. this.phoneShake = false
  178. this.passwordShake = false
  179. this.codedShake = false
  180. }, 500)
  181. },
  182. login() {
  183. if (this.loginData.phone === '') {
  184. tools.error('请输入手机号码');
  185. this.setShake(1)
  186. return;
  187. }
  188. if (this.type !== 1) {
  189. if (this.loginData.password === '') {
  190. this.setShake(2)
  191. tools.error('请输入登陆密码');
  192. return;
  193. }
  194. } else {
  195. if (this.loginData.code === '') {
  196. this.setShake(3)
  197. tools.error('请输入验证码');
  198. return;
  199. }
  200. }
  201. if (!this.isConsent) {
  202. this.setShake(4)
  203. tools.error('请阅读并同意协议');
  204. return;
  205. }
  206. login(this.loginData).then((res) => {
  207. if (res.code === 1) {
  208. tools.setLoginData(res.data, true)
  209. } else {
  210. tools.error(res.msg)
  211. }
  212. })
  213. },
  214. verifyData() {
  215. if (this.type === 1) {
  216. this.isLogin = this.loginData.phone !== '' && this.loginData.code !== '' && this.isConsent
  217. } else {
  218. this.isLogin = this.loginData.phone !== '' && this.loginData.password !== '' && this.isConsent
  219. }
  220. },
  221. getVerifiedCode() {
  222. if (this.timeNum > 0) {
  223. return;
  224. }
  225. if (this.loginData.phone === '') {
  226. tools.error("请输入手机号码")
  227. return;
  228. }
  229. let regPhone = /^(?:(?:\+|00)86)?1\d{10}$/;
  230. if (!regPhone.test(this.loginData.phone)) {
  231. tools.error("手机号码格式错误")
  232. return;
  233. }
  234. uni.login({
  235. provider: "weixin",
  236. success: (loginRes) => {
  237. commonSend({
  238. 'phone': this.loginData.phone,
  239. 'send_type': 'retrieve',
  240. 'wxCode':loginRes.code
  241. }).then((res) => {
  242. if (res.code === 1) {
  243. tools.success(res.msg);
  244. this.timeNum = 60;
  245. this.timer = setInterval(() => {
  246. this.timeNum--;
  247. if (this.timeNum <= 0) {
  248. clearInterval(this.timer);
  249. }
  250. }, 1000);
  251. } else {
  252. tools.error(res.msg);
  253. }
  254. })
  255. }
  256. })
  257. },
  258. setIsConsent() {
  259. this.isConsent = !this.isConsent
  260. },
  261. setType(type) {
  262. if (type !== this.type) {
  263. this.type = type
  264. }
  265. },
  266. },
  267. }
  268. </script>
  269. <style lang="scss" scoped>
  270. @import "/static/css/login.css";
  271. .page-box {
  272. position: relative;
  273. padding-top: 370rpx;
  274. .login-form {
  275. margin: 0 30rpx;
  276. border-radius: 50rpx;
  277. background-color: rgba(255, 255, 255, 0.5);
  278. .from-title {
  279. border-radius: 50rpx 50rpx 0 0;
  280. height: 110rpx;
  281. position: relative;
  282. .title-bg {
  283. position: absolute;
  284. border-radius: 50rpx 50rpx 0 0;
  285. top: 0;
  286. left: 0;
  287. height: 110rpx;
  288. width: 50%;
  289. transition: .5s ease;
  290. z-index: 0;
  291. .bg-icon {
  292. margin: 86rpx auto 0 auto;
  293. width: 36rpx;
  294. height: 6rpx;
  295. border-radius: 99rpx;
  296. }
  297. }
  298. .title-bg-two {
  299. left: 50%;
  300. transition: .5s ease;
  301. }
  302. //.title-bg::after {
  303. // content: '';
  304. // position: absolute;
  305. // right: -50rpx;
  306. // bottom: 0;
  307. // width: 50rpx;
  308. // height:50rpx;
  309. // background-color: #fff;
  310. // border-radius: 50rpx 50rpx 50rpx 0;
  311. //}
  312. .title-list {
  313. display: flex;
  314. justify-content: space-between;
  315. z-index: 1;
  316. position: relative;
  317. .title-text {
  318. width: 50%;
  319. height: 110rpx;
  320. line-height: 102rpx;
  321. color: #333333;
  322. }
  323. .default-text {
  324. color: #10B261;
  325. }
  326. .title-text:first-child {
  327. background-image: url("https://wealfavor-1257406827.cos.ap-beijing.myqcloud.com/new-xcx/login/right.png");
  328. background-repeat: no-repeat;
  329. background-position: right bottom;
  330. }
  331. .title-text:last-child {
  332. background-image: url("https://wealfavor-1257406827.cos.ap-beijing.myqcloud.com/new-xcx/login/left.png");
  333. background-repeat: no-repeat;
  334. background-position: left bottom;
  335. }
  336. }
  337. }
  338. .from-box {
  339. box-shadow: 0rpx 4rpx 36rpx 0rpx rgba(196, 196, 196, 0.25);
  340. border-radius: 0 0 50rpx 50rpx;
  341. padding: 50rpx 45rpx;
  342. .input-item {
  343. height: 96rpx;
  344. padding: 28rpx 40rpx;
  345. box-sizing: border-box;
  346. .login-input {
  347. width: 100%;
  348. }
  349. }
  350. .input-item:last-child {
  351. margin-top: 30rpx;
  352. }
  353. .input-send {
  354. display: flex;
  355. justify-content: flex-start;
  356. align-items: center;
  357. .login-input {
  358. width: calc(100% - 140rpx);
  359. }
  360. .login-send {
  361. width: 140rpx;
  362. text-align: center;
  363. }
  364. }
  365. .input-but {
  366. margin-top: 40rpx;
  367. width: 100%;
  368. height: 96rpx;
  369. line-height: 96rpx;
  370. text-align: center;
  371. }
  372. }
  373. .one-from {
  374. border-radius: 0 50rpx 50rpx 50rpx;
  375. transition: 0.85s ease;
  376. }
  377. .two-from {
  378. border-radius: 50rpx 0 50rpx 50rpx;
  379. transition: 0.85s ease;
  380. }
  381. }
  382. .register-box {
  383. display: flex;
  384. justify-content: center;
  385. align-items: center;
  386. margin-top: 60rpx;
  387. .register-text {
  388. height: 34rpx;
  389. line-height: 34rpx;
  390. }
  391. .register-text:last-child {
  392. margin-right: 5rpx;
  393. }
  394. }
  395. .wx-box {
  396. position: absolute;
  397. bottom: calc(60rpx + env(safe-area-inset-bottom));
  398. left: 0;
  399. width: 100%;
  400. display: flex;
  401. flex-direction: column;
  402. justify-content: center;
  403. .wx-title {
  404. display: flex;
  405. justify-content: center;
  406. align-items: center;
  407. .wx-wire {
  408. background: linear-gradient(90deg, #D9D9D9 0%, rgba(115, 115, 115, 0) 100%);
  409. width: 174rpx;
  410. height: 2rpx;
  411. border-radius: 50%;
  412. }
  413. .wx-text {
  414. margin: 0 15rpx;
  415. height: 34rpx;
  416. line-height: 34rpx;
  417. }
  418. }
  419. .wx-logo {
  420. margin: 25rpx auto 0 auto;
  421. width: 80rpx;
  422. height: 80rpx;
  423. }
  424. }
  425. }
  426. </style>