loginV2.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <template>
  2. <view class="container" :style="{ paddingTop: (12 + statusBarHeight) + 'px' }">
  3. <view class="main-container" v-if="!initing">
  4. <image src="/static/images/logo-long.png" class="logo"></image>
  5. <image src="/static/images/invite.png" class="main-img"></image>
  6. <view class="input-container">
  7. <view class="input-wrapper flex align-center">
  8. <text class="country-code">{{ countryCode }}</text>
  9. <u-icon name="arrow-down" color="rgba(216, 216, 216, 1)"></u-icon>
  10. <text class="border">|</text>
  11. <input v-model="phoneNum" class="input" type="number" placeholder="请输入手机号" maxlength="11" placeholder-class="placeholder" />
  12. </view>
  13. <view class="input-wrapper flex align-center justify-between">
  14. <input v-model="verifyCode" type="number" placeholder="请输入验证码" maxlength="6" placeholder-class="placeholder" />
  15. <view class="verify-code" @click="getVerifyCode">{{ disabled ? `${countdown}s` : '获取验证码' }}</view>
  16. </view>
  17. </view>
  18. <view class="agreement">
  19. <view class="check-box" @click="checked = !checked">
  20. <image src="@/static/images/jobApplicant/check.svg" v-if="checked" mode="scaleToFill" />
  21. <image src="@/static/images/jobApplicant/border.svg" v-else mode="scaleToFill" />
  22. </view>
  23. <view class="content">
  24. 已阅读并同意<navigator url="/my/setting/xieyi">《亿职赞用户协议》</navigator>
  25. 和<navigator url="/my/setting/mimi">《隐私协议》</navigator>,允许亿职赞统一管理本人账号信息
  26. </view>
  27. </view>
  28. <view class="login-btn" @click="handleLogin">注册登录</view>
  29. <!-- #ifdef APP-PLUS -->
  30. <view class="other-login">
  31. <view class="other-type" @click="handleWxLogin">
  32. <image src="/static/wechat.png" class="icon"></image>
  33. <view class="text">微信登录</view>
  34. </view>
  35. <view class="other-type" @click="handlOneKeyLogin">
  36. <image src="/static/phone.png" class="icon"></image>
  37. <view class="text">一键登录</view>
  38. </view>
  39. </view>
  40. <!-- #endif -->
  41. </view>
  42. <!-- <view class="footer">
  43. <view class="link" v-for="item in infos" :key="item.type" @click="showPopup(item.type)">{{ item.name }}</view>
  44. </view>
  45. <u-popup v-model="show" mode="bottom" border-radius="14">
  46. <view class="popup-content">
  47. <view v-if="currentType == 1">企业套餐咨询</view>
  48. <view v-if="currentType == 2">投诉举报</view>
  49. <view v-if="currentType == 3">资质信息</view>
  50. </view>
  51. </u-popup> -->
  52. </view>
  53. </template>
  54. <script>
  55. import { jVerificationLogin, closeVerifyView } from '@/utils/jVerificationLogin'
  56. import { membershipExpirationReminder, getJPLoginParams } from '@/utils/login'
  57. export default {
  58. data() {
  59. return {
  60. initing: true, // 初始化中
  61. statusBarHeight: 0,
  62. checked: false,
  63. countryCode: '+86',
  64. phoneNum: '',
  65. verifyCode: '',
  66. countdown: 60,
  67. timer: null,
  68. disabled: false,
  69. loading: false,
  70. // isFirst: false,
  71. // show: false,
  72. // currentType: 1,
  73. // infos: [
  74. // {
  75. // type: 1,
  76. // name: '企业套餐咨询',
  77. // },
  78. // {
  79. // type: 2,
  80. // name: '投诉举报',
  81. // },
  82. // {
  83. // type: 3,
  84. // name: '资质信息',
  85. // },
  86. // ],
  87. }
  88. },
  89. onLoad(options) {
  90. // #ifdef H5
  91. this.initing = false
  92. // #endif
  93. // #ifdef APP-PLUS
  94. this.checkLoginStatus()
  95. // #endif
  96. // // 判断是否是第一次
  97. // if (options.isFirst) {
  98. // this.isFirst = true
  99. // }
  100. // 获取状态栏高度
  101. let systemInfo = uni.getSystemInfoSync();
  102. this.statusBarHeight = systemInfo.statusBarHeight || 0;
  103. },
  104. onUnload() {
  105. this.clearCountdownTimer()
  106. },
  107. methods: {
  108. // 获取验证码
  109. getVerifyCode() {
  110. if (!this.phoneNum) {
  111. uni.showToast({
  112. title: '请输入手机号',
  113. icon: 'none'
  114. })
  115. return
  116. }
  117. if (!/^1[3-9]\d{9}$/.test(this.phoneNum)) {
  118. uni.showToast({
  119. title: '请输入正确的手机号',
  120. icon: 'none'
  121. })
  122. return
  123. }
  124. if (this.disabled || this.loading) return
  125. uni.showLoading({
  126. title: '正在发送验证码'
  127. })
  128. this.loading = true
  129. this.$Request
  130. .getT('/app/Login/sendMsg/' + this.phoneNum + '/bind')
  131. .then((res) => {
  132. if (res.code === 0) {
  133. this.startCountdown()
  134. } else {
  135. uni.showModal({
  136. showCancel: false,
  137. title: '短信发送失败',
  138. content: res.msg ? res.msg : '请一分钟后再获取验证码',
  139. });
  140. }
  141. })
  142. .finally(() => {
  143. this.loading = false
  144. uni.hideLoading();
  145. })
  146. },
  147. startCountdown() {
  148. this.disabled = true
  149. this.timer = setInterval(() => {
  150. this.countdown--
  151. if (this.countdown <= 0) {
  152. this.clearCountdownTimer()
  153. this.countdown = 60
  154. this.disabled = false
  155. }
  156. }, 1000)
  157. },
  158. clearCountdownTimer() {
  159. if (this.timer) {
  160. clearInterval(this.timer)
  161. this.timer = null // 重置定时器实例
  162. }
  163. },
  164. // showPopup(type) {
  165. // this.currentType = type
  166. // this.show = true
  167. // },
  168. // 登录
  169. handleLogin() {
  170. if (!this.phoneNum) {
  171. uni.showToast({
  172. title: '请输入手机号',
  173. icon: 'none'
  174. })
  175. return
  176. }
  177. if (!this.verifyCode) {
  178. uni.showToast({
  179. title: '请输入验证码',
  180. icon: 'none'
  181. })
  182. return
  183. }
  184. if (!this.checked) {
  185. uni.showToast({
  186. title: '请阅读并同意协议',
  187. icon: 'none'
  188. })
  189. return
  190. }
  191. // 避免出现多个loading
  192. uni.hideLoading()
  193. uni.showLoading({
  194. title: '登录中'
  195. })
  196. let platform = 'app'
  197. // #ifdef H5
  198. platform = 'h5'
  199. // #endif
  200. // 获取极光推送登录信息
  201. let JPLoginParams = getJPLoginParams()
  202. console.log('登录信息', {
  203. phone: this.phoneNum,
  204. msg: this.verifyCode,
  205. platform,
  206. ...JPLoginParams
  207. })
  208. this.$Request
  209. .post('/app/Login/registerAndLogin', {
  210. phone: this.phoneNum,
  211. msg: this.verifyCode,
  212. platform,
  213. ...JPLoginParams
  214. })
  215. .then((res) => {
  216. this.loginFinished(res)
  217. })
  218. .finally(() => {
  219. uni.hideLoading()
  220. })
  221. },
  222. // 微信登录
  223. handleWxLogin() {
  224. uni.showLoading({
  225. title: '登录中'
  226. })
  227. uni.login({
  228. provider: 'weixin',
  229. success: (wxRes) => {
  230. this.$queue.setData('openId', wxRes.authResult.openid)
  231. this.$queue.setData('unionId', wxRes.authResult.unionId)
  232. let data = {
  233. wxOpenId: loginRes.authResult.openid,
  234. token: loginRes.authResult.access_token
  235. }
  236. this.$Request
  237. .postT('/app/Login/wxAppLogin', data)
  238. .then(res => {
  239. this.loginFinished(res)
  240. uni.hideLoading()
  241. })
  242. .catch(() => {
  243. this.$queue.showToast('登录失败,请稍后重试或更换其他登录方式')
  244. uni.hideLoading()
  245. })
  246. },
  247. fail: () => {
  248. this.$queue.showToast('登录失败,请稍后重试或更换其他登录方式')
  249. uni.hideLoading()
  250. }
  251. })
  252. },
  253. // 一键登录
  254. handlOneKeyLogin() {
  255. jVerificationLogin((res) => {
  256. this.loginFinished(res)
  257. })
  258. },
  259. // 登录处理
  260. loginFinished(res) {
  261. if (res.code == 0) {
  262. this.$queue.setData("userId", res.user.userId)
  263. this.$queue.setData("token", res.token)
  264. this.$queue.setData("phone", res.user.phone)
  265. this.$queue.setData("userName", res.user.userName)
  266. this.$queue.setData("avatar", res.user.avatar)
  267. this.$queue.setData("invitationCode", res.user.invitationCode)
  268. this.$queue.setData("inviterCode", res.user.inviterCode)
  269. this.getIsVip()
  270. if (res.user.userType) {
  271. this.$queue.setData("userType", res.user.userType)
  272. uni.reLaunch({
  273. url: '/pages/my/index',
  274. success: closeVerifyView
  275. })
  276. if (res.userVip) {
  277. membershipExpirationReminder(res.userVip)
  278. }
  279. } else {
  280. uni.reLaunch({
  281. url: '/package/jobIntention/basicInfo',
  282. success: closeVerifyView
  283. })
  284. }
  285. } else {
  286. uni.showToast({
  287. title: res.msg,
  288. icon: 'none'
  289. })
  290. }
  291. },
  292. // 获取vip数据
  293. getIsVip() {
  294. this.$Request.get("/app/UserVip/isUserVip").then((res) => {
  295. if (res.code == 0) {
  296. this.$queue.setData("isVip", res.data);
  297. }
  298. });
  299. },
  300. // 检查更新
  301. checkLoginStatus() {
  302. let firstUpload = uni.getStorageSync("firstUpload") || false;
  303. let token = this.$queue.getData('token')
  304. let userType = this.$queue.getData('userType')
  305. let companyStatus = this.$queue.getData('companyStatus')
  306. if (!firstUpload) {
  307. // 第一次登录
  308. // 跳转至引导页
  309. return
  310. }
  311. if (
  312. token &&
  313. (!userType || (userType == 2 && companyStatus != 2))
  314. ) {
  315. // 有登录token,但是没有userType,跳转选择角色页面,强制用户选择
  316. // 有登录token,并且userType为2,但是公司状态没有通过
  317. // 跳转至选择角色页
  318. return
  319. }
  320. if (token && userType) {
  321. // 跳转至首页
  322. return
  323. }
  324. this.initing = false
  325. }
  326. }
  327. }
  328. </script>
  329. <style lang="scss" scoped>
  330. .container {
  331. height: 100vh;
  332. display: flex;
  333. flex-direction: column;
  334. justify-content: space-between;
  335. padding: 0 70rpx;
  336. .logo {
  337. display: block;
  338. width: 204rpx;
  339. height: 56rpx;
  340. margin: 72rpx auto 92rpx;
  341. }
  342. .main-img {
  343. display: block;
  344. width: 400rpx;
  345. height: 400rpx;
  346. margin: 0 auto 34rpx;
  347. }
  348. .input-container {
  349. .input-wrapper {
  350. margin-top: 28rpx;
  351. box-sizing: border-box;
  352. border: 1px solid rgba(242, 242, 242, 1);
  353. border-radius: 12rpx;
  354. background: rgba(250, 250, 250, 1);
  355. padding: 24rpx;
  356. .country-code {
  357. color: rgba(51, 51, 51, 1);
  358. margin-right: 24rpx;
  359. }
  360. .border {
  361. margin: 0 24rpx;
  362. color: rgba(234, 234, 234, 1);
  363. }
  364. .input {
  365. font-size: 28rpx;
  366. }
  367. .placeholder {
  368. color: rgba(153, 153, 153, 1);
  369. }
  370. .verify-code {
  371. color: rgba(1, 107, 246, 1);
  372. line-height: 36rpx;
  373. }
  374. }
  375. }
  376. .agreement {
  377. display: flex;
  378. align-items: flex-start;
  379. font-size: 24rpx;
  380. color: #605d67;
  381. margin: 52rpx auto 40rpx;
  382. .check-box {
  383. display: flex;
  384. justify-content: center;
  385. align-items: center;
  386. margin-right: 16rpx;
  387. image {
  388. width: 24rpx;
  389. height: 24rpx;
  390. margin-top: 6rpx;
  391. }
  392. }
  393. .content {
  394. display: flex;
  395. flex-wrap: wrap;
  396. word-wrap: break-word;
  397. flex: 1;
  398. }
  399. navigator {
  400. color: #016bf6;
  401. }
  402. }
  403. .login-btn {
  404. width: 600rpx;
  405. height: 88rpx;
  406. border-radius: 100px;
  407. background: linear-gradient(90.00deg, rgba(13, 39, 247, 1),rgba(19, 193, 234, 1) 100%);
  408. text-align: center;
  409. line-height: 88rpx;
  410. color: #fff;
  411. font-size: 32rpx;
  412. font-weight: 500;
  413. }
  414. .other-login {
  415. display: flex;
  416. justify-content: center;
  417. margin-top: 80rpx;
  418. .other-type {
  419. margin: 0 24rpx;
  420. }
  421. .icon {
  422. display: block;
  423. width: 60rpx;
  424. height: 60rpx;
  425. margin: 0 auto 8rpx;
  426. }
  427. .text {
  428. text-align: center;
  429. font-size: 24rpx;
  430. line-height: 32rpx;
  431. color: rgb(153, 153, 153);
  432. }
  433. }
  434. // .footer {
  435. // display: flex;
  436. // justify-content: center;
  437. // margin-bottom: 40rpx;
  438. // .link {
  439. // font-size: 28rpx;
  440. // color: #999999;
  441. // margin: 0 14rpx;
  442. // }
  443. // }
  444. // .popup-content {
  445. // padding: 40rpx;
  446. // }
  447. }
  448. </style>