crud.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, UserPageQuery,EditReq ,DelReq,dict} from '@fast-crud/fast-crud';
  2. import * as api from './api';
  3. import { auth } from '/@/utils/authFunction';
  4. export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  5. const pageRequest = async (query: UserPageQuery) => {
  6. return await api.GetList(query);
  7. };
  8. const editRequest = async ({ form, row }: EditReq) => {
  9. form.id = row.id;
  10. form.device_id=Number(form.device);
  11. form.title=form.article_title;
  12. form.content=form.article_content;
  13. return await api.UpdateObj(form);
  14. };
  15. const delRequest = async ({ row }: DelReq) => {
  16. return await api.DelObj(row.id);
  17. };
  18. const addRequest = async ({ form }: AddReq) => {
  19. form.device_id=Number(form.device);
  20. form.title=form.article_title;
  21. form.content=form.article_content;
  22. // console.log("sdfsdfsdfform::::",form);
  23. return await api.AddObj(form);
  24. };
  25. return {
  26. crudOptions: {
  27. request: {
  28. pageRequest,
  29. addRequest,
  30. editRequest,
  31. delRequest,
  32. },
  33. actionbar: {
  34. buttons: {
  35. add: {
  36. show: auth('area:Create'),
  37. },
  38. },
  39. },
  40. toolbar:{
  41. show:false,
  42. },
  43. rowHandle:{
  44. buttons:{
  45. remove:{
  46. show:true,
  47. },
  48. edit:{
  49. show:true,
  50. }
  51. }
  52. },
  53. pagination: {
  54. show: false,
  55. },
  56. columns: {
  57. _index: {
  58. title: '序号',
  59. form: { show: false },
  60. column: {
  61. show:false,
  62. type: 'index',
  63. align: 'center',
  64. width: '70px',
  65. columnSetDisabled: true, //禁止在列设置中选择
  66. },
  67. },
  68. device:{
  69. title: '设备id',
  70. search: {
  71. show: false,
  72. },
  73. treeNode: true,
  74. type: 'dict-select',
  75. column: {
  76. show:false,
  77. minWidth: 120,
  78. },
  79. dict: dict({
  80. url: '/api/system/device/',
  81. value: 'id',
  82. label: 'name',
  83. }),
  84. form: {
  85. show:true,
  86. component: { placeholder: '请选择设备id' },
  87. rules: [{ required: true, message: '请选择设备id' }],
  88. },
  89. },
  90. device_code: {
  91. title: '设备编码',
  92. search: {
  93. show: false,
  94. },
  95. treeNode: true,
  96. type: 'input',
  97. column: {
  98. minWidth: 120,
  99. },
  100. form: {
  101. show:false,
  102. },
  103. },
  104. article_title: {
  105. title: '设备标题',
  106. search: {
  107. show: false,
  108. },
  109. treeNode: true,
  110. type: 'input',
  111. column: {
  112. minWidth: 120,
  113. },
  114. form: {
  115. show:true,
  116. rules: [
  117. // 表单校验规则
  118. { required: true, message: '标题必填项' },
  119. ],
  120. component: {
  121. placeholder: '请输入标题',
  122. },
  123. },
  124. },
  125. article_content:{
  126. title: '内容',
  127. type: 'textarea',
  128. column: {
  129. show:true,
  130. minWidth: 120,
  131. },
  132. form: {
  133. show:true,
  134. col: {
  135. span: 24
  136. },
  137. component: { showWordLimit: true, maxlength: 200 ,placeholder: '请填写内容' },
  138. rules: [{
  139. required: true,
  140. message: '内容为必填项',
  141. }],
  142. },
  143. },
  144. device_name:{
  145. title: '发布人',
  146. type: 'input',
  147. column: {
  148. minWidth: 120,
  149. },
  150. form: {
  151. show:false,
  152. component: { placeholder: '请填发布人' },
  153. rules: [{ required: false, message: '请填写发布人' }],
  154. },
  155. },
  156. create_datetime:{
  157. title: '发布时间',
  158. type: 'input',
  159. column: {
  160. minWidth: 120,
  161. },
  162. form: {
  163. show:false,
  164. component: { placeholder: '请填写发布时间' },
  165. rules: [{ required: false, message: '请填写发布时间' }],
  166. },
  167. },
  168. is_default:{
  169. title: '状态',
  170. type: 'input',
  171. column: {
  172. show:false,
  173. minWidth: 120,
  174. },
  175. form: {
  176. value:true,
  177. show:false,
  178. component: { placeholder: '请填写状态' },
  179. rules: [{ required: false, message: '请填写状态' }],
  180. },
  181. },
  182. // device_id:{
  183. // title: '设备id',
  184. // type: 'input',
  185. // column: {
  186. // show:false,
  187. // minWidth: 120,
  188. // },
  189. // form: {
  190. // show:true,
  191. // component: { placeholder: '请填写状态' },
  192. // rules: [{ required: false, message: '请填写状态' }],
  193. // },
  194. // },
  195. // title:{
  196. // title: '设备标题',
  197. // type: 'input',
  198. // column: {
  199. // show:false,
  200. // minWidth: 120,
  201. // },
  202. // form: {
  203. // show:true,
  204. // component: { placeholder: '请填写设备标题' },
  205. // rules: [{ required: false, message: '请填写设备标题' }],
  206. // },
  207. // },
  208. // content:{
  209. // title: '设备内容',
  210. // type: 'input',
  211. // column: {
  212. // show:false,
  213. // minWidth: 120,
  214. // },
  215. // form: {
  216. // show:true,
  217. // component: { placeholder: '请填写设备内容' },
  218. // rules: [{ required: false, message: '请填写设备内容' }],
  219. // },
  220. // },
  221. },
  222. },
  223. };
  224. };