menu.data.ts 10.0 KB

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