signin.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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="true"
  8. :style="{width:isPc?'50vw':'680rpx',height:isPc?'auto':'450rpx'}">
  9. <swiper-item v-for="i in bannerList">
  10. <image :src="i.picture" mode="" @click="handleBannerJump(i.url)"></image>
  11. </swiper-item>
  12. </swiper>
  13. </view> -->
  14. <view class="txt">
  15. <u-parse :content="companyDes"></u-parse>
  16. </view>
  17. </view>
  18. <block>
  19. <view class="site_name">{{appInfo.site_name}}</view>
  20. <view class="detailed">
  21. <view class="">欢迎立即加入我们!</view>
  22. </view>
  23. <u-popup :show="showlogin" mode="bottom" :round="10" closeable @close="showlogin = false">
  24. <view class="container" :class="[!isPc?'scroll':'']">
  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: 500rpx;">
  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. <!-- 备案信息 -->
  121. <beian @click="toBeianWeb"></beian>
  122. </view>
  123. </template>
  124. <script>
  125. import {
  126. mapMutations,
  127. mapActions,
  128. mapState,
  129. mapGetters
  130. } from 'vuex';
  131. import wechat from '@/common/wechat/wechat';
  132. import TnuiWxUserInfo from '@/components/tnui-wx-user-info/tnui-wx-user-info';
  133. import {
  134. sendCode,
  135. register,
  136. login,
  137. sysParms
  138. } from '@/api/my/index.js'
  139. import {
  140. banner
  141. } from '@/api/index/index.js'
  142. import beian from '@/components/beian/index.vue'
  143. // 判断是否为微信环境
  144. const isWechat = () => {
  145. return String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger";
  146. }
  147. // import uploadUrl from '@/common/config.js'
  148. export default {
  149. components: {
  150. TnuiWxUserInfo,
  151. beian
  152. },
  153. data() {
  154. return {
  155. showWX: true,
  156. list3: [
  157. 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  158. 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  159. 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  160. ],
  161. tips: '',
  162. // refCode: null,
  163. seconds: 60,
  164. agree: true,
  165. // agree1: false,
  166. showAuthorizationModal: false,
  167. tobheight: 45,
  168. platform: this.$platform.get(),
  169. h5_runmode: ['wxOfficialAccount', 'H5'],
  170. isLoading: true,
  171. showlogin: false,
  172. password: true,
  173. twopassword: true,
  174. accountLogin: {
  175. code: '',
  176. invite_code: '',
  177. mobile: '',
  178. password: '',
  179. },
  180. password2: '',
  181. showlogon: true,
  182. route: '',
  183. // register:0
  184. bannerList: [],
  185. companyDes: '',
  186. code: '',
  187. wx_code: '',
  188. isPc: true
  189. }
  190. },
  191. computed: {
  192. ...mapGetters(['appInfo', 'userInfo', 'isLogin'])
  193. },
  194. mounted() {
  195. window.onresize = () => {
  196. if (navigator.userAgent.indexOf('Mobile') > -1) {
  197. // alert('移动端')
  198. this.isPc = false
  199. }
  200. }
  201. },
  202. async onLoad(option) {
  203. if (uni.getStorageSync('token')) {
  204. uni.redirectTo({
  205. url: '/pages/index/index'
  206. })
  207. }
  208. if (navigator.userAgent.indexOf('Mobile') > -1) {
  209. // alert('移动端')
  210. this.isPc = false
  211. }
  212. if (option.code) {
  213. this.wx_code = option.code
  214. uni.showToast({
  215. title: '绑定微信成功,请用手机号注册后登录',
  216. icon: 'none',
  217. duration: 3000
  218. })
  219. this.showWX = false
  220. }
  221. // this.getWechatCode()
  222. console.log('isWechat', isWechat());
  223. if (option.iviteCode) {
  224. if (uni.getStorageSync('invite_code')) {
  225. uni.removeStorageSync('invite_code')
  226. // this.accountLogin.invite_code = option.iviteCode
  227. uni.setStorageSync('invite_code', option.iviteCode)
  228. } else {
  229. uni.setStorageSync('invite_code', option.iviteCode)
  230. }
  231. }
  232. let ress = await sysParms({
  233. })
  234. console.log('登录页系统参数返回值', ress, ress.msg);
  235. if (ress.code == 0) {
  236. this.companyDes = ress.data[5].value
  237. }
  238. let res = await banner()
  239. console.log('登录页轮播图返回值', res);
  240. if (res.code == 0) {
  241. this.bannerList = res.data
  242. }
  243. // console.log(option);
  244. const that = this;
  245. that.isLoading = false
  246. // #ifdef H5
  247. const {
  248. code,
  249. state,
  250. scope
  251. } = option;
  252. that.option = option;
  253. if (code && scope !== 'snsapi_base') {}
  254. // #endif
  255. },
  256. onUnload() {
  257. console.log('onUnload()-----------------');
  258. },
  259. onShow() {
  260. if (uni.getStorageSync('clickStudyBtn')) {
  261. uni.removeStorageSync('clickStudyBtn')
  262. }
  263. if (uni.getStorageSync('myScoreId')) {
  264. uni.removeStorageSync('myScoreId')
  265. }
  266. if (uni.getStorageSync('invite_code')) {
  267. this.accountLogin.invite_code = uni.getStorageSync('invite_code')
  268. }
  269. // if (uni.getStorageSync('token')) {
  270. // uni.redirectTo({
  271. // url: '/pages/index/index'
  272. // })
  273. // }
  274. },
  275. methods: {
  276. toBeianWeb() {
  277. window.open('https://beian.miit.gov.cn/#/Integrated/index')
  278. },
  279. handleBannerJump(url) {
  280. if (url) {
  281. window.open(url)
  282. }
  283. },
  284. async thirdLogin(provider) {
  285. if (!this.agree) {
  286. this.$u.toast('请同意用户协议');
  287. return false;
  288. }
  289. // console.log(provider)
  290. const that = this;
  291. let user = '';
  292. // uni.showLoading({
  293. // title:'登录中...'
  294. // })
  295. switch (provider) {
  296. case 'wechat':
  297. user = await wechat.login();
  298. break;
  299. default:
  300. break;
  301. }
  302. },
  303. auth() {
  304. this.getWechatCode()
  305. },
  306. getWechatCode() {
  307. if (isWechat) {
  308. // let appid = "wx96cad2970c232f6e"; //微信APPid
  309. let appid = uni.getStorageSync('wxId')
  310. let code = this.getUrlCode().code; //是否存在code
  311. uni.showToast({
  312. title: '点击按钮获取的wx_code-----------' + code,
  313. icon: 'none',
  314. duration: 20000
  315. })
  316. // let local = window.location.href;
  317. let local = 'http://www.liwantao.top'
  318. if (code == null || code === "") {
  319. //不存在就打开上面的地址进行授权
  320. window.location.href =
  321. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
  322. appid +
  323. "&redirect_uri=" +
  324. encodeURIComponent(local) +
  325. "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
  326. } else {
  327. this.code = code;
  328. }
  329. }
  330. },
  331. getUrlCode() {
  332. // 截取url中的code方法
  333. var url = location.search;
  334. var theRequest = new Object();
  335. if (url.indexOf("?") != -1) {
  336. var str = url.substr(1);
  337. var strs = str.split("&");
  338. for (var i = 0; i < strs.length; i++) {
  339. theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
  340. }
  341. }
  342. console.log(theRequest);
  343. return theRequest;
  344. },
  345. // ...mapActions(['getUserInfo']),
  346. forgetPwd() {
  347. uni.navigateTo({
  348. url: `/pages/user/accountSafe/updatePwd/index?from=login`
  349. })
  350. },
  351. useGpt() {
  352. uni.navigateTo({
  353. // url: 'pages/gptLead/index'
  354. url: '/pages/chat/chat'
  355. })
  356. },
  357. codeChange(text) {
  358. this.tips = text;
  359. },
  360. async getCode() {
  361. let phoneReg = /^[1][3,4,5,7,8,9][0-9]{9}$/
  362. if (!this.accountLogin.mobile) {
  363. uni.showToast({
  364. title: '请输入手机号',
  365. icon: 'none'
  366. })
  367. return;
  368. }
  369. if (!phoneReg.test(this.accountLogin.mobile)) {
  370. uni.showToast({
  371. title: '手机号不合法',
  372. icon: 'none'
  373. })
  374. return
  375. }
  376. let res = await sendCode({
  377. mobile: this.accountLogin.mobile
  378. })
  379. console.log('验证码返回值', res);
  380. if (res.code == 0) {
  381. if (this.$refs.uCode.canGetCode) {
  382. // 模拟向后端请求验证码
  383. uni.showLoading({
  384. title: '正在获取验证码'
  385. })
  386. setTimeout(() => {
  387. uni.hideLoading();
  388. // 这里此提示会被this.start()方法中的提示覆盖
  389. uni.$u.toast('验证码已发送');
  390. // 通知验证码组件内部开始倒计时
  391. this.$refs.uCode.start();
  392. }, 2000);
  393. } else {
  394. uni.$u.toast('倒计时结束后再发送');
  395. }
  396. } else {
  397. uni.hideLoading();
  398. uni.$u.toast(res.msg);
  399. }
  400. },
  401. async getlogin() {
  402. let phoneReg = /^[1][3,4,5,7,8,9][0-9]{9}$/
  403. if (!this.accountLogin.mobile) {
  404. uni.showToast({
  405. title: '请输入手机号',
  406. icon: 'none'
  407. })
  408. return;
  409. }
  410. if (!phoneReg.test(this.accountLogin.mobile)) {
  411. uni.showToast({
  412. title: '手机号不合法',
  413. icon: 'none'
  414. })
  415. return
  416. }
  417. if (!this.showlogon && !this.accountLogin.code) {
  418. uni.showToast({
  419. title: '请输入验证码',
  420. icon: 'none'
  421. })
  422. return
  423. }
  424. if (!this.accountLogin.password) {
  425. uni.showToast({
  426. title: '请输入密码',
  427. icon: 'none'
  428. })
  429. return;
  430. }
  431. if (!uni.$u.test.rangeLength(this.accountLogin.password, [6, 12])) {
  432. uni.showToast({
  433. title: '密码长度为6至12位',
  434. icon: 'none'
  435. })
  436. return;
  437. }
  438. if (/.*[\u4e00-\u9fa5]+.*$/.test(this.accountLogin.password)) {
  439. uni.showToast({
  440. title: '密码不能含有汉字',
  441. icon: 'none'
  442. })
  443. return;
  444. }
  445. if (!uni.$u.test.enOrNum(this.accountLogin.password)) {
  446. uni.showToast({
  447. title: '密码只能是字母和数字',
  448. icon: 'none'
  449. })
  450. return;
  451. }
  452. if (!this.agree) {
  453. uni.showToast({
  454. title: '请勾选协议',
  455. icon: 'none'
  456. })
  457. return;
  458. }
  459. if (this.showlogon) {
  460. console.log('登录参数', {
  461. account: this.accountLogin.mobile,
  462. password: this.accountLogin.password,
  463. code: this.wx_code
  464. });
  465. // uni.showToast({
  466. // title: this.wx_code,
  467. // icon: 'none',
  468. // duration: 1500
  469. // })
  470. let ress = await login({
  471. account: this.accountLogin.mobile,
  472. password: this.accountLogin.password,
  473. wx_code: this.wx_code
  474. // code: '051Lrz100YBhhQ1tsl200JsnrE4Lrz16'
  475. })
  476. // return
  477. console.log('登录返回值', ress);
  478. if (ress.code == 0) {
  479. this.$store.dispatch('login', ress.data.token);
  480. // this.$store.dispatch('login',
  481. // 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vdDIwLjkwMjYuY29tL2FwaS9hdXRoL2xvZ2luIiwiaWF0IjoxNjg4MDg3MTUxLCJleHAiOjE2ODg2OTE5NTEsIm5iZiI6MTY4ODA4NzE1MSwianRpIjoiU1h5Z0d0NHZqa3E0RkxiaSIsInN1YiI6IjEzIiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyIsInJvbGUiOiJ1c2VyIn0.RLc82OcM-HVhey8IpZlvsp-IruWuk70HGxWBoRwwMDY'
  482. // );
  483. uni.showToast({
  484. title: '登录成功',
  485. icon: 'none'
  486. })
  487. setTimeout(function() {
  488. uni.switchTab({
  489. url: '/pages/index/index'
  490. })
  491. }, 1000);
  492. } else {
  493. // this.$store.dispatch('login',
  494. // 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vdDIwLjkwMjYuY29tL2FwaS9hdXRoL2xvZ2luIiwiaWF0IjoxNjg4MDg3MTUxLCJleHAiOjE2ODg2OTE5NTEsIm5iZiI6MTY4ODA4NzE1MSwianRpIjoiU1h5Z0d0NHZqa3E0RkxiaSIsInN1YiI6IjEzIiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyIsInJvbGUiOiJ1c2VyIn0.RLc82OcM-HVhey8IpZlvsp-IruWuk70HGxWBoRwwMDY'
  495. // );
  496. // setTimeout(function() {
  497. // uni.switchTab({
  498. // url: '/pages/index/index'
  499. // })
  500. // }, 1000);
  501. uni.showToast({
  502. title: ress.msg,
  503. icon: 'none'
  504. })
  505. }
  506. } else {
  507. console.log('注册参数', {
  508. account: this.accountLogin.mobile,
  509. password: this.accountLogin.password,
  510. invite: this.accountLogin.invite_code,
  511. code: this.accountLogin.code,
  512. wx_code: this.wx_code
  513. });
  514. let res = await register({
  515. account: this.accountLogin.mobile,
  516. password: this.accountLogin.password,
  517. invite: this.accountLogin.invite_code,
  518. code: this.accountLogin.code,
  519. wx_code: this.wx_code
  520. })
  521. console.log('注册错误信息', res, res.msg);
  522. if (res.code == 0) {
  523. uni.removeStorageSync('invite_code')
  524. var z = '注册成功'
  525. uni.showToast({
  526. title: z
  527. })
  528. this.showlogon = true
  529. } else {
  530. var z = '注册失败,' + res.msg
  531. uni.showToast({
  532. title: z,
  533. icon: 'none'
  534. })
  535. }
  536. }
  537. },
  538. shgfgh() {
  539. let that = this;
  540. // setTimeout(function(){
  541. uni.showToast({
  542. title: '登录成功'
  543. })
  544. setTimeout(function() {
  545. // uni.navigateBack()
  546. uni.switchTab({
  547. url: '/pages/user/user'
  548. })
  549. }, 1000);
  550. // },2000);
  551. },
  552. agreement(e) {
  553. uni.navigateTo({
  554. url: './public/agreement?type=' + e
  555. })
  556. },
  557. // 绑定手机号
  558. async getphone(e) {
  559. let that = this;
  560. // uni.showLoading({
  561. // title:'绑定中...'
  562. // })
  563. let res = await wechat.getPhoneNumber(e.detail);
  564. // console.log(res)
  565. if (res.code === 0) {
  566. // uni.showToast({
  567. // title:that.cur?'绑定成功':'登录成功',
  568. // duration:1500
  569. // })
  570. // that.whether = true;
  571. // that.$store.commit('userInfo',res.data)
  572. // uni.navigateTo({
  573. // url:'/pages/public/webview?url=https://y.iduomi.cc/api/wechat_login.html'
  574. // })
  575. }
  576. },
  577. }
  578. }
  579. </script>
  580. <style lang="scss" scoped>
  581. @import './signin.scss';
  582. </style>