reset.vue 27 KB

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