206 lines
5.7 KiB
Vue
Raw Normal View History

2022-01-05 18:04:41 +08:00
<template>
<n-space class="go-mt-0">
<n-button v-for="item in comBtnList" :key="item.key" :type="item.type()" ghost @click="item.event">
2022-01-05 18:04:41 +08:00
<template #icon>
<component :is="item.icon"></component>
</template>
2022-06-03 14:48:58 +08:00
<span>{{ item.title() }}</span>
2022-01-05 18:04:41 +08:00
</n-button>
</n-space>
2022-06-03 14:48:58 +08:00
<!-- 发布管理弹窗 -->
<n-modal v-model:show="modelShow" @afterLeave="closeHandle">
<n-list bordered class="go-system-setting">
<template #header>
<n-space justify="space-between">
<n-h3 class="go-mb-0">发布管理</n-h3>
<n-icon size="20" class="go-cursor-pointer" @click="closeHandle">
<close-icon></close-icon>
</n-icon>
</n-space>
</template>
<n-list-item>
<n-space :size="10">
<n-alert :show-icon="false" title="预览地址:" type="success">
{{ previewPath() }}
</n-alert>
2022-06-11 14:23:16 +08:00
<n-space vertical>
<n-button tertiary type="primary" @click="copyPreviewPath()"> 复制地址 </n-button>
2022-06-11 14:23:16 +08:00
<n-button :type="release ? 'warning' : 'primary'" @click="sendHandle">
{{ release ? '取消发布' : '发布大屏' }}
</n-button>
</n-space>
2022-06-03 14:48:58 +08:00
</n-space>
</n-list-item>
<n-list-item>
<n-space :size="10">
2022-06-11 14:23:16 +08:00
<n-button @click="modelShowHandle">关闭弹窗</n-button>
2022-06-03 14:48:58 +08:00
</n-space>
</n-list-item>
</n-list>
</n-modal>
2022-01-05 18:04:41 +08:00
</template>
<script setup lang="ts">
import { ref, computed, watchEffect } from 'vue'
2022-06-03 14:48:58 +08:00
import { useRoute } from 'vue-router'
2022-06-03 18:53:37 +08:00
import { useClipboard } from '@vueuse/core'
2022-03-06 02:08:14 +08:00
import { PreviewEnum } from '@/enums/pageEnum'
import { StorageEnum } from '@/enums/storageEnum'
2022-06-03 14:48:58 +08:00
import { ResultEnum } from '@/enums/httpEnum'
2022-03-06 02:08:14 +08:00
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
2023-03-03 22:25:36 +08:00
import { syncData } from '../../ContentEdit/components/EditTools/hooks/useSyncUpdate.hook'
2022-06-03 14:48:58 +08:00
import { ProjectInfoEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
2022-10-26 10:51:10 +08:00
import { changeProjectReleaseApi } from '@/api/path'
2022-06-03 14:48:58 +08:00
import {
2022-06-03 18:53:37 +08:00
previewPath,
2022-06-03 14:48:58 +08:00
renderIcon,
fetchPathByName,
routerTurnByPath,
setSessionStorage,
getLocalStorage,
httpErrorHandle,
fetchRouteParamsLocation
2022-06-03 14:48:58 +08:00
} from '@/utils'
2022-04-07 11:24:40 +08:00
import { icon } from '@/plugins'
2023-03-03 22:25:36 +08:00
import { cloneDeep } from 'lodash'
2022-03-06 02:08:14 +08:00
const { BrowsersOutlineIcon, SendIcon, AnalyticsIcon, CloseIcon } = icon.ionicons5
2022-03-06 02:08:14 +08:00
const chartEditStore = useChartEditStore()
2022-06-03 18:53:37 +08:00
const previewPathRef = ref(previewPath())
const { copy, isSupported } = useClipboard({ source: previewPathRef })
2022-03-06 02:08:14 +08:00
const routerParamsInfo = useRoute()
2022-06-03 14:48:58 +08:00
const modelShow = ref<boolean>(false)
const release = ref<boolean>(false)
watchEffect(() => {
release.value = chartEditStore.getProjectInfo.release || false
})
// 关闭弹窗
const closeHandle = () => {
modelShow.value = false
}
2022-03-06 02:08:14 +08:00
// 预览
const previewHandle = () => {
const path = fetchPathByName(PreviewEnum.CHART_PREVIEW_NAME, 'href')
if (!path) return
const { id } = routerParamsInfo.params
// id 标识
const previewId = typeof id === 'string' ? id : id[0]
const storageInfo = chartEditStore.getStorageInfo
const sessionStorageInfo = getLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST) || []
2022-03-06 02:08:14 +08:00
if (sessionStorageInfo?.length) {
const repeateIndex = sessionStorageInfo.findIndex((e: { id: string }) => e.id === previewId)
2022-03-06 20:31:45 +08:00
// 重复替换
2022-03-06 02:08:14 +08:00
if (repeateIndex !== -1) {
2022-06-03 14:48:58 +08:00
sessionStorageInfo.splice(repeateIndex, 1, {
id: previewId,
...storageInfo
2022-06-03 14:48:58 +08:00
})
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, sessionStorageInfo)
2022-03-06 20:31:45 +08:00
} else {
sessionStorageInfo.push({
2022-06-03 14:48:58 +08:00
id: previewId,
2023-03-03 22:25:36 +08:00
...storageInfo
2022-03-06 20:31:45 +08:00
})
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, sessionStorageInfo)
2022-03-06 02:08:14 +08:00
}
} else {
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, [{ id: previewId, ...storageInfo }])
2022-03-06 02:08:14 +08:00
}
// 跳转
routerTurnByPath(path, [previewId], undefined, true)
}
2022-06-03 14:48:58 +08:00
// 模态弹窗
const modelShowHandle = () => {
modelShow.value = !modelShow.value
}
// 复制预览地址
2022-06-03 18:53:37 +08:00
const copyPreviewPath = (successText?: string, failureText?: string) => {
2022-06-11 14:23:16 +08:00
if (isSupported) {
2022-06-03 18:53:37 +08:00
copy()
window['$message'].success(successText || '复制成功!')
} else {
window['$message'].error(failureText || '复制失败!')
2022-06-03 18:53:37 +08:00
}
2022-06-03 14:48:58 +08:00
}
2022-03-06 02:08:14 +08:00
// 发布
2022-06-03 14:48:58 +08:00
const sendHandle = async () => {
const res = await changeProjectReleaseApi({
2022-06-03 14:48:58 +08:00
id: fetchRouteParamsLocation(),
// 反过来
state: release.value ? -1 : 1
})
2022-06-03 14:48:58 +08:00
2022-11-27 11:40:00 +08:00
if (res && res.code === ResultEnum.SUCCESS) {
2022-06-03 14:48:58 +08:00
modelShowHandle()
if (!release.value) {
2022-06-03 18:53:37 +08:00
copyPreviewPath('发布成功!已复制地址到剪贴板~', '发布成功!')
2022-06-03 14:48:58 +08:00
} else {
window['$message'].success(`已取消发布`)
}
chartEditStore.setProjectInfo(ProjectInfoEnum.RELEASE, !release.value)
} else {
httpErrorHandle()
}
2022-03-06 02:08:14 +08:00
}
2022-01-05 18:04:41 +08:00
2023-03-03 22:25:36 +08:00
const btnList = [
{
select: true,
title: () => '同步内容',
type: () => 'primary',
2023-03-03 22:25:36 +08:00
icon: renderIcon(AnalyticsIcon),
event: syncData
},
2022-01-05 18:04:41 +08:00
{
2022-06-03 14:48:58 +08:00
key: 'preview',
title: () => '预览',
type: () => 'default',
2022-03-06 02:08:14 +08:00
icon: renderIcon(BrowsersOutlineIcon),
event: previewHandle
2022-01-05 18:04:41 +08:00
},
{
2022-06-03 14:48:58 +08:00
key: 'release',
title: () => (release.value ? '已发布' : '发布'),
2022-03-06 02:08:14 +08:00
icon: renderIcon(SendIcon),
2022-06-03 14:48:58 +08:00
type: () => (release.value ? 'primary' : 'default'),
event: modelShowHandle
2022-01-05 18:04:41 +08:00
}
2023-03-03 22:25:36 +08:00
]
2022-04-07 15:28:25 +08:00
2023-03-03 22:25:36 +08:00
const comBtnList = computed(() => {
if (chartEditStore.getEditCanvas.isCodeEdit) {
return btnList
}
const cloneList = cloneDeep(btnList)
cloneList.shift()
return cloneList
})
2022-01-05 18:04:41 +08:00
</script>
2022-06-03 14:48:58 +08:00
2022-01-05 18:04:41 +08:00
<style lang="scss" scoped>
2022-06-03 14:48:58 +08:00
@include go('system-setting') {
@extend .go-background-filter;
min-width: 100px;
max-width: 60vw;
padding-bottom: 20px;
@include deep() {
.n-list-item:not(:last-child) {
border-bottom: 0;
}
}
2022-01-05 18:04:41 +08:00
}
</style>