login.vue 27 KB

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