优化h5微信授权逻辑;修改CountDown组件报错的问题
This commit is contained in:
@ -1,65 +1,67 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="time">
|
<view class="time">
|
||||||
<text v-if="rtipText">{{ rtipText }}</text>
|
{{ tipText }}
|
||||||
<text class="styleAll" v-if="risDay === true">{{ rday }}</text>
|
<text class="styleAll" v-if="isDay === true">{{ day }}</text>
|
||||||
<text class="timeTxt" v-if="rdayText">{{ rdayText }}</text>
|
<text class="timeTxt">{{ dayText }}</text>
|
||||||
<text class="styleAll">{{ hour }}</text>
|
<text class="styleAll">{{ hour }}</text>
|
||||||
<text class="timeTxt" v-if="rhourText">{{ rhourText }}</text>
|
<text class="timeTxt">{{ hourText }}</text>
|
||||||
<text class="styleAll">{{ minute }}</text>
|
<text class="styleAll">{{ minute }}</text>
|
||||||
<text class="timeTxt" v-if="rminuteText">{{ rminuteText }}</text>
|
<text class="timeTxt">{{ minuteText }}</text>
|
||||||
<text class="styleAll">{{ second }}</text>
|
<text class="styleAll">{{ second }}</text>
|
||||||
<text class="timeTxt" v-if="rsecondText">{{ rsecondText }}</text>
|
<text class="timeTxt">{{ secondText }}</text>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: "CountDown",
|
name: "CountDown",
|
||||||
props: [
|
props: {
|
||||||
//距离开始提示文字
|
//距离开始提示文字
|
||||||
'tipText',
|
tipText: {
|
||||||
'dayText',
|
type: String,
|
||||||
'hourText',
|
default: "倒计时"
|
||||||
'minuteText',
|
},
|
||||||
'secondText',
|
dayText: {
|
||||||
'datatime',
|
type: String,
|
||||||
'isDay'
|
default: "天"
|
||||||
],
|
},
|
||||||
data: function() {
|
hourText: {
|
||||||
|
type: String,
|
||||||
|
default: "时"
|
||||||
|
},
|
||||||
|
minuteText: {
|
||||||
|
type: String,
|
||||||
|
default: "分"
|
||||||
|
},
|
||||||
|
secondText: {
|
||||||
|
type: String,
|
||||||
|
default: "秒"
|
||||||
|
},
|
||||||
|
datatime: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
|
isDay: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data: function () {
|
||||||
return {
|
return {
|
||||||
day: "00",
|
day: "00",
|
||||||
hour: "00",
|
hour: "00",
|
||||||
minute: "00",
|
minute: "00",
|
||||||
second: "00",
|
second: "00"
|
||||||
rtipText: "倒计时",
|
|
||||||
rdayText: "天",
|
|
||||||
rhourText: "时",
|
|
||||||
rminuteText: "分",
|
|
||||||
rsecondText: "秒",
|
|
||||||
rdatatime: 0,
|
|
||||||
risDay: true
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created: function() {
|
created: function () {
|
||||||
// this.show_time();
|
|
||||||
},
|
|
||||||
mounted: function() {
|
|
||||||
this.rtipText = this.$props.tipText;
|
|
||||||
this.rdayText = this.$props.dayText;
|
|
||||||
this.rhourText = this.$props.hourText;
|
|
||||||
this.rminuteText = this.$props.minuteText;
|
|
||||||
this.rsecondText = this.$props.secondText;
|
|
||||||
this.rdatatime = this.$props.datatime;
|
|
||||||
this.risDay = this.$props.isDay;
|
|
||||||
this.show_time();
|
this.show_time();
|
||||||
},
|
},
|
||||||
|
mounted: function () {},
|
||||||
methods: {
|
methods: {
|
||||||
show_time: function() {
|
show_time: function () {
|
||||||
let that = this;
|
|
||||||
this.runTime();
|
|
||||||
setInterval(this.runTime, 1000);
|
|
||||||
},
|
|
||||||
runTime() {
|
|
||||||
let that = this;
|
let that = this;
|
||||||
|
|
||||||
|
function runTime() {
|
||||||
//时间函数
|
//时间函数
|
||||||
let intDiff = that.datatime - Date.parse(new Date()) / 1000; //获取数据中的时间戳的时间差;
|
let intDiff = that.datatime - Date.parse(new Date()) / 1000; //获取数据中的时间戳的时间差;
|
||||||
let day = 0,
|
let day = 0,
|
||||||
@ -94,6 +96,9 @@ export default {
|
|||||||
that.second = "00";
|
that.second = "00";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
runTime();
|
||||||
|
setInterval(runTime, 1000);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -88,7 +88,7 @@ let wechatObj;
|
|||||||
let appId
|
let appId
|
||||||
let wechatLoading = false
|
let wechatLoading = false
|
||||||
|
|
||||||
export async function wechat() {
|
export function wechat() {
|
||||||
console.log('初始化微信配置')
|
console.log('初始化微信配置')
|
||||||
wechatLoading = false
|
wechatLoading = false
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -148,7 +148,7 @@ export async function oAuth() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function auth(code) {
|
export async function auth(code) {
|
||||||
console.log('获取微信授权')
|
console.log('获取微信授权')
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let loginType = cookie.get(LOGINTYPE);
|
let loginType = cookie.get(LOGINTYPE);
|
||||||
@ -170,7 +170,7 @@ export function auth(code) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toAuth() {
|
export async function toAuth() {
|
||||||
if (wechatLoading) {
|
if (wechatLoading) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -187,7 +187,6 @@ function getAuthUrl(appId) {
|
|||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
// #endif
|
// #endif
|
||||||
debugger
|
|
||||||
cookie.set('redirect', window.location.href)
|
cookie.set('redirect', window.location.href)
|
||||||
const redirect_uri = encodeURIComponent(`${location.origin}/pages/Loading/index`);
|
const redirect_uri = encodeURIComponent(`${location.origin}/pages/Loading/index`);
|
||||||
// const redirect_uri = encodeURIComponent(`${location.origin}/pages/Loading/index?path=${encodeURIComponent(window.location.href)}`);
|
// const redirect_uri = encodeURIComponent(`${location.origin}/pages/Loading/index?path=${encodeURIComponent(window.location.href)}`);
|
||||||
|
143
main.js
143
main.js
@ -82,77 +82,7 @@ Object.defineProperty(Vue.prototype, '$yroute', {
|
|||||||
Vue.prototype.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL
|
Vue.prototype.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL
|
||||||
Vue.prototype.$VUE_APP_API_URL = VUE_APP_API_URL
|
Vue.prototype.$VUE_APP_API_URL = VUE_APP_API_URL
|
||||||
Vue.component('cu-custom', cuCustom);
|
Vue.component('cu-custom', cuCustom);
|
||||||
// #ifdef H5
|
|
||||||
// H5编译的代码
|
|
||||||
|
|
||||||
import {
|
|
||||||
wechat,
|
|
||||||
clearAuthStatus,
|
|
||||||
oAuth,
|
|
||||||
auth,
|
|
||||||
toAuth,
|
|
||||||
pay,
|
|
||||||
openAddress,
|
|
||||||
openShareAll,
|
|
||||||
openShareAppMessage,
|
|
||||||
openShareTimeline,
|
|
||||||
wechatEvevt,
|
|
||||||
ready,
|
|
||||||
wxShowLocation,
|
|
||||||
} from '@/libs/wechat'
|
|
||||||
|
|
||||||
import { isWeixin } from '@/utils'
|
|
||||||
|
|
||||||
|
|
||||||
const CACHE_KEY = "clear_0.0.1";
|
|
||||||
|
|
||||||
if (!cookie.has(CACHE_KEY)) {
|
|
||||||
cookie.clearAll();
|
|
||||||
cookie.set(CACHE_KEY, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
var urlSpread = parseQuery()["spread"];
|
|
||||||
|
|
||||||
if (urlSpread !== undefined) {
|
|
||||||
var spread = cookie.get("spread");
|
|
||||||
urlSpread = parseInt(urlSpread);
|
|
||||||
if (!Number.isNaN(urlSpread) && spread !== urlSpread) {
|
|
||||||
cookie.set("spread", urlSpread || 0);
|
|
||||||
} else if (spread === 0 || typeof spread !== "number") {
|
|
||||||
cookie.set("spread", urlSpread || 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Vue.prototype.wechat = wechat
|
|
||||||
Vue.prototype.clearAuthStatus = clearAuthStatus
|
|
||||||
Vue.prototype.oAuth = oAuth
|
|
||||||
Vue.prototype.auth = auth
|
|
||||||
Vue.prototype.toAuth = toAuth
|
|
||||||
Vue.prototype.pay = pay
|
|
||||||
Vue.prototype.openAddress = openAddress
|
|
||||||
Vue.prototype.openShareAll = openShareAll
|
|
||||||
Vue.prototype.openShareAppMessage = openShareAppMessage
|
|
||||||
Vue.prototype.openShareTimeline = openShareTimeline
|
|
||||||
Vue.prototype.wechatEvevt = wechatEvevt
|
|
||||||
Vue.prototype.ready = ready
|
|
||||||
Vue.prototype.wxShowLocation = wxShowLocation
|
|
||||||
|
|
||||||
// 判断是否是微信浏览器
|
|
||||||
if (isWeixin()) {
|
|
||||||
Vue.prototype.$deviceType = 'weixin'
|
|
||||||
store.commit('updateDevicetype', 'weixin')
|
|
||||||
let wechat = await wechat()
|
|
||||||
if (wechat) {
|
|
||||||
await oAuth()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Vue.prototype.$deviceType = 'weixinh5'
|
|
||||||
store.commit('updateDevicetype', 'weixinh5')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
// App平台编译的代码
|
// App平台编译的代码
|
||||||
@ -174,4 +104,75 @@ store.commit('updateDevicetype', 'routine')
|
|||||||
// ...mapState(['$deviceType'])
|
// ...mapState(['$deviceType'])
|
||||||
// },
|
// },
|
||||||
|
|
||||||
app.$mount()
|
|
||||||
|
// #ifdef H5
|
||||||
|
// H5编译的代码
|
||||||
|
|
||||||
|
import {
|
||||||
|
wechat,
|
||||||
|
clearAuthStatus,
|
||||||
|
oAuth,
|
||||||
|
auth,
|
||||||
|
toAuth,
|
||||||
|
pay,
|
||||||
|
openAddress,
|
||||||
|
openShareAll,
|
||||||
|
openShareAppMessage,
|
||||||
|
openShareTimeline,
|
||||||
|
wechatEvevt,
|
||||||
|
ready,
|
||||||
|
wxShowLocation,
|
||||||
|
} from '@/libs/wechat'
|
||||||
|
|
||||||
|
import { isWeixin } from '@/utils'
|
||||||
|
const CACHE_KEY = "clear_0.0.1";
|
||||||
|
|
||||||
|
if (!cookie.has(CACHE_KEY)) {
|
||||||
|
cookie.clearAll();
|
||||||
|
cookie.set(CACHE_KEY, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var urlSpread = parseQuery()["spread"];
|
||||||
|
|
||||||
|
if (urlSpread !== undefined) {
|
||||||
|
var spread = cookie.get("spread");
|
||||||
|
urlSpread = parseInt(urlSpread);
|
||||||
|
if (!Number.isNaN(urlSpread) && spread !== urlSpread) {
|
||||||
|
cookie.set("spread", urlSpread || 0);
|
||||||
|
} else if (spread === 0 || typeof spread !== "number") {
|
||||||
|
cookie.set("spread", urlSpread || 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
|
||||||
|
// #ifdef H5
|
||||||
|
// H5编译的代码
|
||||||
|
// 判断是否是微信浏览器
|
||||||
|
if (isWeixin()) {
|
||||||
|
Vue.prototype.$deviceType = 'weixin'
|
||||||
|
store.commit('updateDevicetype', 'weixin')
|
||||||
|
let wechatInit = await wechat()
|
||||||
|
console.log(wechatInit)
|
||||||
|
if (wechatInit) {
|
||||||
|
await oAuth()
|
||||||
|
app.$mount()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Vue.prototype.$deviceType = 'weixinh5'
|
||||||
|
store.commit('updateDevicetype', 'weixinh5')
|
||||||
|
app.$mount()
|
||||||
|
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifndef H5
|
||||||
|
app.$mount()
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
init()
|
||||||
|
@ -204,25 +204,25 @@ export const authorize = (authorizeStr) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const login = () => {
|
export const login = () => {
|
||||||
debugger;
|
|
||||||
console.log(Vue.prototype)
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (Vue.prototype.$deviceType == 'weixin') {
|
if (Vue.prototype.$deviceType == 'weixin') {
|
||||||
// 微信授权登录
|
// 微信授权登录
|
||||||
const { code } = parseQuery()
|
const { code } = parseQuery()
|
||||||
debugger;
|
|
||||||
if (code) {
|
if (code) {
|
||||||
auth(code)
|
auth(code)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// location.replace(
|
|
||||||
// decodeURIComponent(decodeURIComponent(this.$route.params.url))
|
|
||||||
// );
|
|
||||||
let redirect = cookie.get('redirect')
|
let redirect = cookie.get('redirect')
|
||||||
console.log(redirect)
|
console.log(redirect)
|
||||||
debugger;
|
if (redirect) {
|
||||||
location.href = decodeURIComponent(
|
redirect = redirect.split('/pages')[1]
|
||||||
decodeURIComponent(this.$route.params.url)
|
reLaunch({
|
||||||
);
|
path: '/pages' + redirect,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
reLaunch({
|
||||||
|
path: '/pages/home/index',
|
||||||
|
});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
reject('当前运行环境为微信浏览器')
|
reject('当前运行环境为微信浏览器')
|
||||||
@ -866,7 +866,6 @@ export const handleLoginFailure = () => {
|
|||||||
store.commit("updateAuthorization", false);
|
store.commit("updateAuthorization", false);
|
||||||
|
|
||||||
let currentPageUrl = getCurrentPageUrl()
|
let currentPageUrl = getCurrentPageUrl()
|
||||||
debugger
|
|
||||||
if (store.state.$deviceType == 'weixin') {
|
if (store.state.$deviceType == 'weixin') {
|
||||||
// 如果不是授权页面,
|
// 如果不是授权页面,
|
||||||
if (!store.getters.isAuthorizationPage) {
|
if (!store.getters.isAuthorizationPage) {
|
||||||
|
Reference in New Issue
Block a user