loginwxxcx.vue 13 KB

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