register.vue 30 KB

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