index.vue 11 KB

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