123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <template>
- <div class="pageWrap bgc">
- <div class="content-warp flex-column-page-wrap">
- <!-- 公用搜索组件 -->
- <LeSearchForm ref="searchForm" v-model:searchData="searchData" :forms="forms" :loading="tableOpts.options.loading"></LeSearchForm>
- <!-- LeTable 组件使用 -->
- <LeTable
- ref="tableRef"
- v-model:searchParams="tableOpts.searchParams"
- v-bind="tableOpts"
- v-model:curRow="tableOpts.curRow"
- v-model:checked-options="checkedColumns"
- :columns="activeColumns"
- >
- <template #toolLeft>
- <el-button type="primary" @click="addHandler">
- <el-icon class="btn-icon">
- <Plus />
- </el-icon>
- </el-button>
- <el-button type="danger" :disabled="curSelectionRows.length === 0" @click="batch_del">
- <el-icon class="btn-icon">
- <Delete />
- </el-icon>
- </el-button>
- <el-button type="primary" plain :disabled="!curSelectionRows.length || curSelectionRows.length !== 1" @click="visiblePermission = true"
- >权限设置
- </el-button>
- </template>
- <template #statusSlot="scope">
- <status-indicator v-if="scope.row.status === 1" pulse type="success"></status-indicator>
- <status-indicator v-else pulse type="danger"></status-indicator>
- </template>
- <template #actionSlot="scope">
- <el-tooltip content="编辑" placement="bottom" effect="light">
- <el-icon class="ibt0" @click="table_edit(scope.row)">
- <Edit />
- </el-icon>
- </el-tooltip>
- <el-divider direction="vertical"></el-divider>
- <el-popconfirm title="确定删除吗?" @confirm="table_del(scope.row)">
- <template #reference>
- <el-icon class="ibt0">
- <Delete />
- </el-icon>
- </template>
- </el-popconfirm>
- </template>
- </LeTable>
- </div>
- <LeFormConfigDialog
- v-if="visible"
- ref="dialogUserRef"
- v-model="visible"
- :title="`${isCreate ? '新增' : '编辑'}角色`"
- width="600px"
- :form-data="activeData"
- :form-options="formOptions"
- @submit="submitHandler"
- />
- <!-- 权限设置 -->
- <Permission
- v-if="visiblePermission"
- v-model="visiblePermission"
- :role-id="curSelectionRows.map(item => item.id).join(',')"
- @closed="visiblePermission = false"
- />
- </div>
- </template>
- <script lang="tsx" setup>
- import role from '@/api/system/role'
- import { computed, nextTick, ref, watch } from 'vue'
- import { ElMessage, ElMessageBox, ElTree } from 'element-plus'
- import { useTablePage } from '@/hooks/useTablePage'
- import { Plus, Delete } from '@element-plus/icons-vue'
- import StatusIndicator from '@/components/StatusIndicator'
- import Permission from './permission.vue'
- const visible = ref(false) // 弹窗显示隐藏
- const isCreate = ref(true)
- const visiblePermission = ref(false) // 权限设置弹窗显示隐藏
- const activeData = ref({})
- const formsDialog = [
- {
- prop: 'name',
- label: '角色名称',
- itemType: 'input',
- rules: [{ required: true, message: '请输入角色名称', trigger: 'blur' }]
- },
- {
- prop: 'alias',
- label: '角色别名',
- itemType: 'input',
- rules: [{ required: true, message: '请输入角色别名', trigger: 'blur' }]
- },
- {
- prop: 'sort',
- label: '排序',
- itemType: 'inputNumber',
- rules: [{ required: true, message: '请输入排序', trigger: 'blur' }]
- },
- {
- prop: 'status',
- label: '状态',
- itemType: 'switch',
- activeText: '是',
- inactiveText: '否'
- },
- {
- prop: 'remark',
- label: '备注',
- itemType: 'input'
- }
- ]
- // 新增的表单 和 编辑的表单
- const formOptions = computed(() => {
- return {
- forms: formsDialog,
- labelWidth: 120,
- span: 30,
- showResetBtn: true,
- formConfig: {
- showCancelBtn: true,
- submitLoading: false
- }
- }
- })
- const groupFilterText = ref('')
- const treeRef = ref<InstanceType<typeof ElTree>>()
- // 表格搜索条件
- const forms = ref([
- {
- prop: 'keyword',
- label: '角色名称:',
- itemType: 'input',
- placeholder: '请输入角色名称'
- },
- {
- prop: 'status',
- label: '状态:',
- itemType: 'select',
- placeholder: '请选择状态',
- options: [
- {
- label: '禁用',
- value: 0
- },
- {
- label: '正常',
- value: 1
- }
- ]
- }
- ])
- // table列表数据请求
- const queryList = async () => {
- const { options, searchParams } = tableOpts
- options.loading = true
- try {
- const { records: list, total } = await role.rolePageApi(searchParams)
- tableOpts.total = total
- tableOpts.list = list
- } catch {
- console.log('获取列表数据失败')
- tableOpts.total = 0
- tableOpts.list = []
- options.loading = false // 更改加载中的 loading值
- } finally {
- options.loading = false
- }
- }
- // table 参数
- const columns = [
- {
- prop: 'name',
- label: '角色名称',
- minWidth: 80
- },
- {
- prop: 'status',
- label: '状态',
- minWidth: 50,
- slots: {
- default: 'statusSlot'
- }
- },
- {
- prop: 'alias',
- label: '别名',
- minWidth: 100
- },
- {
- prop: 'remark',
- label: '备注',
- minWidth: 100
- },
- {
- prop: 'sort',
- label: '排序',
- minWidth: 80
- },
- {
- prop: 'updateBy',
- label: '修改人',
- minWidth: 100
- },
- {
- prop: 'updateTime',
- label: '修改时间',
- minWidth: 126
- },
- {
- prop: 'createBy',
- label: '创建人',
- minWidth: 100
- },
- {
- prop: 'createTime',
- label: '创建时间',
- minWidth: 126
- },
- {
- prop: 'action',
- label: '操作',
- width: 100,
- fixed: 'right',
- slots: {
- default: 'actionSlot'
- }
- }
- ]
- const { searchData, tableOpts, checkedColumns, activeColumns, curSelectionRows, updateParams } = useTablePage(
- {
- options: {
- showIndex: false
- },
- // 需要展示的列
- columns,
- // 控制列配置
- columnsConfig: {
- columns
- }
- },
- {
- queryList,
- fetchImmediate: false
- }
- )
- // 删除
- const deleteItem = async ids => {
- // try {
- await role.roleDeleteApi(ids)
- ElMessage.success(`删除成功~`)
- updateParams()
- // } catch (e) {
- // console.log('删除失败')
- // ElMessage.error(`删除失败~`)
- // }
- }
- // 单个删除
- const table_del = row => {
- deleteItem([row.id])
- }
- //批量删除
- const batch_del = () => {
- const ids = curSelectionRows.value.map(item => item.id) // 多选数据
- ElMessageBox.confirm('是否删除选中数据?', '提示', {
- confirmButtonText: '确认',
- cancelButtonText: '取消',
- type: 'error',
- buttonSize: 'default'
- }).then(() => {
- deleteItem(ids)
- })
- }
- const table_edit = async row => {
- isCreate.value = false
- activeData.value = { ...row, status: row.status ? true : false }
- visible.value = true
- }
- // 弹窗事件
- const submitHandler = async params => {
- formOptions.value.formConfig.submitLoading = true
- try {
- params.status = params.status ? 1 : 0
- params.id = activeData.value.id ? activeData.value.id : null
- await role.roleSaveApi(params)
- ElMessage.success(`${isCreate.value ? '新增' : '修改'}成功~`)
- visible.value = false
- updateParams()
- formOptions.value.formConfig.submitLoading = false
- } catch (e) {
- console.log(e)
- formOptions.value.formConfig.submitLoading = false
- }
- }
- const addHandler = () => {
- isCreate.value = true
- activeData.value = {}
- visible.value = true
- }
- nextTick(() => {
- queryList()
- })
- watch(groupFilterText, val => {
- treeRef.value!.filter(val)
- })
- </script>
|