config.vue
12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<template>
<collapse-item name="基础" :expanded="true">
<setting-item-box name="弹窗label" :alone="true">
<setting-item>
<n-switch v-model:value="optionData.dialogCustomField" size="small"></n-switch>
</setting-item>
</setting-item-box>
<setting-item-box name="使用注意" :alone="true">
<n-gradient-text :size="14" type="success">弹窗字段里面配置的键值需要</n-gradient-text>
<n-gradient-text :size="14" type="success">和静态数据里的customField</n-gradient-text>
<n-gradient-text :size="14" type="success">对象里的键相对应</n-gradient-text>
</setting-item-box>
<setting-item-box v-if="optionData.dialogCustomField" name="弹窗字段" :alone="true">
<setting-item>
<template v-for="(item, index) in optionData.dialogConfigField" :key="index">
<setting-item-box name="键名" :alone="true">
<setting-item>
<n-input-group>
<n-input v-model:value="item.label" size="small" placeholder="请输入键名"></n-input>
</n-input-group>
</setting-item>
</setting-item-box>
<setting-item-box name="键值" :alone="true">
<setting-item>
<n-input-group>
<n-input v-model:value="item.value" size="small" placeholder="请输入键值"></n-input>
</n-input-group>
</setting-item>
</setting-item-box>
<setting-item-box :alone="true">
<setting-item>
<n-button size="small" @click="optionData.dialogConfigField.splice(index, 1)"> - </n-button>
</setting-item>
</setting-item-box>
</template>
<setting-item-box :alone="true">
<setting-item>
<n-button
v-if="optionData.dialogConfigField.length < 9"
size="small"
@click="
optionData.dialogConfigField.push({
label: '',
value: '',
realValue: ''
})
"
>
+
</n-button>
</setting-item>
</setting-item-box>
</setting-item>
</setting-item-box>
<setting-item-box name="语言类型" :alone="true">
<setting-item>
<n-select size="small" v-model:value="optionData.mapOptions.lang" :options="langOptions" />
</setting-item>
</setting-item-box>
<setting-item-box name="Key" :alone="true">
<setting-item name="请务必使用自己的高德应用 key">
<n-input v-model:value="optionData.mapOptions.amapKey" size="small"></n-input>
</setting-item>
</setting-item-box>
<setting-item-box name="自定义地图样式ID" :alone="true">
<setting-item>
<n-input size="small" v-model:value="optionData.mapOptions.amapStyleKeyCustom" />
</setting-item>
</setting-item-box>
</collapse-item>
<collapse-item name="地图" :expanded="true">
<setting-item-box name="主题">
<setting-item>
<n-select size="small" v-model:value="optionData.mapOptions.amapStyleKey" :options="themeOptions" />
</setting-item>
</setting-item-box>
<setting-item-box name="内容" :alone="true">
<n-checkbox-group v-model:value="optionData.mapOptions.features">
<n-space item-style="display: flex;">
<n-checkbox :value="item.value" :label="item.label" v-for="(item, index) in featuresOptions" :key="index" />
</n-space>
</n-checkbox-group>
</setting-item-box>
<setting-item-box name="位置">
<setting-item name="经度">
<n-input-number v-model:value="optionData.mapOptions.amapLon" :show-button="false" size="small">
<template #suffix>°</template>
</n-input-number>
</setting-item>
<setting-item name="纬度">
<n-input-number v-model:value="optionData.mapOptions.amapLat" :show-button="false" size="small">
<template #suffix>°</template>
</n-input-number>
</setting-item>
<setting-item name="初始缩放">
<n-input-number v-model:value="optionData.mapOptions.amapZindex" :min="0" size="small"></n-input-number>
</setting-item>
</setting-item-box>
<setting-item-box name="模式" :alone="true">
<setting-item>
<n-radio-group v-model:value="optionData.mapOptions.viewMode" name="radiogroup">
<n-space>
<n-radio v-for="song in viewModeOptions" :key="song.value" :value="song.value">
{{ song.label }}
</n-radio>
</n-space>
</n-radio-group>
</setting-item>
</setting-item-box>
<template v-if="optionData.mapOptions.viewMode === '3D'">
<setting-item-box>
<setting-item name="天空色">
<n-color-picker size="small" :modes="['hex']" v-model:value="optionData.mapOptions.skyColor"></n-color-picker>
</setting-item>
<setting-item name="俯仰角">
<n-input-number v-model:value="optionData.mapOptions.pitch" :min="0" :max="83" size="small"></n-input-number>
</setting-item>
</setting-item-box>
</template>
</collapse-item>
<collapse-item name="标记" :expanded="true">
<setting-item-box name="样式">
<setting-item name="类型">
<n-select size="small" v-model:value="optionData.mapOptions.mapMarkerType" :options="MarkerOptions" />
</setting-item>
<setting-item v-if="optionData.mapOptions.mapMarkerType === MarkerEnum.CIRCLE_MARKER" name="颜色">
<n-color-picker v-model:value="optionData.mapOptions.marker.fillColor" size="small"></n-color-picker>
</setting-item>
</setting-item-box>
<setting-item-box name="图标选择" v-if="optionData.mapOptions.mapMarkerType === MarkerEnum.MARKER">
<setting-item>
<NSelect
size="small"
placeholder="请选择您要使用的图标"
style="width: 250px"
:value="iconMarkerValue"
:options="iconMarkerOptions"
:render-label="renderOption"
clearable
filterable
@update:value="selectHandle"
/>
</setting-item>
</setting-item-box>
<setting-item-box name="弹窗选择" v-if="optionData.mapOptions.mapMarkerType === MarkerEnum.MARKER">
<setting-item>
<NSelect
size="small"
placeholder="请选择您要使用的弹窗"
style="width: 250px"
:value="mapSelectBorderValue"
:options="mapBorderOptions"
:render-label="renderMapBorderOption"
clearable
filterable
@update:value="selectMapBorderHandle"
/>
</setting-item>
</setting-item-box>
<setting-item-box name="弹窗背景" v-if="optionData.mapOptions.mapMarkerType === MarkerEnum.MARKER">
<div style="width: 10vw">
<n-color-picker :modes="['rgb']" v-model:value="optionData.mapOptions.bgColor" size="small"></n-color-picker>
</div>
</setting-item-box>
</collapse-item>
</template>
<script setup lang="ts">
import { PropType, ref, computed, h, onMounted } from 'vue'
import { option, MarkerEnum, ThemeEnum, LangEnum, ViewModeEnum, FeaturesEnum } from './config'
import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting'
import { NEllipsis, NImage, NSelect, NSpace, SelectOption } from 'naive-ui'
import { getUrlBase64 } from '@/utils/external/imageUrlToBase64'
interface BaseSelectBorderIF extends SelectOption {
config?: string
}
const props = defineProps({
optionData: {
type: Object as PropType<typeof option>,
required: true
}
})
const themeOptions = [
{
value: ThemeEnum.NORMAL,
label: '标准'
},
{
value: ThemeEnum.DARK,
label: '幻影黑'
},
{
value: ThemeEnum.LIGHT,
label: '月光银'
},
{
value: ThemeEnum.WHITES_MOKE,
label: '远山黛'
},
{
value: ThemeEnum.FRESH,
label: '草色青'
},
{
value: ThemeEnum.GREY,
label: '雅士灰'
},
{
value: ThemeEnum.GRAFFITI,
label: '涂鸦'
},
{
value: ThemeEnum.MACARON,
label: '马卡龙'
},
{
value: ThemeEnum.BLUE,
label: '靛青蓝'
},
{
value: ThemeEnum.DARKBLUE,
label: '极夜蓝'
},
{
value: ThemeEnum.WINE,
label: '酱籽'
},
{
value: ThemeEnum.WEIXIN,
label: '卫星'
}
]
const langOptions = [
{
value: LangEnum.ZH_CN,
label: '中文简体'
},
{
value: LangEnum.EN,
label: '英文'
},
{
value: LangEnum.ZH_EN,
label: '中英文对照'
}
]
const viewModeOptions = [
{
value: ViewModeEnum.PLANE,
label: '2D'
},
{
value: ViewModeEnum.STEREOSCOPIC,
label: '3D'
}
]
const featuresOptions = [
{
value: FeaturesEnum.BG,
label: '显示地图背景'
},
{
value: FeaturesEnum.POINT,
label: '显示标识'
},
{
value: FeaturesEnum.ROAD,
label: '显示道路'
},
{
value: FeaturesEnum.BUILDING,
label: '显示建筑'
}
]
const MarkerOptions = [
// {
// value: MarkerEnum.CIRCLE_MARKER,
// label: '圆形标点' //在地图里点击无效,所以注释,有需要自行打开即可
// },
{
value: MarkerEnum.MARKER,
label: '定位标点'
},
{
value: MarkerEnum.NONE,
label: '隐藏标点'
}
]
const iconMarkerValue = ref<string | null>('1.png')
const isHref = (url: string) => {
try {
new URL(url)
return true
} catch (error) {
return false
}
}
// import.meta.glob 这个不能封装,必须是字符串,不能通过传值传进去
const iconMarkerOptions = computed(() => {
const pathList = import.meta.glob('../../../../../../assets/external/marker/*')
return Object.keys(pathList).map(item => {
const imgName = item.split('/').at(-1)
return {
label: imgName,
value: imgName
} as SelectOption
})
})
//
const getMarkerImagePath = (name: string) => {
return isHref(name) ? name : new URL(`../../../../../../assets/external/marker/${name}`, import.meta.url).href
}
const renderOption = (option: SelectOption) => {
return h(NSpace, { justify: 'space-between', style: 'padding: 0 15px; height: 28px; line-height: 28px;' }, () => [
h(NImage, {
width: 25,
src: getMarkerImagePath(option.value as string),
previewDisabled: true,
style: { height: '25px' }
} as Recordable),
h(NEllipsis, null, () => option.label)
])
}
const selectHandle = (value: string) => {
iconMarkerValue.value = value
getUrlBase64(getMarkerImagePath(value), 'png', (baseEncodeText: string) => {
props.optionData.mapOptions.iconMarker = baseEncodeText
})
}
const mapSelectBorderValue = ref<string | null>('border01.png')
const needBorder = ['border01.png', 'border02.png', 'border03.png', 'border05.png', 'border07.png']
// import.meta.glob 这个不能封装,必须是字符串,不能通过传值传进去
const mapBorderOptions = computed(() => {
const pathList = import.meta.glob('../../../../../../assets/images/chart/decorates/*')
return Object.keys(pathList)
.map(item => {
const imgName = item.split('/').at(-1) as string
if (needBorder.includes(imgName)) {
return {
label: imgName,
value: imgName
} as SelectOption
}
})
.filter(Boolean) as SelectOption[]
})
//
const getMapBorderImagePath = (name: string) => {
return isHref(name) ? name : new URL(`../../../../../../assets/images/chart/decorates/${name}`, import.meta.url).href
}
const renderMapBorderOption = (option: SelectOption) => {
return h(NSpace, { justify: 'space-between', style: 'padding: 0 15px; height: 28px; line-height: 28px;' }, () => [
h(NImage, {
width: 25,
src: getMapBorderImagePath(option.value as string),
previewDisabled: true,
style: { height: '25px' }
} as Recordable),
h(NEllipsis, null, () => option.label)
])
}
const selectMapBorderHandle = (value: string) => {
mapSelectBorderValue.value = value
const toLowerValue = value.toLocaleLowerCase()
;(props.optionData.mapOptions.mpBorderConfig as BaseSelectBorderIF) = {
value: toLowerValue[0]?.toUpperCase() + toLowerValue?.substr(1)?.split('.')[0]
}
}
onMounted(() => {
getUrlBase64(getMarkerImagePath(props.optionData.mapOptions.iconMarker), 'png', (baseEncodeText: string) => {
props.optionData.mapOptions.iconMarker = baseEncodeText
})
mapSelectBorderValue.value = `${props.optionData.mapOptions.mpBorderConfig.value?.toLocaleLowerCase()}.png`
})
</script>