Commit 9d64bffd authored by 陈浩玮's avatar 陈浩玮

代码调整

parent 41fec57a
......@@ -50,20 +50,38 @@ export default {
},
row: Object,
},
watch: {
row() {
this.init();
},
},
data() {
return {
buttonsArr: [],
};
},
created() {
this.init();
},
computed: {
basicBtns() {
return this.buttons.length > 3 ? this.buttons.slice(0, 3) : this.buttons;
return this.buttonsArr.length > 3 ? this.buttonsArr.slice(0, 3) : this.buttonsArr;
},
moreBtns() {
return this.buttons.length > 3 ? this.buttons.slice(3) : [];
return this.buttonsArr.length > 3 ? this.buttonsArr.slice(3) : [];
},
},
methods: {
getDelUrl(url, row) {
if (isFunction(url)) return url(row);
return url;
},
init() {
this.buttons.map((i) => {
i.__hidden__ = i.isHidden && i.isHidden(this.row);
});
this.buttonsArr = this.buttons.filter((i) => !i.__hidden__);
},
},
};
</script>
......@@ -6,11 +6,11 @@
<script>
import { EMPTY_FUN } from '@/utils';
import { delReq } from '@/utils';
import { delReq, getReq, postReq, putReq } from '@/utils';
export default {
props: {
url: String,
url: [String, Object],
cb: {
type: Function,
default: EMPTY_FUN,
......@@ -30,9 +30,25 @@ export default {
},
methods: {
async confirm() {
if (this.url) {
if (typeof this.url === 'string') {
await delReq(this.url);
}
if (typeof this.url === 'object') {
switch (this.url.method) {
case 'get':
await getReq(this.url.url, this.url?.data);
break;
case 'post':
await postReq(this.url.url, this.url?.data);
break;
case 'put':
await putReq(this.url.url, this.url?.data);
break;
case 'del':
await delReq(this.url.url, this.url?.data);
break;
}
}
if (this.onOk) {
await this.onOk();
}
......
......@@ -20,9 +20,7 @@
<a-button v-if="addBtn" type="primary" key="add" v-bind="addBtn.options" @click="add">
{{ addBtn.text || '新建' }}
</a-button>
<template v-for="btn of buttons">
<a-button :type="btn.primary" :key="btn.text">{{ btn.text }}</a-button>
</template>
<slot name="buttons" />
</a-space>
<div class="tw-mb-2">
<a-alert
......
<template>
<my-table url="/api/v1/users" rowKey="userId" :addBtn="addBtn" ref="table">
<my-table url="/api/v1/users" rowKey="userId" ref="table">
<template #drawer>
<Form ref="form" />
</template>
......@@ -11,6 +11,9 @@
<a-input placeholder="Basic usage" v-model="query.loginId" />
</my-form-item>
</template>
<template #buttons>
<a-button type="primary">新增</a-button>
</template>
<a-table-column title="账号" data-index="loginId" />
<a-table-column title="姓名" data-index="userName" />
......@@ -21,36 +24,91 @@
<a-table-column title="是否锁定" data-index="isLockedName" />
<a-table-column title="操作">
<template #default="row">
<a @click="() => view(row, 1)">编辑</a>
<!-- <a @click="() => view(row, 1)">编辑</a>
<a-divider type="vertical" />
<PopconfirmDelete :url="`/api/v1/jobs/${row.jobId}`" :cb="refreshTable" />
<PopconfirmDelete :url="`/api/v1/jobs/${row.jobId}`" :cb="refreshTable" /> -->
<ActionButton :buttons="buttons" :row="row" />
</template>
</a-table-column>
</my-table>
</template>
<script>
import Form from './form.vue';
import PopconfirmDelete from '@/components/popconfirm_delete/index.vue';
import ActionButton from '@/components/action_button/index.vue';
import OrganizationTree from '../components/OrganizationTree.vue';
export default {
components: { Form, PopconfirmDelete, OrganizationTree },
components: { Form, OrganizationTree, ActionButton },
data() {
return {
addBtn: { width: 600, onOk: () => this.$refs['form']?.submit() },
span: { xs: 12, md: 8, lg: 6 },
buttons: [
{
label: '编辑',
click: (row) => {},
},
{
type: 'confirm',
url: (row) => `/api/v1/jobs/${row.jobId}`,
after: () => this.refreshTable(),
isHidden: (row) => {
return row.userId === 1;
},
},
{
type: 'confirm',
label: '重置',
title: '确认是否重置?',
url: (row) => {
return {
url: `/api/v1/users/${row.userId}/resetting`,
method: 'put',
};
},
after: () => this.refreshTable(),
},
{
type: 'confirm',
label: '解锁',
title: '确认是否解锁?',
url: (row) => {
return {
url: `/api/v1/users/${row.userId}/unlocking`,
method: 'put',
};
},
after: () => this.refreshTable(),
isHidden: (row) => {
return !row.isLocked;
},
},
{
type: 'confirm',
label: '锁定',
title: '确认是否锁定?',
url: (row) => {
return {
url: `/api/v1/users/${row.userId}/locking`,
method: 'put',
};
},
after: () => this.refreshTable(),
isHidden: (row) => {
return !!row.isLocked;
},
},
],
};
},
methods: {
refreshTable() {
this.$refs['table']?.getData();
},
view(data, type) {
this.$refs['table']?.show({ type });
this.$nextTick(() => {
this.$refs['form'].setData({ ...data }, type);
});
},
// view(data, type) {
// this.$refs['table']?.show({ type });
// this.$nextTick(() => {
// this.$refs['form'].setData({ ...data }, type);
// });
// },
},
};
</script>
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