register.vue 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. <template>
  2. <view class="container">
  3. <view class="back-btn cuIcon-back" @click="navBack"></view>
  4. <view class="wrapper">
  5. <h2 class="Semibold">手机号注册</h2>
  6. <view style='width:100%;margin-top:50px;border-bottom:1px solid #E8E9ED;padding:10px;position:relative;' class="flex">
  7. <view class="NumberMedium" style='width:15%;border-right:1px solid #E8E9ED;'>+86</view>
  8. <view style='width:85%;'><input maxlength="11" v-model='phone' @input='phoneinput' style='padding-left:10px;' placeholder="请输入手机号码" type="number" class="Regular"></view>
  9. <image v-if='phone!=""' @click='phone=""' class='close' src='../../static/img/login/guanbi@2x.png'></image>
  10. </view>
  11. <view style='width:100%;border-bottom:1px solid #E8E9ED;position:relative;padding:10px;' class="flex">
  12. <view style='width:70%;position:relative;'>
  13. <input v-model='verifyCode' class="Regular" placeholder="请输入验证码" type="number">
  14. <image v-if='verifyCode!=""' @click='verifyCode=""' class='close1' src='../../static/img/login/guanbi@2x.png'></image>
  15. </view>
  16. <button :class='codestatus&&!sendDisabled?"active":""' @click='getcode' class='getcode Regular'>{{sendText}}</button>
  17. </view>
  18. <view style='border-bottom:1px solid #E8E9ED;padding:10px;position:relative;'>
  19. <u-input maxlength='16' class='Regular input-style' style='height:30px;' v-model='password' placeholder="请输入密码,6-16位字符" :type="type"/>
  20. <!-- <input maxlength='16' class='password Regular input-style' style='height:30px;' v-model='password' placeholder="请输入密码,6-16位字符" :type="type"> -->
  21. <!-- <image v-if='password!=""' @click='password=""' class='close2' src='../../static/img/login/guanbi@2x.png'></image> -->
  22. <!-- <view @click='switchover' style='position:absolute;right:0;top:38%;z-index:10;cursor:pointer;' class="iconfont " :class='type=="password"?"icon-yanjing-biyan":"icon-yanjing-zhengyan"'></view> -->
  23. </view>
  24. <button :class='phone!=""&&verifyCode!=""&&password!=""?"active":""' @click='register' class='verificationCode'>注册</button>
  25. <view style='color:#6A6A6A;margin-top:10px;text-align:center;'>
  26. <image @click='consent' style='width:14px;height:14px;position:relative;top:2px;margin-right:5px;' :src="consentStatus==true?'../../static/img/login/select@2x.png':'../../static/img/login/selected2.png'" alt=""></image>
  27. 已阅读并同意
  28. <navigator url="/pages/sale/webview?can_share=false&url=https://liangxin.zthymaoyi.com/userAgreement.html" class="path" hover-class="navigator-hover">《服务协议》</navigator>和<navigator url="/pages/sale/webview?can_share=false&url=https://liangxin.zthymaoyi.com/screctAgreement.html"
  29. class="path" hover-class="navigator-hover">《隐私政策》</navigator>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. mapMutations
  37. } from 'vuex';
  38. import { openFSqlite, createFSQL, selectFSQL, addFSQL } from '../../util/f.js'
  39. import { queryData, upData, initData } from '../../util/dbUtil.js'
  40. export default {
  41. data() {
  42. return {
  43. inputContent: null,
  44. loginType: "wechat",
  45. phone: '',
  46. password: '',
  47. logining: false,
  48. isPhone: false,
  49. isApple: true,
  50. accessToken:'',
  51. params:{
  52. encryptedData:'',
  53. session_key:'',
  54. iv:'',
  55. },
  56. userInfo:{
  57. nickName:'',
  58. avatarUrl:'',
  59. gender:'',
  60. phone:''
  61. },
  62. consentStatus:false,
  63. codestatus:false,
  64. type:'password',
  65. inputStatus:'none',
  66. verifyCode:null,
  67. sendText:'获取验证码',
  68. sendDisabled: false,
  69. system:'',
  70. platform:'',
  71. userData:undefined,
  72. canIUseProfile:false
  73. }
  74. },
  75. onShow() {
  76. // this.loginType = "wechat"
  77. // this.$api.logout()
  78. },
  79. onLoad(options) {
  80. if( wx.getUserProfile ){
  81. console.log('--check getUserProfile--OK');
  82. this.canIUseProfile = true;
  83. }
  84. console.log("login on load")
  85. var that = this
  86. that.$api.request('user', 'sendIsApple', {
  87. }).then(res => {
  88. that.isApple = res.data
  89. })
  90. uni.getSystemInfo({
  91. success:(res) => {
  92. // console.log(res)
  93. this.system = res.system // ios
  94. this.platform = res.platform // 14.3
  95. }
  96. })
  97. },
  98. methods: {
  99. // 随机数
  100. randomAccess(min,max){
  101. return Math.floor(Math.random() * (min - max) + max)
  102. },
  103. // 解码
  104. decodeUnicode(str) {
  105. //Unicode显示方式是\u4e00
  106. str = "\\u"+str
  107. str = str.replace(/\\/g, "%");
  108. //转换中文
  109. str = unescape(str);
  110. //将其他受影响的转换回原来
  111. str = str.replace(/%/g, "\\");
  112. return str;
  113. },
  114. /*
  115. *@param Number NameLength 要获取的名字长度
  116. */
  117. getRandomName(NameLength){
  118. let name = ""
  119. for(let i = 0;i<NameLength;i++){
  120. let unicodeNum = ""
  121. unicodeNum = this.randomAccess(0x4e00,0x9fa5).toString(16)
  122. name += this.decodeUnicode(unicodeNum)
  123. }
  124. return name
  125. },
  126. phoneinput(e){
  127. if(e.detail.value.length==11){
  128. this.codestatus=true
  129. }
  130. },
  131. getcode(){
  132. var that = this
  133. if(/^0?1[3|4|5|6|7|8][0-9]\d{8}$/.test(this.phone)){
  134. this.$api.doRequest('get','/commonUser/sendVerifyCode',{phone:this.phone}).then(res => {
  135. if(res.data.code==200){
  136. that.sendDisabled = true
  137. let sec = 60
  138. let interval = setInterval(() => {
  139. sec--;
  140. that.sendText = sec + 's后重发'
  141. if (sec <= 0) {
  142. that.sendDisabled = false
  143. that.sendText = "获取验证码"
  144. clearInterval(interval)
  145. }
  146. }, 1000)
  147. }else{
  148. uni.showToast({
  149. title: res.data.message,
  150. icon:'none',
  151. duration: 2000
  152. })
  153. }
  154. })
  155. .catch(res => {
  156. uni.showToast({
  157. title: res.data.message,
  158. icon:'none',
  159. duration: 2000
  160. })
  161. });
  162. }else{
  163. uni.showToast({
  164. title: '请输入正确的手机号',
  165. icon:'none',
  166. duration: 2000
  167. })
  168. }
  169. },
  170. register(){
  171. var that = this
  172. if(!this.consentStatus){
  173. uni.showToast({
  174. title: '请勾选协议',
  175. icon:'none',
  176. duration: 2000
  177. })
  178. return
  179. }
  180. if(this.verifyCode.length>6){
  181. uni.showToast({
  182. title: '验证码错误',
  183. icon:'none',
  184. duration: 2000
  185. })
  186. return
  187. }
  188. if(this.password.length<6){
  189. uni.showToast({
  190. title: '请输入正确的密码格式',
  191. icon:'none',
  192. duration: 2000
  193. })
  194. return
  195. }
  196. var username=this.getRandomName(3)
  197. this.$api.doRequest('post','/commonUser/register',{phone:this.phone,password:this.password,verifyCode:this.verifyCode,userName:username}).then(res => {
  198. if(res.data.code=='11002'){
  199. uni.showToast({
  200. title: '验证码错误或过期,请重新获取',
  201. icon:'none',
  202. duration: 2000
  203. })
  204. return
  205. }else if(res.data.code=='11004'){
  206. uni.showToast({
  207. title: '该手机号已注册,可直接登录',
  208. icon:'none',
  209. duration: 2000
  210. })
  211. return
  212. }
  213. else{
  214. uni.showLoading({
  215. title: '登录中',
  216. mask:true
  217. })
  218. this.$api.doRequest('get','/commonUser/login',{phone:this.phone,password:this.password,cid:this.clientId}).then(res => {
  219. if(res.data.code==200){
  220. // pc登录
  221. this.$api.doRequest('post','/commonUser/api/loginQuickly',{mobilePhone: this.phone,
  222. veriCode: "123456",}).then(res1 => {
  223. if(res1.data.code==200){
  224. uni.setStorageSync('pcUserInfo', res1.data.data)
  225. }else{
  226. that.$api.doRequest('post','/commonUser/api/loginQuickly',{mobilePhone: '13333333333',
  227. veriCode: "123456",}).then(res2 => {
  228. uni.setStorageSync('pcUserInfo', res2.data.data)
  229. })
  230. }
  231. })
  232. uni.setStorageSync('userInfo', res.data)
  233. that.$store.commit('login', res.data)
  234. // that.liangxinLogin()
  235. uni.switchTab({
  236. url: '/pages/sale/information'
  237. });
  238. }else{
  239. uni.showToast({
  240. title: res.data.message,
  241. icon:'none',
  242. duration: 2000
  243. })
  244. }
  245. uni.hideLoading()
  246. })
  247. .catch(res => {
  248. console.log(res);
  249. });
  250. }
  251. })
  252. .catch(res => {
  253. console.log(res);
  254. });
  255. },
  256. consent(){
  257. this.consentStatus=!this.consentStatus
  258. uni.setStorage({
  259. key: 'policyStorageKey',
  260. data: this.consentStatus
  261. });
  262. },
  263. switchover(){
  264. if(this.type=='password'){
  265. this.type='text'
  266. }else{
  267. this.type='password'
  268. }
  269. },
  270. gocode(){
  271. uni.navigateTo({
  272. url:'/pages/public/login'
  273. })
  274. },
  275. forgetpass(){
  276. uni.navigateTo({
  277. url:'/pages/public/reset'
  278. })
  279. },
  280. phonelogin(){
  281. var that=this
  282. uni.showLoading({
  283. title: '登录中',
  284. mask:true
  285. })
  286. console.log("clientid",that.clientId)
  287. this.$api.request('user', 'login',{
  288. password:that.password,
  289. phone:that.phone,
  290. cid:that.clientId
  291. }, failres => {
  292. that.$api.msg(failres.errmsg)
  293. uni.hideLoading()
  294. }).then(res => {
  295. console.log(res)
  296. uni.setStorageSync('userInfo', res.data)
  297. that.$store.commit('login', res.data)
  298. // that.liangxinLogin()
  299. uni.switchTab({
  300. url: '/pages/sale/information'
  301. });
  302. uni.hideLoading()
  303. })
  304. },
  305. appleLogin(){
  306. var that=this
  307. uni.getProvider({
  308. service: 'oauth',
  309. success: function (res) {
  310. // console.log(res.provider)
  311. if(~res.provider.indexOf('apple')) {
  312. uni.login({
  313. provider: 'apple',
  314. success: loginRes => {
  315. uni.getUserInfo({
  316. provider: 'apple',
  317. success: userInfoRes => {
  318. that.$api.request('user', 'thirdPartLogin', {
  319. loginType: 4/* */,
  320. raw: JSON.stringify(userInfoRes.userInfo)
  321. }, failres => {
  322. that.$api.msg(failres.errmsg)
  323. uni.hideLoading()
  324. }).then(res => {
  325. console.log("thirdPartLogin:"+res.data.phone)
  326. that.accessToken = res.data.accessToken
  327. that.logining = false
  328. uni.getUserInfo({
  329. lang: 'zh_CN',
  330. success: (e) => {
  331. uni.setStorageSync('userInfo', res.data)
  332. that.$store.commit('login', res.data)
  333. e.userInfo.nickname = e.userInfo.nickName
  334. e.userInfo.cid = uni.getStorageSync("clientId")
  335. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  336. //同步过后
  337. res.data.nickname = e.userInfo.nickName
  338. res.data.avatarUrl = e.userInfo.avatarUrl
  339. res.data.gender = e.userInfo.gender
  340. if(!res.data.phone){
  341. res.data.phone = e.userInfo.phone
  342. }
  343. uni.setStorageSync('userInfo', res.data)
  344. that.$store.commit('login', res.data)
  345. })
  346. },
  347. complete: (e) => {
  348. uni.hideLoading()
  349. if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
  350. that.isPhone = true//显示自定义的获取手机权限提示框
  351. that.inputStatus = 'inline'
  352. that.inputContent = ''
  353. }
  354. else{
  355. uni.switchTab({
  356. url: '/pages/sale/sale'
  357. });
  358. console.log("complete")
  359. }
  360. }
  361. })
  362. })
  363. console.log('获取用户信息成功'+JSON.stringify(userInfoRes))
  364. }
  365. })
  366. },
  367. fail: err => {
  368. console.log('apple登录失败' + JSON.stringify(err))
  369. uni.showToast({
  370. title:'登录失败',
  371. icon:'none'
  372. })
  373. }
  374. })
  375. }
  376. },
  377. fail: err => {
  378. uni.showToast({
  379. title:'登录失败',
  380. icon:'none'
  381. })
  382. }
  383. })
  384. },
  385. doGetVerify() {
  386. const that = this
  387. var phone = this.inputContent;
  388. if (!phone || phone.length != 11) {
  389. uni.showToast({
  390. title:'请输入正确手机号!',
  391. icon:'none'
  392. })
  393. return
  394. }
  395. that.$api.request('user', 'sendVerifyCode', {
  396. phone: phone,
  397. }).then(res => {
  398. that.sendDisabled = true
  399. let sec = 60
  400. let interval = setInterval(() => {
  401. sec--;
  402. that.sendText = sec + 's后重发'
  403. if (sec <= 0) {
  404. that.sendDisabled = false
  405. that.sendText = "获取验证码"
  406. clearInterval(interval)
  407. }
  408. }, 1000)
  409. })
  410. },
  411. verifyCodeInput(e){
  412. this.verifyCode = e.detail.value
  413. },
  414. cancel() {
  415. this.inputShow = false
  416. this.inputStatus = 'none'
  417. this.isPhone = false
  418. },
  419. confirm() {
  420. var that = this
  421. if (!this.inputContent || this.inputContent.length != 11) {
  422. uni.showToast({
  423. title:'请输入正确手机号!',
  424. icon:'none'
  425. })
  426. return
  427. }
  428. if (!this.verifyCode) {
  429. uni.showToast({
  430. title:'请输入验证码!',
  431. icon:'none'
  432. })
  433. return
  434. }
  435. this.$api.request('user', 'mergeUser', {
  436. phone: that.inputContent,
  437. verifyCode:that.verifyCode
  438. },failres => {
  439. that.$api.msg(failres.errmsg)
  440. uni.hideLoading()
  441. }).then(res => {
  442. that.accessToken = res.data.accessToken
  443. that.$api.setUserInfo(res.data)
  444. that.logining = false
  445. uni.getUserInfo({
  446. lang: 'zh_CN',
  447. success: (e) => {
  448. uni.setStorageSync('userInfo', res.data)
  449. that.$store.commit('login', res.data)
  450. e.userInfo.nickname = e.userInfo.nickName
  451. e.userInfo.cid = uni.getStorageSync("clientId")
  452. console.log(e.userInfo)
  453. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  454. //同步过后
  455. res.data.nickname = e.userInfo.nickName
  456. res.data.avatarUrl = e.userInfo.avatarUrl
  457. res.data.gender = e.userInfo.gender
  458. res.data.phone = e.userInfo.phone
  459. uni.setStorageSync('userInfo', res.data)
  460. that.$store.commit('login', res.data)
  461. // that.liangxinLogin()
  462. })
  463. },
  464. complete: (e) => {
  465. uni.switchTab({
  466. url: '/pages/sale/information'
  467. });
  468. uni.hideLoading()
  469. that.isPhone=false
  470. uni.navigateBack()
  471. }
  472. })
  473. })
  474. },
  475. ...mapMutations(['login']),
  476. inputChange(e) {
  477. const key = e.currentTarget.dataset.key;
  478. this[key] = e.detail.value;
  479. },
  480. chooseLoginType(type) {
  481. this.loginType = type
  482. },
  483. navBack() {
  484. uni.navigateBack();
  485. },
  486. toRegist() {
  487. uni.redirectTo({
  488. url: '/pages/public/register'
  489. })
  490. },
  491. ///发起消息订阅
  492. requestSubscribe(){
  493. const that = this
  494. wx.requestSubscribeMessage({
  495. tmplIds: ['xL_uZEqJz4QP1FbnlzQWAiO2zVBn3Qeu8JwLVOU3hU0','8cVkckXi_8zfHeScXRHhjN6cgZFYYCWIMPDTiPWagXY','IE7WxBsv-fDvPWSrng-97lGWtvZf9rHuECBlhRLlWxI'],//
  496. success :(res)=>{
  497. console.log("订阅消息 成功 "+res);
  498. },
  499. fail :(errMsg) =>{
  500. console.log("订阅消息 失败 "+errMsg.errMsg);
  501. },
  502. complete:(errMsg)=>{
  503. console.log("订阅消息 完成 "+errMsg);
  504. }
  505. });
  506. },
  507. getPhoneNumber(e) {
  508. console.log(e)
  509. if (e.mp.detail.errMsg==="getPhoneNumber:ok") {
  510. this.isPhone = false
  511. this.params.iv = e.mp.detail.iv
  512. this.params.encryptedData = e.mp.detail.encryptedData
  513. this.params.session_key = this.accessToken
  514. console.log(this.params)
  515. this.getTokenAsync(this.params)
  516. }
  517. },
  518. // 请求后获取token
  519. async getTokenAsync(params) {
  520. let that = this
  521. this.$api.request('user', 'getPhoneNumber', params).then(res => {
  522. if(res.data.phoneNumber){
  523. that.userInfo.phone = res.data.phoneNumber
  524. }
  525. if(res.data.unionId){
  526. that.userInfo.unionId = res.data.unionId
  527. }
  528. that.userInfo.cid = uni.getStorageSync("clientId")
  529. console.log(that.userInfo)
  530. that.$api.request('user', 'syncUserInfo', that.userInfo).then(syncRes => {
  531. uni.setStorageSync('userInfo', that.userInfo)
  532. that.$store.commit('login', that.userInfo)
  533. that.$api.setUserInfo(that.userInfo)
  534. uni.hideLoading()
  535. // that.liangxinLogin()
  536. })
  537. if(res.data.phoneNumber){
  538. uni.switchTab({
  539. url: '/pages/sale/information'
  540. });
  541. }
  542. })
  543. },
  544. async toLogin() {
  545. this.verifyCode = ''
  546. const that = this
  547. if (that.phone.length !== 11) {
  548. that.$api.msg('请输入11位中国手机号')
  549. } else if (that.password.length < 8) {
  550. that.$api.msg('密码至少8位')
  551. } else {
  552. that.logining = true;
  553. //#ifdef MP-WEIXIN
  554. //若是小程序平台,则获取到openId。整个过程是静默完成的
  555. uni.login({
  556. provider: 'weixin',
  557. success: (wxres => {
  558. that.$api.request('user', 'login', {
  559. phone: that.phone,
  560. password: that.password,
  561. loginType: 1,
  562. raw: JSON.stringify(wxres)
  563. }, failres => {
  564. that.logining = false
  565. uni.showToast({
  566. title: failres.errmsg,
  567. icon: "none"
  568. });
  569. }).then(res => {
  570. that.logining = false
  571. that.$store.commit('login', res.data)
  572. uni.setStorageSync('userInfo', res.data)
  573. if (that.$api.prePage().lodaData) {
  574. that.$api.prePage().loadData()
  575. }
  576. uni.navigateBack()
  577. })
  578. })
  579. })
  580. //#endif
  581. //#ifdef APP-PLUS || H5
  582. //若是App登录,则不需要保存OpenId。可直接登录
  583. that.$api.request('user', 'login', {
  584. phone: that.phone,
  585. password: that.password,
  586. }, failres => {
  587. that.logining = false
  588. uni.showToast({
  589. title: failres.errmsg,
  590. icon: "none"
  591. });
  592. }).then(res => {
  593. that.logining = false
  594. that.$store.commit('login', res.data)
  595. uni.setStorageSync('userInfo', res.data)
  596. if (that.$api.prePage().lodaData) {
  597. that.$api.prePage().loadData()
  598. }
  599. uni.navigateBack()
  600. })
  601. //#endif
  602. }
  603. },
  604. miniWechatLogin(e) {
  605. const that = this
  606. //旧版本方式
  607. if( this.canIUseProfile == false ){
  608. console.log("旧版本方式")
  609. //获取授权信息
  610. if(e.detail.userInfo){
  611. console.log('用户允许了授权')
  612. console.log( e.detail.userInfo ); //1.拿到基本的微信信息!!
  613. uni.showLoading({
  614. title: '加载中',
  615. mask:true
  616. })
  617. that.logining = true
  618. let loginType = 1
  619. let userInfo = e.detail.userInfo
  620. uni.login({
  621. provider: 'weixin',
  622. success: (wxres => {
  623. that.logining = false
  624. that.$api.request('user', 'thirdPartLogin', {
  625. loginType: loginType,
  626. raw: JSON.stringify(wxres)
  627. }, failres => {
  628. that.$api.msg(failres.errmsg)
  629. uni.hideLoading()
  630. }).then(res => {
  631. that.accessToken = res.data.accessToken
  632. that.$api.setUserInfo(res.data)
  633. that.userInfo = res.data
  634. uni.getUserInfo({
  635. lang: 'zh_CN',
  636. provider: 'weixin',
  637. withCredentials:true,
  638. success: (e) => {
  639. that.params.iv = e.iv
  640. that.params.encryptedData = e.encryptedData
  641. that.params.session_key = that.accessToken
  642. console.log(this.params)
  643. that.getTokenAsync(this.params)
  644. uni.setStorageSync('userInfo', res.data)
  645. that.$store.commit('login', res.data)
  646. e.userInfo.nickname = e.userInfo.nickName
  647. if(e.userInfo.phone == undefined){
  648. e.userInfo.phone = ''
  649. }
  650. e.userInfo.cid = uni.getStorageSync("clientId")
  651. console.log(e.userInfo)
  652. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  653. //同步过后
  654. res.data.nickname = userInfo.nickName
  655. res.data.avatarUrl = userInfo.avatarUrl
  656. res.data.gender = userInfo.gender
  657. if(userInfo.phone){
  658. res.data.phone = userInfo.phone
  659. // that.liangxinLogin()
  660. }
  661. uni.setStorageSync('userInfo', res.data)
  662. that.$store.commit('login', res.data)
  663. that.$api.setUserInfo(res.data)
  664. uni.hideLoading()
  665. // uni.navigateBack()
  666. })
  667. },
  668. complete: (e) => {
  669. uni.hideLoading()
  670. if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
  671. that.isPhone = true//显示自定义的获取手机权限提示框
  672. that.inputStatus = 'inline'
  673. that.inputContent = ''
  674. }
  675. else{
  676. uni.setStorageSync('PageCur', "sale");
  677. // uni.switchTab({
  678. // url: '/pages/sale/sale'
  679. // });
  680. uni.switchTab({
  681. url: '/pages/sale/information'
  682. });
  683. console.log("complete")
  684. }
  685. }
  686. })
  687. })
  688. }),
  689. })
  690. }
  691. //新版本方式
  692. }else{
  693. console.log("新版本方式")
  694. uni.showLoading({
  695. title: '加载中',
  696. mask:true
  697. })
  698. that.logining = true
  699. let loginType = 1
  700. wx.getUserProfile({
  701. desc : '用于完善用户资料',
  702. lang : 'zh_CN',
  703. success : function( proRes ){
  704. console.log('proRes.userInfo',proRes.userInfo)
  705. uni.login({
  706. provider: 'weixin',
  707. success: (wxres => {
  708. that.logining = false
  709. that.$api.request('user', 'thirdPartLogin', {
  710. loginType: loginType,
  711. raw: JSON.stringify(wxres)
  712. }, failres => {
  713. that.$api.msg(failres.errmsg)
  714. uni.hideLoading()
  715. }).then(res => {
  716. console.log('res+++++',res)
  717. that.accessToken = res.data.accessToken
  718. that.$api.setUserInfo(res.data)
  719. that.userInfo = res.data
  720. // that.params.iv = proRes.iv
  721. // that.params.encryptedData = proRes.encryptedData
  722. // that.params.session_key = that.accessToken
  723. // console.log(that.params)
  724. // that.getTokenAsync(that.params)
  725. uni.setStorageSync('userInfo', res.data)
  726. that.$store.commit('login', res.data)
  727. if(proRes.userInfo.phone == undefined){
  728. proRes.userInfo.phone = ''
  729. }
  730. res.data.cid = uni.getStorageSync("clientId")
  731. that.$api.request('user', 'syncUserInfo', res.data).then(syncRes => {
  732. //同步过后
  733. res.data.nickname = proRes.userInfo.nickName
  734. res.data.avatarUrl = proRes.userInfo.avatarUrl
  735. res.data.gender = proRes.userInfo.gender
  736. if(proRes.userInfo.phone){
  737. res.data.phone = proRes.userInfo.phone
  738. }
  739. uni.setStorageSync('userInfo', res.data)
  740. that.$store.commit('login', res.data)
  741. that.$api.setUserInfo(res.data)
  742. uni.hideLoading()
  743. if(!that.userInfo.phone||that.userInfo.phone==""||that.userInfo.phone ==undefined){
  744. that.isPhone = true//显示自定义的获取手机权限提示框
  745. that.inputStatus = 'inline'
  746. that.inputContent = ''
  747. }
  748. else{
  749. uni.setStorageSync('PageCur', "sale");
  750. // uni.switchTab({
  751. // url: '/pages/sale/sale'
  752. // });
  753. uni.reLaunch({
  754. url: '/pages/sale/information'
  755. });
  756. console.log("complete")
  757. // that.liangxinLogin()
  758. }
  759. })
  760. console.log( 'wx.getUserProfile=>用户允许了授权' );
  761. })
  762. })
  763. })
  764. },
  765. fail : function( res ){
  766. console.log('wx.getUserProfile=>用户拒绝了授权');
  767. console.log( res );
  768. }
  769. });
  770. }
  771. // 获取用户的当前设置,判断是否点击了“总是保持以上,不在询问”
  772. // wx.getSetting({
  773. // withSubscriptions: true,//是否获取用户订阅消息的订阅状态,默认false不返回
  774. // success(res){
  775. // debugger
  776. // if(res.subscriptionsSetting.mainSwitch){
  777. // }else{
  778. // }
  779. // }
  780. // })
  781. // uni.showModal({
  782. // title: '温馨提示',
  783. // content: '为更好的与您沟通,小程序需要向您发送通知消息',
  784. // confirmText:"同意",
  785. // cancelText:"拒绝",
  786. // showCancel: false,
  787. // success: function (res) {
  788. // if (res.confirm) {
  789. // //调用订阅消息
  790. // that.requestSubscribe();
  791. // } else if (res.cancel) {
  792. // ///显示第二个弹说明一下
  793. // wx.showModal({
  794. // title: '温馨提示',
  795. // content: '拒绝后您将无法获取实时的交易、物流消息',
  796. // confirmText:"知道了",
  797. // showCancel:false,
  798. // success: function (res) {
  799. // uni.openSetting({ // 打开设置页
  800. // success(res) {
  801. // console.log(res.authSetting)
  802. // }
  803. // });
  804. // }
  805. // });
  806. // }
  807. // }
  808. // });
  809. },
  810. wechatLogin() {
  811. const that = this
  812. that.logining = true
  813. let loginType = 2
  814. uni.showLoading({
  815. title: '正在同步消息',
  816. mask:true
  817. })
  818. uni.login({
  819. provider: 'weixin',
  820. success: (wxres => {
  821. that.$api.request('user', 'thirdPartLogin', {
  822. loginType: loginType,
  823. raw: JSON.stringify(wxres)
  824. }, failres => {
  825. that.$api.msg(failres.errmsg)
  826. uni.hideLoading()
  827. }).then(res => {
  828. console.log("thirdPartLogin:"+res.data.phone)
  829. that.accessToken = res.data.accessToken
  830. that.logining = false
  831. uni.getUserInfo({
  832. lang: 'zh_CN',
  833. success: (e) => {
  834. uni.setStorageSync('userInfo', res.data)
  835. that.$store.commit('login', res.data)
  836. e.userInfo.nickname = e.userInfo.nickName
  837. e.userInfo.cid = uni.getStorageSync("clientId")
  838. console.log(e.userInfo)
  839. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  840. //同步过后
  841. res.data.nickname = e.userInfo.nickName
  842. res.data.avatarUrl = e.userInfo.avatarUrl
  843. res.data.gender = e.userInfo.gender
  844. if(res.data.phone){
  845. res.data.phone = e.userInfo.phone
  846. // that.liangxinLogin()
  847. }
  848. uni.setStorageSync('userInfo', res.data)
  849. that.$store.commit('login', res.data)
  850. })
  851. },
  852. complete: (e) => {
  853. uni.hideLoading()
  854. if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
  855. that.isPhone = true//显示自定义的获取手机权限提示框
  856. that.inputStatus = 'inline'
  857. that.inputContent = ''
  858. }
  859. else{
  860. // uni.switchTab({
  861. // url: '/pages/sale/sale'
  862. // });
  863. uni.switchTab({
  864. url: '/pages/sale/information'
  865. });
  866. console.log("complete")
  867. }
  868. }
  869. })
  870. })
  871. })
  872. })
  873. },
  874. wechatH5Login() {
  875. const that = this
  876. let href = window.location.origin
  877. let page = that.$api.prePage()
  878. let prePath = '/pages/index/index'
  879. if (page) {
  880. prePath = page.__page__.path
  881. }
  882. window.location = 'https://open.weixin.qq.com/connect/oauth2/authorize?'
  883. + 'appid=' + that.$api.defConfig().h5Appid + '&redirect_uri=' + escape(href) + '&response_type=code&scope=snsapi_userinfo&state=' + escape(prePath) + '#wechat_redirect'
  884. },
  885. liangxinLogin(){
  886. const that = this
  887. var userInfoTmp = uni.getStorageSync("userInfo")
  888. console.log('userInfoTmp',userInfoTmp)
  889. that.$socket.login(userInfoTmp.phone, "123456", null, res=>{
  890. console.log('粮信登录',res)
  891. if (res.success) {
  892. that.$socket.showLoginDialog = false
  893. // 缓存用户
  894. that.userData = res.response.data
  895. console.log('userData',that.userData)
  896. that.$u.vuex("userData", that.userData);
  897. // 缓存通讯录
  898. that.$socket.listGuests(that.userData.user.operId, res => {
  899. // #ifdef APP-PLUS
  900. createFSQL(that.userData.user.operId).then();
  901. let contact = res.response.data;
  902. contact.forEach(c=>{
  903. c.members.forEach(m=>{
  904. m.name = c.name;
  905. addFSQL(m, that.userData.user.operId).then();
  906. })
  907. })
  908. // #endif
  909. that.$u.vuex('firendItem', res.response.data)
  910. });
  911. // 缓存消息列表
  912. that.$socket.queryOnlineMessage(that.userData.user.operId,q =>{
  913. let data = q.response.data;
  914. for(var i in data){
  915. initData(data[i].groupMsg.list, data[i].groupInfo.chatId);
  916. }
  917. })
  918. // 缓存链接
  919. that.$socket.getLinks(that.userData.user.operId, res=>{
  920. that.$u.vuex('linkItem',res.response.data)
  921. });
  922. // // 跳转到消息列表
  923. // that.$u.route({
  924. // url: 'pages/home/home',
  925. // type: 'switchTab'
  926. // });
  927. } else {
  928. uni.showModal({
  929. title:res.reason + ",请稍后再试",
  930. showCancel:false
  931. })
  932. }
  933. });
  934. }
  935. },
  936. }
  937. </script>
  938. <style lang='scss' scoped>
  939. .password{
  940. border:none;
  941. outline: none;
  942. }
  943. .apple{
  944. background: #000;
  945. width: 35px;
  946. height: 35px;
  947. padding: 8px;
  948. border-radius: 50%;
  949. vertical-align: middle;
  950. }
  951. page {
  952. background: #fff;
  953. }
  954. .cuIcon-weixin{
  955. background: #39b54a;
  956. color: #fff;
  957. font-size: 18px;
  958. padding: 9px;
  959. border-radius: 50%;
  960. vertical-align: middle;
  961. margin-right:5px;
  962. }
  963. .container {
  964. padding-top: 85px;
  965. position: relative;
  966. width: 100vw;
  967. height: 100vh;
  968. overflow: hidden;
  969. background: url('~@/static/img/login/bg.png');
  970. background-size:100%;
  971. }
  972. .close{
  973. width:20px;height:20px;position:absolute;
  974. right:0px;
  975. }
  976. .close1{
  977. width:20px;height:20px;position:absolute;
  978. right:10px;
  979. top:0;
  980. }
  981. .close2{
  982. width: 15px;
  983. height: 15px;
  984. position: absolute;
  985. right: 19px;
  986. top: 50%;
  987. transform: translateY(-45%);
  988. }
  989. .wrapper {
  990. position: relative;
  991. z-index: 90;
  992. padding-bottom: 40upx;
  993. height:100%;
  994. padding:0 30px;
  995. }
  996. .back-btn {
  997. position: absolute;
  998. left: 40upx;
  999. z-index: 9999;
  1000. padding-top: var(--status-bar-height);
  1001. top: 40upx;
  1002. font-size: 40upx;
  1003. color: $font-color-dark;
  1004. }
  1005. .verificationCode{
  1006. margin-top:20px;
  1007. background:#F5F6F9;
  1008. color:#AFB3BF;
  1009. }
  1010. .verificationCode:after{
  1011. border:none;
  1012. }
  1013. .register{
  1014. position:absolute;
  1015. bottom:20px;
  1016. left:50%;
  1017. transform: translateX(-50%);
  1018. color:#333333;
  1019. height:50px;
  1020. line-height:50px;
  1021. border-radius:30px;border: 1px solid #444444;
  1022. }
  1023. .register:after{
  1024. border:none;
  1025. }
  1026. .verificationCode.active{
  1027. background:#22C572;
  1028. color:#fff;
  1029. }
  1030. .getcode{
  1031. font-size:14px;
  1032. position:absolute;
  1033. right:0;
  1034. top:50%;
  1035. transform: translateY(-50%);
  1036. color:#AFB3BF;
  1037. background:#F5F6F9;
  1038. height:30px;
  1039. line-height:30px;
  1040. }
  1041. .getcode:after{
  1042. border:none;
  1043. }
  1044. uni-navigator{
  1045. display:inline-block;
  1046. color:#22C572;
  1047. }
  1048. .getcode.active{
  1049. background:#22C572;
  1050. color:#fff;
  1051. }
  1052. </style>