365 lines
10 KiB
Vue
Raw Normal View History

2022-02-06 01:04:05 +08:00
<template>
<div class="go-canvas-setting">
2022-02-06 21:35:38 +08:00
<n-form inline :label-width="45" size="small" label-placement="left">
<n-form-item label="宽度">
<!-- 尺寸选择 -->
<n-input-number
size="small"
v-model:value="canvasConfig.width"
2022-05-04 01:46:56 +08:00
:disabled="editCanvas.lockScale"
2022-02-06 21:35:38 +08:00
:validator="validator"
2022-03-10 17:55:59 +08:00
@update:value="changeSizeHandle"
></n-input-number>
2022-02-06 21:35:38 +08:00
</n-form-item>
<n-form-item label="高度">
<n-input-number
size="small"
v-model:value="canvasConfig.height"
2022-05-04 01:46:56 +08:00
:disabled="editCanvas.lockScale"
2022-02-06 21:35:38 +08:00
:validator="validator"
2022-03-10 17:55:59 +08:00
@update:value="changeSizeHandle"
></n-input-number>
2022-02-06 21:35:38 +08:00
</n-form-item>
</n-form>
<n-card class="upload-box">
<n-upload
v-model:file-list="uploadFileListRef"
:show-file-list="false"
:customRequest="customRequest"
:onBeforeUpload="beforeUploadHandle"
>
<n-upload-dragger>
2022-10-08 20:32:36 +08:00
<img v-if="canvasConfig.backgroundImage" class="upload-show" :src="canvasConfig.backgroundImage" alt="背景" />
2022-02-06 21:35:38 +08:00
<div class="upload-img" v-show="!canvasConfig.backgroundImage">
<img src="@/assets/images/canvas/noImage.png" />
<n-text class="upload-desc" depth="3">
2022-10-08 20:32:36 +08:00
背景图需小于 {{ backgroundImageSize }}M 格式为 png/jpg/gif 的文件
2022-02-06 21:35:38 +08:00
</n-text>
</div>
</n-upload-dragger>
</n-upload>
</n-card>
<n-space vertical :size="12">
<n-space>
2022-10-08 20:32:36 +08:00
<n-text>背景颜色</n-text>
<div class="picker-height">
<n-color-picker
v-if="!switchSelectColorLoading"
size="small"
style="width: 250px"
v-model:value="canvasConfig.background"
:showPreview="true"
:swatches="swatchesColors"
></n-color-picker>
</div>
2022-02-06 21:35:38 +08:00
</n-space>
<n-space>
2022-10-08 20:32:36 +08:00
<n-text>应用类型</n-text>
<n-select
2022-02-06 21:35:38 +08:00
size="small"
2022-10-08 20:32:36 +08:00
style="width: 250px"
v-model:value="selectColorValue"
2022-02-06 21:35:38 +08:00
:disabled="!canvasConfig.backgroundImage"
2022-10-08 20:32:36 +08:00
:options="selectColorOptions"
@update:value="selectColorValueHandle"
/>
2022-02-06 21:35:38 +08:00
</n-space>
<n-space>
2022-05-04 01:46:56 +08:00
<n-text>背景控制</n-text>
2022-10-08 20:32:36 +08:00
<n-button class="clear-btn" size="small" :disabled="!canvasConfig.backgroundImage" @click="clearImage">
清除背景
</n-button>
<n-button class="clear-btn" size="small" :disabled="!canvasConfig.background" @click="clearColor">
清除颜色
</n-button>
2022-02-06 21:35:38 +08:00
</n-space>
2022-05-04 01:46:56 +08:00
<n-space>
2022-11-12 21:49:04 +08:00
<n-text>适配方式</n-text>
2022-05-04 01:46:56 +08:00
<n-button-group>
2022-10-08 20:32:36 +08:00
<n-button
2022-05-04 01:46:56 +08:00
v-for="item in previewTypeList"
:key="item.key"
:type="canvasConfig.previewScaleType === item.key ? 'primary' : 'tertiary'"
2022-10-08 20:32:36 +08:00
ghost
2022-05-04 01:46:56 +08:00
size="small"
2022-10-08 20:32:36 +08:00
@click="selectPreviewType(item.key)"
>
2022-05-04 01:46:56 +08:00
<n-tooltip :show-arrow="false" trigger="hover">
<template #trigger>
2022-10-08 20:32:36 +08:00
<n-icon class="select-preview-icon" size="18">
2022-05-04 01:46:56 +08:00
<component :is="item.icon"></component>
</n-icon>
</template>
{{ item.desc }}
</n-tooltip>
</n-button>
</n-button-group>
</n-space>
2022-02-06 21:35:38 +08:00
</n-space>
2022-04-25 16:17:22 +08:00
<!-- 滤镜 -->
2022-08-09 21:08:25 +08:00
<styles-setting :isCanvas="true" :chartStyles="canvasConfig"></styles-setting>
2022-10-08 20:32:36 +08:00
<n-divider style="margin: 10px 0"></n-divider>
2022-04-25 16:17:22 +08:00
2022-02-08 19:39:57 +08:00
<!-- 主题选择和全局配置 -->
<n-tabs class="tabs-box" size="small" type="segment">
2022-02-08 19:39:57 +08:00
<n-tab-pane
v-for="item in globalTabList"
:key="item.key"
:name="item.key"
size="small"
display-directive="show:lazy"
>
<template #tab>
<n-space>
<span>{{ item.title }}</span>
<n-icon size="16" class="icon-position">
<component :is="item.icon"></component>
</n-icon>
</n-space>
</template>
<component :is="item.render"></component>
</n-tab-pane>
</n-tabs>
2022-02-06 01:04:05 +08:00
</div>
</template>
2022-02-06 21:35:38 +08:00
<script setup lang="ts">
2022-10-08 20:32:36 +08:00
import { ref, nextTick, watch } from 'vue'
import { backgroundImageSize } from '@/settings/designSetting'
import { FileTypeEnum } from '@/enums/fileTypeEnum'
2022-03-04 20:57:36 +08:00
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
2022-02-06 21:35:38 +08:00
import { EditCanvasConfigEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
import { useSystemStore } from '@/store/modules/systemStore/systemStore'
2022-04-25 16:17:22 +08:00
import { StylesSetting } from '@/components/Pages/ChartItemSetting'
2022-02-08 19:39:57 +08:00
import { UploadCustomRequestOptions } from 'naive-ui'
import { loadAsyncComponent, fetchRouteParamsLocation } from '@/utils'
2022-05-04 01:46:56 +08:00
import { PreviewScaleEnum } from '@/enums/styleEnum'
import { ResultEnum } from '@/enums/httpEnum'
2022-02-08 19:39:57 +08:00
import { icon } from '@/plugins'
import { uploadFile} from '@/api/path'
2022-02-08 19:39:57 +08:00
const { ColorPaletteIcon } = icon.ionicons5
2022-07-20 21:44:48 +08:00
const { ScaleIcon, FitToScreenIcon, FitToHeightIcon, FitToWidthIcon } = icon.carbon
2022-02-06 21:35:38 +08:00
2022-03-04 20:57:36 +08:00
const chartEditStore = useChartEditStore()
const systemStore = useSystemStore()
2022-03-04 20:57:36 +08:00
const canvasConfig = chartEditStore.getEditCanvasConfig
2022-05-04 01:46:56 +08:00
const editCanvas = chartEditStore.getEditCanvas
2022-02-06 21:35:38 +08:00
const uploadFileListRef = ref()
const switchSelectColorLoading = ref(false)
2022-10-08 20:32:36 +08:00
const selectColorValue = ref(0)
2022-02-06 21:35:38 +08:00
2022-10-08 20:32:36 +08:00
const ChartThemeColor = loadAsyncComponent(() => import('./components/ChartThemeColor/index.vue'))
2022-02-21 21:30:35 +08:00
2022-10-08 20:32:36 +08:00
// 默认应用类型
const selectColorOptions = [
{
label: '应用颜色',
value: 0
},
{
label: '应用背景',
value: 1
}
2022-02-22 15:32:57 +08:00
]
2022-10-08 20:32:36 +08:00
// 默认展示颜色列表
const swatchesColors = ['#232324', '#2a2a2b', '#313132', '#373739', '#757575', '#e0e0e0', '#eeeeee', '#fafafa']
2022-02-08 19:39:57 +08:00
const globalTabList = [
{
key: 'ChartTheme',
2022-02-21 19:45:11 +08:00
title: '主题颜色',
2022-02-08 19:39:57 +08:00
icon: ColorPaletteIcon,
2022-02-21 21:30:35 +08:00
render: ChartThemeColor
}
2022-02-08 19:39:57 +08:00
]
2022-05-04 01:46:56 +08:00
const previewTypeList = [
{
key: PreviewScaleEnum.FIT,
title: '自适应',
icon: ScaleIcon,
desc: '自适应比例展示,页面会有留白'
},
{
key: PreviewScaleEnum.SCROLL_Y,
title: 'Y轴滚动',
icon: FitToWidthIcon,
desc: 'X轴铺满Y轴自适应滚动'
},
{
key: PreviewScaleEnum.SCROLL_X,
title: 'X轴滚动',
icon: FitToHeightIcon,
desc: 'Y轴铺满X轴自适应滚动'
},
{
key: PreviewScaleEnum.FULL,
title: '铺满',
icon: FitToScreenIcon,
desc: '强行拉伸画面,填充所有视图'
2022-10-08 20:32:36 +08:00
}
2022-05-04 01:46:56 +08:00
]
2022-10-08 20:32:36 +08:00
watch(
() => canvasConfig.selectColor,
newValue => {
selectColorValue.value = newValue ? 0 : 1
},
{
immediate: true
}
)
2022-05-04 01:46:56 +08:00
// 画布尺寸规则
2022-02-06 21:35:38 +08:00
const validator = (x: number) => x > 50
2022-05-04 01:46:56 +08:00
// 修改尺寸
const changeSizeHandle = () => {
chartEditStore.computedScale()
}
// 上传图片前置处理
2022-02-06 21:35:38 +08:00
//@ts-ignore
const beforeUploadHandle = async ({ file }) => {
uploadFileListRef.value = []
const type = file.file.type
const size = file.file.size
if (size > 1024 * 1024 * backgroundImageSize) {
2022-10-08 20:32:36 +08:00
window['$message'].warning(`图片超出 ${backgroundImageSize}M 限制,请重新上传!`)
2022-02-06 21:35:38 +08:00
return false
}
if (type !== FileTypeEnum.PNG && type !== FileTypeEnum.JPEG && type !== FileTypeEnum.GIF) {
2022-02-06 21:35:38 +08:00
window['$message'].warning('文件格式不符合,请重新上传!')
return false
}
return true
}
2022-10-08 20:32:36 +08:00
// 应用颜色
const selectColorValueHandle = (value: number) => {
canvasConfig.selectColor = value == 0
2022-02-06 21:35:38 +08:00
}
2022-10-08 20:32:36 +08:00
// 清除背景
const clearImage = () => {
chartEditStore.setEditCanvasConfig(EditCanvasConfigEnum.BACKGROUND_IMAGE, undefined)
chartEditStore.setEditCanvasConfig(EditCanvasConfigEnum.SELECT_COLOR, true)
2022-02-06 21:35:38 +08:00
}
2022-10-08 20:32:36 +08:00
// 启用/关闭 颜色(强制更新)
2022-02-06 21:35:38 +08:00
const switchSelectColorHandle = () => {
switchSelectColorLoading.value = true
setTimeout(() => {
switchSelectColorLoading.value = false
2022-10-08 20:32:36 +08:00
})
}
// 清除颜色
const clearColor = () => {
chartEditStore.setEditCanvasConfig(EditCanvasConfigEnum.BACKGROUND, undefined)
if (canvasConfig.backgroundImage) {
chartEditStore.setEditCanvasConfig(EditCanvasConfigEnum.SELECT_COLOR, false)
}
switchSelectColorHandle()
2022-02-06 21:35:38 +08:00
}
// 自定义上传操作
const customRequest = (options: UploadCustomRequestOptions) => {
const { file } = options
nextTick(async () => {
if (file.file) {
// 修改名称
const newNameFile = new File(
[file.file],
`${fetchRouteParamsLocation()}_index_background.png`,
{ type: file.file.type }
)
let uploadParams = new FormData()
uploadParams.append('object', newNameFile)
const uploadRes = await uploadFile(uploadParams) as unknown as MyResponseType
if(uploadRes.code === ResultEnum.SUCCESS) {
chartEditStore.setEditCanvasConfig(
EditCanvasConfigEnum.BACKGROUND_IMAGE,
`${systemStore.getFetchInfo.OSSUrl}${uploadRes.data.fileName}?time=${new Date().getTime()}`
)
chartEditStore.setEditCanvasConfig(
EditCanvasConfigEnum.SELECT_COLOR,
false
)
return
}
window['$message'].error('添加图片失败,请稍后重试!')
} else {
window['$message'].error('添加图片失败,请稍后重试!')
}
2022-02-06 21:35:38 +08:00
})
}
2022-05-04 01:46:56 +08:00
2022-11-12 21:49:04 +08:00
// 选择适配方式
2022-05-04 01:46:56 +08:00
const selectPreviewType = (key: PreviewScaleEnum) => {
chartEditStore.setEditCanvasConfig(EditCanvasConfigEnum.PREVIEW_SCALE_TYPE, key)
}
2022-02-06 01:04:05 +08:00
</script>
<style lang="scss" scoped>
2022-10-08 20:32:36 +08:00
$uploadWidth: 326px;
$uploadHeight: 193px;
2022-02-06 01:04:05 +08:00
@include go(canvas-setting) {
2022-02-06 21:35:38 +08:00
padding-top: 20px;
.upload-box {
cursor: pointer;
margin-bottom: 20px;
@include deep() {
.n-card__content {
padding: 0;
2022-02-06 21:35:38 +08:00
overflow: hidden;
}
.n-upload-dragger {
padding: 5px;
2022-10-08 20:32:36 +08:00
width: $uploadWidth;
}
2022-02-06 21:35:38 +08:00
}
.upload-show {
width: -webkit-fill-available;
2022-10-08 20:32:36 +08:00
height: $uploadHeight;
2022-02-06 21:35:38 +08:00
border-radius: 5px;
}
.upload-img {
display: flex;
flex-direction: column;
align-items: center;
img {
height: 150px;
}
.upload-desc {
padding: 10px 0;
}
}
}
2022-02-08 19:39:57 +08:00
.icon-position {
padding-top: 2px;
}
2022-10-08 20:32:36 +08:00
.picker-height {
min-height: 35px;
}
.clear-btn {
padding-left: 2.25em;
padding-right: 2.25em;
}
.select-preview-icon {
padding-right: .68em;
padding-left: .68em;
}
2022-02-22 15:32:57 +08:00
.tabs-box {
2022-04-26 11:44:24 +08:00
margin-top: 20px;
2022-02-22 15:32:57 +08:00
}
2022-02-06 01:04:05 +08:00
}
</style>