refactor: 重构 management/pages/publishResult 目录下组件, 使用 Vue3 组合式 API 写法 (#167)
This commit is contained in:
parent
4b8bcac049
commit
fd6585d80c
@ -38,6 +38,7 @@
|
|||||||
"@rushstack/eslint-patch": "^1.10.2",
|
"@rushstack/eslint-patch": "^1.10.2",
|
||||||
"@tsconfig/node20": "^20.1.2",
|
"@tsconfig/node20": "^20.1.2",
|
||||||
"@types/node": "^20.11.19",
|
"@types/node": "^20.11.19",
|
||||||
|
"@types/qrcode": "^1.5.5",
|
||||||
"@vitejs/plugin-vue": "^5.0.3",
|
"@vitejs/plugin-vue": "^5.0.3",
|
||||||
"@vitejs/plugin-vue-jsx": "^3.1.0",
|
"@vitejs/plugin-vue-jsx": "^3.1.0",
|
||||||
"@vue/eslint-config-prettier": "^8.0.0",
|
"@vue/eslint-config-prettier": "^8.0.0",
|
||||||
|
@ -25,7 +25,7 @@ const tabs = [
|
|||||||
text: '投放问卷',
|
text: '投放问卷',
|
||||||
icon: 'icon-toufang',
|
icon: 'icon-toufang',
|
||||||
to: {
|
to: {
|
||||||
name: 'publishResultPage'
|
name: 'publish'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -53,9 +53,7 @@ export default {
|
|||||||
if (publishRes.code === 200) {
|
if (publishRes.code === 200) {
|
||||||
ElMessage.success('发布成功')
|
ElMessage.success('发布成功')
|
||||||
this.$store.dispatch('edit/getSchemaFromRemote')
|
this.$store.dispatch('edit/getSchemaFromRemote')
|
||||||
this.$router.push({
|
this.$router.push({ name: 'publish' })
|
||||||
name: 'publishResultPage'
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error(`发布失败 ${publishRes.errmsg}`)
|
ElMessage.error(`发布失败 ${publishRes.errmsg}`)
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ export default {
|
|||||||
return
|
return
|
||||||
case 'release':
|
case 'release':
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
name: 'publishResultPage',
|
name: 'publish',
|
||||||
params: {
|
params: {
|
||||||
id: this.data._id
|
id: this.data._id
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<LeftMenu class="left" />
|
<LeftMenu class="left" />
|
||||||
<div class="right">
|
<div class="right">
|
||||||
<template v-if="curStatus !== 'new'">
|
<template v-if="curStatus !== 'new'">
|
||||||
<div class="preview-container" :style="{ backgroundImage: `url('${this.phoneBg}')` }">
|
<div class="preview-container" :style="{ backgroundImage: `url('${backgroundImage}')` }">
|
||||||
<iframe :src="mainChannel.fullUrl"></iframe>
|
<iframe :src="mainChannel.fullUrl"></iframe>
|
||||||
</div>
|
</div>
|
||||||
<div class="container-content">
|
<div class="container-content">
|
||||||
@ -20,13 +20,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<EmptyIndex v-else :data="noDataConfig" />
|
<EmptyIndex v-else :data="defaultConfig" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
<script>
|
import { computed, onMounted } from 'vue'
|
||||||
import { mapState } from 'vuex'
|
import { useStore } from 'vuex'
|
||||||
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { get as _get } from 'lodash-es'
|
import { get as _get } from 'lodash-es'
|
||||||
|
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
@ -34,61 +35,43 @@ import 'element-plus/theme-chalk/src/message.scss'
|
|||||||
|
|
||||||
import EmptyIndex from '@/management/components/EmptyIndex.vue'
|
import EmptyIndex from '@/management/components/EmptyIndex.vue'
|
||||||
import LeftMenu from '@/management/components/LeftMenu.vue'
|
import LeftMenu from '@/management/components/LeftMenu.vue'
|
||||||
|
|
||||||
import ChannelRow from './components/ChannelRow.vue'
|
import ChannelRow from './components/ChannelRow.vue'
|
||||||
|
|
||||||
export default {
|
const backgroundImage = '/imgs/phone-bg.webp'
|
||||||
name: 'PublishResultPage',
|
const defaultConfig = {
|
||||||
data() {
|
title: '问卷未发布',
|
||||||
return {
|
desc: '点击发布后,问卷就可以对外投放了哦!',
|
||||||
noDataConfig: {
|
img: '/imgs/icons/unpublished.webp'
|
||||||
title: '问卷未发布',
|
|
||||||
desc: '点击发布后,问卷就可以对外投放了哦!',
|
|
||||||
img: '/imgs/icons/unpublished.webp'
|
|
||||||
},
|
|
||||||
phoneBg: '/imgs/phone-bg.webp'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async created() {
|
|
||||||
this.$store.commit('edit/setSurveyId', this.$route.params.id)
|
|
||||||
try {
|
|
||||||
await this.$store.dispatch('edit/init')
|
|
||||||
} catch (error) {
|
|
||||||
ElMessage.error(error.message)
|
|
||||||
// 自动跳转回列表页
|
|
||||||
setTimeout(() => {
|
|
||||||
this.$router.replace({
|
|
||||||
name: 'survey'
|
|
||||||
})
|
|
||||||
}, 1000)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
...mapState({
|
|
||||||
metaData: (state) => _get(state, 'edit.schema.metaData')
|
|
||||||
}),
|
|
||||||
curStatus() {
|
|
||||||
return _get(this.metaData, 'curStatus.status', 'new')
|
|
||||||
},
|
|
||||||
mainChannel() {
|
|
||||||
if (!this.metaData) {
|
|
||||||
return {
|
|
||||||
fullUrl: ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
fullUrl: `${location.origin}/render/${this.metaData.surveyPath}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
components: {
|
|
||||||
ChannelRow,
|
|
||||||
EmptyIndex,
|
|
||||||
LeftMenu
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
|
||||||
|
|
||||||
|
const store = useStore()
|
||||||
|
const metaData = computed(() => _get(store.state, 'edit.schema.metaData'))
|
||||||
|
const curStatus = computed(() => _get(metaData.value, 'curStatus.status', 'new'))
|
||||||
|
const mainChannel = computed(() => {
|
||||||
|
let fullUrl = ''
|
||||||
|
|
||||||
|
if (metaData.value) {
|
||||||
|
fullUrl = `${location.origin}/render/${metaData.value.surveyPath}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return { fullUrl }
|
||||||
|
})
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
onMounted(async () => {
|
||||||
|
store.commit('edit/setSurveyId', route.params.id)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await store.dispatch('edit/init')
|
||||||
|
} catch (err: any) {
|
||||||
|
ElMessage.error(err.message)
|
||||||
|
setTimeout(() => {
|
||||||
|
router.replace({ name: 'survey' })
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.publish-result-page {
|
.publish-result-page {
|
||||||
width: 100%;
|
width: 100%;
|
@ -4,63 +4,66 @@
|
|||||||
<div class="left">
|
<div class="left">
|
||||||
<div class="crc-url-wrap" :class="{ 'no-name': !data.name }">
|
<div class="crc-url-wrap" :class="{ 'no-name': !data.name }">
|
||||||
<div style="margin-bottom: 16px">
|
<div style="margin-bottom: 16px">
|
||||||
<el-input class="cru-content" :model-value="getFullUrl(data)" :readonly="true" />
|
<el-input class="cru-content" :model-value="normalizationURL(data)" :readonly="true" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="operate-btn-group">
|
<div class="operate-btn-group">
|
||||||
<el-tooltip class="item" effect="dark" content="在新页面打开" placement="top">
|
<el-tooltip class="item" effect="dark" content="在新页面打开" placement="top">
|
||||||
<a class="cru-suffix j-open" @click="openPage(getFullUrl(data))">
|
<a class="cru-suffix j-open" @click="handleOpenPage(normalizationURL(data))">
|
||||||
<i class="font23 iconfont icon-jinru"></i>
|
<i class="font23 iconfont icon-jinru"></i>
|
||||||
</a>
|
</a>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
<el-tooltip class="item" effect="dark" content="复制链接" placement="top">
|
<el-tooltip class="item" effect="dark" content="复制链接" placement="top">
|
||||||
<a class="cru-suffix j-copy" :data-clipboard-text="getFullUrl(data)" @click="handleCopy">
|
<a
|
||||||
|
class="cru-suffix j-copy"
|
||||||
|
:data-clipboard-text="normalizationURL(data)"
|
||||||
|
@click="handleCopy"
|
||||||
|
>
|
||||||
<i class="font23 iconfont icon-fuzhi"></i>
|
<i class="font23 iconfont icon-fuzhi"></i>
|
||||||
</a>
|
</a>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
<QRCode class="cru-suffix" :url="getFullUrl(data)" />
|
<QRCode class="cru-suffix" :url="normalizationURL(data)" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup lang="ts">
|
||||||
import Clipboard from 'clipboard'
|
import Clipboard from 'clipboard'
|
||||||
|
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import 'element-plus/theme-chalk/src/message.scss'
|
import 'element-plus/theme-chalk/src/message.scss'
|
||||||
|
|
||||||
import QRCode from './QRCode.vue'
|
import QRCode from './QRCode.vue'
|
||||||
|
|
||||||
export default {
|
interface Props {
|
||||||
name: 'ChannelRow',
|
data: any
|
||||||
components: {
|
styleWrap: any
|
||||||
QRCode
|
}
|
||||||
},
|
|
||||||
props: ['data', 'styleWrap'],
|
defineProps<Props>()
|
||||||
methods: {
|
|
||||||
handleCopy() {
|
const handleCopy = () => {
|
||||||
const clipboard = new Clipboard('.j-copy')
|
const clipboard = new Clipboard('.j-copy')
|
||||||
clipboard.on('success', (e) => {
|
clipboard.on('success', (e) => {
|
||||||
ElMessage({
|
ElMessage({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: `已复制渠道链接:${e.text}`
|
message: `已复制渠道链接:${e.text}`
|
||||||
})
|
})
|
||||||
})
|
|
||||||
},
|
clipboard.destroy()
|
||||||
openPage(url) {
|
})
|
||||||
window.open(url)
|
}
|
||||||
},
|
|
||||||
getFullUrl(v) {
|
const handleOpenPage = (url: string) => window.open(url)
|
||||||
const url = v.fullUrl
|
|
||||||
const protocol = window.location.protocol
|
const normalizationURL = (value: any) => {
|
||||||
return `${protocol}//${url.split('//')[1]}`
|
const url = value.fullUrl
|
||||||
}
|
const protocol = window.location.protocol
|
||||||
}
|
|
||||||
|
return `${protocol}//${url.split('//')[1]}`
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.channel-list-wrap div.normal-row-wrap {
|
.channel-list-wrap div.normal-row-wrap {
|
||||||
position: relative;
|
position: relative;
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="qrcode" @mouseover="inQcode = true" @mouseout="inQcode = false">
|
<div class="qrcode">
|
||||||
<div class="qcode-mask">
|
<div class="qcode-mask">
|
||||||
<el-popover
|
<el-popover
|
||||||
ref="popover"
|
ref="popover"
|
||||||
@ -18,42 +18,42 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup lang="ts">
|
||||||
|
import { ref, watch, computed, nextTick } from 'vue'
|
||||||
|
|
||||||
import QRCode from 'qrcode'
|
import QRCode from 'qrcode'
|
||||||
|
|
||||||
export default {
|
interface Props {
|
||||||
name: 'QRCode',
|
url: string
|
||||||
props: ['url'],
|
}
|
||||||
data() {
|
|
||||||
return {
|
const props = defineProps<Props>()
|
||||||
inQcode: false,
|
|
||||||
qRCodeImg: ''
|
const qRCodeImg = ref<string>('')
|
||||||
}
|
const watchURL = computed<string>(() => props.url)
|
||||||
},
|
|
||||||
methods: {
|
const convertUrlToQRCode = async (url: string) => {
|
||||||
initQRCodeImg() {
|
try {
|
||||||
QRCode.toDataURL(this.url)
|
const res = await QRCode.toDataURL(url)
|
||||||
.then((url) => {
|
qRCodeImg.value = res
|
||||||
this.qRCodeImg = url
|
} catch (err) {
|
||||||
})
|
console.log(err)
|
||||||
.catch((err) => {
|
|
||||||
console.error(err)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
url: {
|
|
||||||
immediate: true,
|
|
||||||
handler(newVal) {
|
|
||||||
if (newVal) {
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.initQRCodeImg()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
watchURL,
|
||||||
|
(value) => {
|
||||||
|
if ((!qRCodeImg.value && value) || watchURL.value !== value) {
|
||||||
|
nextTick(() => {
|
||||||
|
convertUrlToQRCode(value)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
@ -94,12 +94,12 @@ const routes: RouteRecordRaw[] = [
|
|||||||
component: () => import('../pages/analysis/AnalysisPage.vue')
|
component: () => import('../pages/analysis/AnalysisPage.vue')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/survey/:id/publishResult',
|
path: '/survey/:id/publish',
|
||||||
name: 'publishResultPage',
|
name: 'publish',
|
||||||
meta: {
|
meta: {
|
||||||
needLogin: true
|
needLogin: true
|
||||||
},
|
},
|
||||||
component: () => import('../pages/publishResult/PublishResultPage.vue')
|
component: () => import('../pages/publish/PublishPage.vue')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/create',
|
path: '/create',
|
||||||
|
Loading…
Reference in New Issue
Block a user