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

177 lines
4.2 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>
2022-05-24 17:12:00 +08:00
<!-- <n-button type="primary" @click="deleteUsers"> 删除 </n-button> -->
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
<!-- 新增编辑弹窗 -->
2022-05-24 17:12:00 +08:00
<user-modal v-if="data.modalShow" v-model:visible="data.modalShow" :row="rowData" :title="modalTitle" />
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 17:12:00 +08:00
import { h, unref, ref } 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: 'type',
align: 'center',
width: 100
},
{
title: '角色',
key: 'roles',
2022-05-24 16:59:37 +08:00
align: 'center',
render(row) {
return h(TableTags, {
data: row.roles
})
}
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 16:52:14 +08:00
const modalTitle = ref('添加用户')
let rowData = reactive({})
// 打开编辑弹窗
2022-05-18 17:35:46 +08:00
function play(row) {
2022-05-24 16:52:14 +08:00
rowData = row
modalTitle.value = '编辑用户'
console.log('编辑弹窗内容:', row)
data.modalShow = true
2022-05-18 17:35:46 +08:00
}
2022-05-23 10:52:21 +08:00
const params = reactive({
2022-05-24 16:59:37 +08:00
name: ''
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() {
rowData = {}
modalTitle.value = '添加用户'
data.modalShow = true
}
2022-05-18 17:35:46 +08:00
2022-05-24 16:52:14 +08:00
return { data, loadDataTable, handleUser, rowData, modalTitle }
2022-05-24 17:19:33 +08:00
},
methods: {
// 批量删除用户
deleteUsers() {
},
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>