mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 13:09:19 +08:00
fix: 修复导入文件编码检测及上传区域样式
This commit is contained in:
@@ -4,10 +4,64 @@ import { h } from 'vue';
|
||||
|
||||
import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table';
|
||||
|
||||
import { Button, Image } from 'ant-design-vue';
|
||||
import { Button, Image, Select, TreeSelect } from 'ant-design-vue';
|
||||
import { CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons-vue';
|
||||
|
||||
import { useVbenForm } from './form';
|
||||
|
||||
function createArrowHandlers(
|
||||
getData: () => any[],
|
||||
getIdx: (data: any[]) => number,
|
||||
colField: string,
|
||||
sourceRow: any,
|
||||
) {
|
||||
let timer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const copyTo = (targetRow: any) => {
|
||||
if (targetRow) targetRow[colField] = sourceRow[colField];
|
||||
};
|
||||
|
||||
const copyRange = (from: number, to: number, data: any[]) => {
|
||||
for (let i = from; i < to; i++) {
|
||||
copyTo(data[i]);
|
||||
}
|
||||
};
|
||||
|
||||
const withData = (fn: (data: any[], idx: number) => void) => {
|
||||
const data = getData();
|
||||
const idx = getIdx(data);
|
||||
fn(data, idx);
|
||||
};
|
||||
|
||||
const singleUp = () => {
|
||||
if (timer) { clearTimeout(timer); timer = null; }
|
||||
timer = setTimeout(() => {
|
||||
withData((data, idx) => { if (idx > 0) copyTo(data[idx - 1]); });
|
||||
timer = null;
|
||||
}, 200);
|
||||
};
|
||||
|
||||
const dblUp = () => {
|
||||
if (timer) { clearTimeout(timer); timer = null; }
|
||||
withData((data, idx) => { if (idx > 0) copyRange(0, idx, data); });
|
||||
};
|
||||
|
||||
const singleDown = () => {
|
||||
if (timer) { clearTimeout(timer); timer = null; }
|
||||
timer = setTimeout(() => {
|
||||
withData((data, idx) => { if (idx >= 0 && idx < data.length - 1) copyTo(data[idx + 1]); });
|
||||
timer = null;
|
||||
}, 200);
|
||||
};
|
||||
|
||||
const dblDown = () => {
|
||||
if (timer) { clearTimeout(timer); timer = null; }
|
||||
withData((data, idx) => { if (idx < data.length - 1) copyRange(idx + 1, data.length, data); });
|
||||
};
|
||||
|
||||
return { singleUp, dblUp, singleDown, dblDown };
|
||||
}
|
||||
|
||||
setupVbenVxeTable({
|
||||
configVxeTable: (vxeUI) => {
|
||||
vxeUI.setConfig({
|
||||
@@ -19,7 +73,6 @@ setupVbenVxeTable({
|
||||
},
|
||||
minHeight: 180,
|
||||
formConfig: {
|
||||
// 全局禁用vxe-table的表单配置,使用formOptions
|
||||
enabled: false,
|
||||
},
|
||||
proxyConfig: {
|
||||
@@ -38,7 +91,6 @@ setupVbenVxeTable({
|
||||
} as VxeTableGridOptions,
|
||||
});
|
||||
|
||||
// 表格配置项可以用 cellRender: { name: 'CellImage' },
|
||||
vxeUI.renderer.add('CellImage', {
|
||||
renderTableDefault(_renderOpts, params) {
|
||||
const { column, row } = params;
|
||||
@@ -46,20 +98,107 @@ setupVbenVxeTable({
|
||||
},
|
||||
});
|
||||
|
||||
// 表格配置项可以用 cellRender: { name: 'CellLink' },
|
||||
vxeUI.renderer.add('CellLink', {
|
||||
renderTableDefault(renderOpts) {
|
||||
const { props } = renderOpts;
|
||||
return h(
|
||||
Button,
|
||||
{ size: 'small', type: 'link' },
|
||||
{ default: () => props?.text },
|
||||
);
|
||||
return h(Button, { size: 'small', type: 'link' }, { default: () => props?.text });
|
||||
},
|
||||
});
|
||||
|
||||
// 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化
|
||||
// vxeUI.formats.add
|
||||
function sharedGetData($table: any, $grid: any): any[] {
|
||||
return ($grid as any)?.getTableData?.()?.fullData
|
||||
|| ($table as any)?.getTableData?.()?.fullData
|
||||
|| ($table as any)?.tableData
|
||||
|| [];
|
||||
}
|
||||
|
||||
function sharedGetIdx(data: any[], row: any): number {
|
||||
const srcIdx = (row as any).__srcRowIndex;
|
||||
return typeof srcIdx === 'number'
|
||||
? data.findIndex((r: any) => r.__srcRowIndex === srcIdx)
|
||||
: data.indexOf(row);
|
||||
}
|
||||
|
||||
vxeUI.renderer.add('CellSelect', {
|
||||
renderTableDefault(renderOpts, params) {
|
||||
const { props } = renderOpts;
|
||||
const { row, column, $table, $grid } = params;
|
||||
const getData = () => sharedGetData($table, $grid);
|
||||
const getIdx = (data: any[]) => sharedGetIdx(data, row);
|
||||
const { singleUp, dblUp, singleDown, dblDown } = createArrowHandlers(getData, getIdx, column.field, row);
|
||||
const allOptions: any[] = props?.options || [];
|
||||
const filterField = props?.filterByRowField as string | undefined;
|
||||
const filterKey = props?.filterOptionKey as string | undefined;
|
||||
const rowFilterVal = filterField ? row[filterField] : undefined;
|
||||
const displayOptions = filterField && rowFilterVal && filterKey
|
||||
? allOptions.filter((opt: any) => String(opt[filterKey]) === String(rowFilterVal))
|
||||
: allOptions;
|
||||
return h('div', { style: 'display: flex; align-items: center; gap: 2px;' }, [
|
||||
h(Select, {
|
||||
value: row[column.field] ?? undefined,
|
||||
'onUpdate:value': (val: any) => { row[column.field] = val; },
|
||||
options: displayOptions,
|
||||
allowClear: props?.allowClear ?? true,
|
||||
placeholder: props?.placeholder || '',
|
||||
showSearch: props?.showSearch ?? false,
|
||||
filterOption: props?.filterOption,
|
||||
style: 'flex: 1; min-width: 0;',
|
||||
size: 'small',
|
||||
}),
|
||||
h('div', { style: 'display: flex; flex-direction: column; gap: 0; flex-shrink: 0; width: 18px;' }, [
|
||||
h(Button, {
|
||||
size: 'small', type: 'text',
|
||||
onClick: singleUp, onDblclick: dblUp,
|
||||
title: '单击复制上一行,双击复制上面全部',
|
||||
style: 'padding: 0; height: 11px; width: 18px; line-height: 11px; font-size: 8px; border-radius: 2px 2px 0 0; min-width: 0;',
|
||||
}, { default: () => h(CaretUpOutlined) }),
|
||||
h(Button, {
|
||||
size: 'small', type: 'text',
|
||||
onClick: singleDown, onDblclick: dblDown,
|
||||
title: '单击复制下一行,双击复制下面全部',
|
||||
style: 'padding: 0; height: 11px; width: 18px; line-height: 11px; font-size: 8px; border-radius: 0 0 2px 2px; min-width: 0;',
|
||||
}, { default: () => h(CaretDownOutlined) }),
|
||||
]),
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
vxeUI.renderer.add('CellTreeSelect', {
|
||||
renderTableDefault(renderOpts, params) {
|
||||
const { props } = renderOpts;
|
||||
const { row, column, $table, $grid } = params;
|
||||
const getData = () => sharedGetData($table, $grid);
|
||||
const getIdx = (data: any[]) => sharedGetIdx(data, row);
|
||||
const { singleUp, dblUp, singleDown, dblDown } = createArrowHandlers(getData, getIdx, column.field, row);
|
||||
return h('div', { style: 'display: flex; align-items: center; gap: 2px;' }, [
|
||||
h(TreeSelect, {
|
||||
value: row[column.field] ?? undefined,
|
||||
'onUpdate:value': (val: any) => { row[column.field] = val; },
|
||||
treeData: props?.treeData || [],
|
||||
fieldNames: props?.fieldNames || { label: 'name', value: 'id', children: 'children' },
|
||||
allowClear: props?.allowClear ?? true,
|
||||
placeholder: props?.placeholder || '',
|
||||
treeDefaultExpandAll: props?.treeDefaultExpandAll ?? false,
|
||||
style: 'flex: 1; min-width: 0;',
|
||||
size: 'small',
|
||||
}),
|
||||
h('div', { style: 'display: flex; flex-direction: column; gap: 0; flex-shrink: 0; width: 18px;' }, [
|
||||
h(Button, {
|
||||
size: 'small', type: 'text',
|
||||
onClick: singleUp, onDblclick: dblUp,
|
||||
title: '单击复制上一行,双击复制上面全部',
|
||||
style: 'padding: 0; height: 11px; width: 18px; line-height: 11px; font-size: 8px; border-radius: 2px 2px 0 0; min-width: 0;',
|
||||
}, { default: () => h(CaretUpOutlined) }),
|
||||
h(Button, {
|
||||
size: 'small', type: 'text',
|
||||
onClick: singleDown, onDblclick: dblDown,
|
||||
title: '单击复制下一行,双击复制下面全部',
|
||||
style: 'padding: 0; height: 11px; width: 18px; line-height: 11px; font-size: 8px; border-radius: 0 0 2px 2px; min-width: 0;',
|
||||
}, { default: () => h(CaretDownOutlined) }),
|
||||
]),
|
||||
]);
|
||||
},
|
||||
});
|
||||
},
|
||||
useVbenForm,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user