register.vue 30 KB

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