mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-08 01:17:23 +08:00
chore: update
This commit is contained in:
parent
10fdb30e07
commit
0d0d33ca29
@ -5,7 +5,11 @@ import { clone, delay } from "@pureadmin/utils";
|
|||||||
|
|
||||||
// 温馨提示:编辑整行方法雷同,将cellRenderer后面渲染的组件抽出来做对应处理即可
|
// 温馨提示:编辑整行方法雷同,将cellRenderer后面渲染的组件抽出来做对应处理即可
|
||||||
export function useColumns() {
|
export function useColumns() {
|
||||||
|
// 编辑值(可多个)
|
||||||
const inputValMap = ref({});
|
const inputValMap = ref({});
|
||||||
|
// 是否正处于编辑状态(可多个)
|
||||||
|
const editStatus = ref({});
|
||||||
|
// 当前激活的单元格(唯一)
|
||||||
const activeIndex = ref(-1);
|
const activeIndex = ref(-1);
|
||||||
const dataList = ref(clone(tableDataEdit, true));
|
const dataList = ref(clone(tableDataEdit, true));
|
||||||
|
|
||||||
@ -15,6 +19,26 @@ export function useColumns() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const editing = computed(() => {
|
||||||
|
return index => {
|
||||||
|
return editStatus.value[index]?.editing;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const iconClass = computed(() => {
|
||||||
|
return (index, other = false) => {
|
||||||
|
return [
|
||||||
|
"cursor-pointer",
|
||||||
|
"ml-2",
|
||||||
|
"transition",
|
||||||
|
"delay-100",
|
||||||
|
other
|
||||||
|
? ["hover:scale-110", "hover:text-red-500"]
|
||||||
|
: editing.value(index) && ["scale-150", "text-red-500"]
|
||||||
|
];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const columns: TableColumnList = [
|
const columns: TableColumnList = [
|
||||||
{
|
{
|
||||||
label: "ID(可编辑)",
|
label: "ID(可编辑)",
|
||||||
@ -22,26 +46,26 @@ export function useColumns() {
|
|||||||
// class="flex-bc" flex-bc 代表 flex justify-between items-center 具体看 src/style/tailwind.css 文件
|
// class="flex-bc" flex-bc 代表 flex justify-between items-center 具体看 src/style/tailwind.css 文件
|
||||||
cellRenderer: ({ row, index }) => (
|
cellRenderer: ({ row, index }) => (
|
||||||
<div
|
<div
|
||||||
class="flex-bc"
|
class="flex-bc h-[32px]"
|
||||||
onMouseenter={() => (activeIndex.value = index)}
|
onMouseenter={() => (activeIndex.value = index)}
|
||||||
onMouseleave={() => onMouseleave(index)}
|
onMouseleave={() => onMouseleave(index)}
|
||||||
>
|
>
|
||||||
<p v-show={!comVal.value(index)}>{row.id}</p>
|
<p v-show={!editing.value(index)}>{row.id}</p>
|
||||||
<el-input
|
<el-input
|
||||||
v-show={comVal.value(index)}
|
v-show={editing.value(index)}
|
||||||
modelValue={comVal.value(index)}
|
modelValue={comVal.value(index)}
|
||||||
onInput={value => onChange(value, index)}
|
onInput={value => onChange(value, index)}
|
||||||
/>
|
/>
|
||||||
<iconify-icon-offline
|
<iconify-icon-offline
|
||||||
v-show={comVal.value(index)}
|
v-show={editing.value(index)}
|
||||||
icon="check"
|
icon="check"
|
||||||
class="cursor-pointer ml-2 transition delay-100 hover:scale-150 hover:text-red-500"
|
class={iconClass.value(index)}
|
||||||
onClick={() => onSure(index)}
|
onClick={() => onSure(index)}
|
||||||
/>
|
/>
|
||||||
<iconify-icon-offline
|
<iconify-icon-offline
|
||||||
v-show={activeIndex.value === index && !comVal.value(index)}
|
v-show={activeIndex.value === index && !editing.value(index)}
|
||||||
icon="edits"
|
icon="edits"
|
||||||
class="cursor-pointer ml-2 transition delay-100 hover:scale-110 hover:text-red-500"
|
class={iconClass.value(index, true)}
|
||||||
onClick={() => onEdit(row, index)}
|
onClick={() => onEdit(row, index)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -65,6 +89,10 @@ export function useColumns() {
|
|||||||
inputValMap.value[index] = Object.assign({}, inputValMap.value[index], {
|
inputValMap.value[index] = Object.assign({}, inputValMap.value[index], {
|
||||||
value: id
|
value: id
|
||||||
});
|
});
|
||||||
|
// 处于编辑状态
|
||||||
|
editStatus.value[index] = Object.assign({}, editStatus.value[index], {
|
||||||
|
editing: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseleave(index) {
|
function onMouseleave(index) {
|
||||||
@ -84,6 +112,10 @@ export function useColumns() {
|
|||||||
dataList.value[index]
|
dataList.value[index]
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
|
// 编辑状态关闭
|
||||||
|
editStatus.value[index] = Object.assign({}, editStatus.value[index], {
|
||||||
|
editing: false
|
||||||
|
});
|
||||||
delay().then(() => (inputValMap.value[index].value = null));
|
delay().then(() => (inputValMap.value[index].value = null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ const { columns, dataList, print, cellStyle, rowStyle, headerCellStyle } =
|
|||||||
<el-button type="primary" @click="print" class="mb-[20px] float-right">
|
<el-button type="primary" @click="print" class="mb-[20px] float-right">
|
||||||
打印
|
打印
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<!-- rowHoverBgColor="transparent" 鼠标经过行时,去掉行的背景色 -->
|
||||||
<pure-table
|
<pure-table
|
||||||
rowHoverBgColor="transparent"
|
rowHoverBgColor="transparent"
|
||||||
ref="printRef"
|
ref="printRef"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user