You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.7 KiB
Vue

10 months ago
<script lang="ts">
import hwInputView from './hw-input-view.vue';
export default {
name: 'hw-table-view',
components: {
hwInputView
}
};
</script>
10 months ago
<template>
<div>
10 months ago
<div style="margin-bottom: 12px;" v-if="options.isOperate">
<el-button :icon="Plus" type="primary" disabled @click="addBtn"></el-button>
<el-button :icon="Edit" type="success" disabled>编辑</el-button>
<el-button :icon="Delete" type="danger" disabled>删除</el-button>
</div>
<el-table :data="cs || globalFormData.pageVariable[options.dataKey]"
style="width: 100%"
@selection-change="tableSelectionChange">
<el-table-column type="selection" width="55" />
10 months ago
<el-table-column :prop="i.keyName" :label="i.name" v-for="i in options.thTdMap" />
<el-table-column label="操作">
<template #default="scope">
<el-button
link
type="primary"
size="small"
@click.prevent="updateBtn(scope)"
>
修改
</el-button>
<el-popconfirm title="确定要删除此项数据吗?" @confirm="delBtn(scope)">
<template #reference>
<el-button
link
type="primary"
size="small"
>
删除
</el-button>
</template>
</el-popconfirm>
</template>
</el-table-column>
10 months ago
</el-table>
10 months ago
<el-dialog v-model="tableUpdateFormVisible" title="修改表格信息" width="500">
<el-form :model="form" label-width="120px">
<component v-for="(i,k) in options.thTdMap" :is="'hw-'+i.type+'-view'" :formData="form"
:options="{name:i.name,key:i.keyName}" />
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button @click="tableUpdateFormVisible = false;form={}">关闭</el-button>
<el-button type="primary" @click="onSubmit">
提交
</el-button>
</div>
</template>
</el-dialog>
10 months ago
</div>
</template>
<script lang="ts" setup>
10 months ago
import { Delete, Edit, Plus } from '@element-plus/icons-vue';
import request from '@/utils/request';
10 months ago
defineOptions({
name: 'hw-table-view'
});
const props = defineProps({
options: Object
});
10 months ago
const cs = [
{ a: 1 },
{ a: 2 }
];
10 months ago
const { options } = toRefs(props);
const globalFormData = inject('globalFormData');
10 months ago
const tableUpdateFormVisible = ref(false);
const form = ref({});
const formDataOperation = inject('formDataOperation');
const localData = ref({});
const SelectionList = ref([]);
const tableSelectionChange = (e) => {
SelectionList.value = e;
console.log(SelectionList.value);
};
const addBtn = () => {
};
10 months ago
const updateBtn = (scope) => {
console.log(scope);
10 months ago
console.log(options.value.thTdMap);
form.value = scope.row;
tableUpdateFormVisible.value = true;
};
const onSubmit = async () => {
try {
const fun = () => {
return `return async ()=>{
${options.value.updateFunction}
}`;
};
const updateFunction = new Function('formData', 'request', 'formDataOperation', 'localData', fun());
await updateFunction(form.value, request, formDataOperation, localData.value)();
console.log();
} catch (e) {
console.log(e);
}
10 months ago
};
10 months ago
const delBtn = async (scope) => {
try {
const fun = () => {
return `return async ()=>{
${options.value.deleteFunction}
}`;
};
const deleteFunction = new Function('formData', 'request', 'formDataOperation', 'localData', fun());
await deleteFunction(scope.row, request, formDataOperation, localData.value)();
} catch (e) {
console.log(e);
}
10 months ago
};
10 months ago
</script>
<style scoped lang="less">
</style>