signin.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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. <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.showToast({
  324. title: '登录成功',
  325. icon: 'none'
  326. })
  327. setTimeout(() => {
  328. uni.reLaunch({
  329. url: '/pages/robot/index'
  330. })
  331. }, 1500)
  332. } else {
  333. uni.showToast({
  334. title: res.msg,
  335. icon: 'none'
  336. })
  337. }
  338. }
  339. return
  340. this.$http(this.showlogon ? 'user.login' : 'user.register', this.accountLogin).then(res => {
  341. if (res.code === 0) {
  342. // console.log('登录注册返回值:', res);
  343. var z = this.showlogon ? '登录成功' : '注册登录成功'
  344. this.$store.dispatch('getUserInfo', this.showlogon ? res.data.user.token : res.data
  345. .token);
  346. uni.showToast({
  347. title: z
  348. })
  349. setTimeout(function() {
  350. // uni.switchTab({
  351. // url:'/pages/user/user'
  352. // })
  353. const value = uni.getStorageSync('route');
  354. // console.log(value);
  355. if (value) {
  356. if (value == '/pages/chat/chat' || value == '/pages/painting/draw' ||
  357. value == '/pages/user/member/member') {
  358. uni.reLaunch({
  359. url: value,
  360. })
  361. uni.removeStorageSync('route');
  362. return;
  363. }
  364. if (value.indexOf('/pages/template/detail') > -1) {
  365. uni.reLaunch({
  366. url: value,
  367. })
  368. uni.removeStorageSync('route');
  369. return;
  370. }
  371. uni.switchTab({
  372. url: value
  373. })
  374. uni.removeStorageSync('route');
  375. } else {
  376. uni.switchTab({
  377. url: '/pages/user/user'
  378. })
  379. }
  380. }, 1000);
  381. } else {
  382. // var z = this.showlogon?'登录失败':'注册登录失败'
  383. // uni.showToast({
  384. // title:z,
  385. // icon:'none'
  386. // })
  387. }
  388. })
  389. },
  390. shgfgh() {
  391. let that = this;
  392. // setTimeout(function(){
  393. uni.showToast({
  394. title: '登录成功'
  395. })
  396. setTimeout(function() {
  397. // uni.navigateBack()
  398. uni.switchTab({
  399. url: '/pages/user/user'
  400. })
  401. }, 1000);
  402. // },2000);
  403. },
  404. agreement(e) {
  405. uni.navigateTo({
  406. url: './public/agreement?type=' + e
  407. })
  408. },
  409. // 绑定手机号
  410. async getphone(e) {
  411. let that = this;
  412. // uni.showLoading({
  413. // title:'绑定中...'
  414. // })
  415. let res = await wechat.getPhoneNumber(e.detail);
  416. // console.log(res)
  417. if (res.code === 0) {
  418. // uni.showToast({
  419. // title:that.cur?'绑定成功':'登录成功',
  420. // duration:1500
  421. // })
  422. // that.whether = true;
  423. // that.$store.commit('userInfo',res.data)
  424. // uni.navigateTo({
  425. // url:'/pages/public/webview?url=https://y.iduomi.cc/api/wechat_login.html'
  426. // })
  427. }
  428. },
  429. }
  430. }
  431. </script>
  432. <style lang="scss">
  433. .signin {
  434. font-weight: 700;
  435. font-size: 20px;
  436. color: #101010;
  437. margin: 45rpx 76rpx 76rpx;
  438. }
  439. .site_logo {
  440. width: 100%;
  441. display: flex;
  442. justify-content: center;
  443. }
  444. .weixin {
  445. width: 160rpx;
  446. height: 160rpx;
  447. border-radius: 50%;
  448. }
  449. .site_name {
  450. width: 100%;
  451. display: flex;
  452. justify-content: center;
  453. font-size: 36rpx;
  454. margin-top: 30rpx;
  455. font-weight: bold;
  456. }
  457. .detailed {
  458. color: #999;
  459. font-size: 28rpx;
  460. margin-top: 80rpx;
  461. width: 100%;
  462. display: flex;
  463. justify-content: center;
  464. flex-direction: column;
  465. align-items: center;
  466. }
  467. .grant {
  468. background: linear-gradient(to right, #00ca88, #00BCD4);
  469. border: 1px solid #199063;
  470. width: 80%;
  471. height: 42px;
  472. border-radius: 50rpx;
  473. font-size: 28rpx;
  474. color: #fff;
  475. display: flex;
  476. align-items: center;
  477. justify-content: center;
  478. font-weight: bold;
  479. margin-top: 180rpx;
  480. position: relative;
  481. .dlu {
  482. padding-left: 12rpx;
  483. }
  484. .button {
  485. position: absolute;
  486. width: 100%;
  487. height: 80rpx;
  488. opacity: 0;
  489. }
  490. }
  491. .toregister {
  492. font-size: 26rpx;
  493. margin-top: 16rpx;
  494. color: #c7c7cc;
  495. }
  496. .grants {
  497. // background:linear-gradient(to right,#199063,#26C47D);
  498. border: 1px solid #199063;
  499. // background: #fff;
  500. width: 80%;
  501. height: 42px;
  502. border-radius: 50rpx;
  503. font-size: 28rpx;
  504. color: #199063;
  505. display: flex;
  506. align-items: center;
  507. justify-content: center;
  508. font-weight: bold;
  509. margin-top: 38rpx;
  510. position: relative;
  511. .dlu {
  512. padding-left: 12rpx;
  513. }
  514. .button {
  515. position: absolute;
  516. width: 100%;
  517. height: 80rpx;
  518. opacity: 0;
  519. }
  520. }
  521. .clause {
  522. display: flex;
  523. justify-content: center;
  524. font-size: 26rpx;
  525. color: #c7c7cc;
  526. margin-left: 12rpx;
  527. }
  528. .getbutton {
  529. position: absolute;
  530. width: 100%;
  531. height: 80rpx;
  532. opacity: 0;
  533. margin-top: 180rpx;
  534. }
  535. .container {
  536. margin-top: 60rpx;
  537. .bg {
  538. display: flex;
  539. align-items: center;
  540. justify-content: center;
  541. position: relative;
  542. height: 400rpx;
  543. margin-bottom: 80rpx;
  544. }
  545. .topimg {
  546. image {
  547. width: 180rpx;
  548. height: 180rpx;
  549. border-radius: 50%;
  550. }
  551. }
  552. .textl_ogin {
  553. font-size: 40rpx;
  554. margin: 0 60rpx 50rpx;
  555. font-weight: bold;
  556. }
  557. .login {
  558. margin-bottom: 80rpx;
  559. }
  560. .signinnow {
  561. background: #26C47D;
  562. font-size: 34rpx;
  563. color: #fff;
  564. margin: 0 60rpx 40rpx;
  565. text-align: center;
  566. line-height: 90rpx;
  567. height: 90rpx;
  568. border-radius: 16rpx;
  569. font-weight: bold;
  570. }
  571. .input {
  572. // width: 630rpx;
  573. height: 100rpx;
  574. padding: 0 30rpx;
  575. background: #f7f7f7;
  576. border-radius: 16rpx;
  577. flex-direction: row;
  578. // margin-left: 60rpx;
  579. // margin-bottom: 40rpx;
  580. margin: 0 60rpx 40rpx;
  581. font-style: normal;
  582. font-size: 30rpx;
  583. font-family: Droid Sans Fallback;
  584. &-icon {
  585. width: 30rpx;
  586. height: 38rpx;
  587. }
  588. }
  589. .hoversubmit {
  590. background: #F7F7F7;
  591. color: #ACACB3;
  592. }
  593. .vs-flex-item {
  594. flex: 1;
  595. margin-left: 16rpx;
  596. }
  597. }
  598. </style>