Commit df6b3c14 authored by 陈浩玮's avatar 陈浩玮

修改

parent 16a99e67
import { delReq, getReq, postReq, putReq } from '@/utils'; import { delReq, getReq, postReq, putReq } from '@/utils';
// export function delMenuApi(id) {
// return delReq(`/api/v1/menus/${id}`);
// }
// export function getMenuDataApi() {
// return getReq('/api/v1/menus');
// }
// export function addMenuApi(data) {
// return postReq('/api/v1/menus', data);
// }
function addJobsApi(data) { function addJobsApi(data) {
return postReq('/api/v1/jobs', data); return postReq('/api/v1/jobs', data);
} }
......
export default {
data() {
return {
type: 0,
form: {},
};
},
computed: {
isAdd() {
return this.type === 0;
},
isEdit() {
return this.type === 1;
},
isView() {
return this.type === 2;
},
},
methods: {
async submit() {
await this.$refs.DrawerForm.validate();
if (this.isAdd) {
return this?.add();
}
if (this.isEdit) {
return this?.edit();
}
},
setData(data, type) {
this.form = data;
this.type = type;
},
},
};
...@@ -30,13 +30,12 @@ ...@@ -30,13 +30,12 @@
<!-- 新增 --> <!-- 新增 -->
<a-drawer <a-drawer
:title="addBtn.title || '新建'" :title="title"
placement="right" placement="right"
:visible="addVisible" :visible="addVisible"
@close="addDrawerClose" @close="addDrawerClose"
v-if="addBtn" v-if="addBtn"
:maskClosable="!!addBtn.maskClosable" :maskClosable="!!addBtn.maskClosable"
:closable="false"
:drawerStyle="drawerStyle" :drawerStyle="drawerStyle"
:bodyStyle="bodyStyle" :bodyStyle="bodyStyle"
:width="addBtn.width || 600" :width="addBtn.width || 600"
...@@ -44,7 +43,7 @@ ...@@ -44,7 +43,7 @@
> >
<div class="tw-overflow-y-hidden"> <div class="tw-overflow-y-hidden">
<div class="tw-overflow-y-auto tw-h-full"> <div class="tw-overflow-y-auto tw-h-full">
<slot name="add" /> <slot name="drawer" />
</div> </div>
</div> </div>
<a-divider /> <a-divider />
...@@ -78,6 +77,7 @@ export default { ...@@ -78,6 +77,7 @@ export default {
pageSize: 10, pageSize: 10,
}; };
return { return {
title: '新增',
data: [], data: [],
queryForm: { queryForm: {
...this.initQuery, ...this.initQuery,
...@@ -147,7 +147,19 @@ export default { ...@@ -147,7 +147,19 @@ export default {
} }
this.submitLoading = false; this.submitLoading = false;
}, },
showAdd() { show({ type, title } = {}) {
if (type === 0) {
this.title = '新增';
}
if (type === 1) {
this.title = '编辑';
}
if (type === 2) {
this.title = '查看';
}
if (title) {
this.title = title;
}
this.addVisible = true; this.addVisible = true;
}, },
}, },
......
<template> <template>
<my-table url="/api/v1/jobs" rowKey="jobId" :addBtn="addBtn" ref="table"> <my-table url="/api/v1/jobs" rowKey="jobId" :addBtn="addBtn" ref="table" noPage>
<template #add> <template #drawer>
<Form ref="form" /> <Form ref="form" />
</template> </template>
<template #search="{ query }"> <!-- <template #search="{ query }">
<a-form-model-item label="名称"> <a-form-model-item label="名称">
<a-input v-model="query.jobName" /> <a-input v-model="query.jobName" />
</a-form-model-item> </a-form-model-item>
</template> </template> -->
<a-table-column title="名称" data-index="jobName" /> <a-table-column title="名称" data-index="jobName" />
<a-table-column title="描述" data-index="jobDescription" /> <a-table-column title="描述" data-index="jobDescription" />
<a-table-column title="操作"> <a-table-column title="操作">
<template #default="row"> <template #default="row">
<a @click="() => view(row)">编辑</a> <a @click="() => view(row, 1)">编辑</a>
<a-divider type="vertical" /> <a-divider type="vertical" />
<PopconfirmDelete :url="`/api/v1/roles/${row.roleId}`" :cb="refreshTable" /> <PopconfirmDelete :url="`/api/v1/jobs/${row.jobId}`" :cb="refreshTable" />
</template> </template>
</a-table-column> </a-table-column>
</my-table> </my-table>
...@@ -35,9 +35,9 @@ export default { ...@@ -35,9 +35,9 @@ export default {
this.$refs['table']?.getData(); this.$refs['table']?.getData();
}, },
view(data, type) { view(data, type) {
this.$refs['table']?.showAdd(); this.$refs['table']?.show({ type });
this.$nextTick(() => { this.$nextTick(() => {
this.$refs['form'].setData(data, type); this.$refs['form'].setData({ ...data }, type);
}); });
}, },
}, },
......
<template> <template>
<a-form-model layout="vertical" :model="form" :rules="rules"> <a-form-model layout="vertical" :model="form" :rules="rules" ref="DrawerForm">
<a-form-model-item label="名称"> <a-form-model-item label="名称" prop="jobName">
<a-input v-model="form.jobName" :disabled="isView" /> <a-input v-model="form.jobName" :disabled="isView" />
</a-form-model-item> </a-form-model-item>
<a-form-model-item label="描述"> <a-form-model-item label="描述" prop="jobDescription">
<a-textarea v-model="form.jobDescription" :disabled="isView" :rows="4" /> <a-textarea v-model="form.jobDescription" :disabled="isView" :rows="4" />
</a-form-model-item> </a-form-model-item>
</a-form-model> </a-form-model>
...@@ -11,38 +11,25 @@ ...@@ -11,38 +11,25 @@
<script> <script>
import JobsApi from '@/api/organization'; import JobsApi from '@/api/organization';
import FormMixin from '@/components/FormMixin';
export default { export default {
mixins: [FormMixin],
data() { data() {
return { return {
type: 0, rules: {
form: {}, jobName: [{ required: true, message: 'Please select Activity zone', trigger: 'change' }],
rules: {}, jobDescription: [
checkedKeys: [], { required: true, message: 'Please select Activity zone', trigger: 'change' },
}; ],
},
computed: {
isAdd() {
return this.type === 0;
},
isEdit() {
return this.type === 1;
},
isView() {
return this.type === 2;
}, },
};
}, },
methods: { methods: {
submit() { add() {
if (this.isEdit) {
return JobsApi.add({ ...this.form }); return JobsApi.add({ ...this.form });
}
if (this.isAdd) {
return JobsApi.update({ ...this.form });
}
}, },
setData(data, type) { edit() {
this.form = data; return JobsApi.update({ ...this.form });
this.type = type;
}, },
}, },
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment