201 lines
5.4 KiB
Vue
Raw Normal View History

2022-01-05 18:04:41 +08:00
<template>
2022-06-03 14:48:58 +08:00
<n-space>
<n-button
v-for="item in btnList"
: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>
<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">
2022-06-03 14:48:58 +08:00
import { ref, shallowReactive, watchEffect } from 'vue'
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'
2022-06-03 14:48:58 +08:00
import { ProjectInfoEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
import { updateProjectApi } from '@/api/path'
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,
} from '@/utils'
2022-04-07 11:24:40 +08:00
import { icon } from '@/plugins'
2022-03-06 02:08:14 +08:00
2022-06-03 14:48:58 +08:00
const { BrowsersOutlineIcon, SendIcon, 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
2022-06-03 14:48:58 +08:00
const sessionStorageInfo =
getLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST) || []
2022-03-06 02:08:14 +08:00
if (sessionStorageInfo?.length) {
2022-06-03 14:48:58 +08:00
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,
})
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,
...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 {
2022-06-03 14:48:58 +08:00
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 updateProjectApi({
id: fetchRouteParamsLocation(),
// 反过来
state: release.value ? -1 : 1,
})) as unknown as MyResponseType
if (res.code === ResultEnum.SUCCESS) {
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
2022-03-09 17:37:32 +08:00
const btnList = shallowReactive([
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),
2022-06-03 14:48:58 +08:00
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
])
</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>