Commit 6b10d8fe authored by 水落(YangLei)'s avatar 水落(YangLei)

feat: 完善多按钮的情况

parent 09240bbb
<template> <template>
<a-table-column :title="title"> <div>
<template #default="row"> <span v-for="(btn, index) of basicBtns" :key="btn.label">
<template v-for="btn of basicBtns"> <PopconfirmDelete
<PopconfirmDelete :url="getDelUrl(btn.url, row)"
:url="`/api/v1/roles/${row.roleId}`" v-if="btn.type === 'del'"
:cb="refreshTable" :cb="btn.after"
:key="btn.label" :title="btn.title"
v-if="btn.type === 'del'" />
/> <a v-else @click="() => btn.click(row)">{{ btn.label }}</a>
<a @click="() => btn?.click(row, btn)" :key="btn.label">{{ btn.label }}</a> <a-divider type="vertical" v-if="moreBtns.length || index !== basicBtns.length - 1" />
<a-divider type="vertical" :key="btn.label + 'divider'" /> </span>
</template>
<template v-if="moreBtns.length"> <template v-if="moreBtns.length">
<a-popover> <a-popover>
<template slot="content"> <template slot="content">
<a v-for="btn of moreBtns" :key="btn.label" @click="() => btn?.click(row, btn)"> <a-space direction="vertical">
<a v-for="btn of moreBtns" :key="btn.label" @click="() => btn.click(row)">
{{ btn.label }} {{ btn.label }}
</a> </a>
</template> </a-space>
<a>...</a> </template>
</a-popover> <a>...</a>
</template> </a-popover>
</template> </template>
</a-table-column> </div>
</template> </template>
<script> <script>
import { isFunction } from '@/utils';
import PopconfirmDelete from '@/components/popconfirm_delete/index.vue';
export default { export default {
components: { PopconfirmDelete },
props: { props: {
title: {
type: String,
default: '操作',
},
buttons: { buttons: {
type: Array, type: Array,
default: () => [ default: () => [],
{
label: '查看',
onClick(row) {},
type: 'del',
},
],
}, },
row: Object,
}, },
computed: { computed: {
basicBtns() { basicBtns() {
...@@ -51,5 +48,12 @@ export default { ...@@ -51,5 +48,12 @@ export default {
return this.buttons.length > 3 ? this.buttons.slice(3) : []; return this.buttons.length > 3 ? this.buttons.slice(3) : [];
}, },
}, },
methods: {
getDelUrl(url, row) {
if (isFunction(url)) return url(row);
return url;
},
},
}; };
</script> </script>
<template> <template>
<a-popconfirm title="确认是否删除" ok-text="确认" cancel-text="取消" @confirm="onOk"> <a-popconfirm :title="title" ok-text="确认" cancel-text="取消" @confirm="onOk">
<a>删除</a> <a>删除</a>
</a-popconfirm> </a-popconfirm>
</template> </template>
...@@ -15,11 +15,15 @@ export default { ...@@ -15,11 +15,15 @@ export default {
type: Function, type: Function,
default: EMPTY_FUN, default: EMPTY_FUN,
}, },
title: {
type: String,
default: '确认是否删除',
},
}, },
methods: { methods: {
async onOk() { async onOk() {
await delReq(this.url); await delReq(this.url);
this.cb(); this?.cb();
}, },
}, },
}; };
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<div class="tw-text-right tw-mt-2"> <div class="tw-text-right tw-mt-2">
<a-space> <a-space>
<a-button @click="queryForm = { ...initQuery }">重置</a-button> <a-button @click="queryForm = {}">重置</a-button>
<a-button type="primary" @click="getData">查询</a-button> <a-button type="primary" @click="getData">查询</a-button>
</a-space> </a-space>
</div> </div>
...@@ -79,9 +79,7 @@ export default { ...@@ -79,9 +79,7 @@ export default {
}; };
return { return {
data: [], data: [],
queryForm: { queryForm: {},
...this.initQuery,
},
loading: false, loading: false,
addVisible: false, addVisible: false,
submitLoading: false, submitLoading: false,
...@@ -104,7 +102,6 @@ export default { ...@@ -104,7 +102,6 @@ export default {
}, },
}, },
mounted() { mounted() {
console.log(this.addBtn);
this.getData(); this.getData();
}, },
...@@ -119,13 +116,13 @@ export default { ...@@ -119,13 +116,13 @@ export default {
this.loading = false; this.loading = false;
}, },
async getDataNoPage() { async getDataNoPage() {
const res = await request(this.url, METHOD.GET); const res = await request(this.url, METHOD.GET, this.queryForm);
if (this.formatData) this.data = this.formatData(res); if (this.formatData) this.data = this.formatData(res);
else this.data = res; else this.data = res;
}, },
async getDataWithPage() { async getDataWithPage() {
const res = await request(this.url, METHOD.GET, this.queryForm); const res = await request(this.url, METHOD.GET, { ...this.initQuery, ...this.queryForm });
if (this.formatData) this.data = this.formatData(res); if (this.formatData) this.data = this.formatData(res);
else this.data = res.records; else this.data = res.records;
}, },
......
...@@ -11,7 +11,7 @@ export default { ...@@ -11,7 +11,7 @@ export default {
user: state => { user: state => {
if (!state.user) { if (!state.user) {
try { try {
const user = localStorage.getItem(process.env.VUE_APP_USER_KEY); const user = '{}';
state.user = JSON.parse(user); state.user = JSON.parse(user);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
......
...@@ -4,10 +4,59 @@ ...@@ -4,10 +4,59 @@
<a-table-column title="调度规则" data-index="taskRule" /> <a-table-column title="调度规则" data-index="taskRule" />
<a-table-column title="实现类" data-index="implementClass" /> <a-table-column title="实现类" data-index="implementClass" />
<a-table-column title="说明" data-index="remark" /> <a-table-column title="说明" data-index="remark" />
<a-table-column title="操作" data-index="remark" /> <a-table-column title="操作">
<template #default="row">
<ActionButton :buttons="buttons" :row="row" />
</template>
</a-table-column>
</my-table> </my-table>
</template> </template>
<script> <script>
export default {}; import ActionButton from '@/components/action_button/index.vue';
export default {
components: { ActionButton },
data() {
return {
buttons: [
{
label: '查看',
onClick(row) {},
},
{
label: '编辑',
onClick(row) {},
},
{
type: 'del',
url: row => {
console.log(row);
return 'dassda';
},
after() {
console.log('ddd');
},
},
{
label: 'chakan',
onClick(row) {},
},
{
label: '查看1',
onClick(row) {},
},
{
label: '查看2',
onClick(row) {},
},
{
label: '查看3',
onClick(row) {},
},
],
};
},
};
</script> </script>
...@@ -29,3 +29,5 @@ export function convertListToTree(menuList, filterMenu = false) { ...@@ -29,3 +29,5 @@ export function convertListToTree(menuList, filterMenu = false) {
} }
export function EMPTY_FUN() {} export function EMPTY_FUN() {}
export const isFunction = val => typeof val === 'function';
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