signin.vue 15 KB

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