Browse Source

完成验证并优化微信登录

master
liaoxinyu 2 years ago
parent
commit
478e9e68f4
  1. 29
      common/js/api.js
  2. 61
      pages/Invoicing/Invoicing.vue
  3. 185
      pages/index/index.vue
  4. 95
      pages/wxlogin/wxlogin.vue
  5. 2
      unpackage/dist/build/h5/index.html
  6. BIN
      unpackage/dist/build/h5/static/11.png
  7. BIN
      unpackage/dist/build/h5/static/fonts/uniicons.2579c7da.ttf
  8. 1
      unpackage/dist/build/h5/static/index.2da1efab.css
  9. 7
      unpackage/dist/build/h5/static/js/chunk-vendors.410d4646.js
  10. 1
      unpackage/dist/build/h5/static/js/index.864dc96b.js
  11. 1
      unpackage/dist/build/h5/static/js/pages-Invoiced-Invoiced.ea840cf4.js
  12. 3
      unpackage/dist/build/h5/static/js/pages-Invoicing-Invoicing.f145916c.js
  13. 1
      unpackage/dist/build/h5/static/js/pages-Invoicing-Invoicing~pages-index-index.79e962c1.js
  14. 1
      unpackage/dist/build/h5/static/js/pages-index-index.619bff0a.js
  15. 1
      unpackage/dist/build/h5/static/js/pages-wxlogin-wxlogin.14422d5c.js
  16. BIN
      unpackage/dist/build/h5/static/logo.png
  17. 2
      unpackage/dist/dev/.sourcemap/mp-weixin/common/vendor.js.map
  18. 2
      unpackage/dist/dev/.sourcemap/mp-weixin/pages/index/index.js.map
  19. 2
      unpackage/dist/dev/.sourcemap/mp-weixin/pages/wxlogin/wxlogin.js.map
  20. 24
      unpackage/dist/dev/mp-weixin/common/vendor.js
  21. 90
      unpackage/dist/dev/mp-weixin/pages/index/index.js
  22. 102
      unpackage/dist/dev/mp-weixin/pages/wxlogin/wxlogin.js

29
common/js/api.js

@ -5,19 +5,24 @@
// baseUrl = 'https://apps.dingguagua.vip' // baseUrl = 'https://apps.dingguagua.vip'
// let baseUrl = 'https://apps.dingguagua.vip' // let baseUrl = 'https://apps.dingguagua.vip'
let baseUrl = 'http://intp.xingtongworld.com' let baseUrl = 'https://intp.xingtongworld.com'
let API = { let API = {
baseUrl: baseUrl, baseUrl: baseUrl,
// 登录 // 获取微信授权登录基本信息
getWxCode(data, success, fail){ getWxCode(data, success, fail){
API.sendRequest('get', data, '/wechat/login/getWxCode', success, fail) API.sendRequest('get', data, '/wechat/login/getWxCode', success, fail)
}, },
// 获取微信code进行登录
wx(data, success, fail){
API.sendRequest('get', data, '/wechat/login/wx', success, fail)
},
// 通用api // 通用api
request(url, data, success, fail, boolean=true){ request(url, data, success, fail, boolean=true){
API.sendRequest('post', data, url, success, fail, boolean) API.sendRequest('post', data, url, success, fail, boolean)
}, },
// 请求
sendRequest(method, data, url, success, fail, boolean){ sendRequest(method, data, url, success, fail, boolean){
let types = ''; let types = '';
if (method == 'POST') { if (method == 'POST') {
@ -32,7 +37,7 @@ let API = {
'Content-Type': types, 'Content-Type': types,
'Accept': 'application/json, text/javascript, */*; q=0.01', 'Accept': 'application/json, text/javascript, */*; q=0.01',
// 'Authorization': uni.getStorageSync('user_token')||'' // 'Authorization': uni.getStorageSync('user_token')||''
'token': uni.getStorageSync('user_token')||'' 'token': uni.getStorageSync('AccessToken')||''
} }
} }
uni.request({ uni.request({
@ -52,15 +57,15 @@ let API = {
icon: 'none' icon: 'none'
}) })
if(res.data.code==403 || res.data.code==201){ // if(res.data.code==403 || res.data.code==201){
uni.removeStorageSync('user_token'); // uni.removeStorageSync('user_token');
// setTimeout(()=>{ // // setTimeout(()=>{
// uni.reLaunch({ // // uni.reLaunch({
// url: '/pages/login/login' // // url: '/pages/login/login'
// // url: '/uni_modules/uni-id-pages/pages/login/login-withpwd' // // // url: '/uni_modules/uni-id-pages/pages/login/login-withpwd'
// }) // // })
// }, 1000) // // }, 1000)
} // }
} }
}) })
} }

