import { h } from 'vue'; import { Tag, Switch } from 'ant-design-vue'; import { BasicColumn } from '/@/components/Table'; import { FormSchema } from '/@/components/Form/index'; import { Icon } from '/@/components/Icon'; import { adapt } from '/@/utils/adapt'; import { editRule } from '/@/api/sys/user'; const adaptWidth = adapt(); export const fakeTree = [ { id: 1, title: 'Dashboard', status: true, icon: 'ion:layers-outline', create_time: '2021-01-01', detail: '', children: [ { id: 2, title: '工作台', status: true, icon: 'ion:git-compare-outline', create_time: '2021-01-01', detail: '', children: [ { id: 8, title: '天然光', status: true, icon: 'ion:git-compare-outline', create_time: '2021-01-01', detail: '', }, { id: 9, title: '小苏打粉', status: false, icon: 'ion:tv-outline', create_time: '2021-01-01', detail: '', }, { id: 22, title: '士大夫', status: true, icon: 'ion:git-compare-outline', create_time: '2021-01-01', detail: '', }, { id: 95, title: '小苏打粉', status: false, icon: 'ion:tv-outline', create_time: '2021-01-01', detail: '', }, ], }, { id: 3, title: '分析页', status: false, icon: 'ion:tv-outline', create_time: '2021-01-01', detail: '', children: [ { id: 10, title: '略略略', status: true, icon: 'ion:git-compare-outline', create_time: '2021-01-01', detail: '', }, { id: 19, title: '嘻嘻嘻', status: false, icon: 'ion:tv-outline', create_time: '2021-01-01', detail: '', }, ], }, ], }, { id: 4, title: '权限管理', status: true, icon: 'bx:bx-lock', create_time: '2021-01-01', detail: '', children: [ { id: 5, title: '角色管理', status: true, icon: 'bx:bx-lock', create_time: '2021-01-01', detail: '', }, { id: 6, title: '菜单管理', status: true, icon: 'bx:bx-lock', create_time: '2021-01-01', detail: '', }, ], }, ]; export const columns: BasicColumn[] = [ { title: 'ID', dataIndex: 'id', editComponentProps: { prefix: '$', }, width: 80, }, { title: '标题', dataIndex: 'title', width: 160, }, { title: '图标', dataIndex: 'icon', width: 80, customRender: ({ record }) => { return h(Icon, { icon: record.icon }); }, }, { title: '规则', dataIndex: 'name', width: 200, }, { title: '菜单', dataIndex: 'ismenu', width: 80, customRender: ({ record }) => { function onChange(val) { console.log(val, record.id); record.ismenu = val; const data = { id: record.id, ismenu: Number(val) }; console.log(`data11`, data); editRule(data); } return h(Switch, { checked: record.ismenu, onChange: onChange }); }, }, { title: '状态', dataIndex: 'status', width: 80, customRender: ({ record }) => { const status = record.status; const enable = status === 'normal'; const color = enable ? 'green' : 'red'; const text = enable ? '启用' : '停用'; return h(Tag, { color: color }, () => text); }, }, { title: '权重', dataIndex: 'weigh', width: 160, }, ]; // popup ===================================================== export const schemas: FormSchema[] = [ { field: 'pid', label: '父级', component: 'TreeSelect', componentProps: { replaceFields: { title: 'title', key: 'id', value: 'id', }, getPopupContainer: () => document.body, }, labelWidth: adaptWidth.labelWidth, colProps: { span: adaptWidth.elContainer, }, }, { field: 'title', component: 'Input', label: '标题', labelWidth: adaptWidth.labelWidth, colProps: { span: adaptWidth.elContainer, }, }, { field: 'name', component: 'Input', label: '名称', labelWidth: adaptWidth.labelWidth, colProps: { span: adaptWidth.elContainer, }, }, { field: 'rules', component: 'Input', label: '规则', labelWidth: adaptWidth.labelWidth, colProps: { span: adaptWidth.elContainer, }, }, { field: 'icon', label: '图标', component: 'IconPicker', labelWidth: adaptWidth.labelWidth, colProps: { span: adaptWidth.elContainer, }, }, { field: 'ismenu', label: '是否菜单', component: 'Switch', labelWidth: adaptWidth.labelWidth, colProps: { span: adaptWidth.elContainer, }, }, { field: 'status', label: '状态', component: 'RadioButtonGroup', defaultValue: 'normal', componentProps: { options: [ { label: '启用', value: 'normal' }, { label: '停用', value: 'locked' }, ], }, labelWidth: adaptWidth.labelWidth, colProps: { span: adaptWidth.elContainer, }, }, ];