login.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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. url: '/pages/index/index',
  699. animationType: 'none',
  700. animationDuration: 2000
  701. });
  702. return;
  703. if (pages.length == 1) {
  704. uni.reLaunch({
  705. url: '/pages_im/pages/conversation/conversationList/index',
  706. //url: '../course/video/living-app',
  707. animationType: 'none',
  708. animationDuration: 2000
  709. });
  710. } else {
  711. //this.$navBack();
  712. }
  713. }
  714. },
  715. goToRegister() {
  716. this.$navTo('./register');
  717. },
  718. goToFindPass() {
  719. this.$navTo('./findpass');
  720. },
  721. sendSms() {
  722. if (this.coolDown > 0) {
  723. return;
  724. }
  725. if (!uni.$u.test.mobile(this.userName)) {
  726. uni.showToast({
  727. title: '请输入正确的手机号',
  728. icon: 'none'
  729. });
  730. return;
  731. }
  732. this.coolDown = 60;
  733. sendCode({phone: this.userName}).then((res) => {
  734. console.log("qxj sendCode res",res);
  735. if (res.code == 200) {
  736. uni.showToast({title: '验证码已发送',icon: 'none'});
  737. this.coolDown = 60;
  738. this.timer = setInterval(() => {
  739. this.coolDown--;
  740. if (this.coolDown === 0) {
  741. clearInterval(this.timer);
  742. this.timer = null;
  743. }
  744. }, 1000);
  745. } else {
  746. this.timer && clearInterval(this.timer);
  747. this.coolDown = 0;
  748. uni.showToast({
  749. title: res.msg,
  750. icon: 'none'
  751. });
  752. }
  753. },
  754. (rej) => {
  755. this.timer && clearInterval(this.timer);
  756. this.coolDown = 0;
  757. }
  758. ).catch(() => {
  759. this.timer && clearInterval(this.timer);
  760. this.coolDown = 0;
  761. });
  762. },
  763. loginByPhone() {
  764. if (!uni.$u.test.mobile(this.userName)) {
  765. uni.showToast({
  766. title: '请输入正确的手机号',
  767. icon: 'none'
  768. });
  769. return;
  770. }
  771. if (this.$isEmpty(this.code)) {
  772. uni.showToast({
  773. title: '请输入验证码',
  774. icon: 'none'
  775. });
  776. return;
  777. }
  778. if (!this.agree) {
  779. uni.showToast({
  780. title: '请同意相关协议',
  781. icon: 'none'
  782. });
  783. return;
  784. }
  785. var data = {
  786. phone: this.userName,
  787. code: this.code,
  788. jpushId: this.registrationID,
  789. loginType: 2,
  790. source: this.source
  791. };
  792. var that = this;
  793. uni.showLoading({
  794. title: '处理中...'
  795. });
  796. loginByPhone(data).then((res) => {
  797. uni.hideLoading();
  798. if (res.code == 200 && res.users && isArray(res.users)) {
  799. uni.setStorageSync('requestParam', data);
  800. uni.setStorageSync('wechatList', res.users);
  801. that.goPage();
  802. return;
  803. }
  804. if (res.code == 200) {
  805. uni.setStorageSync('AppToken', res.token);
  806. if( res.liveToken){
  807. uni.setStorageSync('liveToken', res.liveToken);
  808. }
  809. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  810. uni.setStorageSync('userData', JSON.stringify(res.user));
  811. uni.$emit('refreshIM');
  812. uni.$emit('showHealthButler');
  813. that.goPage();
  814. } else {
  815. uni.showToast({
  816. title: res.msg,
  817. icon: 'none'
  818. });
  819. }
  820. },
  821. (rej) => {
  822. uni.hideLoading();
  823. }
  824. );
  825. },
  826. wxLoginAndBindPhone(){
  827. if (!uni.$u.test.mobile(this.userName)) {
  828. uni.showToast({
  829. title: '请输入正确的手机号',
  830. icon: 'none'
  831. });
  832. return;
  833. }
  834. if (this.$isEmpty(this.code)) {
  835. uni.showToast({
  836. title: '请输入验证码',
  837. icon: 'none'
  838. });
  839. return;
  840. }
  841. if (!this.agree) {
  842. uni.showToast({
  843. title: '请同意相关协议',
  844. icon: 'none'
  845. });
  846. return;
  847. }
  848. this.setPhoneAct(this.$isIos() ? 3 : 1, this.userName, this.unionid);
  849. }
  850. },
  851. beforeDestroy() {
  852. // 组件卸载时清掉定时器,防止内存泄漏
  853. this.timer && clearInterval(this.timer);
  854. }
  855. };
  856. </script>
  857. <style scoped lang="scss">
  858. page {
  859. background-color: #ffffff;
  860. }
  861. .logintype {
  862. font-size: 16px;
  863. color: #ff5c03;
  864. padding: 24rpx;
  865. text-align: left;
  866. width: 100%;
  867. background-color: transparent;
  868. display: flex;
  869. align-items: center;
  870. box-sizing: border-box;
  871. &-item {
  872. flex: 1;
  873. margin: 0 16rpx;
  874. padding: 16rpx;
  875. text-align: center;
  876. border-radius: 8rpx;
  877. color: #333;
  878. background-color: transparent;
  879. }
  880. .active {
  881. background-color: #ff5c03 !important;
  882. color: #fff !important;
  883. }
  884. }
  885. .input-yzcode {
  886. margin-top: 20rpx;
  887. margin-bottom: 20rpx;
  888. border-radius: 40rpx;
  889. border: solid 0rpx #efefef;
  890. height: 80rpx;
  891. width: 100%;
  892. background: url(/static/image/login/cz_icon.png) no-repeat 0 center;
  893. background-size: 30rpx 30rpx;
  894. background-position: 30rpx;
  895. }
  896. .other-login-btn {
  897. display: flex;
  898. align-items: center;
  899. justify-content: center;
  900. width: 100%;
  901. height: 80rpx;
  902. background: rgba(229, 138, 0, 0.08);
  903. border-radius: 40rpx;
  904. font-size: 30rpx;
  905. font-family: PingFang SC;
  906. font-weight: 500;
  907. color: #ff5c03;
  908. border: 2rpx solid #ff5c03;
  909. margin-top: 30rpx;
  910. &::after {
  911. border: none;
  912. }
  913. }
  914. .content {
  915. display: flex;
  916. flex-direction: column;
  917. align-items: center;
  918. height: calc(100vh);
  919. width: 100%;
  920. position: relative;
  921. // justify-content: space-between;
  922. //padding-top: calc(100% - 32vh);
  923. }
  924. .backImg {
  925. position: absolute;
  926. left: 30rpx;
  927. top: 40px;
  928. height: 30rpx;
  929. width: 30rpx;
  930. }
  931. .pageTop {
  932. display: flex;
  933. flex-direction: column;
  934. width: 100%;
  935. }
  936. .content .head {
  937. text-align: center;
  938. width: 100%;
  939. height: 100rpx;
  940. // background:url(/static/image/login/top_bg.png) no-repeat 0 center;
  941. background-size: cover;
  942. box-sizing: border-box;
  943. font-size: 36rpx;
  944. font-weight: bold;
  945. color: #666;
  946. }
  947. .content .head image {
  948. width: 150rpx;
  949. height: 150rpx;
  950. border-radius: 10rpx;
  951. box-shadow: 0px 0px 20rpx rgba(0, 0, 0, 0.2);
  952. }
  953. .title {
  954. color: #141414;
  955. margin: 50upx 0upx 30upx 0rpx;
  956. font-size: 38rpx;
  957. font-weight: 500;
  958. }
  959. .desc {
  960. color: #686866;
  961. padding: 0 0 30rpx 0rpx;
  962. font-size: 28rpx;
  963. }
  964. .loginBox {
  965. padding: 0 10px 30rpx;
  966. width: calc(100%);
  967. background: #fdfdfd;
  968. z-index: 10;
  969. position: relative;
  970. .login-item p {
  971. text-align: left;
  972. }
  973. .line {
  974. height: 0.5rpx;
  975. background-color: #efefef;
  976. margin-top: 10rpx;
  977. }
  978. .input-account {
  979. margin-top: 20rpx;
  980. margin-bottom: 0rpx;
  981. border-radius: 40rpx;
  982. border: solid 0rpx #efefef;
  983. height: 80rpx;
  984. width: 100%;
  985. background: url(/static/account.png) no-repeat 0 center;
  986. background-size: 30rpx 30rpx;
  987. background-position: 30rpx;
  988. }
  989. .input-pwd {
  990. margin-top: 20rpx;
  991. margin-bottom: 20rpx;
  992. border-radius: 40rpx;
  993. border: solid 0rpx #efefef;
  994. height: 80rpx;
  995. width: 100%;
  996. background: url(/static/password.png) no-repeat 0 center;
  997. background-size: 30rpx 30rpx;
  998. background-position: 30rpx;
  999. }
  1000. input {
  1001. margin-left: 80rpx;
  1002. height: 80rpx;
  1003. line-height: 80rpx;
  1004. }
  1005. .reg-box {
  1006. padding-bottom: 20rpx;
  1007. margin: 0 10px;
  1008. .reg-btn {
  1009. font-size: 16px;
  1010. color: #ff5c03;
  1011. }
  1012. }
  1013. }
  1014. .btns {
  1015. margin: 60rpx 0rpx;
  1016. }
  1017. .login-btn {
  1018. display: flex;
  1019. align-items: center;
  1020. justify-content: center;
  1021. width: 100%;
  1022. height: 80rpx;
  1023. background: linear-gradient(to right, #ff5c03 0%, #ff5c03 100%);
  1024. background: -moz-linear-gradient(to right, #ff5c03 0%, #ff5c03 100%);
  1025. box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
  1026. border-radius: 40rpx;
  1027. font-size: 30rpx;
  1028. font-family: PingFang SC;
  1029. font-weight: 500;
  1030. color: rgba(255, 255, 255, 1);
  1031. }
  1032. .pageBottom {
  1033. height: 220rpx;
  1034. width: 75%;
  1035. display: flex;
  1036. flex-direction: column;
  1037. position: absolute;
  1038. bottom: 100rpx;
  1039. }
  1040. .tips {
  1041. color: #999;
  1042. font-size: 32rpx;
  1043. }
  1044. .menu {
  1045. margin-top: 30rpx;
  1046. image {
  1047. width: 96rpx;
  1048. height: 96rpx;
  1049. }
  1050. }
  1051. .checkbox {
  1052. margin: 20rpx;
  1053. margin-top: 36rpx;
  1054. display: flex;
  1055. flex-direction: row;
  1056. align-items: flex-start;
  1057. justify-content: flex-start;
  1058. font-family: PingFang SC, PingFang SC;
  1059. font-weight: 400;
  1060. font-size: 26rpx;
  1061. color: #999999;
  1062. line-height: 38rpx;
  1063. text-align: left;
  1064. text {
  1065. color: #ff5c03;
  1066. }
  1067. &-icon {
  1068. flex-shrink: 0;
  1069. margin-right: 12rpx;
  1070. image {
  1071. height: 24rpx;
  1072. width: 24rpx;
  1073. }
  1074. }
  1075. }
  1076. </style>