61
pages/Invoicing/Invoicing.vue

@ -126,8 +126,8 @@
date: currentDate, date: currentDate,
// //
list1:{ list1:{
value: 0,// value: null,//
value2: 0, value2: null,
value3: '', value3: '',
value4: '', value4: '',
email:'', email:'',
@ -135,7 +135,7 @@
}, },
// //
list2:{ list2:{
value: 0, value: null,
name: '', name: '',
taxiD:'' taxiD:''
}, },
@ -157,16 +157,16 @@
], ],
// //
range: [ range: [
{ value: 0, text: "垃圾费" }, { value: 1, text: "垃圾费" },
{ value: 1, text: "污水费" }, { value: 2, text: "污水费" },
{ value: 2, text: "游泳" }, { value: 3, text: "游泳" },
], ],
headerType1: [{text: '单位',value: 0,disable: true},{text: '个人',value: 1,disable: true}], headerType1: [{text: '单位',value: 0,disable: true},{text: '个人',value: 1,disable: true}],
headerType: [{text: '单位',value: 0},{text: '个人',value: 1}], headerType: [{text: '单位',value: 0},{text: '个人',value: 1}],
// //
candidates: ['北京', '南京', '东京', '武汉', '天津', '上海', '海口'], candidates: ['12345689512', '54687913246', '54967846513', '48795123187'],
// //
sex: [{text: '不合并',value: 0},{text: '合并',value: 1}] sex: [{text: '不合并',value: 1},{text: '合并',value: 2}]
} }
}, },
methods: { methods: {
@ -190,10 +190,55 @@
}, },
nextstep(){ nextstep(){
if(this.stepsIndex == 1){ if(this.stepsIndex == 1){
if(!this.list1.value){
uni.showToast({title: '请选择开票项目',icon: 'none'});
this.stepsIndex = 0
return
}
if(!this.list1.value2){
uni.showToast({title: '请选择是否合并开票',icon: 'none'});
this.stepsIndex = 0
return
}
if(!this.list1.value3){
uni.showToast({title: '请选择或输入用户编号',icon: 'none'});
this.stepsIndex = 0
return
}
if(!this.list1.value4){
uni.showToast({title: '请选择到期时间',icon: 'none'});
this.stepsIndex = 0
return
}
if(!this.list1.phoneNumber){
uni.showToast({title: '请输入手机号',icon: 'none'});
this.stepsIndex = 0
return
}
if(!this.list1.email){
uni.showToast({title: '请输入邮箱号',icon: 'none'});
this.stepsIndex = 0
return
}
const list1 = this.$refs.form.modelValue const list1 = this.$refs.form.modelValue
console.log('表单数据信息:', list1); console.log('表单数据信息:', list1);
} }
if(this.stepsIndex == 2){ if(this.stepsIndex == 2){
if(!this.list2.value){
uni.showToast({title: '请选择抬头类型',icon: 'none'});
this.stepsIndex = 0
return
}
if(!this.list2.name){
uni.showToast({title: '请输入抬头名称',icon: 'none'});
this.stepsIndex = 0
return
}
if(!this.list2.taxiD){
uni.showToast({title: '请输入税号',icon: 'none'});
this.stepsIndex = 0
return
}
const list2 = this.$refs.form1.modelValue const list2 = this.$refs.form1.modelValue
console.log('表单数据信息:', list2); console.log('表单数据信息:', list2);
} }

185
pages/index/index.vue

@ -74,12 +74,8 @@
</view> </view>
</view> </view>
</scroll-view> </scroll-view>
<uni-popup ref="popup" type="bottom" background-color="#fff" border-radius="10px 10px 0 0"> <uni-popup ref="popup" type="bottom" background-color="#fff" border-radius="10px 10px 0 0" @close="close">
<view style="height: 150px;text-align: center;"> <view style="height: 150px;text-align: center;">
<!-- #ifdef MP-WEIXIN -->
<!-- <view><image :src="user.img" mode="widthFix" style="width: 50px;"></image></view>
<view>{{user.name}}</view> -->
<!-- #endif -->
<view style="margin: 40rpx 80rpx;"><button type="primary" @click="login">登录</button></view> <view style="margin: 40rpx 80rpx;"><button type="primary" @click="login">登录</button></view>
</view> </view>
</uni-popup> </uni-popup>
@ -107,100 +103,86 @@
console.log('范围选:', this.datetimerange); console.log('范围选:', this.datetimerange);
} }
}, },
onLoad() { onLoad(options) {
// #ifdef MP-WEIXIN
// uni.getUserInfo({ const url = window.location.href;
// provider: 'weixin', // URL
// success: (res) => { const params = this.getUrlParams(url);
// this.user.name = res.userInfo.nickName;
// this.user.img = res.userInfo.avatarUrl; // code
// console.log(res); const code = params['code'];
// //
// }, // start
// fail: (error) => { const start = params['start'];
// console.log(error); if(!uni.getStorageSync('AccessToken')){
// } this.cont()
// }); }
this.getWxCode()
// uni.login({
// provider: "weixin",
// success: (wxraw) => {
// console.log(wxraw,'1111');
// // const data = {
// // _gp: "user",
// // _mt: "thirdPartLogin",
// // phone: this.phone,
// // password: this.password,
// // loginType: 1,
// // raw: JSON.stringify(wxraw)
// // }
// },
// fail: (err) => {
// uni.showToast({
// title: ""
// });
// }
// })
// #endif
API.getWxCode({}, res => {
if (res.code == 1) {
this.redirectUri = res.data.redirectUri;
this.appId = res.data.appId;
this.state = res.data.state
}
})
}, },
mounted() { mounted() {
this.$refs.popup.open(); if(!uni.getStorageSync('AccessToken')){
this.$refs.popup.open();
}
}, },
methods: { methods: {
login(){ // URL
// uni.navigateTo({ getUrlParams(url) {
// url:"/pages/wxlogin/wxlogin" const params = {};
// }) url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
// let url = '/passport/mixedLogin', params[key] = value;
// let data = { });
// account_number: 'root', return params;
// password: 'guaguale@2023', },
// captcha: '' cont(){
// }; let code = this.getUrlCode('code'); // codecodeopenId
// API.request(url, data, res => { let state1 = this.getUrlCode('state');
// console.log(res); let data = {
// }) code : code,
state: state1
}
console.log(this.appId); if(code&&state1){
console.log(this.state); API.wx(data, res => {
let local = this.redirectUri; if(res.code==1){
console.log(local); uni.showToast({title: res.msg,icon: 'none'})
const url = uni.setStorageSync('AccessToken', res.data.token);
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + this.appId + uni.setStorageSync('openid', res.data.openid);
'&redirect_uri=' + local + '&response_type=code&scope=snsapi_userinfo&state=' + this.state + this.$refs.popup.close();
'#wechat_redirect'; this.removepath()
console.log(url); }else{
window.location.href = url; uni.showToast({title: res.msg,icon: 'none'});
this.login();
}
})
}
}, },
// getCode(){ getWxCode(){
// let local = encodeURIComponent(window.location.href); API.getWxCode({}, res => {
// window.location.href = if (res.code == 1) {
// 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + this.appId + this.redirectUri = res.data.redirectUri;
// '&redirect_uri=' + local + '&response_type=code&scope=snsapi_userinfo&state=' + this.state + this.appId = res.data.appId;
// '#wechat_redirect'; this.state = res.data.state
// },
getUser(){
uni.getUserProfile({
desc:'Wexin',
success: (res) => {
// const userInfo = res.userInfo;
console.log(res);
//
},
fail: (error) => {
console.log(error);
} }
}); })
},
//
getUrlCode(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) ||[, ''])[1].replace(/\+/g, '%20')) || null
},
login(){
uni.navigateTo({
url:"/pages/wxlogin/wxlogin"
})
},
removepath(){
// URL
const url = window.location.href;
// 使 code state #/
const newUrl = url.replace(/[\?&]code=[^&]*&?/, '?').replace(/[\?&]state=[^&]*&?/, '#/');
// 使 replaceState URL
window.history.replaceState({}, document.title, newUrl);
},
close(){
}, },
toInvoicing(){ toInvoicing(){
uni.navigateTo({ uni.navigateTo({
@ -209,9 +191,14 @@
}, },
toviewinvoice(n){ toviewinvoice(n){
let id = n; let id = n;
uni.navigateTo({ if(uni.getStorageSync('AccessToken')){
url:'/pages/Invoiced/Invoiced?id=1' uni.navigateTo({
}) url:'/pages/Invoiced/Invoiced?id=1'
})
}else{
uni.showToast({title: '请先进行登入',icon: 'none'});
this.$refs.popup.open();
}
} }
} }
} }
@ -300,18 +287,18 @@
.index_list_size{ .index_list_size{
font-size: 36rpx; font-size: 36rpx;
color: #000; color: #959595;
font-weight: bold; font-weight: bold;
} }
.index_list_color{ .index_list_color{
color: #489ed9; color: #afafaf;
font-size: 26rpx; font-size: 26rpx;
font-weight: bold; font-weight: bold;
} }
.Price_color{ .Price_color{
color: #7daf1d; color: #939393;
font-weight: bold; font-weight: bold;
} }

