register.vue 27 KB

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