login.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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. unionid: _this.weixinInfo.unionid,
  286. session_key: _this.weixinInfo.session_key,
  287. nickname: _this.weixinInfo.nickname,
  288. avatar: _this.weixinInfo.avatar,
  289. iv: e.detail.iv,
  290. encryptedData: encodeURIComponent(e.detail.encryptedData)
  291. }
  292. }).then((data) => {
  293. uni.setStorageSync('userinfo', data.userinfo);
  294. _this.checkuserinfoall(data.userinfo);
  295. _this.toPage();
  296. _this.isRotate = false;
  297. }).catch((err) => {
  298. uni.showModal({
  299. title: '信息提示',
  300. content: err,
  301. showCancel: false
  302. });
  303. _this.isRotate = false;
  304. });
  305. }
  306. },
  307. // 获取OpenId
  308. wxLogin: function() {
  309. if (!_this.isChecked) {
  310. uni.showModal({
  311. title: '警告',
  312. content: '请先查看并勾选协助。',
  313. showCancel: false
  314. });
  315. return false;
  316. }
  317. uni.login({
  318. provider: 'weixin',
  319. success: function(loginRes) {
  320. if (_this.isRotate) {
  321. return false;
  322. }
  323. _this.isRotate = true;
  324. _this.$req.ajax({
  325. path: "login/getwxopenid",
  326. title: "正在授权登录",
  327. data: {
  328. code: loginRes.code
  329. }
  330. }).then((data) => {
  331. if (data.userinfo == null) {
  332. uni.showModal({
  333. title: '温馨提示',
  334. content: '亲,授权微信登录后才能正常使用小程序功能',
  335. success(res) {
  336. //如果用户点击了确定按钮
  337. if (res.confirm) {
  338. uni.getUserProfile({
  339. desc: '获取你的昵称、头像、地区及性别',
  340. success: infoRes => {
  341. _this.weixinInfo.openid = data.openid;
  342. _this.weixinInfo.unionid = data.unionid;
  343. _this.weixinInfo.session_key = data.session_key;
  344. _this.weixinInfo.nickname = infoRes.userInfo.nickName;
  345. _this.weixinInfo.avatar = infoRes.userInfo.avatarUrl;
  346. _this.formName = "wxCheckMobileForm";
  347. },
  348. fail: res => {
  349. uni.showModal({
  350. title: '警告',
  351. content: '您点击了拒绝授权,将无法正常注册登录,点击确定重新获取授权。',
  352. showCancel: false,
  353. success: function(res) {
  354. if (res.confirm) {
  355. uni.openSetting();
  356. }
  357. }
  358. });
  359. }
  360. });
  361. } else if (res.cancel) {
  362. //如果用户点击了取消按钮
  363. uni.showToast({
  364. title: '警告',
  365. content: '您点击了拒绝授权,将无法正常注册登录,点击确定重新获取授权。',
  366. icon: 'error',
  367. duration: 2000
  368. });
  369. return;
  370. }
  371. }
  372. });
  373. // uni.getUserProfile({
  374. // desc:"获取个人信息",
  375. // provider: 'weixin',
  376. // withCredentials: true,
  377. // success: function(infoRes) {
  378. // console.log(infoRes);
  379. // return false;
  380. // _this.weixinInfo.openid = data.openid;
  381. // _this.weixinInfo.session_key = data.session_key;
  382. // _this.weixinInfo.nickname = infoRes.userInfo.nickName;
  383. // _this.weixinInfo.avatar = infoRes.userInfo.avatarUrl;
  384. // _this.formName = "wxCheckMobileForm";
  385. // },
  386. // fail: function(res) {
  387. // console.log(res);
  388. // uni.showModal({
  389. // title: '警告',
  390. // content: '您点击了拒绝授权,将无法正常注册登录,点击确定重新获取授权。',
  391. // showCancel: false,
  392. // success: function(res) {
  393. // if (res.confirm) {
  394. // uni.openSetting();
  395. // }
  396. // }
  397. // });
  398. // }
  399. // });
  400. } else {
  401. uni.setStorageSync('userinfo', data.userinfo);
  402. _this.checkuserinfoall(data.userinfo);
  403. _this.toPage();
  404. }
  405. _this.isRotate = false;
  406. }).catch((err) => {
  407. uni.showModal({
  408. title: '信息提示',
  409. content: err,
  410. showCancel: false
  411. });
  412. _this.isRotate = false;
  413. });
  414. }
  415. });
  416. },
  417. checkMobile: function(e) {
  418. _this.formName = e.currentTarget.dataset.formname;
  419. },
  420. // 获取短信验证码
  421. getSmsCode: function(mobile) {
  422. if (_this.smsinfo.status) {
  423. return false;
  424. }
  425. _this.smsinfo.status = true;
  426. _this.$req.ajax({
  427. path: "login/smsregister",
  428. data: {
  429. identifier: mobile
  430. }
  431. }).then((data) => {
  432. _this.smsinfo.smscodepass = data.smscodepass;
  433. _this.timerId = setInterval(() => {
  434. var codeTime = _this.smsinfo.codeTime;
  435. codeTime--;
  436. _this.smsinfo.codeTime = codeTime;
  437. _this.smsinfo.text = codeTime + "s 后重新发送";
  438. if (codeTime < 1) {
  439. clearInterval(_this.timerId);
  440. _this.smsinfo.text = "重新获取";
  441. _this.smsinfo.codeTime = 60;
  442. _this.smsinfo.status = false;
  443. }
  444. }, 1000);
  445. }).catch((err) => {
  446. uni.showModal({
  447. title: '信息提示',
  448. content: err,
  449. showCancel: false
  450. });
  451. _this.smsinfo.status = false;
  452. });
  453. },
  454. wxInput: function(e) {
  455. var dataval = e.currentTarget.dataset.val;
  456. _this.weixinInfo[dataval] = e.detail.value;
  457. },
  458. // E 微信端登录注册
  459. // S APP端登录注册
  460. appInput: function(e) {
  461. var dataval = e.currentTarget.dataset.val;
  462. _this.mobileInfo[dataval] = e.detail.value;
  463. },
  464. // 获取短信验证码
  465. getSmsMCode: function(mobile) {
  466. if (_this.smsinfo.status) {
  467. return false;
  468. }
  469. _this.smsinfo.status = true;
  470. _this.$req.ajax({
  471. path: "login/smsmobilelogin",
  472. data: {
  473. identifier: mobile
  474. }
  475. }).then((data) => {
  476. _this.smsinfo.smscodepass = data.smscodepass;
  477. _this.timerId = setInterval(() => {
  478. var codeTime = _this.smsinfo.codeTime;
  479. codeTime--;
  480. _this.smsinfo.codeTime = codeTime;
  481. _this.smsinfo.text = codeTime + "s 后重新发送";
  482. if (codeTime < 1) {
  483. clearInterval(_this.timerId);
  484. _this.smsinfo.text = "重新获取";
  485. _this.smsinfo.codeTime = 60;
  486. _this.smsinfo.status = false;
  487. }
  488. }, 1000);
  489. }).catch((err) => {
  490. uni.showModal({
  491. title: '信息提示',
  492. content: err,
  493. showCancel: false
  494. });
  495. _this.smsinfo.status = false;
  496. });
  497. },
  498. regMobile: function() {
  499. if (_this.isRotate) {
  500. return false;
  501. }
  502. _this.isRotate = true;
  503. _this.$req.ajax({
  504. path: "login/mobilelogin",
  505. title: "正在登录",
  506. data: {
  507. parentid: _this.mobileInfo.parentid,
  508. editmobile: _this.mobileInfo.editmobile,
  509. editcode: _this.mobileInfo.editcode,
  510. smscodepass: _this.smsinfo.smscodepass
  511. }
  512. }).then((data) => {
  513. uni.setStorageSync('userinfo', data.userinfo);
  514. _this.toPage();
  515. _this.isRotate = false;
  516. }).catch((err) => {
  517. uni.showModal({
  518. title: '信息提示',
  519. content: err,
  520. showCancel: false
  521. });
  522. _this.isRotate = false;
  523. });
  524. }
  525. // E APP端登录注册
  526. },
  527. onShareAppMessage: function(res) {
  528. return {
  529. title: "登录注册",
  530. path: "/pages/login/login"
  531. }
  532. }
  533. }
  534. </script>
  535. <style lang="scss">
  536. .login-page {
  537. width: 100%;
  538. height: 100vh;
  539. // background-color: #FFFFFF;
  540. }
  541. .cu-form-group .title {
  542. min-width: calc(4em + 15px);
  543. }
  544. .loginBox {
  545. margin: 30rpx 30rpx 0;
  546. padding-bottom: 30rpx;
  547. border-radius: 22rpx;
  548. background-color: #FFFFFF;
  549. display: flex;
  550. flex-direction: column;
  551. align-items: center;
  552. .loginBg {
  553. display: flex;
  554. flex-direction: column;
  555. align-items: center;
  556. .tilteBg {
  557. margin: 70rpx 0 52rpx;
  558. width: 552rpx;
  559. height: 192rpx;
  560. }
  561. .iconBg {
  562. margin-bottom: 100rpx;
  563. width: 277rpx;
  564. height: 205rpx;
  565. }
  566. }
  567. }
  568. .checkCss {
  569. display: flex;
  570. align-items: center;
  571. height: 100rpx;
  572. border-top: 1rpx solid #E6E6E6;
  573. font-size: 28rpx;
  574. }
  575. // 选中的颜色
  576. .option_active {
  577. color: orange;
  578. position: relative;
  579. }
  580. .option_active::after {
  581. content: '';
  582. position: absolute;
  583. left: 30rpx;
  584. top: 50%;
  585. transform: translateY(-50%);
  586. width: 30rpx;
  587. height: 30rpx;
  588. border-radius: 50%;
  589. background-color: #CA151C;
  590. }
  591. .option_active::before {
  592. content: '';
  593. position: absolute;
  594. left: 35rpx;
  595. top: 42%;
  596. transform: translateY(-50%);
  597. width: 18rpx;
  598. height: 10rpx;
  599. border-left: 2rpx solid #ffffff;
  600. border-bottom: 2rpx solid #ffffff;
  601. transform: rotate(-45deg);
  602. z-index: 4;
  603. }
  604. // 默认颜色
  605. .option_default {
  606. color: #000000;
  607. position: relative;
  608. }
  609. .option_default::after {
  610. content: '';
  611. position: absolute;
  612. left: 30rpx;
  613. top: 50%;
  614. transform: translateY(-50%);
  615. width: 30rpx;
  616. height: 30rpx;
  617. border-radius: 50%;
  618. border: 1rpx solid #484848;
  619. box-sizing: border-box;
  620. }
  621. .checkboxHidden {
  622. display: none;
  623. }
  624. .checkTxt {
  625. margin-left: 80rpx;
  626. }
  627. </style>