95
pages/wxlogin/wxlogin.vue

@ -3,90 +3,43 @@
</template> </template>
<script> <script>
// h5 使log npm install vconsole import API from '@/common/js/api.js'
// import Vconsole from 'vconsole';
export default { export default {
data() { data() {
return { return {
code: '', code: '',
state: '' state: '',
state1:'',
appId:'',
redirectUri:''
} }
}, },
onLoad() { onLoad(options) {
// let vConsole = new Vconsole(); this.checkWeChatCode()
// this.state = this.getUrlCode('state')
// this.checkWeChatCode(this.code)
}, },
methods: { methods: {
// checkWeChatCode() { checkWeChatCode() {
// // code API.getWxCode({}, res => {
// this.code = this.getUrlCode('code') if (res.code == 1) {
// if (this.code) { this.redirectUri = res.data.redirectUri;
// // this.appId = res.data.appId;
// this.getLogin(this.code) this.state = res.data.state;
// } else { this.getCode()
// // }
// let params = { })
// url: window.location.href, // },
// state: this.state,
// authType: 0
// }
// xxxx(params).then(res => {
// if (res.data.code == 0) {
// window.location.href = res.data.message
// } else {
// this.$u.toast(res.data.message)
// }
// })
// // 使 this.getCode()
// }
// },
// getUrlCode(name) {
// return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) ||
// [, ''
// ])[1].replace(/\+/g, '%20')) || null
// },
// code // code
// getCode () { getCode () {
// window.location.href = let local = encodeURIComponent('https://intp.xingtongworld.com/wechat/')
// 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + this.appID + window.location.href =
// '&redirect_uri=' + encodeURIComponent(this.callBack) + 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + this.appId +
// '&response_type=code&scope=snsapi_userinfo&state=' + this.state + '#wechat_redirect'; '&redirect_uri=' + local +
'&response_type=code&scope=snsapi_userinfo&state=' + this.state + '#wechat_redirect';
// redirect_uriurlcodeencodeURIComponent // redirect_uriurlcodeencodeURIComponent
// code // code
// https://test.yuruantong.com/pages/loginAndRegister/login/loginH5?code=0312nn200ADR1P1BYh100zp2VL32nn2f&state=1 // https://test.yuruantong.com/pages/loginAndRegister/login/loginH5?code=0312nn200ADR1P1BYh100zp2VL32nn2f&state=1
// }, }
//
// async getLogin(value) {
// let params = {
// code: value,
// wechartState: this.state
// }
// const res = await xxxx(params)
// if (res.data.code != 0) {
// this.$u.toast(res.data.message)
// return;
// }
// if (res.data.rows[0].code == 1) {
// let obj = res.data.rows;
// obj.push({
// wechartState: this.state
// })
// let arr = {
// params: obj,
// isShow: true
// }
// uni.redirectTo({
// url: '/pages/loginAndRegister/login/login?params=' + JSON.stringify(arr)
// })
// } else if (res.data.rows[0].code == 2) { //res.data.rows token
// uni.setStorageSync('userInfo', res.data.rows[0].loginUserVO);
// uni.redirectTo({
// url: '/landlord/home/index/index'
// })
// } else {}
// }
} }
} }
</script> </script>

