login.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <template>
  2. <view class="content" v-if="idfd==1">
  3. <view class="header">
  4. <image :src="staticUrl+'logo.png'"></image>
  5. </view>
  6. <!-- #ifndef MP-TOUTIAO -->
  7. <view class="list">
  8. <view class="list-call">
  9. <image class="img" src="/static/shilu-login/1.png"></image>
  10. <input class="sl-input" v-model="mobile" type="number" maxlength="11" placeholder="输入手机号" />
  11. </view>
  12. <view class="list-call">
  13. <image class="img" src="/static/shilu-login/2.png"></image>
  14. <input class="sl-input" v-model="password" type="text" maxlength="32" placeholder="输入密码" password="true" />
  15. </view>
  16. </view>
  17. <view class="button-login" hover-class="button-hover" @tap="bindLogin()">
  18. <text style="font-size: 40upx;">登录</text>
  19. </view>
  20. <!-- #ifndef MP-WEIXIN -->
  21. <view class="agreenment">
  22. <navigator url="reg" open-type="navigate">注册账户</navigator>
  23. </view>
  24. <!-- #endif -->
  25. <!-- #endif -->
  26. <!-- #ifdef MP-WEIXIN -->
  27. <!-- <view class="list" style="margin-top: 10px; color: #666; font-size: 14px;text-align: center;">openid:{{openid}}</view> -->
  28. <button class="button-login" @click="getUserInfo1()" style="margin-top: 35rpx; font-size: 26upx; color: #fff; height: 80rpx; line-height: 80rpx;">获取微信授权</button>
  29. <!-- #endif -->
  30. <!-- #ifdef MP-TOUTIAO -->
  31. <!-- <view class="list" style="margin-top: 10px; color: #666; font-size: 14px;text-align: center;">openid:{{openid}}</view> -->
  32. <!-- <button v-if="islogin" class="button-login2" @click="getUserdy()" style="margin-top:80rpx; font-size: 26upx; color: #fff; height: 80rpx; line-height: 80rpx;">登录</button> -->
  33. <button v-if="!islogin" class="button-login" @click="douyinglogin()" style="margin-top:80rpx; font-size: 26upx; color: #fff; height: 80rpx; line-height: 80rpx;">获取授权</button>
  34. <view class="preview-wrap" :style="{display: isdl ? 'block' : 'none'}">
  35. <view class="preview">
  36. <view class="hint ft16">获取授权成功</view>
  37. <button class="button-login2" @click="getUserdy()" style="margin-top:40rpx; font-size: 26upx; color: #fff; height: 80rpx; line-height: 80rpx;">立即登录</button>
  38. </view>
  39. </view>
  40. <!-- #endif -->
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. mobile: '',
  48. password: '',
  49. openid:'',
  50. unionid:'',
  51. userinfowx:'',
  52. idfd:1,
  53. fxpid:0,
  54. staticUrl:'',
  55. islogin:false,
  56. isdl:false,
  57. code:'',
  58. anonymousCode:'',
  59. gender:0,
  60. nickName:'',
  61. avatarUrl:'',
  62. };
  63. },
  64. onLoad(e) {
  65. this.staticUrl=this.configs.staticUrl
  66. this.avatarUrl=this.configs.staticUrl
  67. if(e.fxpid){
  68. this.fxpid=e.fxpid
  69. if(e.fxpid>0){
  70. uni.setStorage({
  71. key: 'fxpid',
  72. data: e.fxpid
  73. })
  74. }
  75. }
  76. //#ifdef H5
  77. var ua = window.navigator.userAgent.toLowerCase();
  78. if(ua.match(/MicroMessenger/i) == 'micromessenger'){
  79. this.idfd=0
  80. window.open(this.configs.webUrl+'/login.php', "_self")
  81. }
  82. //#endif
  83. },
  84. methods: {
  85. dyxx(){
  86. //#ifdef MP-WEIXIN
  87. // uni.requestSubscribeMessage({
  88. // tmplIds: ['wAqsuRFgYS9XBJ2OmBgVYgZ-YrpOkS0dfo-WxQuv41c'],
  89. // success (res) {
  90. // /*uni.showModal({
  91. // title: '提醒',
  92. // content: JSON.stringify(res),
  93. // showCancel: false,
  94. // confirmText: "确定",
  95. // success: function (res) {
  96. // if (res.confirm) {
  97. // //uni.navigateBack();
  98. // } else if (res.cancel) {
  99. // }
  100. // }
  101. // });*/
  102. // },
  103. // fail: (data) => {
  104. // uni.showModal({
  105. // title: '提醒',
  106. // content: JSON.stringify(data),
  107. // showCancel: false,
  108. // confirmText: "确定",
  109. // success: function (res) {
  110. // if (res.confirm) {
  111. // //uni.navigateBack();
  112. // } else if (res.cancel) {
  113. // }
  114. // }
  115. // });
  116. // }
  117. // })
  118. //#endif
  119. },
  120. async bindLogin() {
  121. let _this =this
  122. if(!this.mobile){
  123. uni.showToast({ title: '手机号不能为空',icon:"none" });
  124. this.userfocus= true
  125. return false;
  126. }
  127. if(!this.password){
  128. uni.showToast({ title: '密码不能为空',icon:"none" });
  129. this.paswfocus= true
  130. return false;
  131. }
  132. let data = {'account':this.mobile,'password':this.password};
  133. // #ifdef APP-PLUS
  134. var inf = plus.push.getClientInfo();
  135. if(inf.clientid){data.clientid=inf.clientid}
  136. if(plus.os.name == 'iOS') {data.iostoken=inf.token}
  137. data.issb=plus.os.name
  138. // #endif
  139. if(this.openid){
  140. data.openid=this.openid;
  141. }
  142. let [err,res] =await this.$httpas.get('/api/user/login',data);
  143. if (!this.$httpas.errorCheck(err,res)) return;
  144. if(res.data.code === 1){
  145. if(res.data.data.userinfo.avatar){
  146. var str = res.data.data.userinfo.avatar;
  147. if(str.indexOf("data:image") != -1){
  148. var avatar='';
  149. }else{
  150. if(str.indexOf("http") != -1){
  151. avatar=res.data.data.userinfo.avatar;
  152. }else{
  153. avatar=this.configs.imgUrl+res.data.data.userinfo.avatar;
  154. }
  155. }
  156. }else{
  157. var avatar='';
  158. }
  159. uni.setStorage({//缓存配置信息
  160. key: 'avatar',
  161. data: avatar
  162. })
  163. uni.setStorage({//缓存配置信息
  164. key: 'userinfo',
  165. data: res.data.data.userinfo
  166. })
  167. uni.setStorage({//缓存配置信息
  168. key: 'config',
  169. data: res.data.data.config
  170. })
  171. uni.showModal({
  172. title: '温馨提示',
  173. content: res.data.msg,
  174. showCancel: false,
  175. confirmText: "确定",
  176. success: function (res) {
  177. if (res.confirm) {
  178. //_this.dyxx()
  179. uni.navigateBack();
  180. } else if (res.cancel) {
  181. }
  182. }
  183. });
  184. }else{
  185. uni.showToast({ title: res.data.msg,icon:"none" });
  186. }
  187. },
  188. getUserInfo1(){
  189. var this_=this
  190. //console.log("aaaa")
  191. uni.getUserProfile({
  192. desc:'Wexin', // 这个参数是必须的
  193. success:res=>{
  194. console.log(res);
  195. this_.userinfowx=res.userInfo
  196. this_.wxlogin()
  197. },
  198. fail:err=>{
  199. console.log(err)
  200. }
  201. })
  202. },
  203. getuserinfo: function(){
  204. uni.showLoading({
  205. title: '授权中...'
  206. });
  207. var this_=this
  208. // wx登录
  209. wx.login({
  210. success (res) {
  211. if (res.code) {
  212. //发起网络请求
  213. var code = res.code
  214. // 获取微信用户信息
  215. wx.getUserInfo({
  216. success: function(res) {
  217. this_.userinfowx=res.userInfo
  218. this_.wxlogin()
  219. },
  220. fail:res=>{
  221. // 获取失败的去引导用户授权
  222. }
  223. })
  224. } else {
  225. }
  226. }
  227. })
  228. },
  229. wxlogin(){
  230. var userinfowx=this.userinfowx
  231. var this_=this
  232. uni.login({
  233. timeout: 10000,
  234. provider: 'weixin', //如果是uniapp,在这里需要标明平台的类型,支持的参数请查阅uniapp官网的uni.login()文档
  235. success: (res) => {
  236. //console.log(res);
  237. //登陆成功的回调
  238. uni.hideLoading();
  239. uni.request({
  240. url: this.configs.webUrl+'/api/user/getOpenid',
  241. method:'GET',
  242. data: {
  243. //token: uni.getStorageSync("userinfo").token, //你的小程序的secret,
  244. code: res.code //wx.login 登录成功后的code
  245. },
  246. success: (cts) => {
  247. if(cts.data.code==1){
  248. this_.openid=cts.data.data.openid
  249. this_.unionid=cts.data.data.unionid
  250. uni.showModal({
  251. title: '温馨提示',
  252. content: '授权成功',
  253. showCancel: false,
  254. confirmText: "确定",
  255. success: function (res) {
  256. if (res.confirm) {
  257. console.log(cts.data.msg);
  258. if(cts.data.msg=='登录成功'){
  259. this_.logins(cts.data.data)
  260. }else{
  261. this_.opsdd(cts.data.data)
  262. }
  263. } else if (res.cancel) {
  264. }
  265. }
  266. });
  267. }else{
  268. uni.showModal({
  269. title: '温馨提示',
  270. content: JSON.stringify(cts.data),
  271. showCancel: false,
  272. confirmText: "确定",
  273. success: function (res) {
  274. if (res.confirm) {
  275. //uni.navigateBack();
  276. } else if (res.cancel) {
  277. }
  278. }
  279. });
  280. }
  281. },
  282. fail: (err1) => {
  283. console.log(err1);
  284. uni.hideLoading();
  285. }
  286. });
  287. },
  288. fail: (err) => {
  289. uni.hideLoading();
  290. }
  291. })
  292. },
  293. logins(data){
  294. if(data.userinfo.avatar){
  295. var str = data.userinfo.avatar;
  296. if(str.indexOf("data:image") != -1){
  297. var avatar='';
  298. }else{
  299. if(str.indexOf("http") != -1){
  300. avatar=data.userinfo.avatar;
  301. }else{
  302. avatar=this.configs.imgUrl+data.userinfo.avatar;
  303. }
  304. }
  305. }else{
  306. var avatar='';
  307. }
  308. uni.setStorage({//缓存配置信息
  309. key: 'avatar',
  310. data: avatar
  311. })
  312. uni.setStorage({//缓存配置信息
  313. key: 'userinfo',
  314. data: data.userinfo
  315. })
  316. uni.setStorage({//缓存配置信息
  317. key: 'config',
  318. data: data.config
  319. })
  320. if(this.fxpid>0){
  321. uni.switchTab({
  322. url:'/pages/client/member/index'
  323. })
  324. }else{
  325. uni.navigateBack();
  326. }
  327. },
  328. opsdd(data){
  329. this.userinfowx.openid=this.openid
  330. uni.setStorage({//缓存配置信息
  331. key: 'userinfowx',
  332. data: this.userinfowx
  333. })
  334. var urlsa1='/pages/login/loginwxxcx?fxpid='+this.fxpid
  335. if(data.dltel){
  336. urlsa1='/pages/login/loginwxxcx?dltel='+data.dltel+'&fxpid='+this.fxpid
  337. }
  338. uni.navigateTo({
  339. url:urlsa1
  340. })
  341. },
  342. onGetPhoneNumber(e) {
  343. var this_=this
  344. if(!this.openid){
  345. uni.showModal({
  346. title: '温馨提示',
  347. content: '请先授权',
  348. showCancel: false,
  349. confirmText: "确定",
  350. success: function (res) {
  351. //this_.getuserinfo()
  352. }
  353. });
  354. return false;
  355. }
  356. uni.login({
  357. timeout: 10000,
  358. provider: 'weixin', //如果是uniapp,在这里需要标明平台的类型,支持的参数请查阅uniapp官网的uni.login()文档
  359. success: (res) => {
  360. console.log(res);
  361. console.log("onGetPhoneNumber", e);
  362. uni.request({
  363. url: this.configs.webUrl+'/api/user/getphone',
  364. method:'GET',
  365. data: {
  366. openid:this.openid,
  367. userinfowx:this.userinfowx,
  368. code: res.code,
  369. iv: e.detail.iv,
  370. encryptedData:e.detail.encryptedData,
  371. },
  372. success: (cts) => {
  373. console.log(cts.data);
  374. uni.showModal({
  375. title: '温馨提示',
  376. content: JSON.stringify(cts.data),
  377. showCancel: false,
  378. confirmText: "确定",
  379. success: function (res) {
  380. if (res.confirm) {
  381. //uni.navigateBack();
  382. } else if (res.cancel) {
  383. }
  384. }
  385. });
  386. },
  387. fail: (err1) => {
  388. console.log(err1);
  389. //失败的回调
  390. }
  391. });
  392. },
  393. fail: (err) => {
  394. //登陆失败的回调
  395. },
  396. })
  397. }
  398. }
  399. }
  400. </script>
  401. <style>
  402. .content {
  403. display: flex;
  404. flex-direction: column;
  405. justify-content: center;
  406. }
  407. .header {
  408. width: 161rpx;
  409. height: 161rpx;
  410. background: rgba(63, 205, 235, 1);
  411. box-shadow: 0rpx 12rpx 13rpx 0rpx rgba(63, 205, 235, 0.47);
  412. border-radius: 50%;
  413. margin-top: 30rpx;
  414. margin-left: auto;
  415. margin-right: auto;
  416. }
  417. .header image {
  418. width: 161rpx;
  419. height: 161rpx;
  420. border-radius: 50%;
  421. }
  422. .list {
  423. display: flex;
  424. flex-direction: column;
  425. padding-top: 50rpx;
  426. padding-left: 70rpx;
  427. padding-right: 70rpx;
  428. }
  429. .list-call {
  430. display: flex;
  431. flex-direction: row;
  432. justify-content: space-between;
  433. align-items: center;
  434. height: 100rpx;
  435. color: #333333;
  436. border-bottom: 0.5px solid #e2e2e2;
  437. }
  438. .list-call .img {
  439. width: 40rpx;
  440. height: 40rpx;
  441. }
  442. .list-call .sl-input {
  443. flex: 1;
  444. text-align: left;
  445. font-size: 32rpx;
  446. margin-left: 16rpx;
  447. }
  448. .button-login {
  449. color: #FFFFFF;
  450. font-size: 34rpx;
  451. width: 470rpx;
  452. height: 100rpx;
  453. background: linear-gradient(-90deg, rgba(75, 196, 93, 1), rgba(188, 226, 158, 1));
  454. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.2);
  455. border-radius: 50rpx;
  456. line-height: 100rpx;
  457. text-align: center;
  458. margin-left: auto;
  459. margin-right: auto;
  460. margin-top: 100rpx;
  461. }
  462. .button-login1 {
  463. color: #FFFFFF;
  464. font-size: 34rpx;
  465. width: 470rpx;
  466. height: 80rpx;
  467. background: linear-gradient(-90deg, rgba(75, 196, 93, 1), rgba(188, 226, 158, 1));
  468. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.2);
  469. border-radius: 50rpx;
  470. line-height: 80rpx;
  471. text-align: center;
  472. margin-left: auto;
  473. margin-right: auto;
  474. margin-top: 30rpx;
  475. color: #fff;
  476. }
  477. .button-login2 {
  478. color: #FFFFFF;
  479. font-size: 34rpx;
  480. width: 470rpx;
  481. height: 80rpx;
  482. background: linear-gradient(-90deg, rgba(63, 205, 235, 0.8), rgba(188, 226, 158, 0.8));
  483. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.2);
  484. border-radius: 50rpx;
  485. line-height: 80rpx;
  486. text-align: center;
  487. margin-left: auto;
  488. margin-right: auto;
  489. margin-top: 30rpx;
  490. color: #fff;
  491. }
  492. .button-hover {
  493. background: linear-gradient(-90deg, rgba(63, 205, 235, 0.8), rgba(188, 226, 158, 0.8));
  494. }
  495. .agreenment {
  496. display: flex;
  497. flex-direction: row;
  498. justify-content: center;
  499. align-items: center;
  500. font-size: 30rpx;
  501. margin-top: 80rpx;
  502. color: #FFA800;
  503. text-align: center;
  504. height: 40rpx;
  505. line-height: 40rpx;
  506. }
  507. .agreenment text {
  508. font-size: 24rpx;
  509. margin-left: 15rpx;
  510. margin-right: 15rpx;
  511. }
  512. .preview-wrap {
  513. position: absolute;
  514. top: 0;
  515. left: 0;
  516. right: 0;
  517. bottom: 0;
  518. background-color: rgba(0, 0, 0, .8);
  519. }
  520. .preview {
  521. position: absolute;
  522. top: 0;
  523. left: 0;
  524. right: 0;
  525. bottom: 0;
  526. margin: auto;
  527. width: 80%;
  528. height: 400rpx;
  529. border-radius: 12px;
  530. background-color: #fff;
  531. }
  532. .new-avatar {
  533. width: 500rpx;
  534. height: 500rpx;
  535. margin: 40rpx auto 0;
  536. border: 1px solid #b3e6e6;
  537. border-radius: 4px;
  538. overflow: hidden;
  539. }
  540. .hint {
  541. font-size: 28rpx;
  542. color: #999999;
  543. text-align: center;
  544. margin: 110rpx auto 0;
  545. }
  546. </style>