login.vue 19 KB

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