Showing
14 changed files
with
63 additions
and
20 deletions
114 KB
89.5 KB
65.5 KB
76.6 KB
90.2 KB
39.9 KB
121 KB
17.6 KB
280 KB
68.1 KB
40.1 KB
@@ -3,10 +3,12 @@ import { CreateComponentType } from '@/packages/index.d' | @@ -3,10 +3,12 @@ import { CreateComponentType } from '@/packages/index.d' | ||
3 | import { Headline1Config } from './index' | 3 | import { Headline1Config } from './index' |
4 | import cloneDeep from 'lodash/cloneDeep' | 4 | import cloneDeep from 'lodash/cloneDeep' |
5 | import { chartInitConfig } from '@/settings/designSetting' | 5 | import { chartInitConfig } from '@/settings/designSetting' |
6 | +import headerBg08 from '@/assets/external/headbackground/headerBg08.png' | ||
7 | + | ||
6 | 8 | ||
7 | export const option = { | 9 | export const option = { |
8 | dataset: '物联网平台数据统计', | 10 | dataset: '物联网平台数据统计', |
9 | - bgSrc: 'src/assets/external/headbackground/headerBg08.png', | 11 | + bgSrc: headerBg08, |
10 | fontSize: 36, | 12 | fontSize: 36, |
11 | showRight:true, | 13 | showRight:true, |
12 | textColor:'#00f6ff', | 14 | textColor:'#00f6ff', |
@@ -3,8 +3,12 @@ | @@ -3,8 +3,12 @@ | ||
3 | <setting-item-box name="背景上传" :alone="true"> | 3 | <setting-item-box name="背景上传" :alone="true"> |
4 | <setting-item> | 4 | <setting-item> |
5 | <n-card class="upload-box"> | 5 | <n-card class="upload-box"> |
6 | - <n-upload :show-file-list="false" v-model:file-list="uploadFileListRef" :customRequest="customRequest" | ||
7 | - :onBeforeUpload="beforeUploadHandle"> | 6 | + <n-upload |
7 | + :show-file-list="false" | ||
8 | + v-model:file-list="uploadFileListRef" | ||
9 | + :customRequest="customRequest" | ||
10 | + :onBeforeUpload="beforeUploadHandle" | ||
11 | + > | ||
8 | <n-upload-dragger> | 12 | <n-upload-dragger> |
9 | <img v-if="optionData.backgroundImage" class="upload-show" :src="optionData.backgroundImage" alt="背景" /> | 13 | <img v-if="optionData.backgroundImage" class="upload-show" :src="optionData.backgroundImage" alt="背景" /> |
10 | <div class="upload-img" v-show="!optionData.backgroundImage"> | 14 | <div class="upload-img" v-show="!optionData.backgroundImage"> |
@@ -28,8 +32,17 @@ | @@ -28,8 +32,17 @@ | ||
28 | </setting-item-box> | 32 | </setting-item-box> |
29 | <setting-item-box name="背景选择" :alone="true"> | 33 | <setting-item-box name="背景选择" :alone="true"> |
30 | <setting-item> | 34 | <setting-item> |
31 | - <n-select size="small" placeholder="请选择您要使用的背景" style="width: 250px" v-model:value="selectValue" | ||
32 | - :options="selectBgOptions" @update:value="selectBgValueHandle" /> | 35 | + <NSelect |
36 | + size="small" | ||
37 | + placeholder="请选择您要使用的背景" | ||
38 | + style="width: 250px" | ||
39 | + :value="selectValue" | ||
40 | + :options="getAllBackgroundImageList" | ||
41 | + :render-label="renderOption" | ||
42 | + clearable | ||
43 | + filterable | ||
44 | + @update:value="selectBgValueHandle" | ||
45 | + /> | ||
33 | </setting-item> | 46 | </setting-item> |
34 | </setting-item-box> | 47 | </setting-item-box> |
35 | <setting-item-box name="文字" :alone="true"> | 48 | <setting-item-box name="文字" :alone="true"> |
@@ -73,7 +86,11 @@ | @@ -73,7 +86,11 @@ | ||
73 | </setting-item-box> | 86 | </setting-item-box> |
74 | <setting-item-box name="文字"> | 87 | <setting-item-box name="文字"> |
75 | <setting-item name="字体大小"> | 88 | <setting-item name="字体大小"> |
76 | - <n-input-number v-model:value="optionData.textRightFontSize" size="small" placeholder="字体大小"></n-input-number> | 89 | + <n-input-number |
90 | + v-model:value="optionData.textRightFontSize" | ||
91 | + size="small" | ||
92 | + placeholder="字体大小" | ||
93 | + ></n-input-number> | ||
77 | </setting-item> | 94 | </setting-item> |
78 | <setting-item name="字体位置x轴"> | 95 | <setting-item name="字体位置x轴"> |
79 | <n-input-number v-model:value="optionData.xT" size="small" placeholder="字体位置"></n-input-number> | 96 | <n-input-number v-model:value="optionData.xT" size="small" placeholder="字体位置"></n-input-number> |
@@ -96,10 +113,10 @@ | @@ -96,10 +113,10 @@ | ||
96 | </template> | 113 | </template> |
97 | 114 | ||
98 | <script setup lang="ts"> | 115 | <script setup lang="ts"> |
99 | -import { PropType, ref, nextTick } from 'vue' | 116 | +import { PropType, ref, nextTick, h, computed } from 'vue' |
100 | import { option } from './config' | 117 | import { option } from './config' |
101 | import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting' | 118 | import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting' |
102 | -import { SelectOption, UploadCustomRequestOptions } from 'naive-ui' | 119 | +import { NEllipsis, NImage, NSelect, NSpace, SelectOption, UploadCustomRequestOptions } from 'naive-ui' |
103 | import { backgroundImageSize } from '@/settings/designSetting' | 120 | import { backgroundImageSize } from '@/settings/designSetting' |
104 | import { uploadFile } from '@/api/external/contentSave/content' | 121 | import { uploadFile } from '@/api/external/contentSave/content' |
105 | import { FileTypeEnum } from '@/enums/fileTypeEnum' | 122 | import { FileTypeEnum } from '@/enums/fileTypeEnum' |
@@ -113,23 +130,47 @@ const props = defineProps({ | @@ -113,23 +130,47 @@ const props = defineProps({ | ||
113 | }) | 130 | }) |
114 | const uploadFileListRef = ref() | 131 | const uploadFileListRef = ref() |
115 | 132 | ||
116 | -const selectBgOptions = ref<Array<SelectOption>>([]) | 133 | +const selectValue = ref('headerBg08.png') |
117 | 134 | ||
118 | -const selectValue = ref('headerBg08') | 135 | +const getAllBackgroundImageList = computed(() => { |
136 | + const pathList = import.meta.glob('../../../../../../assets/external/headbackground/*') | ||
137 | + return Object.keys(pathList).map(item => { | ||
138 | + const imgName = item.split('/').at(-1) | ||
139 | + return { | ||
140 | + label: imgName, | ||
141 | + value: imgName | ||
142 | + } as SelectOption | ||
143 | + }) | ||
144 | +}) | ||
145 | + | ||
146 | +const renderOption = (option: SelectOption) => { | ||
147 | + return h(NSpace, { justify: 'space-between', style: 'padding: 0 15px; height: 28px; line-height: 28px;' }, () => [ | ||
148 | + h(NImage, { | ||
149 | + width: 50, | ||
150 | + src: getBackgroundImagePath(option.value as string), | ||
151 | + previewDisabled: true, | ||
152 | + style: { height: '28px' } | ||
153 | + } as Recordable), | ||
154 | + h(NEllipsis, null, () => option.label) | ||
155 | + ]) | ||
156 | +} | ||
157 | + | ||
158 | +const isHref = (url: string) => { | ||
159 | + try { | ||
160 | + new URL(url) | ||
161 | + return true | ||
162 | + } catch (error) { | ||
163 | + return false | ||
164 | + } | ||
165 | +} | ||
119 | 166 | ||
120 | -// TODO待封装 成传文件夹名字获取下面所有图片 | ||
121 | -const getFetchImages = () => { | ||
122 | - const imagesModules: Record<string, { default: string }> = import.meta.glob('@/assets/external/headbackground/*', { eager: true }) | ||
123 | - selectBgOptions.value = Object.keys(imagesModules).map(item => ({ | ||
124 | - label: imagesModules[item]?.default.split('/').at(-1), | ||
125 | - value: imagesModules[item]?.default | ||
126 | - })) | 167 | +const getBackgroundImagePath = (name: string) => { |
168 | + return isHref(name) ? name : new URL(`../../../../../../assets/external/headbackground/${name}`, import.meta.url).href | ||
127 | } | 169 | } |
128 | -getFetchImages() | ||
129 | 170 | ||
130 | const selectBgValueHandle = (value: string) => { | 171 | const selectBgValueHandle = (value: string) => { |
131 | selectValue.value = value | 172 | selectValue.value = value |
132 | - props.optionData.bgSrc = value | 173 | + props.optionData.bgSrc = getBackgroundImagePath(value) |
133 | } | 174 | } |
134 | 175 | ||
135 | // 上传图片前置处理 | 176 | // 上传图片前置处理 |
@@ -144,7 +144,7 @@ onUnmounted(() => { | @@ -144,7 +144,7 @@ onUnmounted(() => { | ||
144 | } | 144 | } |
145 | 145 | ||
146 | .go-n-grid { | 146 | .go-n-grid { |
147 | - background: url(@/assets/external/headbackground/headerBg08.png) center no-repeat; | 147 | + // background: url(@/assets/external/headbackground/headerBg08.png) center no-repeat; |
148 | background-size: 100% 100%; | 148 | background-size: 100% 100%; |
149 | text-align: center; | 149 | text-align: center; |
150 | font-size: 36px; | 150 | font-size: 36px; |