feat(完成地区管理基本功能): ✨ 完成地区管理crud菜单
This commit is contained in:
41
web/src/views/system/areas/api.ts
Normal file
41
web/src/views/system/areas/api.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { request } from '/@/utils/service';
|
||||||
|
import { PageQuery, AddReq, DelReq, EditReq, InfoReq } from '@fast-crud/fast-crud';
|
||||||
|
|
||||||
|
export const apiPrefix = '/api/system/area/';
|
||||||
|
export function GetList(query: PageQuery) {
|
||||||
|
return request({
|
||||||
|
url: apiPrefix,
|
||||||
|
method: 'get',
|
||||||
|
data: query,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export function GetObj(id: InfoReq) {
|
||||||
|
return request({
|
||||||
|
url: apiPrefix + id,
|
||||||
|
method: 'get',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AddObj(obj: AddReq) {
|
||||||
|
return request({
|
||||||
|
url: apiPrefix,
|
||||||
|
method: 'post',
|
||||||
|
data: obj,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UpdateObj(obj: EditReq) {
|
||||||
|
return request({
|
||||||
|
url: apiPrefix + obj.id + '/',
|
||||||
|
method: 'put',
|
||||||
|
data: obj,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DelObj(id: DelReq) {
|
||||||
|
return request({
|
||||||
|
url: apiPrefix + id + '/',
|
||||||
|
method: 'delete',
|
||||||
|
data: { id },
|
||||||
|
});
|
||||||
|
}
|
||||||
169
web/src/views/system/areas/crud.tsx
Normal file
169
web/src/views/system/areas/crud.tsx
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
import * as api from './api';
|
||||||
|
import { dict, PageQuery, AddReq, DelReq, EditReq, CrudExpose, CrudOptions } from '@fast-crud/fast-crud';
|
||||||
|
import { request } from '/@/utils/service';
|
||||||
|
import { dictionary } from '/@/utils/dictionary';
|
||||||
|
interface CreateCrudOptionsTypes {
|
||||||
|
crudOptions: CrudOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const createCrudOptions = function ({ crudExpose }: { crudExpose: CrudExpose }): CreateCrudOptionsTypes {
|
||||||
|
const pageRequest = async (query: PageQuery) => {
|
||||||
|
return await api.GetList(query);
|
||||||
|
};
|
||||||
|
const editRequest = async ({ form, row }: EditReq) => {
|
||||||
|
form.id = row.id;
|
||||||
|
return await api.UpdateObj(form);
|
||||||
|
};
|
||||||
|
const delRequest = async ({ row }: DelReq) => {
|
||||||
|
return await api.DelObj(row.id);
|
||||||
|
};
|
||||||
|
const addRequest = async ({ form }: AddReq) => {
|
||||||
|
return await api.AddObj(form);
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
crudOptions: {
|
||||||
|
request: {
|
||||||
|
pageRequest,
|
||||||
|
addRequest,
|
||||||
|
editRequest,
|
||||||
|
delRequest,
|
||||||
|
},
|
||||||
|
columns: {
|
||||||
|
_index: {
|
||||||
|
title: '序号',
|
||||||
|
form: { show: false },
|
||||||
|
column: {
|
||||||
|
//type: 'index',
|
||||||
|
align: 'center',
|
||||||
|
width: '70px',
|
||||||
|
columnSetDisabled: true, //禁止在列设置中选择
|
||||||
|
formatter: (context) => {
|
||||||
|
//计算序号,你可以自定义计算规则,此处为翻页累加
|
||||||
|
let index = context.index ?? 1;
|
||||||
|
let pagination = crudExpose.crudBinding.value.pagination;
|
||||||
|
return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pcode: {
|
||||||
|
title: '父级地区',
|
||||||
|
show: false,
|
||||||
|
search: {
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
|
type: 'dict-tree',
|
||||||
|
form: {
|
||||||
|
component: {
|
||||||
|
showAllLevels: false, // 仅显示最后一级
|
||||||
|
props: {
|
||||||
|
elProps: {
|
||||||
|
clearable: true,
|
||||||
|
showAllLevels: false, // 仅显示最后一级
|
||||||
|
props: {
|
||||||
|
checkStrictly: true, // 可以不需要选到最后一级
|
||||||
|
emitPath: false,
|
||||||
|
clearable: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
title: '名称',
|
||||||
|
search: {
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
|
treeNode: true,
|
||||||
|
width: 160,
|
||||||
|
type: 'input',
|
||||||
|
form: {
|
||||||
|
rules: [
|
||||||
|
// 表单校验规则
|
||||||
|
{ required: true, message: '名称必填项' },
|
||||||
|
],
|
||||||
|
component: {
|
||||||
|
placeholder: '请输入名称',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
code: {
|
||||||
|
title: '地区编码',
|
||||||
|
search: {
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
|
type: 'input',
|
||||||
|
form: {
|
||||||
|
rules: [
|
||||||
|
// 表单校验规则
|
||||||
|
{ required: true, message: '地区编码必填项' },
|
||||||
|
],
|
||||||
|
component: {
|
||||||
|
placeholder: '请输入地区编码',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pinyin: {
|
||||||
|
title: '拼音',
|
||||||
|
search: {
|
||||||
|
disabled: true,
|
||||||
|
},
|
||||||
|
type: 'input',
|
||||||
|
form: {
|
||||||
|
rules: [
|
||||||
|
// 表单校验规则
|
||||||
|
{ required: true, message: '拼音必填项' },
|
||||||
|
],
|
||||||
|
component: {
|
||||||
|
placeholder: '请输入拼音',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
level: {
|
||||||
|
title: '地区层级',
|
||||||
|
search: {
|
||||||
|
disabled: true,
|
||||||
|
},
|
||||||
|
type: 'input',
|
||||||
|
form: {
|
||||||
|
disabled: false,
|
||||||
|
rules: [
|
||||||
|
// 表单校验规则
|
||||||
|
{ required: true, message: '拼音必填项' },
|
||||||
|
],
|
||||||
|
component: {
|
||||||
|
placeholder: '请输入拼音',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
initials: {
|
||||||
|
title: '首字母',
|
||||||
|
form: {
|
||||||
|
rules: [
|
||||||
|
// 表单校验规则
|
||||||
|
{ required: true, message: '首字母必填项' },
|
||||||
|
],
|
||||||
|
|
||||||
|
component: {
|
||||||
|
placeholder: '请输入首字母',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
enable: {
|
||||||
|
title: '是否启用',
|
||||||
|
search: {
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
|
width: 90,
|
||||||
|
type: 'dict-radio',
|
||||||
|
dict: dict({
|
||||||
|
data: dictionary('button_status_bool'),
|
||||||
|
}),
|
||||||
|
form: {
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
26
web/src/views/system/areas/index.vue
Normal file
26
web/src/views/system/areas/index.vue
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<template>
|
||||||
|
<fs-page>
|
||||||
|
<fs-crud ref="crudRef" v-bind="crudBinding"> </fs-crud>
|
||||||
|
</fs-page>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref, onMounted } from 'vue';
|
||||||
|
import { useExpose, useCrud } from '@fast-crud/fast-crud';
|
||||||
|
import { createCrudOptions } from './crud';
|
||||||
|
// crud组件的ref
|
||||||
|
const crudRef = ref();
|
||||||
|
// crud 配置的ref
|
||||||
|
const crudBinding = ref();
|
||||||
|
// 暴露的方法
|
||||||
|
const { crudExpose } = useExpose({ crudRef, crudBinding });
|
||||||
|
// 你的crud配置
|
||||||
|
const { crudOptions } = createCrudOptions({ crudExpose });
|
||||||
|
// 初始化crud配置
|
||||||
|
const { resetCrudOptions } = useCrud({ crudExpose, crudOptions });
|
||||||
|
|
||||||
|
// 页面打开后获取列表数据
|
||||||
|
onMounted(() => {
|
||||||
|
crudExpose.doRefresh();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user