signin.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. <template>
  2. <view>
  3. <view style="color: #000;">
  4. <tn-nav-bar backgroundColor="#fff" :bottomShadow="false">登录</tn-nav-bar>
  5. <view :style="{height: tobheight+'px'}"></view>
  6. </view>
  7. <block>
  8. <view class="signin">
  9. <!-- 注册账户 -->
  10. </view>
  11. <view class="site_logo">
  12. <image class="weixin" :src="appInfo.site_logo_path" mode="aspectFill"></image>
  13. </view>
  14. <view class="site_name">{{appInfo.site_name}}</view>
  15. <view class="detailed">
  16. <view class="">欢迎畅游{{appInfo.site_name}}</view>
  17. <view class="">登录后,可免费获得问答及优惠套餐等服务</view>
  18. </view>
  19. <u-popup :show="showlogin" mode="bottom" :round="10" closeable @close="showlogin = false">
  20. <view class="container">
  21. <view class="textl_ogin">{{showlogon?'账号密码登录':'账号密码注册'}}</view>
  22. <!-- 账号密码登录 -->
  23. <view class="login">
  24. <view class="input u-flex align-center">
  25. <u-icon name="account-fill" color="#26B3A0" size="24"></u-icon>
  26. <input class="vs-flex-item" v-model="accountLogin.account" :maxlength="11"
  27. placeholder="请输入账号" />
  28. </view>
  29. <view class="input u-flex align-center">
  30. <u-icon name="lock-fill" color="#26B3A0" size="24"></u-icon>
  31. <input class="vs-flex-item" type="text" :password="password" v-model="accountLogin.password"
  32. placeholder="请输入登录密码" placeholder-class="input-placeholder" />
  33. <u-icon @click="password = !password" :name="password ? 'eye-off' : 'eye-fill'"
  34. color="#26B3A0" size="18"></u-icon>
  35. </view>
  36. <!-- <view v-if="!showlogon" class="input u-flex align-center">
  37. <u-icon name="lock-fill" color="#26B3A0" size="24"></u-icon>
  38. <input class="vs-flex-item" type="text" :password="twopassword" v-model="password2"
  39. placeholder="请再次确认登录密码" placeholder-class="input-placeholder" />
  40. <u-icon @click="twopassword = !twopassword" :name="twopassword ? 'eye-off' : 'eye-fill'"
  41. color="#26B3A0" size="18"></u-icon>
  42. </view> -->
  43. </view>
  44. <view @click="getlogin()" hover-class="hoversubmit" class="signinnow">{{showlogon?'立即登录':'立即注册'}}
  45. </view>
  46. </view>
  47. </u-popup>
  48. <!-- #ifdef MP-WEIXIN -->
  49. <view class="flxe justify-center">
  50. <view class="grant" @click="showAuthorizationModal = true">
  51. <u-icon name="weixin-fill" color="#ffffff" size="26"></u-icon>
  52. <view class="dlu">微信授权登录</view>
  53. </view>
  54. <!-- <button class="getbutton" open-type="getPhoneNumber" @getphonenumber="getphone"></button> -->
  55. </view>
  56. <!-- #endif -->
  57. <!-- #ifdef H5 -->
  58. <block v-if="appInfo.h5_run_mode">
  59. <block v-if="appInfo.h5_run_mode == 1">
  60. <view v-if="platform == 'wxOfficialAccount'" class="flxe justify-center">
  61. <view class="grant" @click="thirdLogin('wechat')">
  62. <u-icon name="weixin-fill" color="#ffffff" size="26"></u-icon>
  63. <view class="dlu">微信授权登录</view>
  64. </view>
  65. </view>
  66. <view v-if="appInfo.is_account&&appInfo.is_account==1" class="flxe justify-center">
  67. <view class="grants" @click="showlogon = true,showlogin = true">
  68. <u-icon name="account-fill" color="#199063" size="26"></u-icon>
  69. <view class="dlu">账号密码登录</view>
  70. </view>
  71. </view>
  72. <view v-if="appInfo.is_account&&appInfo.is_account==1" @click="showlogon = false,showlogin = true"
  73. class="toregister flxe justify-center">未注册账号?点击去注册></view>
  74. </block>
  75. <block v-if="appInfo.h5_run_mode == 2">
  76. <view class="flxe justify-center">
  77. <view class="grants" @click="showlogon = true,showlogin = true">
  78. <u-icon name="account-fill" color="#199063" size="26"></u-icon>
  79. <view class="dlu">账号密码登录</view>
  80. </view>
  81. </view>
  82. <view @click="showlogon = false,showlogin = true" class="toregister flxe justify-center">
  83. 未注册账号?点击去注册></view>
  84. </block>
  85. <block v-if="appInfo.h5_run_mode == 3">
  86. <view v-if="platform == 'wxOfficialAccount'" class="flxe justify-center">
  87. <view class="grant" @click="thirdLogin('wechat')">
  88. <u-icon name="weixin-fill" color="#ffffff" size="26"></u-icon>
  89. <view class="dlu">微信授权登录</view>
  90. </view>
  91. </view>
  92. <block v-if="platform == 'H5'">
  93. <view class="flxe justify-center">
  94. <view class="grants" @click="showlogon = true,showlogin = true">
  95. <u-icon name="account-fill" color="#199063" size="26"></u-icon>
  96. <view class="dlu">账号密码登录</view>
  97. </view>
  98. </view>
  99. <view @click="showlogon = false,showlogin = true" class="toregister flxe justify-center">
  100. 未注册账号?点击去注册></view>
  101. </block>
  102. </block>
  103. </block>
  104. <block v-else>
  105. <view v-if="platform == 'wxOfficialAccount'" class="flxe justify-center">
  106. <view class="grant" @click="thirdLogin('wechat')">
  107. <u-icon name="weixin-fill" color="#ffffff" size="26"></u-icon>
  108. <view class="dlu">微信授权登录</view>
  109. </view>
  110. </view>
  111. <block v-if="platform == 'H5'">
  112. <view class="flxe justify-center">
  113. <view class="grants" @click="showlogon = true,showlogin = true">
  114. <u-icon name="account-fill" color="#199063" size="26"></u-icon>
  115. <view class="dlu">账号密码登录</view>
  116. </view>
  117. </view>
  118. <view @click="showlogon = false,showlogin = true" class="toregister flxe justify-center">
  119. 未注册账号?点击去注册></view>
  120. </block>
  121. </block>
  122. <!-- #endif -->
  123. <!-- <view class="">{{appInfo.h5_run_mode}}</view> -->
  124. <view @tap="agree = true" class="flxe align-center justify-center" style="margin-top: 50rpx;">
  125. <u-icon name="checkmark-circle-fill" :color="agree?'#07C160':'#ededed'" size="16"></u-icon>
  126. <view class="clause">我已阅读并同意:<view @tap.stop="agreement('privacy')" style="color: #34c758;">《隐私政策》
  127. </view>和<view @tap.stop="agreement('use')" style="color: #34c758;">《使用协议》</view>
  128. </view>
  129. </view>
  130. </block>
  131. <wike-loading-page :isLoading="isLoading"></wike-loading-page>
  132. <tnui-wx-user-info v-model="showAuthorizationModal" @updated="updatedUserInfoEvent"></tnui-wx-user-info>
  133. </view>
  134. </template>
  135. <script>
  136. import {
  137. mapMutations,
  138. mapActions,
  139. mapState,
  140. mapGetters
  141. } from 'vuex';
  142. import wechat from '@/common/wechat/wechat';
  143. import TnuiWxUserInfo from '@/components/tnui-wx-user-info/tnui-wx-user-info';
  144. import {
  145. register,
  146. login
  147. } from '@/api/robot/index.js'
  148. export default {
  149. components: {
  150. TnuiWxUserInfo
  151. },
  152. data() {
  153. return {
  154. agree: true,
  155. showAuthorizationModal: false,
  156. tobheight: 45,
  157. platform: this.$platform.get(),
  158. h5_runmode: ['wxOfficialAccount', 'H5'],
  159. isLoading: true,
  160. showlogin: false,
  161. password: true,
  162. twopassword: true,
  163. accountLogin: {
  164. account: '',
  165. password: '',
  166. },
  167. password2: '',
  168. showlogon: true,
  169. route: ''
  170. // register:0
  171. }
  172. },
  173. computed: {
  174. ...mapGetters(['appInfo', 'userInfo', 'isLogin'])
  175. },
  176. onLoad(option) {
  177. // console.log(option);
  178. const that = this;
  179. that.isLoading = false
  180. if (that.platform == 'wxMiniProgram') {
  181. var menumtop = uni.getMenuButtonBoundingClientRect().top - uni.getSystemInfoSync().statusBarHeight
  182. var paddingtop = uni.getSystemInfoSync().statusBarHeight + menumtop
  183. that.tobheight = (menumtop + paddingtop + uni.getMenuButtonBoundingClientRect().height)
  184. }
  185. console.log(that.appInfo.h5_run_mode, that.platform);
  186. // #ifdef H5
  187. const {
  188. code,
  189. state,
  190. scope
  191. } = option;
  192. that.option = option;
  193. if (code && scope !== 'snsapi_base') {
  194. that.$http('wechat.wechatAuth', {
  195. code: option.code
  196. }, ).then(res => {
  197. // console.log(res);
  198. if (res.code == 0) {
  199. uni.setNavigationBarTitle({
  200. title: that.appInfo.site_name
  201. });
  202. that.$store.dispatch('getUserInfo', res.data.token);
  203. // if(!res.data.phone){
  204. // that.showAuthorizationModal = true;
  205. // }else{
  206. uni.showToast({
  207. title: '登录成功'
  208. })
  209. setTimeout(function() {
  210. const value = uni.getStorageSync('route');
  211. // console.log(value);
  212. if (value) {
  213. if (value == '/pages/chat/chat' || value == '/pages/template/detail' ||
  214. value == '/pages/painting/draw') {
  215. uni.reLaunch({
  216. url: value,
  217. })
  218. uni.removeStorageSync('route');
  219. return;
  220. }
  221. uni.switchTab({
  222. url: value
  223. })
  224. uni.removeStorageSync('route');
  225. } else {
  226. uni.switchTab({
  227. url: '/pages/user/user'
  228. })
  229. }
  230. }, 1000);
  231. // }
  232. }
  233. });
  234. }
  235. // #endif
  236. },
  237. methods: {
  238. ...mapActions(['getUserInfo']),
  239. async thirdLogin(provider) {
  240. if (!this.agree) {
  241. this.$u.toast('请同意用户协议');
  242. return false;
  243. }
  244. // console.log(provider)
  245. const that = this;
  246. let user = '';
  247. // uni.showLoading({
  248. // title:'登录中...'
  249. // })
  250. switch (provider) {
  251. case 'wechat':
  252. user = await wechat.login();
  253. break;
  254. default:
  255. break;
  256. }
  257. // #ifdef MP-WEIXIN
  258. if (user) {
  259. // that.avatarUrl = user.avatarUrl;
  260. // that.nickName = user.nickName;
  261. // that.closeAuthModal();
  262. that.getUserInfo();
  263. }
  264. if (user.errMsg == 'getUserProfile:fail auth deny') {
  265. // this.mobilelogin = false;
  266. uni.showToast({
  267. title: '已取消登录',
  268. icon: 'none'
  269. })
  270. } else {
  271. that.shgfgh()
  272. }
  273. // #endif
  274. },
  275. // memberadd_coin(){
  276. // this.$http('member.add_coin',{type:'register'}).then(res=>{
  277. // if (res.code === 0) {
  278. // that.shgfgh()
  279. // }
  280. // })
  281. // },
  282. updatedUserInfoEvent(e) {
  283. // console.log(e);
  284. // uni.showToast({
  285. // title:'已取消登录',
  286. // icon:'none'
  287. // })
  288. // uni.navigateBack({
  289. // })
  290. },
  291. async getlogin() {
  292. if (!this.accountLogin.account) {
  293. uni.showToast({
  294. title: '请输入账号',
  295. icon: 'none'
  296. })
  297. return;
  298. }
  299. if (!uni.$u.test.rangeLength(this.accountLogin.account, [4, 16])) {
  300. uni.showToast({
  301. title: '账号不能低于4位和高于16位',
  302. icon: 'none'
  303. })
  304. return;
  305. }
  306. if (!this.accountLogin.password) {
  307. uni.showToast({
  308. title: '请输入密码',
  309. icon: 'none'
  310. })
  311. return;
  312. }
  313. if (!uni.$u.test.rangeLength(this.accountLogin.password, [4, 16])) {
  314. uni.showToast({
  315. title: '密码不能低于4位和高于16位',
  316. icon: 'none'
  317. })
  318. return;
  319. }
  320. if (/.*[\u4e00-\u9fa5]+.*$/.test(this.accountLogin.password)) {
  321. uni.showToast({
  322. title: '密码不能含有汉字',
  323. icon: 'none'
  324. })
  325. return;
  326. }
  327. // if (!this.showlogon && !this.password2) {
  328. // uni.showToast({
  329. // title: '请再次确认密码',
  330. // icon: 'none'
  331. // })
  332. // return;
  333. // }
  334. if (!uni.$u.test.enOrNum(this.accountLogin.password) || !uni.$u.test.enOrNum(this.password2)) {
  335. uni.showToast({
  336. title: '密码只能是字母和数字',
  337. icon: 'none'
  338. })
  339. return;
  340. }
  341. // if (!this.showlogon && this.accountLogin.password != this.password2) {
  342. // uni.showToast({
  343. // title: '两次密码不相同,请重新确认',
  344. // icon: 'none'
  345. // })
  346. // return;
  347. // }
  348. // 新登录接口
  349. if (!this.showlogon) {
  350. let res = await register({
  351. account: this.accountLogin.account,
  352. password: this.accountLogin.password
  353. })
  354. console.log('注册参数:', {
  355. account: this.accountLogin.account,
  356. password: this.accountLogin.password
  357. });
  358. console.log('注册返回值:', res);
  359. if (res.code == 0) {
  360. this.showlogon = true
  361. } else {
  362. uni.showToast({
  363. title: res.msg,
  364. icon: 'none'
  365. })
  366. }
  367. } else {
  368. let res = await login({
  369. account: this.accountLogin.account,
  370. password: this.accountLogin.password
  371. })
  372. console.log('登录参数:', {
  373. account: this.accountLogin.account,
  374. password: this.accountLogin.password
  375. });
  376. if (res.code == 0) {
  377. uni.setStorageSync('token', res.data.token)
  378. uni.showToast({
  379. title: '登录成功',
  380. icon: 'none'
  381. })
  382. setTimeout(() => {
  383. uni.reLaunch({
  384. url: '/pages/robot/index'
  385. })
  386. }, 1500)
  387. console.log('登录返回值:', res, res.data.token);
  388. }
  389. }
  390. return
  391. this.$http(this.showlogon ? 'user.login' : 'user.register', this.accountLogin).then(res => {
  392. if (res.code === 0) {
  393. var z = this.showlogon ? '登录成功' : '注册登录成功'
  394. this.$store.dispatch('getUserInfo', this.showlogon ? res.data.user.token : res.data
  395. .token);
  396. uni.showToast({
  397. title: z
  398. })
  399. setTimeout(function() {
  400. // uni.switchTab({
  401. // url:'/pages/user/user'
  402. // })
  403. const value = uni.getStorageSync('route');
  404. // console.log(value);
  405. if (value) {
  406. if (value == '/pages/chat/chat' || value == '/pages/painting/draw' ||
  407. value == '/pages/user/member/member') {
  408. uni.reLaunch({
  409. url: value,
  410. })
  411. uni.removeStorageSync('route');
  412. return;
  413. }
  414. if (value.indexOf('/pages/template/detail') > -1) {
  415. uni.reLaunch({
  416. url: value,
  417. })
  418. uni.removeStorageSync('route');
  419. return;
  420. }
  421. uni.switchTab({
  422. url: value
  423. })
  424. uni.removeStorageSync('route');
  425. } else {
  426. uni.switchTab({
  427. url: '/pages/user/user'
  428. })
  429. }
  430. }, 1000);
  431. } else {
  432. // var z = this.showlogon?'登录失败':'注册登录失败'
  433. // uni.showToast({
  434. // title:z,
  435. // icon:'none'
  436. // })
  437. }
  438. })
  439. },
  440. shgfgh() {
  441. let that = this;
  442. // setTimeout(function(){
  443. uni.showToast({
  444. title: '登录成功'
  445. })
  446. setTimeout(function() {
  447. // uni.navigateBack()
  448. uni.switchTab({
  449. url: '/pages/user/user'
  450. })
  451. }, 1000);
  452. // },2000);
  453. },
  454. agreement(e) {
  455. uni.navigateTo({
  456. url: './public/agreement?type=' + e
  457. })
  458. },
  459. // 绑定手机号
  460. async getphone(e) {
  461. let that = this;
  462. // uni.showLoading({
  463. // title:'绑定中...'
  464. // })
  465. let res = await wechat.getPhoneNumber(e.detail);
  466. // console.log(res)
  467. if (res.code === 0) {
  468. // uni.showToast({
  469. // title:that.cur?'绑定成功':'登录成功',
  470. // duration:1500
  471. // })
  472. // that.whether = true;
  473. // that.$store.commit('userInfo',res.data)
  474. // uni.navigateTo({
  475. // url:'/pages/public/webview?url=https://y.iduomi.cc/api/wechat_login.html'
  476. // })
  477. }
  478. },
  479. }
  480. }
  481. </script>
  482. <style lang="scss">
  483. .signin {
  484. font-weight: 700;
  485. font-size: 20px;
  486. color: #101010;
  487. margin: 45rpx 76rpx 76rpx;
  488. }
  489. .site_logo {
  490. width: 100%;
  491. display: flex;
  492. justify-content: center;
  493. }
  494. .weixin {
  495. width: 160rpx;
  496. height: 160rpx;
  497. border-radius: 50%;
  498. }
  499. .site_name {
  500. width: 100%;
  501. display: flex;
  502. justify-content: center;
  503. font-size: 36rpx;
  504. margin-top: 30rpx;
  505. font-weight: bold;
  506. }
  507. .detailed {
  508. color: #999;
  509. font-size: 28rpx;
  510. margin-top: 80rpx;
  511. width: 100%;
  512. display: flex;
  513. justify-content: center;
  514. flex-direction: column;
  515. align-items: center;
  516. }
  517. .grant {
  518. background: linear-gradient(to right, #00ca88, #00BCD4);
  519. border: 1px solid #199063;
  520. width: 80%;
  521. height: 42px;
  522. border-radius: 50rpx;
  523. font-size: 28rpx;
  524. color: #fff;
  525. display: flex;
  526. align-items: center;
  527. justify-content: center;
  528. font-weight: bold;
  529. margin-top: 180rpx;
  530. position: relative;
  531. .dlu {
  532. padding-left: 12rpx;
  533. }
  534. .button {
  535. position: absolute;
  536. width: 100%;
  537. height: 80rpx;
  538. opacity: 0;
  539. }
  540. }
  541. .toregister {
  542. font-size: 26rpx;
  543. margin-top: 16rpx;
  544. color: #c7c7cc;
  545. }
  546. .grants {
  547. // background:linear-gradient(to right,#199063,#26C47D);
  548. border: 1px solid #199063;
  549. // background: #fff;
  550. width: 80%;
  551. height: 42px;
  552. border-radius: 50rpx;
  553. font-size: 28rpx;
  554. color: #199063;
  555. display: flex;
  556. align-items: center;
  557. justify-content: center;
  558. font-weight: bold;
  559. margin-top: 38rpx;
  560. position: relative;
  561. .dlu {
  562. padding-left: 12rpx;
  563. }
  564. .button {
  565. position: absolute;
  566. width: 100%;
  567. height: 80rpx;
  568. opacity: 0;
  569. }
  570. }
  571. .clause {
  572. display: flex;
  573. justify-content: center;
  574. font-size: 26rpx;
  575. color: #c7c7cc;
  576. margin-left: 12rpx;
  577. }
  578. .getbutton {
  579. position: absolute;
  580. width: 100%;
  581. height: 80rpx;
  582. opacity: 0;
  583. margin-top: 180rpx;
  584. }
  585. .container {
  586. margin-top: 60rpx;
  587. .bg {
  588. display: flex;
  589. align-items: center;
  590. justify-content: center;
  591. position: relative;
  592. height: 400rpx;
  593. margin-bottom: 80rpx;
  594. }
  595. .topimg {
  596. image {
  597. width: 180rpx;
  598. height: 180rpx;
  599. border-radius: 50%;
  600. }
  601. }
  602. .textl_ogin {
  603. font-size: 40rpx;
  604. margin: 0 60rpx 50rpx;
  605. font-weight: bold;
  606. }
  607. .login {
  608. margin-bottom: 80rpx;
  609. }
  610. .signinnow {
  611. background: #26C47D;
  612. font-size: 34rpx;
  613. color: #fff;
  614. margin: 0 60rpx 40rpx;
  615. text-align: center;
  616. line-height: 90rpx;
  617. height: 90rpx;
  618. border-radius: 16rpx;
  619. font-weight: bold;
  620. }
  621. .input {
  622. // width: 630rpx;
  623. height: 100rpx;
  624. padding: 0 30rpx;
  625. background: #f7f7f7;
  626. border-radius: 16rpx;
  627. flex-direction: row;
  628. // margin-left: 60rpx;
  629. // margin-bottom: 40rpx;
  630. margin: 0 60rpx 40rpx;
  631. font-style: normal;
  632. font-size: 30rpx;
  633. font-family: Droid Sans Fallback;
  634. &-icon {
  635. width: 30rpx;
  636. height: 38rpx;
  637. }
  638. }
  639. .hoversubmit {
  640. background: #F7F7F7;
  641. color: #ACACB3;
  642. }
  643. .vs-flex-item {
  644. flex: 1;
  645. margin-left: 16rpx;
  646. }
  647. }
  648. </style>