2
unpackage/dist/build/h5/index.html

@ -0,0 +1,2 @@
<!DOCTYPE html><html lang=zh-CN><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><title>Waterinvoice_uiapp</title><script>var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')</script><link rel=stylesheet href=./static/index.2da1efab.css></head><body><noscript><strong>Please enable JavaScript to continue.</strong></noscript><div id=app></div><script src=./static/js/chunk-vendors.410d4646.js></script><script src=./static/js/index.864dc96b.js></script></body></html>

BIN
unpackage/dist/build/h5/static/11.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
unpackage/dist/build/h5/static/fonts/uniicons.2579c7da.ttf

Binary file not shown.

1
unpackage/dist/build/h5/static/index.2da1efab.css

File diff suppressed because one or more lines are too long

7
unpackage/dist/build/h5/static/js/chunk-vendors.410d4646.js

File diff suppressed because one or more lines are too long

1
unpackage/dist/build/h5/static/js/index.864dc96b.js

File diff suppressed because one or more lines are too long

1
unpackage/dist/build/h5/static/js/pages-Invoiced-Invoiced.ea840cf4.js

File diff suppressed because one or more lines are too long

3
unpackage/dist/build/h5/static/js/pages-Invoicing-Invoicing.f145916c.js

File diff suppressed because one or more lines are too long

