123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- <!--字典类型-->
- <script setup lang="ts">
- import {
- getDictTypePage,
- getDictTypeForm,
- addDictType,
- updateDictType,
- deleteDictTypes,
- } from "@/api/system/dict";
- import { DictTypePageVO, DictTypeQuery, DictTypeForm } from "@/api/system/dict/types";
- import ButtonPermKeys from "@/common/configs/buttonPermission";
- defineOptions({
- name: "DictType",
- inheritAttrs: false,
- });
- const queryFormRef = ref(ElForm);
- const dataFormRef = ref(ElForm);
- const loading = ref(false);
- const ids = ref<number[]>([]);
- const total = ref(0);
- const queryParams = reactive<DictTypeQuery>({
- pageNo: 1,
- pageSize: 10,
- });
- const dictTypeList = ref<DictTypePageVO[]>();
- const dialog = reactive({
- title: "",
- visible: false,
- });
- const formData = reactive<DictTypeForm>({
- state: 1,
- type: "0",
- });
- const rules = reactive({
- dictName: [
- { required: true, message: "请输入字典类型名称", trigger: "blur" },
- ],
- dictType: [
- { required: true, message: "请输入字典类型编码", trigger: "blur" },
- ],
- });
- /** 查询 */
- function handleQuery() {
- loading.value = true;
- getDictTypePage(queryParams)
- .then(({ data }) => {
- dictTypeList.value = data.records;
- total.value = data.totalCount;
- })
- .finally(() => {
- loading.value = false;
- });
- }
- /**
- * 重置查询
- */
- function resetQuery() {
- queryFormRef.value.resetFields();
- queryParams.pageNo = 1;
- handleQuery();
- }
- /** 行复选框选中 */
- function handleSelectionChange(selection: any) {
- ids.value = selection.map((item: any) => item.id);
- }
- /**
- * 打开字典类型表单弹窗
- *
- * @param dicTypeId 字典类型ID
- */
- function openDialog(row?: any) {
- dialog.visible = true;
- console.log(row);
- if (row) {
- dialog.title = "修改字典类型";
- Object.assign(formData, row);
- } else {
- formData.id = null;
- formData.dictName = "";
- formData.dictType = "";
- formData.remark = "";
- dialog.title = "新增字典类型";
- }
- }
- /** 字典类型表单提交 */
- function handleSubmit() {
- dataFormRef.value.validate((isValid: boolean) => {
- if (isValid) {
- const dictTypeId = formData.id;
- if (dictTypeId) {
- updateDictType(formData)
- .then(() => {
- ElMessage.success("修改成功");
- closeDialog();
- handleQuery();
- })
- .finally(() => (loading.value = false));
- } else {
- addDictType(formData)
- .then(() => {
- ElMessage.success("新增成功");
- closeDialog();
- handleQuery();
- })
- .finally(() => (loading.value = false));
- }
- }
- });
- }
- /** 关闭字典类型弹窗 */
- function closeDialog() {
- dialog.visible = false;
- resetForm();
- }
- /** 重置字典类型表单 */
- function resetForm() {
- dataFormRef.value.resetFields();
- dataFormRef.value.clearValidate();
- formData.id = undefined;
- formData.state = 1;
- }
- /** 删除字典类型 */
- function handleDelete(dictTypeId?: number) {
- const dictTypeIds = [dictTypeId || ids.value].join(",");
- if (!dictTypeIds) {
- ElMessage.warning("请勾选删除项");
- return;
- }
- ElMessageBox.confirm("确认删除已选中的数据项?", "警告", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- }).then(() => {
- deleteDictTypes(dictTypeIds).then(() => {
- ElMessage.success("删除成功");
- resetQuery();
- });
- });
- }
- const dictDataDialog = reactive({
- title: "",
- visible: false,
- });
- const selectedDictType = reactive({ typeCode: "", typeName: "" }); // 当前选中的字典类型
- /** 打开字典数据弹窗 */
- function openDictDialog(row: DictTypeForm) {
- dictDataDialog.visible = true;
- dictDataDialog.title = "【" + row.dictName + "】字典数据";
- selectedDictType.typeCode = row.dictType + "";
- selectedDictType.typeName = row.dictName + "";
- }
- /** 关闭字典数据弹窗 */
- function closeDictDialog() {
- dictDataDialog.visible = false;
- }
- onMounted?.(() => {
- handleQuery();
- });
- </script>
- <template>
- <div class="app-container">
- <div class="search-container">
- <el-form ref="queryFormRef" :model="queryParams" :inline="true">
- <el-form-item label="关键字" prop="name">
- <el-input
- v-model="queryParams.keywords"
- placeholder="字典类型名称/编码"
- clearable
- @keyup.enter="handleQuery"
- />
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="handleQuery()"
- ><i-ep-search />搜索</el-button
- >
- <el-button @click="resetQuery()"><i-ep-refresh />重置</el-button>
- </el-form-item>
- </el-form>
- </div>
- <el-card shadow="never" class="table-container">
- <template #header>
- <el-button
- v-hasPerm="[ButtonPermKeys.SYSTEM.BTNS.dictType_add]"
- type="success"
- @click="openDialog()"
- ><i-ep-plus />新增</el-button
- >
- <!-- <el-button
- type="danger"
- :disabled="ids.length === 0"
- @click="handleDelete()"
- ><i-ep-delete />删除</el-button
- > -->
- </template>
- <el-table
- v-loading="loading"
- highlight-current-row
- :data="dictTypeList"
- border
- @selection-change="handleSelectionChange"
- >
- <!-- <el-table-column type="selection" width="55" align="center" /> -->
- <el-table-column label="字典类型名称" prop="dictName" width="200" />
- <el-table-column label="字典类型编码" prop="dictType" width="200" />
- <el-table-column label="状态" align="center" width="100">
- <template #default="scope">
- <el-tag v-if="scope.row.state === 1" type="success">启用</el-tag>
- <el-tag v-else type="info">禁用</el-tag>
- </template>
- </el-table-column>
- <el-table-column label="备注" prop="remark" align="center" />
- <el-table-column fixed="right" label="操作" align="center" width="220">
- <template #default="scope">
- <el-button
- type="primary"
- link
- size="small"
- @click.stop="openDictDialog(scope.row)"
- ><i-ep-Collection />字典数据</el-button
- >
- <el-button
- v-hasPerm="[ButtonPermKeys.SYSTEM.BTNS.dictType_edit]"
- type="primary"
- link
- size="small"
- @click.stop="openDialog(scope.row)"
- ><i-ep-edit />编辑</el-button
- >
- <!-- <el-button
- v-hasPerm="[ButtonPermKeys.SYSTEM.BTNS.dictType_del]"
- type="primary"
- link
- size="small"
- @click.stop="handleDelete(scope.row.id)"
- ><i-ep-delete />删除</el-button
- >-->
- </template>
- </el-table-column>
- </el-table>
- <pagination
- v-if="total > 0"
- v-model:total="total"
- v-model:page="queryParams.pageNo"
- v-model:limit="queryParams.pageSize"
- @pagination="handleQuery"
- />
- </el-card>
- <el-dialog
- v-model="dialog.visible"
- :title="dialog.title"
- width="500px"
- @close="closeDialog"
- >
- <el-form
- ref="dataFormRef"
- :model="formData"
- :rules="rules"
- label-width="80px"
- >
- <el-form-item label="字典名称" prop="dictName">
- <el-input v-model="formData.dictName" placeholder="请输入字典名称" />
- </el-form-item>
- <el-form-item label="字典编码" prop="dictType">
- <el-input
- v-model="formData.dictType"
- v-if="formData.id"
- placeholder="请输入字典编码 sys_test user_test"
- />
- <el-input
- v-model="formData.dictType"
- v-if="!formData.id"
- placeholder="请输入字典编码 sys_test user_test"
- />
- </el-form-item>
- <el-form-item label="状态" prop="state">
- <el-radio-group v-model="formData.state">
- <el-radio :value="1">正常</el-radio>
- <el-radio :value="0">停用</el-radio>
- </el-radio-group>
- </el-form-item>
- <!-- <el-form-item label="字典类别" prop="type">
- <el-radio-group v-model="formData.type">
- <el-radio value="0">用户字典</el-radio>
- <el-radio value="1">系统字典</el-radio>
- </el-radio-group>
- </el-form-item>-->
- <el-form-item label="备注" prop="remark">
- <el-input
- v-model="formData.remark"
- type="textarea"
- placeholder="字典类型备注"
- :autosize="{ minRows: 2, maxRows: 4 }"
- />
- </el-form-item>
- </el-form>
- <template #footer>
- <div class="dialog-footer">
- <el-button type="primary" @click="handleSubmit">确 定</el-button>
- <el-button @click="closeDialog">取 消</el-button>
- </div>
- </template>
- </el-dialog>
- <!--字典数据弹窗-->
- <el-dialog
- v-model="dictDataDialog.visible"
- :title="dictDataDialog.title"
- width="1000px"
- @close="closeDictDialog"
- >
- <dict-item
- v-model:typeCode="selectedDictType.typeCode"
- v-model:typeName="selectedDictType.typeName"
- />
- </el-dialog>
- </div>
- </template>
|