login_account_number.vue 27 KB

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