register.vue 30 KB

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