register.vue 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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','/auth/api/loginEnhanced',{companyName: "易粮易运",
  222. password: "y123456",
  223. username: "13333333333"}).then(res1 => {
  224. uni.setStorageSync('pcUserInfo', res1.data.data)
  225. })
  226. uni.setStorageSync('userInfo', res.data)
  227. that.$store.commit('login', res.data)
  228. // that.liangxinLogin()
  229. uni.switchTab({
  230. url: '/pages/sale/information'
  231. });
  232. }else{
  233. uni.showToast({
  234. title: res.data.message,
  235. icon:'none',
  236. duration: 2000
  237. })
  238. }
  239. uni.hideLoading()
  240. })
  241. .catch(res => {
  242. console.log(res);
  243. });
  244. }
  245. })
  246. .catch(res => {
  247. console.log(res);
  248. });
  249. },
  250. consent(){
  251. this.consentStatus=!this.consentStatus
  252. uni.setStorage({
  253. key: 'policyStorageKey',
  254. data: this.consentStatus
  255. });
  256. },
  257. switchover(){
  258. if(this.type=='password'){
  259. this.type='text'
  260. }else{
  261. this.type='password'
  262. }
  263. },
  264. gocode(){
  265. uni.navigateTo({
  266. url:'/pages/public/login'
  267. })
  268. },
  269. forgetpass(){
  270. uni.navigateTo({
  271. url:'/pages/public/reset'
  272. })
  273. },
  274. phonelogin(){
  275. var that=this
  276. uni.showLoading({
  277. title: '登录中',
  278. mask:true
  279. })
  280. console.log("clientid",that.clientId)
  281. this.$api.request('user', 'login',{
  282. password:that.password,
  283. phone:that.phone,
  284. cid:that.clientId
  285. }, failres => {
  286. that.$api.msg(failres.errmsg)
  287. uni.hideLoading()
  288. }).then(res => {
  289. console.log(res)
  290. uni.setStorageSync('userInfo', res.data)
  291. that.$store.commit('login', res.data)
  292. // that.liangxinLogin()
  293. uni.switchTab({
  294. url: '/pages/sale/information'
  295. });
  296. uni.hideLoading()
  297. })
  298. },
  299. appleLogin(){
  300. var that=this
  301. uni.getProvider({
  302. service: 'oauth',
  303. success: function (res) {
  304. // console.log(res.provider)
  305. if(~res.provider.indexOf('apple')) {
  306. uni.login({
  307. provider: 'apple',
  308. success: loginRes => {
  309. uni.getUserInfo({
  310. provider: 'apple',
  311. success: userInfoRes => {
  312. that.$api.request('user', 'thirdPartLogin', {
  313. loginType: 4/* */,
  314. raw: JSON.stringify(userInfoRes.userInfo)
  315. }, failres => {
  316. that.$api.msg(failres.errmsg)
  317. uni.hideLoading()
  318. }).then(res => {
  319. console.log("thirdPartLogin:"+res.data.phone)
  320. that.accessToken = res.data.accessToken
  321. that.logining = false
  322. uni.getUserInfo({
  323. lang: 'zh_CN',
  324. success: (e) => {
  325. uni.setStorageSync('userInfo', res.data)
  326. that.$store.commit('login', res.data)
  327. e.userInfo.nickname = e.userInfo.nickName
  328. e.userInfo.cid = uni.getStorageSync("clientId")
  329. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  330. //同步过后
  331. res.data.nickname = e.userInfo.nickName
  332. res.data.avatarUrl = e.userInfo.avatarUrl
  333. res.data.gender = e.userInfo.gender
  334. if(!res.data.phone){
  335. res.data.phone = e.userInfo.phone
  336. }
  337. uni.setStorageSync('userInfo', res.data)
  338. that.$store.commit('login', res.data)
  339. })
  340. },
  341. complete: (e) => {
  342. uni.hideLoading()
  343. if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
  344. that.isPhone = true//显示自定义的获取手机权限提示框
  345. that.inputStatus = 'inline'
  346. that.inputContent = ''
  347. }
  348. else{
  349. uni.switchTab({
  350. url: '/pages/sale/sale'
  351. });
  352. console.log("complete")
  353. }
  354. }
  355. })
  356. })
  357. console.log('获取用户信息成功'+JSON.stringify(userInfoRes))
  358. }
  359. })
  360. },
  361. fail: err => {
  362. console.log('apple登录失败' + JSON.stringify(err))
  363. uni.showToast({
  364. title:'登录失败',
  365. icon:'none'
  366. })
  367. }
  368. })
  369. }
  370. },
  371. fail: err => {
  372. uni.showToast({
  373. title:'登录失败',
  374. icon:'none'
  375. })
  376. }
  377. })
  378. },
  379. doGetVerify() {
  380. const that = this
  381. var phone = this.inputContent;
  382. if (!phone || phone.length != 11) {
  383. uni.showToast({
  384. title:'请输入正确手机号!',
  385. icon:'none'
  386. })
  387. return
  388. }
  389. that.$api.request('user', 'sendVerifyCode', {
  390. phone: phone,
  391. }).then(res => {
  392. that.sendDisabled = true
  393. let sec = 60
  394. let interval = setInterval(() => {
  395. sec--;
  396. that.sendText = sec + 's后重发'
  397. if (sec <= 0) {
  398. that.sendDisabled = false
  399. that.sendText = "获取验证码"
  400. clearInterval(interval)
  401. }
  402. }, 1000)
  403. })
  404. },
  405. verifyCodeInput(e){
  406. this.verifyCode = e.detail.value
  407. },
  408. cancel() {
  409. this.inputShow = false
  410. this.inputStatus = 'none'
  411. this.isPhone = false
  412. },
  413. confirm() {
  414. var that = this
  415. if (!this.inputContent || this.inputContent.length != 11) {
  416. uni.showToast({
  417. title:'请输入正确手机号!',
  418. icon:'none'
  419. })
  420. return
  421. }
  422. if (!this.verifyCode) {
  423. uni.showToast({
  424. title:'请输入验证码!',
  425. icon:'none'
  426. })
  427. return
  428. }
  429. this.$api.request('user', 'mergeUser', {
  430. phone: that.inputContent,
  431. verifyCode:that.verifyCode
  432. },failres => {
  433. that.$api.msg(failres.errmsg)
  434. uni.hideLoading()
  435. }).then(res => {
  436. that.accessToken = res.data.accessToken
  437. that.$api.setUserInfo(res.data)
  438. that.logining = false
  439. uni.getUserInfo({
  440. lang: 'zh_CN',
  441. success: (e) => {
  442. uni.setStorageSync('userInfo', res.data)
  443. that.$store.commit('login', res.data)
  444. e.userInfo.nickname = e.userInfo.nickName
  445. e.userInfo.cid = uni.getStorageSync("clientId")
  446. console.log(e.userInfo)
  447. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  448. //同步过后
  449. res.data.nickname = e.userInfo.nickName
  450. res.data.avatarUrl = e.userInfo.avatarUrl
  451. res.data.gender = e.userInfo.gender
  452. res.data.phone = e.userInfo.phone
  453. uni.setStorageSync('userInfo', res.data)
  454. that.$store.commit('login', res.data)
  455. // that.liangxinLogin()
  456. })
  457. },
  458. complete: (e) => {
  459. uni.switchTab({
  460. url: '/pages/sale/information'
  461. });
  462. uni.hideLoading()
  463. that.isPhone=false
  464. uni.navigateBack()
  465. }
  466. })
  467. })
  468. },
  469. ...mapMutations(['login']),
  470. inputChange(e) {
  471. const key = e.currentTarget.dataset.key;
  472. this[key] = e.detail.value;
  473. },
  474. chooseLoginType(type) {
  475. this.loginType = type
  476. },
  477. navBack() {
  478. uni.navigateBack();
  479. },
  480. toRegist() {
  481. uni.redirectTo({
  482. url: '/pages/public/register'
  483. })
  484. },
  485. ///发起消息订阅
  486. requestSubscribe(){
  487. const that = this
  488. wx.requestSubscribeMessage({
  489. tmplIds: ['xL_uZEqJz4QP1FbnlzQWAiO2zVBn3Qeu8JwLVOU3hU0','8cVkckXi_8zfHeScXRHhjN6cgZFYYCWIMPDTiPWagXY','IE7WxBsv-fDvPWSrng-97lGWtvZf9rHuECBlhRLlWxI'],//
  490. success :(res)=>{
  491. console.log("订阅消息 成功 "+res);
  492. },
  493. fail :(errMsg) =>{
  494. console.log("订阅消息 失败 "+errMsg.errMsg);
  495. },
  496. complete:(errMsg)=>{
  497. console.log("订阅消息 完成 "+errMsg);
  498. }
  499. });
  500. },
  501. getPhoneNumber(e) {
  502. console.log(e)
  503. if (e.mp.detail.errMsg==="getPhoneNumber:ok") {
  504. this.isPhone = false
  505. this.params.iv = e.mp.detail.iv
  506. this.params.encryptedData = e.mp.detail.encryptedData
  507. this.params.session_key = this.accessToken
  508. console.log(this.params)
  509. this.getTokenAsync(this.params)
  510. }
  511. },
  512. // 请求后获取token
  513. async getTokenAsync(params) {
  514. let that = this
  515. this.$api.request('user', 'getPhoneNumber', params).then(res => {
  516. if(res.data.phoneNumber){
  517. that.userInfo.phone = res.data.phoneNumber
  518. }
  519. if(res.data.unionId){
  520. that.userInfo.unionId = res.data.unionId
  521. }
  522. that.userInfo.cid = uni.getStorageSync("clientId")
  523. console.log(that.userInfo)
  524. that.$api.request('user', 'syncUserInfo', that.userInfo).then(syncRes => {
  525. uni.setStorageSync('userInfo', that.userInfo)
  526. that.$store.commit('login', that.userInfo)
  527. that.$api.setUserInfo(that.userInfo)
  528. uni.hideLoading()
  529. // that.liangxinLogin()
  530. })
  531. if(res.data.phoneNumber){
  532. uni.switchTab({
  533. url: '/pages/sale/information'
  534. });
  535. }
  536. })
  537. },
  538. async toLogin() {
  539. this.verifyCode = ''
  540. const that = this
  541. if (that.phone.length !== 11) {
  542. that.$api.msg('请输入11位中国手机号')
  543. } else if (that.password.length < 8) {
  544. that.$api.msg('密码至少8位')
  545. } else {
  546. that.logining = true;
  547. //#ifdef MP-WEIXIN
  548. //若是小程序平台,则获取到openId。整个过程是静默完成的
  549. uni.login({
  550. provider: 'weixin',
  551. success: (wxres => {
  552. that.$api.request('user', 'login', {
  553. phone: that.phone,
  554. password: that.password,
  555. loginType: 1,
  556. raw: JSON.stringify(wxres)
  557. }, failres => {
  558. that.logining = false
  559. uni.showToast({
  560. title: failres.errmsg,
  561. icon: "none"
  562. });
  563. }).then(res => {
  564. that.logining = false
  565. that.$store.commit('login', res.data)
  566. uni.setStorageSync('userInfo', res.data)
  567. if (that.$api.prePage().lodaData) {
  568. that.$api.prePage().loadData()
  569. }
  570. uni.navigateBack()
  571. })
  572. })
  573. })
  574. //#endif
  575. //#ifdef APP-PLUS || H5
  576. //若是App登录,则不需要保存OpenId。可直接登录
  577. that.$api.request('user', 'login', {
  578. phone: that.phone,
  579. password: that.password,
  580. }, failres => {
  581. that.logining = false
  582. uni.showToast({
  583. title: failres.errmsg,
  584. icon: "none"
  585. });
  586. }).then(res => {
  587. that.logining = false
  588. that.$store.commit('login', res.data)
  589. uni.setStorageSync('userInfo', res.data)
  590. if (that.$api.prePage().lodaData) {
  591. that.$api.prePage().loadData()
  592. }
  593. uni.navigateBack()
  594. })
  595. //#endif
  596. }
  597. },
  598. miniWechatLogin(e) {
  599. const that = this
  600. //旧版本方式
  601. if( this.canIUseProfile == false ){
  602. console.log("旧版本方式")
  603. //获取授权信息
  604. if(e.detail.userInfo){
  605. console.log('用户允许了授权')
  606. console.log( e.detail.userInfo ); //1.拿到基本的微信信息!!
  607. uni.showLoading({
  608. title: '加载中',
  609. mask:true
  610. })
  611. that.logining = true
  612. let loginType = 1
  613. let userInfo = e.detail.userInfo
  614. uni.login({
  615. provider: 'weixin',
  616. success: (wxres => {
  617. that.logining = false
  618. that.$api.request('user', 'thirdPartLogin', {
  619. loginType: loginType,
  620. raw: JSON.stringify(wxres)
  621. }, failres => {
  622. that.$api.msg(failres.errmsg)
  623. uni.hideLoading()
  624. }).then(res => {
  625. that.accessToken = res.data.accessToken
  626. that.$api.setUserInfo(res.data)
  627. that.userInfo = res.data
  628. uni.getUserInfo({
  629. lang: 'zh_CN',
  630. provider: 'weixin',
  631. withCredentials:true,
  632. success: (e) => {
  633. that.params.iv = e.iv
  634. that.params.encryptedData = e.encryptedData
  635. that.params.session_key = that.accessToken
  636. console.log(this.params)
  637. that.getTokenAsync(this.params)
  638. uni.setStorageSync('userInfo', res.data)
  639. that.$store.commit('login', res.data)
  640. e.userInfo.nickname = e.userInfo.nickName
  641. if(e.userInfo.phone == undefined){
  642. e.userInfo.phone = ''
  643. }
  644. e.userInfo.cid = uni.getStorageSync("clientId")
  645. console.log(e.userInfo)
  646. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  647. //同步过后
  648. res.data.nickname = userInfo.nickName
  649. res.data.avatarUrl = userInfo.avatarUrl
  650. res.data.gender = userInfo.gender
  651. if(userInfo.phone){
  652. res.data.phone = userInfo.phone
  653. // that.liangxinLogin()
  654. }
  655. uni.setStorageSync('userInfo', res.data)
  656. that.$store.commit('login', res.data)
  657. that.$api.setUserInfo(res.data)
  658. uni.hideLoading()
  659. // uni.navigateBack()
  660. })
  661. },
  662. complete: (e) => {
  663. uni.hideLoading()
  664. if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
  665. that.isPhone = true//显示自定义的获取手机权限提示框
  666. that.inputStatus = 'inline'
  667. that.inputContent = ''
  668. }
  669. else{
  670. uni.setStorageSync('PageCur', "sale");
  671. // uni.switchTab({
  672. // url: '/pages/sale/sale'
  673. // });
  674. uni.switchTab({
  675. url: '/pages/sale/information'
  676. });
  677. console.log("complete")
  678. }
  679. }
  680. })
  681. })
  682. }),
  683. })
  684. }
  685. //新版本方式
  686. }else{
  687. console.log("新版本方式")
  688. uni.showLoading({
  689. title: '加载中',
  690. mask:true
  691. })
  692. that.logining = true
  693. let loginType = 1
  694. wx.getUserProfile({
  695. desc : '用于完善用户资料',
  696. lang : 'zh_CN',
  697. success : function( proRes ){
  698. console.log('proRes.userInfo',proRes.userInfo)
  699. uni.login({
  700. provider: 'weixin',
  701. success: (wxres => {
  702. that.logining = false
  703. that.$api.request('user', 'thirdPartLogin', {
  704. loginType: loginType,
  705. raw: JSON.stringify(wxres)
  706. }, failres => {
  707. that.$api.msg(failres.errmsg)
  708. uni.hideLoading()
  709. }).then(res => {
  710. console.log('res+++++',res)
  711. that.accessToken = res.data.accessToken
  712. that.$api.setUserInfo(res.data)
  713. that.userInfo = res.data
  714. // that.params.iv = proRes.iv
  715. // that.params.encryptedData = proRes.encryptedData
  716. // that.params.session_key = that.accessToken
  717. // console.log(that.params)
  718. // that.getTokenAsync(that.params)
  719. uni.setStorageSync('userInfo', res.data)
  720. that.$store.commit('login', res.data)
  721. if(proRes.userInfo.phone == undefined){
  722. proRes.userInfo.phone = ''
  723. }
  724. res.data.cid = uni.getStorageSync("clientId")
  725. that.$api.request('user', 'syncUserInfo', res.data).then(syncRes => {
  726. //同步过后
  727. res.data.nickname = proRes.userInfo.nickName
  728. res.data.avatarUrl = proRes.userInfo.avatarUrl
  729. res.data.gender = proRes.userInfo.gender
  730. if(proRes.userInfo.phone){
  731. res.data.phone = proRes.userInfo.phone
  732. }
  733. uni.setStorageSync('userInfo', res.data)
  734. that.$store.commit('login', res.data)
  735. that.$api.setUserInfo(res.data)
  736. uni.hideLoading()
  737. if(!that.userInfo.phone||that.userInfo.phone==""||that.userInfo.phone ==undefined){
  738. that.isPhone = true//显示自定义的获取手机权限提示框
  739. that.inputStatus = 'inline'
  740. that.inputContent = ''
  741. }
  742. else{
  743. uni.setStorageSync('PageCur', "sale");
  744. // uni.switchTab({
  745. // url: '/pages/sale/sale'
  746. // });
  747. uni.reLaunch({
  748. url: '/pages/sale/information'
  749. });
  750. console.log("complete")
  751. // that.liangxinLogin()
  752. }
  753. })
  754. console.log( 'wx.getUserProfile=>用户允许了授权' );
  755. })
  756. })
  757. })
  758. },
  759. fail : function( res ){
  760. console.log('wx.getUserProfile=>用户拒绝了授权');
  761. console.log( res );
  762. }
  763. });
  764. }
  765. // 获取用户的当前设置,判断是否点击了“总是保持以上,不在询问”
  766. // wx.getSetting({
  767. // withSubscriptions: true,//是否获取用户订阅消息的订阅状态,默认false不返回
  768. // success(res){
  769. // debugger
  770. // if(res.subscriptionsSetting.mainSwitch){
  771. // }else{
  772. // }
  773. // }
  774. // })
  775. // uni.showModal({
  776. // title: '温馨提示',
  777. // content: '为更好的与您沟通,小程序需要向您发送通知消息',
  778. // confirmText:"同意",
  779. // cancelText:"拒绝",
  780. // showCancel: false,
  781. // success: function (res) {
  782. // if (res.confirm) {
  783. // //调用订阅消息
  784. // that.requestSubscribe();
  785. // } else if (res.cancel) {
  786. // ///显示第二个弹说明一下
  787. // wx.showModal({
  788. // title: '温馨提示',
  789. // content: '拒绝后您将无法获取实时的交易、物流消息',
  790. // confirmText:"知道了",
  791. // showCancel:false,
  792. // success: function (res) {
  793. // uni.openSetting({ // 打开设置页
  794. // success(res) {
  795. // console.log(res.authSetting)
  796. // }
  797. // });
  798. // }
  799. // });
  800. // }
  801. // }
  802. // });
  803. },
  804. wechatLogin() {
  805. const that = this
  806. that.logining = true
  807. let loginType = 2
  808. uni.showLoading({
  809. title: '正在同步消息',
  810. mask:true
  811. })
  812. uni.login({
  813. provider: 'weixin',
  814. success: (wxres => {
  815. that.$api.request('user', 'thirdPartLogin', {
  816. loginType: loginType,
  817. raw: JSON.stringify(wxres)
  818. }, failres => {
  819. that.$api.msg(failres.errmsg)
  820. uni.hideLoading()
  821. }).then(res => {
  822. console.log("thirdPartLogin:"+res.data.phone)
  823. that.accessToken = res.data.accessToken
  824. that.logining = false
  825. uni.getUserInfo({
  826. lang: 'zh_CN',
  827. success: (e) => {
  828. uni.setStorageSync('userInfo', res.data)
  829. that.$store.commit('login', res.data)
  830. e.userInfo.nickname = e.userInfo.nickName
  831. e.userInfo.cid = uni.getStorageSync("clientId")
  832. console.log(e.userInfo)
  833. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  834. //同步过后
  835. res.data.nickname = e.userInfo.nickName
  836. res.data.avatarUrl = e.userInfo.avatarUrl
  837. res.data.gender = e.userInfo.gender
  838. if(res.data.phone){
  839. res.data.phone = e.userInfo.phone
  840. // that.liangxinLogin()
  841. }
  842. uni.setStorageSync('userInfo', res.data)
  843. that.$store.commit('login', res.data)
  844. })
  845. },
  846. complete: (e) => {
  847. uni.hideLoading()
  848. if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
  849. that.isPhone = true//显示自定义的获取手机权限提示框
  850. that.inputStatus = 'inline'
  851. that.inputContent = ''
  852. }
  853. else{
  854. // uni.switchTab({
  855. // url: '/pages/sale/sale'
  856. // });
  857. uni.switchTab({
  858. url: '/pages/sale/information'
  859. });
  860. console.log("complete")
  861. }
  862. }
  863. })
  864. })
  865. })
  866. })
  867. },
  868. wechatH5Login() {
  869. const that = this
  870. let href = window.location.origin
  871. let page = that.$api.prePage()
  872. let prePath = '/pages/index/index'
  873. if (page) {
  874. prePath = page.__page__.path
  875. }
  876. window.location = 'https://open.weixin.qq.com/connect/oauth2/authorize?'
  877. + 'appid=' + that.$api.defConfig().h5Appid + '&redirect_uri=' + escape(href) + '&response_type=code&scope=snsapi_userinfo&state=' + escape(prePath) + '#wechat_redirect'
  878. },
  879. liangxinLogin(){
  880. const that = this
  881. var userInfoTmp = uni.getStorageSync("userInfo")
  882. console.log('userInfoTmp',userInfoTmp)
  883. that.$socket.login(userInfoTmp.phone, "123456", null, res=>{
  884. console.log('粮信登录',res)
  885. if (res.success) {
  886. that.$socket.showLoginDialog = false
  887. // 缓存用户
  888. that.userData = res.response.data
  889. console.log('userData',that.userData)
  890. that.$u.vuex("userData", that.userData);
  891. // 缓存通讯录
  892. that.$socket.listGuests(that.userData.user.operId, res => {
  893. // #ifdef APP-PLUS
  894. createFSQL(that.userData.user.operId).then();
  895. let contact = res.response.data;
  896. contact.forEach(c=>{
  897. c.members.forEach(m=>{
  898. m.name = c.name;
  899. addFSQL(m, that.userData.user.operId).then();
  900. })
  901. })
  902. // #endif
  903. that.$u.vuex('firendItem', res.response.data)
  904. });
  905. // 缓存消息列表
  906. that.$socket.queryOnlineMessage(that.userData.user.operId,q =>{
  907. let data = q.response.data;
  908. for(var i in data){
  909. initData(data[i].groupMsg.list, data[i].groupInfo.chatId);
  910. }
  911. })
  912. // 缓存链接
  913. that.$socket.getLinks(that.userData.user.operId, res=>{
  914. that.$u.vuex('linkItem',res.response.data)
  915. });
  916. // // 跳转到消息列表
  917. // that.$u.route({
  918. // url: 'pages/home/home',
  919. // type: 'switchTab'
  920. // });
  921. } else {
  922. uni.showModal({
  923. title:res.reason + ",请稍后再试",
  924. showCancel:false
  925. })
  926. }
  927. });
  928. }
  929. },
  930. }
  931. </script>
  932. <style lang='scss' scoped>
  933. .password{
  934. border:none;
  935. outline: none;
  936. }
  937. .apple{
  938. background: #000;
  939. width: 35px;
  940. height: 35px;
  941. padding: 8px;
  942. border-radius: 50%;
  943. vertical-align: middle;
  944. }
  945. page {
  946. background: #fff;
  947. }
  948. .cuIcon-weixin{
  949. background: #39b54a;
  950. color: #fff;
  951. font-size: 18px;
  952. padding: 9px;
  953. border-radius: 50%;
  954. vertical-align: middle;
  955. margin-right:5px;
  956. }
  957. .container {
  958. padding-top: 85px;
  959. position: relative;
  960. width: 100vw;
  961. height: 100vh;
  962. overflow: hidden;
  963. background: url('~@/static/img/login/bg.png');
  964. background-size:100%;
  965. }
  966. .close{
  967. width:20px;height:20px;position:absolute;
  968. right:0px;
  969. }
  970. .close1{
  971. width:20px;height:20px;position:absolute;
  972. right:10px;
  973. top:0;
  974. }
  975. .close2{
  976. width: 15px;
  977. height: 15px;
  978. position: absolute;
  979. right: 19px;
  980. top: 50%;
  981. transform: translateY(-45%);
  982. }
  983. .wrapper {
  984. position: relative;
  985. z-index: 90;
  986. padding-bottom: 40upx;
  987. height:100%;
  988. padding:0 30px;
  989. }
  990. .back-btn {
  991. position: absolute;
  992. left: 40upx;
  993. z-index: 9999;
  994. padding-top: var(--status-bar-height);
  995. top: 40upx;
  996. font-size: 40upx;
  997. color: $font-color-dark;
  998. }
  999. .verificationCode{
  1000. margin-top:20px;
  1001. background:#F5F6F9;
  1002. color:#AFB3BF;
  1003. }
  1004. .verificationCode:after{
  1005. border:none;
  1006. }
  1007. .register{
  1008. position:absolute;
  1009. bottom:20px;
  1010. left:50%;
  1011. transform: translateX(-50%);
  1012. color:#333333;
  1013. height:50px;
  1014. line-height:50px;
  1015. border-radius:30px;border: 1px solid #444444;
  1016. }
  1017. .register:after{
  1018. border:none;
  1019. }
  1020. .verificationCode.active{
  1021. background:#22C572;
  1022. color:#fff;
  1023. }
  1024. .getcode{
  1025. font-size:14px;
  1026. position:absolute;
  1027. right:0;
  1028. top:50%;
  1029. transform: translateY(-50%);
  1030. color:#AFB3BF;
  1031. background:#F5F6F9;
  1032. height:30px;
  1033. line-height:30px;
  1034. }
  1035. .getcode:after{
  1036. border:none;
  1037. }
  1038. uni-navigator{
  1039. display:inline-block;
  1040. color:#22C572;
  1041. }
  1042. .getcode.active{
  1043. background:#22C572;
  1044. color:#fff;
  1045. }
  1046. </style>