loginV2.vue 11 KB

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