data.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import { h } from 'vue';
  2. import { Tag, Switch } from 'ant-design-vue';
  3. import { BasicColumn } from '/@/components/Table';
  4. import { FormSchema } from '/@/components/Form/index';
  5. import { Icon } from '/@/components/Icon';
  6. import { adapt } from '/@/utils/adapt';
  7. import { editRule } from '/@/api/sys/user';
  8. import { usePermission } from '/@/hooks/web/usePermission';
  9. const { reloadMenu } = usePermission();
  10. const adaptWidth = adapt();
  11. export const columns: BasicColumn[] = [
  12. {
  13. // title: '**',
  14. // dataIndex: '',
  15. align: 'left',
  16. width: 60,
  17. },
  18. {
  19. title: 'ID',
  20. dataIndex: 'id',
  21. editComponentProps: {
  22. prefix: '$',
  23. },
  24. // align: 'left',
  25. width: 100,
  26. },
  27. {
  28. title: '标题',
  29. dataIndex: 'title',
  30. width: 160,
  31. },
  32. {
  33. title: '图标',
  34. dataIndex: 'icon',
  35. width: 80,
  36. customRender: ({ record }) => {
  37. return h(Icon, { icon: record.icon });
  38. },
  39. },
  40. {
  41. title: '规则',
  42. dataIndex: 'name',
  43. width: 200,
  44. },
  45. {
  46. title: '菜单',
  47. dataIndex: 'ismenu',
  48. width: 80,
  49. customRender: ({ record }) => {
  50. async function onChange(val) {
  51. console.log(val, record.id);
  52. record.ismenu = val;
  53. const data = { id: record.id, ismenu: val };
  54. await editRule(data);
  55. reloadMenu();
  56. }
  57. return h(Switch, { checked: record.ismenu, onChange: onChange });
  58. },
  59. },
  60. {
  61. title: '状态',
  62. dataIndex: 'status',
  63. width: 80,
  64. customRender: ({ record }) => {
  65. const status = record.status;
  66. const enable = status === 'normal';
  67. const color = enable ? 'green' : 'red';
  68. const text = enable ? '启用' : '停用';
  69. return h(Tag, { color: color }, () => text);
  70. },
  71. },
  72. {
  73. title: '权重',
  74. dataIndex: 'weigh',
  75. width: 120,
  76. },
  77. ];
  78. // popup =====================================================
  79. export const schemas: FormSchema[] = [
  80. {
  81. field: 'pid',
  82. label: '父级',
  83. component: 'TreeSelect',
  84. defaultValue: 0,
  85. componentProps: {
  86. replaceFields: {
  87. title: 'title',
  88. key: 'id',
  89. value: 'id',
  90. },
  91. getPopupContainer: () => document.body,
  92. },
  93. labelWidth: adaptWidth.labelWidth,
  94. colProps: {
  95. span: adaptWidth.elContainer,
  96. },
  97. },
  98. {
  99. field: 'title',
  100. component: 'Input',
  101. label: '标题',
  102. labelWidth: adaptWidth.labelWidth,
  103. colProps: {
  104. span: adaptWidth.elContainer,
  105. },
  106. },
  107. {
  108. field: 'name',
  109. component: 'Input',
  110. label: '名称',
  111. labelWidth: adaptWidth.labelWidth,
  112. colProps: {
  113. span: adaptWidth.elContainer,
  114. },
  115. required: true,
  116. },
  117. {
  118. field: 'icon',
  119. label: '图标',
  120. component: 'IconPicker',
  121. labelWidth: adaptWidth.labelWidth,
  122. colProps: {
  123. span: adaptWidth.elContainer,
  124. },
  125. },
  126. {
  127. field: 'url',
  128. component: 'Input',
  129. label: '路径',
  130. labelWidth: adaptWidth.labelWidth,
  131. defaultValue: '',
  132. colProps: {
  133. span: adaptWidth.elContainer,
  134. },
  135. show: ({ values }) => {
  136. if (!values.ismenu) {
  137. return false;
  138. }
  139. return true;
  140. },
  141. },
  142. {
  143. field: 'redirect',
  144. component: 'Input',
  145. label: '重定向',
  146. labelWidth: adaptWidth.labelWidth,
  147. defaultValue: '',
  148. colProps: {
  149. span: adaptWidth.elContainer,
  150. },
  151. show: ({ values }) => {
  152. if (values.pid || !values.ismenu) {
  153. return false;
  154. }
  155. return true;
  156. },
  157. // required: ({ values }) => {
  158. // if (values.pid || !values.ismenu) {
  159. // return false;
  160. // }
  161. // return true;
  162. // },
  163. },
  164. {
  165. field: 'ismenu',
  166. label: '是否菜单',
  167. component: 'Switch',
  168. labelWidth: adaptWidth.labelWidth,
  169. colProps: {
  170. span: adaptWidth.elContainer,
  171. },
  172. },
  173. {
  174. field: 'weigh',
  175. component: 'InputNumber',
  176. label: '权重',
  177. labelWidth: adaptWidth.labelWidth,
  178. colProps: {
  179. span: adaptWidth.elContainer,
  180. },
  181. required: true,
  182. },
  183. {
  184. field: 'status',
  185. label: '状态',
  186. component: 'RadioButtonGroup',
  187. defaultValue: 'normal',
  188. componentProps: {
  189. options: [
  190. { label: '启用', value: 'normal' },
  191. { label: '停用', value: 'locked' },
  192. ],
  193. },
  194. labelWidth: adaptWidth.labelWidth,
  195. colProps: {
  196. span: adaptWidth.elContainer,
  197. },
  198. },
  199. ];