login_account_number.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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;align-items: center;' class="flex">
  9. <view class="phone-before-num NumberMedium">+86</view>
  10. <view style='width:85%;'>
  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 { queryData, upData, initData } from '../../util/dbUtil.js'
  38. import {
  39. mapState
  40. } from 'vuex';
  41. export default {
  42. data() {
  43. return {
  44. inputContent: null,
  45. loginType: "wechat",
  46. phone: '',
  47. password: '',
  48. logining: false,
  49. isPhone: false,
  50. isApple: true,
  51. accessToken:'',
  52. params:{
  53. encryptedData:'',
  54. session_key:'',
  55. iv:'',
  56. },
  57. userInfo:{
  58. nickName:'',
  59. avatarUrl:'',
  60. gender:'',
  61. phone:''
  62. },
  63. type:'password',
  64. inputStatus:'none',
  65. verifyCode:null,
  66. sendText:'获取验证码',
  67. sendDisabled: false,
  68. system:'',
  69. platform:'',
  70. userData:undefined,
  71. canIUseProfile:false
  72. }
  73. },
  74. computed: {
  75. ...mapState(['clientId'])
  76. },
  77. onShow() {
  78. // this.loginType = "wechat"
  79. this.$api.logout()
  80. },
  81. onLoad(options) {
  82. if( wx.getUserProfile ){
  83. console.log('--check getUserProfile--OK');
  84. this.canIUseProfile = true;
  85. }
  86. console.log("login on load")
  87. var that = this
  88. that.$api.request('user', 'sendIsApple', {
  89. }).then(res => {
  90. that.isApple = res.data
  91. })
  92. uni.getSystemInfo({
  93. success:(res) => {
  94. // console.log(res)
  95. this.system = res.system // ios
  96. this.platform = res.platform // 14.3
  97. }
  98. })
  99. },
  100. methods: {
  101. passlogin(e){
  102. var that=this
  103. uni.showLoading({
  104. title: '登录中',
  105. mask:true
  106. })
  107. console.log("clinetId",this.clientId)
  108. this.$api.doRequest('get','/commonUser/login',{phone:this.phone,password:this.password,cid:this.clientId}).then(res => {
  109. if(res.data.code==200){
  110. uni.setStorageSync('userInfo', res.data.data)
  111. this.$api.doRequest('post','/commonUser/api/loginQuickly',{mobilePhone: this.phone,
  112. veriCode: "123456",}).then(res1 => {
  113. if(res1.data.code==200){
  114. uni.setStorageSync('pcUserInfo', res1.data.data)
  115. }else{
  116. that.$api.doRequest('post','/commonUser/api/loginQuickly',{mobilePhone: '13333333333',
  117. veriCode: "123456",}).then(res2 => {
  118. uni.setStorageSync('pcUserInfo', res2.data.data)
  119. })
  120. }
  121. })
  122. that.$store.commit('login', res.data.data)
  123. var name = 'userInfo';
  124. var value = res.data.data;
  125. that.$store.commit('$uStore', {
  126. name,
  127. value
  128. });
  129. // that.liangxinLogin()
  130. uni.switchTab({
  131. url: '/pages/sale/information'
  132. });
  133. uni.hideLoading()
  134. }else{
  135. uni.hideLoading()
  136. uni.showToast({
  137. title: res.data.message,
  138. icon:'none',
  139. duration: 2000
  140. })
  141. }
  142. })
  143. .catch(res => {
  144. console.log(res);
  145. });
  146. },
  147. switchover(){
  148. if(this.type=='password'){
  149. this.type='text'
  150. }else{
  151. this.type='password'
  152. }
  153. },
  154. gocode(){
  155. uni.navigateTo({
  156. url:'/pages/public/login'
  157. })
  158. },
  159. forgetpass(){
  160. uni.navigateTo({
  161. url:'/pages/public/reset'
  162. })
  163. },
  164. goregister(){
  165. uni.navigateTo({
  166. url:'/pages/public/register'
  167. })
  168. },
  169. appleLogin(){
  170. var that=this
  171. uni.getProvider({
  172. service: 'oauth',
  173. success: function (res) {
  174. // console.log(res.provider)
  175. if(~res.provider.indexOf('apple')) {
  176. uni.login({
  177. provider: 'apple',
  178. success: loginRes => {
  179. uni.getUserInfo({
  180. provider: 'apple',
  181. success: userInfoRes => {
  182. that.$api.request('user', 'thirdPartLogin', {
  183. loginType: 4/* */,
  184. raw: JSON.stringify(userInfoRes.userInfo)
  185. }, failres => {
  186. that.$api.msg(failres.errmsg)
  187. uni.hideLoading()
  188. }).then(res => {
  189. console.log("thirdPartLogin:"+res.data.phone)
  190. that.accessToken = res.data.accessToken
  191. that.logining = false
  192. uni.getUserInfo({
  193. lang: 'zh_CN',
  194. success: (e) => {
  195. uni.setStorageSync('userInfo', res.data)
  196. that.$store.commit('login', res.data)
  197. e.userInfo.nickname = e.userInfo.nickName
  198. e.userInfo.cid = uni.getStorageSync("clientId")
  199. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  200. //同步过后
  201. res.data.nickname = e.userInfo.nickName
  202. res.data.avatarUrl = e.userInfo.avatarUrl
  203. res.data.gender = e.userInfo.gender
  204. if(!res.data.phone){
  205. res.data.phone = e.userInfo.phone
  206. }
  207. uni.setStorageSync('userInfo', res.data)
  208. that.$store.commit('login', res.data)
  209. })
  210. },
  211. complete: (e) => {
  212. uni.hideLoading()
  213. if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
  214. that.isPhone = true//显示自定义的获取手机权限提示框
  215. that.inputStatus = 'inline'
  216. that.inputContent = ''
  217. }
  218. else{
  219. uni.switchTab({
  220. url: '/pages/sale/sale'
  221. });
  222. console.log("complete")
  223. }
  224. }
  225. })
  226. })
  227. console.log('获取用户信息成功'+JSON.stringify(userInfoRes))
  228. }
  229. })
  230. },
  231. fail: err => {
  232. console.log('apple登录失败' + JSON.stringify(err))
  233. uni.showToast({
  234. title:'登录失败',
  235. icon:'none'
  236. })
  237. }
  238. })
  239. }
  240. },
  241. fail: err => {
  242. uni.showToast({
  243. title:'登录失败',
  244. icon:'none'
  245. })
  246. }
  247. })
  248. },
  249. doGetVerify() {
  250. const that = this
  251. var phone = this.inputContent;
  252. if (!phone || phone.length != 11) {
  253. uni.showToast({
  254. title:'请输入正确手机号!',
  255. icon:'none'
  256. })
  257. return
  258. }
  259. that.$api.request('user', 'sendVerifyCode', {
  260. phone: phone,
  261. }).then(res => {
  262. that.sendDisabled = true
  263. let sec = 60
  264. let interval = setInterval(() => {
  265. sec--;
  266. that.sendText = sec + 's后重发'
  267. if (sec <= 0) {
  268. that.sendDisabled = false
  269. that.sendText = "获取验证码"
  270. clearInterval(interval)
  271. }
  272. }, 1000)
  273. })
  274. },
  275. verifyCodeInput(e){
  276. this.verifyCode = e.detail.value
  277. },
  278. cancel() {
  279. this.inputShow = false
  280. this.inputStatus = 'none'
  281. this.isPhone = false
  282. },
  283. confirm() {
  284. var that = this
  285. if (!this.inputContent || this.inputContent.length != 11) {
  286. uni.showToast({
  287. title:'请输入正确手机号!',
  288. icon:'none'
  289. })
  290. return
  291. }
  292. if (!this.verifyCode) {
  293. uni.showToast({
  294. title:'请输入验证码!',
  295. icon:'none'
  296. })
  297. return
  298. }
  299. this.$api.request('user', 'mergeUser', {
  300. phone: that.inputContent,
  301. verifyCode:that.verifyCode
  302. },failres => {
  303. that.$api.msg(failres.errmsg)
  304. uni.hideLoading()
  305. }).then(res => {
  306. that.accessToken = res.data.accessToken
  307. that.$api.setUserInfo(res.data)
  308. that.logining = false
  309. uni.getUserInfo({
  310. lang: 'zh_CN',
  311. success: (e) => {
  312. uni.setStorageSync('userInfo', res.data)
  313. that.$store.commit('login', res.data)
  314. e.userInfo.nickname = e.userInfo.nickName
  315. e.userInfo.cid = uni.getStorageSync("clientId")
  316. console.log(e.userInfo)
  317. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  318. //同步过后
  319. res.data.nickname = e.userInfo.nickName
  320. res.data.avatarUrl = e.userInfo.avatarUrl
  321. res.data.gender = e.userInfo.gender
  322. res.data.phone = e.userInfo.phone
  323. uni.setStorageSync('userInfo', res.data)
  324. that.$store.commit('login', res.data)
  325. // that.liangxinLogin()
  326. })
  327. },
  328. complete: (e) => {
  329. uni.switchTab({
  330. url: '/pages/sale/information'
  331. });
  332. uni.hideLoading()
  333. that.isPhone=false
  334. uni.navigateBack()
  335. }
  336. })
  337. })
  338. },
  339. ...mapMutations(['login']),
  340. inputChange(e) {
  341. const key = e.currentTarget.dataset.key;
  342. this[key] = e.detail.value;
  343. },
  344. chooseLoginType(type) {
  345. this.loginType = type
  346. },
  347. navBack() {
  348. uni.navigateBack();
  349. },
  350. toRegist() {
  351. console.log(11)
  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. // debugger
  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. .close{
  816. width:20px;height:20px;position:absolute;
  817. right:0px;
  818. }
  819. .close1{
  820. width:20px;height:20px;position:absolute;
  821. right:10px;
  822. top:0;
  823. }
  824. .close2{
  825. width: 15px;
  826. height: 15px;
  827. position: absolute;
  828. right: 19px;
  829. top: 50%;
  830. transform: translateY(-45%);
  831. }
  832. .password{
  833. border:none;
  834. outline:none;
  835. }
  836. .cuIcon-weixin{
  837. background: #39b54a;
  838. color: #fff;
  839. font-size: 18px;
  840. padding: 9px;
  841. border-radius: 50%;
  842. vertical-align: middle;
  843. margin-right:5px;
  844. }
  845. .container {
  846. padding-top: 85px;
  847. position: relative;
  848. width: 100vw;
  849. height: 100vh;
  850. overflow: hidden;
  851. background: url('~@/static/img/login/bg.png');
  852. background-size:100%;
  853. }
  854. .wrapper {
  855. position: relative;
  856. z-index: 90;
  857. padding-bottom: 40upx;
  858. height:100%;
  859. padding:0 30px;
  860. }
  861. .back-btn {
  862. position: absolute;
  863. left: 40upx;
  864. z-index: 9999;
  865. padding-top: var(--status-bar-height);
  866. top: 40upx;
  867. font-size: 40upx;
  868. color: $font-color-dark;
  869. }
  870. .verificationCode{
  871. margin-top:20px;
  872. background:#F5F6F9;
  873. color:#AFB3BF;
  874. }
  875. .verificationCode:after{
  876. border:none;
  877. }
  878. .verificationCode.active{
  879. background:#22C572;
  880. color:#fff;
  881. }
  882. .register{
  883. /* position:absolute; */
  884. bottom:20px;
  885. left:50%;
  886. transform: translateX(-50%);
  887. color:#333333;
  888. height:50px;
  889. line-height:50px;
  890. border-radius:30px;border: 1px solid #444444;
  891. }
  892. .register:after{
  893. border:none;
  894. }
  895. .phone-before-num{
  896. font-size: 34rpx;
  897. color: #333333;
  898. border-right: 1px solid #E8E9ED;
  899. padding-right: 20rpx;
  900. }
  901. .phone-number{
  902. margin-left: 20rpx;
  903. font-size: 34rpx;
  904. font-family: DINPro-Medium, DINPro;
  905. font-weight: 500;
  906. color: #333333;
  907. }
  908. </style>