123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- 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';
- import { usePermission } from '/@/hooks/web/usePermission';
- const { reloadMenu } = usePermission();
- const adaptWidth = adapt();
- export const columns: BasicColumn[] = [
- {
- // title: '**',
- // dataIndex: '',
- align: 'left',
- width: 60,
- },
- {
- title: 'ID',
- dataIndex: 'id',
- editComponentProps: {
- prefix: '$',
- },
- // align: 'left',
- width: 100,
- },
- {
- 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 }) => {
- async function onChange(val) {
- console.log(val, record.id);
- record.ismenu = val;
- const data = { id: record.id, ismenu: val };
- await editRule(data);
- reloadMenu();
- }
- 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: 120,
- },
- ];
- // popup =====================================================
- export const schemas: FormSchema[] = [
- {
- field: 'pid',
- label: '父级',
- component: 'TreeSelect',
- defaultValue: 0,
- 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,
- },
- required: true,
- },
- {
- field: 'icon',
- label: '图标',
- component: 'IconPicker',
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- },
- },
- {
- field: 'url',
- component: 'Input',
- label: '路径',
- labelWidth: adaptWidth.labelWidth,
- defaultValue: '',
- colProps: {
- span: adaptWidth.elContainer,
- },
- show: ({ values }) => {
- if (!values.ismenu) {
- return false;
- }
- return true;
- },
- },
- {
- field: 'redirect',
- component: 'Input',
- label: '重定向',
- labelWidth: adaptWidth.labelWidth,
- defaultValue: '',
- colProps: {
- span: adaptWidth.elContainer,
- },
- show: ({ values }) => {
- if (values.pid || !values.ismenu) {
- return false;
- }
- return true;
- },
- // required: ({ values }) => {
- // if (values.pid || !values.ismenu) {
- // return false;
- // }
- // return true;
- // },
- },
- {
- field: 'ismenu',
- label: '是否菜单',
- component: 'Switch',
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- },
- },
- {
- field: 'weigh',
- component: 'InputNumber',
- label: '权重',
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- },
- required: true,
- },
- {
- field: 'status',
- label: '状态',
- component: 'RadioButtonGroup',
- defaultValue: 'normal',
- componentProps: {
- options: [
- { label: '启用', value: 'normal' },
- { label: '停用', value: 'locked' },
- ],
- },
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- },
- },
- ];
|