92 lines
2.2 KiB
Smarty
92 lines
2.2 KiB
Smarty
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,
|
|
},
|
|
]; |