restructure/src/views/system/user/index.vue

185 lines
4.4 KiB
Vue
Raw Normal View History

2022-05-18 17:35:46 +08:00
<template>
<div>
2022-05-23 10:52:21 +08:00
<n-card>
<data-table
:columns="data.columns"
:row-key="(row) => row.id"
:request="loadDataTable"
size="large"
>
<template #tableTitle>
2022-05-24 16:52:14 +08:00
<n-button type="primary" @click="handleUser"> 新建 </n-button>
<n-popconfirm
@positive-click="handlePositiveClick"
@negative-click="handleNegativeClick"
>
<n-button type="primary" @click="deleteUsers"> 删除 </n-button>
</n-popconfirm>
2022-05-23 10:52:21 +08:00
</template>
</data-table>
</n-card>
2022-05-18 17:35:46 +08:00
</div>
2022-05-24 16:52:14 +08:00
<!-- 新增编辑弹窗 -->
<user-modal v-if="data.modalShow" v-model:visible="data.modalShow" :row="rowData" @done="loadDataTable" />
2022-05-18 17:35:46 +08:00
</template>
<script>
import dataTable from '@/components/DataTable/index.vue'
import TableAction from '@/components/DataTable/tools/Action.vue'
import TableImage from '@/components/DataTable/tools/Image.vue'
2022-05-24 16:59:37 +08:00
import TableTags from '@/components/DataTable/tools/Tags.vue'
2022-05-23 10:52:21 +08:00
import { getUserList } from '@/api/system/user/index.js'
2022-05-24 18:02:23 +08:00
import { h, unref, toRefs } from 'vue'
2022-05-18 17:35:46 +08:00
import { reactive } from 'vue'
2022-05-24 16:52:14 +08:00
import UserModal from './components/UserModal.vue'
2022-05-18 17:35:46 +08:00
export default {
name: 'MenuPage',
2022-05-24 16:52:14 +08:00
components: { dataTable, UserModal },
2022-05-18 17:35:46 +08:00
setup() {
const data = reactive({
columns: [
{
title: '用户编号',
key: 'code',
align: 'center'
},
{
title: '头像',
key: 'avatar',
align: 'center',
render(row) {
return h(TableImage, {
images: {
width: 36,
height: 36,
2022-05-24 16:52:14 +08:00
src: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQiKrYt-fEfJ4SZhF9KfLLaX9f15KV6Ve1ptA&usqp=CAU'
2022-05-18 17:35:46 +08:00
}
})
}
},
{
title: '用户账号',
key: 'username',
align: 'center'
},
{
title: '用户姓名',
key: 'realname',
align: 'center'
},
{
title: '角色',
key: 'roles',
2022-05-24 16:59:37 +08:00
align: 'center',
render(row) {
return h(TableTags, {
2022-05-24 18:02:23 +08:00
data: row.roles,
rowKey: 'name'
// filters: [
// {
// key: '管理员',
// label: '123',
// color: {
// textColor: 'red'
// }
// }
// ]
2022-05-24 16:59:37 +08:00
})
}
2022-05-18 17:35:46 +08:00
},
{
title: '状态',
key: 'status',
align: 'center',
width: 100
},
{
title: '部门',
key: 'deptName',
align: 'center'
},
{
title: '创建时间',
key: 'createTime',
align: 'center',
width: 160
},
{
title: '更新时间',
key: 'updateTime',
align: 'center',
width: 160
},
{
title: '操作',
align: 'center',
width: 150,
fixed: 'right',
render(row) {
return h(TableAction, {
actions: [
{
2022-05-24 16:52:14 +08:00
label: '修改',
2022-05-18 17:35:46 +08:00
type: 'button',
props: {
type: 'primary',
onClick: play.bind(null, row)
},
auth: 'basic_list'
},
{
label: '删除',
type: 'popconfirm',
auth: 'basic_list'
}
],
align: 'center'
})
}
}
],
2022-05-24 16:52:14 +08:00
modalShow: false
2022-05-18 17:35:46 +08:00
})
2022-05-24 18:02:23 +08:00
const modalData = reactive({
rowData: {}
})
2022-05-24 16:52:14 +08:00
// 打开编辑弹窗
2022-05-18 17:35:46 +08:00
function play(row) {
2022-05-24 18:02:23 +08:00
modalData.rowData = row
2022-05-24 16:52:14 +08:00
data.modalShow = true
2022-05-18 17:35:46 +08:00
}
2022-05-23 10:52:21 +08:00
const params = reactive({
2022-05-25 14:38:40 +08:00
page: 1,
limit: 10
2022-05-23 10:52:21 +08:00
})
const loadDataTable = async(res) => {
const _params = {
...unref(params),
...res
}
return await getUserList(_params)
}
2022-05-24 16:52:14 +08:00
function handleUser() {
2022-05-24 18:02:23 +08:00
modalData.rowData = {}
2022-05-24 16:52:14 +08:00
data.modalShow = true
}
2022-05-18 17:35:46 +08:00
2022-05-24 18:02:23 +08:00
return { data, loadDataTable, handleUser, ...toRefs(modalData) }
2022-05-24 17:19:33 +08:00
},
methods: {
// 批量删除用户
deleteUsers() {
2022-05-24 18:02:23 +08:00
}
2022-05-24 17:19:33 +08:00
2022-05-18 17:35:46 +08:00
}
}
</script>
<style scoped lang='scss'>
2022-05-23 10:52:21 +08:00
.n-button + .n-button {
margin-left: 10px;
2022-05-18 17:35:46 +08:00
}
</style>