投票流程大改
This commit is contained in:
@@ -9,7 +9,18 @@ const getToken = () => {
|
|||||||
return !!vuex ? JSON.parse(vuex).user.token : null
|
return !!vuex ? JSON.parse(vuex).user.token : null
|
||||||
}
|
}
|
||||||
const source = axios.CancelToken.source();
|
const source = axios.CancelToken.source();
|
||||||
|
let throttleMap = {}
|
||||||
instance.interceptors.request.use(config => {
|
instance.interceptors.request.use(config => {
|
||||||
|
if (config.throttle) {// 节流处理
|
||||||
|
let timer = throttleMap[config.url]
|
||||||
|
if (!!timer) {
|
||||||
|
config.cancelToken = source.token
|
||||||
|
source.cancel("节流控制,取消请求:" + config.url)
|
||||||
|
}
|
||||||
|
throttleMap[config.url] = setTimeout(() => {
|
||||||
|
throttleMap[config.url] = null
|
||||||
|
}, config.throttle)
|
||||||
|
}
|
||||||
if (config.withoutToken) {
|
if (config.withoutToken) {
|
||||||
return config
|
return config
|
||||||
} else if (getToken()) {
|
} else if (getToken()) {
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ export const user = {
|
|||||||
let {module} = params, action = "/auth/wechat-mp/token"
|
let {module} = params, action = "/auth/wechat-mp/token"
|
||||||
return http.post(action, params, {
|
return http.post(action, params, {
|
||||||
withoutToken: true,
|
withoutToken: true,
|
||||||
|
throttle: 500,
|
||||||
module,
|
module,
|
||||||
params: {
|
params: {
|
||||||
...params, grant_type: 'password',
|
...params, grant_type: 'password',
|
||||||
|
|||||||
@@ -16,12 +16,17 @@
|
|||||||
<AiGroup noBorder description>
|
<AiGroup noBorder description>
|
||||||
<u-parse :html="detail.ending"/>
|
<u-parse :html="detail.ending"/>
|
||||||
</AiGroup>
|
</AiGroup>
|
||||||
|
<weixin-login :autoShow="!user.token" content="投票需要您授权您的微信信息" @login="getList"/>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import {mapState} from "vuex"
|
||||||
|
import WeixinLogin from "./weixinLogin";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "AppVote",
|
name: "AppVote",
|
||||||
|
components: {WeixinLogin},
|
||||||
appName: "公众投票",
|
appName: "公众投票",
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -29,6 +34,9 @@ export default {
|
|||||||
list: []
|
list: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
...mapState(['user']),
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getDetail() {
|
getDetail() {
|
||||||
this.$http.post("/app/appvideovoteconfig/queryDetailByCorpId", null, {
|
this.$http.post("/app/appvideovoteconfig/queryDetailByCorpId", null, {
|
||||||
@@ -41,7 +49,7 @@ export default {
|
|||||||
},
|
},
|
||||||
getList() {
|
getList() {
|
||||||
this.$http.post("/app/appvideoinfo/list", null, {
|
this.$http.post("/app/appvideoinfo/list", null, {
|
||||||
withoutToken: true,
|
withoutToken: !this.user.token,
|
||||||
param: {size: 20}
|
param: {size: 20}
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res?.data) {
|
if (res?.data) {
|
||||||
|
|||||||
@@ -10,14 +10,17 @@
|
|||||||
<div class="text circle mar-l16" :class="{disabled:canotVote}" @click="handleVote">投票</div>
|
<div class="text circle mar-l16" :class="{disabled:canotVote}" @click="handleVote">投票</div>
|
||||||
</div>
|
</div>
|
||||||
</AiBottomBtn>
|
</AiBottomBtn>
|
||||||
|
<weixin-login :autoShow="showWxLogin" @login="handleVote"/>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {mapState, mapActions, mapMutations} from "vuex"
|
import {mapState} from "vuex"
|
||||||
|
import WeixinLogin from "./weixinLogin";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "voteDetail",
|
name: "voteDetail",
|
||||||
|
components: {WeixinLogin},
|
||||||
appName: "投票详情",
|
appName: "投票详情",
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['user']),
|
...mapState(['user']),
|
||||||
@@ -26,12 +29,11 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
detail: {}
|
detail: {},
|
||||||
|
showWxLogin: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(['getWechatToken', 'getCode']),
|
|
||||||
...mapMutations(['setToken']),
|
|
||||||
getDetail() {
|
getDetail() {
|
||||||
const {id} = this.$route.query
|
const {id} = this.$route.query
|
||||||
this.$http.post("/app/appvideoinfo/queryDetailById", null, {params: {id}, withoutToken: !this.user.token}).then(res => {
|
this.$http.post("/app/appvideoinfo/queryDetailById", null, {params: {id}, withoutToken: !this.user.token}).then(res => {
|
||||||
@@ -43,11 +45,7 @@ export default {
|
|||||||
},
|
},
|
||||||
handleVote() {
|
handleVote() {
|
||||||
if (!this.user.token) {//未登录,获取openId和token
|
if (!this.user.token) {//未登录,获取openId和token
|
||||||
this.$http.get("/app/appdvcpconfig/getMpAppid", {withoutToken: true}).then(res => {
|
this.showWxLogin = true
|
||||||
if (res?.code == 0 && res?.data) {
|
|
||||||
this.getCode({scope: "snsapi_userinfo", appid: res.data})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {//已登录,直接投票
|
} else {//已登录,直接投票
|
||||||
if (!this.canotVote) {
|
if (!this.canotVote) {
|
||||||
const {id} = this.$route.query
|
const {id} = this.$route.query
|
||||||
@@ -65,12 +63,6 @@ export default {
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.getDetail()
|
this.getDetail()
|
||||||
if (!!this.wxCode) {
|
|
||||||
this.getWechatToken({module: "AppVote", code: this.wxCode}).then(this.handleVote)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
destroyed() {
|
|
||||||
this.setToken(null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -87,7 +79,8 @@ export default {
|
|||||||
::v-deep video {
|
::v-deep video {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
::v-deep.topLabel{
|
|
||||||
|
::v-deep.topLabel {
|
||||||
padding-right: 20px;
|
padding-right: 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
69
src/project/fengdu/AppVote/weixinLogin.vue
Normal file
69
src/project/fengdu/AppVote/weixinLogin.vue
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<template>
|
||||||
|
<section class="weixinLogin">
|
||||||
|
<u-modal v-model="show" :content="content" confirm-text="去授权" cancel-text="仅浏览" show-cancel-button :show-title="false"
|
||||||
|
@confirm="handleConfirm" @cancel="handleCancel"/>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import {mapActions, mapState} from "vuex"
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "weixinLogin",
|
||||||
|
props: {
|
||||||
|
content: {default: "是否要进行微信授权?"},
|
||||||
|
autoShow: Boolean
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapState(['user']),
|
||||||
|
wxCode: v => v.$route.query.code,
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
show: false,
|
||||||
|
appid: ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapActions(['getWechatToken', 'getCode']),
|
||||||
|
handleConfirm() {
|
||||||
|
this.$http.get("/app/appdvcpconfig/getMpAppid", {withoutToken: true}).then(res => {
|
||||||
|
if (res?.code == 0 && res?.data) {
|
||||||
|
this.getCode({scope: "snsapi_userinfo", appid: res.data})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
handleCancel() {
|
||||||
|
this.show = false
|
||||||
|
},
|
||||||
|
autoLogin() {
|
||||||
|
if (!this.user.token) this.getWechatToken({code: this.wxCode}).then(() => this.$emit("login")).catch(() => {
|
||||||
|
setTimeout(() => uni.showModal({
|
||||||
|
content: "是否要重新加载页面?",
|
||||||
|
success: res => {
|
||||||
|
if (!!res?.confirm) {
|
||||||
|
const redirect = this.$qs.parseUrl(location.href)
|
||||||
|
delete redirect.query.code
|
||||||
|
delete redirect.query.state
|
||||||
|
location.replace(this.$qs.stringifyUrl(redirect))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}), 500)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
autoShow: {
|
||||||
|
immediate: true,
|
||||||
|
handler(v) {
|
||||||
|
this.wxCode ? this.autoLogin() : this.show = !!v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.weixinLogin {
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user