20260723225202
This commit is contained in:
1 parent
5f73b54802
commit
4d118a0037
22 files changed
+1403
-259
No files matched your search
@@ -1,11 +1,11 @@
|
||||
<script setup>
|
||||
import { ref, watch } from "vue";
|
||||
import { nextTick, ref, watch } from "vue";
|
||||
import FmsTable from "@/components/fms-table/FmsTable.vue";
|
||||
import { createTempId } from "@/utils/tempId";
|
||||
import { createDeleteCell, createToggleCell } from "./cellRenderers";
|
||||
|
||||
const props = defineProps({
|
||||
moduleId: { type: String, required: true },
|
||||
moduleCode: { type: String, default: "" },
|
||||
powers: { type: Array, default: () => [] },
|
||||
loading: { type: Boolean, default: false },
|
||||
});
|
||||
@@ -13,11 +13,20 @@ const props = defineProps({
|
||||
const emit = defineEmits(["update"]);
|
||||
|
||||
const localPowers = ref([]);
|
||||
const activeKey = ref(null);
|
||||
const tableRef = ref(null);
|
||||
|
||||
// 多语言键按 power.<模块代码>.<操作编码> 自动生成,无需手动填写。
|
||||
watch(
|
||||
() => props.powers,
|
||||
(val) => {
|
||||
localPowers.value = val?.map((r) => ({ ...r })) || [];
|
||||
() => [props.powers, props.moduleCode],
|
||||
([val]) => {
|
||||
localPowers.value = (val || []).map((r) => ({
|
||||
...r,
|
||||
b_i18n:
|
||||
r.b_code && props.moduleCode
|
||||
? `power.${props.moduleCode}.${r.b_code}`
|
||||
: (r.b_i18n ?? null),
|
||||
}));
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
@@ -26,9 +35,10 @@ function emitUpdate() {
|
||||
emit("update", localPowers.value.map((r) => ({ ...r })));
|
||||
}
|
||||
|
||||
function addRow() {
|
||||
async function addRow() {
|
||||
const newId = createTempId();
|
||||
localPowers.value.push({
|
||||
b_id: createTempId(),
|
||||
b_id: newId,
|
||||
b_module_id: props.moduleId,
|
||||
b_code: "",
|
||||
b_name: "",
|
||||
@@ -37,6 +47,10 @@ function addRow() {
|
||||
b_canuse: 1,
|
||||
});
|
||||
emitUpdate();
|
||||
|
||||
activeKey.value = String(newId);
|
||||
await nextTick();
|
||||
tableRef.value?.scrollToRow(String(newId));
|
||||
}
|
||||
|
||||
function deleteRow(record) {
|
||||
@@ -45,26 +59,23 @@ function deleteRow(record) {
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ dataIndex: "b_code", title: "操作编码", width: 160 },
|
||||
{ dataIndex: "b_name", title: "操作名称", width: 160 },
|
||||
{ dataIndex: "b_code", title: "操作编码", width: 160, editor: { onChange: () => emitUpdate() } },
|
||||
{ dataIndex: "b_name", title: "操作名称", width: 160, editor: { onChange: () => emitUpdate() } },
|
||||
{ dataIndex: "b_i18n", title: "多语言键", width: 160 },
|
||||
{ dataIndex: "b_xh", title: "排序", width: 80 },
|
||||
{ dataIndex: "b_xh", title: "排序", width: 80, editor: { onChange: () => emitUpdate() } },
|
||||
{
|
||||
dataIndex: "b_canuse",
|
||||
title: "启用",
|
||||
width: 70,
|
||||
align: "center",
|
||||
customCell: createToggleCell("b_canuse", (row) => {
|
||||
row.b_canuse = row.b_canuse === 1 ? 0 : 1;
|
||||
emitUpdate();
|
||||
}),
|
||||
editor: { type: "checkbox", onChange: () => emitUpdate() },
|
||||
},
|
||||
{
|
||||
dataIndex: "actions",
|
||||
title: "操作",
|
||||
width: 60,
|
||||
align: "center",
|
||||
customCell: createDeleteCell((row) => deleteRow(row)),
|
||||
actions: [{ type: "danger", label: "删除", confirm: { title: "确定删除该记录?", okText: "删除" }, onClick: (row) => deleteRow(row) }],
|
||||
},
|
||||
];
|
||||
</script>
|
||||
@@ -77,7 +88,7 @@ const columns = [
|
||||
</a-space>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<FmsTable :columns="columns" :data-source="localPowers" row-key="b_id" />
|
||||
<FmsTable ref="tableRef" :columns="columns" :data-source="localPowers" row-key="b_id" :active-row-key="activeKey" @row-click="(_, row) => (activeKey = String(row.b_id))" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -93,13 +104,13 @@ const columns = [
|
||||
display: flex;
|
||||
flex: none;
|
||||
gap: 8px;
|
||||
padding: 12px 20px;
|
||||
padding: 12px 20px 0;
|
||||
}
|
||||
|
||||
.panel-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 16px 20px;
|
||||
padding: 12px 20px 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user