This commit is contained in:
吴鹏 2026-03-16 10:03:51 +08:00
parent d64f67140c
commit 7483acfc1f
5 changed files with 156 additions and 23 deletions

View File

@ -75,8 +75,8 @@ export default {
} }
}, },
onLoad(e) { onLoad(e) {
if (e.type) { if (e.tyep) {
this.type = e.type this.type = e.tyep
} }
if (e.redirectUrl) { if (e.redirectUrl) {
this.redirectUrl = decodeURIComponent(e.redirectUrl) this.redirectUrl = decodeURIComponent(e.redirectUrl)
@ -92,7 +92,7 @@ export default {
btnfh(){ btnfh(){
if(this.type == 99){ if(this.type == 99){
uni.reLaunch({ uni.reLaunch({
url:'/pages/my' url:'/pages/nearbystores/index'
}) })
}else{ }else{
uni.navigateBack() uni.navigateBack()

View File

@ -128,7 +128,7 @@
</view> </view>
<view class="" style="display: flex;padding:0 42rpx;margin-top: 40rpx;gap: 56rpx;"> <view class="" style="display: flex;padding:0 42rpx;margin-top: 40rpx;gap: 56rpx;">
<image @click="btnkjpw" style="width: 112rpx;height: 122rpx;" src="https://api.ccttiot.com/smartmeter/img/static/ukU5dVsJRl0LjuGvV0m8" mode=""></image> <!-- 卡劵配额 --> <image @click="btnkjpw" style="width: 112rpx;height: 122rpx;" src="https://api.ccttiot.com/smartmeter/img/static/ukU5dVsJRl0LjuGvV0m8" mode=""></image> <!-- 卡劵配额 -->
<image @click="btnyy" style="width: 112rpx;height: 122rpx;" src="https://api.ccttiot.com/smartmeter/img/static/ukU5dVsJRl0LjuGvV0m8" mode=""></image> <!-- 语音同步 --> <image @click="btnyy" style="width: 112rpx;height: 122rpx;" src="https://api.ccttiot.com/smartmeter/img/static/uJ7TUS8111sj8b2M6jcv" mode=""></image> <!-- 语音同步 -->
</view> </view>
</view> </view>

View File

@ -62,20 +62,69 @@ export default {
this.useGiftCode(code) this.useGiftCode(code)
}, },
// wx.login code token
silentLogin() {
return new Promise((resolve) => {
// #ifdef MP-WEIXIN
wx.login({
success: (res) => {
if (!res.code) {
resolve(false)
return
}
const data = { loginCode: res.code, appId: this.$store.state.appid }
this.$u.post('/wxLogin', data).then((loginRes) => {
if (loginRes.code === 200) {
uni.setStorageSync('token', loginRes.token)
resolve(true)
} else {
resolve(false)
}
}).catch(() => resolve(false))
},
fail: () => resolve(false)
})
// #endif
// #ifndef MP-WEIXIN
resolve(false)
// #endif
})
},
//
goLoginWithRedirect(code) {
const backUrl = '/page_user/yonghuewmlq?code=' + encodeURIComponent(code)
uni.navigateTo({
url: '/pages/login/login?redirect=' + encodeURIComponent(backUrl)
})
},
// //
useGiftCode(code) { useGiftCode(code) {
this.loading = true this.loading = true
this.$u this.$u.post(`/app/vipUser/useGiftCode?code=${encodeURIComponent(code)}`).then(res => {
.post(`/app/vipUser/useGiftCode?code=${encodeURIComponent(code)}`)
.then(res => {
this.loading = false
if (res.code === 200) { if (res.code === 200) {
this.loading = false
this.success = true this.success = true
this.message = res.msg || '领取成功,已发放至您的会员账户' this.message = res.msg || '领取成功,已发放至您的会员账户'
} else { return
this.success = false
this.message = res.msg || '领取失败,请稍后再试'
} }
if (res.code === 401) {
//
this.silentLogin().then((silentOk) => {
if (silentOk) {
// token
this.useGiftCode(code)
} else {
this.loading = false
this.goLoginWithRedirect(code)
}
})
return
}
this.loading = false
this.success = false
this.message = res.msg || '领取失败,请稍后再试'
}) })
.catch(() => { .catch(() => {
this.loading = false this.loading = false

View File

@ -219,7 +219,8 @@
isindex:false, isindex:false,
areaId:'16', areaId:'16',
appid:'', appid:'',
appimg:{} appimg:{},
redirectUrl: '' //
} }
}, },
onLoad(e) { onLoad(e) {
@ -234,6 +235,9 @@
if(e.isindex=='true'){ if(e.isindex=='true'){
this.isindex=true this.isindex=true
} }
if (e.redirect) {
this.redirectUrl = decodeURIComponent(e.redirect)
}
}, },
computed: { computed: {
codeButtonStyle() { codeButtonStyle() {
@ -625,7 +629,10 @@
this.$u.get("/getInfo").then((res) => { this.$u.get("/getInfo").then((res) => {
console.log('进入跳转'); console.log('进入跳转');
uni.setStorageSync('user',res.user) uni.setStorageSync('user',res.user)
if(this.isindex==true){ if (this.redirectUrl) {
const url = this.redirectUrl.startsWith('/') ? this.redirectUrl : '/' + this.redirectUrl
uni.reLaunch({ url })
} else if(this.isindex==true){
uni.navigateBack({ uni.navigateBack({
delta: 1 // delta1 delta: 1 // delta1
}); });

View File

@ -128,7 +128,8 @@ export default {
channelId: '', channelId: '',
showBuy: false, showBuy: false,
selectedVip: {}, selectedVip: {},
paying: false paying: false,
redirectVipId: '' // vipId
} }
}, },
onLoad(option) { onLoad(option) {
@ -138,6 +139,7 @@ export default {
return return
} }
this.promotionId = String(id) this.promotionId = String(id)
if (option && option.vipId) this.redirectVipId = String(option.vipId)
uni.setStorageSync('areaPromotionId', this.promotionId) uni.setStorageSync('areaPromotionId', this.promotionId)
this.getDetail() this.getDetail()
}, },
@ -237,6 +239,17 @@ export default {
'' ''
if (this.areaId) this.getChannelId() if (this.areaId) this.getChannelId()
//
if (this.redirectVipId) {
const vip = this.vipList.find(v => String(v.id) === String(this.redirectVipId))
const vid = this.redirectVipId
this.redirectVipId = ''
if (vip) {
this.openBuy(vip)
setTimeout(() => this.payNow(), 800)
}
}
}).catch(() => { }).catch(() => {
this.loading = false this.loading = false
uni.showToast({ title: '网络错误', icon: 'none' }) uni.showToast({ title: '网络错误', icon: 'none' })
@ -285,6 +298,43 @@ export default {
this.showBuy = false this.showBuy = false
this.selectedVip = {} this.selectedVip = {}
}, },
// wx.login code token
silentLogin() {
return new Promise((resolve) => {
// #ifdef MP-WEIXIN
wx.login({
success: (res) => {
if (!res.code) {
resolve(false)
return
}
const data = { loginCode: res.code, appId: this.$store.state.appid }
this.$u.post('/wxLogin', data).then((loginRes) => {
if (loginRes.code === 200) {
uni.setStorageSync('token', loginRes.token)
resolve(true)
}else if(res.code == 401){
resolve(false)
} else {
resolve(false)
}
}).catch(() => resolve(false))
},
fail: () => resolve(false)
})
// #endif
// #ifndef MP-WEIXIN
resolve(false)
// #endif
})
},
//
goLoginWithRedirect() {
const backUrl = '/pages/tuihuang?i=' + encodeURIComponent(this.promotionId) + '&vipId=' + encodeURIComponent(this.selectedVip.id)
uni.navigateTo({
url: '/pages/login/login?redirect=' + encodeURIComponent(backUrl)
})
},
payNow() { payNow() {
if (this.paying) return if (this.paying) return
if (!this.selectedVip || !this.selectedVip.id) { if (!this.selectedVip || !this.selectedVip.id) {
@ -314,14 +364,7 @@ export default {
vip vip
} }
this.$u.post(`/app/vipOrder`, data).then(res => { const doPayResult = (res) => {
if (res.code !== 200) {
this.paying = false
uni.hideLoading()
uni.showToast({ title: res.msg || '下单失败', icon: 'none' ,duration:5000})
return
}
//
if (res.data && res.data.needPay) { if (res.data && res.data.needPay) {
uni.requestPayment({ uni.requestPayment({
provider: 'wxpay', provider: 'wxpay',
@ -349,12 +392,46 @@ export default {
} }
}) })
} else { } else {
// 0
this.paying = false this.paying = false
this.showBuy = false this.showBuy = false
uni.hideLoading() uni.hideLoading()
uni.showToast({ title: '购买成功', icon: 'success', duration: 2000 }) uni.showToast({ title: '购买成功', icon: 'success', duration: 2000 })
} }
}
this.$u.post(`/app/vipOrder`, data).then(res => {
if (res.code === 401) {
this.silentLogin().then((silentOk) => {
if (silentOk) {
// token
this.$u.post(`/app/vipOrder`, data).then(res2 => {
if (res2.code !== 200) {
this.paying = false
uni.hideLoading()
uni.showToast({ title: res2.msg || '下单失败', icon: 'none', duration: 5000 })
return
}
doPayResult(res2)
}).catch(() => {
this.paying = false
uni.hideLoading()
uni.showToast({ title: '网络错误', icon: 'none', duration: 5000 })
})
} else {
this.paying = false
uni.hideLoading()
this.goLoginWithRedirect()
}
})
return
}
if (res.code !== 200) {
this.paying = false
uni.hideLoading()
uni.showToast({ title: res.msg || '下单失败', icon: 'none' ,duration:5000})
return
}
doPayResult(res)
}).catch(() => { }).catch(() => {
this.paying = false this.paying = false
uni.hideLoading() uni.hideLoading()