loginV2.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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. })
  228. .catch(() => {
  229. this.$queue.showToast('登录失败,请稍后重试或更换其他登录方式')
  230. uni.hideLoading()
  231. })
  232. },
  233. fail: () => {
  234. this.$queue.showToast('登录失败,请稍后重试或更换其他登录方式')
  235. uni.hideLoading()
  236. }
  237. })
  238. },
  239. // 一键登录
  240. handlOneKeyLogin() {
  241. jVerificationLogin((res) => {
  242. this.loginFinished(res)
  243. })
  244. },
  245. // 登录处理
  246. loginFinished(res) {
  247. if (res.code == 0) {
  248. this.$queue.setData("userId", res.user.userId)
  249. this.$queue.setData("token", res.token)
  250. this.$queue.setData("phone", res.user.phone)
  251. this.$queue.setData("userName", res.user.userName)
  252. this.$queue.setData("avatar", res.user.avatar)
  253. this.$queue.setData("invitationCode", res.user.invitationCode)
  254. this.$queue.setData("inviterCode", res.user.inviterCode)
  255. this.getIsVip()
  256. if (res.user.userType) {
  257. this.$queue.setData("userType", res.user.userType)
  258. uni.reLaunch({
  259. url: '/pages/my/index',
  260. success: closeVerifyView
  261. })
  262. } else if (this.isFirst) {
  263. // 首次登录,跳转至基本详情页
  264. uni.reLaunch({
  265. url: '/package/jobIntention/basicInfo',
  266. success: closeVerifyView
  267. })
  268. } else {
  269. uni.reLaunch({
  270. url: '/pages/my/jobApplicant/guidePage',
  271. success: closeVerifyView
  272. })
  273. }
  274. } else {
  275. uni.showToast({
  276. title: res.msg,
  277. icon: 'none'
  278. })
  279. }
  280. },
  281. // 获取vip数据
  282. getIsVip() {
  283. this.$Request.get("/app/UserVip/isUserVip").then((res) => {
  284. if (res.code == 0) {
  285. this.$queue.setData("isVip", res.data);
  286. }
  287. });
  288. },
  289. // 检查更新
  290. checkLoginStatus() {
  291. let firstUpload = uni.getStorageSync("firstUpload") || false;
  292. let token = this.$queue.getData('token')
  293. let userType = this.$queue.getData('userType')
  294. let companyStatus = this.$queue.getData('companyStatus')
  295. if (!firstUpload) {
  296. // 第一次登录
  297. // 跳转至引导页
  298. return
  299. }
  300. if (
  301. token &&
  302. (!userType || (userType == 2 && companyStatus != 2))
  303. ) {
  304. // 有登录token,但是没有userType,跳转选择角色页面,强制用户选择
  305. // 有登录token,并且userType为2,但是公司状态没有通过
  306. // 跳转至选择角色页
  307. return
  308. }
  309. if (token && userType) {
  310. // 跳转至首页
  311. return
  312. }
  313. this.initing = false
  314. }
  315. }
  316. }
  317. </script>
  318. <style lang="scss" scoped>
  319. .container {
  320. height: 100vh;
  321. display: flex;
  322. flex-direction: column;
  323. justify-content: space-between;
  324. padding: 0 70rpx;
  325. .logo {
  326. display: block;
  327. width: 204rpx;
  328. height: 56rpx;
  329. margin: 72rpx auto 92rpx;
  330. }
  331. .main-img {
  332. display: block;
  333. width: 400rpx;
  334. height: 400rpx;
  335. margin: 0 auto 34rpx;
  336. }
  337. .input-container {
  338. .input-wrapper {
  339. margin-top: 28rpx;
  340. box-sizing: border-box;
  341. border: 1px solid rgba(242, 242, 242, 1);
  342. border-radius: 12rpx;
  343. background: rgba(250, 250, 250, 1);
  344. padding: 24rpx;
  345. .country-code {
  346. color: rgba(51, 51, 51, 1);
  347. margin-right: 24rpx;
  348. }
  349. .border {
  350. margin: 0 24rpx;
  351. color: rgba(234, 234, 234, 1);
  352. }
  353. .input {
  354. font-size: 28rpx;
  355. }
  356. .placeholder {
  357. color: rgba(153, 153, 153, 1);
  358. }
  359. .verify-code {
  360. color: rgba(1, 107, 246, 1);
  361. line-height: 36rpx;
  362. }
  363. }
  364. }
  365. .agreement {
  366. display: flex;
  367. align-items: flex-start;
  368. font-size: 24rpx;
  369. color: #605d67;
  370. margin: 52rpx auto 40rpx;
  371. .check-box {
  372. display: flex;
  373. justify-content: center;
  374. align-items: center;
  375. margin-right: 16rpx;
  376. image {
  377. width: 24rpx;
  378. height: 24rpx;
  379. margin-top: 6rpx;
  380. }
  381. }
  382. .content {
  383. display: flex;
  384. flex-wrap: wrap;
  385. word-wrap: break-word;
  386. flex: 1;
  387. }
  388. navigator {
  389. color: #016bf6;
  390. }
  391. }
  392. .login-btn {
  393. width: 600rpx;
  394. height: 88rpx;
  395. border-radius: 100px;
  396. background: linear-gradient(90.00deg, rgba(13, 39, 247, 1),rgba(19, 193, 234, 1) 100%);
  397. text-align: center;
  398. line-height: 88rpx;
  399. color: #fff;
  400. font-size: 32rpx;
  401. font-weight: 500;
  402. }
  403. .other-login {
  404. display: flex;
  405. justify-content: center;
  406. margin-top: 80rpx;
  407. .other-type {
  408. margin: 0 24rpx;
  409. }
  410. .icon {
  411. display: block;
  412. width: 60rpx;
  413. height: 60rpx;
  414. margin: 0 auto 8rpx;
  415. }
  416. .text {
  417. text-align: center;
  418. font-size: 24rpx;
  419. line-height: 32rpx;
  420. color: rgb(153, 153, 153);
  421. }
  422. }
  423. // .footer {
  424. // display: flex;
  425. // justify-content: center;
  426. // margin-bottom: 40rpx;
  427. // .link {
  428. // font-size: 28rpx;
  429. // color: #999999;
  430. // margin: 0 14rpx;
  431. // }
  432. // }
  433. // .popup-content {
  434. // padding: 40rpx;
  435. // }
  436. }
  437. </style>