reset.vue 26 KB

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