login.vue 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. <template>
  2. <view>
  3. <view class="content x-c">
  4. <image class="backImg" @tap="goBack()" src="../../static/images/icon_close.png"></image>
  5. <view class="pageTop x-c">
  6. <view class="head x-c">
  7. 登录即可体验完整功能
  8. </view>
  9. <!-- <view class="logintype" @click="changeType">{{type==0?'用短信验证码登录':'用密码登录'}}</view> -->
  10. <view class="logintype" v-if="isSms">
  11. <view :class="current==0 ? 'logintype-item active':'logintype-item'" @click="changeType(0)">用密码登录
  12. </view>
  13. <view :class="current==1 ? 'logintype-item active':'logintype-item'" @click="changeType(1)">用短信验证码登录
  14. </view>
  15. </view>
  16. <view class="loginBox">
  17. <view class="login-item">
  18. <view class="input-account">
  19. <input v-model="userName" placeholder="手机号登录" type="number" maxlength="11" />
  20. </view>
  21. <view class="line"></view>
  22. </view>
  23. <view class="login-item" v-show="current==0">
  24. <view class="input-pwd">
  25. <input v-model="password" placeholder="密码" type="password" />
  26. </view>
  27. <view class="line"></view>
  28. </view>
  29. <view class="login-item" v-show="current==1">
  30. <view class="input-yzcode x-bc">
  31. <input v-model="code" placeholder="验证码" type="number" />
  32. <view style="color:#666;flex-shrink: 0;" @click="sendSms">
  33. {{coolDown==0 ? '获取验证码': `${coolDown}秒后重试`}}
  34. </view>
  35. </view>
  36. <view class="line"></view>
  37. </view>
  38. <view class="btns">
  39. <view class="login-btn" @click="login">登录</view>
  40. </view>
  41. <view class="reg-box x-bc" v-if="isSms">
  42. <view class="reg-btn" @click="goToRegister()">注册账号</view>
  43. <view class="reg-btn" @click="goToFindPass()">忘记密码</view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="pageBottom" v-if="isApp && isAgreePrivacy">
  48. <view class="tips y-f"> — 快捷登录 — </view>
  49. <view class="menu x-ac">
  50. <view v-if="wxIsInstalled" @tap="loginWeixin">
  51. <image src="/static/image/login/weixin.png"></image>
  52. </view>
  53. <view v-if="isIos" @tap="quickAppleLogin">
  54. <image src="/static/image/login/apple.png"></image>
  55. </view>
  56. <!-- <view><image src="/static/image/login/qq.png"></image></view>
  57. <view><image src="/static/image/login/weibo.png"></image></view> -->
  58. </view>
  59. </view>
  60. <view class="checkbox">
  61. <view class="checkbox-icon" @tap="handleAgree">
  62. <image src="../../static/image/login/radio_default.png" v-show="!agree"></image>
  63. <image src="../../static/image/login/radio_choose.png" v-show="agree"></image>
  64. </view>
  65. <view>我已阅读并同意<text @tap="goToWeb(0)">《用户协议》</text><text @tap="goToWeb(1)">《隐私政策》</text> 并使用本机号码登录</view>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import {
  72. quickWechatLogin
  73. } from "@/utils/login.js"
  74. import {
  75. login,
  76. loginByWeChat,
  77. getUserInfo,
  78. loginByApple,
  79. setPhone,
  80. sendCode,
  81. loginByPhone,
  82. isSmsVerification
  83. } from '@/api/user'
  84. export default {
  85. data() {
  86. return {
  87. userName: "",
  88. password: "",
  89. registrationID: "",
  90. unionid: "",
  91. userPhone: "",
  92. loginType: 0,
  93. isApp: false,
  94. agree: false,
  95. isAgreePrivacy: false,
  96. isIos: false,
  97. from: '',
  98. source: '',
  99. appleKey: "",
  100. wxIsInstalled: false,
  101. current: 0,
  102. coolDown: 0,
  103. timer: null,
  104. btnLoading: false,
  105. code: '',
  106. list: ['用密码登录', '用短信验证码登录'],
  107. isSms: false,
  108. }
  109. },
  110. onLoad(option) {
  111. // #ifdef APP-PLUS
  112. this.isIos = plus.os.name == "iOS"
  113. this.isApp = true;
  114. if (this.isIos) {
  115. this.wxIsInstalled = this.$checkWechatInstalled();
  116. } else {
  117. this.wxIsInstalled = true;
  118. }
  119. this.source = this.isIos ? "iOS" : plus.runtime.channel || 'app';
  120. // #endif
  121. this.from = option.from || ''
  122. let that = this;
  123. uni.$on('getRegistrationID', function(data) {
  124. that.registrationID = data;
  125. });
  126. uni.hideLoading();
  127. // if(!this.$isLogin()) {
  128. // this.$showLoginPage()
  129. // }
  130. },
  131. onShow() {
  132. if (this.$isLogin()) {
  133. this.goPage()
  134. }
  135. // #ifdef APP-PLUS
  136. this.isAgreePrivacy = plus.runtime.isAgreePrivacy();
  137. if (this.isAgreePrivacy) {
  138. this.getRegistrationID();
  139. }
  140. // #endif
  141. this.isSmsVerificationFun()
  142. },
  143. onUnload() {
  144. uni.$off('getRegistrationID');
  145. },
  146. mounted() {
  147. },
  148. methods: {
  149. async isSmsVerificationFun() {
  150. const res = await isSmsVerification()
  151. if (res.code == 200) {
  152. this.isSms = res.isSmsVerification == 1 ? true : false
  153. } else {
  154. if (!res.msg) return
  155. uni.showToast({
  156. icon: 'none',
  157. title: res.msg
  158. })
  159. }
  160. },
  161. changeType(e) {
  162. console.log("changeType=[===]", e)
  163. this.current = this.current == 0 ? 1 : 0
  164. },
  165. initUniverify() {
  166. const callback = (res) => {
  167. // 获取一键登录弹框协议勾选状态
  168. univerifyManager.getCheckBoxState({
  169. success(res) {
  170. if (res.state) {
  171. // 关闭一键登录弹框
  172. univerifyManager.close()
  173. }
  174. }
  175. })
  176. }
  177. // 订阅自定义按钮点击事件
  178. univerifyManager.onButtonsClick(callback);
  179. // 取消订阅自定义按钮点击事件
  180. univerifyManager.offButtonsClick(callback);
  181. },
  182. login() {
  183. if (this.current == 1) {
  184. this.loginByPhone()
  185. return
  186. }
  187. if (this.$isEmpty(this.userName)) {
  188. uni.showToast({
  189. title: "请输入帐号",
  190. icon: 'none',
  191. });
  192. return
  193. }
  194. if (this.$isEmpty(this.password)) {
  195. uni.showToast({
  196. title: "请输入密码",
  197. icon: 'none',
  198. });
  199. return
  200. }
  201. if (!uni.$u.test.mobile(this.userName)) {
  202. uni.showToast({
  203. title: "请输入正确的手机号",
  204. icon: 'none',
  205. });
  206. return
  207. }
  208. if (!this.agree) {
  209. uni.showToast({
  210. title: "请同意相关协议",
  211. icon: 'none'
  212. });
  213. return
  214. }
  215. let data = {
  216. phone: this.userName,
  217. password: this.password,
  218. jpushId: this.registrationID,
  219. loginType: 1,
  220. source: this.source
  221. };
  222. let that = this;
  223. uni.showLoading({
  224. title: "处理中..."
  225. });
  226. console.log("qxj login", data);
  227. login(data).then(res => {
  228. uni.hideLoading();
  229. if (res.code == 200 && res.users && Object.prototype.toString.call(res.users) ==
  230. '[object Array]') {
  231. uni.setStorageSync('requestParam', data)
  232. uni.setStorageSync('wechatList', res.users)
  233. this.goPage();
  234. return
  235. }
  236. if (res.code == 200) {
  237. // #ifdef APP-PLUS
  238. if (res.isNew) {
  239. quickWechatLogin(true, res.phone);
  240. return;
  241. }
  242. // #endif
  243. uni.setStorageSync('AppToken', res.token);
  244. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  245. uni.$emit('refreshIM');
  246. uni.$emit('showHealthButler');
  247. that.goPage();
  248. } else {
  249. uni.showToast({
  250. title: res.msg,
  251. icon: 'none'
  252. });
  253. }
  254. },
  255. rej => {
  256. uni.hideLoading();
  257. console.log("qxj rej:" + JSON.stringify(rej));
  258. }
  259. );
  260. },
  261. quickAppleLogin() {
  262. let that = this;
  263. if (!this.agree) {
  264. uni.showToast({
  265. title: "请同意相关协议",
  266. icon: 'none'
  267. });
  268. return
  269. }
  270. uni.getProvider({
  271. service: 'oauth',
  272. success: function(res) {
  273. if (res.provider.indexOf('apple')) {
  274. uni.login({
  275. provider: 'apple',
  276. success: function(loginRes) {
  277. that.appleKey = loginRes.authResult.openid
  278. that.loginByAppleAct(loginRes.authResult)
  279. },
  280. fail: function(err) {
  281. console.log(err);
  282. // 登录授权失败
  283. // err.code错误码参考`授权失败错误码(code)说明`
  284. }
  285. });
  286. }
  287. }
  288. });
  289. },
  290. async loginByAppleAct(authResult) {
  291. let loginDevice = ''
  292. if (this.$isAgreePrivacy()) {
  293. const info = await uni.getPushClientId();
  294. uni.setStorageSync("registrationID", info.cid);
  295. this.registrationID = info.cid;
  296. let devinfo = await uni.getDeviceInfo();
  297. if (devinfo != null) {
  298. loginDevice += devinfo.deviceBrand ? devinfo.deviceBrand : "";
  299. loginDevice += devinfo.deviceModel ? " " + devinfo.deviceModel : "";
  300. loginDevice += devinfo.system ? " " + devinfo.system : "";
  301. }
  302. }
  303. const params = {
  304. loginDevice: loginDevice,
  305. jpushId: this.registrationID,
  306. source: this.source,
  307. appleKey: authResult.openid
  308. };
  309. uni.showLoading({
  310. title: '请稍候...'
  311. })
  312. loginByApple(params).then(res => {
  313. uni.hideLoading()
  314. if (res.code == 200) {
  315. if (res.user != null) {
  316. uni.hideLoading();
  317. uni.setStorageSync('AppToken', res.token);
  318. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  319. uni.closeAuthView();
  320. uni.$emit('refreshIM');
  321. uni.$emit('showHealthButler');
  322. uni.$emit('refreshUserInfo', {});
  323. // this.$navBack();
  324. this.goPage()
  325. } else {
  326. if (res.isNew) {
  327. this.bindMobile('apple');
  328. }
  329. }
  330. } else {
  331. uni.showToast({
  332. title: res.msg,
  333. icon: 'none'
  334. });
  335. }
  336. }).catch(() => {
  337. uni.hideLoading()
  338. })
  339. },
  340. loginWeixin() {
  341. if (!this.agree) {
  342. uni.showToast({
  343. title: "请同意相关协议",
  344. icon: 'none'
  345. });
  346. return
  347. }
  348. quickWechatLogin(false)
  349. return
  350. uni.login({
  351. provider: "weixin",
  352. onlyAuthorize: true,
  353. success: async (res) => {
  354. let that = this;
  355. uni.showLoading({
  356. title: "处理中..."
  357. });
  358. const params = {
  359. code: res.code,
  360. jpushId: this.registrationID,
  361. source: this.source
  362. };
  363. this.loginByWeChatAct(params);
  364. },
  365. fail: (err) => {
  366. console.log('qxj loginWeixin fail:', JSON.stringify(err));
  367. if (err.code == 1000) { // 未开通
  368. uni.showModal({
  369. title: '登录失败',
  370. content: `${err.errMsg}\n,错误码:${err.code}`,
  371. confirmText: '开通指南',
  372. cancelText: '确定',
  373. success: (res) => {
  374. if (res.confirm) {
  375. setTimeout(() => {
  376. plus.runtime.openWeb(
  377. 'https://ask.dcloud.net.cn/article/37965'
  378. )
  379. }, 500)
  380. }
  381. }
  382. });
  383. return;
  384. }
  385. // 一键登录预登陆失败
  386. if (err.code == '30005') {
  387. uni.showModal({
  388. showCancel: false,
  389. title: '预登录失败',
  390. content: err.errMsg
  391. });
  392. return;
  393. }
  394. // 一键登录用户关闭验证界面
  395. if (err.code != '30003') {
  396. uni.showModal({
  397. showCancel: false,
  398. title: '登录失败',
  399. content: JSON.stringify(err)
  400. });
  401. }
  402. },
  403. complete: () => {
  404. }
  405. });
  406. },
  407. doUniverify(authResult) {
  408. uniCloud.callFunction({
  409. name: 'loginByMobile', // 你的云函数名称
  410. data: {
  411. access_token: authResult.access_token, // 客户端一键登录接口返回的access_token
  412. openid: authResult.openid // 客户端一键登录接口返回的openid
  413. }
  414. }).then(res => {
  415. uni.closeAuthView();
  416. if (res.result.errCode == 0) {
  417. this.userName = res.result.phoneNumber;
  418. } else {
  419. uni.showToast({
  420. title: res.result.message,
  421. icon: 'none'
  422. });
  423. }
  424. }).catch(err => {
  425. // 处理错误
  426. console.error('调用云函数失败:', err);
  427. // 详细记录错误信息
  428. console.error('错误信息:', err.errMsg);
  429. })
  430. },
  431. loginByWeChatAct(params) {
  432. loginByWeChat(params).then(res => {
  433. if (res.code == 200) {
  434. if (res.user != null) {
  435. uni.hideLoading();
  436. uni.setStorageSync('AppToken', res.token);
  437. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  438. uni.closeAuthView();
  439. uni.$emit('refreshIM');
  440. uni.$emit('showHealthButler');
  441. uni.$emit('refreshUserInfo', {});
  442. // this.$navBack();
  443. this.goPage()
  444. } else {
  445. this.unionid = res.unionid;
  446. if (res.isNew) {
  447. this.bindMobile();
  448. }
  449. }
  450. } else {
  451. uni.hideLoading();
  452. uni.showToast({
  453. title: res.msg,
  454. icon: 'none'
  455. });
  456. }
  457. },
  458. rej => {}
  459. );
  460. },
  461. bindMobile(type) {
  462. let that = this;
  463. // #ifdef APP-PLUS
  464. const uniLogin = () => {
  465. uni.login({
  466. provider: 'univerify',
  467. univerifyStyle: { // 自定义登录框样式
  468. fullScreen: false,
  469. authButton: {
  470. "title": "绑定手机号",
  471. "normalColor": "#2583EB",
  472. "highlightColor": "#2583EB",
  473. },
  474. privacyTerms: {
  475. "defaultCheckBoxState": true, // 条款勾选框初始状态 默认值: true
  476. "isCenterHint": false, //未勾选服务条款时点击登录按钮的提示是否居中显示 默认值: false (3.7.13+ 版本支持)
  477. "uncheckedImage": "", // 可选 条款勾选框未选中状态图片(仅支持本地图片 建议尺寸 24x24px)(3.2.0+ 版本支持)
  478. "checkedImage": "", // 可选 条款勾选框选中状态图片(仅支持本地图片 建议尺寸24x24px)(3.2.0+ 版本支持)
  479. "checkBoxSize": 18, // 可选 条款勾选框大小
  480. "textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB
  481. "termsColor": "#2583EB", // 协议文字颜色 默认值: #5496E3
  482. "prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意”
  483. "suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录”
  484. "privacyItems": [ // 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
  485. ]
  486. },
  487. },
  488. success(res) {
  489. console.log("qxj univerify login:" + JSON.stringify(res
  490. .authResult)); // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
  491. if (type == 'apple') {
  492. that.loginByUniverify(res.authResult, 3);
  493. } else {
  494. that.loginByUniverify(res.authResult, 1);
  495. }
  496. },
  497. fail(res) {
  498. uni.hideLoading();
  499. uni.showToast({
  500. title: "一键登录失败请检查网络和SIM卡是否可用",
  501. icon: 'none',
  502. position: 'bottom'
  503. });
  504. //setTimeout(function() {
  505. uni.navigateTo({
  506. url: "/pages/auth/login"
  507. });
  508. //}, 1800);
  509. //}
  510. //登录失败
  511. console.log("qxj failRes:" + JSON.stringify(res));
  512. }
  513. });
  514. };
  515. if (this.isIos) {
  516. uni.preLogin({
  517. provider: 'univerify',
  518. success(res) { //预登录成功 显示一键登录选项
  519. console.log("预登录成功");
  520. uniLogin();
  521. },
  522. fail(res) { // 预登录失败
  523. // 不显示一键登录选项(或置灰)
  524. // 根据错误信息判断失败原因,如有需要可将错误提交给统计服务器
  525. uni.hideLoading();
  526. if (res.errCode == 30005 || res.errMsg.includes("无SIM卡")) {
  527. uni.navigateTo({
  528. url: "/pages/auth/bindMobile?appleKey=" + that.appleKey
  529. });
  530. }
  531. }
  532. });
  533. } else {
  534. uniLogin();
  535. }
  536. // #endif
  537. // #ifdef H5
  538. uni.navigateTo({
  539. url: "/pages/auth/login"
  540. });
  541. // #endif
  542. },
  543. loginByUniverify(authResult, type) {
  544. uniCloud.callFunction({
  545. name: 'loginByMobile', // 你的云函数名称
  546. data: {
  547. access_token: authResult.access_token, // 客户端一键登录接口返回的access_token
  548. openid: authResult.openid // 客户端一键登录接口返回的openid
  549. }
  550. }).then(res => {
  551. console.log("qxj doUniverify:", JSON.stringify(res));
  552. if (res.result.errCode == 0) {
  553. this.userPhone = res.result.phoneNumber;
  554. if (type == 3) {
  555. // 苹果登录
  556. this.setPhoneAct(3, this.userPhone, this.unionid);
  557. } else {
  558. this.setPhoneAct(1, this.userPhone, this.unionid);
  559. }
  560. } else {
  561. uni.showToast({
  562. title: res.result.message,
  563. icon: 'none'
  564. });
  565. }
  566. }).catch(err => {
  567. // 处理错误
  568. console.error('调用云函数失败:', err);
  569. // 详细记录错误信息
  570. console.error('错误信息:', err.errMsg);
  571. })
  572. },
  573. setPhoneAct(type, phone, unionId) {
  574. let params = {
  575. phone: phone,
  576. unionId: unionId,
  577. };
  578. if (type == 3) {
  579. params = {
  580. phone: phone,
  581. unionId: unionId,
  582. appleKey: this.appleKey
  583. };
  584. }
  585. setPhone(params).then(res => {
  586. uni.hideLoading();
  587. if (res.code == 200) {
  588. uni.setStorageSync('AppToken', res.token);
  589. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  590. uni.closeAuthView();
  591. uni.$emit('refreshIM');
  592. this.goPage()
  593. } else {
  594. uni.showToast({
  595. title: res.msg,
  596. icon: 'none'
  597. });
  598. uni.closeAuthView();
  599. }
  600. },
  601. rej => {}
  602. );
  603. },
  604. getRegistrationID() {
  605. this.registrationID = uni.getStorageSync("registrationID");
  606. if (this.registrationID == null || this.registrationID == "") {
  607. uni.getPushClientId({
  608. success: res => {
  609. uni.setStorageSync("registrationID", res.cid);
  610. this.registrationID = res.cid
  611. }
  612. });
  613. }
  614. },
  615. goBack() {
  616. uni.$emit('showHealthButler');
  617. // this.$navBack();
  618. uni.redirectTo({
  619. url: "/pages/auth/loginIndex"
  620. })
  621. },
  622. handleAgree() { // 同意
  623. this.agree = !this.agree
  624. if (this.isIos) {
  625. if (this.agree) {
  626. plus.runtime.agreePrivacy()
  627. this.getRegistrationID();
  628. } else {
  629. plus.runtime.disagreePrivacy();
  630. }
  631. }
  632. },
  633. goToWeb(index) {
  634. uni.setStorageSync('url', index == 0 ? getApp().globalData.userAgreement : getApp().globalData
  635. .privacyPolicy);
  636. uni.navigateTo({
  637. url: "/pages/index/h5"
  638. })
  639. },
  640. goPage() {
  641. let pages = getCurrentPages();
  642. let url = pages[pages.length - 1];
  643. const wechatList = uni.getStorageSync('wechatList')
  644. if (wechatList) {
  645. return uni.navigateTo({
  646. url: '/pages/auth/wechatList'
  647. })
  648. }
  649. let openUrl = uni.getStorageSync("openUrl");
  650. if (openUrl) {
  651. uni.navigateTo({
  652. url: openUrl,
  653. success: function(res) {
  654. uni.removeStorageSync("openUrl")
  655. }
  656. })
  657. } else {
  658. this.$updateMsgDot();
  659. this.$setSource();
  660. uni.reLaunch({
  661. // url: '../course/index',
  662. url: '/pages_im/pages/conversation/conversationList/index',
  663. animationType: 'none',
  664. animationDuration: 2000
  665. });
  666. return;
  667. if (pages.length == 1) {
  668. uni.reLaunch({
  669. // url: '../course/index',
  670. url: '/pages_im/pages/conversation/conversationList/index',
  671. //url: '../course/video/living-app',
  672. animationType: 'none',
  673. animationDuration: 2000
  674. });
  675. } else {
  676. //this.$navBack();
  677. }
  678. }
  679. },
  680. goToRegister() {
  681. this.$navTo('./register');
  682. },
  683. goToFindPass() {
  684. this.$navTo('./findpass');
  685. },
  686. sendSms() {
  687. if (this.coolDown > 0) {
  688. return
  689. }
  690. if (!uni.$u.test.mobile(this.userName)) {
  691. uni.showToast({
  692. title: "请输入正确的手机号",
  693. icon: 'none',
  694. });
  695. return
  696. }
  697. this.coolDown = 60;
  698. sendCode({
  699. phone: this.userName
  700. }).then(res => {
  701. if (res.code == 200) {
  702. uni.showToast({
  703. title: '验证码已发送',
  704. icon: 'none',
  705. });
  706. this.coolDown = 60;
  707. this.timer = setInterval(() => {
  708. this.coolDown--;
  709. if (this.coolDown === 0) {
  710. clearInterval(this.timer);
  711. this.timer = null;
  712. }
  713. }, 1000);
  714. } else {
  715. this.timer && clearInterval(this.timer);
  716. this.coolDown = 0
  717. uni.showToast({
  718. title: res.msg,
  719. icon: 'none',
  720. });
  721. }
  722. },
  723. rej => {
  724. this.timer && clearInterval(this.timer);
  725. this.coolDown = 0;
  726. }).catch(() => {
  727. this.timer && clearInterval(this.timer);
  728. this.coolDown = 0;
  729. })
  730. },
  731. loginByPhone() {
  732. if (!uni.$u.test.mobile(this.userName)) {
  733. uni.showToast({
  734. title: "请输入正确的手机号",
  735. icon: 'none',
  736. });
  737. return
  738. }
  739. if (this.$isEmpty(this.code)) {
  740. uni.showToast({
  741. title: "请输入验证码",
  742. icon: 'none',
  743. });
  744. return
  745. }
  746. if (!this.agree) {
  747. uni.showToast({
  748. title: "请同意相关协议",
  749. icon: 'none'
  750. });
  751. return
  752. }
  753. let data = {
  754. phone: this.userName,
  755. code: this.code,
  756. jpushId: this.registrationID,
  757. source: this.source
  758. };
  759. let that = this;
  760. uni.showLoading({
  761. title: "处理中..."
  762. });
  763. loginByPhone(data).then(res => {
  764. uni.hideLoading();
  765. if (res.code == 200 && res.users && isArray(res.users)) {
  766. uni.setStorageSync('requestParam', data)
  767. uni.setStorageSync('wechatList', res.users)
  768. that.goPage();
  769. return
  770. }
  771. if (res.code == 200) {
  772. // #ifdef APP-PLUS
  773. if (res.isNew) {
  774. quickWechatLogin(true, res.phone);
  775. return;
  776. }
  777. // #endif
  778. uni.setStorageSync('AppToken', res.token);
  779. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  780. uni.$emit('refreshIM');
  781. uni.$emit('showHealthButler');
  782. that.goPage();
  783. } else {
  784. uni.showToast({
  785. title: res.msg,
  786. icon: 'none'
  787. });
  788. }
  789. },
  790. rej => {
  791. uni.hideLoading();
  792. console.log("qxj rej:" + JSON.stringify(rej));
  793. }
  794. )
  795. }
  796. },
  797. beforeDestroy() { // 组件卸载时清掉定时器,防止内存泄漏
  798. this.timer && clearInterval(this.timer);
  799. }
  800. }
  801. </script>
  802. <style scoped lang="scss">
  803. page {
  804. background-color: #ffffff;
  805. }
  806. .logintype {
  807. font-size: 16px;
  808. color: #2583EB;
  809. padding: 24rpx;
  810. text-align: left;
  811. width: 100%;
  812. background-color: transparent;
  813. display: flex;
  814. align-items: center;
  815. box-sizing: border-box;
  816. &-item {
  817. flex: 1;
  818. margin: 0 16rpx;
  819. padding: 16rpx;
  820. text-align: center;
  821. border-radius: 8rpx;
  822. color: #333;
  823. background-color: transparent;
  824. }
  825. .active {
  826. background-color: #2583EB !important;
  827. color: #fff !important;
  828. }
  829. }
  830. .input-yzcode {
  831. margin-top: 20rpx;
  832. margin-bottom: 20rpx;
  833. border-radius: 40rpx;
  834. border: solid 0rpx #efefef;
  835. height: 80rpx;
  836. width: 100%;
  837. background: url(/static/image/login/cz_icon.png) no-repeat 0 center;
  838. background-size: 30rpx 30rpx;
  839. background-position: 30rpx;
  840. }
  841. .other-login-btn {
  842. display: flex;
  843. align-items: center;
  844. justify-content: center;
  845. width: 100%;
  846. height: 80rpx;
  847. background: rgba(229, 138, 0, 0.08);
  848. border-radius: 40rpx;
  849. font-size: 30rpx;
  850. font-family: PingFang SC;
  851. font-weight: 500;
  852. color: #2583EB;
  853. border: 2rpx solid #2583EB;
  854. margin-top: 30rpx;
  855. &::after {
  856. border: none;
  857. }
  858. }
  859. .content {
  860. display: flex;
  861. flex-direction: column;
  862. align-items: center;
  863. height: calc(100vh);
  864. width: 100%;
  865. position: relative;
  866. // justify-content: space-between;
  867. //padding-top: calc(100% - 32vh);
  868. }
  869. .backImg {
  870. position: absolute;
  871. left: 30rpx;
  872. top: 40px;
  873. height: 30rpx;
  874. width: 30rpx;
  875. }
  876. .pageTop {
  877. display: flex;
  878. flex-direction: column;
  879. width: 100%;
  880. }
  881. .content .head {
  882. text-align: center;
  883. width: 100%;
  884. height: 100rpx;
  885. // background:url(/static/image/login/top_bg.png) no-repeat 0 center;
  886. background-size: cover;
  887. box-sizing: border-box;
  888. font-size: 36rpx;
  889. font-weight: bold;
  890. color: #666;
  891. }
  892. .content .head image {
  893. width: 150rpx;
  894. height: 150rpx;
  895. border-radius: 10rpx;
  896. box-shadow: 0px 0px 20rpx rgba(0, 0, 0, 0.2);
  897. }
  898. .title {
  899. color: #141414;
  900. margin: 50upx 0upx 30upx 0rpx;
  901. font-size: 38rpx;
  902. font-weight: 500;
  903. }
  904. .desc {
  905. color: #686866;
  906. padding: 0 0 30rpx 0rpx;
  907. font-size: 28rpx;
  908. }
  909. .loginBox {
  910. padding: 0 10px 30rpx;
  911. width: calc(100%);
  912. background: #FDFDFD;
  913. z-index: 10;
  914. position: relative;
  915. .login-item p {
  916. text-align: left;
  917. }
  918. .line {
  919. height: 0.5rpx;
  920. background-color: #efefef;
  921. margin-top: 10rpx;
  922. }
  923. .input-account {
  924. margin-top: 20rpx;
  925. margin-bottom: 0rpx;
  926. border-radius: 40rpx;
  927. border: solid 0rpx #efefef;
  928. height: 80rpx;
  929. width: 100%;
  930. background: url(/static/account.png) no-repeat 0 center;
  931. background-size: 30rpx 30rpx;
  932. background-position: 30rpx;
  933. }
  934. .input-pwd {
  935. margin-top: 20rpx;
  936. margin-bottom: 20rpx;
  937. border-radius: 40rpx;
  938. border: solid 0rpx #efefef;
  939. height: 80rpx;
  940. width: 100%;
  941. background: url(/static/password.png) no-repeat 0 center;
  942. background-size: 30rpx 30rpx;
  943. background-position: 30rpx;
  944. }
  945. input {
  946. margin-left: 80rpx;
  947. height: 80rpx;
  948. line-height: 80rpx
  949. }
  950. .reg-box {
  951. padding-bottom: 20rpx;
  952. margin: 0 10px;
  953. .reg-btn {
  954. font-size: 16px;
  955. color: #2583EB;
  956. }
  957. }
  958. }
  959. .btns {
  960. margin: 60rpx 0rpx;
  961. }
  962. .login-btn {
  963. display: flex;
  964. align-items: center;
  965. justify-content: center;
  966. width: 100%;
  967. height: 80rpx;
  968. background: linear-gradient(to right, #2583EB 0%, #2583EB 100%);
  969. background: -moz-linear-gradient(to right, #2583EB 0%, #2583EB 100%);
  970. box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
  971. border-radius: 40rpx;
  972. font-size: 30rpx;
  973. font-family: PingFang SC;
  974. font-weight: 500;
  975. color: rgba(255, 255, 255, 1);
  976. }
  977. .pageBottom {
  978. height: 220rpx;
  979. width: 75%;
  980. display: flex;
  981. flex-direction: column;
  982. position: absolute;
  983. bottom: 100rpx;
  984. }
  985. .tips {
  986. color: #999;
  987. font-size: 32rpx;
  988. }
  989. .menu {
  990. margin-top: 30rpx;
  991. image {
  992. width: 96rpx;
  993. height: 96rpx;
  994. }
  995. }
  996. .checkbox {
  997. margin: 20rpx;
  998. margin-top: 36rpx;
  999. display: flex;
  1000. flex-direction: row;
  1001. align-items: flex-start;
  1002. justify-content: flex-start;
  1003. font-family: PingFang SC, PingFang SC;
  1004. font-weight: 400;
  1005. font-size: 26rpx;
  1006. color: #999999;
  1007. line-height: 38rpx;
  1008. text-align: left;
  1009. text {
  1010. color: #2583EB;
  1011. }
  1012. &-icon {
  1013. flex-shrink: 0;
  1014. margin-right: 12rpx;
  1015. image {
  1016. height: 24rpx;
  1017. width: 24rpx;
  1018. }
  1019. }
  1020. }
  1021. </style>