Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mayi-mp-shop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
程默
mayi-mp-shop
Commits
f74e40d8
Commit
f74e40d8
authored
Sep 18, 2019
by
程默
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
同步
parent
9b6b9567
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
236 additions
and
125 deletions
+236
-125
build/webpack.dev.conf.js
+3
-1
config/dev.env.js
+1
-1
project.config.json
+1
-0
src/api/wxPay.js
+3
-4
src/pages/index/index.vue
+54
-30
src/pages/login/index.vue
+93
-33
src/pages/wxPay/index.vue
+57
-53
src/utils/request.js
+24
-3
No files found.
build/webpack.dev.conf.js
View file @
f74e40d8
var
UglifyJsPlugin
=
require
(
'uglifyjs-webpack-plugin'
)
var
utils
=
require
(
'./utils'
)
var
webpack
=
require
(
'webpack'
)
var
config
=
require
(
'../config'
)
...
...
@@ -80,6 +81,7 @@ module.exports = merge(baseWebpackConfig, {
// template: 'index.html',
// inject: true
// }),
new
FriendlyErrorsPlugin
()
new
FriendlyErrorsPlugin
(),
new
UglifyJsPlugin
({
sourceMap
:
true
})
]
})
config/dev.env.js
View file @
f74e40d8
...
...
@@ -5,5 +5,5 @@ var prodEnv = require('./prod.env')
module
.
exports
=
merge
(
prodEnv
,
{
NODE_ENV
:
'"development"'
,
APPID
:
'"wx743dc2f4adb9cf01"'
,
OLSHOP_URL
:
'"https://
dev
-m-shop.mayi888.cn/innerApi/shopApiService"'
OLSHOP_URL
:
'"https://
test
-m-shop.mayi888.cn/innerApi/shopApiService"'
})
project.config.json
View file @
f74e40d8
...
...
@@ -7,6 +7,7 @@
"minified"
:
true
,
"newFeature"
:
true
,
"coverView"
:
true
,
"nodeModules"
:
false
,
"autoAudits"
:
false
,
"checkInvalidKey"
:
true
,
"checkSiteMap"
:
true
,
...
...
src/api/wxPay.js
View file @
f74e40d8
import
request
from
"@/utils/request.js"
;
const
baseApi
=
"http://test-m-shop.mayi888.cn/innerApi"
;
import
{
requestPOST
,
requestPOST1
}
from
"@/utils/request.js"
;
export
default
{
to_wx_pay
(
options
)
{
return
request
(
`
${
baseApi
}
/shopApiService
/pay/to_wx_pay`
,
options
)
return
request
POST1
(
`
${
process
.
env
.
OLSHOP_URL
}
/pay/to_wx_pay`
,
options
)
}
}
\ No newline at end of file
src/pages/index/index.vue
View file @
f74e40d8
...
...
@@ -40,46 +40,70 @@ export default {
return
{
options
:
{},
session_key
:
""
,
link
:
"http://localhost:3000"
,
page
:
""
,
link
:
"http://test-m-shop.mayi888.cn"
,
// link: "http://localhost:3000",
page
:
"/"
,
params
:
"?mixid=dev001"
,
motto
:
"Hello miniprograme"
,
userInfo
:
{
nickName
:
"mpvue"
,
avatarUrl
:
"http://mpvue.com/assets/logo.png"
}
},
shareUrl
:
""
};
},
onShareAppMessage
()
{
onShareAppMessage
(
res
)
{
console
.
log
(
"share"
,
res
,
this
.
page
);
//获取webview当前页面地址
this
.
shareUrl
=
res
.
webViewUrl
;
return
{
title
:
"微信小程序"
,
desc
:
"小程序开发!"
,
path
:
"/page/logs"
title
:
this
.
shareUrl
,
// 默认是小程序的名称
path
:
`/pages/index/main?share=
${
encodeURIComponent
(
this
.
shareUrl
)}
`
,
// 默认是当前页面
imageUrl
:
"http://test-bucket-ant.oss-cn-shanghai.aliyuncs.com/product/png/026da85e-d78d-4260-bbe1-4ca5e1fed10d.png"
,
//自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
success
:
function
(
res
)
{
// 转发成功之后的回调
if
(
res
.
errMsg
==
"shareAppMessage:ok"
)
{
}
},
fail
:
function
()
{
// 转发失败之后的回调
if
(
res
.
errMsg
==
"shareAppMessage:fail cancel"
)
{
// 用户取消转发
}
else
if
(
res
.
errMsg
==
"shareAppMessage:fail"
)
{
// 转发失败,其中 detail message 为详细失败信息
}
},
complete
:
function
()
{
// 转发结束之后的回调(转发成不成功都会执行)
}
};
},
onLoad
(
options
)
{
Object
.
assign
(
this
.
$data
,
this
.
$options
.
data
());
console
.
log
(
options
,
"index"
);
this
.
options
=
options
;
if
(
options
.
from
==
"login"
)
{
if
(
options
.
share
)
{
//来自分享
this
.
link
=
options
.
share
;
this
.
page
=
""
;
this
.
params
=
""
;
}
else
if
(
options
.
from
&&
options
.
from
==
"login"
)
{
//来自登录页面
this
.
page
=
decodeURIComponent
(
options
.
backpath
);
this
.
params
+=
"&"
+
decodeURIComponent
(
options
.
params
);
}
else
if
(
options
.
from
==
"wxPay"
)
{
}
console
.
log
(
"url"
,
this
.
link
,
"-"
,
this
.
page
,
"-"
,
this
.
params
);
return
;
if
(
options
.
payCallback
&&
options
.
orderSn
)
{
//支付页面跳转过来
this
.
page
=
options
.
payCallback
;
this
.
params
=
this
.
params
+
"&orderSn="
+
options
.
orderSn
;
//来自支付页面
this
.
page
=
options
.
backpath
;
this
.
params
=
this
.
params
+
"&orderSn="
+
options
.
params
;
}
else
if
(
options
.
scene
)
{
//扫码
//
来自
扫码
// options 中的scene需要使用decodeURIComponent才能获取到生成二维码时传入的scene
var
scene
=
decodeURIComponent
(
options
.
scene
);
//参数二维码传递过来的参数
var
query
=
options
.
query
.
dentistId
;
// 参数二维码传递过来的场景参数
}
else
if
(
options
)
{
}
console
.
log
(
"url"
,
this
.
link
+
this
.
page
+
this
.
params
);
},
components
:
{
// card
...
...
@@ -102,20 +126,20 @@ export default {
}
},
onUnload
()
{
console
.
log
(
'卸载----------------'
)
console
.
log
(
"卸载----------------"
,
this
.
options
);
//控制返回按钮
if
(
this
.
options
.
backpath
)
{
switch
(
this
.
options
.
backpath
)
{
case
"/login/accountLogin"
:
wx
.
redirectTo
({
url
:
`../login/main`
});
break
;
//
if (this.options.backpath) {
//
switch (this.options.backpath) {
//
case "/login/accountLogin":
//
wx.redirectTo({
//
url: `../login/main`
//
});
//
break;
default
:
break
;
}
}
//
default:
//
break;
//
}
//
}
}
};
</
script
>
...
...
src/pages/login/index.vue
View file @
f74e40d8
<
template
>
<div
class=
"domain"
>
1234
<div
class=
"toCLogin"
v-if=
"!isShowPhone"
>
<div
class=
"toCLogin"
>
<p
class=
"shopName"
v-if=
"shopName"
>
{{
shopName
}}
</p>
<div
class=
"btn_info"
>
<button
class=
"btn"
open-type=
"getUserInfo"
@
getuserinfo=
"getUserInfo"
>
微信登录
</button>
</div>
<div
class=
"enterpriseLogin"
@
click=
"eLogin"
>
企业员工登录
</div>
</div>
<div
class=
"toCLogin"
v-if=
"isShowPhone"
>
<div
class=
"btn_info"
>
<button
class=
"btn"
open-type=
"getPhoneNumber"
@
getphonenumber=
"getPhoneNumber"
>
绑定手机号
</button>
<div
class=
"toCLogin toCLogin1"
v-if=
"isShowPhone"
>
<div
class=
"btn_info1"
>
<h1>
绑定手机号
</h1>
<span
class=
"hint"
>
检测到您的账号还未绑定手机号,请绑定手机号
</span>
<button
class=
"btn"
open-type=
"getPhoneNumber"
@
getphonenumber=
"getPhoneNumber"
>
绑定手机号一键绑定
</button>
<div
class=
"btn2"
@
click=
"handbindHandle"
>
手动绑定手机号
</div>
</div>
<div
class=
"layer"
@
click=
"isShowPhone=false"
></div>
</div>
<!--
<div
v-else
>
...
...
@@ -40,7 +43,7 @@ export default {
return
{
session_key
:
""
,
shopName
:
""
,
isShow
:
tru
e
,
isShow
:
fals
e
,
isShowPhone
:
false
,
getPhone
:
false
,
openid
:
""
,
...
...
@@ -74,7 +77,6 @@ export default {
getshop
()
{
shop
.
getShopInfo
().
then
(
res
=>
{
console
.
log
(
res
,
"shop"
);
if
(
res
.
data
.
code
==
200
)
{
this
.
shopName
=
res
.
data
.
data
.
shopName
;
}
...
...
@@ -88,24 +90,29 @@ export default {
.
miniLogin
({
code
:
res
.
code
})
.
then
(
res
=>
{
if
(
res
.
data
.
code
==
200
)
{
wx
.
setStorage
({
key
:
"openid"
,
data
:
res
.
data
.
data
.
openid
});
this
.
isShow
=
true
;
if
(
res
.
data
.
data
.
isHaveUnion
==
"true"
)
{
this
.
session_key
=
res
.
data
.
data
.
session_key
;
this
.
isHaveUnion
=
true
;
this
.
backParams
+=
`&sessionid=
${
res
.
data
.
data
.
sessionId
}
`
;
console
.
log
(
this
.
backParams
,
"mini"
);
console
.
log
(
res
,
"mini"
);
wx
.
setStorage
({
key
:
"sessionid"
,
data
:
res
.
data
.
data
.
sessionId
});
process
.
env
.
sessionid
=
res
.
data
.
data
.
sessionId
;
//有账号
// wx.setStorage({
// key: "sessionId",
// data: res.data.data.sessionId
// });
}
else
{
//需要绑定
this
.
isHaveUnion
=
false
;
this
.
openid
=
res
.
data
.
data
.
openid
;
this
.
session_key
=
res
.
data
.
data
.
session_key
;
this
.
appid
=
res
.
data
.
data
.
appid
;
this
.
isShow
=
true
;
}
}
})
...
...
@@ -115,10 +122,10 @@ export default {
});
},
getUserInfo
:
function
(
e
)
{
if
(
e
.
target
.
errMsg
==
"getUserInfo:ok"
)
{
if
(
e
.
target
.
errMsg
==
"getUserInfo:ok"
&&
this
.
isShow
)
{
if
(
this
.
isHaveUnion
)
{
//是会员 直接登录
wx
.
re
directTo
({
wx
.
re
Launch
({
url
:
`../index/main?from=login&backpath=
${
this
.
backPath
}
¶ms=
${
encodeURIComponent
(
this
.
backParams
)}
`
...
...
@@ -132,7 +139,7 @@ export default {
e
.
mp
.
detail
.
encryptedData
,
e
.
mp
.
detail
.
iv
);
this
.
unionId
=
data
.
unionId
;
this
.
unionId
=
data
.
unionId
|
""
;
this
.
userInfo
=
JSON
.
parse
(
e
.
target
.
rawData
);
console
.
log
(
"data"
,
data
,
this
.
unionId
);
}
...
...
@@ -143,6 +150,7 @@ export default {
success
:
()
=>
{
//session_key 未过期,并且在本生命周期一直有效
if
(
e
.
target
.
errMsg
==
"getPhoneNumber:ok"
)
{
console
.
log
(
"生命周期一直"
);
this
.
isShowPhone
=
false
;
this
.
phoneNumber
=
wx_decode
(
process
.
env
.
APPID
,
...
...
@@ -170,15 +178,16 @@ export default {
nickname
:
this
.
userInfo
.
nickName
})
.
then
(
res
=>
{
console
.
log
(
res
.
data
,
"=================-"
);
//绑定成功
if
(
res
.
data
.
code
==
200
)
{
this
.
backParams
+=
`&sessionid=
${
res
.
data
.
data
.
sessionId
}
`
;
// console.log(this.backParams, "binduser");
// wx.setStorage({
// key: "sessionId",
// data: res.data.data
// })
;
wx
.
re
directTo
({
wx
.
setStorage
({
key
:
"sessionid"
,
data
:
res
.
data
.
data
.
sessionId
});
process
.
env
.
sessionid
=
res
.
data
.
data
.
sessionId
;
wx
.
re
Launch
({
url
:
`../index/main?from=login&backpath=
${
this
.
backPath
}
¶ms=
${
encodeURIComponent
(
this
.
backParams
)}
`
...
...
@@ -190,16 +199,23 @@ export default {
});
},
backMainHandle
()
{
wx
.
re
directTo
({
wx
.
re
Launch
({
url
:
`../index/main?from=login&backpath=
${
this
.
backPath
}
¶ms=
${
encodeURIComponent
(
this
.
backParams
)}
`
});
},
eLogin
()
{
//企业员工登录
eLogin
()
{
//企业员工登录
wx
.
redirectTo
({
url
:
`../index/main?from=login&backpath=/login/accountLogin`
});
},
handbindHandle
()
{
//绑定手机号
wx
.
navigateTo
({
url
:
`../index/main?from=login&backpath=/login/wxRegister`
});
}
}
};
...
...
@@ -207,6 +223,7 @@ export default {
<
style
lang=
"scss"
scoped
>
.domain
{
//
position
:
relative
;
.toCLogin
{
display
:
flex
;
width
:
100%
;
...
...
@@ -223,18 +240,64 @@ export default {
.btn_info
{
margin
:
0
auto
;
color
:
#
fff
;
color
:
#
000
;
align-items
:
center
;
justify-content
:
space-around
;
.btn
{
margin-top
:
180px
;
background-color
:
#01d10c
;
color
:
#fff
;
height
:
45px
;
width
:
200px
;
border-radius
:
90
px
;
border-radius
:
5
px
;
}
}
.btn_info1
{
margin
:
80px
10px
;
color
:
#000
;
align-items
:
center
;
justify-content
:
space-around
;
border
:
0.5px
solid
#000
;
border-radius
:
5px
;
padding
:
15px
;
z-index
:
1
;
background-color
:
#fff
;
h1
{
text-align
:
center
;
font-size
:
22px
;
margin
:
10px
15px
;
font-weight
:
700
;
}
.btn
{
margin-top
:
10px
;
background-color
:
#01d10c
;
color
:
#fff
;
height
:
45px
;
//
width
:
90%
;
border-radius
:
5px
;
font-size
:
16px
;
}
.btn2
{
border
:
1px
solid
#000
;
height
:
45px
;
//
width
:
90%
;
border-radius
:
5px
;
margin
:
10px
auto
;
text-align
:
center
;
font-size
:
16px
;
line-height
:
45px
;
}
}
.layer
{
position
:
fixed
;
top
:
0
;
left
:
0
;
width
:
100%
;
height
:
100%
;
background
:
rgba
(
0
,
0
,
0
,
0.5
);
z-index
:
0
;
}
.enterpriseLogin
{
position
:
absolute
;
bottom
:
20px
;
...
...
@@ -245,13 +308,10 @@ export default {
font-size
:
15px
;
}
}
.bind
{
.toCLogin1
{
position
:
absolute
;
top
:
0
;
left
:
0
;
}
}
//
.login
{
//
background-color
:
green
;
//
margin
:
30px
;
//
color
:
#fff
;
//
}
</
style
>
src/pages/wxPay/index.vue
View file @
f74e40d8
<
template
>
<div>
正在支付中。。。
</div>
<div>
{{
message
}}
</div>
</
template
>
<
script
>
import
{
formatTime
}
from
"@/utils/index"
;
import
wxPay
from
"@/api/wxPay"
;
export
default
{
components
:
{
// card
...
...
@@ -12,46 +12,38 @@ export default {
data
()
{
return
{
message
:
"正在支付中"
,
shopmixid
:
""
,
openId
:
""
,
options
:
{}
};
},
onLoad
(
options
)
{
console
.
log
(
"支付开始"
,
options
);
Object
.
assign
(
this
.
$data
,
this
.
$options
.
data
());
//mpvue 的混合周期 使用小程序生命周期数据未初始化
console
.
log
(
"onload//"
);
this
.
options
=
JSON
.
parse
(
options
.
ordercode
);
this
.
getTempcode
(
this
.
options
);
},
methods
:
{
getTempcode
(
options
)
{
let
ths
=
this
;
wx
.
login
({
success
:
res
=>
{
// 发送 res.code 到后台换取 openId, sessionKey, unionId
console
.
log
(
"支付code:"
,
res
);
options
.
openId
=
"ohUOewfkbVbxHLLledEGGNUu1XgY"
;
this
.
getPayinfo
(
options
);
console
.
log
(
this
.
options
,
"pages/wxPay/main"
);
let
that
=
this
;
wx
.
getStorage
({
key
:
"openid"
,
success
(
res
)
{
// this.openId=res;
console
.
log
(
that
.
options
,
"++++"
);
console
.
log
(
res
,
"openid"
);
that
.
options
.
openId
=
res
.
data
;
that
.
options
.
tradeType
=
"Mini"
;
console
.
log
(
"支付开始"
,
that
.
options
);
that
.
toPay
();
}
});
// this.options.openId = "ohUOewfkbVbxHLLledEGGNUu1XgY";
},
getPayinfo
(
options
)
{
var
self
=
this
;
wx
.
request
({
url
:
"http://test-m-shop.mayi888.cn/innerApi/shopApiService/pay/to_wx_pay"
,
//后台接口地址
data
:
options
,
method
:
"POST"
,
header
:
{
"Content-Type"
:
"application/x-www-form-urlencoded"
,
"Shop-Mixid"
:
"dev001"
,
Authorization
:
"ce9d0ca7-ba9b-4951-9c42-47cd9b5e4f42"
},
success
:
function
(
res
)
{
console
.
log
(
res
,
"ressssssss"
);
methods
:
{
toPay
()
{
wxPay
.
to_wx_pay
(
this
.
options
)
.
then
(
res
=>
{
let
payData
=
JSON
.
parse
(
res
.
data
.
data
);
payData
.
appId
=
'wxfe9889fb08e7f50b'
;
console
.
log
(
res
,
"ressssssss"
);
// {
// timestamp: 0, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
// nonceStr: '', // 支付签名随机串,不长于 32 位
...
...
@@ -61,36 +53,48 @@ export default {
// success:
// }
payData
.
success
=
res
=>
{
console
.
log
(
"支付成功"
,
res
);
// wx.redirectTo({"url":`../index/main?payCallback=/pay/paySuccess&orderSn=${options.orderSn}`});
// Toast("支付成功~");
// window.location.replace('/pay/paySuccess?orderSn='+this.$route.query.orderSn);
// this.$router.replace(
// "/pay/paySuccess?orderSn=" + this.$route.query.orderSn
// );
console
.
log
(
"支付成功"
,
res
,
this
.
options
);
this
.
message
=
"支付成功"
;
let
that
=
this
;
wx
.
redirectTo
({
url
:
`../index/main?from=wxPay&backpath=/pay/paySuccess¶ms=
${
that
.
options
.
orderSn
}
`
});
};
payData
.
fail
=
res
=>
{
console
.
log
(
"支付失败"
,
res
);
console
.
log
(
"支付失败"
,
res
,
this
.
options
.
orderSn
);
this
.
message
=
"支付失败"
;
let
that
=
this
;
console
.
log
(
`../index/main?from=wxPay&backpath=/pay/paySuccess¶ms=
${
that
.
options
.
orderSn
}
`
)
wx
.
redirectTo
({
url
:
`../index/main?from=wxPay&backpath=/pay/paySuccess¶ms=
${
that
.
options
.
orderSn
}
`
});
// window.location.replace('/pay/paySuccess?orderSn='+this.$route.query.orderSn);
// this.$router.replace(
// "/pay/paySuccess?orderSn=" + this.$route.query.orderSn
// );
};
payData
.
complete
=
res
=>
{
console
.
log
(
"支付取消"
,
res
,
options
);
wx
.
redirectTo
({
"url"
:
`../index/main?from=wxPay&backpath=/pay/paySuccess¶ms=
${
options
.
orderSn
}
`
});
if
(
res
.
errMsg
==
"chooseWXPay:cancel"
)
{
console
.
log
(
"支付取消11"
);
// payApi.cancelPayment(this.$route.query.orderSn);
console
.
log
(
"支付取消"
,
this
.
options
);
this
.
message
=
"支付取消"
;
let
that
=
this
;
wx
.
redirectTo
({
url
:
`../index/main?from=wxPay&backpath=/pay/paySuccess¶ms=
${
that
.
options
.
orderSn
}
`
});
}
};
wx
.
requestPayment
(
payData
);
// wx.navigateTo({
// url: `/pages/lnyc2019/detail?ordercode=${self.data.ordercode}`
// });
}
});
})
.
catch
(
err
=>
{});
}
}
};
...
...
src/utils/request.js
View file @
f74e40d8
let
shopMixid
=
"dev001"
;
console
.
log
(
'----------------------------'
,
process
.
env
.
sessionid
)
export
function
requestGET
(
url
,
options
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
wx
.
request
({
...
...
@@ -6,9 +7,8 @@ export function requestGET(url, options) {
data
:
options
,
method
:
"GET"
,
header
:
{
"Content-Type"
:
"application/x-www-form-urlencoded"
,
"Shop-Mixid"
:
shopMixid
,
Authorization
:
"
ce9d0ca7-ba9b-4951-9c42-47cd9b5e4f42
"
Authorization
:
"
eedbbdaf-844c-4fcc-8970-1fb92346441c
"
},
success
:
function
(
res
)
{
resolve
(
res
)
...
...
@@ -28,7 +28,28 @@ export function requestPOST(url, options) {
method
:
"POST"
,
header
:
{
"Shop-Mixid"
:
shopMixid
,
Authorization
:
"ce9d0ca7-ba9b-4951-9c42-47cd9b5e4f42"
Authorization
:
"eedbbdaf-844c-4fcc-8970-1fb92346441c"
},
success
:
function
(
res
)
{
resolve
(
res
)
},
fail
:
function
(
res
)
{
reject
(
res
)
}
})
})
}
export
async
function
requestPOST1
(
url
,
options
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
wx
.
request
({
url
:
url
,
data
:
options
,
method
:
"POST"
,
header
:
{
"Content-Type"
:
"application/x-www-form-urlencoded"
,
"Shop-Mixid"
:
shopMixid
,
Authorization
:
"eedbbdaf-844c-4fcc-8970-1fb92346441c"
},
success
:
function
(
res
)
{
resolve
(
res
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment