提交 5dc2419b 编写于 作者: guangjun.yang's avatar guangjun.yang

Merge branch 'dev-purchase-0901' of...

Merge branch 'dev-purchase-0901' of http://192.168.110.53/com.pica.cloud.education.frontend/pica-professional-exam into dev-purchase-0901

* 'dev-purchase-0901' of http://192.168.110.53/com.pica.cloud.education.frontend/pica-professional-exam:
  测试登录
  测试登录
  修改授权等
  授权登录
  测试
  修改微信appid
  修改微信appid
  修改微信appid
  测试微信登录
...@@ -13,6 +13,7 @@ import BuriedPoint, { sendBuriedData } from 'web-buried-point'; ...@@ -13,6 +13,7 @@ import BuriedPoint, { sendBuriedData } from 'web-buried-point';
import Vant from 'vant'; import Vant from 'vant';
import 'vant/lib/index.css'; import 'vant/lib/index.css';
import clipboard from 'clipboard'; import clipboard from 'clipboard';
import { querystring } from '@/utils';
//注册到vue原型上 //注册到vue原型上
Vue.prototype.clipboard = clipboard; Vue.prototype.clipboard = clipboard;
...@@ -68,10 +69,28 @@ function fliterRoute(query, path) { ...@@ -68,10 +69,28 @@ function fliterRoute(query, path) {
delete query.projectId; delete query.projectId;
has = true; has = true;
} }
// 商品详情页去掉code
if (path === '/goods-detail' && query.code) {
store.dispatch('getWxUserInfo', query.code);
delete query.code;
let goodsDetailParams = sessionStorage.getItem('goodsDetailParams');
goodsDetailParams = goodsDetailParams ? JSON.parse(goodsDetailParams) : {};
Object.assign(query, goodsDetailParams);
has = true;
}
return [query, has]; return [query, has];
} }
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
console.log('_____href_____', location.href)
if (to.path === '/goods-detail') {
let searchQuery = querystring(location.search);
if (searchQuery.code) {
let newUrl = location.origin + location.pathname + '#/goods-detail?code=' + searchQuery.code;
location.replace(newUrl);
return;
}
}
let query = { ...to.query }; let query = { ...to.query };
// 登录token保存并替换路径 // 登录token保存并替换路径
let [newQuery, has] = fliterRoute(query, to.path); let [newQuery, has] = fliterRoute(query, to.path);
......
...@@ -2,12 +2,16 @@ import { Toast } from 'vant'; ...@@ -2,12 +2,16 @@ import { Toast } from 'vant';
import fetch from '@/utils/fetch'; import fetch from '@/utils/fetch';
import { getBaseUrl } from '@/utils/index' import { getBaseUrl } from '@/utils/index'
import { setCookie, delCookie } from '@/utils/index'; import { setCookie, delCookie } from '@/utils/index';
import { envConfig } from '@/utils/env-config' import { envConfig } from '@/utils/env-config';
let wxInfo = sessionStorage.getItem('wxInfo');
wxInfo = wxInfo ? JSON.parse(wxInfo) : {};
const user = { const user = {
state: { state: {
token: localStorage.getItem('token') || '', token: localStorage.getItem('token') || '',
info: {}, // 用户信息 info: {}, // 用户信息
wxInfo, // 微信信息,openid等
}, },
mutations: { mutations: {
SET_TOKEN: (state, payload) => { SET_TOKEN: (state, payload) => {
...@@ -16,6 +20,9 @@ const user = { ...@@ -16,6 +20,9 @@ const user = {
SET_USER_INFO: (state, payload) => { SET_USER_INFO: (state, payload) => {
state.info = payload; state.info = payload;
}, },
SET_WX_INFO: (state, payload) => {
state.wxInfo = payload;
},
}, },
actions: { actions: {
// 外部登陆返回设置token // 外部登陆返回设置token
...@@ -69,6 +76,20 @@ const user = { ...@@ -69,6 +76,20 @@ const user = {
window.location.href = envConfig[process.env.BUILD_ENV]['webPageUrl'] + "/pica_login?target_url=" + encodeURIComponent(location.href); window.location.href = envConfig[process.env.BUILD_ENV]['webPageUrl'] + "/pica_login?target_url=" + encodeURIComponent(location.href);
}, },
getWxUserInfo({ state, commit }, code) {
console.log('_______getWxUserInfo__________', code)
const type = 15;
fetch({
url: getBaseUrl(`wechats/users/info/${type}/${code}`),
method: 'get',
headers: { token: state.token }
}).then(res => {
console.log('____wx res_____', res.data)
sessionStorage.setItem('wxInfo', JSON.stringify(res.data));
commit('SET_WX_INFO', res.data)
});
},
// 登出 // 登出
logout({ state, commit }) { logout({ state, commit }) {
commit('SET_TOKEN', ''); commit('SET_TOKEN', '');
......
...@@ -13,7 +13,7 @@ export const envConfig = { ...@@ -13,7 +13,7 @@ export const envConfig = {
baseUrl: 'https://dev-sc.yunqueyi.com/', baseUrl: 'https://dev-sc.yunqueyi.com/',
hactiveUrl: 'https://dev-hactive.yunqueyi.com', hactiveUrl: 'https://dev-hactive.yunqueyi.com',
fileUrl: 'https://dev-www.yunqueyi.com', fileUrl: 'https://dev-www.yunqueyi.com',
appId: 'wxf4e66242d31c81c2', // 用于微信授权登录 appId: 'wx08b383d002c73f26', // 用于微信授权登录
// baseUrl: 'https://test1-sc.yunqueyi.com/', // baseUrl: 'https://test1-sc.yunqueyi.com/',
// apiUrl: 'https://test1-api.yunqueyi.com/', // apiUrl: 'https://test1-api.yunqueyi.com/',
...@@ -47,7 +47,7 @@ export const envConfig = { ...@@ -47,7 +47,7 @@ export const envConfig = {
webPageUrl: 'https://dev-phome.yunqueyi.com/', webPageUrl: 'https://dev-phome.yunqueyi.com/',
hactiveUrl: 'https://dev-hactive.yunqueyi.com', hactiveUrl: 'https://dev-hactive.yunqueyi.com',
fileUrl: 'https://dev-www.yunqueyi.com', fileUrl: 'https://dev-www.yunqueyi.com',
appId: 'wxf4e66242d31c81c2', // 用于微信授权登录 appId: 'wx08b383d002c73f26', // 用于微信授权登录
}, },
test: { test: {
baseUrl: 'https://test1-sc.yunqueyi.com/', baseUrl: 'https://test1-sc.yunqueyi.com/',
......
...@@ -205,6 +205,16 @@ export function isWeiXin() { ...@@ -205,6 +205,16 @@ export function isWeiXin() {
} }
} }
//弹出微信授权
export const wxOauth = () => {
let url = location.href, redirectUrl;
let appId = getAPPID();
url = url.split('?')[0];
redirectUrl = encodeURIComponent(url);
console.log('wxOauth redirectUrl => ', redirectUrl);
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUrl}&response_type=code&scope=snsapi_userinfo&#wechat_redirect`;
}
export const setCookie = (name, value, time) => { export const setCookie = (name, value, time) => {
var expires = 30 * 24 * 60 * 60 * 1000; //一天 var expires = 30 * 24 * 60 * 60 * 1000; //一天
var date = new Date(+new Date() + expires); var date = new Date(+new Date() + expires);
...@@ -249,3 +259,19 @@ export function debounce(fn, wait = 50) { ...@@ -249,3 +259,19 @@ export function debounce(fn, wait = 50) {
}, wait) }, wait)
} }
} }
function decode(input) {
return decodeURIComponent(input.replace(/\+/g, ' '));
}
export function querystring(query) {
var parser = /([^=?&]+)=?([^&]*)/g
, result = {}
, part;
for (;
part = parser.exec(query);
result[decode(part[1])] = decode(part[2])
);
return result;
}
...@@ -73,7 +73,8 @@ ...@@ -73,7 +73,8 @@
<script> <script>
import { Swipe, SwipeItem } from 'vant'; import { Swipe, SwipeItem } from 'vant';
import { debounce } from '@/utils'; import { getAPPID, getWebPageUrl, isWeiXin, wxOauth, debounce } from '@/utils';
const isWechat = isWeiXin();
export default { export default {
components: { components: {
...@@ -98,6 +99,9 @@ export default { ...@@ -98,6 +99,9 @@ export default {
logged() { logged() {
return this.$store.getters.logged; return this.$store.getters.logged;
}, },
wxInfo() {
return this.$store.state.user.wxInfo;
},
tabLeft() { tabLeft() {
const num = this.curtTabIdx + 0.25 + 15 / 115; const num = this.curtTabIdx + 0.25 + 15 / 115;
return this.tabW * num; return this.tabW * num;
...@@ -109,9 +113,15 @@ export default { ...@@ -109,9 +113,15 @@ export default {
this.returnUrl = this.$route.query.returnUrl; this.returnUrl = this.$route.query.returnUrl;
this.getGoodsInfo(); this.getGoodsInfo();
this.getTabW(); this.getTabW();
const { token, info } = this.$store.state.user;
if (token && !info.id) {
this.$store.dispatch('getUserInfo');
}
// 数量加减 // 数量加减
this.curtGoodsNum = this.goodsNum; this.curtGoodsNum = this.goodsNum;
this.countTotalPrice = debounce(this.getTotalPrice, 500); this.countTotalPrice = debounce(this.getTotalPrice, 500);
// 记录参数,授权登录返回时重新赋值,在main.js
sessionStorage.setItem('goodsDetailParams', JSON.stringify(this.$route.query))
}, },
beforeDestroy() { beforeDestroy() {
this.countTotalPrice = null; this.countTotalPrice = null;
...@@ -230,6 +240,11 @@ export default { ...@@ -230,6 +240,11 @@ export default {
this.goLogin(); this.goLogin();
return; return;
} }
// 微信内先去授权
if (isWechat && !this.wxInfo.openid) {
wxOauth();
return;
}
const { id, couponDTO, isSale } = this.goods; const { id, couponDTO, isSale } = this.goods;
const { preferentialPrice, costPrice } = this.totalPrice; const { preferentialPrice, costPrice } = this.totalPrice;
// if (!id || isSale !== 1) { // if (!id || isSale !== 1) {
...@@ -246,7 +261,11 @@ export default { ...@@ -246,7 +261,11 @@ export default {
this.POST('trade/center/order/createV2', orderData).then(res => { this.POST('trade/center/order/createV2', orderData).then(res => {
if (res.code == "000000") { if (res.code == "000000") {
const orderId = res.data.orderId; const orderId = res.data.orderId;
// if (isWechat) {
this.goWxPayInner(orderId);
// } else {
// this.goWxPayOut(orderId);
// }
if (this.projectId) { if (this.projectId) {
this.createRelation(this.projectId, orderId); this.createRelation(this.projectId, orderId);
} }
...@@ -255,9 +274,48 @@ export default { ...@@ -255,9 +274,48 @@ export default {
} }
}) })
}, },
// 支付 // 站外微信支付
goPay(orderId) { goWxPayOut(orderId) {
// const data = {
orderId,
payChannel: 1,
tradeType: 3,
}
this.POST('trade/center/mweb_prepay', data).then(res => {
if (res.code == "000000") {
let redirectUrl = this.getRedirectUrl(orderId);
let jumpLink = res.data + '&redirect_url=' + encodeURIComponent(redirectUrl);
window.location.href = jumpLink;
} else {
this.$toast(res.message);
}
})
},
// 微信内支付
goWxPayInner(orderId) {
const data = {
openId: getAPPID(),
orderId,
payChannel: 1,
tradeType: 1,
}
this.POST('trade/center/jsapi_prepay', data).then(res => {
if (res.code == "000000") {
} else {
this.$toast(res.message);
}
})
},
getRedirectUrl(orderId) {
let path = `profexam/#/prezult?orderId=${orderId}`;
if (this.projectId) {
path += `&projectId=${this.projectId}`
}
if (this.returnUrl) {
path += `&returnUrl=${this.returnUrl}`
}
return getWebPageUrl(path);
}, },
// 绑定项目和订单的关系 // 绑定项目和订单的关系
createRelation(projectId, orderId) { createRelation(projectId, orderId) {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册