|
@@ -16,13 +16,15 @@
|
|
|
</a-button>
|
|
|
</template>
|
|
|
</BasicTable>
|
|
|
- <Add @register="addRegister" />
|
|
|
+ <Add @register="addRegister" :modelData="modelData" @saveData="saveData" />
|
|
|
</div>
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
|
- import { defineComponent, ref, unref } from 'vue';
|
|
|
+ import { defineComponent, reactive, ref, unref } from 'vue';
|
|
|
import Add from './add.vue'
|
|
|
-import { useModal } from '/@/components/Modal';
|
|
|
+ import { useModal } from '/@/components/Modal';
|
|
|
+ import { treeData } from './data';
|
|
|
+
|
|
|
import {
|
|
|
BasicTable,
|
|
|
useTable,
|
|
@@ -33,6 +35,13 @@ import { useModal } from '/@/components/Modal';
|
|
|
TableActionType
|
|
|
} from '/@/components/Table';
|
|
|
|
|
|
+ interface ModelData {
|
|
|
+ title: string,
|
|
|
+ treeData: object[],
|
|
|
+ checkedKeys: string[],
|
|
|
+ selectedKeys: string[],
|
|
|
+ expandedKeys: string[]
|
|
|
+ }
|
|
|
|
|
|
const columns: BasicColumn[] = [
|
|
|
{
|
|
@@ -64,17 +73,28 @@ import { useModal } from '/@/components/Modal';
|
|
|
];
|
|
|
|
|
|
export default defineComponent({
|
|
|
- components: { BasicTable, TableAction, Add },
|
|
|
+ components: { BasicTable, TableAction, Add, treeData },
|
|
|
setup() {
|
|
|
+ console.log(treeData)
|
|
|
const tableRef = ref<Nullable<TableActionType>>(null);
|
|
|
const currentEditKeyRef = ref('');
|
|
|
+ const modelData = reactive<ModelData>({
|
|
|
+ title: '添加',
|
|
|
+ treeData: treeData,
|
|
|
+ checkedKeys: ['0-1'],
|
|
|
+ selectedKeys: ['0-1'],
|
|
|
+ expandedKeys: ['0-1']
|
|
|
+ })
|
|
|
const [registerTable] = useTable({
|
|
|
title: "基础示例",
|
|
|
titleHelpMessage: "温馨提醒",
|
|
|
rowSelection: { type: 'checkbox' },
|
|
|
columns: columns,
|
|
|
clickToRowSelect: false, // 点击行不勾选
|
|
|
- dataSource: [{id:1,name:'vben',detail:'super admin', password: '123456'},{id:2,name:'test',detail:'test admin', password: '123456'}],
|
|
|
+ dataSource: [
|
|
|
+ { id: 1, name: 'vben', detail: 'super admin', password: '123456' },
|
|
|
+ { id:2,name:'test', detail: 'test admin', password: '123456' }
|
|
|
+ ],
|
|
|
showIndexColumn: false,
|
|
|
actionColumn: {
|
|
|
width: 160,
|
|
@@ -105,38 +125,76 @@ import { useModal } from '/@/components/Modal';
|
|
|
|
|
|
function addColumn() {
|
|
|
console.log('添加')
|
|
|
+ modelData.title = '添加'
|
|
|
+ modelData.checkedKeys = []
|
|
|
+ modelData.selectedKeys = []
|
|
|
+ modelData.expandedKeys = []
|
|
|
openAdd(true, {
|
|
|
- // name: '',
|
|
|
- // password: '',
|
|
|
- // detail: '',
|
|
|
- // tree: '',
|
|
|
+ id: 0,
|
|
|
+ name: '',
|
|
|
+ password: '',
|
|
|
+ detail: '',
|
|
|
isUpdate: true,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- function handleSubmit() {
|
|
|
- console.log('handleSubmit')
|
|
|
- // console.log(data)
|
|
|
- }
|
|
|
-
|
|
|
function handleEdit(record: EditRecordRow) {
|
|
|
currentEditKeyRef.value = record.id; // record.key
|
|
|
console.log(record)
|
|
|
+ modelData.title = '编辑'
|
|
|
+ modelData.checkedKeys = ['0-1']
|
|
|
+ if (record.id === 2) {
|
|
|
+ modelData.checkedKeys = []
|
|
|
+ }
|
|
|
+ console.log(record.id)
|
|
|
+ const data = getTableAction().getDataSource()
|
|
|
+ data.map(item => {
|
|
|
+ if (item.id === record.id) {
|
|
|
+ record = item
|
|
|
+ }
|
|
|
+ })
|
|
|
openAdd(true, {
|
|
|
- name: record.name,
|
|
|
- password: record.password,
|
|
|
- detail: record.detail,
|
|
|
- tree: 'none',
|
|
|
+ // id: record.id,
|
|
|
+ // name: record.name,
|
|
|
+ // password: record.password,
|
|
|
+ // detail: record.detail,
|
|
|
+ ...record
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function handleDelete(record: Recordable) {
|
|
|
console.log('点击了删除', record.id);
|
|
|
+ console.log(record)
|
|
|
const data = getTableAction().getDataSource()
|
|
|
console.log(data)
|
|
|
getTableAction().setTableData(data.filter(item => item.id !== record.id))
|
|
|
}
|
|
|
|
|
|
+ function saveData(data: any) {
|
|
|
+ const datas = getTableAction().getDataSource()
|
|
|
+ const info = reactive({...data.info})
|
|
|
+ if (modelData.title === "添加") {
|
|
|
+ datas.map(item => {
|
|
|
+ if (info.id === 0 || info.id === item.id) {
|
|
|
+ info.id = item.id + 1
|
|
|
+ }
|
|
|
+ })
|
|
|
+ datas.push(info)
|
|
|
+ getTableAction().setTableData(datas)
|
|
|
+ } else {
|
|
|
+ console.log('编辑')
|
|
|
+ // getTableAction().setTableData(datas.filter(item => item.id !== info.id))
|
|
|
+ let dataArr:object[] = []
|
|
|
+ datas.map(item => {
|
|
|
+ if (item.id === info.id) {
|
|
|
+ item = info
|
|
|
+ }
|
|
|
+ dataArr.push(item)
|
|
|
+ })
|
|
|
+ getTableAction().setTableData(dataArr)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function createActions(record: EditRecordRow, column: BasicColumn): ActionItem[] {
|
|
|
column
|
|
|
return [
|
|
@@ -158,8 +216,8 @@ import { useModal } from '/@/components/Modal';
|
|
|
];
|
|
|
}
|
|
|
return {
|
|
|
-
|
|
|
- // ...toRefs(state),
|
|
|
+ modelData,
|
|
|
+ treeData,
|
|
|
tableRef,
|
|
|
registerTable,
|
|
|
rowClick,
|
|
@@ -170,8 +228,7 @@ import { useModal } from '/@/components/Modal';
|
|
|
getSelectRowList,
|
|
|
getSelectRowKeyList,
|
|
|
addRegister,
|
|
|
- handleSubmit
|
|
|
-
|
|
|
+ saveData
|
|
|
};
|
|
|
},
|
|
|
});
|