20260731171910
This commit is contained in:
1 parent
318fa0d9e1
commit
c00329b5a4
6 files changed
+1148
-2337
No files matched your search
@@ -11,7 +11,6 @@
|
|||||||
"fmt:check": "oxfmt --check"
|
"fmt:check": "oxfmt --check"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@file-viewer/vue3-full": "^2.2.4",
|
|
||||||
"@lucide/vue": "^1.24.0",
|
"@lucide/vue": "^1.24.0",
|
||||||
"@vueuse/core": "^14.3.0",
|
"@vueuse/core": "^14.3.0",
|
||||||
"antdv-next": "^1.4.2",
|
"antdv-next": "^1.4.2",
|
||||||
@@ -26,7 +25,6 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antdv-next/auto-import-resolver": "^1.1.0",
|
"@antdv-next/auto-import-resolver": "^1.1.0",
|
||||||
"@antdv-next/tailwind": "^1.1.1",
|
"@antdv-next/tailwind": "^1.1.1",
|
||||||
"@file-viewer/vite-plugin": "^2.2.4",
|
|
||||||
"@tailwindcss/vite": "4.3.2",
|
"@tailwindcss/vite": "4.3.2",
|
||||||
"@vitejs/plugin-vue": "^6.0.7",
|
"@vitejs/plugin-vue": "^6.0.7",
|
||||||
"less": "^4.7.0",
|
"less": "^4.7.0",
|
||||||
|
|||||||
Generated
+3
-1965
File diff suppressed because it is too large.
Load diff
@@ -7,8 +7,6 @@ import "./styles/tailwind.css";
|
|||||||
import "./styles/main.scss";
|
import "./styles/main.scss";
|
||||||
import "stk-table-vue/lib/style.css";
|
import "stk-table-vue/lib/style.css";
|
||||||
import { registerFeature, useAreaSelection } from "stk-table-vue";
|
import { registerFeature, useAreaSelection } from "stk-table-vue";
|
||||||
import FileViewer from '@file-viewer/vue3-full'
|
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
const pinia = createPinia();
|
const pinia = createPinia();
|
||||||
|
|
||||||
@@ -17,5 +15,4 @@ registerFeature(useAreaSelection);
|
|||||||
pinia.use(piniaPluginPersistedstate);
|
pinia.use(piniaPluginPersistedstate);
|
||||||
app.use(pinia);
|
app.use(pinia);
|
||||||
app.use(router);
|
app.use(router);
|
||||||
app.use(FileViewer);
|
|
||||||
app.mount("#app");
|
app.mount("#app");
|
||||||
@@ -0,0 +1,317 @@
|
|||||||
|
<script setup>
|
||||||
|
import { h, ref, shallowRef } from "vue";
|
||||||
|
import { message } from "antdv-next";
|
||||||
|
import { Input, InputNumber, Select } from "antdv-next";
|
||||||
|
import FmsSelect from "@/components/FmsSelect.vue";
|
||||||
|
import FmsTable from "@/components/fms-table/FmsTable.vue";
|
||||||
|
|
||||||
|
const COLUMN_COUNT = 20;
|
||||||
|
const ROW_COUNT = 4000;
|
||||||
|
|
||||||
|
const STATUS_OPTIONS = [
|
||||||
|
{ label: "启用", value: 1 },
|
||||||
|
{ label: "禁用", value: 0 },
|
||||||
|
];
|
||||||
|
|
||||||
|
function randInt(min, max) {
|
||||||
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||||
|
}
|
||||||
|
function randText(len) {
|
||||||
|
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
let s = "";
|
||||||
|
for (let i = 0; i < len; i++) s += chars[randInt(0, chars.length - 1)];
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
function generateValue(c, i) {
|
||||||
|
switch (c % 5) {
|
||||||
|
case 0:
|
||||||
|
return randText(randInt(4, 10));
|
||||||
|
case 1:
|
||||||
|
return randInt(0, 99999);
|
||||||
|
case 2:
|
||||||
|
return STATUS_OPTIONS[randInt(0, 1)].value;
|
||||||
|
case 3:
|
||||||
|
return `名称-${i}-${c}`;
|
||||||
|
default:
|
||||||
|
return `${randInt(1000, 9999)}-${randText(4)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildData() {
|
||||||
|
const rows = [];
|
||||||
|
for (let i = 0; i < ROW_COUNT; i++) {
|
||||||
|
const row = { id: `R${i}` };
|
||||||
|
for (let c = 1; c <= COLUMN_COUNT; c++) row[`col${c}`] = generateValue(c, i);
|
||||||
|
rows.push(row);
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataSource = shallowRef(buildData());
|
||||||
|
const selectedLocale = ref("");
|
||||||
|
const selectedLocaleLabel = ref("");
|
||||||
|
const selectedLocaleRecord = shallowRef(null);
|
||||||
|
|
||||||
|
// 当前编辑行 key;进入编辑时留存快照,取消可还原
|
||||||
|
const editingKey = shallowRef(null);
|
||||||
|
const editSnapshot = shallowRef(null);
|
||||||
|
|
||||||
|
function editConfigFor(c) {
|
||||||
|
switch (c % 5) {
|
||||||
|
case 1:
|
||||||
|
return { type: "number" };
|
||||||
|
case 2:
|
||||||
|
return { type: "select", options: STATUS_OPTIONS };
|
||||||
|
default:
|
||||||
|
return { type: "text", maxlength: 64 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单元格渲染:编辑行显示控件,其他行直接返回文本值(让 stk-table 用原生 textContent 渲染,零 VNode 开销)
|
||||||
|
function makeCellEditor(dataIndex, edit) {
|
||||||
|
const selectOptions = edit.options || [];
|
||||||
|
return (props) => {
|
||||||
|
const { row, cellValue } = props;
|
||||||
|
if (row.id !== editingKey.value) {
|
||||||
|
// 非编辑态:直接返回文本字符串,不创建 VNode 包装
|
||||||
|
if (edit.type === "select") {
|
||||||
|
const opt = selectOptions.find((o) => o.value === cellValue);
|
||||||
|
return opt ? opt.label : (cellValue ?? "");
|
||||||
|
}
|
||||||
|
return cellValue ?? "";
|
||||||
|
}
|
||||||
|
// 编辑态:返回编辑组件 VNode
|
||||||
|
const update = (v) => {
|
||||||
|
row[dataIndex] = v;
|
||||||
|
};
|
||||||
|
const common = {
|
||||||
|
size: "small",
|
||||||
|
style: { width: "100%" },
|
||||||
|
onClick: (e) => e.stopPropagation(),
|
||||||
|
};
|
||||||
|
if (edit.type === "number") {
|
||||||
|
return h(InputNumber, {
|
||||||
|
...common,
|
||||||
|
value: cellValue,
|
||||||
|
min: edit.min,
|
||||||
|
max: edit.max,
|
||||||
|
precision: edit.precision,
|
||||||
|
"onUpdate:value": update,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (edit.type === "select") {
|
||||||
|
return h(Select, {
|
||||||
|
...common,
|
||||||
|
value: cellValue,
|
||||||
|
options: selectOptions,
|
||||||
|
"onUpdate:value": update,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return h(Input, {
|
||||||
|
...common,
|
||||||
|
value: cellValue,
|
||||||
|
maxlength: edit.maxlength,
|
||||||
|
"onUpdate:value": update,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildColumns() {
|
||||||
|
const cols = [
|
||||||
|
{
|
||||||
|
dataIndex: "id",
|
||||||
|
title: "编码",
|
||||||
|
width: 120,
|
||||||
|
fixed: "left",
|
||||||
|
customCell: makeCellEditor("id", { type: "text", maxlength: 32 }),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
for (let c = 1; c <= COLUMN_COUNT; c++) {
|
||||||
|
const edit = editConfigFor(c);
|
||||||
|
cols.push({
|
||||||
|
dataIndex: `col${c}`,
|
||||||
|
title: `列 ${c}`,
|
||||||
|
width: 140,
|
||||||
|
sorter: edit.type === "number" ? true : undefined,
|
||||||
|
customCell: makeCellEditor(`col${c}`, edit),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return cols;
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns = shallowRef(buildColumns());
|
||||||
|
|
||||||
|
function onRowClick(ev, row) {
|
||||||
|
if (row.id === editingKey.value) return;
|
||||||
|
editingKey.value = row.id;
|
||||||
|
editSnapshot.value = JSON.parse(JSON.stringify(row));
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveEdit() {
|
||||||
|
if (editingKey.value == null) return;
|
||||||
|
editingKey.value = null;
|
||||||
|
editSnapshot.value = null;
|
||||||
|
message.success("已保存当前行修改");
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelEdit() {
|
||||||
|
if (editingKey.value != null && editSnapshot.value) {
|
||||||
|
const idx = dataSource.value.findIndex((r) => r.id === editingKey.value);
|
||||||
|
if (idx >= 0) dataSource.value[idx] = editSnapshot.value;
|
||||||
|
}
|
||||||
|
editingKey.value = null;
|
||||||
|
editSnapshot.value = null;
|
||||||
|
message.info("已取消编辑");
|
||||||
|
}
|
||||||
|
|
||||||
|
function regenerate() {
|
||||||
|
editingKey.value = null;
|
||||||
|
editSnapshot.value = null;
|
||||||
|
dataSource.value = buildData();
|
||||||
|
message.success("已重新生成随机数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
function rowClassName(row) {
|
||||||
|
return row.id === editingKey.value ? "fms-row-editing" : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function onLocaleChange(record) {
|
||||||
|
selectedLocaleRecord.value = record;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<main class="table-demo">
|
||||||
|
<header class="table-demo__toolbar">
|
||||||
|
<div class="table-demo__title">
|
||||||
|
<strong>大数据表格 Demo</strong>
|
||||||
|
<span class="table-demo__meta">
|
||||||
|
共 {{ dataSource.length }} 行 · {{ columns.length }} 列 ·
|
||||||
|
<template v-if="editingKey">正在编辑:{{ editingKey }}</template>
|
||||||
|
<template v-else>点击任意行进入编辑</template>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="table-demo__actions">
|
||||||
|
<a-button :disabled="editingKey == null" type="primary" @click="saveEdit">保存</a-button>
|
||||||
|
<a-button :disabled="editingKey == null" @click="cancelEdit">取消</a-button>
|
||||||
|
<a-button @click="regenerate">重新生成</a-button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section class="select-demo">
|
||||||
|
<div class="select-demo__field">
|
||||||
|
<label class="select-demo__label">FmsSelect 远程选择</label>
|
||||||
|
<FmsSelect
|
||||||
|
v-model="selectedLocale"
|
||||||
|
v-model:label="selectedLocaleLabel"
|
||||||
|
view-name="b_i18n_type"
|
||||||
|
label-key="b_name"
|
||||||
|
value-key="b_code"
|
||||||
|
order-by="b_code ASC"
|
||||||
|
:page-size="10"
|
||||||
|
@change="onLocaleChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="select-demo__value">
|
||||||
|
<span>当前值:{{ selectedLocale || "-" }}</span>
|
||||||
|
<span>显示文本:{{ selectedLocaleLabel || "-" }}</span>
|
||||||
|
<span>记录编码:{{ selectedLocaleRecord?.b_code || "-" }}</span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="table-demo__body">
|
||||||
|
<FmsTable
|
||||||
|
v-model:columns="columns"
|
||||||
|
:data-source="dataSource"
|
||||||
|
row-key="id"
|
||||||
|
:row-class-name="rowClassName"
|
||||||
|
show-overflow
|
||||||
|
@row-click="onRowClick"
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.table-demo {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
min-height: 0;
|
||||||
|
color: var(--fms-text);
|
||||||
|
background: var(--fms-surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-demo__toolbar {
|
||||||
|
display: flex;
|
||||||
|
flex: none;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
padding: 12px 16px;
|
||||||
|
border-bottom: 1px solid var(--fms-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-demo__title {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-demo__title strong {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-demo__meta {
|
||||||
|
color: var(--fms-text-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-demo__actions {
|
||||||
|
display: flex;
|
||||||
|
flex: none;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-demo__body {
|
||||||
|
position: relative;
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
padding: 12px 16px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-demo {
|
||||||
|
display: flex;
|
||||||
|
flex: none;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 16px;
|
||||||
|
padding: 12px 16px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-demo__field {
|
||||||
|
width: 320px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-demo__label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
color: var(--fms-text-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-demo__value {
|
||||||
|
display: flex;
|
||||||
|
min-width: 0;
|
||||||
|
gap: 16px;
|
||||||
|
color: var(--fms-text-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.fms-row-editing) {
|
||||||
|
background: rgba(22, 119, 255, 0.08) !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -4,7 +4,6 @@ import vue from "@vitejs/plugin-vue";
|
|||||||
import tailwindcss from "@tailwindcss/vite";
|
import tailwindcss from "@tailwindcss/vite";
|
||||||
import { AntdvNextResolver } from "@antdv-next/auto-import-resolver";
|
import { AntdvNextResolver } from "@antdv-next/auto-import-resolver";
|
||||||
import Components from "unplugin-vue-components/vite";
|
import Components from "unplugin-vue-components/vite";
|
||||||
import { fileViewerRenderers } from "@file-viewer/vite-plugin";
|
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
@@ -17,13 +16,10 @@ export default defineConfig({
|
|||||||
host: "127.0.0.1",
|
host: "127.0.0.1",
|
||||||
port: 5180,
|
port: 5180,
|
||||||
strictPort: true,
|
strictPort: true,
|
||||||
// 排除静态资源目录的监听:full 包复制出的 WASM/字体体积大,
|
|
||||||
// 在 Windows 下易被锁定导致 Vite 监听报 EBUSY 崩溃;public 下资源按需直接服务,无需监听
|
|
||||||
watch: {
|
watch: {
|
||||||
ignored: [
|
ignored: [
|
||||||
"**/node_modules/**",
|
"**/node_modules/**",
|
||||||
"**/.git/**",
|
"**/.git/**",
|
||||||
"**/public/file-viewer/**",
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
@@ -39,6 +35,5 @@ export default defineConfig({
|
|||||||
Components({
|
Components({
|
||||||
resolvers: [AntdvNextResolver()],
|
resolvers: [AntdvNextResolver()],
|
||||||
}),
|
}),
|
||||||
fileViewerRenderers({ copyAssets: true }),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user