login.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <template>
  2. <view class="login-page">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <view class="loginBox">
  5. <view class="loginBg">
  6. <image class="tilteBg" :src="$getImageUrl('static/images/applet/other/title.png')"></image>
  7. <image class="iconBg" :src="$getImageUrl('static/images/applet/other/loginBg.png')"></image>
  8. </view>
  9. <view class="padding flex flex-direction" v-if="formName=='wxLoginForm'">
  10. <button class="cu-btn round bg-themeBtn margin-tb-sm lg" style="width: 512rpx;"
  11. @click="wxLogin">授权登录</button>
  12. <button class="cu-btn round bg-gray margin-tb-sm lg" style="width: 512rpx;margin-top: 30rpx;"
  13. @tap="toPage">返回</button>
  14. </view>
  15. </view>
  16. <!-- #endif -->
  17. <view class="padding">
  18. <checkbox-group @change="handelChange" style="display: flex;justify-content: center;align-items: center;">
  19. <label :class="isChecked?'option_active checkCss':'option_default checkCss'">
  20. <view class="checkboxHidden">
  21. <checkbox value="1" style="transform:scale(0.7)" :checked="isChecked" />
  22. </view>
  23. </label>
  24. <view class="checkCircle"></view>
  25. <view class="checkTxt">我已阅读并同意</view>
  26. <view class="text-themeRed" @click="goPage('/pages/login/agreement')">《晋江人力用户服务协议》</view>
  27. </checkbox-group>
  28. </view>
  29. <!-- <view style="width: 100%; height: 80rpx;"></view>
  30. <view class="padding">
  31. <checkbox-group @change="handelChange" style="display: flex;justify-content: center;">
  32. <label class="text-center">
  33. <checkbox value="1" style="transform:scale(0.7)" :checked="isChecked" />
  34. 我已阅读并同意
  35. </label>
  36. <text class="text-themeRed" @click="goPage('/pages/login/agreement')">《晋江人力用户服务协议》</text>
  37. </checkbox-group>
  38. </view> -->
  39. <!-- #ifdef MP-WEIXIN -->
  40. <!-- <view class="padding flex flex-direction" v-if="formName=='wxLoginForm'">
  41. <button class="cu-btn bg-green margin-tb-sm lg" @click="wxLogin">授权登录</button>
  42. <button class="cu-btn margin-tb-sm lg" @tap="toPage">返回</button>
  43. </view>
  44. <view class="padding flex flex-direction" v-if="formName=='wxCheckMobileForm'">
  45. <button class="cu-btn bg-green margin-tb-sm lg" open-type="getPhoneNumber"
  46. @getphonenumber="wxMobile">手机号快捷登录</button>
  47. <button class="cu-btn margin-tb-sm lg" @tap="checkMobile" data-formname="editMobileModal">其他手机号绑定</button>
  48. <button class="cu-btn margin-tb-sm lg" @tap="toPage">取消注册登录操作</button>
  49. </view>
  50. <view class="padding flex flex-direction" v-if="formName=='editMobileModal'">
  51. <form>
  52. <view class="cu-form-group">
  53. <view class="title">手机号码</view>
  54. <input type="number" placeholder="请输入手机号..." @input="wxInput" data-val="editmobile"
  55. :value="weixinInfo.editmobile"></input>
  56. </view>
  57. <view class="cu-form-group margin-bottom solids-bottom">
  58. <view class="title">验证码</view>
  59. <input type="number" placeholder="请输入验证码..." @input="wxInput" data-val="editcode"
  60. :value="weixinInfo.editcode"></input>
  61. <button class='cu-btn bg-green shadow'
  62. @click="getSmsCode(weixinInfo.editmobile)">{{smsinfo.text}}</button>
  63. </view>
  64. </form>
  65. <button class="cu-btn bg-green margin-tb-sm lg" open-type="getUserInfo"
  66. @getuserinfo="editMobile">手机号快捷登录</button>
  67. <button class="cu-btn margin-tb-sm lg" @tap="checkMobile" data-formname="wxCheckMobileForm">返回</button>
  68. </view> -->
  69. <!-- #endif -->
  70. <!-- #ifdef APP-PLUS -->
  71. <view class="padding flex flex-direction">
  72. <form>
  73. <view class="cu-form-group">
  74. <view class="title">手机号码</view>
  75. <input type="number" placeholder="请输入手机号..." @input="appInput" data-val="editmobile"
  76. :value="mobileInfo.editmobile"></input>
  77. </view>
  78. <view class="cu-form-group margin-bottom solids-bottom">
  79. <view class="title">验证码</view>
  80. <input type="number" placeholder="请输入验证码..." @input="appInput" data-val="editcode"
  81. :value="mobileInfo.editcode"></input>
  82. <button class='cu-btn bg-green shadow'
  83. @click="getSmsMCode(mobileInfo.editmobile)">{{smsinfo.text}}</button>
  84. </view>
  85. </form>
  86. <button class="cu-btn bg-green margin-tb-sm lg" @tap="regMobile">立即登录</button>
  87. </view>
  88. <!-- #endif -->
  89. </view>
  90. </template>
  91. <script>
  92. var _this;
  93. export default {
  94. data() {
  95. return {
  96. isChecked: false,
  97. isRotate: false,
  98. backpage: "/pages/index/index",
  99. formName: "editMobileModal",
  100. weixinInfo: {
  101. parentid: 0,
  102. openid: "",
  103. nickname: "",
  104. avatar: "",
  105. editmobile: "",
  106. editcode: ""
  107. },
  108. mobileInfo: {
  109. parentid: 0,
  110. editmobile: "",
  111. editcode: ""
  112. },
  113. timerId: null,
  114. smsinfo: {
  115. text: '获取验证码',
  116. status: false,
  117. codeTime: 60,
  118. smscodepass: ""
  119. }
  120. };
  121. },
  122. onLoad: function(option) {
  123. _this = this;
  124. var backpage = option.backpage || "/pages/index/index";
  125. _this.backpage = decodeURIComponent(backpage);
  126. _this.isLogin();
  127. _this.weixinInfo.parentid = uni.getStorageSync('parentid') || 0;
  128. _this.mobileInfo.parentid = uni.getStorageSync('parentid') || 0;
  129. _this.formName = "wxLoginForm";
  130. },
  131. onHide: function() {
  132. clearInterval(_this.timerId);
  133. },
  134. onUnload: function() {
  135. clearInterval(_this.timerId);
  136. },
  137. methods: {
  138. // 判断是否已登录
  139. isLogin: function() {
  140. try {
  141. const userinfo = uni.getStorageSync('userinfo') || null;
  142. if (userinfo) {
  143. _this.checkuserinfoall(userinfo);
  144. _this.toPage();
  145. }
  146. } catch (e) {
  147. console.log("e: " + JSON.stringify(e));
  148. }
  149. },
  150. handelChange: function(e) {
  151. _this.isChecked = (e.detail.value.length > 0);
  152. },
  153. showAgreement: function() {
  154. },
  155. checkuserinfoall: function(userinfo) {
  156. _this.$req.ajax({
  157. path: "my/getuser",
  158. title: "正在获取用户信息",
  159. data: {
  160. userid: userinfo.id,
  161. }
  162. }).then((data) => {
  163. //判断用户资料是否完善
  164. // if(data.user.education=="" || data.user.address=="" || data.user.workexperience=="" || data.user.eduexperience==""){
  165. // uni.navigateTo({
  166. // url: "/pages/my/myinfo"
  167. // });
  168. // return false;
  169. // }
  170. //判断用户是否已实名认证
  171. _this.toPage();
  172. if (data.user.authstatus == 1) {
  173. uni.navigateTo({
  174. url: "/pages/my/myauth"
  175. });
  176. return false;
  177. }
  178. _this.isRotate = false;
  179. }).catch((err) => {
  180. uni.showModal({
  181. title: '信息提示',
  182. content: err,
  183. showCancel: false
  184. });
  185. _this.isRotate = false;
  186. });
  187. },
  188. // 页面跳转
  189. toPage: function() {
  190. uni.reLaunch({
  191. url: _this.backpage,
  192. fail: function() {
  193. uni.switchTab({
  194. url: _this.backpage
  195. });
  196. }
  197. });
  198. },
  199. goPage: function(pageurl) {
  200. uni.navigateTo({
  201. url: pageurl,
  202. fail: function() {
  203. uni.switchTab({
  204. url: pageurl
  205. });
  206. }
  207. });
  208. },
  209. // S 微信端登录注册
  210. // 自填手机号
  211. editMobile: function() {
  212. if (_this.isRotate) {
  213. return false;
  214. }
  215. _this.isRotate = true;
  216. _this.$req.ajax({
  217. path: "login/seteditmobile",
  218. title: "正在授权登录",
  219. data: {
  220. parentid: _this.weixinInfo.parentid,
  221. openid: _this.weixinInfo.openid,
  222. nickname: _this.weixinInfo.nickname,
  223. avatar: _this.weixinInfo.avatar,
  224. editmobile: _this.weixinInfo.editmobile,
  225. editcode: _this.weixinInfo.editcode,
  226. smscodepass: _this.smsinfo.smscodepass
  227. }
  228. }).then((data) => {
  229. uni.setStorageSync('userinfo', data.userinfo);
  230. _this.toPage();
  231. _this.isRotate = false;
  232. }).catch((err) => {
  233. uni.showModal({
  234. title: '信息提示',
  235. content: err,
  236. showCancel: false
  237. });
  238. _this.isRotate = false;
  239. });
  240. },
  241. // 微信手机号
  242. wxMobile: function(e) {
  243. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
  244. uni.showModal({
  245. title: '警告',
  246. content: '您点击了拒绝授权,将无法正常注册登录,点击确定重新获取授权。',
  247. showCancel: false
  248. });
  249. } else {
  250. if (_this.isRotate) {
  251. return false;
  252. }
  253. _this.isRotate = true;
  254. _this.$req.ajax({
  255. path: "login/setwxmobile",
  256. title: "正在授权登录",
  257. data: {
  258. parentid: _this.weixinInfo.parentid,
  259. openid: _this.weixinInfo.openid,
  260. session_key: _this.weixinInfo.session_key,
  261. nickname: _this.weixinInfo.nickname,
  262. avatar: _this.weixinInfo.avatar,
  263. iv: e.detail.iv,
  264. encryptedData: encodeURIComponent(e.detail.encryptedData)
  265. }
  266. }).then((data) => {
  267. uni.setStorageSync('userinfo', data.userinfo);
  268. _this.checkuserinfoall(data.userinfo);
  269. _this.toPage();
  270. _this.isRotate = false;
  271. }).catch((err) => {
  272. uni.showModal({
  273. title: '信息提示',
  274. content: err,
  275. showCancel: false
  276. });
  277. _this.isRotate = false;
  278. });
  279. }
  280. },
  281. // 获取OpenId
  282. wxLogin: function() {
  283. if (!_this.isChecked) {
  284. uni.showModal({
  285. title: '警告',
  286. content: '请先查看并勾选协助。',
  287. showCancel: false
  288. });
  289. return false;
  290. }
  291. uni.login({
  292. provider: 'weixin',
  293. success: function(loginRes) {
  294. if (_this.isRotate) {
  295. return false;
  296. }
  297. _this.isRotate = true;
  298. _this.$req.ajax({
  299. path: "login/getwxopenid",
  300. title: "正在授权登录",
  301. data: {
  302. code: loginRes.code
  303. }
  304. }).then((data) => {
  305. if (data.userinfo == null) {
  306. uni.showModal({
  307. title: '温馨提示',
  308. content: '亲,授权微信登录后才能正常使用小程序功能',
  309. success(res) {
  310. //如果用户点击了确定按钮
  311. if (res.confirm) {
  312. uni.getUserProfile({
  313. desc: '获取你的昵称、头像、地区及性别',
  314. success: infoRes => {
  315. _this.weixinInfo.openid =
  316. data.openid;
  317. _this.weixinInfo
  318. .session_key = data
  319. .session_key;
  320. _this.weixinInfo.nickname =
  321. infoRes.userInfo
  322. .nickName;
  323. _this.weixinInfo.avatar =
  324. infoRes.userInfo
  325. .avatarUrl;
  326. _this.formName =
  327. "wxCheckMobileForm";
  328. },
  329. fail: res => {
  330. uni.showModal({
  331. title: '警告',
  332. content: '您点击了拒绝授权,将无法正常注册登录,点击确定重新获取授权。',
  333. showCancel: false,
  334. success: function(
  335. res) {
  336. if (res
  337. .confirm
  338. ) {
  339. uni
  340. .openSetting();
  341. }
  342. }
  343. });
  344. }
  345. });
  346. } else if (res.cancel) {
  347. //如果用户点击了取消按钮
  348. uni.showToast({
  349. title: '警告',
  350. content: '您点击了拒绝授权,将无法正常注册登录,点击确定重新获取授权。',
  351. icon: 'error',
  352. duration: 2000
  353. });
  354. return;
  355. }
  356. }
  357. });
  358. // uni.getUserProfile({
  359. // desc:"获取个人信息",
  360. // provider: 'weixin',
  361. // withCredentials: true,
  362. // success: function(infoRes) {
  363. // console.log(infoRes);
  364. // return false;
  365. // _this.weixinInfo.openid = data.openid;
  366. // _this.weixinInfo.session_key = data.session_key;
  367. // _this.weixinInfo.nickname = infoRes.userInfo.nickName;
  368. // _this.weixinInfo.avatar = infoRes.userInfo.avatarUrl;
  369. // _this.formName = "wxCheckMobileForm";
  370. // },
  371. // fail: function(res) {
  372. // console.log(res);
  373. // uni.showModal({
  374. // title: '警告',
  375. // content: '您点击了拒绝授权,将无法正常注册登录,点击确定重新获取授权。',
  376. // showCancel: false,
  377. // success: function(res) {
  378. // if (res.confirm) {
  379. // uni.openSetting();
  380. // }
  381. // }
  382. // });
  383. // }
  384. // });
  385. } else {
  386. uni.setStorageSync('userinfo', data.userinfo);
  387. _this.checkuserinfoall(data.userinfo);
  388. _this.toPage();
  389. }
  390. _this.isRotate = false;
  391. }).catch((err) => {
  392. uni.showModal({
  393. title: '信息提示',
  394. content: err,
  395. showCancel: false
  396. });
  397. _this.isRotate = false;
  398. });
  399. }
  400. });
  401. },
  402. checkMobile: function(e) {
  403. _this.formName = e.currentTarget.dataset.formname;
  404. },
  405. // 获取短信验证码
  406. getSmsCode: function(mobile) {
  407. if (_this.smsinfo.status) {
  408. return false;
  409. }
  410. _this.smsinfo.status = true;
  411. _this.$req.ajax({
  412. path: "login/smsregister",
  413. data: {
  414. identifier: mobile
  415. }
  416. }).then((data) => {
  417. _this.smsinfo.smscodepass = data.smscodepass;
  418. _this.timerId = setInterval(() => {
  419. var codeTime = _this.smsinfo.codeTime;
  420. codeTime--;
  421. _this.smsinfo.codeTime = codeTime;
  422. _this.smsinfo.text = codeTime + "s 后重新发送";
  423. if (codeTime < 1) {
  424. clearInterval(_this.timerId);
  425. _this.smsinfo.text = "重新获取";
  426. _this.smsinfo.codeTime = 60;
  427. _this.smsinfo.status = false;
  428. }
  429. }, 1000);
  430. }).catch((err) => {
  431. uni.showModal({
  432. title: '信息提示',
  433. content: err,
  434. showCancel: false
  435. });
  436. _this.smsinfo.status = false;
  437. });
  438. },
  439. wxInput: function(e) {
  440. var dataval = e.currentTarget.dataset.val;
  441. _this.weixinInfo[dataval] = e.detail.value;
  442. },
  443. // E 微信端登录注册
  444. // S APP端登录注册
  445. appInput: function(e) {
  446. var dataval = e.currentTarget.dataset.val;
  447. _this.mobileInfo[dataval] = e.detail.value;
  448. },
  449. // 获取短信验证码
  450. getSmsMCode: function(mobile) {
  451. if (_this.smsinfo.status) {
  452. return false;
  453. }
  454. _this.smsinfo.status = true;
  455. _this.$req.ajax({
  456. path: "login/smsmobilelogin",
  457. data: {
  458. identifier: mobile
  459. }
  460. }).then((data) => {
  461. _this.smsinfo.smscodepass = data.smscodepass;
  462. _this.timerId = setInterval(() => {
  463. var codeTime = _this.smsinfo.codeTime;
  464. codeTime--;
  465. _this.smsinfo.codeTime = codeTime;
  466. _this.smsinfo.text = codeTime + "s 后重新发送";
  467. if (codeTime < 1) {
  468. clearInterval(_this.timerId);
  469. _this.smsinfo.text = "重新获取";
  470. _this.smsinfo.codeTime = 60;
  471. _this.smsinfo.status = false;
  472. }
  473. }, 1000);
  474. }).catch((err) => {
  475. uni.showModal({
  476. title: '信息提示',
  477. content: err,
  478. showCancel: false
  479. });
  480. _this.smsinfo.status = false;
  481. });
  482. },
  483. regMobile: function() {
  484. if (_this.isRotate) {
  485. return false;
  486. }
  487. _this.isRotate = true;
  488. _this.$req.ajax({
  489. path: "login/mobilelogin",
  490. title: "正在登录",
  491. data: {
  492. parentid: _this.mobileInfo.parentid,
  493. editmobile: _this.mobileInfo.editmobile,
  494. editcode: _this.mobileInfo.editcode,
  495. smscodepass: _this.smsinfo.smscodepass
  496. }
  497. }).then((data) => {
  498. uni.setStorageSync('userinfo', data.userinfo);
  499. _this.toPage();
  500. _this.isRotate = false;
  501. }).catch((err) => {
  502. uni.showModal({
  503. title: '信息提示',
  504. content: err,
  505. showCancel: false
  506. });
  507. _this.isRotate = false;
  508. });
  509. }
  510. // E APP端登录注册
  511. },
  512. onShareAppMessage: function(res) {
  513. return {
  514. title: "登录注册",
  515. path: "/pages/login/login"
  516. }
  517. }
  518. }
  519. </script>
  520. <style lang="scss">
  521. .login-page {
  522. width: 100%;
  523. height: 100vh;
  524. // background-color: #FFFFFF;
  525. }
  526. .cu-form-group .title {
  527. min-width: calc(4em + 15px);
  528. }
  529. .loginBox {
  530. margin: 30rpx 30rpx 0;
  531. padding-bottom: 30rpx;
  532. border-radius: 22rpx;
  533. background-color: #FFFFFF;
  534. display: flex;
  535. flex-direction: column;
  536. align-items: center;
  537. .loginBg {
  538. display: flex;
  539. flex-direction: column;
  540. align-items: center;
  541. .tilteBg {
  542. margin: 70rpx 0 52rpx;
  543. width: 552rpx;
  544. height: 192rpx;
  545. }
  546. .iconBg {
  547. margin-bottom: 100rpx;
  548. width: 277rpx;
  549. height: 205rpx;
  550. }
  551. }
  552. }
  553. .checkCss {
  554. display: flex;
  555. align-items: center;
  556. height: 100rpx;
  557. border-top: 1rpx solid #E6E6E6;
  558. font-size: 28rpx;
  559. }
  560. // 选中的颜色
  561. .option_active {
  562. color: orange;
  563. position: relative;
  564. }
  565. .option_active::after {
  566. content: '';
  567. position: absolute;
  568. left: 30rpx;
  569. top: 50%;
  570. transform: translateY(-50%);
  571. width: 30rpx;
  572. height: 30rpx;
  573. border-radius: 50%;
  574. background-color: #CA151C;
  575. }
  576. .option_active::before {
  577. content: '';
  578. position: absolute;
  579. left: 35rpx;
  580. top: 42%;
  581. transform: translateY(-50%);
  582. width: 18rpx;
  583. height: 10rpx;
  584. border-left: 2rpx solid #ffffff;
  585. border-bottom: 2rpx solid #ffffff;
  586. transform: rotate(-45deg);
  587. z-index: 4;
  588. }
  589. // 默认颜色
  590. .option_default {
  591. color: #000000;
  592. position: relative;
  593. }
  594. .option_default::after {
  595. content: '';
  596. position: absolute;
  597. left: 30rpx;
  598. top: 50%;
  599. transform: translateY(-50%);
  600. width: 30rpx;
  601. height: 30rpx;
  602. border-radius: 50%;
  603. border: 1rpx solid #484848;
  604. box-sizing: border-box;
  605. }
  606. .checkboxHidden {
  607. display: none;
  608. }
  609. .checkTxt {
  610. margin-left: 80rpx;
  611. }
  612. </style>