Commit 35a768c7e2a7d0d50b6477fcff2a9b16322f1bda

Authored by fengwotao
1 parent 3267ab2a

perf(src/packages): 小组件大标题新增图片

... ... @@ -3,10 +3,12 @@ import { CreateComponentType } from '@/packages/index.d'
3 3 import { Headline1Config } from './index'
4 4 import cloneDeep from 'lodash/cloneDeep'
5 5 import { chartInitConfig } from '@/settings/designSetting'
  6 +import headerBg08 from '@/assets/external/headbackground/headerBg08.png'
  7 +
6 8
7 9 export const option = {
8 10 dataset: '物联网平台数据统计',
9   - bgSrc: 'src/assets/external/headbackground/headerBg08.png',
  11 + bgSrc: headerBg08,
10 12 fontSize: 36,
11 13 showRight:true,
12 14 textColor:'#00f6ff',
... ...
... ... @@ -3,8 +3,12 @@
3 3 <setting-item-box name="背景上传" :alone="true">
4 4 <setting-item>
5 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 12 <n-upload-dragger>
9 13 <img v-if="optionData.backgroundImage" class="upload-show" :src="optionData.backgroundImage" alt="背景" />
10 14 <div class="upload-img" v-show="!optionData.backgroundImage">
... ... @@ -28,8 +32,17 @@
28 32 </setting-item-box>
29 33 <setting-item-box name="背景选择" :alone="true">
30 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 46 </setting-item>
34 47 </setting-item-box>
35 48 <setting-item-box name="文字" :alone="true">
... ... @@ -73,7 +86,11 @@
73 86 </setting-item-box>
74 87 <setting-item-box name="文字">
75 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 94 </setting-item>
78 95 <setting-item name="字体位置x轴">
79 96 <n-input-number v-model:value="optionData.xT" size="small" placeholder="字体位置"></n-input-number>
... ... @@ -96,10 +113,10 @@
96 113 </template>
97 114
98 115 <script setup lang="ts">
99   -import { PropType, ref, nextTick } from 'vue'
  116 +import { PropType, ref, nextTick, h, computed } from 'vue'
100 117 import { option } from './config'
101 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 120 import { backgroundImageSize } from '@/settings/designSetting'
104 121 import { uploadFile } from '@/api/external/contentSave/content'
105 122 import { FileTypeEnum } from '@/enums/fileTypeEnum'
... ... @@ -113,23 +130,47 @@ const props = defineProps({
113 130 })
114 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 171 const selectBgValueHandle = (value: string) => {
131 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 144 }
145 145
146 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 148 background-size: 100% 100%;
149 149 text-align: center;
150 150 font-size: 36px;
... ...