1
unpackage/dist/build/h5/static/js/pages-Invoicing-Invoicing~pages-index-index.79e962c1.js

File diff suppressed because one or more lines are too long

1
unpackage/dist/build/h5/static/js/pages-index-index.619bff0a.js

File diff suppressed because one or more lines are too long

1
unpackage/dist/build/h5/static/js/pages-wxlogin-wxlogin.14422d5c.js

@ -0,0 +1 @@
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["pages-wxlogin-wxlogin"],{"0601":function(t,e,n){"use strict";n.d(e,"b",(function(){return a})),n.d(e,"c",(function(){return o})),n.d(e,"a",(function(){}));var a=function(){var t=this.$createElement,e=this._self._c||t;return e("v-uni-view")},o=[]},"16f6":function(t,e,n){"use strict";n.r(e);var a=n("31af"),o=n.n(a);for(var i in a)["default"].indexOf(i)<0&&function(t){n.d(e,t,(function(){return a[t]}))}(i);e["default"]=o.a},"31af":function(t,e,n){"use strict";n("7a82");var a=n("4ea4").default;Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var o=a(n("4d55")),i={data:function(){return{code:"",state:"",state1:"",appId:"",redirectUri:""}},onLoad:function(t){this.checkWeChatCode()},methods:{checkWeChatCode:function(){var t=this;o.default.getWxCode({},(function(e){1==e.code&&(t.redirectUri=e.data.redirectUri,t.appId=e.data.appId,t.state=e.data.state,t.getCode())}))},getCode:function(){var t=encodeURIComponent("https://intp.xingtongworld.com/wechat/");window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+this.appId+"&redirect_uri="+t+"&response_type=code&scope=snsapi_userinfo&state="+this.state+"#wechat_redirect"}}};e.default=i},"4d55":function(t,e,n){"use strict";n("7a82");var a=n("4ea4").default;Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var o=a(n("5530")),i="https://intp.xingtongworld.com",c={baseUrl:i,getWxCode:function(t,e,n){c.sendRequest("get",t,"/wechat/login/getWxCode",e,n)},wx:function(t,e,n){c.sendRequest("get",t,"/wechat/login/wx",e,n)},request:function(t,e,n,a){var o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4];c.sendRequest("post",e,t,n,a,o)},sendRequest:function(t,e,n,a,c,d){var r="";r="POST"==t?"application/x-www-form-urlencoded":"application/json";var u={};d&&(u.header={"Content-Type":r,Accept:"application/json, text/javascript, */*; q=0.01",token:uni.getStorageSync("AccessToken")||""}),uni.request((0,o.default)((0,o.default)({url:i+n,method:t,data:e},u),{},{success:function(t){1!=t.data.code?uni.showToast({title:t.data.msg||t.msg,icon:"none"}):a&&a(t.data)}}))}},d=c;e.default=d},"6a49":function(t,e,n){"use strict";n.r(e);var a=n("0601"),o=n("16f6");for(var i in o)["default"].indexOf(i)<0&&function(t){n.d(e,t,(function(){return o[t]}))}(i);var c=n("f0c5"),d=Object(c["a"])(o["default"],a["b"],a["c"],!1,null,"44bf1784",null,!1,a["a"],void 0);e["default"]=d.exports}}]);

