-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
pure-admin-table
添加单元格编辑表格的简易用法 (#992)
* feat: `pure-admin-table`添加单元格编辑表格的简易用法
- Loading branch information
1 parent
dbfd014
commit e46d3e5
Showing
10 changed files
with
150 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { ref, computed } from "vue"; | ||
import { tableDataEdit } from "../data"; | ||
|
||
import EditPen from "@iconify-icons/ep/edit-pen"; | ||
import Check from "@iconify-icons/ep/check"; | ||
|
||
export function useColumns() { | ||
const editMap = ref({}); | ||
const activeIndex = ref(-1); | ||
const dataList = ref(tableDataEdit); | ||
|
||
const editing = computed(() => { | ||
return index => { | ||
return editMap.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 = [ | ||
{ | ||
label: "姓名(可修改)", | ||
prop: "name", | ||
cellRenderer: ({ row, index }) => ( | ||
<div | ||
class="flex-bc w-full h-[32px]" | ||
onMouseenter={() => (activeIndex.value = index)} | ||
onMouseleave={() => onMouseleave(index)} | ||
> | ||
{!editing.value(index) ? ( | ||
<p>{row.name}</p> | ||
) : ( | ||
<> | ||
<el-input v-model={row.name} /> | ||
<iconify-icon-offline | ||
icon={Check} | ||
class={iconClass.value(index)} | ||
onClick={() => onSave(index)} | ||
/> | ||
</> | ||
)} | ||
<iconify-icon-offline | ||
v-show={activeIndex.value === index && !editing.value(index)} | ||
icon={EditPen} | ||
class={iconClass.value(index, true)} | ||
onClick={() => onEdit(row, index)} | ||
/> | ||
</div> | ||
) | ||
}, | ||
{ | ||
label: "地址", | ||
prop: "address" | ||
} | ||
]; | ||
|
||
function onMouseleave(index) { | ||
editing.value[index] | ||
? (activeIndex.value = index) | ||
: (activeIndex.value = -1); | ||
} | ||
|
||
function onEdit(row, index) { | ||
editMap.value[index] = Object.assign({ ...row, editing: true }); | ||
} | ||
|
||
function onSave(index) { | ||
editMap.value[index].editing = false; | ||
} | ||
|
||
return { | ||
columns, | ||
dataList | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<script setup lang="ts"> | ||
import { useColumns } from "./columns"; | ||
const { columns, dataList } = useColumns(); | ||
</script> | ||
|
||
<template> | ||
<div class="flex"> | ||
<el-scrollbar> | ||
<code> | ||
<pre class="w-[400px]"> {{ dataList }}</pre> | ||
</code> | ||
</el-scrollbar> | ||
<pure-table | ||
class="!w-[30vw]" | ||
row-key="id" | ||
border | ||
:data="dataList" | ||
:columns="columns" | ||
/> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters