- 新增商品券类型支持,包括商品券的领取、使用和展示 - 优化优惠券领取流程,支持兑换码兑换和自动跳转登录 - 新增优惠活动功能,支持活动商品折扣 - 重构优惠券页面布局,区分领取和使用页面 - 新增分销商信息编辑功能 - 优化小程序更新机制,改进更新提示流程 - 修复优惠券使用条件判断逻辑 - 调整UI样式,统一主题色为绿色 - 新增电话客服功能,支持动态电话号码 - 优化订单详情页,展示商品券信息
194 lines
4.8 KiB
Vue
194 lines
4.8 KiB
Vue
<script setup>
|
|
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
|
|
import { storeToRefs } from 'pinia'
|
|
import { useMainStore } from '@/store/store'
|
|
const main = useMainStore()
|
|
import { isWeixin, parseQuery } from '@/utils/util'
|
|
import cookie from '@/utils/cookie'
|
|
import {
|
|
userAuthSession,
|
|
wechatAuth
|
|
} from '@/api/auth'
|
|
import { APP_ID } from '@/config'
|
|
|
|
// 检查更新逻辑
|
|
const autoUpdate = () => {
|
|
// 获取小程序更新机制兼容
|
|
if (uni.canIUse("getUpdateManager")) {
|
|
// 获取更新管理器
|
|
const updateManager = uni.getUpdateManager();
|
|
//1. 检查小程序是否有新版本发布,向小程序后台请求完新版本信息
|
|
updateManager.onCheckForUpdate((res) => {
|
|
// 请求完新版本信息的回调
|
|
if (res.hasUpdate) {
|
|
//检测到新版本,需要更新,给出提示
|
|
uni.showModal({
|
|
title: "更新提示",
|
|
content: "检测到新版本,是否下载新版本并重启小程序?",
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
//2. 用户确定下载更新小程序,小程序下载及更新静默进行
|
|
downLoadAndUpdate(updateManager);
|
|
} else if (res.cancel) {
|
|
//用户点击取消按钮的处理,如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了
|
|
uni.showModal({
|
|
title: "温馨提示",
|
|
content: "本次版本更新涉及到新的功能添加,旧版本无法正常访问的哦",
|
|
showCancel: false, //隐藏取消按钮
|
|
confirmText: "确定更新", //只保留确定更新按钮
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
//下载新版本,并重新应用
|
|
downLoadAndUpdate(updateManager);
|
|
}
|
|
},
|
|
});
|
|
}
|
|
},
|
|
});
|
|
}
|
|
});
|
|
} else {
|
|
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
|
|
uni.showModal({
|
|
title: "提示",
|
|
content: "当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。",
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 下载小程序新版本并重启应用
|
|
*/
|
|
const downLoadAndUpdate = (updateManager) => {
|
|
uni.showLoading();
|
|
//静默下载更新小程序新版本,更新完成后回调
|
|
updateManager.onUpdateReady(() => {
|
|
uni.hideLoading();
|
|
//新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
updateManager.applyUpdate();
|
|
});
|
|
|
|
// 更新失败回调
|
|
updateManager.onUpdateFailed(() => {
|
|
// 新的版本下载失败
|
|
uni.showModal({
|
|
title: "已经有新版本了哟~",
|
|
content: "新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~",
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
onLaunch(() => {
|
|
autoUpdate();
|
|
console.log('App Launch')
|
|
})
|
|
|
|
onShow(() => {
|
|
console.log('App Show')
|
|
|
|
// 检查用户登录情况
|
|
// #ifdef H5
|
|
if (isWeixin()) {
|
|
oAuth()
|
|
// H5编译的代码
|
|
// 判断是否是微信浏览器
|
|
}
|
|
// #endif
|
|
// #ifdef MP-WEIXIN
|
|
wechatMiniLogin();
|
|
// #endif
|
|
})
|
|
|
|
onHide(() => {
|
|
console.log('App Hide')
|
|
})
|
|
|
|
|
|
|
|
const wechatMiniLogin = () => {
|
|
//this.$u.toast('登录中');
|
|
uni.login({
|
|
provider: 'weixin'
|
|
}).then(async (res) => {
|
|
let data = await userAuthSession({
|
|
code: res.code
|
|
});
|
|
if (data) {
|
|
main.SET_OPENID(data.openId)
|
|
if (data.hasOwnProperty('userInfo') && data.accessToken && data.accessToken != '') {
|
|
main.SET_MEMBER(data.userInfo);
|
|
main.SET_TOKEN(data.accessToken);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
const getAuthUrl = (appId) => {
|
|
// #ifdef H5
|
|
// #endif
|
|
cookie.set('redirect', window.location.href)
|
|
const url = `${location.origin}/h5/#/pages/index/index`
|
|
cookie.set('index_url', url)
|
|
let redirect_uri = encodeURIComponent(url)
|
|
|
|
const state = 'STATE'
|
|
return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
|
|
}
|
|
|
|
const oAuth = async () => {
|
|
const WX_AUTH = 'wx_auth'
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const accessToken = uni.getStorageSync('accessToken');
|
|
if (cookie.has('wx_auth') && accessToken && main.isLogin) {
|
|
reject()
|
|
return
|
|
}
|
|
const { code } = parseQuery()
|
|
if (!code) {
|
|
//公众号appid
|
|
const appid = APP_ID;
|
|
location.href = getAuthUrl(appid)
|
|
return
|
|
} else {
|
|
auth(code)
|
|
}
|
|
resolve()
|
|
}).catch(error => {
|
|
console.log(error)
|
|
})
|
|
}
|
|
|
|
const auth = async (code) => {
|
|
console.log('获取微信授权:', code)
|
|
let data = await wechatAuth({ 'code': code })
|
|
cookie.set('wx_auth', code)
|
|
if (data) {
|
|
main.SET_OPENID(data.openId)
|
|
main.SET_MEMBER(data.userInfo);
|
|
main.SET_TOKEN(data.accessToken);
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
@import '~@/static/style/app.scss';
|
|
//@import 'static/iconfont/iconfont.scss';
|
|
//@import url('./static/style/style.less');
|
|
@import 'static/style/yshop.css';
|
|
|
|
// /*每个页面公共css */
|
|
// page {
|
|
// background-color: #f5f5f5;
|
|
// }</style>
|