fix: file upload key loss #120

This commit is contained in:
vben
2020-12-08 22:18:20 +08:00
parent bae53f3e2c
commit 29461a8568
14 changed files with 29 additions and 12 deletions

View File

@@ -1,10 +1,9 @@
import { UploadApiResult } from './model/uploadModel';
import { defHttp } from '/@/utils/http/axios';
import { UploadFileParams } from '/@/utils/http/axios/types';
import { useGlobSetting } from '/@/hooks/setting';
enum Api {
UPLOAD_URL = '/upload',
}
const { uploadUrl = '' } = useGlobSetting();
/**
* @description: Upload interface
@@ -15,7 +14,7 @@ export function uploadApi(
) {
return defHttp.uploadFile<UploadApiResult>(
{
url: Api.UPLOAD_URL,
url: uploadUrl,
onUploadProgress,
},
params

View File

@@ -31,6 +31,7 @@ export function jsonToSheetXlsx<T = any>({
writeFile(workbook, filename, write2excelOpts);
/* at this point, out.xlsb will have been downloaded */
}
export function aoaToSheetXlsx<T = any>({
data,
header,

View File

@@ -17,7 +17,7 @@
import type { ExcelData } from './types';
export default defineComponent({
name: 'ImportExcel',
emits: ['success'],
emits: ['success', 'error'],
setup(_, { emit }) {
const inputRef = ref<HTMLInputElement | null>(null);
const loadingRef = ref<Boolean>(false);
@@ -82,6 +82,7 @@
resolve('');
} catch (error) {
reject(error);
emit('error');
} finally {
loadingRef.value = false;
}

View File

@@ -17,6 +17,7 @@ export interface JsonToSheet<T = any> {
json2sheetOpts?: JSON2SheetOpts;
write2excelOpts?: WritingOptions;
}
export interface AoAToSheet<T = any> {
data: T[][];
header?: T[];

View File

@@ -93,7 +93,6 @@ export type ComponentType =
| 'SelectOption'
| 'TreeSelect'
| 'Transfer'
// | 'Radio'
| 'RadioButtonGroup'
| 'RadioGroup'
| 'Checkbox'

View File

@@ -190,6 +190,7 @@ export default defineComponent({
const { appendClass } = props;
const isAppendActiveCls =
appendClass && level === 1 && menu.path === unref(currentParentPath);
const levelCls = [
`${prefixCls}-item__level${level}`,
` ${menuState.theme} `,

View File

@@ -38,9 +38,9 @@ export default defineComponent({
</tr>
</thead>
<tbody>
{dataSource.map((record = {}) => {
{dataSource.map((record = {}, index) => {
return (
<tr class="file-table-tr" key={record.uuid}>
<tr class="file-table-tr" key={`${index + record.name || ''}`}>
{columnList.map((item) => {
const { dataIndex = '', customRender, align = 'center' } = item;
const render = customRender && isFunction(customRender);

View File

@@ -18,6 +18,7 @@ const {
VITE_GLOB_API_URL,
VITE_GLOB_APP_SHORT_NAME,
VITE_GLOB_API_URL_PREFIX,
VITE_GLOB_UPLOAD_URL,
} = ENV;
if (!reg.test(VITE_GLOB_APP_SHORT_NAME)) {
@@ -33,6 +34,7 @@ export const useGlobSetting = (): Readonly<GlobConfig> => {
apiUrl: VITE_GLOB_API_URL,
shortName: VITE_GLOB_APP_SHORT_NAME,
urlPrefix: VITE_GLOB_API_URL_PREFIX,
uploadUrl: VITE_GLOB_UPLOAD_URL,
};
return glob as Readonly<GlobConfig>;
};

View File

@@ -129,6 +129,7 @@ export interface GlobConfig {
title: string;
// 项目路径
apiUrl: string;
uploadUrl?: string;
urlPrefix?: string;
shortName: string;
}
@@ -139,6 +140,7 @@ export interface GlobEnvConfig {
VITE_GLOB_API_URL: string;
VITE_GLOB_API_URL_PREFIX?: string;
VITE_GLOB_APP_SHORT_NAME: string;
VITE_GLOB_UPLOAD_URL?: string;
}
interface GlobWrap {

View File

@@ -11,11 +11,11 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { BasicTable } from '/@/components/Table';
import { aoaToSheetXlsx, ExportExcelModel } from '/@/components/Excel';
import { aoaToSheetXlsx } from '/@/components/Excel';
import { arrHeader, arrData, columns, data } from './data';
export default defineComponent({
components: { BasicTable, ExportExcelModel },
components: { BasicTable },
setup() {
function aoaToExcel() {
// 保证data顺序与header一致

View File

@@ -12,11 +12,11 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { BasicTable } from '/@/components/Table';
import { jsonToSheetXlsx, ExportExcelModel } from '/@/components/Excel';
import { jsonToSheetXlsx } from '/@/components/Excel';
import { columns, data } from './data';
export default defineComponent({
components: { BasicTable, ExportExcelModel },
components: { BasicTable },
setup() {
function defaultHeader() {
// 默认Object.keys(data[0])作为header
@@ -25,6 +25,7 @@
filename: '使用key作为默认头部.xlsx',
});
}
function customHeader() {
jsonToSheetXlsx({
data,