freshes js bridge
npm install @freshservice/bridgefreshes bridge
`` bash`install dependencies
yarn add @freshservice/bridge引入
`
import {
SignIn,
Address,
AddToCart,
Cart,
Coupon,
FindPayPwd,
HomePage,
OnlineService,
Order,
Point,
Product,
Profile,
Recharge,
Refresh,
Register,
SetShareOptions,
ShareMenu,
UnlockPayPwd,
UpdateAuth,
SetCustomData,
AccountCard,
LimitInWx,
Category
} from '@freshservice/bridge'
...
data () {
return {
from: 'app/wechat' // 从建议从url获取或者从UpdateAuth方法存储的localStorage中获取from
}
}
`
例如登录,跳转到测试环境:
SignIn.init({test: true}).execute()跳转到正式:
SignIn.init().execute()
`$3
`
SignIn.init().execute()
`$3
`
// 手机号码只有从微信商城登录才有,app无此字段
UpdateAuth.init().execute()
console.log(window.localStorage.getItem('TOC_TOKEN'))// 用户token, 例如 {"AccessToken":"xxxxxabcxx","CustomerGuid":"xxx-xxx","SourceType":"9","Phone":"181111xxxxxxx","from":"wechat","expires":"2019-01-08T02:13:30.713Z"}
console.log(window.localStorage.getItem('TOC_CITY'))// 城市信息, 例如 {"CityId":"3","CityFlag":"sh"}
`注意:app里登录完成后仅仅只是将用户信息塞入到url,并不会刷新。
解决方案:
`
'$route.query' () {
if (this.$route.query.token) {
window.location.reload()
}
}
`$3
`
const productId = 111 // 商品id
AddToCart
.init()
.execute(productId)
.success(response => {
// do something
})
`$3
`
const data = {
title: '标题',
desc: '描述',
link: 'https://www.baidu.com',
imgUrl: 'https://picpro-sz.34580.com/sz/ImageUrl/8367/400.jpeg',
shareCode: 3 // 0.禁止分享 1.只允许微信 2.允许所有 3.分享大图
}
SetShareOptions.init().execute(data).success(() => {
// 分享成功
})
`
$3
`
Address.init().execute()
`$3
`
Cart.init().execute()
`$3
`
Coupon.init().execute()
`$3
`
FindPayPwd.init().execute()
`$3
`
UnlockPayPwd.init().execute()
`$3
`
HomePage.init().execute()
`$3
`
OnlineService.init().execute()
`$3
`
Order.init().execute()
`$3
`
Point.init().execute()
`$3
`
const productId = 111 // 商品id
Product.init().execute(productId)
`$3
`
Profile.init().execute()
`$3
`
Recharge.init().execute()
`$3
`
Refresh.init().execute()
`$3
`
// 一般此方法不使用,由公共登录页引导登录即可
const registerMethod = 1200 // ios 安卓有区别
Register.init().execute(registerMethod)
`$3
`
ShareMenu.init().execute()
`
$3
`
SetCustomData.init().execute({ zhugeTitle: '测试标题吼吼吼吼' })
`$3
`
AccountCard.init().execute()
`$3
`
LimitInWx.init().execute()
`
当前环境为微信返回true,并且code作为query string跟在url后,否则返回false.$3
`
type: 1 全场通用 2 品类 4 or 5 单品
// Category.init().execute({type: 4, id: 10493})
// Category.init().execute({type: 2, id: 300})
Category.init().execute({type: 1})
``