签入版本
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import { http } from '@/utils/http/axios';
|
||||
|
||||
/**
|
||||
* @description: {{ module_comment }}分页列表
|
||||
*/
|
||||
export function get{{ model_class_name }}Page(params?) {
|
||||
return http.request({
|
||||
url: '/{{ route_prefix }}/page',
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部{{ module_comment }}列表
|
||||
* @param params 参数
|
||||
* @returns 返回结果
|
||||
*/
|
||||
export function get{{ model_class_name }}List(params?) {
|
||||
return http.request({
|
||||
url: '/{{ route_prefix }}/list',
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 根据ID获取{{ module_comment }}详情
|
||||
* @param {{ primary_key }} {{ module_comment }}ID
|
||||
*/
|
||||
export function get{{ model_class_name }}Detail({{ primary_key }}) {
|
||||
return http.request({
|
||||
url: '/{{ route_prefix }}/detail/' + {{ primary_key }},
|
||||
method: 'get',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 添加{{ module_comment }}
|
||||
* @param data {{ module_comment }}数据
|
||||
*/
|
||||
export function {{ model_class_name_camel }}Add(data: any) {
|
||||
return http.request({
|
||||
url: '/{{ route_prefix }}/add',
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 更新{{ module_comment }}
|
||||
* @param data {{ module_comment }}数据
|
||||
*/
|
||||
export function {{ model_class_name_camel }}Update(data: any) {
|
||||
return http.request({
|
||||
url: '/{{ route_prefix }}/update',
|
||||
method: 'PUT',
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 删除{{ module_comment }}
|
||||
* @param {{ primary_key }} {{ module_comment }}ID
|
||||
*/
|
||||
export function {{ model_class_name_camel }}Delete({{ primary_key }}) {
|
||||
return http.request({
|
||||
url: '/{{ route_prefix }}/delete/' + {{ primary_key }},
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 批量删除{{ module_comment }}
|
||||
* @param data {{ module_comment }}ID数组
|
||||
*/
|
||||
export function {{ model_class_name_camel }}BatchDelete(data: any) {
|
||||
return http.request({
|
||||
url: '/{{ route_prefix }}/batchDelete',
|
||||
method: 'DELETE',
|
||||
data,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import { h } from 'vue';
|
||||
import { ElAvatar, ElTag } from 'element-plus';
|
||||
|
||||
/**
|
||||
* 表格列配置
|
||||
* 定义表格显示的列
|
||||
*/
|
||||
export const columns = [
|
||||
{
|
||||
type: 'selection', // 多选框列
|
||||
},
|
||||
{
|
||||
label: 'ID',
|
||||
prop: 'id',
|
||||
fixed: 'left',
|
||||
width: 50,
|
||||
},
|
||||
{% for field in list_fields %}
|
||||
{
|
||||
label: '{{ field.label }}',
|
||||
prop: '{{ field.camel_name }}',
|
||||
minWidth: {% if field.type == 'CharField' %}120{% elif field.type == 'IntegerField' %}100{% elif field.type == 'DateTimeField' %}180{% else %}120{% endif %},
|
||||
{% if field.is_image %}
|
||||
// 图片渲染
|
||||
render(record) {
|
||||
return h(ElAvatar, {
|
||||
size: 48,
|
||||
src: record.row.{{ field.camel_name }},
|
||||
shape: 'square',
|
||||
fit: 'fill',
|
||||
});
|
||||
},
|
||||
{% elif field.choices %}
|
||||
// 状态标签渲染
|
||||
render(record) {
|
||||
const statusMap = {
|
||||
{% for choice in field.choices %}
|
||||
{{ choice.value }}: { text: '{{ choice.label }}', type: {% if choice.value == 1 %}'success'{% elif choice.value == 2 %}'danger'{% elif choice.value == 3 %}'warning'{% else %}'info'{% endif %} },
|
||||
{% endfor %}
|
||||
};
|
||||
const status = statusMap[record.row.{{ field.camel_name }}];
|
||||
return h(
|
||||
ElTag,
|
||||
{
|
||||
type: status?.type || 'info',
|
||||
},
|
||||
{
|
||||
default: () => status?.text || record.row.{{ field.camel_name }},
|
||||
},
|
||||
);
|
||||
},
|
||||
{% elif field.camel_name == 'status' %}
|
||||
// 状态标签渲染
|
||||
render(record) {
|
||||
return h(
|
||||
ElTag,
|
||||
{
|
||||
type: record.row.status == 1 ? 'success' : 'danger',
|
||||
},
|
||||
{
|
||||
default: () => (record.row.status == 1 ? '正常' : '停用'),
|
||||
},
|
||||
);
|
||||
},
|
||||
{% elif field.type == 'CharField' and field.camel_name|lower in ['website', 'site', 'url', 'link'] %}
|
||||
// 链接渲染
|
||||
render(record) {
|
||||
return h(
|
||||
'a',
|
||||
{
|
||||
href: record.row.{{ field.camel_name }},
|
||||
target: '_blank',
|
||||
},
|
||||
'点击查看',
|
||||
);
|
||||
},
|
||||
{% else %}
|
||||
// 普通文本渲染
|
||||
{% endif %}
|
||||
},
|
||||
{% endfor %}
|
||||
{
|
||||
label: '创建人',
|
||||
prop: 'createUser',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
label: '创建时间',
|
||||
prop: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,184 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="props.visible"
|
||||
title="{{ module_comment }}详情"
|
||||
width="750"
|
||||
:close-on-click-modal="false"
|
||||
:before-close="dialogClose"
|
||||
>
|
||||
<el-descriptions column="2" border>
|
||||
{% for field in form_fields %}
|
||||
<el-descriptions-item label="{{ field.label }}:" label-class-name="des-width">
|
||||
{% if field.is_image %}
|
||||
<el-image
|
||||
v-if="formData.{{ field.camel_name }}"
|
||||
:src="formData.{{ field.camel_name }}"
|
||||
:preview-src-list="[formData.{{ field.camel_name }}]"
|
||||
fit="cover"
|
||||
style="width: 80px; height: 80px"
|
||||
/>
|
||||
<span v-else>-</span>
|
||||
{% elif field.is_rich_text %}
|
||||
<div class="rich-text-content" v-html="formData.{{ field.camel_name }}"></div>
|
||||
{% elif field.type == 'BooleanField' %}
|
||||
<el-tag :type="formData.{{ field.camel_name }} ? 'success' : 'danger'">
|
||||
{{ '{{ formData.' + field.camel_name + ' ? "是" : "否" }}' }}
|
||||
</el-tag>
|
||||
{% elif field.type == 'IntegerField' and field.choices %}
|
||||
<span>{{ '{{ getChoiceLabel(\'' + field.camel_name + '\', formData.' + field.camel_name + ') }}' }}</span>
|
||||
{% else %}
|
||||
{{ '{{ formData.' + field.camel_name + ' || \'-\' }}' }}
|
||||
{% endif %}
|
||||
</el-descriptions-item>
|
||||
{% endfor %}
|
||||
</el-descriptions>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="dialogClose">关闭</el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { get{{ model_class_name }}Detail } from '@/api/{{ api_path }}';
|
||||
import { onMounted, reactive, watch } from 'vue';
|
||||
{% if has_image_field %}
|
||||
import { ElImage } from 'element-plus';
|
||||
{% endif %}
|
||||
|
||||
const emit = defineEmits(['update:visible']);
|
||||
|
||||
/**
|
||||
* 定义表单参数
|
||||
*/
|
||||
const formData = reactive({
|
||||
id: '',
|
||||
{% for field in form_fields %}
|
||||
{{ field.camel_name }}: {% if field.type == 'CharField' %}''{% elif field.type == 'IntegerField' %}0{% elif field.type == 'BooleanField' %}false{% elif field.type == 'FloatField' %}0{% else %}''{% endif %},
|
||||
{% endfor %}
|
||||
});
|
||||
|
||||
/**
|
||||
* 定义接收的参数
|
||||
*/
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
default: false,
|
||||
},
|
||||
{{ primary_key }}: {
|
||||
type: Number,
|
||||
required: true,
|
||||
default: 0,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 获取选项字段的标签
|
||||
*/
|
||||
const getChoiceLabel = (fieldName: string, value: any) => {
|
||||
const choiceMap: Record<string, Record<string, string>> = {
|
||||
{% for field in form_fields %}
|
||||
{% if field.type == 'IntegerField' and field.choices %}
|
||||
{{ field.camel_name }}: {
|
||||
{% for choice in field.choices %}
|
||||
{{ choice.value }}: '{{ choice.label }}',
|
||||
{% endfor %}
|
||||
},
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
};
|
||||
return choiceMap[fieldName]?.[value] || value || '-';
|
||||
};
|
||||
|
||||
/**
|
||||
* 关闭窗体
|
||||
*/
|
||||
const dialogClose = () => {
|
||||
emit('update:visible', false);
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置表单数据
|
||||
*/
|
||||
const setFormData = async () => {
|
||||
try {
|
||||
const data = await get{{ model_class_name }}Detail(props.{{ primary_key }});
|
||||
for (const key in formData) {
|
||||
if (data[key] != null && data[key] != undefined) {
|
||||
//@ts-ignore
|
||||
formData[key] = data[key];
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取{{ module_comment }}详情失败', error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置表单数据
|
||||
*/
|
||||
const resetFormData = () => {
|
||||
for (const key in formData) {
|
||||
//@ts-ignore
|
||||
if (typeof formData[key] === 'string') {
|
||||
//@ts-ignore
|
||||
formData[key] = '';
|
||||
} else if (typeof formData[key] === 'number') {
|
||||
//@ts-ignore
|
||||
formData[key] = 0;
|
||||
} else if (typeof formData[key] === 'boolean') {
|
||||
//@ts-ignore
|
||||
formData[key] = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 监听visible变化,重新加载数据
|
||||
*/
|
||||
watch(
|
||||
() => props.visible,
|
||||
(newVal) => {
|
||||
if (newVal && props.{{ primary_key }}) {
|
||||
setFormData();
|
||||
} else if (newVal && !props.{{ primary_key }}) {
|
||||
resetFormData();
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/**
|
||||
* 钩子函数
|
||||
*/
|
||||
onMounted(() => {
|
||||
if (props.visible && props.{{ primary_key }}) {
|
||||
setFormData();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
:deep(.des-width) {
|
||||
width: 120px;
|
||||
}
|
||||
:deep(.el-descriptions__body .el-descriptions__table .el-descriptions__cell) {
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.rich-text-content {
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
border: 1px solid #e4e7ed;
|
||||
padding: 10px;
|
||||
border-radius: 4px;
|
||||
background-color: #f8f9fa;
|
||||
|
||||
:deep(img) {
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,383 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="props.visible"
|
||||
:title="props.{{ primary_key }} ? '编辑{{ module_comment }}' : '新增{{ module_comment }}'"
|
||||
{% if has_rich_text_field %}
|
||||
width="850"
|
||||
{% else %}
|
||||
width="500"
|
||||
{% endif %}
|
||||
:close-on-click-modal="false"
|
||||
:before-close="dialogClose"
|
||||
>
|
||||
<!-- 表单 -->
|
||||
<el-form class="ls-form" ref="formRef" :model="formData" label-width="80px">
|
||||
{% for field in form_fields %}
|
||||
{% if field.is_image %}
|
||||
<!-- {{ field.comment }}(图片上传) -->
|
||||
<el-form-item
|
||||
label="{{ field.label }}"
|
||||
prop="{{ field.camel_name }}"
|
||||
{% if field.required %}
|
||||
:rules="{ required: true, message: '请上传{{ field.comment }}', trigger: 'change' }"
|
||||
{% endif %}
|
||||
>
|
||||
<UploadImg
|
||||
@changeFileName="(name) => (formData.{{ field.camel_name }}ImgName = name)"
|
||||
:fileType="['image/jpeg', 'image/png', 'image/jpg', 'image/gif', 'image/webp']"
|
||||
name="{{ app_name }}"
|
||||
:fileSize="20"
|
||||
v-model:image-url="formData.{{ field.camel_name }}"
|
||||
>
|
||||
<template #tip>支持扩展名: jpg png jpeg gif webp; 文件大小不超过20M</template>
|
||||
</UploadImg>
|
||||
</el-form-item>
|
||||
{% elif field.is_rich_text %}
|
||||
<!-- {{ field.comment }}(富文本编辑器) -->
|
||||
<el-form-item
|
||||
label="{{ field.label }}"
|
||||
prop="{{ field.camel_name }}"
|
||||
{% if field.required %}
|
||||
:rules="{ required: true, message: '请输入{{ field.comment }}', trigger: 'blur' }"
|
||||
{% endif %}
|
||||
>
|
||||
<div class="flex">
|
||||
<el-form-item class="flex-1" label-width="0">
|
||||
<Editor
|
||||
ref="{{ field.camel_name }}EditorRef"
|
||||
:height="editorHeight"
|
||||
class="flex-1"
|
||||
name="{{ app_name }}"
|
||||
/>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form-item>
|
||||
{% elif field.type == 'CharField' and ('备注' in field.comment or '介绍' in field.comment or '描述' in field.comment or '说明' in field.comment) %}
|
||||
<!-- {{ field.comment }}(多行文本) -->
|
||||
<el-form-item
|
||||
label="{{ field.label }}"
|
||||
prop="{{ field.camel_name }}"
|
||||
{% if field.required %}
|
||||
:rules="{ required: true, message: '请输入{{ field.comment }}', trigger: 'blur' }"
|
||||
{% endif %}
|
||||
>
|
||||
<el-input type="textarea" v-model="formData.{{ field.camel_name }}" placeholder="请输入{{ field.comment }}" :rows="3" clearable />
|
||||
</el-form-item>
|
||||
{% elif field.type == 'CharField' %}
|
||||
<!-- {{ field.comment }} -->
|
||||
<el-form-item
|
||||
label="{{ field.label }}"
|
||||
prop="{{ field.camel_name }}"
|
||||
{% if field.required %}
|
||||
:rules="{ required: true, message: '请输入{{ field.comment }}', trigger: 'blur' }"
|
||||
{% endif %}
|
||||
>
|
||||
<el-input class="ls-input" v-model="formData.{{ field.camel_name }}" placeholder="请输入{{ field.comment }}" clearable />
|
||||
</el-form-item>
|
||||
{% elif field.type == 'IntegerField' and field.choices %}
|
||||
<!-- {{ field.comment }}({% if field.choices|length <= 2 %}单选{% else %}下拉选择{% endif %}) -->
|
||||
<el-form-item
|
||||
label="{{ field.label }}"
|
||||
prop="{{ field.camel_name }}"
|
||||
{% if field.required %}
|
||||
:rules="{ required: true, message: '请选择{{ field.comment }}', trigger: 'change' }"
|
||||
{% endif %}
|
||||
>
|
||||
{% if field.choices|length <= 2 %}
|
||||
<el-radio-group v-model="formData.{{ field.camel_name }}">
|
||||
{% for choice in field.choices %}
|
||||
<el-radio :value="{{ choice.value }}">{{ choice.label }}</el-radio>
|
||||
{% endfor %}
|
||||
</el-radio-group>
|
||||
{% else %}
|
||||
<el-select
|
||||
v-model="formData.{{ field.camel_name }}"
|
||||
placeholder="请选择{{ field.comment }}"
|
||||
clearable
|
||||
filterable
|
||||
>
|
||||
<el-option
|
||||
v-for="item in optionsData.{{ field.camel_name }}List"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
{% endif %}
|
||||
</el-form-item>
|
||||
{% elif field.type == 'IntegerField' and not field.choices %}
|
||||
<!-- {{ field.comment }}(数字输入) -->
|
||||
<el-form-item
|
||||
label="{{ field.label }}"
|
||||
prop="{{ field.camel_name }}"
|
||||
{% if field.required %}
|
||||
:rules="{ required: true, message: '请输入{{ field.comment }}', trigger: 'blur' }"
|
||||
{% endif %}
|
||||
>
|
||||
<el-input-number v-model="formData.{{ field.camel_name }}" :min="{{ field.min_value or 0 }}" :max="{{ field.max_value or 99999 }}" />
|
||||
</el-form-item>
|
||||
{% elif field.type == 'BooleanField' %}
|
||||
<!-- {{ field.comment }}(开关) -->
|
||||
<el-form-item label="{{ field.label }}" prop="{{ field.camel_name }}">
|
||||
<el-switch v-model="formData.{{ field.camel_name }}" :active-value="1" :inactive-value="0" />
|
||||
</el-form-item>
|
||||
{% elif field.type == 'DateField' %}
|
||||
<!-- {{ field.comment }}(日期选择) -->
|
||||
<el-form-item
|
||||
label="{{ field.label }}"
|
||||
prop="{{ field.camel_name }}"
|
||||
{% if field.required %}
|
||||
:rules="{ required: true, message: '请选择{{ field.comment }}', trigger: 'change' }"
|
||||
{% endif %}
|
||||
>
|
||||
<el-date-picker
|
||||
v-model="formData.{{ field.camel_name }}"
|
||||
type="date"
|
||||
placeholder="请选择{{ field.comment }}"
|
||||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
/>
|
||||
</el-form-item>
|
||||
{% elif field.type == 'DateTimeField' %}
|
||||
<!-- {{ field.comment }}(日期时间选择) -->
|
||||
<el-form-item
|
||||
label="{{ field.label }}"
|
||||
prop="{{ field.camel_name }}"
|
||||
{% if field.required %}
|
||||
:rules="{ required: true, message: '请选择{{ field.comment }}', trigger: 'change' }"
|
||||
{% endif %}
|
||||
>
|
||||
<el-date-picker
|
||||
v-model="formData.{{ field.camel_name }}"
|
||||
type="datetime"
|
||||
placeholder="请选择{{ field.comment }}"
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
/>
|
||||
</el-form-item>
|
||||
{% elif field.type == 'TextField' %}
|
||||
<!-- {{ field.comment }}(文本域) -->
|
||||
<el-form-item
|
||||
label="{{ field.label }}"
|
||||
prop="{{ field.camel_name }}"
|
||||
{% if field.required %}
|
||||
:rules="{ required: true, message: '请输入{{ field.comment }}', trigger: 'blur' }"
|
||||
{% endif %}
|
||||
>
|
||||
<el-input type="textarea" v-model="formData.{{ field.camel_name }}" placeholder="请输入{{ field.comment }}" :rows="3" />
|
||||
</el-form-item>
|
||||
{% elif field.type == 'FloatField' or field.type == 'DecimalField' %}
|
||||
<!-- {{ field.comment }}(数字输入) -->
|
||||
<el-form-item
|
||||
label="{{ field.label }}"
|
||||
prop="{{ field.camel_name }}"
|
||||
{% if field.required %}
|
||||
:rules="{ required: true, message: '请输入{{ field.comment }}', trigger: 'blur' }"
|
||||
{% endif %}
|
||||
>
|
||||
<el-input-number
|
||||
v-model="formData.{{ field.camel_name }}"
|
||||
:min="{{ field.min_value or 0 }}"
|
||||
:max="{{ field.max_value or 999999 }}"
|
||||
:precision="2"
|
||||
:step="0.1"
|
||||
/>
|
||||
</el-form-item>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</el-form>
|
||||
|
||||
<!-- 底部按钮 -->
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="dialogClose">取消</el-button>
|
||||
<el-button :loading="subLoading" type="primary" @click="submit">确定</el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FormInstance } from 'element-plus';
|
||||
import { get{{ model_class_name }}Detail, {{ model_class_name_camel }}Add, {{ model_class_name_camel }}Update } from '@/api/{{ api_path }}';
|
||||
import { onMounted, reactive, shallowRef, watch } from 'vue';
|
||||
import { message } from '@/utils/auth';
|
||||
import { useLockFn } from '@/utils/useLockFn';
|
||||
{% if has_image_field %}
|
||||
import UploadImg from '@/components/Upload/Image.vue';
|
||||
{% endif %}
|
||||
{% if has_rich_text_field %}
|
||||
import Editor from '@/components/Editor/tinymce.vue';
|
||||
{% endif %}
|
||||
|
||||
// 定义事件
|
||||
const emit = defineEmits(['success', 'update:visible']);
|
||||
|
||||
// 表单引用
|
||||
const formRef = shallowRef<FormInstance>();
|
||||
|
||||
{% if has_rich_text_field %}
|
||||
// 富文本编辑器高度
|
||||
const editorHeight = document.body.clientHeight - 400;
|
||||
|
||||
// 富文本编辑器引用
|
||||
{% for field in form_fields %}
|
||||
{% if field.is_rich_text %}
|
||||
const {{ field.camel_name }}EditorRef = ref();
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
/**
|
||||
* 定义选项数据
|
||||
*/
|
||||
const optionsData = reactive({
|
||||
{% for field in form_fields %}
|
||||
{% if field.type == 'IntegerField' and field.choices and field.choices|length > 2 %}
|
||||
{{ field.camel_name }}List: [
|
||||
{% for choice in field.choices %}
|
||||
{
|
||||
id: {% if choice.value_type == 'string' %}'{{ choice.value }}'{% else %}{{ choice.value }}{% endif %},
|
||||
name: '{{ choice.label }}',
|
||||
},
|
||||
{% endfor %}
|
||||
],
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
});
|
||||
|
||||
/**
|
||||
* 定义表单数据
|
||||
* 初始化默认值
|
||||
*/
|
||||
const formData = reactive({
|
||||
id: '', // ID字段,新增时为0
|
||||
{% for field in form_fields %}
|
||||
{{ field.camel_name }}: {% if field.type == 'CharField' %}''{% elif field.type == 'IntegerField' %}{{ field.default or 0 }}{% elif field.type == 'BooleanField' %}{{ field.default or 0 }}{% elif field.type == 'FloatField' %}{{ field.default or 0 }}{% else %}''{% endif %},
|
||||
{% endfor %}
|
||||
{% for field in form_fields %}
|
||||
{% if field.is_image %}
|
||||
{{ field.camel_name }}ImgName: '', // {{ field.comment }}文件名
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
});
|
||||
|
||||
/**
|
||||
* 定义接收的参数
|
||||
*/
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
default: false,
|
||||
},
|
||||
{{ primary_key }}: {
|
||||
type: Number,
|
||||
required: true,
|
||||
default: 0,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 执行提交表单
|
||||
* 根据是否有ID判断是新增还是编辑
|
||||
*/
|
||||
const handleSubmit = async () => {
|
||||
// 获取富文本编辑器内容
|
||||
{% for field in form_fields %}
|
||||
{% if field.is_rich_text %}
|
||||
if ({{ field.camel_name }}EditorRef.value) {
|
||||
formData.{{ field.camel_name }} = {{ field.camel_name }}EditorRef.value.myValue;
|
||||
}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
// 表单验证
|
||||
await formRef.value?.validate();
|
||||
|
||||
// 调用接口
|
||||
props.{{ primary_key }} ? await {{ model_class_name_camel }}Update(formData) : await {{ model_class_name_camel }}Add(formData);
|
||||
|
||||
message('操作成功');
|
||||
emit('update:visible', false);
|
||||
emit('success');
|
||||
};
|
||||
|
||||
/**
|
||||
* 关闭窗体
|
||||
*/
|
||||
const dialogClose = () => {
|
||||
emit('update:visible', false);
|
||||
};
|
||||
|
||||
// 防抖处理,防止重复提交
|
||||
const { isLock: subLoading, lockFn: submit } = useLockFn(handleSubmit);
|
||||
|
||||
/**
|
||||
* 设置表单数据
|
||||
* 编辑时获取详情并填充表单
|
||||
*/
|
||||
const setFormData = async () => {
|
||||
try {
|
||||
const data = await get{{ model_class_name }}Detail(props.{{ primary_key }});
|
||||
for (const key in formData) {
|
||||
if (data[key] != null && data[key] != undefined) {
|
||||
// @ts-ignore
|
||||
formData[key] = data[key];
|
||||
}
|
||||
}
|
||||
// 设置富文本编辑器内容
|
||||
{% for field in form_fields %}
|
||||
{% if field.is_rich_text %}
|
||||
if ({{ field.camel_name }}EditorRef.value && formData.{{ field.camel_name }}) {
|
||||
{{ field.camel_name }}EditorRef.value.myValue = formData.{{ field.camel_name }};
|
||||
}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
} catch (error) {
|
||||
console.error('获取{{ module_comment }}详情失败', error);
|
||||
message('获取数据失败', 'error');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置表单
|
||||
*/
|
||||
const resetForm = () => {
|
||||
if (formRef.value) {
|
||||
formRef.value.resetFields();
|
||||
}
|
||||
// 清空富文本编辑器内容
|
||||
{% for field in form_fields %}
|
||||
{% if field.is_rich_text %}
|
||||
if ({{ field.camel_name }}EditorRef.value) {
|
||||
{{ field.camel_name }}EditorRef.value.myValue = '';
|
||||
}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
};
|
||||
|
||||
/**
|
||||
* 监听对话框打开
|
||||
* 编辑时加载数据,新增时重置表单
|
||||
*/
|
||||
onMounted(() => {
|
||||
if (props.{{ primary_key }}) {
|
||||
setFormData();
|
||||
} else {
|
||||
resetForm();
|
||||
}
|
||||
});
|
||||
|
||||
// 监听visible变化,重新加载数据
|
||||
watch(
|
||||
() => props.visible,
|
||||
(newVal) => {
|
||||
if (newVal && props.{{ primary_key }}) {
|
||||
setFormData();
|
||||
} else if (newVal && !props.{{ primary_key }}) {
|
||||
resetForm();
|
||||
}
|
||||
},
|
||||
);
|
||||
</script>
|
||||
@@ -0,0 +1,278 @@
|
||||
<template>
|
||||
<PageWrapper>
|
||||
<!-- 搜索表单卡片 -->
|
||||
<el-card :bordered="false" class="pt-3 mb-3 proCard">
|
||||
<BasicForm @register="register" @submit="handleSubmit" @reset="handleReset" />
|
||||
</el-card>
|
||||
|
||||
<!-- 数据表格卡片 -->
|
||||
<el-card :bordered="false" class="proCard">
|
||||
<BasicTable
|
||||
:columns="columns"
|
||||
:request="loadDataTable"
|
||||
:row-key="(row) => row.id"
|
||||
ref="tableRef"
|
||||
:actionColumn="actionColumn"
|
||||
@selection-change="onSelectionChange"
|
||||
>
|
||||
<!-- 表格顶部工具栏 -->
|
||||
<template #tableTitle>
|
||||
<!-- 新增按钮 -->
|
||||
<el-button type="primary" @click="handleAdd" v-perm="['{{ permission_prefix }}:add']">
|
||||
<template #icon>
|
||||
<el-icon class="el-input__icon">
|
||||
<PlusOutlined />
|
||||
</el-icon>
|
||||
</template>
|
||||
添加{{ module_comment }}
|
||||
</el-button>
|
||||
|
||||
<!-- 批量删除按钮 -->
|
||||
<el-button
|
||||
type="danger"
|
||||
@click="handleDelete()"
|
||||
:disabled="!selectionData.length"
|
||||
v-perm="['{{ permission_prefix }}:batchDelete']"
|
||||
>
|
||||
<template #icon>
|
||||
<el-icon class="el-input__icon">
|
||||
<Delete />
|
||||
</el-icon>
|
||||
</template>
|
||||
批量删除
|
||||
</el-button>
|
||||
{% if has_export %}
|
||||
<!-- 导出按钮 -->
|
||||
<el-button
|
||||
type="success"
|
||||
@click="handleExport"
|
||||
v-perm="['{{ permission_prefix }}:export']"
|
||||
>
|
||||
<template #icon>
|
||||
<el-icon class="el-input__icon">
|
||||
<Download />
|
||||
</el-icon>
|
||||
</template>
|
||||
导出
|
||||
</el-button>
|
||||
{% endif %}
|
||||
</template>
|
||||
</BasicTable>
|
||||
</el-card>
|
||||
|
||||
<!-- 编辑对话框组件 -->
|
||||
<editDialog
|
||||
v-if="editVisible"
|
||||
:{{ primary_key }}="currentId"
|
||||
v-model:visible="editVisible"
|
||||
@success="reloadTable('noRefresh')"
|
||||
/>
|
||||
<!-- 查看详情对话框组件 -->
|
||||
<detailDialog
|
||||
v-if="detailVisible"
|
||||
:{{ primary_key }}="currentId"
|
||||
v-model:visible="detailVisible"
|
||||
@success="reloadTable('noRefresh')"
|
||||
/>
|
||||
</PageWrapper>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref, h, nextTick, defineAsyncComponent } from 'vue';
|
||||
import { ColProps } from 'element-plus';
|
||||
import { schemas } from './querySchemas';
|
||||
import { useForm } from '@/components/Form/index';
|
||||
import { TableAction } from '@/components/Table';
|
||||
import { get{{ model_class_name }}Page, {{ model_class_name_camel }}Delete, {{ model_class_name_camel }}BatchDelete } from '@/api/{{ api_path }}';
|
||||
import { columns } from './columns';
|
||||
import { PlusOutlined } from '@vicons/antd';
|
||||
import { message, confirm } from '@/utils/auth';
|
||||
|
||||
// 动态导入编辑对话框组件
|
||||
const editDialog = defineAsyncComponent(() => import('./edit.vue'));
|
||||
// 动态导入详情对话框组件
|
||||
const detailDialog = defineAsyncComponent(() => import('./detail.vue'));
|
||||
|
||||
// 响应式状态定义
|
||||
const currentId = ref(0); // 当前操作的ID
|
||||
const editVisible = ref(false); // 编辑对话框显示状态
|
||||
const detailVisible = ref(false); // 详情对话框显示状态
|
||||
const selectionData = ref([]); // 表格选中数据
|
||||
const tableRef = ref(); // 表格组件引用
|
||||
|
||||
/**
|
||||
* 定义查询参数
|
||||
* 用于存储搜索表单的值
|
||||
*/
|
||||
const formParams = reactive({
|
||||
{% for field in filter_fields %}
|
||||
{{ field.name }}: '',
|
||||
{% endfor %}
|
||||
});
|
||||
|
||||
/**
|
||||
* 定义操作栏配置
|
||||
* 包含编辑、详情和删除按钮
|
||||
*/
|
||||
const actionColumn = reactive({
|
||||
width: 300,
|
||||
label: '操作',
|
||||
prop: 'action',
|
||||
fixed: 'right',
|
||||
render(record) {
|
||||
return h(TableAction, {
|
||||
style: 'button',
|
||||
actions: [
|
||||
{
|
||||
label: '编辑',
|
||||
icon: 'Edit',
|
||||
type: 'warning',
|
||||
onClick: handleEdit.bind(null, record),
|
||||
auth: ['{{ permission_prefix }}:update'],
|
||||
},
|
||||
{
|
||||
label: '详情',
|
||||
icon: 'View',
|
||||
type: '',
|
||||
onClick: handleDetail.bind(null, record),
|
||||
auth: ['{{ permission_prefix }}:detail'],
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
icon: 'Delete',
|
||||
type: 'danger',
|
||||
onClick: handleDelete.bind(null, record),
|
||||
auth: ['{{ permission_prefix }}:delete'],
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 加载数据列表
|
||||
* @param params 分页参数
|
||||
* @returns 表格数据
|
||||
*/
|
||||
const loadDataTable = async (params: any) => {
|
||||
const result = await get{{ model_class_name }}Page({ ...formParams, ...params });
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 刷新表格数据
|
||||
* @param noRefresh 是否重置页码
|
||||
*/
|
||||
function reloadTable(noRefresh = '') {
|
||||
tableRef.value.reload(noRefresh ? {} : { pageNo: 1 });
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册搜索表单
|
||||
* 配置表单布局和字段
|
||||
*/
|
||||
const [register, {}] = useForm({
|
||||
labelWidth: 80,
|
||||
layout: 'horizontal',
|
||||
colProps: { span: 6 } as ColProps,
|
||||
submitOnReset: true,
|
||||
schemas,
|
||||
});
|
||||
|
||||
/**
|
||||
* 提交搜索表单
|
||||
* @param values 表单值
|
||||
*/
|
||||
function handleSubmit(values: Recordable) {
|
||||
handleReset();
|
||||
for (const key in values) {
|
||||
formParams[key] = values[key];
|
||||
}
|
||||
reloadTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置搜索表单
|
||||
*/
|
||||
function handleReset() {
|
||||
for (const key in formParams) {
|
||||
formParams[key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理新增按钮点击
|
||||
*/
|
||||
const handleAdd = async () => {
|
||||
currentId.value = 0;
|
||||
await nextTick();
|
||||
editVisible.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 处理编辑按钮点击
|
||||
* @param record 当前行数据
|
||||
*/
|
||||
const handleEdit = async (record: Recordable) => {
|
||||
currentId.value = record.row.id;
|
||||
await nextTick();
|
||||
editVisible.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 处理详情按钮点击
|
||||
* @param record 当前行数据
|
||||
*/
|
||||
const handleDetail = async (record: Recordable) => {
|
||||
currentId.value = record.row.id;
|
||||
await nextTick();
|
||||
detailVisible.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 处理删除操作
|
||||
* @param record 当前行数据(可选,不传时表示批量删除)
|
||||
*/
|
||||
async function handleDelete(record: Recordable) {
|
||||
let ids = [];
|
||||
if (!record) {
|
||||
// 批量删除:获取选中行的ID
|
||||
ids = selectionData.value.map(({ id }) => id);
|
||||
if (!ids.length) {
|
||||
message('请选择要删除的数据', 'warning');
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 确认删除
|
||||
await confirm('确定要删除选中的{{ module_comment }}吗?');
|
||||
// 执行删除操作
|
||||
record ? await {{ model_class_name_camel }}Delete(record.row.id) : await {{ model_class_name_camel }}BatchDelete(ids);
|
||||
message('删除成功');
|
||||
reloadTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* 表格选择项变化时的回调
|
||||
* @param value 选中的数据
|
||||
*/
|
||||
function onSelectionChange(value) {
|
||||
selectionData.value = value;
|
||||
}
|
||||
|
||||
{% if has_export %}
|
||||
/**
|
||||
* 处理导出操作
|
||||
*/
|
||||
async function handleExport() {
|
||||
try {
|
||||
await confirm('确定要导出{{ module_comment }}数据吗?');
|
||||
// TODO: 调用导出API
|
||||
message('导出成功');
|
||||
} catch (error) {
|
||||
console.error('导出失败', error);
|
||||
}
|
||||
}
|
||||
{% endif %}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
@@ -0,0 +1,29 @@
|
||||
import { FormSchema } from '@/components/Form/index';
|
||||
|
||||
/**
|
||||
* 查询表单配置
|
||||
* 定义搜索区域的表单项
|
||||
*/
|
||||
export const schemas: FormSchema[] = [
|
||||
{% for field in filter_fields %}
|
||||
{
|
||||
field: '{{ field.name }}',
|
||||
component: '{% if field.type == 'CharField' %}Input{% elif field.choices %}Select{% elif field.type == 'IntegerField' and not field.choices %}InputNumber{% elif field.type == 'DateField' %}DatePicker{% else %}Input{% endif %}',
|
||||
label: '{{ field.label }}',
|
||||
componentProps: {
|
||||
placeholder: '请输入{{ field.label }}',
|
||||
clearable: true,
|
||||
{% if field.choices %}
|
||||
options: [
|
||||
{% for choice in field.choices %}
|
||||
{
|
||||
label: '{{ choice.label }}',
|
||||
value: {{ choice.value }},
|
||||
},
|
||||
{% endfor %}
|
||||
],
|
||||
{% endif %}
|
||||
},
|
||||
},
|
||||
{% endfor %}
|
||||
];
|
||||
Reference in New Issue
Block a user