BIN
unpackage/dist/build/h5/static/logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

2
unpackage/dist/dev/.sourcemap/mp-weixin/common/vendor.js.map

File diff suppressed because one or more lines are too long

2
unpackage/dist/dev/.sourcemap/mp-weixin/pages/index/index.js.map

File diff suppressed because one or more lines are too long

2
unpackage/dist/dev/.sourcemap/mp-weixin/pages/wxlogin/wxlogin.js.map

File diff suppressed because one or more lines are too long

24
unpackage/dist/dev/mp-weixin/common/vendor.js

@ -9676,13 +9676,16 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
// baseUrl = 'https://apps.dingguagua.vip' // baseUrl = 'https://apps.dingguagua.vip'
// let baseUrl = 'https://apps.dingguagua.vip' // let baseUrl = 'https://apps.dingguagua.vip'
var baseUrl = 'http://intp.xingtongworld.com'; var baseUrl = 'https://intp.xingtongworld.com';
var API = { var API = {
baseUrl: baseUrl, baseUrl: baseUrl,
// 登录 // 登录
getWxCode: function getWxCode(data, success, fail) { getWxCode: function getWxCode(data, success, fail) {
API.sendRequest('get', data, '/wechat/login/getWxCode', success, fail); API.sendRequest('get', data, '/wechat/login/getWxCode', success, fail);
}, },
wx: function wx(data, success, fail) {
API.sendRequest('get', data, '/wechat/login/wx', success, fail);
},
// 通用api // 通用api
request: function request(url, data, success, fail) { request: function request(url, data, success, fail) {
var boolean = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true; var boolean = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
@ -9719,15 +9722,16 @@ var API = {
title: res.data.msg || res.msg, title: res.data.msg || res.msg,
icon: 'none' icon: 'none'
}); });
if (res.data.code == 403 || res.data.code == 201) {
uni.removeStorageSync('user_token'); // if(res.data.code==403 || res.data.code==201){
// setTimeout(()=>{ // uni.removeStorageSync('user_token');
// uni.reLaunch({ // // setTimeout(()=>{
// url: '/pages/login/login' // // uni.reLaunch({
// // url: '/uni_modules/uni-id-pages/pages/login/login-withpwd' // // url: '/pages/login/login'
// }) // // // url: '/uni_modules/uni-id-pages/pages/login/login-withpwd'
// }, 1000) // // })
} // // }, 1000)
// }
} }
})); }));
} }

