data.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. const adaptWidth = adapt();
  9. export const fakeTree = [
  10. {
  11. id: 1,
  12. title: 'Dashboard',
  13. status: true,
  14. icon: 'ion:layers-outline',
  15. create_time: '2021-01-01',
  16. detail: '',
  17. children: [
  18. {
  19. id: 2,
  20. title: '工作台',
  21. status: true,
  22. icon: 'ion:git-compare-outline',
  23. create_time: '2021-01-01',
  24. detail: '',
  25. children: [
  26. {
  27. id: 8,
  28. title: '天然光',
  29. status: true,
  30. icon: 'ion:git-compare-outline',
  31. create_time: '2021-01-01',
  32. detail: '',
  33. },
  34. {
  35. id: 9,
  36. title: '小苏打粉',
  37. status: false,
  38. icon: 'ion:tv-outline',
  39. create_time: '2021-01-01',
  40. detail: '',
  41. },
  42. {
  43. id: 22,
  44. title: '士大夫',
  45. status: true,
  46. icon: 'ion:git-compare-outline',
  47. create_time: '2021-01-01',
  48. detail: '',
  49. },
  50. {
  51. id: 95,
  52. title: '小苏打粉',
  53. status: false,
  54. icon: 'ion:tv-outline',
  55. create_time: '2021-01-01',
  56. detail: '',
  57. },
  58. ],
  59. },
  60. {
  61. id: 3,
  62. title: '分析页',
  63. status: false,
  64. icon: 'ion:tv-outline',
  65. create_time: '2021-01-01',
  66. detail: '',
  67. children: [
  68. {
  69. id: 10,
  70. title: '略略略',
  71. status: true,
  72. icon: 'ion:git-compare-outline',
  73. create_time: '2021-01-01',
  74. detail: '',
  75. },
  76. {
  77. id: 19,
  78. title: '嘻嘻嘻',
  79. status: false,
  80. icon: 'ion:tv-outline',
  81. create_time: '2021-01-01',
  82. detail: '',
  83. },
  84. ],
  85. },
  86. ],
  87. },
  88. {
  89. id: 4,
  90. title: '权限管理',
  91. status: true,
  92. icon: 'bx:bx-lock',
  93. create_time: '2021-01-01',
  94. detail: '',
  95. children: [
  96. {
  97. id: 5,
  98. title: '角色管理',
  99. status: true,
  100. icon: 'bx:bx-lock',
  101. create_time: '2021-01-01',
  102. detail: '',
  103. },
  104. {
  105. id: 6,
  106. title: '菜单管理',
  107. status: true,
  108. icon: 'bx:bx-lock',
  109. create_time: '2021-01-01',
  110. detail: '',
  111. },
  112. ],
  113. },
  114. ];
  115. export const columns: BasicColumn[] = [
  116. {
  117. title: 'ID',
  118. dataIndex: 'id',
  119. editComponentProps: {
  120. prefix: '$',
  121. },
  122. width: 80,
  123. },
  124. {
  125. title: '标题',
  126. dataIndex: 'title',
  127. width: 160,
  128. },
  129. {
  130. title: '图标',
  131. dataIndex: 'icon',
  132. width: 80,
  133. customRender: ({ record }) => {
  134. return h(Icon, { icon: record.icon });
  135. },
  136. },
  137. {
  138. title: '规则',
  139. dataIndex: 'name',
  140. width: 200,
  141. },
  142. {
  143. title: '菜单',
  144. dataIndex: 'ismenu',
  145. width: 80,
  146. customRender: ({ record }) => {
  147. function onChange(val) {
  148. console.log(val, record.id);
  149. record.ismenu = val;
  150. const data = { id: record.id, ismenu: Number(val) };
  151. console.log(`data11`, data);
  152. editRule(data);
  153. }
  154. return h(Switch, { checked: record.ismenu, onChange: onChange });
  155. },
  156. },
  157. {
  158. title: '状态',
  159. dataIndex: 'status',
  160. width: 80,
  161. customRender: ({ record }) => {
  162. const status = record.status;
  163. const enable = status === 'normal';
  164. const color = enable ? 'green' : 'red';
  165. const text = enable ? '启用' : '停用';
  166. return h(Tag, { color: color }, () => text);
  167. },
  168. },
  169. {
  170. title: '权重',
  171. dataIndex: 'weigh',
  172. width: 160,
  173. },
  174. ];
  175. // popup =====================================================
  176. export const schemas: FormSchema[] = [
  177. {
  178. field: 'pid',
  179. label: '父级',
  180. component: 'TreeSelect',
  181. componentProps: {
  182. replaceFields: {
  183. title: 'title',
  184. key: 'id',
  185. value: 'id',
  186. },
  187. getPopupContainer: () => document.body,
  188. },
  189. labelWidth: adaptWidth.labelWidth,
  190. colProps: {
  191. span: adaptWidth.elContainer,
  192. },
  193. },
  194. {
  195. field: 'title',
  196. component: 'Input',
  197. label: '标题',
  198. labelWidth: adaptWidth.labelWidth,
  199. colProps: {
  200. span: adaptWidth.elContainer,
  201. },
  202. },
  203. {
  204. field: 'name',
  205. component: 'Input',
  206. label: '名称',
  207. labelWidth: adaptWidth.labelWidth,
  208. colProps: {
  209. span: adaptWidth.elContainer,
  210. },
  211. },
  212. {
  213. field: 'rules',
  214. component: 'Input',
  215. label: '规则',
  216. labelWidth: adaptWidth.labelWidth,
  217. colProps: {
  218. span: adaptWidth.elContainer,
  219. },
  220. },
  221. {
  222. field: 'icon',
  223. label: '图标',
  224. component: 'IconPicker',
  225. labelWidth: adaptWidth.labelWidth,
  226. colProps: {
  227. span: adaptWidth.elContainer,
  228. },
  229. },
  230. {
  231. field: 'ismenu',
  232. label: '是否菜单',
  233. component: 'Switch',
  234. labelWidth: adaptWidth.labelWidth,
  235. colProps: {
  236. span: adaptWidth.elContainer,
  237. },
  238. },
  239. {
  240. field: 'status',
  241. label: '状态',
  242. component: 'RadioButtonGroup',
  243. defaultValue: 'normal',
  244. componentProps: {
  245. options: [
  246. { label: '启用', value: 'normal' },
  247. { label: '停用', value: 'locked' },
  248. ],
  249. },
  250. labelWidth: adaptWidth.labelWidth,
  251. colProps: {
  252. span: adaptWidth.elContainer,
  253. },
  254. },
  255. ];