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

234 lines
5.7 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>
2022-05-26 14:57:01 +08:00
<headSearch :info="info" @search="handleSearch" />
2022-05-23 10:52:21 +08:00
<data-table
ref="tableRef"
2022-05-26 14:57:01 +08:00
:columns="columns"
2022-05-23 10:52:21 +08:00
:row-key="(row) => row.id"
:request="loadDataTable"
size="large"
2022-05-25 18:59:04 +08:00
@update:checked-row-keys="handleCheck"
2022-05-23 10:52:21 +08:00
>
<template #tableTitle>
2022-05-26 14:57:01 +08:00
<n-button type="primary" @click="handleModal"> 新建 </n-button>
<n-popconfirm
2022-05-25 18:59:04 +08:00
negative-text="取消"
positive-text="确认"
2022-05-26 14:57:01 +08:00
@positive-click="deleteComplex"
>
2022-05-25 18:59:04 +08:00
<template #trigger>
<n-button type="primary"> 删除 </n-button>
2022-05-25 18:59:04 +08:00
</template>
2022-05-26 14:57:01 +08:00
确认要删除选中数据吗?
</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
<!-- 新增编辑弹窗 -->
2022-05-25 18:59:04 +08:00
<user-modal
2022-05-26 14:57:01 +08:00
v-if="modalShow"
v-model:visible="modalShow"
2022-05-25 18:59:04 +08:00
:row="rowData"
@done="handleSearch"
2022-05-25 18:59:04 +08:00
/>
2022-05-18 17:35:46 +08:00
</template>
<script>
2022-05-25 18:59:04 +08:00
import headSearch from '@/components/Search/index.vue'
2022-05-18 17:35:46 +08:00
import dataTable from '@/components/DataTable/index.vue'
2022-05-26 14:49:07 +08:00
import TableSwitch from '@/components/DataTable/tools/Switch.vue'
import TableAction from '@/components/DataTable/tools/Action.vue'
import { getUserList, resetPassword, deleteUser, setUserStatus } from '@/api/system/user/index.js'
2022-05-26 15:01:25 +08:00
import { h, unref, ref, toRefs, reactive } from 'vue'
2022-05-24 16:52:14 +08:00
import UserModal from './components/UserModal.vue'
2022-05-25 18:59:04 +08:00
import info from './info.js'
import table from './table.js'
2022-05-18 17:35:46 +08:00
export default {
name: 'MenuPage',
2022-05-25 18:59:04 +08:00
components: { dataTable, UserModal, headSearch },
2022-05-18 17:35:46 +08:00
setup() {
const data = reactive({
columns: [
...table.columns,
2022-05-18 17:35:46 +08:00
{
title: '状态',
key: 'status',
align: 'center',
2022-05-25 18:59:04 +08:00
width: 100,
render(row) {
2022-05-26 14:49:07 +08:00
return h(TableSwitch, {
data: { id: row.id, status: row.status },
2022-05-26 14:49:07 +08:00
rowKey: 'status',
checkedValue: 1,
uncheckedValue: 2,
onChange: setStatus.bind(row)
2022-05-25 18:59:04 +08:00
})
}
2022-05-18 17:35:46 +08:00
},
{
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'
},
2022-05-26 14:57:01 +08:00
{
label: '重置密码',
type: 'popconfirm',
auth: 'basic_list',
tip: '确定要重置为123456吗?',
props: {
negativeText: '取消',
positiveText: '确认',
onPositiveClick: resetPsw.bind(null, row.id)
}
},
2022-05-18 17:35:46 +08:00
{
label: '删除',
type: 'popconfirm',
2022-05-25 18:59:04 +08:00
auth: 'basic_list',
2022-05-26 14:57:01 +08:00
tip: '确定删除这条数据吗?',
2022-05-25 18:59:04 +08:00
props: {
negativeText: '取消',
positiveText: '确认',
onPositiveClick: deleteSingle.bind(null, row.id)
2022-05-25 18:59:04 +08:00
}
2022-05-18 17:35:46 +08:00
}
],
align: 'center'
})
}
}
],
2022-05-25 18:59:04 +08:00
info: ref(info),
modalShow: false,
2022-05-24 18:02:23 +08:00
rowData: {}
})
2022-05-24 16:52:14 +08:00
// 打开编辑弹窗
2022-05-18 17:35:46 +08:00
function play(row) {
2022-05-25 18:59:04 +08:00
data.rowData = row
2022-05-24 16:52:14 +08:00
data.modalShow = true
2022-05-18 17:35:46 +08:00
}
const params = ref({})
2022-05-25 18:59:04 +08:00
const tableRef = ref()
function handleSearch(data) {
params.value = {
...data
}
tableRef.value.reFetch({ ...unref(params) })
}
2022-05-23 10:52:21 +08:00
const loadDataTable = async(res) => {
const _params = {
...unref(params),
...res
}
return await getUserList(_params)
}
// 新增
2022-05-26 14:57:01 +08:00
function handleModal() {
2022-05-25 18:59:04 +08:00
data.rowData = {}
2022-05-24 16:52:14 +08:00
data.modalShow = true
}
2022-05-18 17:35:46 +08:00
// 选择表格数据
const selectedIds = ref([])
function handleCheck(rowKeys) {
selectedIds.value = rowKeys
2022-05-25 18:59:04 +08:00
}
2022-05-26 14:57:01 +08:00
// 批量删除
function deleteComplex() {
if (selectedIds.value.length) {
deleteData(selectedIds.value)
} else {
$message.warning('请至少选中一条数据')
}
}
// 单个删除数据
function deleteSingle(id) {
deleteData([id])
2022-05-25 18:59:04 +08:00
}
// 删除用户接口
function deleteData(data) {
deleteUser(data).then((res) => {
if (res.code === 0) {
handleSearch()
2022-05-26 14:57:01 +08:00
$message.success(res.msg)
} else {
2022-05-26 14:57:01 +08:00
$message.error(res.msg)
}
}).catch(e => {
console.log(e)
})
2022-05-25 18:59:04 +08:00
}
2022-05-24 18:02:23 +08:00
2022-05-26 14:57:01 +08:00
// 重置密码
function resetPsw(id) {
resetPassword({ id }).then(res => {
if (res.code === 0) {
handleSearch()
$message.success(res.msg)
} else {
$message.error(res.msg)
}
}).catch(e => {
console.log(e)
})
}
// 设置状态
function setStatus(row) {
setUserStatus({ id: row.data.id, status: row.value }).then(res => {
if (res.code === 0) {
handleSearch()
$message.success(res.msg)
} else {
$message.error(res.msg)
}
}).catch(e => {
console.log(e)
})
2022-05-26 14:57:01 +08:00
}
2022-05-25 18:59:04 +08:00
return {
loadDataTable,
2022-05-26 14:57:01 +08:00
handleModal,
2022-05-25 18:59:04 +08:00
...toRefs(data),
tableRef,
2022-05-25 18:59:04 +08:00
handleSearch,
selectedIds,
2022-05-26 14:57:01 +08:00
deleteComplex,
handleCheck,
deleteData,
resetPsw,
2022-05-26 14:57:01 +08:00
setStatus
2022-05-24 18:02:23 +08:00
}
2022-05-25 18:59:04 +08:00
},
methods: {
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>