|
|
@@ -0,0 +1,138 @@
|
|
|
+<template>
|
|
|
+ <el-card class="mb-12px" body-class="p-8px!">
|
|
|
+ <template #header>
|
|
|
+ <div class="flex items-center justify-between">
|
|
|
+ <span> 单元格 </span>
|
|
|
+ <span>
|
|
|
+ <el-tooltip content="添加一行">
|
|
|
+ <span>
|
|
|
+ <PiRowsPlusBottomLight class="cursor-pointer" size="16px" @click="handleAddRow" />
|
|
|
+ </span>
|
|
|
+ </el-tooltip>
|
|
|
+ <el-tooltip content="添加一列">
|
|
|
+ <span>
|
|
|
+ <PiColumnsPlusRightLight
|
|
|
+ class="cursor-pointer ml-4px"
|
|
|
+ size="16px"
|
|
|
+ @click="handleAddColumn"
|
|
|
+ />
|
|
|
+ </span>
|
|
|
+ </el-tooltip>
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ <el-scrollbar max-height="120px">
|
|
|
+ <div
|
|
|
+ class="flex items-center gap-4px box-border pr-12px mb-4px"
|
|
|
+ v-for="(row, rowIndex) in items"
|
|
|
+ :key="rowIndex"
|
|
|
+ >
|
|
|
+ <div class="w-full flex items-center gap-4px relative group/item">
|
|
|
+ <div v-for="(_, columnIndex) in row" :key="`${rowIndex}_${columnIndex}`" class="relative">
|
|
|
+ <el-input v-model="row[columnIndex]" />
|
|
|
+ <div
|
|
|
+ v-if="rowIndex === 0 && columnIndex !== 0"
|
|
|
+ class="absolute top--4px right-0 cursor-pointer"
|
|
|
+ >
|
|
|
+ <LuX size="14px" @click="handleDeleteColumn(columnIndex)" />
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ v-if="columnIndex === 0 && rowIndex !== 0"
|
|
|
+ class="absolute left--1px top--4px cursor-pointer"
|
|
|
+ >
|
|
|
+ <LuX size="14px" @click="handleDeleteRow(rowIndex)" />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </el-scrollbar>
|
|
|
+ </el-card>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import { computed, type Ref } from 'vue'
|
|
|
+import { LuX } from 'vue-icons-plus/lu'
|
|
|
+import { PiColumnsPlusRightLight, PiRowsPlusBottomLight } from 'vue-icons-plus/pi'
|
|
|
+
|
|
|
+const props = defineProps<{
|
|
|
+ values: Ref<any>
|
|
|
+}>()
|
|
|
+
|
|
|
+// 子项
|
|
|
+const items = computed({
|
|
|
+ get() {
|
|
|
+ return (props.values?.value?.props.items || []) as any[]
|
|
|
+ },
|
|
|
+ set(list: any[]) {
|
|
|
+ if (props.values?.value?.props.items) {
|
|
|
+ props.values.value.props.items = list
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+// 列数
|
|
|
+const rows = computed({
|
|
|
+ get() {
|
|
|
+ return props.values?.value?.props.rows || 1
|
|
|
+ },
|
|
|
+ set(value: number) {
|
|
|
+ if (props.values?.value?.props.rows) {
|
|
|
+ props.values.value.props.rows = value
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+// 列数
|
|
|
+const cols = computed({
|
|
|
+ get() {
|
|
|
+ return props.values?.value?.props.cols || 1
|
|
|
+ },
|
|
|
+ set(value: number) {
|
|
|
+ if (props.values?.value?.props.cols) {
|
|
|
+ props.values.value.props.cols = value
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+/**
|
|
|
+ * 添加一行
|
|
|
+ */
|
|
|
+const handleAddRow = () => {
|
|
|
+ items.value.push(new Array(cols.value).fill('cell'))
|
|
|
+ rows.value++
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 添加一列
|
|
|
+ */
|
|
|
+const handleAddColumn = () => {
|
|
|
+ items.value.forEach((row, index) => {
|
|
|
+ if (index === 0) {
|
|
|
+ row.push('header')
|
|
|
+ } else {
|
|
|
+ row.push('cell')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ cols.value++
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 删除一行
|
|
|
+ * @param index 索引
|
|
|
+ */
|
|
|
+const handleDeleteRow = (index: number) => {
|
|
|
+ items.value.splice(index, 1)
|
|
|
+ rows.value--
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 删除一列
|
|
|
+ */
|
|
|
+const handleDeleteColumn = (index) => {
|
|
|
+ items.value.forEach((row) => {
|
|
|
+ row.splice(index, 1)
|
|
|
+ })
|
|
|
+ cols.value--
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped></style>
|