Skip to content

Commit 56d3f1c

Browse files
committed
增加普通h5浏览器的登陆,支付
1 parent dc107f9 commit 56d3f1c

15 files changed

Lines changed: 386 additions & 142 deletions

File tree

App.vue

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
goLogin: false,
88
subDomain: 'jdjf0115',
99
merchantId: '42151',
10-
version: '0.0.1',
10+
version: '0.0.2',
1111
sysconfigkeys: 'mallName,shopMod,share_profile'
1212
},
1313
onLaunch: function() {
@@ -112,20 +112,28 @@
112112
}, 500)
113113
// #endif
114114
// #ifdef H5
115-
// TODO 后续需要判断是不是在微信内部打开
116115
const isLogined = await this.checkHasLoginedH5()
117116
if (!isLogined) {
118-
// https://www.yuque.com/apifm/nu0f75/fpvc3m
119-
const res = await this.$wxapi.siteStatistics()
120-
const wxMpAppid = res.data.wxMpAppid
121-
let _domian = this.globalData.h5Domain + '/pages/index/index'
122-
_domian = encodeURIComponent(_domian)
123-
console.log(_domian);
124-
if (!this.globalData.goLogin) {
125-
this.globalData.goLogin = true
126-
window.parent.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
127-
wxMpAppid + '&redirect_uri=' + _domian +
128-
'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
117+
// 判断是普通浏览器还是微信浏览器
118+
const ua = window.navigator.userAgent.toLowerCase();
119+
console.log(ua);//mozilla/5.0 (iphone; cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko)version/9.0 mobile/13b143 safari/601.1
120+
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
121+
// https://www.yuque.com/apifm/nu0f75/fpvc3m
122+
const res = await this.$wxapi.siteStatistics()
123+
const wxMpAppid = res.data.wxMpAppid
124+
let _domian = this.globalData.h5Domain + '/pages/index/index'
125+
_domian = encodeURIComponent(_domian)
126+
console.log(_domian);
127+
if (!this.globalData.goLogin) {
128+
this.globalData.goLogin = true
129+
window.parent.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
130+
wxMpAppid + '&redirect_uri=' + _domian +
131+
'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
132+
}
133+
} else {
134+
uni.navigateTo({
135+
url: "/pages/login/login"
136+
})
129137
}
130138
}
131139
// #endif
@@ -151,6 +159,9 @@
151159
this.$u.vuex('token', res.data.token)
152160
this.$u.vuex('uid', res.data.uid)
153161
this.$u.vuex('openid', res.data.openid)
162+
setTimeout(() => {
163+
uni.$emit('loginOK', {})
164+
}, 500)
154165
}
155166
}
156167
}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
# 开发配置
2121

2222
1. `App.vue` 中的代码 `subDomain: tz` 中的 `tz` 修改为你自己的专属域名(登陆api工厂的后台,在后台首页即可查看你自己的专属域名)
23-
2. 后台左侧菜单“工厂设置” -> “数据克隆” -> “将别人的数据克隆给我”,填写 `951` 克隆一份测试数据
23+
2. 如果需要发布h5版本,`App.vue` 中的代码 `h5Domain` 修改为你自己的h5域名
24+
3. `App.vue` 中的代码 `merchantId: '42151'` 中的 `merchantId` 修改为你自己的商户ID(登陆api工厂的后台,在左侧菜单,工厂设置,商户信息可以看到你的商户ID)
25+
4. 后台左侧菜单“工厂设置” -> “数据克隆” -> “将别人的数据克隆给我”,填写 `951` 克隆一份测试数据
2426

2527
# QQ交流群
2628

components/goods-pop/goods-pop.vue

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
// console.log('最新值是:'+newVal,"原来的值是:"+ oldVal);
118118
// },
119119
goodsDetail: {
120-
// deep: true,
120+
deep: true,
121121
immediate: true,
122122
handler(newVal, oldName) {
123123
this._initData()
@@ -302,31 +302,44 @@
302302
},
303303
goCart() {
304304
this.close()
305+
if(this.goodsDetail.basicInfo.supplyType == 'vop_jd') {
306+
uni.setStorageSync('cart_tabIndex', 1)
307+
}
305308
uni.switchTab({
306309
url: "/pages/cart/index"
307310
})
308311
},
309312
async goodsFavCheck() {
310-
// https://www.yuque.com/apifm/nu0f75/ugf7y9
311-
const res = await this.$wxapi.goodsFavCheckV2({
313+
const data = {
312314
token: this.token,
313315
type: 0,
314316
goodsId: this.goodsDetail.basicInfo.id
315-
})
317+
}
318+
if(this.goodsDetail.basicInfo.supplyType == 'vop_jd') {
319+
data.type = 1
320+
data.goodsId = this.goodsDetail.basicInfo.yyId
321+
}
322+
// https://www.yuque.com/apifm/nu0f75/ugf7y9
323+
const res = await this.$wxapi.goodsFavCheckV2(data)
316324
if (res.code == 0) {
317325
this.faved = true
318326
} else {
319327
this.faved = false
320328
}
321329
},
322330
async addFav() {
331+
const data = {
332+
token: this.token,
333+
type: 0,
334+
goodsId: this.goodsDetail.basicInfo.id
335+
}
336+
if(this.goodsDetail.basicInfo.supplyType == 'vop_jd') {
337+
data.type = 1
338+
data.goodsId = this.goodsDetail.basicInfo.yyId
339+
}
323340
if (this.faved) {
324341
// 取消收藏 https://www.yuque.com/apifm/nu0f75/zy4sil
325-
const res = await this.$wxapi.goodsFavDeleteV2({
326-
token: this.token,
327-
type: 0,
328-
goodsId: this.goodsDetail.basicInfo.id
329-
})
342+
const res = await this.$wxapi.goodsFavDeleteV2(data)
330343
if (res.code == 0) {
331344
this.faved = false
332345
} else {
@@ -336,12 +349,14 @@
336349
})
337350
}
338351
} else {
352+
const extJsonStr = {
353+
pic: this.goodsDetail.basicInfo.pic,
354+
goodsName: this.goodsDetail.basicInfo.name,
355+
supplyType: this.goodsDetail.basicInfo.supplyType
356+
}
357+
data.extJsonStr = JSON.stringify(extJsonStr)
339358
// 加入收藏 https://www.yuque.com/apifm/nu0f75/mr1471
340-
const res = await this.$wxapi.goodsFavAdd({
341-
token: this.token,
342-
type: 0,
343-
goodsId: this.goodsDetail.basicInfo.id
344-
})
359+
const res = await this.$wxapi.goodsFavAdd(data)
345360
if (res.code == 0) {
346361
this.faved = true
347362
} else {

main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ App.mpType = 'app'
1818

1919
Vue.use(uView)
2020

21-
// WXAPI.init('tz')
2221
Vue.prototype.$wxapi = WXAPI
2322

2423
// 引入uView提供的对vuex的简写法文件

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
"enable" : false
156156
}
157157
},
158-
"title" : "tianshitongzhuang",
158+
"title" : "京栖无限企福平台",
159159
"sdkConfigs" : {
160160
"maps" : {
161161
"qqmap" : {

pages.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@
144144
"style": {
145145
"navigationBarTitleText": "申请售后"
146146
}
147+
},
148+
{
149+
"path" : "pages/login/login",
150+
"style": {
151+
"navigationBarTitleText": "登陆"
152+
}
147153
}
148154
],
149155
"globalStyle": {

pages/cart/index.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@
113113
114114
},
115115
onShow() {
116+
const cart_tabIndex = uni.getStorageSync('cart_tabIndex')
117+
if(cart_tabIndex == 1) {
118+
this.tabIndex = 1
119+
uni.removeStorageSync('cart_tabIndex')
120+
}
116121
if(this.tabIndex == 0) {
117122
this._shippingCarInfo()
118123
}

pages/goods/detail.vue

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
this.$u.vuex('referrer', scene.split(',')[1])
171171
}
172172
}
173-
this._goodsDetail(e.id)
173+
this._goodsDetail(e.id, e.supplyType, e.yyId)
174174
},
175175
onShow() {
176176
@@ -185,20 +185,35 @@
185185
186186
},
187187
methods: {
188-
async _goodsDetail(goodsId) {
189-
// https://www.yuque.com/apifm/nu0f75/vuml8a
190-
const res = await this.$wxapi.goodsDetail(goodsId, this.token)
191-
if (res.code != 0) {
192-
uni.showToast({
193-
title: res.msg,
194-
icon: 'none'
195-
})
196-
setTimeout(() => {
197-
uni.navigateBack()
198-
}, 3000)
199-
return
188+
async _goodsDetail(goodsId, supplyType, yyId) {
189+
if(goodsId) {
190+
// https://www.yuque.com/apifm/nu0f75/vuml8a
191+
const res = await this.$wxapi.goodsDetail(goodsId, this.token)
192+
if (res.code != 0) {
193+
uni.showToast({
194+
title: res.msg,
195+
icon: 'none'
196+
})
197+
setTimeout(() => {
198+
uni.navigateBack()
199+
}, 3000)
200+
return
201+
}
202+
this.goodsDetail = res.data
203+
} else {
204+
// 不是api工厂商品
205+
this.goodsDetail = {
206+
basicInfo: {
207+
yyId: yyId,
208+
yyIdStr: yyId,
209+
supplyType: supplyType,
210+
pic: '',
211+
name: '',
212+
stores: 999999
213+
},
214+
pics: []
215+
}
200216
}
201-
this.goodsDetail = res.data
202217
// 检测是否收藏
203218
this.goodsFavCheck()
204219
this._reputationList()
@@ -225,7 +240,8 @@
225240
this.jdGoodsDetail = res.data
226241
this.goodsDetail.basicInfo.minPrice = this.jdGoodsDetail.price.priceSale
227242
this.goodsDetail.basicInfo.originalPrice = this.jdGoodsDetail.price.priceJd
228-
this.goodsDetail.basicInfo.name = this.jdGoodsDetail.price.skuName
243+
this.goodsDetail.basicInfo.name = this.jdGoodsDetail.price.skuName
244+
this.goodsDetail.basicInfo.pic = this.jdGoodsDetail.imageDomain + this.jdGoodsDetail.price.pic
229245
if (this.jdGoodsDetail.info.wxintroduction) {
230246
this.wxintroduction = JSON.parse(this.jdGoodsDetail.info.wxintroduction)
231247
}
@@ -268,32 +284,45 @@
268284
// this.goodsDetail.content = res.data.usageGuide
269285
this.wxintroduction = res.data.pics
270286
},
271-
goCart() {
287+
goCart() {
288+
if(this.goodsDetail.basicInfo.supplyType == 'vop_jd') {
289+
uni.setStorageSync('cart_tabIndex', 1)
290+
}
272291
uni.switchTab({
273292
url: "/pages/cart/index"
274293
})
275294
},
276-
async goodsFavCheck() {
295+
async goodsFavCheck() {
296+
const data = {
297+
token: this.token,
298+
type: 0,
299+
goodsId: this.goodsDetail.basicInfo.id
300+
}
301+
if(this.goodsDetail.basicInfo.supplyType == 'vop_jd') {
302+
data.type = 1
303+
data.goodsId = this.goodsDetail.basicInfo.yyId
304+
}
277305
// https://www.yuque.com/apifm/nu0f75/ugf7y9
278-
const res = await this.$wxapi.goodsFavCheckV2({
279-
token: this.token,
280-
type: 0,
281-
goodsId: this.goodsDetail.basicInfo.id
282-
})
306+
const res = await this.$wxapi.goodsFavCheckV2(data)
283307
if (res.code == 0) {
284308
this.faved = true
285309
} else {
286310
this.faved = false
287311
}
288312
},
289-
async addFav() {
313+
async addFav() {
314+
const data = {
315+
token: this.token,
316+
type: 0,
317+
goodsId: this.goodsDetail.basicInfo.id
318+
}
319+
if(this.goodsDetail.basicInfo.supplyType == 'vop_jd') {
320+
data.type = 1
321+
data.goodsId = this.goodsDetail.basicInfo.yyId
322+
}
290323
if (this.faved) {
291324
// 取消收藏 https://www.yuque.com/apifm/nu0f75/zy4sil
292-
const res = await this.$wxapi.goodsFavDeleteV2({
293-
token: this.token,
294-
type: 0,
295-
goodsId: this.goodsDetail.basicInfo.id
296-
})
325+
const res = await this.$wxapi.goodsFavDeleteV2(data)
297326
if (res.code == 0) {
298327
this.faved = false
299328
} else {
@@ -302,13 +331,15 @@
302331
icon: 'none'
303332
})
304333
}
305-
} else {
334+
} else {
335+
const extJsonStr = {
336+
pic: this.goodsDetail.basicInfo.pic,
337+
goodsName: this.goodsDetail.basicInfo.name,
338+
supplyType: this.goodsDetail.basicInfo.supplyType
339+
}
340+
data.extJsonStr = JSON.stringify(extJsonStr)
306341
// 加入收藏 https://www.yuque.com/apifm/nu0f75/mr1471
307-
const res = await this.$wxapi.goodsFavAdd({
308-
token: this.token,
309-
type: 0,
310-
goodsId: this.goodsDetail.basicInfo.id
311-
})
342+
const res = await this.$wxapi.goodsFavAdd(data)
312343
if (res.code == 0) {
313344
this.faved = true
314345
} else {

0 commit comments

Comments
 (0)