You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
295 lines
11 KiB
295 lines
11 KiB
5 years ago
|
<template>
|
||
|
<div class="write-container">
|
||
4 years ago
|
<h1 id="inActiveTime" style="display: none;" />
|
||
5 years ago
|
<div v-if="writeStatus==0" class="title-icon-view">
|
||
|
<div class="icon-view">
|
||
4 years ago
|
<i class="el-icon-check success-icon" />
|
||
5 years ago
|
</div>
|
||
4 years ago
|
<p v-if="writeNotStartPrompt" style="text-align: center;">
|
||
5 years ago
|
<span v-if="writeNotStartPrompt">{{ writeNotStartPrompt }}</span>
|
||
|
</p>
|
||
|
</div>
|
||
|
<div v-if="writeStatus==1">
|
||
5 years ago
|
<project-form
|
||
4 years ago
|
v-if="projectConfig.projectKey"
|
||
|
:project-config="projectConfig"
|
||
5 years ago
|
@submit="submitForm"
|
||
4 years ago
|
/>
|
||
5 years ago
|
</div>
|
||
5 years ago
|
<div v-if="writeStatus==2" class="title-icon-view">
|
||
|
<div class="icon-view">
|
||
4 years ago
|
<i class="el-icon-check success-icon" />
|
||
5 years ago
|
</div>
|
||
4 years ago
|
<p style="text-align: center;">
|
||
5 years ago
|
<span v-if="userProjectSetting.submitPromptText">{{ userProjectSetting.submitPromptText }}</span>
|
||
5 years ago
|
<span v-else>{{ globalDefaultValue.projectSubmitPromptText }}</span>
|
||
5 years ago
|
</p>
|
||
4 years ago
|
<div>
|
||
|
<el-image
|
||
|
v-if="userProjectSetting.submitPromptImg"
|
||
|
:src="userProjectSetting.submitPromptImg"
|
||
4 years ago
|
fit="cover"
|
||
|
/>
|
||
4 years ago
|
</div>
|
||
5 years ago
|
</div>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
4 years ago
|
import ProjectForm from '../preview/ProjectForm'
|
||
5 years ago
|
import loadWXJs from '@/utils/loadWxSdk'
|
||
|
import defaultValue from '@/utils/defaultValue'
|
||
4 years ago
|
import { getQueryString} from '@/utils'
|
||
5 years ago
|
|
||
5 years ago
|
const uaParser = require('ua-parser-js')
|
||
|
const ua = uaParser(navigator.userAgent)
|
||
|
|
||
5 years ago
|
require('@/utils/ut')
|
||
5 years ago
|
export default {
|
||
|
name: 'WriteView',
|
||
4 years ago
|
components: {
|
||
|
ProjectForm
|
||
|
},
|
||
5 years ago
|
props: {},
|
||
|
data() {
|
||
|
return {
|
||
5 years ago
|
inActiveTime: 0,
|
||
5 years ago
|
projectConfig: {
|
||
|
projectKey: '',
|
||
|
preview: false,
|
||
|
showBtns: true
|
||
|
},
|
||
5 years ago
|
writeStatus: 1,
|
||
5 years ago
|
writeNotStartPrompt: '',
|
||
|
userProjectSetting: {
|
||
|
submitPromptText: ''
|
||
|
},
|
||
5 years ago
|
globalDefaultValue: defaultValue,
|
||
4 years ago
|
// 微信授权地址
|
||
5 years ago
|
wxAuthorizationUrl: '',
|
||
|
wxAuthorizationCode: '',
|
||
|
wxUserInfo: {},
|
||
|
wxSignature: {}
|
||
5 years ago
|
}
|
||
|
},
|
||
5 years ago
|
beforeCreate() {
|
||
5 years ago
|
let meta = document.createElement('meta')
|
||
|
meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'
|
||
|
meta.name = 'viewport'
|
||
|
document.getElementsByTagName('head')[0].appendChild(meta)
|
||
5 years ago
|
},
|
||
|
created() {
|
||
4 years ago
|
let key = this.$route.query.key || this.$route.params.key
|
||
5 years ago
|
this.projectConfig.projectKey = key
|
||
5 years ago
|
let wxCode = getQueryString('code')
|
||
|
if (wxCode) {
|
||
|
this.wxAuthorizationCode = wxCode
|
||
|
this.getWxAuthorizationUserInfo()
|
||
|
}
|
||
|
this.getWxAuthorizationUrl()
|
||
|
this.queryProjectSettingStatus()
|
||
5 years ago
|
this.queryProjectSetting()
|
||
4 years ago
|
// 加载微信相关 获取签名
|
||
5 years ago
|
this.$api.get('/wx/jsapi/signature', {params: {url: window.location.href}}).then(res => {
|
||
5 years ago
|
this.wxSignature = res.data
|
||
|
this.setWxConfig()
|
||
|
})
|
||
|
},
|
||
|
mounted() {
|
||
5 years ago
|
this.viewProjectHandle()
|
||
5 years ago
|
}, methods: {
|
||
5 years ago
|
viewProjectHandle() {
|
||
4 years ago
|
// 是否能进入填写
|
||
4 years ago
|
this.$api.post(`/user/project/result/view/${this.projectConfig.projectKey}`, {params: {projectKey: this.projectConfig.projectKey}}).then(() => {
|
||
5 years ago
|
|
||
|
})
|
||
|
},
|
||
5 years ago
|
queryProjectSettingStatus() {
|
||
4 years ago
|
// 是否能进入填写
|
||
|
this.$api.get('/user/project/setting-status', {params: {projectKey: this.projectConfig.projectKey}}).then(res => {
|
||
5 years ago
|
if (res.msg) {
|
||
|
this.writeNotStartPrompt = res.msg
|
||
|
this.writeStatus = 0
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
getWxAuthorizationUserInfo() {
|
||
|
let wxAuthorizationCode = this.wxAuthorizationCode
|
||
4 years ago
|
// 根据code 获取用户授权信息
|
||
|
this.$api.get('/authorization/user/info', {
|
||
5 years ago
|
params: {
|
||
|
code: wxAuthorizationCode
|
||
|
}
|
||
|
}).then(res => {
|
||
|
if (res.data) {
|
||
|
this.wxUserInfo = res.data
|
||
|
alert(res.data)
|
||
|
}
|
||
|
})
|
||
|
|
||
|
},
|
||
|
getWxAuthorizationUrl() {
|
||
4 years ago
|
// 获取微信授权url地址
|
||
|
this.$api.get('/wx/jsapi/authorization/url', {params: {url: window.location.href}}).then(res => {
|
||
5 years ago
|
if (res.data) {
|
||
|
this.wxAuthorizationUrl = res.data
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
setWxConfig() {
|
||
5 years ago
|
let that = this
|
||
5 years ago
|
let signature = this.wxSignature
|
||
5 years ago
|
loadWXJs(wx => {
|
||
5 years ago
|
wx.config({
|
||
|
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
||
|
appId: signature.appId, // 必填,公众号的唯一标识
|
||
|
timestamp: signature.timestamp, // 必填,生成签名的时间戳
|
||
|
nonceStr: signature.nonceStr, // 必填,生成签名的随机串
|
||
4 years ago
|
signature: signature.signature, // 必填,签名
|
||
5 years ago
|
jsApiList: [
|
||
|
'updateAppMessageShareData',
|
||
|
'updateTimelineShareData',
|
||
5 years ago
|
'onMenuShareAppMessage',
|
||
|
'onMenuShareTimeline',
|
||
5 years ago
|
'showMenuItems',
|
||
|
'hideMenuItems',
|
||
|
'chooseWXPay'
|
||
|
] // 必填,需要使用的JS接口列表
|
||
|
})
|
||
4 years ago
|
// sdk准备完成之后调用
|
||
5 years ago
|
wx.ready(function() {
|
||
4 years ago
|
// 需在用户可能点击分享按钮前就先调用
|
||
5 years ago
|
console.log('ready')
|
||
|
that.setWxProjectShare(wx)
|
||
|
})
|
||
5 years ago
|
})
|
||
|
},
|
||
|
/**
|
||
|
* 微信分享
|
||
|
*/
|
||
5 years ago
|
setWxProjectShare(wx) {
|
||
5 years ago
|
let {shareImg, shareTitle, shareDesc} = this.userProjectSetting
|
||
5 years ago
|
wx.updateAppMessageShareData({
|
||
4 years ago
|
title: shareTitle || defaultValue.projectShareTitle, // 分享标题
|
||
|
desc: shareDesc || defaultValue.projectShareDesc, // 分享描述
|
||
5 years ago
|
link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
||
4 years ago
|
imgUrl: shareImg || defaultValue.projectShareImg, // 分享图标
|
||
5 years ago
|
success: function() {
|
||
|
// 设置成功
|
||
|
console.log('succcess')
|
||
|
},
|
||
|
fail: function() {
|
||
|
console.log('fail')
|
||
|
}
|
||
|
})
|
||
|
wx.updateTimelineShareData({
|
||
4 years ago
|
title: shareTitle || defaultValue.projectShareTitle, // 分享标题
|
||
|
desc: shareDesc || defaultValue.projectShareDesc, // 分享描述
|
||
5 years ago
|
link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
||
4 years ago
|
imgUrl: shareImg || defaultValue.projectShareImg, // 分享图标
|
||
5 years ago
|
success: function() {
|
||
|
// 设置成功
|
||
|
console.log('succcess')
|
||
|
},
|
||
|
fail: function() {
|
||
|
console.log('fail')
|
||
|
}
|
||
|
})
|
||
|
wx.onMenuShareTimeline({
|
||
4 years ago
|
title: shareTitle || defaultValue.projectShareTitle, // 分享标题
|
||
|
desc: shareDesc || defaultValue.projectShareDesc, // 分享描述
|
||
5 years ago
|
link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
||
4 years ago
|
imgUrl: shareImg || defaultValue.projectShareImg, // 分享图标
|
||
5 years ago
|
success: function() {
|
||
|
// 设置成功
|
||
|
console.log('succcess')
|
||
|
}
|
||
|
})
|
||
|
wx.onMenuShareAppMessage({
|
||
4 years ago
|
title: shareTitle || defaultValue.projectShareTitle, // 分享标题
|
||
|
desc: shareDesc || defaultValue.projectShareDesc, // 分享描述
|
||
5 years ago
|
link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
||
4 years ago
|
imgUrl: shareImg || defaultValue.projectShareImg, // 分享图标
|
||
5 years ago
|
success: function() {
|
||
|
// 设置成功
|
||
|
console.log('succcess')
|
||
|
}
|
||
5 years ago
|
})
|
||
|
},
|
||
5 years ago
|
queryProjectSetting() {
|
||
5 years ago
|
this.$api.get(`/user/project/setting/${this.projectConfig.projectKey}`).then(res => {
|
||
5 years ago
|
if (res.data) {
|
||
|
this.userProjectSetting = res.data
|
||
4 years ago
|
// 仅在微信环境打开
|
||
5 years ago
|
if (res.data && res.data.wxWrite) {
|
||
4 years ago
|
// 记录微信用户信息
|
||
5 years ago
|
if (res.data.recordWxUser && !this.wxAuthorizationCode) {
|
||
5 years ago
|
console.log(this.wxAuthorizationUrl)
|
||
5 years ago
|
location.href = this.wxAuthorizationUrl
|
||
|
} else {
|
||
|
this.onlyWxOpenHandle()
|
||
|
}
|
||
5 years ago
|
}
|
||
|
}
|
||
|
})
|
||
|
},
|
||
5 years ago
|
onlyWxOpenHandle() {
|
||
5 years ago
|
let wxUa = navigator.userAgent.toLowerCase()
|
||
|
let isWeixin = wxUa.indexOf('micromessenger') != -1
|
||
5 years ago
|
if (!isWeixin) {
|
||
|
document.head.innerHTML = '<title>抱歉,出错了</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0"><link rel="stylesheet" type="text/css" href="https://res.wx.qq.com/open/libs/weui/0.4.1/weui.css">'
|
||
|
document.body.innerHTML = '<div class="weui_msg"><div class="weui_icon_area"><i class="weui_icon_info weui_icon_msg"></i></div><div class="weui_text_area"><h4 class="weui_msg_title">请在微信客户端打开链接</h4></div></div>'
|
||
|
}
|
||
|
},
|
||
5 years ago
|
submitForm(data) {
|
||
4 years ago
|
// 完成时间
|
||
5 years ago
|
let inActiveTime = document.getElementById('inActiveTime').innerText
|
||
5 years ago
|
this.$api.post('/user/project/result/create', {
|
||
5 years ago
|
'completeTime': inActiveTime,
|
||
5 years ago
|
'projectKey': this.projectConfig.projectKey,
|
||
5 years ago
|
'submitOs': ua.os.name,
|
||
|
'submitBrowser': ua.browser.name,
|
||
|
'submitUa': ua,
|
||
5 years ago
|
'originalData': data.formModel,
|
||
|
'processData': data.labelFormModel
|
||
4 years ago
|
}).then(() => {
|
||
5 years ago
|
this.writeStatus = 2
|
||
5 years ago
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
5 years ago
|
<style lang="scss" scoped>
|
||
5 years ago
|
.write-container {
|
||
|
margin: 0;
|
||
|
padding: 0;
|
||
4 years ago
|
height: 100%;
|
||
5 years ago
|
width: 100%;
|
||
|
}
|
||
|
.title-icon-view {
|
||
|
display: flex;
|
||
|
align-items: center;
|
||
|
align-content: center;
|
||
|
justify-content: center;
|
||
|
flex-direction: column;
|
||
|
height: 100%;
|
||
|
width: 100%;
|
||
5 years ago
|
}
|
||
5 years ago
|
.icon-view {
|
||
|
width: 59px;
|
||
|
height: 59px;
|
||
|
border-radius: 100px;
|
||
4 years ago
|
background-color: #0076ff;
|
||
5 years ago
|
display: flex;
|
||
|
align-content: center;
|
||
5 years ago
|
align-items: center;
|
||
5 years ago
|
justify-content: center;
|
||
|
}
|
||
|
.success-icon {
|
||
|
text-align: center;
|
||
|
color: white;
|
||
|
font-size: 30px;
|
||
|
}
|
||
5 years ago
|
</style>
|