import { h, ref } from 'vue'; import { cloneDeep } from 'lodash-es'; import { FormSchema } from '@/components/Form'; import { renderImage, renderOptionTag } from '@/utils'; import { useDictStore } from '@/store/modules/dict'; const dict = useDictStore(); export class State { public id = 0; // id public title = ''; // 活动标题 public introduction = ''; // 活动介绍 public cover = ''; // 活动封面图 public imgs = ''; // 说明图片 public banner = ''; // 活动头图 public video = ''; // 活动视频 public startTime = ''; // 活动开始时间 public endTime = ''; // 活动结束时间 public extra = ''; // 扩展字段 public attachment = ''; // 活动附件 public status = 1; // 活动状态 public revision = 0; // 乐观锁 public createdBy = 0; // 创建人 public createdTime = ''; // 创建时间 public updatedBy = 0; // 更新人 public updatedTime = ''; // 更新时间 constructor(state?: Partial) { if (state) { Object.assign(this, state); } } } export function newState(state: State | Record | null): State { if (state !== null) { if (state instanceof State) { return cloneDeep(state); } return new State(state); } return new State(); } // 表单验证规则 // 表格搜索表单 export const schemas = ref([ { field: 'id', component: 'NInputNumber', label: 'id', componentProps: { placeholder: '请输入id', onUpdateValue: (e: any) => { console.log(e); }, }, }, { field: 'status', component: 'NSelect', label: '活动状态', defaultValue: null, componentProps: { placeholder: '请选择活动状态', options: dict.getOption('sys_normal_disable'), onUpdateValue: (e: any) => { console.log(e); }, }, }, ]); // 表格列 export const columns = [ { title: 'id', key: 'id', align: 'left', width: -1, }, { title: '活动标题', key: 'title', align: 'left', width: -1, }, { title: '活动封面图', key: 'cover', align: 'left', width: -1, render(row: State) { return renderImage(row.cover); }, }, { title: '活动头图', key: 'banner', align: 'left', width: -1, render(row: State) { return renderImage(row.banner); }, }, { title: '活动开始时间', key: 'startTime', align: 'left', width: -1, }, { title: '活动结束时间', key: 'endTime', align: 'left', width: -1, }, { title: '活动状态', key: 'status', align: 'left', width: -1, render(row: State) { return renderOptionTag('sys_normal_disable', row.status); }, }, ]; // 加载字典数据选项 export function loadOptions() { dict.loadOptions(['sys_normal_disable']); }