FlowBL/src/views/system/dict/index.vue

217 lines
6.1 KiB
Vue
Raw Normal View History

<template>
<!-- 搜索工作栏 -->
2023-03-19 16:48:27 +08:00
<content-wrap>
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
2023-03-19 16:48:27 +08:00
<el-form-item label="字典名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入字典名称"
clearable
style="width: 240px"
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="字典类型" prop="type">
<el-input
v-model="queryParams.type"
placeholder="请输入字典类型"
clearable
style="width: 240px"
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select
v-model="queryParams.status"
placeholder="字典状态"
clearable
style="width: 240px"
>
<el-option
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="parseInt(dict.value)"
:label="dict.label"
:value="dict.value"
/>
2023-03-19 16:48:27 +08:00
</el-select>
</el-form-item>
<el-form-item label="创建时间" prop="createTime">
<el-date-picker
v-model="queryParams.createTime"
style="width: 240px"
value-format="yyyy-MM-dd HH:mm:ss"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button type="primary" @click="openModal('create')" v-hasPermi="['system:dict:create']">
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button
type="success"
plain
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['system:dict:export']"
>
<Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
</el-form-item>
</el-form>
</content-wrap>
2023-03-19 16:48:27 +08:00
<!-- 列表 -->
<content-wrap>
2023-03-19 16:48:27 +08:00
<el-table v-loading="loading" :data="list">
<el-table-column label="字典编号" align="center" prop="id" />
<el-table-column label="字典名称" align="center" prop="name" show-overflow-tooltip />
<el-table-column label="字典类型" align="center" prop="type" width="300" />
2023-03-19 16:48:27 +08:00
<el-table-column label="状态" align="center" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template>
2023-03-19 16:48:27 +08:00
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column
label="创建时间"
:formatter="dateFormatter"
align="center"
prop="createTime"
width="180"
/>
2023-03-19 16:48:27 +08:00
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button
link
type="primary"
2023-03-19 16:48:27 +08:00
@click="openModal('update', scope.row.id)"
v-hasPermi="['system:dict:update']"
>
修改
</el-button>
<router-link :to="'/dict/type/data/' + scope.row.type">
<el-button link type="primary">数据</el-button>
</router-link>
<el-button
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['system:dict:delete']"
2023-03-19 16:48:27 +08:00
>
删除
</el-button>
2023-03-19 16:48:27 +08:00
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
2023-03-19 16:48:27 +08:00
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</content-wrap>
2023-03-19 16:48:27 +08:00
<!-- 表单弹窗添加/修改 -->
<dict-type-form ref="modalRef" @success="getList" />
</template>
2023-03-19 16:48:27 +08:00
<script setup lang="ts" name="Dict">
2023-03-19 16:48:27 +08:00
import { getDictOptions, DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import * as DictTypeApi from '@/api/system/dict/dict.type'
2023-03-19 16:48:27 +08:00
import DictTypeForm from './form.vue'
import download from '@/utils/download'
const message = useMessage() // 消息弹窗
2023-03-19 16:48:27 +08:00
const { t } = useI18n() // 国际化
2023-03-19 16:48:27 +08:00
const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 字典表格数据
const queryParams = reactive({
2023-03-19 16:48:27 +08:00
pageNo: 1,
pageSize: 10,
name: '',
type: '',
status: undefined,
createTime: []
})
2023-03-19 16:48:27 +08:00
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中
/** 查询字典类型列表 */
const getList = async () => {
loading.value = true
try {
const data = await DictTypeApi.getDictTypePage(queryParams)
2023-03-19 16:48:27 +08:00
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
2023-03-19 16:48:27 +08:00
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
2023-03-19 16:48:27 +08:00
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
2023-03-19 16:48:27 +08:00
/** 添加/修改操作 */
const modalRef = ref()
const openModal = (type: string, id?: number) => {
modalRef.value.openModal(type, id)
}
2023-03-19 16:48:27 +08:00
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
// 删除的二次确认
await message.delConfirm()
// 发起删除
await DictTypeApi.deleteDictType(id)
2023-03-19 16:48:27 +08:00
message.success(t('common.delSuccess'))
// 刷新列表
await getList()
} catch {}
}
2023-03-19 16:48:27 +08:00
/** 导出按钮操作 */
const handleExport = async () => {
try {
// 导出的二次确认
await message.exportConfirm()
// 发起导出
exportLoading.value = true
const data = await DictTypeApi.exportDictType(queryParams)
2023-03-19 16:48:27 +08:00
download.excel(data, '字典类型.xls')
} catch {
} finally {
exportLoading.value = false
}
}
2023-03-19 16:48:27 +08:00
/** 初始化 **/
onMounted(() => {
getList()
})
</script>