signin.vue 17 KB

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