config.vue
5.89 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
<template>
<collapse-item name="三维配置" :expanded="true">
<setting-item-box name="文件上传" :alone="true">
<setting-item :name="fileSizeMsg">
<n-upload
:max="1"
:customRequest="customRequest"
:onBeforeUpload="beforeUploadHandle"
:default-file-list="defaultFileList"
>
<n-button> 上传文件</n-button>
</n-upload>
</setting-item>
</setting-item-box>
<setting-item-box name="静态路径">
<setting-item>
<n-select
@change="handlePathChange"
style="width: 12vw"
v-model:value="optionData.dataset"
size="small"
:options="pathList"
:render-label="renderOption"
></n-select>
</setting-item>
</setting-item-box>
<setting-item-box name="属性配置">
<setting-item name="场景色(需要这种格式HEX #000000,否则失效)">
<n-color-picker size="small" :show-alpha="false" v-model:value="optionData.backgroundColor"></n-color-picker>
</setting-item>
<SettingItem name="场景透明度">
<n-input-number :min="0" :max="1" v-model:value="optionData.backgroundAlpha" />
</SettingItem>
<SettingItem name="启用阻尼">
<n-switch v-model:value="optionData.enableDamping" size="small" />
</SettingItem>
<SettingItem v-if="optionData.enableDamping" name="阻尼值">
<n-input-number v-model:value="optionData.dampingFactor" :min="0" :max="1" size="small"></n-input-number>
</SettingItem>
<SettingItem name="启用动画">
<n-switch v-model:value="optionData.autoPlay" size="small" />
</SettingItem>
<SettingItem name="输出编码">
<n-select v-model:value="optionData.outputEncoding" size="small" :options="encodinghList"></n-select>
</SettingItem>
<SettingItem name="是否清空场景">
<n-switch @change="handleChange" v-model:value="optionData.clearScene" size="small" />
</SettingItem>
</setting-item-box>
</collapse-item>
</template>
<script setup lang="ts">
import { PropType, h, ref, nextTick } from 'vue'
import { option } from './config'
import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting'
import { NEllipsis, NInputNumber, NSelect, NSpace, SelectOption, NCard } from 'naive-ui'
import { uploadFile } from '@/api/external/contentSave/content'
import { downloadFile } from '@/api/external/common'
import { UploadCustomRequestOptions } from 'naive-ui'
const props = defineProps({
optionData: {
type: Object as PropType<typeof option>,
required: true
}
})
const defaultFileList = ref([])
//文件限制大小
const fileSizeConst = ref(15)
const handleChange = (e: boolean) => {
if (e) props.optionData.dataset = ''
}
const handlePathChange = () => {
props.optionData.clearScene = false
}
const encodinghList = [
{ label: 'linear', value: 'linear' },
{ label: 'sRGB ', value: 'sRGB ' }
]
const pathList = [
{
label: '猫模型',
value: 'src/assets/external/models/fbx/cat.fbx',
type: 'fbx'
},
{
label: '枪拖把模型',
value: 'src/assets/external/models/gltf/Sniper_Stand.glb',
type: 'gltf'
},
{
label: '飞机模型',
value: 'src/assets/external/models/obj/11803_Airplane_v1_l1.obj',
type: 'obj'
},
{
label: '踏月桥模型',
value: 'src/assets/external/models/stl/踏月桥.stl',
type: 'stl'
},
{
label: '龙模型',
value: 'src/assets/external/models/collada/Dragon 2.5_dae.dae',
type: 'dae'
},
{
label: '战斗机模型',
value: 'src/assets/external/models/ply/Intergalactic_Spaceship-(Ply).ply',
type: 'ply'
},
{
label: '正方体模型',
value: 'src/assets/external/models/json/lightmap.json',
type: 'json'
}
]
/**
* 三维文件格式,vue-3d-loader是这个插件支持的格式,其他格式待解决
*/
const threeSupportFileFormat = ['fbx', 'obj', 'gltf', 'stl', 'dae', 'glb', 'ply', 'json']
const renderOption = (option: SelectOption) => {
const threeSupportType = threeSupportFileFormat.find(item => item === option.type)
return h(NSpace, { justify: 'space-between', style: 'padding: 0 15px; height: 28px; line-height: 28px;' }, () => [
h(NEllipsis, null, () => threeSupportType),
h(NEllipsis, null, () => option.label)
])
}
const fileSizeMsg = ref(`文件需小于 ${fileSizeConst.value}M ,格式为${threeSupportFileFormat.join(',')}的文件`)
const extname = (filename: string) => {
if (!filename || typeof filename != 'string') {
return false
}
let a = filename.split('').reverse().join('')
let b = a.substring(0, a.search(/\./)).split('').reverse().join('')
return b
}
// 上传图片前置处理
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
const beforeUploadHandle = async ({ file }) => {
defaultFileList.value = []
const type = extname(file.file.name) as string
const size = file.file.size
if (size / (1024 * 1024) > fileSizeConst.value) {
window['$message'].warning(`文件超出 ${fileSizeConst.value}M限制,请重新上传!`)
return false
}
if (!threeSupportFileFormat.includes(type)) {
window['$message'].warning('文件格式不符合,请重新上传!')
return false
}
return true
}
// 自定义上传操作
const customRequest = (options: UploadCustomRequestOptions) => {
const { file } = options
nextTick(async () => {
if (file.file) {
const formData = new FormData()
formData.append('file', file.file)
const uploadRes = await uploadFile(formData)
if (uploadRes) {
props.optionData.dataset = uploadRes?.fileStaticUri
const res = await downloadFile(uploadRes?.fileName)
console.log(res)
window['$message'].success('上传文件成功!')
}
} else {
window['$message'].error('上传文件失败,请稍后重试!')
}
})
}
</script>
<style lang="scss" scoped></style>