2022-01-08 21:01:52 +08:00
|
|
|
|
<template>
|
2022-03-19 23:28:33 +08:00
|
|
|
|
<div class="go-chart-configurations-data" v-if="targetData">
|
|
|
|
|
<setting-item-box name="请求方式" :alone="true">
|
2022-03-18 20:36:05 +08:00
|
|
|
|
<n-select
|
|
|
|
|
v-model:value="targetData.data.requestDataType"
|
2022-03-19 23:28:33 +08:00
|
|
|
|
:options="selectOptions"
|
|
|
|
|
@on-update="selectHandle"
|
2022-03-18 20:36:05 +08:00
|
|
|
|
/>
|
|
|
|
|
</setting-item-box>
|
|
|
|
|
<n-timeline>
|
2022-03-19 23:47:24 +08:00
|
|
|
|
<n-timeline-item type="info" :title="TimelineTitleEnum.MAPPING">
|
2022-03-18 20:36:05 +08:00
|
|
|
|
<n-table striped>
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
2022-03-19 23:28:33 +08:00
|
|
|
|
<th v-for="item in tableTitle" :key="item">{{ item }}</th>
|
2022-03-18 20:36:05 +08:00
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
2022-03-19 23:28:33 +08:00
|
|
|
|
<go-skeleton :repeat="3" :load="tableLoad" style="width: 300px;"></go-skeleton>
|
|
|
|
|
<tbody v-show="!tableLoad">
|
|
|
|
|
<tr v-for="(item, index) in getDimensionsAndSource" :key="index">
|
2022-03-18 20:36:05 +08:00
|
|
|
|
<td>{{ item.field }}</td>
|
|
|
|
|
<td>{{ item.mapping }}</td>
|
|
|
|
|
<td>
|
2022-03-19 23:28:33 +08:00
|
|
|
|
<n-space v-if="item.result === 0">
|
|
|
|
|
<n-badge dot type="success"></n-badge>
|
|
|
|
|
<n-text>无</n-text>
|
|
|
|
|
</n-space>
|
|
|
|
|
<n-space v-else>
|
|
|
|
|
<n-badge dot :type="item.result === 1 ? 'success' : 'error'"></n-badge>
|
|
|
|
|
<n-text>匹配{{ item.result === 1 ? '成功' : '失败' }}</n-text>
|
2022-03-18 20:36:05 +08:00
|
|
|
|
</n-space>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</n-table>
|
|
|
|
|
</n-timeline-item>
|
2022-03-19 23:47:24 +08:00
|
|
|
|
<n-timeline-item type="success" :title="TimelineTitleEnum.CONTENT">
|
2022-03-19 23:28:33 +08:00
|
|
|
|
<n-space vertical>
|
2022-03-20 18:11:26 +08:00
|
|
|
|
<n-text depth="3">数据需要符合 ECharts-setdata 规范</n-text>
|
2022-03-19 23:28:33 +08:00
|
|
|
|
<n-space class="source-btn-box">
|
|
|
|
|
<n-upload
|
|
|
|
|
v-model:file-list="uploadFileListRef"
|
|
|
|
|
:show-file-list="false"
|
|
|
|
|
:customRequest="customRequest"
|
|
|
|
|
@before-upload="beforeUpload"
|
|
|
|
|
>
|
2022-03-19 23:47:24 +08:00
|
|
|
|
<n-space>
|
|
|
|
|
<n-button class="sourceBtn-item">
|
|
|
|
|
<template #icon>
|
|
|
|
|
<n-icon>
|
|
|
|
|
<document-add-icon />
|
|
|
|
|
</n-icon>
|
|
|
|
|
</template>
|
|
|
|
|
导入(json / txt)
|
|
|
|
|
</n-button>
|
|
|
|
|
</n-space>
|
2022-03-19 23:28:33 +08:00
|
|
|
|
</n-upload>
|
|
|
|
|
<n-button class="sourceBtn-item" @click="download">
|
|
|
|
|
<template #icon>
|
|
|
|
|
<n-icon>
|
|
|
|
|
<document-download-icon />
|
|
|
|
|
</n-icon>
|
|
|
|
|
</template>
|
|
|
|
|
下载
|
|
|
|
|
</n-button>
|
|
|
|
|
</n-space>
|
|
|
|
|
<n-card>
|
|
|
|
|
<n-code :code="getSource" language="json"></n-code>
|
|
|
|
|
</n-card>
|
|
|
|
|
</n-space>
|
2022-03-18 20:36:05 +08:00
|
|
|
|
</n-timeline-item>
|
|
|
|
|
</n-timeline>
|
2022-01-08 21:01:52 +08:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2022-03-18 20:36:05 +08:00
|
|
|
|
<script setup lang="ts">
|
2022-03-19 23:47:24 +08:00
|
|
|
|
import { ref, computed, watch, nextTick } from 'vue'
|
2022-03-18 20:36:05 +08:00
|
|
|
|
import { SettingItemBox } from '@/components/ChartItemSetting/index'
|
|
|
|
|
import { RequestDataTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
|
|
|
|
import { useTargetData } from '../hooks/useTargetData.hook'
|
2022-03-19 23:28:33 +08:00
|
|
|
|
import { UploadCustomRequestOptions } from 'naive-ui'
|
|
|
|
|
import { FileTypeEnum } from '@/enums/fileTypeEnum'
|
|
|
|
|
import { readFile, downloadFile } from '@/utils'
|
2022-03-19 23:47:24 +08:00
|
|
|
|
import { DataResultEnum, TimelineTitleEnum, SelcetOptionsLableEnum, SelectOptionsType } from './index.d'
|
2022-03-19 23:28:33 +08:00
|
|
|
|
import { icon } from '@/plugins'
|
2022-01-08 21:01:52 +08:00
|
|
|
|
|
2022-03-19 23:28:33 +08:00
|
|
|
|
const { DocumentAddIcon, DocumentDownloadIcon } = icon.carbon
|
2022-03-18 20:36:05 +08:00
|
|
|
|
|
2022-03-19 23:28:33 +08:00
|
|
|
|
const uploadFileListRef = ref()
|
|
|
|
|
const { targetData } = useTargetData()
|
|
|
|
|
const source = ref()
|
|
|
|
|
const dimensions = ref()
|
2022-03-18 20:36:05 +08:00
|
|
|
|
|
2022-03-19 23:28:33 +08:00
|
|
|
|
// 表格标题
|
|
|
|
|
const tableTitle = ['字段', '映射', '状态']
|
|
|
|
|
// 选项
|
|
|
|
|
const selectOptions: SelectOptionsType[] = [
|
2022-03-18 20:36:05 +08:00
|
|
|
|
{
|
2022-03-19 23:28:33 +08:00
|
|
|
|
label: SelcetOptionsLableEnum.STATIC,
|
2022-03-18 20:36:05 +08:00
|
|
|
|
value: RequestDataTypeEnum.STATIC
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-03-19 23:28:33 +08:00
|
|
|
|
label: SelcetOptionsLableEnum.AJAX,
|
|
|
|
|
value: RequestDataTypeEnum.AJAX,
|
|
|
|
|
disabled: true,
|
2022-03-18 20:36:05 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
2022-03-19 23:28:33 +08:00
|
|
|
|
// 获取数据
|
|
|
|
|
const getSource = computed(() => {
|
|
|
|
|
return JSON.stringify(source.value)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
watch(() => targetData.value?.option?.dataset, (newData) => {
|
|
|
|
|
if (newData) {
|
|
|
|
|
source.value = newData.source
|
|
|
|
|
dimensions.value = newData.dimensions
|
2022-03-18 20:36:05 +08:00
|
|
|
|
}
|
2022-03-19 23:28:33 +08:00
|
|
|
|
}, {
|
|
|
|
|
immediate: true
|
|
|
|
|
})
|
2022-03-18 20:36:05 +08:00
|
|
|
|
|
2022-03-19 23:28:33 +08:00
|
|
|
|
// 处理映射列表状态结果
|
|
|
|
|
const matchingHandle = (mapping: string) => {
|
|
|
|
|
for (let i = 0; i < source.value.length; i++) {
|
|
|
|
|
let res = DataResultEnum.FAILURE
|
|
|
|
|
if (source.value[i][mapping] !== undefined) {
|
|
|
|
|
return DataResultEnum.SUCCESS
|
|
|
|
|
}
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
return DataResultEnum.SUCCESS
|
|
|
|
|
}
|
|
|
|
|
// 处理映射列表
|
|
|
|
|
const getDimensionsAndSource = computed(() => {
|
|
|
|
|
// 去除首项数据轴标识
|
|
|
|
|
return dimensions.value.map((item: string, index: number) => {
|
|
|
|
|
return index === 0 ?
|
|
|
|
|
{
|
|
|
|
|
// 字段
|
|
|
|
|
field: '通用标识',
|
|
|
|
|
// 映射
|
|
|
|
|
mapping: item,
|
|
|
|
|
// 结果
|
|
|
|
|
result: DataResultEnum.NULL
|
|
|
|
|
} : {
|
|
|
|
|
field: `数据项-${index}`,
|
|
|
|
|
mapping: item,
|
|
|
|
|
result: matchingHandle(item)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 表格数据加载
|
|
|
|
|
const tableLoad = computed(() => {
|
|
|
|
|
return !getDimensionsAndSource.value || getDimensionsAndSource.value.length === 0
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 选择方式
|
|
|
|
|
const selectHandle = () => { }
|
|
|
|
|
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const beforeUpload = ({ file }) => {
|
|
|
|
|
uploadFileListRef.value = []
|
|
|
|
|
const type = file.file.type
|
|
|
|
|
if (type !== FileTypeEnum.JSON && type !== FileTypeEnum.TXT) {
|
|
|
|
|
window['$message'].warning('仅支持上传 【JSON】 格式文件,请重新上传!')
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 自定义上传操作
|
|
|
|
|
const customRequest = (options: UploadCustomRequestOptions) => {
|
|
|
|
|
const { file } = options
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
if (file.file) {
|
|
|
|
|
readFile(file.file).then((fileData: any) => {
|
|
|
|
|
targetData.value.option.dataset = JSON.parse(fileData)
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
window['$message'].error('导入数据失败,请稍后重试或联系管理员!')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 下载文件
|
|
|
|
|
const download = () => {
|
2022-03-20 16:13:33 +08:00
|
|
|
|
try {
|
|
|
|
|
window['$message'].success('正在下载文件!')
|
|
|
|
|
downloadFile(JSON.stringify(targetData.value?.option?.dataset), undefined, 'json')
|
|
|
|
|
} catch (error) {
|
|
|
|
|
window['$message'].success('下载失败,数据错误!')
|
|
|
|
|
}
|
2022-03-18 20:36:05 +08:00
|
|
|
|
}
|
2022-01-08 21:01:52 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
2022-03-19 23:28:33 +08:00
|
|
|
|
<style>
|
|
|
|
|
</style>
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
@include go("chart-configurations-data") {
|
|
|
|
|
@include deep() {
|
|
|
|
|
pre {
|
|
|
|
|
white-space: pre-wrap;
|
|
|
|
|
word-wrap: break-word;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.source-btn-box {
|
|
|
|
|
margin-top: 10px !important;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|