signin.vue 15 KB

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