299 lines
7.2 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"
: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"
: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>
<img
v-if="canvasConfig.backgroundImage"
class="upload-show"
2022-02-06 21:35:38 +08:00
:src="canvasConfig.backgroundImage"
alt="背景"
/>
<div class="upload-img" v-show="!canvasConfig.backgroundImage">
<img src="@/assets/images/canvas/noImage.png" />
<n-text class="upload-desc" depth="3">
背景图需小于 {{ 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>
<n-text>背景色</n-text>
<n-color-picker
style="width: 326px;"
:showPreview="true"
2022-02-22 15:32:57 +08:00
:swatches="swatchesColors"
2022-02-06 21:35:38 +08:00
v-model:value="canvasConfig.background"
></n-color-picker>
2022-02-06 21:35:38 +08:00
</n-space>
<n-space>
<n-text>使用颜色</n-text>
<n-switch
size="small"
v-model:value="canvasConfig.selectColor"
:loading="switchSelectColorLoading"
:round="false"
:disabled="!canvasConfig.backgroundImage"
:onUpdate="switchSelectColorHandle"
></n-switch>
2022-02-06 21:35:38 +08:00
</n-space>
<n-space>
<n-text>背景</n-text>
<n-button
size="small"
:disabled="!canvasConfig.backgroundImage"
@click="clearImage"
>
清除背景图
</n-button>
<n-button
size="small"
:disabled="!canvasConfig.background"
@click="clearColor"
>
清除颜色
</n-button>
</n-space>
</n-space>
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">
import { ref, nextTick } from 'vue'
import { backgroundImageSize } from '@/settings/designSetting'
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'
2022-02-08 19:39:57 +08:00
import { UploadCustomRequestOptions } from 'naive-ui'
2022-02-21 21:30:35 +08:00
import { fileToUrl, loadAsyncComponent } from '@/utils'
2022-02-08 19:39:57 +08:00
import { icon } from '@/plugins'
const { ColorPaletteIcon } = icon.ionicons5
const { ZAxisIcon } = icon.carbon
2022-02-06 21:35:38 +08:00
2022-03-04 20:57:36 +08:00
const chartEditStore = useChartEditStore()
const canvasConfig = chartEditStore.getEditCanvasConfig
2022-02-06 21:35:38 +08:00
const uploadFileListRef = ref()
const switchSelectColorLoading = ref(false)
2022-02-22 15:32:57 +08:00
const ChartThemeColor = loadAsyncComponent(() =>
import('./components/ChartThemeColor/index.vue')
)
2022-02-24 20:11:38 +08:00
const ChartDataSetting = loadAsyncComponent(() =>
import('./components/ChartDataSetting/index.vue')
2022-02-22 15:32:57 +08:00
)
2022-02-21 21:30:35 +08:00
2022-02-08 19:39:57 +08:00
// 页面设置
2022-02-22 15:32:57 +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
},
{
key: 'ChartSysSetting',
2022-02-24 20:11:38 +08:00
title: '数据配置',
2022-02-08 19:39:57 +08:00
icon: ZAxisIcon,
2022-02-24 20:11:38 +08:00
render: ChartDataSetting
}
2022-02-08 19:39:57 +08:00
]
2022-02-06 21:35:38 +08:00
// 规则
const validator = (x: number) => x > 50
// 前置处理
//@ts-ignore
const beforeUploadHandle = async ({ file }) => {
uploadFileListRef.value = []
const type = file.file.type
const size = file.file.size
if (size > 1024 * 1024 * backgroundImageSize) {
window['$message'].warning(
`图片超出 ${backgroundImageSize}M 限制,请重新上传!`
)
2022-02-06 21:35:38 +08:00
return false
}
if (type !== 'image/png' && type !== 'image/jpeg' && type !== 'image/gif') {
window['$message'].warning('文件格式不符合,请重新上传!')
return false
}
return true
}
2022-03-10 17:55:59 +08:00
// 修改尺寸
const changeSizeHandle = () => {
chartEditStore.computedScale
chartEditStore.setPageSize
}
2022-02-06 21:35:38 +08:00
// 清除背景
const clearImage = () => {
2022-03-04 20:57:36 +08:00
chartEditStore.setEditCanvasConfig(
2022-02-06 21:35:38 +08:00
EditCanvasConfigEnum.BACKGROUND_IAMGE,
undefined
)
2022-03-04 20:57:36 +08:00
chartEditStore.setEditCanvasConfig(
2022-02-22 15:32:57 +08:00
EditCanvasConfigEnum.SELECT_COLOR,
true
)
2022-02-06 21:35:38 +08:00
}
// 清除颜色
const clearColor = () => {
2022-03-04 20:57:36 +08:00
chartEditStore.setEditCanvasConfig(
2022-02-06 21:35:38 +08:00
EditCanvasConfigEnum.BACKGROUND,
undefined
)
if (canvasConfig.backgroundImage) {
2022-03-04 20:57:36 +08:00
chartEditStore.setEditCanvasConfig(
EditCanvasConfigEnum.SELECT_COLOR,
false
)
}
2022-02-06 21:35:38 +08:00
}
// 启用/关闭 颜色
2022-02-06 21:35:38 +08:00
const switchSelectColorHandle = () => {
switchSelectColorLoading.value = true
setTimeout(() => {
switchSelectColorLoading.value = false
}, 1000)
}
// 自定义上传操作
const customRequest = (options: UploadCustomRequestOptions) => {
const {
file,
data,
headers,
withCredentials,
action,
onFinish,
onError,
onProgress
} = options
nextTick(() => {
if (file.file) {
const ImageUrl = fileToUrl(file.file)
2022-03-04 20:57:36 +08:00
chartEditStore.setEditCanvasConfig(
2022-02-06 21:35:38 +08:00
EditCanvasConfigEnum.BACKGROUND_IAMGE,
ImageUrl
2022-02-06 21:35:38 +08:00
)
2022-03-04 20:57:36 +08:00
chartEditStore.setEditCanvasConfig(
EditCanvasConfigEnum.SELECT_COLOR,
false
)
} else {
window['$message'].error('添加图片失败,请稍后重试!')
}
2022-02-06 21:35:38 +08:00
})
}
2022-02-06 01:04:05 +08:00
</script>
<style lang="scss" scoped>
$updloadWidth: 326px;
$updloadHeight: 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;
width: $updloadWidth;
}
2022-02-06 21:35:38 +08:00
}
.upload-show {
width: -webkit-fill-available;
height: $updloadHeight;
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-02-22 15:32:57 +08:00
.tabs-box {
margin-top: 30px;
}
2022-02-06 01:04:05 +08:00
}
</style>