loginV2.vue 12 KB

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