menu.data.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. import { BasicColumn } from '/@/components/Table';
  2. import { FormSchema } from '/@/components/Table';
  3. import { h } from 'vue';
  4. import { Icon } from '/@/components/Icon';
  5. import { duplicateCheck } from '../user/user.api';
  6. import { ajaxGetDictItems, checkPermDuplication } from './menu.api';
  7. import { render } from '/@/utils/common/renderUtils';
  8. const isDir = (type) => type === 0;
  9. const isMenu = (type) => type === 1;
  10. const isButton = (type) => type === 2;
  11. // 定义可选择的组件类型
  12. export enum ComponentTypes {
  13. Default = 'layouts/default/index',
  14. IFrame = 'sys/iframe/FrameBlank',
  15. // IFrame = 'sys/iframe/index',
  16. }
  17. export const columns: BasicColumn[] = [
  18. {
  19. title: '菜单名称',
  20. dataIndex: 'name',
  21. width: 200,
  22. align: 'left',
  23. },
  24. {
  25. title: '菜单类型',
  26. dataIndex: 'menuType',
  27. width: 150,
  28. customRender: ({ text }) => {
  29. return render.renderDict(text, 'menu_type');
  30. },
  31. },
  32. {
  33. title: '图标',
  34. dataIndex: 'icon',
  35. width: 50,
  36. customRender: ({ record }) => {
  37. return h(Icon, { icon: record.icon });
  38. },
  39. },
  40. {
  41. title: '组件',
  42. dataIndex: 'component',
  43. align: 'left',
  44. width: 150,
  45. },
  46. {
  47. title: '路径',
  48. dataIndex: 'url',
  49. align: 'left',
  50. width: 150,
  51. },
  52. {
  53. title: '排序',
  54. dataIndex: 'sortNo',
  55. width: 50,
  56. },
  57. ];
  58. export const searchFormSchema: FormSchema[] = [
  59. {
  60. field: 'name',
  61. label: '菜单名称',
  62. component: 'Input',
  63. colProps: { span: 8 },
  64. },
  65. ];
  66. export const formSchema: FormSchema[] = [
  67. {
  68. label: 'id',
  69. field: 'id',
  70. component: 'Input',
  71. show: false,
  72. },
  73. {
  74. field: 'menuType',
  75. label: '菜单类型',
  76. component: 'RadioButtonGroup',
  77. defaultValue: 0,
  78. componentProps: ({ formActionType, formModel }) => {
  79. return {
  80. options: [
  81. { label: '一级菜单', value: 0 },
  82. { label: '子菜单', value: 1 },
  83. { label: '按钮/权限', value: 2 },
  84. ],
  85. onChange: (e) => {
  86. const { updateSchema, clearValidate } = formActionType;
  87. const label = isButton(e) ? '按钮/权限' : '菜单名称';
  88. //清除校验
  89. clearValidate();
  90. updateSchema([
  91. {
  92. field: 'name',
  93. label: label,
  94. },
  95. {
  96. field: 'url',
  97. required: !isButton(e),
  98. },
  99. ]);
  100. //update-begin---author:wangshuai ---date:20220729 for:[VUEN-1834]只有一级菜单,才默认值,子菜单的时候,清空------------
  101. if (isMenu(e) && !formModel.id && (formModel.component == 'layouts/default/index' || formModel.component == 'layouts/RouteView')) {
  102. formModel.component = '';
  103. }
  104. //update-end---author:wangshuai ---date:20220729 for:[VUEN-1834]只有一级菜单,才默认值,子菜单的时候,清空------------
  105. },
  106. };
  107. },
  108. },
  109. {
  110. field: 'name',
  111. label: '菜单名称',
  112. component: 'Input',
  113. required: true,
  114. },
  115. {
  116. field: 'parentId',
  117. label: '上级菜单',
  118. component: 'TreeSelect',
  119. required: true,
  120. componentProps: {
  121. //update-begin---author:wangshuai ---date:20230829 for:replaceFields已过期,使用fieldNames代替------------
  122. fieldNames: {
  123. label: 'name',
  124. key: 'id',
  125. value: 'id',
  126. },
  127. //update-end---author:wangshuai ---date:20230829 for:replaceFields已过期,使用fieldNames代替------------
  128. dropdownStyle: {
  129. maxHeight: '50vh',
  130. },
  131. getPopupContainer: (node) => node.parentNode,
  132. },
  133. ifShow: ({ values }) => !isDir(values.menuType),
  134. },
  135. {
  136. field: 'url',
  137. label: '访问路径',
  138. component: 'Input',
  139. required: true,
  140. //update-begin-author:liusq date:2023-06-06 for: [issues/5008]子表数据权限设置不生效
  141. ifShow: ({ values }) => !(values.component === ComponentTypes.IFrame && values.internalOrExternal),
  142. //update-begin-author:zyf date:2022-11-02 for: 聚合路由允许路径重复
  143. dynamicRules: ({ model, schema, values }) => {
  144. return checkPermDuplication(model, schema, values.menuType !== 2 ? true : false);
  145. },
  146. //update-end-author:zyf date:2022-11-02 for: 聚合路由允许路径重复
  147. //update-end-author:liusq date:2022-06-06 for: [issues/5008]子表数据权限设置不生效
  148. },
  149. {
  150. field: 'component',
  151. label: '前端组件',
  152. component: 'Input',
  153. componentProps: {
  154. placeholder: '请输入前端组件',
  155. },
  156. defaultValue: 'layouts/default/index',
  157. required: true,
  158. ifShow: ({ values }) => !isButton(values.menuType),
  159. },
  160. {
  161. field: 'componentName',
  162. label: '组件名称',
  163. component: 'Input',
  164. componentProps: {
  165. placeholder: '请输入组件名称',
  166. },
  167. helpMessage: [
  168. '此处名称应和vue组件的name属性保持一致。',
  169. '组件名称不能重复,主要用于路由缓存功能。',
  170. '如果组件名称和vue组件的name属性不一致,则会导致路由缓存失效。',
  171. '非必填,留空则会根据访问路径自动生成。',
  172. ],
  173. defaultValue: '',
  174. ifShow: ({ values }) => !isButton(values.menuType),
  175. },
  176. {
  177. field: 'frameSrc',
  178. label: 'Iframe地址',
  179. component: 'Input',
  180. rules: [
  181. { required: true, message: '请输入Iframe地址' },
  182. { type: 'url', message: '请输入正确的url地址' },
  183. ],
  184. ifShow: ({ values }) => !isButton(values.menuType) && values.component === ComponentTypes.IFrame,
  185. },
  186. {
  187. field: 'redirect',
  188. label: '默认跳转地址',
  189. component: 'Input',
  190. ifShow: ({ values }) => isDir(values.menuType),
  191. },
  192. {
  193. field: 'perms',
  194. label: '授权标识',
  195. component: 'Input',
  196. ifShow: ({ values }) => isButton(values.menuType),
  197. // dynamicRules: ({ model }) => {
  198. // return [
  199. // {
  200. // required: false,
  201. // validator: (_, value) => {
  202. // return new Promise((resolve, reject) => {
  203. // let params = {
  204. // tableName: 'sys_permission',
  205. // fieldName: 'perms',
  206. // fieldVal: value,
  207. // dataId: model.id,
  208. // };
  209. // duplicateCheck(params)
  210. // .then((res) => {
  211. // res.success ? resolve() : reject(res.message || '校验失败');
  212. // })
  213. // .catch((err) => {
  214. // reject(err.message || '校验失败');
  215. // });
  216. // });
  217. // },
  218. // },
  219. // ];
  220. // },
  221. },
  222. {
  223. field: 'permsType',
  224. label: '授权策略',
  225. component: 'RadioGroup',
  226. defaultValue: '1',
  227. helpMessage: ['可见/可访问(授权后可见/可访问)', '可编辑(未授权时禁用)'],
  228. componentProps: {
  229. options: [
  230. { label: '可见/可访问', value: '1' },
  231. { label: '可编辑', value: '2' },
  232. ],
  233. },
  234. ifShow: ({ values }) => isButton(values.menuType),
  235. },
  236. {
  237. field: 'status',
  238. label: '状态',
  239. component: 'RadioGroup',
  240. defaultValue: '1',
  241. componentProps: {
  242. options: [
  243. { label: '有效', value: '1' },
  244. { label: '无效', value: '0' },
  245. ],
  246. },
  247. ifShow: ({ values }) => isButton(values.menuType),
  248. },
  249. {
  250. field: 'icon',
  251. label: '菜单图标',
  252. component: 'IconPicker',
  253. ifShow: ({ values }) => !isButton(values.menuType),
  254. },
  255. {
  256. field: 'sortNo',
  257. label: '排序',
  258. component: 'InputNumber',
  259. defaultValue: 1,
  260. ifShow: ({ values }) => !isButton(values.menuType),
  261. },
  262. {
  263. field: 'route',
  264. label: '是否路由菜单',
  265. component: 'Switch',
  266. defaultValue: true,
  267. componentProps: {
  268. checkedChildren: '是',
  269. unCheckedChildren: '否',
  270. },
  271. ifShow: ({ values }) => !isButton(values.menuType),
  272. },
  273. {
  274. field: 'hidden',
  275. label: '隐藏路由',
  276. component: 'Switch',
  277. defaultValue: 0,
  278. componentProps: {
  279. checkedChildren: '是',
  280. unCheckedChildren: '否',
  281. },
  282. ifShow: ({ values }) => !isButton(values.menuType),
  283. },
  284. {
  285. field: 'hideTab',
  286. label: '隐藏Tab',
  287. component: 'Switch',
  288. defaultValue: 0,
  289. componentProps: {
  290. checkedChildren: '是',
  291. unCheckedChildren: '否',
  292. },
  293. ifShow: ({ values }) => !isButton(values.menuType),
  294. },
  295. {
  296. field: 'keepAlive',
  297. label: '是否缓存路由',
  298. component: 'Switch',
  299. defaultValue: false,
  300. componentProps: {
  301. checkedChildren: '是',
  302. unCheckedChildren: '否',
  303. },
  304. ifShow: ({ values }) => !isButton(values.menuType),
  305. },
  306. {
  307. field: 'alwaysShow',
  308. label: '聚合路由',
  309. component: 'Switch',
  310. defaultValue: false,
  311. componentProps: {
  312. checkedChildren: '是',
  313. unCheckedChildren: '否',
  314. },
  315. ifShow: ({ values }) => !isButton(values.menuType),
  316. },
  317. {
  318. field: 'internalOrExternal',
  319. label: '打开方式',
  320. component: 'Switch',
  321. defaultValue: false,
  322. componentProps: {
  323. checkedChildren: '外部',
  324. unCheckedChildren: '内部',
  325. },
  326. ifShow: ({ values }) => !isButton(values.menuType),
  327. },
  328. {
  329. field: 'ver',
  330. label: '菜单是否可点',
  331. component: 'RadioButtonGroup',
  332. defaultValue: '1',
  333. componentProps: {
  334. options: [
  335. { label: '是', value: '1' },
  336. { label: '否', value: '0' },
  337. ],
  338. },
  339. },
  340. ];
  341. export const dataRuleColumns: BasicColumn[] = [
  342. {
  343. title: '规则名称',
  344. dataIndex: 'ruleName',
  345. width: 150,
  346. },
  347. {
  348. title: '规则字段',
  349. dataIndex: 'ruleColumn',
  350. width: 100,
  351. },
  352. {
  353. title: '规则值',
  354. dataIndex: 'ruleValue',
  355. width: 100,
  356. },
  357. ];
  358. export const dataRuleSearchFormSchema: FormSchema[] = [
  359. {
  360. field: 'ruleName',
  361. label: '规则名称',
  362. component: 'Input',
  363. // colProps: { span: 6 },
  364. },
  365. {
  366. field: 'ruleValue',
  367. label: '规则值',
  368. component: 'Input',
  369. // colProps: { span: 6 },
  370. },
  371. ];
  372. export const dataRuleFormSchema: FormSchema[] = [
  373. {
  374. label: 'id',
  375. field: 'id',
  376. component: 'Input',
  377. show: false,
  378. },
  379. {
  380. field: 'ruleName',
  381. label: '规则名称',
  382. component: 'Input',
  383. required: true,
  384. },
  385. {
  386. field: 'ruleColumn',
  387. label: '规则字段',
  388. component: 'Input',
  389. ifShow: ({ values }) => {
  390. return values.ruleConditions !== 'USE_SQL_RULES';
  391. },
  392. },
  393. {
  394. field: 'ruleConditions',
  395. label: '条件规则',
  396. required: true,
  397. component: 'ApiSelect',
  398. componentProps: {
  399. api: ajaxGetDictItems,
  400. params: { code: 'rule_conditions' },
  401. labelField: 'text',
  402. valueField: 'value',
  403. getPopupContainer: (node) => document.body,
  404. },
  405. },
  406. {
  407. field: 'ruleValue',
  408. label: '规则值',
  409. component: 'Input',
  410. required: true,
  411. },
  412. {
  413. field: 'status',
  414. label: '状态',
  415. component: 'RadioButtonGroup',
  416. defaultValue: '1',
  417. componentProps: {
  418. options: [
  419. { label: '无效', value: '0' },
  420. { label: '有效', value: '1' },
  421. ],
  422. },
  423. },
  424. ];