signin.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. <template>
  2. <view class="outerCon">
  3. <view class="mobile">
  4. <view style="padding: 30rpx; padding-top: 24rpx;padding-bottom: 200rpx;">
  5. <view class="topTxtAndImg">
  6. <view class="swiper">
  7. <swiper class="banner" circular :autoplay="false"
  8. :style="{width:isPc?'600rpx':'680rpx',height:isPc?'auto':'450rpx'}">
  9. <!-- <swiper class="banner" circular :autoplay="false"> -->
  10. <swiper-item v-for="i in bannerList">
  11. <image :src="i.picture" mode=""></image>
  12. </swiper-item>
  13. </swiper>
  14. </view>
  15. <view class="txt">
  16. <u-parse :content="companyDes"></u-parse>
  17. </view>
  18. </view>
  19. <block>
  20. <view class="site_name">{{appInfo.site_name}}</view>
  21. <view class="detailed">
  22. <view class="">欢迎立即加入我们!</view>
  23. </view>
  24. <u-popup :show="showlogin" mode="bottom" :round="10" closeable @close="showlogin = false">
  25. <view class="container">
  26. <view class="textl_ogin">{{showlogon?'账号密码登录':'账号密码注册'}}</view>
  27. <view class="login">
  28. <view class="input u-flex align-center">
  29. <u-icon name="phone-fill" color="#26B3A0" size="24"></u-icon>
  30. <input class="vs-flex-item" v-model="accountLogin.mobile" :maxlength="11"
  31. placeholder="请输入手机号" />
  32. </view>
  33. <view v-if="!showlogon" class="input u-flex align-center">
  34. <u-icon name="account-fill" color="#26B3A0" size="24"></u-icon>
  35. <input class="vs-flex-item" v-model="accountLogin.code" :maxlength="11"
  36. placeholder="验证码" />
  37. <view class="" style="width: 250rpx;">
  38. <u-button style="width: 250rpx;" color='#26B3A0' class="custom-style"
  39. @tap="getCode">{{tips}}</u-button>
  40. </view>
  41. </view>
  42. <view class="input u-flex align-center">
  43. <u-icon name="lock-fill" color="#26B3A0" size="24"></u-icon>
  44. <input class="vs-flex-item" type="text" :password="password"
  45. v-model="accountLogin.password" placeholder="请输入密码"
  46. placeholder-class="input-placeholder" />
  47. <u-icon @click="password = !password" :name="password ? 'eye-off' : 'eye-fill'"
  48. color="#26B3A0" size="18"></u-icon>
  49. </view>
  50. <view class="forgetPwd" @click="forgetPwd" v-if="showlogon">
  51. 忘记密码
  52. </view>
  53. <view v-if="!showlogon" class="input u-flex align-center">
  54. <u-icon name="account-fill" color="#26B3A0" size="24"></u-icon>
  55. <input class="vs-flex-item" v-model="accountLogin.invite_code" :maxlength="11"
  56. placeholder="请输入邀请码" />
  57. </view>
  58. <view @tap="agree = !agree" class="flxe align-center justify-center"
  59. style="margin-top: 50rpx;">
  60. <u-icon name="checkmark-circle-fill" :color="agree?'#07C160':'#ededed'"
  61. size="16"></u-icon>
  62. <view class="clause">我已阅读并同意:<view @tap.stop="agreement('privacy')"
  63. style="color: #34c758;">
  64. 《隐私政策》
  65. </view>和<view @tap.stop="agreement('use')" style="color: #34c758;">《用户协议》</view>
  66. </view>
  67. </view>
  68. </view>
  69. <view @click="getlogin()" hover-class="hoversubmit" class="signinnow">
  70. {{showlogon?'立即登录':'立即注册'}}
  71. </view>
  72. </view>
  73. <view class="wrap">
  74. <u-toast ref="uToast"></u-toast>
  75. <u-code :seconds="seconds" @end="" @start="" ref="uCode" @change="codeChange"></u-code>
  76. </view>
  77. </u-popup>
  78. <block v-if="platform == 'wxOfficialAccount'&&showWX">
  79. <!-- <block v-if="false"> -->
  80. <view class="wxBox">
  81. <view class="">
  82. <view class="grant wxBtn" @click="thirdLogin('wechat')"
  83. style="border: none;width: 280rpx;">
  84. <u-icon name="weixin-fill" color="#ffffff" size="26"></u-icon>
  85. <view class="">绑定微信</view>
  86. </view>
  87. </view>
  88. <view class="tyGpt" style="width: 280rpx;" @click="useGpt">体验CHATGPT</view>
  89. </view>
  90. <view @tap="agree = !agree" class="flxe align-center justify-center" style="margin-top: 50rpx;">
  91. <u-icon name="checkmark-circle-fill" :color="agree?'#07C160':'#ededed'" size="16"></u-icon>
  92. <view class="clause">我已阅读并同意:<view @tap.stop="agreement('privacy')" style="color: #34c758;">
  93. 《隐私政策》
  94. </view>和<view @tap.stop="agreement('use')" style="color: #34c758;">《用户协议》</view>
  95. </view>
  96. </view>
  97. </block>
  98. <block v-else>
  99. <!-- <block> -->
  100. <view class="" v-if="!showWX"
  101. style="color: #34c758;font-weight: 600; margin-bottom: 100rpx;width: 100%;text-align: center;margin-top: 30rpx;">
  102. 微信绑定成功,请手机号注册后登录,如已注册请直接登录
  103. </view>
  104. <view class="main">
  105. <view class="defBtn" style="" @click="showlogon = true,showlogin = true">
  106. <u-icon name="account-fill" color="#199063" size="26"></u-icon>
  107. <view class="">账号登录</view>
  108. </view>
  109. <view class="chatGpt" @click="useGpt">
  110. 体验CHATGPT
  111. </view>
  112. </view>
  113. <view style="color: #199063" @click="showlogon = false,showlogin = true" class="deftoregister">
  114. 未注册账号?点击去注册></view>
  115. </block>
  116. </block>
  117. <tnui-wx-user-info v-model="showAuthorizationModal" @updated="updatedUserInfoEvent"></tnui-wx-user-info>
  118. </view>
  119. </view>
  120. </view>
  121. </template>
  122. <script>
  123. import {
  124. mapMutations,
  125. mapActions,
  126. mapState,
  127. mapGetters
  128. } from 'vuex';
  129. import wechat from '@/common/wechat/wechat';
  130. import TnuiWxUserInfo from '@/components/tnui-wx-user-info/tnui-wx-user-info';
  131. import {
  132. sendCode,
  133. register,
  134. login,
  135. sysParms
  136. } from '@/api/my/index.js'
  137. import {
  138. banner
  139. } from '@/api/index/index.js'
  140. // 判断是否为微信环境
  141. const isWechat = () => {
  142. return String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger";
  143. }
  144. export default {
  145. components: {
  146. TnuiWxUserInfo
  147. },
  148. data() {
  149. return {
  150. showWX: true,
  151. list3: [
  152. 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  153. 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  154. 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  155. ],
  156. tips: '',
  157. // refCode: null,
  158. seconds: 60,
  159. agree: true,
  160. // agree1: false,
  161. showAuthorizationModal: false,
  162. tobheight: 45,
  163. platform: this.$platform.get(),
  164. h5_runmode: ['wxOfficialAccount', 'H5'],
  165. isLoading: true,
  166. showlogin: false,
  167. password: true,
  168. twopassword: true,
  169. accountLogin: {
  170. code: '',
  171. invite_code: '',
  172. mobile: '',
  173. password: '',
  174. },
  175. password2: '',
  176. showlogon: true,
  177. route: '',
  178. // register:0
  179. bannerList: [],
  180. companyDes: '',
  181. code: '',
  182. wx_code: '',
  183. isPc: true
  184. }
  185. },
  186. computed: {
  187. ...mapGetters(['appInfo', 'userInfo', 'isLogin'])
  188. },
  189. async onLoad(option) {
  190. if (navigator.userAgent.indexOf('Mobile') > -1) {
  191. // alert('移动端')
  192. this.isPc = false
  193. }
  194. if (option.code) {
  195. this.wx_code = option.code
  196. uni.showToast({
  197. title: '绑定微信成功,请用手机号注册后登录',
  198. icon: 'none',
  199. duration: 3000
  200. })
  201. this.showWX = false
  202. }
  203. // this.getWechatCode()
  204. console.log('isWechat', isWechat());
  205. if (option.iviteCode) {
  206. if (uni.getStorageSync('invite_code')) {
  207. uni.removeStorageSync('invite_code')
  208. // this.accountLogin.invite_code = option.iviteCode
  209. uni.setStorageSync('invite_code', option.iviteCode)
  210. } else {
  211. uni.setStorageSync('invite_code', option.iviteCode)
  212. }
  213. }
  214. let ress = await sysParms({
  215. })
  216. console.log('登录页系统参数返回值', ress, ress.msg);
  217. if (ress.code == 0) {
  218. this.companyDes = ress.data[5].value
  219. }
  220. let res = await banner()
  221. console.log('登录页轮播图返回值', res);
  222. if (res.code == 0) {
  223. this.bannerList = res.data
  224. }
  225. // console.log(option);
  226. const that = this;
  227. that.isLoading = false
  228. // #ifdef H5
  229. const {
  230. code,
  231. state,
  232. scope
  233. } = option;
  234. that.option = option;
  235. if (code && scope !== 'snsapi_base') {}
  236. // #endif
  237. },
  238. onUnload() {
  239. console.log('onUnload()-----------------');
  240. },
  241. onShow() {
  242. if (uni.getStorageSync('invite_code')) {
  243. this.accountLogin.invite_code = uni.getStorageSync('invite_code')
  244. }
  245. // if (uni.getStorageSync('token')) {
  246. // uni.redirectTo({
  247. // url: '/pages/index/index'
  248. // })
  249. // }
  250. },
  251. methods: {
  252. async thirdLogin(provider) {
  253. if (!this.agree) {
  254. this.$u.toast('请同意用户协议');
  255. return false;
  256. }
  257. // console.log(provider)
  258. const that = this;
  259. let user = '';
  260. // uni.showLoading({
  261. // title:'登录中...'
  262. // })
  263. switch (provider) {
  264. case 'wechat':
  265. user = await wechat.login();
  266. break;
  267. default:
  268. break;
  269. }
  270. },
  271. auth() {
  272. this.getWechatCode()
  273. },
  274. getWechatCode() {
  275. if (isWechat) {
  276. let appid = "wx96cad2970c232f6e"; //微信APPid
  277. let code = this.getUrlCode().code; //是否存在code
  278. uni.showToast({
  279. title: '点击按钮获取的wx_code-----------' + code,
  280. icon: 'none',
  281. duration: 20000
  282. })
  283. // let local = window.location.href;
  284. let local = 'http://www.liwantao.top'
  285. if (code == null || code === "") {
  286. //不存在就打开上面的地址进行授权
  287. window.location.href =
  288. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
  289. appid +
  290. "&redirect_uri=" +
  291. encodeURIComponent(local) +
  292. "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
  293. } else {
  294. this.code = code;
  295. }
  296. }
  297. },
  298. getUrlCode() {
  299. // 截取url中的code方法
  300. var url = location.search;
  301. var theRequest = new Object();
  302. if (url.indexOf("?") != -1) {
  303. var str = url.substr(1);
  304. var strs = str.split("&");
  305. for (var i = 0; i < strs.length; i++) {
  306. theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
  307. }
  308. }
  309. console.log(theRequest);
  310. return theRequest;
  311. },
  312. // ...mapActions(['getUserInfo']),
  313. forgetPwd() {
  314. uni.navigateTo({
  315. url: `/pages/user/accountSafe/updatePwd/index?from=login`
  316. })
  317. },
  318. useGpt() {
  319. uni.navigateTo({
  320. // url: 'pages/gptLead/index'
  321. url: '/pages/chat/chat'
  322. })
  323. },
  324. codeChange(text) {
  325. this.tips = text;
  326. },
  327. async getCode() {
  328. let phoneReg = /^[1][3,4,5,7,8,9][0-9]{9}$/
  329. if (!this.accountLogin.mobile) {
  330. uni.showToast({
  331. title: '请输入手机号',
  332. icon: 'none'
  333. })
  334. return;
  335. }
  336. if (!phoneReg.test(this.accountLogin.mobile)) {
  337. uni.showToast({
  338. title: '手机号不合法',
  339. icon: 'none'
  340. })
  341. return
  342. }
  343. let res = await sendCode({
  344. mobile: this.accountLogin.mobile
  345. })
  346. console.log('验证码返回值', res);
  347. if (res.code == 0) {
  348. if (this.$refs.uCode.canGetCode) {
  349. // 模拟向后端请求验证码
  350. uni.showLoading({
  351. title: '正在获取验证码'
  352. })
  353. setTimeout(() => {
  354. uni.hideLoading();
  355. // 这里此提示会被this.start()方法中的提示覆盖
  356. uni.$u.toast('验证码已发送');
  357. // 通知验证码组件内部开始倒计时
  358. this.$refs.uCode.start();
  359. }, 2000);
  360. } else {
  361. uni.$u.toast('倒计时结束后再发送');
  362. }
  363. } else {
  364. uni.hideLoading();
  365. uni.$u.toast(res.msg);
  366. }
  367. },
  368. async getlogin() {
  369. let phoneReg = /^[1][3,4,5,7,8,9][0-9]{9}$/
  370. if (!this.accountLogin.mobile) {
  371. uni.showToast({
  372. title: '请输入手机号',
  373. icon: 'none'
  374. })
  375. return;
  376. }
  377. if (!phoneReg.test(this.accountLogin.mobile)) {
  378. uni.showToast({
  379. title: '手机号不合法',
  380. icon: 'none'
  381. })
  382. return
  383. }
  384. if (!this.showlogon && !this.accountLogin.code) {
  385. uni.showToast({
  386. title: '请输入验证码',
  387. icon: 'none'
  388. })
  389. return
  390. }
  391. if (!this.accountLogin.password) {
  392. uni.showToast({
  393. title: '请输入密码',
  394. icon: 'none'
  395. })
  396. return;
  397. }
  398. if (!uni.$u.test.rangeLength(this.accountLogin.password, [6, 12])) {
  399. uni.showToast({
  400. title: '密码长度为6至12位',
  401. icon: 'none'
  402. })
  403. return;
  404. }
  405. if (/.*[\u4e00-\u9fa5]+.*$/.test(this.accountLogin.password)) {
  406. uni.showToast({
  407. title: '密码不能含有汉字',
  408. icon: 'none'
  409. })
  410. return;
  411. }
  412. if (!uni.$u.test.enOrNum(this.accountLogin.password)) {
  413. uni.showToast({
  414. title: '密码只能是字母和数字',
  415. icon: 'none'
  416. })
  417. return;
  418. }
  419. if (!this.agree) {
  420. uni.showToast({
  421. title: '请勾选协议',
  422. icon: 'none'
  423. })
  424. return;
  425. }
  426. if (this.showlogon) {
  427. console.log('登录参数', {
  428. account: this.accountLogin.mobile,
  429. password: this.accountLogin.password,
  430. code: this.wx_code
  431. });
  432. // uni.showToast({
  433. // title: this.wx_code,
  434. // icon: 'none',
  435. // duration: 1500
  436. // })
  437. let ress = await login({
  438. account: this.accountLogin.mobile,
  439. password: this.accountLogin.password,
  440. wx_code: this.wx_code
  441. // code: '051Lrz100YBhhQ1tsl200JsnrE4Lrz16'
  442. })
  443. // return
  444. console.log('登录返回值', ress);
  445. if (ress.code == 0) {
  446. this.$store.dispatch('login', ress.data.token);
  447. // this.$store.dispatch('login',
  448. // 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vdDIwLjkwMjYuY29tL2FwaS9hdXRoL2xvZ2luIiwiaWF0IjoxNjg4MDg3MTUxLCJleHAiOjE2ODg2OTE5NTEsIm5iZiI6MTY4ODA4NzE1MSwianRpIjoiU1h5Z0d0NHZqa3E0RkxiaSIsInN1YiI6IjEzIiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyIsInJvbGUiOiJ1c2VyIn0.RLc82OcM-HVhey8IpZlvsp-IruWuk70HGxWBoRwwMDY'
  449. // );
  450. uni.showToast({
  451. title: '登录成功',
  452. icon: 'none'
  453. })
  454. setTimeout(function() {
  455. uni.switchTab({
  456. url: '/pages/index/index'
  457. })
  458. }, 1000);
  459. } else {
  460. // this.$store.dispatch('login',
  461. // 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vdDIwLjkwMjYuY29tL2FwaS9hdXRoL2xvZ2luIiwiaWF0IjoxNjg4MDg3MTUxLCJleHAiOjE2ODg2OTE5NTEsIm5iZiI6MTY4ODA4NzE1MSwianRpIjoiU1h5Z0d0NHZqa3E0RkxiaSIsInN1YiI6IjEzIiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyIsInJvbGUiOiJ1c2VyIn0.RLc82OcM-HVhey8IpZlvsp-IruWuk70HGxWBoRwwMDY'
  462. // );
  463. // setTimeout(function() {
  464. // uni.switchTab({
  465. // url: '/pages/index/index'
  466. // })
  467. // }, 1000);
  468. uni.showToast({
  469. title: ress.msg,
  470. icon: 'none'
  471. })
  472. }
  473. } else {
  474. console.log('注册参数', {
  475. account: this.accountLogin.mobile,
  476. password: this.accountLogin.password,
  477. invite: this.accountLogin.invite_code,
  478. code: this.accountLogin.code,
  479. wx_code: this.wx_code
  480. });
  481. let res = await register({
  482. account: this.accountLogin.mobile,
  483. password: this.accountLogin.password,
  484. invite: this.accountLogin.invite_code,
  485. code: this.accountLogin.code,
  486. wx_code: this.wx_code
  487. })
  488. console.log('注册错误信息', res, res.msg);
  489. if (res.code == 0) {
  490. uni.removeStorageSync('invite_code')
  491. var z = '注册成功'
  492. uni.showToast({
  493. title: z
  494. })
  495. this.showlogon = true
  496. } else {
  497. var z = '注册失败,' + res.msg
  498. uni.showToast({
  499. title: z,
  500. icon: 'none'
  501. })
  502. }
  503. }
  504. },
  505. shgfgh() {
  506. let that = this;
  507. // setTimeout(function(){
  508. uni.showToast({
  509. title: '登录成功'
  510. })
  511. setTimeout(function() {
  512. // uni.navigateBack()
  513. uni.switchTab({
  514. url: '/pages/user/user'
  515. })
  516. }, 1000);
  517. // },2000);
  518. },
  519. agreement(e) {
  520. uni.navigateTo({
  521. url: './public/agreement?type=' + e
  522. })
  523. },
  524. // 绑定手机号
  525. async getphone(e) {
  526. let that = this;
  527. // uni.showLoading({
  528. // title:'绑定中...'
  529. // })
  530. let res = await wechat.getPhoneNumber(e.detail);
  531. // console.log(res)
  532. if (res.code === 0) {
  533. // uni.showToast({
  534. // title:that.cur?'绑定成功':'登录成功',
  535. // duration:1500
  536. // })
  537. // that.whether = true;
  538. // that.$store.commit('userInfo',res.data)
  539. // uni.navigateTo({
  540. // url:'/pages/public/webview?url=https://y.iduomi.cc/api/wechat_login.html'
  541. // })
  542. }
  543. },
  544. }
  545. }
  546. </script>
  547. <style lang="scss" scoped>
  548. @import './signin.scss';
  549. @import './signin1.scss';
  550. </style>