login.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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="loginBox">
  10. <view class="login-item">
  11. <view class="input-account">
  12. <input v-model="userName" placeholder="手机号登录" type="number" />
  13. </view>
  14. <view class="line"></view>
  15. </view>
  16. <view class="login-item">
  17. <view class="input-pwd">
  18. <input v-model="password" placeholder="请输入密码" type="password" />
  19. </view>
  20. <view class="line"></view>
  21. </view>
  22. <view class="btns">
  23. <view class="login-btn" @click="login">登录</view>
  24. </view>
  25. <view class="reg-box x-bc">
  26. <view class="reg-btn" @click="goToRegister()">注册账号</view>
  27. <view class="reg-btn" @click="goToFindPass()">忘记密码</view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="pageBottom" v-if="isApp && isAgreePrivacy">
  32. <view class="tips y-f"> — 微信快捷登录 — </view>
  33. <view class="menu x-ac">
  34. <view @tap="loginWeixin"><image src="/static/image/login/weixin.png"></image></view>
  35. <!-- <view><image src="/static/image/login/qq.png"></image></view>
  36. <view><image src="/static/image/login/weibo.png"></image></view> -->
  37. </view>
  38. </view>
  39. <view class="checkbox">
  40. <view class="checkbox-icon" @tap="handleAgree">
  41. <image src="../../static/image/login/radio_default.png" v-show="!agree"></image>
  42. <image src="../../static/image/login/radio_choose.png" v-show="agree"></image>
  43. </view>
  44. <view>我已阅读并同意<text @tap="goToWeb(0)">《用户协议》</text><text @tap="goToWeb(1)">《隐私政策》</text> 并使用本机号码登录</view>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import { login,loginByWeChat,getUserInfo } from '@/api/user'
  51. export default {
  52. data() {
  53. return {
  54. userName:"",
  55. password:"",
  56. registrationID:"",
  57. unionid:"",
  58. userPhone:"",
  59. loginType:0,
  60. isApp:false,
  61. agree: false,
  62. isAgreePrivacy:false,
  63. from: '',
  64. source:''
  65. }
  66. },
  67. onLoad(option) {
  68. this.from= option.from || ''
  69. let that=this;
  70. uni.$on('getRegistrationID', function(data) {
  71. //console.log("getRegistrationID " + JSON.stringify(data));
  72. that.registrationID=data;
  73. });
  74. // #ifdef APP-PLUS
  75. this.isApp=true;
  76. this.source = plus.runtime.channel || 'app'
  77. // #endif
  78. // if(!this.$isLogin()) {
  79. // this.$showLoginPage()
  80. // }
  81. },
  82. onShow() {
  83. if(this.$isLogin()) {
  84. this.goPage()
  85. }
  86. // #ifdef APP-PLUS
  87. this.isAgreePrivacy=plus.runtime.isAgreePrivacy();
  88. if(plus.runtime.isAgreePrivacy()) {
  89. this.getRegistrationID();
  90. }
  91. // #endif
  92. },
  93. onUnload() {
  94. uni.$off('getRegistrationID');
  95. },
  96. mounted() {
  97. },
  98. methods: {
  99. initUniverify(){
  100. const callback = (res) => {
  101. // 获取一键登录弹框协议勾选状态
  102. univerifyManager.getCheckBoxState({
  103. success(res) {
  104. console.log("getCheckBoxState res: ", res);
  105. if (res.state) {
  106. // 关闭一键登录弹框
  107. univerifyManager.close()
  108. }
  109. }
  110. })
  111. }
  112. // 订阅自定义按钮点击事件
  113. univerifyManager.onButtonsClick(callback);
  114. // 取消订阅自定义按钮点击事件
  115. univerifyManager.offButtonsClick(callback);
  116. },
  117. login(){
  118. if (this.$isEmpty(this.userName)) {
  119. uni.showToast({
  120. title: "请输入帐号",
  121. icon: 'none',
  122. });
  123. return
  124. }
  125. if (this.$isEmpty(this.password)) {
  126. uni.showToast({
  127. title: "请输入密码",
  128. icon: 'none',
  129. });
  130. return
  131. }
  132. if (!this.agree) {
  133. uni.showToast({
  134. title: "请同意相关协议",
  135. icon: 'none'
  136. });
  137. return
  138. }
  139. var data = {
  140. phone:this.userName,
  141. password: this.password,
  142. jpushId:this.registrationID,
  143. loginType:1,
  144. source: this.source
  145. };
  146. var that=this;
  147. uni.showLoading({
  148. title:"处理中..."
  149. });
  150. login(data).then(res => {
  151. uni.hideLoading()
  152. if(res.code==200){
  153. uni.setStorageSync('AppToken',res.token);
  154. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  155. uni.$emit('refreshIM');
  156. uni.$emit('showHealthButler');
  157. this.goPage();
  158. // // #ifdef H5
  159. // this.$navBack();
  160. // // #endif
  161. // // #ifdef APP-PLUS
  162. // this.$navBack();
  163. // // uni.reLaunch({
  164. // // url: '../index/index',
  165. // // animationType: 'pop-in',
  166. // // animationDuration: 100
  167. // // })
  168. // // #endif
  169. }
  170. else{
  171. uni.showToast({title: res.msg,icon: 'none'});
  172. }
  173. },
  174. rej => {}
  175. );
  176. },
  177. loginWeixin(){
  178. if (!this.agree) {
  179. uni.showToast({
  180. title: "请同意相关协议",
  181. icon: 'none'
  182. });
  183. return
  184. }
  185. uni.login({
  186. provider: "weixin",
  187. onlyAuthorize:true,
  188. success: async (res) => {
  189. let that=this;
  190. uni.showLoading({
  191. title:"处理中..."
  192. });
  193. const params={code:res.code,jpushId:this.registrationID,source:this.source};
  194. this.loginByWeChatAct(params);
  195. },
  196. fail: (err) => {
  197. console.log('qxj loginWeixin fail:', JSON.stringify(err));
  198. // 未开通
  199. if (err.code == 1000) {
  200. uni.showModal({
  201. title: '登录失败',
  202. content: `${err.errMsg}\n,错误码:${err.code}`,
  203. confirmText: '开通指南',
  204. cancelText: '确定',
  205. success: (res) => {
  206. if (res.confirm) {
  207. setTimeout(() => {
  208. plus.runtime.openWeb('https://ask.dcloud.net.cn/article/37965')
  209. }, 500)
  210. }
  211. }
  212. });
  213. return;
  214. }
  215. // 一键登录预登陆失败
  216. if (err.code == '30005') {
  217. uni.showModal({
  218. showCancel: false,
  219. title: '预登录失败',
  220. content: err.errMsg
  221. });
  222. return;
  223. }
  224. // 一键登录用户关闭验证界面
  225. if (err.code != '30003') {
  226. uni.showModal({
  227. showCancel: false,
  228. title: '登录失败',
  229. content: JSON.stringify(err)
  230. });
  231. }
  232. },
  233. complete: () => {
  234. }
  235. });
  236. },
  237. goToRegister(){
  238. this.$navTo('./register');
  239. },
  240. goToFindPass(){
  241. this.$navTo('./findpass');
  242. },
  243. doUniverify(authResult){
  244. uniCloud.callFunction({
  245. name: 'loginByMobile', // 你的云函数名称
  246. data: {
  247. access_token: authResult.access_token, // 客户端一键登录接口返回的access_token
  248. openid:authResult.openid // 客户端一键登录接口返回的openid
  249. }
  250. }).then(res => {
  251. uni.closeAuthView();
  252. if(res.result.errCode==0){
  253. this.userName=res.result.phoneNumber;
  254. }else{
  255. uni.showToast({title:res.result.message,icon: 'none' });
  256. }
  257. }).catch(err=>{
  258. // 处理错误
  259. console.error('调用云函数失败:',err);
  260. // 详细记录错误信息
  261. console.error('错误信息:', err.errMsg);
  262. })
  263. },
  264. loginByWeChatAct(params){
  265. loginByWeChat(params).then(res => {
  266. console.log('login loginByWeChat success:', JSON.stringify(res));
  267. if(res.code==200){
  268. if(res.user!=null){
  269. uni.hideLoading();
  270. uni.setStorageSync('AppToken',res.token);
  271. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  272. uni.closeAuthView();
  273. uni.$emit('showHealthButler');
  274. uni.$emit('refreshUserInfo',{});
  275. // this.$navBack();
  276. this.goPage()
  277. }else{
  278. this.unionid=res.unionid;
  279. if(res.isNew){
  280. this.bindMobile();
  281. }
  282. }
  283. }
  284. else{
  285. uni.hideLoading();
  286. uni.showToast({title: res.msg,icon: 'none'});
  287. }
  288. },
  289. rej => {}
  290. );
  291. },
  292. bindMobile(){
  293. // #ifdef APP-PLUS
  294. uni.login({
  295. provider: 'univerify',
  296. univerifyStyle: { // 自定义登录框样式
  297. fullScreen: false,
  298. authButton: {
  299. "title": "绑定手机号",
  300. "normalColor": "#FF5C03",
  301. "highlightColor": "#FF5C03",
  302. },
  303. privacyTerms: {
  304. "defaultCheckBoxState":true, // 条款勾选框初始状态 默认值: true
  305. "isCenterHint":false, //未勾选服务条款时点击登录按钮的提示是否居中显示 默认值: false (3.7.13+ 版本支持)
  306. "uncheckedImage":"", // 可选 条款勾选框未选中状态图片(仅支持本地图片 建议尺寸 24x24px)(3.2.0+ 版本支持)
  307. "checkedImage":"", // 可选 条款勾选框选中状态图片(仅支持本地图片 建议尺寸24x24px)(3.2.0+ 版本支持)
  308. "checkBoxSize":18, // 可选 条款勾选框大小
  309. "textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB
  310. "termsColor": "#FF5C03", // 协议文字颜色 默认值: #5496E3
  311. "prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意”
  312. "suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录”
  313. "privacyItems": [ // 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
  314. ]
  315. },
  316. },
  317. success(res){ //
  318. console.log("qxj univerify login:"+JSON.stringify(res.authResult)); // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
  319. loginByUniverify(res.authResult,1);
  320. },
  321. fail(res){
  322. uni.hideLoading();
  323. uni.showToast({title: "一键登录失败请检查网络和SIM卡是否可用",icon: 'none',position:'bottom'});
  324. //setTimeout(function() {
  325. uni.navigateTo({url: "/pages/auth/login"});
  326. //}, 1800);
  327. //}
  328. //登录失败
  329. console.log("qxj failRes:"+JSON.stringify(res));
  330. }
  331. });
  332. // #endif
  333. // #ifdef H5
  334. uni.navigateTo({
  335. url: "/pages/auth/login"
  336. });
  337. // #endif
  338. },
  339. loginByUniverify(authResult,type){
  340. uniCloud.callFunction({
  341. name: 'loginByMobile', // 你的云函数名称
  342. data: {
  343. access_token: authResult.access_token, // 客户端一键登录接口返回的access_token
  344. openid:authResult.openid // 客户端一键登录接口返回的openid
  345. }
  346. }).then(res => {
  347. console.log("qxj doUniverify:",JSON.stringify(res));
  348. if(res.result.errCode==0){
  349. userPhone=res.result.phoneNumber;
  350. this.setPhoneAct(userPhone,unionid);
  351. }else{
  352. uni.showToast({title:res.result.message,icon: 'none' });
  353. }
  354. }).catch(err=>{
  355. // 处理错误
  356. console.error('调用云函数失败:',err);
  357. // 详细记录错误信息
  358. console.error('错误信息:', err.errMsg);
  359. })
  360. },
  361. setPhoneAct(phone,unionId){
  362. let params={phone:phone,unionId:unionId};
  363. setPhone(params).then(res => {
  364. uni.hideLoading();
  365. if(res.code==200){
  366. uni.setStorageSync('AppToken',res.token);
  367. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  368. uni.closeAuthView();
  369. // #ifdef APP-PLUS
  370. // #endif
  371. this.goPage()
  372. }
  373. else{
  374. uni.showToast({title: res.msg,icon: 'none'});
  375. uni.closeAuthView();
  376. }
  377. },
  378. rej => {}
  379. );
  380. },
  381. getRegistrationID(){
  382. this.registrationID=uni.getStorageSync("registrationID");
  383. if(this.registrationID==null || this.registrationID==""){
  384. uni.getPushClientId({success: res => {
  385. uni.setStorageSync("registrationID",res.cid);
  386. this.registrationID = res.cid
  387. }
  388. });
  389. }
  390. },
  391. goBack(){
  392. console.log("qxj goBack");
  393. uni.$emit('showHealthButler');
  394. // this.$navBack();
  395. uni.redirectTo({
  396. url: "/pages/auth/loginIndex"
  397. })
  398. },
  399. handleAgree() { // 同意
  400. this.agree = !this.agree
  401. },
  402. goToWeb(index){
  403. uni.setStorageSync('url',index==0?"https://userapp.his.cdwjyyh.com/web/userAgreement":"https://userapp.his.cdwjyyh.com/web/privacyPolicy");
  404. uni.navigateTo({
  405. url:"/pages/index/h5"
  406. })
  407. },
  408. goPage() {
  409. let pages = getCurrentPages();
  410. let url = pages[ pages.length - 1];
  411. const openUrl = uni.getStorageSync("openUrl")
  412. if(openUrl) {
  413. uni.navigateTo({
  414. url: openUrl,
  415. success: function(res) {
  416. uni.removeStorageSync("openUrl")
  417. }
  418. })
  419. } else {
  420. if(pages.length == 1) {
  421. uni.reLaunch({
  422. url: '../course/index',
  423. //url: '../course/video/living-app',
  424. animationType: 'none',
  425. animationDuration: 2000
  426. })
  427. } else {
  428. this.$navBack();
  429. }
  430. }
  431. this.$updateMsgDot()
  432. this.$setSource()
  433. }
  434. },
  435. }
  436. </script>
  437. <style scoped lang="scss">
  438. page{
  439. background-color: #ffffff;
  440. }
  441. .other-login-btn {
  442. display: flex;
  443. align-items: center;
  444. justify-content: center;
  445. width: 100%;
  446. height: 80rpx;
  447. background: rgba(229, 138, 0, 0.08);
  448. border-radius: 40rpx;
  449. font-size: 30rpx;
  450. font-family: PingFang SC;
  451. font-weight: 500;
  452. color: #FF5C03;
  453. border: 2rpx solid #FF5C03;
  454. margin-top: 30rpx;
  455. &::after {
  456. border: none;
  457. }
  458. }
  459. .content{
  460. display: flex;
  461. flex-direction: column;
  462. align-items: center;
  463. height: calc(100vh);
  464. width: 100%;
  465. position: relative;
  466. // justify-content: space-between;
  467. //padding-top: calc(100% - 32vh);
  468. }
  469. .backImg{
  470. position: absolute;
  471. left:30rpx;
  472. top:40px;
  473. height: 30rpx;
  474. width: 30rpx;
  475. }
  476. .pageTop{
  477. display: flex;
  478. flex-direction: column;
  479. width: 100%;
  480. }
  481. .content .head{
  482. text-align: center;
  483. width: 100%;
  484. height: 100rpx;
  485. // background:url(/static/image/login/top_bg.png) no-repeat 0 center;
  486. background-size: cover;
  487. box-sizing: border-box;
  488. font-size: 36rpx;
  489. font-weight: bold;
  490. color: #666;
  491. }
  492. .content .head image{
  493. width: 150rpx;
  494. height: 150rpx;
  495. border-radius: 10rpx;
  496. box-shadow:0px 0px 20rpx rgba(0,0,0,0.2);
  497. }
  498. .title{
  499. color: #141414;
  500. margin:50upx 0upx 30upx 0rpx;
  501. font-size: 38rpx;
  502. font-weight: 500;
  503. }
  504. .desc{
  505. color: #686866;
  506. padding:0 0 30rpx 0rpx;
  507. font-size: 28rpx;
  508. }
  509. .loginBox{
  510. padding:0 10px 30rpx;
  511. width: calc(100%) ;
  512. background: #FDFDFD;
  513. z-index: 10;
  514. position: relative;
  515. .login-item p{
  516. text-align: left;
  517. }
  518. .line{
  519. height: 0.5rpx;
  520. background-color: #efefef;
  521. margin-top: 10rpx;
  522. }
  523. .input-account{
  524. margin-top: 20rpx;
  525. margin-bottom: 0rpx;
  526. border-radius:40rpx;
  527. border:solid 0rpx #efefef;
  528. height: 80rpx;
  529. width: 100%;
  530. background:url(/static/account.png) no-repeat 0 center;
  531. background-size: 30rpx 30rpx;
  532. background-position: 30rpx;
  533. }
  534. .input-pwd{
  535. margin-top: 40rpx;
  536. margin-bottom: 20rpx;
  537. border-radius:40rpx;
  538. border:solid 0rpx #efefef;
  539. height: 80rpx;
  540. width: 100%;
  541. background:url(/static/password.png) no-repeat 0 center;
  542. background-size: 30rpx 30rpx;
  543. background-position: 30rpx;
  544. }
  545. input{
  546. margin-left: 80rpx;
  547. height: 80rpx;
  548. line-height: 80rpx
  549. }
  550. .reg-box {
  551. padding-bottom:20rpx;
  552. margin:0 10px;
  553. .reg-btn{
  554. font-size:16px ;
  555. color: #FF5C03;
  556. }
  557. }
  558. }
  559. .btns{
  560. margin: 60rpx 0rpx;
  561. }
  562. .login-btn {
  563. display: flex;
  564. align-items: center;
  565. justify-content: center;
  566. width: 100%;
  567. height: 80rpx;
  568. background: linear-gradient(to right, #FF5C03 0%, #FF5C03 100%);
  569. background: -moz-linear-gradient(to right, #FF5C03 0%, #FF5C03 100%);
  570. box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
  571. border-radius: 40rpx;
  572. font-size: 30rpx;
  573. font-family: PingFang SC;
  574. font-weight: 500;
  575. color: rgba(255, 255, 255, 1);
  576. }
  577. .pageBottom{
  578. height: 220rpx;
  579. width: 75%;
  580. display: flex;
  581. flex-direction: column;
  582. position: absolute;
  583. bottom: 100rpx;
  584. }
  585. .tips{
  586. color: #999;
  587. font-size: 32rpx;
  588. }
  589. .menu{
  590. margin-top: 30rpx;
  591. image{
  592. width: 120rpx;
  593. height: 120rpx;
  594. }
  595. }
  596. .checkbox {
  597. margin: 20rpx;
  598. margin-top: 36rpx;
  599. display: flex;
  600. flex-direction:row;
  601. align-items: flex-start;
  602. justify-content: flex-start;
  603. font-family: PingFang SC, PingFang SC;
  604. font-weight: 400;
  605. font-size: 26rpx;
  606. color: #999999;
  607. line-height: 38rpx;
  608. text-align: left;
  609. text {
  610. color:#FF5C03;
  611. }
  612. &-icon {
  613. flex-shrink: 0;
  614. margin-right: 12rpx;
  615. image {
  616. height: 24rpx;
  617. width: 24rpx;
  618. }
  619. }
  620. }
  621. </style>