signin.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. <template>
  2. <view>
  3. <view style="color: #000;">
  4. <tn-nav-bar backgroundColor="#fff" :bottomShadow="false" :isBack="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. console.log('登录返回值:', res, res.data.token);
  379. if (res.code == 0) {
  380. uni.setStorageSync('token', res.data.token)
  381. uni.showToast({
  382. title: '登录成功',
  383. icon: 'none'
  384. })
  385. setTimeout(() => {
  386. uni.reLaunch({
  387. url: '/pages/robot/index'
  388. })
  389. }, 1500)
  390. } else {
  391. uni.showToast({
  392. title: res.msg,
  393. icon: 'none'
  394. })
  395. }
  396. }
  397. return
  398. this.$http(this.showlogon ? 'user.login' : 'user.register', this.accountLogin).then(res => {
  399. if (res.code === 0) {
  400. var z = this.showlogon ? '登录成功' : '注册登录成功'
  401. this.$store.dispatch('getUserInfo', this.showlogon ? res.data.user.token : res.data
  402. .token);
  403. uni.showToast({
  404. title: z
  405. })
  406. setTimeout(function() {
  407. // uni.switchTab({
  408. // url:'/pages/user/user'
  409. // })
  410. const value = uni.getStorageSync('route');
  411. // console.log(value);
  412. if (value) {
  413. if (value == '/pages/chat/chat' || value == '/pages/painting/draw' ||
  414. value == '/pages/user/member/member') {
  415. uni.reLaunch({
  416. url: value,
  417. })
  418. uni.removeStorageSync('route');
  419. return;
  420. }
  421. if (value.indexOf('/pages/template/detail') > -1) {
  422. uni.reLaunch({
  423. url: value,
  424. })
  425. uni.removeStorageSync('route');
  426. return;
  427. }
  428. uni.switchTab({
  429. url: value
  430. })
  431. uni.removeStorageSync('route');
  432. } else {
  433. uni.switchTab({
  434. url: '/pages/user/user'
  435. })
  436. }
  437. }, 1000);
  438. } else {
  439. // var z = this.showlogon?'登录失败':'注册登录失败'
  440. // uni.showToast({
  441. // title:z,
  442. // icon:'none'
  443. // })
  444. }
  445. })
  446. },
  447. shgfgh() {
  448. let that = this;
  449. // setTimeout(function(){
  450. uni.showToast({
  451. title: '登录成功'
  452. })
  453. setTimeout(function() {
  454. // uni.navigateBack()
  455. uni.switchTab({
  456. url: '/pages/user/user'
  457. })
  458. }, 1000);
  459. // },2000);
  460. },
  461. agreement(e) {
  462. uni.navigateTo({
  463. url: './public/agreement?type=' + e
  464. })
  465. },
  466. // 绑定手机号
  467. async getphone(e) {
  468. let that = this;
  469. // uni.showLoading({
  470. // title:'绑定中...'
  471. // })
  472. let res = await wechat.getPhoneNumber(e.detail);
  473. // console.log(res)
  474. if (res.code === 0) {
  475. // uni.showToast({
  476. // title:that.cur?'绑定成功':'登录成功',
  477. // duration:1500
  478. // })
  479. // that.whether = true;
  480. // that.$store.commit('userInfo',res.data)
  481. // uni.navigateTo({
  482. // url:'/pages/public/webview?url=https://y.iduomi.cc/api/wechat_login.html'
  483. // })
  484. }
  485. },
  486. }
  487. }
  488. </script>
  489. <style lang="scss">
  490. .signin {
  491. font-weight: 700;
  492. font-size: 20px;
  493. color: #101010;
  494. margin: 45rpx 76rpx 76rpx;
  495. }
  496. .site_logo {
  497. width: 100%;
  498. display: flex;
  499. justify-content: center;
  500. }
  501. .weixin {
  502. width: 160rpx;
  503. height: 160rpx;
  504. border-radius: 50%;
  505. }
  506. .site_name {
  507. width: 100%;
  508. display: flex;
  509. justify-content: center;
  510. font-size: 36rpx;
  511. margin-top: 30rpx;
  512. font-weight: bold;
  513. }
  514. .detailed {
  515. color: #999;
  516. font-size: 28rpx;
  517. margin-top: 80rpx;
  518. width: 100%;
  519. display: flex;
  520. justify-content: center;
  521. flex-direction: column;
  522. align-items: center;
  523. }
  524. .grant {
  525. background: linear-gradient(to right, #00ca88, #00BCD4);
  526. border: 1px solid #199063;
  527. width: 80%;
  528. height: 42px;
  529. border-radius: 50rpx;
  530. font-size: 28rpx;
  531. color: #fff;
  532. display: flex;
  533. align-items: center;
  534. justify-content: center;
  535. font-weight: bold;
  536. margin-top: 180rpx;
  537. position: relative;
  538. .dlu {
  539. padding-left: 12rpx;
  540. }
  541. .button {
  542. position: absolute;
  543. width: 100%;
  544. height: 80rpx;
  545. opacity: 0;
  546. }
  547. }
  548. .toregister {
  549. font-size: 26rpx;
  550. margin-top: 16rpx;
  551. color: #c7c7cc;
  552. }
  553. .grants {
  554. // background:linear-gradient(to right,#199063,#26C47D);
  555. border: 1px solid #199063;
  556. // background: #fff;
  557. width: 80%;
  558. height: 42px;
  559. border-radius: 50rpx;
  560. font-size: 28rpx;
  561. color: #199063;
  562. display: flex;
  563. align-items: center;
  564. justify-content: center;
  565. font-weight: bold;
  566. margin-top: 38rpx;
  567. position: relative;
  568. .dlu {
  569. padding-left: 12rpx;
  570. }
  571. .button {
  572. position: absolute;
  573. width: 100%;
  574. height: 80rpx;
  575. opacity: 0;
  576. }
  577. }
  578. .clause {
  579. display: flex;
  580. justify-content: center;
  581. font-size: 26rpx;
  582. color: #c7c7cc;
  583. margin-left: 12rpx;
  584. }
  585. .getbutton {
  586. position: absolute;
  587. width: 100%;
  588. height: 80rpx;
  589. opacity: 0;
  590. margin-top: 180rpx;
  591. }
  592. .container {
  593. margin-top: 60rpx;
  594. .bg {
  595. display: flex;
  596. align-items: center;
  597. justify-content: center;
  598. position: relative;
  599. height: 400rpx;
  600. margin-bottom: 80rpx;
  601. }
  602. .topimg {
  603. image {
  604. width: 180rpx;
  605. height: 180rpx;
  606. border-radius: 50%;
  607. }
  608. }
  609. .textl_ogin {
  610. font-size: 40rpx;
  611. margin: 0 60rpx 50rpx;
  612. font-weight: bold;
  613. }
  614. .login {
  615. margin-bottom: 80rpx;
  616. }
  617. .signinnow {
  618. background: #26C47D;
  619. font-size: 34rpx;
  620. color: #fff;
  621. margin: 0 60rpx 40rpx;
  622. text-align: center;
  623. line-height: 90rpx;
  624. height: 90rpx;
  625. border-radius: 16rpx;
  626. font-weight: bold;
  627. }
  628. .input {
  629. // width: 630rpx;
  630. height: 100rpx;
  631. padding: 0 30rpx;
  632. background: #f7f7f7;
  633. border-radius: 16rpx;
  634. flex-direction: row;
  635. // margin-left: 60rpx;
  636. // margin-bottom: 40rpx;
  637. margin: 0 60rpx 40rpx;
  638. font-style: normal;
  639. font-size: 30rpx;
  640. font-family: Droid Sans Fallback;
  641. &-icon {
  642. width: 30rpx;
  643. height: 38rpx;
  644. }
  645. }
  646. .hoversubmit {
  647. background: #F7F7F7;
  648. color: #ACACB3;
  649. }
  650. .vs-flex-item {
  651. flex: 1;
  652. margin-left: 16rpx;
  653. }
  654. }
  655. </style>