90
unpackage/dist/dev/mp-weixin/pages/index/index.js

@ -281,8 +281,33 @@ var _default = {
console.log('范围选:', this.datetimerange); console.log('范围选:', this.datetimerange);
} }
}, },
onLoad: function onLoad() { onLoad: function onLoad(options) {
var _this = this; var _this = this;
this.cont();
var url = window.location.href;
// 获取URL中的参数对象
var params = getUrlParams(url);
// 解析URL中的参数
var getUrlParams = function getUrlParams(url) {
var params = {};
var urlParts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
params[key] = value;
});
return params;
};
// 获取code参数
var code = params['code'];
// 获取start参数
var start = params['start'];
// 打印参数值
console.log('code:', code);
console.log('start:', start);
console.log(options, '11111');
// uni.getUserInfo({ // uni.getUserInfo({
// provider: 'weixin', // provider: 'weixin',
// success: (res) => { // success: (res) => {
@ -328,47 +353,30 @@ var _default = {
this.$refs.popup.open(); this.$refs.popup.open();
}, },
methods: { methods: {
login: function login() { cont: function cont() {
// uni.navigateTo({ var code = this.getUrlCode('code'); // 截取路径中的code,如果没有就去微信授权,如果已经获取到了就直接传code给后台获取openId
// url:"/pages/wxlogin/wxlogin" var state1 = this.getUrlCode('state');
// }) // const local = window.location.href;
// let url = '/passport/mixedLogin', console.log(343, code);
// let data = { console.log(344, state1);
// account_number: 'root', var data = {
// password: 'guaguale@2023', code: code,
// captcha: '' state: state1
// }; };
// API.request(url, data, res => { if (code && state1) {
// console.log(res); _api.default.wx(data, function (res) {
// })
console.log(this.appId);
console.log(this.state);
var local = this.redirectUri;
console.log(local);
var url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + this.appId + '&redirect_uri=' + local + '&response_type=code&scope=snsapi_userinfo&state=' + this.state + '#wechat_redirect';
console.log(url);
window.location.href = url;
},
// getCode(){
// let local = encodeURIComponent(window.location.href);
// window.location.href =
// 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + this.appId +
// '&redirect_uri=' + local + '&response_type=code&scope=snsapi_userinfo&state=' + this.state +
// '#wechat_redirect';
// },
getUser: function getUser() {
uni.getUserProfile({
desc: 'Wexin',
success: function success(res) {
// const userInfo = res.userInfo;
console.log(res); console.log(res);
// 在这里可以对用户信息进行处理或者其他操作 });
}, }
// this.handleToLogin(code)
fail: function fail(error) { },
console.log(error); // 正则匹配请求地址中的参数函数
} getUrlCode: function getUrlCode(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) || null;
},
login: function login() {
uni.navigateTo({
url: "/pages/wxlogin/wxlogin"
}); });
}, },
toInvoicing: function toInvoicing() { toInvoicing: function toInvoicing() {

102
unpackage/dist/dev/mp-weixin/pages/wxlogin/wxlogin.js

@ -135,98 +135,50 @@ __webpack_require__.r(__webpack_exports__);
"use strict"; "use strict";
var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ 4);
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.default = void 0; exports.default = void 0;
var _api = _interopRequireDefault(__webpack_require__(/*! @/common/js/api.js */ 40));
// //
// //
// //
// //
// h5 使用控制台打log 得先npm install vconsole
// import Vconsole from 'vconsole';
var _default = { var _default = {
data: function data() { data: function data() {
return { return {
code: '', code: '',
state: '' state: '',
state1: '',
appId: '',
redirectUri: ''
}; };
}, },
onLoad: function onLoad() { onLoad: function onLoad(options) {
// let vConsole = new Vconsole(); this.checkWeChatCode();
// this.state = this.getUrlCode('state')
// this.checkWeChatCode(this.code)
}, },
methods: { methods: {
// checkWeChatCode() { checkWeChatCode: function checkWeChatCode() {
// // 页面一进来先判断是否有code var _this = this;
// this.code = this.getUrlCode('code') _api.default.getWxCode({}, function (res) {
// if (this.code) { if (res.code == 1) {
// // 如果有,走登记接口 _this.redirectUri = res.data.redirectUri;
// this.getLogin(this.code) _this.appId = res.data.appId;
// } else { _this.state = res.data.state;
// // 没有调后端接口获取地址 _this.getCode();
// let params = { }
// url: window.location.href, //当前页面的详细地址 });
// state: this.state, },
// authType: 0
// }
// xxxx(params).then(res => {
// if (res.data.code == 0) {
// window.location.href = res.data.message
// } else {
// this.$u.toast(res.data.message)
// }
// })
// // 根据需求使用 this.getCode()
// }
// },
// getUrlCode(name) {
// return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) ||
// [, ''
// ])[1].replace(/\+/g, '%20')) || null
// },
// 获取code // 获取code
// getCode () { getCode: function getCode() {
// window.location.href = var local = encodeURIComponent('https://intp.xingtongworld.com/wechat/index.html');
// 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + this.appID + window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + this.appId + '&redirect_uri=' + local + '&response_type=code&scope=snsapi_userinfo&state=' + this.state + '#wechat_redirect';
// '&redirect_uri=' + encodeURIComponent(this.callBack) +
// '&response_type=code&scope=snsapi_userinfo&state=' + this.state + '#wechat_redirect'; // redirect_uri是授权成功后,跳转的url地址,微信会帮我们跳转到该链接,并且通过?的形式拼接code,这里需要用encodeURIComponent对链接进行处理。
// 如果配置参数一一对应,那么此时已经通过回调地址刷新页面后,你就会再地址栏中看到code了。
// redirect_uri是授权成功后,跳转的url地址,微信会帮我们跳转到该链接,并且通过?的形式拼接code,这里需要用encodeURIComponent对链接进行处理。 // https://test.yuruantong.com/pages/loginAndRegister/login/loginH5?code=0312nn200ADR1P1BYh100zp2VL32nn2f&state=1
// 如果配置参数一一对应,那么此时已经通过回调地址刷新页面后,你就会再地址栏中看到code了。 }
// https://test.yuruantong.com/pages/loginAndRegister/login/loginH5?code=0312nn200ADR1P1BYh100zp2VL32nn2f&state=1
// },
//登录
// async getLogin(value) {
// let params = {
// code: value,
// wechartState: this.state
// }
// const res = await xxxx(params)
// if (res.data.code != 0) {
// this.$u.toast(res.data.message)
// return;
// }
// if (res.data.rows[0].code == 1) {
// let obj = res.data.rows;
// obj.push({
// wechartState: this.state
// })
// let arr = {
// params: obj,
// isShow: true
// }
// uni.redirectTo({
// url: '/pages/loginAndRegister/login/login?params=' + JSON.stringify(arr)
// })
// } else if (res.data.rows[0].code == 2) { //res.data.rows 返回的是token 跳转对应的页面
// uni.setStorageSync('userInfo', res.data.rows[0].loginUserVO);
// uni.redirectTo({
// url: '/landlord/home/index/index'
// })
// } else {}
// }
} }
}; };
exports.default = _default; exports.default = _default;

Loading…
Cancel
Save