login.vue 19 KB

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