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
bfb0e796
Commit
bfb0e796
authored
Apr 27, 2021
by
李嘉林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
多主题方法封装
parent
8db45656
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
431 additions
and
7 deletions
+431
-7
src/api/shop.js
+23
-2
src/main.js
+9
-3
src/utils/mayi.js
+100
-2
src/utils/themeModule.js
+299
-0
No files found.
src/api/shop.js
View file @
bfb0e796
...
...
@@ -12,9 +12,30 @@ export default {
},
// 页面数据
themePagesInfo
(
params
)
{
return
requestPOST
(
`
${
process
.
env
.
OLSHOP_URL
}
/cms/get_shop_install_pages`
,
params
)
return
requestPOST
(
`
${
process
.
env
.
OLSHOP_URL
}
/cms/get_shop_install_pages`
,
params
);
},
checkShowCondition
(
params
)
{
return
requestPOST
(
`
${
process
.
env
.
OLSHOP_URL
}
/cms/check_show_condition`
,
params
)
return
requestPOST
(
`
${
process
.
env
.
OLSHOP_URL
}
/cms/check_show_condition`
,
params
);
},
// 获取新版会员卡列表
getV3CardList
(
params
)
{
return
requestPOST
(
`
${
process
.
env
.
OLSHOP_URL
}
/user/membership_card_list`
,
{
params
}
);
},
// 领取新版无门槛会员卡
drawV3Card
(
params
)
{
return
requestPOST
(
`
${
process
.
env
.
OLSHOP_URL
}
/user/draw_membership_card?cardId=
${
params
}
`
);
}
};
src/main.js
View file @
bfb0e796
...
...
@@ -11,7 +11,13 @@ import classificationApi from "./api/classification";
import
spokesmanApi
from
'./api/spokesman'
import
{
DFSImg
,
concatUrl
}
from
"@/utils/index"
;
import
fenxiaoModel
from
"@/utils/fenxiaoModel"
;
import
{
$themeToLink
,
$themeAddToCard
,
$themeArticleLike
}
from
"@/utils/mayi"
;
import
{
$themeAddToCard
,
$themeArticleLike
,
getCoupon
,
themeMemberCardClick
}
from
"@/utils/mayi"
;
import
{
themeToLinkInit
}
from
"@/utils/themeModule"
;
import
shop
from
"./api/shop"
;
import
spokesman
from
"@/api/spokesman"
;
...
...
@@ -31,6 +37,8 @@ Vue.prototype.$mpAnalytics = mpAnalytics;
const
app
=
new
Vue
(
App
)
app
.
$mount
()
// 初始化
themeToLinkInit
({
homeNative
:
2
,
getCoupon
,
themeMemberCardClick
});
// glob挂载到
let
mpApp
=
getApp
();
...
...
@@ -66,8 +74,6 @@ mpApp.indexBgCallBack = function(){ }
// 全局数据
mpApp
.
processEnv
=
process
.
env
;
console
.
log
(
'3555555'
,
wx
)
// 全局跳转 data为link对象
mpApp
.
$themeToLink
=
$themeToLink
// 全局加入购物车
mpApp
.
$themeAddToCard
=
$themeAddToCard
// 文章点赞
...
...
src/utils/mayi.js
View file @
bfb0e796
import
cart
from
"@/api/cart"
import
shop
from
"@/api/shop"
import
coupon
from
"@/api/coupon"
;
import
classificationApi
from
"@/api/classification"
;
// 登录白名单 name
export
const
noLoginList
=
[
"index"
,
"media-video"
,
"goods-goodsInfo"
,
"goods-commodityMenu"
,
"goodsSearch-goodsSearch"
,
"chooseStores"
,
"activty-receivingGift"
,
"activty"
,
"login-register"
,
"login-phoneLogin"
,
"login-authInformation"
,
"login-forgetPassWord"
,
"login-accountLogin"
,
"login-wxRegister"
,
"pay-payList"
,
"comment-evaluateList"
,
"goods-commonProblemList"
,
"article-articlePage"
,
"article-articleList"
,
"goods-posters"
,
"liveBroadcast"
,
"liveBroadcast-list"
,
"personalCenter-coupon-getCoupon"
,
"buyerShow-showDetail"
,
"goods-addGoodsList"
,
"personalCenter-CDkey-exchange"
,
"giftCards-linkReceive"
,
"giftCoupon-preview"
,
"smartForm"
,
"shopCart-shareShopCart"
,
"groupBuying-beInvite"
,
"brandTopics"
,
'personalCenter-spokesmanCenter'
,
'personalCenter-spokesmanCenter-mine-spokesmanHomePage'
,
'liveBroadcast-lived'
,
'personalCenter-spokesmanCenter-mine-getBusinessCard'
,
'changeAdr'
];
...
...
@@ -233,4 +235,100 @@ export function $themeArticleLike(item, callback) {
}
else
{
}
});
}
\ No newline at end of file
}
export
function
getCoupon
(
code
,
item
)
{
console
.
log
(
"--------------------239"
);
let
usingIntegrals
=
(
item
.
consumeIntegral
-
0
).
toFixed
(
0
);
let
couponCode
=
code
;
console
.
log
(
item
,
"------------------------242"
);
if
(
item
.
receiveCostType
==
1
)
{
wx
.
showModal
({
confirmColor
:
"#CA173B"
,
content
:
`是否消耗
${
usingIntegrals
}
积分领取`
})
.
then
(()
=>
{
useCoupon
(
2
,
couponCode
,
usingIntegrals
);
})
.
catch
(()
=>
{
// on cancel
});
return
;
}
else
{
useCoupon
(
1
,
couponCode
,
usingIntegrals
);
}
};
function
useCoupon
(
val
,
couponCode
,
usingIntegrals
)
{
coupon
.
receive_coupon
(
couponCode
).
then
(
res
=>
{
console
.
log
(
res
,
"cou137"
);
if
(
res
.
data
.
data
==
"true"
)
{
if
(
val
==
1
)
{
wx
.
showToast
({
title
:
"领取成功"
,
icon
:
"success"
});
}
else
{
let
tit
=
"积分-"
+
usingIntegrals
;
wx
.
showToast
({
title
:
tit
,
icon
:
"success"
});
}
// item.receive=false;
}
else
{
wx
.
showToast
({
title
:
res
.
data
.
msg
,
icon
:
"none"
});
// item.receive=true;
}
});
};
export
function
themeMemberCardClick
(
item
)
{
let
query
=
{
portalCardId
:
item
.
id
};
shop
.
getV3CardList
(
query
).
then
(
res
=>
{
console
.
log
(
res
,
'--------------------282'
)
if
(
res
.
data
.
code
==
200
)
{
let
cardData
=
""
;
res
.
data
.
data
.
forEach
(
innerItem
=>
{
if
(
innerItem
.
id
==
item
.
id
)
{
cardData
=
innerItem
;
}
});
if
(
cardData
.
receiveWay
==
0
)
{
// 无门槛
let
cardId
=
cardData
.
id
;
let
userInfo
=
wx
.
getStorageSync
(
"userInfo"
)
?
JSON
.
parse
(
wx
.
getStorageSync
(
"userInfo"
))
:
""
;
shop
.
drawV3Card
(
cardId
).
then
(
res
=>
{
if
(
res
.
data
.
code
==
200
)
{
wx
.
showToast
({
title
:
`开通【
${
cardData
.
title
}
】成功`
,
icon
:
"none"
});
}
else
{
if
(
res
.
data
.
msg
==
"不能重复领卡"
)
{
let
query
=
{
cardId
:
cardData
.
id
,
userTel
:
userInfo
.
mobilephone
};
let
url
=
`../index/main?from=themeLink&backpath=
${
encodeURIComponent
(
"/personalCenter/membershipCard"
)}
¶ms=
${
encodeURIComponent
(
query
)}
`
;
wx
.
navigateTo
({
url
});
}
else
{
wx
.
showToast
({
title
:
res
.
data
.
msg
,
icon
:
"none"
});
}
}
});
}
else
if
(
cardData
.
receiveWay
==
1
)
{
// 自动领取
console
.
log
(
"自动领取"
);
}
else
if
(
cardData
.
receiveWay
==
2
)
{
// 付费购买
if
(
cardData
.
receiveStatus
==
0
)
{
let
query
=
{
cardId
:
cardData
.
id
};
let
url
=
`../index/main?from=themeLink&backpath=
${
encodeURIComponent
(
"/pay/payCard"
)}
¶ms=
${
encodeURIComponent
(
query
)}
`
;
wx
.
navigateTo
({
url
});
}
else
{
let
query
=
{
cardId
:
cardData
.
id
,
userTel
:
userInfo
.
mobilephone
};
let
url
=
`../index/main?from=themeLink&backpath=
${
encodeURIComponent
(
"/personalCenter/membershipCard"
)}
¶ms=
${
encodeURIComponent
(
query
)}
`
;
wx
.
navigateTo
({
url
});
}
}
else
{
console
.
error
(
"无效的领取方式"
);
}
}
else
{
wx
.
showToast
({
title
:
res
.
data
.
msg
,
icon
:
"none"
});
}
});
};
\ No newline at end of file
src/utils/themeModule.js
0 → 100644
View file @
bfb0e796
let
Vue
=
null
;
let
homeNative
=
null
;
//首页环境 1:h5 2:小程序 3:头条
let
miniApp
=
null
;
let
Toast
=
null
;
// 弹窗方法
let
hylToLink
=
null
;
let
toPageFun
=
null
;
let
h5Config
=
null
;
// 函数柯里化
/**
* @toPage type:环境变量
* @pageUrl pageUrlVal:跳转链接
*/
// 调用方法使用.call
function
toPage
(
type
)
{
if
(
type
==
1
)
{
return
function
({
pagePath
,
pageType
=
1
})
{
if
(
pageType
==
1
)
{
this
.
$router
.
push
(
pagePath
);
}
else
if
(
pageType
==
2
)
{
window
.
location
.
href
=
pagePath
;
}
};
}
else
if
(
type
==
2
)
{
return
function
({
pagePath
,
pageType
=
1
})
{
if
(
pageType
==
1
)
{
wx
.
navigateTo
({
url
:
pagePath
});
}
};
}
}
function
toPageUrl
(
backPath
,
backParams
=
""
)
{
return
`../index/main?from=themeLink&backpath=
${
encodeURIComponent
(
backPath
)}
¶ms=
${
encodeURIComponent
(
backParams
)}
`
;
}
/**
*
* @param {*} type 环境变量
*/
function
getSessionId
(
type
)
{
if
(
type
==
1
)
{
return
(
this
.
$store
&&
this
.
$store
.
state
.
sessionId
&&
this
.
$store
.
state
.
sessionId
&&
null
);
}
else
if
(
type
==
2
)
{
return
(
wx
&&
wx
.
getStorageSync
(
"sessionid"
)
&&
JSON
.
parse
(
wx
.
getStorageSync
(
"sessionid"
))
&&
null
);
}
}
function
getIsMini
(
type
)
{
return
type
==
1
&&
this
.
$store
&&
this
.
$store
.
state
.
miniProgram
;
};
/**
*
* @param {*} type 环境变量
*/
function
getUserInfo
(
type
)
{
if
(
type
==
1
)
{
return
this
.
$store
&&
this
.
$store
.
state
.
userInfo
&&
null
;
}
else
if
(
type
==
2
)
{
return
(
wx
&&
wx
.
getStorageSync
(
"userInfo"
)
&&
JSON
.
parse
(
wx
.
getStorageSync
(
"userInfo"
))
&&
null
);
}
}
function
createdUserJWTApi
(
homeNative
)
{
if
(
homeNative
==
1
)
{
try
{
return
require
(
"~/assets/js/daoke.js"
).
createdUserJWT
;
}
catch
(
error
)
{}
}
return
null
;
}
function
getBcakUrlApi
(
homeNative
)
{
if
(
homeNative
==
1
)
{
try
{
return
require
(
"~/assets/js/daoke.js"
).
getBcakUrl
;
}
catch
(
error
)
{}
}
return
null
;
}
//商家中心外链(小程序使用 /pages/wxArticle/main?link 这个方法跳转)
function
getGUIDE_URL
(
type
)
{
if
(
type
==
1
)
{
return
h5Config
.
GUIDE_URL
;
}
else
if
(
type
==
2
)
{
return
config
.
GUIDE_URL
;
}
}
// 分享
function
toShare
(
type
,
data
)
{
if
(
type
==
1
)
{
this
.
$nuxt
.
$SHARE
({
itemList
:
data
.
feature
.
value
});
}
else
if
(
type
==
2
)
{
miniApp
.
shareInit
({
itemList
:
data
.
feature
.
value
});
}
};
// 获取link 中页面地址(link兼容 有object或者string)
function
getUrlofLink
(
data
)
{
return
data
.
link
.
split
(
"?"
)[
0
];
}
function
getUrlofQuery
(
data
)
{
return
data
.
link
.
split
(
"?"
)[
1
]
||
""
;
}
export
function
themeToLinkInit
({
homeNative
:
shop_env
,
getCoupon
,
themeMemberCardClick
})
{
homeNative
=
shop_env
;
console
.
log
(
homeNative
,
"-------------themeToLinkInit"
);
toPageFun
=
toPage
(
homeNative
);
if
(
homeNative
==
1
)
{
try
{
Vue
=
require
(
"vue"
)
||
null
;
h5Config
=
require
(
"~/config"
)
||
null
;
Vue
.
default
.
prototype
.
$themeToLink
=
$themeToLink
;
Toast
=
require
(
"vant"
).
Toast
||
null
;
hylToLink
=
require
(
"~/utils/hylModule.js"
).
hylToLink
||
null
;
}
catch
(
error
)
{}
}
else
if
(
homeNative
==
2
)
{
miniApp
=
getApp
();
miniApp
.
$themeToLink
=
$themeToLink
;
miniApp
.
getCoupon
=
getCoupon
;
miniApp
.
themeMemberCardClick
=
themeMemberCardClick
;
}
}
export
async
function
$themeToLink
(
data
)
{
console
.
log
(
data
,
"$themeToLink"
);
// 第三方嵌入系统
if
(
data
.
type
)
{
if
(
data
.
link
&&
data
.
link
.
includes
(
"scene=sso"
))
{
//?token=${token}&scene=sso
Toast
.
loading
({
message
:
"加载中..."
,
forbidClick
:
true
});
if
(
!
getSessionId
.
call
(
this
))
{
Toast
(
"请先登录"
);
return
;
}
if
(
homeNative
==
1
)
{
let
{
mobilephone
:
phoneNumber
,
email
}
=
getUserInfo
.
call
(
this
);
data
.
link
=
await
getBcakUrlApi
({
toAppid
:
"hgFTLLhgnBmeOyCkcbyv"
,
callbackUrl
:
data
.
link
,
phoneNumber
,
email
});
}
}
if
(
data
.
link
&&
data
.
link
.
includes
(
"dynamicForm"
)
&&
homeNative
==
1
)
{
await
createdUserJWTApi
(
homeNative
)().
then
(
res
=>
{
data
.
link
+=
`&token=
${
res
}
`
;
});
}
}
let
type
=
data
.
type
;
//商城跳转到嗨有料首页
if
(
homeNative
==
1
)
{
hylToLink
();
}
////向后兼容 兼容老数据
if
(
type
==
undefined
||
type
==
"undefined"
)
{
if
(
data
.
length
>
0
)
{
this
.
$nuxt
.
$router
.
push
(
data
);
}
return
;
}
//----
if
(
type
==
0
)
{
//无链接
return
;
}
else
if
(
type
==
1
)
{
//h5页面
//兼容
if
(
data
.
link
.
substring
(
0
,
1
)
==
"/"
)
{
// 跳转类型 targetType 0 push 1 replace
// if (data.targetType && data.targetType == 1) {
// this.$nuxt.$router.push({
// path: data.link,
// });
// } else {
// this.$nuxt.$router.push(data.link);
// }
if
(
homeNative
==
1
)
{
toPageFun
.
call
(
this
,
{
pagePath
:
data
.
link
});
}
else
if
(
homeNative
==
2
)
{
let
url
=
toPageUrl
(
getUrlofLink
(
data
),
getUrlofQuery
(
data
));
toPageFun
.
call
(
this
,
{
pagePath
:
url
});
}
}
else
{
if
(
data
.
link
.
startsWith
(
"http"
)
||
data
.
link
.
startsWith
(
"https"
))
{
if
(
homeNative
==
1
)
{
toPageFun
.
call
(
this
,
{
pagePath
:
data
.
link
,
pageType
:
2
});
}
else
{
let
url
=
"/pages/wxArticle/main?link="
+
encodeURIComponent
(
data
.
link
);
toPageFun
.
call
(
this
,
{
pagePath
:
url
});
}
}
else
{
toPageFun
.
call
(
this
,
{
pagePath
:
data
.
link
,
pageType
:
2
});
}
}
}
else
if
(
type
==
1.1
)
{
//小程序页面 可能增加登录态拦截
if
(
homeNative
==
2
)
{
toPageFun
.
call
(
this
,
{
pagePath
:
data
.
link
});
}
else
{
Toast
(
"暂不支持"
);
}
}
else
if
(
type
==
1.2
)
{
//第三方链接
if
(
data
.
link
==
"outerChain:businessCenter"
)
{
// 进入商家中心外链
console
.
log
(
getGUIDE_URL
(),
"-----getGUIDE_URL()"
);
let
url
=
`
${
getGUIDE_URL
()}
/login?mixid=
${
this
.
$nuxt
.
$route
.
query
.
mixid
}
&back=
${
encodeURIComponent
(
window
.
location
.
href
)}
`
;
toPageFun
.
call
(
this
,
{
pagePath
:
url
,
pageType
:
2
});
return
;
}
if
(
data
.
link
.
substring
(
0
,
1
)
==
"/"
)
{
toPageFun
.
call
(
this
,
{
pagePath
:
data
.
link
});
}
else
{
if
(
this
.
$store
.
state
.
miniProgram
==
1
||
this
.
$store
.
state
.
miniProgram
==
2
)
{
let
url
=
"/pages/wxArticle/main?link="
+
encodeURIComponent
(
data
.
link
);
toPageFun
.
call
(
this
,
{
pagePath
:
url
});
}
else
{
toPageFun
.
call
(
this
,
{
pagePath
:
data
.
link
,
pageType
:
2
});
}
}
}
else
if
(
type
==
2
)
{
//功能
let
featureType
=
data
.
feature
.
type
;
if
(
featureType
==
"themeCouponClick"
||
featureType
==
0
)
{
//优惠券
if
(
homeNative
==
1
)
{
this
.
$themeCouponClick
(
data
.
feature
.
value
.
couponCode
,
data
.
feature
.
value
);
}
else
if
(
homeNative
==
2
)
{
miniApp
.
getCoupon
(
data
.
feature
.
value
.
couponCode
,
data
.
feature
.
value
);
}
}
else
if
(
featureType
==
1
)
{
//分享
if
(
data
.
type
==
2
&&
data
.
feature
.
type
==
1
)
{
//分享
toShare
.
call
(
this
,
homeNative
,
data
)
}
// if (cb) {
// cb();
// }
}
else
if
(
featureType
==
"themeMemberCardClick"
||
featureType
==
2
)
{
//会员卡
if
(
homeNative
==
1
)
{
this
.
$themeMemberCardClick
(
data
.
feature
.
value
);
}
else
if
(
homeNative
==
2
)
{
miniApp
.
themeMemberCardClick
(
data
.
feature
.
value
);
}
}
}
else
if
(
type
==
3
)
{
//小程序跳转到小程序
if
(
homeNative
==
1
)
{
if
(
getIsMini
.
call
(
this
,
homeNative
)
==
1
||
getIsMini
.
call
(
this
,
homeNative
)
==
2
)
{
if
(
this
.
$store
.
getters
[
"sceneModule/flushbonadingVisible"
])
{
let
url
=
`/pages/toMini/toMini?weappPage=
${
encodeURIComponent
(
data
.
link
)}
&weappAppId=
${
data
.
name
}
`
;
toPageFun
.
call
(
this
,
{
pagePath
:
url
});
return
;
}
let
url2
=
`/pages/toMini/main?weappPage=
${
encodeURIComponent
(
data
.
link
)}
&weappAppId=
${
data
.
name
}
`
;
toPageFun
.
call
(
this
,
{
pagePath
:
url2
});
}
else
{
Toast
(
"暂不支持"
);
}
}
else
{
let
url2
=
`/pages/toMini/main?weappPage=
${
encodeURIComponent
(
data
.
link
)}
&weappAppId=
${
data
.
name
}
`
;
toPageFun
.
call
(
this
,
{
pagePath
:
url2
});
}
}
else
{
//向后兼容
if
(
data
.
length
>
0
)
{
toPageFun
.
call
(
this
,
{
pagePath
:
data
.
link
});
}
}
}
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