login.vue 26 KB

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